Message ID | 1614758717-18223-1-git-send-email-dillon.minfei@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | ARM: STM32: add art-pi(stm32h750xbh6) board support | expand |
On 3/3/21 8:05 AM, dillon.minfei@gmail.com wrote: > From: dillon min <dillon.minfei@gmail.com> > > For some case, kernel not boot by u-boot(single thread), > but by rtos , as most rtos use pendsv to do context switch. Hmm, does it mean that it starts kernel from process context? I'd assume that it is not only kernel who expects MSP. So, what if RTOS you mentioned want to boot other RTOS (even itself)? What if you have no access to the source code for those RTOS(es) to patch MSP/PSP switch? I'd very much prefer to keep stack switching logic outside kernel, say, in some shim which RTOS/bootloader can maintain. Cheers Vladimir > > So, we need add an lr check after svc call, to find out should > use psp or msp. else register restore after svc call might be > corrupted. > > Fixes: b70cd406d7fe ("ARM: 8671/1: V7M: Preserve registers across switch from Thread to Handler mode") > Signed-off-by: dillon min <dillon.minfei@gmail.com> > --- > arch/arm/mm/proc-v7m.S | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S > index 84459c1d31b8..c93d2757312d 100644 > --- a/arch/arm/mm/proc-v7m.S > +++ b/arch/arm/mm/proc-v7m.S > @@ -137,7 +137,10 @@ __v7m_setup_cont: > 1: cpsid i > /* Calculate exc_ret */ > orr r10, lr, #EXC_RET_THREADMODE_PROCESSSTACK > - ldmia sp, {r0-r3, r12} > + tst lr, #EXC_RET_STACK_MASK > + mrsne r4, psp > + moveq r4, sp > + ldmia r4!, {r0-r3, r12} > str r5, [r12, #11 * 4] @ restore the original SVC vector entry > mov lr, r6 @ restore LR > >
Hi Vladimir, Thanks for the review. On Wed, Mar 3, 2021 at 5:52 PM Vladimir Murzin <vladimir.murzin@arm.com> wrote: > > On 3/3/21 8:05 AM, dillon.minfei@gmail.com wrote: > > From: dillon min <dillon.minfei@gmail.com> > > > > For some case, kernel not boot by u-boot(single thread), > > but by rtos , as most rtos use pendsv to do context switch. > > > Hmm, does it mean that it starts kernel from process context? Yes, kernel might be started from process context, since u-boot not switch context, so kernel always startup under msp. > > I'd assume that it is not only kernel who expects MSP. So, what > if RTOS you mentioned want to boot other RTOS (even itself)? What > if you have no access to the source code for those RTOS(es) to > patch MSP/PSP switch? My case is a little complicated. stm32h7 only have 128Kbytes internal flash, can't store u-boot.bin (>200K), so, set a bootloader (rt-thread rtos) to internal flash, load linux/u-boot from serial port via ymodem store to qspi flash(8Mbytes), then jump to u-boot. qspi flash layout: 0 - 512K: u-boot 512K- 8M : kernel(xip) load process : rt-thread -> u-boot -> linux before add psp/msp check after svc call, register restore corrupt. add a printhex8 around svc call, found the sp stack is 0x24040000c0ffcff8 it should be 0xc0ffcdf8c0ffcff8. 0x24040000 is the sp stack address assigned by u-boot i've no idea how it's become to u-boot's sp. I have the rtos code, and will try to fix it on the rtos side. Can you give more explanation about why linux relies on MSP ? thanks > > I'd very much prefer to keep stack switching logic outside kernel, > say, in some shim which RTOS/bootloader can maintain. > > Cheers > Vladimir > > > > > So, we need add an lr check after svc call, to find out should > > use psp or msp. else register restore after svc call might be > > corrupted. > > > > Fixes: b70cd406d7fe ("ARM: 8671/1: V7M: Preserve registers across switch from Thread to Handler mode") > > Signed-off-by: dillon min <dillon.minfei@gmail.com> > > --- > > arch/arm/mm/proc-v7m.S | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S > > index 84459c1d31b8..c93d2757312d 100644 > > --- a/arch/arm/mm/proc-v7m.S > > +++ b/arch/arm/mm/proc-v7m.S > > @@ -137,7 +137,10 @@ __v7m_setup_cont: > > 1: cpsid i > > /* Calculate exc_ret */ > > orr r10, lr, #EXC_RET_THREADMODE_PROCESSSTACK > > - ldmia sp, {r0-r3, r12} > > + tst lr, #EXC_RET_STACK_MASK > > + mrsne r4, psp > > + moveq r4, sp > > + ldmia r4!, {r0-r3, r12} > > str r5, [r12, #11 * 4] @ restore the original SVC vector entry > > mov lr, r6 @ restore LR > > > > >
On Wed, Mar 3, 2021 at 10:19 PM Vladimir Murzin <vladimir.murzin@arm.com> wrote: > > On 3/3/21 1:35 PM, dillon min wrote: > > Hi Vladimir, > > > > Thanks for the review. > > > > On Wed, Mar 3, 2021 at 5:52 PM Vladimir Murzin <vladimir.murzin@arm.com> wrote: > >> > >> On 3/3/21 8:05 AM, dillon.minfei@gmail.com wrote: > >>> From: dillon min <dillon.minfei@gmail.com> > >>> > >>> For some case, kernel not boot by u-boot(single thread), > >>> but by rtos , as most rtos use pendsv to do context switch. > >> > >> > >> Hmm, does it mean that it starts kernel from process context? > > Yes, kernel might be started from process context, since u-boot not > > switch context, so kernel always startup under msp. > >> > >> I'd assume that it is not only kernel who expects MSP. So, what > >> if RTOS you mentioned want to boot other RTOS (even itself)? What > >> if you have no access to the source code for those RTOS(es) to > >> patch MSP/PSP switch? > > > > My case is a little complicated. > > stm32h7 only have 128Kbytes internal flash, can't store u-boot.bin (>200K), > > so, set a bootloader (rt-thread rtos) to internal flash, load > > linux/u-boot from serial port via ymodem > > store to qspi flash(8Mbytes), then jump to u-boot. > > > > qspi flash layout: > > 0 - 512K: u-boot > > 512K- 8M : kernel(xip) > > > > load process : rt-thread -> u-boot -> linux > > > > before add psp/msp check after svc call, register restore corrupt. > > add a printhex8 around svc call, found the sp stack is 0x24040000c0ffcff8 > > it should be 0xc0ffcdf8c0ffcff8. 0x24040000 is the sp stack address > > assigned by u-boot > > i've no idea how it's become to u-boot's sp. > > > > I have the rtos code, and will try to fix it on the rtos side. > > That would be great! > > > > > Can you give more explanation about why linux relies on MSP ? thanks > > MSP is what set from boot, thus it is natural assumption that boot code > would preserve that illusion. > > I'd guess that kernel is in line in such assumption across different > (RT)OS capable to run on M-class cores (please, note that some variants > might not have two stack pointers) > Okay, got it. after adding msp/psp switch code in RTOS, now the kernel can be loaded normally without any modification. So, just drop the changes in proc-v7m.S. Thanks. > Cheers > Vladimir > > > > >> > >> I'd very much prefer to keep stack switching logic outside kernel, > >> say, in some shim which RTOS/bootloader can maintain. > >> > >> Cheers > >> Vladimir > >> > >>> > >>> So, we need add an lr check after svc call, to find out should > >>> use psp or msp. else register restore after svc call might be > >>> corrupted. > >>> > >>> Fixes: b70cd406d7fe ("ARM: 8671/1: V7M: Preserve registers across switch from Thread to Handler mode") > >>> Signed-off-by: dillon min <dillon.minfei@gmail.com> > >>> --- > >>> arch/arm/mm/proc-v7m.S | 5 ++++- > >>> 1 file changed, 4 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S > >>> index 84459c1d31b8..c93d2757312d 100644 > >>> --- a/arch/arm/mm/proc-v7m.S > >>> +++ b/arch/arm/mm/proc-v7m.S > >>> @@ -137,7 +137,10 @@ __v7m_setup_cont: > >>> 1: cpsid i > >>> /* Calculate exc_ret */ > >>> orr r10, lr, #EXC_RET_THREADMODE_PROCESSSTACK > >>> - ldmia sp, {r0-r3, r12} > >>> + tst lr, #EXC_RET_STACK_MASK > >>> + mrsne r4, psp > >>> + moveq r4, sp > >>> + ldmia r4!, {r0-r3, r12} > >>> str r5, [r12, #11 * 4] @ restore the original SVC vector entry > >>> mov lr, r6 @ restore LR > >>> > >>> > >> > > >
On 3/4/21 5:42 AM, dillon min wrote: > Okay, got it. after adding msp/psp switch code in RTOS, now the kernel > can be loaded normally > without any modification. Yay! > > So, just drop the changes in proc-v7m.S. Glad to see they are not strictly necessary :) Thanks Vladimir
for the device tree part , still waiting review. just a gentle ping. if Mr Alexandre torgue can take a look, would be great. thanks, On Wed, Mar 3, 2021 at 4:05 PM <dillon.minfei@gmail.com> wrote: > > From: dillon min <dillon.minfei@gmail.com> > > This patchset intend to add art-pi board support, this board developed > by rt-thread(https://www.rt-thread.org/). > > Board resources: > > 8MiB QSPI flash > 16MiB SPI flash > 32MiB SDRAM > AP6212 wifi,bt,fm comb > > sw context: > - as stm32h750 just has 128k bytes internal flash, so running a fw on > internal flash to download u-boot/kernel to qspi flash, boot > u-boot/kernel from qspi flash. this fw is based on rt-thread. > - kernel can be xip on qspi flash or load to sdram > - root filesystem is jffs2(created by buildroot), stored on spi flash > > to support the boad, add following changes. > - fix r0-r3, r12 register restore failed after svc call, > - add dts binding > - update yaml doc > > dillon min (8): > ARM: ARMv7-M: Fix register restore corrupt after svc call > Documentation: arm: stm32: Add stm32h750 value line > dt-bindings: arm: stm32: Add compatible strings for ART-PI board > dt-bindings: pinctrl: stm32: Add stm32h750 pinctrl > ARM: dts: stm32: introduce stm32h7-pinctrl.dtsi to support stm32h75x > ARM: dts: stm32: add stm32h750-pinctrl.dtsi > ARM: dts: stm32: add support for art-pi board based on stm32h750xbh6 > ARM: stm32: add initial support for stm32h750 > > Documentation/arm/index.rst | 1 + > Documentation/arm/stm32/stm32h750-overview.rst | 33 ++ > .../devicetree/bindings/arm/stm32/stm32.yaml | 4 + > .../bindings/pinctrl/st,stm32-pinctrl.yaml | 1 + > arch/arm/boot/dts/Makefile | 1 + > arch/arm/boot/dts/stm32h7-pinctrl.dtsi | 392 +++++++++++++++++++++ > arch/arm/boot/dts/stm32h743-pinctrl.dtsi | 307 +--------------- > arch/arm/boot/dts/stm32h743.dtsi | 30 ++ > arch/arm/boot/dts/stm32h750-pinctrl.dtsi | 11 + > arch/arm/boot/dts/stm32h750.dtsi | 5 + > arch/arm/boot/dts/stm32h750i-art-pi.dts | 227 ++++++++++++ > arch/arm/mach-stm32/board-dt.c | 1 + > arch/arm/mm/proc-v7m.S | 5 +- > 13 files changed, 716 insertions(+), 302 deletions(-) > create mode 100644 Documentation/arm/stm32/stm32h750-overview.rst > create mode 100644 arch/arm/boot/dts/stm32h7-pinctrl.dtsi > create mode 100644 arch/arm/boot/dts/stm32h750-pinctrl.dtsi > create mode 100644 arch/arm/boot/dts/stm32h750.dtsi > create mode 100644 arch/arm/boot/dts/stm32h750i-art-pi.dts > > -- > 2.7.4 >
Hi Dillon > -----Original Message----- > From: dillon min <dillon.minfei@gmail.com> > Sent: mercredi 10 mars 2021 12:48 > To: Rob Herring <robh+dt@kernel.org>; Maxime Coquelin > <mcoquelin.stm32@gmail.com>; Alexandre TORGUE > <alexandre.torgue@st.com>; open list:OPEN FIRMWARE AND FLATTENED > DEVICE TREE BINDINGS <devicetree@vger.kernel.org>; linux-stm32@st-md- > mailman.stormreply.com; Linux ARM <linux-arm- > kernel@lists.infradead.org>; Linux Kernel Mailing List <linux- > kernel@vger.kernel.org>; linux@armlinux.org.uk; Vladimir Murzin > <vladimir.murzin@arm.com>; afzal.mohd.ma@gmail.com > Subject: Re: [PATCH 0/8] ARM: STM32: add art-pi(stm32h750xbh6) board > support > > for the device tree part , still waiting review. just a gentle ping. > if Mr Alexandre torgue can take a look, would be great. > Sorry for the delay. For next versions can you send it to Alexandre.torgue@foss.st.com please. Thanks Alex > thanks, > > On Wed, Mar 3, 2021 at 4:05 PM <dillon.minfei@gmail.com> wrote: > > > > From: dillon min <dillon.minfei@gmail.com> > > > > This patchset intend to add art-pi board support, this board developed > > by rt-thread(https://www.rt-thread.org/). > > > > Board resources: > > > > 8MiB QSPI flash > > 16MiB SPI flash > > 32MiB SDRAM > > AP6212 wifi,bt,fm comb > > > > sw context: > > - as stm32h750 just has 128k bytes internal flash, so running a fw on > > internal flash to download u-boot/kernel to qspi flash, boot > > u-boot/kernel from qspi flash. this fw is based on rt-thread. > > - kernel can be xip on qspi flash or load to sdram > > - root filesystem is jffs2(created by buildroot), stored on spi flash > > > > to support the boad, add following changes. > > - fix r0-r3, r12 register restore failed after svc call, > > - add dts binding > > - update yaml doc > > > > dillon min (8): > > ARM: ARMv7-M: Fix register restore corrupt after svc call > > Documentation: arm: stm32: Add stm32h750 value line > > dt-bindings: arm: stm32: Add compatible strings for ART-PI board > > dt-bindings: pinctrl: stm32: Add stm32h750 pinctrl > > ARM: dts: stm32: introduce stm32h7-pinctrl.dtsi to support stm32h75x > > ARM: dts: stm32: add stm32h750-pinctrl.dtsi > > ARM: dts: stm32: add support for art-pi board based on stm32h750xbh6 > > ARM: stm32: add initial support for stm32h750 > > > > Documentation/arm/index.rst | 1 + > > Documentation/arm/stm32/stm32h750-overview.rst | 33 ++ > > .../devicetree/bindings/arm/stm32/stm32.yaml | 4 + > > .../bindings/pinctrl/st,stm32-pinctrl.yaml | 1 + > > arch/arm/boot/dts/Makefile | 1 + > > arch/arm/boot/dts/stm32h7-pinctrl.dtsi | 392 > +++++++++++++++++++++ > > arch/arm/boot/dts/stm32h743-pinctrl.dtsi | 307 +--------------- > > arch/arm/boot/dts/stm32h743.dtsi | 30 ++ > > arch/arm/boot/dts/stm32h750-pinctrl.dtsi | 11 + > > arch/arm/boot/dts/stm32h750.dtsi | 5 + > > arch/arm/boot/dts/stm32h750i-art-pi.dts | 227 ++++++++++++ > > arch/arm/mach-stm32/board-dt.c | 1 + > > arch/arm/mm/proc-v7m.S | 5 +- > > 13 files changed, 716 insertions(+), 302 deletions(-) create mode > > 100644 Documentation/arm/stm32/stm32h750-overview.rst > > create mode 100644 arch/arm/boot/dts/stm32h7-pinctrl.dtsi > > create mode 100644 arch/arm/boot/dts/stm32h750-pinctrl.dtsi > > create mode 100644 arch/arm/boot/dts/stm32h750.dtsi create mode > > 100644 arch/arm/boot/dts/stm32h750i-art-pi.dts > > > > -- > > 2.7.4 > >
Hi Alexandre, Thanks for quickly responding. On Thu, Mar 11, 2021 at 6:26 PM Alexandre TORGUE <alexandre.torgue@st.com> wrote: > > Hi Dillon > > > -----Original Message----- > > From: dillon min <dillon.minfei@gmail.com> > > Sent: mercredi 10 mars 2021 12:48 > > To: Rob Herring <robh+dt@kernel.org>; Maxime Coquelin > > <mcoquelin.stm32@gmail.com>; Alexandre TORGUE > > <alexandre.torgue@st.com>; open list:OPEN FIRMWARE AND FLATTENED > > DEVICE TREE BINDINGS <devicetree@vger.kernel.org>; linux-stm32@st-md- > > mailman.stormreply.com; Linux ARM <linux-arm- > > kernel@lists.infradead.org>; Linux Kernel Mailing List <linux- > > kernel@vger.kernel.org>; linux@armlinux.org.uk; Vladimir Murzin > > <vladimir.murzin@arm.com>; afzal.mohd.ma@gmail.com > > Subject: Re: [PATCH 0/8] ARM: STM32: add art-pi(stm32h750xbh6) board > > support > > > > for the device tree part , still waiting review. just a gentle ping. > > if Mr Alexandre torgue can take a look, would be great. > > > > Sorry for the delay. For next versions can you send it to > Alexandre.torgue@foss.st.com please Okay, I will add your new e-mail address to next review mailing list. > > Thanks > Alex > > > thanks, > > > > On Wed, Mar 3, 2021 at 4:05 PM <dillon.minfei@gmail.com> wrote: > > > > > > From: dillon min <dillon.minfei@gmail.com> > > > > > > This patchset intend to add art-pi board support, this board developed > > > by rt-thread(https://www.rt-thread.org/). > > > > > > Board resources: > > > > > > 8MiB QSPI flash > > > 16MiB SPI flash > > > 32MiB SDRAM > > > AP6212 wifi,bt,fm comb > > > > > > sw context: > > > - as stm32h750 just has 128k bytes internal flash, so running a fw on > > > internal flash to download u-boot/kernel to qspi flash, boot > > > u-boot/kernel from qspi flash. this fw is based on rt-thread. > > > - kernel can be xip on qspi flash or load to sdram > > > - root filesystem is jffs2(created by buildroot), stored on spi flash > > > > > > to support the boad, add following changes. > > > - fix r0-r3, r12 register restore failed after svc call, > > > - add dts binding > > > - update yaml doc > > > > > > dillon min (8): > > > ARM: ARMv7-M: Fix register restore corrupt after svc call > > > Documentation: arm: stm32: Add stm32h750 value line > > > dt-bindings: arm: stm32: Add compatible strings for ART-PI board > > > dt-bindings: pinctrl: stm32: Add stm32h750 pinctrl > > > ARM: dts: stm32: introduce stm32h7-pinctrl.dtsi to support stm32h75x > > > ARM: dts: stm32: add stm32h750-pinctrl.dtsi > > > ARM: dts: stm32: add support for art-pi board based on stm32h750xbh6 > > > ARM: stm32: add initial support for stm32h750 > > > > > > Documentation/arm/index.rst | 1 + > > > Documentation/arm/stm32/stm32h750-overview.rst | 33 ++ > > > .../devicetree/bindings/arm/stm32/stm32.yaml | 4 + > > > .../bindings/pinctrl/st,stm32-pinctrl.yaml | 1 + > > > arch/arm/boot/dts/Makefile | 1 + > > > arch/arm/boot/dts/stm32h7-pinctrl.dtsi | 392 > > +++++++++++++++++++++ > > > arch/arm/boot/dts/stm32h743-pinctrl.dtsi | 307 +--------------- > > > arch/arm/boot/dts/stm32h743.dtsi | 30 ++ > > > arch/arm/boot/dts/stm32h750-pinctrl.dtsi | 11 + > > > arch/arm/boot/dts/stm32h750.dtsi | 5 + > > > arch/arm/boot/dts/stm32h750i-art-pi.dts | 227 ++++++++++++ > > > arch/arm/mach-stm32/board-dt.c | 1 + > > > arch/arm/mm/proc-v7m.S | 5 +- > > > 13 files changed, 716 insertions(+), 302 deletions(-) create mode > > > 100644 Documentation/arm/stm32/stm32h750-overview.rst > > > create mode 100644 arch/arm/boot/dts/stm32h7-pinctrl.dtsi > > > create mode 100644 arch/arm/boot/dts/stm32h750-pinctrl.dtsi > > > create mode 100644 arch/arm/boot/dts/stm32h750.dtsi create mode > > > 100644 arch/arm/boot/dts/stm32h750i-art-pi.dts > > > > > > -- > > > 2.7.4 > > >
From: dillon min <dillon.minfei@gmail.com> This patchset intend to add art-pi board support, this board developed by rt-thread(https://www.rt-thread.org/). Board resources: 8MiB QSPI flash 16MiB SPI flash 32MiB SDRAM AP6212 wifi,bt,fm comb sw context: - as stm32h750 just has 128k bytes internal flash, so running a fw on internal flash to download u-boot/kernel to qspi flash, boot u-boot/kernel from qspi flash. this fw is based on rt-thread. - kernel can be xip on qspi flash or load to sdram - root filesystem is jffs2(created by buildroot), stored on spi flash to support the boad, add following changes. - fix r0-r3, r12 register restore failed after svc call, - add dts binding - update yaml doc dillon min (8): ARM: ARMv7-M: Fix register restore corrupt after svc call Documentation: arm: stm32: Add stm32h750 value line dt-bindings: arm: stm32: Add compatible strings for ART-PI board dt-bindings: pinctrl: stm32: Add stm32h750 pinctrl ARM: dts: stm32: introduce stm32h7-pinctrl.dtsi to support stm32h75x ARM: dts: stm32: add stm32h750-pinctrl.dtsi ARM: dts: stm32: add support for art-pi board based on stm32h750xbh6 ARM: stm32: add initial support for stm32h750 Documentation/arm/index.rst | 1 + Documentation/arm/stm32/stm32h750-overview.rst | 33 ++ .../devicetree/bindings/arm/stm32/stm32.yaml | 4 + .../bindings/pinctrl/st,stm32-pinctrl.yaml | 1 + arch/arm/boot/dts/Makefile | 1 + arch/arm/boot/dts/stm32h7-pinctrl.dtsi | 392 +++++++++++++++++++++ arch/arm/boot/dts/stm32h743-pinctrl.dtsi | 307 +--------------- arch/arm/boot/dts/stm32h743.dtsi | 30 ++ arch/arm/boot/dts/stm32h750-pinctrl.dtsi | 11 + arch/arm/boot/dts/stm32h750.dtsi | 5 + arch/arm/boot/dts/stm32h750i-art-pi.dts | 227 ++++++++++++ arch/arm/mach-stm32/board-dt.c | 1 + arch/arm/mm/proc-v7m.S | 5 +- 13 files changed, 716 insertions(+), 302 deletions(-) create mode 100644 Documentation/arm/stm32/stm32h750-overview.rst create mode 100644 arch/arm/boot/dts/stm32h7-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stm32h750-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stm32h750.dtsi create mode 100644 arch/arm/boot/dts/stm32h750i-art-pi.dts