From 41edb1fd9057e4b2cbc9fb10c837143256ccc2fd Mon Sep 17 00:00:00 2001
From: Qiyang Sun <qs2g22@soton.ac.uk>
Date: Fri, 9 Aug 2024 01:34:39 +0100
Subject: [PATCH] Fastinit runlevel 2: add kernel modules for camera

---
 recipes-bsp/bootfiles/rpi-cmdline.bbappend |  2 +-
 recipes-core/fastinit/files/fastinit.sh    | 35 +++++++++++++++++++++-
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/recipes-bsp/bootfiles/rpi-cmdline.bbappend b/recipes-bsp/bootfiles/rpi-cmdline.bbappend
index edd3908..eb4f84f 100644
--- a/recipes-bsp/bootfiles/rpi-cmdline.bbappend
+++ b/recipes-bsp/bootfiles/rpi-cmdline.bbappend
@@ -5,4 +5,4 @@ CMDLINE:append = " modules.load=dwc2,g_serial"
 CMDLINE:append = " earlycon=uart8250,mmio32,0x20215040"
 #CMDLINE:append = " earlycon=pl011,mmio32,0x20201000"
 
-CMDLINE:append = " init=/usr/sbin/fastinit.sh 1"
+CMDLINE:append = " init=/usr/sbin/fastinit.sh 2"
diff --git a/recipes-core/fastinit/files/fastinit.sh b/recipes-core/fastinit/files/fastinit.sh
index abda454..09b1965 100755
--- a/recipes-core/fastinit/files/fastinit.sh
+++ b/recipes-core/fastinit/files/fastinit.sh
@@ -19,20 +19,48 @@ level_zero() {
 	exec /sbin/poweroff -f
 }
 
-level_one() {
+mountfs() {
 	log_to_kernel "mounting filesystems"
 	mount -t proc proc /proc
 	mount -t sysfs sysfs /sys
 	mount -o ro /dev/mmcblk0p1 /boot
+}
 
+gp23hi() {
 	log_to_kernel "setting gpio 23 to high"
 	/usr/bin/gpioset -c 0 23=1 &
+}
 
+level_one() {
+	mountfs
+	gp23hi
+	crit_to_kernel "host is up and ready"
+	log_to_kernel "getting teletypes on ttyS0"
+	/sbin/getty -L 115200 ttyS0 vt100
+}
+
+level_two() {
+	mountfs
+	gp23hi
+
+	log_to_kernel "adding modules to linux kernel"
+	log_to_kernel "to be added: bcm2835-codec, bcm2835-isp, bcm2835-v4l2, bcm2835-unicam, ov5647, i2c-mux-pinctrl, i2c-bcm2835, uio, fixed"
+	modprobe bcm2835-codec # minors 0-4
+	modprobe bcm2835-isp # minors 5-12
+	modprobe bcm2835-v4l2
+	modprobe bcm2835-unicam # cause red led flash
+	modprobe ov5647
+	modprobe i2c-mux-pinctrl
+	modprobe i2c-bcm2835
+	modprobe uio
+	modprobe fixed
+	
 	crit_to_kernel "host is up and ready"
 	
 	log_to_kernel "getting teletypes on ttyS0"
 	/sbin/getty -L 115200 ttyS0 vt100
 }
+
 level_five() {
 	exec /sbin/init 5
 }
@@ -58,6 +86,11 @@ else
 			log_to_kernel "runlevel 1: tty, serial, gpio"
 			level_one
 			;;
+		2)
+			log_to_kernel "entering runlevel 2 (camera)"
+			log_to_kernel "runlevel 2: tty, serial, gpio, camera"
+			level_two
+			;;
 		5)
 			log_to_kernel "entering runlevel 5 (sysvinit)"
 			level_five
-- 
GitLab