| 1444 | } |
| 1445 | |
| 1446 | static int cbfs_create(void) |
| 1447 | { |
| 1448 | struct cbfs_image image; |
| 1449 | memset(&image, 0, sizeof(image)); |
| 1450 | buffer_clone(&image.buffer, param.image_region); |
| 1451 | |
| 1452 | if (param.fmap) { |
| 1453 | if (param.arch != CBFS_ARCHITECTURE_UNKNOWN || param.size || |
| 1454 | param.baseaddress_assigned || |
| 1455 | param.headeroffset_assigned || |
| 1456 | param.cbfsoffset_assigned || |
| 1457 | param.bootblock) { |
| 1458 | ERROR("Since -M was provided, -m, -s, -b, -o, -H, and -B should be omitted\n"); |
| 1459 | return 1; |
| 1460 | } |
| 1461 | |
| 1462 | return cbfs_image_create(&image, image.buffer.size); |
| 1463 | } |
| 1464 | |
| 1465 | if (param.arch == CBFS_ARCHITECTURE_UNKNOWN) { |
| 1466 | ERROR("You need to specify -m/--machine arch.\n"); |
| 1467 | return 1; |
| 1468 | } |
| 1469 | |
| 1470 | struct buffer bootblock; |
| 1471 | if (!param.bootblock) { |
| 1472 | DEBUG("-B not given, creating image without bootblock.\n"); |
| 1473 | if (buffer_create(&bootblock, 0, "(dummy)") != 0) |
| 1474 | return 1; |
| 1475 | } else if (buffer_from_file(&bootblock, param.bootblock)) { |
| 1476 | return 1; |
| 1477 | } |
| 1478 | |
| 1479 | if (!param.alignment) |
| 1480 | param.alignment = CBFS_ALIGNMENT; |
| 1481 | |
| 1482 | // Set default offsets. x86, as usual, needs to be a special snowflake. |
| 1483 | if (!param.baseaddress_assigned) { |
| 1484 | if (param.arch == CBFS_ARCHITECTURE_X86) { |
| 1485 | // Make sure there's at least enough room for rel_offset |
| 1486 | param.baseaddress = param.size - |
| 1487 | MAX(bootblock.size, sizeof(int32_t)); |
| 1488 | DEBUG("x86 -> bootblock lies at end of ROM (%#x).\n", |
| 1489 | param.baseaddress); |
| 1490 | } else { |
| 1491 | param.baseaddress = 0; |
| 1492 | DEBUG("bootblock starts at address 0x0.\n"); |
| 1493 | } |
| 1494 | } |
| 1495 | if (!param.headeroffset_assigned) { |
| 1496 | if (param.arch == CBFS_ARCHITECTURE_X86) { |
| 1497 | param.headeroffset = param.baseaddress - |
| 1498 | sizeof(struct cbfs_header); |
| 1499 | DEBUG("x86 -> CBFS header before bootblock (%#x).\n", |
| 1500 | param.headeroffset); |
| 1501 | } else { |
| 1502 | param.headeroffset = align_up(param.baseaddress + |
| 1503 | bootblock.size, sizeof(uint32_t)); |
nothing calls this directly
no test coverage detected