From 696689bfb11933565db8fac6921dcb082abcb2ec Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 21 Apr 2015 15:20:46 -0500 Subject: [PATCH] qemu-armv7: fix cbfs media implementation When using qemu-armv7 to load coreboot.rom with the -kernel flag the rom is offset by 0x10000. Therefore only allow mappings within 0x10000 and 0x10000 + CONFIG_ROM_SIZE. TEST= QEMU_AUDIO_DRV=none qemu-system-arm -M vexpress-a9 \ -m 1024M -nographic \ -kernel coreboot-builds/emulation_qemu-armv7/coreboot.rom Change-Id: Ifec5761a7d54685f664c54efaa31949b8cc94bad Signed-off-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/9935 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Patrick Georgi --- src/mainboard/emulation/qemu-armv7/media.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mainboard/emulation/qemu-armv7/media.c b/src/mainboard/emulation/qemu-armv7/media.c index c3760ab033..8c71263e67 100644 --- a/src/mainboard/emulation/qemu-armv7/media.c +++ b/src/mainboard/emulation/qemu-armv7/media.c @@ -26,7 +26,9 @@ static int emu_rom_open(struct cbfs_media *media) static void *emu_rom_map(struct cbfs_media *media, size_t offset, size_t count) { - return (void*)offset; + if (offset + count > CONFIG_ROM_SIZE) + return (void *)-1; + return (void*)(offset + 0x10000); } static void *emu_rom_unmap(struct cbfs_media *media, const void *address) @@ -38,6 +40,10 @@ static size_t emu_rom_read(struct cbfs_media *media, void *dest, size_t offset, size_t count) { void *ptr = emu_rom_map(media, offset, count); + + if (ptr == (void *)-1) + return 0; + memcpy(dest, ptr, count); emu_rom_unmap(media, ptr); return count;