Skip to content

Commit d11316a

Browse files
Restructure error handling
Signed-off-by: Vladimir Sokolovsky <[email protected]>
1 parent 26ddf26 commit d11316a

File tree

6 files changed

+216
-118
lines changed

6 files changed

+216
-118
lines changed

src/bf-upgrade

Lines changed: 120 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ unmount_partitions()
7979
}
8080

8181
RC=0
82+
ACTVATION_STATUS=0
8283
# Maximum idle time in seconds to decide no more data from BOOTFIFO.
8384
IDLE_MAX=5
8485
INITIAL_DATA_RECEIVE_TIMEOUT=20
@@ -115,48 +116,56 @@ state=$(cat /proc/acpi/button/lid/LID/state | awk '{print $2}' 2>/dev/null)
115116
TMPDIR=${TMPDIR:-"/tmp"}
116117
WDIR=${WDIR:-"$(mktemp -d ${TMPDIR}/bfb.XXXXXX)"}
117118
BFB_DIR=${TMPDIR}/bfb
118-
119-
if [ -e /tmp/update_in_progress ]; then
119+
UPDATE_IN_PROGRESS=0
120+
UPDATE_IN_PROGRESS_FILE=${TMPDIR}/update_in_progress
121+
if [ -e $UPDATE_IN_PROGRESS_FILE ]; then
120122
ilog "Update in progress. Awaiting for activation."
121-
/bin/rm -rf /tmp/update_in_progress
123+
UPDATE_IN_PROGRESS=1
124+
/bin/rm -rf $UPDATE_IN_PROGRESS_FILE
122125
else
123126
/bin/rm -rf ${BFB_DIR}/* ${BFB_DIR}
124127
/bin/ln -sf ${WDIR} ${BFB_DIR}
125128
fi
126129

127130
# Read 8 bytes starting from the 5th byte (offset 4)
128-
SP2=$(read_SP2)
129-
ilog "UINT64 value starting from the 5th byte (little-endian): $SP2"
131+
RSHIM_SP2=$(read_SP2)
132+
ilog "UINT64 value starting from the 5th byte (little-endian): $RSHIM_SP2"
133+
134+
set_upgrade_progress 0 0
130135

131-
if is_mode_upgrade $SP2; then
132-
ilog "RSSHIM SP2 is $SP2: Running Upgrade flow"
136+
if is_mode_upgrade $RSHIM_SP2; then
137+
ilog "RSHIM SP2 is $RSHIM_SP2: Running Upgrade flow"
138+
if [ $UPDATE_IN_PROGRESS -eq 1 ]; then
139+
ilog "Previous update in progress. Awaiting for activation."
140+
exit 1
141+
fi
133142
UPGRADE_FLOW=1
134-
touch /tmp/update_in_progress
143+
touch $UPDATE_IN_PROGRESS_FILE
135144
fi
136-
if is_mode_activate $SP2; then
137-
ilog "RSSHIM SP2 is $SP2: Running ActivateFirmware flow"
145+
if is_mode_activate $RSHIM_SP2; then
146+
ilog "RSHIM SP2 is $RSHIM_SP2: Running ActivateFirmware flow"
138147
ACTIVATE_FLOW=1
139148
fi
140-
if is_mode_cancel; then
141-
ilog "RSSHIM SP2 is $SP2: Running Cancel flow"
149+
if is_mode_cancel $RSHIM_SP2; then
150+
ilog "RSHIM SP2 is $RSHIM_SP2: Running Cancel flow"
142151
CANCEL_FLOW=1
143152
fi
144153
if [ $UPGRADE_FLOW -eq 0 ] && [ $ACTIVATE_FLOW -eq 0 ] && [ $CANCEL_FLOW -eq 0 ]; then
145-
ilog "RSSHIM SP2 is $SP2: Running Compatibility flow"
154+
ilog "RSHIM SP2 is $RSHIM_SP2: Running Compatibility flow"
146155
COMPATIBILITY_FLOW=1
147156
fi
148157

149158
# IS_BUNDLE is set to 1 if the BFB is a bf-bundle or bf-fwbundle (non-flat) BFB
150159
IS_BUNDLE=0
151-
UPDATE_ATF_UEFI=${UPDATE_ATF_UEFI:-"yes"}
152-
UPDATE_DPU_OS=${UPDATE_DPU_OS:-"no"}
153-
UPDATE_BMC_FW=${UPDATE_BMC_FW:-"yes"}
154-
UPDATE_CEC_FW=${UPDATE_CEC_FW:-"yes"}
155-
UPDATE_DPU_GOLDEN_IMAGE=${UPDATE_DPU_GOLDEN_IMAGE:-"yes"}
156-
UPDATE_NIC_FW_GOLDEN_IMAGE=${UPDATE_NIC_FW_GOLDEN_IMAGE:-"yes"}
157-
WITH_NIC_FW_UPDATE=${WITH_NIC_FW_UPDATE:-"yes"}
158-
RUNTIME_UPGRADE="yes"
159-
USE_BFB_INSTALL=${USE_BFB_INSTALL:-"no"}
160+
export UPDATE_ATF_UEFI=${UPDATE_ATF_UEFI:-"yes"}
161+
export UPDATE_DPU_OS=${UPDATE_DPU_OS:-"no"}
162+
export UPDATE_BMC_FW=${UPDATE_BMC_FW:-"yes"}
163+
export UPDATE_CEC_FW=${UPDATE_CEC_FW:-"yes"}
164+
export UPDATE_DPU_GOLDEN_IMAGE=${UPDATE_DPU_GOLDEN_IMAGE:-"yes"}
165+
export UPDATE_NIC_FW_GOLDEN_IMAGE=${UPDATE_NIC_FW_GOLDEN_IMAGE:-"yes"}
166+
export WITH_NIC_FW_UPDATE=${WITH_NIC_FW_UPDATE:-"yes"}
167+
export RUNTIME_UPGRADE="yes"
168+
export USE_BFB_INSTALL=${USE_BFB_INSTALL:-"no"}
160169

161170
if [[ $COMPATIBILITY_FLOW -eq 1 || $UPGRADE_FLOW -eq 1 ]]; then
162171
# Add a delay for the boot-fifo to be filled.
@@ -189,7 +198,7 @@ if [[ $COMPATIBILITY_FLOW -eq 1 || $UPGRADE_FLOW -eq 1 ]]; then
189198

190199
if [ ! -s "${UPGRADE_IMAGE}" ]; then
191200
log "ERR Failed to receive a BFB"
192-
/bin/rm -rf ${WDIR} ${BFB_DIR} /tmp/update_in_progress
201+
/bin/rm -rf ${WDIR} ${BFB_DIR} $UPDATE_IN_PROGRESS_FILE
193202
exit 1
194203
fi
195204

@@ -257,12 +266,24 @@ if (bash -n ${SCRIPTS_DIR}/bf-upgrade.env/bmc 2>/dev/null); then
257266
. ${SCRIPTS_DIR}/bf-upgrade.env/bmc
258267
fi
259268

260-
if [ -n "$BMC_IP" ]; then
261-
if ! (ping -c 3 $BMC_IP > /dev/null 2>&1); then
262-
create_vlan
269+
if [[ -n "$BMC_USER" && -n "$BMC_PASSWORD" ]]; then
270+
if [ -n "$BMC_IP" ]; then
271+
if ! (ping -c 3 $BMC_IP > /dev/null 2>&1); then
272+
if ! create_vlan; then
273+
log "ERR Failed to create VLAN"
274+
skip_bmc 0
275+
RC=$(( RC + 1 ))
276+
fi
277+
else
278+
BMC_LINK_UP="yes"
279+
fi
263280
else
264-
BMC_LINK_UP="yes"
281+
log "WARN BMC_IP is not set"
282+
skip_bmc 0
265283
fi
284+
else
285+
log "WARN BMC credentials are not set"
286+
skip_bmc 0
266287
fi
267288

268289
if [ $IS_BUNDLE -eq 0 ]; then
@@ -283,15 +304,15 @@ if [ $IS_BUNDLE -eq 0 ]; then
283304

284305
if [[ $UPGRADE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
285306
if ! function_exists bmc_components_update; then
286-
log "ERROR: BMC upgrade function does not exist"
307+
log "ERR BMC upgrade function does not exist"
287308
skip_bmc 0
288309
fi
289310

290311
if [ "$UPDATE_BMC_FW" == "yes" ]; then
291312
if [ -e dump-image-v0 ]; then
292313
BMC_IMAGE=$(readlink -f dump-image-v0)
293314
else
294-
log "ERROR: BMC firmware dump-image-v0 was not found"
315+
log "ERR BMC firmware dump-image-v0 was not found"
295316
UPDATE_BMC_FW="no"
296317
fi
297318
fi
@@ -300,7 +321,7 @@ if [ $IS_BUNDLE -eq 0 ]; then
300321
if [ -e dump-upgrade-image-v0 ]; then
301322
CEC_IMAGE=$(readlink -f dump-upgrade-image-v0)
302323
else
303-
log "ERROR: CEC firmware dump-upgrade-image-v0 was not found"
324+
log "ERR CEC firmware dump-upgrade-image-v0 was not found"
304325
UPDATE_CEC_FW="no"
305326
fi
306327
fi
@@ -309,7 +330,7 @@ if [ $IS_BUNDLE -eq 0 ]; then
309330
if [ -e dump-dpu-gi-v0 ]; then
310331
DPU_GOLDEN_IMAGE=$(readlink -f dump-dpu-gi-v0)
311332
else
312-
log "ERROR: DPU Golden Image dump-dpu-gi-v0 was not found"
333+
log "ERR DPU Golden Image dump-dpu-gi-v0 was not found"
313334
UPDATE_DPU_GOLDEN_IMAGE="no"
314335
fi
315336
fi
@@ -318,7 +339,7 @@ if [ $IS_BUNDLE -eq 0 ]; then
318339
if [ -e dump-ramdisk-v0 ]; then
319340
NIC_FW_GOLDEN_IMAGE=$(readlink -f dump-ramdisk-v0)
320341
else
321-
# log "ERROR: NIC firmware golden image dump-upgrade-image-v0 was not found"
342+
# log "ERR NIC firmware golden image dump-upgrade-image-v0 was not found"
322343
UPDATE_NIC_FW_GOLDEN_IMAGE="no"
323344
fi
324345
fi
@@ -328,11 +349,11 @@ if [ $IS_BUNDLE -eq 0 ]; then
328349
if function_exists update_nic_firmware; then
329350
NIC_FW_BIN=$(readlink -f dump-nicfw-v0)
330351
else
331-
log "ERROR: NIC Firmware upgrade function does not exist"
352+
log "ERR NIC Firmware upgrade function does not exist"
332353
WITH_NIC_FW_UPDATE="no"
333354
fi
334355
else
335-
# log "ERROR: NIC firmware binary dump-nicfw-v0 was not found"
356+
# log "ERR NIC firmware binary dump-nicfw-v0 was not found"
336357
WITH_NIC_FW_UPDATE="no"
337358
fi
338359
fi
@@ -341,32 +362,41 @@ if [ $IS_BUNDLE -eq 0 ]; then
341362
update_progress install_setup 0
342363
fi # compatibility flow or upgrade flow - finish updating components
343364

344-
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
345-
# Update components
346-
if [ "$UPDATE_ATF_UEFI" == "yes" ]; then
347-
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
348-
update_atf_uefi $(readlink -f dump-capsule-v0)
349-
update_progress atf_uefi $?
350-
fi
365+
if [ "$UPDATE_ATF_UEFI" == "yes" ]; then
366+
update_atf_uefi_status=0
367+
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
368+
# Update components
369+
update_atf_uefi $(readlink -f dump-capsule-v0)
370+
update_atf_uefi_status=$?
371+
ACTVATION_STATUS=$(( ACTVATION_STATUS + update_atf_uefi_status ))
372+
fi
373+
if [[ $UPGRADE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
374+
update_progress atf_uefi $update_atf_uefi_status
351375
fi
352376
fi
353377

354378
if [[ $UPGRADE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
355379
bmc_components_update
356380

357381
if [ "$WITH_NIC_FW_UPDATE" == "yes" ]; then
358-
update_nic_firmware
359-
update_progress nic_firmware $?
382+
nic_firmware_update
360383
fi
361384
fi
362385

363386
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
364-
bmc_activate
387+
if [ -e ${BFB_DIR}/bmc_firmware_staged ]; then
388+
ilog "Activating BMC firmware"
389+
bmc_activate
390+
ACTVATION_STATUS=$(( ACTVATION_STATUS + $? ))
391+
/bin/rm -f ${BFB_DIR}/bmc_firmware_staged
392+
else
393+
ilog "BMC firmware was not staged. Skipping BMC firmware activation."
394+
fi
365395
fi
366396
else
367397
#BUNDLE BFB that contains Linux kernel and initramfs
368398
if [ ! -e dump-initramfs-v0 ]; then
369-
log "ERROR: BFB's initramfs dump-initramfs-v0 was not found"
399+
log "ERR BFB's initramfs dump-initramfs-v0 was not found"
370400
exit 1
371401
fi
372402

@@ -382,7 +412,7 @@ else
382412
fi
383413
if [ "$USE_BFB_INSTALL" == "yes" ]; then
384414
if [ ! -e ubuntu/install.sh ]; then
385-
log "ERROR: ubuntu/install.sh was not found. Only bf-fwbundle is supported."
415+
log "ERR ubuntu/install.sh was not found. Only bf-fwbundle is supported."
386416
exit 1
387417
fi
388418
log "Running ubuntu/install.sh"
@@ -431,39 +461,72 @@ else
431461

432462
if [ "$WITH_NIC_FW_UPDATE" == "yes" ]; then
433463
if [[ $UPGRADE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
434-
update_nic_firmware
435-
update_progress nic_firmware $?
464+
nic_firmware_update
436465
fi
437466
fi
438-
cat /tmp/*log >> /var/log/bf-upgrade.log 2> /dev/null || true
439-
fi
440-
if [ "$WITH_NIC_FW_UPDATE" == "yes" ]; then
441-
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
442-
reset_nic_firmware
443-
fi
444467
fi
445468
fi
446469
cd ..
447470
fi
448471

472+
if [ -e ${BFB_DIR}/nic_firmware_updated ]; then
473+
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
474+
ilog "Resetting NIC firmware"
475+
NIC_FW_UPDATE_DONE=1
476+
NIC_FW_UPDATE_PASSED=1
477+
reset_nic_firmware
478+
reset_nic_firmware_status=$?
479+
ACTVATION_STATUS=$(( ACTVATION_STATUS + reset_nic_firmware_status ))
480+
/bin/rm -f ${BFB_DIR}/nic_firmware_updated
481+
fi
482+
elif [ -e ${BFB_DIR}/nic_firmware_update_failed ]; then
483+
if [[ $ACTIVATE_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 ]]; then
484+
ilog "ERR NIC firmware update failed. Skipping activation."
485+
ACTVATION_STATUS=$(( ACTVATION_STATUS + 1 ))
486+
RC=$(( RC + 1 ))
487+
/bin/rm -f ${BFB_DIR}/nic_firmware_update_failed
488+
fi
489+
fi
490+
449491
# Keep the WDIR for activate
450492
# During the activate flow, the WDIR is used to run the ATF/UEFI upgrade
451493
if [[ $ACTIVATE_FLOW -eq 1 || $CANCEL_FLOW -eq 1 || $COMPATIBILITY_FLOW -eq 1 || $RC -ne 0 ]]; then
452494
if [ $RC -ne 0 ]; then
453495
log "ERR $0 flow failed with RC: $RC"
454496
ilog "Removing BFB directory: $BFB_DIR"
455-
set_status $FAILED
456497
fi
457498
cd ${WDIR}
458499
/bin/rm -rf dump-*
459500
cd ..
460501

461502
if [ ! -d ${WDIR}/initramfs/dev/pts ]; then
462-
/bin/rm -rf ${WDIR} ${BFB_DIR} /tmp/update_in_progress
503+
/bin/rm -rf ${WDIR} ${BFB_DIR} $UPDATE_IN_PROGRESS_FILE
463504
else
464505
ilog "Failed to unmount ${WDIR}/initramfs"
465506
fi
466507
fi
467508

468-
log "Runtime upgrade finished"
509+
if [ $UPGRADE_FLOW -eq 1 ]; then
510+
if [ $ACTIVATE_FLOW -eq 1 ]; then
511+
if [ $RC -eq 0 ]; then
512+
log "Runtime upgrade finished successfully"
513+
else
514+
log "ERR Runtime upgrade finished with errors"
515+
fi
516+
else
517+
update_progress finished $RC
518+
log "Runtime upgrade finished. Activate firmware to complete the update."
519+
fi
520+
fi
521+
522+
if [ $ACTIVATE_FLOW -eq 1 ]; then
523+
update_progress activate $((ACTVATION_STATUS + RC))
524+
if [ $ACTVATION_STATUS -eq 0 ]; then
525+
log "Activation finished successfully"
526+
else
527+
log "ERR Activation finished with errors"
528+
fi
529+
fi
530+
469531
sleep 3
532+
exit $((RC + ACTVATION_STATUS))

src/bf-upgrade.env/atf-uefi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ UPDATE_ATF_UEFI=${UPDATE_ATF_UEFI:-"yes"}
22

33
update_atf_uefi()
44
{
5+
local rc=0
56
if function_exists pre_update_atf_uefi; then
67
log "INFO: Running pre_update_atf_uefi from bf.cfg"
78
pre_update_atf_uefi
@@ -12,10 +13,17 @@ update_atf_uefi()
1213
fi
1314

1415
ilog "Updating ATF/UEFI:"
15-
ilog "$(bfrec --capsule $1 2>&1)"
16+
output=$(bfrec --capsule $1 2>&1)
17+
rc=$?
18+
if [ $rc -ne 0 ]; then
19+
ilog "ERR Failed to update ATF/UEFI:"
20+
RC=$(( RC + 1 ))
21+
fi
22+
ilog "$output"
1623

1724
if function_exists post_update_atf_uefi; then
1825
log "INFO: Running post_update_atf_uefi from bf.cfg"
1926
post_update_atf_uefi
2027
fi
28+
return $rc
2129
}

0 commit comments

Comments
 (0)