Skip to contentSkip to conversation

linux: Add support for FIT image

PATCH Superseded Jörg Krause 2 participants 2 messages May 29, 2015 – Jul 13, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux: Add support for FIT image

The FIT (Flattened Image Tree) image format is a much more advanced and flexible format compared to regular uImage, let alone zImage.

The FIT image format allows for storing multiple kernel images, multiple device tree blobs and even multiple configurations for their combinations in a single image.

Furthermore, it enhances integrity protection of images with sha1, sha256 and md5 checksums as well as signature verification against a public key.

---
Changes in v2:
- build the device tree blob prior to the FIT image
- add error message if file path is missing

---
 linux/Config.in | 13 +++++++++++++
 linux/linux.mk  | 21 ++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
linux/Config.in +13 -0
index 457ada6..03ce8cf 100644
@@ -174,6 +174,13 @@ config BR2_LINUX_KERNEL_UBOOT_IMAGE
 choice
 	prompt "Kernel binary format"
 
+config BR2_LINUX_KERNEL_FITIMAGE
+	bool "fitImage"
+	depends on BR2_arc || BR2_arm || BR2_armeb || BR2_bfin || \
+		   BR2_powerpc || BR2_avr32 || BR2_sh || BR2_sh64 || \
+		   BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
+	select BR2_LINUX_KERNEL_UBOOT_IMAGE
+
 config BR2_LINUX_KERNEL_UIMAGE
 	bool "uImage"
 	depends on BR2_arc || BR2_arm || BR2_armeb || BR2_bfin || \
@@ -248,6 +255,12 @@ config BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM
 
 endchoice
 
+config BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE
+	string "FIT image device tree descriptor file path"
+	depends on BR2_LINUX_KERNEL_FITIMAGE
+	help
+	  Path to the FIT image device tree descriptor.
+
 config BR2_LINUX_KERNEL_IMAGE_TARGET_NAME
 	string "Kernel image target name"
 	depends on BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM
linux/linux.mk +20 -1
index c765954..a4fbe47 100644
@@ -108,6 +108,9 @@ LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
 ifeq ($(LINUX_IMAGE_NAME),)
 LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME)
 endif
+else ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+LINUX_IMAGE_NAME = fitImage
+LINUX_TARGET_NAME = zImage
 else
 ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y)
 LINUX_IMAGE_NAME = uImage
@@ -155,7 +158,9 @@ else
 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
 endif
 
-ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
+ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
+else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
@@ -277,6 +282,13 @@ LINUX_APPEND_DTB += $(sep) MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\
 endif
 endif
 
+define LINUX_BUILD_FITIMAGE
+	$(LINUX_INSTALL_HOST_TOOLS)
+	cp $(call qstrip,$(BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE)) $(@D)/fit-image.its
+	$(TARGET_MAKE_ENV) $(MKIMAGE) -f $(@D)/fit-image.its $(@D)/$(LINUX_IMAGE_NAME)
+	rm $(@D)/fit-image.its
+endef
+
 # Compilation. We make sure the kernel gets rebuilt when the
 # configuration has changed.
 define LINUX_BUILD_CMDS
@@ -288,6 +300,7 @@ define LINUX_BUILD_CMDS
 	fi
 	$(LINUX_BUILD_DTB)
 	$(LINUX_APPEND_DTB)
+	$(if $(BR2_LINUX_KERNEL_FITIMAGE), $(LINUX_BUILD_FITIMAGE))
 endef
 
 
@@ -374,4 +387,10 @@ $(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUST
 endif
 endif
 
+ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE)),)
+$(error No FIT image device tree descriptor file specified, check your BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE setting)
+endif
+endif
+
 endif
Signature · 1 line
2.4.2
#1 lore raw

PATCH v2 1/1 linux: Add support for FIT image

Hi J?rg,

Le 29/05/2015 21:32, J?rg Krause a ?crit :

Quoted 25 lines

The FIT (Flattened Image Tree) image format is a much more advanced and flexible format compared to regular uImage, let alone zImage.

The FIT image format allows for storing multiple kernel images, multiple device tree blobs and even multiple configurations for their combinations in a single image.

Furthermore, it enhances integrity protection of images with sha1, sha256 and md5 checksums as well as signature verification against a public key.

---
Changes in v2:
- build the device tree blob prior to the FIT image
- add error message if file path is missing

---
 linux/Config.in | 13 +++++++++++++
 linux/linux.mk  | 21 ++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
linux/Config.in +0 -0
index 457ada6..03ce8cf 100644

linux/Config.in config BR2_LINUX_KERNEL_UBOOT_IMAGE · line 180

Quoted 7 lines
linux/Config.in +4 -0
@@ -174,6 +174,13 @@ config BR2_LINUX_KERNEL_UBOOT_IMAGE
 choice
 	prompt "Kernel binary format"
 
