1# $NetBSD: riscv.conf,v 1.3 2024/12/27 19:02:19 christos 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() {
67          make_fstab_default EFI
68}
69
70customize_riscv() {
71          cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
72          cat >> ${mnt}/etc/rc.conf << EOF
73dev_exists() {
74          if /sbin/drvctl -l \$1 >/dev/null 2>&1 ; then
75                    printf YES
76          else
77                    printf NO
78          fi
79}
80
81rc_configured=YES
82hostname=${hostname:-${board}}
83no_swap=YES
84savecore=NO
85sshd=YES
86dhcpcd=YES
87ntpd=YES
88ntpd_flags="-g"
89creds_msdos=YES
90creds_msdos_partition=/boot
91certctl_init=YES
92EOF
93
94          if $resize; then
95                    cat >> ${mnt}/etc/rc.conf << EOF
96resize_${partition_type}=YES
97resize_root=YES
98resize_root_flags="-p"
99resize_root_postcmd="/sbin/reboot -n"
100EOF
101          fi
102
103          echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" \
104              >> "$tmp/selected_sets"
105
106          mkdir ${mnt}/etc/rc.d
107          for _f in resize_${partition_type} creds_msdos; do
108                    cp ${DIR}/files/${_f} ${mnt}/etc/rc.d/${_f}
109                    echo "./etc/rc.d/${_f} type=file uname=root gname=wheel mode=0555" \
110                        >> "$tmp/selected_sets"
111          done
112
113          if [ ! -f ${release}/dev/MAKEDEV ]; then
114                    echo ${PROG}: Missing ${release}/dev/MAKEDEV 1>&2
115                    exit 1
116          fi
117          echo "${bar} running MAKEDEV ${bar}"
118          ${HOST_SH} ${release}/dev/MAKEDEV -s all | sed -e 's:^\./:\./dev/:' \
119              >> "$tmp/selected_sets"
120
121          echo "${bar} fixing up permissions"
122          echo "./boot type=dir uname=root gname=wheel mode=0755" \
123              >> "$tmp/selected_sets"
124}
125