• «
  • 1
  • 2
  • »
  • Pages: 1/2     Go
主题 : something wrong 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
楼主  发表于: 2009-04-16 19:51

 something wrong

when inserting a module using the kmalloc API, it prompts "unknown symbol malloc_sizes".
does that mean the symbol is not included in kernel?
I am using kernel 2.6.29 downloaded from this forum.

And I notice that my loadable module, which I think is as well removable, is not able to be removed.
What's going on with the kernel?
Give me some tips or advice, Webmaster!

Any help is appreciated! Thx in advance.
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-04-17 09:09
Does that mean the symbol is not included in kernel?

No, it depends on how it is defined.

And I notice that my loadable module, which I think is as well removable, is not able to be removed.

Please attach module sources and error message when trying to remove it
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
2楼  发表于: 2009-04-17 14:26
source code:

/* usdb.c */
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <linux/semaphore.h>
#include <linux/slab.h>

#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/irq.h>

#include <mach/regs-irq.h>

#include <plat/regs-udc.h>
#include <plat/irq.h>


#define MON_DEBUG

#undef PDEBUG
#ifdef MON_DEBUG
#  ifdef __KERNEL__
#    define PDEBUG(fmt, args...) printk(KERN_DEBUG "debug info: "fmt, ##args)
#  else
#    define PDEBUG(fmt, args...)
#  endif
#endif

#define PDEBUGG(fmt, args...)

MODULE_LICENSE("GPL");

struct circular_buffer{
    int    head;
    int    tail;
    char    *page;
};

static int        mon_major    = 0;
static int         dev_id        = 0;
static char         *dev_name    = "usb_monitor";
static void __iomem    *base_addr;

#define BUFSIZE        (1 << 12)

static struct cdev        cdev;
static struct semaphore        buf_sema;
static struct tasklet_struct    mon_tasklet;
static struct circular_buffer    buffer = {
    .head    = 0,
    .tail    = 0
};
/****************************** IO Functions ******************************/
static void udc_write8(u8 value, u32 reg){
    iowrite8(value, base_addr + reg);
}

static u8 udc_read8(u32 reg){
    return ioread8(base_addr + reg);
}

/************************** Interrupt handling ****************************/
static void dat_handler(unsigned long args){
    u16 size = 0x0000U;
    int head = buffer.head;
    int tail = buffer.tail;
    char *page = buffer.page;

    PDEBUG("Proceed to data transfer\n");
    
    size = udc_read8(S3C2410_UDC_OUT_FIFO_CNT1_REG) |
        (udc_read8(S3C2410_UDC_OUT_FIFO_CNT2_REG) << 8);

    /* Verify space availablility, load data into the buffer */
    while (size-- && ((tail + 1) % BUFSIZE != head)){
        *(char *)(page + tail) = udc_read8(S3C2410_UDC_EP3_FIFO_REG);
        tail = (tail + 1) % BUFSIZE;
    }

    /* Disable irq when there is no more buffer space */
    if (size)
        disable_irq(IRQ_USBD);
    
    buffer.tail = tail;
}

static irqreturn_t mon_isr(int irq, void *id){
    static int cnt = 0;
    u16 tfr = 0x0000;

    /* Clear interrupts */
    udc_write8(udc_read8(S3C2410_UDC_EP_INT_REG),
            S3C2410_UDC_EP_INT_REG);

    udc_write8(0x03, S3C2410_UDC_INDEX_REG);
    tfr = udc_read8(S3C2410_UDC_OUT_FIFO_CNT1_REG) |
        (udc_read8(S3C2410_UDC_OUT_FIFO_CNT2_REG) << 8);

    PDEBUG("USBD interrupt has been triggered %i times\n", ++cnt);
    PDEBUG("%u-bytes data to be transferred\n", tfr);
    
    /* Is it an interrupt of EP3 */
    if (tfr)
        tasklet_schedule(&mon_tasklet);

    return IRQ_HANDLED;
}

static int mon_release(void){
    /*
     * disable and waiting for
     * current irq being finished
     */
    disable_irq(IRQ_USBD);        
    free_irq(IRQ_USBD, &dev_id);
    enable_irq(IRQ_USBD);

    iounmap(base_addr);
    release_mem_region(S3C2410_PA_USBDEV, S3C24XX_SZ_USBDEV);
    
    return 0;
}

static int mon_open(void){
    int retval = 0;
    
    PDEBUG("Allocating io memory and ISR\n");
    
    if (!request_mem_region(S3C2410_PA_USBDEV, S3C24XX_SZ_USBDEV, dev_name))
        return -EBUSY;
        
    base_addr = ioremap_nocache(S3C2410_PA_USBDEV, S3C24XX_SZ_USBDEV);
    if (!base_addr){
        retval = -ENOMEM;
        goto merr;
    }

    retval = request_irq(IRQ_USBD, mon_isr,
        IRQF_SHARED | IRQF_TRIGGER_LOW,
        dev_name, &dev_id);
    if (retval)
        goto ierr;
    
    return 0;

ierr:
    iounmap(base_addr);
merr:
    release_mem_region(S3C2410_PA_USBDEV, S3C24XX_SZ_USBDEV);
    return retval;

}

