[PATCH v5 0/7] hw/arm/sabrelite: Add FlexCAN support

Matyáš Bobek posted 7 patches 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/cover.1781111270.git.matyas.bobek@gmail.com
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Jean-Christophe Dubois <jcd@tribudubois.net>, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>, Pavel Pisa <pisa@cmp.felk.cvut.cz>, Francisco Iglesias <francisco.iglesias@amd.com>, Vikram Garhwal <vikram.garhwal@bytedance.com>, Paolo Bonzini <pbonzini@redhat.com>, Jason Wang <jasowang@redhat.com>, Matyas Bobek <matyas.bobek@gmail.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
MAINTAINERS                   |    9 +
docs/system/arm/sabrelite.rst |    1 +
docs/system/devices/can.rst   |   24 +
hw/arm/Kconfig                |    1 +
hw/arm/fsl-imx6.c             |   29 +
hw/arm/sabrelite.c            |   68 +-
hw/misc/imx6_ccm.c            |   24 +
hw/misc/trace-events          |    2 +
hw/net/Kconfig                |    5 +
hw/net/can/flexcan.c          | 1395 +++++++++++++++++++++++++++++++++
hw/net/can/flexcan_regs.h     |  197 +++++
hw/net/can/meson.build        |    1 +
hw/net/can/trace-events       |   18 +
include/hw/arm/fsl-imx6.h     |    6 +
include/hw/misc/imx6_ccm.h    |    4 +
include/hw/misc/imx_ccm.h     |    1 +
include/hw/net/flexcan.h      |  145 ++++
tests/qtest/flexcan-test.c    |  421 ++++++++++
tests/qtest/meson.build       |    1 +
19 files changed, 2342 insertions(+), 10 deletions(-)
create mode 100644 hw/net/can/flexcan.c
create mode 100644 hw/net/can/flexcan_regs.h
create mode 100644 include/hw/net/flexcan.h
create mode 100644 tests/qtest/flexcan-test.c
[PATCH v5 0/7] hw/arm/sabrelite: Add FlexCAN support
Posted by Matyáš Bobek 5 days ago
This series adds emulation of the FlexCAN CAN controller, version 2,
found in NXP i.MX6 series SoCs. The controller is integrated into
fsl-imx6 and the Sabrelite ARM board.

The chip has two FlexCAN controllers, but the Linux Sabrelite
device tree enables only one by default. Linux kernel with both
controllers enabled has been tested to work properly (using a custom
device tree).
See docs/system/devices/can.rst for an example of QEMU command line
invocation.

More information about the implementation can be found in my bachelor
thesis [1].

Changes from v4:
- renamed can in fsl-imx6 to flexcan
- corrected attribution for definitions borrowed from the Linux kernel
- rebased onto latest master
- Link to v4: https://lore.kernel.org/qemu-devel/cover.1779986496.git.matyas.bobek@gmail.com/

Changes from v3 to v4:
- corrected attribution for definitions borrowed from the Linux kernel
- rebased onto latest master
- Link to v3: https://lore.kernel.org/qemu-devel/cover.1777571962.git.matyas.bobek@gmail.com/

Changes from v2 to v3:
- moved variable declarations to the top-of-the-block
- cleanup
- removed redundant license boilerplate
- rebased onto latest master
- Link to v2: https://lore.kernel.org/qemu-devel/cover.1773866323.git.matyas.bobek@gmail.com/

Changes from v1 to v2:
- removed DPRINTF (turned into traces or guest errors)
- removed gotos and unnecessary continues
- register memory region shortened to actual length w/o padding
- make flexcan_* fns private
- used DEVICE(s)->canonical_path instead of allocating new strings
- changed DEVICE_NATIVE_ENDIAN to DEVICE_LITTLE_ENDIAN
- removed ugly USE macro
- used enums instead of define sequences in flexcan.c
- fixed FlexCAN KConfig conf (fixes build on non-arm-softmmu)
- fixed style and other issues from Bernhard's review
- better wording in docs
- rebased onto latest master
- Link to v1: https://lore.kernel.org/qemu-devel/cover.1765826753.git.matyas.bobek@gmail.com

Thanks Bernhard Beschow for the review and his patience.
I borrowed some fixes from his flexcan branch at [2].

[1] http://dspace.cvut.cz/bitstream/handle/10467/122654/F3-BP-2025-Bobek-Matyas-BP_Bobek_FlexCAN_final_4.pdf
[2] https://github.com/shentok/qemu/tree/flexcan

