milkv-duo启动流程分析:手动构建fip.bin [2/2]

手动合成fip.bin和boot.sd [2/2]

编译FSBL

编译FSBL是为了得到bl2.bin。注意到我们需要配置一些参数:

ARCH ?=

ifneq ($(origin CROSS_COMPILE),command line)
ifeq ($(ARCH),riscv)
CROSS_COMPILE := ${CROSS_COMPILE_GLIBC_RISCV64}
BOOT_CPU ?= riscv
else
CROSS_COMPILE := ${CROSS_COMPILE_64}
BOOT_CPU := aarch64
ARCH := aarch64
endif
endif

ifeq (${CHIP_ARCH},)
$(error CHIP_ARCH is undefined)
endif

ifeq (${CROSS_COMPILE},)
$(error CROSS_COMPILE is undefined)
endif

我们需要

make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-musl- BOOT_CPU=riscv CHIP_ARCH=cv180x PROJECT_FULLNAME=cv1800b_milkv_duo_sd bl2

此时又报错:

lib/cpu/riscv/bl2_entrypoint.S: Assembler messages:
lib/cpu/riscv/bl2_entrypoint.S:60: Error: unknown CSR `mxstatus'
lib/cpu/riscv/bl2_entrypoint.S:69: Error: unknown CSR `mcor'
lib/cpu/riscv/bl2_entrypoint.S:71: Error: unknown CSR `mcor'
lib/cpu/riscv/bl2_entrypoint.S:74: Error: unknown CSR `mhcr'
lib/cpu/riscv/bl2_entrypoint.S:77: Error: unknown CSR `mcor'
lib/cpu/riscv/bl2_entrypoint.S:79: Error: unknown CSR `mcor'
lib/cpu/riscv/bl2_entrypoint.S:82: Error: unknown CSR `mhcr'
make: *** [Makefile:195: build/cv180x/bl2/bl2_entrypoint.o] Error 1

打开lib/cpu/riscv/bl2_entrypoint.S,在头部添加

#define mxstatus 0x7c0
#define mhcr 0x7c1
#define mcor 0x7c2

问题解决。继续,又碰到riscv64-buildroot-linux-musl-ld: warning: build/cv180x/bl2/bl2.elf has a LOAD segment with RWX permissions。直接禁用掉--fatal-warnings。修改lib/cpu/riscv/cpu.mk

ASFLAGS +=\
$(CPPFLAGS) \
-DRISCV \
-D__ASSEMBLY__ \
-march=rv64imafdc -mstrict-align \
-mcmodel=medany \
-mabi=lp64d \
-ffreestanding  \
-Wa

TF_LDFLAGS += \
-Os \
--gc-sections \
${TF_LDFLAGS_aarch64}

问题解决,在build/cv180x下可发现bl2.bin

riscv64-buildroot-linux-musl-ld: warning: build/cv180x/bl2/bl2.elf has a LOAD segment with RWX permissions
  BIN     build/cv180x/bl2.bin
riscv64-buildroot-linux-musl-objcopy -O binary build/cv180x/bl2/bl2.elf build/cv180x/bl2.bin

Built build/cv180x/bl2.bin successfully

  SYM     build/cv180x/bl2/bl2.sym
riscv64-buildroot-linux-musl-readelf -s build/cv180x/bl2/bl2.elf | sort -b -r -g -k 3 > build/cv180x/bl2/bl2.sym
  OD      build/cv180x/bl2/bl2.dis
riscv64-buildroot-linux-musl-objdump -dx build/cv180x/bl2/bl2.elf > build/cv180x/bl2/bl2.dis
  TARGET bl2

制作fip.bin

制作chip_conf.bin

进入fsbl/plat/cv180x/chip_conf.py,执行./chip_conf.py chip_conf.bin

ddr_param.bin

此二进制文件位于test/cv181x/ddr_param.bin,没有关于其的更多信息。

fiptool.py

使用以下脚本可以使用fiptool.py脚本生成需要的二进制文件。

mkdir fip-play
cp fsbl/build/cv180x/bl2.bin fip-play/
cp fsbl/plat/cv180x/chip_conf.bin fip-play/
cp fsbl/plat/cv180x/fiptool.py
cp fsbl/test/cv181x/ddr_param.bin fip-play/
cp opensbi/build/platform/generic/firmware/fw_dynamic.bin fip-play/
cp u-boot/u-boot.bin fip-play/

./fiptool.py genfip fip.bin \
    --MONITOR_RUNADDR=0x80000000 \
    --CHIP_CONF=chip_conf.bin \
    --NOR_INFO=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF \
    --NAND_INFO=00000000 \
    --BL2=bl2.bin \
    --BLCP_IMG_RUNADDR=0x05200200 \
    --BLCP_PARAM_LOADADDR=0 \
    --DDR_PARAM=ddr_param.bin \
    --MONITOR=fw_dynamic.bin \
    --LOADER_2ND=u-boot.bin

此时,目录下出现了fip.bin。上电,已经可以成功进入u-boot。

posted @ 2023-10-15 19:22  可爱无辜猫猫头  阅读(193)  评论(0编辑  收藏  举报