/* devmem.c - Access physical addresses * * Copyright 2019 The Android Open Source Project USE_DEVMEM(NEWTOY(devmem, "<1>3", TOYFLAG_USR|TOYFLAG_BIN)) config DEVMEM bool "devmem" default y help usage: devmem ADDR [WIDTH [DATA]] Read/write physical address. WIDTH is 1, 2, 4, or 8 bytes (default 4). Prefix ADDR with 0x for hexadecimal, output is in same base as address. */ #define FOR_devmem #include "toys.h" void devmem_main(void) { int writing = toys.optc == 3, page_size = sysconf(_SC_PAGESIZE), bytes = 4,fd; unsigned long long data = 0, map_off, map_len; unsigned long addr = atolx(*toys.optargs); void *map, *p; // WIDTH? if (toys.optc>1) { int i; if ((i=stridx("1248", *toys.optargs[1]))==-1 || toys.optargs[1][1]) error_exit("bad width: %s", toys.optargs[1]); bytes = 1<