快速上手 R2
Revision as of 00:09, 12 October 2018 by JackZengWiki (talk | contribs) (→WiFi and Ap mode on R2 Ubuntu)
介绍
Banana Pi R2是一块基于路由功能的开发板,R2上可以运行Android和开源系统openwrt,Ubuntu等,其具有4路Gb通信能力的lan口,1路Gb通信能力的wan口以及300Mb通信能力的无线通信能力。
关于更多: Banana Pi BPI-R2
关键特性
- MediaTek MT7623N, Quad-core ARM Cortex-A7
- Mali 450 MP4 GPU
- 2G DDR3 SDRAM
- 1x Mini PCIE interface
- 2x SATA interface
- 4x Gigabit LAN 1x Gigabit WAN
硬件
BPI-R2 SATA 接口
BPI-R2 支持2个sata接口和板载电源接口.
你可以用sata线将硬盘接到R2上.
- 测试SAMSUNG SSD 硬盘读写性能的方法如下:
- 读取硬盘: 230MB/s \(command: dd if=/dev/sda of=/dev/zero bs=1M count=10240\)
- 刻入硬盘: 192MB/s \(command: dd if=/dev/zero of=/dev/sda bs=1M count=1024 oflag=direct\)
- 注意:
- 如果用3.5寸的硬盘,你可能需要通过外部电源通电,板载的电源不足以支撑足够的电流.
开发
基础开发
开发前准备
* 准备一张容量至少 8Gb 的TF卡, 串口线, 一台运行Ubuntu系统的PC机 * 使用串口线连接R2的调试串口
* R2调试串口:http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:debug-uart
烧录第一个Linux镜像到 R2
1.你可以从下面链接下载最近的镜像 * Here is the example image link: http://forum.banana-pi.org/t/bpi-r2-new-image-release-ubuntu-16-04-v1-3-2018-3-30/5293 2.在你的Ubuntu系统电脑上安装bpi-tools, 执行以下命令即可安装: * apt-get install pv * curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools | sudo -E bash 3.下载完镜像后, 插入TF卡到你的Ubuntu电脑中 * 运行命令 "bpi-copy xxx.img /dev/sdx" 烧录镜像到你的TF卡中. 4.完成步骤3后, 请将TF卡插入R2, 长按电源键10s直到启动R2
在SD卡上安装Ubuntu
1. 从Github上复制bsp代码 * 执行命令 "git clone [email protected]:BPI-SINOVOIP/BPI-R2-bsp.git" 2. 执行"./build.sh"命令, 编译你自己的uboot和 kernel. 3. 完成编译后, 执行"cd SD"命令, 插入TF卡到你的PC端 . 4. 执行命令 "bpi-update -c bpi-r2.conf -d /dev/sdX", 将编译好的kernel更新到你的TF卡中.
在emmc上安装Ubuntu
1. 如果你想在emmc上安装ubuntu, 请遵循以下这些步骤: bpi-copy <XXX.img.zip> /dev/mmcblk1
* XXX.img.zip 是我们下载的Ubuntu镜像, 请从 http://www.banana-pi.org/r2-download.html 下载 * 关机 * 移除SD卡并开机
如何安装在SD&emmc上安装Openwrt
1. 从Github上复制OpenWrt代码. * 执行命令 "git clone https://github.com/garywangcn/bpi-r2_lede.git" 2. 你需要安装 gcc, binutils, bzip2, flex, python, perl, make, find, grep, diff, unzip, gawk, getopt, subversion, libz-dev and libc headers. 3. 运行"./scripts/feeds update -a"命令,分别获取定义在“feeds.conf / feeds.conf.default”和"./scripts/feeds install -a"中的最新的软件包定义, 然后安装它们的所有符号链接到 package/feeds/. 4. 使用 "make menuconfig"命令来配置你的镜像. * 选择 "Target System" 来配置 "MediaTek Ralink ARM" * 选择 "Boot Loaders" 来配置 "u-boot-bpi_r2" 5. 执行"make -j1 V=s" 命令来编译你自己的OpenWrt镜像. 6. 编译完成后,你可以通过两种方法安装镜像. (1) 将TF卡插到Ubuntu PC端, 并输入 "build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-mediatek_32/", 你会发现两个镜像: * mtk-bpi-r2-EMMC.img * mtk-bpi-r2-SD.img (2) 烧录镜像到TF卡,执行 "dd if=mtk-bpi-r2-SD.img of=/dev/sdX"命令 (3) 如果你想要安装镜像到emmc,请遵循以下步骤: * 从SD卡启动R2 * 复制EMMC镜像到SD卡运行的镜像中 * 解锁EMMC boot0 block: echo 0 > /sys/block/mmcblk0boot0/force_ro * 烧录EMMC镜像到EMMC的用户数据区: dd if=mtk-bpi-r2-EMMC.img of=/dev/mmcblk0 (assume /dev/mmcblk0 is for EMMC) * 烧录 preloader 到 EMMC boot0 分区: dd if=mtk-bpi-r2-EMMC.img of=/dev/mmcblk0boot0 bs=1M count=1 * 更改EMMC的分区配置为48h: 重启SD卡的运行系统, 并输入U-boot命令行,运行命令“emmc pconf 48” (对于此步骤,我们可以使用mmc-utils更改用户空间中的分区配置,请参阅BPI-R2 OpenWrt(LEDE)中源代码获取更多信息:2018-04-11) * 关机,移除SD卡,然后重启R2板 7. 此步骤用于升级,如果你构建完成后不想安装镜像,你可以直接运行升级. * 拷贝 "bin/targets/mediatek/32/lede-mediatek-32-bananapi,bpi-r2-sysupgrade.tar" to 到正在运行OpenWrt系统的R2板中(无论是从emmc还是SD卡运行的), 然后运行 "sysupgrade lede-mediatek-32-bananapi,bpi-r2-sysupgrade.tar" 命令进行 kernel和 rootfs的升级.
- 1,在R2上安装openWRT: https://www.cnblogs.com/topbin/p/8794152.html
- 2,Banana Pi R2 Openwrt网口配置分析 : https://www.cnblogs.com/topbin/p/9518279.html
- 3,Banana Pi R2开发基于Openwrt的简易路由器 : https://www.cnblogs.com/topbin/p/9519881.html
- 4,Banana Pi R2 Openwrt Luci: https://www.cnblogs.com/topbin/p/9519875.html
网络配置
进阶开发
GPIO
GPIO 控制
- echo xxx > /sys/class/gpio/export
- echo in/out > /sys/class/gpio/gpioxxx/direction
- echo 0/1 > /sys/class/gpio/gpioxxx/value
检测基础gpio, 你可查看到我的是233
例如:如果你想要更改GPIO22为高电平输出,你需要输入以下命令:
- echo 255(22+233) > /sys/class/gpio/export
- echo out > /sys/class/gpio/gpio255/direction
- echo 1 > /sys/class/gpio/gpio255/value
PWM 控制
- echo x >/sys/class/pwm/pwmchip0/export
- echo 200000 >/sys/class/pwm/pwmchip0/pwmx/period
- echo 100000 >/sys/class/pwm/pwmchip0/pwmx/duty_cycle
- echo 1 >/sys/class/pwm/pwmchip0/pwmx/enable
关于更多 GPIO : http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:gpio
R2和4G模块的开发
更多资料请参考:
R2 Ubuntu上的wifi和AP模式
WiFi 功能
- wmt_loader (ignore errors)
- stp_uart_launcher -p /etc/firmware &
- ip link set wlan0 up
- iw dev wlan0 scan | grep SSID
- vim /etc/wpasupplicant/wpa_supplicant.conf
- network={ ssid=“ssid” psk=“password” priority=1}
- wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
- dhclient wlan0
AP 模式
- wmt_loader (ignore errors)
- stp_uart_launcher -p /etc/firmware &
- echo A >/dev/wmtWifi
- 创建你的 hostapd.conf: "vim /etc/hostapd/hostapd.conf "
interface=ap0 bridge=br0 ssid=test_r2 driver=nl80211 country_code=US hw_mode=b channel=1 max_num_sta=5 wpa=2 auth_algs=1 rsn_pairwise=CCMP wpa_key_mgmt=WPA-PSK wpa_passphrase=ledetest logger_stdout=-1 logger_stdout_level=2
- 根据你的网络接口来配置ap0:
如果我可以搜到网络的网口是wan口, IP是192.168.30.102, 那么我对ap0进行以下配置:
“ifconfig ap0 192.168.30.188 netmask 255.255.255.0”
- 运行hostapd : “hostapd -d /etc/hostapd/hostapd.conf”
- 配置dhcp文件 : “vim /etc/dhcp/dhcpd.conf”
subnet 192.168.30.0 netmask 255.255.255.0 { range 192.168.30.2 192.168.30.250; option domain-name-servers 8.8.8.8; option routers 192.168.30.1; }
- 配置ap0的dhcp, 然后连接ap0的设备可以得到IP: "dhcpd ap0 -pf /var/run/dhcpd.pid "
- 增加网桥, 并执行一下命令:
- brctl addbr br0
- brctl addif br0 ap0
- brctl addif br wan
- 配置 br0 : “ifconfig br0 192.168.30.180 netmask 255.255.255.0”
- 添加br0的网关 : “route add -net default netmask 255.255.255.0 gw 192.168.30.1 dev br0”
WiFi and Ap mode on R2 Openwrt
AP mode
1. Make a bash script
- vim setup.sh
#!/bin/ash wmt_loader & sheep 3 stp_uart_launcher -p /etc/firmware & sleep 5 echo A > /dev/wmtWifi & sleep 5 hostapd -d hostapd.conf
2. Create your hostapd.conf
- vim hostapd.conf
interface=ap0 bridge=br-lan ssid=BPI_R2 driver=nl80211 country_code=CN hw_mode=g channel=1 max_num_sta=5 wpa=2 auth_algs=1 rsn_pairwise=CCMP wpa_key_mgmt=WPA-PSK wpa_passphrase=ledetest logger_stdout=-1 logger_stdout_level=2
3. Make it run
- ./setup.sh
4. Add it to starting progress
- vim /etc/rc.local
cd /root/ sleep 6 ./setup.sh &
5. If your Ap is not stable, please limit the speed, here I limit download speed as 8Mbit/s, upload as 4Mbit/s
- tc qdisc add dev ap0 root handle 1: htb default 11
- tc class add dev ap0 parent 1:1 classid 1:2 htb rate 8Mbit ceil 4Mbit prio 2
Make your own image
- Prepare a SD card which have installed Ubuntu system
- Boot your SD card with R2, after R2 finish starting, copy your files and config your Ubuntu, then poweroff R2
- Plug your SD card in Linux PC, "cd /media", then "ln -s <your account> pi"
- Execute "bpi-migrate -c bpi-r2.conf -c ubuntu-mate-from-sd.conf -d /dev/sdx"
- Then you could get your own image now
FAQ
- 1.Banana Pi BPI-R2 Razberry board OpenHab2
Reference Link
http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:start