Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Factory:Rebuild
devmem2
fix_usage_on_64_bits.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix_usage_on_64_bits.patch of Package devmem2
--- devmem2.c.orig 2004-09-09 21:19:29.000000000 +0200 +++ devmem2.c 2017-05-05 13:17:10.682241495 +0200 @@ -1,7 +1,7 @@ /* * devmem2.c: Simple program to read/write from/to any location in memory. * - * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl) + * Copyright (C) 2000, Jan-Derk Bakker (jdb@lartmaker.nl) * * * This software has been developed for the LART computing board @@ -10,16 +10,6 @@ * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/) * projects. * - * The author can be reached at: - * - * Jan-Derk Bakker - * Information and Communication Theory Group - * Faculty of Information Technology and Systems - * Delft University of Technology - * P.O. Box 5031 - * 2600 GA Delft - * The Netherlands - * * * 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 @@ -46,6 +36,7 @@ #include <fcntl.h> #include <ctype.h> #include <termios.h> +#include <stdint.h> #include <sys/types.h> #include <sys/mman.h> @@ -55,77 +46,99 @@ #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; +int main(int argc, char **argv) +{ + uint64_t read_result, writeval; + unsigned int access_size = sizeof(uint32_t); + void *map_base, *virt_addr; off_t target; + int fd; 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" + "\ttype : access operation type:\n" + "\t [b]yte (8bit), [h]alfword (16bit), [w]ord (32bit), [l]ong (64bit)\n" "\tdata : data to be written\n\n", argv[0]); exit(1); } - target = strtoul(argv[1], 0, 0); + target = strtoul(argv[1], 0, 0); if(argc > 2) access_type = tolower(argv[2][0]); + fd = open("/dev/mem", O_RDWR | O_SYNC); + if (fd == -1) + FATAL; + + /* 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; + + close(fd); + + virt_addr = map_base + (target & MAP_MASK); + switch (access_type) { + case 'b': + read_result = *(uint8_t *)virt_addr; + access_size = sizeof(uint8_t); + break; + case 'h': + read_result = *(uint16_t *)virt_addr; + access_size = sizeof(uint16_t); + break; + case 'w': + read_result = *(uint32_t *)virt_addr; + access_size = sizeof(uint32_t); + break; + case 'l': + read_result = *(uint64_t *)virt_addr; + access_size = sizeof(uint64_t); + break; + default: + fprintf(stderr, "Illegal data type '%c'.\n", access_type); + exit(2); + } + + printf("Value at address 0x%08lx: 0x%0*llx\n", + (unsigned long)target, access_size * 2, + (unsigned long long)read_result); + fflush(stdout); - 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) { + if(argc > 3) { + writeval = strtoull(argv[3], 0, 0); + switch(access_type) { case 'b': - read_result = *((unsigned char *) virt_addr); + *(volatile uint8_t *)virt_addr = writeval; + read_result = *(volatile uint8_t *)virt_addr; break; case 'h': - read_result = *((unsigned short *) virt_addr); + *(volatile uint16_t *) virt_addr = writeval; + read_result = *(volatile uint16_t *)virt_addr; break; case 'w': - read_result = *((unsigned long *) virt_addr); + *(volatile uint32_t *)virt_addr = writeval; + read_result = *(volatile uint32_t *)virt_addr; + break; + case 'l': + *(volatile uint64_t *)virt_addr = writeval; + read_result = *(volatile uint64_t *)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); + printf("Written 0x%0*llx; readback 0x%0*llx\n", + access_size * 2, + (unsigned long long)writeval, + access_size * 2, + (unsigned long long)read_result); fflush(stdout); } if(munmap(map_base, MAP_SIZE) == -1) FATAL; - close(fd); - return 0; + + return 0; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor