Plan 9 from Bell Labs’s /usr/web/sources/contrib/miller/build-9pi.rc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


ISO=/tmp/plan9.iso
SDIMG=/tmp/9pi.img
#SDBLOCKS=7743330   # for a 4GB SD card
SDBLOCKS=3855600  # for a 2GB SD card

SDCYLS=`{hoc -e $SDBLOCKS/255/63}

test -f /srv/9660 || 9660srv
mount /srv/9660 /n/cd $ISO

# partition the SD card image

dd -if /dev/zero -of $SDIMG -bs 512 -count 1
aux/disksim -f $SDIMG
echo geometry $SDBLOCKS 512 $SDCYLS 255 63 >/dev/sdXX/ctl
disk/mbr /dev/sdXX/data
{echo a p1 0 8; echo t p1 FAT32; echo a p2 8 '$'; echo w} | disk/fdisk -b /dev/sdXX/data
{echo a nvram 2551 2552; echo a fossil 2552 '$'; echo w} | disk/prep -b /dev/sdXX/plan9

# format and populate the dos partition for booting all raspberry pi models

disk/format -b /386/pbs -df /dev/sdXX/dos
rm -f /srv/dos.rpi
dossrv -f/dev/sdXX/dos dos.rpi
mount -c /srv/dos.rpi /n/dos
cd /n/dos

RPI=(LICENCE.broadcom bcm2711-rpi-4-b.dtb bcm2711-rpi-400.dtb bootcode.bin fixup.dat fixup4.dat fixup4cd.dat fixup_cd.dat start.elf start4.elf start4cd.elf start_cd.elf)
for (i in $RPI) {
	echo $i
	hget https://github.com/raspberrypi/firmware/raw/stable/boot/$i >x && mv x $i
}

echo >cmdline-demo.txt 'readparts=1 nobootprompt=local user=glenda'
echo >cmdline-term.txt 'readparts=1 nvram=#S/sdM0/nvram ipconfig='
echo >cmdline-cpu.txt 'readparts=1 nvram=#S/sdM0/nvram bootargs=local!#S/sdM0/fossil'
echo >cmdline-wifiroot.txt 'ether1=type=4330 essid=WHATEVER wificrypt=wpa2 fs=N.N.N.N auth=N.N.N.N'
cp cmdline-demo.txt cmdline.txt

cat >config.txt <<XXX
[pi0]
kernel=9pi

[pi02]
kernel=9pi2
core_freq=250

[pi1]
# in older firmware Pi Zero W used this entry, not [pi0]
kernel=9pi

[pi2]
kernel=9pi2

[pi3]
kernel=9pi2
core_freq=250

[pi4]
kernel=9pi4
core_freq=250
device_tree=
enable_gic=1

[all]
gpu_mem=16

# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
XXX

cat >LICENCE <<XXX
LICENCE.broadcom
	applies to these binary files in the FAT partition:
		bootcode.bin, fixup*.dat, and start*.elf

LICENCE.plan9
	applies to binary files 9pi* in the FAT partition
	and to the contents of the Plan 9 partition(s)
XXX

cp /n/cd/LICENSE LICENCE.plan9
###cp /n/cd/arm/^(9pi 9pi2 9pi4) .

# format the fossil partition

fossil/flfmt -y /dev/sdXX/fossil
fossil/conf -w /dev/sdXX/fossil <<XXX
fsys main config
fsys main open -Va
fsys main
XXX

fossil/fossil -f/dev/sdXX/fossil -c 'srv -p fscons.rpi' -c 'srv -AWP fossil.rpi'
echo uname upas :upas >>/srv/fscons.rpi
echo uname $user :$user >>/srv/fscons.rpi
mount -c /srv/fossil.rpi /n/fossil.rpi
cd /n/fossil.rpi

# copy the Plan 9 tree from cd to fossil, without 386 binaries

for (d in 386) {
	bind /n/cd/mips/bin /n/cd/$d/bin
	bind /n/cd/mips/lib /n/cd/$d/lib
	bind /n/cd/acme/bin/mips /n/cd/acme/bin/$d
	for (f in /n/cd/$d/9*) bind /dev/null $f
}
disk/mkfs -a -s /n/cd /n/cd/dist/replica/plan9.proto | disk/mkext -ud .
echo users -w >>/srv/fscons.rpi
echo fsys main create /active/usr/glenda/bin/arm glenda glenda d775 >>/srv/fscons.rpi
for (d in 386) rm $d/9*
rm -f 9load bootdisk.img pbsraw README

# adjust some config files for convenience of rpi users

ape/patch -p1 <<'XXX'
--- /n/sources/usr/glenda/bin/rc/riostart	Tue Apr 16 17:23:12 2002
+++ /usr/glenda/bin/rc/riostart	Thu Jun 24 20:01:42 2021
@@ -6,6 +6,10 @@
 
 window 0,0,161,117 stats -lmisce
 window 161,0,560,117 faces -i
+window -scroll -r 560 0 $wid 117 '
+	label console
+	echo ''Console output (/dev/kprint):''
+	cat /dev/kprint'
 
 if(~ `{screensize} small)
 	dump=acme.dump.small
--- /n/sources/usr/glenda/lib/profile	Fri Jan  7 20:11:03 2005
+++ /usr/glenda/lib/profile	Mon Apr  9 20:28:42 2018
@@ -6,6 +6,11 @@
 font = /lib/font/bit/pelm/euro.9.font
 upas/fs
 fn cd { builtin cd $* && awd }  # for acme
