Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: utility/dump_fmap.c

Issue 6465018: Add load_firmware_test utility program (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Code review & remove tabs Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: utility/dump_fmap.c
diff --git a/utility/dump_fmap.c b/utility/dump_fmap.c
index ab92b82a28d463e00bdb6813f362273ae4e5ca2e..191359f23b638a90968a2554dc3839ca419191da 100644
--- a/utility/dump_fmap.c
+++ b/utility/dump_fmap.c
@@ -15,39 +15,20 @@
#include <sys/types.h>
#include <unistd.h>
+#include "fmap.h"
+
/* global variables */
static int opt_extract = 0;
static char *progname;
gauravsh 2011/02/10 20:02:05 (optional nit): for consistency with the rest of v
Che-Liang Chiou 2011/02/14 02:27:53 Done.
static void *base_of_rom;
-/* FMAP structs. See http://code.google.com/p/flashmap/wiki/FmapSpec */
-#define FMAP_SIGLEN 8
-#define FMAP_NAMELEN 32
-#define FMAP_SEARCH_STRIDE 4
-typedef struct _FmapHeader {
- char fmap_signature[FMAP_SIGLEN]; /* avoiding endian issues */
- uint8_t fmap_ver_major;
- uint8_t fmap_ver_minor;
- uint64_t fmap_base;
- uint32_t fmap_size;
- char fmap_name[FMAP_NAMELEN];
- uint16_t fmap_nareas;
-} __attribute__((packed)) FmapHeader;
-
-typedef struct _AreaHeader {
- uint32_t area_offset;
- uint32_t area_size;
- char area_name[FMAP_NAMELEN];
- uint16_t area_flags;
-} __attribute__((packed)) AreaHeader;
-
/* Return 0 if successful */
-static int dump_fmap(void *ptr) {
+static int dump_fmap(const void *ptr) {
gauravsh 2011/02/10 20:02:05 const void*
Che-Liang Chiou 2011/02/14 02:27:53 Done.
int i,retval = 0;
char buf[80]; // DWR: magic number
- FmapHeader *fmh = (FmapHeader *)ptr;
- AreaHeader *ah = (AreaHeader *)(ptr + sizeof(FmapHeader));
+ const FmapHeader *fmh = (const FmapHeader *) ptr;
Randall Spangler 2011/02/11 17:26:04 const FmapHeader* fmh
Che-Liang Chiou 2011/02/14 02:27:53 Done.
+ const FmapAreaHeader *ah = (const FmapAreaHeader *)(ptr + sizeof(FmapHeader));
snprintf(buf, FMAP_SIGLEN+1, "%s", fmh->fmap_signature);
printf("fmap_signature %s\n", buf);
@@ -99,8 +80,7 @@ int main(int argc, char *argv[]) {
int errorcnt = 0;
struct stat sb;
int fd;
- char *s;
- size_t i;
+ const char *fmap;
gauravsh 2011/02/10 20:02:05 const char*
Che-Liang Chiou 2011/02/14 02:27:53 Done.
int retval = 1;
progname = strrchr(argv[0], '/');
@@ -170,14 +150,10 @@ int main(int argc, char *argv[]) {
}
close(fd); /* done with this now */
- s = (char *)base_of_rom;
- for (i=0; i<sb.st_size; i += FMAP_SEARCH_STRIDE) {
- if (0 == strncmp(s, "__FMAP__", 8)) {
- printf("hit at 0x%08x\n", (uint32_t)i);
- retval = dump_fmap(s);
- break;
- }
- s += FMAP_SEARCH_STRIDE;
+ fmap = FindFmap((char *) base_of_rom, sb.st_size);
+ if (fmap) {
+ printf("hit at 0x%08x\n", (uint32_t) (fmap - (char *) base_of_rom));
+ retval = dump_fmap(fmap);
}
if (0 != munmap(base_of_rom, sb.st_size)) {

Powered by Google App Engine
This is Rietveld 408576698