diff options
author | Steve Arnold <stephen.arnold42@gmail.com> | 2015-04-11 17:43:49 -0700 |
---|---|---|
committer | Steve Arnold <stephen.arnold42@gmail.com> | 2015-04-11 17:43:49 -0700 |
commit | 1916c98e2680928212937cdd0f328c6ea0387c0a (patch) | |
tree | 9f61d51219f4f9a06aea5aa5e281d770e3036cbf /dev-util | |
parent | test version of glamo driver for mndar (diff) | |
download | arm-1916c98e2680928212937cdd0f328c6ea0387c0a.tar.gz arm-1916c98e2680928212937cdd0f328c6ea0387c0a.tar.bz2 arm-1916c98e2680928212937cdd0f328c6ea0387c0a.zip |
initial test commit of devmem2 utility
Diffstat (limited to 'dev-util')
-rw-r--r-- | dev-util/devmem2/Manifest | 3 | ||||
-rw-r--r-- | dev-util/devmem2/devmem2-20040805.ebuild | 31 | ||||
-rw-r--r-- | dev-util/devmem2/files/Makefile | 4 | ||||
-rw-r--r-- | dev-util/devmem2/files/devmem2.c | 121 |
4 files changed, 159 insertions, 0 deletions
diff --git a/dev-util/devmem2/Manifest b/dev-util/devmem2/Manifest new file mode 100644 index 0000000..f4a19e5 --- /dev/null +++ b/dev-util/devmem2/Manifest @@ -0,0 +1,3 @@ +AUX Makefile 72 SHA256 e550bd019879bec56592cf44d967f7bda3abd8f75687694a7cc9d9cb8208d02d SHA512 b2b42ae47c9f0724309bce4e4aff611b650f746d17984b131554068e6bcabe67e7c92d885d0cc55034b46ba476e37b4fb3b338a3a3f7c7e3ccef539185db427f WHIRLPOOL 06fbadd1ea7b363d124454ccffe6086ed336b79d66fcdaa62accecde8ac753bce2f4588d3dd9af446261d414363bd119bfeb1552836a033bf94ceaa581f2571b +AUX devmem2.c 3551 SHA256 ec382c90af3ef2f49695ff14a4d6521e58ac482c4e29d6c9ebca8768f699c191 SHA512 e3e46203492a1b4c9a292f59b2d998e79fd40dd82b5b8c99ce52af466819e34b3ccc3234b726560264a744716955fe24d69685760ae431fefef87237b4e5f83d WHIRLPOOL 38e964718116bd52d1ca9e3af950b9730dbcc36e078572c6d32d41cb4ccaa69a9212bae47ebd9a85b6a33216dc229e5d3810f38dda86f4da8e7f6021a08c996a +EBUILD devmem2-20040805.ebuild 566 SHA256 386ec90bd495d490f1ac562b056dc6f7899bb11af681d7322dd06f81b30df125 SHA512 7ffe3138b80ad6e61723ea47ce0274bc8244fdfd3a274cbd228946ad0baa6832338b25be7e751fe18c2fdcca12b1c7cb0c5ae7f1d2ea04f00aad111943b1e80d WHIRLPOOL 16e89f9d540c307b75ff9a43cd085b430782522985bfa7015bedfc0f296b1d33c43882b656d4802e14cf5c389dd8a7a574195b7689ea8a2fe80c684499575070 diff --git a/dev-util/devmem2/devmem2-20040805.ebuild b/dev-util/devmem2/devmem2-20040805.ebuild new file mode 100644 index 0000000..31d0f42 --- /dev/null +++ b/dev-util/devmem2/devmem2-20040805.ebuild @@ -0,0 +1,31 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +inherit toolchain-funcs + +DESCRIPTION="Simple program to read/write from/to any location in memory." +HOMEPAGE="http://www.lartmaker.nl/lartware/port/" + +KEYWORDS="~arm" + +SLOT="0" +LICENSE="GPL-2" +IUSE="" + +DEPEND="" + +S="${WORKDIR}" + +src_unpack() { + cp "${FILESDIR}"/Makefile "${FILESDIR}"/devmem2.c "${S}"/ +} + +src_compile() { + emake CC=$(tc-getCC) || die "make failed..." +} + +src_install() { + dobin "${WORKDIR}/devmem2" || die "install failed..." +} + diff --git a/dev-util/devmem2/files/Makefile b/dev-util/devmem2/files/Makefile new file mode 100644 index 0000000..bdcac70 --- /dev/null +++ b/dev-util/devmem2/files/Makefile @@ -0,0 +1,4 @@ +SRC=devmem2.c + +devmem2: $(SRC) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) diff --git a/dev-util/devmem2/files/devmem2.c b/dev-util/devmem2/files/devmem2.c new file mode 100644 index 0000000..9bcb79d --- /dev/null +++ b/dev-util/devmem2/files/devmem2.c @@ -0,0 +1,121 @@ +/* + * devmem2.c: Simple program to read/write from/to any location in memory. + * + * Copyright (C) 2000, Jan-Derk Bakker (jdb@lartmaker.nl) + * + * + * 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 <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <signal.h> +#include <fcntl.h> +#include <ctype.h> +#include <termios.h> +#include <sys/types.h> +#include <sys/mman.h> + +#define FATAL do { fprintf(stderr, "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 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) { + fprintf(stderr, "\nUsage:\t%s { address } [ type [ data ] ]\n" + "\taddress : memory address to act upon\n" + "\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n" + "\tdata : data to be written\n\n", + argv[0]); + exit(1); + } + target = strtoul(argv[1], 0, 0); + + if(argc > 2) + access_type = tolower(argv[2][0]); + + + if((fd = open("/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: + fprintf(stderr, "Illegal data type '%c'.\n", access_type); + exit(2); + } + printf("Value at address 0x%X (%p): 0x%X\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%X; readback 0x%X\n", writeval, read_result); + fflush(stdout); + } + + if(munmap(map_base, MAP_SIZE) == -1) FATAL; + close(fd); + return 0; +} + |