U-Boot allows to store commands or command sequences in a plain text file. Using the mkimage tool you can then convert this file into a script image which can be executed using U-Boot's autoscr command.
U_BOOT_CMD(
autoscr, 2, 0,do_autoscript,
"run script from memory",
"[addr] - run script starting at addr"
" - A valid autoscr header must be present\n"
);
uboot/common/cmd_autoscript.c下的int autoscript (ulong addr, const char *fit_uname)中genimg_get_format会去检查文件头是否存在和正确。
/*
* Legacy format image header,
* all data in network byte order (aka natural aka bigendian).
*/
typedef struct image_header {
uint32_tih_magic;/* Image Header Magic Number*/
uint32_tih_hcrc;/* Image Header CRC Checksum*/
uint32_tih_time;/* Image Creation Timestamp*/
uint32_tih_size;/* Image Data Size*/
uint32_tih_load;/* DataLoad Address*/
uint32_tih_ep;/* Entry Point Address*/
uint32_tih_dcrc;/* Image Data CRC Checksum*/
uint8_tih_os;/* Operating System*/
uint8_tih_arch;/* CPU architecture*/
uint8_tih_type;/* Image Type*/
uint8_tih_comp;/* Compression Type*/
uint8_tih_name[IH_NMLEN];/* Image Name*/
} image_header_t;
$ mkimage
Usage: mkimage -l image
-l ==> list image header information
mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
mkimage [-D dtc_options] -f fit-image.its fit-image
用法举例:
$ mkimage -A arm -O linux -T script -C none -n 'Demo Script File' -d MyText setenv.img
Image Name: Demo Script File
Created: Tue Sep 18 11:23:02 2012
Image Type: ARM Linux Script (uncompressed)
Data Size: 77 Bytes = 0.08 kB = 0.00 MB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 69 Bytes = 0.07 kB = 0.00 MB
查看刚才生成的setenv.img文件的文件头:
$ mkimage -l setenv.img
Image Name: Demo Script File
Created: Tue Sep 18 11:23:02 2012
Image Type: ARM Linux Script (uncompressed)
Data Size: 77 Bytes = 0.08 kB = 0.00 MB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 69 Bytes = 0.07 kB = 0.00 MB
牵涉到的几个源文件:
uboot/common/image.c
uboot/tools/mkimage.c