tegra-helper-scripts: let initrd-flash use USB instance for storage check

Since we can't get the target's serial number out of the CVM EEPROM when
using pre-signed binaries, look for the USB instance in the device path
as a way of cross-checking that a storage device matches the target we're
trying to flash.

Signed-off-by: Matt Madison <matt@madison.systems>
This commit is contained in:
Matt Madison
2025-01-19 06:10:57 -08:00
committed by Matt Madison
parent b84d637a5c
commit 18d621753f

View File

@@ -252,15 +252,30 @@ unmount_and_release() {
wait_for_usb_storage() { wait_for_usb_storage() {
local sessid="$1" local sessid="$1"
local name="$2" local name="$2"
local usbi="$3"
local count=0 local count=0
local output candidate cand_model cand_vendor local output candidate cand_model cand_vendor cand_devpath ok
local fromname="${sessid:-${usbi}}"
echo -n "Waiting for USB storage device $name from ${sessid:-target}..." >&2 echo -n "Waiting for USB storage device $name from ${fromname:-target}..." >&2
while [ -z "$output" ]; do while [ -z "$output" ]; do
for candidate in /dev/sd[a-z]; do for candidate in /dev/sd[a-z]; do
[ -b "$candidate" ] || continue [ -b "$candidate" ] || continue
ok=
if [ -n "$sessid" ]; then
cand_model=$(udevadm info --query=property $candidate | grep '^ID_MODEL=' | cut -d= -f2) cand_model=$(udevadm info --query=property $candidate | grep '^ID_MODEL=' | cut -d= -f2)
if [ -z "$sessid" -o "$cand_model" = "$sessid" ]; then if [ "$cand_model" = "$sessid" ]; then
ok=yes
fi
elif [ -n "$usbi" ]; then
cand_devpath=$(udevadm info --query=property $candidate | grep '^DEVPATH=' | cut -d= -f2)
if echo "$cand_devpath" | grep -q "/$usbi/" 2>/dev/null; then
ok=yes
fi
else
ok=yes
fi
if [ "$ok" = "yes" ]; then
cand_vendor=$(udevadm info --query=property $candidate | grep '^ID_VENDOR=' | cut -d= -f2) cand_vendor=$(udevadm info --query=property $candidate | grep '^ID_VENDOR=' | cut -d= -f2)
if [ "$cand_vendor" = "$name" ]; then if [ "$cand_vendor" = "$name" ]; then
echo "[$candidate]" >&2 echo "[$candidate]" >&2
@@ -331,7 +346,7 @@ copy_bootloader_files() {
} }
generate_flash_package() { generate_flash_package() {
local dev=$(wait_for_usb_storage "$session_id" "flashpkg") local dev=$(wait_for_usb_storage "$session_id" "flashpkg" "$usb_instance")
local exports local exports
if [ -z "$dev" ]; then if [ -z "$dev" ]; then
@@ -372,7 +387,7 @@ generate_flash_package() {
write_to_device() { write_to_device() {
local devname="$1" local devname="$1"
local flashlayout="$2" local flashlayout="$2"
local dev=$(wait_for_usb_storage "$session_id" "$devname") local dev=$(wait_for_usb_storage "$session_id" "$devname" "$usb_instance")
local opts="$3" local opts="$3"
local rewritefiles="internal-secureflash.xml" local rewritefiles="internal-secureflash.xml"
local datased simgname rc=1 local datased simgname rc=1
@@ -409,7 +424,7 @@ write_to_device() {
get_final_status() { get_final_status() {
local dtstamp="$1" local dtstamp="$1"
local dev=$(wait_for_usb_storage "$session_id" "flashpkg") local dev=$(wait_for_usb_storage "$session_id" "flashpkg" "$usb_instance")
local mnt final_status logdir logfile local mnt final_status logdir logfile
if [ -z "$dev" ]; then if [ -z "$dev" ]; then
echo "ERR: could not get final status from device" >&2 echo "ERR: could not get final status from device" >&2