qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bernhard Beschow <shentey@gmail.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	qemu-arm@nongnu.org, "Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Subject: Re: [PATCH 08/21] hw/arm/fsl-imx8mp: Add USDHC storage controllers
Date: Mon, 03 Feb 2025 23:01:03 +0000	[thread overview]
Message-ID: <FA8D7DA4-2CD8-4310-A210-A147EE385103@gmail.com> (raw)
In-Reply-To: <3e6208b1-7d70-5205-a92f-549d7d2fff13@eik.bme.hu>



Am 21. Januar 2025 02:52:58 UTC schrieb BALATON Zoltan <balaton@eik.bme.hu>:
>On Mon, 20 Jan 2025, Bernhard Beschow wrote:
>> The USDHC emulation allows for running real-world images such as those generated
>> by Buildroot. Convert the board documentation accordingly instead of running a
>> Linux kernel with ephemeral storage.
>> 
>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>> ---
>> docs/system/arm/imx8mp-evk.rst | 39 +++++++++++++++++++++++-----------
>> include/hw/arm/fsl-imx8mp.h    |  7 ++++++
>> hw/arm/fsl-imx8mp.c            | 28 ++++++++++++++++++++++++
>> hw/arm/imx8mp-evk.c            | 18 ++++++++++++++++
>> hw/arm/Kconfig                 |  1 +
>> 5 files changed, 81 insertions(+), 12 deletions(-)
>> 
>> diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst
>> index d7d08cc198..1514bc5864 100644
>> --- a/docs/system/arm/imx8mp-evk.rst
>> +++ b/docs/system/arm/imx8mp-evk.rst
>> @@ -13,6 +13,7 @@ The ``imx8mp-evk`` machine implements the following devices:
>>  * Up to 4 Cortex-A53 Cores
>>  * Generic Interrupt Controller (GICv3)
>>  * 4 UARTs
>> + * 3 USDHC Storage Controllers
>>  * Secure Non-Volatile Storage (SNVS) including an RTC
>>  * Clock Tree
>> 
>> @@ -25,25 +26,39 @@ for loading a Linux kernel.
>> Direct Linux Kernel Boot
>> ''''''''''''''''''''''''
>> 
>> -Linux mainline v6.12 release is tested at the time of writing. To build a Linux
>> -mainline kernel that can be booted by the ``imx8mp-evk`` machine, simply
>> -configure the kernel using the defconfig configuration:
>> +Probably the easiest way to get started with a whole Linux system on the machine
>> +is to generate an image with Buildroot. Version 2024.11.1 is tested at the time
>> +of writing and involves three steps. First run the following command in the
>> +toplevel directory of the Buildroot source tree:
>> 
>> .. code-block:: bash
>> 
>> -  $ export ARCH=arm64
>> -  $ export CROSS_COMPILE=aarch64-linux-gnu-
>> -  $ make defconfig
>> +  $ make freescale_imx8mpevk_defconfig
>>   $ make
>
>Adding documentation that is removed a few patches later seems unnecessary. Maybe you could keep the bare kernel docs as that could also be useful or not add it in the first place? But if this is already written keeping it may make more sense than dropping it.

I'd like the documentation to be complete and easy to follow at the same time. Buildroot achieves both, and allows for generating a cpio initrd instead. So I'd start with that which just requires minor adjustments here.

Best regards,
Bernhard

