[RFC][PATCH 1/2] firmware version management: add firmware_version()

From: Martin Langer
Date: Sat Jul 08 2006 - 09:01:58 EST


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@xxxxxx>


--- ../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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/