How to create a QEMU ARM machine with custom peripherals and memory maps?
Asked Answered
M

3

39

I am writing a code for Cortex-M3 cpu and I am performing unit testing using qemu-arm binary. For now everything works just fine. But I am wondering If I am able to test whole system using qemu-system-arm? I mean, I want to write custom "machine" for qemu where I will define desired memory map and eventually some software imitation of desired peripherals, are there some examples of such module? I found very little amount of information about this. I have read some source code in hw directory in qemu source tree but it is almost all uncommented, and I am still not sure if I understand how to add new machine to the qemu and how append peripheral to the address space?

Materiel answered 4/5, 2016 at 13:15 Comment(5)
What do you see as a benefit to do it on an arm emulator? It might be easier if you worked on your favorite dev-system, after all. Just stick to C, don't use anything specific which is not available on Arm and you can simulate the target hardware probably in a more straightforward way.Caoutchouc
Too broad. If you want to write a custom machine for qemu, then do that. there are many there already use one of them as a starting point and the others as reference. If you end up with a specific problem, some code that doesnt work the way you think it should, then that is what stackoverflow is for.Leventhal
I've toyed with this idea for years, but in general, you would have to model the hardware peripherals you're talking to (which is really the interesting part of embedded work), and that isn't easy, and definitely isn't easy to be correct and is nearly impossible to model the quirks of the hardware peripherals. In short, I've always come to the conclusion that it's a fools errand.Mclin
Yeah, it is one of those things like climb the mountain "because its there" or just go around. Restore a classic car but then never drive it. Depending on the accuracy this could be a major task or not, and balance that with what you get vs just running on the hardware (you do get better visibility). It often becomes the mountain climbing hobby, or restoring a car, etc, not because I needed this tool, but more of I enjoyed the act of making the tool.Leventhal
I wouldnt assume that qemu's cpu cores are perfect nor constantly maintained, so you would have to start there.Leventhal
N
51

In order to add your own machine, you need at least create one source file, containing the parameters and peripherals of your machine. After that, add a entry inside Makefile.objs, under qemu/hw/arm/. STM32 P103 machine entry.

Let's take as example Olimex STM32 P103 Development Board: Olimex STM32 P103 Development Board code. In lines 105 and 106, we have flash_size and ram_size. In lines 114 and 115 the code add a LED connect to GPIO A pin 0. In line 130 we have machine description, "Olimex STM32 p103 Dev Board". In line 131, the machine init function: stm32_p103_init. Another example of a machine more complete: Pebble machine code.

About peripherals, they are instantiated in each family code, considering stm32 case. stm32f1 family: stm32f1xx.c, stm32f2 family: stm32f2xx.c, stm32f4 family: stm32f4xx.c. The peripheral itself is implemented in a driver which typically has a suggestive name: stm32f2xx_adc.c, stm32f2xx_crc.c and so on. Example of a patch that add new peripheral: Addition of ADC to STM32.

Noncontributory answered 21/7, 2016 at 19:49 Comment(2)
Thank you very much for this answer. I have needed exactly that kind of a tip!Materiel
Ok, good! And sorry, I forgot to mention about peripherals. So I edited the post to include more informations.Noncontributory
D
1

For posterity, back in 2014, v3wwg created a new arm machine by making changes to Stellaris, an existing machine. Others who find this post can track his work by reading his thread on the [PRJC forum][1] and reviewing commits made to his qemu fork: https://github.com/ve3wwg/teensy3_qemu/commits/master

Dagley answered 19/2, 2021 at 19:10 Comment(0)
C
0

You can use Jumper Virtual Lab for simulation, check out this blog post from ARM mBed.

Cyanotype answered 10/9, 2018 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.