MCPcopy Create free account
hub / github.com/coreboot/coreboot / read_physmem

Function read_physmem

util/intelvbttool/intelvbttool.c:417–451  ·  view source on GitHub ↗

Create fileobject from physical memory at given address of size 64 KiB */

Source from the content-addressed store, hash-verified

415
416/* Create fileobject from physical memory at given address of size 64 KiB */
417static struct fileobject *read_physmem(size_t addr)
418{
419 const int fd = open("/dev/mem", O_RDONLY);
420 const size_t size = 64 * 2 * KiB;
421 if (fd < 0) {
422 printerr("/dev/mem open failed: %s\n", strerror(errno));
423 return NULL;
424 }
425
426 const void *data = mmap(0, size, PROT_READ, MAP_SHARED, fd, addr);
427 if (data == MAP_FAILED) {
428 close(fd);
429 printerr("mmap failed: %s\n", strerror(errno));
430 return NULL;
431 }
432
433 struct fileobject *fo = malloc_fo(size);
434 if (!fo) {
435 printerr("malloc failed\n");
436 munmap((void *)data, size);
437 close(fd);
438 return NULL;
439 }
440
441 memcpy(fo->data, data, size);
442 munmap((void *)data, size);
443
444 if (close(fd)) {
445 printerr("/dev/mem close failed: %s\n", strerror(errno));
446 free_fo(fo);
447 return NULL;
448 }
449
450 return fo;
451}
452
453/* Write fileobject contents to file */
454static int write_file(const char *filename, const struct fileobject *fo)

Callers 1

mainFunction · 0.85

Calls 5

printerrFunction · 0.85
strerrorFunction · 0.85
malloc_foFunction · 0.85
free_foFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected