Patrick Georgi (pgeorgi@google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10969
-gerrit
commit 1bce5171c91c789801b184e2cebf0680c188b17f Author: Patrick Georgi pgeorgi@chromium.org Date: Fri Jul 17 21:33:00 2015 +0200
cbfstool: Add accessor functions to manipulate cbfs file headers
There will be more to add file attributes. The overall idea is to build a header, then pass header and data into the functions that make use of them, eg. to store them in the image or to find a suitable location.
Change-Id: Ic0e916c6fd6d1fff7d0ef3581f4b0027bd483137 Signed-off-by: Patrick Georgi pgeorgi@chromium.org --- util/cbfstool/Makefile | 2 +- util/cbfstool/Makefile.inc | 1 + util/cbfstool/cbfs_file_header.c | 71 ++++++++++++++++++++++++++++++++++++++++ util/cbfstool/cbfs_file_header.h | 26 +++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-)
diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile index 65d5710..68939dd 100644 --- a/util/cbfstool/Makefile +++ b/util/cbfstool/Makefile @@ -12,7 +12,7 @@ CPPFLAGS += -Iflashmap LDFLAGS += -g3
CBFSTOOL_BINARY:=$(obj)/cbfstool -CBFSTOOL_COMMON:=common.o cbfs_image.o compress.o fit.o +CBFSTOOL_COMMON:=common.o cbfs_image.o cbfs_file_header.o compress.o fit.o CBFSTOOL_COMMON+=elfheaders.o cbfs-mkstage.o cbfs-mkpayload.o xdr.o CBFSTOOL_COMMON+=partitioned_file.o linux_trampoline.o cbfs-payload-linux.o # LZMA diff --git a/util/cbfstool/Makefile.inc b/util/cbfstool/Makefile.inc index 976f0c2..b7877fd 100644 --- a/util/cbfstool/Makefile.inc +++ b/util/cbfstool/Makefile.inc @@ -3,6 +3,7 @@ cbfsobj += cbfstool.o cbfsobj += common.o cbfsobj += compress.o cbfsobj += cbfs_image.o +cbfsobj += cbfs_file_header.o cbfsobj += cbfs-mkstage.o cbfsobj += cbfs-mkpayload.o cbfsobj += elfheaders.o diff --git a/util/cbfstool/cbfs_file_header.c b/util/cbfstool/cbfs_file_header.c new file mode 100644 index 0000000..9d359ca --- /dev/null +++ b/util/cbfstool/cbfs_file_header.c @@ -0,0 +1,71 @@ +/* + * CBFS file header management + * + * Copyright (C) 2015 Google Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#include <inttypes.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +#include "swab.h" +#include "cbfs_file_header.h" + +/* this is excessive so should provide enough room */ +#define MAX_FILE_HEADER_SIZE 4096 + +struct cbfs_file *create_file_header(void) +{ + struct cbfs_file *file = malloc(MAX_FILE_HEADER_SIZE); + if (!file) return NULL; + + memset(file, CBFS_CONTENT_DEFAULT_VALUE, MAX_FILE_HEADER_SIZE); + memcpy(file->magic, CBFS_FILE_MAGIC, sizeof(file->magic)); + file->type = htonl(CBFS_COMPONENT_NULL); + file->attributes_offset = 0; + file->offset = htonl(sizeof(struct cbfs_file)); + file->filename[0] = 0; + + return file; +} + +int file_header_set_filename(struct cbfs_file *file, const char *name) +{ + if (file->offset != sizeof(struct cbfs_file)) + return -1; + + int len = strlen(name); + + if (sizeof(struct cbfs_file) + len + 1 > MAX_FILE_HEADER_SIZE) + return -1; + + strcpy(file->filename, name); + file->offset += len + 1; + return 0; +} + +uint32_t file_header_get_length(struct cbfs_file *file) +{ + return ntohl(file->offset); +} + +void file_header_set_data_size(struct cbfs_file *file, uint32_t size) +{ + file->len = htonl(size); +} diff --git a/util/cbfstool/cbfs_file_header.h b/util/cbfstool/cbfs_file_header.h new file mode 100644 index 0000000..6dcd743 --- /dev/null +++ b/util/cbfstool/cbfs_file_header.h @@ -0,0 +1,26 @@ +/* + * CBFS file header management + * + * Copyright (C) 2015 Google Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#include "common.h" +#include "cbfs.h" + +struct cbfs_file *create_file_header(void); +int file_header_set_filename(struct cbfs_file *file, const char *name); +uint32_t file_header_get_length(struct cbfs_file *file); +void file_header_set_data_size(struct cbfs_file *file, uint32_t size);