In src/arch/x86/Makefile.bootblock.inc: ####################################################################### 75 # Build the romstage 76 $(obj)/coreboot.romstage: $(obj)/coreboot.pre1 $$(romstage-objs) $(obj)/romstage/ldscript.ld 77 @printf " LINK $(subst $(obj)/,,$(@))\n" 78 printf "CONFIG_ROMBASE = 0x0;\nAUTO_XIP_ROM_BASE = 0x0;\n" > $(obj)/location.ld 79 $(CC) -nostdlib -nostartfiles -static -o $(obj)/romstage.elf -L$(obj) -T $(obj)/romstage/ldscript.ld $(romstage-objs) 80 $(OBJCOPY) -O binary $(obj)/romstage.elf $(obj)/romstage.bin 81 printf "CONFIG_ROMBASE = 0x" > $(obj)/location.ld 82 $(CBFSTOOL) $(obj)/coreboot.pre1 locate $(obj)/romstage.bin $(CONFIG_CBFS_PREFIX)/romstage $(CONFIG_XIP_ROM_SIZE) > $(obj)/location.txt 83 cat $(obj)/location.txt >> $(obj)/location.ld 84 printf ';\nAUTO_XIP_ROM_BASE = CONFIG_ROMBASE & ~(CONFIG_XIP_ROM_SIZE - 1);\n' >> $(obj)/location.ld 85 $(CC) -nostdlib -nostartfiles -static -o $(obj)/romstage.elf -L$(obj) -T $(obj)/romstage/ldscript.ld $(romstage-objs) 86 $(NM) -n $(obj)/romstage.elf | sort > $(obj)/romstage.map 87 $(OBJCOPY) --only-keep-debug $(obj)/romstage.elf $(obj)/romstage.debug 88 $(OBJCOPY) --strip-debug $(obj)/romstage.elf 89 $(OBJCOPY) --add-gnu-debuglink=$(obj)/romstage.debug $(obj)/romstage.elf 90 $(OBJCOPY) -O binary $(obj)/romstage.elf $@
We can see how the romstage is built. At the line 82, the cbfstool locates a space in the image, using $(CONFIG_XIP_ROM_SIZE) as parameter ALIGN. In my building, the $(CONFIG_XIP_ROM_SIZE) is 0x80000. So the romstage should align at 0x80000, correct? But my final image is: Name offset Type size cmos_layout.bin 0x0 unknown 1775 pci1002,9615.rom 0x740 optionrom 60416 fallback/romstage 0xf380 stage 99192 fallback/coreboot_ram 0x27740 stage 57274 fallback/payload 0x35740 payload 38442 (empty) 0x3edc0 null 789990
Obviously the romstage is not aligned to 0x80000. So I take a look at the file Util/cbfstool/common.c uint32_t cbfs_find_location(const char *romfile, uint32_t filesize, 440 const char *filename, uint32_t alignment) 441 { 442 void *rom = loadrom(romfile); 443 int filename_size = strlen(filename); 444 445 int headersize = 446 sizeof(struct cbfs_file) + ALIGN(filename_size + 1, 447 16) + sizeof(struct cbfs_stage); 448 int totalsize = headersize + filesize; 449 450 uint32_t current = phys_start; 451 while (current < phys_end) { 452 if (!cbfs_file_header(current)) { 453 current += align; 454 continue; 455 } 456 struct cbfs_file *thisfile = 457 (struct cbfs_file *)phys_to_virt(current); 458 459 uint32_t top = 460 current + ntohl(thisfile->len) + ntohl(thisfile->offset); 461 if (((ntohl(thisfile->type) == 0x0) 462 || (ntohl(thisfile->type) == 0xffffffff)) 463 && (ntohl(thisfile->len) + ntohl(thisfile->offset) >= 464 totalsize)) { 465 if (in_segment 466 (current + headersize, filesize, alignment)) 467 return current + headersize; 468 if ((ALIGN(current, alignment) + filesize < top) 469 && (ALIGN(current, alignment) - headersize > 470 current) 471 && in_segment(ALIGN(current, alignment), filesize, 472 alignment)) 473 return ALIGN(current, alignment); 474 if ((ALIGN(current, alignment) + alignment + filesize < 475 top) 476 && (ALIGN(current, alignment) + alignment - 477 headersize > current) 478 && in_segment(ALIGN(current, alignment) + alignment, 479 filesize, alignment)) 480 return ALIGN(current, alignment) + alignment; 481 } 482 current = 483 ALIGN(current + ntohl(thisfile->len) + 484 ntohl(thisfile->offset), align); 485 } 486 return 0; 487 }
The code between 465 and 467 is confusing. Why doesn't it align to alignment? What if we delete these 3 lines?
Where am I wrong in the whole analysis?
Zheng
Am 23.02.2011 09:45, schrieb Bao, Zheng:
The code between 465 and 467 is confusing. Why doesn't it align to alignment? What if we delete these 3 lines?
The kind of alignment that cbfstool seeks is, for alignment "ALIGN", look for an address so that the file data is inside a block sized ALIGN, aligned to ALIGN granularity, with enough space before it so that the header fits.
So if you look for a suitable location for a file of 99192 bytes, that has to be inside a 0x80000 block, aligned to 0x80000, 0xf380 is okay:
The block in question starts at 0x0 and ends at 0x7ffff. The file starts at 0xf380, and ends at 0x276f8.
Where am I wrong in the whole analysis?
We have a less strict requirement than the one you assumed (that the file must start at the beginning of such a block)
Regards, Patrick