+
+# make vfp the default for ARM
+fn 5l { /$cputype/bin/5l -f $* }
+fn pcc { /$cputype/bin/pcc -f $* }
+
 switch($service){
 case terminal
 	plumber
--- /n/sources/sys/lib/newuser	Sat Apr 13 00:28:29 2013
+++ /sys/lib/newuser	Mon Apr  9 20:28:38 2018
@@ -21,6 +21,11 @@
 bind -a $x^home/bin/$x^cputype /bin
 bind -c $x^home/tmp /tmp
 font = /lib/font/bit/pelm/euro.9.font
+
+# make vfp the default for ARM
+fn 5l { /$x^cputype/bin/5l -f $x^* }
+fn pcc { /$x^cputype/bin/pcc -f $x^* }
+
 switch($x^service){
 case terminal
 	plumber
XXX

# to avoid 5-minute dhcp delay if not connected to a network,
# use the ipconfig env variable to control network initialisation: for example
#	ipconfig=        (starts ipconfig with no arguments, to use dhcp)
#	ipconfig=-N      (get network parameters by searching ethernet address in /lib/ndb)
#	ipconfig='-g N.N.N.N ether /net/ether0 N.N.N.N'   (set local and gateway addresses)
# if ipconfig env variable is undefined, don't run ipconfig automatically from termrc

ape/patch -p1 <<'XXX'
--- /n/sources/rc/bin/termrc.local	Fri Nov  8 22:56:06 2013
+++ /rc/bin/termrc.local	Mon Jun 23 20:02:37 2014
@@ -11,3 +11,12 @@
 facedom=FACEDOM
 # replace CPU with the name of your cpu server
 cpu=CPU
+# start network if ipconfig variable is set
+if(test ! -e /net/ipifc/0/ctl -a -e /env/ipconfig) {
+	echo -n ipconfig...
+	eval ip/ipconfig $ipconfig
+	echo
+}
+TIMESYNCARGS=''
+if(test -e /net/ipifc/0/ctl)
+	TIMESYNCARGS=(-n pool.ntp.org)
XXX

# apply selected 9legacy patches

# essential for raspberry pi
p=(bcm-20210411 bcm-brian-man libc-arm-atom usb-ether-rpi usb-ether-cdc usb-ether-lan78xx usb-usbd-usb3 usb-usb3)
# corrections to 4e bugs
p=($p ramfs-fixes usb-serial-ftdi-writelen 9-segment-imagereclaim 9-segment-isoverlap 9-proc-rebalance 9-proc-procflushseg 9-proc-pexit 9-taslock-unlock 9-sysproc-close-on-exec 9-pread-offset fossil-wstat-qid man-2-ainc libc-atom-dmp)
# interoperability with modern internet
p=($p aes-ctr ssh2-aes-ctr ssh2-dh-group14 aux-wpa factotum-wpa tls-tlshand12 libsec-pbkdf2 libsec-tlshand12-norc4 libsec-tlshand12-nossl3 libsec-tlshand12-fixes libsec-tlshand-sigalgs libsec-x509-sha2 libsec-x509-sig tls-devtls12)
# support for golang
p=($p 9-tcp-close ca)

for (i in $p) {
	echo $i:
	hget http://9legacy.org/9legacy/patch/$i.diff | ape/patch -p1 --no-backup-if-mismatch
}

# this fossil bug fix needs altering because fossil-libventi isn't applied on 9pi
hget http://9legacy.org/9legacy/patch/fossil-deadlocks.diff |
	sed 's/canqlock\(&/vtCanLock(/;s/qlock\(&/vtLock(/;s/qunlock\(&/vtUnlock(/;s/%r/%R/' |
	ape/patch -p1 --no-backup-if-mismatch

# compatibility with 9legacy patch 9-ainc
ape/patch -p1 <<'XXX'
--- /n/sources/sys/src/9/bcm/archbcm.c	Fri Dec 24 11:41:23 2021
+++ /sys/src/9/bcm/archbcm.c	Fri Dec 24 11:56:29 2021
@@ -138,6 +138,27 @@
  */
 
 long
+_xdec(long *p)
+{
+	int s, v;
+
+	s = splhi();
+	v = --*p;
+	splx(s);
+	return v;
+}
+
+void
+_xinc(long *p)
+{
+	int s;
+
+	s = splhi();
+	++*p;
+	splx(s);
+}
+
+long
 ainc(long *p)
 {
 	int s, v;
XXX

# install wifi firmware

mkdir sys/lib/firmware
repo=https://github.com/RPi-Distro/firmware-nonfree/raw/buster/brcm
for (f in \
	brcmfmac434^(30 36 55)^-sdio.bin \
	brcmfmac434^(30 36 55)^-sdio.txt \
	brcmfmac434^(36 55)^-sdio.clm_blob) {
		hget $repo/$f >sys/lib/firmware/$f
}

echo fsys main sync >>/srv/fscons.rpi

echo Building libraries, command binaries and kernels is left as an exercise for the reader ☺

# Something like this perhaps:

# cd /n/fossil.rpi
# bind -c acme /acme
# bind -c sys /sys
# bind -c arm /arm
# bind -c mail/lib /mail/lib
# bind -c rc/bin /rc/bin
# fn 5l {/$cputype/bin/5l -f $*}
# fn pcc {/$cputype/bin/pcc -f $*}
# cd /sys/src
# objtype=arm mk install
# cd /sys/src/9/bcm
# mk installall
# echo fsys main sync >>/srv/fscons.rpi
# cd /arm
# cp pi picpu pi2 pi2cpu pi4 pi4cpu /n/dos

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].