184cd9327SGabe Black /* 284cd9327SGabe Black * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 384cd9327SGabe Black * 484cd9327SGabe Black * This program is free software; you can redistribute it and/or 584cd9327SGabe Black * modify it under the terms of the GNU General Public License as 684cd9327SGabe Black * published by the Free Software Foundation; either version 2 of 784cd9327SGabe Black * the License, or (at your option) any later version. 884cd9327SGabe Black * 984cd9327SGabe Black * This program is distributed in the hope that it will be useful, 1084cd9327SGabe Black * but WITHOUT ANY WARRANTY; without even the implied warranty of 1184cd9327SGabe Black * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1284cd9327SGabe Black * GNU General Public License for more details. 1384cd9327SGabe Black * 1484cd9327SGabe Black * You should have received a copy of the GNU General Public License 1584cd9327SGabe Black * along with this program; if not, write to the Free Software 1684cd9327SGabe Black * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 1784cd9327SGabe Black * MA 02111-1307 USA 1884cd9327SGabe Black */ 1984cd9327SGabe Black 2084cd9327SGabe Black #ifndef __CBFS_H 2184cd9327SGabe Black #define __CBFS_H 2284cd9327SGabe Black 2384cd9327SGabe Black #include <compiler.h> 2484cd9327SGabe Black #include <linux/compiler.h> 2584cd9327SGabe Black 2684cd9327SGabe Black enum cbfs_result { 2784cd9327SGabe Black CBFS_SUCCESS = 0, 2884cd9327SGabe Black CBFS_NOT_INITIALIZED, 2984cd9327SGabe Black CBFS_BAD_HEADER, 3084cd9327SGabe Black CBFS_BAD_FILE, 3184cd9327SGabe Black CBFS_FILE_NOT_FOUND 3284cd9327SGabe Black }; 3384cd9327SGabe Black 3484cd9327SGabe Black enum cbfs_filetype { 3584cd9327SGabe Black CBFS_TYPE_STAGE = 0x10, 3684cd9327SGabe Black CBFS_TYPE_PAYLOAD = 0x20, 3784cd9327SGabe Black CBFS_TYPE_OPTIONROM = 0x30, 3884cd9327SGabe Black CBFS_TYPE_BOOTSPLASH = 0x40, 3984cd9327SGabe Black CBFS_TYPE_RAW = 0x50, 4084cd9327SGabe Black CBFS_TYPE_VSA = 0x51, 4184cd9327SGabe Black CBFS_TYPE_MBI = 0x52, 4284cd9327SGabe Black CBFS_TYPE_MICROCODE = 0x53, 4384cd9327SGabe Black CBFS_COMPONENT_CMOS_DEFAULT = 0xaa, 4484cd9327SGabe Black CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa 4584cd9327SGabe Black }; 4684cd9327SGabe Black 4784cd9327SGabe Black struct cbfs_header { 4884cd9327SGabe Black u32 magic; 4984cd9327SGabe Black u32 version; 5084cd9327SGabe Black u32 rom_size; 5184cd9327SGabe Black u32 boot_block_size; 5284cd9327SGabe Black u32 align; 5384cd9327SGabe Black u32 offset; 5484cd9327SGabe Black u32 pad[2]; 5584cd9327SGabe Black } __packed; 5684cd9327SGabe Black 5784cd9327SGabe Black struct cbfs_fileheader { 5884cd9327SGabe Black u8 magic[8]; 5984cd9327SGabe Black u32 len; 6084cd9327SGabe Black u32 type; 6184cd9327SGabe Black u32 checksum; 6284cd9327SGabe Black u32 offset; 6384cd9327SGabe Black } __packed; 6484cd9327SGabe Black 6584cd9327SGabe Black struct cbfs_cachenode { 6684cd9327SGabe Black struct cbfs_cachenode *next; 6784cd9327SGabe Black u32 type; 6884cd9327SGabe Black void *data; 6984cd9327SGabe Black u32 data_length; 7084cd9327SGabe Black char *name; 7184cd9327SGabe Black u32 name_length; 7284cd9327SGabe Black u32 checksum; 7384cd9327SGabe Black } __packed; 7484cd9327SGabe Black 7584cd9327SGabe Black extern enum cbfs_result file_cbfs_result; 7684cd9327SGabe Black 77*e3ff797cSSimon Glass /** 78*e3ff797cSSimon Glass * file_cbfs_error() - Return a string describing the most recent error 79*e3ff797cSSimon Glass * condition. 8084cd9327SGabe Black * 8184cd9327SGabe Black * @return A pointer to the constant string. 8284cd9327SGabe Black */ 8384cd9327SGabe Black const char *file_cbfs_error(void); 8484cd9327SGabe Black 85*e3ff797cSSimon Glass /** 86*e3ff797cSSimon Glass * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. 8784cd9327SGabe Black * 88*e3ff797cSSimon Glass * @end_of_rom: Points to the end of the ROM the CBFS should be read 8984cd9327SGabe Black * from. 9084cd9327SGabe Black */ 9184cd9327SGabe Black void file_cbfs_init(uintptr_t end_of_rom); 9284cd9327SGabe Black 93*e3ff797cSSimon Glass /** 94*e3ff797cSSimon Glass * file_cbfs_get_header() - Get the header structure for the current CBFS. 9584cd9327SGabe Black * 9684cd9327SGabe Black * @return A pointer to the constant structure, or NULL if there is none. 9784cd9327SGabe Black */ 9884cd9327SGabe Black const struct cbfs_header *file_cbfs_get_header(void); 9984cd9327SGabe Black 100*e3ff797cSSimon Glass /** 101*e3ff797cSSimon Glass * file_cbfs_get_first() - Get a handle for the first file in CBFS. 10284cd9327SGabe Black * 10384cd9327SGabe Black * @return A handle for the first file in CBFS, NULL on error. 10484cd9327SGabe Black */ 10584cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_get_first(void); 10684cd9327SGabe Black 107*e3ff797cSSimon Glass /** 108*e3ff797cSSimon Glass * file_cbfs_get_next() - Get a handle to the file after this one in CBFS. 10984cd9327SGabe Black * 110*e3ff797cSSimon Glass * @file: A pointer to the handle to advance. 11184cd9327SGabe Black */ 11284cd9327SGabe Black void file_cbfs_get_next(const struct cbfs_cachenode **file); 11384cd9327SGabe Black 114*e3ff797cSSimon Glass /** 115*e3ff797cSSimon Glass * file_cbfs_find() - Find a file with a particular name in CBFS. 11684cd9327SGabe Black * 117*e3ff797cSSimon Glass * @name: The name to search for. 11884cd9327SGabe Black * 11984cd9327SGabe Black * @return A handle to the file, or NULL on error. 12084cd9327SGabe Black */ 12184cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find(const char *name); 12284cd9327SGabe Black 12384cd9327SGabe Black 12484cd9327SGabe Black /***************************************************************************/ 12584cd9327SGabe Black /* All of the functions below can be used without first initializing CBFS. */ 12684cd9327SGabe Black /***************************************************************************/ 12784cd9327SGabe Black 128*e3ff797cSSimon Glass /** 129*e3ff797cSSimon Glass * file_cbfs_find_uncached() - Find a file with a particular name in CBFS 130*e3ff797cSSimon Glass * without using the heap. 13184cd9327SGabe Black * 132*e3ff797cSSimon Glass * @end_of_rom: Points to the end of the ROM the CBFS should be read 13384cd9327SGabe Black * from. 134*e3ff797cSSimon Glass * @name: The name to search for. 13584cd9327SGabe Black * 13684cd9327SGabe Black * @return A handle to the file, or NULL on error. 13784cd9327SGabe Black */ 13884cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, 13984cd9327SGabe Black const char *name); 14084cd9327SGabe Black 141*e3ff797cSSimon Glass /** 142*e3ff797cSSimon Glass * file_cbfs_name() - Get the name of a file in CBFS. 14384cd9327SGabe Black * 144*e3ff797cSSimon Glass * @file: The handle to the file. 14584cd9327SGabe Black * 14684cd9327SGabe Black * @return The name of the file, NULL on error. 14784cd9327SGabe Black */ 14884cd9327SGabe Black const char *file_cbfs_name(const struct cbfs_cachenode *file); 14984cd9327SGabe Black 150*e3ff797cSSimon Glass /** 151*e3ff797cSSimon Glass * file_cbfs_size() - Get the size of a file in CBFS. 15284cd9327SGabe Black * 153*e3ff797cSSimon Glass * @file: The handle to the file. 15484cd9327SGabe Black * 15584cd9327SGabe Black * @return The size of the file, zero on error. 15684cd9327SGabe Black */ 15784cd9327SGabe Black u32 file_cbfs_size(const struct cbfs_cachenode *file); 15884cd9327SGabe Black 159*e3ff797cSSimon Glass /** 160*e3ff797cSSimon Glass * file_cbfs_type() - Get the type of a file in CBFS. 16184cd9327SGabe Black * 162*e3ff797cSSimon Glass * @file: The handle to the file. 16384cd9327SGabe Black * 16484cd9327SGabe Black * @return The type of the file, zero on error. 16584cd9327SGabe Black */ 16684cd9327SGabe Black u32 file_cbfs_type(const struct cbfs_cachenode *file); 16784cd9327SGabe Black 168*e3ff797cSSimon Glass /** 169*e3ff797cSSimon Glass * file_cbfs_read() - Read a file from CBFS into RAM 17084cd9327SGabe Black * 171*e3ff797cSSimon Glass * @file: A handle to the file to read. 172*e3ff797cSSimon Glass * @buffer: Where to read it into memory. 173*e3ff797cSSimon Glass * @maxsize: Maximum number of bytes to read 17484cd9327SGabe Black * 17584cd9327SGabe Black * @return If positive or zero, the number of characters read. If negative, an 17684cd9327SGabe Black * error occurred. 17784cd9327SGabe Black */ 17884cd9327SGabe Black long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, 17984cd9327SGabe Black unsigned long maxsize); 18084cd9327SGabe Black 18184cd9327SGabe Black #endif /* __CBFS_H */ 182