ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6027
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: QEMU patches for RPi emulation - Initial release

Sat Nov 30, 2013 5:04 pm

Ah, thanks for the thorough explanation.

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Sat Nov 30, 2013 9:54 pm

QEMU supports a net USB device. Try calling the emulation with

Code: Select all

-usb -usbdevice keyboard -usbdevice mouse -usbdevice net
. Here is the result from my test:
[ 13.152882] usb 1-1.3: new full-speed USB device number 5 using dwc_otg
usbnet: failed control transaction: request 0x8006 value 0x600 index 0x0 length 0xa
qemu-system-arm: /qemu/hw/arm/bcm2835_usb.c:229: channel_enable: Assertion `0' failed.

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Sat Nov 30, 2013 10:15 pm

Oh, great :)
It should be easier that way, at least I can enhance/debug the USB emulation separatedly from the NIC one.
Thanks for the info.

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Sat Nov 30, 2013 10:16 pm

Hi Greg,

the latest version is a great step towards compatibility with QEMU mainstream. The code now passes the script which checks the coding conventions (scripts/checkpatch.pl).

May I suggest some further improvements? I tried sorting the include statements and removed some of them which were not needed. Then I simplified some timer related function calls. Finally I replaced some string constants by macros which have the same value. The patch for these modifications is available from http://qemu.weilnetz.de/patches/raspi-20131130.patch.

In addition, I suggest either removing code which is currently unused, or replacing the comments by #if 0 ... #endif like this:

Code: Select all

    /* cpu_pic = arm_pic_init_cpu(cpu);
    dev = sysbus_create_varargs("bcm2835_ic", ARMCTRL_IC_BASE,
        cpu_pic[ARM_PIC_CPU_IRQ],
        cpu_pic[ARM_PIC_CPU_FIQ], NULL);*/

#if 0 /* This is better. Add a comment why this code is here. */
    cpu_pic = arm_pic_init_cpu(cpu);
    dev = sysbus_create_varargs("bcm2835_ic", ARMCTRL_IC_BASE,
        cpu_pic[ARM_PIC_CPU_IRQ],
        cpu_pic[ARM_PIC_CPU_FIQ], NULL);
#endif
Cheers,
Stefan

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Sun Dec 01, 2013 3:53 pm

Hi Stefan,
I've applied your patch and done additional code cleanup as you suggested.

I've also added the proposed patch file to https://github.com/Torlus/qemu-rpi
I've added you to the "signed-off-by" list, I hope you don't mind, otherwise just tell me.

Regards,
Greg

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Sun Dec 01, 2013 8:35 pm

Hi Greg,

please use only your personal Signed-off-by for the patch which you send to qemu-devel and add Jan, me and perhaps other contributors to the e-mail addresses (CC:). Then we can send a public answer and add our own Signed-off-by.

I now reviewed more of the code and have some additional suggestions:

The newly written code must not add macros which start with underscores, so macros like __BCM2835_COMMON_H will have to be replaced by BCM2835_COMMON_H. I think this does not apply to code copied from external projects (Linux).

printf statements should avoid type casts for the arguments and use the correct format specifiers instead of this. Most (all?) printf statements are currently used for debug code. Maybe it would be good to use the standard tracing mechanism of QEMU, see docs/tracing.txt for details and remove the conditional compilations, especially because some parts of the code are still experimental.

These lines can be removed because they are not relevant for Raspberry Pi:
+ * Specification available at:
+ * http://www.milkymist.org/socdoc/vgafb.pdf
The local array irq_dups is const, so please add the const attribute.

I think even without these modifications you can send your patch (please use git send email) to qemu-devel (of course only with your own Signed-off-by) and wait for answers. You'll get more suggestions from the list, so be prepared for some iterations until it is accepted, but I'm sure that it will be accepted finally.

Best regards,
Stefan

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Sun Dec 01, 2013 10:05 pm

Hi Stefan,
Thanks for the advice, I will fix what you've suggested so far, and I'll tell you when it's done.
Regards,
Greg

jp1
Posts: 12
Joined: Wed Nov 13, 2013 5:32 am

Re: QEMU patches for RPi emulation - Initial release

Tue Dec 03, 2013 10:24 am

@swell: nice hints, thanks.

But I don't agree with your hint to remove additional signs. At least I spent
some time cleaning the code (even sed tool helped me much) to get raspi machine
"upstreamable". As is described in the SubmittingPatches document it is perfectly
OK to add sign on it. But I don't insist on it. I would be happy to get code in Qemu
to allow futher enhancements/fixing possible.

Anyway, I think we have to fix only stuffs regarding code cleaning and resend it to the Qemu-dev for getting upstreaming process started. It is good start point and every feature fix/enhance can be added lately on.

/Honza

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Tue Dec 03, 2013 8:57 pm

Hi,
I did some additional cleaning and pushed it to GitHub.
However, as someone in the mailing list stated, 1) it doesn't cope well with the directory structure and 2) the patch should be splitted in several smaller patches, which is understandable.
Fixing 1) shouldn't be too hard, however I don't really know how to cope easily with 2)

Any suggestion?

Regards,
Greg

jp1
Posts: 12
Joined: Wed Nov 13, 2013 5:32 am

Re: QEMU patches for RPi emulation - Initial release

Wed Dec 04, 2013 8:52 am

Torlus wrote:Hi,
I did some additional cleaning and pushed it to GitHub.
Great.
However, as someone in the mailing list stated, 1) it doesn't cope well with the directory structure
What he means for? Something regarding the naming? That all files (bcm2835_xxx) are in hw/arm/ directory?
Of course it can be scattered around device specific directories, something like hw/usb/bcm2835_usb.c, hw/timer/bcm2835_timer.c ... etc? If so it is not problem to move them there. One git commit including file rename should do the job :)
and 2) the patch should be splitted in several smaller patches, which is understandable.
That is I was a bit worried about ;) Of course it would be nice to have several commits (like "basic model add", "usb add" ...etc) but because it is a bit hard to manage, I prefer to do initial one-big-patch which will be base for the rest updates/fixes.

Anyway, it can be disscussed on Qemu-dev mailing list.

Let do second try.

If it is ok for you to use current patch in your github repo, let me know I will roll it out.

/Honza

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Wed Dec 04, 2013 9:47 am

Well, I will fix the directory structure and makefiles stuff before, then we'll see.
Please don't submit the latest patch, as I'm afraid it will be rejected as well...
Regards,
Greg

jp1
Posts: 12
Joined: Wed Nov 13, 2013 5:32 am

Re: QEMU patches for RPi emulation - Initial release

Wed Dec 04, 2013 10:20 am

Torlus wrote:Well, I will fix the directory structure and makefiles stuff before, then we'll see.
Please don't submit the latest patch, as I'm afraid it will be rejected as well...
Regards,
Greg
Don't worry, I'm not going to send anything before your direct ACK ;)

BTW, if you want to submit it yourself, let me know, it's ok for me.
Only please to send me CC: when you do it so I can track it easily
w/o need for tracking of Qemu-dev forum so much B-)

Thx.
/Honza

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Wed Dec 04, 2013 4:45 pm

I updated both the branch and the "candidate" patch.
@sweil, if you happen to be around, your comments are welcome ;)

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Wed Dec 04, 2013 7:45 pm

I suggest these changes:
  • * Move hw/misc/bcm2835_dma.c to hw/dma/bcm2835_dma.c (and fix Makefile.objs).

    * Preserve alphabetic sort order in Makefile.objs, don't add unnecessary empty lines.

    * Use obj-$(CONFIG_RASPI) instead of common-obj-$(CONFIG_RASPI) in Makefile.objs (common-obj means that it must be useful for all architectures, not only ARM).

    * Did you run a compile test? I had to rearrange the include statements in hw/sd/bcm2835_emmc.c.
My personal git repository http://repo.or.cz/w/qemu/ar7.git/ contains all these changes.

For the next patch series on qemu-devel I suggest splitting the changes like this:
  • * The first patch adds only the include files which were copied from external sources (Linux). These files don't have to follow the QEMU coding conventions. I'd take them as they are (no line wrapping) and only replace tabs by spaces, so it is easier to compare original and copy.

    * The second patch adds raspi.c without the code for the bcm* devices.

    * The following patches add one device each with the corresponding code in raspi.c.

    * A final patch might add some documentation to qemu-doc.texi.
Regards
Stefan

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Thu Dec 05, 2013 5:24 am

Here are two links which show how new ARM boards get added to the official QEMU:
These patch series add support for Canon DIGIC SoC and Allwinner A10.

Regards,
Stefan

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Thu Dec 05, 2013 5:40 pm

Thanks again.
Now for an additional question :)
Let's say I prepare a set of patches, by starting from origin, and add changes "by hand" with commits in-between.
How should I proceed if there is a need to change something in the middle of this set of patches, and resubmit the whole set ?
That's probably achievable with some git commands, but if you know the process, that would surely help. ;)
Regards,
Greg

sweil
Posts: 7
Joined: Tue Aug 20, 2013 6:33 am

Re: QEMU patches for RPi emulation - Initial release

Thu Dec 05, 2013 5:57 pm

This can be done with git commands:

Code: Select all

# Modify the latest 4 patches.
git rebase -i HEAD~4

# Create patches from the latest 5 commits.
git format-patch -5

# Send the patches with an introduction.
git send-email --compose --to ... --cc ... 00*
Did you have a look at the two other ARM SoCs which are currently in the process of getting added?
I'm afraid that raspi.c needs some modifications to match the latest QEMU API requirements (QEMU object model = QOM).

Stefan

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Fri Dec 06, 2013 8:46 am

Ok, it seems that there's still some work to do ;)
Well, I'll do my best. Any help is welcome :)

jp1
Posts: 12
Joined: Wed Nov 13, 2013 5:32 am

Re: QEMU patches for RPi emulation - Initial release

Tue Dec 17, 2013 7:15 am

FYI, I'm just working on adding I2C support.

/Honza

UncleVan
Posts: 16
Joined: Fri Dec 28, 2012 7:43 pm

Re: QEMU patches for RPi emulation - Initial release

Tue May 27, 2014 10:41 pm

Dont know whats going on, why is this thread suddenly dead ?
Sadly , but true - the sources from

Code: Select all

https://github.com/Torlus/qemu.git
dont compile anymore :o
Errors look like :

Code: Select all

/media/INSTALL/qemurpi/hw/display/xenfb.c: In function ‘xen_init_display’:
/media/INSTALL/qemurpi/hw/display/xenfb.c:995:5: error: passing argument 2 of ‘graphic_console_init’ makes integer from pointer without a cast [-Werror]
In file included from /media/INSTALL/qemurpi/hw/display/xenfb.c:39:0:
/media/INSTALL/qemurpi/include/ui/console.h:282:14: note: expected ‘uint32_t’ but argument is of type ‘const struct GraphicHwOps *’
-and few more from these.

Even if I manage to fix this - after all it is just a wrong-sugnature function call - and raspbian boots, startx dies with some wrong assertion, probably due to failure in the memory mapping for the DMA:

Code: Select all

 98         assert(!(ch->ti & BCM2708_DMA_TDMODE));
in

Code: Select all

hw/dma/bcm2835_dma.c
Torlus, hopefully healthy and alive , save us from this misery ....

Thanks in advance.

Your UncleVan

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Fri May 30, 2014 1:48 am

Well, "healthy" might not be appropriate for now, but I am still there...
I hope to fix it during the weekend ..
Regards
Greg

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6027
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: QEMU patches for RPi emulation - Initial release

Fri May 30, 2014 7:18 am

Sorry to hear that Torlus, I hope you get better.

I've just compiled the rpi branch without any issues though.

masterrob
Posts: 1
Joined: Mon Sep 22, 2014 12:47 pm

Re: QEMU patches for RPi emulation - Initial release

Mon Sep 22, 2014 1:21 pm

Hi Torlus,

Can you help me to get network connection on RPi ?

I found out that -usb -usbdevice net option starts the USB NIC on Pi

Code: Select all

qemu-system-arm -kernel kernel.img -cpu arm1176 -m 512 -M raspi -serial stdio -append "rw earlyprintk loglevel=8 panic=120 keep_bootcon rootwait dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1024 bcm2708_fb.fbheight=768 bcm2708.boardrev=0xf bcm2708.serial=0xcad0eedf smsc95xx.macaddr=B8:27:EB:D0:EE:DF sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1c000000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait" -sd 2014-09-09-wheezy-raspbian.img -device usb-kbd -device usb-mouse -usb -usbdevice net
While I start with this option I will get those messages on terminal

Image

But I get a NIC shows on startup

Image

Image


My host bridge config

Code: Select all

iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto br0
iface br0 inet static 
	address 192.168.2.24
	netmask 255.255.255.0
	gateway 192.168.2.254
	dns-nameservers 192.168.2.254
#bridge options
	bridge_ports eth0
	bridge_stp no
	bridge_maxwait 0
	bridge_fd 0
Thanks

Regards
Robin

Torlus
Posts: 45
Joined: Mon Nov 19, 2012 8:26 am

Re: QEMU patches for RPi emulation - Initial release

Tue Sep 23, 2014 2:23 pm

Interesting...
I'll have a look at it, and I'll keep you informed.

BTW, the "qemu-rpi" GitHub project is gone, as it didn't make sense to maintain both the patch and the branch.
My "rpi" branch can be found here: https://github.com/Torlus/qemu/tree/rpi

Regards,
Greg

sigjuice
Posts: 4
Joined: Thu Sep 04, 2014 7:09 am
Contact: Website

Re: QEMU patches for RPi emulation - Initial release

Mon Sep 29, 2014 6:48 am

Hi,

I am trying to compile the latest rpi qemu branch, commit 2096dc64 https://github.com/Torlus/qemu/tree/rpi .

Here is what I tried on my OS X 10.9.5 system.

Code: Select all

$ git show
commit 2096dc6455bcac15d1e71babd5f54acac78a2002
Merge: 362c64c e4d50d4
Author: Gregory Estrade <[email protected]>
Date:   Thu Sep 18 19:29:46 2014 +0200

    Merge branch 'master' into rpi

$ git submodule update --init dtc

$ ./configure --prefix=$HOME/qemu-rpi --disable-sdl --disable-kvm --enable-cocoa --cc=gcc-4.9 --host-cc=gcc-4.9 --cxx=g++-4.9 --target-list=arm-softmmu 

$ make

This is how the build fails.

Code: Select all

  CC    block/qapi.o
  CC    block/raw-posix.o
block/raw-posix.c: In function 'raw_create':
block/raw-posix.c:1421:9: warning: implicit declaration of function 'posix_fallocate' [-Wimplicit-function-declaration]
         result = -posix_fallocate(fd, 0, total_size);
         ^
block/raw-posix.c:1421:9: warning: nested extern declaration of 'posix_fallocate' [-Wnested-externs]
block/raw-posix.c: In function 'hdev_open':
block/raw-posix.c:1813:23: warning: variable 'kernResult' set but not used [-Wunused-but-set-variable]
         kern_return_t kernResult;
                       ^
  CC    block/nbd.o
  CC    block/nbd-client.o
  CC    block/sheepdog.o
  CC    block/accounting.o
  CC    block/curl.o
  LINK  qemu-nbd
Undefined symbols for architecture x86_64:
  "_posix_fallocate", referenced from:
      _raw_create in raw-posix.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [qemu-nbd] Error 1
Any suggestions on what I might be doing wrong and how to resolve the build problem?

Thanks!

Return to “Bare metal, Assembly language”