From 7f4f07fc4039353ee499d76bb53b6c742adb6428 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 21 Apr 2026 13:39:29 +0100 Subject: use old nvmutil for now, in lbmk i'm trying to make nvmutil work on openbsd. the new code in lbutils is a bit buggy, likely somewhere in mkhtemp. i'm still debugging it. Signed-off-by: Leah Rowe --- util/nvmutil/lib/word.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 util/nvmutil/lib/word.c (limited to 'util/nvmutil/lib/word.c') diff --git a/util/nvmutil/lib/word.c b/util/nvmutil/lib/word.c new file mode 100644 index 00000000..5d9220c7 --- /dev/null +++ b/util/nvmutil/lib/word.c @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: MIT + * Copyright (c) 2022-2026 Leah Rowe + * + * Manipulate Intel GbE NVM words, which are 16-bit little + * endian in the files (MAC address words are big endian). + */ + +#include + +#include +#include + +#include "../include/common.h" + +unsigned short +nvm_word(unsigned long pos16, unsigned long p) +{ + struct xstate *x = xstatus(0, NULL); + struct xfile *f = &x->f; + + unsigned long pos; + + check_nvm_bound(pos16, p); + pos = (pos16 << 1) + (p * GBE_PART_SIZE); + + return (unsigned short)f->buf[pos] | + ((unsigned short)f->buf[pos + 1] << 8); +} + +void +set_nvm_word(unsigned long pos16, unsigned long p, unsigned short val16) +{ + struct xstate *x = xstatus(0, NULL); + struct xfile *f = &x->f; + + unsigned long pos; + + check_nvm_bound(pos16, p); + pos = (pos16 << 1) + (p * GBE_PART_SIZE); + + f->buf[pos] = (unsigned char)(val16 & 0xff); + f->buf[pos + 1] = (unsigned char)(val16 >> 8); + + set_part_modified(p); +} + +void +set_part_modified(unsigned long p) +{ + struct xstate *x = xstatus(0, NULL); + struct xfile *f = &x->f; + + check_bin(p, "part number"); + f->part_modified[p] = 1; +} + +void +check_nvm_bound(unsigned long c, unsigned long p) +{ + /* Block out of bound NVM access + */ + + check_bin(p, "part number"); + + if (c >= NVM_WORDS) + err(ECANCELED, "check_nvm_bound: out of bounds %lu", + (unsigned long)c); +} -- cgit v1.2.1