Help with rootfs script

#!/bin/sh
# Copyright (C) 2011 O.S. Systems Software LTDA.
# Licensed on MIT

rootfs_enabled() {
	return 0
}

e2fsck_check() {
	if [ -n "`which e2fsck`" ]; then
		fsckout=`e2fsck -p -v ${1}`
		fsckret=$?
		# Avoid empty newline after summary
		echo "e2fsck: ${fsckout}" >/dev/kmsg
		# Return code >= 4 means uncorrected / operational error
		## TODO: force boot into a recovery mode or similar, as there is really not
		## much we can do in case the fs is corrupted in a bad way
		if [ "${fsckret}" -ge "4" ]; then
			echo "e2fsck: WARNING: file system errors left uncorrected: ret ${fsckret}" >/dev/kmsg
		fi
	fi
}

rootfs_run() {
        if [ -z "$ROOTFS_DIR" ]; then
		return
        fi
	C=0
	delay=${bootparam_rootdelay:-1}
	timeout=${bootparam_roottimeout:-5}
	while ! mountpoint -q $ROOTFS_DIR; do
		if [ $(( $C * $delay )) -gt $timeout ]; then
			fatal "root '$bootparam_root' doesn't exist or does not contain a /dev."
		fi

		if [ -n "$bootparam_root" ]; then
			debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."
                        
                        # Explicitly set the correct PARTUUID here
                        if [ "$bootparam_root" = "PARTUUID=765186fb-02" ]; then
                                bootparam_root="/dev/disk/by-partuuid/765186fb-02"
                        fi
			
			if [ -e "$bootparam_root" ]; then
				e2fsck_check ${bootparam_root}
				flags=""
				if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then
					if [  -n "$bootparam_rootflags" ]; then
						bootparam_rootflags="$bootparam_rootflags,"
					fi
					bootparam_rootflags="${bootparam_rootflags}ro"
				fi
				if [ -n "$bootparam_rootflags" ]; then
					flags="$flags -o$bootparam_rootflags"
				fi
				if [ -n "$bootparam_rootfstype" ]; then
					flags="$flags -t$bootparam_rootfstype"
				fi
				mount $flags $bootparam_root $ROOTFS_DIR
				if mountpoint -q $ROOTFS_DIR; then
				        debug "Root filesystem successfully mounted."
					break
				else
					# It is unlikely to change, but keep trying anyway.
					# Perhaps we pick a different device next time.
					debug "Failed to mount $bootparam_root. Retrying..."
					umount $ROOTFS_DIR
			        fi
			fi
		fi
		debug "Sleeping for $delay second(s) to wait root to settle..."
		sleep $delay
		C=$(( $C + 1 ))
	done
}

this is the rootfs script that i am using when i boot the board this error keeps showing

/init: [    4.686699] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000200
/init.d/90-rootfs: line 68: syntax error: unexpected "done" (expe[    4.694894] CPU: 2 PID: 1 Comm: init Not tainted 5.15.148-6.7.0-devel+git.bfdbfb2c85fb #1
cting "fi")

i tried over an over to find the missing "fi " but i couldn’t
in case this is the rest of the boot logs:

/init: [    4.686699] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000200
/init.d/90-rootfs: line 68: syntax error: unexpected "done" (expe[    4.694894] CPU: 2 PID: 1 Comm: init Not tainted 5.15.148-6.7.0-devel+git.bfdbfb2c85fb #1
cting "fi")
[    4.708700] Hardware name: Toradex Apalis iMX8QM V1.1 on Apalis Evaluation Board (DT)
[    4.717657] Call trace:
[    4.720098]  dump_backtrace+0x0/0x1f0
[    4.723784]  show_stack+0x18/0x40
[    4.727102]  dump_stack_lvl+0x68/0x84
[    4.730777]  dump_stack+0x18/0x34
[    4.734095]  panic+0x18c/0x34c
[    4.737152]  do_exit+0x964/0x9b0
[    4.740384]  do_group_exit+0x38/0xa0
[    4.743964]  __arm64_sys_exit_group+0x18/0x20
[    4.748334]  invoke_syscall+0x48/0x114
[    4.752095]  el0_svc_common.constprop.0+0x44/0xfc
[    4.756816]  do_el0_svc+0x28/0xa0
[    4.760140]  el0_svc+0x28/0x80
[    4.763198]  el0t_64_sync_handler+0xa4/0x130
[    4.767473]  el0t_64_sync+0x1a0/0x1a4
[    4.771152] SMP: stopping secondary CPUs
[    4.775085] Kernel Offset: disabled
[    4.778577] CPU features: 0x4,000820b1,20000846
[    4.783110] Memory Limit: none
[    4.786178] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000200 ]---

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello there!

