From 72de9a901d715cb812d3042e2cb9972f4fdf5d24 Mon Sep 17 00:00:00 2001
From: Mark Sauder <mcsauder@gmail.com>
Date: Thu, 12 Jul 2018 14:45:19 -0600
Subject: [PATCH] Move additional logic block to rc.vehicle_setup, add
 rc.vehicle_setup to init.d/CMakeLists.txt, and relocate sd card logic block
 higher up in rcS. (#9896)

---
 ROMFS/px4fmu_common/init.d/CMakeLists.txt   |  1 +
 ROMFS/px4fmu_common/init.d/rc.vehicle_setup |  9 +++++
 ROMFS/px4fmu_common/init.d/rcS              | 41 ++++++---------------
 3 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/ROMFS/px4fmu_common/init.d/CMakeLists.txt b/ROMFS/px4fmu_common/init.d/CMakeLists.txt
index ac5a93112a..0a8ff11660 100644
--- a/ROMFS/px4fmu_common/init.d/CMakeLists.txt
+++ b/ROMFS/px4fmu_common/init.d/CMakeLists.txt
@@ -114,6 +114,7 @@ px4_add_romfs_files(
 	rc.thermal_cal
 	rc.ugv_apps
 	rc.ugv_defaults
+	rc.vehicle_setup
 	rc.vtol_apps
 	rc.vtol_defaults
 	rcS
diff --git a/ROMFS/px4fmu_common/init.d/rc.vehicle_setup b/ROMFS/px4fmu_common/init.d/rc.vehicle_setup
index da22203368..d4d0a9f196 100644
--- a/ROMFS/px4fmu_common/init.d/rc.vehicle_setup
+++ b/ROMFS/px4fmu_common/init.d/rc.vehicle_setup
@@ -165,3 +165,12 @@ then
 	# Start standard UGV apps
 	sh /etc/init.d/rc.ugv_apps
 fi
+
+#
+# Generic setup (autostart ID not found).
+#
+if [ $VEHICLE_TYPE == none ]
+then
+	echo "No autostart ID found"
+	ekf2 start
+fi
diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS
index 38019807dd..f38330cd83 100644
--- a/ROMFS/px4fmu_common/init.d/rcS
+++ b/ROMFS/px4fmu_common/init.d/rcS
@@ -100,6 +100,18 @@ else
 	fi
 fi
 
+if ver hwcmp CRAZYFLIE -o ver hwcmp AEROCORE2
+then
+	# AEROCORE2 and CF2 shouldn't have an sd card.
+else
+	# Run no SD alarm.
+	if [ $LOG_FILE == /dev/null ]
+	then
+		# Play SOS.
+		tone_alarm error
+	fi
+fi
+
 #
 # Look for an init script on the microSD card.
 # Disable autostart if the script found.
@@ -561,15 +573,6 @@ then
 	#
 	navigator start
 
-	#
-	# Generic setup (autostart ID not found).
-	#
-	if [ $VEHICLE_TYPE == none ]
-	then
-		echo "No autostart ID found"
-		ekf2 start
-	fi
-
 	# Start any custom addons.
 	if [ -f $FEXTRAS ]
 	then
@@ -577,26 +580,6 @@ then
 		sh $FEXTRAS
 	fi
 
-	if ver hwcmp CRAZYFLIE
-	then
-		# CF2 shouldn't have an sd card.
-	else
-
-		if ver hwcmp AEROCORE2
-		then
-			# AEROCORE2 shouldn't have an sd card.
-		else
-			# Run no SD alarm.
-			if [ $LOG_FILE == /dev/null ]
-			then
-				# Play SOS.
-				tone_alarm error
-			fi
-
-		fi
-
-	fi
-
 	#
 	# Start a thermal calibration if required.
 	#
-- 
GitLab