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