blob: def12a70f7b235d1d7652ab1f07d013a309ca3ae [file] [log] [blame]
Simon Glass16e859f2023-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
11with sha1 and md5 checksums.
12
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 Costa37d91a92023-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 Glass16e859f2023-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
60If a platform specific image source file (.its) is shipped with the U-Boot
61source, it can be specified using the CONFIG_SPL_FIT_SOURCE Kconfig symbol.
62In this case it will be automatically used by U-Boot's Makefile to generate
63the image.
64If a static source file is not flexible enough, CONFIG_SPL_FIT_GENERATOR
65can point to a script which generates this image source file during
66the build process. It gets passed a list of device tree files (taken from the
67CONFIG_OF_LIST symbol).
68
69The SPL also records to a DT all additional images (called loadables) which are
70loaded. The information about loadables locations is passed via the DT node with
71fit-images name.
72
73Finally, if there are multiple xPL phases (e.g. SPL, VPL), images can be marked
74as intended for a particular phase using the 'phase' property. For example, if
75fit_image_load() is called with image_ph(IH_PHASE_SPL, IH_TYPE_FIRMWARE), then
76only the image listed into the "firmware" property where phase is set to "spl"
77will be loaded.
78
79Loadables Example
80-----------------
81Consider the following case for an ARM64 platform where U-Boot runs in EL2
82started by ATF where SPL is loading U-Boot (as loadables) and ATF (as firmware).
83
84::
85
86 /dts-v1/;
87
88 / {
89 description = "Configuration to load ATF before U-Boot";
90
91 images {
92 uboot {
93 description = "U-Boot (64-bit)";
94 data = /incbin/("u-boot-nodtb.bin");
95 type = "firmware";
96 os = "u-boot";
97 arch = "arm64";
98 compression = "none";
99 load = <0x8 0x8000000>;
100 entry = <0x8 0x8000000>;
101 hash {
102 algo = "md5";
103 };
104 };
105 atf {
106 description = "ARM Trusted Firmware";
107 data = /incbin/("bl31.bin");
108 type = "firmware";
109 os = "arm-trusted-firmware";
110 arch = "arm64";
111 compression = "none";
112 load = <0xfffea000>;
113 entry = <0xfffea000>;
114 hash {
115 algo = "md5";
116 };
117 };
118 fdt_1 {
119 description = "zynqmp-zcu102-revA";
120 data = /incbin/("arch/arm/dts/zynqmp-zcu102-revA.dtb");
121 type = "flat_dt";
122 arch = "arm64";
123 compression = "none";
124 load = <0x100000>;
125 hash {
126 algo = "md5";
127 };
128 };
129 };
130 configurations {
131 default = "config_1";
132
133 config_1 {
134 description = "zynqmp-zcu102-revA";
135 firmware = "atf";
136 loadables = "uboot";
137 fdt = "fdt_1";
138 };
139 };
140 };
141
142In this case the SPL records via fit-images DT node the information about
143loadables U-Boot image::
144
145 ZynqMP> fdt addr $fdtcontroladdr
146 ZynqMP> fdt print /fit-images
147 fit-images {
148 uboot {
149 os = "u-boot";
150 type = "firmware";
151 size = <0x001017c8>;
152 entry = <0x00000008 0x08000000>;
153 load = <0x00000008 0x08000000>;
154 };
155 };
156
157As you can see entry and load properties are 64bit wide to support loading
158images above 4GB (in past entry and load properties where just 32bit).
159
160
161Example 1 -- old-style (non-FDT) kernel booting
162-----------------------------------------------
163
164Consider a simple scenario, where a PPC Linux kernel built from sources on the
165development host is to be booted old-style (non-FDT) by U-Boot on an embedded
166target. Assume that the outcome of the build is vmlinux.bin.gz, a file which
167contains a gzip-compressed PPC Linux kernel (the only data file in this case).
168The uImage can be produced using the image source file
169doc/uImage.FIT/kernel.its (note that kernel.its assumes that vmlinux.bin.gz is
170in the current working directory; if desired, an alternative path can be
171specified in the kernel.its file). Here's how to create the image and inspect
172its contents:
173
174[on the host system]::
175
176 $ mkimage -f kernel.its kernel.itb
177 DTC: dts->dtb on file "kernel.its"
178 $
179 $ mkimage -l kernel.itb
180 FIT description: Simple image with single Linux kernel
181 Created: Tue Mar 11 17:26:15 2008
182 Image 0 (kernel)
183 Description: Vanilla Linux kernel
184 Type: Kernel Image
185 Compression: gzip compressed
186 Data Size: 943347 Bytes = 921.24 kB = 0.90 MB
187 Architecture: PowerPC
188 OS: Linux
189 Load Address: 0x00000000
190 Entry Point: 0x00000000
191 Hash algo: crc32
192 Hash value: 2ae2bb40
193 Hash algo: sha1
194 Hash value: 3c200f34e2c226ddc789240cca0c59fc54a67cf4
195 Default Configuration: 'config-1'
196 Configuration 0 (config-1)
197 Description: Boot Linux kernel
198 Kernel: kernel
199
200
201The resulting image file kernel.itb can be now transferred to the target,
202inspected and booted (note that first three U-Boot commands below are shown
203for completeness -- they are part of the standard booting procedure and not
204specific to the new image format).
205
206[on the target system]::
207
208 => print nfsargs
209 nfsargs=setenv bootargs root=/dev/nfs rw nfsroot=${serverip}:${rootpath}
210 => print addip
211 addip=setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off panic=1
212 => run nfsargs addip
213 => tftp 900000 /path/to/tftp/location/kernel.itb
214 Using FEC device
215 TFTP from server 192.168.1.1; our IP address is 192.168.160.5
216 Filename '/path/to/tftp/location/kernel.itb'.
217 Load address: 0x900000
218 Loading: #################################################################
219 done
220 Bytes transferred = 944464 (e6950 hex)
221 => iminfo
222
223 ## Checking Image at 00900000 ...
224 FIT image found
225 FIT description: Simple image with single Linux kernel
226 Created: 2008-03-11 16:26:15 UTC
227 Image 0 (kernel)
228 Description: Vanilla Linux kernel
229 Type: Kernel Image
230 Compression: gzip compressed
231 Data Start: 0x009000e0
232 Data Size: 943347 Bytes = 921.2 kB
233 Architecture: PowerPC
234 OS: Linux
235 Load Address: 0x00000000
236 Entry Point: 0x00000000
237 Hash algo: crc32
238 Hash value: 2ae2bb40
239 Hash algo: sha1
240 Hash value: 3c200f34e2c226ddc789240cca0c59fc54a67cf4
241 Default Configuration: 'config-1'
242 Configuration 0 (config-1)
243 Description: Boot Linux kernel
244 Kernel: kernel
245
246 => bootm
247 ## Booting kernel from FIT Image at 00900000 ...
248 Using 'config-1' configuration
249 Trying 'kernel' kernel subimage
250 Description: Vanilla Linux kernel
251 Type: Kernel Image
252 Compression: gzip compressed
253 Data Start: 0x009000e0
254 Data Size: 943347 Bytes = 921.2 kB
255 Architecture: PowerPC
256 OS: Linux
257 Load Address: 0x00000000
258 Entry Point: 0x00000000
259 Hash algo: crc32
260 Hash value: 2ae2bb40
261 Hash algo: sha1
262 Hash value: 3c200f34e2c226ddc789240cca0c59fc54a67cf4
263 Verifying Hash Integrity ... crc32+ sha1+ OK
264 Uncompressing Kernel Image ... OK
265 Memory BAT mapping: BAT2=256Mb, BAT3=0Mb, residual: 0Mb
266 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
267 On node 0 totalpages: 65536
268 zone(0): 65536 pages.
269 zone(1): 0 pages.
270 zone(2): 0 pages.
271 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
272 Calibrating delay loop... 307.20 BogoMIPS
273
274
275Example 2 -- new-style (FDT) kernel booting
276-------------------------------------------
277
278Consider another simple scenario, where a PPC Linux kernel is to be booted
279new-style, i.e., with a FDT blob. In this case there are two prerequisite data
280files: vmlinux.bin.gz (Linux kernel) and target.dtb (FDT blob). The uImage can
281be produced using image source file doc/uImage.FIT/kernel_fdt.its like this
282(note again, that both prerequisite data files are assumed to be present in
283the current working directory -- image source file kernel_fdt.its can be
284modified to take the files from some other location if needed):
285
286[on the host system]::
287
288 $ mkimage -f kernel_fdt.its kernel_fdt.itb
289 DTC: dts->dtb on file "kernel_fdt.its"
290 $
291 $ mkimage -l kernel_fdt.itb
292 FIT description: Simple image with single Linux kernel and FDT blob
293 Created: Tue Mar 11 16:29:22 2008
294 Image 0 (kernel)
295 Description: Vanilla Linux kernel
296 Type: Kernel Image
297 Compression: gzip compressed
298 Data Size: 1092037 Bytes = 1066.44 kB = 1.04 MB
299 Architecture: PowerPC
300 OS: Linux
301 Load Address: 0x00000000
302 Entry Point: 0x00000000
303 Hash algo: crc32
304 Hash value: 2c0cc807
305 Hash algo: sha1
306 Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
307 Image 1 (fdt-1)
308 Description: Flattened Device Tree blob
309 Type: Flat Device Tree
310 Compression: uncompressed
311 Data Size: 16384 Bytes = 16.00 kB = 0.02 MB
312 Architecture: PowerPC
313 Hash algo: crc32
314 Hash value: 0d655d71
315 Hash algo: sha1
316 Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
317 Default Configuration: 'conf-1'
318 Configuration 0 (conf-1)
319 Description: Boot Linux kernel with FDT blob
320 Kernel: kernel
321 FDT: fdt-1
322
323
324The resulting image file kernel_fdt.itb can be now transferred to the target,
325inspected and booted:
326
327[on the target system]::
328
329 => tftp 900000 /path/to/tftp/location/kernel_fdt.itb
330 Using FEC device
331 TFTP from server 192.168.1.1; our IP address is 192.168.160.5
332 Filename '/path/to/tftp/location/kernel_fdt.itb'.
333 Load address: 0x900000
334 Loading: #################################################################
335 ###########
336 done
337 Bytes transferred = 1109776 (10ef10 hex)
338 => iminfo
339
340 ## Checking Image at 00900000 ...
341 FIT image found
342 FIT description: Simple image with single Linux kernel and FDT blob
343 Created: 2008-03-11 15:29:22 UTC
344 Image 0 (kernel)
345 Description: Vanilla Linux kernel
346 Type: Kernel Image
347 Compression: gzip compressed
348 Data Start: 0x009000ec
349 Data Size: 1092037 Bytes = 1 MB
350 Architecture: PowerPC
351 OS: Linux
352 Load Address: 0x00000000
353 Entry Point: 0x00000000
354 Hash algo: crc32
355 Hash value: 2c0cc807
356 Hash algo: sha1
357 Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
358 Image 1 (fdt-1)
359 Description: Flattened Device Tree blob
360 Type: Flat Device Tree
361 Compression: uncompressed
362 Data Start: 0x00a0abdc
363 Data Size: 16384 Bytes = 16 kB
364 Architecture: PowerPC
365 Hash algo: crc32
366 Hash value: 0d655d71
367 Hash algo: sha1
368 Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
369 Default Configuration: 'conf-1'
370 Configuration 0 (conf-1)
371 Description: Boot Linux kernel with FDT blob
372 Kernel: kernel
373 FDT: fdt-1
374 => bootm
375 ## Booting kernel from FIT Image at 00900000 ...
376 Using 'conf-1' configuration
377 Trying 'kernel' kernel subimage
378 Description: Vanilla Linux kernel
379 Type: Kernel Image
380 Compression: gzip compressed
381 Data Start: 0x009000ec
382 Data Size: 1092037 Bytes = 1 MB
383 Architecture: PowerPC
384 OS: Linux
385 Load Address: 0x00000000
386 Entry Point: 0x00000000
387 Hash algo: crc32
388 Hash value: 2c0cc807
389 Hash algo: sha1
390 Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
391 Verifying Hash Integrity ... crc32+ sha1+ OK
392 Uncompressing Kernel Image ... OK
393 ## Flattened Device Tree from FIT Image at 00900000
394 Using 'conf-1' configuration
395 Trying 'fdt-1' FDT blob subimage
396 Description: Flattened Device Tree blob
397 Type: Flat Device Tree
398 Compression: uncompressed
399 Data Start: 0x00a0abdc
400 Data Size: 16384 Bytes = 16 kB
401 Architecture: PowerPC
402 Hash algo: crc32
403 Hash value: 0d655d71
404 Hash algo: sha1
405 Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
406 Verifying Hash Integrity ... crc32+ sha1+ OK
407 Booting using the fdt blob at 0xa0abdc
408 Loading Device Tree to 007fc000, end 007fffff ... OK
409 [ 0.000000] Using lite5200 machine description
410 [ 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
411
412
413Example 3 -- advanced booting
414-----------------------------
415
416Refer to :doc:`multi` for an image source file that allows more
417sophisticated booting scenarios (multiple kernels, ramdisks and fdt blobs).
418
419.. sectionauthor:: Bartlomiej Sieka <tur@semihalf.com>