Skip to content

Commit

Permalink
provisioner: Attempt automatic pre-signed device recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewey-rpi committed Jan 22, 2025
1 parent 5c89daa commit d377e82
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions service/rpi-sb-provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,6 @@ if [ ! -e "${DESTINATION_EEPROM_SIGNATURE}" ]; then
fi
fi

### NOTE: Use this in only case of a partial signing situation, where you have provisioned the key, but need to re-write the eeprom.
# case ${RPI_DEVICE_FAMILY} in
# 4)
# cp "${BOOTCODE_BINARY_IMAGE}" "${BOOTCODE_FLASHING_NAME}"
# ;;
# 5)
# rpi-sign-bootcode --debug -c 2712 -i "${BOOTCODE_BINARY_IMAGE}" -o "${BOOTCODE_FLASHING_NAME}" -k "${CUSTOMER_KEY_FILE_PEM}" -v 0 -n 16
# ;;
# esac
### In the completely-unprovisioned state, where you have not yet written a customer OTP key, simply make the copy of the unsigned bootcode
cp "${BOOTCODE_BINARY_IMAGE}" "${BOOTCODE_FLASHING_NAME}"
####
Expand Down Expand Up @@ -459,11 +450,27 @@ keywriter_log "Writing key and EEPROM configuration to the device"
set +e
[ -z "${DEMO_MODE_ONLY}" ] && timeout 120 rpiboot -d "${FLASHING_DIR}" -i "${TARGET_DEVICE_SERIAL}" -j "/var/log/rpi-sb-provisioner/${TARGET_DEVICE_SERIAL}/metadata/"
KEYWRITER_EXIT_STATUS=$?
if [ $KEYWRITER_EXIT_STATUS -eq 124 ]
if [ ${KEYWRITER_EXIT_STATUS} -eq 124 ]
then
keywriter_log "Writing failed, timed out."
echo "${KEYWRITER_ABORTED}" >> /var/log/rpi-sb-provisioner/"${TARGET_DEVICE_SERIAL}"/progress
return 124
case "${RPI_DEVICE_FAMILY}" in
5)
# Raspberry Pi 5-family hardware may already have a key provisioned - so retry with a signed bootcode.
rpi-sign-bootcode --debug -c 2712 -i "${BOOTCODE_BINARY_IMAGE}" -o "${BOOTCODE_FLASHING_NAME}" -k "${CUSTOMER_KEY_FILE_PEM}" -v 0 -n 16
[ -z "${DEMO_MODE_ONLY}" ] && timeout 120 rpiboot -d "${FLASHING_DIR}" -i "${TARGET_DEVICE_SERIAL}" -j "/var/log/rpi-sb-provisioner/${TARGET_DEVICE_SERIAL}/metadata/"
KEYWRITER_RETRY_EXIT_STATUS=$?
if [ ${KEYWRITER_RETRY_EXIT_STATUS} -eq 124 ]; then
# If the retry with a signed recovery image fails, this is likely a hard failure.
echo "${KEYWRITER_ABORTED}" >> /var/log/rpi-sb-provisioner/"${TARGET_DEVICE_SERIAL}"/progress
return 124
fi
;;
*)
# If we're not Raspberry Pi 5-family, then this is the end of the line, no retry will help.
echo "${KEYWRITER_ABORTED}" >> /var/log/rpi-sb-provisioner/"${TARGET_DEVICE_SERIAL}"/progress
return 124
;;
esac
else
keywriter_log "Writing completed."
fi
Expand Down

0 comments on commit d377e82

Please sign in to comment.