Matyáš Bobek (7):
  hw/arm/sabrelite: Open code DEFINE_MACHINE_ARM
  hw/arm/sabrelite: Introduce class SabreliteMachineState
  hw/misc/imx6_ccm: Add PLL3 and CAN clock
  hw/net/can/flexcan: NXP FlexCAN core emulation
  hw/arm: Plug FlexCAN into FSL_IMX6 and Sabrelite
  tests: Add qtests for FlexCAN
  docs/arm/sabrelite: Mention FlexCAN support

 MAINTAINERS                   |    9 +
 docs/system/arm/sabrelite.rst |    1 +
 docs/system/devices/can.rst   |   24 +
 hw/arm/Kconfig                |    1 +
 hw/arm/fsl-imx6.c             |   29 +
 hw/arm/sabrelite.c            |   68 +-
 hw/misc/imx6_ccm.c            |   24 +
 hw/misc/trace-events          |    2 +
 hw/net/Kconfig                |    5 +
 hw/net/can/flexcan.c          | 1395 +++++++++++++++++++++++++++++++++
 hw/net/can/flexcan_regs.h     |  197 +++++
 hw/net/can/meson.build        |    1 +
 hw/net/can/trace-events       |   18 +
 include/hw/arm/fsl-imx6.h     |    6 +
 include/hw/misc/imx6_ccm.h    |    4 +
 include/hw/misc/imx_ccm.h     |    1 +
 include/hw/net/flexcan.h      |  145 ++++
 tests/qtest/flexcan-test.c    |  421 ++++++++++
 tests/qtest/meson.build       |    1 +
 19 files changed, 2342 insertions(+), 10 deletions(-)
 create mode 100644 hw/net/can/flexcan.c
 create mode 100644 hw/net/can/flexcan_regs.h
 create mode 100644 include/hw/net/flexcan.h
 create mode 100644 tests/qtest/flexcan-test.c

-- 
2.54.0


Re: [PATCH v5 0/7] hw/arm/sabrelite: Add FlexCAN support
Posted by Peter Maydell 5 days ago
On Mon, 15 Jun 2026 at 13:15, Matyáš Bobek <matyas.bobek@gmail.com> wrote:
>
> This series adds emulation of the FlexCAN CAN controller, version 2,
> found in NXP i.MX6 series SoCs. The controller is integrated into
> fsl-imx6 and the Sabrelite ARM board.
>
> The chip has two FlexCAN controllers, but the Linux Sabrelite
> device tree enables only one by default. Linux kernel with both
> controllers enabled has been tested to work properly (using a custom
> device tree).
> See docs/system/devices/can.rst for an example of QEMU command line
> invocation.
>
> More information about the implementation can be found in my bachelor
> thesis [1].
>
> Changes from v4:
> - renamed can in fsl-imx6 to flexcan
> - corrected attribution for definitions borrowed from the Linux kernel
> - rebased onto latest master
> - Link to v4: https://lore.kernel.org/qemu-devel/cover.1779986496.git.matyas.bobek@gmail.com/

Have you fixed the clang sanitizer array-overrun bug that
I reported against v4?

https://lore.kernel.org/qemu-devel/CAFEAcA-diz0Bh1Ah87MPXxkDcvxF58tACTcxxJw68xtw8pTfLw@mail.gmail.com/

thanks
-- PMM
Re: [PATCH v5 0/7] hw/arm/sabrelite: Add FlexCAN support
Posted by Matyáš Bobek 5 days ago
On Mon, 2026-06-15 at 13:18 +0100, Peter Maydell wrote:
> On Mon, 15 Jun 2026 at 13:15, Matyáš Bobek <matyas.bobek@gmail.com>
> wrote:
> > 
> > This series adds emulation of the FlexCAN CAN controller, version
> > 2,
> > found in NXP i.MX6 series SoCs. The controller is integrated into
> > fsl-imx6 and the Sabrelite ARM board.
> > 
> > The chip has two FlexCAN controllers, but the Linux Sabrelite
> > device tree enables only one by default. Linux kernel with both
> > controllers enabled has been tested to work properly (using a
> > custom
> > device tree).
> > See docs/system/devices/can.rst for an example of QEMU command line
> > invocation.
> > 
> > More information about the implementation can be found in my
> > bachelor
> > thesis [1].
> > 
> > Changes from v4:
> > - renamed can in fsl-imx6 to flexcan
> > - corrected attribution for definitions borrowed from the Linux
> > kernel
> > - rebased onto latest master
> > - Link to v4:
> > https://lore.kernel.org/qemu-devel/cover.1779986496.git.matyas.bobek@gmail.com/
> 
> Have you fixed the clang sanitizer array-overrun bug that
> I reported against v4?

Oh, I'm afraid I forgot about it. I will fix it and post new version.
Sorry, Matt