sergev / qemu

QEMU for PIC32
https://github.com/sergev/qemu/wiki
Other
29 stars 7 forks source link

Wiki, can not run 'LiteBSD on MEB-II board with Ethernet enabled' #15

Closed ypwangreg closed 1 year ago

ypwangreg commented 1 year ago

Hi Sergev,

It is very awesome that you created such a qemu variant for PIC32MZ and it is very fun.

I could compile (on ubuntu 22.04) and run much of the demos but not the last one. it stuck in the following

ubuntu@ubuntu:~/pic32mz$ sh run_meb2.sh 
Board: Microchip MEB-II
Processor: microAptivP
RAM size: 512 kbytes
Load file: 'vmunix.hex', 522408 bytes
Card0 image 'litebsd.img', 339969 kbytes

By comparing with other examples, it seems that it might be missing the '-bios boot-meb2.hex' ? I am not sure, could you please share some lights on this? Thanks!

FYI.. for the people who wants to compile on the latest Ubuntu 22.04, please see following note

ubuntu@ubuntu:~/qemu$ cat compile.mips.qemu.jammy.kvm 
  183  sudo apt-get install libpixman-1-dev libfdt-dev zlib1g-dev libglib2.0-dev libsdl1.2-dev
  186  du -sh qemu/
  187  cd qemu/
  189  sudo apt install gcc
  199  sudo apt install python2.7
  206  sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 20
  208  sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 30
  209  python
  215  sudo apt install make
  221  sudo apt install libglib2.0-dev
  223  pkg-config --cflags --libs gtk+-2.0
  224  sudo apt install libgtk2.0-dev
  233  pkg-config --cflags glib-2.0
  280  ./configure --prefix=/usr/local/qemu-mips --target-list=mipsel-softmmu --extra-cflags='-Wno-deprecated -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include' --disable-werror
  281  make
  286  sudo make install

Cheers, Andy

sergev commented 1 year ago

File boot-meb2.hex is not needed, as there is no bootloader on the MEB-II board. Here is a command to start it:

qemu-system-mipsel -machine pic32mz-meb2 \
    -nographic \
    -monitor none \
    -serial stdio \
    -net nic \
    -net tap,ifname=tap0,script=no,downscript=no \
    -kernel vmunix.hex \
    -sd litebsd.img
ypwangreg commented 1 year ago

Hi Sergev,

Thanks for the reply. I tried and it did not work somehow.

ubuntu@ubuntu:~/pic32mz$ ifconfig tap0
tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 20.2.2.2  netmask 255.0.0.0  broadcast 20.255.255.255
        inet6 fe80::d478:aff:fe5c:c744  prefixlen 64  scopeid 0x20<link>
        ether d6:78:0a:5c:c7:44  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23  bytes 1946 (1.9 KB)
        TX errors 0  dropped 4 overruns 0  carrier 0  collisions 0

ubuntu@ubuntu:~/pic32mz$ cat run_meb2.sh 
#    -net nic -net user \
/usr/local/qemu-mips/bin/qemu-system-mipsel -machine pic32mz-meb2 \
    -nographic \
    -monitor none \
    -serial stdio \
    -net nic \
    -net tap,ifname=tap0,script=no,downscript=no \
    -kernel vmunix.hex \
    -sd litebsd.img
ubuntu@ubuntu:~/pic32mz$ sh run_meb2.sh 
Board: Microchip MEB-II
Processor: microAptivP
RAM size: 512 kbytes
Load file: 'vmunix.hex', 522408 bytes
Card0 image 'litebsd.img', 339969 kbytes

I did a tcpdump and it seems that there was some activities on tap0 so maybe the issue was I can't access the 'console' somehow?

ubuntu@ubuntu:~$ sudo tcpdump -i tap0 -nx
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on tap0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
19:30:19.303010 IP6 fe80::d478:aff:fe5c:c744 > ff02::16: HBH ICMP6, multicast listener report v2, 1 group record(s), length 28
        0x0000:  6000 0000 0024 0001 fe80 0000 0000 0000
        0x0010:  d478 0aff fe5c c744 ff02 0000 0000 0000
        0x0020:  0000 0000 0000 0016 3a00 0502 0000 0100
        0x0030:  8f00 044f 0000 0001 0400 0000 ff02 0000
        0x0040:  0000 0000 0000 0001 ff5c c744
