NanoPi M2

From FriendlyELEC WiKi
Revision as of 08:30, 1 March 2016 by Yftan (Talk | contribs) (编译Android)

Jump to: navigation, search

查看中文

1 Introduction

Overview
Front
Back
  • The NanoPi M2 is a high performance ARM Board after the NanoPi 2 and NanoPi 2 Fire, developed by FriendlyARM for hobbysts, makers and hackers for IOT projects. It integrates Gbit Ethernet port, AXP228 power management unit and supports Android5.1 and Debian.
  • Its new style of design makes it smaller than the NanoPi 2 Fire but still keeps all the rich interfaces and ports the NanoPi 2 Fire has. Besides the standard HDMI, USB, audio and Gbit Ethernet it has a Raspberry Pi compatible 40 pin header and supports various video devices including I2C capacitive LCD and CMOS cameras. In addition it has a serial debug port
  • Its support for Debian and Android makes it easily applied in various applications. Hardware wise it works with all the existing accessories, LCDs and sensor modules FriendlyARM has developed. Software wise it works with all the existing image files that the NanoPi 2 and NanoPi 2 Fire work with.

2 Features

  • CPU: S5P4418, 400Mhz~1.4GHz
  • PMU Power Management Unit: AXP228, support software power-off, sleep and wakeup functions
  • DDR3 RAM: 32bit 1GB DDR3
  • MicroSD Slot x1
  • Connectivity: Gbps Ethernet port(RTL8211E)
  • Audio: 3.5mm audio jack/Via HDMI
  • Microphone: 1 x onboard Microphone
  • USB Host: 4 x USB 2.0 Host, two are standard type A ports and the other two are 2.54mm pitch pin headers
  • Micro USB: 1 x USB 2.0 Client
  • LCD Interface: 0.5 mm pitch SMT FPC seat, for full-color LCD (RGB: 8-8-8)
  • HDMI: HDMI 1.4A, Type-A, 1080P60
  • DVP Camera Interface: 0.5mm pitch FPC socket. It includes ITU-R BT 601/656 8-bit, I2C and IO
  • GPIO1: 2.54mm pitch 40pin, compatible with Raspberry Pi's GPIO. It includes UART, SPI, I2C, PWM, IO etc
  • Debug Serial Port: 4Pin 2.54mm pitch pin header
  • User Key: 1 x Power , 1 x Reset
  • LED: 1 x Power LED, 1 x System LED
  • RTC: RTC Pins
  • Power: DC 5V/2A
  • PCB Dimension(mm): 64 x 56, Six Layer
  • OS/Software: u-boot, Android5.1, Debian Jessie 8

3 Diagram, Layout and Dimension

3.1 Layout

NanoPi M2 Interfaces and Ports
NanoPi M201 Interfaces and Ports
  • GPIO1 Pin Spec
Pin# Name Pin# Name
1 SYS_3.3V 2 VDD_5V
3 I2C0_SDA 4 VDD_5V
5 I2C0_SCL 6 DGND
7 GPIOD8/PPM 8 UART3_TXD/GPIOD21
9 DGND 10 UART3_RXD/GPIOD17
11 UART4_TX/GPIOB29 12 GPIOD1/PWM0
13 GPIOB30 14 DGND
15 GPIOB31 16 GPIOC14/PWM2
17 SYS_3.3V 18 GPIOB27
19 SPI0_MOSI/GPIOC31 20 DGND
21 SPI0_MISO/GPIOD0 22 UART4_RX/GPIOB28
23 SPI0_CLK/GPIOC29 24 SPI0_CS/GPIOC30
25 DGND 26 GPIOB26
27 I2C1_SDA 28 I2C1_SCL
29 GPIOC8 30 DGND
31 GPIOC7 32 GPIOC28
33 GPIOC13/PWM1 34 DGND
35 SPI2_MISO/GPIOC11 36 SPI2_CS/GPIOC10
37 AliveGPIO3 38 SPI2_MOSI/GPIOC12
39 DGND 40 SPI2_CLK/GPIOC9

