Use Autoscript in U-Boot

本文详细介绍了如何使用U-Boot的mkimage工具将脚本转换为可执行的脚本图像,并通过autoscr命令执行这些脚本。包括mkimage的用法示例、生成的setenv.img文件文件头解析、以及涉及的关键源文件介绍。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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




U-Boot Scripting Capabilities


U-Boot images


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值