Chinaunix首页 | 论坛 | 博客
  • 博客访问: 336467
  • 博文数量: 73
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 421
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-03 15:18
个人简介

做笔记用,多为转载。

文章分类

全部博文(73)

文章存档

2016年(2)

2015年(29)

2014年(19)

2013年(23)

我的朋友

分类: LINUX

2016-03-03 10:47:49

http://www.cnblogs.com/cornflower/archive/2011/11/25/2263316.html
MODULE_LICENSE 来声明该模块的Lience。

  1. 如果是FREE SOFTWRAE, we can feed with the string
  • "GPL"
  • "GPL v2"
  • "Dual BSD/GPL"
  • "Dual MIT/GPL"
  • "Dual MPL/GPL"

2. Non free products. we can feed with

  • "Proprietary"

This exists for several reasons:

    1. 用户有人感兴趣,可以是用MODULE_ALIAS(Not sure)
    2. 如果设置为Proprietary,community 可以忽略你的BUG Report

如果你的驱动中没有声明MODULE_LICENSE, 则会出现如下的警告:

module license 'unspecified' taints kernel.

如果你声明的是"Proprietary",则会出现的结果是你不能调用系统提供的以EXPORT_SYMBOL_GPL 导出的函数

module license 'Proprietary' taints kernel. 这个也会出现的。

比如“hrtimer* ”“work_queue”相关的一些函数。这种错误就会在你build image的时候就会产生。类似

FATAL: modpost: GPL-incompatible module mytest.ko uses GPL-only symbol 'ktime_get'

 

如下的方法可以来实现逃离GPL。强烈不建议这样做

  1. 将所有涉及到GPL的API重新封装和并且以EXPORT_SYMBOL的形式导出,在一个C文件中完成。将其声明称GPL,并将其编译成模块
  2. 自己"Proprietary" 的模块中调用我们刚刚封装的函数,就可以了,

如下是一个例子

总共四个文件如下

hello.c  Makefile  open_toall.c  open_toall.h

其中:hello.c

#include
#include
#include
#include "open_toall.h"
MODULE_LICENSE("Proprietary");

static int hello_init(void)
{
    u64 now = ktime_to_ns (hktime_get ());
    printk ("[%6.6lld]", now);
    printk(KERN_ALERT "hello,world1\n");
    return 0;
}
static void hello_exit(void)
{
    printk(KERN_ALERT "goodbye cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

 

Makefile  :

ifneq ($(KERNELRELEASE),)
    obj-m:=hello.o open_toall.o
else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
    rm -f *.o *.ko *.mod.c *.order *.symvers
endif

 

open_toall.c :

#include
#include
#include
#include
#include
#include

ktime_t hktime_get(void)
{
    return ktime_get();
}
EXPORT_SYMBOL(hktime_get);
MODULE_LICENSE("Dual BSD/GPL");

static int hello_gplin(void)
{
        printk(KERN_ALERT "hello,gpl\n");
            return 0;
}
static void hello_gplexit(void)
{
        printk(KERN_ALERT "goodbye gpl\n");
}

module_init(hello_gplin);
module_exit(hello_gplexit);

open_toall.h :

#include

extern ktime_t hktime_get(void);

 

make 完成之后可以insmod了。

首先insmod open_toall.ko

接着  insmod hello.ko

Torvalds said. 'We've always made it very clear that the kernel system call interfaces do not in any way result in a derived work as per the GPL.'

调用系统内核接口不会变成一个派生作品。

并且,由于Glibc 库也是基于GPL的,所以你所有的编译都是受到GPL的感染的,如果定义API的调用所产生的文件也是GPL的,那么我们什么东西都不要用了。

阅读(2870) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~