参考
http://www.alliedjeep.com/38071.htm
https://www.zhihu.com/question/21518507
http://professor.blog.51cto.com/996189/1618390/
概述
前面几篇博文介绍了Python交叉编译到ARM开发板上面,在使用的时候遇到一个问题,就是当按下键盘上面的方向键的时候看到的都是乱码。
平台
主机: ubuntu14.04 64bit
开发板: qemu + aarch64 (参考: http://www.cnblogs.com/pengdonglin137/p/6442583.html)
工具链: aarch64-linux-gnu-gcc (gcc version 4.9.1 20140529) 用于编译aarch64上面运行的程序
Python版本: Python-3.6.0 和 Python-2.7.13
解决
1、下载readline和termcap的源码
-
readline的下载链接:
http://files.cnblogs.com/files/pengdonglin137/readline-7.0.tar.gz
或者 http://ftp.gnu.org/gnu/readline/readline-7.0.tar.gz
-
termcap的下载链接:
http://files.cnblogs.com/files/pengdonglin137/termcap-1.3.1.tar.gz
或者 http://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
2、交叉编译
-
readline
解压:
1 tar -xf readline-7.0.tar.gz 2 mkdir aarch64 3 cd aarch64
配置、编译和安装 mk.sh:
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 ../readline-7.0/configure --host=aarch64-linux-gnu 6 --prefix=`pwd` 7 8 make -j4 9 make install
-
termcap
termcap编译稍微麻烦一点,需要手动修改configure生成的Makefile文件。
解压:
1 tar -xf termcap-1.3.1.tar.gz 2 mkdir aarch64 3 cd aarch64
配置 mk1_conf.sh:
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 ../termcap-1.3.1/configure --host=aarch64-linux-gnu 6 --prefix=`pwd`
修改Makefile:
1 --- Makefile.orgin 2017-03-24 15:50:24.557379472 +0800 2 +++ Makefile 2017-03-24 15:50:32.749379210 +0800 3 @@ -21,9 +21,11 @@ 4 srcdir = ../termcap-1.3.1 5 VPATH = ../termcap-1.3.1 6 7 -CC = gcc 8 -AR = ar 9 -RANLIB = ranlib 10 +cross_compile = aarch64-linux-gnu- 11 + 12 +CC = ${cross_compile}gcc 13 +AR = ${cross_compile}ar 14 +RANLIB = ${cross_compile}ranlib 15 16 INSTALL = /usr/bin/install -c 17 INSTALL_DATA = ${INSTALL} -m 644
即需要手动将修改工具链。
编译安装 mk2_make.sh:
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 make -j4 6 make install
3、配置Python3
-
修改mk1_conf.sh, 增加readline和termcap的lib和include路径
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 ../Python-3.6.0/configure 6 --host=aarch64-linux-gnu 7 --build=aarch64 8 --prefix=`pwd` 9 --enable-ipv6 10 --enable-shared 11 ac_cv_file__dev_ptmx="yes" 12 ac_cv_file__dev_ptc="no" 13 LDFLAGS="-L/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/lib 14 -L/home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch64/lib 15 -L/home/pengdonglin/src/qemu/python_cross_compile/Termcap/aarch64/lib" 16 CPPFLAGS="-I/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/include 17 -I/home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch64/include 18 -I/home/pengdonglin/src/qemu/python_cross_compile/Termcap/aarch64/include"
修改完成之后,执行mk1_conf.sh
-
修改该Module/Setup文件
1 --- Setup.origin 2017-03-24 15:54:52.609370903 +0800 2 +++ Setup 2017-03-24 15:09:46.781457397 +0800 3 @@ -164,7 +164,7 @@ 4 # it, depending on your system -- see the GNU readline instructions. 5 # It's okay for this to be a shared library, too. 6 7 -#readline readline.c -lreadline -ltermcap 8 +readline readline.c -lreadline -ltermcap 9 10 11 # Modules that should always be present (non UNIX dependent)
即将readline这一行取消注释
-
编译安装 mk2_make.sh
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 make -j4 6 make install
4、配置Python2
Python2跟Python3的处理方法稍有不同。
-
修改mk1_conf.sh, 增加readline和termcap的lib和include路径
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH 4 5 ../Python-2.7.13/configure --prefix=`pwd` 6 --host=arm-none-linux-gnueabi 7 --build=x86_64-linux-gnu 8 --enable-ipv6 9 --enable-shared 10 ac_cv_file__dev_ptmx="yes" 11 ac_cv_file__dev_ptc="no" 12 LDFLAGS="-L/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/lib 13 -L/home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch32/lib 14 -L/home/pengdonglin/src/qemu/python_cross_compile/Termcap/aarch32/lib" 15 CPPFLAGS="-I/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/include 16 -I/home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch32/include 17 -I/home/pengdonglin/src/qemu/python_cross_compile/Termcap/aarch32/include" 18 LDLAST="-L/home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch32/lib 19 -L/home/pengdonglin/src/qemu/python_cross_compile/Termcap/aarch32/lib"
跟Python3一样,添加readline和termcap的include和lib路径, 此外,还需要手动修改LDLAST的值,将readline和termcap的lib的路径添加到其中,否则在编译的时候会提示找不到l-lreadline和-ltermcap,然后执行./mk1_conf.sh
- 修改Modules/Setup
1 --- Setup.orig 2017-03-24 16:44:37.121275501 +0800 2 +++ Setup 2017-03-24 15:18:11.845441252 +0800 3 @@ -163,7 +163,7 @@ 4 # it, depending on your system -- see the GNU readline instructions. 5 # It's okay for this to be a shared library, too. 6 7 -#readline readline.c -lreadline -ltermcap 8 +readline readline.c -lreadline -ltermcap 9 10 11 # Modules that should always be present (non UNIX dependent):
-
编译 mk2_make.sh
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 make HOSTPYTHON=../x86_64/python 6 HOSTPGEN=../x86_64/Parser/pgen 7 BLDSHARED="aarch64-linux-gnu-gcc -shared" 8 CROSS_COMPILE=aarch64-linux-gnu- 9 CROSS_COMPILE_TARGET=yes 10 HOSTARCH=aarch64-linux-gnu 11 BUILDARCH=x86_64-linux-gnu 12 -j4
-
安装 mk3_install.sh
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 make install HOSTPYTHON=../x86_64/python 6 BLDSHARED="aarch64-linux-gnu-gcc -shared" 7 CROSS_COMPILE=arm-none-linux-gnueabi- 8 CROSS_COMPILE_TARGET=yes 9 prefix=`pwd`
5、修改制作ramdisk的脚本 mk_ramdisk.sh
1 #!/bin/bash 2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH 4 5 sudo rm -rf rootfs 6 sudo rm -rf tmpfs 7 sudo rm -rf ramdisk* 8 9 sudo mkdir rootfs 10 sudo cp ../busybox-1.24.2/_install/* rootfs/ -raf 11 12 sudo mkdir -p rootfs/proc/ 13 sudo mkdir -p rootfs/sys/ 14 sudo mkdir -p rootfs/tmp/ 15 sudo mkdir -p rootfs/root/ 16 sudo mkdir -p rootfs/var/ 17 sudo mkdir -p rootfs/mnt/ 18 19 sudo cp etc rootfs/ -arf 20 sudo mkdir -p rootfs/lib 21 22 sudo cp -arf ../gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/aarch64-linux-gnu/libc/lib/aarch64-linux-gnu/* rootfs/lib/ 23 24 #python 25 version=3 26 sudo mkdir -p rootfs/usr 27 pushd rootfs/usr 28 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/lib . 29 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/include . 30 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/bin . 31 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/share . 32 sudo aarch64-linux-gnu-strip lib/python* 33 popd 34 35 version=2 36 pushd rootfs/usr 37 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/lib . 38 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/include . 39 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/bin . 40 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${version}/aarch64/share . 41 sudo aarch64-linux-gnu-strip lib/python* 42 popd 43 44 #sqlite 45 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/bin/* rootfs/bin/ 46 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/include/* rootfs/include/ 47 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/lib/* rootfs/lib/ 48 sudo strip rootfs/bin/sqlite3 49 50 #readline 51 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch64/include/* rootfs/include/ 52 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Readline/aarch64/lib/* rootfs/lib/ 53 54 sudo mkdir -p rootfs/dev/ 55 sudo mknod rootfs/dev/tty1 c 4 1 56 sudo mknod rootfs/dev/tty2 c 4 2 57 sudo mknod rootfs/dev/tty3 c 4 3 58 sudo mknod rootfs/dev/tty4 c 4 4 59 sudo mknod rootfs/dev/console c 5 1 60 sudo mknod rootfs/dev/null c 1 3 61 62 sudo rm rootfs/lib/*.a 63 sudo rm rootfs/lib/*.la 64 sudo aarch64-linux-gnu-strip rootfs/lib/* 65 66 sudo mkdir -p rootfs/lib/modules/4.10.0+ 67 68 pushd rootfs/lib 69 sudo ln -sf ld-2.19-2014.07.so ld-linux-aarch64.so.1 70 popd 71 72 sudo mkdir -p rootfs/tools 73 sudo cp ./other_tools/* rootfs/tools 74 75 sudo dd if=/dev/zero of=ramdisk bs=1M count=300 76 sudo mkfs.ext4 -F ramdisk 77 78 sudo mkdir -p tmpfs 79 sudo mount -t ext4 ramdisk ./tmpfs/ -o loop 80 sudo cp -raf rootfs/* tmpfs/ 81 sudo umount tmpfs 82 83 sudo gzip --best -c ramdisk > ramdisk.gz 84 sudo mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img
6、验证
经测试,在板子板子上面使用python3或者python2的时候,按键盘的方向键不会乱码。
完。
修改Modules/Setup