2023-01-08 22:49:32 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Copyright (C) 2017-2021 Team LibreELEC (https://libreelec.tv)
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2023-01-08 22:49:32 +00:00
|
|
|
|
|
|
|
PKG_RKBIN="$(get_build_dir rkbin)"
|
|
|
|
PKG_UBOOT="$(get_build_dir u-boot)"
|
|
|
|
source ${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/options
|
|
|
|
|
2023-01-11 21:31:08 +00:00
|
|
|
RKSPI_LOADER=${INSTALL}/usr/share/bootloader/rkspi_loader.img
|
2023-01-10 23:39:16 +00:00
|
|
|
|
2023-01-11 21:31:08 +00:00
|
|
|
generate_rkspi_loader() {
|
2023-01-10 23:39:16 +00:00
|
|
|
echo "spi: create rkspi_loader.img..."
|
2023-01-11 21:31:08 +00:00
|
|
|
dd if=/dev/zero of=$RKSPI_LOADER bs=1M count=0 seek=16
|
2023-08-24 21:00:28 +00:00
|
|
|
# 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
|
2023-01-10 23:39:16 +00:00
|
|
|
echo "spi: write idbloader.img to rkspi_loader.img..."
|
2023-01-11 21:31:08 +00:00
|
|
|
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
|
2023-01-10 23:39:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 22:49:32 +00:00
|
|
|
if [ -n "${PKG_DATAFILE}" -a -n "${PKG_LOADER}" ]; then
|
|
|
|
echo "loader: Make idbloader.img from ${PKG_DATAFILE}:${PKG_LOADER}..."
|
|
|
|
case "${PKG_SOC}" in
|
2023-06-23 03:14:11 +00:00
|
|
|
rk35*|rk3399)
|
2023-02-16 22:40:39 +00:00
|
|
|
tools/mkimage -n ${PKG_SOC} -T rksd -d ${PKG_DATAFILE}:${PKG_LOADER} -C bzip2 idbloader.img
|
2023-01-08 22:49:32 +00:00
|
|
|
;;
|
2023-05-04 18:06:54 +00:00
|
|
|
*)
|
2023-01-08 22:49:32 +00:00
|
|
|
tools/mkimage -n ${PKG_SOC} -T rksd -d "${PKG_DATAFILE}" -C bzip2 idbloader.img
|
|
|
|
cat "${PKG_LOADER}" >> idbloader.img
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2023-01-10 23:39:16 +00:00
|
|
|
echo "uboot: copy idbloader.img image to ${INSTALL}/usr/share/bootloader..."
|
2023-01-08 22:49:32 +00:00
|
|
|
cp -av idbloader.img ${INSTALL}/usr/share/bootloader
|
|
|
|
|
|
|
|
if [ ! -n "${PKG_LOAD_ADDR}" ]; then
|
|
|
|
PKG_LOAD_ADDR="0x00200000"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "${PKG_SOC}" in
|
2023-02-16 22:40:39 +00:00
|
|
|
rk35*)
|
2023-01-08 22:49:32 +00:00
|
|
|
echo "uboot: copy u-boot.itb image to ${INSTALL}/usr/share/bootloader..."
|
2023-01-10 23:39:16 +00:00
|
|
|
cp -av u-boot.itb ${INSTALL}/usr/share/bootloader/u-boot.itb
|
2023-01-11 21:31:08 +00:00
|
|
|
generate_rkspi_loader
|
2023-01-08 22:49:32 +00:00
|
|
|
;;
|
2023-05-04 18:06:54 +00:00
|
|
|
*)
|
|
|
|
echo "uboot: build loader image uboot.img at ${PKG_LOAD_ADDR}..."
|
|
|
|
${PKG_UBOOT}/tools/loaderimage --pack --uboot u-boot-dtb.bin uboot.img ${PKG_LOAD_ADDR} ||:
|
|
|
|
cp -av uboot.img ${INSTALL}/usr/share/bootloader
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-05-11 19:11:56 +00:00
|
|
|
case "${DEVICE}" in
|
2023-06-23 03:14:11 +00:00
|
|
|
RK33*)
|
2023-05-04 18:06:54 +00:00
|
|
|
if [ -n "${PKG_BL31}" ]; then
|
|
|
|
echo "trust: create trust.ini..."
|
|
|
|
cat >trust.ini <<EOF
|
|
|
|
[BL30_OPTION]
|
|
|
|
SEC=0
|
|
|
|
[BL31_OPTION]
|
|
|
|
SEC=1
|
|
|
|
PATH=${PKG_BL31}
|
|
|
|
ADDR=0x00010000
|
|
|
|
[BL32_OPTION]
|
|
|
|
SEC=0
|
|
|
|
[BL33_OPTION]
|
|
|
|
SEC=0
|
|
|
|
[OUTPUT]
|
|
|
|
PATH=trust.img
|
|
|
|
EOF
|
|
|
|
TROPTS="--verbose"
|
|
|
|
${PKG_UBOOT}/tools/trust_merger ${TROPTS} trust.ini
|
|
|
|
cp -av trust.img ${INSTALL}/usr/share/bootloader
|
|
|
|
fi
|
|
|
|
;;
|
2023-01-08 22:49:32 +00:00
|
|
|
esac
|
|
|
|
|
2023-05-04 18:06:54 +00:00
|
|
|
|
2023-01-08 22:49:32 +00:00
|
|
|
if [ "${BOOT_INI}" == true ]
|
|
|
|
then
|
|
|
|
echo "boot: create boot.ini..."
|
|
|
|
cat >${INSTALL}/usr/share/bootloader/boot.ini <<EOF
|
2023-05-11 19:11:56 +00:00
|
|
|
odroidgoa-uboot-config
|
|
|
|
|
|
|
|
setenv bootargs "boot=UUID=@BOOT_UUID@ disk=UUID=@DISK_UUID@ ${EXTRA_CMDLINE}"
|
|
|
|
|
|
|
|
setenv loadaddr "0x02000000"
|
|
|
|
setenv dtb_loadaddr "0x01f00000"
|
|
|
|
|
|
|
|
load mmc 1:1 \${loadaddr} KERNEL
|
|
|
|
|
|
|
|
if test \${hwrev} = 'v11'; then
|
|
|
|
if gpio input c22; then
|
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-odroid-go2-v11.dtb
|
|
|
|
else
|
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-anbernic-rg351m.dtb
|
|
|
|
fi
|
|
|
|
elif test \${hwrev} = 'v10-go3'; then
|
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-odroid-go3.dtb
|
|
|
|
elif test \${hwrev} = 'v10'; then
|
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-odroid-go2.dtb
|
2023-08-04 21:17:40 +00:00
|
|
|
elif test \${hwrev} = 'rg351v'; then
|
2023-05-16 14:51:12 +00:00
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-anbernic-rg351v.dtb
|
2023-08-04 21:17:40 +00:00
|
|
|
elif test \${hwrev} = 'rg351mp'; then
|
|
|
|
load mmc 1:1 \${dtb_loadaddr} rk3326-anbernic-rg351mp.dtb
|
2023-05-11 19:11:56 +00:00
|
|
|
fi
|
2023-01-08 22:49:32 +00:00
|
|
|
|
2023-05-11 19:11:56 +00:00
|
|
|
booti \${loadaddr} - \${dtb_loadaddr}
|
2023-01-08 22:49:32 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2023-05-11 19:11:56 +00:00
|
|
|
if [ "${EXT_LINUX_CONF}" == true ]
|
|
|
|
then
|
2023-01-08 22:49:32 +00:00
|
|
|
echo "boot: create extlinux.conf..."
|
|
|
|
mkdir -p "${INSTALL}/usr/share/bootloader/extlinux"
|
2023-02-21 22:32:31 +00:00
|
|
|
|
|
|
|
if [ "${TRUST_LABEL}" = "resource" ]
|
|
|
|
then
|
|
|
|
FDTMODE="FDTDIR /"
|
|
|
|
else
|
2023-05-10 21:15:44 +00:00
|
|
|
FDTMODE="FDT /${DEVICE_DTB[0]}.dtb"
|
2023-02-21 22:32:31 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-08 22:49:32 +00:00
|
|
|
cat << EOF > "${INSTALL}/usr/share/bootloader/extlinux/extlinux.conf"
|
|
|
|
LABEL ${DISTRO}
|
|
|
|
LINUX /${KERNEL_NAME}
|
2023-02-21 22:32:31 +00:00
|
|
|
${FDTMODE}
|
2023-01-08 22:49:32 +00:00
|
|
|
APPEND boot=UUID=@BOOT_UUID@ disk=UUID=@DISK_UUID@ ${EXTRA_CMDLINE}
|
|
|
|
EOF
|
2023-05-11 19:11:56 +00:00
|
|
|
fi
|