A patch to include a small program that reads from/to physical memory. Useful for e.g. tuning the processor register map after bootup.
I put in util-linux.
--
greetz, marc
Is everybody aboard this ship kinkoid?
Chiana - A Bug's Life
chiana 2.6.18-4-ixp4xx #1 Tue Mar 27 18:01:56 BST 2007 GNU/Linux
---
include/applets.h | 1
include/usage.h | 10 ++++
util-linux/Config.in | 7 +++
util-linux/Kbuild | 1
util-linux/devmem2.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 125 insertions(+)
Index: busybox-1.6.1/include/applets.h
===================================================================
--- busybox-1.6.1.orig/include/applets.h
+++ busybox-1.6.1/include/applets.h
@@ -111,6 +111,7 @@
USE_DELGROUP(APPLET_ODDNAME(delgroup, deluser, _BB_DIR_BIN, _BB_SUID_NEVER, delgroup))
USE_DELUSER(APPLET(deluser, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_DEVFSD(APPLET(devfsd, _BB_DIR_SBIN, _BB_SUID_NEVER))
+USE_DEVMEM2(APPLET(devmem2, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_DF(APPLET(df, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_APP_DHCPRELAY(APPLET(dhcprelay, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
USE_DIFF(APPLET(diff, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
Index: busybox-1.6.1/include/usage.h
===================================================================
--- busybox-1.6.1.orig/include/usage.h
+++ busybox-1.6.1/include/usage.h
@@ -603,6 +603,16 @@
"\n and processing synthetic REGISTER events," \
"\n do not poll for events")
+#define devmem2_trivial_usage \
+ "devmem2 { address } [ type [ data ] ]"
+
+#define devmem2_full_usage \
+ "Read/Write from physical addresses" \
+ "\n\nUsage: devmem2 { address } [ type [ data ] ]" \
+ "\n address : memory address to act upon" \
+ "\n type : access operation type : [b]yte, [h]alfword, [w]ord" \
+ "\n data : data to be written"
+
#define df_trivial_usage \
"[-" USE_FEATURE_HUMAN_READABLE("hm") "k] [FILESYSTEM ...]"
#define df_full_usage \
Index: busybox-1.6.1/util-linux/Config.in
===================================================================
--- busybox-1.6.1.orig/util-linux/Config.in
+++ busybox-1.6.1/util-linux/Config.in
@@ -5,6 +5,13 @@
menu "Linux System Utilities"
+config DEVMEM2
+ bool "devmem2"
+ default n
+ help
+ devmem2 is a small program that reads and writes from physcial
+ memory using /dev/mem.
+
config DMESG
bool "dmesg"
default n
Index: busybox-1.6.1/util-linux/Kbuild
===================================================================
--- busybox-1.6.1.orig/util-linux/Kbuild
+++ busybox-1.6.1/util-linux/Kbuild
@@ -30,3 +30,4 @@
lib-$(CONFIG_SWAPONOFF) +=swaponoff.o
lib-$(CONFIG_SWITCH_ROOT) +=switch_root.o
lib-$(CONFIG_UMOUNT) +=umount.o
+lib-$(CONFIG_DEVMEM2) +=devmem2.o
Index: busybox-1.6.1/util-linux/devmem2.c
===================================================================
--- /dev/null
+++ busybox-1.6.1/util-linux/devmem2.c
@@ -0,0 +1,106 @@
+/*
+ * devmem2.c: Simple program to read/write from/to any location in memory.
+ *
+ * Copyright (C) 2000, Jan-Derk Bakker ([EMAIL PROTECTED])
+ * Include in busybox by Marc Leeman ([EMAIL PROTECTED])
+ *
+ * This software has been developed for the LART computing board
+ * (http://www.lart.tudelft.nl/). The development has been sponsored by
+ * the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/)
+ * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
+ * projects.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "libbb.h"
+
+#define FATAL do { bb_perror_msg_and_die("Error at line %d, file %s (%d) [%s]\n", \
+ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
+
+#define MAP_SIZE 4096UL
+#define MAP_MASK (MAP_SIZE - 1)
+
+int devmem2_main(int argc, char **argv);
+int devmem2_main(int argc, char **argv) {
+ int fd;
+ void *map_base, *virt_addr;
+ unsigned long read_result, writeval;
+ off_t target;
+ int access_type = 'w';
+
+ if(argc < 2) {
+ bb_show_usage();
+ }
+ target = strtoul(argv[1], 0, 0);
+
+ if(argc > 2)
+ access_type = tolower(argv[2][0]);
+
+
+ if((fd = xopen("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
+ printf("/dev/mem opened.\n");
+ fflush(stdout);
+
+ /* Map one page */
+ map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
+ if(map_base == (void *) -1) FATAL;
+ printf("Memory mapped at address %p.\n", map_base);
+ fflush(stdout);
+
+ virt_addr = map_base + (target & MAP_MASK);
+ switch(access_type) {
+ case 'b':
+ read_result = *((unsigned char *) virt_addr);
+ break;
+ case 'h':
+ read_result = *((unsigned short *) virt_addr);
+ break;
+ case 'w':
+ read_result = *((unsigned long *) virt_addr);
+ break;
+ default:
+ bb_perror_msg_and_die("Illegal data type '%c'.\n", access_type);
+ }
+ printf("Value at address 0x%lx (%p): 0x%lx\n", target, virt_addr, read_result);
+ fflush(stdout);
+
+ if(argc > 3) {
+ writeval = strtoul(argv[3], 0, 0);
+ switch(access_type) {
+ case 'b':
+ *((unsigned char *) virt_addr) = writeval;
+ read_result = *((unsigned char *) virt_addr);
+ break;
+ case 'h':
+ *((unsigned short *) virt_addr) = writeval;
+ read_result = *((unsigned short *) virt_addr);
+ break;
+ case 'w':
+ *((unsigned long *) virt_addr) = writeval;
+ read_result = *((unsigned long *) virt_addr);
+ break;
+ }
+ printf("Written 0x%lx; readback 0x%lx\n", writeval, read_result);
+ fflush(stdout);
+ }
+
+ if(munmap(map_base, MAP_SIZE) == -1) FATAL;
+ close(fd);
+ return 0;
+}
+
signature.asc
Description: Digital signature
_______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
