persistent-vars-storage: (PR #752): Add READ -a flag to read all vars

Define all the known vars and a flag that prints them all. This is only
useful for developers who forget the names of vars.

Missing vars are printed like `mm_mode=`, so there is no way to
distinguish empty and missing vars.  Non printable characters are not
escaped, nor are newlines or = signs.  This is only useful for
developers.

This works on EKH01, although it is not very useful. It spews a lot of
text to stderr.

Approved-by: James Haggerty
Approved-by: Sophronia Koilpillai
This commit is contained in:
Evan Benn 2024-08-23 03:17:51 +00:00 committed by Arien Judge
parent 4d44171796
commit eec5432f7c
2 changed files with 21 additions and 5 deletions

View File

@ -20,10 +20,12 @@ get_key_from_persistent_storage()
print_usage() print_usage()
{ {
echo "persistent_vars_storage.sh OPERATION(READ|WRITE|ERASE) KEY [VALUE]" 1>&2; echo "persistent_vars_storage.sh OPERATION(READ|READALL|WRITE|ERASE) KEY [VALUE]" 1>&2;
} }
all_keys="device_password default_wifi_key dpp_priv_key mm_region
mm_virtual_wire mm_mode dropbear_authorized_keys dropbear_ed25519_host_key
dropbear_rsa_host_key"
case "$operation" in case "$operation" in
READ) READ)
@ -38,6 +40,12 @@ case "$operation" in
fi fi
;; ;;
READALL)
for key in $all_keys; do
printf '%s=%s\n' "$key" "$($0 READ "$key")"
done
;;
WRITE|ERASE) WRITE|ERASE)
echo "Writing to persistent memory isn't implemented on bcm2711, yet." 1>&2; echo "Writing to persistent memory isn't implemented on bcm2711, yet." 1>&2;
exit 1 exit 1
@ -49,5 +57,3 @@ case "$operation" in
;; ;;
esac esac

View File

@ -9,7 +9,7 @@ trap exit_handler EXIT
exit_handler() exit_handler()
{ {
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "Usage: $0 OPERATION(READ|WRITE|ERASE) KEY [VALUE]" 1>&2 echo "Usage: $0 OPERATION(READ|READALL|WRITE|ERASE) KEY [VALUE]" 1>&2
exit 1 exit 1
fi fi
} }
@ -82,6 +82,10 @@ fi
operation="$1" operation="$1"
key="$2" key="$2"
all_keys="device_password default_wifi_key dpp_priv_key mm_region
mm_virtual_wire mm_mode dropbear_authorized_keys dropbear_ed25519_host_key
dropbear_rsa_host_key"
case "$operation" in case "$operation" in
READ) READ)
if ! fw_printenv -n -c "$conffile" "$key" 2> /dev/null; then if ! fw_printenv -n -c "$conffile" "$key" 2> /dev/null; then
@ -91,6 +95,12 @@ case "$operation" in
fi fi
;; ;;
READALL)
for key in $all_keys; do
printf '%s=%s\n' "$key" "$($0 READ "$key")"
done
;;
WRITE) WRITE)
value="$3" value="$3"
fw_setenv -c "$conffile" "$key" "$value" fw_setenv -c "$conffile" "$key" "$value"