From 1c08ff3277d47979c7897842ba683c23aa8197f7 Mon Sep 17 00:00:00 2001 From: Salman Nabi Date: Thu, 12 Dec 2024 17:38:54 +0000 Subject: [PATCH] feat(arm): add initrd props to dtb at build time Add initrd properties to the device tree blob at build time, giving users the ability to run a linux kernel and successfully boot it to the terminal. Users can boot a linux kernel in a normal flow as well as in RESET_TO_BL31. This function is an extension of the build time option "ARM_LINUX_KERNEL_AS_BL33=1". The build time options INITRD_SIZE or INITRD_PATH will trigger the insertion of initrd properties in to the DTB. If both options are provided then the INITRD_SIZE will take precedence. The available options are: INITRD_SIZE: Provide the initrd size in dec or hex (hex format must precede with '0x'. Example: INITRD_SIZE=0x1000000 INITRD_PATH: Provide an initrd path for the build time to find its exact size. INITRD_BASE: A required build time option that sets the initrd base address in hex format. A default value can be set by the platform. Example: INITRD_BASE=0x90000000 Change-Id: Ief8de5f00c453509bcc6e978e0a95d768f1f509c Signed-off-by: Salman Nabi --- Makefile | 15 +++++++++++++++ make_helpers/build_macros.mk | 1 + plat/arm/board/fvp/platform.mk | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 413ce46be..26636c8c9 100644 --- a/Makefile +++ b/Makefile @@ -1638,6 +1638,21 @@ endif #(NEED_BL2U) # Expand build macros for the different images ifeq (${NEED_FDT},yes) $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES))) + + ifneq (${INITRD_SIZE}${INITRD_PATH},) + ifndef INITRD_BASE + $(error INITRD_BASE must be set when inserting initrd properties to the DTB.) + endif + + INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH))) + initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE))))) + + define $(HW_CONFIG)-after += + $(s)echo " INITRD $(HW_CONFIG)" + $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE) + $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end) + endef + endif endif #(NEED_FDT) # Add Secure Partition packages diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index b1b299cd9..aa1675193 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -604,6 +604,7 @@ $(DPRE): $(2) | $$$$(@D)/ $(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ $$(s)echo " DTC $$<" $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< + $$($$@-after) -include $(DTBDEP) -include $(DTSDEP) diff --git a/plat/arm/board/fvp/platform.mk b/plat/arm/board/fvp/platform.mk index 1dd0b4930..5472a327e 100644 --- a/plat/arm/board/fvp/platform.mk +++ b/plat/arm/board/fvp/platform.mk @@ -367,6 +367,10 @@ FVP_HW_CONFIG_DTS := fdts/${FVP_DT_PREFIX}.dts FDT_SOURCES += ${FVP_HW_CONFIG_DTS} $(eval FVP_HW_CONFIG := ${BUILD_PLAT}/$(patsubst %.dts,%.dtb,$(FVP_HW_CONFIG_DTS))) +HW_CONFIG := ${FVP_HW_CONFIG} + +# Set default initrd base 128MiB offset of the default kernel address in FVP +INITRD_BASE ?= 0x90000000 ifeq (${TRANSFER_LIST}, 0) FDT_SOURCES += $(addprefix plat/arm/board/fvp/fdts/, \ @@ -419,7 +423,6 @@ ifeq (${TRANSFER_LIST}, 1) include lib/transfer_list/transfer_list.mk ifeq ($(RESET_TO_BL31), 1) -HW_CONFIG := ${FVP_HW_CONFIG} FW_HANDOFF_SIZE := 20000 TRANSFER_LIST_DTB_OFFSET := 0x20