Enabling Qemu support for iMX8MM EVK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Enabling Qemu support for iMX8MM EVK

Enabling Qemu support for iMX8MM EVK

This blog specifically aims at explaining how we can enable QEMU emulation for iMX8MM EVK.
Imagine not having the hardware but still you want to test the software. Qemu gives you exactly that.

1. Booting uboot, linux and user-space application even when you do not possess a real hardware.
2. Early firmware development when the silicon doesn’t yet exist.
3. Linux driver development, debugging and testing. 

There are tons of articles on the web that gets into the nitty-gritties of it along with the official documentation -
Welcome to QEMU’s documentation! — QEMU documentation so we urge the readers to go through it.

Up until now, there was no support for enabling iMX8MM. As part of this blog, we are attaching a series of patches that enable support of Qemu emulation for iMX8MM EVK. Meaning, without having iMX8MM EVK board at your disposal, you can test the uboot,linux bsp and user space applications. 
 

Qemu is a generic open-source machine emulator that lets you run software built for one hardware platform on a completely different host system. An example would be emulating an ARM based SOC on a x86 PC. It emulates CPU and the entire machine using virtualization on the host system such as KVM.

This CPU emulation is done via DBT[Dynamic Binary Translation]. It is a runtime technique that translates executable code from one instruction set architecture to another on the fly. The translator reads guest instructions, coverts them into an intermediate representation, then emits native code for the host processor.

For example:-
 

When you emulate an ARM CPU on an x86 host, QEMU uses Dynamic Binary Translation:

  1. Guest ARM instructions are fetched
  2. QEMU translates ARM instruction blocks → x86 instructions
  3. Translated blocks are cached
  4. Control flow is preserved exactly

This happens via QEMU’s TCG (Tiny Code Generator).
 
A SOC contains: -

CPU(ARM,x86,RISC-V etc)
Interrupt controller

General purpose and Watchdog Timers

UART,I2C, SPI
Memory map

DMA, Ethernet, USB, PCIe

Similarly, iMX8MM EVK also has all of the above. You can visit this page to get a user manual and reference manual -
i.MX 8M Mini | Arm Cortex A53 | Cortex M4 | NXP Semiconductors

 

Qemu presents a coherent “machine” made of memory regions and devices. RAM is backed by host memory.  QEMU’s memory subsystem is explicitly designed to model RAM and MMIO via MemoryRegion graphs and callback-based IO regions.

iMX8MM SOC is based on Cortex-A53 with a broad set of connectivity peripherals. The patches mirrors those blocks of peripherals.

 To enable qemu support, fetch the qemu repo's master branch and apply the patches attached with this blog. Build the qemu after the patches are applied. Steps to build are mentioned in the repo's readme itself -

 

https://github.com/qemu/QEMU

There are 2 ways you can test these changes:-

1. Using the functional testing python script that comes as a part of these patches.

Execute the following to trigger a test:-

python3 tests/functional/aarch64/test_imx8mm_evk.py

This functional test boots a linux kernel and checks the console. It will return Ok if it succeeds.
 

  1. Using the kernel 'Image' and imx8mm dtb from your bsp and rootfs img file which can be downloaded from here - Buildroot 2024.02 Release for i.MX Platforms | Ezurio

    After you have the 'Image', 'imx8mm-evk.dtb' and downloaded rootfs '20240522-br2024.02-nitrogen8mm_qt5_gst1.img', execute this command in the build folder:-

    ./qemu-bundle/usr/local/bin/qemu-system-aarch64 -M imx8mm-evk -smp 4 -m 3G -display none -serial null -serial stdio -kernel ~/qemu-emulation/iMX8MM/Image -dtb ~/qemu-emulation/iMX8MM/imx8mm-evk.dtb -append "root=/dev/mmcblk2p1" -drive file=~/qemu-emulation/iMX8MM/20240522-br2024.02-nitrogen8mm_qt5_gst1.img,if=sd,bus=2,format=raw,id=mmcblk2
     
    1.png2.png
