Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | How to use images in the new image format |
| 4 | ========================================= |
| 5 | |
| 6 | Overview |
| 7 | -------- |
| 8 | |
| 9 | The new uImage format allows more flexibility in handling images of various |
| 10 | types (kernel, ramdisk, etc.), it also enhances integrity protection of images |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 11 | with cryptographic checksums. |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 12 | |
| 13 | Two auxiliary tools are needed on the development host system in order to |
| 14 | create an uImage in the new format: mkimage and dtc, although only one |
| 15 | (mkimage) is invoked directly. dtc is called from within mkimage and operates |
| 16 | behind the scenes, but needs to be present in the $PATH nevertheless. It is |
| 17 | important that the dtc used has support for binary includes -- refer to:: |
| 18 | |
| 19 | git://git.kernel.org/pub/scm/utils/dtc/dtc.git |
| 20 | |
| 21 | for its latest version. mkimage (together with dtc) takes as input |
| 22 | an image source file, which describes the contents of the image and defines |
| 23 | its various properties used during booting. By convention, image source file |
Joao Marcos Costa | 37d91a9 | 2023-09-07 22:50:45 +0200 | [diff] [blame] | 24 | has the ".its" extension, also, the details of its format are provided in |
| 25 | :doc:`source_file_format`. The actual data that is to be included in |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 26 | the uImage (kernel, ramdisk, etc.) is specified in the image source file in the |
| 27 | form of paths to appropriate data files. The outcome of the image creation |
| 28 | process is a binary file (by convention with the ".itb" extension) that |
| 29 | contains all the referenced data (kernel, ramdisk, etc.) and other information |
| 30 | needed by U-Boot to handle the uImage properly. The uImage file is then |
| 31 | transferred to the target (e.g., via tftp) and booted using the bootm command. |
| 32 | |
| 33 | To summarize the prerequisites needed for new uImage creation: |
| 34 | |
| 35 | - mkimage |
| 36 | - dtc (with support for binary includes) |
| 37 | - image source file (`*.its`) |
| 38 | - image data file(s) |
| 39 | |
| 40 | |
| 41 | Here's a graphical overview of the image creation and booting process:: |
| 42 | |
| 43 | image source file mkimage + dtc transfer to target |
| 44 | + ---------------> image file --------------------> bootm |
| 45 | image data file(s) |
| 46 | |
| 47 | SPL usage |
| 48 | --------- |
| 49 | |
| 50 | The SPL can make use of the new image format as well, this traditionally |
| 51 | is used to ship multiple device tree files within one image. Code in the SPL |
| 52 | will choose the one matching the current board and append this to the |
| 53 | U-Boot proper binary to be automatically used up by it. |
| 54 | Aside from U-Boot proper and one device tree blob the SPL can load multiple, |
| 55 | arbitrary image files as well. These binaries should be specified in their |
| 56 | own subnode under the /images node, which should then be referenced from one or |
| 57 | multiple /configurations subnodes. The required images must be enumerated in |
| 58 | the "loadables" property as a list of strings. |
| 59 | |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 60 | The SPL also records to a DT all additional images (called loadables) which are |
| 61 | loaded. The information about loadables locations is passed via the DT node with |
| 62 | fit-images name. |
| 63 | |
| 64 | Finally, if there are multiple xPL phases (e.g. SPL, VPL), images can be marked |
| 65 | as intended for a particular phase using the 'phase' property. For example, if |
| 66 | fit_image_load() is called with image_ph(IH_PHASE_SPL, IH_TYPE_FIRMWARE), then |
| 67 | only the image listed into the "firmware" property where phase is set to "spl" |
| 68 | will be loaded. |
| 69 | |
| 70 | Loadables Example |
| 71 | ----------------- |
| 72 | Consider the following case for an ARM64 platform where U-Boot runs in EL2 |
| 73 | started by ATF where SPL is loading U-Boot (as loadables) and ATF (as firmware). |
| 74 | |
| 75 | :: |
| 76 | |
| 77 | /dts-v1/; |
| 78 | |
| 79 | / { |
| 80 | description = "Configuration to load ATF before U-Boot"; |
| 81 | |
| 82 | images { |
| 83 | uboot { |
| 84 | description = "U-Boot (64-bit)"; |
| 85 | data = /incbin/("u-boot-nodtb.bin"); |
| 86 | type = "firmware"; |
| 87 | os = "u-boot"; |
| 88 | arch = "arm64"; |
| 89 | compression = "none"; |
| 90 | load = <0x8 0x8000000>; |
| 91 | entry = <0x8 0x8000000>; |
| 92 | hash { |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 93 | algo = "sha256"; |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 94 | }; |
| 95 | }; |
| 96 | atf { |
| 97 | description = "ARM Trusted Firmware"; |
| 98 | data = /incbin/("bl31.bin"); |
| 99 | type = "firmware"; |
| 100 | os = "arm-trusted-firmware"; |
| 101 | arch = "arm64"; |
| 102 | compression = "none"; |
| 103 | load = <0xfffea000>; |
| 104 | entry = <0xfffea000>; |
| 105 | hash { |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 106 | algo = "sha256"; |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 107 | }; |
| 108 | }; |
| 109 | fdt_1 { |
| 110 | description = "zynqmp-zcu102-revA"; |
| 111 | data = /incbin/("arch/arm/dts/zynqmp-zcu102-revA.dtb"); |
| 112 | type = "flat_dt"; |
| 113 | arch = "arm64"; |
| 114 | compression = "none"; |
| 115 | load = <0x100000>; |
| 116 | hash { |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 117 | algo = "sha256"; |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 118 | }; |
| 119 | }; |
| 120 | }; |
| 121 | configurations { |
| 122 | default = "config_1"; |
| 123 | |
| 124 | config_1 { |
| 125 | description = "zynqmp-zcu102-revA"; |
| 126 | firmware = "atf"; |
| 127 | loadables = "uboot"; |
| 128 | fdt = "fdt_1"; |
| 129 | }; |
| 130 | }; |
| 131 | }; |
| 132 | |
| 133 | In this case the SPL records via fit-images DT node the information about |
| 134 | loadables U-Boot image:: |
| 135 | |
| 136 | ZynqMP> fdt addr $fdtcontroladdr |
| 137 | ZynqMP> fdt print /fit-images |
| 138 | fit-images { |
| 139 | uboot { |
| 140 | os = "u-boot"; |
| 141 | type = "firmware"; |
| 142 | size = <0x001017c8>; |
| 143 | entry = <0x00000008 0x08000000>; |
| 144 | load = <0x00000008 0x08000000>; |
| 145 | }; |
| 146 | }; |
| 147 | |
| 148 | As you can see entry and load properties are 64bit wide to support loading |
| 149 | images above 4GB (in past entry and load properties where just 32bit). |
| 150 | |
| 151 | |
| 152 | Example 1 -- old-style (non-FDT) kernel booting |
| 153 | ----------------------------------------------- |
| 154 | |
| 155 | Consider a simple scenario, where a PPC Linux kernel built from sources on the |
| 156 | development host is to be booted old-style (non-FDT) by U-Boot on an embedded |
| 157 | target. Assume that the outcome of the build is vmlinux.bin.gz, a file which |
| 158 | contains a gzip-compressed PPC Linux kernel (the only data file in this case). |
| 159 | The uImage can be produced using the image source file |
| 160 | doc/uImage.FIT/kernel.its (note that kernel.its assumes that vmlinux.bin.gz is |
| 161 | in the current working directory; if desired, an alternative path can be |
| 162 | specified in the kernel.its file). Here's how to create the image and inspect |
| 163 | its contents: |
| 164 | |
| 165 | [on the host system]:: |
| 166 | |
| 167 | $ mkimage -f kernel.its kernel.itb |
| 168 | DTC: dts->dtb on file "kernel.its" |
| 169 | $ |
| 170 | $ mkimage -l kernel.itb |
| 171 | FIT description: Simple image with single Linux kernel |
| 172 | Created: Tue Mar 11 17:26:15 2008 |
| 173 | Image 0 (kernel) |
| 174 | Description: Vanilla Linux kernel |
| 175 | Type: Kernel Image |
| 176 | Compression: gzip compressed |
| 177 | Data Size: 943347 Bytes = 921.24 kB = 0.90 MB |
| 178 | Architecture: PowerPC |
| 179 | OS: Linux |
| 180 | Load Address: 0x00000000 |
| 181 | Entry Point: 0x00000000 |
| 182 | Hash algo: crc32 |
| 183 | Hash value: 2ae2bb40 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 184 | Hash algo: sha256 |
| 185 | Hash value: c22f6bb5a3f96942507a37e7d6a9333ebdc7da57971bc4c082113fe082fdc40f |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 186 | Default Configuration: 'config-1' |
| 187 | Configuration 0 (config-1) |
| 188 | Description: Boot Linux kernel |
| 189 | Kernel: kernel |
| 190 | |
| 191 | |
| 192 | The resulting image file kernel.itb can be now transferred to the target, |
| 193 | inspected and booted (note that first three U-Boot commands below are shown |
| 194 | for completeness -- they are part of the standard booting procedure and not |
| 195 | specific to the new image format). |
| 196 | |
| 197 | [on the target system]:: |
| 198 | |
| 199 | => print nfsargs |
| 200 | nfsargs=setenv bootargs root=/dev/nfs rw nfsroot=${serverip}:${rootpath} |
| 201 | => print addip |
| 202 | addip=setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off panic=1 |
| 203 | => run nfsargs addip |
| 204 | => tftp 900000 /path/to/tftp/location/kernel.itb |
| 205 | Using FEC device |
| 206 | TFTP from server 192.168.1.1; our IP address is 192.168.160.5 |
| 207 | Filename '/path/to/tftp/location/kernel.itb'. |
| 208 | Load address: 0x900000 |
| 209 | Loading: ################################################################# |
| 210 | done |
| 211 | Bytes transferred = 944464 (e6950 hex) |
| 212 | => iminfo |
| 213 | |
| 214 | ## Checking Image at 00900000 ... |
| 215 | FIT image found |
| 216 | FIT description: Simple image with single Linux kernel |
| 217 | Created: 2008-03-11 16:26:15 UTC |
| 218 | Image 0 (kernel) |
| 219 | Description: Vanilla Linux kernel |
| 220 | Type: Kernel Image |
| 221 | Compression: gzip compressed |
| 222 | Data Start: 0x009000e0 |
| 223 | Data Size: 943347 Bytes = 921.2 kB |
| 224 | Architecture: PowerPC |
| 225 | OS: Linux |
| 226 | Load Address: 0x00000000 |
| 227 | Entry Point: 0x00000000 |
| 228 | Hash algo: crc32 |
| 229 | Hash value: 2ae2bb40 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 230 | Hash algo: sha256 |
| 231 | Hash value: c22f6bb5a3f96942507a37e7d6a9333ebdc7da57971bc4c082113fe082fdc40f |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 232 | Default Configuration: 'config-1' |
| 233 | Configuration 0 (config-1) |
| 234 | Description: Boot Linux kernel |
| 235 | Kernel: kernel |
| 236 | |
| 237 | => bootm |
| 238 | ## Booting kernel from FIT Image at 00900000 ... |
| 239 | Using 'config-1' configuration |
| 240 | Trying 'kernel' kernel subimage |
| 241 | Description: Vanilla Linux kernel |
| 242 | Type: Kernel Image |
| 243 | Compression: gzip compressed |
| 244 | Data Start: 0x009000e0 |
| 245 | Data Size: 943347 Bytes = 921.2 kB |
| 246 | Architecture: PowerPC |
| 247 | OS: Linux |
| 248 | Load Address: 0x00000000 |
| 249 | Entry Point: 0x00000000 |
| 250 | Hash algo: crc32 |
| 251 | Hash value: 2ae2bb40 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 252 | Hash algo: sha256 |
| 253 | Hash value: c22f6bb5a3f96942507a37e7d6a9333ebdc7da57971bc4c082113fe082fdc40f |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 254 | Verifying Hash Integrity ... crc32+ sha1+ OK |
| 255 | Uncompressing Kernel Image ... OK |
| 256 | Memory BAT mapping: BAT2=256Mb, BAT3=0Mb, residual: 0Mb |
| 257 | Linux version 2.4.25 (m8@hekate) (gcc version 4.0.0 (DENX ELDK 4.0 4.0.0)) #2 czw lip 5 17:56:18 CEST 2007 |
| 258 | On node 0 totalpages: 65536 |
| 259 | zone(0): 65536 pages. |
| 260 | zone(1): 0 pages. |
| 261 | zone(2): 0 pages. |
| 262 | Kernel command line: root=/dev/nfs rw nfsroot=192.168.1.1:/opt/eldk-4.1/ppc_6xx ip=192.168.160.5:192.168.1.1::255.255.0.0:lite5200b:eth0:off panic=1 |
| 263 | Calibrating delay loop... 307.20 BogoMIPS |
| 264 | |
| 265 | |
| 266 | Example 2 -- new-style (FDT) kernel booting |
| 267 | ------------------------------------------- |
| 268 | |
| 269 | Consider another simple scenario, where a PPC Linux kernel is to be booted |
| 270 | new-style, i.e., with a FDT blob. In this case there are two prerequisite data |
| 271 | files: vmlinux.bin.gz (Linux kernel) and target.dtb (FDT blob). The uImage can |
| 272 | be produced using image source file doc/uImage.FIT/kernel_fdt.its like this |
| 273 | (note again, that both prerequisite data files are assumed to be present in |
| 274 | the current working directory -- image source file kernel_fdt.its can be |
| 275 | modified to take the files from some other location if needed): |
| 276 | |
| 277 | [on the host system]:: |
| 278 | |
| 279 | $ mkimage -f kernel_fdt.its kernel_fdt.itb |
| 280 | DTC: dts->dtb on file "kernel_fdt.its" |
| 281 | $ |
| 282 | $ mkimage -l kernel_fdt.itb |
| 283 | FIT description: Simple image with single Linux kernel and FDT blob |
| 284 | Created: Tue Mar 11 16:29:22 2008 |
| 285 | Image 0 (kernel) |
| 286 | Description: Vanilla Linux kernel |
| 287 | Type: Kernel Image |
| 288 | Compression: gzip compressed |
| 289 | Data Size: 1092037 Bytes = 1066.44 kB = 1.04 MB |
| 290 | Architecture: PowerPC |
| 291 | OS: Linux |
| 292 | Load Address: 0x00000000 |
| 293 | Entry Point: 0x00000000 |
| 294 | Hash algo: crc32 |
| 295 | Hash value: 2c0cc807 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 296 | Hash algo: sha256 |
| 297 | Hash value: a3e9e18b793873827d27c97edfbca67c404a1972d9f36cf48e73ff85d69a422c |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 298 | Image 1 (fdt-1) |
| 299 | Description: Flattened Device Tree blob |
| 300 | Type: Flat Device Tree |
| 301 | Compression: uncompressed |
| 302 | Data Size: 16384 Bytes = 16.00 kB = 0.02 MB |
| 303 | Architecture: PowerPC |
| 304 | Hash algo: crc32 |
| 305 | Hash value: 0d655d71 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 306 | Hash algo: sha256 |
| 307 | Hash value: e9b9a40c5e2e12213ac819e7ccad7271ef43eb5edf9b421f0fa0b4b51bfdb214 |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 308 | Default Configuration: 'conf-1' |
| 309 | Configuration 0 (conf-1) |
| 310 | Description: Boot Linux kernel with FDT blob |
| 311 | Kernel: kernel |
| 312 | FDT: fdt-1 |
| 313 | |
| 314 | |
| 315 | The resulting image file kernel_fdt.itb can be now transferred to the target, |
| 316 | inspected and booted: |
| 317 | |
| 318 | [on the target system]:: |
| 319 | |
| 320 | => tftp 900000 /path/to/tftp/location/kernel_fdt.itb |
| 321 | Using FEC device |
| 322 | TFTP from server 192.168.1.1; our IP address is 192.168.160.5 |
| 323 | Filename '/path/to/tftp/location/kernel_fdt.itb'. |
| 324 | Load address: 0x900000 |
| 325 | Loading: ################################################################# |
| 326 | ########### |
| 327 | done |
| 328 | Bytes transferred = 1109776 (10ef10 hex) |
| 329 | => iminfo |
| 330 | |
| 331 | ## Checking Image at 00900000 ... |
| 332 | FIT image found |
| 333 | FIT description: Simple image with single Linux kernel and FDT blob |
| 334 | Created: 2008-03-11 15:29:22 UTC |
| 335 | Image 0 (kernel) |
| 336 | Description: Vanilla Linux kernel |
| 337 | Type: Kernel Image |
| 338 | Compression: gzip compressed |
| 339 | Data Start: 0x009000ec |
| 340 | Data Size: 1092037 Bytes = 1 MB |
| 341 | Architecture: PowerPC |
| 342 | OS: Linux |
| 343 | Load Address: 0x00000000 |
| 344 | Entry Point: 0x00000000 |
| 345 | Hash algo: crc32 |
| 346 | Hash value: 2c0cc807 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 347 | Hash algo: sha256 |
| 348 | Hash value: a3e9e18b793873827d27c97edfbca67c404a1972d9f36cf48e73ff85d69a422c |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 349 | Image 1 (fdt-1) |
| 350 | Description: Flattened Device Tree blob |
| 351 | Type: Flat Device Tree |
| 352 | Compression: uncompressed |
| 353 | Data Start: 0x00a0abdc |
| 354 | Data Size: 16384 Bytes = 16 kB |
| 355 | Architecture: PowerPC |
| 356 | Hash algo: crc32 |
| 357 | Hash value: 0d655d71 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 358 | Hash algo: sha256 |
| 359 | Hash value: e9b9a40c5e2e12213ac819e7ccad7271ef43eb5edf9b421f0fa0b4b51bfdb214 |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 360 | Default Configuration: 'conf-1' |
| 361 | Configuration 0 (conf-1) |
| 362 | Description: Boot Linux kernel with FDT blob |
| 363 | Kernel: kernel |
| 364 | FDT: fdt-1 |
| 365 | => bootm |
| 366 | ## Booting kernel from FIT Image at 00900000 ... |
| 367 | Using 'conf-1' configuration |
| 368 | Trying 'kernel' kernel subimage |
| 369 | Description: Vanilla Linux kernel |
| 370 | Type: Kernel Image |
| 371 | Compression: gzip compressed |
| 372 | Data Start: 0x009000ec |
| 373 | Data Size: 1092037 Bytes = 1 MB |
| 374 | Architecture: PowerPC |
| 375 | OS: Linux |
| 376 | Load Address: 0x00000000 |
| 377 | Entry Point: 0x00000000 |
| 378 | Hash algo: crc32 |
| 379 | Hash value: 2c0cc807 |
| 380 | Hash algo: sha1 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 381 | Hash value: a3e9e18b793873827d27c97edfbca67c404a1972d9f36cf48e73ff85d69a422c |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 382 | Verifying Hash Integrity ... crc32+ sha1+ OK |
| 383 | Uncompressing Kernel Image ... OK |
| 384 | ## Flattened Device Tree from FIT Image at 00900000 |
| 385 | Using 'conf-1' configuration |
| 386 | Trying 'fdt-1' FDT blob subimage |
| 387 | Description: Flattened Device Tree blob |
| 388 | Type: Flat Device Tree |
| 389 | Compression: uncompressed |
| 390 | Data Start: 0x00a0abdc |
| 391 | Data Size: 16384 Bytes = 16 kB |
| 392 | Architecture: PowerPC |
| 393 | Hash algo: crc32 |
| 394 | Hash value: 0d655d71 |
| 395 | Hash algo: sha1 |
Sean Anderson | 72a09cc | 2023-12-02 14:33:14 -0500 | [diff] [blame] | 396 | Hash value: e9b9a40c5e2e12213ac819e7ccad7271ef43eb5edf9b421f0fa0b4b51bfdb214 |
Simon Glass | 16e859f | 2023-06-23 13:22:07 +0100 | [diff] [blame] | 397 | Verifying Hash Integrity ... crc32+ sha1+ OK |
| 398 | Booting using the fdt blob at 0xa0abdc |
| 399 | Loading Device Tree to 007fc000, end 007fffff ... OK |
| 400 | [ 0.000000] Using lite5200 machine description |
| 401 | [ 0.000000] Linux version 2.6.24-rc6-gaebecdfc (m8@hekate) (gcc version 4.0.0 (DENX ELDK 4.1 4.0.0)) #1 Sat Jan 12 15:38:48 CET 2008 |
| 402 | |
| 403 | |
| 404 | Example 3 -- advanced booting |
| 405 | ----------------------------- |
| 406 | |
| 407 | Refer to :doc:`multi` for an image source file that allows more |
| 408 | sophisticated booting scenarios (multiple kernels, ramdisks and fdt blobs). |
| 409 | |
| 410 | .. sectionauthor:: Bartlomiej Sieka <tur@semihalf.com> |