Home | History | Annotate | Line # | Download | only in conf
evbarm.conf revision 1.40
      1 # $NetBSD: evbarm.conf,v 1.40 2022/10/15 18:32:30 jmcneill Exp $
      2 # evbarm shared config
      3 #
      4 image=$HOME/${board}.img
      5 
      6 MACHINE=evbarm
      7 
      8 extra=48		# spare space
      9 init=32
     10 boot=$((192 - ${init}))
     11 ffsoffset=$(( (${init} + ${boot}) / 2 ))m
     12 
     13 size=0		# autocompute
     14 msdosid=12
     15 
     16 if $gpt; then
     17 	partition_type="gpt"
     18 else
     19 	partition_type="disklabel"
     20 fi
     21 
     22 mkdir -p ${mnt}/boot
     23 
     24 make_label_evbarm() {
     25 	# compute all sizes in terms of sectors
     26 	local totalsize=$(( ${size} / 512 ))
     27 
     28 	local bootsize=$(( ${boot} * 1024 ))
     29 
     30 	local bootoffset=$(( ${init} * 1024 ))
     31 
     32 	local asize=$(( ${totalsize} - ${bootsize} - ${bootoffset} ))
     33 	local aoffset=$(( ${bootoffset} + ${bootsize} ))
     34 
     35 	local bps=512
     36 	local spt=32
     37 	local tpc=64
     38 	local spc=2048
     39 	local cylinders=$(( ${totalsize} / ${spc} ))
     40 
     41 	cat << EOF
     42 type: SCSI
     43 disk: STORAGE DEVICE
     44 label: fictitious
     45 flags: removable
     46 bytes/sector: ${bps}
     47 sectors/track: ${spt}
     48 tracks/cylinder: ${tpc}
     49 sectors/cylinder: ${spc}
     50 cylinders: ${cylinders}
     51 total sectors: ${totalsize}
     52 rpm: 3600
     53 interleave: 1
     54 trackskew: 0
     55 cylinderskew: 0
     56 headswitch: 0           # microseconds
     57 track-to-track seek: 0  # microseconds
     58 drivedata: 0 
     59 
     60 8 partitions:
     61 #     size         offset        fstype [fsize bsize cpg/sgs]
     62  a:   ${asize}     ${aoffset}    4.2BSD  ${fsize} ${bsize} 0  # 
     63  c:   ${totalsize} 0             unused      0     0          #
     64  e:   ${bootsize}  ${bootoffset} MSDOS                        #
     65 EOF
     66 }
     67 
     68 make_fstab_evbarm_gpt() {
     69 	cat > ${mnt}/etc/fstab << EOF
     70 # NetBSD /etc/fstab
     71 # See /usr/share/examples/fstab/ for more examples.
     72 NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
     73 NAME=${gpt_label_boot:-EFI}		/boot		msdos	rw	1 1
     74 ptyfs		/dev/pts	ptyfs	rw
     75 procfs		/proc		procfs	rw
     76 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
     77 EOF
     78 }
     79 
     80 make_fstab_evbarm_normal() {
     81 	cat > ${mnt}/etc/fstab << EOF
     82 # NetBSD /etc/fstab
     83 # See /usr/share/examples/fstab/ for more examples.
     84 ROOT.a		/		ffs	rw,noatime	1 1
     85 ROOT.e		/boot		msdos	rw	1 1
     86 ptyfs		/dev/pts	ptyfs	rw
     87 procfs		/proc		procfs	rw
     88 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
     89 EOF
     90 }
     91 
     92 # From Richard Neswold's:
     93 # http://rich-tbp.blogspot.com/2013/03/netbsd-on-rpi-minimizing-disk-writes.html
     94 # Also for the postfix stuff below
     95 make_fstab_evbarm_minwrites() {
     96 	cat > ${mnt}/etc/fstab << EOF
     97 # NetBSD /etc/fstab
     98 # See /usr/share/examples/fstab/ for more examples.
     99 ROOT.a		/			ffs	rw,log,noatime,nodevmtime 1 1
    100 ROOT.e		/boot			msdos	rw			  1 1
    101 ptyfs		/dev/pts		ptyfs	rw
    102 procfs		/proc			procfs	rw
    103 tmpfs		/tmp			tmpfs	rw,-s32M
    104 tmpfs		/var/log		tmpfs	rw,union,-s32M
    105 tmpfs		/var/run		tmpfs	rw,union,-s1M
    106 tmpfs		/var/mail		tmpfs	rw,union,-s10M
    107 tmpfs		/var/spool/postfix	tmpfs	rw,union,-s20M
    108 tmpfs		/var/db/postfix		tmpfs	rw,union,-s1M
    109 tmpfs		/var/chroot		tmpfs	rw,union,-s10M
    110 tmpfs		/var/shm		tmpfs	rw,-m1777,-sram%25
    111 EOF
    112 }
    113 
    114 make_fstab_evbarm() {
    115 	if $gpt; then
    116 		make_fstab_evbarm_gpt
    117 	elif $minwrites; then
    118 		make_fstab_evbarm_minwrites
    119 	else
    120 		make_fstab_evbarm_normal
    121 	fi
    122 	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" \
    123 	    >> "$tmp/selected_sets"
    124 
    125 	# Missing mount points from fstab
    126 	echo "./proc type=dir uname=root gname=wheel mode=0755" \
    127 	    >> "$tmp/selected_sets"
    128 }
    129 
    130 customize_evbarm() {
    131 	if $minwrites; then
    132 		mkdir ${mnt}/etc/postfix
    133 		(umask 022
    134 		sed -e 's/fifo/unix/' < ${release}/etc/postfix/master.cf > \
    135 		    ${mnt}/etc/postfix/master.cf)
    136 	fi
    137 	
    138 	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
    139 	cat >> ${mnt}/etc/rc.conf << EOF
    140 dev_exists() {
    141 	if /sbin/drvctl -l \$1 >/dev/null 2>&1 ; then
    142 		printf YES
    143 	else
    144 		printf NO
    145 	fi
    146 }
    147 
    148 is_cloud() {
    149 	ret=NO
    150 
    151 	# AWS EC2
    152 	if [ "\$(dev_exists ena0)" = "YES" ]; then
    153 		ret=YES
    154 	fi
    155 
    156 	# Oracle OCI
    157 	case "\$(/sbin/sysctl -n machdep.dmi.chassis-asset-tag)" in
    158 	OracleCloud*)
    159 		ret=YES
    160 		;;
    161 	esac
    162 
    163 	printf \$ret
    164 }
    165 
    166 rc_configured=YES
    167 hostname=${hostname:-${board}}
    168 no_swap=YES
    169 savecore=NO
    170 sshd=YES
    171 dhcpcd=YES
    172 ntpd=YES
    173 ntpd_flags="-g"
    174 creds_msdos=YES
    175 creds_msdos_partition=/boot
    176 EOF
    177 
    178 	if $resize; then
    179 		cat >> ${mnt}/etc/rc.conf << EOF
    180 resize_${partition_type}=YES
    181 resize_root=YES
    182 resize_root_flags="-p"
    183 resize_root_postcmd="/sbin/reboot -n"
    184 EOF
    185 	fi
    186 
    187 	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" \
    188 	    >> "$tmp/selected_sets"
    189 
    190 	mkdir ${mnt}/etc/rc.d
    191 	for _f in resize_${partition_type} creds_msdos; do
    192 		cp ${DIR}/files/${_f} ${mnt}/etc/rc.d/${_f}
    193 		echo "./etc/rc.d/${_f} type=file uname=root gname=wheel mode=0555" \
    194 		    >> "$tmp/selected_sets"
    195 	done
    196 
    197 	if [ ! -f ${release}/dev/MAKEDEV ]; then
    198 		echo ${PROG}: Missing ${release}/dev/MAKEDEV 1>&2
    199 		exit 1
    200 	fi
    201 	echo "${bar} running MAKEDEV ${bar}"
    202 	${HOST_SH} ${release}/dev/MAKEDEV -s all | sed -e 's:^\./:\./dev/:' \
    203 	    >> "$tmp/selected_sets"
    204 
    205 	echo "${bar} fixing up permissions"
    206 	echo "./boot type=dir uname=root gname=wheel mode=0755" \
    207 	    >> "$tmp/selected_sets"
    208 }
    209