[PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine

Niek Linnenbank posted 20 patches 4 years, 2 months ago
Test docker-quick@centos7 passed
Test docker-mingw@fedora passed
Test FreeBSD passed
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200119005102.3847-1-nieklinnenbank@gmail.com
Maintainers: Kamil Rytarowski <kamil@netbsd.org>, Gerd Hoffmann <kraxel@redhat.com>, Jason Wang <jasowang@redhat.com>, Beniamino Galvani <b.galvani@gmail.com>, Niek Linnenbank <nieklinnenbank@gmail.com>, Peter Maydell <peter.maydell@linaro.org>
There is a newer version of this series
docs/orangepi.rst                         | 199 +++++
default-configs/arm-softmmu.mak           |   1 +
hw/usb/hcd-ehci.h                         |   1 +
include/hw/arm/allwinner-a10.h            |   4 +
include/hw/arm/allwinner-h3.h             | 163 ++++
include/hw/misc/allwinner-cpucfg.h        |  52 ++
include/hw/misc/allwinner-h3-ccu.h        |  66 ++
include/hw/misc/allwinner-h3-dramc.h      | 106 +++
include/hw/misc/allwinner-h3-sysctrl.h    |  67 ++
include/hw/misc/allwinner-sid.h           |  60 ++
include/hw/net/allwinner-sun8i-emac.h     |  99 +++
include/hw/rtc/allwinner-rtc.h            | 128 ++++
include/hw/sd/allwinner-sdhost.h          | 135 ++++
hw/arm/allwinner-a10.c                    |  19 +
hw/arm/allwinner-h3.c                     | 476 ++++++++++++
hw/arm/cubieboard.c                       |  15 +
hw/arm/orangepi.c                         | 127 ++++
hw/misc/allwinner-cpucfg.c                | 269 +++++++
hw/misc/allwinner-h3-ccu.c                | 243 ++++++
hw/misc/allwinner-h3-dramc.c              | 358 +++++++++
hw/misc/allwinner-h3-sysctrl.c            | 140 ++++
hw/misc/allwinner-sid.c                   | 170 +++++
hw/net/allwinner-sun8i-emac.c             | 871 ++++++++++++++++++++++
hw/rtc/allwinner-rtc.c                    | 386 ++++++++++
hw/sd/allwinner-sdhost.c                  | 848 +++++++++++++++++++++
hw/usb/hcd-ehci-sysbus.c                  |  17 +
MAINTAINERS                               |   9 +
hw/arm/Kconfig                            |   9 +
hw/arm/Makefile.objs                      |   1 +
hw/misc/Makefile.objs                     |   5 +
hw/misc/trace-events                      |  19 +
hw/net/Kconfig                            |   3 +
hw/net/Makefile.objs                      |   1 +
hw/net/trace-events                       |  10 +
hw/rtc/Makefile.objs                      |   1 +
hw/rtc/trace-events                       |   4 +
hw/sd/Makefile.objs                       |   1 +
hw/sd/trace-events                        |   7 +
tests/acceptance/avocado_qemu/__init__.py |  59 +-
tests/acceptance/boot_linux_console.py    | 210 ++++++
40 files changed, 5345 insertions(+), 14 deletions(-)
create mode 100644 docs/orangepi.rst
create mode 100644 include/hw/arm/allwinner-h3.h
create mode 100644 include/hw/misc/allwinner-cpucfg.h
create mode 100644 include/hw/misc/allwinner-h3-ccu.h
create mode 100644 include/hw/misc/allwinner-h3-dramc.h
create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
create mode 100644 include/hw/misc/allwinner-sid.h
create mode 100644 include/hw/net/allwinner-sun8i-emac.h
create mode 100644 include/hw/rtc/allwinner-rtc.h
create mode 100644 include/hw/sd/allwinner-sdhost.h
create mode 100644 hw/arm/allwinner-h3.c
create mode 100644 hw/arm/orangepi.c
create mode 100644 hw/misc/allwinner-cpucfg.c
create mode 100644 hw/misc/allwinner-h3-ccu.c
create mode 100644 hw/misc/allwinner-h3-dramc.c
create mode 100644 hw/misc/allwinner-h3-sysctrl.c
create mode 100644 hw/misc/allwinner-sid.c
create mode 100644 hw/net/allwinner-sun8i-emac.c
create mode 100644 hw/rtc/allwinner-rtc.c
create mode 100644 hw/sd/allwinner-sdhost.c
[PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Niek Linnenbank 4 years, 2 months ago
Dear QEMU developers,

Hereby I would like to contribute the following set of patches to QEMU
which add support for the Allwinner H3 System on Chip and the
Orange Pi PC machine. The following features and devices are supported:

 * SMP (Quad Core Cortex A7)
 * Generic Interrupt Controller configuration
 * SRAM mappings
 * SDRAM controller
 * Real Time Clock
 * Timer device (re-used from Allwinner A10)
 * UART
 * SD/MMC storage controller
 * EMAC ethernet connectivity
 * USB 2.0 interfaces
 * Clock Control Unit
 * System Control module
 * Security Identifier device

Functionality related to graphical output such as HDMI, GPU,
Display Engine and audio are not included. Recently released
mainline Linux kernels (4.19 up to latest master), mainline U-Boot
and NetBSD 9.0-RC1 are known to work.

For full details on how to use the Orange Pi PC machine, see the file
docs/orangepi.rst which is included as a patch in this series.

The contents of this patch series is available on Github at:

  https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3

The followings are currently known issues in this series:

  - NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
     -> This is due to difference in base year defined by the corresponding drivers
  - RTC date & time is not persistent
  - boot0 custom Allwinner bootloader not yet working
  - Watchdog not yet implemented, affects U-Boot 'reset' and shutdown/reboot
     -> This is part of the existing A10 timer that needs to be generalized first

Looking forward to your review comments. I will do my best
to update the patches where needed.

===== CHANGELOG =====
v4:
 * docs/orangepi.rst: correct SDRAM size in board description: 512MB -> 1GiB
 * hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
 * hw/arm/orangepi.c: set .nb_cpus in the orangepi_binfo struct static initialisation
 * hw/arm/orangepi.c: remove .board_id from orangepi_binfo struct
 * hw/arm/orangepi.c: move BIOS check to top of orangepi_init()
 * hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 * 1000 for readability
 * hw/arm/orangepi.c: rephrase 1GiB check error message
 * include/hw/arm/allwinner-h3.h: improved comments
 * hw/arm/allwinner-h3.c: remove duplicate initialization and declaration of i variable
 * hw/arm/allwinner-h3.c: use DEVICE(&s->cpus[i]) instead of qemu_get_cpu()
 * hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU initialization part
 * hw/arm/allwinner-h3.c: add note that UARTs are connected to APB2_CLK, for future clocktree API
 * hw/arm/allwinner-h3.c: extend commit message for Boot ROM with description for the 32KiB size
 * hw/rtc/allwinner-rtc.c: correct usage of AwRtcClass->regmap_size for checking r/w offset
 * hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by Linux/U-Boot/NetBSD
 * hw/misc/allwinner-cpucfg.c: add CPU_EXCEPTION_LEVEL_ON_RESET constant
 * hw/misc/allwinner-cpucfg.c: break instead of return after logging guest error, for tracing
 * hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case for REG_CPUX_RST_CTRL in write function
 * include/hw/rtc/allwinner-rtc.h: increase AW_RTC_REGS_MAXADDR to 0x200
 * include/hw/rtc/allwinner-rtc.h: change type of AwRtcClass->year_offset to int, to match struct tm
 * tests/acceptance/boot_linux_console.py: remove calls to vm.set_machine()
 * tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
 * docs/orangepi.rst: removed some unneeded words/typos
 * docs/orangepi.rst: remove usage of -j5 for calling make (not all users have >= 4 SMP cores)
 * include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded #includes to .c file

v3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
    https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3

v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
    https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2

v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
    https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1

With kind regards,

Niek Linnenbank

Niek Linnenbank (13):
  hw/arm: add Allwinner H3 System-on-Chip
  hw/arm: add Xunlong Orange Pi PC machine
  hw/arm/allwinner-h3: add Clock Control Unit
  hw/arm/allwinner-h3: add USB host controller
  hw/arm/allwinner-h3: add System Control module
  hw/arm/allwinner: add CPU Configuration module
  hw/arm/allwinner: add Security Identifier device
  hw/arm/allwinner: add SD/MMC host controller
  hw/arm/allwinner-h3: add EMAC ethernet device
  hw/arm/allwinner-h3: add Boot ROM support
  hw/arm/allwinner-h3: add SDRAM controller device
  hw/arm/allwinner: add RTC device support
  docs: add Orange Pi PC document

Philippe Mathieu-Daudé (7):
  tests/boot_linux_console: Add a quick test for the OrangePi PC board
  tests/boot_linux_console: Add initrd test for the Orange Pi PC board
  tests/boot_linux_console: Add a SD card test for the OrangePi PC board
  tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
    PC
  Acceptance tests: Extract _console_interaction()
  Acceptance tests: Add interrupt_interactive_console_until_pattern()
  tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
    PC

 docs/orangepi.rst                         | 199 +++++
 default-configs/arm-softmmu.mak           |   1 +
 hw/usb/hcd-ehci.h                         |   1 +
 include/hw/arm/allwinner-a10.h            |   4 +
 include/hw/arm/allwinner-h3.h             | 163 ++++
 include/hw/misc/allwinner-cpucfg.h        |  52 ++
 include/hw/misc/allwinner-h3-ccu.h        |  66 ++
 include/hw/misc/allwinner-h3-dramc.h      | 106 +++
 include/hw/misc/allwinner-h3-sysctrl.h    |  67 ++
 include/hw/misc/allwinner-sid.h           |  60 ++
 include/hw/net/allwinner-sun8i-emac.h     |  99 +++
 include/hw/rtc/allwinner-rtc.h            | 128 ++++
 include/hw/sd/allwinner-sdhost.h          | 135 ++++
 hw/arm/allwinner-a10.c                    |  19 +
 hw/arm/allwinner-h3.c                     | 476 ++++++++++++
 hw/arm/cubieboard.c                       |  15 +
 hw/arm/orangepi.c                         | 127 ++++
 hw/misc/allwinner-cpucfg.c                | 269 +++++++
 hw/misc/allwinner-h3-ccu.c                | 243 ++++++
 hw/misc/allwinner-h3-dramc.c              | 358 +++++++++
 hw/misc/allwinner-h3-sysctrl.c            | 140 ++++
 hw/misc/allwinner-sid.c                   | 170 +++++
 hw/net/allwinner-sun8i-emac.c             | 871 ++++++++++++++++++++++
 hw/rtc/allwinner-rtc.c                    | 386 ++++++++++
 hw/sd/allwinner-sdhost.c                  | 848 +++++++++++++++++++++
 hw/usb/hcd-ehci-sysbus.c                  |  17 +
 MAINTAINERS                               |   9 +
 hw/arm/Kconfig                            |   9 +
 hw/arm/Makefile.objs                      |   1 +
 hw/misc/Makefile.objs                     |   5 +
 hw/misc/trace-events                      |  19 +
 hw/net/Kconfig                            |   3 +
 hw/net/Makefile.objs                      |   1 +
 hw/net/trace-events                       |  10 +
 hw/rtc/Makefile.objs                      |   1 +
 hw/rtc/trace-events                       |   4 +
 hw/sd/Makefile.objs                       |   1 +
 hw/sd/trace-events                        |   7 +
 tests/acceptance/avocado_qemu/__init__.py |  59 +-
 tests/acceptance/boot_linux_console.py    | 210 ++++++
 40 files changed, 5345 insertions(+), 14 deletions(-)
 create mode 100644 docs/orangepi.rst
 create mode 100644 include/hw/arm/allwinner-h3.h
 create mode 100644 include/hw/misc/allwinner-cpucfg.h
 create mode 100644 include/hw/misc/allwinner-h3-ccu.h
 create mode 100644 include/hw/misc/allwinner-h3-dramc.h
 create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
 create mode 100644 include/hw/misc/allwinner-sid.h
 create mode 100644 include/hw/net/allwinner-sun8i-emac.h
 create mode 100644 include/hw/rtc/allwinner-rtc.h
 create mode 100644 include/hw/sd/allwinner-sdhost.h
 create mode 100644 hw/arm/allwinner-h3.c
 create mode 100644 hw/arm/orangepi.c
 create mode 100644 hw/misc/allwinner-cpucfg.c
 create mode 100644 hw/misc/allwinner-h3-ccu.c
 create mode 100644 hw/misc/allwinner-h3-dramc.c
 create mode 100644 hw/misc/allwinner-h3-sysctrl.c
 create mode 100644 hw/misc/allwinner-sid.c
 create mode 100644 hw/net/allwinner-sun8i-emac.c
 create mode 100644 hw/rtc/allwinner-rtc.c
 create mode 100644 hw/sd/allwinner-sdhost.c

-- 
2.17.1

Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Niek Linnenbank 4 years, 2 months ago
On Sun, Jan 19, 2020, 01:51 Niek Linnenbank <nieklinnenbank@gmail.com>
wrote:

> Dear QEMU developers,
>
> Hereby I would like to contribute the following set of patches to QEMU
> which add support for the Allwinner H3 System on Chip and the
> Orange Pi PC machine. The following features and devices are supported:
>
>  * SMP (Quad Core Cortex A7)
>  * Generic Interrupt Controller configuration
>  * SRAM mappings
>  * SDRAM controller
>  * Real Time Clock
>  * Timer device (re-used from Allwinner A10)
>  * UART
>  * SD/MMC storage controller
>  * EMAC ethernet connectivity
>  * USB 2.0 interfaces
>  * Clock Control Unit
>  * System Control module
>  * Security Identifier device
>
> Functionality related to graphical output such as HDMI, GPU,
> Display Engine and audio are not included. Recently released
> mainline Linux kernels (4.19 up to latest master), mainline U-Boot
> and NetBSD 9.0-RC1 are known to work.
>
> For full details on how to use the Orange Pi PC machine, see the file
> docs/orangepi.rst which is included as a patch in this series.
>
> The contents of this patch series is available on Github at:
>
>   https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3


I forgot to update this link in the cover letter to v4. The correct link is:

https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v4


>
> The followings are currently known issues in this series:
>
>   - NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
>      -> This is due to difference in base year defined by the
> corresponding drivers
>   - RTC date & time is not persistent
>   - boot0 custom Allwinner bootloader not yet working
>   - Watchdog not yet implemented, affects U-Boot 'reset' and
> shutdown/reboot
>      -> This is part of the existing A10 timer that needs to be
> generalized first
>
> Looking forward to your review comments. I will do my best
> to update the patches where needed.
>
> ===== CHANGELOG =====
> v4:
>  * docs/orangepi.rst: correct SDRAM size in board description: 512MB ->
> 1GiB
>  * hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
>  * hw/arm/orangepi.c: set .nb_cpus in the orangepi_binfo struct static
> initialisation
>  * hw/arm/orangepi.c: remove .board_id from orangepi_binfo struct
>  * hw/arm/orangepi.c: move BIOS check to top of orangepi_init()
>  * hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 *
> 1000 for readability
>  * hw/arm/orangepi.c: rephrase 1GiB check error message
>  * include/hw/arm/allwinner-h3.h: improved comments
>  * hw/arm/allwinner-h3.c: remove duplicate initialization and declaration
> of i variable
>  * hw/arm/allwinner-h3.c: use DEVICE(&s->cpus[i]) instead of qemu_get_cpu()
>  * hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU
> initialization part
>  * hw/arm/allwinner-h3.c: add note that UARTs are connected to APB2_CLK,
> for future clocktree API
>  * hw/arm/allwinner-h3.c: extend commit message for Boot ROM with
> description for the 32KiB size
>  * hw/rtc/allwinner-rtc.c: correct usage of AwRtcClass->regmap_size for
> checking r/w offset
>  * hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by
> Linux/U-Boot/NetBSD
>  * hw/misc/allwinner-cpucfg.c: add CPU_EXCEPTION_LEVEL_ON_RESET constant
>  * hw/misc/allwinner-cpucfg.c: break instead of return after logging guest
> error, for tracing
>  * hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case for
> REG_CPUX_RST_CTRL in write function
>  * include/hw/rtc/allwinner-rtc.h: increase AW_RTC_REGS_MAXADDR to 0x200
>  * include/hw/rtc/allwinner-rtc.h: change type of AwRtcClass->year_offset
> to int, to match struct tm
>  * tests/acceptance/boot_linux_console.py: remove calls to vm.set_machine()
>  * tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
>  * docs/orangepi.rst: removed some unneeded words/typos
>  * docs/orangepi.rst: remove usage of -j5 for calling make (not all users
> have >= 4 SMP cores)
>  * include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded
> #includes to .c file
>
> v3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
>
> v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2
>
> v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1
>
> With kind regards,
>
> Niek Linnenbank
>
> Niek Linnenbank (13):
>   hw/arm: add Allwinner H3 System-on-Chip
>   hw/arm: add Xunlong Orange Pi PC machine
>   hw/arm/allwinner-h3: add Clock Control Unit
>   hw/arm/allwinner-h3: add USB host controller
>   hw/arm/allwinner-h3: add System Control module
>   hw/arm/allwinner: add CPU Configuration module
>   hw/arm/allwinner: add Security Identifier device
>   hw/arm/allwinner: add SD/MMC host controller
>   hw/arm/allwinner-h3: add EMAC ethernet device
>   hw/arm/allwinner-h3: add Boot ROM support
>   hw/arm/allwinner-h3: add SDRAM controller device
>   hw/arm/allwinner: add RTC device support
>   docs: add Orange Pi PC document
>
> Philippe Mathieu-Daudé (7):
>   tests/boot_linux_console: Add a quick test for the OrangePi PC board
>   tests/boot_linux_console: Add initrd test for the Orange Pi PC board
>   tests/boot_linux_console: Add a SD card test for the OrangePi PC board
>   tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
>     PC
>   Acceptance tests: Extract _console_interaction()
>   Acceptance tests: Add interrupt_interactive_console_until_pattern()
>   tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
>     PC
>
>  docs/orangepi.rst                         | 199 +++++
>  default-configs/arm-softmmu.mak           |   1 +
>  hw/usb/hcd-ehci.h                         |   1 +
>  include/hw/arm/allwinner-a10.h            |   4 +
>  include/hw/arm/allwinner-h3.h             | 163 ++++
>  include/hw/misc/allwinner-cpucfg.h        |  52 ++
>  include/hw/misc/allwinner-h3-ccu.h        |  66 ++
>  include/hw/misc/allwinner-h3-dramc.h      | 106 +++
>  include/hw/misc/allwinner-h3-sysctrl.h    |  67 ++
>  include/hw/misc/allwinner-sid.h           |  60 ++
>  include/hw/net/allwinner-sun8i-emac.h     |  99 +++
>  include/hw/rtc/allwinner-rtc.h            | 128 ++++
>  include/hw/sd/allwinner-sdhost.h          | 135 ++++
>  hw/arm/allwinner-a10.c                    |  19 +
>  hw/arm/allwinner-h3.c                     | 476 ++++++++++++
>  hw/arm/cubieboard.c                       |  15 +
>  hw/arm/orangepi.c                         | 127 ++++
>  hw/misc/allwinner-cpucfg.c                | 269 +++++++
>  hw/misc/allwinner-h3-ccu.c                | 243 ++++++
>  hw/misc/allwinner-h3-dramc.c              | 358 +++++++++
>  hw/misc/allwinner-h3-sysctrl.c            | 140 ++++
>  hw/misc/allwinner-sid.c                   | 170 +++++
>  hw/net/allwinner-sun8i-emac.c             | 871 ++++++++++++++++++++++
>  hw/rtc/allwinner-rtc.c                    | 386 ++++++++++
>  hw/sd/allwinner-sdhost.c                  | 848 +++++++++++++++++++++
>  hw/usb/hcd-ehci-sysbus.c                  |  17 +
>  MAINTAINERS                               |   9 +
>  hw/arm/Kconfig                            |   9 +
>  hw/arm/Makefile.objs                      |   1 +
>  hw/misc/Makefile.objs                     |   5 +
>  hw/misc/trace-events                      |  19 +
>  hw/net/Kconfig                            |   3 +
>  hw/net/Makefile.objs                      |   1 +
>  hw/net/trace-events                       |  10 +
>  hw/rtc/Makefile.objs                      |   1 +
>  hw/rtc/trace-events                       |   4 +
>  hw/sd/Makefile.objs                       |   1 +
>  hw/sd/trace-events                        |   7 +
>  tests/acceptance/avocado_qemu/__init__.py |  59 +-
>  tests/acceptance/boot_linux_console.py    | 210 ++++++
>  40 files changed, 5345 insertions(+), 14 deletions(-)
>  create mode 100644 docs/orangepi.rst
>  create mode 100644 include/hw/arm/allwinner-h3.h
>  create mode 100644 include/hw/misc/allwinner-cpucfg.h
>  create mode 100644 include/hw/misc/allwinner-h3-ccu.h
>  create mode 100644 include/hw/misc/allwinner-h3-dramc.h
>  create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
>  create mode 100644 include/hw/misc/allwinner-sid.h
>  create mode 100644 include/hw/net/allwinner-sun8i-emac.h
>  create mode 100644 include/hw/rtc/allwinner-rtc.h
>  create mode 100644 include/hw/sd/allwinner-sdhost.h
>  create mode 100644 hw/arm/allwinner-h3.c
>  create mode 100644 hw/arm/orangepi.c
>  create mode 100644 hw/misc/allwinner-cpucfg.c
>  create mode 100644 hw/misc/allwinner-h3-ccu.c
>  create mode 100644 hw/misc/allwinner-h3-dramc.c
>  create mode 100644 hw/misc/allwinner-h3-sysctrl.c
>  create mode 100644 hw/misc/allwinner-sid.c
>  create mode 100644 hw/net/allwinner-sun8i-emac.c
>  create mode 100644 hw/rtc/allwinner-rtc.c
>  create mode 100644 hw/sd/allwinner-sdhost.c
>
> --
> 2.17.1
>
Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Niek Linnenbank 4 years, 1 month ago
Hi all,

Short status update regarding this series.

Currently I am debugging booting NetBSD 9.0-RC2, which is recently released
[1]
The problem is that, apparently, RC2 can't mount the rootfs properly:

[   3.1871510] vfs_mountroot: can't open root device
[   3.2141370] cannot mount root, error = 6

This only happens using the RC2 filesystem image. However, the RC2 kernel
can
properly load & boot the RC1 filesystem image, and the RC1 kernel gives the
same error
on the RC2 filesystem.  But I dont think its a NetBSD-RC2 issue, because on
a real
Orange Pi PC hardware board, this problem does not show.

I'm comparing traces and adding more low-level debug output to NetBSD and
QEMU to find the issue.

Also I processed the review remarks which were send so far.

Kind regards,
Niek

[1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html

On Sun, Jan 19, 2020 at 1:51 AM Niek Linnenbank <nieklinnenbank@gmail.com>
wrote:

> Dear QEMU developers,
>
> Hereby I would like to contribute the following set of patches to QEMU
> which add support for the Allwinner H3 System on Chip and the
> Orange Pi PC machine. The following features and devices are supported:
>
>  * SMP (Quad Core Cortex A7)
>  * Generic Interrupt Controller configuration
>  * SRAM mappings
>  * SDRAM controller
>  * Real Time Clock
>  * Timer device (re-used from Allwinner A10)
>  * UART
>  * SD/MMC storage controller
>  * EMAC ethernet connectivity
>  * USB 2.0 interfaces
>  * Clock Control Unit
>  * System Control module
>  * Security Identifier device
>
> Functionality related to graphical output such as HDMI, GPU,
> Display Engine and audio are not included. Recently released
> mainline Linux kernels (4.19 up to latest master), mainline U-Boot
> and NetBSD 9.0-RC1 are known to work.
>
> For full details on how to use the Orange Pi PC machine, see the file
> docs/orangepi.rst which is included as a patch in this series.
>
> The contents of this patch series is available on Github at:
>
>   https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
>
> The followings are currently known issues in this series:
>
>   - NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
>      -> This is due to difference in base year defined by the
> corresponding drivers
>   - RTC date & time is not persistent
>   - boot0 custom Allwinner bootloader not yet working
>   - Watchdog not yet implemented, affects U-Boot 'reset' and
> shutdown/reboot
>      -> This is part of the existing A10 timer that needs to be
> generalized first
>
> Looking forward to your review comments. I will do my best
> to update the patches where needed.
>
> ===== CHANGELOG =====
> v4:
>  * docs/orangepi.rst: correct SDRAM size in board description: 512MB ->
> 1GiB
>  * hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
>  * hw/arm/orangepi.c: set .nb_cpus in the orangepi_binfo struct static
> initialisation
>  * hw/arm/orangepi.c: remove .board_id from orangepi_binfo struct
>  * hw/arm/orangepi.c: move BIOS check to top of orangepi_init()
>  * hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 *
> 1000 for readability
>  * hw/arm/orangepi.c: rephrase 1GiB check error message
>  * include/hw/arm/allwinner-h3.h: improved comments
>  * hw/arm/allwinner-h3.c: remove duplicate initialization and declaration
> of i variable
>  * hw/arm/allwinner-h3.c: use DEVICE(&s->cpus[i]) instead of qemu_get_cpu()
>  * hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU
> initialization part
>  * hw/arm/allwinner-h3.c: add note that UARTs are connected to APB2_CLK,
> for future clocktree API
>  * hw/arm/allwinner-h3.c: extend commit message for Boot ROM with
> description for the 32KiB size
>  * hw/rtc/allwinner-rtc.c: correct usage of AwRtcClass->regmap_size for
> checking r/w offset
>  * hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by
> Linux/U-Boot/NetBSD
>  * hw/misc/allwinner-cpucfg.c: add CPU_EXCEPTION_LEVEL_ON_RESET constant
>  * hw/misc/allwinner-cpucfg.c: break instead of return after logging guest
> error, for tracing
>  * hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case for
> REG_CPUX_RST_CTRL in write function
>  * include/hw/rtc/allwinner-rtc.h: increase AW_RTC_REGS_MAXADDR to 0x200
>  * include/hw/rtc/allwinner-rtc.h: change type of AwRtcClass->year_offset
> to int, to match struct tm
>  * tests/acceptance/boot_linux_console.py: remove calls to vm.set_machine()
>  * tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
>  * docs/orangepi.rst: removed some unneeded words/typos
>  * docs/orangepi.rst: remove usage of -j5 for calling make (not all users
> have >= 4 SMP cores)
>  * include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded
> #includes to .c file
>
> v3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
>
> v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2
>
> v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
>     https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1
>
> With kind regards,
>
> Niek Linnenbank
>
> Niek Linnenbank (13):
>   hw/arm: add Allwinner H3 System-on-Chip
>   hw/arm: add Xunlong Orange Pi PC machine
>   hw/arm/allwinner-h3: add Clock Control Unit
>   hw/arm/allwinner-h3: add USB host controller
>   hw/arm/allwinner-h3: add System Control module
>   hw/arm/allwinner: add CPU Configuration module
>   hw/arm/allwinner: add Security Identifier device
>   hw/arm/allwinner: add SD/MMC host controller
>   hw/arm/allwinner-h3: add EMAC ethernet device
>   hw/arm/allwinner-h3: add Boot ROM support
>   hw/arm/allwinner-h3: add SDRAM controller device
>   hw/arm/allwinner: add RTC device support
>   docs: add Orange Pi PC document
>
> Philippe Mathieu-Daudé (7):
>   tests/boot_linux_console: Add a quick test for the OrangePi PC board
>   tests/boot_linux_console: Add initrd test for the Orange Pi PC board
>   tests/boot_linux_console: Add a SD card test for the OrangePi PC board
>   tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
>     PC
>   Acceptance tests: Extract _console_interaction()
>   Acceptance tests: Add interrupt_interactive_console_until_pattern()
>   tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
>     PC
>
>  docs/orangepi.rst                         | 199 +++++
>  default-configs/arm-softmmu.mak           |   1 +
>  hw/usb/hcd-ehci.h                         |   1 +
>  include/hw/arm/allwinner-a10.h            |   4 +
>  include/hw/arm/allwinner-h3.h             | 163 ++++
>  include/hw/misc/allwinner-cpucfg.h        |  52 ++
>  include/hw/misc/allwinner-h3-ccu.h        |  66 ++
>  include/hw/misc/allwinner-h3-dramc.h      | 106 +++
>  include/hw/misc/allwinner-h3-sysctrl.h    |  67 ++
>  include/hw/misc/allwinner-sid.h           |  60 ++
>  include/hw/net/allwinner-sun8i-emac.h     |  99 +++
>  include/hw/rtc/allwinner-rtc.h            | 128 ++++
>  include/hw/sd/allwinner-sdhost.h          | 135 ++++
>  hw/arm/allwinner-a10.c                    |  19 +
>  hw/arm/allwinner-h3.c                     | 476 ++++++++++++
>  hw/arm/cubieboard.c                       |  15 +
>  hw/arm/orangepi.c                         | 127 ++++
>  hw/misc/allwinner-cpucfg.c                | 269 +++++++
>  hw/misc/allwinner-h3-ccu.c                | 243 ++++++
>  hw/misc/allwinner-h3-dramc.c              | 358 +++++++++
>  hw/misc/allwinner-h3-sysctrl.c            | 140 ++++
>  hw/misc/allwinner-sid.c                   | 170 +++++
>  hw/net/allwinner-sun8i-emac.c             | 871 ++++++++++++++++++++++
>  hw/rtc/allwinner-rtc.c                    | 386 ++++++++++
>  hw/sd/allwinner-sdhost.c                  | 848 +++++++++++++++++++++
>  hw/usb/hcd-ehci-sysbus.c                  |  17 +
>  MAINTAINERS                               |   9 +
>  hw/arm/Kconfig                            |   9 +
>  hw/arm/Makefile.objs                      |   1 +
>  hw/misc/Makefile.objs                     |   5 +
>  hw/misc/trace-events                      |  19 +
>  hw/net/Kconfig                            |   3 +
>  hw/net/Makefile.objs                      |   1 +
>  hw/net/trace-events                       |  10 +
>  hw/rtc/Makefile.objs                      |   1 +
>  hw/rtc/trace-events                       |   4 +
>  hw/sd/Makefile.objs                       |   1 +
>  hw/sd/trace-events                        |   7 +
>  tests/acceptance/avocado_qemu/__init__.py |  59 +-
>  tests/acceptance/boot_linux_console.py    | 210 ++++++
>  40 files changed, 5345 insertions(+), 14 deletions(-)
>  create mode 100644 docs/orangepi.rst
>  create mode 100644 include/hw/arm/allwinner-h3.h
>  create mode 100644 include/hw/misc/allwinner-cpucfg.h
>  create mode 100644 include/hw/misc/allwinner-h3-ccu.h
>  create mode 100644 include/hw/misc/allwinner-h3-dramc.h
>  create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
>  create mode 100644 include/hw/misc/allwinner-sid.h
>  create mode 100644 include/hw/net/allwinner-sun8i-emac.h
>  create mode 100644 include/hw/rtc/allwinner-rtc.h
>  create mode 100644 include/hw/sd/allwinner-sdhost.h
>  create mode 100644 hw/arm/allwinner-h3.c
>  create mode 100644 hw/arm/orangepi.c
>  create mode 100644 hw/misc/allwinner-cpucfg.c
>  create mode 100644 hw/misc/allwinner-h3-ccu.c
>  create mode 100644 hw/misc/allwinner-h3-dramc.c
>  create mode 100644 hw/misc/allwinner-h3-sysctrl.c
>  create mode 100644 hw/misc/allwinner-sid.c
>  create mode 100644 hw/net/allwinner-sun8i-emac.c
>  create mode 100644 hw/rtc/allwinner-rtc.c
>  create mode 100644 hw/sd/allwinner-sdhost.c
>
> --
> 2.17.1
>


-- 
Niek Linnenbank
Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Philippe Mathieu-Daudé 4 years, 1 month ago
On 2/12/20 10:47 PM, Niek Linnenbank wrote:
> Hi all,
> 
> Short status update regarding this series.
> 
> Currently I am debugging booting NetBSD 9.0-RC2, which is recently 
> released [1]
> The problem is that, apparently, RC2 can't mount the rootfs properly:
> 
> [   3.1871510] vfs_mountroot: can't open root device
> [   3.2141370] cannot mount root, error = 6
> 
> This only happens using the RC2 filesystem image. However, the RC2 
> kernel can
> properly load & boot the RC1 filesystem image, and the RC1 kernel gives 
> the same error
> on the RC2 filesystem.  But I dont think its a NetBSD-RC2 issue, because 
> on a real
> Orange Pi PC hardware board, this problem does not show.

Linux shows:
   console: mmc0: Problem switching card into high-speed mode!

QEMU MMC support is not in good shape, and high-speed SD card support is 
limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.

So you added:

  * DMA transfers
  * Direct FIFO I/O
  * Short/Long format command responses

I'd start diffing the trace output of the following events:

allwinner_sdhost*
sdcard*

with both kernels.

> 
> I'm comparing traces and adding more low-level debug output to NetBSD 
> and QEMU to find the issue.
> 
> Also I processed the review remarks which were send so far.
> 
> Kind regards,
> Niek
> 
> [1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html


Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Niek Linnenbank 4 years, 1 month ago
Hi Philippe,

On Wed, Feb 12, 2020 at 11:12 PM Philippe Mathieu-Daudé <philmd@redhat.com>
wrote:

> On 2/12/20 10:47 PM, Niek Linnenbank wrote:
> > Hi all,
> >
> > Short status update regarding this series.
> >
> > Currently I am debugging booting NetBSD 9.0-RC2, which is recently
> > released [1]
> > The problem is that, apparently, RC2 can't mount the rootfs properly:
> >
> > [   3.1871510] vfs_mountroot: can't open root device
> > [   3.2141370] cannot mount root, error = 6
> >
> > This only happens using the RC2 filesystem image. However, the RC2
> > kernel can
> > properly load & boot the RC1 filesystem image, and the RC1 kernel gives
> > the same error
> > on the RC2 filesystem.  But I dont think its a NetBSD-RC2 issue, because
> > on a real
> > Orange Pi PC hardware board, this problem does not show.
>
> Linux shows:
>    console: mmc0: Problem switching card into high-speed mode!
>
> QEMU MMC support is not in good shape, and high-speed SD card support is
> limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.
>
> So you added:
>
>   * DMA transfers
>   * Direct FIFO I/O
>   * Short/Long format command responses
>
> I'd start diffing the trace output of the following events:
>
> allwinner_sdhost*
> sdcard*
>
> with both kernels.
>
> Thanks for the kind suggestions Philippe.
Indeed, comparing the trace files of both the RC1 and RC2 kernels is one of
the things I did, and many more.

After extensive low-level debugging, I discovered that the issue is much
more simple than I thought.
In particular, when using -sd <file>, the emulated device gets the same
physical size as the file.
Normally this is not a problem, but for the NetBSD RC2 image, the kernel
reads the MBR partition table,
compares it with the device size and concludes that the NetBSD partition in
the image is larger than the actual device.

Unfortunately, this root cause is not printed on the NetBSD console, only
the final  'can't open root device' message.
Also, when running on hardware, obviously the SD card will be larger, e.g.
4GB or more, so that is why this issue does not show.

So the fix is to extend the input image by a few megabytes before booting
it.
And on the positive side, with this search we now have more confidence that
the
emulated SD/MMC device in Qemu works as expected.

Kind regards,
Niek


> >
> > I'm comparing traces and adding more low-level debug output to NetBSD
> > and QEMU to find the issue.
> >
> > Also I processed the review remarks which were send so far.
> >
> > Kind regards,
> > Niek
> >
> > [1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html
>
>

-- 
Niek Linnenbank
Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Philippe Mathieu-Daudé 4 years, 1 month ago
On 2/17/20 9:27 PM, Niek Linnenbank wrote:
> Hi Philippe,
> 
> On Wed, Feb 12, 2020 at 11:12 PM Philippe Mathieu-Daudé 
> <philmd@redhat.com <mailto:philmd@redhat.com>> wrote:
> 
>     On 2/12/20 10:47 PM, Niek Linnenbank wrote:
>      > Hi all,
>      >
>      > Short status update regarding this series.
>      >
>      > Currently I am debugging booting NetBSD 9.0-RC2, which is recently
>      > released [1]
>      > The problem is that, apparently, RC2 can't mount the rootfs properly:
>      >
>      > [   3.1871510] vfs_mountroot: can't open root device
>      > [   3.2141370] cannot mount root, error = 6
>      >
>      > This only happens using the RC2 filesystem image. However, the RC2
>      > kernel can
>      > properly load & boot the RC1 filesystem image, and the RC1 kernel
>     gives
>      > the same error
>      > on the RC2 filesystem.  But I dont think its a NetBSD-RC2 issue,
>     because
>      > on a real
>      > Orange Pi PC hardware board, this problem does not show.
> 
>     Linux shows:
>         console: mmc0: Problem switching card into high-speed mode!
> 
>     QEMU MMC support is not in good shape, and high-speed SD card
>     support is
>     limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.
> 
>     So you added:
> 
>        * DMA transfers
>        * Direct FIFO I/O
>        * Short/Long format command responses
> 
>     I'd start diffing the trace output of the following events:
> 
>     allwinner_sdhost*
>     sdcard*
> 
>     with both kernels.
> 
> Thanks for the kind suggestions Philippe.
> Indeed, comparing the trace files of both the RC1 and RC2 kernels is one 
> of the things I did, and many more.
> 
> After extensive low-level debugging, I discovered that the issue is much 
> more simple than I thought.
> In particular, when using -sd <file>, the emulated device gets the same 
> physical size as the file.
> Normally this is not a problem, but for the NetBSD RC2 image, the kernel 
> reads the MBR partition table,
> compares it with the device size and concludes that the NetBSD partition 
> in the image is larger than the actual device.
> 
> Unfortunately, this root cause is not printed on the NetBSD console, 
> only the final  'can't open root device' message.
> Also, when running on hardware, obviously the SD card will be larger, 
> e.g. 4GB or more, so that is why this issue does not show.
> 
> So the fix is to extend the input image by a few megabytes before 
> booting it.
> And on the positive side, with this search we now have more confidence 
> that the
> emulated SD/MMC device in Qemu works as expected.

Good news!

IIRC from the specs, cards are block devices and the only alignment 
required is the size of a block (512KiB for your 4GiB card).

That said I never saw a card not pow2 aligned, but the card firmware 
should be able to discard blocks and announce fewer. Maybe FreeBSD is 
incorrect assuming a pow2 alignment?

> 
> Kind regards,
> Niek
> 
>      >
>      > I'm comparing traces and adding more low-level debug output to
>     NetBSD
>      > and QEMU to find the issue.
>      >
>      > Also I processed the review remarks which were send so far.
>      >
>      > Kind regards,
>      > Niek
>      >
>      > [1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html
> 
> 
> 
> -- 
> Niek Linnenbank
> 


Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Peter Maydell 4 years, 1 month ago
On Tue, 18 Feb 2020 at 06:46, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> IIRC from the specs, cards are block devices and the only alignment
> required is the size of a block (512KiB for your 4GiB card).

Isn't there something related to erase blocks too, which impose
a larger granularity than just a single block?

Anyway, in general the backing image for an SD card device
needs to be exactly the size of the SD card you're emulating,
because QEMU needs somewhere it can write back the data
if the guest decides to write to the last block on the card.
So short-length images generally don't work (true for all
block devices, not just SD cards, I think). This often bites users
if they're using some distro "here's a disk/sd card image file"
where the expected use with real hardware is "dd the image
file onto the SD card".

thanks
-- PMM

Re: [PATCH v4 00/20] Add Allwinner H3 SoC and Orange Pi PC Machine
Posted by Niek Linnenbank 4 years, 1 month ago
Hi Peter & Philippe,

On Tue, Feb 18, 2020 at 11:05 AM Peter Maydell <peter.maydell@linaro.org>
wrote:

> On Tue, 18 Feb 2020 at 06:46, Philippe Mathieu-Daudé <philmd@redhat.com>
> wrote:
> > IIRC from the specs, cards are block devices and the only alignment
> > required is the size of a block (512KiB for your 4GiB card).
>
> Isn't there something related to erase blocks too, which impose
> a larger granularity than just a single block?
>
> Anyway, in general the backing image for an SD card device
> needs to be exactly the size of the SD card you're emulating,
> because QEMU needs somewhere it can write back the data
> if the guest decides to write to the last block on the card.
> So short-length images generally don't work (true for all
> block devices, not just SD cards, I think). This often bites users
> if they're using some distro "here's a disk/sd card image file"
> where the expected use with real hardware is "dd the image
> file onto the SD card".
>

Yes, the description you gave here is indeed the issue.
And unfortunately in this particular case, the distro did not give a very
understandable
diagnostic error message.

Kind regards,
Niek


>
> thanks
> -- PMM
>


-- 
Niek Linnenbank