From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Stephanos Ioannidis <root@stephanos.io>,
Alistair Francis <alistair@alistair23.me>
Cc: Peter Maydell <peter.maydell@linaro.org>,
"open list:ARM TCG CPUs" <qemu-arm@nongnu.org>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Subject: Re: [PATCH v2 2/2] hw/arm/armv7m: Downgrade CPU reset handler priority
Date: Thu, 27 Feb 2020 14:31:23 +0100 [thread overview]
Message-ID: <88ad7129-9654-088d-6569-066949973a86@redhat.com> (raw)
In-Reply-To: <20200227115005.66349-3-root@stephanos.io>
Hi Stephanos,
On 2/27/20 12:51 PM, Stephanos Ioannidis wrote:
> The ARMv7-M CPU reset handler, which loads the initial SP and PC
> register values from the vector table, is currently executed before
> the ROM reset handler (rom_reset), and this causes the devices that
> alias low memory region (e.g. STM32F405 that aliases the flash memory
> located at 0x8000000 to 0x0) to load an invalid reset vector of 0 when
> the kernel image is linked to be loaded at the high memory address.
So we have armv7m_load_kernel -> load_elf_as -> rom_add_blob_fixed_as ->
rom_add_blob -> rom_insert.
arm_cpu_reset is called before rom_reset, rom_ptr is NULL, we call
initial_pc = ldl_phys(cpu_as) from an empty flash.
Then later rom_reset -> address_space_write_rom.
I think Alistair and myself use the 'loader' device with Cortex-M boards
and never hit this problem.
>
> For instance, it is norm for the STM32F405 firmware ELF image to have
> the text and rodata sections linked at 0x8000000, as this facilitates
> proper image loading by the firmware burning utility, and the processor
> can execute in place from the high flash memory address region as well.
>
> In order to resolve this issue, this commit downgrades the ARMCPU reset
> handler invocation priority level to -1 such that it is always executed
> after the ROM reset handler, which has a priority level of 0.
>
> Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
> ---
> hw/arm/armv7m.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
> index 7531b97ccd..8b7c4b12a6 100644
> --- a/hw/arm/armv7m.c
> +++ b/hw/arm/armv7m.c
> @@ -352,7 +352,8 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
> * way A-profile does it. Note that this means that every M profile
> * board must call this function!
> */
> - qemu_register_reset(armv7m_reset, cpu);
> + qemu_register_reset_with_priority(
> + QEMU_RESET_PRIORITY_LEVEL(-1), armv7m_reset, cpu);
> }
>
> static Property bitband_properties[] = {
>
next prev parent reply other threads:[~2020-02-27 13:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200227115005.66349-1-root@stephanos.io>
2020-02-27 11:51 ` [PATCH v2 1/2] hw/core: Support device reset handler priority Stephanos Ioannidis
2020-02-27 11:51 ` [PATCH v2 2/2] hw/arm/armv7m: Downgrade CPU " Stephanos Ioannidis
2020-02-27 13:31 ` Philippe Mathieu-Daudé [this message]
2020-02-27 21:30 ` Alistair Francis
2020-02-27 21:44 ` Peter Maydell
2020-02-27 21:41 ` Alistair Francis
2020-02-27 11:58 ` [PATCH v2 0/2] Support device reset handler priority configuration Stephanos Ioannidis
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=88ad7129-9654-088d-6569-066949973a86@redhat.com \
--to=philmd@redhat.com \
--cc=alistair@alistair23.me \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=root@stephanos.io \
/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).