1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

Clean up ICH descriptor code

- allows for compilation with -Werror=shadow,
 - use extended line limit to fix the most awful line breaks.

Corresponding to flashrom svn r1570.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
This commit is contained in:
Stefan Tauner 2012-08-13 08:45:13 +00:00
parent 37e8686284
commit a1a14ec5d2
2 changed files with 52 additions and 74 deletions

View File

@ -85,26 +85,16 @@ void prettyprint_ich_descriptor_content(const struct ich_desc_content *cont)
msg_pdbg2("\n"); msg_pdbg2("\n");
msg_pdbg2("--- Details ---\n"); msg_pdbg2("--- Details ---\n");
msg_pdbg2("NR (Number of Regions): %5d\n", msg_pdbg2("NR (Number of Regions): %5d\n", cont->NR + 1);
cont->NR + 1); msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
getFRBA(cont)); msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
msg_pdbg2("NC (Number of Components): %5d\n", msg_pdbg2("ISL (ICH/PCH Strap Length): %5d\n", cont->ISL);
cont->NC + 1); msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH Strap Base Address): 0x%03x\n", getFISBA(cont));
msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", msg_pdbg2("NM (Number of Masters): %5d\n", cont->NM + 1);
getFCBA(cont)); msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
msg_pdbg2("ISL (ICH/PCH Strap Length): %5d\n", msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
cont->ISL); msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH Strap Base Address): 0x%03x\n",
getFISBA(cont));
msg_pdbg2("NM (Number of Masters): %5d\n",
cont->NM + 1);
msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n",
getFMBA(cont));
msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n",
cont->MSL);
msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n",
getFMSBA(cont));
msg_pdbg2("\n"); msg_pdbg2("\n");
} }
@ -520,8 +510,8 @@ void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap
msg_pdbg2("Integrated Clocking Configuration used: %d\n", msg_pdbg2("Integrated Clocking Configuration used: %d\n",
s->cougar.ICC_SEL); s->cougar.ICC_SEL);
msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a " msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
"reset.\n", s->ibex.MER_CL1 ? "" : "not "); s->ibex.MER_CL1 ? "" : "not ");
msg_pdbg2("ICC Profile is selected by %s.\n", msg_pdbg2("ICC Profile is selected by %s.\n",
s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS"); s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
msg_pdbg2("Deep SX is %ssupported on the platform.\n", msg_pdbg2("Deep SX is %ssupported on the platform.\n",
@ -538,8 +528,7 @@ void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap
s->cougar.IWL_EN ? "en" : "dis"); s->cougar.IWL_EN ? "en" : "dis");
msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5); msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
msg_pdbg2("SMLink1 provides temperature from %s.\n", msg_pdbg2("SMLink1 provides temperature from %s.\n",
s->cougar.SMLINK1_THERM_SEL ? s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
"PCH only" : "the CPU, PCH and DIMMs");
msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ? msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
"general purpose output" : "SLP_LAN#"); "general purpose output" : "SLP_LAN#");
@ -552,32 +541,32 @@ void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap
void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc) void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
{ {
unsigned int i, max; unsigned int i, max_count;
msg_pdbg2("=== Softstraps ===\n"); msg_pdbg2("=== Softstraps ===\n");
if (sizeof(desc->north.STRPs) / 4 + 1 < desc->content.MSL) { if (sizeof(desc->north.STRPs) / 4 + 1 < desc->content.MSL) {
max = sizeof(desc->north.STRPs) / 4 + 1; max_count = sizeof(desc->north.STRPs) / 4 + 1;
msg_pdbg2("MSL (%u) is greater than the current maximum of %u " msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
"entries.\n", desc->content.MSL, max + 1); desc->content.MSL, max_count + 1);
msg_pdbg2("Only the first %u entries will be printed.\n", max); msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
} else } else
max = desc->content.MSL; max_count = desc->content.MSL;
msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max); msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
for (i = 0; i < max; i++) for (i = 0; i < max_count; i++)
msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]); msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
msg_pdbg2("\n"); msg_pdbg2("\n");
if (sizeof(desc->south.STRPs) / 4 < desc->content.ISL) { if (sizeof(desc->south.STRPs) / 4 < desc->content.ISL) {
max = sizeof(desc->south.STRPs) / 4; max_count = sizeof(desc->south.STRPs) / 4;
msg_pdbg2("ISL (%u) is greater than the current maximum of %u " msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
"entries.\n", desc->content.ISL, max); desc->content.ISL, max_count);
msg_pdbg2("Only the first %u entries will be printed.\n", max); msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
} else } else
max = desc->content.ISL; max_count = desc->content.ISL;
msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max); msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
for (i = 0; i < max; i++) for (i = 0; i < max_count; i++)
msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]); msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
msg_pdbg2("\n"); msg_pdbg2("\n");
@ -608,8 +597,7 @@ void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_des
case CHIPSET_ICH_UNKNOWN: case CHIPSET_ICH_UNKNOWN:
break; break;
default: default:
msg_pdbg2("The meaning of the descriptor straps are unknown " msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
"yet.\n\n");
break; break;
} }
} }
@ -634,8 +622,7 @@ void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
msg_pdbg2("\n"); msg_pdbg2("\n");
msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2); msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
for (i = 0; i < umap->VTL/2; i++) for (i = 0; i < umap->VTL/2; i++) {
{
uint32_t jid = umap->vscc_table[i].JID; uint32_t jid = umap->vscc_table[i].JID;
uint32_t vscc = umap->vscc_table[i].VSCC; uint32_t vscc = umap->vscc_table[i].VSCC;
msg_pdbg2(" JID%d = 0x%08x\n", i, jid); msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
@ -651,7 +638,7 @@ void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
/* len is the length of dump in bytes */ /* len is the length of dump in bytes */
int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struct ich_descriptors *desc) int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struct ich_descriptors *desc)
{ {
unsigned int i, max; unsigned int i, max_count;
uint8_t pch_bug_offset = 0; uint8_t pch_bug_offset = 0;
if (dump == NULL || desc == NULL) if (dump == NULL || desc == NULL)
@ -708,10 +695,8 @@ int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struc
return ICH_RET_OOB; return ICH_RET_OOB;
for (i = 0; i < desc->upper.VTL/2; i++) { for (i = 0; i < desc->upper.VTL/2; i++) {
desc->upper.vscc_table[i].JID = desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0]; desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
desc->upper.vscc_table[i].VSCC =
dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
} }
/* MCH/PROC (aka. North) straps */ /* MCH/PROC (aka. North) straps */
@ -719,20 +704,18 @@ int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len, struc
return ICH_RET_OOB; return ICH_RET_OOB;
/* limit the range to be written */ /* limit the range to be written */
max = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL); max_count = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
for (i = 0; i < max; i++) for (i = 0; i < max_count; i++)
desc->north.STRPs[i] = desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
dump[(getFMSBA(&desc->content) >> 2) + i];
/* ICH/PCH (aka. South) straps */ /* ICH/PCH (aka. South) straps */
if (len < getFISBA(&desc->content) + desc->content.ISL * 4) if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
return ICH_RET_OOB; return ICH_RET_OOB;
/* limit the range to be written */ /* limit the range to be written */
max = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL); max_count = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
for (i = 0; i < max; i++) for (i = 0; i < max_count; i++)
desc->south.STRPs[i] = desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
dump[(getFISBA(&desc->content) >> 2) + i];
return ICH_RET_OK; return ICH_RET_OK;
} }
@ -755,13 +738,12 @@ int getFCBA_component_density(const struct ich_descriptors *desc, uint8_t idx)
size_enc = desc->component.comp2_density; size_enc = desc->component.comp2_density;
break; break;
default: default:
msg_perr("Only ICH SPI component index 0 or 1 are supported " msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
"yet.\n");
return 0; return 0;
} }
if (size_enc > 5) { if (size_enc > 5) {
msg_perr("Density of ICH SPI component with index %d is " msg_perr("Density of ICH SPI component with index %d is invalid. Encoded density is 0x%x.\n",
"invalid. Encoded density is 0x%x.\n", idx, size_enc); idx, size_enc);
return 0; return 0;
} }
return (1 << (19 + size_enc)); return (1 << (19 + size_enc));
@ -804,8 +786,7 @@ int read_ich_descriptors_via_fdo(void *spibar, struct ich_descriptors *desc)
return ICH_RET_ERR; return ICH_RET_ERR;
} }
msg_pdbg2("Reading flash descriptors " msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
"mapped by the chipset via FDOC/FDOD...");
/* content section */ /* content section */
desc->content.FLVALSIG = read_descriptor_reg(0, 0, spibar); desc->content.FLVALSIG = read_descriptor_reg(0, 0, spibar);
desc->content.FLMAP0 = read_descriptor_reg(0, 1, spibar); desc->content.FLMAP0 = read_descriptor_reg(0, 1, spibar);