It looks like you’re encountering a syntax error in your shell script, specifically an unexpected “done” where a “fi” was expected. This usually indicates a mismatch in the use of conditional statements and loops.

Upon reviewing your script, the issue seems to be in the rootfs_run function. The script uses a while loop to attempt mounting the root filesystem, but there is a missing fi to close the if statement that checks if $ROOTFS_DIR is set. Here is a corrected version of the relevant part of your script:

rootfs_run() {
    if [ -z "$ROOTFS_DIR" ]; then
        return
    fi  # Add this line to close the if statement
    C=0
    delay=${bootparam_rootdelay:-1}
    timeout=${bootparam_roottimeout:-5}
    while ! mountpoint -q $ROOTFS_DIR; do
        if [ $(( $C * $delay )) -gt $timeout ]; then
            fatal "root '$bootparam_root' doesn't exist or does not contain a /dev."
        fi

        if [ -n "$bootparam_root" ]; then
            debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."

            # Explicitly set the correct PARTUUID here
            if [ "$bootparam_root" = "PARTUUID=765186fb-02" ]; then
                bootparam_root="/dev/disk/by-partuuid/765186fb-02"
            fi

            if [ -e "$bootparam_root" ]; then
                e2fsck_check ${bootparam_root}
                flags=""
                if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then
                    if [  -n "$bootparam_rootflags" ]; then
                        bootparam_rootflags="$bootparam_rootflags,"
                    fi
                    bootparam_rootflags="${bootparam_rootflags}ro"
                fi
                if [ -n "$bootparam_rootflags" ]; then
                    flags="$flags -o$bootparam_rootflags"
                fi
                if [ -n "$bootparam_rootfstype" ]; then
                    flags="$flags -t$bootparam_rootfstype"
                fi
                mount $flags $bootparam_root $ROOTFS_DIR
                if mountpoint -q $ROOTFS_DIR; then
                    debug "Root filesystem successfully mounted."
                    break
                else
                    debug "Failed to mount $bootparam_root. Retrying..."
                    umount $ROOTFS_DIR
                fi
            fi
        fi
        debug "Sleeping for $delay second(s) to wait root to settle..."
        sleep $delay
        C=$(( $C + 1 ))
    done
}

Adding the missing fi after the initial if statement should resolve the syntax error. Ensure all conditional statements are properly closed with fi and loops with done to prevent such issues.

I hope this helps! If you have any more questions, feel free to ask.

Best regards,
Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

https://community.nxp.com/t5/i-MX-Processors/imx8mp-debix-model-a-dts-syntax-error/td-p/1897414

Problem with apalis imx8 easyinstaller and recovery failed.

showed same error again

/init.d/90-rootfs: line 68: syntax error: unexpected "done" (expe[    4.640057] CPU: 3 PID: 1 Comm: init Not tainted 5.15.148-6.7.0-devel+git.bfdbfb2c85fb #1
cting "fi")
[    4.653860] Hardware name: Toradex Apalis iMX8QM V1.1 on Apalis Evaluation Board (DT)
[    4.662817] Call trace:
[    4.665261]  dump_backtrace+0x0/0x1f0
[    4.668947]  show_stack+0x18/0x40
[    4.672266]  dump_stack_lvl+0x68/0x84
[    4.675939]  dump_stack+0x18/0x34
[    4.679257]  panic+0x18c/0x34c
[    4.682315]  do_exit+0x964/0x9b0
[    4.685547]  do_group_exit+0x38/0xa0
[    4.689126]  __arm64_sys_exit_group+0x18/0x20
[    4.693488]  invoke_syscall+0x48/0x114
[    4.697249]  el0_svc_common.constprop.0+0x44/0xfc
[    4.701959]  do_el0_svc+0x28/0xa0
[    4.705285]  el0_svc+0x28/0x80
[    4.708351]  el0t_64_sync_handler+0xa4/0x130
[    4.712626]  el0t_64_sync+0x1a0/0x1a4
[    4.716297] SMP: stopping secondary CPUs
[    4.720227] Kernel Offset: disabled
[    4.723720] CPU features: 0x4,000820b1,20000846
[    4.728258] Memory Limit: none
[    4.731323] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000200 ]---

Hi @rania !

If I understood correctly, you are using a script different from that used on Torizon OS 7 (scarthgap):

As previously explained, if you need further help with your custom Yocto image, best thing would be to contact one of Toradex Partners:

Best regards,