From 1e61b60cf8916866289237c5c3d4e71d80e7765d Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Fri, 7 Apr 2023 12:58:50 +0200 Subject: [PATCH] `orangepizero2`/`sun50iw9`/`legacy`: implement `pre_package_kernel_image` hook to convert vmlinuz to uImage manually; fix legacy u-boot build - sourceaddr `0x40008000` was found in Xunlong's legacy kernel source squashed into a huge commit. Thanks, Xunlong! - bring `busybox` dependency with inline hook for legacy u-boot "unix2dos" which is essential --- config/boards/orangepizero2.conf | 7 ++-- config/bootscripts/boot-sun50iw9.cmd | 1 + config/sources/families/sun50iw9.conf | 55 ++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/config/boards/orangepizero2.conf b/config/boards/orangepizero2.conf index 92c1235326..edce20b5f6 100644 --- a/config/boards/orangepizero2.conf +++ b/config/boards/orangepizero2.conf @@ -12,15 +12,14 @@ PACKAGE_LIST_BOARD="rfkill bluetooth bluez bluez-tools" FORCE_BOOTSCRIPT_UPDATE="yes" function post_family_tweaks_bsp__orangepizero2_BSP() { - display_alert "Installing BSP firmware and fixups" + display_alert "Installing BSP firmware and fixups" + : "${destination:?}" if [[ $BRANCH == legacy ]]; then - # Bluetooth for most of others (custom patchram is needed only in legacy) install -m 755 $SRC/packages/bsp/rk3399/brcm_patchram_plus_rk3399 $destination/usr/bin cp $SRC/packages/bsp/rk3399/rk3399-bluetooth.service $destination/lib/systemd/system/ - fi return 0 -} \ No newline at end of file +} diff --git a/config/bootscripts/boot-sun50iw9.cmd b/config/bootscripts/boot-sun50iw9.cmd index 959f75ff23..c55a656f94 100644 --- a/config/bootscripts/boot-sun50iw9.cmd +++ b/config/bootscripts/boot-sun50iw9.cmd @@ -61,6 +61,7 @@ for overlay_file in ${user_overlays}; do fi done +# Legacy uboot, requires uImage - see pre_package_kernel_image__orangepi_legacy_uImage_manual_conversion() load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}uImage diff --git a/config/sources/families/sun50iw9.conf b/config/sources/families/sun50iw9.conf index 44e74af264..0f67fc8cdb 100644 --- a/config/sources/families/sun50iw9.conf +++ b/config/sources/families/sun50iw9.conf @@ -16,12 +16,27 @@ case $BRANCH in legacy) + # Legacy kernel LINUXFAMILY=sun50iw9 KERNELSOURCE='https://github.com/orangepi-xunlong/linux-orangepi.git' declare -g KERNEL_MAJOR_MINOR="4.9" # Major and minor versions of this kernel. KERNELBRANCH="branch:orange-pi-4.9-sun50iw9" KERNELPATCHDIR=${BOARDFAMILY}-${BRANCH} KERNELDIR='linux-orangepi' + INITRD_ARCH=arm + ASOUND_STATE='asound.state.sun50iw9-legacy' + + # This (legacy/vendor) kernel requires uImage manual conversion; do it via a 'pre_package_kernel_image' hook. + function pre_package_kernel_image__orangepi_legacy_uImage_manual_conversion() { + display_alert "Converting" "${BOARDFAMILY} - ${LINUXFAMILY} :: legacy :: uImage" "warn" + if [[ -z "${kernel_image_pre_package_path}" || ! -f "${kernel_image_pre_package_path}" ]]; then + exit_with_error "kernel_image_pre_package_path ('${kernel_image_pre_package_path}') is not set or does not exist" + fi + run_host_command_logged mkimage -A arm -O linux -T kernel -C none -a "'0x40008000'" -e "'0x40008000'" -n "'Linux kernel'" -d "${kernel_image_pre_package_path}" "${kernel_image_pre_package_path}.uImage.tmp" + run_host_command_logged mv -v "${kernel_image_pre_package_path}.uImage.tmp" "${kernel_image_pre_package_path}" + } + + # Legacy u-boot BOOTSOURCE='https://github.com/orangepi-xunlong/u-boot-orangepi.git' BOOTBRANCH='branch:v2018.05-sun50iw9' BOOTPATCHDIR="legacy" @@ -34,9 +49,6 @@ case $BRANCH in OFFSET=20 ATFSOURCE="" ATF_COMPILE="no" - INITRD_ARCH=arm - - ASOUND_STATE='asound.state.sun50iw9-legacy' # this overrides the one in sunxi64_common.inc function write_uboot_platform() { @@ -56,6 +68,12 @@ case $BRANCH in ;; esac +# This build requires busybox (and dos2unix) +function add_host_dependencies__sunxi_add_32_bit_c_compiler() { + display_alert "Adding busybox dep" "for ${BOARD} bootloader compile" "debug" + declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} busybox" +} + function family_tweaks_s() { if [[ -f $SDCARD/lib/systemd/system/aw859a-bluetooth.service ]]; then # Enable Bluetooth @@ -82,18 +100,45 @@ function family_tweaks_bsp() { function uboot_custom_postprocess() { if [[ ${BRANCH} == legacy ]]; then display_alert "Post-processing U-Boot" "$BOARD - $BRANCH" "info" - run_host_command_logged cp -pv ${SRC}/packages/pack-uboot/${BOARDFAMILY}/bin/* . -r + # "Vendor" code (by Igor) is at https://raw.githubusercontent.com/orangepi-xunlong/orangepi-build/main/external/config/sources/families/sun50iw9.conf + + run_host_command_logged rm -rfv dts/*.dts sys_config ${BOARD}-u-boot.dtb + + run_host_command_logged cp -rpv ${SRC}/packages/pack-uboot/${BOARDFAMILY}/bin/* . + run_host_command_logged cp -pv sys_config/sys_config_${BOARD}.fex sys_config.fex run_host_command_logged cp -pv u-boot.bin u-boot.fex + + # [[ ${BOARD} =~ orangepizero2-b|orangepizero2-lts ]] && run_host_command_logged mv -v boot0_sdcard_new.fex boot0_sdcard.fex # From vendor code, they have multiple of those boards + + # make u-boot dtb run_host_command_logged dtc -p 2048 -W no-unit_address_vs_reg -@ -O dtb -o ${BOARD}-u-boot.dtb -b 0 dts/${BOARD}-u-boot.dts + [[ ! -f "${BOARD}-u-boot.dtb" ]] && exit_with_error "dts compilation failed for ${BOARD}-u-boot.dtb" + + run_host_command_logged busybox unix2dos sys_config.fex + run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/script sys_config.fex run_host_command_logged cp -pv ${BOARD}-u-boot.dtb sunxi.fex + run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/update_dtb sunxi.fex 4096 run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/update_boot0 boot0_sdcard.fex sys_config.bin SDMMC_CARD - # @TODO: rpardini: this looks wrong + + # rpardini: this looks wrong, but isn't. look at vendor code. run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/update_uboot -no_merge u-boot.fex sys_config.bin run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/update_uboot -no_merge u-boot.bin sys_config.bin + + #pack boot package + run_host_command_logged busybox unix2dos boot_package.cfg run_host_command_logged $SRC/packages/pack-uboot/${BOARDFAMILY}/tools/dragonsecboot -pack boot_package.cfg + + # From vendor code, we never had this. + #if [[ ${MERGE_UBOOT} == yes ]]; then + # display_alert "Merge u-boot" "u-boot-${BOARD}-merged.bin" "info" + # dd if=/dev/zero of=u-boot-${BOARD}-merged.bin bs=1M count=20 > /dev/null 2>&1 + # dd if=boot0_sdcard.fex of=u-boot-${BOARD}-merged.bin bs=8k seek=1 conv=fsync > /dev/null 2>&1 + # dd if=boot_package.fex of=u-boot-${BOARD}-merged.bin bs=8k seek=2050 conv=fsync > /dev/null 2>&1 + # mv u-boot-${BOARD}-merged.bin ${DEB_STORAGE}/u-boot/ + #fi fi return 0