Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 2 | /* |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 3 | * From coreboot src/southbridge/intel/bd82x6x/mrccache.c |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2014 Google Inc. |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 6 | * Copyright (C) 2015 Bin Meng <bmeng.cn@gmail.com> |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 15 | #include <net.h> |
| 16 | #include <spi.h> |
| 17 | #include <spi_flash.h> |
Bin Meng | 21666cf | 2015-10-11 21:37:36 -0700 | [diff] [blame] | 18 | #include <asm/mrccache.h> |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 19 | #include <dm/device-internal.h> |
| 20 | #include <dm/uclass-internal.h> |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 21 | |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Simon Glass | 040bef1 | 2019-09-25 08:57:04 -0600 | [diff] [blame] | 24 | static uint mrc_block_size(uint data_size) |
| 25 | { |
| 26 | uint mrc_size = sizeof(struct mrc_data_container) + data_size; |
| 27 | |
| 28 | return ALIGN(mrc_size, MRC_DATA_ALIGN); |
| 29 | } |
| 30 | |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 31 | static struct mrc_data_container *next_mrc_block( |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 32 | struct mrc_data_container *cache) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 33 | { |
| 34 | /* MRC data blocks are aligned within the region */ |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 35 | u8 *region_ptr = (u8 *)cache; |
| 36 | |
Simon Glass | 040bef1 | 2019-09-25 08:57:04 -0600 | [diff] [blame] | 37 | region_ptr += mrc_block_size(cache->data_size); |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 38 | |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 39 | return (struct mrc_data_container *)region_ptr; |
| 40 | } |
| 41 | |
| 42 | static int is_mrc_cache(struct mrc_data_container *cache) |
| 43 | { |
| 44 | return cache && (cache->signature == MRC_DATA_SIGNATURE); |
| 45 | } |
| 46 | |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 47 | struct mrc_data_container *mrccache_find_current(struct mrc_region *entry) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 48 | { |
| 49 | struct mrc_data_container *cache, *next; |
| 50 | ulong base_addr, end_addr; |
| 51 | uint id; |
| 52 | |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 53 | base_addr = entry->base + entry->offset; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 54 | end_addr = base_addr + entry->length; |
| 55 | cache = NULL; |
| 56 | |
| 57 | /* Search for the last filled entry in the region */ |
| 58 | for (id = 0, next = (struct mrc_data_container *)base_addr; |
| 59 | is_mrc_cache(next); |
| 60 | id++) { |
| 61 | cache = next; |
| 62 | next = next_mrc_block(next); |
| 63 | if ((ulong)next >= end_addr) |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | if (id-- == 0) { |
| 68 | debug("%s: No valid MRC cache found.\n", __func__); |
| 69 | return NULL; |
| 70 | } |
| 71 | |
| 72 | /* Verify checksum */ |
| 73 | if (cache->checksum != compute_ip_checksum(cache->data, |
| 74 | cache->data_size)) { |
| 75 | printf("%s: MRC cache checksum mismatch\n", __func__); |
| 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | debug("%s: picked entry %u from cache block\n", __func__, id); |
| 80 | |
| 81 | return cache; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * find_next_mrc_cache() - get next cache entry |
| 86 | * |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 87 | * This moves to the next cache entry in the region, making sure it has enough |
| 88 | * space to hold data of size @data_size. |
| 89 | * |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 90 | * @entry: MRC cache flash area |
| 91 | * @cache: Entry to start from |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 92 | * @data_size: Required data size of the new entry. Note that we assume that |
| 93 | * all cache entries are the same size |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 94 | * |
| 95 | * @return next cache entry if found, NULL if we got to the end |
| 96 | */ |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 97 | static struct mrc_data_container *find_next_mrc_cache(struct mrc_region *entry, |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 98 | struct mrc_data_container *prev, int data_size) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 99 | { |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 100 | struct mrc_data_container *cache; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 101 | ulong base_addr, end_addr; |
| 102 | |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 103 | base_addr = entry->base + entry->offset; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 104 | end_addr = base_addr + entry->length; |
| 105 | |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 106 | /* |
| 107 | * We assume that all cache entries are the same size, but let's use |
| 108 | * data_size here for clarity. |
| 109 | */ |
| 110 | cache = next_mrc_block(prev); |
| 111 | if ((ulong)cache + mrc_block_size(data_size) > end_addr) { |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 112 | /* Crossed the boundary */ |
| 113 | cache = NULL; |
| 114 | debug("%s: no available entries found\n", __func__); |
| 115 | } else { |
| 116 | debug("%s: picked next entry from cache block at %p\n", |
| 117 | __func__, cache); |
| 118 | } |
| 119 | |
| 120 | return cache; |
| 121 | } |
| 122 | |
Simon Glass | 6e1b956 | 2019-12-06 21:42:09 -0700 | [diff] [blame] | 123 | /** |
| 124 | * mrccache_update() - update the MRC cache with a new record |
| 125 | * |
| 126 | * This writes a new record to the end of the MRC cache region. If the new |
| 127 | * record is the same as the latest record then the write is skipped |
| 128 | * |
| 129 | * @sf: SPI flash to write to |
| 130 | * @entry: Position and size of MRC cache in SPI flash |
| 131 | * @cur: Record to write |
| 132 | * @return 0 if updated, -EEXIST if the record is the same as the latest |
| 133 | * record, -EINVAL if the record is not valid, other error if SPI write failed |
| 134 | */ |
| 135 | static int mrccache_update(struct udevice *sf, struct mrc_region *entry, |
| 136 | struct mrc_data_container *cur) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 137 | { |
| 138 | struct mrc_data_container *cache; |
| 139 | ulong offset; |
| 140 | ulong base_addr; |
| 141 | int ret; |
| 142 | |
Simon Glass | fbef25f | 2019-04-25 21:58:59 -0600 | [diff] [blame] | 143 | if (!is_mrc_cache(cur)) { |
| 144 | debug("%s: Cache data not valid\n", __func__); |
Bin Meng | d61a7b4 | 2015-10-11 21:37:37 -0700 | [diff] [blame] | 145 | return -EINVAL; |
Simon Glass | fbef25f | 2019-04-25 21:58:59 -0600 | [diff] [blame] | 146 | } |
Bin Meng | d61a7b4 | 2015-10-11 21:37:37 -0700 | [diff] [blame] | 147 | |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 148 | /* Find the last used block */ |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 149 | base_addr = entry->base + entry->offset; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 150 | debug("Updating MRC cache data\n"); |
| 151 | cache = mrccache_find_current(entry); |
| 152 | if (cache && (cache->data_size == cur->data_size) && |
| 153 | (!memcmp(cache, cur, cache->data_size + sizeof(*cur)))) { |
| 154 | debug("MRC data in flash is up to date. No update\n"); |
| 155 | return -EEXIST; |
| 156 | } |
| 157 | |
| 158 | /* Move to the next block, which will be the first unused block */ |
| 159 | if (cache) |
Simon Glass | d553f97 | 2019-12-06 21:42:02 -0700 | [diff] [blame] | 160 | cache = find_next_mrc_cache(entry, cache, cur->data_size); |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | * If we have got to the end, erase the entire mrc-cache area and start |
| 164 | * again at block 0. |
| 165 | */ |
| 166 | if (!cache) { |
| 167 | debug("Erasing the MRC cache region of %x bytes at %x\n", |
| 168 | entry->length, entry->offset); |
| 169 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 170 | ret = spi_flash_erase_dm(sf, entry->offset, entry->length); |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 171 | if (ret) { |
| 172 | debug("Failed to erase flash region\n"); |
| 173 | return ret; |
| 174 | } |
| 175 | cache = (struct mrc_data_container *)base_addr; |
| 176 | } |
| 177 | |
| 178 | /* Write the data out */ |
| 179 | offset = (ulong)cache - base_addr + entry->offset; |
| 180 | debug("Write MRC cache update to flash at %lx\n", offset); |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 181 | ret = spi_flash_write_dm(sf, offset, cur->data_size + sizeof(*cur), |
| 182 | cur); |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 183 | if (ret) { |
| 184 | debug("Failed to write to SPI flash\n"); |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 185 | return log_msg_ret("Cannot update mrccache", ret); |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 190 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 191 | static void mrccache_setup(struct mrc_output *mrc, void *data) |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 192 | { |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 193 | struct mrc_data_container *cache = data; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 194 | u16 checksum; |
| 195 | |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 196 | cache->signature = MRC_DATA_SIGNATURE; |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 197 | cache->data_size = mrc->len; |
| 198 | checksum = compute_ip_checksum(mrc->buf, cache->data_size); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 199 | debug("Saving %d bytes for MRC output data, checksum %04x\n", |
| 200 | cache->data_size, checksum); |
| 201 | cache->checksum = checksum; |
| 202 | cache->reserved = 0; |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 203 | memcpy(cache->data, mrc->buf, cache->data_size); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 204 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 205 | mrc->cache = cache; |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | int mrccache_reserve(void) |
| 209 | { |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 210 | int i; |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 211 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 212 | for (i = 0; i < MRC_TYPE_COUNT; i++) { |
| 213 | struct mrc_output *mrc = &gd->arch.mrc[i]; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 214 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 215 | if (!mrc->len) |
| 216 | continue; |
| 217 | |
| 218 | /* adjust stack pointer to store pure cache data plus header */ |
| 219 | gd->start_addr_sp -= (mrc->len + MRC_DATA_HEADER_SIZE); |
| 220 | mrccache_setup(mrc, (void *)gd->start_addr_sp); |
| 221 | |
| 222 | gd->start_addr_sp &= ~0xf; |
| 223 | } |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 228 | int mrccache_get_region(enum mrc_type_t type, struct udevice **devp, |
| 229 | struct mrc_region *entry) |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 230 | { |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 231 | struct udevice *dev; |
| 232 | ofnode mrc_node; |
Simon Glass | 4e988f9 | 2019-12-06 21:42:04 -0700 | [diff] [blame] | 233 | ulong map_base; |
| 234 | uint map_size; |
| 235 | uint offset; |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 236 | ofnode node; |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 237 | u32 reg[2]; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 238 | int ret; |
| 239 | |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 240 | /* |
| 241 | * Find the flash chip within the SPI controller node. Avoid probing |
| 242 | * the device here since it may put it into a strange state where the |
| 243 | * memory map cannot be read. |
| 244 | */ |
| 245 | ret = uclass_find_first_device(UCLASS_SPI_FLASH, &dev); |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 246 | if (ret || !dev) { |
| 247 | /* |
| 248 | * Fall back to searching the device tree since driver model |
| 249 | * may not be ready yet (e.g. with FSPv1) |
| 250 | */ |
| 251 | node = ofnode_by_compatible(ofnode_null(), "jedec,spi-nor"); |
| 252 | if (!ofnode_valid(node)) |
| 253 | return log_msg_ret("Cannot find SPI flash\n", -ENOENT); |
Simon Glass | 92f9828 | 2020-02-02 13:37:06 -0700 | [diff] [blame] | 254 | ret = -ENODEV; |
Simon Glass | 4e988f9 | 2019-12-06 21:42:04 -0700 | [diff] [blame] | 255 | } else { |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 256 | ret = dm_spi_get_mmap(dev, &map_base, &map_size, &offset); |
| 257 | if (!ret) |
| 258 | entry->base = map_base; |
| 259 | node = dev_ofnode(dev); |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * At this point we have entry->base if ret == 0. If not, then we have |
| 264 | * the node and can look for memory-map |
| 265 | */ |
| 266 | if (ret) { |
| 267 | ret = ofnode_read_u32_array(node, "memory-map", reg, 2); |
Simon Glass | 4e988f9 | 2019-12-06 21:42:04 -0700 | [diff] [blame] | 268 | if (ret) |
| 269 | return log_msg_ret("Cannot find memory map\n", ret); |
| 270 | entry->base = reg[0]; |
| 271 | } |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 272 | |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 273 | /* Find the place where we put the MRC cache */ |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 274 | mrc_node = ofnode_find_subnode(node, type == MRC_TYPE_NORMAL ? |
| 275 | "rw-mrc-cache" : "rw-var-mrc-cache"); |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 276 | if (!ofnode_valid(mrc_node)) |
| 277 | return log_msg_ret("Cannot find node", -EPERM); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 278 | |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 279 | ret = ofnode_read_u32_array(mrc_node, "reg", reg, 2); |
| 280 | if (ret) |
| 281 | return log_msg_ret("Cannot find address", ret); |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 282 | entry->offset = reg[0]; |
| 283 | entry->length = reg[1]; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 284 | |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 285 | if (devp) |
| 286 | *devp = dev; |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 287 | debug("MRC cache type %d in '%s', offset %x, len %x, base %x\n", |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 288 | type, dev ? dev->name : ofnode_get_name(node), entry->offset, |
| 289 | entry->length, entry->base); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 294 | static int mrccache_save_type(enum mrc_type_t type) |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 295 | { |
Simon Glass | c3d0c23 | 2019-12-06 21:42:05 -0700 | [diff] [blame] | 296 | struct mrc_data_container *cache; |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 297 | struct mrc_output *mrc; |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 298 | struct mrc_region entry; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 299 | struct udevice *sf; |
| 300 | int ret; |
| 301 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 302 | mrc = &gd->arch.mrc[type]; |
| 303 | if (!mrc->len) |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 304 | return 0; |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 305 | log_debug("Saving %#x bytes of MRC output data type %d to SPI flash\n", |
| 306 | mrc->len, type); |
| 307 | ret = mrccache_get_region(type, &sf, &entry); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 308 | if (ret) |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 309 | return log_msg_ret("Cannot get region", ret); |
Simon Glass | 9d25f2e | 2019-12-06 21:42:03 -0700 | [diff] [blame] | 310 | ret = device_probe(sf); |
| 311 | if (ret) |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 312 | return log_msg_ret("Cannot probe device", ret); |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 313 | cache = mrc->cache; |
| 314 | |
Simon Glass | c3d0c23 | 2019-12-06 21:42:05 -0700 | [diff] [blame] | 315 | ret = mrccache_update(sf, &entry, cache); |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 316 | if (!ret) |
Simon Glass | c3d0c23 | 2019-12-06 21:42:05 -0700 | [diff] [blame] | 317 | debug("Saved MRC data with checksum %04x\n", cache->checksum); |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 318 | else if (ret == -EEXIST) |
Simon Glass | 9df244f | 2016-01-17 16:11:29 -0700 | [diff] [blame] | 319 | debug("MRC data is the same as last time, skipping save\n"); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 320 | |
Simon Glass | 1b9d815 | 2019-12-06 21:42:06 -0700 | [diff] [blame] | 321 | return 0; |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 322 | } |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 323 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 324 | int mrccache_save(void) |
| 325 | { |
| 326 | int i; |
| 327 | |
| 328 | for (i = 0; i < MRC_TYPE_COUNT; i++) { |
| 329 | int ret; |
| 330 | |
| 331 | ret = mrccache_save_type(i); |
| 332 | if (ret) |
| 333 | return ret; |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 339 | int mrccache_spl_save(void) |
| 340 | { |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 341 | int i; |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 342 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 343 | for (i = 0; i < MRC_TYPE_COUNT; i++) { |
| 344 | struct mrc_output *mrc = &gd->arch.mrc[i]; |
| 345 | void *data; |
| 346 | int size; |
| 347 | |
| 348 | size = mrc->len + MRC_DATA_HEADER_SIZE; |
| 349 | data = malloc(size); |
| 350 | if (!data) |
| 351 | return log_msg_ret("Allocate MRC cache block", -ENOMEM); |
| 352 | mrccache_setup(mrc, data); |
| 353 | } |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 354 | |
| 355 | return mrccache_save(); |
| 356 | } |