Skip to contentSkip to conversation

uboot: add support for bundling ATF BL31 in ELF format into U-Boot

PATCH Superseded Michał Łyszczek 3 participants 6 messages Nov 11, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

Rockchip's rk3328 encapsulates the BL31 part of ATP but it needs image in ELF format. This is extension to 2c4809e6088660dc71de9de8cee0bba312aafbe4

This commit introduces a BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF variable to achieve this.

---
Changes v1 -> v2:
- fix wrong prefix BR_ to BR2_

---
 boot/arm-trusted-firmware/arm-trusted-firmware.mk | 7 +++++++
 boot/uboot/Config.in                              | 7 +++++++
 boot/uboot/uboot.mk                               | 4 ++++
 3 files changed, 18 insertions(+)
boot/arm-trusted-firmware/arm-trusted-firmware.mk +7 -0
index 23f493653d..8f0f745ac0 100644
@@ -94,6 +94,12 @@ ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1
 ARM_TRUSTED_FIRMWARE_DEPENDENCIES += host-uboot-tools
 endif
 
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+define ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF
+	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/bl31/bl31.elf $(BINARIES_DIR)/
+endef
+endif
+
 define ARM_TRUSTED_FIRMWARE_BUILD_CMDS
 	$(ARM_TRUSTED_FIRMWARE_BUILD_FIPTOOL)
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(ARM_TRUSTED_FIRMWARE_MAKE_OPTS) \
@@ -104,6 +110,7 @@ endef
 define ARM_TRUSTED_FIRMWARE_INSTALL_IMAGES_CMDS
 	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/
 	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL)
+	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF)
 endef
 
 # Configuration check
boot/uboot/Config.in +7 -0
index ac6f8bc8c1..7f2f7945ac 100644
@@ -179,6 +179,13 @@ config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
 	  variable pointing to ATF's BL31 binary, is passed during the
 	  Buildroot build.
 
+config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF
+	bool "U-Boot needs bl31.elf"
+	depends on BR2_TARGET_UBOOT_NEEDS_ATF_BL31
+	help
+		Uses bl31.elf instead of bl31.bin image.  This is needed by some
+		platforms (like rk3328) to generate valid uboot.itb with ATF
+
 menu "U-Boot binary format"
 
 config BR2_TARGET_UBOOT_FORMAT_AIS
boot/uboot/uboot.mk +4 -0
index cbdfee6ac3..06efd7b052 100644
@@ -137,8 +137,12 @@ UBOOT_MAKE_OPTS += \
 
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31),y)
 UBOOT_DEPENDENCIES += arm-trusted-firmware
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.elf
+else
 UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.bin
 endif
+endif
 
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_DTC),y)
 UBOOT_DEPENDENCIES += host-dtc
Signature · 1 line
2.18.1
#1 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

Hi Micha?,

Quoted 24 lines · Micha? ?yszczek

Rockchip's rk3328 encapsulates the BL31 part of ATP but it needs image in ELF format. This is extension to 2c4809e6088660dc71de9de8cee0bba312aafbe4

This commit introduces a BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF variable to achieve this.

---
Changes v1 -> v2:
- fix wrong prefix BR_ to BR2_

---
 boot/arm-trusted-firmware/arm-trusted-firmware.mk | 7 +++++++
 boot/uboot/Config.in                              | 7 +++++++
 boot/uboot/uboot.mk                               | 4 ++++
 3 files changed, 18 insertions(+)
boot/arm-trusted-firmware/arm-trusted-firmware.mk +0 -0
index 23f493653d..8f0f745ac0 100644

boot/arm-trusted-firmware/arm-trusted-firmware.mk ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1 · line 101

Quoted 8 lines
boot/arm-trusted-firmware/arm-trusted-firmware.mk +5 -0
@@ -94,6 +94,12 @@ ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1
 ARM_TRUSTED_FIRMWARE_DEPENDENCIES += host-uboot-tools
 endif
 
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+define ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF
+	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/bl31/bl31.elf $(BINARIES_DIR)/
+endef
+endif

Why not add this 'ifeq' into ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL ...

boot/arm-trusted-firmware/arm-trusted-firmware.mk endef · line 113

Quoted 9 lines
boot/arm-trusted-firmware/arm-trusted-firmware.mk +2 -0
+
 define ARM_TRUSTED_FIRMWARE_BUILD_CMDS
 	$(ARM_TRUSTED_FIRMWARE_BUILD_FIPTOOL)
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(ARM_TRUSTED_FIRMWARE_MAKE_OPTS) \
@@ -104,6 +110,7 @@ endef
 define ARM_TRUSTED_FIRMWARE_INSTALL_IMAGES_CMDS
 	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/
 	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL)
+	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF)

... and drop this part.

Quoted 28 lines
boot/arm-trusted-firmware/arm-trusted-firmware.mk +0 -0
 endef
 
 # Configuration check