19:30:19.335000 IP6 fe80::d478:aff:fe5c:c744 > ff02::16: HBH ICMP6, multicast listener report v2, 1 group record(s), length 28
        0x0000:  6000 0000 0024 0001 fe80 0000 0000 0000
        0x0010:  d478 0aff fe5c c744 ff02 0000 0000 0000
        0x0020:  0000 0000 0000 0016 3a00 0502 0000 0100
        0x0030:  8f00 044f 0000 0001 0400 0000 ff02 0000
        0x0040:  0000 0000 0000 0001 ff5c c744
ypwangreg commented 1 year ago

LiteBSD on WireFire works like a charm but not MEB2. same vmunix.hex and litebsd..

ubuntu@ubuntu:~/pic32mz$ sh run_wifire.sh 
Board: chipKIT WiFire
Processor: microAptivP
RAM size: 512 kbytes
Load file: 'boot-wifire.hex', 6916 bytes
Load file: 'vmunix.hex', 522408 bytes
Card0 image 'litebsd.img', 339969 kbytes
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

4.4BSD-Lite build 13 compiled 2015-01-20
    sergev@ubuntu-sergev:LiteBSD/sys/compile/WIFIRE.pic32
cpu: PIC32MZ2048ECG100 rev A4, 200 MHz
oscillator: system PLL div 1:6 mult x50
real mem = 512 kbytes
avail mem = 344 kbytes
using 18 buffers containing 73728 bytes of memory
spi1 at pins sdi=D14/sdo=C1/sck=D1
spi2 at pins sdi=F0/sdo=D11/sck=G6
spi3 at pins sdi=B10/sdo=C4/sck=B14
spi4 at pins sdi=F5/sdo=G0/sck=D10
uart1 at pins rx=F1/tx=D15, interrupts 112/113/114
uart4 at pins rx=F2/tx=F8, interrupts 170/171/172, console
sd0 at port spi3, pin cs=C3
sd0: type I, size 339968 kbytes, speed 12 Mbit/sec
sd0a: partition type b7, sector 2, size 204800 kbytes
sd0b: partition type b8, sector 409602, size 32768 kbytes
sd0c: partition type b7, sector 475138, size 102400 kbytes
bpf: sl0 attached
bpf: lo0 attached
WARNING: preposterous clock chip time -- CHECK AND RESET THE DATE!

starting file system checks.
/dev/rsd0a: file system is clean; not checking
starting network
clearing /tmp
standard daemons: update.
Wed Dec 10 21:07:39 PST 2014

4.4BSD-Lite (bsd.net) (tty4)

login: root
Last login: Wed Dec 10 21:07:35 on tty4
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.   All rights reserved.

4.4BSD-Lite UNIX #1: Fri Apr 01 00:00:00 PDT 1994

Welcome to 4.4BSD-Lite!

