summaryrefslogtreecommitdiff
path: root/util/ifdtool
diff options
context:
space:
mode:
authorChris Douglass <cdouglass.orion@gmail.com>2014-02-28 08:54:41 -0500
committerStefan Reinauer <stefan.reinauer@coreboot.org>2014-02-28 21:13:15 +0100
commite2718656ec9ca7cb3c6f94453b9e76b0ae132abd (patch)
treec0e72e9126c47c4970cdd8a54aac47fc2108b373 /util/ifdtool
parent4eabe1e4e1e4aa7ffa5a147a609a8782f48f0791 (diff)
downloadcoreboot-e2718656ec9ca7cb3c6f94453b9e76b0ae132abd.tar.xz
util/ifdtool: cleanup some magic numbers
There are five firmware regions that are (currently) defined. This was assumed throughout the ifdtool code with many literal 4s and 5s. This patch changes them to refer to a new #define NUM_REGIONS. Change-Id: I523d3763942f875025ebc4b9ba8b2ccf1db5b2f5 Signed-off-by: Christopher Douglass <cdouglass.orion@gmail.com> Reviewed-on: http://review.coreboot.org/5313 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/ifdtool')
-rw-r--r--util/ifdtool/ifdtool.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index 28dbaacec7..0425b1cd49 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -27,7 +27,9 @@
#include <sys/stat.h>
#include "ifdtool.h"
-static const struct region_name region_names[5] = {
+#define NUM_REGIONS 5
+
+static const struct region_name region_names[NUM_REGIONS] = {
{ "Flash Descriptor", "fd" },
{ "BIOS", "bios" },
{ "Intel ME", "me" },
@@ -126,7 +128,7 @@ static void set_region(frba_t *frba, int region_type, region_t region)
static const char *region_name(int region_type)
{
- if (region_type < 0 || region_type > 4) {
+ if (region_type < 0 || region_type >= NUM_REGIONS) {
fprintf(stderr, "Invalid region type.\n");
exit (EXIT_FAILURE);
}
@@ -136,7 +138,7 @@ static const char *region_name(int region_type)
static const char *region_name_short(int region_type)
{
- if (region_type < 0 || region_type > 4) {
+ if (region_type < 0 || region_type >= NUM_REGIONS) {
fprintf(stderr, "Invalid region type.\n");
exit (EXIT_FAILURE);
}
@@ -148,7 +150,7 @@ static int region_num(const char *name)
{
int i;
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < NUM_REGIONS; i++) {
if (strcasecmp(name, region_names[i].pretty) == 0)
return i;
if (strcasecmp(name, region_names[i].terse) == 0)
@@ -160,7 +162,7 @@ static int region_num(const char *name)
static const char *region_filename(int region_type)
{
- static const char *region_filenames[5] = {
+ static const char *region_filenames[NUM_REGIONS] = {
"flashregion_0_flashdescriptor.bin",
"flashregion_1_bios.bin",
"flashregion_2_intel_me.bin",
@@ -168,7 +170,7 @@ static const char *region_filename(int region_type)
"flashregion_4_platform_data.bin"
};
- if (region_type < 0 || region_type > 4) {
+ if (region_type < 0 || region_type >= NUM_REGIONS) {
fprintf(stderr, "Invalid region type.\n");
exit (EXIT_FAILURE);
}
@@ -219,7 +221,7 @@ static void dump_frba_layout(frba_t * frba, char *layout_fname)
exit(EXIT_FAILURE);
}
- for (i = 0; i <= 4; i++) {
+ for (i = 0; i < NUM_REGIONS; i++) {
dump_region_layout(buf, bufsize, i, frba);
if (write(layout_fd, buf, strlen(buf)) < 0) {
perror("Could not write to file");
@@ -530,7 +532,7 @@ static void write_regions(char *image, int size)
frba_t *frba =
(frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4));
- for (i = 0; i<5; i++) {
+ for (i = 0; i < NUM_REGIONS; i++) {
region_t region = get_region(frba, i);
dump_region(i, frba);
if (region.size > 0) {
@@ -721,8 +723,8 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
char layout_region_name[256];
int i, j;
int region_number;
- region_t current_regions[5];
- region_t new_regions[5];
+ region_t current_regions[NUM_REGIONS];
+ region_t new_regions[NUM_REGIONS];
int new_extent = 0;
char *new_image;
@@ -734,7 +736,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
frba_t *frba =
(frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4));
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < NUM_REGIONS; i++) {
current_regions[i] = get_region(frba, i);
new_regions[i] = get_region(frba, i);
}
@@ -778,7 +780,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
fclose(romlayout);
/* check new layout */
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < NUM_REGIONS; i++) {
if (new_regions[i].size == 0)
continue;
@@ -789,7 +791,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
printf(" This may result in an unusable image.\n");
}
- for (j = i + 1; j < 5; j++) {
+ for (j = i + 1; j < NUM_REGIONS; j++) {
if (regions_collide(new_regions[i], new_regions[j])) {
fprintf(stderr, "Regions would overlap.\n");
exit(EXIT_FAILURE);
@@ -811,7 +813,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
/* copy regions to a new image */
new_image = malloc(new_extent);
memset(new_image, 0xff, new_extent);
- for (i = 0; i < 5; i++) {
+ 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];
@@ -849,7 +851,7 @@ void new_layout(char *filename, char *image, int size, char *layout_fname)
exit(EXIT_FAILURE);
frba = (frba_t *) (new_image + (((fdb->flmap0 >> 16) & 0xff) << 4));
- for (i = 1; i < 5; i++) {
+ for (i = 1; i < NUM_REGIONS; i++) {
set_region(frba, i, new_regions[i]);
}