$$HEADER$$
So, you realized how cool eLua is :), and you'd like to give it a try. Unfortunately, eLua doesn't have a port on your CPU or board of choice. The solution is simple: write the port yourself. This might seem as a daunting task at first, but it's actually easier than it sounds. eLua was designed to make the task of implementing new ports as easy and intuitive as possible. This section gives an overview of the porting process. It's not an exhaustive guide, but it should be enough to point you in the right direction. Before diving into this, it's highly recommended that you take a look at the eLua architecture page.
Before starting to work on the port, make sure that:
If all of the above are true, you should continue reading this document to bring your port to life. If not, we're sorry, but (at least at this point) eLua can't be ported to your CPU. If, on the other hand, you're good to go, please take a bit of time and read this section first, as it details the structure of a port and might simplify your work quite a bit.
If all you need is to add a new board that uses a CPU already supported by eLua (check here for a complete list), it's fairly easy to accomplish this:
# List of board/CPU combinations
board_list = { 'SAM7-EX256' : [ 'AT91SAM7X256', 'AT91SAM7X512' ],
'EK-LM3S8962' : [ 'LM3S8962' ],
'EK-LM3S6965' : [ 'LM3S6965' ],
..............................
}
# List of board/romfs data combinations
file_list = { 'SAM7-EX256' : [ 'bisect', 'hangman' , 'led', 'piano', 'hello', 'info', 'morse' ],
'EK-LM3S8962' : [ 'bisect', 'hangman', 'lhttpd', 'pong', 'led', 'piano', 'pwmled', 'tvbgone', 'hello', 'info', 'morse', 'adcscope' ],
'EK-LM3S6965' : [ 'bisect', 'hangman', 'lhttpd', 'pong', 'led', 'piano', 'pwmled', 'tvbgone', 'hello', 'info', 'morse', 'adcscope' ],
...............................
}
# CPU/allocator mapping (if allocator not specified)
if allocator == '':
if boardname == 'LPC-H2888' or boardname == 'ATEVK1100':
allocator = 'multiple'
else:
allocator = 'newlib'
elif allocator not in [ 'newlib', 'multiple', 'simple' ]:
print "Unknown allocator", allocator
print "Allocator can be either 'newlib', 'multiple' or 'simple'"
sys.exit( -1 )
if boardname == 'EK-LM3S6965' or boardname == 'EK-LM3S8962':
specific_files = specific_files + " rit128x96x4.c disp.c"
cdefs = cdefs + " -DENABLE_DISP"
# The default for the Eagle 100 board is to start the image at 0x2000,
# so that the built in Ethernet boot loader can be used to upload it
if boardname == 'EAGLE-100':
linkopts = "-Wl,-Ttext,0x2000"
else:
linkopts = ""
After you edit all the relevant source files, all you have to do is to execute scons board=<boardname> and you'll have eLua compiled for your board.
If you want to add a new CPU to eLua and the new CPU happens to be supported by a platform on which eLua already runs (see here for a full list), your task is still quite easy. Follow the steps below:
# List of platform/CPU/toolchains combinations
# The first toolchain in the toolchains list is the default one
# (the one that will be used if none is specified)
platform_list = {
'at91sam7x' : { 'cpus' : [ 'AT91SAM7X256', 'AT91SAM7X512' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
'lm3s' : { 'cpus' : [ 'LM3S8962', 'LM3S6965', 'LM3S6918' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
'str9' : { 'cpus' : [ 'STR912FAW44' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
..................
}
if cputype == 'AT91SAM7X256':
ldscript = "flash256.lds"
cdefs = cdefs + " -Dat91sam7x256"
elif cputype == 'AT91SAM7X512':
ldscript = "flash512.lds"
cdefs = cdefs + " -Dat91sam7x512"
else:
print "Invalid AT91SAM7X CPU %s" % cputype
sys.exit( -1 )
After you edit all the relevant source files, all you have to do is to execute scons board=<boardname> and you'll have eLua compiled for your board (and implicitly for your new CPU).
If you want to add a new CPU to eLua and the new CPU is not supported by a platform on which eLua already runs (see here for a full list), you have to go the whole way and add a completely new platform to eLua. This is certainly more difficult than the previous cases, but still not that hard. Remember to start small (implement only minimal support at first) and don't write everything from scratch, start from an already existing platform implementation and work your way up from there. The i386 port is the simplest, but also a bit different from the embedded ports. Another port that is quite simple at this point is the lpc2888 port, you might take a look at that too. After you "get a feeling" of how a port should look like, and after you read about the architecture of eLua and the structure of a port here, follow the steps below:
# List of platform/CPU/toolchains combinations
# The first toolchain in the toolchains list is the default one
# (the one that will be used if none is specified)
platform_list = {
'at91sam7x' : { 'cpus' : [ 'AT91SAM7X256', 'AT91SAM7X512' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
'lm3s' : { 'cpus' : [ 'LM3S8962', 'LM3S6965', 'LM3S6918' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
'str9' : { 'cpus' : [ 'STR912FAW44' ], 'toolchains' : [ 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' ] },
..................
}
After you edit all the relevant source files, all you have to do is to execute scons board=<boardname> and you'll have eLua compiled for your board (and implicitly for your new CPU).
$$FOOTER$$