Home | History | Annotate | Line # | Download | only in conf
riscv.conf revision 1.2
      1 # $NetBSD: riscv.conf,v 1.2 2023/09/27 00:24:13 riastradh Exp $
      2 # riscv shared config
      3 #
      4 image=$HOME/${board}.img
      5 
      6 extra=48		# spare space
      7 init=32
      8 boot=$((192 - ${init}))
      9 ffsoffset=$(( (${init} + ${boot}) / 2 ))m
     10 
     11 size=0		# autocompute
     12 msdosid=12
     13 
     14 if $gpt; then
     15 	partition_type="gpt"
     16 else
     17 	partition_type="disklabel"
     18 fi
     19 
     20 mkdir -p ${mnt}/boot
     21 
     22 make_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
     40 type: SCSI
     41 disk: STORAGE DEVICE
     42 label: fictitious
     43 flags: removable
     44 bytes/sector: ${bps}
     45 sectors/track: ${spt}
     46 tracks/cylinder: ${tpc}
     47 sectors/cylinder: ${spc}
     48 cylinders: ${cylinders}
     49 total sectors: ${totalsize}
     50 rpm: 3600
     51 interleave: 1
     52 trackskew: 0
     53 cylinderskew: 0
     54 headswitch: 0           # microseconds
     55 track-to-track seek: 0  # microseconds
     56 drivedata: 0
     57 
     58 8 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                        #
     63 EOF
     64 }
     65 
     66 make_fstab_riscv_gpt() {
     67 	cat > ${mnt}/etc/fstab << EOF
     68 # NetBSD /etc/fstab
     69 # See /usr/share/examples/fstab/ for more examples.
     70 NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
     71 NAME=${gpt_label_boot:-EFI}		/boot		msdos	rw	1 1
     72 ptyfs		/dev/pts	ptyfs	rw
     73 procfs		/proc		procfs	rw
     74 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
     75 EOF
     76 }
     77 
     78 make_fstab_riscv_normal() {
     79 	cat > ${mnt}/etc/fstab << EOF
     80 # NetBSD /etc/fstab
     81 # See /usr/share/examples/fstab/ for more examples.
     82 ROOT.a		/		ffs	rw,noatime	1 1
     83 ROOT.e		/boot		msdos	rw	1 1
     84 ptyfs		/dev/pts	ptyfs	rw
     85 procfs		/proc		procfs	rw
     86 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
     87 EOF
     88 }
     89 
     90 make_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 
    104 customize_riscv() {
    105 	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
    106 	cat >> ${mnt}/etc/rc.conf << EOF
    107 dev_exists() {
    108 	if /sbin/drvctl -l \$1 >/dev/null 2>&1 ; then
    109 		printf YES
    110 	else
    111 		printf NO
    112 	fi
    113 }
    114 
    115 rc_configured=YES
    116 hostname=${hostname:-${board}}
    117 no_swap=YES
    118 savecore=NO
    119 sshd=YES
    120 dhcpcd=YES
    121 ntpd=YES
    122 ntpd_flags="-g"
    123 creds_msdos=YES
    124 creds_msdos_partition=/boot
    125 certctl_init=YES
    126 EOF
    127 
    128 	if $resize; then
    129 		cat >> ${mnt}/etc/rc.conf << EOF
    130 resize_${partition_type}=YES
    131 resize_root=YES
    132 resize_root_flags="-p"
    133 resize_root_postcmd="/sbin/reboot -n"
    134 EOF
    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