编写hello内核模块--fedora21环境

1、编写内核模块

参考:https://blog.csdn.net/sh21_/article/details/60878812

hello.c --- 注意函数参数中void  ----hello_init(void)

#include <linux/module.h>
#include <linux/kernel.h>
static int hello_init(void)
{
    printk("hello  world\n");
    return 0;
}
static void hello_exit(void)
{printk("exit\n");
}
module_init(hello_init);
module_exit(hello_exit);

Makefile文件

ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR:=/lib/modules/3.17.4/build
all:
	make -C $(KDIR) M=$(PWD) modules
clean:
	rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif

这里编译出错,原因是我以前修改了 ~/.bashrc文件,所以提示找不到arm-linx-gcc

希望找到原本的bashrc,于是这篇文章帮了我:https://blog.csdn.net/yucicheung/article/details/79334998

/etc/skel是Ubuntu的各种初始配置文件的存放目录.

原始bashrc位置: /etc/skel/.bashrc

我现有的bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export ANDROID_HOME=/home/pengfei/android/sdk
export CROSS_COMPILE=/run/media/pengfei/6CC2286EC2283F28/asop/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-eabi-
export ARMH=arm
export SUBARCH=arm
export eabi_home=/run/media/pengfei/6CC2286EC2283F28/asop/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8
#export PYTHONPATH=/run/media/pengfei/6CC2286EC2283F28/asop/prebuilts/python/linux-x86/2.7.5/lib/python2.7/site-packages:$PYTHONPATH
export ANDROID_SWT=/run/media/pengfei/6CC2286EC2283F28/asop/out/host/linux-x86/framework
export ANDROID_PRODUCT_OUT=/run/media/pengfei/6CC2286EC2283F28/asop/out/target/product/generic
PATH=$eabi_home/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
export USE_CCACHE=1

初始的bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

替换之后make,生成hello.ko

插入hello模块


2、内核编程insmod后,fedora查看日志无/var/log/messages

fedora 21上没有/var/log/message了,取而代之的是journal.
参考:https://fedoraproject.org/wiki/Changes/NoDefaultSyslog

"cat /var/log/messages" will now become "journalctl".

"tail -f /var/log/messages" will now become "journalctl -f".

"grep foobar /var/log/messages" will now become "journalctl | grep foobar".


journalctl -f

5月 16 22:03:03 pengfei kernel: hello  world

5月 16 22:03:47 pengfei kernel: exit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值