cbfs: hardcode file alignment

Assume that it's 64 byte.

Change-Id: I168facd92f64c2cf99c26c350c60317807a4aed4
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/10919
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Patrick Georgi 2015-07-14 22:28:27 +02:00 committed by Patrick Georgi
parent 45acb34ffc
commit 4d3e4c421e
7 changed files with 16 additions and 28 deletions

View File

@ -53,13 +53,11 @@ int cbfs_boot_region_properties(struct cbfs_props *props)
header.magic = ntohl(header.magic); header.magic = ntohl(header.magic);
header.romsize = ntohl(header.romsize); header.romsize = ntohl(header.romsize);
header.bootblocksize = ntohl(header.bootblocksize); header.bootblocksize = ntohl(header.bootblocksize);
header.align = ntohl(header.align);
header.offset = ntohl(header.offset); header.offset = ntohl(header.offset);
if (header.magic != CBFS_HEADER_MAGIC) if (header.magic != CBFS_HEADER_MAGIC)
return -1; return -1;
props->align = header.align;
props->offset = header.offset; props->offset = header.offset;
if (CONFIG_ROM_SIZE != header.romsize) if (CONFIG_ROM_SIZE != header.romsize)
props->size = CONFIG_ROM_SIZE; props->size = CONFIG_ROM_SIZE;
@ -67,7 +65,7 @@ int cbfs_boot_region_properties(struct cbfs_props *props)
props->size = header.romsize; props->size = header.romsize;
props->size -= props->offset; props->size -= props->offset;
props->size -= header.bootblocksize; props->size -= header.bootblocksize;
props->size = ALIGN_DOWN(props->size, props->align); props->size = ALIGN_DOWN(props->size, 64);
printk(BIOS_DEBUG, "CBFS @ %zx size %zx\n", props->offset, props->size); printk(BIOS_DEBUG, "CBFS @ %zx size %zx\n", props->offset, props->size);

View File

@ -7,6 +7,9 @@
#define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4) #define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4)
#define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4) #define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4)
/* we use this instead of CBFS_HEADER_ALIGN because the latter is retired. */
#define CBFS_ALIGNMENT 64
#define CBFS_FILE_MAGIC 0 #define CBFS_FILE_MAGIC 0
#define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) #define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8)
#define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) #define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4)
@ -74,13 +77,9 @@ tryharder:
mov CBFS_FILE_LEN(%ebx), %edi mov CBFS_FILE_LEN(%ebx), %edi
bswap %edi bswap %edi
add %edi, %ecx add %edi, %ecx
mov CBFS_HEADER_PTR, %edi /* round by 64 bytes */
mov CBFS_HEADER_ALIGN(%edi), %edi add $(CBFS_ALIGNMENT - 1), %ecx
bswap %edi and $~(CBFS_ALIGNMENT - 1), %ecx
sub $1, %edi
add %edi, %ecx
not %edi
and %edi, %ecx
/* if oldaddr >= addr, leave */ /* if oldaddr >= addr, leave */
cmp %ebx, %ecx cmp %ebx, %ecx
@ -106,11 +105,8 @@ out:
searchfile: searchfile:
/* if filemagic isn't found, move forward cbfs_header->align bytes */ /* if filemagic isn't found, move forward 64 bytes */
mov CBFS_HEADER_PTR, %edi add $CBFS_ALIGNMENT, %ebx
mov CBFS_HEADER_ALIGN(%edi), %edi
bswap %edi
add %edi, %ebx
jmp check_for_exit jmp check_for_exit
filemagic: filemagic:

View File

