Linux 内核编译——瞎编译导致的问题

最近买了itop-4412 的板子 准被从内核移植  驱动编写  应用编程重新走一遍,刚开始很多问题没有搞懂,导致下面一些问题,后面会整理从0编译的文档


Makefile:506: arch//Makefile: No such file or directory

make: *** No rule to make target 'arch//Makefile'.  Stop.

ARCH?= $(SUBARCH) 这里不能修改成 ARCH?= $(arm)

Makefile$是递归展开 如果arm在之前没有定义 则ARCH展开为空

应该改为ARCH?= arm

gcc: error: unrecognized argument in option -mabi=aapcs-linux

gcc: note: valid arguments to -mabi=are: ms sysv

gcc: error: unrecognized command line option -mlittle-endian

gcc: error: unrecognized command line option -mno-thumb-interwork

gcc: error: unrecognized command line option -mfpu=vfp

Kbuild:21: recipe for target 'kernel/bounds.s' failed

make[1]: *** [kernel/bounds.s] Error 1

Makefile:1097: recipe for target 'prepare0' failed

make: *** [prepare0] Error 2

CROSS_COMPLIE?= /home/cjx/Linux/Linux/LinuxTool/CompileTool/arm-2009q3/bin/arm-none-linux-

gnueabi-

 

这个问题是猜测是由于编译器OABI  ,而我下载最新的内核是只支持EABI的编译器 所以没法通过,所以我又下载

3.1的版本来编译,去掉内核中的Kernel Features->Use the ARM EABIto compile the kernel选项

 

cc1: error: unrecognized command line option "-fstack-protector-strong"

Kbuild:35: recipe for target 'kernel/bounds.s' failed

make[1]: *** [kernel/bounds.s] Error 1

Makefile:980: recipe for target 'prepare0' failed

make: *** [prepare0] Error 2

这是由于编译器太老的原因 换个编译器 重新修改下Makefile编译器路径

 

fixdep: error opening depfile: kernel/.bounds.s.d: No such file or directory

Kbuild:35: recipe for target 'kernel/bounds.s' failed

make[1]: *** [kernel/bounds.s] Error 2

Makefile:980: recipe for target 'prepare0' failed

make: *** [prepare0] Error 2

有人说还是编译器不兼容内核的原因 可以查Documentation/Changes 看内核需要最低版本的编译器

Gnu C                  3.2                     # gcc --version

换了4.4.3的版本还是不行

bounds.c里面是个跳跃函数

这里看问题的描述是在Kbuild35行,Kbuild是内核的配置文件,这里看出bounds.s 是由bounds.c生成的,

但是为什么生成不了呢,最后想想还是编译器不行,又把下载了3.3.2的版本,编译又出现下面的问题

 

error: unrecognized command line option '-fstack-protector-strong

解决办法:

kernel目录下:

make menuconfig   

 General setup——

Optimize very unlikely/likely branches   把该项在编译该项中去掉。如下图:

或者把子选项Stack Protector buffer overflow detection 设置为None

接着编译

Assembler messages:

Error: unknown architecture `armv7-a'

 

scripts/Makefile.build:257: recipe for target 'scripts/mod/empty.o' failed

make[2]: *** [scripts/mod/empty.o] Error 1

scripts/Makefile.build:402: recipe for target 'scripts/mod' failed

make[1]: *** [scripts/mod] Error 2

Makefile:555: recipe for target 'scripts' failed

make: *** [scripts] Error 2

这应该是menuconfig没有配置好的原因,

System Type中选择Samsung S3C24XX SoCs

/home/cjx/usr/local/arm/3.3.2/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/bin/as: unrecognized option '-gdwarf-2'

scripts/Makefile.build:293: recipe for target 'usr/initramfs_data.o' failed

make[1]: *** [usr/initramfs_data.o] Error 1

Makefile:937: recipe for target 'usr' failed

make: *** [usr] Error 2

这里看还是gcc有问题 没有 gdwarf-2 的选项

最终又换了编译器通过,后续要分析下编译器与内核的关系


  CHK     include/config/kernel.release
Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
Makefile:1090: recipe for target 'prepare-compiler-check' failed
make: *** [prepare-compiler-check] Error 1



说明编译器不支持更强的堆栈保护,
在 >General setup->Stack Protector buffer overflow detection (Regular)  --->
改成Regular
这个变量在arch/Kconfig里面

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ARM 是一种广泛使用的 CPU 架构,而 Linux 内核是一个开放源代码的操作系统内核。在 ARM 平台上,我们可以通过内核模块编程的方式与内核进行交互,实现一些自定义的功能。 下面,我们将介绍如何在 ARM Linux 上编写内核模块,并输出一个简单的 "Hello World" 消息。 ## 1. 环境准备 在开始编写内核模块之前,需要先准备好开发环境。具体步骤如下: 1. 安装交叉编译工具链。ARM 平台上的应用程序和内核模块需要使用交叉编译工具链进行编译。可以从官网下载对应的交叉编译工具链,也可以使用已经编译好的交叉编译工具链。 2. 下载内核源代码。可以从官网下载对应版本的内核源代码,也可以使用已经编译好的内核源代码。 3. 配置内核源代码。需要在内核源代码根目录下运行配置命令 `make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig` 进行配置,选择需要的模块和功能。 ## 2. 编写内核模块 在准备好开发环境之后,可以开始编写内核模块了。具体步骤如下: 1. 创建一个新的文件夹,用于存放内核模块代码。 2. 创建一个新的 C 文件,命名为 `hello.c`。 3. 在 `hello.c` 文件中编写以下代码: ```c #include <linux/init.h> #include <linux/module.h> static int __init hello_init(void) { printk(KERN_INFO "Hello, world!\n"); return 0; } static void __exit hello_exit(void) { printk(KERN_INFO "Goodbye, world!\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("A simple hello world module"); ``` 这段代码定义了一个简单的内核模块,当模块加载时会输出 "Hello, world!" 消息,当模块卸载时会输出 "Goodbye, world!" 消息。 4. 使用交叉编译工具链进行编译。在终端中进入 `hello.c` 文件所在的文件夹,运行以下命令进行编译: ```bash arm-linux-gnueabi-gcc -Wall -Werror -O2 -o hello.ko -c hello.c ``` 这个命令将生成一个名为 `hello.ko` 的内核模块文件。 ## 3. 加载和卸载内核模块 在编写好内核模块后,我们需要将它加载到内核中进行测试。具体步骤如下: 1. 将 `hello.ko` 文件复制到 ARM Linux 系统上。 2. 在终端中进入 `hello.ko` 文件所在的文件夹,运行以下命令以加载内核模块: ```bash insmod hello.ko ``` 这个命令将调用内核中的 `init_module` 函数,执行 `hello_init` 函数,输出 "Hello, world!" 消息。 3. 查看系统日志,可以看到 "Hello, world!" 消息。 ```bash dmesg ``` 4. 在终端中运行以下命令以卸载内核模块: ```bash rmmod hello ``` 这个命令将调用内核中的 `cleanup_module` 函数,执行 `hello_exit` 函数,输出 "Goodbye, world!" 消息。 5. 再次查看系统日志,可以看到 "Goodbye, world!" 消息。 至此,我们已经成功地在 ARM Linux 上编写了一个简单的内核模块,并输出了 "Hello, world!" 消息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值