1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00
elua/doc/en/arch_newport.html
2009-03-12 22:01:32 +00:00

89 lines
6.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Language" content="en-us"><title>Porting eLua</title>
<link rel="stylesheet" type="text/css" href="../style.css"></head>
<body style="background-color: rgb(255, 255, 255);">
<h3>Porting eLua</h3>
<p>So, you realized how cool <b>eLua</b> is :), and you'd like to give it a try. Unfortunately, <b>eLua</b> 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. <b>eLua</b> 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 <a href="elua_arch.html">eLua architecture page</a>. </p>
<h3>Prerequisites</h3>
<p>Before starting to work on the port, make sure that:
<ul>
<li>your CPU has enough resources to run <b>eLua</b>. A very rough estimation (based on ARM Thumb code only) is that you'd need at least 256k
of program memory and 32k of RAM for a complete <b>eLua</b> image, and 128k of program memory for a basic image. It's possible to run <b>eLua</b> in
less than 32k of RAM (especially when <a href="arch_ltr.html">LTR</a> is enabled), but you'll probably run out of memory fast.
64k of RAM (or more) is recommended.</li>
<li><a target="_blank" href="http://sourceware.org/newlib">Newlib</a> is available for your CPU. <b>eLua</b> depends on Newlib currently
(although this limitation will be eliminated in a future version), so if Newlib is not available for your CPU, you're out of luck. </li>
<li>you have a C compiler for your target. Ideally you'd use GCC, but if this isn't possible other compilers might work as well. Keep in mind that
<a href="arch_ltr.html">LTR</a> needs a C99 C compiler (or at least a partially C99 compliant C compiler than supports C99-style union initialization).
</li>
<li>you have a platform library (it usually comes from the CPU manufacturer) that you can use to implement (at least part of) the platform interface.
It's also highly recommended to gain at least a basic understanding of your platform, it will help a lot while writing the port.</li>
</ul></p>
<p>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)
<b>eLua</b> 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
<a href="arch_overview.html#platforms">this section</a> first, as it details the structure of a port and might simplify your work quite a bit.</p>
<h3>Adding a new board</h3>
<p>If all you need is to add a new board that uses a CPU already supported by <b>eLua</b> (check <a href="status.html">here</a> for a complete list), it's
fairly easy to accomplish this:
<ol>
<li>choose a good name for your board :)</li>
<li>edit <b>SConstruct</b> and add your board to the <b>board_list</b> dictionary, specifying its CPU. A part of the definition of <b>board_list</b> is given below:
<p><pre><code># List of board/CPU combinations
board_list = { 'SAM7-EX256' : [ 'AT91SAM7X256', 'AT91SAM7X512' ],
'EK-LM3S8962' : [ 'LM3S8962' ],
'EK-LM3S6965' : [ 'LM3S6965' ],
..............................
}</code></pre></p>
</li>
<li>also edit the <b>file_list</b> dictionary in <b>SConstruct</b> to specify the list of ROMFS files that will be compiled for your board (see the
<a href="arch_romfs.html">ROMFS section</a> for details). A part of the definition of <b>file_list</b> is given below:
<p><pre><code># 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' ],
...............................
}</code></pre></p></li>
<li>if your board has external memory, you'll probably want to use the "multiple" allocator by default to take advantage of that (see <a href="building.html">building</a>)
for details. If so, you need to modify the CPU/allocator mapping code from <b>SConstruct</b>:
<p><pre><code># CPU/allocator mapping (if allocator not specified)
if allocator == '':
if <b>boardname == 'LPC-H2888'</b> or <b>boardname == 'ATEVK1100'</b>:
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 )
</code></pre></p>
</li>
<li>customize the <b>eLua</b> image for this new board. You can use the variable <b>boardname</b> in <b>conf.py</b> to define new preprocessor macros specifically for your board
(that you can use later in <b>platform_conf.h</b>, for example), or to include or exclude certain files from the build, or change the build flags and so on. An example taken from
the <b>lm3s</b> port is given below (part of <b>conf.py</b>):
<p><pre><code>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 = ""
</code></pre></p>
</li>
</ol></p>
<p>After you edit all the relevant source files, all you have to do is to execute "scons board=&lt;boardname;&gt;" and you'll have <b>eLua</b> compiled for your board.</p>
<h3>Adding a new CPU</h3>
##TODO
<h3>Adding a new platform</h3>
##TODO
</body></html>