Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 2 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 3 | #include <assert.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 4 | #include <boot_device.h> |
| 5 | #include <cbfs.h> |
Julius Werner | 98eeb96 | 2019-12-11 15:47:42 -0800 | [diff] [blame] | 6 | #include <commonlib/bsd/compression.h> |
Bill XIE | c79e96b | 2019-08-22 20:28:36 +0800 | [diff] [blame] | 7 | #include <console/console.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 8 | #include <endian.h> |
Bill XIE | c79e96b | 2019-08-22 20:28:36 +0800 | [diff] [blame] | 9 | #include <fmap.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 10 | #include <lib.h> |
Bill XIE | c79e96b | 2019-08-22 20:28:36 +0800 | [diff] [blame] | 11 | #include <security/tpm/tspi/crtm.h> |
| 12 | #include <security/vboot/vboot_common.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 15 | #include <symbols.h> |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 16 | #include <timestamp.h> |
Patrick Georgi | 58a150a | 2016-05-02 17:22:29 +0800 | [diff] [blame] | 17 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 18 | #define ERROR(x...) printk(BIOS_ERR, "CBFS: " x) |
| 19 | #define LOG(x...) printk(BIOS_INFO, "CBFS: " x) |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 20 | #if CONFIG(DEBUG_CBFS) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 21 | #define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x) |
| 22 | #else |
| 23 | #define DEBUG(x...) |
| 24 | #endif |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 25 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 26 | 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] | 27 | { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 28 | struct region_device rdev; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 29 | |
Aaron Durbin | fe338e2 | 2019-11-18 12:35:21 -0700 | [diff] [blame] | 30 | if (cbfs_boot_region_device(&rdev)) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 31 | return -1; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 32 | |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 33 | int ret = cbfs_locate(fh, &rdev, name, type); |
Wim Vervoorn | 114e2e8 | 2019-11-05 14:09:16 +0100 | [diff] [blame] | 34 | |
| 35 | if (CONFIG(VBOOT_ENABLE_CBFS_FALLBACK) && ret) { |
| 36 | |
| 37 | /* |
| 38 | * When VBOOT_ENABLE_CBFS_FALLBACK is enabled and a file is not available in the |
| 39 | * active RW region, the RO (COREBOOT) region will be used to locate the file. |
| 40 | * |
| 41 | * This functionality makes it possible to avoid duplicate files in the RO |
| 42 | * and RW partitions while maintaining updateability. |
| 43 | * |
| 44 | * Files can be added to the RO_REGION_ONLY config option to use this feature. |
| 45 | */ |
| 46 | printk(BIOS_DEBUG, "Fall back to RO region for %s\n", name); |
Bill XIE | bad08c2 | 2020-02-13 11:11:35 +0800 | [diff] [blame] | 47 | if (fmap_locate_area_as_rdev("COREBOOT", &rdev)) |
| 48 | ERROR("RO region not found\n"); |
| 49 | else |
| 50 | ret = cbfs_locate(fh, &rdev, name, type); |
Wim Vervoorn | 114e2e8 | 2019-11-05 14:09:16 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 53 | if (!ret) |
Bill XIE | c79e96b | 2019-08-22 20:28:36 +0800 | [diff] [blame] | 54 | if (tspi_measure_cbfs_hook(fh, name)) |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 55 | return -1; |
| 56 | |
| 57 | return ret; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size) |
| 61 | { |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 62 | struct cbfsf fh; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 63 | size_t fsize; |
| 64 | |
| 65 | if (cbfs_boot_locate(&fh, name, &type)) |
| 66 | return NULL; |
| 67 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 68 | fsize = region_device_sz(&fh.data); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 69 | |
| 70 | if (size != NULL) |
| 71 | *size = fsize; |
| 72 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 73 | return rdev_mmap(&fh.data, 0, fsize); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 76 | int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name, |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 77 | const char *name, uint32_t *type) |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 78 | { |
| 79 | struct region_device rdev; |
Bill XIE | bad08c2 | 2020-02-13 11:11:35 +0800 | [diff] [blame] | 80 | int ret = 0; |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 81 | if (fmap_locate_area_as_rdev(region_name, &rdev)) { |
| 82 | LOG("%s region not found while looking for %s\n", |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 83 | region_name, name); |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 84 | return -1; |
| 85 | } |
| 86 | |
Bill XIE | bad08c2 | 2020-02-13 11:11:35 +0800 | [diff] [blame] | 87 | ret = cbfs_locate(fh, &rdev, name, type); |
| 88 | if (!ret) |
| 89 | if (tspi_measure_cbfs_hook(fh, name)) |
| 90 | return -1; |
| 91 | return ret; |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 94 | static inline bool fsps_env(void) |
| 95 | { |
| 96 | /* FSP-S is assumed to be loaded in ramstage. */ |
| 97 | if (ENV_RAMSTAGE) |
| 98 | return true; |
| 99 | return false; |
| 100 | } |
| 101 | |
Aaron Durbin | a121f95 | 2020-05-26 15:48:10 -0600 | [diff] [blame] | 102 | static inline bool cbfs_lz4_enabled(void) |
| 103 | { |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 104 | if (fsps_env() && CONFIG(FSP_COMPRESS_FSP_S_LZ4)) |
| 105 | return true; |
| 106 | |
Aaron Durbin | a121f95 | 2020-05-26 15:48:10 -0600 | [diff] [blame] | 107 | if ((ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE) && !CONFIG(COMPRESS_PRERAM_STAGES)) |
| 108 | return false; |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | static inline bool cbfs_lzma_enabled(void) |
| 114 | { |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 115 | if (fsps_env() && CONFIG(FSP_COMPRESS_FSP_S_LZMA)) |
| 116 | return true; |
Aaron Durbin | a121f95 | 2020-05-26 15:48:10 -0600 | [diff] [blame] | 117 | /* We assume here romstage and postcar are never compressed. */ |
| 118 | if (ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE) |
| 119 | return false; |
| 120 | if (ENV_ROMSTAGE && CONFIG(POSTCAR_STAGE)) |
| 121 | return false; |
| 122 | if ((ENV_ROMSTAGE || ENV_POSTCAR) |
| 123 | && !CONFIG(COMPRESS_RAMSTAGE)) |
| 124 | return false; |
| 125 | return true; |
| 126 | } |
| 127 | |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 128 | size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, |
| 129 | size_t in_size, void *buffer, size_t buffer_size, uint32_t compression) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 130 | { |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 131 | size_t out_size; |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 132 | void *map; |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 133 | |
| 134 | switch (compression) { |
| 135 | case CBFS_COMPRESS_NONE: |
Julius Werner | f975e55 | 2016-08-19 15:43:06 -0700 | [diff] [blame] | 136 | if (buffer_size < in_size) |
| 137 | return 0; |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 138 | if (rdev_readat(rdev, buffer, offset, in_size) != in_size) |
| 139 | return 0; |
| 140 | return in_size; |
| 141 | |
| 142 | case CBFS_COMPRESS_LZ4: |
Aaron Durbin | a121f95 | 2020-05-26 15:48:10 -0600 | [diff] [blame] | 143 | if (!cbfs_lz4_enabled()) |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 146 | /* cbfs_stage_load_and_decompress() takes care of in-place |
| 147 | lz4 decompression by setting up the rdev to be in memory. */ |
| 148 | map = rdev_mmap(rdev, offset, in_size); |
| 149 | if (map == NULL) |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | |
| 152 | timestamp_add_now(TS_START_ULZ4F); |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 153 | out_size = ulz4fn(map, in_size, buffer, buffer_size); |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 154 | timestamp_add_now(TS_END_ULZ4F); |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 155 | |
| 156 | rdev_munmap(rdev, map); |
| 157 | |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 158 | return out_size; |
| 159 | |
| 160 | case CBFS_COMPRESS_LZMA: |
Aaron Durbin | a121f95 | 2020-05-26 15:48:10 -0600 | [diff] [blame] | 161 | if (!cbfs_lzma_enabled()) |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 162 | return 0; |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 163 | map = rdev_mmap(rdev, offset, in_size); |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 164 | if (map == NULL) |
| 165 | return 0; |
| 166 | |
| 167 | /* Note: timestamp not useful for memory-mapped media (x86) */ |
| 168 | timestamp_add_now(TS_START_ULZMA); |
| 169 | out_size = ulzman(map, in_size, buffer, buffer_size); |
| 170 | timestamp_add_now(TS_END_ULZMA); |
| 171 | |
| 172 | rdev_munmap(rdev, map); |
| 173 | |
| 174 | return out_size; |
| 175 | |
| 176 | default: |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 177 | return 0; |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 178 | } |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 179 | } |
| 180 | |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 181 | static size_t cbfs_stage_load_and_decompress(const struct region_device *rdev, |
| 182 | size_t offset, size_t in_size, void *buffer, size_t buffer_size, |
| 183 | uint32_t compression) |
| 184 | { |
| 185 | struct region_device rdev_src; |
| 186 | |
| 187 | if (compression == CBFS_COMPRESS_LZ4) { |
| 188 | if (!cbfs_lz4_enabled()) |
| 189 | return 0; |
| 190 | /* Load the compressed image to the end of the available memory |
| 191 | * area for in-place decompression. It is the responsibility of |
| 192 | * the caller to ensure that buffer_size is large enough |
| 193 | * (see compression.h, guaranteed by cbfstool for stages). */ |
| 194 | void *compr_start = buffer + buffer_size - in_size; |
| 195 | if (rdev_readat(rdev, compr_start, offset, in_size) != in_size) |
| 196 | return 0; |
| 197 | /* Create a region device backed by memory. */ |
| 198 | rdev_chain(&rdev_src, &addrspace_32bit.rdev, |
| 199 | (uintptr_t)compr_start, in_size); |
| 200 | |
| 201 | return cbfs_load_and_decompress(&rdev_src, 0, in_size, buffer, |
| 202 | buffer_size, compression); |
| 203 | } |
| 204 | |
| 205 | /* All other algorithms can use the generic implementation. */ |
| 206 | return cbfs_load_and_decompress(rdev, offset, in_size, buffer, |
| 207 | buffer_size, compression); |
| 208 | } |
| 209 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 210 | static inline int tohex4(unsigned int c) |
Patrick Georgi | b203c2f | 2009-08-20 14:48:03 +0000 | [diff] [blame] | 211 | { |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 212 | return (c <= 9) ? (c + '0') : (c - 10 + 'a'); |
Patrick Georgi | b203c2f | 2009-08-20 14:48:03 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 215 | static void tohex8(unsigned int val, char *dest) |
| 216 | { |
| 217 | dest[0] = tohex4((val >> 4) & 0xf); |
| 218 | dest[1] = tohex4(val & 0xf); |
| 219 | } |
| 220 | |
Lee Leahy | b2d834a | 2017-03-08 16:52:22 -0800 | [diff] [blame] | 221 | static void tohex16(unsigned int val, char *dest) |
Patrick Georgi | b203c2f | 2009-08-20 14:48:03 +0000 | [diff] [blame] | 222 | { |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 223 | dest[0] = tohex4(val >> 12); |
| 224 | dest[1] = tohex4((val >> 8) & 0xf); |
| 225 | dest[2] = tohex4((val >> 4) & 0xf); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 226 | dest[3] = tohex4(val & 0xf); |
Patrick Georgi | b203c2f | 2009-08-20 14:48:03 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 229 | void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device) |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 230 | { |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 231 | char name[17] = "pciXXXX,XXXX.rom"; |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 232 | |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 233 | tohex16(vendor, name + 3); |
| 234 | tohex16(device, name + 8); |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 235 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 236 | return cbfs_boot_map_with_leak(name, CBFS_TYPE_OPTIONROM, NULL); |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 239 | void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev) |
| 240 | { |
| 241 | char name[20] = "pciXXXX,XXXX,XX.rom"; |
| 242 | |
| 243 | tohex16(vendor, name + 3); |
| 244 | tohex16(device, name + 8); |
| 245 | tohex8(rev, name + 13); |
| 246 | |
| 247 | return cbfs_boot_map_with_leak(name, CBFS_TYPE_OPTIONROM, NULL); |
| 248 | } |
| 249 | |
T Michael Turney | 809fa7b | 2018-04-12 13:36:40 -0700 | [diff] [blame] | 250 | size_t cbfs_boot_load_file(const char *name, void *buf, size_t buf_size, |
| 251 | uint32_t type) |
Julius Werner | f975e55 | 2016-08-19 15:43:06 -0700 | [diff] [blame] | 252 | { |
| 253 | struct cbfsf fh; |
| 254 | uint32_t compression_algo; |
| 255 | size_t decompressed_size; |
Julius Werner | f975e55 | 2016-08-19 15:43:06 -0700 | [diff] [blame] | 256 | |
| 257 | if (cbfs_boot_locate(&fh, name, &type) < 0) |
| 258 | return 0; |
| 259 | |
| 260 | if (cbfsf_decompression_info(&fh, &compression_algo, |
Philipp Deppenwiese | 66f9a09 | 2018-11-08 10:59:40 +0100 | [diff] [blame] | 261 | &decompressed_size) |
| 262 | < 0 |
| 263 | || decompressed_size > buf_size) |
Julius Werner | f975e55 | 2016-08-19 15:43:06 -0700 | [diff] [blame] | 264 | return 0; |
| 265 | |
| 266 | return cbfs_load_and_decompress(&fh.data, 0, region_device_sz(&fh.data), |
| 267 | buf, buf_size, compression_algo); |
| 268 | } |
| 269 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 270 | int cbfs_prog_stage_load(struct prog *pstage) |
| 271 | { |
| 272 | struct cbfs_stage stage; |
| 273 | uint8_t *load; |
| 274 | void *entry; |
| 275 | size_t fsize; |
| 276 | size_t foffset; |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 277 | const struct region_device *fh = prog_rdev(pstage); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 278 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 279 | if (rdev_readat(fh, &stage, 0, sizeof(stage)) != sizeof(stage)) |
Julius Werner | b29bd27b | 2015-12-03 11:29:12 -0800 | [diff] [blame] | 280 | return -1; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 281 | |
| 282 | fsize = region_device_sz(fh); |
| 283 | fsize -= sizeof(stage); |
| 284 | foffset = 0; |
| 285 | foffset += sizeof(stage); |
| 286 | |
| 287 | assert(fsize == stage.len); |
| 288 | |
| 289 | /* Note: cbfs_stage fields are currently in the endianness of the |
| 290 | * running processor. */ |
| 291 | load = (void *)(uintptr_t)stage.load; |
| 292 | entry = (void *)(uintptr_t)stage.entry; |
| 293 | |
Aaron Durbin | ed253c8 | 2015-10-07 17:22:42 -0500 | [diff] [blame] | 294 | /* Hacky way to not load programs over read only media. The stages |
| 295 | * that would hit this path initialize themselves. */ |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 296 | if ((ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE) && |
| 297 | !CONFIG(NO_XIP_EARLY_STAGES) && CONFIG(BOOT_DEVICE_MEMORY_MAPPED)) { |
Aaron Durbin | ed253c8 | 2015-10-07 17:22:42 -0500 | [diff] [blame] | 298 | void *mapping = rdev_mmap(fh, foffset, fsize); |
| 299 | rdev_munmap(fh, mapping); |
| 300 | if (mapping == load) |
| 301 | goto out; |
| 302 | } |
| 303 | |
Aaron Durbin | 84f394e | 2020-05-26 16:16:42 -0600 | [diff] [blame] | 304 | fsize = cbfs_stage_load_and_decompress(fh, foffset, fsize, load, |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 305 | stage.memlen, stage.compression); |
| 306 | if (!fsize) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 307 | return -1; |
| 308 | |
| 309 | /* Clear area not covered by file. */ |
| 310 | memset(&load[fsize], 0, stage.memlen - fsize); |
| 311 | |
Aaron Durbin | 096f457 | 2016-03-31 13:49:00 -0500 | [diff] [blame] | 312 | prog_segment_loaded((uintptr_t)load, stage.memlen, SEG_FINAL); |
Aaron Durbin | ed253c8 | 2015-10-07 17:22:42 -0500 | [diff] [blame] | 313 | |
| 314 | out: |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 315 | prog_set_area(pstage, load, stage.memlen); |
| 316 | prog_set_entry(pstage, entry, NULL); |
| 317 | |
| 318 | return 0; |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 319 | } |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 320 | |
Aaron Durbin | fe338e2 | 2019-11-18 12:35:21 -0700 | [diff] [blame] | 321 | int cbfs_boot_region_device(struct region_device *rdev) |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 322 | { |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 323 | boot_device_init(); |
Julius Werner | 815611e | 2019-12-05 22:29:07 -0800 | [diff] [blame] | 324 | return vboot_locate_cbfs(rdev) && |
| 325 | fmap_locate_area_as_rdev("COREBOOT", rdev); |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 326 | } |