@ -66,13 +66,10 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs,
struct cbfsd { struct cbfsd {
const struct region_device *rdev; const struct region_device *rdev;
size_t align;
}; };
/* The cbfs_props struct describes the properties associated with a CBFS. */ /* The cbfs_props struct describes the properties associated with a CBFS. */
struct cbfs_props { struct cbfs_props {
/* Each file is aligned. */
size_t align;
/* CBFS starts at the following offset within the boot region. */ /* CBFS starts at the following offset within the boot region. */
size_t offset; size_t offset;
/* CBFS size. */ /* CBFS size. */

View File

@ -95,12 +95,15 @@ struct cbfs_header {
uint32_t version; uint32_t version;
uint32_t romsize; uint32_t romsize;
uint32_t bootblocksize; uint32_t bootblocksize;
uint32_t align; uint32_t align; /* fixed to 64 bytes */
uint32_t offset; uint32_t offset;
uint32_t architecture; uint32_t architecture;
uint32_t pad[1]; uint32_t pad[1];
} __attribute__((packed)); } __attribute__((packed));
/* this used to be flexible, but wasn't ever set to something different. */
#define CBFS_ALIGNMENT 64
/* "Unknown" refers to CBFS headers version 1, /* "Unknown" refers to CBFS headers version 1,
* before the architecture was defined (i.e., x86 only). * before the architecture was defined (i.e., x86 only).
*/ */

View File

@ -57,7 +57,6 @@ int cbfs_boot_locate(struct region_device *fh, const char *name, uint32_t *type)
return -1; return -1;
cbfs.rdev = &rdev; cbfs.rdev = &rdev;
cbfs.align = props.align;
return cbfs_locate(fh, &cbfs, name, type); return cbfs_locate(fh, &cbfs, name, type);
} }
@ -83,11 +82,9 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs,
{ {
size_t offset; size_t offset;
const struct region_device *rd; const struct region_device *rd;
size_t align;
offset = 0; offset = 0;
rd = cbfs->rdev; rd = cbfs->rdev;
align = cbfs->align;
LOG("Locating '%s'\n", name); LOG("Locating '%s'\n", name);
@ -107,7 +104,7 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs,
if (memcmp(file.magic, CBFS_FILE_MAGIC, sizeof(file.magic))) { if (memcmp(file.magic, CBFS_FILE_MAGIC, sizeof(file.magic))) {
offset++; offset++;
offset = ALIGN_UP(offset, align); offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
continue; continue;
} }
@ -127,14 +124,14 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs,
if (!name_match) { if (!name_match) {
DEBUG(" Unmatched '%s' at %zx\n", fname, offset); DEBUG(" Unmatched '%s' at %zx\n", fname, offset);
offset += file.offset + file.len; offset += file.offset + file.len;
offset = ALIGN_UP(offset, align); offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
continue; continue;
} }
if (type != NULL && *type != file.type) { if (type != NULL && *type != file.type) {
DEBUG(" Unmatched type %x at %zx\n", file.type, offset); DEBUG(" Unmatched type %x at %zx\n", file.type, offset);
offset += file.offset + file.len; offset += file.offset + file.len;
offset = ALIGN_UP(offset, align); offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
continue; continue;
} }

View File

@ -49,13 +49,11 @@ int __attribute__((weak)) cbfs_boot_region_properties(struct cbfs_props *props)
header.magic = ntohl(header.magic); header.magic = ntohl(header.magic);
header.romsize = ntohl(header.romsize); header.romsize = ntohl(header.romsize);
header.align = ntohl(header.align);
header.offset = ntohl(header.offset); header.offset = ntohl(header.offset);
if (header.magic != CBFS_HEADER_MAGIC) if (header.magic != CBFS_HEADER_MAGIC)
return -1; return -1;
props->align = header.align;
props->offset = header.offset; props->offset = header.offset;
props->size = header.romsize; props->size = header.romsize;
props->size -= props->offset; props->size -= props->offset;

View File

@ -173,7 +173,6 @@ static int vboot_locate_by_multi_cbfs(const struct region_device *fw_main,
return -1; return -1;
cbfs.rdev = &rdev; cbfs.rdev = &rdev;
cbfs.align = props.align;
return cbfs_locate(asset_rdev(asset), &cbfs, asset_name(asset), NULL); return cbfs_locate(asset_rdev(asset), &cbfs, asset_name(asset), NULL);
} }