mirror of
https://github.com/bmartini/zynq-axis.git
synced 2024-09-05 19:19:27 +08:00
Add app to read raw /dev/mem for debugging
This allows for direct access by the host to the same memory region as the AXIS ports are accessing. Should be useful for debugging.
This commit is contained in:
parent
624e40c03e
commit
c31b303289
@ -4,6 +4,7 @@ CFLAGS := -c -Wall -Werror
|
||||
INCLUDES := -I.
|
||||
|
||||
EXECUTABLE = \
|
||||
read-memory \
|
||||
test-cfg
|
||||
|
||||
|
||||
@ -15,6 +16,10 @@ all : $(EXECUTABLE)
|
||||
$(CC) $(INCLUDES) $(CFLAGS) $< -o $@
|
||||
|
||||
|
||||
read-memory : read-memory.o
|
||||
$(CC) $< -o $@ $(LDFLAGS)
|
||||
|
||||
|
||||
test-cfg : test-cfg.o
|
||||
$(CC) $< -o $@ $(LDFLAGS)
|
||||
|
||||
|
46
app/read-memory.c
Normal file
46
app/read-memory.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i = 0;
|
||||
int total = 0;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("Usage: %s <phys_addr> <length>\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//off_t offset = 462422016;
|
||||
off_t offset = atoi(argv[1]);
|
||||
size_t len = atoi(argv[2]);
|
||||
printf("phys_addr: %ld, %02x, length: %ld\n", (long int)offset, (unsigned int)offset,
|
||||
(long int)len);
|
||||
|
||||
int fd = open("/dev/mem", O_SYNC);
|
||||
unsigned short *mem =
|
||||
(unsigned short *)mmap(NULL, len, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE, fd, offset);
|
||||
|
||||
if (mem == NULL) {
|
||||
printf("Can't map memory\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
// for (i = 0; i < len; ++i) {
|
||||
// mem[i] = 0xDEAD;
|
||||
// }
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (0xDEAD == mem[i]) {
|
||||
total++;
|
||||
printf("%6d, %10ld, %02x, %02x\n", total, (offset + i),
|
||||
(unsigned int)(offset + i), (int)mem[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user