Chanh Nguyen | a3150fa | 2021-09-07 17:50:12 +0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021 Ampere Computing LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # This script updates the EDKII / SCP firmware. |
| 18 | # Author : Chanh Nguyen (chnguyen@amperecomputing.com) |
| 19 | # Date : Sep 7, 2021 |
| 20 | # Modified: |
| 21 | |
| 22 | usage () { |
| 23 | echo "Usage:" |
| 24 | echo " $(basename $0) <image path> " |
| 25 | echo "Where:" |
| 26 | echo " <image path>: the path link to folder, which include image file and MANIFEST" |
| 27 | echo "Example:" |
| 28 | echo " $(basename $0) /tmp/images/ghdh1393" |
| 29 | } |
| 30 | |
| 31 | |
| 32 | IMG_PATH="$1" |
| 33 | if [ ! -d $IMG_PATH ]; then |
| 34 | echo $IMG_PATH |
| 35 | echo "The folder $IMG_PATH does not exist" |
| 36 | usage |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | MANIFEST_PATH="${IMG_PATH}/MANIFEST" |
| 41 | if [ ! -f $MANIFEST_PATH ]; then |
| 42 | echo $MANIFEST_PATH |
| 43 | echo "The MANIFEST file $MANIFEST_PATH does not exist" |
| 44 | usage |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | EXTENDED_VERSION=$(awk '/ExtendedVersion/ {print}' ${MANIFEST_PATH} | cut -d "=" -f 2) |
| 49 | |
| 50 | # If the ExtendedVersion is empty, set default to update UEFI/EDKII on primary device |
| 51 | if [ -z "$EXTENDED_VERSION" ] |
| 52 | then |
| 53 | EXTENDED_VERSION="primary" |
| 54 | fi |
| 55 | |
| 56 | # Assign the command based on the ExtendedVersion |
| 57 | case ${EXTENDED_VERSION} in |
| 58 | "primary") |
| 59 | export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \)) |
| 60 | export CMD='/usr/sbin/ampere_flash_bios.sh $IMAGE 1' |
| 61 | ;; |
| 62 | |
| 63 | "secondary") |
| 64 | export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.bin" -o -name "*.rom" \)) |
| 65 | export CMD='/usr/sbin/ampere_flash_bios.sh $IMAGE 2' |
| 66 | ;; |
| 67 | |
| 68 | "scp-primary") |
| 69 | export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \)) |
| 70 | export CMD='/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 1' |
| 71 | ;; |
| 72 | |
| 73 | "scp-secondary") |
| 74 | export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.img" -o -name "*.slim" -o -name "*.rom" \)) |
| 75 | export CMD='/usr/sbin/ampere_firmware_upgrade.sh smpmpro $IMAGE 2' |
| 76 | ;; |
| 77 | |
| 78 | "fru") |
| 79 | export IMAGE=$(find ${IMG_PATH} -type f \( -name "*.bin" \)) |
| 80 | export CMD='/usr/sbin/ampere_firmware_upgrade.sh fru $IMAGE' |
| 81 | ;; |
| 82 | |
| 83 | *) |
| 84 | echo "Invalid ExtendedVersion: ${EXTENDED_VERSION}. Please check MANIFEST file!" |
| 85 | exit 1 |
| 86 | ;; |
| 87 | esac |
| 88 | |
| 89 | |
| 90 | if [ -z "$IMAGE" ] |
| 91 | then |
| 92 | echo "ERROR: The image file: No such file or directory" |
| 93 | exit 1 |
| 94 | else |
| 95 | eval $CMD |
| 96 | fi |
| 97 | |
| 98 | if [[ $? -ne 0 ]]; then |
| 99 | echo "ERROR: The firmware update not successfull" |
| 100 | exit 1 |
| 101 | fi |