1 // SPDX-License-Identifier: MIT
8 #include "platforms/platforms.h"
9 #include "gpio/ps_protocol.h"
11 void dump_range_to_file(uint32_t addr, uint32_t size, char *filename) {
12 FILE *out = fopen(filename, "wb+");
14 printf ("[SHARED-DUMP_RANGE_TO_FILE] Failed to open %s for writing.\n", filename);
15 printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range has not been dumped to file.\n");
19 for (uint32_t i = 0; i < size; i += 2) {
20 uint16_t in = be16toh(read16(addr + i));
21 fwrite(&in, 2, 1, out);
25 printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range dumped to file %s.\n", filename);
28 uint8_t *dump_range_to_memory(uint32_t addr, uint32_t size) {
29 uint8_t *mem = calloc(size, 1);
32 printf ("[SHARED-DUMP_RANGE_TO_MEMORY] Failed to allocate memory for dumped range.\n");
36 for (uint32_t i = 0; i < size; i += 2) {
37 *(uint16_t *)&mem[i] = (uint16_t)be16toh(read16(addr + i));
40 printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range copied to RAM.\n");