erase ^H, kill ^U, intr ^C status ^T
Don't login as root, use the su command.
# ps axv
  PID STAT      TIME  SL  RE PAGEIN   VSZ  RSS   LIM TSIZ %CPU %MEM COMMAND
   35 Ss     0:00.09   0  22      0   244   64     -  196  0.0  0.0 -sh (sh)
   37 R+     0:00.01   0   0      0   200   88     -  144  0.0  0.0 (ps)
    1 IWs    0:00.03  22   0      0   172    0     -  116  0.0  0.0 /sbin/init
   28 IWs    0:00.00  22   0      0    20    0     -    8  0.0  0.0 update
    0 DLs    0:00.01   0  23      0     0    0     -    0  0.0  0.0 (swapper)
    2 RL     0:00.09   0  22      0     0    0     -    0  0.4  0.0 (pagedaemon
# halt
qemu: terminating on signal 15 from pid 42456
ubuntu@ubuntu:~/pic32mz$ cat run_wifire.sh 
/usr/local/qemu-mips/bin/qemu-system-mipsel -machine pic32mz-wifire \
    -nographic \
    -monitor none \
    -serial vc \
    -serial vc \
    -serial vc \
    -serial stdio \
    -bios boot-wifire.hex \
    -kernel vmunix.hex \
    -sd litebsd.img
ubuntu@ubuntu:~/pic32mz$ 
sergev commented 1 year ago

The kernel for MEB-II must be different. The one you have was compiled for Wi-Fire:

4.4BSD-Lite build 13 compiled 2015-01-20
    sergev@ubuntu-sergev:LiteBSD/sys/compile/WIFIRE.pic32

Please try this one: vmunix-meb2.zip

ypwangreg commented 1 year ago

Hi Sergev,

Thanks for the new kernel and Now it works like a charm!

ubuntu@ubuntu:~/pic32mz$ sh run_meb2.sh 
Board: Microchip MEB-II
Processor: microAptivP
RAM size: 512 kbytes
Load file: 'vmunix-meb2.hex', 519148 bytes
Card0 image 'litebsd.img', 339969 kbytes
Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.

4.4BSD-Lite build 0 compiled 2016-04-17
    vak@tundra.local:LiteBSD/sys/compile/MEBII.pic32
cpu: PIC32MZ2048ECH144 rev A4, 200 MHz
oscillator: system PLL div 1:6 mult x50
real mem = 512 kbytes
avail mem = 344 kbytes
using 18 buffers containing 73728 bytes of memory
spi1 at pins sdi=RD14/sdo=RB10/sck=RD1
spi2 at pins sdi=RD7/sdo=RG8/sck=RG6
spi4 at pins sdi=RG7/sdo=RB3/sck=RD10
en0 at interrupt 153, MAC address 52:54:00:12:34:56
en0: <SMSC LAN8740A> at address 0
uart1 at pins rx=RA14/tx=RA15, interrupts 112/113/114, console
sd0 at port spi2, pin cs=RB14
gpio0 at portA, pins ii---ii-iiiiiiii
gpio1 at portB, pins ioiiiiiiiiiiiiii
gpio2 at portC, pins iiii-------iiii-
gpio3 at portD, pins iiiiiii-ioiiiiii
gpio4 at portE, pins ------iiiiiiiiii
gpio5 at portF, pins --ii---i--iiiiii
gpio6 at portG, pins iiii--iiii----ii
gpio7 at portH, pins iiiiiiiiiiiiiiio
gpio8 at portJ, pins iiiiiiooiiiiiiii
gpio9 at portK, pins --------iiiiiiii
sd0: type I, size 339968 kbytes, speed 12 Mbit/sec
sd0a: partition type b7, sector 2, size 204800 kbytes
sd0b: partition type b8, sector 409602, size 32768 kbytes
sd0c: partition type b7, sector 475138, size 102400 kbytes
WARNING: preposterous clock chip time -- CHECK AND RESET THE DATE!
Enter pathname of shell or RETURN for sh: 
erase ^H, kill ^U, intr ^C status ^T
Don't login as root, use the su command.
# if ifconfig en0 >/dev/null 2>&1; then
> 
>     ifconfig en0 inet 10.0.2.15
> 
> fi
# en0: link up, 100Mbps, full duplex

# ping 10.0.2.2
PING 10.0.2.2 (10.0.2.2): 56 data bytes
64 bytes from 10.0.2.2: icmp_seq=0 ttl=64 time=2.538 ms
64 bytes from 10.0.2.2: icmp_seq=1 ttl=64 time=0.137 ms
^C
--- 10.0.2.2 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.137/1.337/2.538 ms

# route add default 10.0.2.2
add net default: gateway 10.0.2.2
# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=115 time=25.861 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=23.426 ms

I can also run inetd and telnet to 10.0.2.15 works fine too. The only issue is root fs is read-only otherwise I can add resolv.conf so I can ping google.com.

For the Ubuntu host, I have to run the following command for above network to work

sudo ifconfig tap0 10.0.2.2
sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o enp0s2 -j MASQUERADE

one minor issue is the ps and vmstat does not work so I might need to build new image for the meb2 as well.

# ps avx
ps: proc size mismatch (6640 total, 656 chunks)
# vmstat
vmstat: undefined symbols: _scsi_dinit 

it would be also cool if we could have a basic c compiler and linker to work and it is way ahead.

Thanks again and I will close the ticket!