穿插编译Python-3.6.0到aarch64/aarch32 —— 支持sqlite3

参考

Cross-compiling Python 3.3.1 for Beaglebone (arm-angstrom)

 

平台

主机: ubuntu14.04
64bit

开发板: qemu +
aarch64
(参考: http://www.cnblogs.com/pengdonglin137/p/6442583.html)

工具链: 

    aarch64-linux-gnu-gcc  (gcc version 4.9.1 20140529)
 用于编译aarch64上面运行的次

    arm-none-linux-gnueabi-gcc  (gcc version
4.8.3 20140320) 用于编译aarch32上面运行的主次

Python版本: Python-3.6.0

 

概述

前方几篇博文介绍了Python2.7.13底接力编译,在编译前待给Python源码打上用来交叉编译的patch,从Python-3.3.1开始,就非需再行打什么patch了,只需要以configure的早晚指定–build和–host参数即可。

脚我们以aarch64和aarch32为例说明。

 

正文

一致、编译PC上面用之Python

因为在陆续编译的时段要以PC上面运行对应版本的Python程序,所以我们得事先编译和设置PC上面用之Python,下面是令:

1 #!/bin/bash
2 
3 ../Python-3.6.0/configure
4 
5 make -j8
6 sudo make install 

默认,Python3.6.0会晤给设置到/usr/local下面。

次、交叉编译

1、配置 mk1_conf.sh

  • aarch32

    1 #!/bin/bash
    2
    3 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH
    4
    5 ../Python-3.6.0/configure \
    6 –host=arm-none-linux-gnueabi \
    7 –build=armv7 \
    8 –prefix=pwd \
    9 –enable-ipv6 \
    10 –enable-shared \
    11 ac_cv_filedev_ptmx=”yes” \
    12 ac_cv_file
    dev_ptc=”no” \
    13 LDFLAGS=”-L/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/lib” \
    14 CPPFLAGS=”-I/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/include”

内–build表示编译出来的程序运行的CPU架构,–host是陆续编译工具链。这里我一度吧sqlite3的lib和include添加上了,所以生成的python3凡支撑sqlite3之。

  • aarch64

    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_filedev_ptmx=”yes” \
    12 ac_cv_file
    dev_ptc=”no” \
    13 LDFLAGS=”-L/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/lib” \
    14 CPPFLAGS=”-I/home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/include”

单独待替换运行的CPU架构为aarch64,然后设置相应的工具链即可,别忘了还有sqlite3的相关路线的修改。

2、编译和设置 mk2_make.sh

此地没呀好说的,下面是本子内容:

  • aarch32

    1 #!/bin/bash
    2
    3 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH
    4
    5 make -j4
    6 make install

  • aarch64

    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、制作ramdisk

为便利在python2和python3次的切换,适当修改mk_ramdisk.sh如下:

  • aarch32

    1 #!/bin/bash
    2
    3 sudo rm -rf rootfs
    4 sudo rm -rf tmpfs
    5 sudo rm -rf ramdisk
    6
    7 sudo mkdir rootfs
    8 sudo cp ../busybox-1.24.2/_install/
    rootfs/ -raf
    9
    10 sudo mkdir -p rootfs/proc/
    11 sudo mkdir -p rootfs/sys/
    12 sudo mkdir -p rootfs/tmp/
    13 sudo mkdir -p rootfs/root/
    14 sudo mkdir -p rootfs/var/
    15 sudo mkdir -p rootfs/mnt/
    16
    17 sudo cp etc rootfs/ -arf
    18
    19 sudo cp -arf ../arm-2014.05/arm-none-linux-gnueabi/libc/lib rootfs/
    20
    21 ver=3
    22 sudo mkdir -p rootfs/usr
    23 pushd rootfs/usr
    24 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${ver}/aarch32/lib .
    25 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${ver}/aarch32/include .
    26 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${ver}/aarch32/bin .
    27 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/Python${ver}/aarch32/share .
    28 sudo /home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-strip lib/python
    29 popd
    30
    31 #sqlite
    32 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/bin/
    rootfs/bin/
    33 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/include/ rootfs/include/
    34 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch32/lib/
    rootfs/lib/
    35 sudo strip rootfs/bin/sqlite3
    36
    37 sudo mkdir -p rootfs/dev/
    38 sudo mknod rootfs/dev/tty1 c 4 1
    39 sudo mknod rootfs/dev/tty2 c 4 2
    40 sudo mknod rootfs/dev/tty3 c 4 3
    41 sudo mknod rootfs/dev/tty4 c 4 4
    42 sudo mknod rootfs/dev/console c 5 1
    43 sudo mknod rootfs/dev/null c 1 3
    44
    45 sudo rm -rf rootfs/lib/.a
    46 sudo rm -rf rootfs/lib/
    .la
    47 sudo /home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-strip rootfs/lib/
    48
    49 sudo mkdir -p rootfs/tools
    50 sudo cp ./other_tools/
    rootfs/tools
    51
    52 sudo mkdir -p rootfs/lib/modules/4.10.0+
    53
    54 sudo dd if=/dev/zero of=ramdisk bs=1M count=150
    55 sudo mkfs.ext4 -F ramdisk
    56
    57 sudo mkdir -p tmpfs
    58 sudo mount -t ext4 ramdisk ./tmpfs/ -o loop
    59 sudo cp -raf rootfs/* tmpfs/
    60 sudo umount tmpfs
    61
    62 sudo gzip –best -c ramdisk > ramdisk.gz
    63 sudo mkimage -n “ramdisk” -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img

假定提示空间不足的言辞,可以将dd命令的count参数扩大,同时不要忘记了以kernel配置里之ramdisk的大小也扩大:

1 Device Drivers  --->
2 
3     [*] Block devices  --->
4 
5         (153600) Default RAM disk size (kbytes)

这里将ramdisk的大大小小修改以150MB,然后还编译kernel

  • aarch64

    1 #!/bin/bash
    2
    3 sudo rm -rf rootfs
    4 sudo rm -rf tmpfs
    5 sudo rm -rf ramdisk
    6
    7 sudo mkdir rootfs
    8 sudo cp ../busybox-1.24.2/_install/
    rootfs/ -raf
    9
    10 sudo mkdir -p rootfs/proc/
    11 sudo mkdir -p rootfs/sys/
    12 sudo mkdir -p rootfs/tmp/
    13 sudo mkdir -p rootfs/root/
    14 sudo mkdir -p rootfs/var/
    15 sudo mkdir -p rootfs/mnt/
    16
    17 sudo cp etc rootfs/ -arf
    18 sudo mkdir -p rootfs/lib
    19
    20 sudo cp -arf ../gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/aarch64-linux-gnu/libc/lib/aarch64-linux-gnu/ rootfs/lib/
    21
    22 sudo rm rootfs/lib/
    .a
    23 sudo ../gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin/aarch64-linux-gnu-strip rootfs/lib/
    24
    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 /home/pengdonglin/src/qemu/aarch64/gcc-linaro-aarch64-linux-gnu-4.9-2014.07_linux/bin/aarch64-linux-gnu-strip lib/python

    33 popd
    34
    35 #sqlite
    36 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/bin/ rootfs/bin/
    37 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/include/
    rootfs/include/
    38 sudo cp -raf /home/pengdonglin/src/qemu/python_cross_compile/SQlite/aarch64/lib/ rootfs/lib/
    39 sudo strip rootfs/bin/sqlite3
    40
    41 sudo mkdir -p rootfs/dev/
    42 sudo mknod rootfs/dev/tty1 c 4 1
    43 sudo mknod rootfs/dev/tty2 c 4 2
    44 sudo mknod rootfs/dev/tty3 c 4 3
    45 sudo mknod rootfs/dev/tty4 c 4 4
    46 sudo mknod rootfs/dev/console c 5 1
    47 sudo mknod rootfs/dev/null c 1 3
    48
    49 sudo mkdir -p rootfs/lib/modules/4.10.0+
    50
    51 pushd rootfs/lib
    52 sudo ln -sf ld-2.19-2014.07.so ld-linux-aarch64.so.1
    53 popd
    54
    55 sudo mkdir -p rootfs/tools
    56 sudo cp ./other_tools/
    rootfs/tools
    57
    58 sudo dd if=/dev/zero of=ramdisk bs=1M count=200
    59 sudo mkfs.ext4 -F ramdisk
    60
    61 sudo mkdir -p tmpfs
    62 sudo mount -t ext4 ramdisk ./tmpfs/ -o loop
    63 sudo cp -raf rootfs/* tmpfs/
    64 sudo umount tmpfs
    65
    66 sudo gzip –best -c ramdisk > ramdisk.gz
    67 sudo mkimage -n “ramdisk” -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img

此间用ramdisk的深浅设置以200MB,同时修改kernel配置:

1 Device Drivers  --->
2     
3     [*] Block devices  --->
4         
5         (204800) Default RAM disk size (kbytes)

然后重新编译kernel。

4、测试

每当板子起来后,运行:

 python3 /usr/lib/python3.6/test/test___all__.py 

  • aarch32

    1 [root@vexpress ]# python3 /usr/lib/python3.6/test/test_all.py
    2 phello.foo
    3 _bootlocale
    4 _collections_abc
    5 _compat_pickle
    6 _compression
    7 _dummy_thread
    8 … …
    9 .
    10 ———————————————————————-
    11 Ran 1 test in 15.731s
    12 OK

  • aarch64

    1 [root@aarch64 ]# python3 /usr/lib/python3.6/test/test_all.py
    2 [ 20.347974] random: python3: uninitialized urandom read (24 bytes read)
    3 [ 21.049645] random: fast init done
    4 phello.foo
    5 _bootlocale
    6 _collections_abc
    7 _compat_pickle
    8 _compression
    9 _dummy_thread
    10 _markupbase
    11 … …
    12 .
    13 ———————————————————————-
    14 Ran 1 test in 10.745s
    15 OK

 

网站地图xml地图