Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

# $NetBSD: riscv.conf,v 1.1 2023/05/07 12:41:46 skrll Exp $
# riscv shared config
#
image=$HOME/${board}.img

extra=48		# spare space
init=32
boot=$((192 - ${init}))
ffsoffset=$(( (${init} + ${boot}) / 2 ))m

size=0		# autocompute
msdosid=12

if $gpt; then
	partition_type="gpt"
else
	partition_type="disklabel"
fi

mkdir -p ${mnt}/boot

make_label_riscv() {
	# compute all sizes in terms of sectors
	local totalsize=$(( ${size} / 512 ))

	local bootsize=$(( ${boot} * 1024 ))

	local bootoffset=$(( ${init} * 1024 ))

	local asize=$(( ${totalsize} - ${bootsize} - ${bootoffset} ))
	local aoffset=$(( ${bootoffset} + ${bootsize} ))

	local bps=512
	local spt=32
	local tpc=64
	local spc=2048
	local cylinders=$(( ${totalsize} / ${spc} ))

	cat << EOF
type: SCSI
disk: STORAGE DEVICE
label: fictitious
flags: removable
bytes/sector: ${bps}
sectors/track: ${spt}
tracks/cylinder: ${tpc}
sectors/cylinder: ${spc}
cylinders: ${cylinders}
total sectors: ${totalsize}
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

8 partitions:
#     size         offset        fstype [fsize bsize cpg/sgs]
 a:   ${asize}     ${aoffset}    4.2BSD  ${fsize} ${bsize} 0  #
 c:   ${totalsize} 0             unused      0     0          #
 e:   ${bootsize}  ${bootoffset} MSDOS                        #
EOF
}

make_fstab_riscv_gpt() {
	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
NAME=${gpt_label_boot:-EFI}		/boot		msdos	rw	1 1
ptyfs		/dev/pts	ptyfs	rw
procfs		/proc		procfs	rw
tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
EOF
}

make_fstab_riscv_normal() {
	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
ROOT.a		/		ffs	rw,noatime	1 1
ROOT.e		/boot		msdos	rw	1 1
ptyfs		/dev/pts	ptyfs	rw
procfs		/proc		procfs	rw
tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
EOF
}

make_fstab_riscv() {
	if $gpt; then
		make_fstab_riscv_gpt
	else
		make_fstab_riscv_normal
	fi
	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" \
	    >> "$tmp/selected_sets"

	# Missing mount points from fstab
	echo "./proc type=dir uname=root gname=wheel mode=0755" \
	    >> "$tmp/selected_sets"
}

customize_riscv() {
	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
	cat >> ${mnt}/etc/rc.conf << EOF
dev_exists() {
	if /sbin/drvctl -l \$1 >/dev/null 2>&1 ; then
		printf YES
	else
		printf NO
	fi
}

rc_configured=YES
hostname=${hostname:-${board}}
no_swap=YES
savecore=NO
sshd=YES
dhcpcd=YES
ntpd=YES
ntpd_flags="-g"
creds_msdos=YES
creds_msdos_partition=/boot
EOF

	if $resize; then
		cat >> ${mnt}/etc/rc.conf << EOF
resize_${partition_type}=YES
resize_root=YES
resize_root_flags="-p"
resize_root_postcmd="/sbin/reboot -n"
EOF
	fi

	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" \
	    >> "$tmp/selected_sets"

	mkdir ${mnt}/etc/rc.d
	for _f in resize_${partition_type} creds_msdos; do
		cp ${DIR}/files/${_f} ${mnt}/etc/rc.d/${_f}
		echo "./etc/rc.d/${_f} type=file uname=root gname=wheel mode=0555" \
		    >> "$tmp/selected_sets"
	done

	if [ ! -f ${release}/dev/MAKEDEV ]; then
		echo ${PROG}: Missing ${release}/dev/MAKEDEV 1>&2
		exit 1
	fi
	echo "${bar} running MAKEDEV ${bar}"
	${HOST_SH} ${release}/dev/MAKEDEV -s all | sed -e 's:^\./:\./dev/:' \
	    >> "$tmp/selected_sets"

	echo "${bar} fixing up permissions"
	echo "./boot type=dir uname=root gname=wheel mode=0755" \
	    >> "$tmp/selected_sets"
}