Skip to content

Conversation

@iuliana-prodan
Copy link
Contributor

@iuliana-prodan iuliana-prodan commented May 19, 2021

Add support for i.MX to build Sound Open Firmware with Zephyr OS.

Please check each commit message.

With these commits I have a successful build.
I obtain the zephyr.ri image which boots the DSP and loads the topology.

root@imx8qmmek:~# ./loadSof.sh 
[  166.405965] sof-audio-of 556e8000.dsp: DT DSP detected
[  166.416971] imx-dsp imx-dsp: NXP i.MX DSP IPC initialized
[  166.430784] sof-audio-of 556e8000.dsp: warning: unknown sof_ext_man header type 5 size 0x20
[  166.439213] sof-audio-of 556e8000.dsp: warning: unknown sof_ext_man header type 3 size 0x30
[  166.447885] sof-audio-of 556e8000.dsp: Firmware info: version 1:8:0-cf919
[  166.454703] sof-audio-of 556e8000.dsp: Firmware: ABI 3:19:0 Kernel ABI 3:17:0
[  166.461862] sof-audio-of 556e8000.dsp: warn: FW ABI is more recent than kernel
[  166.469453] sof-audio-of 556e8000.dsp: Firmware info: version 1:8:0-cf919
[  166.476264] sof-audio-of 556e8000.dsp: Firmware: ABI 3:19:0 Kernel ABI 3:17:0
[  166.483406] sof-audio-of 556e8000.dsp: warn: FW ABI is more recent than kernel
[  166.506546] sof-audio-of 556e8000.dsp: Topology: ABI 3:18:1 Kernel ABI 3:17:0
[  166.515821] sof-audio-of 556e8000.dsp: warn: topology ABI is more recent than kernel
[  166.526795] sof-audio-of 556e8000.dsp: tplg: config SAI1 fmt 0x1 mclk 12288000 width 32 slots 2 mclk id 0
[  166.537294] sof-audio-of 556e8000.dsp: ASoC: Parent card not yet available, widget card binding deferred
root@imx8qmmek:~# 
root@imx8qmmek:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: btscoaudio [bt-sco-audio], device 0: 59040000.sai-bt-sco-pcm-wb bt-sco-pcm-wb-0 [59040000.sai-bt-sco-pcm-wb bt-sco-pcm-wb-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofwm8960audio [sof-wm8960-audio], device 0: Port0 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@imx8qmmek:~# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: btscoaudio [bt-sco-audio], device 0: 59040000.sai-bt-sco-pcm-wb bt-sco-pcm-wb-0 [59040000.sai-bt-sco-pcm-wb bt-sco-pcm-wb-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofwm8960audio [sof-wm8960-audio], device 0: Port0 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Pull requests were also opened on:

  • zephyr repo - see #35467
  • xtensa_hal - see #12

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add the imx Zephyr targets into the build script used by CI.

@iuliana-prodan
Copy link
Contributor Author

Can we also add the imx Zephyr targets into the build script used by CI.

Sure, I can do that, but shouldn't we wait for the Zephy PR be merged - #35467?
I also need to modify the sign.py from west_commands, for imx - we don't need a bootloader.elf, only the zephy.elf. This is required now when signing the image.

So, I would add the imx8 target in xtensa-build-zephyr.sh, when I'll have the corresponding patch for sign.py from Zephyr. Otherwise, it will fail at:
west sign -d build-"$platform" -t rimage -p "$RIMAGE_DIR"/rimage -D modules/audio/sof/rimage/config -- -k "$RIMAGE_KEY"
(here).

@lgirdwood
Copy link
Member

Sure, I can do that, but shouldn't we wait for the Zephy PR be merged - #35467?

Yes, sorry I was meaning to make the script build imx Zephyr as part of this PR.

@iuliana-prodan
Copy link
Contributor Author

Sure, I can do that, but shouldn't we wait for the Zephy PR be merged - #35467?

Yes, sorry I was meaning to make the script build imx Zephyr as part of this PR.

Sure, I'll do that.
I also have another suggestion from @lyakh to fix some warnings on trace.h.

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I wont merge until NXP folks have aligned or merge it themselves.

Build SOF with Zephyr for i.MX platforms.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Zephyr already uses main() and has already performed
a lot of initialization before entering SOF.
Split initialization, for i.MX platforms, to make sure
no operation is repeated.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Use the Zephyr sys/util.h when Zephyr RTOS is used.

While here, remove sof/lib/cpu.h which is not used.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
When building SOF with Zephyr for i.MX the following
additional adjustments, to the wrapper, are required:
1. include heapmem variable in .heap_mem section,
otherwise the HEAP_SIZE is duplicated in two sections and
the sdram0 region overflows;
2. no need to split heap into shared and unshared since
we only have 1 DSP core; In this case, the kernel will
never be built in a mode where all shared data is placed
in multiprocessor-coherent (generally "uncached") memory.
3. use simple interrupt_get_irq() to get the Linux interrupt
and later pass it to irq_steer;
4. use Xtensa timer, as we do now with SOF and XTOS.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
…CE not set

When building SOF with Zephyr, for i.MX, we get the following
error: undefined reference to `z_xtensa_cache_inv'.

i.MX has only one DSP core, so CONFIG_KERNEL_COHERENCE is not set.

Therefore include arch/xtensa/cache.h, where z_xtensa_cache_inv
is defined and implemented, in cases when the kernel is not built in
a mode where all shared data is placed in uncached memory.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
@iuliana-prodan iuliana-prodan changed the title [WIP] Build SOF with Zephyr on i.MX Build SOF with Zephyr on i.MX Jul 6, 2021
@dbaluta
Copy link
Collaborator

dbaluta commented Jul 6, 2021

LGTM, thanks Iulia!

@dbaluta dbaluta merged commit 4c06d00 into thesofproject:main Jul 6, 2021
marc-hb added a commit to marc-hb/sof that referenced this pull request Jul 10, 2021
This reverts the only line in commit 34bb9b7 / PR thesofproject#4217 that is not
under some #ifdef IMX

This avoids the following crash always happening on my Up Squared board
on the second aplay command:

[00022612] <err> os:  ** FATAL EXCEPTION
[00022612] <err> os:  ** CPU 0 EXCCAUSE 13 (load/store PIF d{slot 33, seq=34} ata error)
[00022612] <err> os:  **  PC 0xbe00b7ed VADDR 0x9e08bbc4
[00022612] <err> os:  **  PS 0x60a20
[00022612] <err> os:  **    (INTLEVEL:0 EXCM: 0 UM:1 RING:0 {slot 37, seq=38} WOE:1 OWB:10 CALLINC:2)
[00022612] <err> os:  **  A0 0xbe00ba7e  SP 0xbe0498e0  A2 0{slot 39, seq=40} x1fff  A3 0x9e08bbc4
[00022612] <err> os:  **  A4 0x4  A5 0xc1  A6 0x1b20  A7 0xb{slot 41, seq=42} e049b64
[00022612] <err> os:  **  A8 0x7fff  A9 0x7fff A10 0xe A11 0{slot 43, seq=44} x9e0732c2
[00022612] <err> os:  ** A12 0x2 A13 0x182 A14 0x180 A15 0x6{slot 45, seq=46} 0
[00022612] <err> os:  ** LBEG 0xbe01739c LEND 0xbe0173a6 LCO{slot 47, seq=48} UNT (nil)
[00022612] <err> os:  ** SAR 0x19
[00022612] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception{slot 50, seq=51}  on CPU 0
[00022612] <err> os: Current thread: 0x9e075ca8 (unknown)
[00022614] <err> os: Halting system
if (zone_is_cached(zone))
return heap_alloc_aligned_cached(&sof_heap, 0, bytes);
else
return heap_alloc_aligned(&sof_heap, 8, bytes);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line "reliably" crashes my Up Squared board on the second aplay command every time, see partial revert PR #4472

git bisect found this commit and then it was easy to identify this line because it seems to be the only one not IMX-specific.

Cc: @lyakh , @lgirdwood , @andyross

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a pull request to fix this, for both i.MX and Up Squared: #4477
The PR #4472 breaks i.MX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants