Move the arm releated helper functions into a separate file and added function descriptions to the md.
This commit is contained in:
parent
d19de8c3e9
commit
afd07f5d22
|
|
@ -0,0 +1,804 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
install_u-boot(){
|
||||
fn install_u-boot
|
||||
req=(strapdir disk_name efi_partitions swap_part_number rpool_name bpool_name root_name grub_mount)
|
||||
ckreq || return 1
|
||||
|
||||
# When installing to metal we will install the os plus grub as usual and
|
||||
# then boot grub from u-boot written to SPI.
|
||||
# u-boot gets build as a part of the board definition in arm-sdk. We add
|
||||
# zfs support there in case we wish to boot the kernel directly later.
|
||||
|
||||
# https://github.com/sigmaris/u-boot/wiki/RockPro64-boot-sequence
|
||||
|
||||
# notice "installing u-boot to SPI."
|
||||
|
||||
# The RK3399 Boot ROM will look for code with an ID block header for:
|
||||
# SPI flash at offset 0 bytes
|
||||
# eMMC at offset 0x8000 bytes (64 sectors, a sector is 0x200 bytes)
|
||||
# SDcard at offset 0x8000 bytes (64 sectors, a sector is 0x200 bytes)
|
||||
|
||||
# this is where we write the idbloader.img (containing U-Boot TPL & SPL)
|
||||
|
||||
# For SPI it must be written in rkspi format using the U-Boot mkimage tool.
|
||||
|
||||
cat /proc/device-tree/model # Pine64 RockPro64 v2.0
|
||||
cat /proc/device-tree/compatible # pine64,rockpro64-v2.0pine64,rockpro64rockchip,rk3399
|
||||
|
||||
cat /proc/mtd
|
||||
# dev: size erasesize name
|
||||
# mtd0: 00060000 00001000 "u-boot-spl"
|
||||
# mtd1: 00398000 00001000 "u-boot"
|
||||
# mtd2: 00008000 00001000 "u-boot-env"
|
||||
# mtd3: 00c00000 00001000 "user"
|
||||
|
||||
lsmtd
|
||||
# DEVICE MAJ:MIN NAME TYPE SIZE
|
||||
# mtd0 90:0 u-boot-spl nor 384K
|
||||
# mtd1 90:2 u-boot nor 3.6M
|
||||
# mtd2 90:4 u-boot-env nor 32K
|
||||
# mtd3 90:6 user nor 12M
|
||||
|
||||
mtdinfo
|
||||
# Count of MTD devices: 4
|
||||
# Present MTD devices: mtd0, mtd1, mtd2, mtd3
|
||||
# Sysfs interface supported: yes
|
||||
|
||||
sudo mtdinfo /dev/mtd0
|
||||
# mtd0
|
||||
# Name: u-boot-spl
|
||||
# Type: nor
|
||||
# Eraseblock size: 4096 bytes, 4.0 KiB
|
||||
# Amount of eraseblocks: 96 (393216 bytes, 384.0 KiB)
|
||||
# Minimum input/output unit size: 1 byte
|
||||
# Sub-page size: 1 byte
|
||||
# Character device major/minor: 90:0
|
||||
# Bad blocks are allowed: false
|
||||
# Device is writable: true
|
||||
|
||||
sudo mtd_debug info /dev/mtd0
|
||||
# mtd.type = MTD_NORFLASH
|
||||
# mtd.flags = MTD_CAP_NORFLASH
|
||||
# mtd.size = 393216 (384K)
|
||||
# mtd.erasesize = 4096 (4K)
|
||||
# mtd.writesize = 1
|
||||
# mtd.oobsize = 0
|
||||
# regions = 0
|
||||
|
||||
|
||||
build_atf(){
|
||||
fn build_atf
|
||||
req=(strapdir atf_branch atfgit compiler)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Build arm-trusted-firmware bl31.elf for rk3399."
|
||||
|
||||
git config --global user.name 'Build Robot'
|
||||
git config --global user.email 'noemail@example.com'
|
||||
git clone --depth 1 -b "$atf_branch" "$atfgit" "$R/tmp/kernels/arm-trusted-firmware" || zerr
|
||||
pushd "$R/tmp/kernels/arm-trusted-firmware"
|
||||
#git am ../atf-rk3399-baudrate.patch
|
||||
make realclean
|
||||
make -j$(nproc) CROSS_COMPILE=$compile PLAT=rk3399 DEBUG=1 bl31 || zerr
|
||||
popd
|
||||
|
||||
act "Publish arm-trusted-firmware bl31.elf"
|
||||
mkdir -p "$R/dist"
|
||||
cp "$R/tmp/kernels/arm-trusted-firmware/build/rk3399/debug/bl31/bl31.elf" "$R/dist"
|
||||
}
|
||||
|
||||
build_uboot(){
|
||||
fn build_u-boot
|
||||
req=(strapdir ubootgit uboot_branch MAKEOPTS)
|
||||
ckreq || return 1
|
||||
|
||||
defconfig=rockpro64-rk3399_defconfig
|
||||
img1type=rksd # Rockchip SD Boot Image
|
||||
img1name=idbloader.img
|
||||
img2name=u-boot.itb
|
||||
artifact=u-boot
|
||||
|
||||
notice "Build u-boot"
|
||||
"FIXME: AUTOBOOT was too chatty at the configure stage with these entries do its disabled for now."
|
||||
git clone --depth 1 "$ubootgit" -b "$uboot_branch" "$R/tmp/kernels/u-boot-rockpro64" || zer
|
||||
pushd "$R/tmp/kernels/u-boot-rockpro64"
|
||||
make mrproper
|
||||
make $(defconfig)
|
||||
act "apply local changes to defconfig."
|
||||
"$R/tmp/kernels/rockpro64/rockpro64-linux/scripts/config" --file .config \
|
||||
--enable CONFIG_CMD_ZFS \
|
||||
--enable CONFIG_CMD_BOOTMENU \
|
||||
--enable CONFIG_MENU \
|
||||
--enable CONFIG_MENU_SHOW \
|
||||
--enable CONFIG_CFB_CONSOLE_ANSI \
|
||||
--enable CONFIG_CMD_BOOTEFI \
|
||||
--enable CONFIG_EFI_LOADER \
|
||||
--enable CONFIG_EFI_SECURE_BOOT \
|
||||
--enable CONFIG_CMD_BOOTM \
|
||||
--enable CONFIG_BOOTM_EFI \
|
||||
--enable CONFIG_BOOTM_LINUX \
|
||||
--enable CONFIG_BOOTM_NETBSD \
|
||||
--enable CONFIG_BLK \
|
||||
--enable CONFIG_VERSION_VARIABLE \
|
||||
--enable CONFIG_PARTITIONS \
|
||||
--enable CONFIG_DM_VIDEO
|
||||
#--enable CONFIG_AUTOBOOT_KEYED \
|
||||
#--set-val CONFIG_BOOTDELAY 30
|
||||
|
||||
act "apply sigmaris changes to defconfig."
|
||||
"$R/tmp/kernels/rockpro64/rockpro64-linux/scripts/config" --file .config \
|
||||
--enable CONFIG_OF_BOARD_SETUP \
|
||||
--enable CONFIG_MTD \
|
||||
--enable CONFIG_CMD_MTDPARTS \
|
||||
--enable CONFIG_SPL_MMC \
|
||||
--enable CONFIG_SPL_SPI \
|
||||
--enable CONFIG_SPI_FLASH_MTD \
|
||||
--enable CONFIG_SPL_SPI_FLASH_SUPPORT \
|
||||
--enable CONFIG_NVME \
|
||||
--enable CONFIG_SCSI \
|
||||
--enable CONFIG_DM_SCSI \
|
||||
--enable CONFIG_OF_LIBFDT_OVERLAY \
|
||||
--enable CONFIG_FDT_FIXUP_PARTITIONS \
|
||||
--enable CONFIG_SERVERIP_FROM_PROXYDHCP \
|
||||
--enable CONFIG_AHCI \
|
||||
--enable CONFIG_SCSI_AHCI \
|
||||
--enable CONFIG_AHCI_PCI \
|
||||
--enable CONFIG_DM_KEYBOARD \
|
||||
--enable CONFIG_LED \
|
||||
--enable CONFIG_LED_GPIO \
|
||||
--set-val CONFIG_DEFAULT_DEVICE_TREE "rk3399-rockpro64" \
|
||||
--set-val CONFIG_SERVERIP_FROM_PROXYDHCP_DELAY_MS 100 \
|
||||
--set-val CONFIG_MTDIDS_DEFAULT "nor0=spi0.0" \
|
||||
--set-val CONFIG_MTDPARTS_DEFAULT="mtdparts=spi0.0:384k(u-boot-spl),3680k(u-boot),32k(u-boot-env),-(user)"
|
||||
|
||||
|
||||
make -j$(nproc) $MAKEOPTS ARCH=arm CROSS_COMPILE=$compiler || zerr
|
||||
export BL31="$R/tmp/kernels/arm-trusted-firmware/build/rk3399/debug/bl31/bl31.elf"
|
||||
mkdir -p "$R/dist"
|
||||
|
||||
act "create ${img1type}_${img1name} image file."
|
||||
"$R/tmp/kernels/u-boot-rockpro64/tools/mkimage" \
|
||||
-n rk3399 \ # set image name
|
||||
-T $(img1type) \ # set image type
|
||||
-d tpl/u-boot-tpl.bin:spl/u-boot-spl.bin \ # use image data from
|
||||
${img1type}_$(img1name) # idbloader.img
|
||||
act "Publish ${img1type}_${image1name}"
|
||||
cp ${img1type}_$(img1name) "$R/dist"
|
||||
|
||||
img1type=rkspi # Rockchip SPI Boot Image
|
||||
act "create ${img1type}_${img1name} image file."
|
||||
"$R/tmp/kernels/u-boot-rockpro64/tools/mkimage" \
|
||||
-n rk3399 \ # set image name
|
||||
-T $(img1type) \ # set image type
|
||||
-d tpl/u-boot-tpl.bin:spl/u-boot-spl.bin \ # use image data from
|
||||
${img1type}_$(img1name) # idbloader.img
|
||||
act "Publish ${img1type}_${image1name}"
|
||||
cp ${img1type}_$(img1name) "$R/dist"
|
||||
|
||||
act "Publish ${image2name}"
|
||||
cp u-boot.itb "$R/dist"/$(img2name) # u-boot.itb
|
||||
popd
|
||||
}
|
||||
|
||||
create_spi_image(){
|
||||
act "Create single SPI image with u-boot.itb at 0x60000"
|
||||
|
||||
padsize=$((0x60000 - 1))
|
||||
img1size=$(wc -c <"$(img1name)")
|
||||
[ $img1size -le $padsize ] || exit 1
|
||||
dd \
|
||||
if=/dev/zero \
|
||||
of=$(img1name) \
|
||||
conv=notrunc \
|
||||
bs=1 \
|
||||
count=1 \
|
||||
seek=$padsize
|
||||
cat $(img1name) u-boot.itb > "$R/dist"/spi_combined.img
|
||||
create-u-boot-spi-scripts
|
||||
"$R/tmp/kernels/u-boot-rockpro64/tools/mkimage" \
|
||||
-C none \ # set compression
|
||||
-A arm \ # set architecture
|
||||
-T script \ # set image type
|
||||
-d scripts/flash_spi.cmd \ # use image data fro
|
||||
"$R/dist/flash_spi.scr"
|
||||
}
|
||||
|
||||
spi_flash_img(){
|
||||
fn spi_flash_img
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Create SD card image to flash u-boot to SPI"
|
||||
|
||||
cp "$R/dist/flash_spi.scr boot.scr"
|
||||
cp "$R/dist/spi_combined.img spi_combined.img"
|
||||
dd \
|
||||
if=/dev/zero \
|
||||
of=boot.tmp \
|
||||
bs=1M \
|
||||
count=16
|
||||
mkfs.vfat -n u-boot-script boot.tmp
|
||||
mcopy -sm -i boot.tmp boot.scr ::
|
||||
mcopy -sm -i boot.tmp spi_combined.img ::
|
||||
dd \
|
||||
if=/dev/zero \
|
||||
of=flash_spi.img \
|
||||
bs=1M \
|
||||
count=32
|
||||
parted -s flash_spi.img mklabel gpt
|
||||
parted -s flash_spi.img unit s mkpart loader1 64 8063
|
||||
parted -s flash_spi.img unit s mkpart loader2 16384 24575
|
||||
parted -s flash_spi.img unit s mkpart boot fat16 24576 100%
|
||||
parted -s flash_spi.img set 3 legacy_boot on
|
||||
dd \
|
||||
if= "$R/tmp/kernels/u-boot-rockpro64/idbloader.img" \
|
||||
of=flash_spi.img \
|
||||
conv=notrunc \
|
||||
seek=64
|
||||
dd \
|
||||
if="$R/tmp/kernels/u-boot-rockpro6/u-boot.itb" \
|
||||
of=flash_spi.img \
|
||||
conv=notrunc \
|
||||
seek=16384
|
||||
dd \
|
||||
if=boot.tmp \
|
||||
of=flash_spi.img \
|
||||
conv=notrunc \
|
||||
seek=24576
|
||||
gzip flash_spi.img
|
||||
}
|
||||
|
||||
set-bootloader(){
|
||||
fn set-bootloader
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
case "$1" in
|
||||
*-rockchip-rock64-*)
|
||||
SD_LOADER="$R/dist/rksd_loader.img"
|
||||
SPI_LOADER="$R/dist/rksd_loader.img"
|
||||
BOARD=rock64
|
||||
;;
|
||||
|
||||
*-rockchip-rockpro64-*)
|
||||
SD_LOADER="$R/dist/rksd_loader.img"
|
||||
SPI_LOADER="$R/dist/rkspi_loader.img"
|
||||
BOARD=rockpro64
|
||||
;;
|
||||
|
||||
*-rockchip-pinebookpro-*)
|
||||
SD_LOADER="$R/dist/rksd_loader.img"
|
||||
SPI_LOADER="$R/dist/rkspi_loader.img"
|
||||
BOARD=pinebookpro
|
||||
;;
|
||||
|
||||
*-rockchip-rockpi4b-*)
|
||||
SD_LOADER="$R/dist/rksd_loader.img"
|
||||
SPI_LOADER="$R/dist/rkspi_loader.img"
|
||||
BOARD=rockpi4b
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Cannot detect board from $1."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! grep -qi "$BOARD" /proc/device-tree/compatible; then
|
||||
echo "You are currently running on different board:"
|
||||
echo "$(tr -d '\0' < /proc/device-tree/model || true)"
|
||||
echo "It may brick your device or the system unless"
|
||||
echo "you know what are you doing."
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
bootloader-version(){
|
||||
fn bootloader-version
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
# FIXME: Assumes partitions number p1 or p6 and uses p1 for both
|
||||
version() {
|
||||
local DEVICE="${1/p6/p1}"
|
||||
|
||||
echo -n "Current version: "
|
||||
if strings "$DEVICE" | grep "^U-Boot [a-z0-9.-]*$"; then
|
||||
echo -n "Board: "
|
||||
strings "$DEVICE" | grep -E "^board="
|
||||
echo -n "FDT: "
|
||||
strings "$DEVICE" | grep -E "^fdtfile="
|
||||
else
|
||||
echo "not installed on $DEVICE."
|
||||
fi
|
||||
echo
|
||||
}
|
||||
}
|
||||
|
||||
upgrade-sd-bootloader(){
|
||||
fn upgrade-sd-bootloader
|
||||
req=(strapdir SD_LOADER)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Upgrading pre-existing bootloader."
|
||||
# FIXME:
|
||||
# extlinux, u-boot, grub, EFI
|
||||
# Assumes u-boot written to a mounted efi partion
|
||||
# Writes the rksd image only to a specific partition number on sd devices. Uses p1
|
||||
if [[ $(findmnt -M /boot/efi) ]]; then
|
||||
MNT_DEV=$(findmnt /boot/efi -n -o SOURCE)
|
||||
else
|
||||
echo "Error: efi partition not mounted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# report current version
|
||||
bootloader-version "$MNT_DEV"
|
||||
|
||||
write_sd() {
|
||||
case "$1" in
|
||||
/dev/mmcblk*p6|/dev/sd*p6|/dev/mapper/loop*p6|/dev/mapper/nvme*p6)
|
||||
dd if="$2" of="${1/p6/p1}"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Cannot detect boot device ($MNT_DEV)."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
write_sd "$MNT_DEV" "$SD_LOADER"
|
||||
|
||||
sync
|
||||
}
|
||||
|
||||
erase-sd-bootloader(){
|
||||
fn erase-sd-bootloader
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Erasing pre-existing bootloader."
|
||||
# FIXME: Writes/erases a specific partition number on sd devices. Uses p1
|
||||
MNT_DEV=$(findmnt /boot/efi -n -o SOURCE)
|
||||
|
||||
# report current version
|
||||
bootloader-version "$MNT_DEV"
|
||||
|
||||
write_sd() {
|
||||
case "$1" in
|
||||
/dev/mmcblk*p6|/dev/sd*p6|/dev/mapper/loop*p6|/dev/mapper/nvme*p6)
|
||||
dd \
|
||||
if="$2" \
|
||||
of="${1/p6/p1}"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Cannot detect boot device ($MNT_DEV)."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
write_sd "$MNT_DEV" "/dev/zero"
|
||||
|
||||
sync
|
||||
}
|
||||
|
||||
write-emmc-flash(){
|
||||
fn write-emmc-flash
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Writing u-boot to emmc."
|
||||
for blkdevice in $(ls -d /dev/mmcblk* | sed -n -E '/mmcblk[0-9]+$/ p' ); do
|
||||
if [[ -f /sys/block/${blkdevice##*/}/device/type ]]; then
|
||||
if [[ $(< /sys/block/${blkdevice##*/}/device/type) == MMC ]]; then
|
||||
emmc_blkdevice=${blkdevice}
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
MNT_DEV=$(findmnt / -n -o SOURCE)
|
||||
MNT_DEV=${MNT_DEV%p[0-9]*}
|
||||
if [[ "$MNT_DEV" == $emmc_blkdevice* ]]; then
|
||||
echo "Cannot write when running from eMMC, use: $0 --force."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# When booting from sdcard:
|
||||
# the card appears as /dev/mmcblk1 and
|
||||
# the emmc appears as /dev/mmcblk2
|
||||
pushd "$R/tmp/kernels/u-boot-rockpro64"
|
||||
dd \
|
||||
if="$R/dist/rksd_idbloader.img" \
|
||||
of=/dev/${emmc_blkdevice} \
|
||||
seek=64
|
||||
dd \
|
||||
if="$R/dist/u-boot.itb" \
|
||||
of=/dev/${emmc_blkdevice} \
|
||||
seek=16384
|
||||
popd
|
||||
}
|
||||
|
||||
erase-spi-flash(){
|
||||
fn erase-spi-flash
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Erasing spi flash."
|
||||
# FIXME: Assumes contents of spi labels, we don't have 'loader' so fails.
|
||||
# mtd0: 00060000 00001000 "u-boot-spl"
|
||||
# mtd1: 00398000 00001000 "u-boot"
|
||||
# mtd2: 00008000 00001000 "u-boot-env"
|
||||
# mtd3: 00c00000 00001000 "user"
|
||||
|
||||
if ! MTD=$(grep \"loader\" /proc/mtd | cut -d: -f1); then
|
||||
echo "loader partition on MTD is not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# report current version
|
||||
bootloader-version "/dev/${MTD/mtd/mtdblock}"
|
||||
|
||||
flash_erase "/dev/$MTD" 0 0
|
||||
}
|
||||
|
||||
write-spi-flash(){
|
||||
fn write-spi-flash
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
notice "Writing spi flash."
|
||||
|
||||
version "/dev/${MTD/mtd/mtdblock}"
|
||||
confirm
|
||||
|
||||
write_nand() {
|
||||
if ! MTD=$(grep \"${1}\" /proc/mtd | cut -d: -f1); then
|
||||
echo "${1} partition on MTD is not found"
|
||||
exit 1
|
||||
fi
|
||||
echo "Writing /dev/$MTD with content of $2"
|
||||
flash_erase "/dev/$MTD" 0 0
|
||||
nandwrite "/dev/$MTD" < "$2"
|
||||
}
|
||||
write_nand u-boot-spl "$SPI_LOADER"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
# u-boot menu has been deprecated, extlinux.conf is used instead and uutomatically
|
||||
# updated with u-boot-update from u-boot-menu. see ARM-sdk/BOARDs/rockpro64-ayunfan.
|
||||
create-u-boot-menu(){
|
||||
fn create-u-boot-menu
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
# FIXME: Need to choose a default and fix the other calls
|
||||
cat <<-EOF | tee scripts/boot.cmd > /dev/null
|
||||
setenv bootmenu_0 Boot 1. kernel=bootm 0x82000000 # Set first menu entry
|
||||
setenv bootmenu_1 Boot 2. kernel=bootm 0x83000000 # Set second menu entry
|
||||
setenv bootmenu_2 Reset board=reset # Set third menu entry
|
||||
setenv bootmenu_3 U-Boot boot order=boot # Set fourth menu entry
|
||||
bootmenu 20 # Run bootmenu with autoboot delay 20s
|
||||
|
||||
u-boot console command sequence:
|
||||
from a android phone
|
||||
setenv bootmenu_0 "Boot LNX ARCH =
|
||||
setenv bootargs 'root=/dev/mmcblk0p7 rootfstype=ext4 rootwait'; \
|
||||
ext2load mmc 0:2 0x1000000 /boot/zImage;
|
||||
ext2load mmc 0:2 0x2000000 /boot/tegra20-paz00.dtb;
|
||||
bootz 0x1000000 - 0x2000000;"
|
||||
pastbin example
|
||||
setenv bootargs 'mem=214M root=/dev/mmcblk0p2 noinitrd rw rootfstype=ext2 console=ttyS0,115200n8 rootwait'
|
||||
setenv kernelargs 'mem=214M root=/dev/mmcblk0p2 noinitrd rw rootfstype=ext2 console=ttyS0,115200n8 rootwait'
|
||||
saveenv
|
||||
display init force
|
||||
mmcinit 0
|
||||
fatload mmc 0 0 uzImage.bin
|
||||
textout -1 -1 \"Commands finished. Trying to boot...\" FFFFFF
|
||||
bootm 0
|
||||
|
||||
from fat partition
|
||||
fatload mmc 0 0x3000000 uImage
|
||||
fatload mmc 0 0x2A00000 devicetree.dtb
|
||||
bootm 0x3000000 - 0x2A00000
|
||||
|
||||
zfs support
|
||||
zfsload <interface> <dev[:part]> [addr] [filename] [bytes]
|
||||
zfsload mmc 2:2 0x30007fc0 /rpool/@/boot/uImage
|
||||
|
||||
grub from u-boot
|
||||
ext4load mmc 0:1 0x43300000 /boot/grub/arm-uboot/core.img
|
||||
bootm 0x43300000
|
||||
|
||||
raspberrypi example
|
||||
setenv kernel_addr_r 2000000
|
||||
setenv fdt_addr_r 1000000
|
||||
setenv bootargs 'root=/dev/mmcblk0p7 rootfstype=ext4 rootwait'; \
|
||||
load mmc 0:2 \$kernel_addr_r /boot/image
|
||||
load mmc 0:2 \$fdt_addr_r boot/dtb/bcm2837-rpi-3-b.dtb
|
||||
|
||||
from the current spi
|
||||
setenv fdt_addr_r 0x01f00000
|
||||
setenv kernel_addr_r 0x02080000
|
||||
setenv devtype scsi
|
||||
setenv devnum 0
|
||||
setenv distro_bootpart 2
|
||||
|
||||
devuan-sdk version - variables set in arm-sdk-boards/(boardname>)
|
||||
setenv kernel_addr_z 0x44080000
|
||||
setenv kernel_addr_r 0x43000000
|
||||
setenv fdt_addr_r 0x42000000
|
||||
setenv ramdisk_addr_r 0x43300000
|
||||
setenv rootfsaddr 0x43300000
|
||||
setenv devtype mmc
|
||||
setenv devnum 0
|
||||
setenv distro_bootpart 1
|
||||
qemu changes
|
||||
setenv console /dev/ttyS2
|
||||
setenv root /dev/mmcblk0p2
|
||||
setenv root /dev/vda2
|
||||
setenv bootargs "consoleblank=0 root=${root} rw rootwait console=${console},1500000n8 earlycon=uart8250,mmio32,0xff1a0000 console=tty1"
|
||||
setenv bootargs "console=tty0 console=${console} root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4 fbcon=rotate:1"
|
||||
setenv bootargs "console=${console} root=/dev/vda2 mem=128M rdinit=/sbin/init"
|
||||
setenv fdt_addr_r 0xf5f17000
|
||||
setenv devtype virtio
|
||||
|
||||
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_z} Image.gz; then
|
||||
unzip ${kernel_addr_z} ${kernel_addr_r}
|
||||
if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} rk3399-rockpro64.dtb; then
|
||||
booti ${kernel_addr_r} - ${fdt_addr_r};
|
||||
fi;
|
||||
fi
|
||||
|
||||
armbian: https://github.com/armbian/build/blob/master/config/bootscripts/boot-rockchip64.cmd
|
||||
|
||||
efi: https://github.com/ARM-software/u-boot/blob/master/doc/README.uefi
|
||||
https://u-boot.readthedocs.io/en/latest/develop/uefi/uefi.html
|
||||
# the efi fat32 partition is mounted under /boot/efi
|
||||
load mmc 0:1 ${fdt_addr_r} rk3399-rockpro64.dtb
|
||||
load mmc 0:1 ${kernel_addr_r} \
|
||||
/EFI/Devuan\ daedalus\ \(RAID\ disk\ ata-WDC_WD30EZRZ-00WN9B0_WD-WCC4E6RKKRVX\)/grubaa64.efi
|
||||
bootefi ${kernel_addr_r} ${fdt_addr_r}
|
||||
|
||||
# u-boot, extlinux.conf
|
||||
label linux-5.0.0-rc3
|
||||
kernel /Image
|
||||
devicetree /sun50i-a64-amarula-relic.dtb
|
||||
append console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait rw
|
||||
|
||||
=> load mmc 0:2 ${fdt_addr_r} boot/dtb
|
||||
29830 bytes read in 14 ms (2 MiB/s)
|
||||
=> load mmc 0:1 ${kernel_addr_r} efi/debian/grubaa64.efi
|
||||
reading efi/debian/grubaa64.efi
|
||||
120832 bytes read in 7 ms (16.5 MiB/s)
|
||||
=> bootefi ${kernel_addr_r} ${fdt_addr_r}
|
||||
|
||||
efi FIT:
|
||||
=> load mmc 0:1 ${kernel_addr_r} image.fit
|
||||
4620426 bytes read in 83 ms (53.1 MiB/s)
|
||||
=> bootm ${kernel_addr_r}#config-grub-nofdt
|
||||
## Loading kernel from FIT Image at 40400000 ...
|
||||
Using 'config-grub-nofdt' configuration
|
||||
Verifying Hash Integrity ... sha256,rsa2048:dev+ OK
|
||||
Trying 'efi-grub' kernel subimage
|
||||
Description: GRUB EFI Firmware
|
||||
Created: 2019-11-20 8:18:16 UTC
|
||||
Type: Kernel Image (no loading done)
|
||||
Compression: uncompressed
|
||||
Data Start: 0x404000d0
|
||||
Data Size: 450560 Bytes = 440 KiB
|
||||
Hash algo: sha256
|
||||
Hash value: 4dbee00021112df618f58b3f7cf5e1595533d543094064b9ce991e8b054a9eec
|
||||
Verifying Hash Integrity ... sha256+ OK
|
||||
XIP Kernel Image (no loading done)
|
||||
## Transferring control to EFI (at address 404000d0) ...
|
||||
Welcome to GRUB!
|
||||
|
||||
initramfs example https://armtix.artixlinux.org/info/firefly-rk3399.html
|
||||
mkimage -A arm -T ramdisk -d <path to initramfs> mkinitramfs-linux.uimg
|
||||
|
||||
Next, you have to create u-boot script u-boot.cmd with following contents:
|
||||
|
||||
setenv bootargs "consoleblank=0 root=${console} rw rootwait console=ttyS2,1500000n8 earlycon=uart8250,mmio32,0xff1a0000 console=tty1"
|
||||
load mmc 1:1 ${fdt_addr_r} /dtbs/rockchip/rk3399-firefly.dtb
|
||||
load mmc 1:1 ${kernel_addr_r} /Image
|
||||
load mmc 1:1 ${ramdisk_addr_r} /initramfs-linux.uimg
|
||||
booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
|
||||
|
||||
mkimage -A arm -T ramdisk -d boot.cmd boot.scr
|
||||
|
||||
EOF
|
||||
|
||||
"$R/tmp/kernels/u-boot-rockpro64/tools/mkimage" \
|
||||
-A arm \ # set architechture
|
||||
-O linux \ # set operating system
|
||||
-T script \ # set image type
|
||||
-C none \ # set compression type
|
||||
-a 0 \ # set load address
|
||||
-e 0 \ # set entry point
|
||||
-n "ubootscript" \ # set image name
|
||||
-d scripts/boot.cmd \ # use image data from
|
||||
"$R/dist/boot.scr"
|
||||
|
||||
}
|
||||
|
||||
create-u-boot-spi-scripts(){
|
||||
fn create-u-boot-spi-scripts
|
||||
req=(strapdir)
|
||||
ckreq || return 1
|
||||
|
||||
cat <<-'EOF' | tee "$R/tmp/kernels/u-boot-rockpro64/scripts/erase_spi.cmd" > /dev/null
|
||||
setenv blink_work 'led work on; sleep 0.1; led work off; sleep 0.1'
|
||||
setenv blink_diy 'led diy on; sleep 0.1; led diy off; sleep 0.1'
|
||||
|
||||
echo "Enable SPI Flash now."
|
||||
|
||||
run blink_work
|
||||
sleep 2
|
||||
run blink_work
|
||||
sleep 2
|
||||
run blink_work
|
||||
sleep 2
|
||||
run blink_work
|
||||
sleep 2
|
||||
run blink_work
|
||||
sleep 2
|
||||
|
||||
if sf probe; then
|
||||
|
||||
# erase all mtd partitions containing u-boot
|
||||
run blink_work
|
||||
run blink_work
|
||||
run blink_work
|
||||
mtd erase u-boot-spl
|
||||
run blink_work
|
||||
run blink_work
|
||||
run blink_work
|
||||
mtd erase u-boot
|
||||
run blink_work
|
||||
run blink_work
|
||||
run blink_work
|
||||
mtd erase u-boot-env
|
||||
|
||||
led work on
|
||||
echo "Erased U-Boot from SPI Flash."
|
||||
while true; do sleep 1; done
|
||||
else
|
||||
echo "Error: No SPI flash."
|
||||
# blink both LEDs forever
|
||||
while true; do run blink_diy; run blink_work; done
|
||||
fi
|
||||
EOF
|
||||
|
||||
cat <<-'EOF' | tee "$R/tmp/kernels/u-boot-rockpro64/scripts/flash-spi.cmd" > /dev/null
|
||||
setenv blink_work 'led work on; sleep 0.1; led work off; sleep 0.1'
|
||||
setenv blink_diy 'led diy on; sleep 0.1; led diy off; sleep 0.1'
|
||||
|
||||
run blink_work
|
||||
if sf probe; then
|
||||
run blink_work
|
||||
|
||||
if size ${devtype} ${devnum}:${distro_bootpart} spi_combined.img; then
|
||||
run blink_work
|
||||
load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} spi_combined.img
|
||||
|
||||
# write flash
|
||||
run blink_work
|
||||
run blink_work
|
||||
run blink_work
|
||||
sf update ${kernel_addr_r} 0 ${filesize}
|
||||
run blink_work
|
||||
run blink_work
|
||||
run blink_work
|
||||
|
||||
led work on
|
||||
echo "Wrote U-Boot to SPI Flash successfully."
|
||||
while true; do sleep 1; done
|
||||
else
|
||||
echo "Error: Missing spi_combined.img"
|
||||
# blink red LED forever
|
||||
while true; do run blink_diy; sleep 0.1; done
|
||||
fi
|
||||
else
|
||||
echo "Error: No SPI flash."
|
||||
# blink both LEDs forever
|
||||
while true; do run blink_diy; run blink_work; done
|
||||
fi
|
||||
EOF
|
||||
|
||||
# The procedure if you have idbloader.img and u-boot.itb on an sdcard.
|
||||
cat <<-'EOF' | tee tee "$R/tmp/kernels/u-boot-rockpro64/scripts/load-spi-from-usb.cmd" > /dev/null
|
||||
if ls usb 0:1; then
|
||||
if sf probe; then
|
||||
load usb 0:1 ${fdt_addr_r} idbloader.img
|
||||
sf update ${fdt_addr_r} 0 ${filesize}
|
||||
load usb 0:1 ${fdt_addr_r} u-boot.itb
|
||||
sf update ${fdt_addr_r} 60000 ${filesize}
|
||||
else
|
||||
echo "Error: No SPI flash."
|
||||
# blink both LEDs forever
|
||||
while true; do run blink_diy; run blink_work; done
|
||||
fi
|
||||
else
|
||||
echo "Error: No USB available."
|
||||
fi
|
||||
EOF
|
||||
}
|
||||
|
||||
create-rockpro64-scripts(){
|
||||
cat <<-'EOF' | tee /usr/local/sbin/rockpro64_enable_eth_gadget.sh > /dev/null
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
# enable peripheral mode
|
||||
enable_dtoverlay usb0_dwc3_peripheral usb0/dwc3@fe800000 okay \
|
||||
'dr_mode="peripheral"'
|
||||
|
||||
# reload dwc3
|
||||
echo fe800000.dwc3 > /sys/bus/platform/drivers/dwc3/unbind
|
||||
echo fe800000.dwc3 > /sys/bus/platform/drivers/dwc3/bind
|
||||
|
||||
# install eth gadget
|
||||
install_gadget RockPro64 fe800000.dwc3 ecm
|
||||
EOF
|
||||
|
||||
cat <<-'EOF' | tee /usr/local/sbin/rockpro64_disable_otg.sh > /dev/null
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# enable peripheral mode
|
||||
disable_dtoverlay dwc3_peripheral
|
||||
|
||||
# reload dwc3
|
||||
echo fe800000.dwc3 > /sys/bus/platform/drivers/dwc3/unbind
|
||||
echo fe800000.dwc3 > /sys/bus/platform/drivers/dwc3/bind
|
||||
|
||||
# install eth gadget
|
||||
uninstall_gadgets
|
||||
EOF
|
||||
|
||||
cat <<-'EOF' | tee /usr/local/sbin/rockpro64_reset_emmc.sh > /dev/null
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$1" != "--force" ]]; then
|
||||
MNT_DEV=$(findmnt / -n -o SOURCE)
|
||||
if [[ "$MNT_DEV" == /dev/mmcblk1* ]]; then
|
||||
echo "Cannot reset when running from eMMC, use: $0 --force."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -d /sys/bus/platform/drivers/sdhci-arasan/fe330000.sdhci ]]; then
|
||||
echo "Unbinding..."
|
||||
echo fe330000.sdhci > /sys/bus/platform/drivers/sdhci-arasan/unbind
|
||||
fi
|
||||
|
||||
echo "Binding..."
|
||||
echo fe330000.sdhci > /sys/bus/platform/drivers/sdhci-arasan/bind
|
||||
|
||||
echo "Finished"
|
||||
EOF
|
||||
|
||||
cat <<-'EOF' | tee /usr/local/sbin/rockpro64_reset_spi_flash.sh > /dev/null
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -d /sys/bus/platform/drivers/rockchip-spi/ff1d0000.spi ]]; then
|
||||
echo "Unbinding..."
|
||||
echo ff1d0000.spi > /sys/bus/platform/drivers/rockchip-spi/unbind
|
||||
fi
|
||||
|
||||
echo "Binding..."
|
||||
echo ff1d0000.spi > /sys/bus/platform/drivers/rockchip-spi/bind
|
||||
|
||||
echo "Finished"
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
@ -1,25 +1,503 @@
|
|||
helper functions
|
||||
================
|
||||
These functions focus on supporting the arm-sdk and generating and writing the appropriate images to different block devices.
|
||||
# helper functions
|
||||
|
||||
These functions focus on supporting the arm-sdk and generating and writing the
|
||||
appropriate images to different block devices.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [build_atf()](#build_atf)
|
||||
- [build_uboot()](#build_uboot)
|
||||
- [set-bootloader()](#set-bootloader)
|
||||
- [bootloader-version()](#bootloader-version)
|
||||
- [upgrade-sd-bootloader()](#upgrade-sd-bootloader)
|
||||
- [erase-sd-bootloader()](#erase-sd-bootloader)
|
||||
- [write-emmc-flash()](#write-emmc-flash)
|
||||
- [erase-spi-flash()](#erase-spi-flash)
|
||||
- [write-spi-flash()](#write-spi-flash)
|
||||
- [create-u-boot-menu()](#create-u-boot-menu)
|
||||
- [create_spi_image()](#create-spi-image)
|
||||
- [spi_flash_img()](#spi-flash-img)
|
||||
- [create-u-boot-spi-scripts()](#create-u-boot-spi-scripts)
|
||||
- [create-rockpro64-scripts()](#create-rockpro64-scripts)
|
||||
|
||||
## build_atf()
|
||||
|
||||
This function automates the process of building the ARM Trusted Firmware (ATF) for the Rockchip RK3399 platform. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `build_atf()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It sets up the required environment variables such as `strapdir`, `atf_branch`, `atfgit`, and `compiler`. These variables are essential for specifying the location of the ATF source code, the branch to checkout, the Git repository URL, and the compiler to use.
|
||||
|
||||
2. **Git Configuration**: The function configures Git with a global username and email address. This is necessary for committing changes during the build process.
|
||||
|
||||
3. **Cloning the ATF Repository**: It clones the specified branch of the ATF repository into a temporary directory. This ensures that the build process uses the correct version of the ATF source code.
|
||||
|
||||
4. **Cleaning and Building**: The function cleans any previous build artifacts using `make realclean` and then builds the `bl31.elf` file for the RK3399 platform using the specified compiler and platform settings. The build process is parallelized across all available processors for efficiency.
|
||||
|
||||
5. **Error Handling**: Throughout the process, error handling is implemented to ensure that any issues encountered during the cloning or building stages are promptly reported and handled.
|
||||
|
||||
6. **Output**: After a successful build, the `bl31.elf` file is copied to a distribution directory. This file is crucial for the boot process of devices running the RK3399 platform.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variables (`strapdir`, `atf_branch`, `atfgit`, and `compiler`) are set appropriately. Then, simply call `build_atf()` in your script or terminal to initiate the build process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
|
||||
### References
|
||||
|
||||
- ARM Trusted Firmware documentation for RK3399: [Source 0](http://opensource.rock-chips.com/wiki_ATF)
|
||||
- General guidance on building ATF: [Source 4](https://github.com/skiffos/rk3399-firmware-blobs)
|
||||
|
||||
## build_uboot()
|
||||
|
||||
This function automates the process of building U-Boot for the Rockchip RK3399 platform, specifically tailored for the RockPro64 device. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `build_uboot()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It sets up the required environment variables such as `strapdir`, `ubootgit`, `uboot_branch`, and `MAKEOPTS`. These variables are essential for specifying the location of the U-Boot source code, the branch to checkout, the Git repository URL, and the make options to use.
|
||||
|
||||
2. **Git Clone**: The function clones the specified branch of the U-Boot repository into a temporary directory. This ensures that the build process uses the correct version of the U-Boot source code.
|
||||
|
||||
3. **Configuration**: It applies various configurations to the U-Boot build process to enable specific features and functionalities. This includes enabling support for ZFS, EFI Secure Boot, and various command-line interfaces among others.
|
||||
|
||||
4. **Building**: The function cleans any previous build artifacts using `make mrproper` and then builds U-Boot using the specified make options and cross-compiler. The build process is parallelized across all available processors for efficiency.
|
||||
|
||||
5. **Image Creation**: After a successful build, the function creates two types of boot images: one for SD boot (`idbloader.img`) and another for SPI boot (`u-boot.itb`). These images are generated using the `mkimage` tool and are crucial for the boot process of devices running the RK3399 platform.
|
||||
|
||||
6. **Output**: The generated images are copied to a distribution directory. This allows for easy distribution and deployment of the built U-Boot images.
|
||||
|
||||
7. **Error Handling**: Throughout the process, error handling is implemented to ensure that any issues encountered during the cloning, configuration, or building stages are promptly reported and handled.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variables (`strapdir`, `ubootgit`, `uboot_branch`, and `MAKEOPTS`) are set appropriately. Then, simply call `build_uboot()` in your script or terminal to initiate the build process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for RK3399: [Source 0](http://www.denx.de/wiki/U-Boot/RK3399)
|
||||
- General guidance on building U-Boot: [Source 4](https://www.u-boot.org/docs/)
|
||||
|
||||
## set-bootloader()
|
||||
## bootloader-sd-version()
|
||||
|
||||
This function automates the process of setting the appropriate bootloader for different Rockchip-based boards, including Rock64, RockPro64, PineBook Pro, and RockPi4B. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `set-bootloader()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **Board Detection**: Based on the input argument (`$1`), the function determines the target board (Rock64, RockPro64, PineBook Pro, or RockPi4B) and sets the appropriate loader images (`SD_LOADER` and `SPI_LOADER`) and board identifier (`BOARD`). This is done through a case statement that matches the input against predefined patterns.
|
||||
|
||||
3. **Error Handling for Unknown Boards**: If the input does not match any of the predefined patterns, the function prints an error message and exits with a failure status. This ensures that only supported boards can proceed with the bootloader setup.
|
||||
|
||||
4. **Device Tree Check**: Before proceeding, the function checks if the current running board matches the detected board (`BOARD`). This is done by comparing the board identifier against the `/proc/device-tree/compatible` file. If there is a mismatch, the function warns the user about the potential risks of proceeding with an incorrect board setup.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, pass the board identifier as an argument when calling `set-bootloader()`. For example, to set the bootloader for a RockPro64, you would call `set-bootloader rockchip-rockpro64`.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- Rockchip documentation for bootloader setup: [Source 0](http://www.rock-chips.com.cn/en/doc_download.php?bid=1043)
|
||||
- General guidance on setting bootloaders for Rockchip boards: [Source 4](https://www.rockchip.com.cn/)
|
||||
|
||||
## bootloader-version()
|
||||
|
||||
This function automates the process of retrieving the version information of the U-Boot bootloader installed on a Rockchip-based board. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `bootloader-version()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **Version Retrieval**: The function defines a nested function `version()` that takes a device identifier as an argument. This function attempts to retrieve the U-Boot version and other relevant information (such as the board and FDT file) from the specified device. It does this by using the `strings` command to parse the device's contents for U-Boot version strings and other metadata.
|
||||
|
||||
3. **Error Handling**: If the U-Boot version cannot be found on the specified device, the function prints a message indicating that U-Boot is not installed on the device.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, pass the device identifier as an argument when calling `bootloader-version()`. For example, to retrieve the U-Boot version from a device named `mmcblk0boot0`, you would call `bootloader-version mmcblk0boot0`.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for version retrieval: [Source 1](https://stackoverflow.com/questions/5781738/getting-u-boots-version-from-userspace)
|
||||
- General guidance on working with U-Boot versions: [Source 2](https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Custom-Scripts-in-U-Boot/ta-p/1792382)
|
||||
|
||||
## upgrade-sd-bootloader()
|
||||
|
||||
This function automates the process of upgrading the bootloader on an SD card for Rockchip-based boards. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `upgrade-sd-bootloader()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variables (`strapdir` and `SD_LOADER`). These variables are essential for specifying the root directory where the necessary files are located and the path to the new bootloader image.
|
||||
|
||||
2. **Mount Check**: The function checks if the EFI partition is mounted. This is crucial for writing the new bootloader image to the correct partition. If the EFI partition is not mounted, the function prints an error message and exits with a failure status.
|
||||
|
||||
3. **Report Current Version**: Before upgrading, the function retrieves and reports the current version of the bootloader installed on the device. This is done by calling the `bootloader-version()` function with the device identifier obtained from the mounted EFI partition.
|
||||
|
||||
4. **Bootloader Upgrade**: The function defines a nested function `write_sd()` that takes a device identifier and the path to the new bootloader image as arguments. This function writes the new bootloader image to a specific partition on the SD card. It assumes that the new bootloader image is intended for a partition numbered `p1` on SD devices.
|
||||
|
||||
5. **Sync**: After writing the new bootloader image, the function calls `sync` to ensure that all pending writes to the disk are completed.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variables (`strapdir` and `SD_LOADER`) are set appropriately. Then, simply call `upgrade-sd-bootloader()` in your script or terminal to initiate the bootloader upgrade process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for bootloader upgrade: [Source 0](http://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on upgrading bootloaders on SD cards: [Source 1](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
||||
## erase-sd-bootloader()
|
||||
|
||||
This function automates the process of erasing the bootloader on an SD card for Rockchip-based boards. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `erase-sd-bootloader()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **Mount Check**: The function identifies the device associated with the mounted EFI partition. This is crucial for determining which partition to erase. If the EFI partition is not mounted, the function prints an error message and exits with a failure status.
|
||||
|
||||
3. **Report Current Version**: Before erasing, the function retrieves and reports the current version of the bootloader installed on the device. This is done by calling the `bootloader-version()` function with the device identifier obtained from the mounted EFI partition.
|
||||
|
||||
4. **Erase Bootloader**: The function defines a nested function `write_sd()` that takes a device identifier and the path to the erase block as arguments. This function writes zeros to a specific partition on the SD card, effectively erasing the bootloader. It assumes that the erase operation is intended for a partition numbered `p1` on SD devices.
|
||||
|
||||
5. **Sync**: After erasing the bootloader, the function calls `sync` to ensure that all pending writes to the disk are completed.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `erase-sd-bootloader()` in your script or terminal to initiate the bootloader erasure process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for bootloader erasure: [Source 0](http://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on erasing bootloaders on SD cards: [Source 1](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
||||
## create_spi_image()
|
||||
|
||||
This function automates the creation of a single SPI flash image for the Rockchip RK3399 platform, specifically tailored for devices that require a combined SPI flash image containing both the U-Boot ITB (Image Transfer Buffer) and a custom script for flashing the SPI flash. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `create_spi_image()` function performs the following actions:
|
||||
|
||||
1. **Initialization**: It starts by calculating the padding size needed to align the U-Boot ITB at a specific memory address (0x60000 in this case). This is crucial for ensuring that the U-Boot ITB is correctly positioned within the SPI flash.
|
||||
|
||||
2. **Padding**: The function creates a zero-filled file (`$(img1name)`) with a size equal to the calculated padding size. This file serves as the initial part of the SPI flash image, ensuring that the U-Boot ITB is correctly aligned.
|
||||
|
||||
3. **Combining Images**: It concatenates the padded file with the U-Boot ITB file (`u-boot.itb`) to form a single SPI flash image. This combined image is then saved to a distribution directory.
|
||||
|
||||
4. **Script Creation**: The function calls `create-u-boot-spi-scripts` to generate the necessary scripts for flashing the SPI flash. This includes creating a script for flashing the SPI flash with the newly created SPI flash image.
|
||||
|
||||
5. **SPI Flash Image Creation**: Finally, the function uses the `mkimage` tool to create a script image (`flash_spi.scr`) that contains the commands for flashing the SPI flash. This script is also saved to the distribution directory.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variables (`img1name`) are set appropriately. Then, simply call `create_spi_image()` in your script or terminal to initiate the SPI flash image creation process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for RK3399: [Source 0](http://www.denx.de/wiki/U-Boot/RK3399)
|
||||
- General guidance on creating SPI flash images: [Source 4](https://www.u-boot.org/docs/)
|
||||
|
||||
## spi_flash_img()
|
||||
|
||||
This function automates the creation of an SD card image that can be flashed onto an SPI flash chip, specifically for booting U-Boot from SPI on Rockchip RK3399 platforms. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `spi_flash_img()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **Copying Scripts**: The function copies the `flash_spi.scr` script and the `spi_combined.img` image to the current working directory. These files are necessary for flashing the SPI flash and contain the U-Boot ITB (Image Transfer Buffer) and a custom script for flashing the SPI flash.
|
||||
|
||||
3. **Creating Temporary File System**: It creates a temporary FAT32 file system (`boot.tmp`) with a size of 16MB. This file system will be used to store the boot scripts and images.
|
||||
|
||||
4. **Copying Boot Scripts and Images**: The function copies the `boot.scr` script and the `spi_combined.img` image into the temporary file system. This prepares the boot environment on the SD card.
|
||||
|
||||
5. **Creating Main SPI Flash Image**: It creates a new image (`flash_spi.img`) with a size of 32MB. This image will serve as the main SPI flash image for booting U-Boot.
|
||||
|
||||
6. **Partitioning the SPI Flash Image**: The function partitions the `flash_spi.img` into three parts: `loader1`, `loader2`, and `boot`. Each partition is assigned a specific size and purpose, with `loader1` and `loader2` likely serving as loaders for the U-Boot SPL (Secondary Program Loader), and `boot` being formatted as FAT16 to store the boot scripts and images.
|
||||
|
||||
7. **Setting Legacy Boot Flag**: The `legacy_boot` flag is set on the `boot` partition to indicate that it should be used for booting.
|
||||
|
||||
8. **Writing U-Boot Images**: The function writes the `idbloader.img` and `u-boot.itb` images to the `loader1` and `loader2` partitions of the `flash_spi.img`, respectively. This prepares the SPI flash for booting U-Boot.
|
||||
|
||||
9. **Writing Boot Scripts and Images**: The `boot.tmp` file system is written to the `boot` partition of the `flash_spi.img`. This includes the `boot.scr` script and the `spi_combined.img` image.
|
||||
|
||||
10. **Compressing the SPI Flash Image**: Finally, the `flash_spi.img` is compressed using gzip. This reduces the size of the image, making it easier to transfer and flash onto the SPI flash chip.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `spi_flash_img()` in your script or terminal to initiate the creation of the SD card image for SPI flashing.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
- `dd`, `mkfs.vfat`, `mcopy`, `parted`, and `gzip` utilities.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for RK3399: [Source 0](http://www.denx.de/wiki/U-Boot/RK3399)
|
||||
- General guidance on creating bootable SD cards with U-Boot: [Source 2](https://forum.armbian.com/topic/17650-how-to-make-a-sd-card-bootable-with-u-boot/)
|
||||
|
||||
## erase-spi-flash()
|
||||
|
||||
This function automates the process of erasing the SPI flash memory on embedded systems. It is designed to simplify the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `erase-spi-flash()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **SPI Flash Device Identification**: The function searches for the SPI flash device by looking for the string "loader" in `/proc/mtd`. If the loader partition on MTD is not found, the function prints an error message and exits with a failure status.
|
||||
|
||||
3. **Reporting Current Version**: The function reports the current bootloader version by querying the device identified in the previous step.
|
||||
|
||||
4. **Erasing SPI Flash**: The function erases the entire SPI flash memory by calling `flash_erase` with the identified device and offsets for each partition.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `erase-spi-flash()` in your script or terminal to initiate the SPI flash erasing process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for erasing SPI flash: [Source 0](http://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on erasing SPI flash on embedded systems: [Source 1](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
||||
## write-spi-flash()
|
||||
|
||||
This function automates the process of writing to the SPI flash memory on embedded systems. It is designed to simplify the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `write-spi-flash()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **SPI Flash Device Identification**: The function searches for the SPI flash device by looking for the string "u-boot-spl" in `/proc/mtd`. If the "u-boot-spl" partition on MTD is not found, the function prints an error message and exits with a failure status.
|
||||
|
||||
3. **Writing to SPI Flash**: The function writes the content of the specified file to the identified SPI flash device. It first erases the device using `flash_erase` and then writes the content using `nandwrite`.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `write-spi-flash()` in your script or terminal to initiate the SPI flash writing process.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for writing to SPI flash: [Source 1](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842223/U-boot?view=blog)
|
||||
- General guidance on writing to SPI flash on embedded systems: [Source 3](https://unix.stackexchange.com/questions/743524/how-to-write-data-to-raw-nand-flash-through-dev-mtd0-in-linux)
|
||||
|
||||
## write-emmc-flash()
|
||||
|
||||
This function automates the process of writing U-Boot to the eMMC storage on Rockchip-based boards. It is designed to streamline the development and testing process by encapsulating the necessary steps into a single script.
|
||||
|
||||
### Description
|
||||
|
||||
The `write-emmc-flash()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **eMMC Device Identification**: The function iterates over all MMC block devices to identify the eMMC device. It does this by checking the device type in `/sys/block/<device>/device/type`. Once identified, the eMMC device is stored in the `emmc_blkdevice` variable.
|
||||
|
||||
3. **Mount Check**: The function identifies the device currently mounted as the root filesystem. If the root filesystem is on the eMMC device, the function prints a warning message and exits with a failure status, preventing accidental overwriting of the running system.
|
||||
|
||||
4. **Writing U-Boot to eMMC**: The function writes the U-Boot IDBLoader and U-Boot ITB images to the eMMC device. It does this by using the `dd` command to copy the images to the correct offsets on the eMMC device. The IDBLoader is written to offset 64, and the U-Boot ITB is written to offset 16384.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `write-emmc-flash()` in your script or terminal to initiate the U-Boot writing process to the eMMC.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for writing to eMMC: [Source 0](http://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on writing U-Boot to eMMC on Rockchip boards: [Source 1](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
||||
## create-u-boot-menu()
|
||||
|
||||
This function automates the creation of a U-Boot menu for booting various operating systems or configurations. It is designed to simplify the setup process for developers working with U-Boot on embedded systems.
|
||||
|
||||
### Description
|
||||
|
||||
The `create-u-boot-menu()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **U-Boot Menu Configuration**: The function creates a U-Boot script (`boot.cmd`) that defines a boot menu with several options for booting different kernels or resetting the board. This script is then compiled into a U-Boot script image (`boot.scr`) using the `mkimage` tool.
|
||||
|
||||
3. **U-Boot Script Compilation**: The function compiles the `boot.cmd` script into a U-Boot script image (`boot.scr`) using the `mkimage` tool. This image is used by U-Boot to execute the boot menu.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `create-u-boot-menu()` in your script or terminal to generate the U-Boot boot menu.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for creating boot menus: [Source 1](https://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on configuring U-Boot for booting various operating systems: [Source 2](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
||||
## create-u-boot-spi-scripts()
|
||||
|
||||
"$R/tmp/kernels/u-boot-rockpro64"/scripts/load-spi-from-usb.cmd
|
||||
"$R/tmp/kernels/u-boot-rockpro64"/scripts/flash-spi.cmd
|
||||
"$R/tmp/kernels/u-boot-rockpro64"/scripts/erase_spi.cmd
|
||||
|
||||
## create-u-boot-spi-scripts()
|
||||
|
||||
This function automates the creation of U-Boot SPI flash scripts for RockPro64 boards. It simplifies the process of erasing, flashing, and loading U-Boot to SPI flash, making it easier for developers to manage the boot process.
|
||||
|
||||
### Description
|
||||
|
||||
The `create-u-boot-spi-scripts()` function performs the following actions:
|
||||
|
||||
1. **Preparation**: It checks for the presence of the required environment variable (`strapdir`). This variable is essential for specifying the root directory where the necessary files are located.
|
||||
|
||||
2. **Script Creation**:
|
||||
|
||||
- `erase_spi.cmd`: This script erases the U-Boot partitions from SPI flash. It includes visual feedback through LED blinking to indicate progress.
|
||||
- `flash-spi.cmd`: This script flashes the U-Boot image to SPI flash. Similar to the erase script, it uses LED indicators to show the operation's progress.
|
||||
- `load-spi-from-usb.cmd`: This script loads U-Boot from a USB drive to SPI flash. It checks for the presence of the necessary files on the USB drive before proceeding.
|
||||
|
||||
3. **Script Compilation**: The function compiles these scripts into U-Boot script images using the `mkimage` tool, making them ready for use in U-Boot.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, ensure that the required environment variable (`strapdir`) is set appropriately. Then, simply call `create-u-boot-spi-scripts()` in your script or terminal to generate the U-Boot SPI flash scripts.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- A compatible cross-compiler for ARM architecture.
|
||||
- Git installed on the system.
|
||||
- Make utility.
|
||||
- U-Boot source code and tools.
|
||||
|
||||
### References
|
||||
|
||||
- U-Boot documentation for scripting: [Source 1](https://www.denx.de/wiki/U-Boot/Manuals)
|
||||
- General guidance on managing U-Boot on RockPro64 boards: [Source 2](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)```
|
||||
|
||||
## create-rockpro64-scripts()
|
||||
|
||||
/usr/local/sbin/rockpro64_reset_spi_flash.sh
|
||||
/usr/local/sbin/rockpro64_reset_emmc.sh
|
||||
/usr/local/sbin/rockpro64_disable_otg.sh
|
||||
/usr/local/sbin/rockpro64_enable_eth_gadget.sh
|
||||
|
||||
This function automates the creation of shell scripts for managing Ethernet gadget functionality and resetting the eMMC and SPI flash on RockPro64 boards. It simplifies the process of enabling and disabling Ethernet gadget mode, resetting the eMMC, and resetting the SPI flash, making it easier for developers to manage the board's configuration.
|
||||
|
||||
### Description
|
||||
|
||||
The `create-rockpro64-scripts()` function performs the following actions:
|
||||
|
||||
1. **Script Creation**:
|
||||
|
||||
- `rockpro64_enable_eth_gadget.sh`: This script enables the Ethernet gadget mode on the RockPro64 board, allowing it to act as a network device. It involves enabling the `usb0_dwc3_peripheral` overlay, reloading the DWC3 driver, and installing the Ethernet gadget.
|
||||
- `rockpro64_disable_otg.sh`: This script disables the Ethernet gadget mode, effectively turning off the board's ability to act as a network device. It involves disabling the `dwc3_peripheral` overlay and unbinding the DWC3 driver.
|
||||
- `rockpro64_reset_emmc.sh`: This script resets the eMMC interface on the RockPro64 board. It checks if the script is being run from the eMMC and prevents execution if so, unless the `--force` option is provided. It then unbinds and binds the SDHCI driver to reset the interface.
|
||||
- `rockpro64_reset_spi_flash.sh`: This script resets the SPI flash interface on the RockPro64 board. It unbinds and binds the SPI driver to reset the interface.
|
||||
|
||||
2. **Script Compilation**: The function compiles these scripts into executable files, making them ready for use in the terminal or included in other scripts.
|
||||
|
||||
### Usage
|
||||
|
||||
To use this function, simply call `create-rockpro64-scripts()` in your script or terminal. This will generate the necessary shell scripts in the `/usr/local/sbin/` directory, which can then be executed as needed.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Bash shell.
|
||||
- Access to the RockPro64 board's device tree overlays and drivers.
|
||||
|
||||
### References
|
||||
|
||||
- RockPro64 documentation for managing Ethernet gadget mode: [Source 1](https://www.pine64.org/docs/)
|
||||
- General guidance on managing RockPro64 interfaces: [Source 2](https://forum.armbian.com/topic/20847-the-boot-process-and-various-devices/)
|
||||
|
|
|
|||
Loading…
Reference in New Issue