最近开始学习嵌入式linux,开发板买的时JZ2440,按教程,使用给的3.4.5版本的arm-linux-gcc编译linux 2.6.22.6是没有问题的。在尝试用最新的cross_compile出现了许多问题,最新的交叉编译是直接在ubuntu 上安装的,使用
sudo apt install gcc-arm-linux-gnueabi
安装完了之后先给CROSS_COMPILE赋值
sudo nano ~/.bashrc
在打开的文件里,在最后一行加上
export CROSS_COMPILE=arm-linux-gnueabi-
然后再
. ~/.bashrc
把CROSS_COMPILE永久赋值。
按教程,解压linux-2.6.22.6后,进入文件目录,然后打补丁,然后复制config_ok为.config后,要改四个文件:
第一个是根目录的Makefile:
有两个地方要修改
首先是416行的代码:
config %config: scripts_basic outputmakefile FORCE
$(Q)mkdir -p include/linux include/config
$(Q)$(MAKE) $(build)=scripts/kconfig $@
要修改成:
config: scripts_basic outputmakefile FORCE
$(Q)mkdir -p include/linux include/config
$(Q)$(MAKE) $(build)=scripts/kconfig $@
%config: scripts_basic outputmakefile FORCE
$(Q)mkdir -p include/linux include/config
$(Q)$(MAKE) $(build)=scripts/kconfig $@
也就是分开来
然后要更改的地方,先搜索dwarf,找到
AFLAGS += -gdwarf2
改成
AFLAGS += -gdwarf-2
第二个文件是在arch/arm/nwfpe/目录里的fpa11.inl文件:
把整个代码区的代码替换成下面的内容形式
#include "fpa11.h"
/* Read and write floating point status register */
static inline unsigned int readFPSR(void)
{
FPA11 *fpa11 = GET_FPA11();
return (fpa11->fpsr);
}
static inline void writeFPSR(FPSR reg)
{
FPA11 *fpa11 = GET_FPA11();
/* the sysid byte in the status register is readonly */
fpa11->fpsr = (fpa11->fpsr & MASK_SYSID) | (reg & ~MASK_SYSID);
}
/* Read and write floating point control register */
static inline FPCR readFPCR(void)
{
FPA11 *fpa11 = GET_FPA11();
/* clear SB, AB and DA bits before returning FPCR */
return (fpa11->fpcr & ~MASK_RFC);
}
static inline void writeFPCR(FPCR reg)
{
FPA11 *fpa11 = GET_FPA11();
fpa11->fpcr &= ~MASK_WFC; /* clear SB, AB and DA bits */
fpa11->fpcr |= (reg & MASK_WFC); /* write SB, AB and DA bits */
}
第三个要改的文件是 arch/arm/kernel/目录里的sys_arm.c文件:
把56行的函数定义:
inline long do_mmap2(
unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
改成
asmlinkage long do_mmap2(
unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
然后第四个要改的文件是与第三个对应的,在 include/linux/目录里的syscalls.h文件里:
添加上相应的函数申明:
asmlinkage long do_mmap2(
unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff);
做出所有上述更改后,再首先安装mkimage工具:
sudo apt install u-boot-tools
然后可以开始编译了:
make uImage -j4
这样就能顺利的编译出uImage文件了,烧写到开发板上。