Attachments
%3CLINGO-SUB%20id%3D%22lingo-sub-2347939%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EEnabling%20Qemu%20support%20for%20iMX8MM%20EVK%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2347939%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%0A%3CP%3EThis%20blog%20specifically%20aims%20at%20explaining%20how%20we%20can%20enable%20QEMU%20emulation%20for%20iMX8MM%20EVK.%3CBR%20%2F%3EImagine%20not%20having%20the%20hardware%20but%20still%20you%20want%20to%20test%20the%20software.%20Qemu%20gives%20you%20exactly%20that.%20%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20Booting%20uboot%2C%20linux%20and%20user-space%20application%20even%20when%20you%20do%20not%20possess%20a%20real%20hardware.%3CBR%20%2F%3E2.%20Early%20firmware%20development%20when%20the%20silicon%20doesn%E2%80%99t%20yet%20exist.%3CBR%20%2F%3E%3CSPAN%3E3.%20Linux%20driver%20development%2C%20debugging%20and%20testing.%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThere%20are%20tons%20of%20articles%20on%20the%20web%20that%20gets%20into%20the%20nitty-gritties%20of%20it%20along%20with%20the%20official%20documentation%20-%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.qemu.org%2Fdocs%2Fmaster%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSPAN%3EWelcome%20to%20QEMU%E2%80%99s%20documentation!%20%E2%80%94%20QEMU%20documentation%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%20so%20we%20urge%20the%20readers%20to%20go%20through%20it.%3CBR%20%2F%3E%3CBR%20%2F%3EUp%20until%20now%2C%20there%20was%20no%20support%20for%20enabling%20iMX8MM.%20As%20part%20of%20this%20blog%2C%20we%20are%20attaching%20a%20series%20of%20patches%20that%20enable%20support%20of%20Qemu%20emulation%20for%20iMX8MM%20EVK.%20Meaning%2C%20without%20having%20iMX8MM%20EVK%20board%20at%20your%20disposal%2C%20you%20can%20test%20the%20uboot%2Clinux%20bsp%20and%20user%20space%20applications.%26nbsp%3B%20%3CBR%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EQemu%20is%20a%20generic%20open-source%20machine%20emulator%20that%20lets%20you%20run%20software%20built%20for%20one%20hardware%20platform%20on%20a%20completely%20different%20host%20system.%20An%20example%20would%20be%20emulating%20an%20ARM%20based%20SOC%20on%20a%20x86%20PC.%20It%20emulates%20CPU%20and%20the%20entire%20machine%20using%20virtualization%20on%20the%20host%20system%20such%20as%20KVM.%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20CPU%20emulation%20is%20done%20via%20DBT%5BDynamic%20Binary%20Translation%5D.%20It%20is%20a%20runtime%20technique%20that%20translates%20executable%20code%20from%20one%20instruction%20set%20architecture%20to%20another%20on%20the%20fly.%20The%20translator%20reads%20guest%20instructions%2C%20coverts%20them%20into%20an%20intermediate%20representation%2C%20then%20emits%20native%20code%20for%20the%20host%20processor.%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20example%3A-%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWhen%20you%20emulate%20an%20ARM%20CPU%20on%20an%20x86%20host%2C%20QEMU%20uses%20%3C%2FSPAN%3E%3CSTRONG%3EDynamic%20Binary%20Translation%3C%2FSTRONG%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EGuest%20ARM%20instructions%20are%20fetched%3C%2FLI%3E%0A%3CLI%3EQEMU%20translates%20ARM%20instruction%20blocks%20%E2%86%92%20x86%20instructions%3C%2FLI%3E%0A%3CLI%3ETranslated%20blocks%20are%20cached%3C%2FLI%3E%0A%3CLI%3EControl%20flow%20is%20preserved%20exactly%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%3EThis%20happens%20via%20QEMU%E2%80%99s%20%3C%2FSPAN%3E%3CSTRONG%3ETCG%20(Tiny%20Code%20Generator)%3C%2FSTRONG%3E%3CSPAN%3E.%3CBR%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3CBR%20%2F%3EA%20SOC%20contains%3A%20-%3CBR%20%2F%3E%3CBR%20%2F%3ECPU(ARM%2Cx86%2CRISC-V%20etc)%3CBR%20%2F%3EInterrupt%20controller%3C%2FP%3E%0A%3CP%3EGeneral%20purpose%20and%20Watchdog%20Timers%3C%2FP%3E%0A%3CP%3EUART%2CI2C%2C%20SPI%3CBR%20%2F%3EMemory%20map%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EDMA%2C%20Ethernet%2C%20USB%2C%20PCIe%20%3CBR%20%2F%3E%3CBR%20%2F%3ESimilarly%2C%20iMX8MM%20EVK%20also%20has%20all%20of%20the%20above.%20You%20can%20visit%20this%20page%20to%20get%20a%20user%20manual%20and%20reference%20manual%20-%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nxp.com%2Fproducts%2Fi.MX8MMINI%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSPAN%3Ei.MX%208M%20Mini%20%7C%20Arm%20Cortex%20A53%20%7C%20Cortex%20M4%20%7C%20NXP%20Semiconductors%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EQemu%20presents%20a%20coherent%20%E2%80%9Cmachine%E2%80%9D%20made%20of%20memory%20regions%20and%20devices.%20RAM%20is%20backed%20by%20host%20memory.%26nbsp%3B%20QEMU%E2%80%99s%20memory%20subsystem%20is%20explicitly%20designed%20to%20model%20RAM%20and%20MMIO%20via%20%3C%2FSPAN%3E%3CSPAN%3EMemoryRegion%3C%2FSPAN%3E%3CSPAN%3E%20graphs%20and%20callback-based%20IO%20regions.%3CBR%20%2F%3E%3CBR%20%2F%3EiMX8MM%20SOC%20is%20based%20on%20Cortex-A53%20with%20a%20broad%20set%20of%20connectivity%20peripherals.%20The%20patches%20mirrors%20those%20blocks%20of%20peripherals.%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3BTo%20enable%20qemu%20support%2C%20fetch%20the%20qemu%20repo's%20master%20branch%20and%20apply%20the%20patches%20attached%20with%20this%20blog.%20Build%20the%20qemu%20after%20the%20patches%20are%20applied.%20Steps%20to%20build%20are%20mentioned%20in%20the%20repo's%20readme%20itself%20-%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fqemu%2FQEMU%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fqemu%2FQEMU%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThere%20are%202%20ways%20you%20can%20test%20these%20changes%3A-%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20Using%20the%20functional%20testing%20python%20script%20that%20comes%20as%20a%20part%20of%20these%20patches.%3CBR%20%2F%3E%3CBR%20%2F%3EExecute%20the%20following%20to%20trigger%20a%20test%3A-%3CBR%20%2F%3E%3CBR%20%2F%3Epython3%20tests%2Ffunctional%2Faarch64%2Ftest_imx8mm_evk.py%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20functional%20test%20boots%20a%20linux%20kernel%20and%20checks%20the%20console.%20It%20will%20return%20Ok%20if%20it%20succeeds.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CSPAN%3E%20Using%20the%20kernel%20'Image'%20and%20imx8mm%20dtb%20from%20your%20bsp%20and%20rootfs%20img%20file%20which%20can%20be%20downloaded%20from%20here%20-%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.ezurio.com%2Fdocumentation%2Fbuildroot-2024-02-release-for-i-mx-platforms%3Fsrsltid%3DAfmBOoq_nbs2NsiJ4WTuynkXfQEw08BcZJqhxmE4fghsJ1JteisY14wO%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSPAN%3EBuildroot%202024.02%20Release%20for%20i.MX%20Platforms%20%7C%20Ezurio%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAfter%20you%20have%20the%20'Image'%2C%20'imx8mm-evk.dtb'%20and%20downloaded%20rootfs%20'20240522-br2024.02-nitrogen8mm_qt5_gst1.img'%2C%20execute%20this%20command%20in%20the%20build%20folder%3A-%3CBR%20%2F%3E%3CBR%20%2F%3E.%2Fqemu-bundle%2Fusr%2Flocal%2Fbin%2Fqemu-system-aarch64%20-M%20imx8mm-evk%20-smp%204%20-m%203G%20-display%20none%20-serial%20null%20-serial%20stdio%20-kernel%20~%2Fqemu-emulation%2FiMX8MM%2FImage%20-dtb%20~%2Fqemu-emulation%2FiMX8MM%2Fimx8mm-evk.dtb%20-append%20%22root%3D%2Fdev%2Fmmcblk2p1%22%20-drive%20file%3D~%2Fqemu-emulation%2FiMX8MM%2F20240522-br2024.02-nitrogen8mm_qt5_gst1.img%2Cif%3Dsd%2Cbus%3D2%2Cformat%3Draw%2Cid%3Dmmcblk2%3CBR%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%221.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%221.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F381697i17A56A9D0238BF65%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%221.png%22%20alt%3D%221.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%222.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F381696iDAC759CB16BE196F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%222.png%22%20alt%3D%222.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2347939%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThis%20blog%20enables%20support%20of%20Qemu%20emulation%20for%20iMX8MM%20EVK.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EImagine%20not%20having%20the%20hardware%20but%20still%20you%20want%20to%20test%20the%20software.%20Qemu%20gives%20you%20exactly%20that.%20%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20Booting%20uboot%2C%20linux%20and%20user-space%20application%20even%20when%20you%20do%20not%20possess%20a%20real%20hardware.%3CBR%20%2F%3E2.%20Early%20firmware%20development%20when%20the%20silicon%20doesn%E2%80%99t%20yet%20exist.%3CBR%20%2F%3E3.%20Linux%20driver%20development%2C%20debugging%20and%20testing.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
No ratings
Version history
Last update:
4 weeks ago
Updated by: