码迷,mamicode.com
首页 > 其他好文 > 详细

elua学习(三)--定制elua的编译选项

时间:2014-09-04 11:53:39      阅读:465      评论:0      收藏:0      [点我收藏+]

标签:elua   stm32f4   嵌入式   lua   

第二篇关于elua的文章讲了,elua的编译和烧写。不过编译选项比较简单,全按照默认的配置,在这篇文章中主要讲怎么定制编译选项。当然还是以stm32f4discovery平台为例子。


关于参考文献

这里首先提参考文献,是因为以下的内容出处比较混乱,提前说一下,省的读者混淆。

elua为开源项目,文档还算齐全,但是文档更新的比较混乱:存在多个版本,且有的地方代码和文档不一致。

例如:

http://www.eluaproject.net/doc/v0.9/en_index.html

http://www.eluaproject.net/doc/v0.8/en_index.html

elua的安装目录下/Doc/En


我采取的原则是:离代码越近的文档可信度越高。所以首选/Doc/En,之后是v0.9的版本,之后才是0.8的版本。(编译elua时就因为文档更新不及时“codecourcery问题”,导致走了很多弯路)。

以下以elua/Doc/En/Building.txt为准

还可以参考:

自动编译器的变化

Building.txt

IMPORTANT:Starting with eLua 0.10, a new Lua-based build system replaces theprevious Python based (scons) build system. You‘ll need to use thenew build system to build eLua

