persistent-vars-storage-bcm2711: adds a Raspberry Pi compatible persistent storage utility

The Morse Micro persistent-vars-storage package is used to load and store certain device
parameters or configuration from non-volatile storage on a device. This is useful for a
more persistent configuration than what is offered by UCI. Typically used for dpp keys.

The bcm2711 version targets Raspberry Pis and pushes this configuration to the on-board
eeprom.
This commit is contained in:
Morse Micro 2024-09-17 20:24:51 +10:00 committed by Arien Judge
parent a60dee014e
commit 7eb52b2b31
2 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,35 @@
#
# Copyright 2023 Morse Micro
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=persistent-vars-storage-bcm2711
PKG_RELEASE=1
PKG_MAINTAINER:=Morse Micro
include $(INCLUDE_DIR)/package.mk
define Package/persistent-vars-storage-bcm2711
SECTION:=Utilities
CATEGORY:=Utilities
PROVIDES:=persistent-vars-storage
TITLE:=Reads (or maybe writes in future) key-value pairs from(/into) the RPi 4 EEPROM memory
DEPENDS:= +bcm27xx-userland @TARGET_bcm27xx_bcm2711
endef
define Build/Compile
endef
define Package/persistent-vars-storage-bcm2711/install
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) ./files/sbin/persistent_vars_storage.sh $(1)/sbin/persistent_vars_storage.sh
endef
$(eval $(call BuildPackage,persistent-vars-storage-bcm2711))

View File

@ -0,0 +1,53 @@
#!/bin/sh
#
# Copyright (C) 2023 MorseMicro
#
operation="$1"
key="$2"
value="$3"
set -eu
get_key_from_persistent_storage()
{
local config_key=
config_key=$(vcgencmd bootloader_config | grep "$key=")
config_key=$(echo "$config_key" | sed "s/$key=//g")
echo "$config_key"
}
print_usage()
{
echo "persistent_vars_storage.sh OPERATION(READ|WRITE|ERASE) KEY [VALUE]" 1>&2;
}
case "$operation" in
READ)
value=$(get_key_from_persistent_storage)
if [ -n "$value" ]; then
echo "$value"
exit 0
else
echo "The key \"$key\" doesn't exist in bootloader config." 1>&2;
print_usage
exit 1
fi
;;
WRITE|ERASE)
echo "Writing to persistent memory isn't implemented on bcm2711, yet." 1>&2;
exit 1
;;
*)
print_usage
exit 1
;;
esac