Skip to content

Commit

Permalink
Platform/Ampere: Add scripts to help building and flashing firmware
Browse files Browse the repository at this point in the history
Add scripts which help users to build and flash firmware images for
platforms based on the Ampere Altra SoC.

'buildfw.sh' can be used to build images containing just UEFI, or if
the TF-A (ATF) binary is present TF-A + UEFI and complete 32MB SPI-NOR
images. If the SYS (SMPro and PMPro microprocessors) binary is also
present then a capsule update file for the SYS/SCP component of the SOC
will also be built. Usage:

Usage:
  ./Platform/Ampere/buildfw.sh [options]

Options:
  -b <bldtype>, --build <bldtype>  Specify the build type: DEBUG or
                                   RELEASE
  -t <tc>, --toolchain <tc>        Specify the toolchain to use: GCC or
                                   CLANG
  -m <mfg>, --manufacturer <mfg>   Specify platform manufacturer
                                   (e.g. Ampere)
  -p <plat>, --platform <plat>     Specify platform to build (e.g. Jade)
  -l <kern>, --linuxboot <kern>    Build LinuxBoot firmware instead of
           full EDK2 with UEFI Shell, specifying path to flashkernel
  -f, --flash                      Copy firmware to BMC and flash
           firmware (keeping EFI variables and NVPARAMs) after building
  -F, --full-flash                 Copy firmware to BMC and flash full
           EEPROM (resetting EFI variables and NVPARAMs) after building

  Note: flash options require bmc.sh file with env vars BMC_HOST, BMC_USER and BMC_PASS defined

  Available manufacturers:
    ADLINK
    Ampere
    ASRockRack

  Available platforms:
    ADLINK     -> ComHpcAlt
    Ampere     -> Jade
    ASRockRack -> Altrad8ud2

'fwver.sh' is used by buildfw.sh to keep track of the number of builds
done, so that firmware files of the format e.g.
comhpcalt_uefi_2024-10-22-5.bin are created along with displaying the
date including build number during boot.

'fwflash.sh' automates flashing the host firmware when the target
system is running a BMC with OpenBMC. 'fwflash.exp' is a helper
script used by 'fwflash.sh' to ssh into the BMC and run the
ampere_flash_bios.sh utility. Usage:

Copies firmware to the BMC (running OpenBMC) and runs
               ampere_flash_bios.sh to flash the host.
Usage:
  fwflash.sh [options] <Host firmware file>

Options:
  -f, --full   Flash the entire SPI-NOR chip (default)
  -c, --code   Flash the code (TF-A + UEFI) area
  -t, --tfa    Flash the TF-A (ATF) area
  -u, --uefi   Flash the UEFI area
  -h, --help   This help message

Note: TF-A (Trusted Firmware for ARMv8-A) is the same as ATF
      (ARM Trusted Firmware).

Signed-off-by: Rebecca Cran <[email protected]>
  • Loading branch information
bexcran committed Oct 31, 2024
1 parent 0d03670 commit 0a37b48
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Platform/Ampere/Tools/fw_ver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
touch .fw_bld
BUILD="$(cat .fw_bld)"

if [ "${BUILD}" = "" ]; then
BUILD="1"
echo ${BUILD} > .fw_bld
elif [ "$1" == "UPDATE" ]; then
BUILD=$((BUILD + 1))
echo ${BUILD} > .fw_bld
fi

MAJOR_VER="$(date +%y)"
MINOR_VER="$(date +%m)"
VER="$(date +%Y.%m.%d)"
21 changes: 21 additions & 0 deletions Platform/Ampere/Tools/fwflash.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set ARG [lindex $argv 0]
set DIR [lindex $argv 1]
set FILE [lindex $argv 2]

set timeout -1

