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: armv7.conf,v 1.35.2.1 2019/11/27 13:46:45 martin Exp $
# ARMv7 customization script used by mkimage
#
board=armv7
console=fb
resize=true

. ${DIR}/conf/evbarm.conf

kernels_generic="GENERIC"

make_label() {
	make_label_evbarm
}

make_fstab() {
	make_fstab_evbarm
}

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

populate_common() {
	if [ -f "${release}/usr/mdec/bootarm.efi" ]; then
		# Install EFI bootloader
		mkdir -p "${mnt}/boot/EFI/BOOT"
		cp "${release}/usr/mdec/bootarm.efi" "${mnt}/boot/EFI/BOOT/bootarm.efi"

		# Install GENERIC kernel to root of the FFS partition
		${GZIP_CMD} -dc ${kernel}/netbsd-${kernels_generic}.gz > "${mnt}/netbsd"
		echo "./netbsd type=file uname=root gname=wheel mode=0755" \
		    >> "$tmp/selected_sets"

		cp ${DIR}/files/armv7_boot.cmd ${mnt}/boot/boot.cmd
	else
		# Fallback to non-EFI boot command
		cp ${DIR}/files/armv7_boot_nonefi.cmd ${mnt}/boot/boot.cmd
	fi

	# Install boot script
	"${MKUBOOTIMAGE}" -A arm -C none -O netbsd -T script -a 0 -n "NetBSD/armv7 boot" "${mnt}/boot/boot.cmd" "${mnt}/boot/boot.scr"
}

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

	# The GENERIC .img kernel needs to be installed as kernel7.img for RPI2
	if [ -f "${mnt}/boot/netbsd-GENERIC.img" ]; then
		echo "${bar} renaming netbsd-GENERIC.img to kernel7.img ${bar}"
		mv "${mnt}/boot/netbsd-GENERIC.img" "${mnt}/boot/kernel7.img"

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

		cat > ${mnt}/boot/config.txt << EOF
# Boot options, see https://www.raspberrypi.org/documentation/configuration/config-txt/boot.md
kernel_address=0x01000040
# UART settings, see https://www.raspberrypi.org/documentation/configuration/uart.md
enable_uart=1
force_turbo=0
EOF

	        echo "${bar} installing firmware files ${bar}"
		(cd "${mnt}/boot" &&
			for f in ${firmwarefiles}; do
				echo " $f"
				cp "${firmwaredir}/${f}" .
			done
		)

	fi

	#
	# 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_amlogic() {
	odroidc1_kernelimg=netbsd-GENERIC.ub

	# Create a boot.ini for Amlogic U-Boot
	cat >> "${mnt}/boot/boot.ini" << EOF
ODROIDC-UBOOT-CONFIG

setenv bootargs "awge0.mac-address=\${ethaddr}"
setenv bootcmd "fatload mmc 0:1 0x21000000 ${odroidc1_kernelimg}; fatload mmc 0:1 0x20000000 dtb/meson8b-odroidc1.dtb; bootm 0x21000000 - 0x20000000"
run bootcmd
EOF
}

populate() {
	echo "${bar} looking for kernels in ${kernel} ${bar}"
	kernels=""
	# .ub kernels
	for k in $kernels_generic; do
		f="${kernel}/netbsd-${k}.ub.gz"
		test -f "${f}" && kernels="${kernels} ${f}"
	done
	# .img kernels
	for k in $kernels_generic; do
		f="${kernel}/netbsd-${k}.img.gz"
		test -f "${f}" && kernels="${kernels} ${f}"
	done
	# .dtb files
	for k in $kernels_generic $; do
		test -d "${KERNOBJDIR}/${k}" && \
		    dtbs="$(${MAKE} -C ${KERNOBJDIR}/${k} -v DTB)" || \
		    dtbs=
		for dtb in $dtbs; do
			f="${kernel}/${dtb}.gz"
			test -f "${f}" && kernels="${kernels} ${f}"
		done
	done

	# "kernels" includes some .dtb files that should go into a separate
	# directory
	mkdir -p "${mnt}/boot/dtb"

	# install kernels to /boot partition
	for k in ${kernels}; do
		tgt="$(basename ${k} | sed 's/\.gz$//')"
		case "${tgt}" in
		sun*.dtb|am335x-*.dtb|omap3-*.dtb|meson8b-*.dtb|tegra*.dtb|vexpress*.dtb)
			pfx="dtb/";;
		*)
			pfx=;;
		esac
		echo "${bar} installing ${k} to /boot/${tgt} (on ${mnt}, pfx=${pfx}) ${bar}"
		case "${k}" in
		*.gz)
			${GZIP_CMD} -dc "${k}" > "${mnt}/boot/${pfx}${tgt}"
			;;
		*)
			cp "${k}" "${mnt}/boot/${pfx}${tgt}"
			;;
		esac ||
			fail "Copy of ${k} to ${mnt}/boot/${tgt} failed"
	done

	# board specific configuration
	populate_amlogic
	populate_rpi

	# common configuration
	populate_common
}