|
terasic 有点坑爹DE1-soc这块基于Cyclone-V soc的开发板除了Altera的 DS-5 AE以外没有放出任何工具链以及内核的源码。而且配套教材全是及其简单的一些应用的开发,涉及到驱动部分都是用/dev/mem在访问物理内存。这你让人怎么玩!!!!
在其他网友的提醒下我用用linaro搭建了de1-soc的工具链,过程异常艰 辛现在分享出来。这下可以好好玩了 。
版权归amobbs YFM所有,转载请注明来处
安装ubuntu12.04LTS
这个就不说了在Vmware Player下装就可以
为DE1-SOC制作SD启动盘
从terasic官网上下载Linux BSP (Board Support Package): MicroSD Card Image中的Linux Console
http://www.terasic.com.cn/cgi-bi ... No=870&PartNo=4
安装工具链
在http://releases.linaro.org/14.05/components/toolchain/binaries下载交叉编译器gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux.tar.xz
以上的编译器是ubuntu下可执行的文件因此不用编译他。
解压xz –d xxxxx.tar.xz
tar –xvf xxxxx.tar
添加PATH变量export PATH=$PATH:\..\ gcc-linaro-arm-linux-gnueabihf-4.9-2014.05_linux\bin
\..\为您老解压的这个交叉编译器的目录
重新登录系统 用arm-linux-gnueabihf-gcc –v验证是否PATH环境变量添加成功。
构建内核树
下载内核 3.12.0 版本
解压内核 xz –b linux-3.12.tar.xz
tar –xvf linux-3.12.tar
进入内核源码的文件夹
gedit 顶层Makefile
修改ARCH ?= $(SUBARCH) 为 ARCH = arm
修改CROSS_COMPILE ?= 为 CROSS_COMPILE = arm-linux-gnueabihf-
make menuconfig发现如下错误:
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
原因是缺少 libncurses5-dev这个包
用apt-get install libncurses5-dev 安装这个包。在ubuntu14.40版本下apt-get找不到这个包我就又重新装了一个ubuntu12.04版的ubuntu 然后就可以安装这个libncurses5-dev的包了。
然后make下面这个文件出现错误 出错原因不明
drivers/staging/lustre/lustre/lov/lov_pack.c
这个是lustre的分布式文件系统 直接进menuconfig –> device driver->staging device 直接把这个模块去掉。
然后继续make
make modules
make modules_install
顺利完成后在ubuntu 的 /lib/modules/下可以看到3.12.0文件夹这个就是内核树。
传输文件到DE1-SOC并运行
用生成的内核树编译驱动程序hello.c生成 hello.ko
scp hello.ko root@192.168.1.253:/home
将hello.ko送到主机名为root IP地址为192.168.1.253运行在DE1-SOC上的linux系统的/home文件夹下
然后在DE1-SOC终端上insmod hello.ko出现下面的错误:
hello: version magic '3.12.0 SMP mod_unload modversions ARMv7 p2v8 ' should be '3.12.0-00307-g507abb4-dirty SMP mod_unload ARMv7 p2v8 '
Error: could not insert module hello.ko: Invalid module format
错误原因是内核树和DE1-SOC上运行的linux的vervision不一样
3.12.0-00307-g507abb4-dirty SMP mod_unload ARMv7 p2v8 这个为DE1-SOC上kernel的version
而
3.12.0 SMP mod_unload modversions ARMv7 p2v8 是我内核树的version
内核树的version少了-00307-g507abb4-dirty却多了modversions
少了-00307-g507abb4-dirty的解决方法请您老参见http://linux.die.net/lkmpg/x380.html
现复制原网页内容如下
2.8. Building modules for a precompiled kernel
Obviously, we strongly suggest you to recompile your kernel, so that you can enable a number of useful debugging features, such as forced module unloading (MODULE_FORCE_UNLOAD): when this option is enabled, you can force the kernel to unload a module even when it believes it is unsafe, via a rmmod -f module command. This option can save you a lot of time and a number of reboots during the development of a module.
Nevertheless, there is a number of cases in which you may want to load your module into a precompiled running kernel, such as the ones shipped with common Linux distributions, or a kernel you have compiled in the past. In certain circumstances you could require to compile and insert a module into a running kernel which you are not allowed to recompile, or on a machine that you prefer not to reboot. If you can't think of a case that will force you to use modules for a precompiled kernel you might want to skip this and treat the rest of this chapter as a big footnote.
Now, if you just install a kernel source tree, use it to compile your kernel module and you try to insert your module into the kernel, in most cases you would obtain an error as follows:
insmod: error inserting 'poet_atkm.ko': -1 Invalid module format
Less cryptical information are logged to /var/log/messages:
Jun 4 22:07:54 localhost kernel: poet_atkm: version magic '2.6.5-1.358custom 686
REGPARM 4KSTACKS gcc-3.3' should be '2.6.5-1.358 686 REGPARM 4KSTACKS gcc-3.3'
In other words, your kernel refuses to accept your module because version strings (more precisely, version magics) do not match. Incidentally, version magics are stored in the module object in the form of a static string, starting with vermagic:. Version data are inserted in your module when it is linked against theinit/vermagic.o file. To inspect version magics and other strings stored in a given module, issue the modinfo module.ko command:
[root@pcsenonsrv 02-HelloWorld]# modinfo hello-4.ko
license: GPL
author: Peter Jay Salzman <p@dirac.org>
description: A sample driver
vermagic: 2.6.5-1.358 686 REGPARM 4KSTACKS gcc-3.3
depends:
To overcome this problem we could resort to the --force-vermagic option, but this solution is potentially unsafe, and unquestionably inacceptable in production modules. Consequently, we want to compile our module in an environment which was identical to the one in which our precompiled kernel was built. How to do this, is the subject of the remainder of this chapter.
First of all, make sure that a kernel source tree is available, having exactly the same version as your current kernel. Then, find the configuration file which was used to compile your precompiled kernel. Usually, this is available in your current /boot directory, under a name like config-2.6.x. You may just want to copy it to your kernel source tree: cp /boot/config-`uname -r` /usr/src/linux-`uname -r`/.config.
Let's focus again on the previous error message: a closer look at the version magic strings suggests that, even with two configuration files which are exactly the same, a slight difference in the version magic could be possible, and it is sufficient to prevent insertion of the module into the kernel. That slight difference, namely the custom string which appears in the module's version magic and not in the kernel's one, is due to a modification with respect to the original, in the makefile that some distribution include. Then, examine your /usr/src/linux/Makefile, and make sure that the specified version information matches exactly the one used for your current kernel. For example, you makefile could start as follows:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 5
EXTRAVERSION = -1.358custom
...
In this case, you need to restore the value of symbol EXTRAVERSION to -1.358. We suggest to keep a backup copy of the makefile used to compile your kernel available in/lib/modules/2.6.5-1.358/build. A simple cp /lib/modules/`uname -r`/build/Makefile /usr/src/linux-`uname -r` should suffice. Additionally, if you already started a kernel build with the previous (wrong) Makefile, you should also rerun make, or directly modify symbol UTS_RELEASE in file /usr/src/linux-2.6.x/include/linux/version.haccording to contents of file /lib/modules/2.6.x/build/include/linux/version.h, or overwrite the latter with the first.
Now, please run make to update configuration and version headers and objects:
[root@pcsenonsrv linux-2.6.x]# make
CHK include/linux/version.h
UPD include/linux/version.h
SYMLINK include/asm -> include/asm-i386
SPLIT include/linux/autoconf.h -> include/config/*
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/split-include
HOSTCC scripts/basic/docproc
HOSTCC scripts/conmakehash
HOSTCC scripts/kallsyms
CC scripts/empty.o
...
If you do not desire to actually compile the kernel, you can interrupt the build process (CTRL-C) just after the SPLIT line, because at that time, the files you need will be are ready. Now you can turn back to the directory of your module and compile it: It will be built exactly according your current kernel settings, and it will load into it without any errors.
对于以上这个我是这样做的:
在建立内核树的源代码下修改顶层Makefile。在顶层Makefile的开始有如下内容
VERSION = 3
PATCHLEVEL = 12
SUBLEVEL = 0
EXTRAVERSION =
EXTRAVERSION为空这就是-00307-g507abb4-dirty不存在的原因。EXTRAVERSION=后面加上-00307-g507abb4-dirty。
多了modversions的解决方法为在建立内核树的源代码下make menuconfig 然后关闭
Enable loadable module support --->Module versioning support 这个选项。
最后重新make
make modules
make modules_install
最后您老会发现在lib/modules下多了一个3.12.0-00307-g507abb4-dirty的文件夹,这个就是新生成的内核树。
最后的最后编译ko模块传到DE1-SOC。insmod成功加载。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|