TT扩展件microPython实现.1,这个是上篇,下面是下篇
GCC的目录,只为ESP芯片编译
代码语言:javascript复制C:Program Files (x86)Mind Arduinohardwaretoolsmpythonxtensa-esp32-elf
bin
xtensa-esp32-elf-gcc
-nostdlib
-L
后两个是参数
-nostdlib作用:不连接系统标准启动文件和标准库文件,只把指定的文件传递给连接器。这个选项常用于编译内核、bootloader等程序,它们不需要启动文件、标准库文件。
代码语言:javascript复制https://blog.csdn.net/weibo1230123/article/details/82817006
代码语言:javascript复制https://www.cnblogs.com/benio/archive/2010/10/25/1860394.html
代码语言:javascript复制C:Program Files (x86)Mind Arduinohardwaredfrobotmpython
toolssdklib -L
-l参数就是用来指定程序要链接的库,-l参数紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so去掉就是库名了
好了现在我们知道怎么得到库名,当我们自已要用到一个第三方提供的库名字libtest.so,那么我们只要把libtest.so拷贝到/usr/lib里,编译时加上-ltest参数,我们就能用上libtest.so库了(当然要用libtest.so库里的函数,我们还需要与libtest.so配套的头文件)
放在/lib和/usr/lib和/usr/local/lib里的库直接用-l参数就能链接了,但如果库文件没放在这三个目录里,而是放在其他目录里,这时我们只用-l参数的话,链接还是会出错,出错信息大概是:“/usr/bin/ld: cannot find -lxxx”,也就是链接程序ld在那3个目录里找不到libxxx.so,这时另外一个参数-L就派上用场了,比如常用的X11的库,它在/usr/X11R6/lib目录下,我们编译时就要用-L/usr/X11R6/lib -lX11参数,-L参数跟着的是库文件所在的目录名。再比如我们把libtest.so放在/aaa/bbb/ccc目录下,那链接参数就是-L/aaa/bbb/ccc -ltest
代码语言:javascript复制C:Program Files (x86)Mind Arduinohardwaredfrobotmpythontoolssdkld
-T esp32_out.ld
-T esp32.common.ld
-T esp32.rom.ld
-T esp32.peripherals.ld
-T esp32.rom.libgcc.ld
-T esp32.rom.spiram_incompatible_fns.ld
-u ld_include_panic_highint_hdl
-u call_user_start_cpu0
-Wl,
--gc-sections -Wl
,-static -Wl,
--undefined=uxTopUsedPriority
-u __cxa_guard_dummy
-u __cxx_fatal_exception
-Wl,
--start-group
-Wl,-Bstatic &-Wl,-Bdynamic参数说明
默认情况下,GCC/G 链接时优先链接动态库,如果没有动态库,则链接相应的静态库。同时,GCC/G 也提供了链接选项 -Wl,-Bstatic 和 -Wl,-Bdynamic 供用户指定链接动态库或者静态库。
-Wl,-Bstatic指示跟在后面的-lxxx选项链接的都是静态库 -Wl,-Bdynamic指示跟在后面的-lxxx选项链接的都是动态库。
代码语言:javascript复制1
前面的 -Wl,-Bstatic指示链接libtest.a静态库,后面的 -Wl,-Bdynamic指示链接系统动态库。
选项 | 说明 |
---|---|
-shared | 产生共享对象 |
-static | 使用静态链接,默认是动态链接 |
-e xx | 指定xx 为程序的入口函数 |
-fpic | 产生地址无关代码,较小且较快,但某些平台会有限制符号数量和代码长度, |
-fPIC | 产生地址无关代码,没有限制。一般用这个 |
-no-builtin | GCC编译器提供了很多内置函数(Built-in function),会把常用的C库函数替换成编译的内置函数,以优化功能,这个选项就是关闭内置函数功能,不要被其优化 |
在开发一个项目时,使用了非常多的第三方.a静态库文件,导致编译出的可执行文件非常大。这样一是占用ROM空间,二是会导致程序启动加载速度变慢(项目对启动时间非常敏感)。其实,这些静态库中的函数,并非所有都有调用,项目只使用了其中小部分。这种情况下,gcc的“-Wl,–gc-sections”参数,就非常有用。 补充说明:想要达到生成最终可执行文件,只链接.a库中用到的函数,需要在编译生成.a库时,就带有-ffunction-sections参数。
代码语言:javascript复制https://blog.csdn.net/wuu19/article/details/100725025
--gc-sections -Wl参数说明
英文原版的-Wl,–gc-sections解释说明如下:
代码语言:javascript复制6.3.3.2 Compilation options The operation of eliminating the unused code and data from the final executable is directly performed by the linker. In order to do this, it has to work with objects compiled with the following options: -ffunction-sections -fdata-sections. These options are usable with C and Ada files. They will place respectively each function or data in a separate section in the resulting object file. Once the objects and static libraries are created with these options, the linker can perform the dead code elimination. You can do this by setting the -Wl,–gc-sections option to gcc command or in the -largs section of gnatmake. This will perform a garbage collection of code and data never referenced. If the linker performs a partial link (-r linker option), then you will need to provide the entry point using the -e / --entry linker option. Note that objects compiled without the -ffunction-sections and -fdata-sections options can still be linked with the executable. However, no dead code elimination will be performed on those objects (they will be linked as is). The GNAT static library is now compiled with -ffunction-sections and -fdata-sections on some platforms. This allows you to eliminate the unused code and data of the GNAT library from your executable.
https://gcc.gnu.org/onlinedocs/gnat_ugn/Compilation-options.html
大致说明如下:
- 在编译C、Ada源文件(C 也可以),在gcc/g 编译选项中增加
-ffunction-sections
、-fdata-sections
,在编译生成的.o目标文件中,会将每个函数或数据段,放在各种单独独立的section
中; - 在链接生成最终可执行文件时,如果带有
-Wl,--gc-sections
参数,并且之前编译目标文件时带有-ffunction-sections
、-fdata-sections
参数,则链接器ld不会链接未使用的函数,从而减小可执行文件大小; - 如果使用了
-r
的链接参数,来产生重定位的输出,需要显示的调用-e
参数来指定程序入口。否则-Wl,--gc-sections
不会生效。
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32drone.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_fonts.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_gamesirt1d.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_libs.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_matrix.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_matrixeffect.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_protocol.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_rgb.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_rgbeffect.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_shell.cpp.o
c:program files (x86)mind arduinostaticlibrariesrmtt_libstelloesp32rmtt_tof.cpp.o
这些是TT的编译库
代码语言:javascript复制c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32ble2902.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32ble2904.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleaddress.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleadvertiseddevice.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleadvertising.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blebeacon.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blecharacteristic.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blecharacteristicmap.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleclient.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bledescriptor.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bledescriptormap.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bledevice.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleeddystonetlm.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleeddystoneurl.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleexceptions.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blehiddevice.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleremotecharacteristic.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleremotedescriptor.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleremoteservice.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blescan.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blesecurity.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleserver.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleservice.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleservicemap.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleuuid.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32bleutils.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32blevalue.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32freertos.cpp.o
c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrariesbletelloesp32generalutils.cpp.o
代码语言:javascript复制c:program files (x86)mind arduinostatichardwaredfrobotmpythonlibrarieswiretelloesp32wire.cpp.o
我觉得是从这个库里面
这么大,我觉得是抽取以下的库编译到固件里面.只是猜想
这个core文件还是分布在各个地方的.还是不清楚作用
代码语言:javascript复制-lgcc
-lopenssl
-lbtdm_app
-lfatfs
-lwps
-lcoexist
-lwear_levelling
-lesp_http_client
-lprotobuf
-c
-lhal
-lnewlib
-ldriver
-lbootloader_support
-lpp
-lfreemodbus
-lmesh
-lsmartconfig
-ljsmn
-lwpa
-lethernet
-lphy
-lapp_trace
-lconsole
-lulp
-lwpa_supplicant
-lfreertos
-lbt
-lmicro-ecc
-lesp32-camera
-lcxx
-lxtensa
-debug-module
-ltcp_transport
-lmdns
-lvfs
-lesp_ringbuf
-lsoc
-lcore
-lfb_gfx
-lsdmmc
-llibsodium
-lcoap
-ltcpip_adapter
-lprotocomm
-lesp_event
-limage_util
-lc_nano
-lesp-tls
-lasio
-lrtc
-lspi_flash
-lwpa2
-lwifi_provisioning
-lesp32
-lface_recognition
-lapp_update
-lnghttp
-lspiffs
-lface_detection
-lespnow
-lnvs_flash
-lesp_adc_cal
-llog
-ldl_lib
-lsmartconfig_ack
-lexpat
-lm
-lfr
-lmqtt
-lc
-lheap
-lmbedtls
-llwip
-lnet80211
-lesp_http_server
-lpthread
-ljson
-lesp_https_ota
-lfd
-lstdc
-Wl,
--end-group
-Wl,
-EL
-o
这个地方是编译加入的库一览
GNU链接器几个开关项的解释:-lm -lc -lgcc
-lm 代表链接器将连接GCC的数学库libm.a -lc 代表链接器将连接GCC的标准C库libc.a -lgcc 代表链接器将连接GCC的支持库libgcc.a 在连接时,这些库的排列顺序一般为: -lm -lc -lgcc
代码语言:javascript复制https://blog.csdn.net/cos_sin_tan/article/details/8423397
–start-group archives --end-group
The archives should be a list of archive files. They may be either explicit file names, or `-l’ options. The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives.
正常情况,链接的时候库文件只会按它们出现在命令行的顺序搜索一遍,如果包里有未定义的引用标号,而且该包还被放在命令行的后面,这样链接器就无法解决该标号的引用问题。通过给包分组,这些包可以被循环搜索直到所有的引用都可以解决为止。使用该选项将降低性能。只有在无法避免多个包之间互相引用的情况下才使用。用法示例:
代码语言:javascript复制cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@
-T $(vmlinux-lds) $(vmlinux-init)
--start-group $(vmlinux-main) --end-group
$(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o FORCE ,$^
在已经编译的文件里面确实是这样的,就是有的参数是重复出现的,不知道怎么办,就是不知道gcc是怎么处理这个参数重复的
是一个内存的布局文件
代码语言:javascript复制esptool.py"
--chip esp32 elf2image
--flash_mode "dio"
--flash_freq "80m"
--flash_size "2MB"
-o
这个是上传工具的参数,可以看到频率是80Mhz
flash是2MB
还有一个参数,我需要自己查文档
代码语言:javascript复制项目使用了223976字节,占用了(17%)程序存储空间,余留1086744字节,最大为1310720字节。
全局变量使用了16388字节,(6%)的动态内存,余留278524字节局部变量,最大为294912字节。
可以输出空间情况
代码语言:javascript复制esptool.py
--chip esp32
--port COM8
--baud 921600
read_flash 0x400000 4
真正的上传参数
代码语言:javascript复制esptool.py v2.3.1
Connecting.......
Chip is ESP32D2WDQ5 (revision 1)
Features: WiFi, BT, Dual Core, Embedded Flash, VRef calibration in efuse
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
这个是正在的刷写log
代码语言:javascript复制Read 4 bytes at 0x400000 in 0.0 seconds (2.6 kbit/s)...
Hard resetting via RTS pin...
4 (100 %)
4%,中断一下.继续上传
代码语言:javascript复制C:Program Files (x86)Mind python36python
C:Program Files (x86)Mind Arduinohardwaretoolsmpython
esptool.py --chip esp32
--port COM8 --baud 921600
--before default_reset
--after hard_reset write_flash -z
--flash_mode dio
--flash_freq 80m
--flash_size detect 0xe000
C:Program Files (x86)Mind Arduinofwtelloesp32boot_app0.bin 0x1000
C:Program Files (x86)Mind Arduinofwtelloesp32bootloader_dio_40m.bin 0x10000
C:UsersyunswjAppDataLocalDFScratchbuilddfrobot.ino.bin 0x8000
C:UsersyunswjAppDataLocalDFScratchbuilddfrobot.ino.partitions.bin 0x150000
C:Program Files (x86)Mind Arduinofwtelloesp32spiffs.bin
接着又开始刷写
后面跟着5个bin文件
代码语言:javascript复制esptool.py v2.3.1
Connecting....
Chip is ESP32D2WDQ5 (revision 1)
Features: WiFi, BT, Dual Core, Embedded Flash, VRef calibration in efuse
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 2MB
esptool.py v2.3.1
正在连接...。
芯片是ESP32D2WDQ5(版本1)
功能:WiFi,BT,双核,嵌入式闪存,易用的VRef校准
上载存根...
正在运行存根...
存根正在运行...
将波特率更改为921600
变了
配置闪光灯大小...
自动检测到的闪存大小:2MB
又开始调用了
代码语言:javascript复制Writing at 0x00000000... (2 %)
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.2s
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 8158.8 kbit/s)...
Hash of data verified.
Flash params set to 0x021f
Compressed 15872 bytes to 10320...
Writing at 0x00001000... (100 %)
Wrote 15872 bytes (10320 compressed) at 0x00001000 in 0.1 seconds (effective 925.0 kbit/s)...
Hash of data verified.
Compressed 224144 bytes to 108799...
写在0x00000000 ...(2%)
正在擦除闪光灯(这可能需要一段时间)...
芯片擦除在4.2秒内成功完成
压缩8192字节为47 ...
写在0x0000e000 ...(100%)
在0.0秒内以0x0000e000(有效8158.8 kbit / s)写入8192字节(压缩47)。
验证数据的哈希值。
Flash参数设置为0x021f
将15872字节压缩到10320 ...
写在0x00001000 ...(100%)
在0.1秒(有效925.0 kbit / s)中以0x00001000写入15872字节(压缩的20320)...
验证数据的哈希值。
压缩224144字节为108799 ...
又一段log
代码语言:javascript复制
Writing at 0x00010000... (14 %)
Writing at 0x00014000... (28 %)
Writing at 0x00018000... (42 %)
Writing at 0x0001c000... (57 %)
Writing at 0x00020000... (71 %)
Writing at 0x00024000... (85 %)
Writing at 0x00028000... (100 %)
Wrote 224144 bytes (108799 compressed) at 0x00010000 in 1.7 seconds (effective 1041.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 118...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (118 compressed) at 0x00008000 in 0.0 seconds (effective 2731.9 kbit/s)...
Hash of data verified.
Compressed 720896 bytes to 1330...
Writing at 0x00150000... (100 %)
Wrote 720896 bytes (1330 compressed) at 0x00150000 in 0.0 seconds (effective 262322.2 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
最后一段日志,上传成功