This GPIO pin spec is a little bit different from that of the NanoPi 2. Here is a comparison table of the two:40 pins GPIO comparison table

  • Debug Port(UART0)
Pin# Name
1 DGND
2 VDD_5V
3 UART_TXD0
4 UART_RXD0
  • DVP Camera IF Pin Spec
Pin# Name
1, 2 SYS_3.3V
7,9,13,15,24 DGND
3 I2C0_SCL
4 I2C0_SDA
5 GPIOB14
6 GPIOB16
8,10 NC
11 VSYNC
12 HREF
14 PCLK
16-23 Data bit7-0
  • RGB LCD IF Pin Spec
Pin# Name Description
1, 2 VDD_5V 5V Output, it can be used to power LCD modules
11,20,29, 37,38,39,40, 45 DGND Gound
3-10 Blue LSB to MSB RGB blue
12-19 Green LSB to MSB RGB green
21-28 Red LSB to MSB RGB red
30 GPIOB25 available for users
31 GPIOC15 occupied by FriendlyARM one wire technology to recognize LCD models and control backlight and implement resistive touch, not applicable for users
32 XnRSTOUT Form CPU low when system is reset
33 VDEN signal the external LCD that data is valid on the data bus
34 VSYNC vertical synchronization
35 HSYNC horizontal synchronization
36 LCDCLK LCD clock, Pixel frequency
41 I2C2_SCL I2C2 clock signal, for capacitive touch's data transmission
42 I2C2_SDA I2C2 data signal, for capacitive touch's data transmission
43 GPIOC16 interrupt pin for capacitive touch, used with I2C2
44 NC not connected
Note
  1. SYS_3.3V: 3.3V power output
  2. VVDD_5V: 5V power input/output. When the external device’s power is greater than the MicroUSB’s the external device is charging the board otherwise the board powers the external device. The input range is 4.7V ~ 5.6V
  3. All pins are 3.3V
  4. GPIO1's pin spec is a little bit different from that of the NanoPi 2. Please refer to this comparison table 40 pins GPIO comparison table
  5. For more details please refer to the document: NanoPi-M2-1602-Schematic.pdf

3.2 Board Dimension

NanoPi M2 Dimensions

For more details please refer to the document: NanoPi-M2-1602-Dimensions(dxf).zip

4 Get Started

4.1 Essentials You Need

Before play with your NanoPi M2 please get the following items ready

  • NanoPi M2
  • microSD Card/TFCard: Class 10 or Above, minimum 8GB SDHC
  • microUSB power. A 5V/2A power is a must
  • HDMI monitor or LCD
  • USB keyboard and mouse
  • A Host running Ubuntu 14.04 64 bit system

4.2 TF Cards We Tested

To make your NanoPi 2 Fire boot and run fast we highly recommand you use a Class10 8GB SDHC TF card or a better one. The following cards are what we used in all our test cases presented here:

  • SanDisk TF 8G Class10 Micro/SD TF card:

SanDisk MicroSD 8G

  • SanDisk TF128G MicroSDXC TF 128G Class10 48MB/S:

SanDisk MicroSD 128G

  • 川宇 8G C10 High Speed class10 micro SD card:

chuanyu MicroSD 8G

4.3 Make an Installation MicroSD Card

4.3.1 Under Windows

Please get the following files from here:[http://wiki.friendlyarm.com/wiki/nanopi2/download/ to download image files.

For LCD or HDMI output please use the following files:
nanopi2-debian-sd4g.img.zip Debian image files
nanopi2-android-sd4g.img.zip Android image files
Flash Utility:
win32diskimager.rar Windows utility. Under Linux users can use "dd"
  • Please uncompress these files. Insert an SD card(at least 4G) to a Windows PC, run the win32diskimager utility as administrator,On the utility's main window select your SD card's drive and the image files and click on "write" to start flashing the SD card.
  • Please insert this card to your NanoPi M2 and power on (with a 5V/2A power source). If the blue LED and green LED are blinking this indicates your NanoPi M2 is successfully booted.

4.3.2 Under Linux Desktop

  • 1) Insert your microSD card to your host running Ubuntu and check your SD card's device name
