Huawei E173-u1 3G dongle w/ ExtRoot on dongle-SDCARD, and QMI

Having gathered that it is a bit problematic to usb_modeswitch when using the modeswitched devices as extroot, I wonder what the best solution might be.
AFAIK, there is no AT^U2DIAG-parameter that allows me to permanently enable both the QMI-device and the SDCARD on this device (although, there is one for PPP-mode and SDCARD, e g 256, c.f. http://www.3g-modem-wiki.com/page/Huawei+AT-commands). This device has no AT^SETPORT support, so the instructions on the extroot-wiki do not apply.
Thus, I need to use usb_modeswitch, without it messing up my file system (which it would if the file system is mounted and it usb-disconnects the dongle as a part of the modeswitch), meaning that I need to most likely have it on the rom, and have it execute before the SDCARD is mounted as overlay by fstab.
Is there a somewhat straight-forward way of doing this?

After some reading and research, I solved this by including usb_modeswitch in the ROM and creating the following preinit script [/lib/preinit/79_usbmode].

#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications

# - /lib/preinit/79_usbmode -
#
# To be included in ROM image, together with at least usb-modeswitch,
#  kmod-usb-storage and a /etc/usb-mode.preinit.json.
#
# Note that wait_for_usbmode() can not detect partitions as support for doing that
#  is not yet loaded at the stage of the boot process this script is run.
#
# Tested on OpenWRT v19.07.3

log_usbmode() {
	echo "preinit-usbmode: $1" > /dev/kmsg
}

wait_for_usbmode() {
	local i=0 T=15 DEVICE="${1}"
	while [ ${i} -lt ${T} ] && [ ! -e "${DEVICE}" ]; do
		[ ${i} -gt 0 ] || log_usbmode "Waiting a maximum of ${T} seconds for dongle-attached block device ${DEVICE} to re-appear."
		sleep 1; i="$(( ${i} + 1 ))"; done
	[ ${i} -eq 0 ] && { log_usbmode "USB-dongle-attached block device ${DEVICE} seems to have reappeared without any need for further waiting."; sleep 3; } || {
		[ -e "${DEVICE}" ] && { log_usbmode "USB-dongle-attached block device ${DEVICE} seems to have reappeared after ${i} seconds."; sleep 3; } || {
					log_usbmode "USB-dongle-attached block device ${DEVICE} seems NOT to have reappeared!"; }
	}
}

do_usbmode() {
	[ -s "/etc/usb-mode.preinit.json" ] || {
		log_usbmode "Not configured. Exiting."; return 0; }

	[ -d "/dev/bus/usb" ] || {
		log_usbmode "Creating /dev/bus/usb/001/00{1,2,3,4}."
		/bin/mkdir -m 755 -p "/dev/bus/usb/001" && \
		/bin/mknod -m 600 "/dev/bus/usb/001/001" c 189 0 && \
		/bin/mknod -m 600 "/dev/bus/usb/001/002" c 189 1 && \
		/bin/mknod -m 600 "/dev/bus/usb/001/003" c 189 2 && \
		/bin/mknod -m 600 "/dev/bus/usb/001/004" c 189 3
	}

	log_usbmode "Checking for USB device to mode switch."
	[ `/sbin/usbmode -c "/etc/usb-mode.preinit.json" -l 2>&1 | /usr/bin/wc -l` -gt 0 ] || sleep 3;
	/sbin/usbmode -c "/etc/usb-mode.preinit.json" -l 1> /dev/kmsg 2> /dev/kmsg
	[ `/sbin/usbmode -c "/etc/usb-mode.preinit.json" -l 2>&1 | /usr/bin/wc -l` -gt 0 ] || {
		log_usbmode "Found no USB device to mode switch. Exiting."; return 0; }

	log_usbmode "Found USB device to mode switch. Switching..."
	/sbin/usbmode -c "/etc/usb-mode.preinit.json" -s 1> /dev/kmsg 2> /dev/kmsg
	sleep 5; wait_for_usbmode "/dev/sda"
}

boot_hook_add preinit_main do_usbmode

The switching seems to work as intended, although I haven't tried using the block device for ExtRoot yet.But I think the hardest problem has been solved here.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.