§2023-10-03
¶ mkimage
The mkimage command is used to create images for use with the U-Boot boot loader. Thes eimages can contain the linux kernel, device tree blob, root file system image, firmware images etc., either separate or combined.
¶1. emerge -av u-boot-tools
(chroot) hc4Gentoo /boot # emerge -av u-boot-tools
* IMPORTANT: 11 news items need reading for repository 'gentoo'.
* Use eselect news read to view new items.
These are the packages that would be merged, in order:
Calculating dependencies... done!
Dependency resolution took 5.96 s.
[ebuild N ] dev-lang/swig-4.1.1-r1::gentoo USE="pcre -ccache -doc -test" 8400 KiB
[ebuild N ] dev-embedded/u-boot-tools-2023.01::gentoo USE="-envtools" 18126 KiB
Total: 2 packages (2 new), Size of downloads: 26525 KiB
Would you like to merge these packages? [Yes/No] yes
>>> Verifying ebuild manifests
>>> Emerging (1 of 2) dev-lang/swig-4.1.1-r1::gentoo
* Fetching files in the background.
* To view fetch progress, run in another terminal:
* tail -f /var/log/emerge-fetch.log
....
--- /usr/bin/
>>> /usr/bin/fw_printenv
>>> /usr/bin/dumpimage
>>> /usr/bin/img2srec
>>> /usr/bin/bmp_logo
>>> /usr/bin/gen_eth_addr
>>> /usr/bin/mkenvimage
>>> /usr/bin/fw_setenv -> fw_printenv
>>> /usr/bin/fdtgrep
>>> /usr/bin/mkimage
¶ 2. `mkimage1
(chroot) hc4Gentoo /boot # pwd
/boot
(chroot) hc4Gentoo /boot # mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 "Initramfs Image" -d initramfs-6.1.46-gentoo.img initramfs-6.1.46-gentoo.uimg
Image Name:
Created: Sun Aug 27 11:34:52 2023
Image Type: AArch64 Linux RAMDisk Image (uncompressed)
Data Size: 5770132 Bytes = 5634.89 KiB = 5.50 MiB
Load Address: 00000000
Entry Point: 00000000
(chroot) hc4Gentoo /boot # ls
'Initramfs Image' initramfs-6.1.46-gentoo.img
- orangepi5+ ubuntu 22.04
root@orangepi5plus:/boot# mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 -d initrd.img-5.10.110-rockchip-rk3588 uInitrd-5.10.110-rockchip-rk3588
Image Name:
Created: Sat Oct 7 15:48:57 2023
Image Type: AArch64 Linux RAMDisk Image (uncompressed)
Data Size: 20015902 Bytes = 19546.78 KiB = 19.09 MiB
Load Address: 00000000
Entry Point: 00000000
(chroot) orangepi5plus /boot # mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 -d initramfs-6.1.53-gentoo-r1.img uInitrd-6.1.53-gentoo-r1
Image Name:
Created: Sun Oct 8 00:33:49 2023
Image Type: AArch64 Linux RAMDisk Image (uncompressed)
Data Size: 12177947 Bytes = 11892.53 KiB = 11.61 MiB
Load Address: 00000000
Entry Point: 00000000
root@orangepi5plus:/boot# chmod a+x uInitrd-5.10.110-rockchip-rk3588
(chroot) orangepi5plus /boot # ls -l
total 279540
-rwxr-xr-x 1 root root 230456 Jun 1 04:07 boot.bmp
-rwxr-xr-x 1 root root 3339 Jun 1 04:05 boot.cmd
-rwxr-xr-x 1 root root 3411 Jun 1 04:15 boot.scr
-rwxr-xr-x 1 root root 219610 Jun 1 03:43 config-5.10.110-rockchip-rk3588
-rw-r--r-- 1 root root 281506 Oct 7 09:22 config-6.1.55-gentoo-dist
-rwxr-xr-x 1 root root 37714432 Oct 7 12:09 decompressed_kernel
drwxr-xr-x 3 root root 4096 Jun 1 04:06 dtb
drwxr-xr-x 3 root root 4096 Jun 1 04:06 dtb-5.10.110-rockchip-rk3588
drwxr-xr-x 3 root root 4096 Oct 7 09:20 dtbs
lrwxrwxrwx 1 root root 32 Oct 7 23:50 Image -> vmlinuz-5.10.110-rockchip-rk3588
-rw------- 1 root root 12177947 Oct 8 00:29 initramfs-6.1.53-gentoo-r1.img
-rw-r--r-- 1 root root 28914325 Oct 7 09:22 initramfs-6.1.55-gentoo-dist.img
-rwxr-xr-x 1 root root 20015902 Jun 1 04:16 initrd.img-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 1152056 Jun 1 04:07 logo.bmp
drwx------ 2 root root 16384 Oct 7 07:05 lost+found
-rwxr-xr-x 1 root root 226 Oct 7 23:52 orangepiEnv.txt
-rwxr-xr-x 1 root root 1542 Jun 1 04:13 orangepi_first_run.txt.template
-rwxr-xr-x 1 root root 7780782 Jun 1 03:43 System.map-5.10.110-rockchip-rk3588
-rw-r--r-- 1 root root 6986092 Oct 7 09:22 System.map-6.1.55-gentoo-dist
lrwxrwxrwx 1 root root 32 Oct 7 23:50 uInitrd -> uInitrd-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 20015966 Oct 7 07:48 uInitrd-5.10.110-rockchip-rk3588
-rw-r--r-- 1 root root 12178011 Oct 8 00:33 uInitrd-6.1.53-gentoo-r1
-rwxr-xr-x 1 root root 28914389 Oct 7 09:38 uInitrd-6.1.55-gentoo-dist
-rwxr-xr-x 1 root root 20015966 Jun 1 04:16 uInitrd.ori
-rwxr-xr-x 1 root root 34109952 Oct 7 11:46 vmlinuz-5.10.110-rockchip-rk3588
-rw-r--r-- 1 root root 31156736 Oct 7 23:31 vmlinuz-6.1.53-gentoo-dist
-rw-r--r-- 1 root root 12272594 Oct 7 09:22 vmlinuz-6.1.55-gentoo-dist
-rw-r--r-- 1 root root 12272594 Oct 7 12:03 vmlinuz-6.1.55-gentoo-dist.ori
[root@orgpi5Gentoo boot]# mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 -d initramfs-6.1.53-gentoo-r1-arm64.img initramfs-6.1.53-gentoo-r1-arm64.uimg
Image Name:
Created: Tue Oct 10 19:23:18 2023
Image Type: AArch64 Linux RAMDisk Image (uncompressed)
Data Size: 9639588 Bytes = 9413.66 KiB = 9.19 MiB
Load Address: 00000000
Entry Point: 00000000
[root@orgpi5Gentoo boot]# file initramfs-6.1.53-gentoo-r1-arm64.uimg
initramfs-6.1.53-gentoo-r1-arm64.uimg: u-boot legacy uImage, , Linux/ARM 64-bit, RAMDisk Image (Not compressed), 9639588 bytes, Tue Oct 10 11:23:18 2023, Load Address: 00000000, Entry Point: 00000000, Header CRC: 0XC0199261, Data CRC: 0X6916659A[root@orgpi5Gentoo boot]# mv initramfs-6.1.53-gentoo-r1-arm64.uimg initramfs-linux.img
[root@orgpi5Gentoo boot]# ls -l
total 97980
drwxr-xr-x 3 root root 4096 5月 25 13:40 dtbs
drwxr-xr-x 2 root root 4096 5月 9 09:30 extlinux
-rwxr-xr-x 1 root root 292864 5月 16 17:25 idbloader.img
-rwxr-xr-x 1 root root 27806208 10月 10 17:36 Image
-rwxr-xr-x 1 root root 34175488 5月 16 10:33 Image-orgpi5Gentoo-5.10.110
-rwxr-xr-x 1 root root 9639588 10月 10 18:56 initramfs-6.1.53-gentoo-r1-arm64.img
-rwxr-xr-x 1 root root 9639652 10月 10 19:23 initramfs-linux.img
-rwxr-xr-x 1 root root 7644276 10月 10 14:10 initramfs-linux-orgpi5Gentoo-5.10.110.img
-rwxr-xr-x 1 root root 1152056 5月 16 17:25 logo.bmp
-rwxr-xr-x 1 root root 4194304 5月 16 17:25 rkspi_loader.img
-rwxr-xr-x 1 root root 4371654 10月 10 17:36 System.map-6.1.53-gentoo-r1-arm64
-rwxr-xr-x 1 root root 1388032 5月 16 17:25 u-boot.itb
[root@orgpi5Gentoo boot]# blkid
/dev/nvme0n1p3: UUID="e54225a5-ca72-4c82-8dcd-fa37c8af0355" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="8d058135-7486-44cd-bc4a-830290f0bc36"
/dev/nvme0n1p1: UUID="EA72-56F2" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="Linux filesystem" PARTUUID="5c4af2be-2035-44af-8cb1-705f99752ecf"
/dev/nvme0n1p4: UUID="713f87ba-a4c7-49d3-b9e3-168b15e63663" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="c5f079f1-6ab9-4b2e-8a63-2f15d9691ec8"
/dev/nvme0n1p2: UUID="d96e5ecc-b7f3-4590-ace2-4a2fb26a2d15" TYPE="swap" PARTLABEL="Linux swap" PARTUUID="9fbb04ff-6645-4a9d-8cea-c0fe19eb49f6"
/dev/mtdblock0: PTUUID="a267dd49-0aae-40a3-8512-9f65341c8a27" PTTYPE="gpt"
/dev/zram0: LABEL="zram0" UUID="4f45f461-39f5-4b56-b19d-df727f900345" TYPE="swap"
[root@orgpi5Gentoo boot]# cd extlinux/
[root@orgpi5Gentoo extlinux]# ls
extlinux.conf
[root@orgpi5Gentoo extlinux]# cp extlinux.conf extlinux.conf.ori
[root@orgpi5Gentoo extlinux]# cat extlinux.conf.ori
LABEL Orange Pi
LINUX /Image
FDT /dtbs/rockchip/rk3588-orangepi-5-plus.dtb
APPEND initrd=/initramfs-linux.img console=ttyS2,1500000 root=PARTUUID=8d058135-7486-44cd-bc4a-830290f0bc36 rw rootwait audit=0 splash plymouth.ignore-serial-consoles loglevel=2 cma=128M
[root@orgpi5Gentoo extlinux]# nano extlinux.conf
[root@orgpi5Gentoo extlinux]# cat extlinux.conf
LABEL Orange Pi
LINUX /Image
FDT /dtbs/rockchip/rk3588-orangepi-5-plus.dtb
APPEND initrd=/initramfs-linux.img console=ttyS2,1500000 root=PARTUUID=c5f079f1-6ab9-4b2e-8a63-2f15d9691ec8 rw rootwait audit=0 splash plymouth.ignore-serial-consoles loglevel=2 cma=128M
¶Description
The mkimage command is used to create images for use with the U-Boot boot loader. Thes eimages can contain the linux kernel, device tree blob, root file system image, firmware images etc., either separate or combined.
mkimage supports two different formats:
- The old, legacy image format concatenates the individual parts (for example, kernel image, device tree blob and ramdisk image) and adds a 64 bytes header containing information about target architecture, operating system, image type, compression method, entry points, time stamp, checksums, etc.
- The new, FIT (Flattened Image Tree) format allows for more flexibility in handling images of various and also enhances integrity protection of images with stronger checksums.
For Example:
`mkimage -A arm64 -O linux -T ramdisk -C none -a 0x4080000 -e 0x1080000 -n "Initramfs Image" -d initramfs.img initramfs.img.uimg`
> -a 0, -e 0 for odroid
Options
List image information:
-l [uimage file name]
mkimage lists the information contained in the header of an existing U-Boot image.
Create old legacy image:
-A [architecture]
Set architecture. Pass `-A -h` as the architecture to see the list of supported architectures.
-O [os]
Set operating system. bootm command of u-boot changes boot method by os type. Pass -h as the OS to see the list of supported OS.
-T [image type]
Set image type. Pass ` -T -h` as the image to see the list of supported image type.
-C [compression type]
Set compression type. Pass -h as the compression to see the list of supported compression type.
-a [load addess]
Set load address with a hex number.
-e [entry point]
Set entry point with a hex number.
-n [image name]
Set image name to 'image name'.
-d [image data file]
Use image data from 'image data file'.
-x
Set XIP (execute in place) flag.
Create FIT image:
-D dtcoption"
Provide special options to the device tree compiler that is used to create the image.
-f fit-image.its"
Image tree source fine that descbres the structure and contents of the FIT image.
---
- in my boot.ini
ODROIDC4-UBOOT-CONFIG
Default Console Device Setting
setenv condev "console=ttyAML0,115200n8" # on both
setenv bootlabel
setenv bootlabel "2023-08-26 From Manjaro-arm-installer To Gentoo"
Boot Args
setenv bootargs "root=PARTUUID=69ed71c7-03 rootwait rw ${condev} ${amlogic} no_console_suspend fsck.repair=yes net.ifnames=0 clk_ignore_unused quiet splash plymouth.ignore-serial-consoles"
Set load addresses
setenv dtb_loadaddr "0x20000000" setenv loadaddr "0x1080000" setenv initrd_loadaddr "0x4080000"
Load kernel, dtb and initrd
load mmc ${devno}:1 ${loadaddr} /Image load mmc ${devno}:1 ${dtb_loadaddr} /dtbs/amlogic/meson-sm1-odroid-hc4.dtb load mmc ${devno}:1 ${initrd_loadaddr} /initramfs-linux.uimg #fdt addr ${dtb_loadaddr}
boot
booti ${loadaddr} ${initrd_loadaddr} ${dtb_loadaddr}
And my /boot/Image is my image file, what will be my `initramfs.img.uimg` for U-boot using mkimage?
---
dracut --hostonly --kver 6.1.53-gentoo-r1