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: rpi.conf,v 1.40 2022/11/19 09:19:27 yamt Exp $
# Raspberry Pi customization script used by mkimage
#

board=rpi
kerneldir=$src/sys/arch/evbarm/compile/RPI/
kernel=$kerneldir/netbsd-RPI.bin
resize=true

. ${DIR}/conf/evbarm.conf

firmwaredir=$src/external/broadcom/rpi-firmware/dist
firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat start.elf start_cd.elf"

make_fstab() {
	make_fstab_evbarm
}

make_label() {
	make_label_evbarm
}

customize() {
	customize_evbarm
	cat >> ${mnt}/etc/rc.conf << EOF
wscons=YES
devpubd=YES
EOF

	#
	# If arm_freq is specified in config.txt, set CPU frequency
	# to match at boot time.
	#
	cp ${release}/etc/rc.local ${mnt}/etc/rc.local
	cat >> ${mnt}/etc/rc.local << EOF
if /sbin/sysctl -q machdep.cpu.frequency.max; then
	cpufreq_max=\$(/sbin/sysctl -n machdep.cpu.frequency.max)
	cpufreq_cur=\$(/sbin/sysctl -n machdep.cpu.frequency.current)
	if [ ! "\$cpufreq_max" = "\$cpufreq_cur" ]; then
		/sbin/sysctl -w machdep.cpu.frequency.target=\$cpufreq_max
	fi
fi
EOF
	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" \
	    >> "$tmp/selected_sets"
}

populate() {
	rpi2_kernel="$(echo $kernel | sed -e 's/RPI/RPI2/g')"

	cat > ${mnt}/boot/cmdline.txt << EOF
root=ld0a console=fb
#fb=1280x1024		# to select a mode, otherwise try EDID
#fb=disable		# to disable fb completely
EOF

	cat > ${mnt}/boot/config.txt << EOF
#
upstream_kernel=1
os_prefix=dtb/
cmdline=../cmdline.txt
# UART settings, see https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-uarts
enable_uart=1
force_turbo=0
# Default kernel for BCM2836 and later
kernel=/kernel7.img
# Override kernel for BCM2835 based boards
[pi0]
kernel=/kernel.img
[pi0w]
kernel=/kernel.img
[pi1]
kernel=/kernel.img
[all]
#
EOF

	echo "${bar} kernel ${kernel} ${bar}"

	if [ ! -f ${kernel} ]; then
		echo ${PROG}: Missing ${kernel} 1>&2
		exit 1
	fi

	# .img files
	echo "${bar} installing RPI kernel ${bar}"
	case ${kernel} in
	*.gz)
		gzip -dc ${kernel} > ${mnt}/boot/kernel.img
		;;
	*)
		cp ${kernel} ${mnt}/boot/kernel.img
		;;
	esac || fail "copy of ${kernel} to ${mnt}/boot/kernel.img failed"

	echo "${bar} installing RPI2 kernel ${bar}"
	case ${rpi2_kernel} in
	*.gz)
		gzip -dc ${rpi2_kernel} > ${mnt}/boot/kernel7.img
		;;
	*)
		cp ${rpi2_kernel} ${mnt}/boot/kernel7.img
		;;
	esac || fail "Copy of ${rpi2_kernel} to ${mnt}/boot/kernel7.img failed"

	echo "${bar} installing kernel files ${bar}"
	# install kernels to /boot partition
	for k in ${kernels}; do
		tgt="$(basename ${k} | sed 's/\.gz$//')"
		echo "${bar} installing ${k} to /boot/${tgt} ${bar}"
		case "${k}" in
		*.gz)
			${GZIP_CMD} -dc "${k}" > "${mnt}/boot/${tgt}"
			;;
		*)
			cp "${k}" "${mnt}/boot/${tgt}"
			;;
		esac
	done

	echo "${bar} installing firmware files ${bar}"
	(cd ${mnt}/boot &&
		for f in ${firmwarefiles}; do
			echo " $f"
			cp ${firmwaredir}/${f} . || exit 1
		done
	) || fail "Copy of firmware into ${mnt}/boot failed"

}