boot/uboot/Config.in +7 -0
index ac6f8bc8c1..7f2f7945ac 100644
@@ -179,6 +179,13 @@ config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
 	  variable pointing to ATF's BL31 binary, is passed during the
 	  Buildroot build.
 
+config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF
+	bool "U-Boot needs bl31.elf"
+	depends on BR2_TARGET_UBOOT_NEEDS_ATF_BL31
+	help
+		Uses bl31.elf instead of bl31.bin image.  This is needed by some
+		platforms (like rk3328) to generate valid uboot.itb with ATF
+
 menu "U-Boot binary format"
 
 config BR2_TARGET_UBOOT_FORMAT_AIS
boot/uboot/uboot.mk +0 -0
index cbdfee6ac3..06efd7b052 100644
@@ -137,8 +137,12 @@ UBOOT_MAKE_OPTS += \
 
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31),y)

boot/uboot/uboot.mk UBOOT_MAKE_OPTS += \ · line 148

Quoted 10 lines
boot/uboot/uboot.mk +4 -0
 UBOOT_DEPENDENCIES += arm-trusted-firmware
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.elf
+else
 UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.bin
 endif
+endif
 
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_DTC),y)
 UBOOT_DEPENDENCIES += host-dtc

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
#2 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

On 2018-11-11 18:56:17, Baruch Siach wrote:
Hi Baruch

Quoted 8 lines

boot/arm-trusted-firmware/arm-trusted-firmware.mk ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1 · line 101

Quoted 5 lines
boot/arm-trusted-firmware/arm-trusted-firmware.mk +5 -0
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+define ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF
+	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/bl31/bl31.elf $(BINARIES_DIR)/
+endef
+endif

Why not add this 'ifeq' into ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL ...

Quoted 12 lines

boot/arm-trusted-firmware/arm-trusted-firmware.mk endef · line 113

Quoted 9 lines
boot/arm-trusted-firmware/arm-trusted-firmware.mk +2 -0
+
 define ARM_TRUSTED_FIRMWARE_BUILD_CMDS
 	$(ARM_TRUSTED_FIRMWARE_BUILD_FIPTOOL)
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(ARM_TRUSTED_FIRMWARE_MAKE_OPTS) \
@@ -104,6 +110,7 @@ endef
 define ARM_TRUSTED_FIRMWARE_INSTALL_IMAGES_CMDS
 	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/
 	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL)
+	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF)

... and drop this part.

Because ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL is inside BR2_TARGET_ARM_TRUSTED_FIRMWARE_BL31_UBOOT ifeq and that option is not required for my change. What's more, ATP won't build for rk3328 when BR2_TARGET_ARM_TRUSTED_FIRMWARE_BL31_UBOOT is enabled, because some functions are no implemented and undefined reference error occurs.

#3 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

In reply to Michał Łyszczek

Hello,

Thanks for this contribution!

Quoted 30 lines · Micha? ?yszczek
boot/arm-trusted-firmware/arm-trusted-firmware.mk +7 -0
index 23f493653d..8f0f745ac0 100644
@@ -94,6 +94,12 @@ ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1
 ARM_TRUSTED_FIRMWARE_DEPENDENCIES += host-uboot-tools
 endif
 
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+define ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF
+	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/bl31/bl31.elf $(BINARIES_DIR)/
+endef
+endif
+
 define ARM_TRUSTED_FIRMWARE_BUILD_CMDS
 	$(ARM_TRUSTED_FIRMWARE_BUILD_FIPTOOL)
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(ARM_TRUSTED_FIRMWARE_MAKE_OPTS) \
@@ -104,6 +110,7 @@ endef
 define ARM_TRUSTED_FIRMWARE_INSTALL_IMAGES_CMDS
 	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/
 	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL)
+	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF)
 endef
 
 # Configuration check
boot/uboot/Config.in +0 -0
index ac6f8bc8c1..7f2f7945ac 100644

boot/uboot/Config.in config BR2_TARGET_UBOOT_NEEDS_ATF_BL31 · line 187

Quoted 9 lines
boot/uboot/Config.in +6 -0
@@ -179,6 +179,13 @@ config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
 	  variable pointing to ATF's BL31 binary, is passed during the
 	  Buildroot build.
 
+config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF
+	bool "U-Boot needs bl31.elf"
+	depends on BR2_TARGET_UBOOT_NEEDS_ATF_BL31
+	help
+		Uses bl31.elf instead of bl31.bin image.  This is needed by some
+		platforms (like rk3328) to generate valid uboot.itb with ATF

Nit: the indentation for the help text should be one tab + two spaces.

boot/uboot/Config.in config BR2_TARGET_UBOOT_NEEDS_ATF_BL31

Quoted 7 lines
boot/uboot/Config.in +3 -0
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31),y)
 UBOOT_DEPENDENCIES += arm-trusted-firmware
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.elf
+else
 UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.bin
 endif

