Hmm, I've applied the patches and built the kernel. I can see the image loaded at 0x80010000, but it is spinning at address 0xffff000c; is this a sdmmc load loop? 

I'm using version 8.0.0 of QEMU. What version are you using, Mr. Miller? Also, since the SD takes seconds to load and not ms/us, how long are you waiting until you see something printed on the console...? Curious if I'm just running very slow, or if there is still something buggy going on... 

Thanks for responding and adding some patches. I am trying to follow along to make it work, if you don't mind a bit of back and forth :-) 

D


On Thu, Aug 31, 2023 at 2:48 PM Richard Miller <9fans@hamnavoe.com> wrote:
don.bailey@gmail.com:
> So to get this back on the track of RPI emulated in QEMU … has anyone successfully used the Miller image with Q?

After a bit of experimentation, I have done so, for some value of "successfully".

A few tweaks are required first, because QEMU's emulation of Pi hardware and
firmware is not as faithful as it might be:

- binary kernel file is loaded at 0x10000, not 0x8000
- the watchdog timer doesn't work (or isn't there)
- system timer behaviour is a bit peculiar
- emulation of the SDMMC in multi-block mode is spectacularly slow
  (transfers take not milliseconds but seconds)

After tweaking as shown below, a QEMU-compatible kernel can be built with
  mk CONF'='pi2 9pi2.qemu
and run with something like
  qemu-system-arm -M raspi2b -kernel 9pi2.qemu -serial stdio \
    -drive file=9pi.img,if=sd,format=raw \
    -append 'readparts=1 console=1 *ncpu=1 nobootprompt=local!/dev/sdM0/fossil'

For convenience I've put a kernel file on /n/sources/contrib/miller/9pi2.qemu

However ...

- the DWC usb host adapter of the Pi2/3 does not work the way Plan 9 expects
- therefore there's no functioning usb
- therefore I don't know how to attach a keyboard, mouse or network interface

If anybody wants to debug this further I'm happy to collaborate, but I'm
not sufficiently motivated to do it myself.

Diffs against files in /n/sources/contrib/miller/9/bcm, which I think are
identical to 9legacy 9/bcm sources):

mkfile:
85a86,90
> $p$CONF.qemu:DQ:      $CONF.$O $OBJ $LIB
>       $CC $CFLAGS '-DKERNDATE='`{date -n} $CONF.c
>       echo '# linking kernel for QEMU'
>       $LD -s -l -o $target -H6 -R4096 -T0x80010000 $OBJ $CONF.$O $LIB
>

mem.h:
48c48
< #define       KTZERO          (KZERO+0x8000)          /* kernel text start */
---
> #define       KTZERO          (KZERO+0x10000)         /* kernel text start */

archbcm2.c:
225c225
<       addclock0link(wdogfeed, HZ);
---
>       //addclock0link(wdogfeed, 1000);

sdmmc.c:
25c25
<       Multiblock      = 1,
---
>       Multiblock      = 0,

clock.c:
35c35
<       MinPeriod       = 10,
---
>       MinPeriod       = 100,
124c124
<       u32int t0, t1, tstart, tend;
---
>       u32int t0, t1, tstart;
142d141
<       tend = tstart + 10000;
145c144
<       }while(tn->clo != tend);
---
>       }while(tn->clo - tstart < 10000);

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T5da5467097e4eab2-M2edf6c6413ee49aaee761281
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription