qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, joel@jms.id.au, stefanha@redhat.com
Subject: Re: [PATCH] hw/core: properly terminate loading .hex on EOF record
Date: Thu, 2 Apr 2020 23:35:00 +0200	[thread overview]
Message-ID: <1911f95f-3a51-d4fa-59c7-ff5e7ecd5452@redhat.com> (raw)
In-Reply-To: <20200401193849.14017-1-alex.bennee@linaro.org>

On 4/1/20 9:38 PM, Alex Bennée wrote:
> 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>
> ---
>   hw/core/loader.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index eeef6da9a1b..8bbb1797a4c 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':
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



      parent reply	other threads:[~2020-04-02 21:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01 19:38 [PATCH] hw/core: properly terminate loading .hex on EOF record Alex Bennée
2020-04-02  9:09 ` Stefan Hajnoczi
2020-04-02 16:50 ` Richard Henderson
2020-04-02 21:35 ` Philippe Mathieu-Daudé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1911f95f-3a51-d4fa-59c7-ff5e7ecd5452@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=joel@jms.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).