So this code means that you can either use the bl31 as ELF *or* the bl31 as binary. So I believe it should not be possible to select both. Therefore, I would suggest to instead have:

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
bool "U-Boot needs ATF BL31"
... as it already exists ...

choice
prompt "U-Boot ATF BL31 format" default BR2_TARGET_UBOOT_NEEDS_ATF_BL31_BIN

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_BIN

	bool "bl31.bin"

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF

	bool "bl31.elf"

endchoice

And then use that in both arm-trusted-firmware.mk and uboot.mk.

What do you think ?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

Quoted 39 lines · Thomas Petazzoni

Hello,

Thanks for this contribution!

Quoted 33 lines · Micha? ?yszczek
boot/arm-trusted-firmware/arm-trusted-firmware.mk +7 -0
index 23f493653d..8f0f745ac0 100644
@@ -94,6 +94,12 @@ ARM_TRUSTED_FIRMWARE_MAKE_OPTS += RESET_TO_BL31=1
 ARM_TRUSTED_FIRMWARE_DEPENDENCIES += host-uboot-tools
 endif
 
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+define ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF
+	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/bl31/bl31.elf $(BINARIES_DIR)/
+endef
+endif
+
 define ARM_TRUSTED_FIRMWARE_BUILD_CMDS
 	$(ARM_TRUSTED_FIRMWARE_BUILD_FIPTOOL)
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(ARM_TRUSTED_FIRMWARE_MAKE_OPTS) \
@@ -104,6 +110,7 @@ endef
 define ARM_TRUSTED_FIRMWARE_INSTALL_IMAGES_CMDS
 	cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/
 	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL)
+	$(ARM_TRUSTED_FIRMWARE_BL31_UBOOT_INSTALL_ELF)
 endef
 
 # Configuration check
boot/uboot/Config.in +0 -0
index ac6f8bc8c1..7f2f7945ac 100644
@@ -179,6 +179,13 @@ config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
 	  variable pointing to ATF's BL31 binary, is passed during the
 	  Buildroot build.
 
Quoted 8 lines

boot/uboot/Config.in config BR2_TARGET_UBOOT_NEEDS_ATF_BL31 · line 187

Quoted 6 lines
boot/uboot/Config.in +6 -0
+config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF
+	bool "U-Boot needs bl31.elf"
+	depends on BR2_TARGET_UBOOT_NEEDS_ATF_BL31
+	help
+		Uses bl31.elf instead of bl31.bin image.  This is needed by some
+		platforms (like rk3328) to generate valid uboot.itb with ATF

Nit: the indentation for the help text should be one tab + two spaces.

Oops, didn't notice, fixed.

Quoted 23 lines

boot/uboot/Config.in config BR2_TARGET_UBOOT_NEEDS_ATF_BL31

Quoted 7 lines
boot/uboot/Config.in +3 -0
 ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31),y)
 UBOOT_DEPENDENCIES += arm-trusted-firmware
+ifeq ($(BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF),y)
+UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.elf
+else
 UBOOT_MAKE_OPTS += BL31=$(BINARIES_DIR)/bl31.bin
 endif

So this code means that you can either use the bl31 as ELF *or* the bl31 as binary. So I believe it should not be possible to select both. Therefore, I would suggest to instead have:

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31
bool "U-Boot needs ATF BL31"
... as it already exists ...

choice
prompt "U-Boot ATF BL31 format" default BR2_TARGET_UBOOT_NEEDS_ATF_BL31_BIN

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_BIN

	bool "bl31.bin"
Quoted 8 lines

config BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF

	bool "bl31.elf"

endchoice

And then use that in both arm-trusted-firmware.mk and uboot.mk.

What do you think ?

This is definately better option. And it even looks I won't have to change anything other than uboot's Config.in.

I was also thinking to delete this line when elf is used:

Quoted 1 line

cp -dpf $(ARM_TRUSTED_FIRMWARE_IMG_DIR)/*.bin $(BINARIES_DIR)/

But since it's wildcard I'd leave it as is. This will cause bl31.bin to be copied to $BINARIES_DIR alongside with bl31.elf, but it may be possible someone will need to have, let's say bl31.elf but bl32.bin, and removing this line would takie this option away from him.

I will prepare new patch shortly.

#5 lore raw

PATCH v2 1/1 uboot: add support for bundling ATF BL31 in ELF format into U-Boot

In reply to Michał Łyszczek

Hello,

Quoted 9 lines · Micha? ?yszczek

Rockchip's rk3328 encapsulates the BL31 part of ATP but it needs image in ELF format. This is extension to 2c4809e6088660dc71de9de8cee0bba312aafbe4

This commit introduces a BR2_TARGET_UBOOT_NEEDS_ATF_BL31_ELF variable to achieve this.

Another small comment: there is no need to have your own Tested-by. Indeed, when you send a patch, we expect that you have tested it :-)

Tested-by are useful when other people than the patch author give their Tested-by.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com