整理:linux kernel firmware update 内核设备固件升级方法

//firmware update test
//2014.07.11

#include 
#include 

const struct firmware *cust_firmware;

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = "test",
};


void devices_upgrade_start(void)
{
    int i;
    for(i=0;isize;i++)
    {
        printk("test: %x \n",*(cust_firmware->data+i));
    }
}

void firmware_test(void)
{
    int retval;

    printk("test: firmware_test\n");

    retval = request_firmware(&cust_firmware, "aa.bin", misc.this_device);
    if (retval < 0) {
        printk("test: %s: aa.bin request firmware failed(%d)\n", __func__,retval);
    } else {
        /* check and start upgrade */
        devices_upgrade_start();

        release_firmware(cust_firmware);
        printk("test: release_firmware\n");
    }
}

static int test_init(void)
{
    int ret;
    printk("test: init\n");
    //registe misc device
    ret = misc_register(&misc);
    if(ret < 0)
    {
      printk("test: can't registe misc device");
      return ret;
    }
    printk("test: misc_register ok\n");

    firmware_test();

    return 0;
}

static void test_exit(void)
{

    misc_deregister(&misc);
    printk("test: good bye\n");
}

module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");


cp aa.bin /lib/firmware

sudo insmod firmware_test.ko

[11654.046821] test: init
[11654.094990] test: misc_register ok
[11654.094993] test: firmware_test
[11654.095042] misc test: firmware: requesting aa.bin
[11654.214125] test: 31
[11654.214126] test: 32
[11654.214127] test: 33
[11654.214128] test: 34
[11654.214128] test: 35
[11654.214129] test: 36
[11654.214131] test: release_firmware


把固件放到代码中,开机自动下载

make menuconfig

Devices  Drivers  --->  Generic Driver Options  --->   External firmware blobs to build into the kernel binary  增加aa.bin文件就可以了



你可能感兴趣的:(整理:linux kernel firmware update 内核设备固件升级方法)