Compiling u boot generates many images: u-boot.img u boot.bin u boot_crc.bin and u boot_crc.bin.crc. What are the differences and connections between these image files? We will do the following detailed analysis:
1. u-boot.bin
It is the original image file generated by u-boot compilation, and many image files need to be generated on it.
2. u-boot.img
It's a Header with a length of 0x40 Byte added to u-boot.bin. It contains important information such as loading address, running address, CRC and so on, which is used to identify its loader.
u-boot.img contains u-boot.bin along with an additional header to be used by the boot ROM to determine how and where to load and execute U-Boot.
Ultimately, u-boot.img will use mkimage to generate u-boot.bin into u-boot.img.
$(obj)u-boot.img: $(obj)u-boot.bin
./tools/mkimage -A $(ARCH) -T firmware -C none \
-a $(TEXT_BASE) -e 0 \
-n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
sed -e 's/"[ ]*$$/ for $(BOARD) board"/') \
-d $< $@
Let's study the use of mkimge:
mkimage It's when making mirror files, in the original image Add a 0 before the file x40 The head of byte length, with the additional head structure described below
/*
* Legacy format image header,
* all data in network byte order (aka natural aka bigendian).
*/
typedef struct image_header {
uint32_t ih_magic; /* Image Header Magic Number */
uint32_t ih_hcrc; /* Image Header CRC Checksum */
uint32_t ih_time; /* Image Creation Timestamp */
uint32_t ih_size; /* Image Data Size */
uint32_t ih_load; /* Data Load Address */
uint32_t ih_ep; /* Entry Point Address */
uint32_t ih_dcrc; /* Image Data CRC Checksum */
uint8_t ih_os; /* Operating System */
uint8_t ih_arch; /* CPU architecture */
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN]; /* Image Name */
} image_header_t;
Image Name It takes 32 bytes, and other information takes 32 bytes.
mkimage Usage:
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
-A Set the schema type and refer to the values available uboot/common/image.c
-O Set the operating system type, refer to the values available uboot/common/image.c
-T image Type, Value Reference uboot/common/image.c
-a Appoint image Load Address in Memory
-e Appoint image Running entry point address
-C Specify compression mode, compression mode reference uboot/common/image.c
-d data_file[:data_file…] Make image Source file
//Example
$MKIMAGE_TOOL -A arm -O linux -T kernel -C none -a 0x90008000 -e 0x90008000 -n "Android Linux Kernel" -d ./zImage ./uImage
3. u-boot_crc.bin
u-boot_crc.bin is a fixed-length image of u-boot.bin.
Let's look at its implementation form:
u-boot_crc.bin: u-boot.bin
@cp tools/mk_uboot_crc .
@./mk_uboot_crc
@crc32 ./u-boot_crc.bin > ./u-boot_crc.bin.crc
@rm -f ./mk_uboot_crc
Mk_uboot_crc is implemented in / tools / mk_uboot_crc.c.
#define IMG_SZ 614400
int main(void)
{
struct stat buf;
unsigned char binary[IMG_SZ];
int fd;
memset(binary, 0, IMG_SZ);
if(stat("./u-boot.bin", &buf) != 0)
return -1;
//printf("File size %d\n", buf.st_size);
fd = open("./u-boot.bin", O_RDWR);
if(fd < 0)
{
printf("Open u-boot.bin file fail %d\n", fd);
return -1;
}
read(fd, binary, buf.st_size);
close(fd);
fd = open("./u-boot_crc.bin", O_RDWR | O_CREAT, S_IRWXU);
if(fd < 0)
{
printf("Open file fail %d\n", fd);
return -1;
}
write(fd, binary, IMG_SZ);
//printf("padding done\n");
return 0;
}
4. uboot_crc.bin.crc
This file stores the CRC32 results of uboot_crc.bin.
The makefile implementation in 3 can be seen.
@crc32 ./u-boot_crc.bin > ./u-boot_crc.bin.crc