| 1204 | } |
| 1205 | |
| 1206 | static void validate_layout(char *image, int size) |
| 1207 | { |
| 1208 | uint i, errors = 0; |
| 1209 | struct fmap *fmap; |
| 1210 | long int fmap_loc = fmap_find((uint8_t *)image, size); |
| 1211 | const struct frba *frba = find_frba(image, size); |
| 1212 | |
| 1213 | if (fmap_loc < 0 || !frba) { |
| 1214 | printf("Could not find FMAP (%p) or Intel Flash Descriptor (%p)\n", |
| 1215 | (void *)fmap_loc, frba); |
| 1216 | exit(EXIT_FAILURE); |
| 1217 | } |
| 1218 | |
| 1219 | fmap = (struct fmap *)(image + fmap_loc); |
| 1220 | |
| 1221 | int matches = 0; |
| 1222 | for (i = 0; i < max_regions; i++) { |
| 1223 | struct region region = get_region(frba, i); |
| 1224 | if (region.size == 0) |
| 1225 | continue; |
| 1226 | |
| 1227 | const struct fmap_area *area = fmap_find_area(fmap, region_names[i].fmapname); |
| 1228 | if (!area) |
| 1229 | continue; |
| 1230 | |
| 1231 | matches++; // found a match between FMAP and IFD region |
| 1232 | |
| 1233 | if ((uint)region.base != area->offset || (uint)region.size != area->size) { |
| 1234 | if (i == REGION_BIOS) { |
| 1235 | /* |
| 1236 | * BIOS FMAP region is a special case |
| 1237 | * coreboots FMAP BIOS region depends on the CONFIG_CBFS_SIZE |
| 1238 | * while the IFD BIOS region is always of static size. |
| 1239 | * Therefore we just make sure that the BIOS region of the FMAP |
| 1240 | * is inside the region specified by the IFD |
| 1241 | */ |
| 1242 | if ((uint)region.base <= area->offset && |
| 1243 | ((uint)region.base + region.size) >= (area->offset + area->size)) { |
| 1244 | continue; |
| 1245 | } |
| 1246 | } |
| 1247 | printf("Region mismatch between %s and %s\n", region_names[i].terse, area->name); |
| 1248 | printf(" Descriptor region %s:\n", region_names[i].terse); |
| 1249 | printf(" offset: 0x%08x\n", region.base); |
| 1250 | printf(" length: 0x%08x\n", region.size); |
| 1251 | printf(" FMAP area %s:\n", area->name); |
| 1252 | printf(" offset: 0x%08x\n", area->offset); |
| 1253 | printf(" length: 0x%08x\n", area->size); |
| 1254 | errors++; |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | if (!matches) { |
| 1259 | // At least a BIOS region should be present in both IFD and FMAP |
| 1260 | fprintf(stderr, "Warning: Not a single IFD region found in FMAP\n"); |
| 1261 | } |
| 1262 | |
| 1263 | if (errors > 0) |
no test coverage detected