dmesg | tail

Search the messages output by "dmesg" for similar words like "sdc: sdc1 sdc2". If you can find them it means your SD card is recognized as "/dev/sdc". Or you can check that by commanding "cat /proc/partitions"

  • 2) Download Flashing Script
git clone https://github.com/friendlyarm/sd-fuse_nanopi2.git
cd sd-fuse_nanopi2
  • 3) Flash Android Firmware to MicroSD Card
su
./fusing.sh /dev/sdx

(Note: you need to replace "/dev/sdx" with the device name in your system)
When you do “git clone” you have to hit “Y” within 10 seconds after it prompts you to download image files otherwise you will miss the download.

  • 4) Flash Debian Firmware to MicroSD Card
./fusing.sh /dev/sdx debian

4.3.3 LCD/HDMI Resolution

When system boots our uboot will check whether it is connected to an LCD. If it recognizes an LCD it will configure its resolution. By default our uboot configures the display to HDMI 720P.
If you want to reset the LCD resolution you can modify file "arch/arm/plat-s5p4418/nanopi2/lcds.c" in the kernel and recompile it.
If your NanoPi 2 connects an HDMI monitor and it runs Android it will automatically set the resolution to an appropriate HDMI mode by checking "EDID". If your NanoPi 2 connects an HDMI monitor and it runs Debian by default it will set the resolution to HDMI 720P and in this case you can set it to 1080P by modifying your kernel's configuration.

4.4 Update Image Files in MicroSD Card From PC Host

If you want to make some changes to the image files in your MicroSD card please follow steps below otherwise you can skip this section.
Please insert your MicroSD card to a PC host running LINUX, mount the boot and rootfs sections of the SD card and follow the steps below:
1) If you want to change your kernel command line parameters you can do it via the fw_setevn utility under "sd-fuse_nanopi2/tools".
Check the current Command Line:

cd sd-fuse_nanopi2/tools
./fw_printenv /dev/sdc | grep bootargs

Android 5.1.1_r6 starts SELinux. By default it is enforcing. You can change it this way:

./fw_setenv /dev/sdc bootargs XXX androidboot.selinux=permissive

This sets it to "permissive". The "XXX" stands for the original bootargs' value.

2) Update Kernel
Our customized uboot will check the LCD type when it boots.For a non-Android OS If it recognizes an LCD connected to the NanoPi 2 Fire it will load "uImage" from "boot" otherwise it will load "uImage.hdmi".
However for Android these two files don't make any differences for whatever display device it detects. You can use your generated uImage to replace the existing one under "boot".
For Debian if your generated kernel is for LCD you need to replace the existing uImage or if your kernel is for HDMI you need to replace the existing uImage.hdmi.

4.5 Run Android or Debian

  • Insert a MicroSD card with Android/Debian image files to your NanoPi 2 Fire, connect the NanoPi M2 to an HDMI monitor and a 5V/2A power source the NanoPi M2 will be automatically powered on. If you can see the blue LED flashing it means your board is working and you will see Android/Debain loading on the HDMI monitor.

1)If you connect the NanoPi M2 to an HDMI monitor you need to use a USB mouse and a USB keyboard to operate. If you connect it to an LCD with capacitive touch you can operate directly on the LCD.
2)If you want to do kernel development you'd better have a serial board which allows you to operate the board via a serial terminal.

  • Here is a case in which we connect a NanoPi M2 to a PC running Ubuntu and Minicom via a serial cable you will see system messages output to the PC’s minicom terminal:

