From 46a0fe6b8af7ce3a516895ab8d872a43d845304b Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 4 Mar 2026 00:41:08 +0000 Subject: util/nvmutil: Comments relating to NVM size limit Part of the code currently assumes we only work on the smaller NVM area. I'm adding some comments to make this clear, for when and if the code is ever expanded to support operating on the Extended NVM area (just part the main 128-byte NVM area). Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index d775f116..26659779 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -623,6 +623,20 @@ set_word(int pos16, int p, uint16_t val16) static void check_bound(int c, int p) { + /* + * NVM_SIZE assumed as the limit, because the + * current design assumes that we will only + * ever modified the NVM area. + * + * The only exception is copy/swap, but these + * do not use word/set_word and therefore do + * not cause check_bound() to be called. + * + * TODO: + * This should be adjusted in the future, if + * we ever wish to work on the Extented NVM. + */ + if ((p != 0) && (p != 1)) err(EINVAL, "check_bound: invalid partnum %d", p); if ((c < 0) || (c >= (NVM_SIZE >> 1))) @@ -655,9 +669,22 @@ write_gbe_part(int p) } } +/* + * GbE files store bytes in little-endian order. + * This function ensures big-endian host CPU support. + */ static void swap(int partnum) { + /* + * NVM_SIZE assumed as the limit; see notes in + * check_bound(). + * + * TODO: + * This should be adjusted in the future, if + * we ever wish to work on the Extended NVM. + */ + size_t w; size_t x; @@ -669,7 +696,6 @@ swap(int partnum) /* * The host CPU stores bytes in big-endian order. - * GbE files store bytes in little-endian order. * We will therefore reverse the order in memory: */ for (w = 0, x = 1; w < NVM_SIZE; w += 2, x += 2) { -- cgit v1.2.1