diff options
author | Alex Bennée <alex.bennee@linaro.org> | 2020-04-03 20:11:49 +0100 |
---|---|---|
committer | Alex Bennée <alex.bennee@linaro.org> | 2020-04-07 16:19:49 +0100 |
commit | 58d5e749d6663701f90931764f8bee6c76b0b1f1 (patch) | |
tree | 0f1b7452c41f0c585b4ae90a54b0a0be2d6587db /hw/core/loader.c | |
parent | bb55173cfb7bd69b79c4092bf524a32b0fdeddbb (diff) |
hw/core: properly terminate loading .hex on EOF record
The https://makecode.microbit.org/#editor generates slightly weird
.hex files which work fine on a real microbit but causes QEMU to
choke. The reason is extraneous data after the EOF record which causes
the loader to attempt to write a bigger file than it should to the
"rom". According to the HEX file spec an EOF really should be the last
thing we process so lets do that.
Reported-by: Ursula Bennée <alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200403191150.863-12-alex.bennee@linaro.org>
Diffstat (limited to 'hw/core/loader.c')
-rw-r--r-- | hw/core/loader.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/hw/core/loader.c b/hw/core/loader.c index eeef6da9a1..8bbb1797a4 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1447,6 +1447,7 @@ typedef struct { uint32_t current_rom_index; uint32_t rom_start_address; AddressSpace *as; + bool complete; } HexParser; /* return size or -1 if error */ @@ -1484,6 +1485,7 @@ static int handle_record_type(HexParser *parser) parser->current_rom_index, parser->rom_start_address, parser->as); } + parser->complete = true; return parser->total_size; case EXT_SEG_ADDR_RECORD: case EXT_LINEAR_ADDR_RECORD: @@ -1548,11 +1550,12 @@ static int parse_hex_blob(const char *filename, hwaddr *addr, uint8_t *hex_blob, .bin_buf = g_malloc(hex_blob_size), .start_addr = addr, .as = as, + .complete = false }; rom_transaction_begin(); - for (; hex_blob < end; ++hex_blob) { + for (; hex_blob < end && !parser.complete; ++hex_blob) { switch (*hex_blob) { case '\r': case '\n': |