1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/devmem2/hotfix-64bit.patch
3 # Copyright (C) 2022 The T2 SDE Project
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 --- ./devmem2.c.orig 2004-09-09 21:19:29.000000000 +0200
15 +++ ./devmem2.c 2017-05-05 13:17:10.682241495 +0200
18 * devmem2.c: Simple program to read/write from/to any location in memory.
20 - * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
21 + * Copyright (C) 2000, Jan-Derk Bakker (jdb@lartmaker.nl)
24 * This software has been developed for the LART computing board
26 * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
29 - * The author can be reached at:
32 - * Information and Communication Theory Group
33 - * Faculty of Information Technology and Systems
34 - * Delft University of Technology
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
47 #include <sys/types.h>
51 #define MAP_SIZE 4096UL
52 #define MAP_MASK (MAP_SIZE - 1)
54 -int main(int argc, char **argv) {
56 - void *map_base, *virt_addr;
57 - unsigned long read_result, writeval;
58 +int main(int argc, char **argv)
60 + uint64_t read_result, writeval;
61 + unsigned int access_size = sizeof(uint32_t);
62 + void *map_base, *virt_addr;
65 int access_type = 'w';
68 fprintf(stderr, "\nUsage:\t%s { address } [ type [ data ] ]\n"
69 "\taddress : memory address to act upon\n"
70 - "\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n"
71 + "\ttype : access operation type:\n"
72 + "\t [b]yte (8bit), [h]alfword (16bit), [w]ord (32bit), [l]ong (64bit)\n"
73 "\tdata : data to be written\n\n",
77 - target = strtoul(argv[1], 0, 0);
79 + target = strtoul(argv[1], 0, 0);
81 access_type = tolower(argv[2][0]);
83 + fd = open("/dev/mem", O_RDWR | O_SYNC);
88 + map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
89 + fd, target & ~MAP_MASK);
90 + if (map_base == (void *)-1)
95 + virt_addr = map_base + (target & MAP_MASK);
96 + switch (access_type) {
98 + read_result = *(uint8_t *)virt_addr;
99 + access_size = sizeof(uint8_t);
102 + read_result = *(uint16_t *)virt_addr;
103 + access_size = sizeof(uint16_t);
106 + read_result = *(uint32_t *)virt_addr;
107 + access_size = sizeof(uint32_t);
110 + read_result = *(uint64_t *)virt_addr;
111 + access_size = sizeof(uint64_t);
114 + fprintf(stderr, "Illegal data type '%c'.\n", access_type);
118 + printf("Value at address 0x%08lx: 0x%0*llx\n",
119 + (unsigned long)target, access_size * 2,
120 + (unsigned long long)read_result);
123 - if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
124 - printf("/dev/mem opened.\n");
128 - map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
129 - if(map_base == (void *) -1) FATAL;
130 - printf("Memory mapped at address %p.\n", map_base);
133 - virt_addr = map_base + (target & MAP_MASK);
134 - switch(access_type) {
136 + writeval = strtoull(argv[3], 0, 0);
137 + switch(access_type) {
139 - read_result = *((unsigned char *) virt_addr);
140 + *(volatile uint8_t *)virt_addr = writeval;
141 + read_result = *(volatile uint8_t *)virt_addr;
144 - read_result = *((unsigned short *) virt_addr);
145 + *(volatile uint16_t *) virt_addr = writeval;
146 + read_result = *(volatile uint16_t *)virt_addr;
149 - read_result = *((unsigned long *) virt_addr);
150 + *(volatile uint32_t *)virt_addr = writeval;
151 + read_result = *(volatile uint32_t *)virt_addr;
154 + *(volatile uint64_t *)virt_addr = writeval;
155 + read_result = *(volatile uint64_t *)virt_addr;
158 - fprintf(stderr, "Illegal data type '%c'.\n", access_type);
161 - printf("Value at address 0x%X (%p): 0x%X\n", target, virt_addr, read_result);
165 - writeval = strtoul(argv[3], 0, 0);
166 - switch(access_type) {
168 - *((unsigned char *) virt_addr) = writeval;
169 - read_result = *((unsigned char *) virt_addr);
172 - *((unsigned short *) virt_addr) = writeval;
173 - read_result = *((unsigned short *) virt_addr);
176 - *((unsigned long *) virt_addr) = writeval;
177 - read_result = *((unsigned long *) virt_addr);
180 - printf("Written 0x%X; readback 0x%X\n", writeval, read_result);
181 + printf("Written 0x%0*llx; readback 0x%0*llx\n",
183 + (unsigned long long)writeval,
185 + (unsigned long long)read_result);
189 if(munmap(map_base, MAP_SIZE) == -1) FATAL;