Update flashtools patch with latest

This commit is contained in:
Francis Lam 2018-03-31 15:36:14 -07:00
parent e0c1ab2d79
commit 8b1d194b5a
No known key found for this signature in database
GPG Key ID: 0A59C698920806EB

View File

@ -29,10 +29,10 @@ index 27e28b5..f02daee 100644
$(CC) $(LDFLAGS) -o $@ $^ $(CC) $(LDFLAGS) -o $@ $^
diff --git ./cbfs.c ./cbfs.c diff --git ./cbfs.c ./cbfs.c
new file mode 100644 new file mode 100644
index 0000000..bab5f76 index 0000000..c0ddf48
--- /dev/null --- /dev/null
+++ ./cbfs.c +++ ./cbfs.c
@@ -0,0 +1,271 @@ @@ -0,0 +1,262 @@
+#include <stdio.h> +#include <stdio.h>
+#include <fcntl.h> +#include <fcntl.h>
+#include <stdlib.h> +#include <stdlib.h>
@ -56,7 +56,7 @@ index 0000000..bab5f76
+ { "verbose", 0, NULL, 'v' }, + { "verbose", 0, NULL, 'v' },
+ { "read", 1, NULL, 'r' }, + { "read", 1, NULL, 'r' },
+ { "list", 0, NULL, 'l' }, + { "list", 0, NULL, 'l' },
+ { "type", 0, NULL, 't' }, + { "type", 1, NULL, 't' },
+ { "help", 0, NULL, 'h' }, + { "help", 0, NULL, 'h' },
+ { NULL, 0, NULL, 0 }, + { NULL, 0, NULL, 0 },
+}; +};
@ -140,6 +140,11 @@ index 0000000..bab5f76
+ } + }
+ } + }
+ +
+ if (!do_list && !do_read) {
+ fprintf(stderr, "%s", usage);
+ return EXIT_FAILURE;
+ }
+
+ argc -= optind; + argc -= optind;
+ argv += optind; + argv += optind;
+ if (argc != 0) + if (argc != 0)
@ -148,14 +153,8 @@ index 0000000..bab5f76
+ return EXIT_FAILURE; + return EXIT_FAILURE;
+ } + }
+ +
+ int fd;
+ fd = open("/dev/mem", O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open /dev/mem : %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ uint64_t end = 0x100000000; + uint64_t end = 0x100000000;
+
+ if (verbose) { + if (verbose) {
+ fprintf(stderr, "Seeking to %lx\n", end-4); + fprintf(stderr, "Seeking to %lx\n", end-4);
+ } + }
@ -166,18 +165,13 @@ index 0000000..bab5f76
+ fprintf(stderr, "Header Offset: %d\n", header_delta); + fprintf(stderr, "Header Offset: %d\n", header_delta);
+ } + }
+ +
+ uint64_t header_off; + uint64_t header_off = end + header_delta;
+ if (header_delta < 0) {
+ header_off = end - ((uint64_t)(-header_delta));
+ } else {
+ header_off = ((uint64_t)header_delta);
+ }
+ +
+ if (verbose) { + if (verbose) {
+ fprintf(stderr, "Seeking to %lx\n", header_off); + fprintf(stderr, "Seeking to %lx\n", header_off);
+ } + }
+ struct cbfs_header header; + struct cbfs_header header;
+ copy_physical(header_off, sizeof(struct cbfs_header), &header); + copy_physical(header_off, sizeof(header), &header);
+ +
+ header.magic = ntohl(header.magic); + header.magic = ntohl(header.magic);
+ header.version = ntohl(header.version); + header.version = ntohl(header.version);
@ -203,15 +197,17 @@ index 0000000..bab5f76
+ } + }
+ +
+ uint32_t align = header.align; + uint32_t align = header.align;
+
+ // loop through files + // loop through files
+ uint64_t off = end - ((uint64_t) header.romsize) + + uint64_t off = end - ((uint64_t) header.romsize) +
+ ((uint64_t) header.offset); + ((uint64_t) header.offset);
+ void *rom = map_physical(off, end - off);
+ while (off < end) { + while (off < end) {
+ if (verbose) { + if (verbose) {
+ fprintf(stderr, "Potential CBFS File Offset: %lx\n", off); + fprintf(stderr, "Potential CBFS File Offset: %lx\n", off);
+ } + }
+ struct cbfs_file file; + struct cbfs_file file;
+ copy_physical(off, sizeof(struct cbfs_file), &file); + memcpy(&file, rom, sizeof(file));
+ +
+ file.len = ntohl(file.len); + file.len = ntohl(file.len);
+ file.type = ntohl(file.type); + file.type = ntohl(file.type);
@ -230,9 +226,8 @@ index 0000000..bab5f76
+ break; + break;
+ } + }
+ +
+ size_t name_size = file.offset - sizeof(struct cbfs_file); + size_t name_size = file.offset - sizeof(file);
+ char *name = calloc(name_size, sizeof(char)); + char *name = (char *)rom + sizeof(file);
+ copy_physical(off+sizeof(struct cbfs_file), name_size, name);
+ +
+ if (verbose) { + if (verbose) {
+ fprintf(stderr, "File name : '%s'\n", name); + fprintf(stderr, "File name : '%s'\n", name);
@ -252,14 +247,12 @@ index 0000000..bab5f76
+ fprintf(stderr, "Seeking to %lx\n-------- Start Data\n", file_off); + fprintf(stderr, "Seeking to %lx\n-------- Start Data\n", file_off);
+ } + }
+ +
+ char *file_data = malloc(file.len); + if (file_off + file.len > end) {
+ if (file_data == NULL) { + fprintf(stderr, "File offset/length extends beyond ROM");
+ fprintf(stderr, "Failed to allocate memory for file data: length=%d\n",
+ file.len);
+ return EXIT_FAILURE; + return EXIT_FAILURE;
+ } + }
+ copy_physical(file_off, file.len, file_data);
+ +
+ char *file_data = (char *) rom + file.offset;
+ for (size_t offset = 0 ; offset < file.len ; ) { + for (size_t offset = 0 ; offset < file.len ; ) {
+ const ssize_t rc = write( + const ssize_t rc = write(
+ STDOUT_FILENO, + STDOUT_FILENO,
@ -281,19 +274,17 @@ index 0000000..bab5f76
+ } + }
+ +
+ do_read++; + do_read++;
+ free(file_data);
+ free(name);
+ break; + break;
+ } + }
+ +
+ free(name);
+ uint64_t inc = (align + (file.offset + file.len) - 1) & (~(align-1)); + uint64_t inc = (align + (file.offset + file.len) - 1) & (~(align-1));
+ off += inc; + off += inc;
+ rom += inc;
+ if (verbose) { + if (verbose) {
+ fprintf(stderr, "File Off+Len : %x\n", file.offset + file.len); + fprintf(stderr, "File Off+Len : %x\n", file.offset + file.len);
+ fprintf(stderr, "Align : %x\n", align); + fprintf(stderr, "Align : %x\n", align);
+ fprintf(stderr, "Inc : %lx\n", inc); + fprintf(stderr, "Inc : %lx\n", inc);
+ fprintf(stderr, "Next file align : %lx\n", off); + fprintf(stderr, "Next file off : %lx\n", off);
+ } + }
+ } + }
+ +
@ -320,13 +311,16 @@ index be429e8..a756519 100644
int int
diff --git ./util.c ./util.c diff --git ./util.c ./util.c
index 55ae71f..d79eda7 100644 index 55ae71f..a3cf593 100644
--- ./util.c --- ./util.c
+++ ./util.c +++ ./util.c
@@ -153,3 +153,22 @@ map_physical( @@ -151,5 +151,22 @@ map_physical(
return (void *)(addr + page_offset); close(fd);
}
- return (void *)(addr + page_offset);
+ return (void *)(addr + page_offset);
+}
+ +
+void +void
+copy_physical( +copy_physical(
@ -343,9 +337,7 @@ index 55ae71f..d79eda7 100644
+ } + }
+ +
+ memcpy(dest, buf, len); + memcpy(dest, buf, len);
+ }
+ munmap((uint8_t *)buf, len);
+}
diff --git ./util.h ./util.h diff --git ./util.h ./util.h
index 6846007..d9fb59c 100644 index 6846007..d9fb59c 100644
--- ./util.h --- ./util.h