PSU-ONECOM-M2

  • Under Debian the password for "root" is "fa".

4.6 Login Debian via VNC or SSH

If your NanoPi M2 is not connected to a display device you can download and install a "VNC Viewer" on your PC or mobile phone and login the NanoPi M2 via VNC. Its default password is "fa123456".
Here is a screenshot which shows how it looks like when users login the NanoPi M2 from an iPhone via VNC:
VNC to NanoPi2
You can login via "SSH -l root 192.168.8.1" too and the default password for "root" is "fa"

5 Play with Debian

5.1 Ethernet Connection

If the NanoPi M2 is connected to a network via Ethernet before it is powered on it will automatically obtain an IP after it is powered on. If it is not connected via Ethernet or its DHCP is not activated obtaining an IP will fail and system will hang on for about 15 to 60 seconds

  • 1) Setup MAC Address

The NanoPi M2 by default doesn't have a valid MAC address. If the board connects a network successfully it will automatically generates a random MAC in "/etc/network/interfaces.d/eth0". Users can change it to a self-defined valid one:

vi /etc/network/interfaces.d/eth0

Here is the content of a sample configuration file:

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
hwaddress 76:92:d4:85:f3:0f

The "hwaddress" specifies the MAC address. Here the "76:92:d4:85:f3:0f" is a random MAC. We suggest users change it to a valid one.
Note: when you reset the MAC please make sure your MAC meets IEEE's definition otherwise it will cause unexpected issues. After you make your change, save, exit and reboot your board or run the following commands to restart the network:

systemctl restart networking

5.2 Install Debian Packages

We provide a Debian jessie image. You can install Jessie's packages by commanding "apt-get". If this is your first installation you need to update the package list by running the following command:

apt-get update

You can install your preferred packages. For example if you want to install an FTP server you can do this:

apt-get install vsftpd

Note: you can change your download server by editting "/etc/apt/sources.list". You can get a complete server list from [1]. You need to select the one with "armhf".

6 Make Your Own OS Image

6.1 Setup Development Environment

Install Cross Compiler:

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/

Then add the compiler's directory to "PATH" by appending the following lines in "~/.bashrc":

export PATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH
export GCC_COLORS=auto

Execute "~/.bashrc" to make the changes into effect. Please note that there is a space after ".":

. ~/.bashrc

This compiler is a 64-bit one therefore it cannot be run on a 32-bit LINUX. After the compiler is installed you can verify it by running the following commands:

arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/4.9.3/libexec/gcc/arm-cortexa9-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-cortexa9-linux-gnueabihf
Configured with: /work/toolchain/build/src/gcc-4.9.3/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=arm-cortexa9-linux-gnueabihf --prefix=/opt/FriendlyARM/toolchain/4.9.3
--with-sysroot=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-languages=c,c++
--with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3 --with-float=hard
...
Thread model: posix
gcc version 4.9.3 (ctng-1.21.0-229g-FA)

6.2 Compile U-Boot

Download the U-Boot source code and compile it. Please note the github's branch is nanopi2-lollipop-mr1:

git clone https://github.com/friendlyarm/uboot_nanopi2.git
cd uboot_nanopi2
git checkout nanopi2-lollipop-mr1
make s5p4418_nanopi2_config
make CROSS_COMPILE=arm-linux-

After your compilation succeeds a u-boot.bin will be generated. If you want to test it please flash it to your installation MicroSD card via fastboot. Here is how you can do it:
1) On your PC host please run "sudo apt-get install android-tools-fastboot" to install the fastboot utility;
2) Connect your NanoPi M2 to your PC host via a serial cable (e.g. PSU-ONECOME). Press the enter key within two seconds right after you power on your NanoPi M2 and you will enter uboot's command line mode;
3) After type "fastboot" and press "enter" you will enter the fastboot mode;
4) Connect your NanoPi M2 to this PC host via a microUSB cable and type the following command to flash the u-boot.bin:

