请教各位大佬,Melis是如何将编译出来的 melis.elf app等文件打包进melis.img生产一个可以烧录的系统!
-
这次我们也设计了一个 板载CkLink的D1s RISC-V教育开发板,目的是为了用来学习RISC-V体系架构与编程,裸机开发,YoC RTOS系统(已支持helloword),RTT等系统。
这两天有看到RT-Smart支持了D1s的RTT系统,但是是基于SDCard或SD-Nand存储实现,因为我们的板子flash是NorFlash,所以想研究一下怎么在NorFlash运行。
编译RTT
- 参考 https://mp.weixin.qq.com/s/XznlHTqiTijgJ8uwPWXBBw
最后编译生成对应的sd.bin文件,可以直接烧录,但是我想烧录到NorFlash 要怎么做呢?
根据RISC-V的启动流程来看,opensbi-->u-boot-->rtt kernel -->app
因为存储介质的区别,我要确定烧录的地址,这里无从得知,
那面我需要获取到 前面 opensbi u-boot是从哪里来的,这个我一开始认为是全志提供,后来经过对比,发现并不是,询问RTT内部人员,他们也不知从何而来,这就比较尴尬,我只能除了IDA换个思路去解决。
分析Melis
- 全志有一款自家RTT系统,已经完整支持了D1s/F133,但是因为某些原因,无法对外公开,但是它却支持了NorFlash的系统,大家都知道Melis系统底层也是RTT的内核,所以我是不是可以把Melis里面的打包过程 单独领出来,去给 rt-smart支持,这样就能完美解决 不同flash支持的问题了。
分析1
- 每个芯片厂家都有自己的一套特定启动流程,烧录标准,以及打包的特定格式,所以简单的打包就是指定头部 指定分区文件,用特定的工具把一堆bin按照特定的要求生成一个img镜像格式,使用凤凰烧写工具烧写并启动。https://bbs.aw-ol.com/topic/1532/分析tina打包流程-并在buildroot上来实现打包生成tina镜像-支持phoenixsuit烧写?_=1668677556734
分析2
- 在D1s Melis系统里面 它的打包也是从 /D1s-Melis$ vim ./tools/scripts/pack_img.sh 开始入手
我们可以通过执行pack命令 来看 对应的过程。
INFO: running the function do_dragon with file "image_nor.cfg sys_partition_nor.fex" ==================================== show "sys_partition_nor.fex" message ------------------------------------ [mbr] mbr_size : 16 Kbyte ------------------------------------ partition_name : bootA partition_size : 2048 downloadfile : melis_pkg_nor.fex melis_pkg_nor.fex size : 608K byte ------------------------------------ partition_name : ROOTFS partition_size : 10240 downloadfile : data_udisk.fex data_udisk.fex size : 5.0M byte ------------------------------------ partition_name : UDISK ------------------------------------ /home/book/D1s-Melis/tools/packtool/ /home/book/D1s-Melis/out/d1s-nezha/image Begin Parse sys_partion.fex Add partion melis_pkg_nor.fex MELIS_PKG_NOR_FEX Add partion very melis_pkg_nor.fex MELIS_PKG_NOR_FEX FilePath: melis_pkg_nor.fex FileLength=98000Add partion data_udisk.fex DATA_UDISK_FEX00 Add partion very data_udisk.fex DATA_UDISK_FEX00 FilePath: data_udisk.fex FileLength=500000sys_config_nor.fex Len: 0x1132d config_nor.fex Len: 0xc000 split_xxxx.fex Len: 0x200 sys_partition_nor.fex Len: 0xc81 sunxi.fex Len: 0x12c00 boot0_nor.fex Len: 0xc000 boot0_card.fex Len: 0x10000 boot_pkg_uboot_nor.fex Len: 0x4c000 boot_pkg_uboot_nor.fex Len: 0x4c000 u-boot_nor.fex Len: 0x48000 fes1.fex Len: 0x7de0 usbtool.fex Len: 0x24400 usbtool_crash.fex Len: 0x1ec00 aultools.fex Len: 0x288b7 aultls32.fex Len: 0x2511f cardtool.fex Len: 0x11e00 cardscript.fex Len: 0x766 sunxi_gpt.fex Len: 0x2000 sunxi_mbr_nor.fex Len: 0x4000 dlinfo.fex Len: 0x4000 arisc.fex Len: 0xf melis_pkg_nor.fex Len: 0x98000 Vmelis_pkg_nor.fex Len: 0x4 data_udisk.fex Len: 0x500000 Vdata_udisk.fex Len: 0x4 BuildImg 0 Dragon execute image_nor.cfg SUCCESS ! -------------------- ----------image is at---------- /home/book/D1s-Melis/out/d1s-nezha/melis_d1s-nezha_uart0_8Mnor.img do_finish 100ask +++++++++++++ 3 INFO: pack finish
- 首先最后打包成一个完整可以烧录的镜像 没有变化 还是使用 dragon 根据分区配置文件统一生成。
do_finish 555 do_dragon image_$1.cfg sys_partition_$1.fex do_dragon() 602 dragon $@
- 继续倒着 往上看
INFO: packing for melis INFO: making data image for 8M nor INFO: running the function make_data_image for partition data [mbr] size = 16 [partition_start] [partition] name = bootA size = 2048 downloadfile = "melis_pkg_nor.fex" user_type = 0x8000 [partition] name = ROOTFS size = 10240 downloadfile = "data_udisk.fex" user_type = 0x8000 [partition] name = UDISK user_type = 0x8000 ROOTFS:5120:"data_udisk.fex" UDISK:1984:"None" =bootA:1024:"melis_pkg_nor.fex"= ROOTFS:5120:"data_udisk.fex" UDISK:1984:"None" =ROOTFS:5120:"data_udisk.fex"= data_udisk.fex try to create image: ROOTFS to data_udisk.fex with size 5242880 ------------------------------------------------------------- make minfs image file [/home/book/D1s-Melis/out/d1s-nezha/image/data_udisk.fex] succeeded image config size : [ 5242880] image used size : [ 4715036] DEntry count : [ 90] DEntry length : [ 13148] FData length : [ 4701212] ------------------------------------------------------------- /home/book/D1s-Melis/projects/d1s-nezha/data/UDISK data_udisk.fex make_data_image 100ask +++++++++++++++++++++ bootA:1024:"melis_pkg_nor.fex" ROOTFS:5120:"data_udisk.fex" UDISK:1984:"None" =UDISK:1984:"None"= INFO: running the function do_finish "sys_partition_nor.bin" partitation file Path=/home/book/D1s-Melis/out/d1s-nezha/image/sys_partition_nor.bin mbr_name file Path=/home/book/D1s-Melis/out/d1s-nezha/image/sunxi_mbr_nor.fex download_name file Path=/home/book/D1s-Melis/out/d1s-nezha/image/dlinfo.fex this is not a partition key gpt_head->header_crc32 = 0x8c195ae6 GPT----part num 3--- gpt_entry: 128 gpt_header: 92 GPT:bootA : 20 81f GPT:ROOTFS : 820 301f GPT:UDISK : 3020 302f update gpt file ok update mbr file ok WARN: 2021-01-19 do not create full binary because new uboot INFO: running the function create_rtos_full_img for pure binary imagefile 3968 8 ----------------mbr convert to gpt start--------------------- out: sunxi_gpt_nor.fex source: sunxi_mbr_nor.fex input_logic_offset: 96 input_flash_size: 8M gpt partition entry crc32 = 0x25cd3a50 gpt header crc32 = 0xb8d9d416 GPT----part num 3--- gpt_entry: 128 gpt_header: 92 GPT:bootA : 20 81f GPT:ROOTFS : 820 301f GPT:UDISK : 3020 3f9f update gpt file ok ----------------mbr convert to gpt end--------------------- boot0: boot0_nor.fex mbr: sunxi_gpt_nor.fex partition: sys_partition_nor.bin UDISK_partition_size: 3968 sector outfile: melis_8Mnor.fex logic_start: 48K total_image_size: 8M load file: boot0_nor.fex ok load file: sunxi_gpt_nor.fex ok load file: sys_partition_nor.bin ok part name=bootA file name:melis_pkg_nor.fex part size:2048 sector load file: melis_pkg_nor.fex ok part name=ROOTFS file name:data_udisk.fex part size:10240 sector load file: data_udisk.fex ok part name=UDISK this is not a partition key merge_package ok ----------rtos full image is at---------- /home/book/D1s-Melis/out/d1s-nezha/melis_8Mnor.fex
这部分是最终生成的包含Melis系统镜像的命令,实际的程序在
do_finish 522 if [ $1 = "nor" ] ; then 523 update_mbr sys_partition_$1.bin 1 sunxi_mbr_$1.fex 541 if [ "x$1" = "xnor" ] ; then 542 if [ ${current_rtos_full_img_size} -eq 8 ]; then 543 pack_warn "2021-01-19 do not create full binary because new uboot";create_rtos_full_img ${LOGICAL_UDISK_PARTS_KB_REMAIN_FOR_8M} ${current_rtos_full_img_size} prepare_for_8Mnor 880 pack_info "making data image for 8M nor" 881 make_data_image sys_partition_nor.fex ${LOGICAL_PARTS_KB_FOR_8M} LOGICAL_UDISK_PARTS_KB_REMAIN_FOR_8M 882 sed -i 's/\(imagename = .*\)_[^_]*nor/\1_8Mnor/g' image_nor.cfg 883 IMG_NAME=$(awk '{if($3~/^'${PACK_PLATFORM}'.*img$/)print$3}' image_nor.cfg) 884 current_rtos_full_img_size=8 create_rtos_full_img 839 echo ----------------mbr convert to gpt start--------------------- 840 mbr_convert_to_gpt --source ${mbr_source_file} \ 841 ¦ ¦ --out ${gpt_file} \ 842 ¦ ¦ --input_logic_offset $((${LOGIC_START} * 1024 / 512 )) \ 843 ¦ ¦ --input_flash_size ${2} 844 echo ----------------mbr convert to gpt end--------------------- 846 cp ${gpt_file} sunxi_gpt.fex 847 848 cp ${boot0_file_name} boot0.fex 853 merge_full_rtos_img --out ${full_rtos_img_name} \ 854 ¦ ¦ ¦ --boot0 ${boot0_file_name} \ 855 ¦ ¦ ¦ --mbr ${gpt_file} \ 856 ¦ ¦ ¦ --logic_start ${LOGIC_START} \ 857 ¦ ¦ ¦ --partition sys_partition_nor.bin \ 858 ¦ ¦ ¦ --UDISK_partition_size ${1} \ 859 ¦ ¦ ¦ --total_image_size ${2}
从上面可以看出来是根据 我们指定的 分区文件 来最终生成一个 包含完整系统镜像的这么一个系统。
但是只有这些还是不够,我要知道 Melis.elf到底是包含在了哪里。
我们看一下这个分区定义,整个打包操作步骤是没有变化,还是更新头部,转换fex为bin格式,然后使用 特定的命令进行完整打包
D1s-Melis/projects/d1s-nezha/configs$ cat sys_partition_nor.fex
从上图可以看到,他的分区只有3个,首先排除最后一个分区UDISK,是一个没有文件的空分区,然后 就是ROOTFS分区和 bootA分区了,然后根据 downloadfile名称来看,更像是bootA分区里面存放了melis.elf文件。
但是这个我没法解包,也无从得知是哪里得到,无果,继续往上看- 打包过程分析
book@virtual-machine:~/D1s-Melis$ pack INFO: temporarily Enter pack directory: "/home/book/D1s-Melis/out/d1s-nezha/image", will be back when terminated INFO: copying config/boot binary/phoenix plugin files /home/book/D1s-Melis/tools/phoenixplugin/aultls32.fex /home/book/D1s-Melis/tools/phoenixplugin/aultools.fex /home/book/D1s-Melis/tools/phoenixplugin/cardtool.fex /home/book/D1s-Melis/tools/phoenixplugin/split_xxxx.fex /home/book/D1s-Melis/tools/phoenixplugin/Tools.fex /home/book/D1s-Melis/tools/phoenixplugin/usbtool_crash.fex /home/book/D1s-Melis/tools/phoenixplugin/usbtool.fex /home/book/D1s-Melis/tools/phoenixplugin/usbtool_test.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/arisc.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/cardscript.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/cardscript_product.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/config.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/split_xxxx.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sunxi.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_config_card.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_config_card_product.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_config.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_config_nand.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_config_nor.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_card_dump.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_card.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_card_product.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_nand_dump.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_nand.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_nor_dump.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/sys_partition_nor.fex /home/book/D1s-Melis/projects/d1s-nezha/configs/env.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/image_card.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/image_card_product.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/image_nand.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/image_nor.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/package_boot0.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/package_uboot_card.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/package_uboot_card_product.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/package_uboot_nand.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/package_uboot_nor.cfg /home/book/D1s-Melis/projects/d1s-nezha/configs/rootfs.ini /home/book/D1s-Melis/projects/d1s-nezha/version/version_base.mk /home/book/D1s-Melis/projects/d1s-nezha/bin/boot0_sun20iw1p1_nand.bin:boot0_nand.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/boot0_sun20iw1p1_nor.bin:boot0_nor.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/boot0_sun20iw1p1_card.bin:boot0_card.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/boot0_sun20iw1p1_card.bin:boot0_card_product.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/fes1_sun20iw1p1.bin:fes1.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/u-boot_sun20iw1p1_nand.bin:u-boot_nand.fex /home/book/D1s-Melis/projects/d1s-nezha/bin/u-boot_sun20iw1p1_nor_uart0.bin:u-boot_nor.fex /home/book/D1s-Melis/projects/d1s-nezha/epos.img:epos.img Compressed 1203760 bytes into 836271 bytes ==> 69.47% INFO: define image file name is:melis_d1s-nezha_uart0_nor.img pack boot nor package GetPrivateProfileSection read to end content_count=2 32+0 records in 32+0 records out 32768 bytes (33 kB, 32 KiB) copied, 0.000412117 s, 79.5 MB/s fes1 file Path=/home/book/D1s-Melis/out/d1s-nezha/image/fes1.fex script file Path=/home/book/D1s-Melis/out/d1s-nezha/image/sys_config_nor.bin script update fes1 ok uboot file Path=/home/book/D1s-Melis/out/d1s-nezha/image/u-boot_nor.fex script file Path=/home/book/D1s-Melis/out/d1s-nezha/image/sys_config_nor.bin debug_mode =1 secure_mode =0 GetPrivateProfileSection read to end content_count=1 toc1 file Path=/home/book/D1s-Melis/out/d1s-nezha/image/boot_package.fex script file Path=/home/book/D1s-Melis/out/d1s-nezha/image/sys_config_nor.bin cant get board_id_enable script update toc1 ok
最上面这部分来看,就是检查一下文件是否完整,然后指定头部等配置文件,将其转换成特定的格式并等待后续使用,这部分并没有特别有用信息。
相关操作都在do_common
待解决
那么问题来了,melis.elf到底包含在了那个 分区里面 是bootA还是ROOTFS,亦或者其它我不知道的,
具体单板工程下的 epos.img是做什么用的?
/D1s-Melis/projects/d1s-nezha/sbi-bin$ cat osinit 里面为什么指定了 melis30.elf文件,但是这个文件到底是何时被编译打包进去,前面为什么有target这个 gdb调试地址,是否是调试时才需要的。
另外但从启动信息看
第一部分首先是 boot0 也就是norflash ddr头部信息,然后是一个 所谓的复合bin里面应该包含了opensbi部分 melis kernel本身,可能还有uboot部分和env启动参数部分。
后面就是加载melis kernel的log日志信息了,请有知道的大佬提点一二!!!后面我尝试从 烧录 编译好的Melis系统镜像打印信息来分析 烧录过程,看是否可以反推出对应位置等。
- 参考 https://mp.weixin.qq.com/s/XznlHTqiTijgJ8uwPWXBBw
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号