研究了下flash.bin的生成的过程, 主要是会用到anchor, 整理了下, 备查.
下面是anchor的用法.
D:>anchor -h
anchor:
flash map generate tool
Synopsis:
anchor [option] [source] [target]
Usage:
Generate flash bin from configuration file
(1)anchor [-v] [src file] [target file]
:generate a flash bin with compile local time to the end of file(16bytes
,Y/M/D/H/M/S/MS)
(1)anchor [-l] [config file] [target file]
:generate a flash bin use nomarl type following the config file
(2)anchor [-m] [config file] [target file]
:generate a flash bin, all blocks with the fixed addr.
(3)anchor [-i] [target file] [src file] [dst address] [jump address]
:generate a img file. add a header with 3 u32
header format: [file size][0x81000000][0x81000000]
(4)anchor [-z] [target file] [padding size]
:pending 0xff in src file.
(5)anchor [-g] [target file] [src file]
:generate a img file. add a header with a u32
header format: [file size], L mode
(5)anchor [-s] [src file] [target file]
:generate a img file. add a header with a u32
header format: [file size], B mode
(7)anchor [-c] [src file] [custom file] [target file]
:update the last read only block. the block size should not changed
(8)anchor help
anchor [-h]
以-m为例,需要一个config文件,这个config文件需要符合一定的规则.
下面是config文件的例子.
先是uboot的例子:
生成uboot的命令 anchor.exe -m uboot.cfg u_boot.bin
下面是uboot.cfg
//Please follow these rules to modify block info:
//1. Each comment a line, start with "//", do not append comments at the end
//2. "size=" means the specified size, and it must do not less than actual size.
//3. "-----------" is meaningless, just to separate the block, clear to see
//4. use "dmhstart" is specified position.
//5. a new block must stop with name!
-------------------------
FLASH=256K
-------------------------
dmhstart=0x4
//size=0x1bf0
name=chip_ddr2_init.bin
-------------------------
dmhstart=0x1bf4
//size=0xA0000
name=u-boot.bin
-------------------------
接下来是生成flash.bin的例子,下面是flash.cfg:
//Please follow these rules to modify block info:
//1. start commments with "//" in a new line, do not append comments at the end
//2. the first 3 line should be: sdram size, flash size, bootloader file name
//3. a new block must start with "ID=", !!!IDs are defined in sys_define.h!!!
//4. name,version <= 8B, time<=12B, the overflow bytes will be discarded
//5. use "time=" to add block time, or the file time will be used automaticlly
//6. default: type=0. "type=0" means read only block,"type=1" means increasing write block.
//7. default: node=1. modify this field for IW block.
//8. "size=" only for IW block. for RO block, the file size will be got automaticlly
//9. "crc=0x4352434e" (NCRC)for NO CRC check block
//10. "-----------" is meaningless, just to separate the block, clear to see
//11. use "frontalign" if you want a block to start with flash 64K section align
//12. use "endalign" if you want a block to end with flash 64K section align
//13. use "SDRAM=xxM" "FLASH=xxM" to specify the sdram and flash size
//14. use "padding" to make the output file the same size as the FLASH size
SDRAM=8M
FLASH=4M
-------------------------
ID=0x80
name=bl
file=bootloader.bin //前一段是bootloader.bin
-------------------------
dmhstart=0x80000
padding=4M
---------------------------
ID=0x88
file=xxxx_lzma.img //后一段是这个img, 这个img从0x80000开始, 最后到4M为止都用FF填充
crc=0x4352434e
name=img
version=00000001
-------------------------
flash.cfg在下面这个shell脚本中被调用到
ANCHOR=../../../../../config_prj/other/anchor/bin/anchor.exe
ANCHOR2=../../../../../config_prj/other/anchor/bin/anchor.exe
ANCHOR3=../../../../../../config_prj/other/anchor/bin/anchor.exe
MKIMG=mkimg_mips
cd release
mv ../xxxx.map .
mipsel-linux-objcopy -O binary ${1} xxxx.bin //${1} is xxxx.elf
echo "xxxx.bin ok"
mipsel-linux-objdump -d ${1} > xxxx.s
$ANCHOR -i xxxx.img xxxx.bin 0x80008000 0x80008000
cp xxxx.bin xxxx.tmp
rm -f xxxx.tmp.lzma
lzma -z -k xxxx.tmp //压缩,原来的xxxx.tmp不删除,生成xxxx.tmp.lzma
rm -f xxxx.tmp
$MKIMG xxxx.tmp.lzma xxxx_lzma.img -g //-g是什么意思?
rm -f xxxx.tmp.lzma
rm -f xxxx_dl.img
$ANCHOR -g xxxx_dl.img xxxx_lzma.img //加一个文件大小的头
mv -f xxxx_lzma.img ../binary/
cd ../binary/ota_binary
$ANCHOR3 -m ./ota_flash.cfg ./../bootloader.bin //其实没变化,就是u_boot.bin
cd ../
echo "anchor flash.bin ............"
rm -f ../flash.bin
$ANCHOR2 -l ./flash.cfg ../release/flash.bin
rm -f ../flash_ddr2.bin
$ANCHOR2 -l ./flash_ddr2.cfg ../release/flash_ddr2.bin
echo "post build process completes"
shell脚本的参数是xxxx.elf, 就是那个${1}
sh ${PROJECT_DIR}post_build.sh xxxx.elf