From ed36718a63e746c563066ac72c4463ac5cd8a579 Mon Sep 17 00:00:00 2001 From: spycat88 Date: Mon, 8 Apr 2024 23:45:57 +0100 Subject: [PATCH] Rockchip: make bash scripting easier to read --- projects/Rockchip/bootloader/canupdate.sh | 9 --- projects/Rockchip/bootloader/install | 74 +++++++------------- projects/Rockchip/bootloader/mkimage | 65 ++++++++--------- projects/Rockchip/bootloader/release | 13 ++-- projects/Rockchip/bootloader/update.sh | 8 +-- projects/Rockchip/packages/u-boot/package.mk | 24 +++---- 6 files changed, 71 insertions(+), 122 deletions(-) delete mode 100755 projects/Rockchip/bootloader/canupdate.sh diff --git a/projects/Rockchip/bootloader/canupdate.sh b/projects/Rockchip/bootloader/canupdate.sh deleted file mode 100755 index b9b32ca91..000000000 --- a/projects/Rockchip/bootloader/canupdate.sh +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# Copyright (C) 2017-present Team LibreELEC (https://libreelec.tv) - -# Allow upgrades between arm and aarch64 -if [ "$1" = "@PROJECT@.arm" -o "$1" = "@PROJECT@.aarch64" ]; then - exit 0 -else - exit 1 -fi diff --git a/projects/Rockchip/bootloader/install b/projects/Rockchip/bootloader/install index 959262532..499da8689 100755 --- a/projects/Rockchip/bootloader/install +++ b/projects/Rockchip/bootloader/install @@ -6,42 +6,19 @@ PKG_RKBIN="$(get_build_dir rkbin)" PKG_UBOOT="$(get_build_dir u-boot)" source ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/options -RKSPI_LOADER=${INSTALL}/usr/share/bootloader/rkspi_loader.img - -generate_rkspi_loader() { - echo "spi: create rkspi_loader.img..." - dd if=/dev/zero of=$RKSPI_LOADER bs=1M count=0 seek=16 - # When running as a non-root user, /sbin & /usr/sbin are excluded from $PATH - PATH=/sbin:/usr/sbin:$PATH PARTED_CMD="$(which parted)" - ${PARTED_CMD} -s $RKSPI_LOADER mklabel gpt - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart idbloader 64 7167 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart vnvm 7168 7679 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart reserved_space 7680 8063 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart reserved1 8064 8127 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart uboot_env 8128 8191 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart reserved2 8192 16383 - ${PARTED_CMD} -s $RKSPI_LOADER unit s mkpart uboot 16384 32734 - echo "spi: write idbloader.img to rkspi_loader.img..." - dd if=${PKG_BUILD}/idbloader.img of=$RKSPI_LOADER seek=64 conv=notrunc - echo "spi: write uboot.itb to rkspi_loader.img..." - dd if=${PKG_BUILD}/u-boot.itb of=$RKSPI_LOADER seek=16384 conv=notrunc -} - - - if [ -n "${PKG_DATAFILE}" -a -n "${PKG_LOADER}" ]; then echo "loader: Make idbloader.img from ${PKG_DATAFILE}:${PKG_LOADER}..." case "${PKG_SOC}" in rk35*) tools/mkimage -n ${PKG_SOC} -T rksd -d ${PKG_DATAFILE}:${PKG_LOADER} -C bzip2 idbloader.img - ;; + ;; rk3399) ${PKG_RKBIN}/tools/mkimage -n "${PKG_SOC}" -T rksd -d ${PKG_DATAFILE}:${PKG_LOADER} idbloader.img.rk || exit 1 - ;; + ;; *) tools/mkimage -n ${PKG_SOC} -T rksd -d "${PKG_DATAFILE}" -C bzip2 idbloader.img cat "${PKG_LOADER}" >> idbloader.img - ;; + ;; esac fi @@ -49,7 +26,7 @@ case "${PKG_SOC}" in rk35*|px30) echo "uboot: copy idbloader.img image to ${INSTALL}/usr/share/bootloader..." cp -av idbloader.img ${INSTALL}/usr/share/bootloader - ;; + ;; esac if [ ! -n "${PKG_LOAD_ADDR}" ]; then @@ -65,7 +42,7 @@ case "${PKG_SOC}" in break fi done - ;; + ;; rk3399) PKG_ATF_INI="${PKG_RKBIN}"/RKTRUST/"${DEVICE}"TRUST.ini echo "uboot: building ${UBOOT_FIT_IMAGE}..." @@ -77,19 +54,19 @@ case "${PKG_SOC}" in echo "uboot: copy ${UBOOT_FIT_IMAGE} to ${INSTALL}/usr/share/bootloader..." cp -av ${UBOOT_FIT_IMAGE} ${INSTALL}/usr/share/bootloader - ;; + ;; *) echo "uboot: build loader image u-boot.img at ${PKG_LOAD_ADDR}..." ${PKG_UBOOT}/tools/loaderimage --pack --uboot u-boot-dtb.bin u-boot.img ${PKG_LOAD_ADDR} ||: cp -av u-boot.img ${INSTALL}/usr/share/bootloader - ;; + ;; esac case "${DEVICE}" in RK3326) -if [ -n "${PKG_BL31}" ]; then - echo "trust: create trust.ini..." - cat >trust.ini <trust.ini < "${INSTALL}/usr/share/bootloader/extlinux/extlinux.conf" + cat << EOF > "${INSTALL}/usr/share/bootloader/extlinux/extlinux.conf" LABEL ${DISTRO} LINUX /${KERNEL_NAME} ${FDTMODE} diff --git a/projects/Rockchip/bootloader/mkimage b/projects/Rockchip/bootloader/mkimage index 1a63b36c3..290a9142c 100755 --- a/projects/Rockchip/bootloader/mkimage +++ b/projects/Rockchip/bootloader/mkimage @@ -7,10 +7,10 @@ source ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/options case "${PKG_SOC}" in rk35*|rk3399) IDBSEEK="bs=512 seek=64" - ;; + ;; *) IDBSEEK="bs=32k seek=1" - ;; + ;; esac if [ -f "${RELEASE_DIR}/3rdparty/bootloader/idbloader.img" ]; then @@ -18,12 +18,9 @@ if [ -f "${RELEASE_DIR}/3rdparty/bootloader/idbloader.img" ]; then dd if="${RELEASE_DIR}/3rdparty/bootloader/idbloader.img" of="$DISK" ${IDBSEEK} conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error fi - - case "${PKG_SOC}" in rk35*) - for BOOT_IMAGE in u-boot.itb u-boot.img - do + for BOOT_IMAGE in u-boot.itb u-boot.img; do if [ -f "${RELEASE_DIR}/3rdparty/bootloader/${BOOT_IMAGE}" ]; then echo "image: burn ${BOOT_IMAGE} to image..." dd if="${RELEASE_DIR}/3rdparty/bootloader/${BOOT_IMAGE}" of="${DISK}" bs=512 seek=16384 conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error @@ -37,16 +34,15 @@ case "${PKG_SOC}" in echo "image: burn resource.img to image..." dd if="${RELEASE_DIR}/3rdparty/bootloader/resource.img" of="${DISK}" bs=512 seek=24576 conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error fi - ;; + ;; rk3399) if [ -f "${RELEASE_DIR}/3rdparty/bootloader/rk3399-uboot.bin" ]; then echo "image: burn u-boot.bin to image..." dd if="${RELEASE_DIR}/3rdparty/bootloader/rk3399-uboot.bin" of="${DISK}" bs=512 seek=64 conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error fi - ;; + ;; *) - for BOOT_IMAGE in u-boot.itb u-boot.img - do + for BOOT_IMAGE in u-boot.itb u-boot.img; do if [ -f "${RELEASE_DIR}/3rdparty/bootloader/${BOOT_IMAGE}" ]; then echo "image: burn ${BOOT_IMAGE} to image..." dd if="${RELEASE_DIR}/3rdparty/bootloader/${BOOT_IMAGE}" of="${DISK}" bs=512 seek=16384 conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error @@ -57,19 +53,19 @@ case "${PKG_SOC}" in echo "image: burn trust.img to image..." dd if="${RELEASE_DIR}/3rdparty/bootloader/trust.img" of="$DISK" bs=512 seek=24576 conv=sync,noerror,notrunc >"${SAVE_ERROR}" 2>&1 || show_error fi - ;; + ;; esac #Create boot.ini -if [ "${BOOT_INI}" == true ] -then +if [ "${BOOT_INI}" == true ]; then echo "boot: create boot.ini..." - if [ -e "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/boot/boot.ini" ] - then + if [ -e "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/boot/boot.ini" ]; then cp -f ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/boot/boot.ini ${LE_TMP}/boot.ini - sed -i "s~@DISTRO_BOOTLABEL@~${DISTRO_BOOTLABEL}~g" ${LE_TMP}/boot.ini - sed -i "s~@DISTRO_DISKLABEL@~${DISTRO_DISKLABEL}~g" ${LE_TMP}/boot.ini - sed -i "s~@EXTRA_CMDLINE@~${EXTRA_CMDLINE}~g" ${LE_TMP}/boot.ini + sed -e "s/@DISTRO_BOOTLABEL@/${DISTRO_BOOTLABEL}/" \ + -e "s/@DISTRO_DISKLABEL@/${DISTRO_DISKLABEL}/" \ + -e "s/@EXTRA_CMDLINE@/${EXTRA_CMDLINE}/" \ + -i "${LE_TMP}/boot.ini" + mcopy -so "${LE_TMP}/boot.ini" :: else echo "ERROR: No boot.ini found in ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/boot/." @@ -80,36 +76,31 @@ fi mkdir -p "${LE_TMP}/extlinux" # copy device trees to part1 -for DTB in ${DEVICE_DTB[@]} -do - if [ -e "${DTB}.dtb" ] - then +for DTB in ${DEVICE_DTB[@]}; do + if [ -e "${DTB}.dtb" ]; then echo "image: copy device trees to image..." mcopy -o "${DTB}.dtb" :: fi done -if [ "${EXT_LINUX_CONF}" == true ] -then -mkdir -p "${LE_TMP}/extlinux" +if [ "${EXT_LINUX_CONF}" == true ]; then + mkdir -p "${LE_TMP}/extlinux" -if [[ "${PKG_SOC}" != "rk3588" ]] && \ - [[ "${TRUST_LABEL}" = "resource" || "${#DEVICE_DTB[@]}" -gt 1 ]] -then - echo "image: Set FDTDIR to /..." - FDTMODE="FDTDIR /" -else - echo "image: Set FDT to ${DEVICE_DTB}..." - FDTMODE="FDT /${DEVICE_DTB}.dtb" -fi + if [[ "${PKG_SOC}" != "rk3588" ]] && [[ "${TRUST_LABEL}" = "resource" || "${#DEVICE_DTB[@]}" -gt 1 ]]; then + echo "image: Set FDTDIR to /..." + FDTMODE="FDTDIR /" + else + echo "image: Set FDT to ${DEVICE_DTB}..." + FDTMODE="FDT /${DEVICE_DTB}.dtb" + fi -echo "image: Set extlinux.conf..." -cat << EOF > "${LE_TMP}/extlinux/extlinux.conf" + echo "image: Set extlinux.conf..." + cat << EOF > "${LE_TMP}/extlinux/extlinux.conf" LABEL ${DISTRO} LINUX /${KERNEL_NAME} ${FDTMODE} APPEND boot=LABEL=${DISTRO_BOOTLABEL} disk=LABEL=${DISTRO_DISKLABEL} ${EXTRA_CMDLINE} EOF -mcopy -so "${LE_TMP}/extlinux" :: + mcopy -so "${LE_TMP}/extlinux" :: fi diff --git a/projects/Rockchip/bootloader/release b/projects/Rockchip/bootloader/release index 074bc3abd..565412e48 100755 --- a/projects/Rockchip/bootloader/release +++ b/projects/Rockchip/bootloader/release @@ -11,8 +11,7 @@ if [ -n "${UBOOT_CONFIG}" ]; then fi case "${PKG_SOC}" in rk35*) - for BOOT_IMAGE in u-boot.itb u-boot.img - do + for BOOT_IMAGE in u-boot.itb u-boot.img; do if [ -f "${BOOTLOADER_DIR}/${BOOT_IMAGE}" ]; then cp -a ${BOOTLOADER_DIR}/${BOOT_IMAGE} ${RELEASE_DIR}/3rdparty/bootloader break @@ -21,15 +20,14 @@ if [ -n "${UBOOT_CONFIG}" ]; then if [ -f ${KERNEL_DIR}/resource.img ]; then cp -a ${KERNEL_DIR}/resource.img ${RELEASE_DIR}/3rdparty/bootloader fi - ;; + ;; rk3399) if [ -f ${BOOTLOADER_DIR}/rk3399-uboot.bin ]; then cp -a ${BOOTLOADER_DIR}/rk3399-uboot.bin ${RELEASE_DIR}/3rdparty/bootloader fi - ;; + ;; *) - for BOOT_IMAGE in u-boot.itb u-boot.img - do + for BOOT_IMAGE in u-boot.itb u-boot.img; do if [ -f "${BOOTLOADER_DIR}/${BOOT_IMAGE}" ]; then cp -a ${BOOTLOADER_DIR}/${BOOT_IMAGE} ${RELEASE_DIR}/3rdparty/bootloader break @@ -38,6 +36,7 @@ if [ -n "${UBOOT_CONFIG}" ]; then if [ -f ${BOOTLOADER_DIR}/trust.img ]; then cp -a ${BOOTLOADER_DIR}/trust.img ${RELEASE_DIR}/3rdparty/bootloader fi + ;; esac fi @@ -50,7 +49,7 @@ if [ -f ${INSTALL}/usr/share/bootloader/boot.scr ]; then fi LINUX_DTS_DIR=$(get_build_dir linux)/arch/${TARGET_KERNEL_ARCH}/boot/dts/ -for dtb in $(find ${LINUX_DTS_DIR} -name "*.dtb") ; do +for dtb in $(find ${LINUX_DTS_DIR} -name "*.dtb"); do if [ -f $dtb ]; then cp -a $dtb ${RELEASE_DIR}/3rdparty/bootloader fi diff --git a/projects/Rockchip/bootloader/update.sh b/projects/Rockchip/bootloader/update.sh index e248a48dc..0e5dd1320 100755 --- a/projects/Rockchip/bootloader/update.sh +++ b/projects/Rockchip/bootloader/update.sh @@ -40,18 +40,18 @@ if [ -f $BOOT_ROOT/extlinux/extlinux.conf ]; then *gameforce,ace) echo "Setting boot FDT to GameForce Ace..." sed -i '/FDT/c\ FDT /rk3588s-gameforce-ace.dtb' $BOOT_ROOT/extlinux/extlinux.conf - ;; + ;; *orangepi-5) echo "Setting boot FDT to Orange Pi 5..." sed -i '/FDT/c\ FDT /rk3588s-orangepi-5.dtb' $BOOT_ROOT/extlinux/extlinux.conf sed -i 's/ fbcon=rotate:1//' $BOOT_ROOT/extlinux/extlinux.conf - ;; + ;; *rock-5) echo "Setting boot FDT to Rock 5B..." sed -i '/FDT/c\ FDT /rk3588-rock-5b.dtb' $BOOT_ROOT/extlinux/extlinux.conf sed -i 's/ fbcon=rotate:1//' $BOOT_ROOT/extlinux/extlinux.conf - ;; - esac + ;; + esac fi fi diff --git a/projects/Rockchip/packages/u-boot/package.mk b/projects/Rockchip/packages/u-boot/package.mk index f4af8750d..39e7fdbee 100644 --- a/projects/Rockchip/packages/u-boot/package.mk +++ b/projects/Rockchip/packages/u-boot/package.mk @@ -17,22 +17,22 @@ case ${DEVICE} in RK3588*) PKG_VERSION="ad0cfba1ac51e8dd8b039f6c56b9c9f9a679df91" PKG_URL="${PKG_SITE}/rk3588-uboot/archive/${PKG_VERSION}.tar.gz" - ;; + ;; RK3566*) PKG_URL="https://github.com/u-boot/u-boot.git" PKG_VERSION="9cba29b19f43f9450117e8bc89e7dda691ed5ab5" PKG_GIT_CLONE_BRANCH="master" - ;; + ;; RK3399) PKG_DEPENDS_TARGET+=" atf openssl:host" PKG_VERSION="2024.04" PKG_URL="https://ftp.denx.de/pub/u-boot/${PKG_NAME}-${PKG_VERSION}.tar.bz2" - ;; + ;; RK3326) PKG_VERSION="0e26e35cb18a80005b7de45c95858c86a2f7f41e" PKG_URL="${PKG_SITE}/hardkernel-uboot/archive/${PKG_VERSION}.tar.gz" PKG_GIT_CLONE_BRANCH="RK3326" - ;; + ;; esac PKG_IS_KERNEL_PKG="yes" @@ -59,23 +59,18 @@ make_target() { if [ -z "${UBOOT_CONFIG}" ]; then echo "UBOOT_CONFIG must be set to build an image" else - if [ -e "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/u-boot/${UBOOT_CONFIG}" ] - then + if [ -e "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/u-boot/${UBOOT_CONFIG}" ]; then cp ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/u-boot/${UBOOT_CONFIG} configs fi [ "${BUILD_WITH_DEBUG}" = "yes" ] && PKG_DEBUG=1 || PKG_DEBUG=0 - if [[ "${PKG_BL31}" =~ ^/bin ]] - then + if [[ "${PKG_BL31}" =~ ^/bin ]]; then PKG_BL31="$(get_build_dir rkbin)/${PKG_BL31}" fi - if [[ "${PKG_LOADER}" =~ ^/bin ]] - then + if [[ "${PKG_LOADER}" =~ ^/bin ]]; then PKG_LOADER="$(get_build_dir rkbin)/${PKG_LOADER}" fi - if [[ "${PKG_SOC}" =~ "rk3568" ]] || \ - [[ "${PKG_SOC}" =~ "rk356x" ]] - then + if [[ "${PKG_SOC}" =~ "rk3568" ]] || [[ "${PKG_SOC}" =~ "rk356x" ]]; then # rk3566 device echo "Building for GPT (${UBOOT_DTB})..." echo "toolchain (${TOOLCHAIN})" @@ -87,8 +82,7 @@ make_target() { DEBUG=${PKG_DEBUG} CROSS_COMPILE="${TARGET_KERNEL_PREFIX}" LDFLAGS="--lssl -lcrypto" ARCH=arm64 make ${UBOOT_CONFIG} ${PKG_LOADER} u-boot.dtb u-boot.img tools HOSTCC="${HOST_CC}" HOSTLDFLAGS="-L${TOOLCHAIN}/lib" HOSTCFLAGS="-I${TOOLCHAIN}/include" echo "end make" DEBUG=${PKG_DEBUG} CROSS_COMPILE="${TARGET_KERNEL_PREFIX}" LDFLAGS="" ARCH=arm64 _python_sysroot="${TOOLCHAIN}" _python_prefix=/ _python_exec_prefix=/ make HOSTCC="${HOST_CC}" HOSTLDFLAGS="-L${TOOLCHAIN}/lib" HOSTCFLAGS="-I${TOOLCHAIN}/include" HOSTSTRIP="true" CONFIG_MKIMAGE_DTC_PATH="scripts/dtc/dtc" - elif [[ "${PKG_SOC}" =~ "rk3588" ]] - then + elif [[ "${PKG_SOC}" =~ "rk3588" ]]; then # rk3588 devices DEBUG=${PKG_DEBUG} CROSS_COMPILE="${TARGET_KERNEL_PREFIX}" LDFLAGS="" ARCH=arm64 make mrproper DEBUG=${PKG_DEBUG} CROSS_COMPILE="${TARGET_KERNEL_PREFIX}" LDFLAGS="" ARCH=arm64 make ${UBOOT_CONFIG} BL31=${PKG_BL31} ${PKG_LOADER} u-boot.dtb u-boot.itb CONFIG_MKIMAGE_DTC_PATH="scripts/dtc/dtc"