Chinaunix首页 | 论坛 | 博客
  • 博客访问: 416270
  • 博文数量: 99
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 1012
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 16:30
个人简介

linux kernel 工程师

文章分类

全部博文(99)

文章存档

2018年(5)

2017年(12)

2016年(27)

2015年(10)

2014年(43)

2012年(2)

我的朋友

分类: LINUX

2018-01-31 11:08:18

How to build modules using WRLinux SDK

1. Prepare sdk
===============

In $PRJ directory, execute  
# make export-sdk
then ensure that wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh is generated in $PRJ/export.


Copy the sdk to a work directory and extract the sdk.
# cp $PRJ/export/wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh /path-to-work-dir
# cd /path-to-work-dir
# ./wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh

setup the buid env
# source ./env.sh
# cd sysroots/corei7-64-wrs-linux/usr/src/kernel
# make scripts
# cd /path-to-work-dir


2. An example for building ko
==============================

a. Create a directory to create ko source.

b. Generate a C file in the ko source as below:

/* hello.c */

#include     // included for all kernel modules
#include     // included for KERN_INFO
#include       // included for __init and __exit macros

MODULE_LICENSE("GPL");
MODULE_AUTHOR("my_name");
MODULE_DESCRIPTION("A Simple Hello World module");


static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world!\n");
    return 0;    // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void)
{
    printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);

c. Generate a Makefile in the ko source as below:

#Makefile for modules

obj-m += hello.o


KERNEL_DIR := ${SDKTARGETSYSROOT}/usr/src/kernel

all:
    make -C ${KERNEL_DIR} M=$(PWD) modules
clean:
    make -C ${KERNEL_DIR} M=$(PWD) clean

d. Build the ko
# make
then the ko could be created.



















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