How to pack new U-Boot to FIP.BIN?

I’m creating PostmarketOS aport for MilkV-Duo and want to run mainline u-boot on my board.
How can i pack U-Boot to fip.bin?

Tried:

fiptool.py -v genfip \
  'duo-buildroot-sdk/fsbl/build/cv1800b_milkv_duo_sd/fip.bin'  \
  --MONITOR_RUNADDR="0x0000000080000000" \
  --BLCP_2ND_RUNADDR="0x0000000080000000" \
  --CHIP_CONF='duo-buildroot-sdk/fsbl/build/cv1800b_milkv_duo_sd/chip_conf.bin' \
  --NOR_INFO='FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' \
  --NAND_INFO='00000000'\
  --BL2='duo-buildroot-sdk/fsbl/build/cv1800b_milkv_duo_sd/bl2.bin' \
  --BLCP_IMG_RUNADDR=0x05200200 \
  --BLCP_PARAM_LOADADDR=0 \
  --BLCP=test/empty.bin \
  --DDR_PARAM='test/cv181x/ddr_param.bin' \
  --BLCP_2ND='duo-buildroot-sdk/freertos/cvitek/install/bin/cvirtos.bin' \
  --MONITOR='duo-buildroot-sdk/opensbi/build/platform/generic/firmware/fw_dynamic.bin' \
  --LOADER_2ND='u-boot/u-boot-dtb.bin'  \
  --compress='lzma'

But there are error:

ValueError: loader_2nd's magic should be b'BL33', but b'\x93\x01\x00\x00'
1 Like

Apply my patch which I have used successfully on U-Boot v2024.10-rc2 and v2024.07.

diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S
index 8e58f641f1..a0eb7dc95e 100644
--- a/arch/riscv/cpu/start.S
+++ b/arch/riscv/cpu/start.S
@@ -39,6 +39,8 @@ secondary_harts_relocation_error:
 .section .text
 .globl _start
 _start:
+#include <asm/boot0.h>
+_start_real:
 #if CONFIG_IS_ENABLED(RISCV_MMODE)
 	csrr	a0, CSR_MHARTID
 #endif
diff --git a/arch/riscv/include/asm/boot0.h b/arch/riscv/include/asm/boot0.h
new file mode 100644
index 0000000000..d547c19f03
--- /dev/null
+++ b/arch/riscv/include/asm/boot0.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CVITEK u-boot header
+ */
+
+#ifndef __BOOT0_H__
+#define __BOOT0_H__
+
+/* BOOT0 header information */
+	j boot0_time_recode
+	.balign 4
+	.word 0x33334c42  /* b'BL33' */
+	.word 0xdeadbeea  /* CKSUM */
+	.word 0xdeadbeeb  /* SIZE */
+#ifdef CONFIG_SPL_BUILD
+	.quad	CONFIG_SPL_TEXT_BASE
+#else
+	.quad   CONFIG_TEXT_BASE
+#endif
+	.word 0xdeadbeec
+	.balign 4
+	j boot0_time_recode
+	.balign 4
+/* BOOT0 header end */
+boot0_time_recode:
+	csrr x1, time
+	la x2, BOOT0_START_TIME
+	sw x1, 0(x2)
+	j _start_real
+
+	.global BOOT0_START_TIME
+BOOT0_START_TIME:
+	.word 0
+
+#endif /* __BOOT0_H__ */

It’s not an optimal solution but it does work. One rebuilt, pack the patched u-boot into fip.bin:

--LOADER_2ND='u-boot/u-boot.bin'
2 Likes