Aaron Jin (jin.aaron@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8275
-gerrit
commit ec967eb43b247a8f67697dc20cfabfb1ff6d3f89 Author: Aaron Jin jin.aaron@gmail.com Date: Fri Jan 23 23:35:22 2015 -0800
ifdtool: Apply coding style
- Run "indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs *.[ch]" - Fix coding style violations documented in: http://www.coreboot.org/Coding_Style
Change-Id: Ibdf51c03cbd17b4a0e1cb526c6de8178920b5db7 Signed-off-by: Aaron Jin jin.aaron@gmail.com --- util/ifdtool/ifdtool.c | 352 ++++++++++++++++++++++++++----------------------- util/ifdtool/ifdtool.h | 57 ++++---- 2 files changed, 215 insertions(+), 194 deletions(-)
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c old mode 100644 new mode 100755 index 9569dfa..3e7fe7c --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -34,20 +34,21 @@ #define NUM_REGIONS 5
static const struct region_name region_names[NUM_REGIONS] = { - { "Flash Descriptor", "fd" }, - { "BIOS", "bios" }, - { "Intel ME", "me" }, - { "GbE", "gbe" }, - { "Platform Data", "pd" } + {"Flash Descriptor", "fd"}, + {"BIOS", "bios"}, + {"Intel ME", "me"}, + {"GbE", "gbe"}, + {"Platform Data", "pd"} };
-static fdbar_t *find_fd(char *image, int size) +static struct fdbar *find_fd(char *image, int size) { - int i, found = 0; + int i; + int found = 0;
/* Scan for FD signature */ for (i = 0; i < (size - 4); i += 4) { - if (*(uint32_t *) (image + i) == 0x0FF0A55A) { + if (*(uint32_t *) (image + i) == DESCRIPTOR_SIGNATURE) { found = 1; break; // signature found. } @@ -60,13 +61,16 @@ static fdbar_t *find_fd(char *image, int size)
printf("Found Flash Descriptor signature at 0x%08x\n", i);
- return (fdbar_t *) (image + i); + return (struct fdbar *)(image + i); }
-static region_t get_region(frba_t *frba, int region_type) +static struct region get_region(struct frba *frba, int region_type) { - region_t region; - region.base = 0, region.limit = 0, region.size = 0; + struct region region; + + region.base = 0; + region.limit = 0; + region.size = 0;
switch (region_type) { case 0: @@ -91,7 +95,7 @@ static region_t get_region(frba_t *frba, int region_type) break; default: fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); }
region.size = region.limit - region.base + 1; @@ -101,32 +105,32 @@ static region_t get_region(frba_t *frba, int region_type) return region; }
-static void set_region(frba_t *frba, int region_type, region_t region) +static void set_region(struct frba *frba, int region_type, struct region region) { switch (region_type) { case 0: frba->flreg0 = (((region.limit >> 12) & 0x7fff) << 16) - | ((region.base >> 12) & 0x7fff); + | ((region.base >> 12) & 0x7fff); break; case 1: frba->flreg1 = (((region.limit >> 12) & 0x7fff) << 16) - | ((region.base >> 12) & 0x7fff); + | ((region.base >> 12) & 0x7fff); break; case 2: frba->flreg2 = (((region.limit >> 12) & 0x7fff) << 16) - | ((region.base >> 12) & 0x7fff); + | ((region.base >> 12) & 0x7fff); break; case 3: frba->flreg3 = (((region.limit >> 12) & 0x7fff) << 16) - | ((region.base >> 12) & 0x7fff); + | ((region.base >> 12) & 0x7fff); break; case 4: frba->flreg4 = (((region.limit >> 12) & 0x7fff) << 16) - | ((region.base >> 12) & 0x7fff); + | ((region.base >> 12) & 0x7fff); break; default: fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } }
@@ -134,7 +138,7 @@ static const char *region_name(int region_type) { if (region_type < 0 || region_type >= NUM_REGIONS) { fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); }
return region_names[region_type].pretty; @@ -144,7 +148,7 @@ static const char *region_name_short(int region_type) { if (region_type < 0 || region_type >= NUM_REGIONS) { fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); }
return region_names[region_type].terse; @@ -176,28 +180,29 @@ static const char *region_filename(int region_type)
if (region_type < 0 || region_type >= NUM_REGIONS) { fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); }
return region_filenames[region_type]; }
-static void dump_region(int num, frba_t *frba) +static void dump_region(int num, struct frba *frba) { - region_t region = get_region(frba, num); + struct region region = get_region(frba, num); printf(" Flash Region %d (%s): %08x - %08x %s\n", - num, region_name(num), region.base, region.limit, - region.size < 1 ? "(unused)" : ""); + num, region_name(num), region.base, region.limit, + region.size < 1 ? "(unused)" : ""); }
-static void dump_region_layout(char *buf, size_t bufsize, int num, frba_t *frba) +static void dump_region_layout(char *buf, size_t bufsize, int num, + struct frba *frba) { - region_t region = get_region(frba, num); + struct region region = get_region(frba, num); snprintf(buf, bufsize, "%08x:%08x %s\n", - region.base, region.limit, region_name_short(num)); + region.base, region.limit, region_name_short(num)); }
-static void dump_frba(frba_t * frba) +static void dump_frba(struct frba *frba) { printf("Found Region Section\n"); printf("FLREG0: 0x%08x\n", frba->flreg0); @@ -212,14 +217,14 @@ static void dump_frba(frba_t * frba) dump_region(4, frba); }
-static void dump_frba_layout(frba_t * frba, char *layout_fname) +static void dump_frba_layout(struct frba *frba, char *layout_fname) { char buf[LAYOUT_LINELEN]; size_t bufsize = LAYOUT_LINELEN; int i;
int layout_fd = open(layout_fname, O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (layout_fd == -1) { perror("Could not open file"); exit(EXIT_FAILURE); @@ -279,12 +284,12 @@ static void decode_component_density(unsigned int density) } }
-static void dump_fcba(fcba_t * fcba) +static void dump_fcba(struct fcba *fcba) { printf("\nFound Component Section\n"); printf("FLCOMP 0x%08x\n", fcba->flcomp); printf(" Dual Output Fast Read Support: %ssupported\n", - (fcba->flcomp & (1 << 30))?"":"not "); + (fcba->flcomp & (1 << 30)) ? "" : "not "); printf(" Read ID/Read Status Clock Frequency: "); decode_spi_frequency((fcba->flcomp >> 27) & 7); printf("\n Write/Erase Clock Frequency: "); @@ -292,7 +297,7 @@ static void dump_fcba(fcba_t * fcba) printf("\n Fast Read Clock Frequency: "); decode_spi_frequency((fcba->flcomp >> 21) & 7); printf("\n Fast Read Support: %ssupported", - (fcba->flcomp & (1 << 20))?"":"not "); + (fcba->flcomp & (1 << 20)) ? "" : "not "); printf("\n Read Clock Frequency: "); decode_spi_frequency((fcba->flcomp >> 17) & 7); printf("\n Component 2 Density: "); @@ -301,20 +306,16 @@ static void dump_fcba(fcba_t * fcba) decode_component_density(fcba->flcomp & 7); printf("\n"); printf("FLILL 0x%08x\n", fcba->flill); - printf(" Invalid Instruction 3: 0x%02x\n", - (fcba->flill >> 24) & 0xff); - printf(" Invalid Instruction 2: 0x%02x\n", - (fcba->flill >> 16) & 0xff); - printf(" Invalid Instruction 1: 0x%02x\n", - (fcba->flill >> 8) & 0xff); - printf(" Invalid Instruction 0: 0x%02x\n", - fcba->flill & 0xff); + printf(" Invalid Instruction 3: 0x%02x\n", (fcba->flill >> 24) & 0xff); + printf(" Invalid Instruction 2: 0x%02x\n", (fcba->flill >> 16) & 0xff); + printf(" Invalid Instruction 1: 0x%02x\n", (fcba->flill >> 8) & 0xff); + printf(" Invalid Instruction 0: 0x%02x\n", fcba->flill & 0xff); printf("FLPB 0x%08x\n", fcba->flpb); printf(" Flash Partition Boundary Address: 0x%06x\n\n", - (fcba->flpb & 0xfff) << 12); + (fcba->flpb & 0xfff) << 12); }
-static void dump_fpsba(fpsba_t * fpsba) +static void dump_fpsba(struct fpsba *fpsba) { printf("Found PCH Strap Section\n"); printf("PCHSTRP0: 0x%08x\n", fpsba->pchstrp0); @@ -340,32 +341,32 @@ static void dump_fpsba(fpsba_t * fpsba) static void decode_flmstr(uint32_t flmstr) { printf(" Platform Data Region Write Access: %s\n", - (flmstr & (1 << 28)) ? "enabled" : "disabled"); + (flmstr & (1 << 28)) ? "enabled" : "disabled"); printf(" GbE Region Write Access: %s\n", - (flmstr & (1 << 27)) ? "enabled" : "disabled"); + (flmstr & (1 << 27)) ? "enabled" : "disabled"); printf(" Intel ME Region Write Access: %s\n", - (flmstr & (1 << 26)) ? "enabled" : "disabled"); + (flmstr & (1 << 26)) ? "enabled" : "disabled"); printf(" Host CPU/BIOS Region Write Access: %s\n", - (flmstr & (1 << 25)) ? "enabled" : "disabled"); + (flmstr & (1 << 25)) ? "enabled" : "disabled"); printf(" Flash Descriptor Write Access: %s\n", - (flmstr & (1 << 24)) ? "enabled" : "disabled"); + (flmstr & (1 << 24)) ? "enabled" : "disabled");
printf(" Platform Data Region Read Access: %s\n", - (flmstr & (1 << 20)) ? "enabled" : "disabled"); + (flmstr & (1 << 20)) ? "enabled" : "disabled"); printf(" GbE Region Read Access: %s\n", - (flmstr & (1 << 19)) ? "enabled" : "disabled"); + (flmstr & (1 << 19)) ? "enabled" : "disabled"); printf(" Intel ME Region Read Access: %s\n", - (flmstr & (1 << 18)) ? "enabled" : "disabled"); + (flmstr & (1 << 18)) ? "enabled" : "disabled"); printf(" Host CPU/BIOS Region Read Access: %s\n", - (flmstr & (1 << 17)) ? "enabled" : "disabled"); + (flmstr & (1 << 17)) ? "enabled" : "disabled"); printf(" Flash Descriptor Read Access: %s\n", - (flmstr & (1 << 16)) ? "enabled" : "disabled"); + (flmstr & (1 << 16)) ? "enabled" : "disabled");
printf(" Requester ID: 0x%04x\n\n", - flmstr & 0xffff); + flmstr & 0xffff); }
-static void dump_fmba(fmba_t * fmba) +static void dump_fmba(struct fmba *fmba) { printf("Found Master Section\n"); printf("FLMSTR1: 0x%08x (Host CPU/BIOS)\n", fmba->flmstr1); @@ -376,7 +377,7 @@ static void dump_fmba(fmba_t * fmba) decode_flmstr(fmba->flmstr3); }
-static void dump_fmsba(fmsba_t * fmsba) +static void dump_fmsba(struct fmsba *fmsba) { printf("Found Processor Strap Section\n"); printf("????: 0x%08x\n", fmsba->data[0]); @@ -388,23 +389,21 @@ static void dump_fmsba(fmsba_t * fmsba) static void dump_jid(uint32_t jid) { printf(" SPI Componend Device ID 1: 0x%02x\n", - (jid >> 16) & 0xff); + (jid >> 16) & 0xff); printf(" SPI Componend Device ID 0: 0x%02x\n", - (jid >> 8) & 0xff); - printf(" SPI Componend Vendor ID: 0x%02x\n", - jid & 0xff); + (jid >> 8) & 0xff); + printf(" SPI Componend Vendor ID: 0x%02x\n", jid & 0xff); }
static void dump_vscc(uint32_t vscc) { - printf(" Lower Erase Opcode: 0x%02x\n", - vscc >> 24); + printf(" Lower Erase Opcode: 0x%02x\n", vscc >> 24); printf(" Lower Write Enable on Write Status: 0x%02x\n", - vscc & (1 << 20) ? 0x06 : 0x50); + vscc & (1 << 20) ? 0x06 : 0x50); printf(" Lower Write Status Required: %s\n", - vscc & (1 << 19) ? "Yes" : "No"); + vscc & (1 << 19) ? "Yes" : "No"); printf(" Lower Write Granularity: %d bytes\n", - vscc & (1 << 18) ? 64 : 1); + vscc & (1 << 18) ? 64 : 1); printf(" Lower Block / Sector Erase Size: "); switch ((vscc >> 16) & 0x3) { case 0: @@ -422,13 +421,13 @@ static void dump_vscc(uint32_t vscc) }
printf(" Upper Erase Opcode: 0x%02x\n", - (vscc >> 8) & 0xff); + (vscc >> 8) & 0xff); printf(" Upper Write Enable on Write Status: 0x%02x\n", - vscc & (1 << 4) ? 0x06 : 0x50); + vscc & (1 << 4) ? 0x06 : 0x50); printf(" Upper Write Status Required: %s\n", - vscc & (1 << 3) ? "Yes" : "No"); + vscc & (1 << 3) ? "Yes" : "No"); printf(" Upper Write Granularity: %d bytes\n", - vscc & (1 << 2) ? 64 : 1); + vscc & (1 << 2) ? 64 : 1); printf(" Upper Block / Sector Erase Size: "); switch (vscc & 0x3) { case 0: @@ -446,7 +445,7 @@ static void dump_vscc(uint32_t vscc) } }
-static void dump_vtba(vtba_t *vtba, int vtl) +static void dump_vtba(struct vtba *vtba, int vtl) { int i; int num = (vtl >> 1) < 8 ? (vtl >> 1) : 8; @@ -461,22 +460,24 @@ static void dump_vtba(vtba_t *vtba, int vtl) printf("\n"); }
-static void dump_oem(uint8_t *oem) +static void dump_oem(uint8_t * oem) { - int i, j; + int i; + int j; + printf("OEM Section:\n"); for (i = 0; i < 4; i++) { printf("%02x:", i << 4); for (j = 0; j < 16; j++) - printf(" %02x", oem[(i<<4)+j]); - printf ("\n"); + printf(" %02x", oem[(i << 4) + j]); + printf("\n"); } - printf ("\n"); + printf("\n"); }
static void dump_fd(char *image, int size) { - fdbar_t *fdb = find_fd(image, size); + struct fdbar *fdb = find_fd(image, size); if (!fdb) exit(EXIT_FAILURE);
@@ -498,57 +499,59 @@ static void dump_fd(char *image, int size)
printf("FLUMAP1: 0x%08x\n", fdb->flumap1); printf(" Intel ME VSCC Table Length (VTL): %d\n", - (fdb->flumap1 >> 8) & 0xff); + (fdb->flumap1 >> 8) & 0xff); printf(" Intel ME VSCC Table Base Address (VTBA): 0x%06x\n\n", - (fdb->flumap1 & 0xff) << 4); - dump_vtba((vtba_t *) - (image + ((fdb->flumap1 & 0xff) << 4)), - (fdb->flumap1 >> 8) & 0xff); - dump_oem((uint8_t *)image + 0xf00); - dump_frba((frba_t *) - (image + (((fdb->flmap0 >> 16) & 0xff) << 4))); - dump_fcba((fcba_t *) (image + (((fdb->flmap0) & 0xff) << 4))); - dump_fpsba((fpsba_t *) - (image + (((fdb->flmap1 >> 16) & 0xff) << 4))); - dump_fmba((fmba_t *) (image + (((fdb->flmap1) & 0xff) << 4))); - dump_fmsba((fmsba_t *) (image + (((fdb->flmap2) & 0xff) << 4))); + (fdb->flumap1 & 0xff) << 4); + dump_vtba((struct vtba *) + (image + ((fdb->flumap1 & 0xff) << 4)), + (fdb->flumap1 >> 8) & 0xff); + dump_oem((uint8_t *) image + 0xf00); + dump_frba((struct frba *) + (image + (((fdb->flmap0 >> 16) & 0xff) << 4))); + dump_fcba((struct fcba *)(image + (((fdb->flmap0) & 0xff) << 4))); + dump_fpsba((struct fpsba *) + (image + (((fdb->flmap1 >> 16) & 0xff) << 4))); + dump_fmba((struct fmba *)(image + (((fdb->flmap1) & 0xff) << 4))); + dump_fmsba((struct fmsba *)(image + (((fdb->flmap2) & 0xff) << 4))); }
static void dump_layout(char *image, int size, char *layout_fname) { - fdbar_t *fdb = find_fd(image, size); + struct fdbar *fdb = find_fd(image, size); if (!fdb) exit(EXIT_FAILURE);
- dump_frba_layout((frba_t *) - (image + (((fdb->flmap0 >> 16) & 0xff) << 4)), - layout_fname); + dump_frba_layout((struct frba *) + (image + (((fdb->flmap0 >> 16) & 0xff) << 4)), + layout_fname); }
static void write_regions(char *image, int size) { int i;
- fdbar_t *fdb = find_fd(image, size); + struct fdbar *fdb = find_fd(image, size); if (!fdb) exit(EXIT_FAILURE);
- frba_t *frba = - (frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4)); + struct frba *frba = + (struct frba *)(image + (((fdb->flmap0 >> 16) & 0xff) << 4));
for (i = 0; i < NUM_REGIONS; i++) { - region_t region = get_region(frba, i); + struct region region = get_region(frba, i); dump_region(i, frba); if (region.size > 0) { int region_fd; region_fd = open(region_filename(i), - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + O_WRONLY | O_CREAT | O_TRUNC | + O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (region_fd < 0) { perror("Error while trying to open file"); exit(EXIT_FAILURE); } - if (write(region_fd, image + region.base, region.size) != region.size) + if (write(region_fd, image + region.base, region.size) + != region.size) perror("Error while writing"); close(region_fd); } @@ -557,7 +560,7 @@ static void write_regions(char *image, int size)
static void write_image(char *filename, char *image, int size) { - char new_filename[FILENAME_MAX]; // allow long file names + char new_filename[FILENAME_MAX]; // allow long file names int new_fd;
// - 5: leave room for ".new\0" @@ -568,8 +571,8 @@ static void write_image(char *filename, char *image, int size)
// Now write out new image new_fd = open(new_filename, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (new_fd < 0) { perror("Error while trying to open file"); exit(EXIT_FAILURE); @@ -582,8 +585,9 @@ static void write_image(char *filename, char *image, int size) static void set_spi_frequency(char *filename, char *image, int size, enum spi_frequency freq) { - fdbar_t *fdb = find_fd(image, size); - fcba_t *fcba = (fcba_t *) (image + (((fdb->flmap0) & 0xff) << 4)); + struct fdbar *fdb = find_fd(image, size); + struct fcba *fcba = + (struct fcba *)(image + (((fdb->flmap0) & 0xff) << 4));
/* clear bits 21-29 */ fcba->flcomp &= ~0x3fe00000; @@ -599,8 +603,9 @@ static void set_spi_frequency(char *filename, char *image, int size,
static void set_em100_mode(char *filename, char *image, int size) { - fdbar_t *fdb = find_fd(image, size); - fcba_t *fcba = (fcba_t *) (image + (((fdb->flmap0) & 0xff) << 4)); + struct fdbar *fdb = find_fd(image, size); + struct fcba *fcba = + (struct fcba *)(image + (((fdb->flmap0) & 0xff) << 4));
fcba->flcomp &= ~(1 << 30); set_spi_frequency(filename, image, size, SPI_FREQUENCY_20MHZ); @@ -608,8 +613,9 @@ static void set_em100_mode(char *filename, char *image, int size)
static void lock_descriptor(char *filename, char *image, int size) { - fdbar_t *fdb = find_fd(image, size); - fmba_t *fmba = (fmba_t *) (image + (((fdb->flmap1) & 0xff) << 4)); + struct fdbar *fdb = find_fd(image, size); + struct fmba *fmba = + (struct fmba *)(image + (((fdb->flmap1) & 0xff) << 4)); /* TODO: Dynamically take Platform Data Region and GbE Region * into regard. */ @@ -622,8 +628,9 @@ static void lock_descriptor(char *filename, char *image, int size)
static void unlock_descriptor(char *filename, char *image, int size) { - fdbar_t *fdb = find_fd(image, size); - fmba_t *fmba = (fmba_t *) (image + (((fdb->flmap1) & 0xff) << 4)); + struct fdbar *fdb = find_fd(image, size); + struct fmba *fmba = + (struct fmba *)(image + (((fdb->flmap1) & 0xff) << 4)); fmba->flmstr1 = 0xffff0000; fmba->flmstr2 = 0xffff0000; fmba->flmstr3 = 0x08080118; @@ -634,16 +641,17 @@ static void unlock_descriptor(char *filename, char *image, int size) void inject_region(char *filename, char *image, int size, int region_type, char *region_fname) { - fdbar_t *fdb = find_fd(image, size); + struct fdbar *fdb = find_fd(image, size); if (!fdb) exit(EXIT_FAILURE); - frba_t *frba = - (frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4)); + struct frba *frba = + (struct frba *)(image + (((fdb->flmap0 >> 16) & 0xff) << 4));
- region_t region = get_region(frba, region_type); + struct region region = get_region(frba, region_type); if (region.size <= 0xfff) { - fprintf(stderr, "Region %s is disabled in target. Not injecting.\n", - region_name(region_type)); + fprintf(stderr, + "Region %s is disabled in target. Not injecting.\n", + region_name(region_type)); exit(EXIT_FAILURE); }
@@ -661,21 +669,21 @@ void inject_region(char *filename, char *image, int size, int region_type,
printf("File %s is %d bytes\n", region_fname, region_size);
- if ( (region_size > region.size) || ((region_type != 1) && - (region_size > region.size))) { + if ((region_size > region.size) || ((region_type != 1) && + (region_size > region.size))) { fprintf(stderr, "Region %s is %d(0x%x) bytes. File is %d(0x%x)" - " bytes. Not injecting.\n", - region_name(region_type), region.size, - region.size, region_size, region_size); + " bytes. Not injecting.\n", + region_name(region_type), region.size, + region.size, region_size, region_size); exit(EXIT_FAILURE); }
int offset = 0; if ((region_type == 1) && (region_size < region.size)) { fprintf(stderr, "Region %s is %d(0x%x) bytes. File is %d(0x%x)" - " bytes. Padding before injecting.\n", - region_name(region_type), region.size, - region.size, region_size, region_size); + " bytes. Padding before injecting.\n", + region_name(region_type), region.size, + region.size, region_size, region_size); offset = region.size - region_size; memset(image + region.base, 0xff, offset); } @@ -687,7 +695,7 @@ void inject_region(char *filename, char *image, int size, int region_type, }
if (read(region_fd, image + region.base + offset, region_size) - != region_size) { + != region_size) { perror("Could not read file"); exit(EXIT_FAILURE); } @@ -717,13 +725,13 @@ unsigned int next_pow2(unsigned int x) * @return 0 if the two regions are seperate * @return 1 if the two regions overlap */ -static int regions_collide(region_t r1, region_t r2) +static int regions_collide(struct region r1, struct region r2) { if ((r1.size == 0) || (r2.size == 0)) return 0;
- if ( ((r1.base >= r2.base) && (r1.base <= r2.limit)) || - ((r1.limit >= r2.base) && (r1.limit <= r2.limit)) ) + if (((r1.base >= r2.base) && (r1.base <= r2.limit)) || + ((r1.limit >= r2.base) && (r1.limit <= r2.limit))) return 1;
return 0; @@ -734,20 +742,21 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) FILE *romlayout; char tempstr[256]; char layout_region_name[256]; - int i, j; + int i; + int j; int region_number; - region_t current_regions[NUM_REGIONS]; - region_t new_regions[NUM_REGIONS]; + struct region current_regions[NUM_REGIONS]; + struct region new_regions[NUM_REGIONS]; int new_extent = 0; char *new_image;
/* load current descriptor map and regions */ - fdbar_t *fdb = find_fd(image, size); + struct fdbar *fdb = find_fd(image, size); if (!fdb) exit(EXIT_FAILURE);
- frba_t *frba = - (frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4)); + struct frba *frba = + (struct frba *)(image + (((fdb->flmap0 >> 16) & 0xff) << 4));
for (i = 0; i < NUM_REGIONS; i++) { current_regions[i] = get_region(frba, i); @@ -766,7 +775,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) char *tstr1, *tstr2;
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, - layout_region_name)) + layout_region_name)) continue;
region_number = region_num(layout_region_name); @@ -780,12 +789,12 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) exit(EXIT_FAILURE); } new_regions[region_number].base = strtol(tstr1, - (char **)NULL, 16); + (char **)NULL, 16); new_regions[region_number].limit = strtol(tstr2, - (char **)NULL, 16); + (char **)NULL, 16); new_regions[region_number].size = - new_regions[region_number].limit - - new_regions[region_number].base + 1; + new_regions[region_number].limit - + new_regions[region_number].base + 1;
if (new_regions[region_number].size < 0) new_regions[region_number].size = 0; @@ -799,7 +808,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
if (new_regions[i].size < current_regions[i].size) { printf("DANGER: Region %s is shrinking.\n", - region_name(i)); + region_name(i)); printf(" The region will be truncated to fit.\n"); printf(" This may result in an unusable image.\n"); } @@ -828,9 +837,10 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) memset(new_image, 0xff, new_extent); for (i = 0; i < NUM_REGIONS; i++) { int copy_size = new_regions[i].size; - int offset_current = 0, offset_new = 0; - region_t current = current_regions[i]; - region_t new = new_regions[i]; + int offset_current = 0; + int offset_new = 0; + struct region current = current_regions[i]; + struct region new = new_regions[i];
if (new.size == 0) continue; @@ -846,16 +856,15 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) offset_current = current.size - new.size; }
- printf("Copy Descriptor %d (%s) (%d bytes)\n", i, - region_name(i), copy_size); + printf("Copy Descriptor %d (%s)(%d bytes)\n", i, + region_name(i), copy_size); printf(" from %08x+%08x:%08x (%10d)\n", current.base, - offset_current, current.limit, current.size); + offset_current, current.limit, current.size); printf(" to %08x+%08x:%08x (%10d)\n", new.base, - offset_new, new.limit, new.size); + offset_new, new.limit, new.size);
memcpy(new_image + new.base + offset_new, - image + current.base + offset_current, - copy_size); + image + current.base + offset_current, copy_size); }
/* update new descriptor regions */ @@ -863,7 +872,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname) if (!fdb) exit(EXIT_FAILURE);
- frba = (frba_t *) (new_image + (((fdb->flmap0 >> 16) & 0xff) << 4)); + frba = (struct frba *)(new_image + (((fdb->flmap0 >> 16) & 0xff) << 4)); for (i = 1; i < NUM_REGIONS; i++) { set_region(frba, i, new_regions[i]); } @@ -904,18 +913,26 @@ static void print_usage(const char *name) " -u | --unlock Unlock firmware descriptor and ME region\n" " -v | --version: print the version\n" " -h | --help: print this help\n\n" - "<region> is one of Descriptor, BIOS, ME, GbE, Platform\n" - "\n"); + "<region> is one of Descriptor, BIOS, ME, GbE, Platform\n" "\n"); }
int main(int argc, char *argv[]) { int opt, option_index = 0; - int mode_dump = 0, mode_extract = 0, mode_inject = 0, mode_spifreq = 0; - int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0; - int mode_layout = 0, mode_newlayout = 0; - char *region_type_string = NULL, *region_fname = NULL, *layout_fname = NULL; - int region_type = -1, inputfreq = 0; + int mode_dump = 0; + int mode_extract = 0; + int mode_inject = 0; + int mode_spifreq = 0; + int mode_em100 = 0; + int mode_locked = 0; + int mode_unlocked = 0; + int mode_layout = 0; + int mode_newlayout = 0; + char *region_type_string = NULL; + char *region_fname = NULL; + char *layout_fname = NULL; + int region_type = -1; + int inputfreq = 0; enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ;
static struct option long_options[] = { @@ -1017,14 +1034,16 @@ int main(int argc, char *argv[]) case 'l': mode_locked = 1; if (mode_unlocked == 1) { - fprintf(stderr, "Locking/Unlocking FD and ME are mutually exclusive\n"); + fprintf(stderr, + "Locking/Unlocking FD and ME are mutually exclusive\n"); exit(EXIT_FAILURE); } break; case 'u': mode_unlocked = 1; if (mode_locked == 1) { - fprintf(stderr, "Locking/Unlocking FD and ME are mutually exclusive\n"); + fprintf(stderr, + "Locking/Unlocking FD and ME are mutually exclusive\n"); exit(EXIT_FAILURE); } break; @@ -1042,8 +1061,8 @@ int main(int argc, char *argv[]) }
if ((mode_dump + mode_layout + mode_extract + mode_inject + - mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked | - mode_locked)) > 1) { + mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked | + mode_locked)) > 1) { fprintf(stderr, "You may not specify more than one mode.\n\n"); print_usage(argv[0]); exit(EXIT_FAILURE); @@ -1101,8 +1120,7 @@ int main(int argc, char *argv[]) write_regions(image, size);
if (mode_inject) - inject_region(filename, image, size, region_type, - region_fname); + inject_region(filename, image, size, region_type, region_fname);
if (mode_newlayout) new_layout(filename, image, size, layout_fname); @@ -1113,7 +1131,7 @@ int main(int argc, char *argv[]) if (mode_em100) set_em100_mode(filename, image, size);
- if(mode_locked) + if (mode_locked) lock_descriptor(filename, image, size);
if (mode_unlocked) diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h old mode 100644 new mode 100755 index ed8f440..19a1258 --- a/util/ifdtool/ifdtool.h +++ b/util/ifdtool/ifdtool.h @@ -21,6 +21,7 @@ #define IFDTOOL_VERSION "1.1"
#define LAYOUT_LINELEN 80 +#define DESCRIPTOR_SIGNATURE 0x0FF0A55A
enum spi_frequency { SPI_FREQUENCY_20MHZ = 0, @@ -30,41 +31,41 @@ enum spi_frequency {
enum component_density { COMPONENT_DENSITY_512KB = 0, - COMPONENT_DENSITY_1MB = 1, - COMPONENT_DENSITY_2MB = 2, - COMPONENT_DENSITY_4MB = 3, - COMPONENT_DENSITY_8MB = 4, - COMPONENT_DENSITY_16MB = 5, + COMPONENT_DENSITY_1MB = 1, + COMPONENT_DENSITY_2MB = 2, + COMPONENT_DENSITY_4MB = 3, + COMPONENT_DENSITY_8MB = 4, + COMPONENT_DENSITY_16MB = 5, };
// flash descriptor -typedef struct { +struct fdbar { uint32_t flvalsig; uint32_t flmap0; uint32_t flmap1; uint32_t flmap2; - uint8_t reserved[0xefc - 0x20]; + uint8_t reserved[0xefc - 0x20]; uint32_t flumap1; -} __attribute__((packed)) fdbar_t; +} __attribute__ ((packed));
// regions -typedef struct { +struct frba { uint32_t flreg0; uint32_t flreg1; uint32_t flreg2; uint32_t flreg3; uint32_t flreg4; -} __attribute__((packed)) frba_t; +} __attribute__ ((packed));
// component section -typedef struct { +struct fcba { uint32_t flcomp; uint32_t flill; uint32_t flpb; -} __attribute__((packed)) fcba_t; +} __attribute__ ((packed));
// pch strap -typedef struct { +struct fpsba { uint32_t pchstrp0; uint32_t pchstrp1; uint32_t pchstrp2; @@ -83,36 +84,38 @@ typedef struct { uint32_t pchstrp15; uint32_t pchstrp16; uint32_t pchstrp17; -} __attribute__((packed)) fpsba_t; +} __attribute__ ((packed));
// master -typedef struct { +struct fmba { uint32_t flmstr1; uint32_t flmstr2; uint32_t flmstr3; -} __attribute__((packed)) fmba_t; +} __attribute__ ((packed));
// processor strap -typedef struct { +struct fmsba { uint32_t data[8]; -} __attribute__((packed)) fmsba_t; +} __attribute__ ((packed));
// ME VSCC -typedef struct { +struct vscc { uint32_t jid; uint32_t vscc; -} vscc_t; +} __attribute__ ((packed));
-typedef struct { +struct vtba { // Actual number of entries specified in vtl - vscc_t entry[8]; -} vtba_t; + struct vscc entry[8]; +} __attribute__ ((packed));
-typedef struct { - int base, limit, size; -} region_t; +struct region { + int base; + int limit; + int size; +} __attribute__ ((packed));
struct region_name { char *pretty; char *terse; -}; +} __attribute__ ((packed));