Alex Feinman has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31531
Change subject: intelvbttool: Added support for reading vbt from sysfs ......................................................................
intelvbttool: Added support for reading vbt from sysfs
VBT on intel systems is available via sysfs as /sys/kernel/debug/dri/0/i915_vbt However the size of this file reads as 0 causing intelvbttool to fail. This patch implements incremental reads with realloc for such cases. After this patch is applied, intelvbttool can be used as follows: sudo intelvbttool -f /sys/kernel/debug/dri/0/i915_vbt -d
Change-Id: I5d17095a5747550b7115a54a7619b7294a846196 Signed-off-by: Alex Feinman alexfeinman@hotmail.com --- M util/intelvbttool/intelvbttool.c 1 file changed, 21 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/31531/1
diff --git a/util/intelvbttool/intelvbttool.c b/util/intelvbttool/intelvbttool.c index 1444129..2941b42 100644 --- a/util/intelvbttool/intelvbttool.c +++ b/util/intelvbttool/intelvbttool.c @@ -29,6 +29,7 @@ typedef uint16_t u16; typedef uint32_t u32;
+#define DEF_ALLOC 1024
typedef struct { u16 signature; @@ -392,8 +393,8 @@ return NULL; }
- const off_t size = ftell(fd); - if (size < 0 || size > SIZE_MAX) { + off_t read_size = ftell(fd); + if (read_size < 0 || read_size > SIZE_MAX) { printerr("%s tell failed: %s\n", filename, strerror(errno)); fclose(fd); return NULL; @@ -405,14 +406,29 @@ return NULL; }
- struct fileobject *fo = malloc_fo(size); + if ( read_size == 0 ) + read_size = DEF_ALLOC; + + struct fileobject *fo = malloc_fo(read_size); if (!fo) { printerr("malloc failed\n"); fclose(fd); return NULL; }
- if (fread(fo->data, 1, size, fd) != size) { + off_t bytes_read = 0, cb; + while((cb = fread(fo->data + bytes_read, 1, read_size, fd)) > 0) { + bytes_read += cb; + struct fileobject* newfo = remalloc_fo(fo, fo->size + read_size); + if (!newfo) { + fclose(fd); + free_fo(fo); + return NULL; + } + fo = newfo; + } + + if (!bytes_read) { fclose(fd); free_fo(fo); return NULL; @@ -424,7 +440,7 @@ return NULL; }
- fo->size = size; + fo->size = bytes_read;
return fo; }