vpd_get_value: Allow ignoring cache by environment VPD_IGNORE_CACHE.
Some programs may want to read current VPD values, or from the
dump_vpd_log cache files (usually for testing, or factory provisioning).
Add two environment variables to control how vpd_get_value retrieves VPD
values:
VPD_IGNORE_CACHE: Ignore any caches (read directly by 'vpd -g').
VPD_IGNORE_SYS_CACHE: Ignore cache from /sys/firmware.
BRANCH=None
BUG=None
TEST=vpd_get_value customization_id # A-B
vpd -s customization_id=C-D
vpd_get_value customization_id # A-B
VPD_IGNORE_CACHE=1 vpd_get_value customization_id # C-D
VPD_IGNORE_SYS_CACH=1 vpd_get_value customization_id # A-B
dump_vpd_log --force
VPD_IGNORE_CACHE=1 vpd_get_value customization_id # C-D
VPD_IGNORE_SYS_CACH=1 vpd_get_value customization_id # C-D
Change-Id: Id2e1be9596cdff1ff8b4810d89d2b1f91e29ba87
Reviewed-on: https://chromium-review.googlesource.com/440713
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
diff --git a/util/vpd_get_value b/util/vpd_get_value
index a695244..99de55e 100755
--- a/util/vpd_get_value
+++ b/util/vpd_get_value
@@ -12,6 +12,9 @@
CACHE_FILE=/mnt/stateful_partition/unencrypted/cache/vpd/full-v2.txt
SYS_VPD=/sys/firmware/vpd
+: "${VPD_IGNORE_CACHE:=}"
+: "${VPD_IGNORE_SYS_CACHE}"
+
cat_if_exists() {
local file="$1"
if [ -f "${file}" ]; then
@@ -28,9 +31,13 @@
fi
local key="$1"
+ if [ -n "${VPD_IGNORE_CACHE}" ]; then
+ exec vpd -g "${key}"
+ fi
+
# Reading from /sys (works on ARM 3.18+, x86 4.4+) is most efficient;
# otherwise we have to parse from VPD cache (maintained by dump_vpd_log).
- if [ -d "${SYS_VPD}/ro" ]; then
+ if [ -z "${VPD_IGNORE_SYS_CACHE}" ] && [ -d "${SYS_VPD}/ro" ]; then
cat_if_exists "${SYS_VPD}/ro/${key}" ||
cat_if_exists "${SYS_VPD}/rw/${key}"
else