我为自定义的开发板编写了Linux USB驱动程序,说文件名为usb_test.c。该驱动程序可以刷新微控制器上的固件。
固件存储在一个数组中。这是两个文件(app.h和app.c)
app.h
#define PIC_APPSECTOR_START_ADDRESS 0x700
#define PIC_APPSECTOR_SIZE 0x900
#define PIC_APPSECTOR_CURRENT_VERSION 0x5
extern const unsigned char ucPICAppsectorFirmware[];
app.c
#include "app.h"
const unsigned char ucPICAppsectorFirmware[] =
{
0x93,0x2b,0xff,0x3f, 0xff,0x3f,0xff,0x3f, // Address 0x0700
0x83,0x31,0x27,0x00, 0x93,0x1e,0x8e,0x2b, // Address 0x0708
0x20,0x00,0x8e,0x16, 0x4b,0x08,0x95,0x00, // Address 0x0710
0x27,0x00,0x93,0x12, 0x0b,0x1d,0x09,0x00, // Address 0x0718
0x40,0x26,0x0b,0x11, 0x09,0x00,0x94,0x2b, // Address 0x0720
0x22,0x30,0x84,0x00, 0x00,0x30,0x85,0x00, // Address 0x0728
0x2d,0x30,
};
我想从usb_test.c访问ucPICAppsectorFirmware []并执行刷新。因此,我在usb_test.c
中添加了#include "app.h"
在内核模块Makefile中,我添加了以下内容:
obj-m += usb_test.o
usb_test-objs := app.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
虽然编译运行“ make”命令的模块并没有给我错误,但是没有调用probe函数。但是,当我从Makefile中删除“ usb_test-objs:= app.o”时,出现以下错误:
WARNING: "ucPICAppsectorFirmware" [USB_Driver/usb_test.ko] undefined!
如何解决此问题。我可以将数组复制到app.h中,它可以工作。但是我想要一个解决方案,该解决方案适用于app.c中存在的数组,而不是app.h中存在的数组