# BPI-M3 BSP Cross Compile teach

thank 陳鈞 share it.we just transfer to english.

![](https://3925975408-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2HWtRJQoosYe3-dUmx%2F-M2HWuG855qPFbpCRkE5%2F-M2HXI-rPA66aHKZL_Kr%2Fchen.jpg?generation=1584080181032419\&alt=media)

BLOG：<http://blog.jim60105.com/2016/03/bananapi-m3-cross-compile.html>

use system message:

```
jim@jim-Ubuntu:~$ uname -a
Linux jim-Ubuntu 4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
```

**1 Compile BPI-M3 BSP**

create a dir for BPI-M3 and get source code from gitgub

```
mkdir bananapi
cd bananapi
git clone https://github.com/BPI-SINOVOIP/BPI-M3-bsp.git
```

```
cd BPI-M3-bsp
mkdir -p linux-sunxi/output/lib/firmware
```

**2, run this segment if you use 64 bits platform**

the official kit was compiled on 32 bit platform ,so you must support 32bit execution in your 64 bits ubuntu.

```
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386
```

**3,install necessary tools:(skip this if you have executed the two instructions in the segment of the 64 bits)**

```
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential u-boot-tools binutils-arm-linux-gnueabihf gcc-4.7-arm-linux-gnueabihf-base g++-4.7-arm-linux-gnueabihf gcc-arm-linux-gnueabihf gcc-arm-linux-gnueabi cpp-arm-linux-gnueabihf libusb-1.0-0 libusb-1.0-0-dev git wget fakeroot kernel-package zlib1g-dev libncurses5-dev
```

**4,begin to Compile**

for me, i need use LCD on BPI-M3, so i choose is:3

```
./build.sh
```

now choose menu:

```
            BPI-M3 BSP Build Tool         
==========================================

This tool support following BPI board(s):
------------------------------------------
 1. BPI_M3_720P
 2. BPI_M3_1080P
 3. BPI_M3_LCD7
 4. BPI_M3_USB_720P
 5. BPI_M3_USB_1080P
 6. BPI_M3_USB_LCD7
------------------------------------------
Please choose a target(1-6): 3


 Now configuring...

BPI_M3_LCD7 configured. Now run `make`

 Configure success!
```

please waitting , it need long time to compile,it takes a while and depends on the performance of your computer

![](https://github.com/bananapi/bpi-m3/tree/70738568d16e91df00cd94c296f2a515a69b8ce3/zh/complie%20m3%20bps.png)

Note: if compile success ,will have ../bananapi/BPI-M3-BSP dir.if it does not show up, any other "build success" screen are deceptive.

**5 burn image to SD card:**

take a new SD card , and install official image to SD card.

official image : <http://www.banana-pi.org/download.html>

the next step, be sure to choose the correct device.

```
sudo fdisk -l
```

![](https://3925975408-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2HWtRJQoosYe3-dUmx%2F-M2HWuG855qPFbpCRkE5%2F-M2HXI-tc-nc2t_Y-JaH%2F11.png?generation=1584080181363113\&alt=media)

```
 umount /dev/sdf*
```

clean

```
sudo fdisk /dev/sdf
p 
d
w
sync
```

please use "d" clean partition.And then dropped the device completely clear

`dd if=/dev/zero of=/dev/sdf bs=4M`

buru official image to SD card .please do not Android and Berryboot image.

example: ArchLinux

image name: 015-12-09-ArchLinuxARM-lite-bpi-m3-sd-emmc.img.zip

```
unzip 2015-12-09-ArchLinuxARM-lite-bpi-m3-sd-emmc.img.zip -d ~
cd ~
sudo dd if=2015-12-09-ArchLinuxARM-lite-bpi-m3-sd-emmc.img of=/dev/sdf bs=4M
```

waiting still dd finish.

```
umount /dev/sdf*
```

check partition

```
sudo fsck /dev/sdf1
sudo fsck /dev/sdf2
```

change /dev/sdf2 to ext2，and change size

```
sudo tune2fs -O ^has_journal /dev/sdf2
sudo e2fsck -f /dev/sdf2
```

Write the first compiled data: next step will clean partition table, so we must transcribe it at first

![](https://3925975408-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2HWtRJQoosYe3-dUmx%2F-M2HWuG855qPFbpCRkE5%2F-M2HXI-vYTd2TBpBYEo0%2F12.png?generation=1584080185418731\&alt=media)

go to we just compiled things stored folder

```
cd ~/bananapi/BPI-M3-bsp/download/BPI_M3_LCD7
```

all file will such as this below:

![](https://3925975408-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2HWtRJQoosYe3-dUmx%2F-M2HWuG855qPFbpCRkE5%2F-M2HXI-x2MenlftBymmM%2F13.png?generation=1584080183709838\&alt=media)

Empty memory card 1m before space (and clears the partition table)

```
sudo dd if=/dev/zero of=/dev/sdf bs=1M count=1
```

in order to write compiled file

```
sudo dd if=boot0_sdcard.fex of=/dev/sdf bs=1k seek=8
sudo dd if=u-boot.fex of=/dev/sdf bs=1k seek=19096
sudo dd if=sunxi_mbr.fex of=/dev/sdf bs=1k seek=20480
sudo dd if=boot-resource.fex of=/dev/sdf bs=1k seek=36864
sudo dd if=env.fex of=/dev/sdf bs=1k seek=69632
sudo dd if=boot.fex of=/dev/sdf bs=1k seek=86016
```

recovery partition table,and increase the capacity to the memory card is the largest,also change to /dev/sdf2.

```
sudo fdisk /dev/sdf
p
n
p
1
204800
729087
t
c
n
p
2
729088
# here just "enter"，default will get max size 
w
sync
sudo fsck /dev/sdf1
sudo fsck /dev/sdf2
sudo resize2fs /dev/sdf2
sudo tune2fs -j /dev/sdf2
sudo e2fsck -f /dev/sdf2
```

all is finish. just use this SD card to boot your banana pi.
