Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 4 | * Copyright 2015 Google Inc. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 5 | * |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 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. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef _CBFS_H_ |
| 17 | #define _CBFS_H_ |
| 18 | |
Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 19 | #include <commonlib/cbfs.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 20 | #include <program_loading.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 21 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 22 | /*********************************************** |
| 23 | * Perform CBFS operations on the boot device. * |
| 24 | ***********************************************/ |
| 25 | |
| 26 | /* Return mapping of option rom found in boot device. NULL on error. */ |
| 27 | void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device); |
| 28 | /* Load stage by name into memory. Returns entry address on success. NULL on |
| 29 | * failure. */ |
| 30 | void *cbfs_boot_load_stage_by_name(const char *name); |
| 31 | /* Locate file by name and optional type. Return 0 on success. < 0 on error. */ |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 32 | int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 33 | /* Map file into memory leaking the mapping. Only should be used when |
| 34 | * leaking mappings are a no-op. Returns NULL on error, else returns |
| 35 | * the mapping and sets the size of the file. */ |
| 36 | void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size); |
| 37 | |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 38 | /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes |
| 39 | * large |buffer|, decompressing it according to |compression| in the process. |
| 40 | * Returns the decompressed file size, or 0 on error. |
| 41 | * LZMA files will be mapped for decompression. LZ4 files will be decompressed |
| 42 | * in-place with the buffer size requirements outlined in compression.h. */ |
| 43 | size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, |
| 44 | size_t in_size, void *buffer, size_t buffer_size, uint32_t compression); |
| 45 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 46 | /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */ |
| 47 | int cbfs_prog_stage_load(struct prog *prog); |
| 48 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 49 | /***************************************************************** |
| 50 | * Support structures and functions. Direct field access should * |
| 51 | * only be done by implementers of cbfs regions -- Not the above * |
| 52 | * API. * |
| 53 | *****************************************************************/ |
| 54 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 55 | /* The cbfs_props struct describes the properties associated with a CBFS. */ |
| 56 | struct cbfs_props { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 57 | /* CBFS starts at the following offset within the boot region. */ |
| 58 | size_t offset; |
| 59 | /* CBFS size. */ |
| 60 | size_t size; |
| 61 | }; |
| 62 | |
| 63 | /* Return < 0 on error otherwise props are filled out accordingly. */ |
| 64 | int cbfs_boot_region_properties(struct cbfs_props *props); |
| 65 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 66 | /* Allow external logic to take action prior to locating a program |
| 67 | * (stage or payload). */ |
| 68 | void cbfs_prepare_program_locate(void); |
| 69 | |
| 70 | /* Object used to identify location of current cbfs to use for cbfs_boot_* |
| 71 | * operations. It's used by cbfs_boot_region_properties() and |
| 72 | * cbfs_prepare_program_locate(). */ |
| 73 | struct cbfs_locator { |
| 74 | const char *name; |
| 75 | void (*prepare)(void); |
| 76 | /* Returns 0 on successful fill of cbfs properties. */ |
| 77 | int (*locate)(struct cbfs_props *props); |
| 78 | }; |
| 79 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 80 | #endif |