| 139 | } |
| 140 | |
| 141 | static void fetch_cbmem_entry(const uint32_t id, const size_t size, uint8_t **buf_out) |
| 142 | { |
| 143 | char path[PATH_MAX_LEN]; |
| 144 | |
| 145 | new_sysfs_path(id, CBMEM_SYSFS_PATH_MEM, path, sizeof(path)); |
| 146 | |
| 147 | FILE *mem_file = fopen(path, "rb"); |
| 148 | if (!mem_file) |
| 149 | die("Unable to open mem file for CBMEM entry id: %#" PRIx32 |
| 150 | " at %s. Error: %s\n", |
| 151 | id, path, strerror(errno)); |
| 152 | |
| 153 | *buf_out = malloc(size); |
| 154 | if (!buf_out) |
| 155 | die("Unable to allocate memory for CBMEM entry id: %#" PRIx32 |
| 156 | " of size: %zuB.\n", |
| 157 | id, size); |
| 158 | |
| 159 | if (fread(*buf_out, 1, size, mem_file) != size) |
| 160 | die("Unable to correctly read memory of CBMEM entry id: %#" PRIx32 |
| 161 | " at %s. Error: %s\n", |
| 162 | id, path, strerror(errno)); |
| 163 | |
| 164 | fclose(mem_file); |
| 165 | } |
| 166 | |
| 167 | bool cbmem_sysfs_get_cbmem_entry(uint32_t id, uint8_t **buf_out, size_t *size_out, uint64_t *addr_out) |
| 168 | { |