+config BR2_LINUX_KERNEL_FITIMAGE
+	bool "fitImage"
+	depends on BR2_arc || BR2_arm || BR2_armeb || BR2_bfin || \
+		   BR2_powerpc || BR2_avr32 || BR2_sh || BR2_sh64 || \

avr32 support has been removed since 2015.05 Buildroot release.

linux/Config.in config BR2_LINUX_KERNEL_UBOOT_IMAGE · line 181

Quoted 1 line
linux/Config.in +1 -0
+		   BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el

I don't know much about FIT image format, is it really architecture dependent ? There is an example in uboot documentation for booting an x86 (32bit) system with a FIT image format.

http://git.denx.de/?p=u-boot.git;a=blob;f=doc/uImage.FIT/x86-fit-boot.txt

Quoted 6 lines
linux/Config.in +2 -0
+	select BR2_LINUX_KERNEL_UBOOT_IMAGE
+
 config BR2_LINUX_KERNEL_UIMAGE
 	bool "uImage"
 	depends on BR2_arc || BR2_arm || BR2_armeb || BR2_bfin || \

linux/Config.in config BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM · line 262

Quoted 8 lines
linux/Config.in +5 -0
@@ -248,6 +255,12 @@ config BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM
 
 endchoice
 
+config BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE
+	string "FIT image device tree descriptor file path"
+	depends on BR2_LINUX_KERNEL_FITIMAGE
+	help
+	  Path to the FIT image device tree descriptor.

Maybe say that a FIT image device tree descriptor is an *.its file ?

Quoted 19 lines
linux/Config.in +1 -0
+
 config BR2_LINUX_KERNEL_IMAGE_TARGET_NAME
 	string "Kernel image target name"
 	depends on BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM
linux/linux.mk +3 -0
index c765954..a4fbe47 100644
@@ -108,6 +108,9 @@ LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
 ifeq ($(LINUX_IMAGE_NAME),)
 LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME)
 endif
+else ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+LINUX_IMAGE_NAME = fitImage
+LINUX_TARGET_NAME = zImage
 else
 ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y)
 LINUX_IMAGE_NAME = uImage

linux/linux.mk else · line 164

Quoted 8 lines
linux/linux.mk +3 -1
@@ -155,7 +158,9 @@ else
 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
 endif
 
-ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
+ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
+else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)

This can be factorized with:
ifeq ($(BR2_LINUX_KERNEL_VMLINUX)$(BR2_LINUX_KERNEL_FITIMAGE),y) LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)

linux/linux.mk LINUX_APPEND_DTB += $(sep) MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\ · line 284

Quoted 6 lines
linux/linux.mk +0 -0
 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
@@ -277,6 +282,13 @@ LINUX_APPEND_DTB += $(sep) MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\
 endif
 endif
 

For consistency with the coding style, define LINUX_BUILD_FITIMAGE only when BR2_LINUX_KERNEL_FITIMAGE is selected:

ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)

linux/linux.mk LINUX_APPEND_DTB += $(sep) MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\ · line 290

Quoted 6 lines
linux/linux.mk +6 -0
+define LINUX_BUILD_FITIMAGE
+	$(LINUX_INSTALL_HOST_TOOLS)
+	cp $(call qstrip,$(BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE)) $(@D)/fit-image.its
+	$(TARGET_MAKE_ENV) $(MKIMAGE) -f $(@D)/fit-image.its $(@D)/$(LINUX_IMAGE_NAME)
+	rm $(@D)/fit-image.its
+endef

endif

linux/linux.mk define LINUX_BUILD_CMDS · line 303

Quoted 9 lines
linux/linux.mk +2 -0
+
 # Compilation. We make sure the kernel gets rebuilt when the
 # configuration has changed.
 define LINUX_BUILD_CMDS
@@ -288,6 +300,7 @@ define LINUX_BUILD_CMDS
 	fi
 	$(LINUX_BUILD_DTB)
 	$(LINUX_APPEND_DTB)
+	$(if $(BR2_LINUX_KERNEL_FITIMAGE), $(LINUX_BUILD_FITIMAGE))

Then simply use:

	$(LINUX_BUILD_FITIMAGE)

linux/linux.mk define LINUX_BUILD_CMDS · line 305

Quoted 2 lines
linux/linux.mk +0 -0
 endef
 

Best regards,
Romain Naour

Quoted 13 lines
linux/linux.mk +6 -0
@@ -374,4 +387,10 @@ $(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUST
 endif
 endif
 
+ifeq ($(BR2_LINUX_KERNEL_FITIMAGE),y)
+ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE)),)
+$(error No FIT image device tree descriptor file specified, check your BR2_LINUX_KERNEL_FITIMAGE_ITS_FILE setting)
+endif
+endif
+
 endif