博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决Python交叉编译后,键盘方向键乱码的问题
阅读量:6254 次
发布时间:2019-06-22

本文共 8770 字,大约阅读时间需要 29 分钟。

参考

 

概述

前面几篇博文介绍了Python交叉编译到ARM开发板上面,在使用的时候遇到一个问题,就是当按下键盘上面的方向键的时候看到的都是乱码。

 

平台

主机: ubuntu14.04 64bit

开发板: qemu + aarch64 (参考: )

工具链: aarch64-linux-gnu-gcc  (gcc version 4.9.1 20140529)  用于编译aarch64上面运行的程序

Python版本:  和 

 

解决

1、下载readline和termcap的源码

  • readline的下载链接:

或者 

  • termcap的下载链接:

或者 

2、交叉编译

  • readline

解压:

1 tar -xf readline-7.0.tar.gz2 mkdir aarch643 cd aarch64

配置、编译和安装 mk.sh:

1 #!/bin/bash2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH4 5 ../readline-7.0/configure --host=aarch64-linux-gnu \6     --prefix=`pwd`7 8 make -j49 make install
  • termcap

termcap编译稍微麻烦一点,需要手动修改configure生成的Makefile文件。

解压:

1 tar -xf termcap-1.3.1.tar.gz2 mkdir aarch643 cd aarch64

配置 mk1_conf.sh:

1 #!/bin/bash2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH4 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 = ranlib10 +cross_compile = aarch64-linux-gnu-11 +12 +CC = ${cross_compile}gcc13 +AR = ${cross_compile}ar14 +RANLIB = ${cross_compile}ranlib15  16  INSTALL = /usr/bin/install -c17  INSTALL_DATA = ${INSTALL} -m 644

即需要手动将修改工具链。

编译安装 mk2_make.sh

1 #!/bin/bash2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH4 5 make -j46 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/bash2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH4 5 make -j46 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/bash2 3 export PATH=/home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin:$PATH4 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 rootfs10 sudo cp ../busybox-1.24.2/_install/*  rootfs/ -raf11 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/ -arf20 sudo mkdir -p rootfs/lib21 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 #python25 version=326 sudo mkdir -p rootfs/usr27 pushd rootfs/usr28 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 popd34 35 version=236 pushd rootfs/usr37 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 popd43 44 #sqlite45 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/sqlite349 50 #readline51 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 156 sudo mknod rootfs/dev/tty2 c 4 257 sudo mknod rootfs/dev/tty3 c 4 358 sudo mknod rootfs/dev/tty4 c 4 459 sudo mknod rootfs/dev/console c 5 160 sudo mknod rootfs/dev/null c 1 361 62 sudo rm rootfs/lib/*.a63 sudo rm rootfs/lib/*.la64 sudo aarch64-linux-gnu-strip rootfs/lib/*65 66 sudo mkdir -p rootfs/lib/modules/4\.10\.0\+67 68 pushd rootfs/lib69 sudo ln -sf ld-2.19-2014.07.so ld-linux-aarch64.so.170 popd71 72 sudo mkdir -p rootfs/tools73 sudo cp ./other_tools/* rootfs/tools74 75 sudo dd if=/dev/zero of=ramdisk bs=1M count=30076 sudo mkfs.ext4 -F ramdisk77 78 sudo mkdir -p tmpfs79 sudo mount -t ext4 ramdisk ./tmpfs/  -o loop80 sudo cp -raf rootfs/*  tmpfs/81 sudo umount tmpfs82 83 sudo gzip --best -c ramdisk > ramdisk.gz84 sudo mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img
这里我把Python3和Python2都拷贝到板子上面了, 同时别忘了拷贝readline和termcap的lib和include。如果提示空间不够的话,修改第75行的count的数值,这个要不能大于kernel里配置的值。

6、验证

经测试,在板子板子上面使用python3或者python2的时候,按键盘的方向键不会乱码。

 

完。

修改Modules/Setup

转载地址:http://pgjsa.baihongyu.com/

你可能感兴趣的文章
大数据和云计算是何关系?
查看>>
黑客使用含病毒的邮件 半年内盗取近20亿卢布
查看>>
俄罗斯阿尔法银行遭DNS攻击 黑客或栽赃其与特朗普团
查看>>
Silverlight+WCF 新手实例 象棋 该谁下棋-B下A停(三十)
查看>>
2017年底预标准5G网络支出将达到2.5亿美元
查看>>
2017到2021全球通信提供商CAPEX超2.1万亿美元
查看>>
CYQ.Data 轻量数据层之路 使用篇-辅助工具枚举生成器 视频 C (二十)
查看>>
网络安全为人民 联防联治补短板
查看>>
苹果携手 SAP 开发的 iOS 云平台 SDK 正式上线
查看>>
灿芯半导体落户合肥 打造集成电路产业园
查看>>
“智慧交通”可为“智慧城市”打头阵
查看>>
电子政务安全不容乐观,专家建议部分政府网站运营可尝试外包
查看>>
PCI-e介面的SSD火了,PC OEM厂商为啥这么青睐?
查看>>
卡塔尔半岛电视台称遭黑客全面攻击 未透露攻击来源
查看>>
2017年,美国科技巨头们面临那些“当头一棒”
查看>>
D1net阅闻:中国广电:两期互联互通工程 计划投千亿
查看>>
品高公开课 | 基于Docker容器的微服务架构实践
查看>>
公交WiFi再燃烧钱大战
查看>>
EMC联邦公布最新超融合型设备
查看>>
web测试20种界测试思路
查看>>