blob: af3e2bead600fc075dd265708765305b91636847 [file] [log] [blame]
Chanh Nguyena3150fa2021-09-07 17:50:12 +07001#!/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
22usage () {
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
32IMG_PATH="$1"
33if [ ! -d $IMG_PATH ]; then
34 echo $IMG_PATH
35 echo "The folder $IMG_PATH does not exist"
36 usage
37 exit 1
38fi
39
40MANIFEST_PATH="${IMG_PATH}/MANIFEST"
41if [ ! -f $MANIFEST_PATH ]; then
42 echo $MANIFEST_PATH
43 echo "The MANIFEST file $MANIFEST_PATH does not exist"
44 usage
45 exit 1
46fi
47
48EXTENDED_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
51if [ -z "$EXTENDED_VERSION" ]
52then
53 EXTENDED_VERSION="primary"
54fi
55
56# Assign the command based on the ExtendedVersion
57case ${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 ;;
87esac
88
89
90if [ -z "$IMAGE" ]
91then
92 echo "ERROR: The image file: No such file or directory"
93 exit 1
94else
95 eval $CMD
96fi
97
98if [[ $? -ne 0 ]]; then
99 echo "ERROR: The firmware update not successfull"
100 exit 1
101fi