diff --git a/config/boards/tinkerboard.conf b/config/boards/tinkerboard.conf index 0486aee73f..6f477b604f 100644 --- a/config/boards/tinkerboard.conf +++ b/config/boards/tinkerboard.conf @@ -9,3 +9,25 @@ KERNEL_TARGET="current,edge" KERNEL_TEST_TARGET="current" FULL_DESKTOP="yes" BOOT_SOC="rk3288" + +function tinkerboard_uboot_postinst(){ + [[ $DEVICE == /dev/null ]] && exit 0 + if [[ -z $DEVICE ]]; then + DEVICE="/dev/mmcblk0" + # proceed to other options. + [ ! -b $DEVICE ] && DEVICE="/dev/mmcblk1" + [ ! -b $DEVICE ] && DEVICE="/dev/mmcblk2" + fi + [[ $(type -t setup_write_uboot_platform) == function ]] && setup_write_uboot_platform + if [[ -b $DEVICE ]]; then + echo "Updating u-boot on $DEVICE" >&2 + write_uboot_platform $DIR $DEVICE + sync + else + echo "Device $DEVICE does not exist, skipping" >&2 + fi +} + +function pre_package_uboot_image__tinkerboard_update_uboot_postinst_script(){ + postinst_functions+=('tinkerboard_uboot_postinst') +} diff --git a/config/sources/families/meson-s4t7.conf b/config/sources/families/meson-s4t7.conf index c08c5e8f6b..cb79fd24da 100644 --- a/config/sources/families/meson-s4t7.conf +++ b/config/sources/families/meson-s4t7.conf @@ -32,6 +32,7 @@ BOOTPATCHDIR="u-boot-meson-s4t7" BOOTENV_FILE='meson.txt' BOOTSCRIPT="boot-meson-s4t7.cmd:boot.cmd" FORCE_BOOTSCRIPT_UPDATE="yes" +FORCE_UBOOT_UPDATE="yes" UBOOT_TARGET_MAP=";;fip/_tmp/u-boot.bin.sd.bin.signed:u-boot.bin.sd.bin.signed" ## funny enough, the uboot+fip blobs go in the same spot as normal meson64... diff --git a/lib/functions/artifacts/artifact-uboot.sh b/lib/functions/artifacts/artifact-uboot.sh index 97db4e8406..84ce63fa95 100644 --- a/lib/functions/artifacts/artifact-uboot.sh +++ b/lib/functions/artifacts/artifact-uboot.sh @@ -74,7 +74,7 @@ function artifact_uboot_prepare_version() { # Hash the extension hooks declare -a extension_hooks_to_hash=( "post_uboot_custom_postprocess" "fetch_custom_uboot" "build_custom_uboot" - "pre_config_uboot_target" "post_config_uboot_target" + "pre_config_uboot_target" "post_config_uboot_target" "pre_package_uboot_image" ) declare -a extension_hooks_hashed=("$(dump_extension_method_sources_functions "${extension_hooks_to_hash[@]}")") declare hash_hooks="undetermined" diff --git a/lib/functions/bsp/armbian-bsp-cli-deb.sh b/lib/functions/bsp/armbian-bsp-cli-deb.sh index 4d14c5adc8..4d0e3ab1ee 100644 --- a/lib/functions/bsp/armbian-bsp-cli-deb.sh +++ b/lib/functions/bsp/armbian-bsp-cli-deb.sh @@ -103,6 +103,7 @@ function compile_armbian-bsp-cli() { INITRD_ARCH=$INITRD_ARCH KERNEL_IMAGE_TYPE=$KERNEL_IMAGE_TYPE FORCE_BOOTSCRIPT_UPDATE=$FORCE_BOOTSCRIPT_UPDATE + FORCE_UBOOT_UPDATE=$FORCE_UBOOT_UPDATE VENDOR="$VENDOR" VENDORDOCS="$VENDORDOCS" VENDORURL="$VENDORURL" diff --git a/lib/functions/compilation/uboot.sh b/lib/functions/compilation/uboot.sh index 7cd2c086cf..70fddd412f 100644 --- a/lib/functions/compilation/uboot.sh +++ b/lib/functions/compilation/uboot.sh @@ -368,30 +368,18 @@ function compile_uboot() { display_alert "Preparing u-boot general packaging" "${version} ${target_make}" - # set up postinstall script # @todo: extract into a tinkerboard extension - if [[ $BOARD == tinkerboard ]]; then - cat <<- EOF > "$uboottempdir/DEBIAN/postinst" - #!/bin/bash - source /usr/lib/u-boot/platform_install.sh - [[ \$DEVICE == /dev/null ]] && exit 0 - if [[ -z \$DEVICE ]]; then - DEVICE="/dev/mmcblk0" - # proceed to other options. - [ ! -b \$DEVICE ] && DEVICE="/dev/mmcblk1" - [ ! -b \$DEVICE ] && DEVICE="/dev/mmcblk2" - fi - [[ \$(type -t setup_write_uboot_platform) == function ]] && setup_write_uboot_platform - if [[ -b \$DEVICE ]]; then - echo "Updating u-boot on \$DEVICE" >&2 - write_uboot_platform \$DIR \$DEVICE - sync - else - echo "Device \$DEVICE does not exist, skipping" >&2 - fi - exit 0 - EOF - chmod 755 "$uboottempdir/DEBIAN/postinst" - fi + local -a postinst_functions=() + local destination=$uboottempdir + + call_extension_method "pre_package_uboot_image" <<- 'PRE_PACKAGE_UBOOT_IMAGE' + *allow making some last minute changes before u-boot is packaged* + This should be implemented by the config to tweak the uboot package, after the board or family has had the chance to. + You can write to `$destination` here and it will be packaged. + You can also append to the `postinst_functions` array, and the _content_ of those functions will be added to the postinst script. + PRE_PACKAGE_UBOOT_IMAGE + + artifact_package_hook_helper_board_side_functions "postinst" uboot_postinst_base "${postinst_functions[@]}" + unset uboot_postinst_base postinst_functions destination # declare -f on non-defined function does not do anything (but exits with errors, so ignore them with "|| true") cat <<- EOF > "$uboottempdir/usr/lib/u-boot/platform_install.sh" @@ -434,3 +422,21 @@ function compile_uboot() { display_alert "Built u-boot deb OK" "linux-u-boot-${BOARD}-${BRANCH} ${artifact_version}" "info" return 0 # success } + +function uboot_postinst_base() { + # Source the armbian-release information file + [ -f /etc/armbian-release ] && . /etc/armbian-release + source /usr/lib/u-boot/platform_install.sh + + if [ "${FORCE_UBOOT_UPDATE:-no}" == "yes" ]; then + #recognize_root + root_uuid=$(sed -e 's/^.*root=//' -e 's/ .*$//' < /proc/cmdline) + root_partition=$(blkid | tr -d '":' | grep "${root_uuid}" | awk '{print $1}') + root_partition_name=$(echo $root_partition | sed 's/\/dev\///g') + root_partition_device_name=$(lsblk -ndo pkname $root_partition) + root_partition_device=/dev/$root_partition_device_name + + write_uboot_platform "$DIR" "${root_partition_device}" + sync + fi +}