fastboot flash bootloader u-boot.bin


Warning: you cannot update this MicroSD card by commanding "dd". This command which will cause trouble when booting the NanoPi M2.

6.3 Prepare mkimage

You need the mkimage utility to compile a U-Boot source code package. Please make sure this utility works well on your host before you start compiling a uImage.
You can install this utility by either commanding "sudo apt-get install u-boot-tools" or following the commands below:

cd uboot_nanopi2
make CROSS_COMPILE=arm-linux- tools
sudo mkdir -p /usr/local/sbin && sudo cp -v tools/mkimage /usr/local/sbin

6.4 Compile Linux kernel

6.4.1 Compile Kernel

  • Download Kernel Source Code
git clone https://github.com/friendlyarm/linux-3.4.y.git
cd linux-3.4.y
git checkout nanopi2-lollipop-mr1

The NanoPi M2's kernel source code lies in the "nanopi2-lollipop-mr1" branch.

  • Compile Android Kernel
make nanopi2_android_defconfig
touch .scmversion
make uImage
  • Compile Debian Kernel
make nanopi2_linux_defconfig
touch .scmversion
make uImage

After your compilation succeeds a uImage will be generated in the "arch/arm/boot/uImage" directory. This kernel is for HDMI 720P. You can use it to replace the existing uImage.hdmi
If you want to generate a kernel for HDMI 1080P you can do it this way:

touch .scmversion
make nanopi2_linux_defconfig
make menuconfig
  Device Drivers -->
    Graphics support -->
      Nexell Graphics -->
        [ ] LCD
        [*] HDMI
        (0)   Display In  [0=Display 0, 1=Display 1]
              Resolution (1920 * 1080p)  --->
make uImage

After your compilation succeeds a uImage will be generated for HDMI 1080P. You can use it to replace the existing uImage.
If you want to generate a kernel for LCD you can do it this way:

touch .scmversion
make nanopi2_linux_defconfig
make menuconfig
  Device Drivers -->
    Graphics support -->
      Nexell Graphics -->
        [*] LCD
        [ ] HDMI
make uImage

After your compilation succeeds a uImage will be generated for LCD. You can use it to replace the existing uImage.

6.4.2 Compile Kernel Modules

Android contains kernel modules which are in the "/lib/modules" directory in the system section. If you want to add your own modules to the kernel or you changed your kernel configurations you need to recompile these new modules.
Compile Original Kernel Modules:

cd linux-3.4.y
make CROSS_COMPILE=arm-linux- modules

Here we have two new modules and we can compile them by following the commands below:

cd /opt/FriendlyARM/s5p4418/android
./vendor/friendly-arm/build/common/build-modules.sh

The "/opt/FriendlyARM/s5p4418/android" directory points to the top directory of Android source code. You can get more details by specifying option "-h".
After your compilation succeeds new modules will be generated

6.5 Compile Android

  • Install Cross Compiler

We recommend installing 64 bit Ubuntu 14.04 on your PC host.

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
sudo apt-get install flex libncurses5-dev zlib1g-dev gawk minicom

For more details please refer to https://source.android.com/source/initializing.html

  • Download Source Code

You need to use repo to get the Android source code. Please refer to https://source.android.com/source/downloading.html

mkdir android && cd android
repo init -u https://github.com/friendlyarm/android_manifest.git -b nanopi2-lollipop-mr1
repo sync

The "android" directory is the working directory.

  • Compile System Package
source build/envsetup.sh
lunch aosp_nanopi2-userdebug
make -j8

After your compilation succeeds an image will be generated in the "out/target/product/nanopi2/" directory.

7 扩展连接

7.1 连接USB(FA-CAM202)200万摄像头模块

  • NanoPi M2使用Debian系统,假设你已接好LCD屏或者HDMI,进入系统后,点击左下角的菜单键“Other”-->xawtv9,打开USB Camera软件。进入“welcome to xawtv!”,选择OK即可进行拍照。

