Skip to content

Instantly share code, notes, and snippets.

@ignisf
Last active October 3, 2023 22:49
Show Gist options
  • Select an option

  • Save ignisf/9273360 to your computer and use it in GitHub Desktop.

Select an option

Save ignisf/9273360 to your computer and use it in GitHub Desktop.
FreeBSD kernel, rootfs generation script (useful for running freebsd on qumu with MALTA emulation)
#!/bin/sh
set -e
export TARGET=mips
export TARGET_ARCH=mips
export KERNCONF=MALTA
export DESTDIR=/nfsroot/$TARGET.$TARGET_ARCH
export KERNDIR=/tftpboot/$TARGET.$TARGET_ARCH
export IMAGEDIR=/images
export WERROR=
export NO_CLEAN=yes
make -C /usr/src buildworld buildkernel
mkdir -p $DESTDIR
mkdir -p $KERNDIR
mkdir -p $IMAGEDIR
make -C /usr/src installworld installkernel distribution
echo "/dev/ada0 / ffs rw 0 1" > $DESTDIR/etc/fstab
echo 'hostname="malta.local"' > $DESTDIR/etc/rc.conf
rm -f $KERNDIR/$KERNCONF
ln -s $DESTDIR/boot/kernel $KERNDIR/$KERNCONF
rm -f $IMAGEDIR/FreeBSD-$KERNCONF.$TARGET.$TARGET_ARCH.kernel
ln -s $KERNDIR/$KERNCONF/kernel $IMAGEDIR/FreeBSD-$KERNCONF.$TARGET.$TARGET_ARCH.kernel
portsnap -d $DESTDIR/var/db/portsnap -p $DESTDIR/usr/ports fetch
if [ ! -d $DESTDIR/usr/ports ]; then
portsnap -d $DESTDIR/var/db/portsnap -p $DESTDIR/usr/ports extract
else
portsnap -d $DESTDIR/var/db/portsnap -p $DESTDIR/usr/ports update
fi
rm -f $IMAGEDIR/FreeBSD-$TARGET.$TARGET_ARCH.rootfs
makefs -t ffs -B be -b 50% -f 50% $IMAGEDIR/FreeBSD-$TARGET.$TARGET_ARCH.rootfs $DESTDIR
@ignisf
Copy link
Author

ignisf commented Feb 28, 2014

qemu-system-mips -M malta -kernel FreeBSD-MALTA.mips.mips.kernel -hda FreeBSD-mips.mips.rootfs -nographic

@cyberkulebyaka
Copy link

Hi, can u help?

I try repeat, but when i start qemu-system-mips got error:

entry: platform_start()
cmd line: FreeBSD-MALTA.mips.mips.kernel console=ttyS0 nokaslr 
envp:
        memsize = 268435456
        ememsize = 268435456
        modetty0 = 38400n8r
memsize = 268435456 (0x10000000)
ememsize = 268435456
Cache info:
  picache_stride    = 4096
  picache_loopcount = 0
  pdcache_stride    = 1024
  pdcache_loopcount = 2
  max line size     = 16
