Skip to content
Snippets Groups Projects
Commit ce0728f7 authored by Dan Johansen's avatar Dan Johansen Committed by Philip Müller
Browse files

Switch to autoflash and use boot.scr

parent cadbc28b
No related branches found
No related tags found
1 merge request!1Switch to autoflash and use boot.scr
# U-Boot: Pinephone Pro based on PKGBUILD for RK3399 # U-Boot: Pinephone Pro based on PKGBUILD for RK3399
# Contributor: Furkan Kardame <furkan@fkardame.com> # Contributor: Furkan Kardame <furkan@fkardame.com>
# Contributor: Dan Johansen <strit@manjaro.org>
# Contributor: Dragan Simic <dsimic@buserror.io>
pkgname=uboot-pinephonepro pkgname=uboot-pinephonepro
pkgver=2021.01rc3 pkgver=2021.01rc3
pkgrel=5 pkgrel=6
epoch=1 epoch=1
_srcname=u-boot-pine64-pinephonepro _srcname=u-boot-pine64-pinephonepro
_commit=0719bf42931033c3109ecc6357e8adb567cb637b _commit=0719bf42931033c3109ecc6357e8adb567cb637b
_tfaver=2.6 _tfaver=2.6
pkgdesc="U-Boot for Pinephone Pro" pkgdesc="U-Boot for Pine64 PinePhone Pro"
arch=('aarch64') arch=('aarch64')
url='https://git.sr.ht/~martijnbraam/u-boot' url='https://git.sr.ht/~martijnbraam/u-boot'
license=('GPL') license=('GPL')
makedepends=('git' 'arm-none-eabi-gcc' 'dtc' 'bc') makedepends=('git' 'arm-none-eabi-gcc' 'dtc' 'bc')
depends=('uboot-tools')
provides=('uboot') provides=('uboot')
conflicts=('uboot') conflicts=('uboot')
install=${pkgname}.install install=${pkgname}.install
source=("u-boot-$_commit.tar.gz::https://source.denx.de/u-boot/u-boot/-/archive/${_commit}/u-boot-${_commit}.tar.gz" source=("u-boot-$_commit.tar.gz::https://source.denx.de/u-boot/u-boot/-/archive/${_commit}/u-boot-${_commit}.tar.gz"
"https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/snapshot/trusted-firmware-a-$_tfaver.tar.gz" "https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/snapshot/trusted-firmware-a-$_tfaver.tar.gz"
"boot.txt"
"ppp-prepare-fstab"
"ppp-prepare-fstab.service"
"ppp-uboot-flash"
"ppp-uboot-mkscr"
0001-PPP.patch 0001-PPP.patch
0002-Add-ppp-dt.patch 0002-Add-ppp-dt.patch
0003-Config-changes.patch 0003-Config-changes.patch
...@@ -29,6 +37,11 @@ source=("u-boot-$_commit.tar.gz::https://source.denx.de/u-boot/u-boot/-/archive/ ...@@ -29,6 +37,11 @@ source=("u-boot-$_commit.tar.gz::https://source.denx.de/u-boot/u-boot/-/archive/
0009-Correct-boot-order-to-be-USB-SD-eMMC.patch) 0009-Correct-boot-order-to-be-USB-SD-eMMC.patch)
sha256sums=('6b196b6592fabed060b7c5b1fa05a743f9be131d11389b762b7d0e2beebbd381' sha256sums=('6b196b6592fabed060b7c5b1fa05a743f9be131d11389b762b7d0e2beebbd381'
'4e59f02ccb042d5d18c89c849701b96e6cf4b788709564405354b5d313d173f7' '4e59f02ccb042d5d18c89c849701b96e6cf4b788709564405354b5d313d173f7'
'4e356b3868c0c1ac061c2c15c7ba80c627e1743214680409f418f9b4c00eb3f7'
'de7e36cdc7ed2fb5abb9155c97f87926361aa5be87d794c9016776160f3430ec'
'e55fb02dfb6213eabbb899b468dc5f68d36a11c05feda4c14e80282415222fea'
'6265fb9d3bc84bf1217383b52587b1d5a36372d88a824932586a802a502f62ba'
'05eaccb2e8ea1eba3e86a4e7fcf12fd232195b5018c049ddf36e5a82a968cc24'
'f2e9d4efd24b7a6d94ccfe8c1a6fd0fac04776483be7a2d343f5b7a6b50a8ff2' 'f2e9d4efd24b7a6d94ccfe8c1a6fd0fac04776483be7a2d343f5b7a6b50a8ff2'
'c889eb1b55868a3d007be6f5c618823faca70905ce4a4047cd98bdcbfb48d6ab' 'c889eb1b55868a3d007be6f5c618823faca70905ce4a4047cd98bdcbfb48d6ab'
'355444b20346bb5adbc531b1a8813483bb8e8e6a0b884139479dbf2ad342ef79' '355444b20346bb5adbc531b1a8813483bb8e8e6a0b884139479dbf2ad342ef79'
...@@ -52,21 +65,41 @@ prepare() { ...@@ -52,21 +65,41 @@ prepare() {
} }
build() { build() {
cd trusted-firmware-a-$_tfaver # Avoid build warnings by editing a .config option in place instead of
# appending an option to .config, if an option is already present
update_config() {
if ! grep -q "^$1=$2$" .config; then
if grep -q "^# $1 is not set$" .config; then
sed -i -e "s/^# $1 is not set$/$1=$2/g" .config
elif grep -q "^$1=" .config; then
sed -i -e "s/^$1=.*/$1=$2/g" .config
else
echo "$1=$2" >> .config
fi
fi
}
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
cd trusted-firmware-a-$_tfaver
echo -e "\nBuilding TF-A for Pine64 PinePhone Pro...\n"
make PLAT=rk3399 make PLAT=rk3399
cp build/rk3399/release/bl31/bl31.elf ../u-boot-${_commit} cp build/rk3399/release/bl31/bl31.elf ../u-boot-${_commit}
cd ../u-boot-${_commit} cd ../u-boot-${_commit}
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
echo -e "\nBuilding U-Boot for Pine64 PinePhone Pro...\n"
make pinephone-pro-rk3399_defconfig make pinephone-pro-rk3399_defconfig
echo 'CONFIG_IDENT_STRING=" Manjaro ARM"' >> .config
echo 'CONFIG_USB_EHCI_HCD=n' >> .config update_config 'CONFIG_IDENT_STRING' '" Manjaro Linux ARM"'
echo 'CONFIG_USB_EHCI_GENERIC=n' >> .config update_config 'CONFIG_BOOTDELAY' '0'
echo 'CONFIG_USB_XHCI_HCD=n' >> .config update_config 'CONFIG_USB_EHCI_HCD' 'n'
echo 'CONFIG_USB_XHCI_DWC3=n' >> .config update_config 'CONFIG_USB_EHCI_GENERIC' 'n'
echo 'CONFIG_USB_DWC3=n' >> .config update_config 'CONFIG_USB_XHCI_HCD' 'n'
echo 'CONFIG_USB_DWC3_GENERIC=n' >> .config update_config 'CONFIG_USB_XHCI_DWC3' 'n'
echo 'CONFIG_BOOTDELAY=0' >> .config update_config 'CONFIG_USB_DWC3' 'n'
update_config 'CONFIG_USB_DWC3_GENERIC' 'n'
make EXTRAVERSION=-${pkgrel} make EXTRAVERSION=-${pkgrel}
} }
...@@ -74,7 +107,11 @@ build() { ...@@ -74,7 +107,11 @@ build() {
package() { package() {
cd u-boot-${_commit} cd u-boot-${_commit}
mkdir -p "${pkgdir}/boot/extlinux" install -D -m 0644 idbloader.img u-boot.itb -t "${pkgdir}/boot"
cp idbloader.img u-boot.itb "${pkgdir}/boot/" install -D -m 0644 "${srcdir}/boot.txt" -t "${pkgdir}/boot"
} install -D -m 0755 "${srcdir}/ppp-uboot-mkscr" -t "${pkgdir}/usr/bin"
install -D -m 0755 "${srcdir}/ppp-prepare-fstab" -t "${pkgdir}/usr/bin"
install -D -m 0644 "${srcdir}/ppp-prepare-fstab.service" -t "${pkgdir}/usr/lib/systemd/system"
install -D -m 0755 "${srcdir}/ppp-uboot-flash" -t "${pkgdir}/usr/bin"
}
boot.txt 0 → 100644
#
# /boot/boot.txt
# After modifying, run "ppp-uboot-mkscr" to re-generate the U-Boot boot script.
#
#
# This is the description of the GPIO lines used in this boot script:
#
# GPIO #105 is GPIO3_B1, or RK3399 ball C27, which controls the vibrator motor
# GPIO #154 is GPIO4_D2, or RK3399 ball AH3, which controls the red part of the multicolor LED
# GPIO #157 is GPIO4_D5, or RK3399 ball AJ3, which controls the green part of the multicolor LED
# GPIO #158 is GPIO4_D6, or RK3399 ball AG4, which controls the blue part of the multicolor LED
#
gpio set 105
gpio set 154
# Set root partition to the second partition of boot device
part uuid ${devtype} ${devnum}:1 uuid_boot
part uuid ${devtype} ${devnum}:2 uuid_root
setenv bootargs loglevel=4 console=tty0 console=${console} earlycon=uart8250,mmio32,0xff1a0000 consoleblank=0 boot=PARTUUID=${uuid_boot} root=PARTUUID=${uuid_root} rw rootwait quiet audit=0 bootsplash.bootfile=bootsplash-themes/manjaro/bootsplash
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} /Image; then
gpio clear 105
if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /dtbs/${fdtfile}; then
if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /initramfs-linux.img; then
gpio set 157
booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
else
gpio set 158
booti ${kernel_addr_r} - ${fdt_addr_r};
fi;
fi;
fi
# EOF
#!/bin/bash
#
# /usr/bin/ppp-prepare-fstab
# This script will be executed automatically on boot, and only once.
#
FSTAB="/etc/fstab"
kernel_cmdline() {
for param in $(cat /proc/cmdline); do
case "${param}" in
$1=*) echo "${param##*=}"; return 0 ;;
$1) return 0 ;;
*) continue ;;
esac
done
[ -n "${2}" ] && echo "${2}"
return 1
}
PART_BOOT=$(kernel_cmdline boot)
PART_ROOT=$(kernel_cmdline root)
if [[ -z ${PART_BOOT} ]]; then
echo "Failed to determine boot partition, no changes made to ${FSTAB}."
exit 1
fi
if [[ -z ${PART_ROOT} ]]; then
echo "Failed to determine root partition, no changes made to ${FSTAB}."
exit 1
fi
sed -i -e '/[ \t]\+\/boot[ \t]\+/d' ${FSTAB}
sed -i -e '/[ \t]\+\/[ \t]\+/d' ${FSTAB}
echo "PARTUUID=${PART_BOOT} /boot vfat defaults,noexec,nodev,showexec 0 0" >> ${FSTAB}
echo "PARTUUID=${PART_ROOT} / auto defaults 0 0" >> ${FSTAB}
echo "Configured ${FSTAB} to use ${PART_BOOT} and ${PART_ROOT} as boot and root partitions, respectively."
mount -a
# EOF
[Unit]
Description=Prepare Partition Mounts
Before=local-fs.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/ppp-prepare-fstab
ExecStartPost=/usr/bin/systemctl disable ppp-prepare-fstab.service
[Install]
WantedBy=local-fs.target
#!/bin/bash
#
# /usr/bin/ppp-uboot-flash
# Utility that flashes selected U-Boot image to the boot device.
#
# Check that we're running as root
if [[ ${EUID} != 0 ]]; then
echo "Flashing U-Boot image not possible, please execute this utility as root."
exit 1
fi
# Get the device that the root resides on, and remove "/dev/" from the device name
ROOT_DEV=`findmnt / -o source -n | cut -d "[" -f 1 | cut -d "/" -f 3`
# Get the full real name of the root device, which is usually "/dev/mmcblk0"
ROOT_DEV_NAME="/dev/"`echo /sys/block/*/${ROOT_DEV} | cut -d "/" -f 4`
# Verify that the determined root device is available, just in case
if [[ ! -r ${ROOT_DEV_NAME} ]]; then
echo "Flashing U-Boot not possible, device ${ROOT_DEV_NAME} not found. No changes made to U-Boot."
exit 1
fi
# Get the U-Boot component names and check that they exist
IDBLOADER_IMG="/boot/idbloader.img"
U_BOOT_ITB="/boot/u-boot.itb"
for COMPONENT in ${IDBLOADER_IMG} ${U_BOOT_ITB}; do
if [[ ! -r ${COMPONENT} ]]; then
echo "Flashing U-Boot not possible, file ${COMPONENT} not found. No changes made to U-Boot."
exit 1
fi
done
# Flash the first of the selected U-Boot components to the determined root device
echo -n "Flashing U-Boot components..."
dd if=${IDBLOADER_IMG} of=${ROOT_DEV_NAME} seek=64 conv=notrunc,fsync > /dev/null 2>&1
STATUS_IMG=$?
STATUS_ITB=0
# Now flash the second U-Boot component, but only if the first one flashed successfully
if [[ ${STATUS_IMG} = 0 ]]; then
dd if=${U_BOOT_ITB} of=${ROOT_DEV_NAME} seek=16384 conv=notrunc,fsync > /dev/null 2>&1
STATUS_ITB=$?
fi
# At the end, display the final status message of the U-Boot flashing
if [[ ${STATUS_IMG} = 0 && ${STATUS_ITB} = 0 ]]; then
echo " done."
echo "Required U-Boot components flashed to ${ROOT_DEV_NAME} successfully."
echo "Please reboot your phone for the changes to take effect."
else
echo " failed."
echo "Flashing U-Boot components to ${ROOT_DEV_NAME} failed due to unknown reason."
echo "Please try flashing the U-Boot again, or your phone may no longer boot properly."
exit 1
fi
# EOF
#!/bin/bash
#
# /usr/bin/ppp-uboot-mkscr
# Utility that generates the U-Boot boot script.
#
# Source and destination file paths
BOOT_TXT="/boot/boot.txt"
BOOT_SCR="/boot/boot.scr"
# Boot script description
IMAGE_DESC="U-Boot boot script"
# Determine the performed action
if [[ ! -r ${BOOT_SCR} ]]; then
ACTION="Generating"
else
ACTION="Re-generating"
fi
# Check that we're running as root
if [[ ${EUID} != 0 ]]; then
echo "${ACTION} ${IMAGE_DESC} not possible, please execute this utility as root."
exit 1
fi
# Make sure that the required utility is available
if [[ ! -x /usr/bin/mkimage ]]; then
echo "${ACTION} ${IMAGE_DESC} not possible, mkimage utility not found."
echo "Please install the uboot-tools package, by running the following command:"
echo " pacman -S uboot-tools"
exit 1
fi
# Check that the source file exists
if [[ ! -r ${BOOT_TXT} ]]; then
echo "${ACTION} ${IMAGE_DESC} not possible, file ${BOOT_TXT} not found."
echo "Please reinstall the uboot-pinephone package, by running the following command:"
echo " pacman -S uboot-pinephone"
exit 1
fi
# Is this a quiet execution?
VERBOSE=true
while getopts "q" SWITCH; do
if [[ ${SWITCH} = "q" ]]; then
VERBOSE=false
fi
done
# Generate the U-Boot boot script
echo -n "${ACTION} ${IMAGE_DESC} ${BOOT_SCR}..."
if [[ ${VERBOSE} = true ]]; then
echo
mkimage -A arm -O linux -T script -C none -n "${IMAGE_DESC}" -d ${BOOT_TXT} ${BOOT_SCR}
else
mkimage -A arm -O linux -T script -C none -n "${IMAGE_DESC}" -d ${BOOT_TXT} ${BOOT_SCR} > /dev/null 2>&1
if [[ $? = 0 ]]; then
echo " done."
else
echo " failed."
echo "${ACTION} ${IMAGE_DESC} from ${BOOT_TXT} failed due to unknown reason."
echo "Please try generating the boot script again, or your phone may no longer boot properly."
fi
fi
# EOF
notice_uboot() { flash_uboot() {
echo "New version of U-Boot firmware can be flashed to your microSD card" # (Re-)generate the U-Boot boot script and flash the U-Boot image
echo "or eMMC module. You can do that by running:" ppp-uboot-mkscr -q
echo "# dd if=/boot/idbloader.img of=/dev/mmcblkX seek=64 conv=notrunc,fsync" ppp-uboot-flash
echo "# dd if=/boot/u-boot.itb of=/dev/mmcblkX seek=16384 conv=notrunc,fsync"
}
create_config() {
mkdir -p /boot/extlinux
echo "LABEL Manjaro ARM
KERNEL /Image
FDT /dtbs/rockchip/rk3399-pinephone-pro.dtb
APPEND initrd=/initramfs-linux.img console=ttyS2,1500000 root=LABEL=ROOT_MNJRO rw rootwait quiet splash plymouth.ignore-serial-consoles" > /boot/extlinux/extlinux.conf
} }
post_install() { post_install() {
notice_uboot # Perform the U-Boot flashing
if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then flash_uboot
mv /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
fi # The service will be executed only once, it disables itself
if [ -f /boot/extlinux/extlinux.conf ]; then systemctl enable ppp-prepare-fstab.service
echo "Keeping old extlinux.conf file..."
else
create_config
fi
} }
post_upgrade() { post_upgrade() {
notice_uboot EXTLINUX="/boot/extlinux"
if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then BOOT_OPTIONS="defaults,noexec,nodev,showexec"
mv /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
# Remove an obsolete directory, if it's present
if [[ -e ${EXTLINUX} ]]; then
echo -n "Removing obsolete ${EXTLINUX} directory..."
rm -rf ${EXTLINUX}
echo " done."
fi fi
if [ -f /boot/extlinux/extlinux.conf ]; then
echo "Keeping old extlinux.conf file..." # Ensure updated mount options for /boot, if using vfat
else if grep -q "/boot.*vfat" /etc/fstab; then
create_config if ! grep -q "/boot.*${BOOT_OPTIONS}" /etc/fstab; then
echo -n "Updating mount options for /boot in /etc/fstab..."
sed -i -e "s#\(/boot\)\([ \t]\+\)\([^ \t]\+\)\([ \t]\+\)\([^ \t]\+\)\(.*\)\$#\1\2\3\4${BOOT_OPTIONS}\6#g" /etc/fstab
echo " done."
fi
fi fi
}
# Perform the U-Boot flashing
flash_uboot
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment