Hung-Te Lin | eab2c81 | 2013-01-29 01:56:17 +0800 | [diff] [blame] | 1 | /* |
| 2 | * CBFS Image Manipulation |
| 3 | * |
| 4 | * Copyright (C) 2013 The Chromium OS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef __CBFS_IMAGE_H |
| 21 | #define __CBFS_IMAGE_H |
| 22 | #include "common.h" |
| 23 | #include "cbfs.h" |
| 24 | |
| 25 | /* CBFS image processing */ |
| 26 | |
| 27 | struct cbfs_image { |
| 28 | struct buffer buffer; |
| 29 | struct cbfs_header *header; |
| 30 | }; |
| 31 | |
| 32 | /* Loads a CBFS image from file. Returns 0 on success, otherwise non-zero. */ |
| 33 | int cbfs_image_from_file(struct cbfs_image *image, const char *filename); |
| 34 | |
| 35 | /* Writes a CBFS image into file. Returns 0 on success, otherwise non-zero. */ |
| 36 | int cbfs_image_write_file(struct cbfs_image *image, const char *filename); |
| 37 | |
| 38 | /* Releases the CBFS image. Returns 0 on success, otherwise non-zero. */ |
| 39 | int cbfs_image_delete(struct cbfs_image *image); |
| 40 | |
Hung-Te Lin | 3bb035b | 2013-01-29 02:15:49 +0800 | [diff] [blame^] | 41 | /* Callback function used by cbfs_walk. |
| 42 | * Returns 0 on success, or non-zero to stop further iteration. */ |
| 43 | typedef int (*cbfs_entry_callback)(struct cbfs_image *image, |
| 44 | struct cbfs_file *file, |
| 45 | void *arg); |
| 46 | |
| 47 | /* Iterates through all entries in CBFS image, and invoke with callback. |
| 48 | * Stops if callback returns non-zero values. |
| 49 | * Returns number of entries invoked. */ |
| 50 | int cbfs_walk(struct cbfs_image *image, cbfs_entry_callback callback, void *arg); |
| 51 | |
Hung-Te Lin | eab2c81 | 2013-01-29 01:56:17 +0800 | [diff] [blame] | 52 | /* Primitive CBFS utilities */ |
| 53 | |
| 54 | /* Returns a pointer to the only valid CBFS header in give buffer, otherwise |
| 55 | * NULL (including when multiple headers were found). If there is a X86 ROM |
| 56 | * style signature (pointer at 0xfffffffc) found in ROM, it will be selected as |
| 57 | * the only header.*/ |
| 58 | struct cbfs_header *cbfs_find_header(char *data, size_t size); |
| 59 | |
| 60 | /* Returns the first cbfs_file entry in CBFS image by CBFS header (no matter if |
| 61 | * the entry has valid content or not), otherwise NULL. */ |
| 62 | struct cbfs_file *cbfs_find_first_entry(struct cbfs_image *image); |
| 63 | |
| 64 | /* Returns next cbfs_file entry (no matter if its content is valid or not), or |
| 65 | * NULL on failure. */ |
| 66 | struct cbfs_file *cbfs_find_next_entry(struct cbfs_image *image, |
| 67 | struct cbfs_file *entry); |
| 68 | |
| 69 | /* Returns ROM address (offset) of entry. |
| 70 | * This is different from entry->offset (pointer to content). */ |
| 71 | uint32_t cbfs_get_entry_addr(struct cbfs_image *image, struct cbfs_file *entry); |
| 72 | |
| 73 | /* Returns 1 if entry has valid data (by checking magic number), otherwise 0. */ |
| 74 | int cbfs_is_valid_entry(struct cbfs_file *entry); |
| 75 | |
Hung-Te Lin | 3bb035b | 2013-01-29 02:15:49 +0800 | [diff] [blame^] | 76 | /* Print CBFS component information. */ |
| 77 | int cbfs_print_directory(struct cbfs_image *image); |
| 78 | int cbfs_print_header_info(struct cbfs_image *image); |
| 79 | int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry, |
| 80 | void *arg); |
| 81 | |
Hung-Te Lin | eab2c81 | 2013-01-29 01:56:17 +0800 | [diff] [blame] | 82 | #endif |