spawn scp $DIR/$FILE $::env(BMC_USER)@$::env(BMC_HOST):/tmp
match_max 100000
expect "*?assword:*"
send -- "$::env(BMC_PASS)\r"
expect eof
spawn ssh $::env(BMC_USER)@$::env(BMC_HOST)
expect "*?assword:*"
send -- "$::env(BMC_PASS)\r"
expect "root@*~#"
send -- "ampere_flash_bios.sh $ARG /tmp/$FILE\r"
expect "root@*~#"
send -- "rm -fv /tmp/$FILE\r"
expect "root@*~#"
send -- "logout\r"
expect eof
107 changes: 107 additions & 0 deletions Platform/Ampere/Tools/fwflash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash

# Flashes the SPI-NOR of an Ampere-based machine via the BMC.
# The BMC must be running OpenBMC.

set -e

BMC_ENV_FILE=bmc.sh

usage () {
echo "Copies firmware to the BMC (running OpenBMC) and runs ampere_flash_bios.sh to flash the host."
echo "Usage:"
echo " $(basename "$0") [options] <Host firmware file>"
echo
echo "Options:"
echo " -f, --full Flash the entire SPI-NOR chip (default)"
echo " -c, --code Flash the code (TF-A + UEFI) area"
echo " -t, --tfa Flash the TF-A (ATF) area"
echo " -u, --uefi Flash the UEFI area"
echo " -y, --yes Don't show warning about BMC compatibility requirements"
echo " -h, --help This help message"
echo ""
echo "Note: TF-A (Trusted Firmware for ARMv8-A) is the same as ATF (ARM Trusted Firmware)."
exit 1
}

if ! [ -f "${BMC_ENV_FILE}" ]; then
echo "bmc.sh does not exist!"
echo
echo "Please create it, with contents such as:"
echo
echo " export BMC_HOST=192.168.0.10"
echo " export BMC_USER=root"
echo " export BMC_PASS=0penBmc"
exit 1
fi

. "./${BMC_ENV_FILE}"

if [ -z "${BMC_USER}" ] || [ -z "${BMC_PASS}" ] || [ -z "${BMC_HOST}" ]; then
echo "${BMC_ENV_FILE} is not correct. BMC_HOST, BMC_USER and/or BMC_PASS is not configured."
exit 1
fi

export BMC_HOST
export BMC_USER
export BMC_PASS

ACCEPT_PROMPTS=no

OPTIONS=$(getopt -o fctuyh --long full,code,tfa,uefi,yes,help -- "$@")
eval set -- "${OPTIONS}"

while true; do
case "$1" in
-f|--full)
FLASH_ARG="-f"; shift;;
-c|--code)
FLASH_ARG="-c"; shift;;
-t|--tfa)
FLASH_ARG="-t"; shift;;
-u|--uefi)
FLASH_ARG="-u"; shift;;
-y|--yes)
ACCEPT_PROMPTS=yes; shift;;
-h|--help)
usage;;
--) shift; break;;
*) echo "Internal error ($1)!"; exit 1;;
esac
done

if [ "$#" -eq 1 ] && [ -n "$1" ]; then
IMAGE="$1"
else
usage
fi

if [ "${ACCEPT_PROMPTS}" = "no" ]; then
echo "Warning: this script only works on Ampere systems running OpenBMC with tag 'bexcran'."
echo -n "Do you want to continue (y/n): "
read -r cont
while [ "$cont" != "y" ] && [ "$cont" != "n" ]; do
echo -n "Please enter 'y' or 'n': "
read -r cont
done
if [ "$cont" != "y" ]; then
exit 0
fi
fi


if [ -z "${FLASH_ARG}" ]; then
usage
fi

eval set -- ""

if ! [ -f "${IMAGE}" ]; then
echo "ERROR: file \"$1\" does not exist."
exit 1
fi

DIR=$(dirname "${IMAGE}")
FILE=$(basename "${IMAGE}")

expect "$(dirname ${BASH_SOURCE[0]})/fwflash.exp" "${FLASH_ARG}" "${DIR}" "${FILE}"
Loading

0 comments on commit 0a37b48

Please sign in to comment.