>
>Regards,
>BALATON Zoltan
>
>> 
>> -To boot the newly built Linux kernel in QEMU with the ``imx8mp-evk`` machine,
>> -run:
>> +Once finished successfully there is an ``output/image`` subfolder. Navigate into
>> +it and resize the SD card image to a power of two:
>> +
>> +.. code-block:: bash
>> +
>> +  $ qemu-img resize sdcard.img 256M
>> +
>> +Finally, the device tree needs to be patched with the following commands which
>> +will remove the ``cpu-idle-states`` properties from CPU nodes:
>> +
>> +.. code-block:: bash
>> +
>> +  $ dtc imx8mp-evk.dtb | sed '/cpu-idle-states/d' > imx8mp-evk-patched.dts
>> +  $ dtc imx8mp-evk-patched.dts -o imx8mp-evk-patched.dtb
>> +
>> +Now that everything is prepared the newly built image can be run in the QEMU
>> +``imx8mp-evk`` machine:
>> 
>> .. code-block:: bash
>> 
>>   $ qemu-system-aarch64 -M imx8mp-evk -smp 4 -m 3G \
>>       -display none -serial null -serial stdio \
>> -      -kernel arch/arm64/boot/Image \
>> -      -dtb arch/arm64/boot/dts/freescale/imx8mp-evk.dtb \
>> -      -initrd /path/to/rootfs.ext4 \
>> -      -append "root=/dev/ram"
>> +      -kernel Image \
>> +      -dtb imx8mp-evk-patched.dtb \
>> +      -append "root=/dev/mmcblk2p2" \
>> +      -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2
>> diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h
>> index 9d2a757c2a..9832c05e8c 100644
>> --- a/include/hw/arm/fsl-imx8mp.h
>> +++ b/include/hw/arm/fsl-imx8mp.h
>> @@ -14,6 +14,7 @@
>> #include "hw/intc/arm_gicv3_common.h"
>> #include "hw/misc/imx7_snvs.h"
>> #include "hw/misc/imx8mp_ccm.h"
>> +#include "hw/sd/sdhci.h"
>> #include "qom/object.h"
>> #include "qemu/units.h"
>> 
>> @@ -27,6 +28,7 @@ enum FslImx8mpConfiguration {
>>     FSL_IMX8MP_NUM_CPUS         = 4,
>>     FSL_IMX8MP_NUM_IRQS         = 160,
>>     FSL_IMX8MP_NUM_UARTS        = 4,
>> +    FSL_IMX8MP_NUM_USDHCS       = 3,
>> };
>> 
>> struct FslImx8mpState {
>> @@ -38,6 +40,7 @@ struct FslImx8mpState {
>>     IMX8MPAnalogState  analog;
>>     IMX7SNVSState      snvs;
>>     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
>> +    SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
>> };
>> 
>> enum FslImx8mpMemoryRegions {
>> @@ -183,6 +186,10 @@ enum FslImx8mpMemoryRegions {
>> };
>> 
>> enum FslImx8mpIrqs {
>> +    FSL_IMX8MP_USDHC1_IRQ   = 22,
>> +    FSL_IMX8MP_USDHC2_IRQ   = 23,
>> +    FSL_IMX8MP_USDHC3_IRQ   = 24,
>> +
>>     FSL_IMX8MP_UART1_IRQ    = 26,
>>     FSL_IMX8MP_UART2_IRQ    = 27,
>>     FSL_IMX8MP_UART3_IRQ    = 28,
>> diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c
>> index 0abde2b1fc..612ea7bf93 100644
>> --- a/hw/arm/fsl-imx8mp.c
>> +++ b/hw/arm/fsl-imx8mp.c
>> @@ -210,6 +210,11 @@ static void fsl_imx8mp_init(Object *obj)
>>         snprintf(name, NAME_SIZE, "uart%d", i + 1);
>>         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
>>     }
>> +
>> +    for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
>> +        snprintf(name, NAME_SIZE, "usdhc%d", i + 1);
>> +        object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
>> +    }
>> }
>> 
>> static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
>> @@ -350,6 +355,28 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
>>                            qdev_get_gpio_in(gicdev, serial_table[i].irq));
>>     }
>> 
>> +    /* USDHCs */
>> +    for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
>> +        static const struct {
>> +            hwaddr addr;
>> +            unsigned int irq;
>> +        } usdhc_table[FSL_IMX8MP_NUM_USDHCS] = {
>> +            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC1].addr, FSL_IMX8MP_USDHC1_IRQ },
>> +            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC2].addr, FSL_IMX8MP_USDHC2_IRQ },
>> +            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC3].addr, FSL_IMX8MP_USDHC3_IRQ },
>> +        };
>> +
>> +        object_property_set_uint(OBJECT(&s->usdhc[i]), "vendor",
>> +                                 SDHCI_VENDOR_IMX, &error_abort);
>> +        if (!sysbus_realize(SYS_BUS_DEVICE(&s->usdhc[i]), errp)) {
>> +            return;
>> +        }
>> +
>> +        sysbus_mmio_map(SYS_BUS_DEVICE(&s->usdhc[i]), 0, usdhc_table[i].addr);
>> +        sysbus_connect_irq(SYS_BUS_DEVICE(&s->usdhc[i]), 0,
>> +                           qdev_get_gpio_in(gicdev, usdhc_table[i].irq));
>> +    }
>> +
>>     /* SNVS */
>>     if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
>>         return;
>> @@ -367,6 +394,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
>>         case FSL_IMX8MP_RAM:
>>         case FSL_IMX8MP_SNVS_HP:
>>         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
>> +        case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3:
>>             /* device implemented and treated above */
>>             break;
>> 
>> diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c
>> index 2756d4c21c..27d9e9e8ee 100644
>> --- a/hw/arm/imx8mp-evk.c
>> +++ b/hw/arm/imx8mp-evk.c
>> @@ -11,6 +11,7 @@
>> #include "hw/arm/boot.h"
>> #include "hw/arm/fsl-imx8mp.h"
>> #include "hw/boards.h"
>> +#include "hw/qdev-properties.h"
>> #include "system/qtest.h"
>> #include "qemu/error-report.h"
>> #include "qapi/error.h"
>> @@ -40,6 +41,23 @@ static void imx8mp_evk_init(MachineState *machine)
>>     memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START,
>>                                 machine->ram);
>> 
>> +    for (int i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
>> +        BusState *bus;
>> +        DeviceState *carddev;
>> +        BlockBackend *blk;
>> +        DriveInfo *di = drive_get(IF_SD, i, 0);
>> +
>> +        if (!di) {
>> +            continue;
>> +        }
>> +
>> +        blk = blk_by_legacy_dinfo(di);
>> +        bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
>> +        carddev = qdev_new(TYPE_SD_CARD);
>> +        qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
>> +        qdev_realize_and_unref(carddev, bus, &error_fatal);
>> +    }
>> +
>>     if (!qtest_enabled()) {
>>         arm_load_kernel(&s->cpu[0], machine, &boot_info);
>>     }
>> diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
>> index adb4ed8076..f880c03d35 100644
>> --- a/hw/arm/Kconfig
>> +++ b/hw/arm/Kconfig
>> @@ -582,6 +582,7 @@ config FSL_IMX8MP
>>     imply TEST_DEVICES
>>     select ARM_GIC
>>     select IMX
>> +    select SDHCI
>>     select UNIMP
>> 
>> config FSL_IMX8MP_EVK
>> 


  reply	other threads:[~2025-02-03 23:01 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 20:37 [PATCH 00/21] Add i.MX 8M Plus EVK machine Bernhard Beschow
2025-01-20 20:37 ` [PATCH 01/21] hw/char/imx_serial: Fix reset value of UFCR register Bernhard Beschow
2025-01-20 20:37 ` [PATCH 02/21] hw/char/imx_serial: Update all state before restarting ageing timer Bernhard Beschow
2025-01-20 20:37 ` [PATCH 03/21] hw/pci-host/designware: Expose MSI IRQ Bernhard Beschow
2025-01-20 20:37 ` [PATCH 04/21] hw/usb/hcd-dwc3: Align global registers size with Linux Bernhard Beschow
2025-01-28 14:21   ` Peter Maydell
2025-01-20 20:37 ` [PATCH 05/21] hw/arm: Add i.MX 8M Plus EVK board Bernhard Beschow
2025-01-28 14:29   ` Peter Maydell
2025-01-28 22:16     ` Bernhard Beschow
2025-01-29 12:17       ` Peter Maydell
2025-01-29 13:04         ` Bernhard Beschow
2025-01-20 20:37 ` [PATCH 06/21] hw/arm/fsl-imx8mp: Implement clock tree Bernhard Beschow
2025-01-28 14:35   ` Peter Maydell
2025-01-28 21:53     ` Bernhard Beschow
2025-01-20 20:37 ` [PATCH 07/21] hw/arm/fsl-imx8mp: Add SNVS Bernhard Beschow
2025-01-28 14:31   ` Peter Maydell
2025-01-20 20:37 ` [PATCH 08/21] hw/arm/fsl-imx8mp: Add USDHC storage controllers Bernhard Beschow
2025-01-21  2:52   ` BALATON Zoltan
2025-02-03 23:01     ` Bernhard Beschow [this message]
2025-01-20 20:37 ` [PATCH 09/21] hw/arm/fsl-imx8mp: Add PCIe support Bernhard Beschow
2025-01-28 14:33   ` Peter Maydell
2025-01-28 22:04     ` Bernhard Beschow
2025-01-29 17:54       ` BALATON Zoltan
2025-02-01 14:45         ` Bernhard Beschow
2025-01-20 20:37 ` [PATCH 10/21] hw/arm/fsl-imx8mp: Add GPIO controllers Bernhard Beschow
2025-01-20 20:37 ` [PATCH 11/21] hw/arm/fsl-imx8mp: Add I2C controllers Bernhard Beschow
2025-01-20 20:37 ` [PATCH 12/21] hw/arm/fsl-imx8mp: Add SPI controllers Bernhard Beschow
2025-01-20 20:37 ` [PATCH 13/21] hw/arm/fsl-imx8mp: Add watchdog support Bernhard Beschow
2025-01-20 20:37 ` [PATCH 14/21] hw/arm/fsl-imx8mp: Implement gneral purpose timers Bernhard Beschow
2025-01-20 20:37 ` [PATCH 15/21] hw/arm/fsl-imx8mp: Add Ethernet controller Bernhard Beschow
2025-01-20 20:37 ` [PATCH 16/21] hw/arm/fsl-imx8mp: Add USB support Bernhard Beschow
2025-01-20 20:37 ` [PATCH 17/21] hw/arm/fsl-imx8mp: Add boot ROM Bernhard Beschow
2025-01-21  3:00   ` BALATON Zoltan
2025-01-21 21:03     ` Bernhard Beschow
2025-01-20 20:37 ` [PATCH 18/21] hw/arm/fsl-imx8mp: Add on-chip RAM Bernhard Beschow
2025-01-20 20:37 ` [PATCH 19/21] hw/rtc: Add Ricoh RS5C372 RTC emulation Bernhard Beschow
2025-01-20 20:37 ` [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx Bernhard Beschow
2025-01-21  3:07   ` BALATON Zoltan
2025-01-28 22:20     ` Bernhard Beschow
2025-01-30  1:14   ` Corey Minyard
2025-01-30 23:05   ` Philippe Mathieu-Daudé
2025-02-01 15:28     ` Bernhard Beschow
2025-02-02 17:09       ` Philippe Mathieu-Daudé
2025-02-03  5:42         ` Dmitriy Sharikhin
2025-02-04  8:13           ` Bernhard Beschow
2025-02-17 18:06           ` Bernhard Beschow
2025-02-03 22:38         ` Bernhard Beschow
2025-01-20 20:37 ` [PATCH 21/21] hw/gpio/imx_gpio: Don't clear input GPIO values upon reset Bernhard Beschow
2025-01-28 14:33   ` Gustavo Romero
2025-02-03 23:06     ` Bernhard Beschow

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=FA8D7DA4-2CD8-4310-A210-A147EE385103@gmail.com \
    --to=shentey@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=andrew.smirnov@gmail.com \
    --cc=balaton@eik.bme.hu \
    --cc=edgar.iglesias@gmail.com \
    --cc=jcd@tribudubois.net \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).