Merge 4.16
Change-Id: I11db70a8e25a6656c5ec640a703e7b06d5a3672e
This commit is contained in:
2
util/cbfstool/.gitignore
vendored
2
util/cbfstool/.gitignore
vendored
@@ -1,5 +1,7 @@
|
||||
cbfs-compression-tool
|
||||
cbfstool
|
||||
cse_fpt
|
||||
cse_serger
|
||||
elogtool
|
||||
fmaptool
|
||||
ifittool
|
||||
|
@@ -134,10 +134,6 @@ TOOLCPPFLAGS += -I$(top)/src/vendorcode/intel/edk2/uefi_2.4/MdePkg/Include
|
||||
TOOLLDFLAGS ?=
|
||||
HOSTCFLAGS += -fms-extensions
|
||||
|
||||
ifneq ($(shell uname -o 2>/dev/null), FreeBSD)
|
||||
TOOLCPPFLAGS += -D_XOPEN_SOURCE=700 # strdup() from string.h
|
||||
endif
|
||||
|
||||
ifeq ($(shell uname -s | cut -c-7 2>/dev/null), MINGW32)
|
||||
TOOLCFLAGS += -mno-ms-bitfields
|
||||
endif
|
||||
|
@@ -80,9 +80,9 @@ static int fill_cbfs_stageheader(struct cbfs_file_attr_stageheader *stageheader,
|
||||
return -1;
|
||||
}
|
||||
|
||||
stageheader->loadaddr = htonll(loadaddr);
|
||||
stageheader->memlen = htonl(memsize);
|
||||
stageheader->entry_offset = htonl(entry - loadaddr);
|
||||
stageheader->loadaddr = htobe64(loadaddr);
|
||||
stageheader->memlen = htobe32(memsize);
|
||||
stageheader->entry_offset = htobe32(entry - loadaddr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ static struct typedesc_t filetypes[] unused = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
|
||||
#define CBFS_SUBHEADER(_p) ((void *) ((((uint8_t *) (_p)) + be32toh((_p)->offset))))
|
||||
|
||||
static inline size_t cbfs_file_attr_hash_size(enum vb2_hash_algorithm algo)
|
||||
{
|
||||
|
@@ -86,16 +86,15 @@ static int cbfs_fix_legacy_size(struct cbfs_image *image, char *hdr_loc)
|
||||
entry && cbfs_is_valid_entry(image, entry);
|
||||
entry = cbfs_find_next_entry(image, entry)) {
|
||||
/* Is the header guarded by a CBFS file entry? Then exit */
|
||||
if (((char *)entry) + ntohl(entry->offset) == hdr_loc) {
|
||||
if (((char *)entry) + be32toh(entry->offset) == hdr_loc)
|
||||
return 0;
|
||||
}
|
||||
last = entry;
|
||||
}
|
||||
if ((char *)first < (char *)hdr_loc &&
|
||||
(char *)entry > (char *)hdr_loc) {
|
||||
WARN("CBFS image was created with old cbfstool with size bug. "
|
||||
"Fixing size in last entry...\n");
|
||||
last->len = htonl(ntohl(last->len) - image->header.align);
|
||||
last->len = htobe32(be32toh(last->len) - image->header.align);
|
||||
DEBUG("Last entry has been changed from 0x%x to 0x%x.\n",
|
||||
cbfs_get_entry_addr(image, entry),
|
||||
cbfs_get_entry_addr(image,
|
||||
@@ -141,17 +140,17 @@ static int cbfs_file_get_compression_info(struct cbfs_file *entry,
|
||||
{
|
||||
unsigned int compression = CBFS_COMPRESS_NONE;
|
||||
if (decompressed_size)
|
||||
*decompressed_size = ntohl(entry->len);
|
||||
*decompressed_size = be32toh(entry->len);
|
||||
for (struct cbfs_file_attribute *attr = cbfs_file_first_attr(entry);
|
||||
attr != NULL;
|
||||
attr = cbfs_file_next_attr(entry, attr)) {
|
||||
if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_COMPRESSION) {
|
||||
if (be32toh(attr->tag) == CBFS_FILE_ATTR_TAG_COMPRESSION) {
|
||||
struct cbfs_file_attr_compression *ac =
|
||||
(struct cbfs_file_attr_compression *)attr;
|
||||
compression = ntohl(ac->compression);
|
||||
compression = be32toh(ac->compression);
|
||||
if (decompressed_size)
|
||||
*decompressed_size =
|
||||
ntohl(ac->decompressed_size);
|
||||
be32toh(ac->decompressed_size);
|
||||
}
|
||||
}
|
||||
return compression;
|
||||
@@ -165,11 +164,11 @@ static struct cbfs_file_attr_hash *cbfs_file_get_next_hash(
|
||||
attr = cbfs_file_first_attr(entry);
|
||||
if (attr == NULL)
|
||||
return NULL;
|
||||
if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_HASH)
|
||||
if (be32toh(attr->tag) == CBFS_FILE_ATTR_TAG_HASH)
|
||||
return (struct cbfs_file_attr_hash *)attr;
|
||||
}
|
||||
while ((attr = cbfs_file_next_attr(entry, attr)) != NULL) {
|
||||
if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_HASH)
|
||||
if (be32toh(attr->tag) == CBFS_FILE_ATTR_TAG_HASH)
|
||||
return (struct cbfs_file_attr_hash *)attr;
|
||||
};
|
||||
return NULL;
|
||||
@@ -375,12 +374,12 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
|
||||
src_entry = cbfs_find_next_entry(image, src_entry)) {
|
||||
size_t entry_size;
|
||||
|
||||
if ((src_entry->type == htonl(CBFS_TYPE_NULL)) ||
|
||||
(src_entry->type == htonl(CBFS_TYPE_CBFSHEADER)) ||
|
||||
(src_entry->type == htonl(CBFS_TYPE_DELETED)))
|
||||
if ((src_entry->type == htobe32(CBFS_TYPE_NULL)) ||
|
||||
(src_entry->type == htobe32(CBFS_TYPE_CBFSHEADER)) ||
|
||||
(src_entry->type == htobe32(CBFS_TYPE_DELETED)))
|
||||
continue;
|
||||
|
||||
entry_size = htonl(src_entry->len) + htonl(src_entry->offset);
|
||||
entry_size = htobe32(src_entry->len) + htobe32(src_entry->offset);
|
||||
memcpy(dst_entry, src_entry, entry_size);
|
||||
dst_entry = (struct cbfs_file *)(
|
||||
(uintptr_t)dst_entry + align_up(entry_size, align));
|
||||
@@ -473,8 +472,8 @@ int cbfs_truncate_space(struct buffer *region, uint32_t *size)
|
||||
* maximum size.
|
||||
*/
|
||||
if ((strlen(trailer->filename) != 0) &&
|
||||
(trailer->type != htonl(CBFS_TYPE_NULL)) &&
|
||||
(trailer->type != htonl(CBFS_TYPE_DELETED))) {
|
||||
(trailer->type != htobe32(CBFS_TYPE_NULL)) &&
|
||||
(trailer->type != htobe32(CBFS_TYPE_DELETED))) {
|
||||
/* nothing to truncate. Return de-facto CBFS size in case it
|
||||
* was already truncated. */
|
||||
*size = (uint8_t *)entry - (uint8_t *)buffer_get(region);
|
||||
@@ -488,12 +487,12 @@ int cbfs_truncate_space(struct buffer *region, uint32_t *size)
|
||||
|
||||
static size_t cbfs_file_entry_metadata_size(const struct cbfs_file *f)
|
||||
{
|
||||
return ntohl(f->offset);
|
||||
return be32toh(f->offset);
|
||||
}
|
||||
|
||||
static size_t cbfs_file_entry_data_size(const struct cbfs_file *f)
|
||||
{
|
||||
return ntohl(f->len);
|
||||
return be32toh(f->len);
|
||||
}
|
||||
|
||||
static size_t cbfs_file_entry_size(const struct cbfs_file *f)
|
||||
@@ -525,11 +524,9 @@ int cbfs_compact_instance(struct cbfs_image *image)
|
||||
size_t cur_size;
|
||||
size_t empty_metadata_size;
|
||||
size_t spill_size;
|
||||
uint32_t type = htonl(cur->type);
|
||||
|
||||
/* Current entry is empty. Kepp track of it. */
|
||||
if ((type == htonl(CBFS_TYPE_NULL)) ||
|
||||
(type == htonl(CBFS_TYPE_DELETED))) {
|
||||
if (cur->type == CBFS_TYPE_NULL || cur->type == CBFS_TYPE_DELETED) {
|
||||
prev = cur;
|
||||
continue;
|
||||
}
|
||||
@@ -631,7 +628,7 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
|
||||
uint32_t len, header_offset;
|
||||
uint32_t align = image->has_header ? image->header.align :
|
||||
CBFS_ALIGNMENT;
|
||||
uint32_t header_size = ntohl(header->offset);
|
||||
uint32_t header_size = be32toh(header->offset);
|
||||
|
||||
header_offset = content_offset - header_size;
|
||||
if (header_offset % align)
|
||||
@@ -660,8 +657,8 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
|
||||
* to file data. Move attributes forward so the end of the
|
||||
* attribute list still matches the end of the metadata.
|
||||
*/
|
||||
uint32_t offset = ntohl(entry->offset);
|
||||
uint32_t attrs = ntohl(entry->attributes_offset);
|
||||
uint32_t offset = be32toh(entry->offset);
|
||||
uint32_t attrs = be32toh(entry->attributes_offset);
|
||||
DEBUG("|..|header|content|... <use offset to create entry>\n");
|
||||
DEBUG("before: attr_offset=0x%x, offset=0x%x\n", attrs, offset);
|
||||
if (attrs == 0) {
|
||||
@@ -671,10 +668,10 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
|
||||
memmove(p + len, p, offset - attrs);
|
||||
memset(p, 0, len);
|
||||
attrs += len;
|
||||
entry->attributes_offset = htonl(attrs);
|
||||
entry->attributes_offset = htobe32(attrs);
|
||||
}
|
||||
offset += len;
|
||||
entry->offset = htonl(offset);
|
||||
entry->offset = htobe32(offset);
|
||||
DEBUG("after: attr_offset=0x%x, offset=0x%x\n", attrs, offset);
|
||||
}
|
||||
|
||||
@@ -684,14 +681,14 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
|
||||
image->buffer.data));
|
||||
assert((char*)CBFS_SUBHEADER(entry) - image->buffer.data ==
|
||||
(ptrdiff_t)content_offset);
|
||||
memcpy(CBFS_SUBHEADER(entry), data, ntohl(entry->len));
|
||||
memcpy(CBFS_SUBHEADER(entry), data, be32toh(entry->len));
|
||||
if (verbose > 1) cbfs_print_entry_info(image, entry, stderr);
|
||||
|
||||
// Align the length to a multiple of len_align
|
||||
if (len_align &&
|
||||
((ntohl(entry->offset) + ntohl(entry->len)) % len_align)) {
|
||||
size_t off = (ntohl(entry->offset) + ntohl(entry->len)) % len_align;
|
||||
entry->len = htonl(ntohl(entry->len) + len_align - off);
|
||||
((be32toh(entry->offset) + be32toh(entry->len)) % len_align)) {
|
||||
size_t off = (be32toh(entry->offset) + be32toh(entry->len)) % len_align;
|
||||
entry->len = htobe32(be32toh(entry->len) + len_align - off);
|
||||
}
|
||||
|
||||
// Process buffer AFTER entry.
|
||||
@@ -738,7 +735,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
|
||||
uint32_t addr, addr_next;
|
||||
struct cbfs_file *entry, *next;
|
||||
uint32_t need_size;
|
||||
uint32_t header_size = ntohl(header->offset);
|
||||
uint32_t header_size = be32toh(header->offset);
|
||||
|
||||
need_size = header_size + buffer->size;
|
||||
DEBUG("cbfs_add_entry('%s'@0x%x) => need_size = %u+%zu=%u\n",
|
||||
@@ -752,7 +749,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
|
||||
entry && cbfs_is_valid_entry(image, entry);
|
||||
entry = cbfs_find_next_entry(image, entry)) {
|
||||
|
||||
entry_type = ntohl(entry->type);
|
||||
entry_type = be32toh(entry->type);
|
||||
if (entry_type != CBFS_TYPE_NULL)
|
||||
continue;
|
||||
|
||||
@@ -975,7 +972,7 @@ static int cbfs_stage_make_elf(struct buffer *buff, uint32_t arch,
|
||||
struct cbfs_file_attr_stageheader *stage = NULL;
|
||||
for (struct cbfs_file_attribute *attr = cbfs_file_first_attr(entry);
|
||||
attr != NULL; attr = cbfs_file_next_attr(entry, attr)) {
|
||||
if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_STAGEHEADER) {
|
||||
if (be32toh(attr->tag) == CBFS_FILE_ATTR_TAG_STAGEHEADER) {
|
||||
stage = (struct cbfs_file_attr_stageheader *)attr;
|
||||
break;
|
||||
}
|
||||
@@ -1000,7 +997,7 @@ static int cbfs_stage_make_elf(struct buffer *buff, uint32_t arch,
|
||||
|
||||
/* Rmodule couldn't do anything with the data. Continue on with SELF. */
|
||||
|
||||
ehdr.e_entry = ntohll(stage->loadaddr) + ntohl(stage->entry_offset);
|
||||
ehdr.e_entry = be64toh(stage->loadaddr) + be32toh(stage->entry_offset);
|
||||
|
||||
ew = elf_writer_init(&ehdr);
|
||||
if (ew == NULL) {
|
||||
@@ -1011,9 +1008,9 @@ static int cbfs_stage_make_elf(struct buffer *buff, uint32_t arch,
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
shdr.sh_type = SHT_PROGBITS;
|
||||
shdr.sh_flags = SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR;
|
||||
shdr.sh_addr = ntohll(stage->loadaddr);
|
||||
shdr.sh_addr = be64toh(stage->loadaddr);
|
||||
shdr.sh_size = buffer_size(buff);
|
||||
empty_sz = ntohl(stage->memlen) - buffer_size(buff);
|
||||
empty_sz = be32toh(stage->memlen) - buffer_size(buff);
|
||||
|
||||
if (elf_writer_add_section(ew, &shdr, buff, ".program")) {
|
||||
ERROR("Unable to add ELF section: .program\n");
|
||||
@@ -1028,7 +1025,7 @@ static int cbfs_stage_make_elf(struct buffer *buff, uint32_t arch,
|
||||
memset(&shdr, 0, sizeof(shdr));
|
||||
shdr.sh_type = SHT_NOBITS;
|
||||
shdr.sh_flags = SHF_WRITE | SHF_ALLOC;
|
||||
shdr.sh_addr = ntohl(stage->loadaddr) + buffer_size(buff);
|
||||
shdr.sh_addr = be64toh(stage->loadaddr) + buffer_size(buff);
|
||||
shdr.sh_size = empty_sz;
|
||||
if (elf_writer_add_section(ew, &shdr, &b, ".empty")) {
|
||||
ERROR("Unable to add ELF section: .empty\n");
|
||||
@@ -1230,7 +1227,7 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int compressed_size = ntohl(entry->len);
|
||||
unsigned int compressed_size = be32toh(entry->len);
|
||||
unsigned int decompressed_size = 0;
|
||||
unsigned int compression = cbfs_file_get_compression_info(entry,
|
||||
&decompressed_size);
|
||||
@@ -1252,7 +1249,7 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
||||
|
||||
LOG("Found file %.30s at 0x%x, type %.12s, compressed %d, size %d\n",
|
||||
entry_name, cbfs_get_entry_addr(image, entry),
|
||||
get_cbfs_entry_type_name(ntohl(entry->type)), compressed_size,
|
||||
get_cbfs_entry_type_name(be32toh(entry->type)), compressed_size,
|
||||
decompressed_size);
|
||||
|
||||
buffer_init(&buffer, strdup("(cbfs_export_entry)"), NULL, 0);
|
||||
@@ -1274,7 +1271,7 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
||||
if (do_processing) {
|
||||
int (*make_elf)(struct buffer *, uint32_t,
|
||||
struct cbfs_file *) = NULL;
|
||||
switch (ntohl(entry->type)) {
|
||||
switch (be32toh(entry->type)) {
|
||||
case CBFS_TYPE_STAGE:
|
||||
make_elf = cbfs_stage_make_elf;
|
||||
break;
|
||||
@@ -1312,7 +1309,7 @@ int cbfs_remove_entry(struct cbfs_image *image, const char *name)
|
||||
}
|
||||
DEBUG("cbfs_remove_entry: Removed %s @ 0x%x\n",
|
||||
entry->filename, cbfs_get_entry_addr(image, entry));
|
||||
entry->type = htonl(CBFS_TYPE_DELETED);
|
||||
entry->type = htobe32(CBFS_TYPE_DELETED);
|
||||
cbfs_legacy_walk(image, cbfs_merge_empty_entry, NULL);
|
||||
return 0;
|
||||
}
|
||||
@@ -1340,7 +1337,7 @@ static int cbfs_print_stage_info(struct cbfs_file *entry, FILE* fp)
|
||||
struct cbfs_file_attr_stageheader *stage = NULL;
|
||||
for (struct cbfs_file_attribute *attr = cbfs_file_first_attr(entry);
|
||||
attr != NULL; attr = cbfs_file_next_attr(entry, attr)) {
|
||||
if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_STAGEHEADER) {
|
||||
if (be32toh(attr->tag) == CBFS_FILE_ATTR_TAG_STAGEHEADER) {
|
||||
stage = (struct cbfs_file_attr_stageheader *)attr;
|
||||
break;
|
||||
}
|
||||
@@ -1354,9 +1351,9 @@ static int cbfs_print_stage_info(struct cbfs_file *entry, FILE* fp)
|
||||
fprintf(fp,
|
||||
" entry: 0x%" PRIx64 ", load: 0x%" PRIx64 ", "
|
||||
"memlen: %d\n",
|
||||
ntohll(stage->loadaddr) + ntohl(stage->entry_offset),
|
||||
ntohll(stage->loadaddr),
|
||||
ntohl(stage->memlen));
|
||||
be64toh(stage->loadaddr) + be32toh(stage->entry_offset),
|
||||
be64toh(stage->loadaddr),
|
||||
be32toh(stage->memlen));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1434,16 +1431,16 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
|
||||
fprintf(fp, "%-30s 0x%-8x %-12s %8d %-4s\n",
|
||||
*name ? name : "(empty)",
|
||||
cbfs_get_entry_addr(image, entry),
|
||||
get_cbfs_entry_type_name(ntohl(entry->type)),
|
||||
ntohl(entry->len),
|
||||
get_cbfs_entry_type_name(be32toh(entry->type)),
|
||||
be32toh(entry->len),
|
||||
compression_name
|
||||
);
|
||||
else
|
||||
fprintf(fp, "%-30s 0x%-8x %-12s %8d %-4s (%d decompressed)\n",
|
||||
*name ? name : "(empty)",
|
||||
cbfs_get_entry_addr(image, entry),
|
||||
get_cbfs_entry_type_name(ntohl(entry->type)),
|
||||
ntohl(entry->len),
|
||||
get_cbfs_entry_type_name(be32toh(entry->type)),
|
||||
be32toh(entry->len),
|
||||
compression_name,
|
||||
decompressed_size
|
||||
);
|
||||
@@ -1461,7 +1458,7 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
|
||||
}
|
||||
char *hash_str = bintohex(attr->hash.raw, hash_len);
|
||||
int valid = vb2_hash_verify(CBFS_SUBHEADER(entry),
|
||||
ntohl(entry->len), &attr->hash) == VB2_SUCCESS;
|
||||
be32toh(entry->len), &attr->hash) == VB2_SUCCESS;
|
||||
const char *valid_str = valid ? "valid" : "invalid";
|
||||
|
||||
fprintf(fp, " hash %s:%s %s\n",
|
||||
@@ -1471,12 +1468,12 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
|
||||
}
|
||||
|
||||
DEBUG(" cbfs_file=0x%x, offset=0x%x, content_address=0x%x+0x%x\n",
|
||||
cbfs_get_entry_addr(image, entry), ntohl(entry->offset),
|
||||
cbfs_get_entry_addr(image, entry) + ntohl(entry->offset),
|
||||
ntohl(entry->len));
|
||||
cbfs_get_entry_addr(image, entry), be32toh(entry->offset),
|
||||
cbfs_get_entry_addr(image, entry) + be32toh(entry->offset),
|
||||
be32toh(entry->len));
|
||||
|
||||
/* note the components of the subheader may be in host order ... */
|
||||
switch (ntohl(entry->type)) {
|
||||
switch (be32toh(entry->type)) {
|
||||
case CBFS_TYPE_STAGE:
|
||||
cbfs_print_stage_info(entry, fp);
|
||||
break;
|
||||
@@ -1521,9 +1518,9 @@ static int cbfs_print_parseable_entry_info(struct cbfs_image *image,
|
||||
name = entry->filename;
|
||||
if (*name == '\0')
|
||||
name = "(empty)";
|
||||
type = get_cbfs_entry_type_name(ntohl(entry->type)),
|
||||
metadata_size = ntohl(entry->offset);
|
||||
data_size = ntohl(entry->len);
|
||||
type = get_cbfs_entry_type_name(be32toh(entry->type)),
|
||||
metadata_size = be32toh(entry->offset);
|
||||
data_size = be32toh(entry->len);
|
||||
offset = cbfs_get_entry_addr(image, entry);
|
||||
|
||||
fprintf(fp, "%s%s", name, sep);
|
||||
@@ -1549,7 +1546,7 @@ static int cbfs_print_parseable_entry_info(struct cbfs_image *image,
|
||||
continue;
|
||||
char *hash_str = bintohex(attr->hash.raw, hash_len);
|
||||
int valid = vb2_hash_verify(CBFS_SUBHEADER(entry),
|
||||
ntohl(entry->len), &attr->hash) == VB2_SUCCESS;
|
||||
be32toh(entry->len), &attr->hash) == VB2_SUCCESS;
|
||||
fprintf(fp, "%shash:%s:%s:%s", sep,
|
||||
vb2_get_hash_algorithm_name(attr->hash.algo),
|
||||
hash_str, valid ? "valid" : "invalid");
|
||||
@@ -1600,8 +1597,8 @@ int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
|
||||
/* Loop until non-empty entry is found, starting from the current entry.
|
||||
After the loop, next_addr points to the next non-empty entry. */
|
||||
next = entry;
|
||||
while (ntohl(next->type) == CBFS_TYPE_DELETED ||
|
||||
ntohl(next->type) == CBFS_TYPE_NULL) {
|
||||
while (be32toh(next->type) == CBFS_TYPE_DELETED ||
|
||||
be32toh(next->type) == CBFS_TYPE_NULL) {
|
||||
next = cbfs_find_next_entry(image, next);
|
||||
if (!next)
|
||||
break;
|
||||
@@ -1644,10 +1641,10 @@ int cbfs_legacy_walk(struct cbfs_image *image, cbfs_entry_callback callback,
|
||||
|
||||
static int cbfs_header_valid(struct cbfs_header *header)
|
||||
{
|
||||
if ((ntohl(header->magic) == CBFS_HEADER_MAGIC) &&
|
||||
((ntohl(header->version) == CBFS_HEADER_VERSION1) ||
|
||||
(ntohl(header->version) == CBFS_HEADER_VERSION2)) &&
|
||||
(ntohl(header->offset) < ntohl(header->romsize)))
|
||||
if ((be32toh(header->magic) == CBFS_HEADER_MAGIC) &&
|
||||
((be32toh(header->version) == CBFS_HEADER_VERSION1) ||
|
||||
(be32toh(header->version) == CBFS_HEADER_VERSION2)) &&
|
||||
(be32toh(header->offset) < be32toh(header->romsize)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1718,7 +1715,7 @@ struct cbfs_file *cbfs_find_next_entry(struct cbfs_image *image,
|
||||
uint32_t addr = cbfs_get_entry_addr(image, entry);
|
||||
int align = image->has_header ? image->header.align : CBFS_ALIGNMENT;
|
||||
assert(entry && cbfs_is_valid_entry(image, entry));
|
||||
addr += ntohl(entry->offset) + ntohl(entry->len);
|
||||
addr += be32toh(entry->offset) + be32toh(entry->len);
|
||||
addr = align_up(addr, align);
|
||||
return (struct cbfs_file *)(image->buffer.data + addr);
|
||||
}
|
||||
@@ -1760,11 +1757,11 @@ struct cbfs_file *cbfs_create_file_header(int type,
|
||||
struct cbfs_file *entry = malloc(CBFS_METADATA_MAX_SIZE);
|
||||
memset(entry, CBFS_CONTENT_DEFAULT_VALUE, CBFS_METADATA_MAX_SIZE);
|
||||
memcpy(entry->magic, CBFS_FILE_MAGIC, sizeof(entry->magic));
|
||||
entry->type = htonl(type);
|
||||
entry->len = htonl(len);
|
||||
entry->type = htobe32(type);
|
||||
entry->len = htobe32(len);
|
||||
entry->attributes_offset = 0;
|
||||
entry->offset = htonl(cbfs_calculate_file_header_size(name));
|
||||
memset(entry->filename, 0, ntohl(entry->offset) - sizeof(*entry));
|
||||
entry->offset = htobe32(cbfs_calculate_file_header_size(name));
|
||||
memset(entry->filename, 0, be32toh(entry->offset) - sizeof(*entry));
|
||||
strcpy(entry->filename, name);
|
||||
return entry;
|
||||
}
|
||||
@@ -1773,7 +1770,7 @@ int cbfs_create_empty_entry(struct cbfs_file *entry, int type,
|
||||
size_t len, const char *name)
|
||||
{
|
||||
struct cbfs_file *tmp = cbfs_create_file_header(type, len, name);
|
||||
memcpy(entry, tmp, ntohl(tmp->offset));
|
||||
memcpy(entry, tmp, be32toh(tmp->offset));
|
||||
free(tmp);
|
||||
memset(CBFS_SUBHEADER(entry), CBFS_CONTENT_DEFAULT_VALUE, len);
|
||||
return 0;
|
||||
@@ -1783,17 +1780,17 @@ struct cbfs_file_attribute *cbfs_file_first_attr(struct cbfs_file *file)
|
||||
{
|
||||
/* attributes_offset should be 0 when there is no attribute, but all
|
||||
* values that point into the cbfs_file header are invalid, too. */
|
||||
if (ntohl(file->attributes_offset) <= sizeof(*file))
|
||||
if (be32toh(file->attributes_offset) <= sizeof(*file))
|
||||
return NULL;
|
||||
|
||||
/* There needs to be enough space for the file header and one
|
||||
* attribute header for this to make sense. */
|
||||
if (ntohl(file->offset) <=
|
||||
if (be32toh(file->offset) <=
|
||||
sizeof(*file) + sizeof(struct cbfs_file_attribute))
|
||||
return NULL;
|
||||
|
||||
return (struct cbfs_file_attribute *)
|
||||
(((uint8_t *)file) + ntohl(file->attributes_offset));
|
||||
(((uint8_t *)file) + be32toh(file->attributes_offset));
|
||||
}
|
||||
|
||||
struct cbfs_file_attribute *cbfs_file_next_attr(struct cbfs_file *file,
|
||||
@@ -1804,17 +1801,17 @@ struct cbfs_file_attribute *cbfs_file_next_attr(struct cbfs_file *file,
|
||||
return NULL;
|
||||
|
||||
/* Is there enough space for another attribute? */
|
||||
if ((uint8_t *)attr + ntohl(attr->len) +
|
||||
if ((uint8_t *)attr + be32toh(attr->len) +
|
||||
sizeof(struct cbfs_file_attribute) >
|
||||
(uint8_t *)file + ntohl(file->offset))
|
||||
(uint8_t *)file + be32toh(file->offset))
|
||||
return NULL;
|
||||
|
||||
struct cbfs_file_attribute *next = (struct cbfs_file_attribute *)
|
||||
(((uint8_t *)attr) + ntohl(attr->len));
|
||||
(((uint8_t *)attr) + be32toh(attr->len));
|
||||
/* If any, "unused" attributes must come last. */
|
||||
if (ntohl(next->tag) == CBFS_FILE_ATTR_TAG_UNUSED)
|
||||
if (be32toh(next->tag) == CBFS_FILE_ATTR_TAG_UNUSED)
|
||||
return NULL;
|
||||
if (ntohl(next->tag) == CBFS_FILE_ATTR_TAG_UNUSED2)
|
||||
if (be32toh(next->tag) == CBFS_FILE_ATTR_TAG_UNUSED2)
|
||||
return NULL;
|
||||
|
||||
return next;
|
||||
@@ -1831,7 +1828,7 @@ struct cbfs_file_attribute *cbfs_add_file_attr(struct cbfs_file *header,
|
||||
attr = next;
|
||||
next = cbfs_file_next_attr(header, attr);
|
||||
} while (next != NULL);
|
||||
uint32_t header_size = ntohl(header->offset) + size;
|
||||
uint32_t header_size = be32toh(header->offset) + size;
|
||||
if (header_size > CBFS_METADATA_MAX_SIZE) {
|
||||
DEBUG("exceeding allocated space for cbfs_file headers");
|
||||
return NULL;
|
||||
@@ -1847,20 +1844,20 @@ struct cbfs_file_attribute *cbfs_add_file_attr(struct cbfs_file *header,
|
||||
header->attributes_offset = header->offset;
|
||||
attr = (struct cbfs_file_attribute *)
|
||||
(((uint8_t *)header) +
|
||||
ntohl(header->attributes_offset));
|
||||
be32toh(header->attributes_offset));
|
||||
} else {
|
||||
attr = (struct cbfs_file_attribute *)
|
||||
(((uint8_t *)attr) +
|
||||
ntohl(attr->len));
|
||||
be32toh(attr->len));
|
||||
}
|
||||
header->offset = htonl(header_size);
|
||||
header->offset = htobe32(header_size);
|
||||
/* Attributes are expected to be small (much smaller than a flash page)
|
||||
and not really meant to be overwritten in-place. To avoid surprising
|
||||
values in reserved fields of attribute structures, initialize them to
|
||||
0, not 0xff. */
|
||||
memset(attr, 0, size);
|
||||
attr->tag = htonl(tag);
|
||||
attr->len = htonl(size);
|
||||
attr->tag = htobe32(tag);
|
||||
attr->len = htobe32(size);
|
||||
return attr;
|
||||
}
|
||||
|
||||
@@ -1965,7 +1962,7 @@ int32_t cbfs_locate_entry(struct cbfs_image *image, size_t size,
|
||||
entry && cbfs_is_valid_entry(image, entry);
|
||||
entry = cbfs_find_next_entry(image, entry)) {
|
||||
|
||||
uint32_t type = ntohl(entry->type);
|
||||
uint32_t type = be32toh(entry->type);
|
||||
if (type != CBFS_TYPE_NULL)
|
||||
continue;
|
||||
|
||||
|
@@ -169,11 +169,11 @@ static struct mh_cache *get_mh_cache(void)
|
||||
if (cbfs_image_from_buffer(&cbfs, &buffer, param.headeroffset))
|
||||
goto no_metadata_hash;
|
||||
bootblock = cbfs_get_entry(&cbfs, "bootblock");
|
||||
if (!bootblock || ntohl(bootblock->type) != CBFS_TYPE_BOOTBLOCK)
|
||||
if (!bootblock || be32toh(bootblock->type) != CBFS_TYPE_BOOTBLOCK)
|
||||
goto no_metadata_hash;
|
||||
offset = (void *)bootblock + ntohl(bootblock->offset) -
|
||||
offset = (void *)bootblock + be32toh(bootblock->offset) -
|
||||
buffer_get(&cbfs.buffer);
|
||||
size = ntohl(bootblock->len);
|
||||
size = be32toh(bootblock->len);
|
||||
}
|
||||
|
||||
/* Find and validate the metadata hash anchor inside the bootblock and
|
||||
@@ -507,13 +507,9 @@ static int convert_region_offset(unsigned int offset, uint32_t *region_offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_cbfs_locate(uint32_t *cbfs_addr, size_t metadata_size,
|
||||
size_t data_size)
|
||||
static int do_cbfs_locate(uint32_t *cbfs_addr, size_t data_size)
|
||||
{
|
||||
if (!param.filename) {
|
||||
ERROR("You need to specify -f/--filename.\n");
|
||||
return 1;
|
||||
}
|
||||
uint32_t metadata_size = 0;
|
||||
|
||||
if (!param.name) {
|
||||
ERROR("You need to specify -n/--name.\n");
|
||||
@@ -529,17 +525,10 @@ static int do_cbfs_locate(uint32_t *cbfs_addr, size_t metadata_size,
|
||||
WARN("'%s' already in CBFS.\n", param.name);
|
||||
|
||||
if (!data_size) {
|
||||
struct buffer buffer;
|
||||
if (buffer_from_file(&buffer, param.filename) != 0) {
|
||||
ERROR("Cannot load %s.\n", param.filename);
|
||||
return 1;
|
||||
}
|
||||
data_size = buffer.size;
|
||||
buffer_delete(&buffer);
|
||||
ERROR("File '%s' is empty?\n", param.name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEBUG("File size is %zd (0x%zx)\n", data_size, data_size);
|
||||
|
||||
/* Compute required page size */
|
||||
if (param.force_pow2_pagesize) {
|
||||
param.pagesize = 1;
|
||||
@@ -559,6 +548,8 @@ static int do_cbfs_locate(uint32_t *cbfs_addr, size_t metadata_size,
|
||||
}
|
||||
if (param.precompression || param.compression != CBFS_COMPRESS_NONE)
|
||||
metadata_size += sizeof(struct cbfs_file_attr_compression);
|
||||
if (param.type == CBFS_TYPE_STAGE)
|
||||
metadata_size += sizeof(struct cbfs_file_attr_stageheader);
|
||||
|
||||
/* Take care of the hash attribute if it is used */
|
||||
if (param.hash != VB2_HASH_INVALID)
|
||||
@@ -568,8 +559,8 @@ static int do_cbfs_locate(uint32_t *cbfs_addr, size_t metadata_size,
|
||||
param.alignment, metadata_size);
|
||||
|
||||
if (address < 0) {
|
||||
ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n",
|
||||
param.name, param.pagesize, param.alignment);
|
||||
ERROR("'%s'(%u + %zu) can't fit in CBFS for page-size %#x, align %#x.\n",
|
||||
param.name, metadata_size, data_size, param.pagesize, param.alignment);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -673,7 +664,7 @@ static int update_master_header_loc_topswap(struct cbfs_image *image,
|
||||
* Check if the existing topswap boundary matches with
|
||||
* the one provided.
|
||||
*/
|
||||
if (param.topswap_size != ntohl(entry->len)/2) {
|
||||
if (param.topswap_size != be32toh(entry->len)/2) {
|
||||
ERROR("Top swap boundary does not match\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -710,16 +701,16 @@ static int cbfs_add_master_header(void)
|
||||
return 1;
|
||||
|
||||
struct cbfs_header *h = (struct cbfs_header *)buffer.data;
|
||||
h->magic = htonl(CBFS_HEADER_MAGIC);
|
||||
h->version = htonl(CBFS_HEADER_VERSION);
|
||||
h->magic = htobe32(CBFS_HEADER_MAGIC);
|
||||
h->version = htobe32(CBFS_HEADER_VERSION);
|
||||
/* The 4 bytes are left out for two reasons:
|
||||
* 1. the cbfs master header pointer resides there
|
||||
* 2. some cbfs implementations assume that an image that resides
|
||||
* below 4GB has a bootblock and get confused when the end of the
|
||||
* image is at 4GB == 0.
|
||||
*/
|
||||
h->bootblocksize = htonl(4);
|
||||
h->align = htonl(CBFS_ALIGNMENT);
|
||||
h->bootblocksize = htobe32(4);
|
||||
h->align = htobe32(CBFS_ALIGNMENT);
|
||||
/* The offset and romsize fields within the master header are absolute
|
||||
* values within the boot media. As such, romsize needs to relfect
|
||||
* the end 'offset' for a CBFS. To achieve that the current buffer
|
||||
@@ -729,9 +720,9 @@ static int cbfs_add_master_header(void)
|
||||
offset = buffer_get(param.image_region) -
|
||||
buffer_get_original_backing(param.image_region);
|
||||
size = buffer_size(param.image_region);
|
||||
h->romsize = htonl(size + offset);
|
||||
h->offset = htonl(offset);
|
||||
h->architecture = htonl(CBFS_ARCHITECTURE_UNKNOWN);
|
||||
h->romsize = htobe32(size + offset);
|
||||
h->offset = htobe32(offset);
|
||||
h->architecture = htobe32(CBFS_ARCHITECTURE_UNKNOWN);
|
||||
|
||||
/* Never add a hash attribute to the master header. */
|
||||
header = cbfs_create_file_header(CBFS_TYPE_CBFSHEADER,
|
||||
@@ -812,18 +803,39 @@ static int add_topswap_bootblock(struct buffer *buffer, uint32_t *offset)
|
||||
|
||||
static int cbfs_add_component(const char *filename,
|
||||
const char *name,
|
||||
uint32_t type,
|
||||
uint32_t headeroffset,
|
||||
convert_buffer_t convert)
|
||||
{
|
||||
size_t len_align = 0;
|
||||
/*
|
||||
* The steps used to determine the final placement offset in CBFS, in order:
|
||||
*
|
||||
* 1. If --base-address was passed, that value is used. If it was passed in the host
|
||||
* address space, convert it to flash address space. (After that, |*offset| is always
|
||||
* in the flash address space.)
|
||||
*
|
||||
* 2. The convert() function may write a location back to |offset|, usually by calling
|
||||
* do_cbfs_locate(). In this case, it needs to ensure that the location found can fit
|
||||
* the CBFS file in its final form (after any compression and conversion).
|
||||
*
|
||||
* 3. If --align was passed and the offset is still undecided at this point,
|
||||
* do_cbfs_locate() is called to find an appropriately aligned location.
|
||||
*
|
||||
* 4. If |offset| is still 0 at the end, cbfs_add_entry() will find the first available
|
||||
* location that fits.
|
||||
*/
|
||||
uint32_t offset = param.baseaddress_assigned ? param.baseaddress : 0;
|
||||
size_t len_align = 0;
|
||||
|
||||
if (param.alignment && param.baseaddress_assigned) {
|
||||
ERROR("Cannot specify both alignment and base address\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (param.stage_xip && param.compression != CBFS_COMPRESS_NONE) {
|
||||
ERROR("Cannot specify compression for XIP.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
ERROR("You need to specify -f/--filename.\n");
|
||||
return 1;
|
||||
@@ -834,7 +846,7 @@ static int cbfs_add_component(const char *filename,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (type == 0) {
|
||||
if (param.type == 0) {
|
||||
ERROR("You need to specify a valid -t/--type.\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -855,12 +867,12 @@ static int cbfs_add_component(const char *filename,
|
||||
}
|
||||
|
||||
struct cbfs_file *header =
|
||||
cbfs_create_file_header(type, buffer.size, name);
|
||||
cbfs_create_file_header(param.type, buffer.size, name);
|
||||
|
||||
/* Bootblock and CBFS header should never have file hashes. When adding
|
||||
the bootblock it is important that we *don't* look up the metadata
|
||||
hash yet (before it is added) or we'll cache an outdated result. */
|
||||
if (type != CBFS_TYPE_BOOTBLOCK && type != CBFS_TYPE_CBFSHEADER) {
|
||||
if (param.type != CBFS_TYPE_BOOTBLOCK && param.type != CBFS_TYPE_CBFSHEADER) {
|
||||
enum vb2_hash_algorithm mh_algo = get_mh_cache()->cbfs_hash.algo;
|
||||
if (mh_algo != VB2_HASH_INVALID && param.hash != mh_algo) {
|
||||
if (param.hash == VB2_HASH_INVALID) {
|
||||
@@ -874,25 +886,29 @@ static int cbfs_add_component(const char *filename,
|
||||
}
|
||||
}
|
||||
|
||||
/* This needs to run after potentially updating param.hash above. */
|
||||
if (param.alignment)
|
||||
if (do_cbfs_locate(&offset, 0, 0))
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* Check if Intel CPU topswap is specified this will require a
|
||||
* second bootblock to be added.
|
||||
*/
|
||||
if (type == CBFS_TYPE_BOOTBLOCK && param.topswap_size)
|
||||
if (param.type == CBFS_TYPE_BOOTBLOCK && param.topswap_size)
|
||||
if (add_topswap_bootblock(&buffer, &offset))
|
||||
goto error;
|
||||
|
||||
/* With --base-address we allow host space addresses -- if so, convert it here. */
|
||||
if (IS_HOST_SPACE_ADDRESS(offset))
|
||||
offset = convert_addr_space(param.image_region, offset);
|
||||
|
||||
if (convert && convert(&buffer, &offset, header) != 0) {
|
||||
ERROR("Failed to parse file '%s'.\n", filename);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* This needs to run after convert(). */
|
||||
/* This needs to run after convert() to take compression into account. */
|
||||
if (!offset && param.alignment)
|
||||
if (do_cbfs_locate(&offset, buffer_size(&buffer)))
|
||||
goto error;
|
||||
|
||||
/* This needs to run after convert() to hash the actual final file data. */
|
||||
if (param.hash != VB2_HASH_INVALID &&
|
||||
cbfs_add_file_hash(header, &buffer, param.hash) == -1) {
|
||||
ERROR("couldn't add hash for '%s'\n", name);
|
||||
@@ -909,7 +925,7 @@ static int cbfs_add_component(const char *filename,
|
||||
sizeof(struct cbfs_file_attr_position));
|
||||
if (attrs == NULL)
|
||||
goto error;
|
||||
attrs->position = htonl(offset);
|
||||
attrs->position = htobe32(offset);
|
||||
}
|
||||
/* Add alignment attribute if used */
|
||||
if (param.alignment) {
|
||||
@@ -920,7 +936,7 @@ static int cbfs_add_component(const char *filename,
|
||||
sizeof(struct cbfs_file_attr_align));
|
||||
if (attrs == NULL)
|
||||
goto error;
|
||||
attrs->alignment = htonl(param.alignment);
|
||||
attrs->alignment = htobe32(param.alignment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,9 +964,6 @@ static int cbfs_add_component(const char *filename,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (IS_HOST_SPACE_ADDRESS(offset))
|
||||
offset = convert_addr_space(param.image_region, offset);
|
||||
|
||||
if (cbfs_add_entry(&image, &buffer, offset, header, len_align) != 0) {
|
||||
ERROR("Failed to add '%s' into ROM image.\n", filename);
|
||||
goto error;
|
||||
@@ -1011,15 +1024,15 @@ static int cbfstool_convert_raw(struct buffer *buffer,
|
||||
free(compressed);
|
||||
return -1;
|
||||
}
|
||||
attrs->compression = htonl(param.compression);
|
||||
attrs->decompressed_size = htonl(decompressed_size);
|
||||
attrs->compression = htobe32(param.compression);
|
||||
attrs->decompressed_size = htobe32(decompressed_size);
|
||||
|
||||
free(buffer->data);
|
||||
buffer->data = compressed;
|
||||
buffer->size = compressed_size;
|
||||
|
||||
out:
|
||||
header->len = htonl(buffer->size);
|
||||
header->len = htobe32(buffer->size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1028,45 +1041,44 @@ static int cbfstool_convert_fsp(struct buffer *buffer,
|
||||
{
|
||||
uint32_t address;
|
||||
struct buffer fsp;
|
||||
int do_relocation = 1;
|
||||
|
||||
address = *offset;
|
||||
|
||||
/*
|
||||
* If the FSP component is xip, then ensure that the address is a memory
|
||||
* mapped one.
|
||||
* If the FSP component is not xip, then use param.baseaddress that is
|
||||
* passed in by the caller.
|
||||
* There are 4 different cases here:
|
||||
*
|
||||
* 1. --xip and --base-address: we need to place the binary at the given base address
|
||||
* in the CBFS image and relocate it to that address. *offset was already filled in,
|
||||
* but we need to convert it to the host address space for relocation.
|
||||
*
|
||||
* 2. --xip but no --base-address: we implicitly force a 4K minimum alignment so that
|
||||
* relocation can occur. Call do_cbfs_locate() here to find an appropriate *offset.
|
||||
* This also needs to be converted to the host address space for relocation.
|
||||
*
|
||||
* 3. No --xip but a --base-address: special case where --base-address does not have its
|
||||
* normal meaning, instead we use it as the relocation target address. We explicitly
|
||||
* reset *offset to 0 so that the file will be placed wherever it fits in CBFS.
|
||||
*
|
||||
* 4. No --xip and no --base-address: this means that the FSP was pre-linked and should
|
||||
* not be relocated. Just chain directly to convert_raw() for compression.
|
||||
*/
|
||||
|
||||
if (param.stage_xip) {
|
||||
if (!IS_HOST_SPACE_ADDRESS(address))
|
||||
address = convert_addr_space(param.image_region, address);
|
||||
if (!param.baseaddress_assigned) {
|
||||
param.alignment = 4*1024;
|
||||
if (do_cbfs_locate(offset, buffer_size(buffer)))
|
||||
return -1;
|
||||
}
|
||||
assert(!IS_HOST_SPACE_ADDRESS(*offset));
|
||||
address = convert_addr_space(param.image_region, *offset);
|
||||
} else {
|
||||
if (param.baseaddress_assigned == 0) {
|
||||
INFO("Honoring pre-linked FSP module.\n");
|
||||
do_relocation = 0;
|
||||
INFO("Honoring pre-linked FSP module, no relocation.\n");
|
||||
return cbfstool_convert_raw(buffer, offset, header);
|
||||
} else {
|
||||
address = param.baseaddress;
|
||||
/*
|
||||
* *offset should either be 0 or the value returned by
|
||||
* do_cbfs_locate. do_cbfs_locate is called only when param.baseaddress
|
||||
* is not provided by user. Thus, set *offset to 0 if user provides
|
||||
* a baseaddress i.e. params.baseaddress_assigned is set. The only
|
||||
* requirement in this case is that the binary should be relocated to
|
||||
* the base address that is requested. There is no requirement on where
|
||||
* the file ends up in the cbfs.
|
||||
*/
|
||||
*offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing left to do if relocation is not being attempted. Just add
|
||||
* the file.
|
||||
*/
|
||||
if (!do_relocation)
|
||||
return cbfstool_convert_raw(buffer, offset, header);
|
||||
|
||||
/* Create a copy of the buffer to attempt relocation. */
|
||||
if (buffer_create(&fsp, buffer_size(buffer), "fsp"))
|
||||
return -1;
|
||||
@@ -1100,15 +1112,12 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset,
|
||||
}
|
||||
|
||||
/*
|
||||
* If we already did a locate for alignment we need to locate again to
|
||||
* take the stage header into account. XIP stage parsing also needs the
|
||||
* location. But don't locate in other cases, because it will ignore
|
||||
* compression (not applied yet) and thus may cause us to refuse adding
|
||||
* stages that would actually fit once compressed.
|
||||
* We need a final location for XIP parsing, so we need to call do_cbfs_locate() early
|
||||
* here. That is okay because XIP stages may not be compressed, so their size cannot
|
||||
* change anymore at a later point.
|
||||
*/
|
||||
if ((param.alignment || param.stage_xip) &&
|
||||
do_cbfs_locate(offset, sizeof(struct cbfs_file_attr_stageheader),
|
||||
data_size)) {
|
||||
if (param.stage_xip &&
|
||||
do_cbfs_locate(offset, data_size)) {
|
||||
ERROR("Could not find location for stage.\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -1120,16 +1129,10 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset,
|
||||
return -1;
|
||||
|
||||
if (param.stage_xip) {
|
||||
/*
|
||||
* Ensure the address is a memory mapped one. This assumes
|
||||
* x86 semantics about the boot media being directly mapped
|
||||
* below 4GiB in the CPU address space.
|
||||
**/
|
||||
*offset = convert_addr_space(param.image_region, *offset);
|
||||
|
||||
ret = parse_elf_to_xip_stage(buffer, &output, *offset,
|
||||
param.ignore_section,
|
||||
stageheader);
|
||||
uint32_t host_space_address = convert_addr_space(param.image_region, *offset);
|
||||
assert(IS_HOST_SPACE_ADDRESS(host_space_address));
|
||||
ret = parse_elf_to_xip_stage(buffer, &output, host_space_address,
|
||||
param.ignore_section, stageheader);
|
||||
} else {
|
||||
ret = parse_elf_to_stage(buffer, &output, param.ignore_section,
|
||||
stageheader);
|
||||
@@ -1149,7 +1152,7 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset,
|
||||
/* Special care must be taken for LZ4-compressed stages that the BSS is
|
||||
large enough to provide scratch space for in-place decompression. */
|
||||
if (!param.precompression && param.compression == CBFS_COMPRESS_LZ4) {
|
||||
size_t memlen = ntohl(stageheader->memlen);
|
||||
size_t memlen = be32toh(stageheader->memlen);
|
||||
size_t compressed_size = buffer_size(&output);
|
||||
uint8_t *compare_buffer = malloc(memlen);
|
||||
uint8_t *start = compare_buffer + memlen - compressed_size;
|
||||
@@ -1193,7 +1196,7 @@ static int cbfstool_convert_mkpayload(struct buffer *buffer,
|
||||
if (ret != 0) {
|
||||
ret = parse_fit_to_payload(buffer, &output, param.compression);
|
||||
if (ret == 0)
|
||||
header->type = htonl(CBFS_TYPE_FIT);
|
||||
header->type = htobe32(CBFS_TYPE_FIT);
|
||||
}
|
||||
|
||||
/* If it's not an FIT, see if it's a UEFI FV */
|
||||
@@ -1215,7 +1218,7 @@ static int cbfstool_convert_mkpayload(struct buffer *buffer,
|
||||
buffer_delete(buffer);
|
||||
// Direct assign, no dupe.
|
||||
memcpy(buffer, &output, sizeof(*buffer));
|
||||
header->len = htonl(output.size);
|
||||
header->len = htobe32(output.size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1232,7 +1235,7 @@ static int cbfstool_convert_mkflatpayload(struct buffer *buffer,
|
||||
buffer_delete(buffer);
|
||||
// Direct assign, no dupe.
|
||||
memcpy(buffer, &output, sizeof(*buffer));
|
||||
header->len = htonl(output.size);
|
||||
header->len = htobe32(output.size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1240,50 +1243,41 @@ static int cbfs_add(void)
|
||||
{
|
||||
convert_buffer_t convert = cbfstool_convert_raw;
|
||||
|
||||
/* Set the alignment to 4KiB minimum for FSP blobs when no base address
|
||||
* is provided so that relocation can occur. */
|
||||
if (param.type == CBFS_TYPE_FSP) {
|
||||
if (!param.baseaddress_assigned)
|
||||
param.alignment = 4*1024;
|
||||
convert = cbfstool_convert_fsp;
|
||||
} else if (param.type == CBFS_TYPE_STAGE) {
|
||||
ERROR("stages can only be added with cbfstool add-stage\n");
|
||||
return 1;
|
||||
} else if (param.stage_xip) {
|
||||
ERROR("cbfs add supports xip only for FSP component type\n");
|
||||
ERROR("cbfstool add supports xip only for FSP component type\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return cbfs_add_component(param.filename,
|
||||
param.name,
|
||||
param.type,
|
||||
param.headeroffset,
|
||||
convert);
|
||||
}
|
||||
|
||||
static int cbfs_add_stage(void)
|
||||
{
|
||||
if (param.stage_xip) {
|
||||
if (param.baseaddress_assigned) {
|
||||
ERROR("Cannot specify base address for XIP.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (param.compression != CBFS_COMPRESS_NONE) {
|
||||
ERROR("Cannot specify compression for XIP.\n");
|
||||
return 1;
|
||||
}
|
||||
if (param.stage_xip && param.baseaddress_assigned) {
|
||||
ERROR("Cannot specify base address for XIP.\n");
|
||||
return 1;
|
||||
}
|
||||
param.type = CBFS_TYPE_STAGE;
|
||||
|
||||
return cbfs_add_component(param.filename,
|
||||
param.name,
|
||||
CBFS_TYPE_STAGE,
|
||||
param.headeroffset,
|
||||
cbfstool_convert_mkstage);
|
||||
}
|
||||
|
||||
static int cbfs_add_payload(void)
|
||||
{
|
||||
param.type = CBFS_TYPE_SELF;
|
||||
return cbfs_add_component(param.filename,
|
||||
param.name,
|
||||
CBFS_TYPE_SELF,
|
||||
param.headeroffset,
|
||||
cbfstool_convert_mkpayload);
|
||||
}
|
||||
@@ -1300,9 +1294,9 @@ static int cbfs_add_flat_binary(void)
|
||||
"-e/--entry-point.\n");
|
||||
return 1;
|
||||
}
|
||||
param.type = CBFS_TYPE_SELF;
|
||||
return cbfs_add_component(param.filename,
|
||||
param.name,
|
||||
CBFS_TYPE_SELF,
|
||||
param.headeroffset,
|
||||
cbfstool_convert_mkflatpayload);
|
||||
}
|
||||
@@ -1777,7 +1771,6 @@ static struct option long_options[] = {
|
||||
{"pow2page", no_argument, 0, 'Q' },
|
||||
{"ucode-region", required_argument, 0, 'q' },
|
||||
{"size", required_argument, 0, 's' },
|
||||
{"top-aligned", required_argument, 0, 'T' },
|
||||
{"type", required_argument, 0, 't' },
|
||||
{"verbose", no_argument, 0, 'v' },
|
||||
{"with-readonly", no_argument, 0, 'w' },
|
||||
@@ -1933,9 +1926,6 @@ static void usage(char *name)
|
||||
"Create a legacy ROM file with CBFS master header*\n"
|
||||
" create -M flashmap [-r list,of,regions,containing,cbfses] "
|
||||
"Create a new-style partitioned firmware image\n"
|
||||
" locate [-r image,regions] -f FILE -n NAME [-P page-size] \\\n"
|
||||
" [-a align] [-T] "
|
||||
"Find a place for a file of that size\n"
|
||||
" layout [-w] "
|
||||
"List mutable (or, with -w, readable) image regions\n"
|
||||
" print [-r image,regions] [-k] "
|
||||
@@ -1970,8 +1960,7 @@ static void usage(char *name)
|
||||
" specifying the location of this FMAP itself and a '%s'\n"
|
||||
" section describing the primary CBFS. It should also be noted\n"
|
||||
" that, when working with such images, the -F and -r switches\n"
|
||||
" default to '%s' for convenience, and both the -b switch to\n"
|
||||
" CBFS operations and the output of the locate action become\n"
|
||||
" default to '%s' for convenience, and the -b switch becomes\n"
|
||||
" relative to the selected CBFS region's lowest address.\n"
|
||||
" The one exception to this rule is the top-aligned address,\n"
|
||||
" which is always relative to the end of the entire image\n"
|
||||
|
@@ -15,17 +15,6 @@
|
||||
/* Utilities */
|
||||
int verbose = 0;
|
||||
|
||||
/* Small, OS/libc independent runtime check for endianness */
|
||||
int is_big_endian(void)
|
||||
{
|
||||
static const uint32_t inttest = 0x12345678;
|
||||
const uint8_t inttest_lsb = *(const uint8_t *)&inttest;
|
||||
if (inttest_lsb == 0x12) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static off_t get_file_size(FILE *f)
|
||||
{
|
||||
off_t fsize;
|
||||
|
@@ -10,11 +10,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <commonlib/bsd/cbfs_serialized.h>
|
||||
#include <commonlib/bsd/sysincludes.h>
|
||||
#include <commonlib/helpers.h>
|
||||
#include <console/console.h>
|
||||
|
||||
#include "swab.h"
|
||||
|
||||
/*
|
||||
* There are two address spaces that this tool deals with - SPI flash address space and host
|
||||
* address space. This macros checks if the address is greater than 2GiB under the assumption
|
||||
|
@@ -157,6 +157,7 @@ static void eventlog_print_type(const struct event_header *event)
|
||||
{ELOG_TYPE_CR50_NEED_RESET, "cr50 Reset Required"},
|
||||
{ELOG_TYPE_EC_DEVICE_EVENT, "EC Device"},
|
||||
{ELOG_TYPE_EXTENDED_EVENT, "Extended Event"},
|
||||
{ELOG_TYPE_CROS_DIAGNOSTICS, "Diagnostics Mode"},
|
||||
|
||||
{ELOG_TYPE_EOL, "End of log"},
|
||||
};
|
||||
@@ -533,6 +534,11 @@ static int eventlog_print_data(const struct event_header *event)
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
static const struct valstr cros_diagnostics_types[] = {
|
||||
{ELOG_CROS_LAUNCH_DIAGNOSTICS, "Launch Diagnostics"},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
switch (event->type) {
|
||||
case ELOG_TYPE_LOG_CLEAR: {
|
||||
const uint16_t *bytes = event_get_data(event);
|
||||
@@ -614,6 +620,10 @@ static int eventlog_print_data(const struct event_header *event)
|
||||
eventlog_printf("0x%X", ext_event->event_complement);
|
||||
break;
|
||||
}
|
||||
case ELOG_TYPE_CROS_DIAGNOSTICS: {
|
||||
const uint8_t *type = event_get_data(event);
|
||||
eventlog_printf("%s", val2str(*type, cros_diagnostics_types));
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause or GPL-2.0-only */
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -15,6 +13,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include <commonlib/bsd/sysincludes.h>
|
||||
|
||||
#include "fmap.h"
|
||||
#include "kv_pair.h"
|
||||
@@ -35,7 +34,7 @@ int fmap_size(const struct fmap *fmap)
|
||||
if (!fmap)
|
||||
return -1;
|
||||
|
||||
return sizeof(*fmap) + (fmap->nareas * sizeof(struct fmap_area));
|
||||
return sizeof(*fmap) + (le16toh(fmap->nareas) * sizeof(struct fmap_area));
|
||||
}
|
||||
|
||||
/* Make a best-effort assessment if the given fmap is real */
|
||||
@@ -47,8 +46,8 @@ static int is_valid_fmap(const struct fmap *fmap)
|
||||
if (fmap->ver_major != FMAP_VER_MAJOR)
|
||||
return 0;
|
||||
/* a basic consistency check: flash should be larger than fmap */
|
||||
if (fmap->size <
|
||||
sizeof(*fmap) + fmap->nareas * sizeof(struct fmap_area))
|
||||
if (le32toh(fmap->size) <
|
||||
sizeof(*fmap) + le16toh(fmap->nareas) * sizeof(struct fmap_area))
|
||||
return 0;
|
||||
|
||||
/* fmap-alikes along binary data tend to fail on having a valid,
|
||||
@@ -177,14 +176,14 @@ int fmap_print(const struct fmap *fmap)
|
||||
kv_pair_fmt(kv, "fmap_ver_major", "%d", fmap->ver_major);
|
||||
kv_pair_fmt(kv, "fmap_ver_minor","%d", fmap->ver_minor);
|
||||
kv_pair_fmt(kv, "fmap_base", "0x%016llx",
|
||||
(unsigned long long)fmap->base);
|
||||
kv_pair_fmt(kv, "fmap_size", "0x%04x", fmap->size);
|
||||
(unsigned long long)le64toh(fmap->base));
|
||||
kv_pair_fmt(kv, "fmap_size", "0x%04x", le32toh(fmap->size));
|
||||
kv_pair_fmt(kv, "fmap_name", "%s", fmap->name);
|
||||
kv_pair_fmt(kv, "fmap_nareas", "%d", fmap->nareas);
|
||||
kv_pair_fmt(kv, "fmap_nareas", "%d", le16toh(fmap->nareas));
|
||||
kv_pair_print(kv);
|
||||
kv_pair_free(kv);
|
||||
|
||||
for (i = 0; i < fmap->nareas; i++) {
|
||||
for (i = 0; i < le16toh(fmap->nareas); i++) {
|
||||
struct kv_pair *pair;
|
||||
uint16_t flags;
|
||||
char *str;
|
||||
@@ -194,16 +193,16 @@ int fmap_print(const struct fmap *fmap)
|
||||
return -1;
|
||||
|
||||
kv_pair_fmt(pair, "area_offset", "0x%08x",
|
||||
fmap->areas[i].offset);
|
||||
le32toh(fmap->areas[i].offset));
|
||||
kv_pair_fmt(pair, "area_size", "0x%08x",
|
||||
fmap->areas[i].size);
|
||||
le32toh(fmap->areas[i].size));
|
||||
kv_pair_fmt(pair, "area_name", "%s",
|
||||
fmap->areas[i].name);
|
||||
kv_pair_fmt(pair, "area_flags_raw", "0x%02x",
|
||||
fmap->areas[i].flags);
|
||||
le16toh(fmap->areas[i].flags));
|
||||
|
||||
/* Print descriptive strings for flags rather than the field */
|
||||
flags = fmap->areas[i].flags;
|
||||
flags = le16toh(fmap->areas[i].flags);
|
||||
str = fmap_flags_to_string(flags);
|
||||
if (str == NULL) {
|
||||
kv_pair_free(pair);
|
||||
@@ -265,8 +264,8 @@ struct fmap *fmap_create(uint64_t base, uint32_t size, uint8_t *name)
|
||||
memcpy(&fmap->signature, FMAP_SIGNATURE, strlen(FMAP_SIGNATURE));
|
||||
fmap->ver_major = FMAP_VER_MAJOR;
|
||||
fmap->ver_minor = FMAP_VER_MINOR;
|
||||
fmap->base = base;
|
||||
fmap->size = size;
|
||||
fmap->base = htole64(base);
|
||||
fmap->size = htole32(size);
|
||||
memccpy(&fmap->name, name, '\0', FMAP_STRLEN);
|
||||
|
||||
return fmap;
|
||||
@@ -289,7 +288,7 @@ int fmap_append_area(struct fmap **fmap,
|
||||
return -1;
|
||||
|
||||
/* too many areas */
|
||||
if ((*fmap)->nareas >= 0xffff)
|
||||
if (le16toh((*fmap)->nareas) >= 0xffff)
|
||||
return -1;
|
||||
|
||||
orig_size = fmap_size(*fmap);
|
||||
@@ -301,12 +300,12 @@ int fmap_append_area(struct fmap **fmap,
|
||||
|
||||
area = (struct fmap_area *)((uint8_t *)*fmap + orig_size);
|
||||
memset(area, 0, sizeof(*area));
|
||||
memcpy(&area->offset, &offset, sizeof(area->offset));
|
||||
memcpy(&area->size, &size, sizeof(area->size));
|
||||
memccpy(&area->name, name, '\0', FMAP_STRLEN);
|
||||
memcpy(&area->flags, &flags, sizeof(area->flags));
|
||||
area->offset = htole32(offset);
|
||||
area->size = htole32(size);
|
||||
area->flags = htole16(flags);
|
||||
|
||||
(*fmap)->nareas++;
|
||||
(*fmap)->nareas = htole16(le16toh((*fmap)->nareas) + 1);
|
||||
return new_size;
|
||||
}
|
||||
|
||||
@@ -319,7 +318,7 @@ const struct fmap_area *fmap_find_area(const struct fmap *fmap,
|
||||
if (!fmap || !name)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < fmap->nareas; i++) {
|
||||
for (i = 0; i < le16toh(fmap->nareas); i++) {
|
||||
if (!strcmp((const char *)fmap->areas[i].name, name)) {
|
||||
area = &fmap->areas[i];
|
||||
break;
|
||||
@@ -358,12 +357,12 @@ static struct fmap *fmap_create_test(void)
|
||||
goto fmap_create_test_exit;
|
||||
}
|
||||
|
||||
if (fmap->base != base) {
|
||||
if (le64toh(fmap->base) != base) {
|
||||
printf("FAILURE: base is incorrect\n");
|
||||
goto fmap_create_test_exit;
|
||||
}
|
||||
|
||||
if (fmap->size != 0x100000) {
|
||||
if (le32toh(fmap->size) != 0x100000) {
|
||||
printf("FAILURE: size is incorrect\n");
|
||||
goto fmap_create_test_exit;
|
||||
}
|
||||
@@ -373,7 +372,7 @@ static struct fmap *fmap_create_test(void)
|
||||
goto fmap_create_test_exit;
|
||||
}
|
||||
|
||||
if (fmap->nareas != 0) {
|
||||
if (le16toh(fmap->nareas) != 0) {
|
||||
printf("FAILURE: number of areas is incorrect\n");
|
||||
goto fmap_create_test_exit;
|
||||
}
|
||||
@@ -414,10 +413,10 @@ static int fmap_append_area_test(struct fmap **fmap)
|
||||
uint16_t nareas_orig;
|
||||
/* test_area will be used by fmap_csum_test and find_area_test */
|
||||
struct fmap_area test_area = {
|
||||
.offset = 0x400,
|
||||
.size = 0x10000,
|
||||
.offset = htole32(0x400),
|
||||
.size = htole32(0x10000),
|
||||
.name = "test_area_1",
|
||||
.flags = FMAP_AREA_STATIC,
|
||||
.flags = htole16(FMAP_AREA_STATIC),
|
||||
};
|
||||
|
||||
status = fail;
|
||||
@@ -428,26 +427,26 @@ static int fmap_append_area_test(struct fmap **fmap)
|
||||
goto fmap_append_area_test_exit;
|
||||
}
|
||||
|
||||
nareas_orig = (*fmap)->nareas;
|
||||
(*fmap)->nareas = ~(0);
|
||||
nareas_orig = le16toh((*fmap)->nareas);
|
||||
(*fmap)->nareas = htole16(~(0));
|
||||
if (fmap_append_area(fmap, 0, 0, (const uint8_t *)"foo", 0) >= 0) {
|
||||
printf("FAILURE: failed to abort with too many areas\n");
|
||||
goto fmap_append_area_test_exit;
|
||||
}
|
||||
(*fmap)->nareas = nareas_orig;
|
||||
(*fmap)->nareas = htole16(nareas_orig);
|
||||
|
||||
total_size = sizeof(**fmap) + sizeof(test_area);
|
||||
if (fmap_append_area(fmap,
|
||||
test_area.offset,
|
||||
test_area.size,
|
||||
le32toh(test_area.offset),
|
||||
le32toh(test_area.size),
|
||||
test_area.name,
|
||||
test_area.flags
|
||||
le16toh(test_area.flags)
|
||||
) != total_size) {
|
||||
printf("failed to append area\n");
|
||||
goto fmap_append_area_test_exit;
|
||||
}
|
||||
|
||||
if ((*fmap)->nareas != 1) {
|
||||
if (le16toh((*fmap)->nareas) != 1) {
|
||||
printf("FAILURE: failed to increment number of areas\n");
|
||||
goto fmap_append_area_test_exit;
|
||||
}
|
||||
|
@@ -356,11 +356,11 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
len = ntohl(cbfs_file->len);
|
||||
len = be32toh(cbfs_file->len);
|
||||
offset = offset_to_ptr(convert_to_from_top_aligned,
|
||||
&image.buffer,
|
||||
cbfs_get_entry_addr(&image, cbfs_file) +
|
||||
ntohl(cbfs_file->offset));
|
||||
be32toh(cbfs_file->offset));
|
||||
|
||||
|
||||
if (fit_add_entry(fit, offset, len, fit_type,
|
||||
@@ -384,7 +384,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
fit_address = offset_to_ptr(convert_to_from_top_aligned, &image.buffer,
|
||||
cbfs_get_entry_addr(&image, cbfs_file)
|
||||
+ ntohl(cbfs_file->offset));
|
||||
+ be32toh(cbfs_file->offset));
|
||||
|
||||
|
||||
if (set_fit_pointer(&bootblock, fit_address, convert_to_from_top_aligned,
|
||||
|
@@ -1,56 +0,0 @@
|
||||
#ifndef _SWAB_H
|
||||
#define _SWAB_H
|
||||
|
||||
/*
|
||||
* linux/byteorder/swab.h
|
||||
* Byte-swapping, independently from CPU endianness
|
||||
* swabXX[ps]?(foo)
|
||||
*
|
||||
* Francois-Rene Rideau <fare@tunes.org> 19971205
|
||||
* separated swab functions from cpu_to_XX,
|
||||
* to clean up support for bizarre-endian architectures.
|
||||
*
|
||||
* See asm-i386/byteorder.h and suches for examples of how to provide
|
||||
* architecture-dependent optimized versions
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__NetBSD__)
|
||||
#define ntohl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
|
||||
#define htonl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#define ntohll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
|
||||
#define htonll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
|
||||
|
||||
/* casts are necessary for constants, because we never know how for sure
|
||||
* how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
|
||||
*/
|
||||
#define swab16(x) \
|
||||
((unsigned short)( \
|
||||
(((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \
|
||||
(((unsigned short)(x) & (unsigned short)0xff00U) >> 8) ))
|
||||
|
||||
#define swab32(x) \
|
||||
((unsigned int)( \
|
||||
(((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \
|
||||
(((unsigned int)(x) & (unsigned int)0x0000ff00UL) << 8) | \
|
||||
(((unsigned int)(x) & (unsigned int)0x00ff0000UL) >> 8) | \
|
||||
(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) ))
|
||||
|
||||
#define swab64(x) \
|
||||
((uint64_t)( \
|
||||
(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
|
||||
(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
|
||||
|
||||
/* common.c */
|
||||
int is_big_endian(void);
|
||||
|
||||
#endif /* _SWAB_H */
|
Reference in New Issue
Block a user