Skip to content

Commit

Permalink
rockpro64: bump u-boot to v2024.04-rc4; use binman-produced bins
Browse files Browse the repository at this point in the history
- `mmc-sdhci-allow-disabling-sdma-in-spl.patch` has landed in u-boot/u-boot@3cd664d
- remove `CONFIG_SPL_MMC_SDHCI_SDMA=n`, as fix has landed in u-boot/u-boot@3b804b3 (thanks Kwiboo for the pointer)
- use binman-produced binaries
- use `flashcp -p` to write fast to spi
- bump ATF (TF-A) to lts-v2.8.16
- configure /etc/fw_env.config userspace to SPI env coordinates
  - configure /etc/fw_env.config userspace to SPI env coordinates
  - include libubootenv-tool userspace for fw_printenv and fw_setenv
- use `bs=32k seek=1` instead of `seek=64` suggested by Kwiboo (thanks!) for speedy writing
- add a check for the u-boot.bin size (992KiB) suggested by Kwiboo (thanks!)
  - really a close call: we're at 994.920 bytes right now

Signed-off-by: Ricardo Pardini <[email protected]>
Co-authored-by: Jonas Karlman <[email protected]>
  • Loading branch information
rpardini and Kwiboo committed Mar 30, 2024
1 parent 9905082 commit 8d426f6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 80 deletions.
66 changes: 55 additions & 11 deletions config/boards/rockpro64.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,73 @@ BOOT_LOGO="desktop"
BOOT_SCENARIO="blobless"
BOOT_SUPPORT_SPI=yes

# u-boot 2023.01 for rockpro64
BOOTBRANCH_BOARD="tag:v2023.01"
BOOTPATCHDIR="v2023.01"
# u-boot v2024.04-rc4 for rockpro64
BOOTBRANCH_BOARD="tag:v2024.04-rc4"
BOOTPATCHDIR="v2024.04"

# Include fw_setenv, configured to point to the correct spot on the SPI Flash
PACKAGE_LIST_BOARD="libubootenv-tool" # libubootenv-tool provides fw_printenv and fw_setenv, for talking to U-Boot environment

function add_host_dependencies__new_uboot_wants_python3_rockpro64() {
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} python3-pyelftools" # @TODO: convert to array later
}

function post_family_config__hacks_for_new_uboot_rockpro64() {
display_alert "$BOARD" "using ATF (blobless) for 2023.01 u-boot" "info"
function post_family_config__use_mainline_uboot_rockpro64() {
# Use latest lts 2.8 ATF
ATFBRANCH='tag:lts-v2.8.8'
ATFBRANCH='tag:lts-v2.8.16'
ATFPATCHDIR="atf-rockchip64" # patches for logging etc
# With recent-enough u-boot and ATF.
# bl31.elf is copied directly from ATF build dir to uboot dir anyway.
UBOOT_TARGET_MAP="BL31=bl31.elf;;idbloader.img u-boot.itb tpl/u-boot-tpl.bin spl/u-boot-spl.bin u-boot.itb rkspi_loader.img"
display_alert "$BOARD" "using ATF (blobless) ${ATFBRANCH} for ${BOOTBRANCH_BOARD} u-boot" "info"
# bl31.elf is copied directly from ATF build dir to uboot dir (by armbian u-boot build system)
UBOOT_TARGET_MAP="BL31=bl31.elf;;u-boot-rockchip.bin u-boot-rockchip-spi.bin"

# Ignore most of the rockchip64_common stuff, we're using binman here which does all the work already
unset uboot_custom_postprocess write_uboot_platform write_uboot_platform_mtd

function write_uboot_platform() {
dd "if=$1/u-boot-rockchip.bin" "of=$2" bs=32k seek=1 conv=notrunc status=none
}

function write_uboot_platform_mtd() {
flashcp -v -p "$1/u-boot-rockchip-spi.bin" /dev/mtd0
}
}

# From Kwiboo:
# ... "note that u-boot mainline for rk3328/rk3399 suffers from a limitation in that the u-boot.bin may not exceed 1000 KiB or the stack may overwrite part of it during runtime, resulting in strange unexplained issues.
# This has been fixed in current U-Boot next branch with https://github.com/u-boot/u-boot/commit/5e7cd8a119953dc2f466fea81e230d683ee03493 and should be included with v2024.07-rc1
# If your u-boot.bin build output is less than 950 KiB in size you should not suffer from this limitation/issue."
# ... "The real limit will be at most 1 MiB - 16 KiB (malloc heap on stack) = 1008 KiB and any additional runtime usage of the stack will take up until U-Boot has been relocated to top of RAM,
# lets say an additional 16 KiB (same as malloc heap) to be on the safer side, so I would suggest you check for e.g. < 992 KiB or similar instead of < 1 MiB.
# As long as the generated u-boot.bin is < 992 KiB I think it should be safe, and I do not think the stack usage will be that much before relocation so < 1000 KiB may also be fine 😎"
# rpardini: close call; the u-boot.bin is 994920 bytes. Let's check for >992KiB and break the build if it's too large.
function post_uboot_custom_postprocess__check_bin_size_less_than_992KiB() {
declare one_bin
declare -i uboot_bin_size
declare -a bins_to_check=("u-boot.bin")
for one_bin in "${bins_to_check[@]}"; do
uboot_bin_size=$(stat -c %s "${one_bin}")
display_alert "Checking u-boot ${BOARD} bin size" "'${one_bin}' is less than 992KiB (1015808 bytes): ${uboot_bin_size} bytes" "info"
if [[ ${uboot_bin_size} -ge 1015808 ]]; then
display_alert "u-boot for ${BOARD}" "'${one_bin}' is larger than 992KiB (1015808 bytes): ${uboot_bin_size} bytes" "err"
exit_with_error "u-boot ${BOARD} bin size check failed"
fi
done
}

function post_config_uboot_target__extra_configs_for_rockpro64() {
# Taken from https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/blob/master/PKGBUILD
display_alert "$BOARD" "u-boot configs for 2023.01 u-boot config" "info"
display_alert "$BOARD" "u-boot configs for ${BOOTBRANCH_BOARD} u-boot config" "info"
run_host_command_logged scripts/config --set-val CONFIG_OF_LIBFDT_OVERLAY "y"
run_host_command_logged scripts/config --set-val CONFIG_SPL_MMC_SDHCI_SDMA "n"
run_host_command_logged scripts/config --set-val CONFIG_MMC_HS400_SUPPORT "y"
run_host_command_logged scripts/config --set-val CONFIG_USE_PREBOOT "n"
}

function post_family_tweaks__config_rockpro64_fwenv() {
display_alert "Configuring fw_printenv and fw_setenv" "for ${BOARD} and u-boot ${BOOTBRANCH_BOARD}" "info"
# Addresses below come from CONFIG_ENV_OFFSET and CONFIG_ENV_SIZE in https://github.com/u-boot/u-boot/blob/v2024.04-rc4/configs/rockpro64-rk3399_defconfig
cat <<- 'FW_ENV_CONFIG' > "${SDCARD}"/etc/fw_env.config
# MTD on the SPI for the Rockpro64
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd0 0x3F8000 0x8000
FW_ENV_CONFIG
}

This file was deleted.

2 comments on commit 8d426f6

@Tonymac32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpardini have we tried 2024.07 yet? I see u-boot/u-boot@5e7cd8a landed

@rpardini
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't dug the rp64 out of a drawer yet since then -- will do eventually, otherwise feel free!

Please sign in to comment.