public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Langer <martin-langer@gmx.de>
To: linux-kernel@vger.kernel.org
Cc: bcm43xx-dev@lists.berlios.de
Subject: [RFC][PATCH 1/2] firmware version management: add firmware_version()
Date: Sat, 8 Jul 2006 15:09:04 +0200	[thread overview]
Message-ID: <20060708130904.GA3819@tuba> (raw)

It would be good if a driver knows which firmware version will be 
written to the hardware. I'm talking about external firmware files 
claimed by request_firmware(). 

We know so many different firmware files for bcm43xx and it becomes 
more and more complicated without some firmware version management.

This patch can create the md5sum of a firmware file. Then it looks into 
a table to figure out which version number is assigned to the hashcode.
That table is placed in the driver code and an example for bcm43xx comes 
in my next mail. Any comments?


Signed-off-by: Martin Langer <martin-langer@gmx.de>


--- ../linux-2.6.18rc1/drivers/base/firmware_class.c	2006-07-07 13:41:01.000000000 +0200
+++ drivers/base/firmware_class.c	2006-07-07 14:39:15.000000000 +0200
@@ -16,6 +16,8 @@
 #include <linux/interrupt.h>
 #include <linux/bitops.h>
 #include <linux/mutex.h>
+#include <linux/scatterlist.h>
+#include <linux/crypto.h>
 
 #include <linux/firmware.h>
 #include "base.h"
@@ -48,6 +50,32 @@
 	struct timer_list timeout;
 };
 
+u32 firmware_version(const struct firmware *fw, struct firmware_files *elmnt)
+{
+	struct scatterlist sg;
+	struct crypto_tfm *tfm;
+	char sig[16];
+
+	tfm = crypto_alloc_tfm("md5", 0);
+	if (tfm == NULL)
+		return 0;
+
+	sg_init_one(&sg, fw->data, fw->size);
+
+	crypto_digest_init(tfm);
+	crypto_digest_update(tfm, &sg, 1);
+	crypto_digest_final(tfm, sig);
+	crypto_free_tfm(tfm);
+
+	while (elmnt->version) {
+		if (memcmp(sig, elmnt->signature, sizeof(sig)) == 0)
+			return elmnt->version;
+		elmnt++;
+	}
+
+	return 0;
+}
+
 static void
 fw_load_abort(struct firmware_priv *fw_priv)
 {
@@ -605,6 +633,7 @@
 module_init(firmware_class_init);
 module_exit(firmware_class_exit);
 
+EXPORT_SYMBOL(firmware_version);
 EXPORT_SYMBOL(release_firmware);
 EXPORT_SYMBOL(request_firmware);
 EXPORT_SYMBOL(request_firmware_nowait);
--- ../linux-2.6.18rc1/include/linux/firmware.h	2006-06-18 03:49:35.000000000 +0200
+++ include/linux/firmware.h	2006-07-08 13:36:36.000000000 +0200
@@ -10,7 +10,12 @@
 	size_t size;
 	u8 *data;
 };
+struct firmware_files {
+	u8 signature[16];
+	u32 version;
+};
 struct device;
+u32 firmware_version(const struct firmware *fw, struct firmware_files *elmnt);
 int request_firmware(const struct firmware **fw, const char *name,
 		     struct device *device);
 int request_firmware_nowait(
--- ../linux-2.6.18rc1/drivers/base/Kconfig	2006-07-07 13:41:01.000000000 +0200
+++ drivers/base/Kconfig	2006-07-07 14:34:23.000000000 +0200
@@ -21,6 +21,7 @@
 config FW_LOADER
 	tristate "Userspace firmware loading support"
 	select HOTPLUG
+	select CRYPTO_MD5
 	---help---
 	  This option is provided for the case where no in-kernel-tree modules
 	  require userspace firmware loading support, but a module built outside

             reply	other threads:[~2006-07-08 13:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-08 13:09 Martin Langer [this message]
2006-07-08 13:31 ` [RFC][PATCH 1/2] firmware version management: add firmware_version() Arjan van de Ven
2006-07-08 13:49   ` Marcel Holtmann
2006-07-09 12:21     ` Martin Langer
2006-07-09 13:25       ` Marcel Holtmann
2006-07-09 14:44       ` Michael Buesch
2006-07-09 14:57         ` Marcel Holtmann
2006-07-09 15:00         ` Jon Smirl
2006-07-09 14:51       ` Jon Smirl
2006-07-09 15:01       ` Arjan van de Ven
2006-07-09 15:25         ` Martin Langer
2006-07-09 19:09           ` Michael Buesch
2006-07-09 21:07             ` Arjan van de Ven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060708130904.GA3819@tuba \
    --to=martin-langer@gmx.de \
    --cc=bcm43xx-dev@lists.berlios.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox