diff options
author | Hung-Te Lin <hungte@chromium.org> | 2013-01-29 01:56:17 +0800 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2013-02-05 22:25:02 +0100 |
commit | eab2c81949c8859892443c1e71449f391bc52d97 (patch) | |
tree | bcb9c90daed2693b96d35e39e60a6b7e1771e0d5 /util/cbfstool/cbfs_image.h | |
parent | 3cfacbf1961accff8670997368b403d8068ad94c (diff) |
cbfstool: Add cbfs_image new CBFS image manipulation API.
Current cbfstool implementation is relying on global variables to pass processed
data, and the calculation of address is based on x86 architecture (ex, always
assuming 0x0000 as invalid address), not easy to be used on platforms without
top-aligned memory mapping. This CL is a first step to start a new cbfstool
without global variables, and to prevent assuming memory layout in x86 mode.
The first published APIs are for reading and writing existing CBFS ROM image
files (and to find file entries in a ROM file).
Read cbfs_image.h for detail usage of each API function.
Change-Id: I28c737c8f290e51332119188248ac9e28042024c
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2194
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfs_image.h')
-rw-r--r-- | util/cbfstool/cbfs_image.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h new file mode 100644 index 0000000000..9535c2d95f --- /dev/null +++ b/util/cbfstool/cbfs_image.h @@ -0,0 +1,65 @@ +/* + * CBFS Image Manipulation + * + * Copyright (C) 2013 The Chromium OS Authors. All rights reserved. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + */ + +#ifndef __CBFS_IMAGE_H +#define __CBFS_IMAGE_H +#include "common.h" +#include "cbfs.h" + +/* CBFS image processing */ + +struct cbfs_image { + struct buffer buffer; + struct cbfs_header *header; +}; + +/* Loads a CBFS image from file. Returns 0 on success, otherwise non-zero. */ +int cbfs_image_from_file(struct cbfs_image *image, const char *filename); + +/* Writes a CBFS image into file. Returns 0 on success, otherwise non-zero. */ +int cbfs_image_write_file(struct cbfs_image *image, const char *filename); + +/* Releases the CBFS image. Returns 0 on success, otherwise non-zero. */ +int cbfs_image_delete(struct cbfs_image *image); + +/* Primitive CBFS utilities */ + +/* Returns a pointer to the only valid CBFS header in give buffer, otherwise + * NULL (including when multiple headers were found). If there is a X86 ROM + * style signature (pointer at 0xfffffffc) found in ROM, it will be selected as + * the only header.*/ +struct cbfs_header *cbfs_find_header(char *data, size_t size); + +/* Returns the first cbfs_file entry in CBFS image by CBFS header (no matter if + * the entry has valid content or not), otherwise NULL. */ +struct cbfs_file *cbfs_find_first_entry(struct cbfs_image *image); + +/* Returns next cbfs_file entry (no matter if its content is valid or not), or + * NULL on failure. */ +struct cbfs_file *cbfs_find_next_entry(struct cbfs_image *image, + struct cbfs_file *entry); + +/* Returns ROM address (offset) of entry. + * This is different from entry->offset (pointer to content). */ +uint32_t cbfs_get_entry_addr(struct cbfs_image *image, struct cbfs_file *entry); + +/* Returns 1 if entry has valid data (by checking magic number), otherwise 0. */ +int cbfs_is_valid_entry(struct cbfs_file *entry); + +#endif |