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 <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/9935
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Aaron Durbin 2015-04-21 15:20:46 -05:00
parent 69cb2c2b5e
commit 696689bfb1
1 changed files with 7 additions and 1 deletions

View File

@ -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;