在TX1上安裝RPLidar及其驅動


安裝:參考官方教程即可:https://github.com/robopeak/rplidar_ros/wiki

問題:安裝完rplidar後,命令行輸入ls –l /dev | grep ttyUSB 並沒有發現 /dev/ttyUSB0。

原因:TX1內核裏缺少相應的驅動,cp210x


方法1:

比較直接的方法是 http://blog.csdn.net/sinat_31135199/article/details/52902744?locationNum=13&fps=1 博客裏的方法,即直接在TX1上編譯相應的驅動。

但是我在tx1上編譯的過程中遇到了以下問題:
Failed to compile kernel module (gcc cannot recognize aarch64 option: -mgeneral-regs-only)

可能原因是:
‘This is an aarch64 specific option that the ARM A57 on TX1 should support, so I guess it’s a toolchain issue.’
如果執行以下步驟重新安裝gcc,會卸載掉原先安裝好的cuda,ros,plc等程序
sudo dpkg –add-architecture arm64
sudo apt-get update
sudo apt-get install libc6:arm64 binutils:arm64 cpp-4.8:arm64 gcc-4.8:arm64


方法2:

用這個方法解決了以上問題,思路是在pc機上交叉編譯cp210x這個驅動,然後把相應的庫文件拷貝到tx1上的相應位置,配置生效。

參考:

https://devtalk.nvidia.com/default/topic/906942/failed-to-compile-module-gcc-cannot-recognize-aarch64-option-mgeneral-regs-only-/

I’ve been struggling with getting cross compilation to work with the Jetson TX1 kernel source for a while and also found a lot of the posts on the forum to be only partial answers. I’m going to step through it here.

As a more direct response to the question above, the -mgeneral-regs-only error means you’re using the wrong compiler to attempt to compile the kernel source (one which doesn’t take the -mgeneral-regs-only flag). You might be trying to just compile the kernel source on the Jetson or you might be trying to cross compile on another machine and the ARCH variable is not set correctly.

Beginning Notes:
I have only needed to compile the CP210x and FTDI kernel modules. All of this should be extensible and work for any additional modules you want to compile (once your cross compilation environment is setup, it should just be a matter of changing things in menuconfig).

If you weren’t sure, all of the cross compiling should take place on a different workstation. I am using a desktop running Ubuntu 14.04 x86_64 with kernel 3.13.0-92-generic

The kernel source version I downloaded/installed was L4T R23.2, and my Jetson TX1 kernel version was 3.10.67-g458d45c (note the general kernel version should match 3.10.67 in my case). This guide should not be specific to either of these.

apt-get Dependencies:
{menuconfig}

sudo apt-get install libncurses5-dev

Setup Helpful Directories:
Anywhere you’d like, setup a directory structure to manage the kernel sources, compilers, and the output files. I used /usr/local for the unpacked, binaries of the Linaro compilers I used, and a directory structure shown below.

jetson_kernel
|
|- build
|- modules
|- kernel
   |
   |- ${UNPACKED_KERNEL_SOURCE_LOCATION}
|- bin
   |
   |- jetson_latest_kernel
      |
      |- ${KERNEL_SOURCE_TAR_LOCATION}
   |- linaro_11
      |
      |- ${LINARO_COMPILER_TARS}

# LINARO_COMPILER_BINARIES at /usr/local/

Kernel Source: https://developer.nvidia.com/embedded/dlc/l4t-23-2-kernel-sources
aarch64 compiler: http://releases.linaro.org/components/toolchain/binaries/5.2-2015.11/aarch64-linux-gnu/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu.tar.xz
arm compiler: http://releases.linaro.org/components/toolchain/binaries/5.2-2015.11/arm-linux-gnueabihf/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf.tar.xz

Move each to respective dir shown above, unpack, and move to /jetson_kernel/kernel/ and /usr/local respectively as shown above.

Setup Environment Variables:
NOTE: unlike other users at https://devtalk.nvidia.com/default/topic/929186/jetson-tx1-kernel-compilation/ the Makefile for the kernel sources would NOT use my env paths for CROSS_COMPILE, CROSS32CC, or ARCH. I decided to flag these explicitly below.

export TEGRA_KERNEL_OUT=/full/path/to/jetson_kernel/build/


export TEGRA_MODULES_OUT=/full/path/to/jetson_kernel/modules/

Then env to make sure they show up.

Fixing Makefile and c file errors:
NOTE: I would recommend trying to compile things before making these changes, just to verify that they are a problem for you. They should occur while trying zImage.

Error: r7 cannot be used in asm here

sudo vim jetson_kernel/kernel/Makefile
#Search for KBUILD_CFLAGS_KERNEL (around line 378)
#Edit to add the -fomit-frame-pointer flag to read
KBUILD_CFLAGS_KERNEL := -fomit-frame-pointer

logical not is only applied to the left hand side of comparison

sudo vim jetson_kernel/kernel/drivers/platform/tegra/tegra21_clocks.c
#Search for is_lp_cluster (around line 1064)
#Edit to add parenthesis around the !is_lp_cluster() expression such that line reads
c->state = ((!is_lp_cluster()) == (c->u.cpu.mode == MODE_G)) ? ON : OFF;

Compilation Setup makes:
Note: I am compiling with -j8, you might have to change this depending on the number of cores in your computer.
Note 2: As stated above, I am specifying all of my path locations in the make because environment variables were not being inherited by the kernel source Makefile.
Note 3: Do not copy paste all of these commands in at once. Run each individually and make sure it compiles/runs through.

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT prepare

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT mrproper

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT tegra21_defconfig

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT menuconfig

In the menuconfig, you will want to go to General Setup -> Local Version and enter the dash and what comes after of uname -r on your Jetson TX1.

uname -r
3.10.67-g458d45c
-g458d45c
#^^^ What we want

Then we will want to enable the compilation of the modules we need in menuconfig. For me these are CP210x and FTDI. So I will navigate to Device Drivers -> USB Support -> USB Serial Converter Support and then type “M” in each “< >” field of the drivers I want compiled.

Once this is done, navigate to “Save” at the bottom, then “Exit” until menuconfig exits.

Finish compiling the kernel source:

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT zImage

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT dtbs

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT modules

sudo make -j8 ARCH=arm64 CROSS_COMPILE=/usr/local/gcc-linaro-5.2-2015.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- CROSS32CC=/usr/local/gcc-linaro-5.2-2015.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$TEGRA_MODULES_OUT

Now your compiled kernel modules should be located in the /jetson_kernel/modules directory you created at the beginning, down in a drivers directory, under your specific device.

Ex. - /jetson_kernel/modules/lib/modules/3.10.67-g458d45c/kernel/drivers/usb/serial/cp210x.ko

Installing the Compiled Modules:
Once you have these modules compiled you just need to copy them into their respective kernel module directory on the Jetson TX1.

For me, this was done with

sudo cp cp210x.ko ftdi_sio.ko /lib/modules/3.10.67-g458d45c/kernel/drivers/usb/serial/

Then you just need to install them via

sudo depmod -a
#我使用的是:
sudo insmod /lib/modules/3.10.67-g458d45c/kernel/drivers/usb/serial/cp210x.ko 
(inmod 意爲加載模塊,rmmod 意爲刪除模塊)
#sudo modprobe -v /lib/modules/3.10.67-g458d45c/kernel/drivers/usb/serial/cp210x.ko
#sudo modprobe -v /lib/modules/3.10.67-g458d45c/kernel/drivers/usb/serial/ftdi_sio.ko

在終端輸入一下命令檢驗模塊是否加載成功,至此問題解決。
ls –l /dev | grep ttyUSB

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章