Cross-compile Python-2.7.13 to ARM (aarch32) platform

Publisher:人妙果华Latest update time:2020-02-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

environment

Host: ubuntu14.04 64bit


Development board: qemu + vexpress-a9 (reference: http://www.cnblogs.com/pengdonglin137/p/6442583.html)


Toolchain: arm-none-linux-gnueabi-gcc (gcc version 4.8.3 20140320)


Python version: Python-2.7.13


Go to top

reference

http://www.41443.com/HTML/Python/20151105/414154.html


http://www.cnblogs.com/tolimit/p/4519838.html?utm_source=tuicool&utm_medium=referral


Go to top

text

1. Download and decompress the Python source code

Go to https://www.python.org/downloads/ to download the latest python2 series software. Here I use Python-2.7.13


1 # Unzip

2 tar -xf Python-2.7.13.tar.xz

4 #Create python2_7_13_for_x86_64

5 mkdir python2_7_13_for_x86_64

7 #Create python2_7_13_for_arm

8 mkdir python2_7_13_for_arm


2. Compile the x86_64 version of Python software

I wrote the compilation process into a script, enter the python2_7_13_for_x86_64/ directory, and then execute the following script:


Configure mk1_conf.sh


1 #!/bin/bash

3 ../Python-2.7.13/configure --prefix=`pwd`

Compile mk2_make.sh


1 #!/bin/bash

3 make -j4

Install mk3_install.sh


1 #!/bin/bash

3 make install

3. Cross-compilation

The first step of cross-compilation is to apply the cross-compilation patch to the Python source code: Python-2.7.13-compile.patch.tar.gz


1 cd Python-2.7.13/

2 patch -p1 < ../python2_7_13_for_arm/Python-2.7.13-xcompile.patch

I also put the compilation process into the script, which is also divided into three parts:


Configure mk1_conf.sh


1 #!/bin/bash

2 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH

3 ../Python-2.7.13/configure --prefix=`pwd`

4     --host=arm-none-linux-gnueabi

5     --build=x86_64-linux-gnu

6     --enable-ipv6

7     --enable-shared

8     ac_cv_file__dev_ptmx="yes"

9     ac_cv_file__dev_ptc="no"


Compile mk2_make.sh


 1 #!/bin/bash

 2 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH

 3 make HOSTPYTHON=../python2_7_13_for_x86_64/python

 4     HOSTPGEN=../python2_7_13_for_x86_64/Parser/pgen

 5     BLDSHARED="arm-none-linux-gnueabi-gcc -shared"

 6     CROSS_COMPILE=arm-none-linux-gnueabi-

 7     CROSS_COMPILE_TARGET=yes

 8     HOSTARCH=arm-none-linux-gnueabi

 9     BUILDARCH=x86_64-linux-gnu

10     -j4


Install mk3_install.sh


1 #!/bin/bash

2 export PATH=/home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin:$PATH

3 make install HOSTPYTHON=../python2_7_13_for_x86_64/python

4     BLDSHARED="arm-none-linux-gnueabi-gcc -shared"

5     CROSS_COMPILE=arm-none-linux-gnueabi-

6     CROSS_COMPILE_TARGET=yes

7     prefix=`pwd`

4. Recreate the ramdisk image

Reference blog post: Using Qemu to build aarch32 learning environment


Modify mk_ramdisk.sh as follows:


 1 #!/bin/bash

 2 sudo rm -rf rootfs

 3 sudo rm -rf tmpfs

 4 sudo rm -rf ramdisk*

 5 sudo mkdir rootfs

 6 sudo cp ../busybox-1.24.2/_install/*  rootfs/ -raf

 7 sudo mkdir -p rootfs/proc/

 8 sudo mkdir -p rootfs/sys/

 9 sudo mkdir -p rootfs/tmp/

10 sudo mkdir -p rootfs/root/

11 sudo mkdir -p rootfs/var/

12 sudo mkdir -p rootfs/mnt/

13 sudo cp etc rootfs/ -arf

14 sudo cp -arf ../arm-2014.05/arm-none-linux-gnueabi/libc/lib rootfs/

15 sudo rm -rf rootfs/lib/*.a

16 sudo /home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-strip rootfs/lib/*

17 # Copy Python related files to the root file system

18 sudo mkdir -p rootfs/usr

19 pushd rootfs/usr

20 sudo cp  -raf /home/pengdonglin/src/qemu/python_cross_compile/python2_7_13_for_arm/lib .

21 sudo cp  -raf /home/pengdonglin/src/qemu/python_cross_compile/python2_7_13_for_arm/include .

22 sudo cp  -raf /home/pengdonglin/src/qemu/python_cross_compile/python2_7_13_for_arm/bin .

23 sudo cp  -raf /home/pengdonglin/src/qemu/python_cross_compile/python2_7_13_for_arm/share .

24 sudo /home/pengdonglin/src/qemu/aarch32/arm-2014.05/bin/arm-none-linux-gnueabi-strip lib/python*

25 popd

26 sudo mkdir -p rootfs/dev/

27 sudo mknod rootfs/dev/tty1 c 4 1

28 sudo mknod rootfs/dev/tty2 c 4 2

29 sudo mknod rootfs/dev/tty3 c 4 3

30 sudo mknod rootfs/dev/tty4 c 4 4

31 sudo mknod rootfs/dev/console c 5 1

32 sudo mknod rootfs/dev/null c 1 3

33 sudo mkdir -p rootfs/lib/modules/4.10.0+

34 sudo mkdir -p rootfs/tools

35 sudo cp ./other_tools/* rootfs/tools

36 # Expand the size of ramdisk to 100MB

37 sudo dd if=/dev/zero of=ramdisk bs=1M count=100

38 sudo mkfs.ext4 -F ramdisk

39 sudo mkdir -p tmpfs

40 sudo mount -t ext4 ramdisk ./tmpfs/  -o loop

41 sudo cp -raf rootfs/*  tmpfs/

42 sudo umount tmpfs

43 sudo gzip --best -c ramdisk > ramdisk.gz

44 sudo mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img


Things to note here:


1. Copy the files obtained by cross-compiling Python to rootfs/usr: bin, lib, include and share


2. Since Python's lib directory takes up a lot of space, about 70MB, we set the size of ramdisk to 100MB here.


3. In addition, when running qemu-system-arm, you can set a larger physical memory for -m. Here I set it to 1GB


5. Modify kernel configuration

Modify the size of the ramdisk. Here I set it to 100MB:


1 Device Drivers  ---> 

3         [*] Block devices  --->

5                 (102400) Default RAM disk size (kbytes) 

6. Testing

After making the ramdisk and compiling the new kernel, run the system:


 1 sudo qemu-system-arm

 2 -M vexpress-a9

 3     -m 1024M

 4 - junior high school 2

 5     -kernel ./linux-4.10/out_aarch32/arch/arm/boot/zImage

 6     -nographic

 7     -append "root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel"

 8     -initrd ./rootfs/ramdisk.img

 9     -net nic,vlan=0 -net tap,vlan=0,ifname=tap0

10 -dtb ./linux-4.10/out_aarch32/arch/arm/boot/dts/vexpress-v2p-ca9.dtb


Here is the startup log:


  1 $./run.sh 

  2 sudo tunctl -u root -t tap0

  3 TUNSETIFF: Device or resource busy

  4 sudo ifconfig tap0 0.0.0.0 promisc up

  5 sudo brctl addif br0 tap0

  6 brctl show

  7 bridge name    bridge id        STP enabled    interfaces

  8 br0        8000.480fcf3ace87    no        eth0

  9                             tap0

 10 docker0        8000.02423772cc85    no        

 11 [    0.000000] Booting Linux on physical CPU 0x0

 12 [    0.000000] Linux version 4.10.0+ (pengdonglin@pengdonglin-HP) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29) ) #10 SMP Mon Mar 20 11:31:00 CST 2017

 13 [    0.000000] CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d

 14 [    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache

 15 [    0.000000] OF: fdt:Machine model: V2P-CA9

 16 [    0.000000] debug: ignoring loglevel setting.

 17 [    0.000000] Memory policy: Data cache writealloc

 18 [    0.000000] On node 0 totalpages: 262144

 19 [    0.000000] free_area_init_node: node 0, pgdat c0a637c0, node_mem_map ef7fa000

 20 [    0.000000]   Normal zone: 1536 pages used for memmap

 21 [    0.000000]   Normal zone: 0 pages reserved

 22 [    0.000000]   Normal zone: 196608 pages, LIFO batch:31

 23 [    0.000000]   HighMem zone: 65536 pages, LIFO batch:15

 24 [    0.000000] percpu: Embedded 14 pages/cpu @ef7b5000 s27648 r8192 d21504 u57344

 25 [    0.000000] pcpu-alloc: s27648 r8192 d21504 u57344 alloc=14*4096

 26 [    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 

 27 [    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 260608

 28 [    0.000000] Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=ttyAMA0 init=/linuxrc ignore_loglevel

 29 [    0.000000] log_buf_len individual max cpu contribution: 4096 bytes

 30 [    0.000000] log_buf_len total cpu_extra contributions: 12288 bytes

 31 [    0.000000] log_buf_len min size: 16384 bytes

 32 [    0.000000] log_buf_len: 32768 bytes

 33 [    0.000000] early log buf free: 14860(90%)

 34 [    0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)

 35 [    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)

 36 [    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)

 37 [    0.000000] Memory: 1007212K/1048576K available (6144K kernel code, 453K rwdata, 1440K rodata, 1024K init, 191K bss, 41364K reserved, 0K cma-reserved, 262144K highmem)

 38 [    0.000000] Virtual kernel memory layout:

 39 [    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)

 40 [    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)

 41 [    0.000000]     vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)

 42 [    0.000000]     lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)

 43 [    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)

 44 [    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)

 45 [    0.000000]       .text : 0xc0008000 - 0xc0700000   (7136 kB)

 46 [    0.000000]       .init : 0xc0900000 - 0xc0a00000   (1024 kB)

 47 [    0.000000]       .data : 0xc0a00000 - 0xc0a71784   ( 454 kB)

 48 [    0.000000]        .bss : 0xc0a73000 - 0xc0aa2c4c   ( 192 kB)

 49 [    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1

 50 [    0.000000] Hierarchical RCU implementation.

 51 [    0.000000]     Build-time adjustment of leaf fanout to 32.

 52 [    0.000000]     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.

 53 [    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=32, nr_cpu_ids=4

 54 [ 0.000000] NR_IRQS:16 nr_irqs:16 16

 55 [    0.000000] L2C: platform modifies aux control register: 0x02020000 -> 0x02420000

 56 [    0.000000] L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000

 57 [    0.000000] L2C-310 enabling early BRESP for Cortex-A9

 58 [    0.000000] L2C-310 full line of zeros enabled for Cortex-A9

 59 [    0.000000] L2C-310 dynamic clock gating disabled, standby mode disabled

 60 [    0.000000] L2C-310 cache controller enabled, 8 ways, 128 kB

 61 [    0.000000] L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001

 62 [    0.000000] smp_twd: clock not found -2

 63 [    0.000206] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns

 64 [    0.002899] clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns

 65 [    0.003447] Failed to initialize '/smb@04000000/motherboard/iofpga@7,00000000/timer@12000': -22

 66 [    0.006792] Console: colour dummy device 80x30

 67 [    0.007168] Calibrating local timer... 94.56MHz.

[1] [2] [3]
Reference address:Cross-compile Python-2.7.13 to ARM (aarch32) platform

Previous article:valgrind arm-linux cross-compilation
Next article:Run perf on TQ2440 to generate Flame Graph

Recommended ReadingLatest update time:2024-11-16 13:33

The relationship and actual situation between 8051, AVR and ARM
Today, a friend who is an enthusiast wanted me to release video tutorials on AVR and ARM. I said that you can record videos on ARM, but there is no need to talk about AVR. This friend was puzzled when I said that AVR is unnecessary. Yes, there are still many enthusiast friends who have doubts, which is caused by the a
[Microcontroller]
Arm Ethos-U makes NXP eIQ smarter
NXP Semiconductors recently announced that it will enhance its machine learning development environment and product portfolio. Through an investment, NXP has established an exclusive strategic partnership with Canadian Au-Zone Technologies to expand NXP's eIQ™ machine learning (ML) software development environment wit
[Internet of Things]
Arm Ethos-U makes NXP eIQ smarter
Summary of 7 major domestic and foreign autonomous driving simulation platforms
Before self-driving cars can be truly commercialized, they need to undergo a large number of road tests to meet commercial requirements. Using road tests to optimize self-driving algorithms consumes too much time and cost, and open road testing is still subject to regulatory restrictions. It is difficult to reproduc
[Automotive Electronics]
Summary of 7 major domestic and foreign autonomous driving simulation platforms
How to install Linux system on ARM development board
      Note: This section assumes that you have connected the serial port and USB port between the development board and the PC, and set the development board to boot from NOR  Flash  . After the system update and installation is complete, please set it to boot from Nand  Flash  .       The bootloader, kernel and file
[Microcontroller]
Design of intelligent water meter reading system based on ARM microcontroller
    Introduction to Water Meter Intelligent Reading System   At present, the power industry mechanisms of many countries are introducing competition mechanisms and establishing power market power system reforms, with the aim of more rationally allocating resources, improving resource utilization, and promoting the co
[Microcontroller]
Design of intelligent water meter reading system based on ARM microcontroller
ATmega128(DS1302)
//DS1302 real-time clock chip driver for ATmega128 //Compilation environment AVR Studio 4.17/AVR GCC //System clock 7.3728MHZ, set fuse bits to external high-frequency quartz crystal oscillator, startup time 4.1ms //Author: Zhang  Qizhangqi123zq@126.com //Date: 2010.02.20 //**************************************
[Microcontroller]
Panasonic Automotive Electronics Systems and Arm Join Forces to Promote Standardization of Software-Defined Vehicles
Panasonic Automotive Systems Co., Ltd. (PAS) and Arm recently announced a strategic collaboration to jointly promote the standardization of software-defined vehicle (SDV) architecture. Based on a common vision, the two parties are committed to co-creating a flexible software stack that can meet current and fut
[Automotive Electronics]
Pi Ziheng Embedded: ARM Cortex-M Files (8) - Image Files
  Today's class is the last class of Pi Ziheng's "ARM Cortex-M Files" series (I suddenly feel a little reluctant to say goodbye, ahem, let Pi Ziheng sort out his emotions first). Today Pi Ziheng mainly talks about the final output file of engineering development, that is, the image file. Image files are also called mi
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号