现在(0.9)的自动编译工具不同于elua0.7版本scons(例如:sconscpu=at91sam7x256

而是已经采用基于lua的自动编译器,请注意这里的文档有误导性:

http://www.eluaproject.net/doc/v0.9/en_building.html (没有改过来)

http://www.eluaproject.net/doc/master/en_building.html (新的)

定制eluaimage 大致分为两步(两者是有先后顺序的):

Configuringthe build image。(配置)

Invokethe build system (build_elua) with the right arguments。(编译选项)


[[configuring]]

参考elua/Doc/En/configurator.txt

Theconfigurator works by reading a Lua based board configuration fileand generating the corresponding C header file (which for the mostpart has the same role as the platform_conf.h file that was usedbefore the configurator). The board name is given by the _board_argument to build_elua (see link:building.html#buildoptions[thislink] for more details about building your eLua image). Theconfigurator looks for a file named _<board>.lua_ in twolocations:

**boards/custom* is searched first. The files under this directory arenot part of the eLua source tree, so this is the place where you canadd configuration files for your custom board or customize theconfiguration for one of the standard boards (seelink:#config_customize[here] for more details about this).

**boards/known* is searched if _<board>.lua_ is not found in_boards/custom_. It contains the configuration of the boards on whicheLua is known to run properly. The files under this directory arepart of the eLua source tree.

Afterfinding _<board>.lua_ in one of these locations, theconfigurator runs and generates the corresponding header file in__boards/headers/board_<board>.h__. The files under_boards/headers_ are also not part of the eLua source tree, so theycan be edited manually if needed (see link:#manualedit[here] for moredetails). After this, the configurator is done and the build processcontinues with the usual steps (compiling and linking the sourcefiles).

三个目录

均在elua/board/

其中配置程序(configurator)首先搜索custom目录,需找<board>.lua文件,其中<board通过buildoptions中的[board=<board>]给出。开始时这个目录为空。

如果configuratorcustom目录搜索不到配置信息后(如果找到了就不会访问known目录的文件了),转向known目录,同样搜索<board>.lua。如果buildoptions中的[board=<board>]填写正确,就可以找到对应的<board>.lua。例如:stm32f4discovery.lua稍后我们详细解释该文件

最后,生成board_stm32f4discovery.h文件,该文件类似于以前自动编译器的platform_conf.h。这个文件可以手动修改。稍后我们将解释该文件。

这里需要说明的是,尽量不要修改known目录下的文件,可以在custom目录进行变更。

详解known/stm32f4discovery.lua

-- STM32F4DISCOVERY build configuration


return {

cpu = ‘stm32f407vg‘,

components = {

sercon = { uart = "cdc",speed = 115200 },

romfs = true,

cdc = { buf_size = 128 },

advanced_shell = true,

term = { lines = 25, cols = 80},

linenoise = { shell_lines = 10,lua_lines = 50 },

stm32f4_enc = true,

rpc = { uart = 0, speed =115200 },

adc = { buf_size = 2 },

xmodem = true,

cints = true,

luaints = true

},

config = {

egc = { mode = "alloc"},

vtmr = { num = 4, freq = 10 },

ram = { internal_rams = 2 },

clocks = { external = 8000000,cpu = 168000000 }

},

modules = {

generic = { ‘all‘, "-i2c","-net" },

platform = ‘all‘,

},

}

首先看一下分为几部分:

[[config_cpu]]

The CPU is given by the *cpu* key in the configuration table. The CPUmust be already known to the build system. A list of the known CPUscan be found in the *build_data.lua*file in the __platform_list__ table.

cpu = ‘stm32f407vg‘,

build_data.lua

local platform_list =

{

at91sam7x = { cpus = { ‘AT91SAM7X256‘, ‘AT91SAM7X512‘ }, arch =‘arm‘ },

lm3s = { cpus = { ‘LM3S1968‘, ‘LM3S8962‘, ‘LM3S6965‘, ‘LM3S6918‘,‘LM3S9B92‘, ‘LM3S9D92‘ }, arch = ‘cortexm‘ },

str9 = { cpus = { ‘STR912FAW44‘ }, arch = ‘arm‘ },

i386 = { cpus = { ‘I386‘ }, arch = ‘i386‘ },

sim = { cpus = { ‘LINUX‘ }, arch = ‘i386‘ },

lpc288x = { cpus = { ‘LPC2888‘ }, arch = ‘arm‘ },

str7 = { cpus = { ‘STR711FR2‘ }, arch = ‘arm‘ },

stm32f2 = { cpus = { ‘STM32F205RF‘ }, arch = ‘cortexm‘ },

stm32 = { cpus = { ‘STM32F103ZE‘, ‘STM32F103RE‘ }, arch = ‘cortexm‘},

stm32f4 = { cpus = { ‘STM32F401RE‘,‘STM32F407VG‘, ‘STM32F407ZG‘ }, arch = ‘cortexm‘ },

avr32 = { cpus = { ‘AT32UC3A0128‘, ‘AT32UC3A0256‘, ‘AT32UC3A0512‘,‘AT32UC3B0256‘ }, arch = ‘avr32‘ },

lpc24xx = { cpus = { ‘LPC2468‘ }, arch = ‘arm‘ },

lpc17xx = { cpus = { ‘LPC1768‘ }, arch = ‘cortexm‘ }

}

如果你不作porting,那么cpu为以上其中一个。(porting详见elua/doc/en/arch_newport.txt

[[config_components]]

涉及文件系统(romfswofs,mmcfs,rfsshell,adnvance_shell(sercon,xmoden,term),中断(luaints,cints,dns,dhcp,tcpip,rpc等参数配置

详见elua/Doc/En/configurator.txt

[[config_config]]

The *config* section containsvarious build time configuration data.

虚拟时钟vtmr,垃圾收集egc,内存大小起始地址ram,系统时钟clock

[[config_modules]]

The configurator has supportfor fine-grained selections of the Lua modules that are going to bepart of the eLua firmware.

The module chooser knows how todifferentiate between 3 categories of modules:

1. *Lua modules*: the standardLua modules that are compiled in eLua (_mlmath, _mlio, _mlstring,_mltable, _mldebug, _mlpackage, _mlco). These can be referenced as agroup under the name *all_lua*.

2. *Generic eLua modules*:these are _madc, _mbit, _mcan, _mcpu, _melua, _mi2c, _mpack, _mrpc,_mnet, _mpd, _mpio, _mpwm, _mspi, _mterm, _mtmr, _muart. These can bereferenced as a group under the name *all_elua*.

3. *Platform specific eLuamodules*: these are added by each platform as needed.

* ifused in *generic*, *all* is equivalent with *all_lua* + *all_elua*(all the standard Lua modules and the generic eLua modules)

* if used in *platform*, *all*is a list of all the platform specific modules.

A module name can be prefixedwith a dash (*-*) if thatmodule must be _excluded_ from the image instead of being included.Generally, this makes sense only when a group name (*all*, *all_lua*or*all_elua*) is also used in the list of modules.

注意:allall_luaall_elua,"-i2c"表示不包括I2c组件


[[config_headers]]

the configurator compiles theLua board description file into a C header file (*board_<board>.h*)that is later used to compile the eLua firmware. If additionalheaders must be included in the generated header file, they can bespecified in the *headers* section:

headers = { "specific1.h","specific2.h" }

[[config_macros]]

Besides the macros generated bythe configurator, it is sometimes useful to add other macros to the*board_<board>.h* file. These can be specified in the *macros*section. If present, *macros* must be a table with two kinds of keys:

* strings: these define simplemacros (macros without a value)

* arrays with two entries:these define macros with values.

For example, this definition:

[source, lua]

macros = { ‘MACRO1‘, {‘MACRO2‘, 0 } }

[source, c]

#define MACRO1

#define MACRO2 0

定制编译属性时,一般不修改/known目录下的文件,而是采用在/custom目录下添加文件。注意文件名要与对应的平台相同,例如custom/stm32f4discovery.lua

[source,lua]


-- Fileboards/custom/stm32f4discovery .lua

local t =dofile( "boards/known/stm32f4discovery .lua" )

t.components.wofs=true

return t

例如:增加wofs文件系统的支持,(stm32f4discovery平台默认只支持romfs文件系统,只读,不能动态添加文件,限制lua的应用,advanced_shell中的recv命令也不能用,所以添加可读写的文件系统wofs)



[[buildoptions]]

参考elua/Doc/En/Building.txt

luabuild_elua.lua[board=<boardname>](支持的平台详见boards/known文件夹)

[target=lua | lualong | lualonglong]

[allocator=newlib | multiple | simple]

[toolchain=<toolchain name>]

[optram=true | false]

[boot=standard | luarpc]

[romfs=verbatim | compress | compile]

[cpumode=arm | thumb]

[bootloader=none | emblod]

[output_dir=<directory>]

[romfs_dir=<directory>]

[board_config_file=<file>]

[skip_conf=true | false]

[config_only=true | false]

[build_mode=keep_dir | build_dir_linearized]

[build_dir=<directory>]

[disp_mode=all | summary | minimal]

[-E | -S]

[-h]

[prog]


target=lua| lualong | lualonglong: specify if you want to build"regular" Lua (with floating point support). 32 bit integeronly Lua (lualong) or 64 bit integer only Lua (lualonglong, startingwith version 0.9). The default is "lua". "lualong"and "lualonglong" run faster on targets that don’t have afloating point co-processor, but they completely lack support forfloating point operations, they can only handle integers. Also,"lualonglong" doesn’t support cross-compilation of Luasource files to bytecode

默认lua,为float类型,在stm32f4discovery平台下发现,如果编译选项为-mfloat-abi=softfp时,选择target=luaelua中的lua解释器无法正常工作,只能便以为lualong

optram=true| false: enables of disables the LTR patch, see the LTRdocumentation for more details. The default istrue, which enables the LTR patch. Keep LTR enabled unless you have avery good reason to do otherwise, eLua might notfunction properly with LTR disabled.


默认打开,目的是节约RAM,详见elua/doc/en/arch_ltr.html


prog:by default, the above build_eluacommand will build only the elf(executable) file. Specify "prog" to build also theplatform-specific programming file where appropriate (for example, ona AT91SAM7X256 this results in a .bin file that can be programmed inthe CPU).

生成bin文件


缺少参数:-c: clean target

其它参数详见http://www.eluaproject.net/doc/master/en_building.html


本文介绍了如何定制elua的编译选项,主要是configuratorbuildoptions两部分。下一篇文章讲解如何使用elua,主要讲解elua的链接和shell




elua学习(三)--定制elua的编译选项

标签:elua   stm32f4   嵌入式   lua   

原文地址:http://blog.csdn.net/coolwaterld/article/details/39049239

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!