USB camera-Fire

7.2 连接CMOS 500万摄像头模块

  • NanoPi M2使用Android5.1系统,假设你已经接好LCD屏或者HDMI,进入系统后,直接点击“camera”图标,即可打开摄像头进行拍照。

CMOS camera01

7.3 连接USB摄像头使用OpenCV

  • OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库。
  • NanoPi M2跑Debian系统时,接USB Camera,可直接使用官方的OpenCV。

1、以下介绍的是NanoPi M2用C++使用的OpenCV:

  • 首先需要保证你的NanoPi M2能连外网,假如你有串口,直接串口登陆超级终端(或者ssh登陆)。进入系统后,输入用户名(root),密码(fa)登陆;
  • 以下命令在超级终端执行:
apt-get update
apt-get install libcv-dev libopencv-dev

2、NanoPi M2烧写Debian系统启动后,接上USB Camera,使用Debian系统自带的摄像头软件测试,确定摄像头能正常使用。
3、通过终端执行命令,查看你的摄像头设备:

ls /dev/video*
  • 注:video9 是你的USB摄像头设备(注:video0到8均被其它设备占用了)

4、opencv的测试代码(官方C++示例代码)在 /home/fa/Documents/opencv-demo, 使用以下命令即可编译:

cd /home/fa/Documents/opencv-demo
make

编译成功后,得到可执行文件demo
5、这里特别说明:目前NanoPi M2的内核注册了9个video设备,而opencv的官方源码定义了最多只能使用8个Camera,所以这里需要临时删除一个video设备,以下命令则是删除video0:

rm /dev/video0
mv /dev/video9 /dev/video0

6、以下步骤需要在NanoPi M2上连接键盘后执行:

./demo

你便可以看到opencv已经用起来,如图:
OpenCV-Fire01

7.4 连接USB WiFi

  • 点击此处,内核编译链接[1]

8 更多OS

8.1 Ubuntu-Core

Ubuntu-Core是一个轻量级的Ubuntu系统,无桌面环境,可通过ssh登录。
仅提供给进阶爱好者交流使用,不对该系统提供专业技术支持。

  • 访问此处下载地址下载系统固件。
  • 将固件解压后,在Windows下使用友善官方提供 win32diskimager 工具烧写即可。
  • 烧写完成后,将SD卡插入NanoPi M2,上电即可体验Ubuntu-Core。
  • 登录账号:root或fa ; 登录密码:fa

8.2 Ubuntu-Mate

Ubuntu-Mate基于Ubuntu系统,使用的桌面环境是Mate-desktop,界面简洁易用,需配合LCD或者HDMI使用,可通过ssh登录。
仅提供给进阶爱好者交流使用,不对该系统提供专业技术支持。

  • 访问此处下载地址下载系统固件。
  • 将固件解压后,在Windows下使用友善官方提供 win32diskimager 工具烧写Ubuntu-Mate即可。
  • 烧写完成后,将SD卡插入NanoPi M2,上电即可体验Ubuntu-Mate。
  • 登录账号:root或fa ; 登录密码:fa

8.3 Kali

  • 首先访问此处[2]的下载地址下载需要的固件文件;
  • 准备大于8G的高速microSD卡(建议使用友善官方测试过的SD卡),并插入linux主机,通过命令sudo fdisk -l 查看该sd卡是哪个设备即/dev/sd*。
  • 下载后把文件写到卡里,使用超级用户权限执行下列命令:
xzcat kali-2.0-nanopi2.img.xz | dd of=<YOURDEVICE> bs=1m
  • 烧写完成,将卡插入设备,上电即可开始体验Kali操作系统。

说明:此文件系统是由Kali官方制作,我们仅提供下载链接供爱好者使用,不对此做技术支持。

9 源代码和固件下载链接

  • 烧写固件下载链接:[3]
  • 源代码下载链接:[4]

10 资源链接

11 更新日志