r4543 - in developers/werner: . poke
werner at docs.openmoko.org
werner at docs.openmoko.org
Sun Jul 20 22:07:35 CEST 2008
Author: werner
Date: 2008-07-20 22:07:34 +0200 (Sun, 20 Jul 2008)
New Revision: 4543
Added:
developers/werner/poke/
developers/werner/poke/Makefile
developers/werner/poke/poke.c
Log:
Quick and dirty utility to peek into registers and to tweak them.
Added: developers/werner/poke/Makefile
===================================================================
--- developers/werner/poke/Makefile (rev 0)
+++ developers/werner/poke/Makefile 2008-07-20 20:07:34 UTC (rev 4543)
@@ -0,0 +1,5 @@
+CC=arm-angstrom-linux-gnueabi-gcc
+
+CFLAGS=-Wall -g
+
+all: poke
Added: developers/werner/poke/poke.c
===================================================================
--- developers/werner/poke/poke.c (rev 0)
+++ developers/werner/poke/poke.c 2008-07-20 20:07:34 UTC (rev 4543)
@@ -0,0 +1,75 @@
+/*
+ * poke.c - Read or write any CPU register
+ *
+ * Copyright (C) 2008 by OpenMoko, Inc.
+ * Written by Werner Almesberger <werner at openmoko.org>
+ * All Rights Reserved
+ *
+ * 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.
+ */
+
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+
+#define PAGE_SIZE 4096
+#define MEM(addr) (*(uint32_t *) (mem+((addr) & (PAGE_SIZE-1))))
+
+static volatile void *mem;
+
+
+/* ----- Command-line parsing ---------------------------------------------- */
+
+
+static void __attribute__((noreturn)) usage(const char *name)
+{
+ fprintf(stderr, "usage: %s hex_address [value]\n", name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ int fd;
+ char *end;
+ unsigned long addr;
+ uint32_t val;
+
+ fd = open("/dev/mem", O_RDWR);
+ if (fd < 0) {
+ perror("/dev/mem");
+ exit(1);
+ }
+ switch (argc) {
+ case 3:
+ val = strtoul(argv[2], &end, 0);
+ if (*end)
+ usage(*argv);
+ /* fall through */
+ case 2:
+ addr = strtoul(argv[1], &end, 16);
+ if (*end)
+ usage(*argv);
+ break;
+ default:
+ usage(*argv);
+ }
+ mem = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
+ addr & ~(PAGE_SIZE-1));
+ if (mem == MAP_FAILED) {
+ perror("mmap");
+ exit(1);
+ }
+ if (argc == 2)
+ printf("0x%08lx\n", (unsigned long) MEM(addr));
+ else
+ MEM(addr) = val;
+ return 0;
+}
More information about the commitlog
mailing list