Skip to content

Commit

Permalink
Merge pull request #3803 from MilhouseVH/le92_rpi4_firmware
Browse files Browse the repository at this point in the history
RPi4: add tools for updating SPI bootloader [backport]
  • Loading branch information
HiassofT committed Sep 18, 2019
2 parents ebceed9 + e807b9c commit 28ecf8f
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/devel/binutils/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ make_target() {
make -C libiberty
make -C bfd
make -C opcodes
make -C binutils strings
}

makeinstall_target() {
mkdir -p $SYSROOT_PREFIX/usr/lib
cp libiberty/libiberty.a $SYSROOT_PREFIX/usr/lib
make DESTDIR="$SYSROOT_PREFIX" -C bfd install
make DESTDIR="$SYSROOT_PREFIX" -C opcodes install

mkdir -p ${INSTALL}/usr/bin
cp binutils/strings ${INSTALL}/usr/bin
}
2 changes: 2 additions & 0 deletions packages/graphics/bcm2835-driver/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ makeinstall_target() {
ln -s dtoverlay ${INSTALL}/usr/bin/dtparam
cp -PRv ${PKG_FLOAT}/opt/vc/bin/vcdbg ${INSTALL}/usr/bin
cp -PRv ${PKG_FLOAT}/opt/vc/bin/vcgencmd ${INSTALL}/usr/bin
cp -PRv ${PKG_FLOAT}/opt/vc/bin/vcmailbox ${INSTALL}/usr/bin
cp -PRv ${PKG_FLOAT}/opt/vc/bin/tvservice ${INSTALL}/usr/bin
cp -PRv ${PKG_FLOAT}/opt/vc/bin/edidparser ${INSTALL}/usr/bin

# Create symlinks to /opt/vc to satisfy hardcoded lib paths
mkdir -p ${INSTALL}/opt/vc
ln -sf /usr/bin ${INSTALL}/opt/vc/bin
ln -sf /usr/lib ${INSTALL}/opt/vc/lib
}

