Hi guys
I was playing with CBFS and I found an strange behavior. There are actually 4 types of files in a CBFS rom : stage, payload, option rom and NULL. The latest is used when we don't care of the component type.
I guess if we want to embed a logo, payload specific data or other stuffs, we must use this NULL type. The problem is that the free space in the rom also has a NULL type. In the fs.c file, rom_alloc function, the code searches for a cbfs_file with type == CBFS_COMPONENT_NULL, and if it is large enough, it will store the file in it. Otherwise, it continues until finding a large enough NULL type file.
If you want to add more than one NULL type file, it will work as long as you insert them from the smallest to the largest. Otherwise the NULL type file you are adding will overwrite an existing one.
Example to reproduce the behavior : - create a dummy bootblock dd if=/dev/urandom of=bootblock.rom bs=64k count=1 - create a test cbfs archive ./cbfstool test.rom create 524288 65536 ./bootblock.rom - create 2 dummy files (64 and 128 KB) dd if=/dev/urandom of=dummy64K bs=64k count=1 dd if=/dev/urandom of=dummy128K bs=64k count=2
Now, if I add my files from the smallest to the largest :
./cbfstool test.rom add dummy64K dummy64K free ./cbfstool test.rom add dummy128K dummy128K free ./cbfstool test.rom print test.rom: 512 kB, bootblocksize 65536, romsize 524288, offset 0x0 Alignment: 16 bytes
Name Offset Type Size dummy64K 0x0 free 65536 dummy128K 0x10030 free 131072 0x30060 free 261976
Everything works fine. But if I had the 128K file first, then the 64K file :
./cbfstool test.rom add dummy128K dummy128K free ./cbfstool test.rom add dummy64K dummy64K free ./cbfstool test.rom print test.rom: 512 kB, bootblocksize 65536, romsize 524288, offset 0x0 Alignment: 16 bytes
Name Offset Type Size dummy64K 0x0 free 65536 0x10030 free 65496 0x20030 free 327560
I think it is required to make the distinction between a user or custom type for embedded data, and the free space.
What do you think ?
Regards, Thomas
Bonus question : shouldn't the cbfs code (to parse, find a file...) be added to the libpayload ?