View File

@ -40,7 +40,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
static void dump_file(const char *basename, const uint32_t *dump, unsigned int len, struct ich_desc_region *reg, unsigned int i) static void dump_file(const char *prefix, const uint32_t *dump, unsigned int len, struct ich_desc_region *reg, unsigned int i)
{ {
int ret; int ret;
char *fn; char *fn;
@ -54,8 +54,7 @@ static void dump_file(const char *basename, const uint32_t *dump, unsigned int l
reg_name = region_names[i]; reg_name = region_names[i];
if (base > limit) { if (base > limit) {
printf("The %s region is unused and thus not dumped.\n", printf("The %s region is unused and thus not dumped.\n", reg_name);
reg_name);
return; return;
} }
@ -68,13 +67,13 @@ static void dump_file(const char *basename, const uint32_t *dump, unsigned int l
return; return;
} }
fn = malloc(strlen(basename) + strlen(reg_name) + strlen(".bin") + 2); fn = malloc(strlen(prefix) + strlen(reg_name) + strlen(".bin") + 2);
if (!fn) { if (!fn) {
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
exit(1); exit(1);
} }
snprintf(fn, strlen(basename) + strlen(reg_name) + strlen(".bin") + 2, snprintf(fn, strlen(prefix) + strlen(reg_name) + strlen(".bin") + 2,
"%s.%s.bin", basename, reg_name); "%s.%s.bin", prefix, reg_name);
printf("Dumping %u bytes of the %s region from 0x%08x-0x%08x to %s... ", printf("Dumping %u bytes of the %s region from 0x%08x-0x%08x to %s... ",
file_len, region_names[i], base, limit, fn); file_len, region_names[i], base, limit, fn);
int fh = open(fn, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); int fh = open(fn, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
@ -95,12 +94,12 @@ static void dump_file(const char *basename, const uint32_t *dump, unsigned int l
close(fh); close(fh);
} }
void dump_files(const char *n, const uint32_t *buf, unsigned int len, struct ich_desc_region *reg) void dump_files(const char *name, const uint32_t *buf, unsigned int len, struct ich_desc_region *reg)
{ {
unsigned int i; unsigned int i;
printf("=== Dumping region files ===\n"); printf("=== Dumping region files ===\n");
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
dump_file(n, buf, len, reg, i); dump_file(name, buf, len, reg, i);
printf("\n"); printf("\n");
} }
@ -157,8 +156,7 @@ int main(int argc, char *argv[])
} }
} }
if (fn == NULL) if (fn == NULL)
usage(argv, usage(argv, "Need the file name of a descriptor image to read from.");
"Need a file name of a descriptor image to read from.");
fd = open(fn, O_RDONLY); fd = open(fn, O_RDONLY);
if (fd < 0) if (fd < 0)
@ -209,8 +207,7 @@ int main(int argc, char *argv[])
printf("Image not in descriptor mode.\n"); printf("Image not in descriptor mode.\n");
exit(1); exit(1);
case ICH_RET_OOB: case ICH_RET_OOB:
printf("Tried to access a location out of bounds of the image. " printf("Tried to access a location out of bounds of the image. - Corrupt image?\n");
"- Corrupt image?\n");
exit(1); exit(1);
default: default:
printf("Unhandled return value at %s:%u, please report this.\n", printf("Unhandled return value at %s:%u, please report this.\n",