xref: /netbsd-src/distrib/utils/embedded/conf/riscv.conf (revision 345cf9fb81bd0411c53e25d62cd93bdcaa865312)
1# $NetBSD: riscv.conf,v 1.2 2023/09/27 00:24:13 riastradh Exp $
2# riscv shared config
3#
4image=$HOME/${board}.img
5
6extra=48		# spare space
7init=32
8boot=$((192 - ${init}))
9ffsoffset=$(( (${init} + ${boot}) / 2 ))m
10
11size=0		# autocompute
12msdosid=12
13
14if $gpt; then
15	partition_type="gpt"
16else
17	partition_type="disklabel"
18fi
19
20mkdir -p ${mnt}/boot
21
22make_label_riscv() {
23	# compute all sizes in terms of sectors
24	local totalsize=$(( ${size} / 512 ))
25
26	local bootsize=$(( ${boot} * 1024 ))
27
28	local bootoffset=$(( ${init} * 1024 ))
29
30	local asize=$(( ${totalsize} - ${bootsize} - ${bootoffset} ))
31	local aoffset=$(( ${bootoffset} + ${bootsize} ))
32
33	local bps=512
34	local spt=32
35	local tpc=64
36	local spc=2048
37	local cylinders=$(( ${totalsize} / ${spc} ))
38
39	cat << EOF
40type: SCSI
41disk: STORAGE DEVICE
42label: fictitious
43flags: removable
44bytes/sector: ${bps}
45sectors/track: ${spt}
46tracks/cylinder: ${tpc}
47sectors/cylinder: ${spc}
48cylinders: ${cylinders}
49total sectors: ${totalsize}
50rpm: 3600
51interleave: 1
52trackskew: 0
53cylinderskew: 0
54headswitch: 0           # microseconds
55track-to-track seek: 0  # microseconds
56drivedata: 0
57
588 partitions:
59#     size         offset        fstype [fsize bsize cpg/sgs]
60 a:   ${asize}     ${aoffset}    4.2BSD  ${fsize} ${bsize} 0  #
61 c:   ${totalsize} 0             unused      0     0          #
62 e:   ${bootsize}  ${bootoffset} MSDOS                        #
63EOF
64}
65
66make_fstab_riscv_gpt() {
67	cat > ${mnt}/etc/fstab << EOF
68# NetBSD /etc/fstab
69# See /usr/share/examples/fstab/ for more examples.
70NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
71NAME=${gpt_label_boot:-EFI}		/boot		msdos	rw	1 1
72ptyfs		/dev/pts	ptyfs	rw
73procfs		/proc		procfs	rw
74tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
75EOF
76}
77
78make_fstab_riscv_normal() {
79	cat > ${mnt}/etc/fstab << EOF
80# NetBSD /etc/fstab
81# See /usr/share/examples/fstab/ for more examples.
82ROOT.a		/		ffs	rw,noatime	1 1
83ROOT.e		/boot		msdos	rw	1 1
84ptyfs		/dev/pts	ptyfs	rw
85procfs		/proc		procfs	rw
86tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
87EOF
88}
89
90make_fstab_riscv() {
91	if $gpt; then
92		make_fstab_riscv_gpt
93	else
94		make_fstab_riscv_normal
95	fi
96	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" \
97	    >> "$tmp/selected_sets"
98
99	# Missing mount points from fstab
100	echo "./proc type=dir uname=root gname=wheel mode=0755" \
101	    >> "$tmp/selected_sets"
102}
103
104customize_riscv() {
105	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
106	cat >> ${mnt}/etc/rc.conf << EOF
107dev_exists() {
108	if /sbin/drvctl -l \$1 >/dev/null 2>&1 ; then
109		printf YES
110	else
111		printf NO
112	fi
113}
114
115rc_configured=YES
116hostname=${hostname:-${board}}
117no_swap=YES
118savecore=NO
119sshd=YES
120dhcpcd=YES
121ntpd=YES
122ntpd_flags="-g"
123creds_msdos=YES
124creds_msdos_partition=/boot
125certctl_init=YES
126EOF
127
128	if $resize; then
129		cat >> ${mnt}/etc/rc.conf << EOF
130resize_${partition_type}=YES
131resize_root=YES
132resize_root_flags="-p"
133resize_root_postcmd="/sbin/reboot -n"
134EOF
135	fi
136
137	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" \
138	    >> "$tmp/selected_sets"
139
140	mkdir ${mnt}/etc/rc.d
141	for _f in resize_${partition_type} creds_msdos; do
142		cp ${DIR}/files/${_f} ${mnt}/etc/rc.d/${_f}
143		echo "./etc/rc.d/${_f} type=file uname=root gname=wheel mode=0555" \
144		    >> "$tmp/selected_sets"
145	done
146
147	if [ ! -f ${release}/dev/MAKEDEV ]; then
148		echo ${PROG}: Missing ${release}/dev/MAKEDEV 1>&2
149		exit 1
150	fi
151	echo "${bar} running MAKEDEV ${bar}"
152	${HOST_SH} ${release}/dev/MAKEDEV -s all | sed -e 's:^\./:\./dev/:' \
153	    >> "$tmp/selected_sets"
154
155	echo "${bar} fixing up permissions"
156	echo "./boot type=dir uname=root gname=wheel mode=0755" \
157	    >> "$tmp/selected_sets"
158}
159