fmap: allocate memory as much as discovered fmap size
fmap_find used to read 4096 bytes from the fmap offset blindly. instead, we read the fmap header first to calcurate the size of the fmap. Then, we read flash again exactly as much as the discovered fmap. BUG=none BRANCH=ToT TEST=Booted Storm and Peppy. Built all current boards. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ie5058d181e6565acb70bf108464682dd0e6c1f64 Reviewed-on: https://chromium-review.googlesource.com/231685 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
2f6a6c8497
commit
755ff66ab0
1 changed files with 45 additions and 20 deletions
|
|
@ -24,6 +24,21 @@
|
|||
#include <cbfs.h>
|
||||
#include "fmap.h"
|
||||
|
||||
static int is_fmap_signature_valid(const struct fmap *fmap)
|
||||
{
|
||||
if (memcmp(fmap, FMAP_SIGNATURE, sizeof(FMAP_SIGNATURE) - 1)) {
|
||||
printk(BIOS_ERR, "No FMAP found at %p.\n", fmap);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printk(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %p.\n",
|
||||
fmap->name, fmap->ver_major, fmap->ver_minor, fmap);
|
||||
printk(BIOS_DEBUG, "FMAP: base = %llx size = %x #areas = %d\n",
|
||||
(unsigned long long)fmap->base, fmap->size, fmap->nareas);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find FMAP data structure in ROM.
|
||||
* See http://code.google.com/p/flashmap/ for more information on FMAP.
|
||||
*/
|
||||
|
|
@ -36,32 +51,42 @@ const struct fmap *fmap_find(void)
|
|||
* master header; that would require some more changes to cbfstool
|
||||
* and possibly cros_bundle_firmware.
|
||||
*/
|
||||
const struct fmap *fmap;
|
||||
struct cbfs_media media;
|
||||
size_t size;
|
||||
|
||||
#if CONFIG_ARCH_X86
|
||||
/* wrapping around 0x100000000 */
|
||||
const struct fmap *fmap = (void *)
|
||||
(CONFIG_FLASHMAP_OFFSET - CONFIG_ROM_SIZE);
|
||||
#else
|
||||
struct cbfs_media default_media, *media;
|
||||
media = &default_media;
|
||||
init_default_cbfs_media(media);
|
||||
media->open(media);
|
||||
const struct fmap *fmap = (void *)
|
||||
media->map(media, CONFIG_FLASHMAP_OFFSET, 4096); // FIXME size
|
||||
media->close(media);
|
||||
#endif
|
||||
|
||||
if (fmap == CBFS_MEDIA_INVALID_MAP_ADDRESS ||
|
||||
memcmp(fmap, FMAP_SIGNATURE, sizeof(FMAP_SIGNATURE) - 1)) {
|
||||
printk(BIOS_DEBUG, "No FMAP found at %p.\n", fmap);
|
||||
if (init_default_cbfs_media(&media)) {
|
||||
printk(BIOS_ERR, "failed to init default cbfs media\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printk(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %p.\n",
|
||||
fmap->name, fmap->ver_major, fmap->ver_minor, fmap);
|
||||
printk(BIOS_DEBUG, "FMAP: base = %llx size = %x #areas = %d\n",
|
||||
(unsigned long long)fmap->base, fmap->size, fmap->nareas);
|
||||
media.open(&media);
|
||||
fmap = media.map(&media, CONFIG_FLASHMAP_OFFSET, sizeof(*fmap));
|
||||
|
||||
if (fmap == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
|
||||
printk(BIOS_ERR, "failed to map FMAP header\n");
|
||||
media.close(&media);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (is_fmap_signature_valid(fmap)) {
|
||||
media.unmap(&media, fmap);
|
||||
media.close(&media);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = sizeof(*fmap) + sizeof(struct fmap_area) * fmap->nareas;
|
||||
media.unmap(&media, fmap);
|
||||
fmap = media.map(&media, CONFIG_FLASHMAP_OFFSET, size);
|
||||
|
||||
if (fmap == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
|
||||
printk(BIOS_ERR, "failed to map FMAP (size=%zu)\n", size);
|
||||
media.unmap(&media, fmap);
|
||||
media.close(&media);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
media.close(&media);
|
||||
return fmap;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue