Skip to content

Commit 7a23b02

Browse files
sjg20willdeacon
authored andcommitted
arm64: boot: Support Flat Image Tree
Add a script which produces a Flat Image Tree (FIT), a single file containing the built kernel and associated devicetree files. Compression defaults to gzip which gives a good balance of size and performance. The files compress from about 86MB to 24MB using this approach. The FIT can be used by bootloaders which support it, such as U-Boot and Linuxboot. It permits automatic selection of the correct devicetree, matching the compatible string of the running board with the closest compatible string in the FIT. There is no need for filenames or other workarounds. Add a 'make image.fit' build target for arm64, as well. The FIT can be examined using 'dumpimage -l'. This uses the 'dtbs-list' file but processes only .dtb files, ignoring the overlay .dtbo files. This features requires pylibfdt (use 'pip install libfdt'). It also requires compression utilities for the algorithm being used. Supported compression options are the same as the Image.xxx files. Use FIT_COMPRESSION to select an algorithm other than gzip. While FIT supports a ramdisk / initrd, no attempt is made to support this here, since it must be built separately from the Linux build. Signed-off-by: Simon Glass <[email protected]> Acked-by: Masahiro Yamada <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 0dc1670 commit 7a23b02

File tree

7 files changed

+333
-3
lines changed

7 files changed

+333
-3
lines changed

Documentation/process/changes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Sphinx\ [#f1]_ 2.4.4 sphinx-build --version
6262
cpio any cpio --version
6363
GNU tar 1.28 tar --version
6464
gtags (optional) 6.6.5 gtags --version
65+
mkimage (optional) 2017.01 mkimage --version
6566
====================== =============== ========================================
6667

6768
.. [#f1] Sphinx is needed only to build the Kernel documentation
@@ -189,6 +190,14 @@ The kernel build requires GNU GLOBAL version 6.6.5 or later to generate
189190
tag files through ``make gtags``. This is due to its use of the gtags
190191
``-C (--directory)`` flag.
191192

193+
mkimage
194+
-------
195+
196+
This tool is used when building a Flat Image Tree (FIT), commonly used on ARM
197+
platforms. The tool is available via the ``u-boot-tools`` package or can be
198+
built from the U-Boot source code. See the instructions at
199+
https://docs.u-boot.org/en/latest/build/tools.html#building-tools-for-linux
200+
192201
System utilities
193202
****************
194203

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,13 @@ F: drivers/mmc/host/sdhci-of-arasan.c
30513051
N: zynq
30523052
N: xilinx
30533053

3054+
ARM64 FIT SUPPORT
3055+
M: Simon Glass <[email protected]>
3056+
L: [email protected] (moderated for non-subscribers)
3057+
S: Maintained
3058+
F: arch/arm64/boot/Makefile
3059+
F: scripts/make_fit.py
3060+
30543061
ARM64 PORT (AARCH64 ARCHITECTURE)
30553062
M: Catalin Marinas <[email protected]>
30563063
M: Will Deacon <[email protected]>

arch/arm64/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
154154
# Default target when executing plain make
155155
boot := arch/arm64/boot
156156

157-
BOOT_TARGETS := Image vmlinuz.efi
157+
BOOT_TARGETS := Image vmlinuz.efi image.fit
158158

159159
PHONY += $(BOOT_TARGETS)
160160

@@ -166,7 +166,9 @@ endif
166166

167167
all: $(notdir $(KBUILD_IMAGE))
168168

169-
vmlinuz.efi: Image
169+
image.fit: dtbs
170+
171+
vmlinuz.efi image.fit: Image
170172
$(BOOT_TARGETS): vmlinux
171173
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
172174

@@ -219,6 +221,7 @@ virtconfig:
219221
define archhelp
220222
echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
221223
echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
224+
echo ' image.fit - Flat Image Tree (arch/$(ARCH)/boot/image.fit)'
222225
echo ' install - Install uncompressed kernel'
223226
echo ' zinstall - Install compressed kernel'
224227
echo ' Install using (your) ~/bin/installkernel or'

arch/arm64/boot/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Image
33
Image.gz
44
vmlinuz*
5+
image.fit

arch/arm64/boot/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
1818

19-
targets := Image Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo Image.zst
19+
targets := Image Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo \
20+
Image.zst image.fit
2021

2122
$(obj)/Image: vmlinux FORCE
2223
$(call if_changed,objcopy)
@@ -39,6 +40,9 @@ $(obj)/Image.lzo: $(obj)/Image FORCE
3940
$(obj)/Image.zst: $(obj)/Image FORCE
4041
$(call if_changed,zstd)
4142

43+
$(obj)/image.fit: $(obj)/Image $(obj)/dts/dtbs-list FORCE
44+
$(call if_changed,fit)
45+
4246
EFI_ZBOOT_PAYLOAD := Image
4347
EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64
4448
EFI_ZBOOT_MACH_TYPE := ARM64

scripts/Makefile.lib

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,22 @@ quiet_cmd_uimage = UIMAGE $@
504504
-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
505505
-n '$(UIMAGE_NAME)' -d $< $@
506506

507+
# Flat Image Tree (FIT)
508+
# This allows for packaging of a kernel and all devicetrees files, using
509+
# compression.
510+
# ---------------------------------------------------------------------------
511+
512+
MAKE_FIT := $(srctree)/scripts/make_fit.py
513+
514+
# Use this to override the compression algorithm
515+
FIT_COMPRESSION ?= gzip
516+
517+
quiet_cmd_fit = FIT $@
518+
cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \
519+
--name '$(UIMAGE_NAME)' \
520+
$(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \
521+
--compress $(FIT_COMPRESSION) -k $< @$(word 2,$^)
522+
507523
# XZ
508524
# ---------------------------------------------------------------------------
509525
# Use xzkern to compress the kernel image and xzmisc to compress other things.

0 commit comments

Comments
 (0)