Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __CBFS_H |
| 8 | #define __CBFS_H |
| 9 | |
| 10 | #include <compiler.h> |
| 11 | #include <linux/compiler.h> |
| 12 | |
| 13 | enum cbfs_result { |
| 14 | CBFS_SUCCESS = 0, |
| 15 | CBFS_NOT_INITIALIZED, |
| 16 | CBFS_BAD_HEADER, |
| 17 | CBFS_BAD_FILE, |
| 18 | CBFS_FILE_NOT_FOUND |
| 19 | }; |
| 20 | |
| 21 | enum cbfs_filetype { |
| 22 | CBFS_TYPE_STAGE = 0x10, |
| 23 | CBFS_TYPE_PAYLOAD = 0x20, |
| 24 | CBFS_TYPE_OPTIONROM = 0x30, |
| 25 | CBFS_TYPE_BOOTSPLASH = 0x40, |
| 26 | CBFS_TYPE_RAW = 0x50, |
| 27 | CBFS_TYPE_VSA = 0x51, |
| 28 | CBFS_TYPE_MBI = 0x52, |
| 29 | CBFS_TYPE_MICROCODE = 0x53, |
| 30 | CBFS_COMPONENT_CMOS_DEFAULT = 0xaa, |
| 31 | CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa |
| 32 | }; |
| 33 | |
| 34 | struct cbfs_header { |
| 35 | u32 magic; |
| 36 | u32 version; |
| 37 | u32 rom_size; |
| 38 | u32 boot_block_size; |
| 39 | u32 align; |
| 40 | u32 offset; |
| 41 | u32 pad[2]; |
| 42 | } __packed; |
| 43 | |
| 44 | struct cbfs_fileheader { |
| 45 | u8 magic[8]; |
| 46 | u32 len; |
| 47 | u32 type; |
| 48 | u32 checksum; |
| 49 | u32 offset; |
| 50 | } __packed; |
| 51 | |
| 52 | struct cbfs_cachenode { |
| 53 | struct cbfs_cachenode *next; |
| 54 | u32 type; |
| 55 | void *data; |
| 56 | u32 data_length; |
| 57 | char *name; |
| 58 | u32 name_length; |
| 59 | u32 checksum; |
| 60 | } __packed; |
| 61 | |
| 62 | extern enum cbfs_result file_cbfs_result; |
| 63 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 64 | /** |
| 65 | * file_cbfs_error() - Return a string describing the most recent error |
| 66 | * condition. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 67 | * |
| 68 | * @return A pointer to the constant string. |
| 69 | */ |
| 70 | const char *file_cbfs_error(void); |
| 71 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 72 | /** |
| 73 | * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 74 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 75 | * @end_of_rom: Points to the end of the ROM the CBFS should be read |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 76 | * from. |
| 77 | */ |
| 78 | void file_cbfs_init(uintptr_t end_of_rom); |
| 79 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 80 | /** |
| 81 | * file_cbfs_get_header() - Get the header structure for the current CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 82 | * |
| 83 | * @return A pointer to the constant structure, or NULL if there is none. |
| 84 | */ |
| 85 | const struct cbfs_header *file_cbfs_get_header(void); |
| 86 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 87 | /** |
| 88 | * file_cbfs_get_first() - Get a handle for the first file in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 89 | * |
| 90 | * @return A handle for the first file in CBFS, NULL on error. |
| 91 | */ |
| 92 | const struct cbfs_cachenode *file_cbfs_get_first(void); |
| 93 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 94 | /** |
| 95 | * file_cbfs_get_next() - Get a handle to the file after this one in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 96 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 97 | * @file: A pointer to the handle to advance. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 98 | */ |
| 99 | void file_cbfs_get_next(const struct cbfs_cachenode **file); |
| 100 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 101 | /** |
| 102 | * file_cbfs_find() - Find a file with a particular name in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 103 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 104 | * @name: The name to search for. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 105 | * |
| 106 | * @return A handle to the file, or NULL on error. |
| 107 | */ |
| 108 | const struct cbfs_cachenode *file_cbfs_find(const char *name); |
| 109 | |
| 110 | |
| 111 | /***************************************************************************/ |
| 112 | /* All of the functions below can be used without first initializing CBFS. */ |
| 113 | /***************************************************************************/ |
| 114 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 115 | /** |
| 116 | * file_cbfs_find_uncached() - Find a file with a particular name in CBFS |
| 117 | * without using the heap. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 118 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 119 | * @end_of_rom: Points to the end of the ROM the CBFS should be read |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 120 | * from. |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 121 | * @name: The name to search for. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 122 | * |
| 123 | * @return A handle to the file, or NULL on error. |
| 124 | */ |
| 125 | const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, |
| 126 | const char *name); |
| 127 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 128 | /** |
| 129 | * file_cbfs_name() - Get the name of a file in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 130 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 131 | * @file: The handle to the file. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 132 | * |
| 133 | * @return The name of the file, NULL on error. |
| 134 | */ |
| 135 | const char *file_cbfs_name(const struct cbfs_cachenode *file); |
| 136 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 137 | /** |
| 138 | * file_cbfs_size() - Get the size of a file in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 139 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 140 | * @file: The handle to the file. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 141 | * |
| 142 | * @return The size of the file, zero on error. |
| 143 | */ |
| 144 | u32 file_cbfs_size(const struct cbfs_cachenode *file); |
| 145 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 146 | /** |
| 147 | * file_cbfs_type() - Get the type of a file in CBFS. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 148 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 149 | * @file: The handle to the file. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 150 | * |
| 151 | * @return The type of the file, zero on error. |
| 152 | */ |
| 153 | u32 file_cbfs_type(const struct cbfs_cachenode *file); |
| 154 | |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 155 | /** |
| 156 | * file_cbfs_read() - Read a file from CBFS into RAM |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 157 | * |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 158 | * @file: A handle to the file to read. |
| 159 | * @buffer: Where to read it into memory. |
| 160 | * @maxsize: Maximum number of bytes to read |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 161 | * |
| 162 | * @return If positive or zero, the number of characters read. If negative, an |
Simon Glass | e3ff797 | 2012-11-05 12:16:25 +0000 | [diff] [blame] | 163 | * error occurred. |
Gabe Black | 84cd932 | 2012-10-12 14:26:11 +0000 | [diff] [blame] | 164 | */ |
| 165 | long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, |
| 166 | unsigned long maxsize); |
| 167 | |
| 168 | #endif /* __CBFS_H */ |