static ssize_t mon_read(struct file *filp, char __user *buf, size_t count,
            loff_t *pos){
    int head;
    int tail;
    int size;
    char *page = buffer.page;
    int retval = 0;

    PDEBUG("Output data from buffer\n");
    if (down_interruptible(&buf_sema))
        return -ERESTARTSYS;

    /* Read the position and the data size */
    head = buffer.head;
    tail = buffer.tail;
    size = (tail + BUFSIZE - head) % BUFSIZE;

    /* No data available */
    if (!size)
        goto exit;

    /* Copy the data to user space */
    retval = copy_to_user(buf, (char *)(page + head), size);
    if (retval){
        retval = -EFAULT;
        goto exit;
    }
    
    /* Re-enable the irq when there is space available */
    if ((tail + 1) % BUFSIZE == head)
        enable_irq(IRQ_USBD);

    /* Update buffer's position pointers */
    buffer.head += size;

    retval = size;
exit:
    up(&buf_sema);
    return retval;
}

struct file_operations fops = {
    .owner = THIS_MODULE,
    .read = mon_read
};

static void __exit mon_cleanup(void){
    dev_t devno = MKDEV(mon_major, 0);

    /* free the irq before killing the data handling tasklet */    
    mon_release();
    tasklet_kill(&mon_tasklet);
    
    kfree(buffer.page);
    cdev_del(&cdev);
    unregister_chrdev_region(devno, 1);
}

static int __init mon_init(void){
    dev_t devno;
    int retval = 0;

    /*
     * create device major and minor number
     */
    if (mon_major){
        devno = MKDEV(mon_major, 0);
        retval = register_chrdev_region(devno, 1, dev_name);
    }
    else{
        retval = alloc_chrdev_region(&devno, 0, 1, dev_name);
        mon_major = MAJOR(devno);
    }
    if (retval)
        goto exit;

    /* Initialize the buffer */
    buffer.page = kmalloc(BUFSIZE, GFP_KERNEL);
    if (!buffer.page){
        retval = -ENOMEM;
        goto err1;
    }
    memset(buffer.page, 0, BUFSIZE);

    /* Initialize a tasklet for data handling */
    tasklet_init(&mon_tasklet, dat_handler, 0x0UL);

    if ((retval = mon_open()))
        goto err2;
    

    sema_init(&buf_sema, 1);
    /*
     * add a char device
     */
    cdev_init(&cdev, &fops);
    cdev.owner = THIS_MODULE;
    retval = cdev_add(&cdev, devno, 1);
    if (retval)
        goto err3;
    
    return 0;

err3:
    mon_release();
err2:
    kfree(buffer.page);
err1:
    unregister_chrdev_region(devno, 1);
exit:
    return retval;
}

module_init(mon_init);
module_exit(mon_cleanup);


error message:
usbd: Unknown symbol malloc_sizes
insmod: cannot insert 'usbd.ko': unknown symbol in module or invalid parameter
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2009-04-17 15:34
I've tried to compile your module source code but it seems there's no symbol called 'malloc_sizes' referenced by this module.

alex@localhost:~/project3/qq2440/linux/usbd_mod$ make ARCH=arm CROSS_COMPILE=/home/alex/project3/openmoko-build/build/tmp/cross/armv4t/bin/arm-angstrom-linux-gnueabi- -C ../linux-2.6.29-mini2440 M=`pwd` modules
make: Entering directory `/home/alex/project3/qq2440/linux/linux-2.6.29-mini2440'

  WARNING: Symbol version dump /home/alex/project3/qq2440/linux/linux-2.6.29-mini2440/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/alex/project3/qq2440/linux/usbd_mod/usbd_mod.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/alex/project3/qq2440/linux/usbd_mod/usbd_mod.mod.o
  LD [M]  /home/alex/project3/qq2440/linux/usbd_mod/usbd_mod.ko
make: Leaving directory `/home/alex/project3/qq2440/linux/linux-2.6.29-mini2440'
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$ ls -l
total 40
-rw-r--r-- 1 alex alex   20 2009-04-17 15:26 Makefile
-rw-r--r-- 1 alex alex   61 2009-04-17 15:30 modules.order
-rw-r--r-- 1 alex alex    0 2009-04-17 15:30 Module.symvers
-rw-r--r-- 1 alex alex 6253 2009-04-17 15:26 usbd_mod.c
-rw-r--r-- 1 alex alex 5964 2009-04-17 15:30 usbd_mod.ko
-rw-r--r-- 1 alex alex  444 2009-04-17 15:30 usbd_mod.mod.c
-rw-r--r-- 1 alex alex 1356 2009-04-17 15:30 usbd_mod.mod.o
-rw-r--r-- 1 alex alex 5260 2009-04-17 15:30 usbd_mod.o
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$ nm usbd_mod.ko
00000000 t $a
00000020 t $a
00000040 t $a
00000148 t $a
0000023c t $a
00000000 t $a
00000000 t $a
00000294 t $a
0000001c t $d
0000003c t $d
00000138 t $d
00000234 t $d
00000288 t $d
0000004c t $d
000001bc t $d
00000354 t $d
00000000 d $d
00000000 r $d
000000b4 d $d
         U __arm_ioremap
         U __copy_to_user
         U __iounmap
         U __memzero
