Re: [PATCH] MODULE_FIRMWARE for binary firmware(s)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a reference implementation with the debian mkinitrd-tools
package.  It shows how to identify the firmware files necessary for
drivers in the initrd and also includes a primitive system for loading
them.

I've tested this with the aic94xx driver using the new MODULE_FIRMWARE()
tag.  Initramfs should be much easier because it already includes most
of the boot time loading; all it has to do is the piece identifying the
firmware for the selected modules.

James

---
Index: initrd-tools-0.1.84.1/mkinitrd
===================================================================
--- initrd-tools-0.1.84.1.orig/mkinitrd	2006-08-28 13:37:30.000000000 -0500
+++ initrd-tools-0.1.84.1/mkinitrd	2006-08-28 16:33:28.000000000 -0500
@@ -950,6 +950,7 @@ add_modules_dep() {
 		return
 	elif ! [ $oldstyle ]; then
 		add_modules_dep_2_5 $VERSION
+		add_firmware $VERSION
 		return
 	fi
 
@@ -1016,6 +1017,25 @@ add_modules_dep_2_5() {
 	fi
 }
 
+add_firmware() {
+	ver=$1
+	set -- $FSTYPES
+	unset IFS
+
+	cat modules.? |
+		while read junk mod junk; do
+			modpath=$(modprobe --set-version "$ver" --list $mod)
+			if [ -z "$modpath" ]; then
+				continue;
+			fi
+			p=$(modinfo -F firmware "$modpath" |sed 's/^/\/lib\/firmware\//')
+			if [ -n "$p" ]; then
+				echo $p
+				echo /usr/sbin/firmware_loader
+			fi
+		done
+}
+
 add_command() {
 	if [ -h initrd/"$1" ]; then
 		return
Index: initrd-tools-0.1.84.1/firmware_loader
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ initrd-tools-0.1.84.1/firmware_loader	2006-08-28 16:56:18.000000000 -0500
@@ -0,0 +1,29 @@
+#!/bin/sh -e
+#
+# firmware loader agent
+#
+FIRMWARE_DIRS="/lib/firmware"
+
+if [ "$SUBSYSTEM" != "firmware" ]; then
+    exit 0;
+fi
+
+if [ ! -e /sys/$DEVPATH/loading ]; then
+    echo "/sys/$DEVPATH/ does not exist"
+    exit 1
+fi
+
+for DIR in $FIRMWARE_DIRS; do
+    [ -e "$DIR/$FIRMWARE" ] || continue
+    echo 1 > /sys/$DEVPATH/loading
+    cat "$DIR/$FIRMWARE" > /sys/$DEVPATH/data
+    echo 0 > /sys/$DEVPATH/loading
+    exit 0
+done
+
+# the firmware was not found
+echo -1 > /sys/$DEVPATH/loading
+
+echo "Cannot find the $FIRMWARE firmware"
+exit 1
+
Index: initrd-tools-0.1.84.1/debian/rules
===================================================================
--- initrd-tools-0.1.84.1.orig/debian/rules	2006-08-28 16:07:52.000000000 -0500
+++ initrd-tools-0.1.84.1/debian/rules	2006-08-28 16:08:56.000000000 -0500
@@ -35,7 +35,7 @@ install: 
 	install -o root -g root -m 644 \
 		echo init linuxrc debian/initrd-tools/usr/share/initrd-tools/
 	install -o root -g root -m 755 \
-		mkinitrd debian/initrd-tools/usr/sbin/
+		mkinitrd firmware_loader debian/initrd-tools/usr/sbin/
 	install -o root -g root -m 644 \
 		mkinitrd.conf modules debian/initrd-tools/etc/mkinitrd/
 ifeq ($(DEB_HOST_ARCH),powerpc)
Index: initrd-tools-0.1.84.1/linuxrc
===================================================================
--- initrd-tools-0.1.84.1.orig/linuxrc	2006-08-28 16:30:30.000000000 -0500
+++ initrd-tools-0.1.84.1/linuxrc	2006-08-28 16:40:45.000000000 -0500
@@ -10,3 +10,7 @@ echo 256 > proc/sys/kernel/real-root-dev
 mount -nt tmpfs tmpfs bin ||
 	mount -nt ramfs ramfs bin
 echo $root > bin/root
+if [ -x /usr/sbin/firmware_loader ]; then
+	echo /usr/sbin/firmware_loader > /proc/sys/kernel/hotplug
+fi
+
Index: initrd-tools-0.1.84.1/init
===================================================================
--- initrd-tools-0.1.84.1.orig/init	2006-08-28 16:54:52.000000000 -0500
+++ initrd-tools-0.1.84.1/init	2006-08-28 16:55:01.000000000 -0500
@@ -366,6 +366,7 @@ get_cmdline
 [ -c /dev/.devfsd ] && DEVFS=yes
 
 mount -nt devfs devfs devfs
+mount -nt sysfs sysfs sys
 if [ $IDE_CORE != none ] && [ -n "$ide_options" ]; then
 	echo modprobe -k $IDE_CORE "options=\"$ide_options\""
 	modprobe -k $IDE_CORE options="$ide_options"


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux