空燃比分析仪,horiba尾气分析仪,CAN总线分析仪,CAN数据记录仪

广州智维电子科技有限公司

Guangzhou Triv Electronic Technologies Co.LTD

技术服务
SUPPORT

目前位置: 首页 > 技术服务 > 技术资讯

2019-03-05

在Raspberry Pi上构建CANlib(linuxcan)

作者:    点击:3241

当在任何Linux计算机上编译CANlib(linuxcan)时,您需要确保使用正确的内核头文件版本。例如,在Ubuntu上,您可以发出命令:

sudo apt install linux-headers-$(uname -r)

Linux标头包目前不能用于Rasbian上,所以你必须做一些挖掘。一旦你知道要找什么其实并不难,让我们开始。

安装所需的软件包

我们首先使用apt安装’bc’包,用它在内核上执行`make prepare’。

$ sudo apt update
$ sudo apt install bc

查找正确版本的Linux标头

通过一些详细的挖掘,我们现在会发现在我们的Raspberry Pi上运行的Rasbian操作系统的构建中使用了什么版本的Linux标头。我们首先通过执行以下命令找到目标系统中的固件版本:

$ export RPI_FW_REV=$(zcat /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | sed -n '/.*firmware as of [0-9a-fA-F]+/ {s/.*firmware as of ([0-9a-fA-F]+)/1/;p;q}')

环境变量‘RPI_FW_REV’现在应该已包含在我们的系统中使用的[https://github.com/raspberrypi/firmware]的修订版本(git_hash)。

$ echo $RPI_FW_REV
3b98f7433649e13cf08f54f509d11491c99c4c0b

使用固件版本,我们现在可以通过执行以下命令找到系统中使用的Linux内核版本:

$ export RPI_LINUX_REV=$(wget https://raw.github.com/raspberrypi/firmware/$RPI_FW_REV/extra/git_hash --quiet -O -)

环境变量`RPI_LINUX_REV’现在应该已包含系统中使用的[https://github.com/raspberrypi/linux]的修订版本(git_hash)。

$ echo $RPI_LINUX_REV
233755da0e7903fccb41f0b8c14e1da5244b69ec

获取和构建Linux标头

现在我们知道所使用的Linux标头的修订版本,我们可以通过执行以下代码下载和提取内核源代码树:

$ mkdir ~/linuxcan
$ cd ~/linuxcan
$ wget https://github.com/raspberrypi/linux/archive/$RPI_LINUX_REV.zip -O linux-$RPI_LINUX_REV.zip
$ unzip linux-$RPI_LINUX_REV.zip

从包含预编译的二进制文件的存储库中,我们也提取“Module.symvers”,其中包含了内核构建中所有导出的符号的列表。

$ cd linux-$RPI_LINUX_REV

# For RaspberryPi Model B and B+
$ wget https://raw.github.com/raspberrypi/firmware/$RPI_FW_REV/extra/Module.symvers

# For RaspberryPi 2 and 3
$ wget https://raw.github.com/raspberrypi/firmware/$RPI_FW_REV/extra/Module7.symvers -O Module.symvers

现在我们可以设置内核配置和构建标头。

$ sudo modprobe configs
$ zcat /proc/config.gz > .config
$ make prepare
$ make modules_prepare

两个“make”命令在我们的Raspberry Pi B型上执行大约需要三分钟时间。

获取和配置linuxcan

从Kvaser网站获取并提取Kvaser Linux驱动程序和开发包:

$ cd ~/linuxcan
$ wget http://www.kvaser.com/software/7330130980754/V5_17_0/linuxcan.tar.gz
$ tar xvzf linuxcan.tar.gz
$ cd ~/linuxcan/linuxcan

在linuxcan 5.17版本中,我们可以将环境变量`KV_NO_PCI’设置为1,以避免构建基于PCI的驱动程序。变量`KDIR’应该包含内核源目录的路径:

$ export KV_NO_PCI=1
$ export KDIR=/home/pi/linuxcan/linux-$RPI_LINUX_REV

构建和安装linuxcan

最后一步是构建和安装linuxcan。 `sudo’的`-E’参数将保留环境变量。在我们的例子中,我们需要使用环境变量`KDIR’和`KV_NO_PCI’。

$ make
$ sudo -E make install

2016-11-04更新: Module7.symvers应用于RaspberryPi 2和3。

使用的版本

The Raspberry Pi Model B is using the following versions

   OS            Rasbian 8.0 with kernel 4.4.11+              
   firmware.git  rev 3b98f7433649e13cf08f54f509d11491c99c4c0b 
   linux.git     rev 233755da0e7903fccb41f0b8c14e1da5244b69ec 

返回列表