00000000 r __mod_license37
00000018 r __mod_vermagic5
0000000c r __module_depends
         U __release_region
         U __request_region
         U __tasklet_schedule
00000000 D __this_module
         U alloc_chrdev_region
00000018 b base_addr
00000058 b buf_sema
00000000 b buffer
0000001c b cdev
         U cdev_add
         U cdev_del
         U cdev_init
00000000 T cleanup_module
00000014 b cnt.15385
00000148 t dat_handler
00000010 b dev_id
00000000 r dev_name
         U disable_irq
         U down_interruptible
         U enable_irq
00000000 D fops
         U free_irq
00000000 T init_module
         U iomem_resource
         U kfree
         U kmalloc_caches
         U kmem_cache_alloc
00000000 t mon_cleanup
00000000 t mon_init
00000294 t mon_isr
0000000c b mon_major
00000040 t mon_read
0000023c t mon_release
00000064 b mon_tasklet
         U printk
         U register_chrdev_region
         U request_irq
         U tasklet_init
         U tasklet_kill
00000020 t udc_read8
00000000 t udc_write8
         U unregister_chrdev_region
         U up
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$ nm usbd_mod.ko |grep malloc
         U kmalloc_caches
alex@localhost:~/project3/qq2440/linux/usbd_mod$
alex@localhost:~/project3/qq2440/linux/usbd_mod$ nm usbd_mod.ko |grep U
         U __arm_ioremap
         U __copy_to_user
         U __iounmap
         U __memzero
         U __release_region
         U __request_region
         U __tasklet_schedule
         U alloc_chrdev_region
         U cdev_add
         U cdev_del
         U cdev_init
         U disable_irq
         U down_interruptible
         U enable_irq
         U free_irq
         U iomem_resource
         U kfree
         U kmalloc_caches
         U kmem_cache_alloc
         U printk
         U register_chrdev_region
         U request_irq
         U tasklet_init
         U tasklet_kill
         U unregister_chrdev_region
         U up

You can try using attached module and tell me the output of insmod.
附件: usbd_mod.ko.bz2 (3 K) 下载次数:4
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
4楼  发表于: 2009-04-17 17:25

 回 3楼(kasim) 的帖子

Firstly, I appreciate your help, sir

error output when inserting the module you provide:

insmod: cannot insert 'usbf_mod.ko': invalid module format
usbd_mod: version magic '2.6.29-FriendlyARM mod_unload ARMv4 ' should be 2.6.29 mod_unload ARMv4

I think the problem is located in the kmalloc() API, for a reference to "malloc_sizes" is found
within the function kmalloc() in source file mm/slab.c.

After realizing the above, I marked all kmalloc()-related lines to be comments, resulting in the problem's going!
what's going on with the kernel, or anything wrong with my module?!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2009-04-17 21:50
insmod: cannot insert 'usbf_mod.ko': invalid module format
usbd_mod: version magic '2.6.29-FriendlyARM mod_unload ARMv4 ' should be 2.6.29 mod_unload ARMv4

Which kernel image you're running on your board? Is it built from 2.6.29 sources provided by FriendlyARM?
You can find CONFIG_LOCALVERSION="-FriendlyARM" in default kernel config of 2.6.29 sources provided by FriendlyARM
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
6楼  发表于: 2009-04-17 22:44
mine is mini2440-20090323
do i have to update to linux-2.6.29-mini2440-20090405 ?
    
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2009-04-17 23:25
Always build your kernel module using kernel sources and configuration from which your running kernel image are built :)
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
8楼  发表于: 2009-04-18 17:08
还是说回中文吧,呵呵

今天重烧了zImage,不过还是之前那个,因为用这个
http://www.arm9down.cn/linux/linux-mini2440-20090405.tgz 和里面的config_N35编译出来的的不行,
启动时会卡在Uncompressing linux那里,所以只好用之前那个影像文件。

当插入usbd.ko 的时候就发现IRQ_USBD 不断被 trigger, 不知是何原因。之前没有这个问题
后来在中断处理中把usb的中断清除了(之前只把endpoint的清除)就没事了。

现在问题是: 将开发板插入PC机后, 发现PC机不能识别USB device,反而将板设置成NOR启动的时候就识别到。
这是通过lsusb输出的信息判断的,NOR启动时,包含如下信息:
Bus 003 Device 004: ID 5345:1234 Owon PDS6062T Oscilloscope
而NAND启动就不然。

请问是不是我的板坏了,还是怎样呢?好郁闷。
级别: 侠客
UID: 3278
精华: 0
发帖: 61
金钱: 600 两
威望: 576 点
综合积分: 122 分
注册时间: 2009-01-03
最后登录: 2011-03-07
9楼  发表于: 2009-04-18 18:18
那个中断是suspend中断
  • «
  • 1
  • 2
  • »
  • Pages: 1/2     Go