With a few changes to ATF it is possible to load and start the linux kernel directly from ATF.
Start with http://github.com/mtk-openwrt/arm-trusted-firmware, the default mtksoc branch.
Apply these patches to ATF:
--- a/plat/mediatek/mt7622/bl2_plat_setup.c 2021-09-15 13:35:58.536925357 +0200
+++ b/plat/mediatek/mt7622/bl2_plat_setup.c 2021-09-15 14:00:52.439937687 +0200
@@ -72,7 +72,21 @@
SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2,
image_info_t, 0),
.image_info.image_base = BL33_BASE,
- .image_info.image_max_size = 0x200000 /* 2MB */,
+ .image_info.image_max_size = 0x1000000 /* 16MB */,
+
+#ifdef PRELOADED_BL33_BASE
+ .next_handoff_image_id = NT_FW_CONFIG_ID,
+ },
+ /* Fill NT_FW_CONFIG related information */
+ {
+ .image_id = NT_FW_CONFIG_ID,
+ SET_STATIC_PARAM_HEAD(ep_info, PARAM_IMAGE_BINARY,
+ VERSION_2, entry_point_info_t, NON_SECURE | NON_EXECUTABLE),
+ SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
+ VERSION_2, image_info_t, 0),
+ .image_info.image_base = BL32_BASE,
+ .image_info.image_max_size = BL32_LIMIT,
+#endif
.next_handoff_image_id = INVALID_IMAGE_ID,
}
@@ -126,6 +140,10 @@
.uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
};
+static const io_uuid_spec_t ntfwconf_uuid_spec = {
+ .uuid = UUID_NT_FW_CONFIG,
+};
+
static const io_uuid_spec_t bl32_uuid_spec = {
.uuid = UUID_SECURE_PAYLOAD_BL32,
};
@@ -183,6 +201,11 @@
(uintptr_t)&bl31_uuid_spec,
check_fip
},
+ [NT_FW_CONFIG_ID] = {
+ &fip_dev_handle,
+ (uintptr_t)&ntfwconf_uuid_spec,
+ check_fip
+ },
[BL32_IMAGE_ID] = {
&fip_dev_handle,
(uintptr_t)&bl32_uuid_spec,
We need to compile setting PRELOADED_BL33_BASE (use it as a switch to build with or without the changed code).
--- a/plat/mediatek/mt7622/bl31_plat_setup.c 2021-09-15 13:35:58.536925357 +0200
+++ b/plat/mediatek/mt7622/bl31_plat_setup.c 2021-09-15 13:54:41.122386656 +0200
@@ -99,6 +99,13 @@
bl33_ep_info.pc = BL33_BASE;
bl33_ep_info.spsr = plat_get_spsr_for_bl33_entry();
SET_SECURITY_STATE(bl33_ep_info.h.attr, NON_SECURE);
+
+#ifdef PRELOADED_BL33_BASE
+ bl33_ep_info.args.arg0 = (u_register_t)BL32_BASE;
+ bl33_ep_info.args.arg1 = 0U;
+ bl33_ep_info.args.arg2 = 0U;
+ bl33_ep_info.args.arg3 = 0U;
+#endif
}
/*******************************************************************************
Kernel .dts needs a fix:
--- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-09-15 09:27:26.875953005 +0200
+++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-09-15 09:23:25.597138058 +0200
@@ -70,6 +70,7 @@
};
memory {
+ device_type = "memory";
reg = <0 0x40000000 0 0x40000000>;
};
And finally we need to edit the bootargs inside the dts, as U-Boot does not change this anymore for us:
bootargs = "console=ttyS0,115200 rw rootwait root=PARTLABEL=root-bpir64-sdmmc";
Now build a fip image like this:
atf/tools/fiptool/fiptool --verbose create fip.bin \
--soc-fw bl31.bin \
--nt-fw linux/arch/arm64/boot/Image \
--nt-fw-config linux/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dtb
And that is about it…
All changes are also found in my buildscript, it is now set as default: