Skip to contentSkip to conversation

tools: nvmem: add nvmemctl for userspace NVMEM device management

RFC PATCH New Kuan-Wei Chiu 1 participant 1 message Mar 15

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 tools: nvmem: add nvmemctl for userspace NVMEM device management

Introduce nvmemctl, a userspace CLI tool designed to cleanly interact with the NVMEM subsystem. It eliminates the need for manual sysfs traversal and raw binary parsing by providing a standard interface strictly based on the documented ABIs:
- Documentation/ABI/stable/sysfs-bus-nvmem
- Documentation/ABI/testing/sysfs-nvmem-cells

Supported operations:
- list: Discovers and displays NVMEM devices, types, read-only status, sizes, and device tree cells in a tree topology.
- dump: Safely hexdumps the entire binary content of a device.
- read: Parses the cells directory and hexdumps a specific cell.
- lock/unlock: Toggles the force_ro attribute to prevent or allow writes.

---
 MAINTAINERS            |   6 +
 tools/Makefile         |  17 ++-
 tools/nvmem/Makefile   |  22 +++
 tools/nvmem/nvmemctl.c | 340 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 382 insertions(+), 3 deletions(-)
 create mode 100644 tools/nvmem/Makefile
 create mode 100644 tools/nvmem/nvmemctl.c
MAINTAINERS +6 -0
index 61bf550fd37c..4bc40b6fe4ff 100644
@@ -18998,6 +18998,12 @@ F:	include/dt-bindings/nvmem/
 F:	include/linux/nvmem-consumer.h
 F:	include/linux/nvmem-provider.h
 
+NVMEM TOOL
+M:	Kuan-Wei Chiu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	tools/nvmem/
+
 NXP BLUETOOTH WIRELESS DRIVERS
 M:	Amitkumar Karwar <[email protected]>
 M:	Neeraj Kale <[email protected]>
tools/Makefile +14 -3
index cb40961a740f..59b2f245dd39 100644
@@ -43,6 +43,7 @@ help:
 	@echo '  wmi			- WMI interface examples'
 	@echo '  x86_energy_perf_policy - Intel energy policy tool'
 	@echo '  ynl			- ynl headers, library, and python tool'
+	@echo '  nvmem                  - NVMEM tools'
 	@echo ''
 	@echo 'You can do:'
 	@echo ' $$ make -C tools/ <tool>_install'
@@ -123,11 +124,14 @@ kvm_stat: FORCE
 ynl: FORCE
 	$(call descend,net/ynl)
 
+nvmem: FORCE
+	$(call descend,nvmem)
+
 all: acpi counter cpupower dma gpio hv firewire \
 		perf selftests bootconfig spi turbostat usb \
 		virtio mm bpf x86_energy_perf_policy \
 		tmon freefall iio objtool kvm_stat wmi \
-		debugging tracing thermal thermometer thermal-engine ynl
+		debugging tracing thermal thermometer thermal-engine ynl nvmem
 
 acpi_install:
 	$(call descend,power/$(@:_install=),install)
@@ -165,13 +169,17 @@ kvm_stat_install:
 ynl_install:
 	$(call descend,net/$(@:_install=),install)
 
+nvmem_install:
+	$(call descend,nvmem,install)
+
 install: acpi_install counter_install cpupower_install dma_install gpio_install \
 		hv_install firewire_install iio_install \
 		perf_install selftests_install turbostat_install usb_install \
 		virtio_install mm_install bpf_install x86_energy_perf_policy_install \
 		tmon_install freefall_install objtool_install kvm_stat_install \
 		wmi_install debugging_install intel-speed-select_install \
-		tracing_install thermometer_install thermal-engine_install ynl_install
+		tracing_install thermometer_install thermal-engine_install ynl_install \
+		nvmem_install
 
 acpi_clean:
 	$(call descend,power/acpi,clean)
@@ -225,12 +233,15 @@ build_clean:
 ynl_clean:
 	$(call descend,net/$(@:_clean=),clean)
 
+nvmem_clean:
+	$(call descend,nvmem,clean)
+
 clean: acpi_clean counter_clean cpupower_clean dma_clean hv_clean firewire_clean \
 		perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
 		mm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
 		freefall_clean build_clean libbpf_clean libsubcmd_clean \
 		gpio_clean objtool_clean leds_clean wmi_clean firmware_clean debugging_clean \
 		intel-speed-select_clean tracing_clean thermal_clean thermometer_clean thermal-engine_clean \
-		sched_ext_clean ynl_clean
+		sched_ext_clean ynl_clean nvmem_clean
 
 .PHONY: FORCE
tools/nvmem/Makefile new file +22 -0
new file mode 100644
index 000000000000..7ef25f616f7a
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+include ../scripts/Makefile.include
+
+CC ?= $(CROSS_COMPILE)gcc
+CFLAGS += -Wall -Wextra -O2
+
+PROG := nvmemctl
+SRCS := nvmemctl.c
+
+all: $(PROG)
+
+$(PROG): $(SRCS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+install: $(PROG)
+	install -d $(DESTDIR)$(PREFIX)/bin
+	install -m 755 $(PROG) $(DESTDIR)$(PREFIX)/bin/
+
+clean:
+	rm -f $(PROG)
+
+.PHONY: all install clean
tools/nvmem/nvmemctl.c new file +340 -0

340 lines not on this page · raw message

Signature · 1 line
2.53.0.851.ga537e3e6e9-goog