Expand Down
4 changes: 2 additions & 2 deletions packages/mediacenter/LibreELEC-settings/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Copyright (C) 2017-present Team LibreELEC (https://libreelec.tv)

PKG_NAME="LibreELEC-settings"
PKG_VERSION="f59dcc824fd8fe5b79c0a709a0c70676cc9ab3b1"
PKG_SHA256="0dcfa78f80386c0bcbf550ef0cb0e28a99e6aca1208ccb0664a5fccaff20d01e"
PKG_VERSION="a8481d9b223441d47c518161616bbeefc412a6fc"
PKG_SHA256="5ed50f5317bcdee15cc113563b2d078175eb494a673412273cda463d6e95ad62"
PKG_LICENSE="GPL"
PKG_SITE="https://libreelec.tv"
PKG_URL="https://github.com/LibreELEC/service.libreelec.settings/archive/$PKG_VERSION.tar.gz"
Expand Down
5 changes: 5 additions & 0 deletions packages/sysutils/busybox/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ makeinstall_target() {
sed -e "s/@DISTRONAME@/$DISTRONAME/g" \
-i $INSTALL/usr/lib/libreelec/fs-resize

if listcontains "${FIRMWARE}" "rpi-eeprom"; then
cp $PKG_DIR/scripts/rpi-flash-firmware $INSTALL/usr/lib/libreelec
fi

mkdir -p $INSTALL/etc
cp $PKG_DIR/config/profile $INSTALL/etc
cp $PKG_DIR/config/inputrc $INSTALL/etc
Expand Down Expand Up @@ -183,6 +187,7 @@ post_install() {
enable_service var.mount
enable_service var-log-debug.service
enable_service fs-resize.service
listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service

# cron support
if [ "$CRON_SUPPORT" = "yes" ] ; then
Expand Down
27 changes: 19 additions & 8 deletions packages/sysutils/busybox/scripts/init
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ mount_flash() {
fi
}

cleanup_flash() {
progress "Cleaning up flash (if required)"

if [ -f /flash/pieeprom.upd ]; then
mount -o remount,rw /flash
rm -f /flash/pieeprom.bin /flash/pieeprom.upd
rm -f /flash/recovery.bin /flash/recovery.[0-9][0-9][0-9] /flash/RECOVERY.[0-9][0-9][0-9]
mount -o remount,ro /flash
fi
}

mount_storage() {
progress "Mounting storage"

Expand Down Expand Up @@ -1072,6 +1083,7 @@ for BOOT_STEP in \
set_consolefont \
check_disks \
mount_flash \
cleanup_flash \
update_bootmenu \
load_splash \
mount_storage \
Expand Down Expand Up @@ -1117,17 +1129,16 @@ if [ "$STORAGE_NETBOOT" = "yes" ]; then
echo "" > /sysroot/dev/.storage_netboot
fi

if [ -f /sysroot/storage/.please_resize_me ]; then
INIT_UNIT="--unit=fs-resize.target"
fi

BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1)
if [ -f "$BACKUP_FILE" ]; then
INIT_UNIT="--unit=backup-restore.target"
fi

if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then
if [ -f /sysroot/storage/.please_resize_me ]; then
INIT_UNIT="--unit=fs-resize.target"
elif [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then
INIT_UNIT="--unit=factory-reset.target"
elif [ -f "$BACKUP_FILE" ]; then
INIT_UNIT="--unit=backup-restore.target"
elif [ -f /sysroot/storage/.rpi_flash_firmware ]; then
INIT_UNIT="--unit=rpi-flash-firmware.target"
fi

# switch to new sysroot and start real init
Expand Down
63 changes: 63 additions & 0 deletions packages/sysutils/busybox/scripts/rpi-flash-firmware
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv)

FLAG_FILE="/storage/.rpi_flash_firmware"

. /usr/lib/libreelec/functions

hidecursor

if ! mount -o remount,rw /flash 2>/dev/null; then
# Remove flag file and bail out
rm -f "${FLAG_FILE}"
sync

echo "ERROR: Unable to mount /flash as a read/write file system."
echo
echo "Aborting Flash update process - please proceed with a manual update."
echo

StartProgress countdown "Rebooting in 15s... " 15 "NOW"
fi

if [ -f "${FLAG_FILE}" ]; then
. ${FLAG_FILE}

# Prepare flashing environment
if [ "${MODE}" = "init" ]; then
# Install new SPI bootloader files to /flash (if required)
if [ "${BOOTLOADER}" = "yes" ]; then
USE_FLASHROM=0 /usr/bin/.rpi-eeprom-update.real -a
fi

# Bump process to next step
sed -e 's/^MODE=.*/MODE="update"/' -i "${FLAG_FILE}"
sync
else
rm -f "${FLAG_FILE}"
sync

if [ "${MODE}" = "update" ]; then
# Display current bootloader status
if [ "${BOOTLOADER}" = "yes" ]; then
USE_FLASHROM=0 /usr/bin/.rpi-eeprom-update.real
fi

# Apply VIA USB3 update
# if [ "${USB3}" = "yes" ]; then
# /usr/bin/vl805
# fi

sync
echo ""
StartProgress countdown "Rebooting in 15s... " 15 "NOW"
fi
fi

sync
mount -o remount,ro /flash
fi

reboot -f &>/dev/null
12 changes: 12 additions & 0 deletions packages/sysutils/busybox/system.d/rpi-flash-firmware.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=RPi Flash Firmware
Requires=tmp.mount var.mount sys-kernel-config.mount kernel-overlays.service
After=tmp.mount var.mount sys-kernel-config.mount kernel-overlays.service
DefaultDependencies=no

[Service]
Type=idle
ExecStart=/usr/lib/libreelec/rpi-flash-firmware
StandardInput=tty-force
StandardOutput=inherit
StandardError=inherit
5 changes: 5 additions & 0 deletions packages/sysutils/busybox/system.d/rpi-flash-firmware.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=RPi Flash Firmware target
Requires=rpi-flash-firmware.service
After=rpi-flash-firmware.service
AllowIsolate=yes
22 changes: 22 additions & 0 deletions packages/tools/flashrom/package.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019 Team LibreELEC (https://libreelec.tv)

PKG_NAME="flashrom"
PKG_VERSION="1.1"
PKG_SHA256="aeada9c70c22421217c669356180c0deddd0b60876e63d2224e3260b90c14e19"
PKG_LICENSE="GPL"
PKG_SITE="https://www.flashrom.org/Flashrom"
PKG_URL="https://download.flashrom.org/releases/${PKG_NAME}-v${PKG_VERSION}.tar.bz2"
PKG_DEPENDS_TARGET="toolchain libusb-compat"
PKG_LONGDESC="flashrom is a utility for identifying, reading, writing, verifying and erasing flash chips. It is designed to flash BIOS/EFI/coreboot/firmware/optionROM images on mainboards, network/graphics/storage controller cards, and various other programmer devices."

PKG_MAKE_OPTS_TARGET="PREFIX=/usr \
CONFIG_ENABLE_LIBPCI_PROGRAMMERS=no \
CONFIG_FT2232_SPI=no \
CONFIG_USBBLASTER_SPI=no \
CONFIG_JLINK_SPI=no"
PKG_MAKEINSTALL_OPTS_TARGET="${PKG_MAKE_OPTS_TARGET}"

post_makeinstall_target() {
rm -fr ${INSTALL}/usr/share/man
}
4 changes: 4 additions & 0 deletions packages/tools/rpi-eeprom/config/rpi-eeprom-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use direct path to firmware as update script doesn't dereference sym links.
FIRMWARE_ROOT="/usr/lib/kernel-overlays/base/lib/firmware/raspberrypi/bootloader"
FIRMWARE_BACKUP_DIR="/storage/.config/rpifw-backup"
BOOTFS=/flash
38 changes: 38 additions & 0 deletions packages/tools/rpi-eeprom/package.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv)

PKG_NAME="rpi-eeprom"
PKG_VERSION="1923a55d0e4629becf50b834a83b86e6d5a55233"
PKG_SHA256="2775c6f9975d43aa6f6714de648fc1cab08b5c8de599cc942a9baad378c2cefe"
PKG_ARCH="arm"
PKG_LICENSE="BSD-3/custom"
PKG_SITE="https://github.com/raspberrypi/rpi-eeprom"
PKG_URL="https://github.com/raspberrypi/rpi-eeprom/archive/${PKG_VERSION}.tar.gz"
PKG_DEPENDS_TARGET="flashrom"
PKG_LONGDESC="rpi-eeprom: firmware, config and scripts to update RPi4 SPI bootloader"
PKG_TOOLCHAIN="manual"

makeinstall_target() {
DESTDIR=${INSTALL}/$(get_kernel_overlay_dir)/lib/firmware/raspberrypi/bootloader

mkdir -p ${DESTDIR}
mkdir -p ${DESTDIR}/${_dir}
cp -PRv ${PKG_BUILD}/firmware/recovery.bin ${DESTDIR}

_dirs="critical"
[ "$LIBREELEC_VERSION" = "devel" ] && _dirs+=" beta"
for _dir in ${_dirs}; do
if [ -n "$(ls -1 ${PKG_BUILD}/firmware/${_dir}/pieeprom-* 2>/dev/null)" ]; then
mkdir -p ${DESTDIR}/${_dir}
cp -PRv $(ls -1 ${PKG_BUILD}/firmware/${_dir}/pieeprom-* | tail -1) ${DESTDIR}/${_dir}
fi
done

mkdir -p ${INSTALL}/usr/bin
cp -PRv ${PKG_DIR}/source/rpi-eeprom-update ${INSTALL}/usr/bin
cp -PRv ${PKG_BUILD}/rpi-eeprom-update ${INSTALL}/usr/bin/.rpi-eeprom-update.real
cp -PRv ${PKG_BUILD}/rpi-eeprom-config ${INSTALL}/usr/bin

mkdir -p ${INSTALL}/etc/default
cp -PRv ${PKG_DIR}/config/* ${INSTALL}/etc/default
}
10 changes: 10 additions & 0 deletions packages/tools/rpi-eeprom/source/rpi-eeprom-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# If read-only then mount writeable, and restore read-only on exit
# This means we don't restore read-only if /flash is already writeable
if [ -n "$(grep " /flash " /proc/mounts | grep "[[:space:]]ro[[:space:],]")" ]; then
trap "mount -o remount,ro /flash" EXIT
mount -o remount,rw /flash
fi

sh /usr/bin/.rpi-eeprom-update.real $@
3 changes: 3 additions & 0 deletions projects/RPi/devices/RPi4/options
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# NOOBS supported model versions
NOOBS_SUPPORTED_MODELS='"Pi 4"'

# additional Firmware to use (dvb-firmware, misc-firmware, wlan-firmware)
FIRMWARE="${FIRMWARE} rpi-eeprom"

OPENGLES="mesa"
GRAPHIC_DRIVERS="vc4"
KODIPLAYER_DRIVER="mesa"
Expand Down

0 comments on commit 28ecf8f

Please sign in to comment.