diff options
author | Aaron Durbin <adurbin@chromium.org> | 2015-05-15 15:57:51 -0500 |
---|---|---|
committer | Aaron Durbin <adurbin@chromium.org> | 2015-05-26 22:33:35 +0200 |
commit | b6981c0f9c4ce89c4209c14fb326a414096f2ff1 (patch) | |
tree | 604e3df8ef60b2a962f19be791bba4398ab868a9 /src/vendorcode/google/chromeos/vboot_common.c | |
parent | b59eaf6ca88267baf28cb318117696df1fb03fee (diff) | |
download | coreboot-b6981c0f9c4ce89c4209c14fb326a414096f2ff1.tar.xz |
vboot: use only offsets for tracking firmware components
Because of the fmap API returning pointers to represent
regions within the boot device a vboot_region structure
was used to track the case where offsets could be pointers
on x86 but not on !x86. Normalize this tracking to use
offsets only as it provides consistency in the code.
Change-Id: I63c08b31ace3bd0e66ebc17e308f87eb5f857c86
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10221
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/vendorcode/google/chromeos/vboot_common.c')
-rw-r--r-- | src/vendorcode/google/chromeos/vboot_common.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/src/vendorcode/google/chromeos/vboot_common.c b/src/vendorcode/google/chromeos/vboot_common.c index dfaefdba41..f593c7b43b 100644 --- a/src/vendorcode/google/chromeos/vboot_common.c +++ b/src/vendorcode/google/chromeos/vboot_common.c @@ -18,7 +18,7 @@ */ #include <boot/coreboot_tables.h> -#include <cbfs.h> +#include <boot_device.h> #include <cbmem.h> #include <console/cbmem_console.h> #include <console/console.h> @@ -31,36 +31,42 @@ #include "vboot_common.h" #include "vboot_handoff.h" -void vboot_locate_region(const char *name, struct vboot_region *region) +void vboot_locate_region(const char *name, struct region *region) { - region->size = find_fmap_entry(name, (void **)®ion->offset_addr); + const struct fmap_area *area; + + region->size = 0; + + area = find_fmap_area(fmap_find(), name); + + if (area != NULL) { + region->offset = area->offset; + region->size = area->size; + } } -void *vboot_get_region(uintptr_t offset_addr, size_t size, void *dest) +void *vboot_get_region(size_t offset, size_t size, void *dest) { - if (IS_ENABLED(CONFIG_SPI_FLASH_MEMORY_MAPPED)) { - if (dest != NULL) - return memcpy(dest, (void *)offset_addr, size); - else - return (void *)offset_addr; - } else { - struct cbfs_media default_media, *media = &default_media; - void *cache; - - init_default_cbfs_media(media); - media->open(media); - if (dest != NULL) { - cache = dest; - if (media->read(media, dest, offset_addr, size) != size) - cache = NULL; - } else { - cache = media->map(media, offset_addr, size); - if (cache == CBFS_MEDIA_INVALID_MAP_ADDRESS) - cache = NULL; - } - media->close(media); - return cache; - } + const struct region_device *boot_dev; + struct region_device rdev; + + boot_device_init(); + boot_dev = boot_device_ro(); + + if (boot_dev == NULL) + return NULL; + + if (rdev_chain(&rdev, boot_dev, offset, size)) + return NULL; + + /* Each call will leak a mapping. */ + if (dest == NULL) + return rdev_mmap_full(&rdev); + + if (rdev_readat(&rdev, dest, 0, size) != size) + return NULL; + + return dest; } int vboot_get_handoff_info(void **addr, uint32_t *size) @@ -78,7 +84,7 @@ int vboot_get_handoff_info(void **addr, uint32_t *size) } /* This will leak a mapping of a fw region */ -struct vboot_components *vboot_locate_components(struct vboot_region *region) +struct vboot_components *vboot_locate_components(struct region *region) { size_t req_size; struct vboot_components *vbc; @@ -87,7 +93,7 @@ struct vboot_components *vboot_locate_components(struct vboot_region *region) req_size += sizeof(struct vboot_component_entry) * MAX_PARSED_FW_COMPONENTS; - vbc = vboot_get_region(region->offset_addr, req_size, NULL); + vbc = vboot_get_region(region_offset(region), req_size, NULL); if (vbc && vbc->num_components > MAX_PARSED_FW_COMPONENTS) vbc = NULL; |