Physical memory chunk(s):
0x7f2000 - 0xfffffff, 260104192 bytes (63502 pages)
Maxmem is 0x10000000
---<<BOOT>>---
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2021 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 13.1-RELEASE n250148-fc952ac2212b MALTA mips
FreeBSD clang version 13.0.0 ([email protected]:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Preloaded elf kernel "kernel" at 0x807eb810.
CPU: MIPS Technologies processor v0.147
  MMU: Standard TLB, 16 entries (4K 16K 64K 256K 1M 16M 64M 256M pg sizes)
  L1 i-cache: 2 ways of 64 sets, 16 bytes per line
  L1 d-cache: 2 ways of 64 sets, 16 bytes per line
  L2 cache: disabled
  Config1=0x9e190c8f<WatchRegs,MIPS16,EJTAG,FPU>
  FPU ID=0x739300<S,D,PS,L,F64,2008>
  Config2=0x80000000
real memory  = 268435456 (262144K bytes)
Physical memory chunk(s):
0x00886000 - 0x0fbb6fff, 255004672 bytes (62257 pages)
avail memory = 253865984 (242MB)
random: no preloaded entropy cache
random: no platform bootloader entropy
arc4random: WARNING: initial seeding bypassed the cryptographic random device because it was not yet seeded and the knob 'bypass_before_seeding' was enabled.
hostuuid: using 00000000-0000-0000-0000-000000000000
random: entropy device external interface
null: <full device, null device, zero device>
mem: <memory>
nexus0: <MIPS32 root nexus>
gt0: <GT64120 chip> on nexus0
pcib0: <GT64120 PCI bridge> on gt0
pci0: <PCI bus> on pcib0
pci0: domain=0, physical bus=0
found-> vendor=0x11ab, dev=0x4620, revid=0x10
        domain=0, bus=0, slot=0, func=0
        class=06-00-00, hdrtype=0x00, mfdev=0
        cmdreg=0x0000, statreg=0x0280, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
        intpin=a, irq=0
        map[14]: type Prefetchable Memory, range 32, base 0x1000000, size 24, memory disabled
        map[18]: type Memory, range 32, base 0x1c000000, size 26, memory disabled
        map[1c]: type Memory, range 32, base 0x1f000000, size 24, memory disabled
        map[20]: type Memory, range 32, base 0x14000000, size 26, memory disabled
        map[24]: type I/O Port, range 32, base 0x14000000, size 26, port disabled
pcib0: no IRQ mapping for 0/0/0/1
found-> vendor=0x8086, dev=0x7110, revid=0x00
        domain=0, bus=0, slot=10, func=0
        class=06-01-00, hdrtype=0x00, mfdev=1
        cmdreg=0x0000, statreg=0x0200, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
found-> vendor=0x8086, dev=0x7111, revid=0x00
        domain=0, bus=0, slot=10, func=1
        class=01-01-80, hdrtype=0x00, mfdev=0
        cmdreg=0x0000, statreg=0x0280, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
        map[20]: type I/O Port, range 32, base 0, size  4, port disabled
found-> vendor=0x8086, dev=0x7112, revid=0x01
        domain=0, bus=0, slot=10, func=2
        class=0c-03-00, hdrtype=0x00, mfdev=0
        cmdreg=0x0000, statreg=0x0000, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
        intpin=d, irq=0
        map[20]: type I/O Port, range 32, base 0, size  5, port disabled
pcib0: no IRQ mapping for 0/10/2/4
found-> vendor=0x8086, dev=0x7113, revid=0x03
        domain=0, bus=0, slot=10, func=3
        class=06-80-00, hdrtype=0x00, mfdev=0
        cmdreg=0x0000, statreg=0x0280, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
        intpin=a, irq=0
pcib0: no IRQ mapping for 0/10/3/1
found-> vendor=0x1234, dev=0x1111, revid=0x02
        domain=0, bus=0, slot=18, func=0
        class=03-00-00, hdrtype=0x00, mfdev=0
        cmdreg=0x0000, statreg=0x0000, cachelnsz=0 (dwords)
        lattimer=0x00 (0 ns), mingnt=0x00 (0 ns), maxlat=0x00 (0 ns)
        map[10]: type Prefetchable Memory, range 32, base 0, size 24, memory disabled
        map[18]: type Memory, range 32, base 0, size 12, memory disabled
obio0 irq 0 at device 0.0 on pci0
uart0: <16550 or compatible> on obio0
uart0: console (9600,n,8,1)
uart0: fast interrupt
uart0: PPS capture mode: DCD
pci0: <bridge, PCI-ISA> at device 10.0 (no driver attached)
atapci0: <Intel PIIX4 UDMA33 controller> port 0x1f0-0x1f7,0x3f6,0x170-0x177,0x376 at device 10.1 on pci0
atapci0: Lazy allocation of 0x10 bytes rid 0x20 type 4 at 0x100
ata0: <ATA channel> at channel 0 on atapci0
ata1: <ATA channel> at channel 1 on atapci0
pci0: <serial bus, USB> at device 10.2 (no driver attached)
pci0: <bridge> at device 10.3 (no driver attached)
vgapci0: <VGA-compatible display> at device 18.0 on pci0
clock0: <Generic MIPS32 ticker> on nexus0
Timecounter "MIPS32" frequency 100000000 Hz quality 800
Event timer "MIPS32" frequency 100000000 Hz quality 800
Device configuration finished.
Timecounters tick every 10.000 msec
lo0: bpf attached
tcp_init: net.inet.tcp.tcbhashsize auto tuned to 4096
ata0: reset tp1 mask=03 ostat0=50 ostat1=00
ata0: stat0=0x50 err=0x01 lsb=0x00 msb=0x00
ata0: stat1=0x00 err=0x00 lsb=0xff msb=0xff
ata0: reset tp2 stat0=50 stat1=00 devices=0x1
ata1: reset tp1 mask=03 ostat0=00 ostat1=00
ata1: stat0=0x00 err=0x00 lsb=0x00 msb=0x00
ata1: stat1=0x00 err=0x00 lsb=0x00 msb=0x00
ata1: reset tp2 stat0=00 stat1=00 devices=0x0
Trying to mount root from ufs:ada0 []...
ada0 at ata0 bus 0 scbus0 target 0 lun 0
ada0: <QEMU HARDDISK 2.5+> ATA-7 device
ada0: Serial Number QM00001
ada0: 33.300MB/s transfers (UDMA2, PIO 8192bytes)
ada0: 5108MB (10462592 512 byte sectors)
pass0 at ata0 bus 0 scbus0 target 0 lun 0
pass0: <QEMU HARDDISK 2.5+> ATA-7 device
pass0: Serial Number QM00001
pass0: 33.300MB/s transfers (UDMA2, PIO 8192bytes)
GEOM: new disk ada0
Warning: no time-of-day clock registered, system time will not be set accurately
start_init: trying /sbin/init
init died (signal 6, exit 0)
panic: Going nowhere without my init!
time = 1696343663
KDB: enter: panic
[ thread pid 1 tid 100001 ]
Stopped at      0x4
db>

I just try run with -append "nokaslr" and without it... For build i use FreeBSD release/13.1 source code

@ignisf
Copy link
Author

ignisf commented Oct 3, 2023

I am sorry @cyberkulebyaka but this is from a different lifetime for me, I literally have no idea what was going on whenever I created this gist. I'd suggest asking in the FreeBSD mailing lists regarding this one, sorry :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment