../

Rpi_4b

RPI 4B

0x00 Boot config

Stage Filename Description Source
FSBL - Mounts SD and loads SSBL ROM
GPU firmware start4.elf Loads CPU bootloader and boots CPU https://github.com/raspberrypi/firmware/tree/master/boot/start4.elf
Additional GPU firmware fixup4.dat Fixes memory locations used in start4.elf https://github.com/raspberrypi/firmware/tree/master/boot/fixup4.dat
Usually the Linux kernel, but could also be U-Boot u-boot.bin U-Boot binary Compiled using the instructions above
  config.txt U-Boot parameters Add arm_64bit=1 and kernel=u-boot.bin to the bottom of config.txt
还需要指定enable_uart=1以及uart_2ndstage=1
  uboot.env U-Boot saved environment Generated by U-Boot (default environment) bootcmd copied to bootcmd_orig bootcmd and bootdelay removed. This file will not exist when you first setup your SD card.
  bcm2711-rpi-4-b.dtb RPi4 device tree blob https://github.com/raspberrypi/firmware/tree/master/boot/bcm2711-rpi-4-b.dtb
  overlays/* Device tree overlays https://github.com/raspberrypi/firmware/tree/master/boot/overlays

Partition the SD card

# fdisk操作SD卡 根据fdisk提示信息来操作就行了
# /boot / 两个就行
# 所有的启动文件放在boot里面
sudo fdisk /dev/sdb

0x01 GPIO Pinout

[]: https://pinout.xyz/pinout/pin8_gpio14/ “RPI 40 GPIO pinout”

0x02 uboot & kernel

编译源码

git clone git://git.denx.de/u-boot.git
cd u-boot
make CROSS_COMPILE=aarch64-linux-gnu- rpi_4_defconfig
make CROSS_COMPILE=aarch64-linux-gnu-
git clone --depth=1 -b rpi-6.12.y https://github.com/raspberrypi/linux.git
cd linux
make ARCH=arm64 CROSS_COMPILE=aarch64-rpi4-linux-gnu- bcm2711_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-rpi4-linux-gnu- -j12

Boot设置

# boot kernel from uboot
tftpboot ${kernel_addr_r} Image
tftpboot ${fdt_addr_r} bcm2711-rpi-4-b.dtb
booti ${kernel_addr_r} - ${fdt_addr_r}
setenv bootargs 8250.nr_uarts=1 console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait rw fsck.repair=yes 

可以把三个load和启动命令做成脚本自动执行:

# 把命令写入boot.cmd,并且在PC上做成scr脚本
mkimage -A arm64 -O linux -T script -C none -d boot.cmd boot.scr

# 在uboot中用bootcmd来执行脚本
setenv bootcmd "load mmc 0:1 ${scriptaddr} boot.scr; source ${scriptaddr}"
saveenv

问题

1. 启动kenel后停留在starting kernel...

连接HDMI屏幕发现屏幕有打印,应该是串口没被正确设置。在bootargs中添加8250.nr_uarts=1

2. 报错systemd-remount-fs.service fails to remount rootfs as read-write

串口配置好后,发现启动没有进入控制台,检查后发现remount失败了。因为rootfs是从做好的img镜像文件中直接复制的,所以UUID和自己的SD分区UUID不匹配。需要修改/etc/fstab中的配置匹配SD分区

$ blkid
/dev/sdb1: LABEL_FATBOOT="boot" LABEL="boot" UUID="9489-2CD5" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="2ab1dd98-12c4-4f14-8cc4-5182555a9c24"
/dev/sdb2: LABEL="root" UUID="9263d76f-db89-4e1b-95c8-9cce75656338" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="6958800b-7d1c-4941-bdea-5a1ad942258b"
$ cat /etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=2ab1dd98-12c4-4f14-8cc4-5182555a9c24  /boot  vfat    defaults          0       2
PARTUUID=6958800b-7d1c-4941-bdea-5a1ad942258b  /               ext4    defaults,noatime  0       1

3. 用户名密码错误

修改bootargs直接进入bash,在bash中修改并固化

# 进入到bash可以修改密码
setenv bootargs 8250.nr_uarts=1 console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait rw init=/bin/sh

$ passwd pi # pi代表用户名
$ sync
$ exec /sbin/init # 继续启动

0x00 Reference

[]: https://docs.sel4.systems/Hardware/Rpi4.html “rpi4b boot preparation” []: https://hechao.li/posts/Boot-Raspberry-Pi-4-Using-uboot-and-Initramfs/#72-option-2-boot-with-a-permanent-rootfs-directly []: https://lancesimms.com/RaspberryPi/HackingRaspberryPi4WithYocto_Part3.html