Home BeagleBone Black 安装 OpenWrt
Post
Cancel

BeagleBone Black 安装 OpenWrt

春节在家找到之前的一块 BeagleBone Black,一直吃灰比较可惜,给它刷个 OpenWrt 顶替树莓派,把树莓派腾出来当个游戏机。

What is BeagleBone Black?

BeagleBone Black is a low-cost, community-supported development platform for developers and hobbyists. Boot Linux in under 10 seconds and get started on development in less than 5 minutes with just a single USB cable.

Processor: AM335x 1GHz ARM® Cortex-A8

  • 512MB DDR3 RAM
  • 4GB 8-bit eMMC on-board flash storage
  • 3D graphics accelerator
  • NEON floating-point accelerator
  • 2x PRU 32-bit microcontrollers

Connectivity

  • USB client for power & communications
  • USB host
  • Ethernet
  • HDMI
  • 2x 46 pin headers

Software Compatibility

  • Debian
  • Android
  • Ubuntu
  • Cloud9 IDE on Node.js w/ BoneScript library
  • plus much more

在给 BBB 安装 OpenWrt 之前,先说说怎么把 Debian、Ubuntu 装到 eMMC。

  • Debian
    1. 先下载 image,”Flasher” Debian images 是可以通过 SD 卡烧写到 eMMC 的版本。
    2. etcher 把下载好的 image 烧写到 SD 卡里。
    3. 把烧写好的 SD 卡插到卡槽里,按住 SD 卡边上的 S2 开关(这是为了让 BBB 从 SD 卡启动),然后给 BBB 上电。
    4. 大概等几十秒左右的时间,4 个 user led 开始跑马灯(烧写 eMMC),等到 led 全灭或者全亮后:断电 -> 拔卡 -> 上电,就会从 eMMC 启动了。
  • Ubuntu
    1. 先读文档,装到 eMMC 的说明
    2. 下载 image:wget https://rcn-ee.com/rootfs/2020-03-12/flasher/bone-eMMC-flasher-ubuntu-18.04.4-console-armhf-2020-03-12-2gb.img.xz
    3. 之后跟装 Debian 的 2-4 步一致
  • Ubuntu 更新
    1. 下载 image:https://rcn-ee.com/rootfs/ubuntu-armhf/
    2. 直接 copy 到一个能启动的 SD 卡里,然后从 SD 卡启动 bbb
    3. 执行命令 dd if=xxx.iso of=/dev/mmcblk1 bs=4k conv=fsync 写入 eMMC

安装 OpenWrt 跟安装 Debian 不太一样,主要是 OpenWrt 的 image 不带自动写入 eMMC 的脚本,需要自己手动写,下面是具体步骤。

1. 获取 Image

OpenWrt 是支持 BBB 的,可以在 Table of Hardware 里查到。

官方提供了不怎么有用的说明和编译好的版本:21.02.1,如果不想折腾或者官方的能满足要求,那么 image 就请直接下载官方的使用。

不想用官方的 image 的话就得自己编译了,自己编译需要:Linux 环境、20G 左右的硬盘空间、2-3 小时的时间、科学上网环境,贼费劲。

(更新:可以小媷下 Github 的羊毛,利用 Actions 在线编译。bbb-openwrt-actions

我是用的 Lean 的源码:lede,官方的也行。

第一次编译大概需要 2-3 小时。

  1. 装 Ubuntu 虚拟机:Ubuntu Server 20.04 LTS x64

  2. 换清华源后安装工具:

    1
    2
    
    $ sudo apt-get update
    $ sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync
    
  3. clone 源码:git clone https://github.com/coolsnowwolf/lede,进入 lede 目录

  4. 修改 feeds.conf.default 文件加入 ssr:src-git helloworld https://github.com/fw876/helloworld

  5. 调整编译选项:

    1
    2
    3
    
    $ ./scripts/feeds update -a
    $ ./scripts/feeds install -a
    $ make menuconfig
    
  6. 下载 dl 库:make -j8 download V=s

  7. 开始编译:make -j1 V=s

  8. 编译结果目录:bin/targets

如果不满意之前的结果,可以二次编译,会快很多。

1
2
3
4
5
6
$ cd lede
$ git pull
$ ./scripts/feeds update -a && ./scripts/feeds install -a
$ make defconfig
$ make -j8 download
$ make -j$(($(nproc) + 1)) V=s

如果需要重新配置:

1
2
3
$ rm -rf ./tmp && rm -rf .config
$ make menuconfig
$ make -j$(($(nproc) + 1)) V=s

2. 烧录启动

  • 用 etcher 把 image 写到 SD卡里,并插到卡槽里。

  • Mac 接好串口线(PLC2303):screen /dev/tty.usbserial-xxxx 115200,板上接法见下图。

    serial

  • 按住 S2 给 BBB 上电,观查 OpenWrt 是否能启动,有问题度娘或谷哥。

3. 接入网络

在 BBB 能正常启动的情况下,就可把它接入自己的网络中了。

接入前需要额外检查下 BBB 的 ip 是不是可用,OpenWrt 默认是静态 ip:192.168.1.1,如果它不在自己的子网范围内就需要手动修改下。

文件 /etc/config/network

1
2
3
4
config interface 'lan'
	...
	option ipaddr '192.168.x.x'
	...

浏览器中访问相应 ip 就能看到登陆界面了。

4. 写入 eMMC

用 dd 是把系统写入 eMMC 的简单办法,缺点就是 eMMC 空间没法完全利用。

把之前烧到 SD 卡的 image 拷备到 BBB 里,然后执行以下命令即可:

1
zcat openwrt-omap-ti_am335x-bone-black-ext4-sdcard.img.gz| dd of=/dev/mmcblk1 bs=4k conv=fsync

别外比较复杂的办法应该可以完全利用 eMMC 空间,我没试。

BeagleBone Black eMMC烧写指南

附上脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
echo "****************************************************"
echo "****************************************************"
echo ""
echo "Sitara Example Flashing Script - 02/11/2014"
echo ""
 
STARTTIME=$(date +%s)
 
##---------Start of variables---------------------##
 
## Set Server IP here
#SERVER_IP="192.168.100.1"
 
## Names of the images to grab from TFTP server
BOOT_PARTITION="boot_partition.tar.gz"
 
## Rename rootfs as needed depending on use of tar or img
ROOTFS_PARTITION="rootfs_partition.tar.xz"
## ROOTFS_PARTITION="rootfs_partition.img.gz"
 
## Declare eMMC device name here
DRIVE="/dev/mmcblk1"
 
##----------End of variables-----------------------##
 
## TFTP files from host.  Edit the files and host IP address for your application.
## We are grabbing two files, one an archive with files to populate a FAT partion,
## which we will create.  Another for a filesystem image to 'dd' onto an unmounted partition.
## Using a compressed tarball can be easier to implement, however, with a large file system
## with a lot of small files, we recommend a 'dd' image of the partition to speed up writes.
#echo "Getting files from server: ${SERVER_IP}"
#time tftp -b 4096 -g -r ${BOOT_PARTITION} ${SERVER_IP} &
#boot_pid=$!
#time tftp -b 4096 -g -r ${ROOTFS_PARTITION} ${SERVER_IP} &
#rootfs_pid=$!
 
 
## Kill any partition info that might be there
dd if=/dev/zero of=$DRIVE bs=4k count=1
sync
sync
 
## Check to see if the eMMC partitions have automatically loaded from the old MBR.
## This might have occured during the boot process if the kernel detected a filesystem
## before we killed the MBR. We will need to unmount and kill them by writing 4k zeros to the
## partitions that were found.
 
check_mounted(){
  is_mounted=$(grep ${DRIVE}p /proc/mounts | awk '{print $2}')
 
  if grep -q ${DRIVE}p /proc/mounts; then
      echo "Found mounted partition(s) on " ${DRIVE}": " $is_mounted
      umount $is_mounted
      counter=1
      for i in $is_mounted; do \
          echo "4k erase on ${DRIVE}p${counter}"; 
          dd if=/dev/zero of=${DRIVE}p${counter} bs=4k count=1;
          counter=$((counter+1));
      done
  else
      echo "No partition found. Continuing."
  fi
}
 
check_mounted;
 
## Partitioning the eMMC using information gathered.
## Here is where you can add/remove partitions.
## We are building 2 partitions:
##  1. FAT, size = 9 cylinders * 255 heads * 63 sectors * 512 bytes/sec = ~70MB
##  2. EXT3, size = 223 ($CYLINDERS-[9 for fat]) cylinders * 255 heads * 63 sectors * 512 bytes/sec = ~1l.7GB
##
## You will need to change the lines ",9,0c0C,*", "10,,,-" to suit your needs.  Adding is similar,
## but you will need to be aware of partition sizes and boundaries.  Use the man page for sfdisk.
echo "Partitioning the eMMC..."
sfdisk --force /dev/mmcblk1 << EOF
    1,104447,b,*
	,,,
EOF
 
## This sleep is necessary as there is a service which attempts
## to automount any filesystems that it finds as soon as sfdisk
## finishes partitioning.  We sleep to let it run.  May need to
## be lengthened if you have more partitions.
sleep 2
 
## Check here if there has been a partition that automounted.
##  This will eliminate the old partition that gets
##  automatically found after the sfdisk command.  It ONLY
##  gets found if there was a previous file system on the same
##  partition boundary.  Happens when running this script more than once.
##  To fix, we just unmount and write some zeros to it.
check_mounted;
 
## Clean up the dos (FAT) partition as recommended by SFDISK
dd if=/dev/zero of=${DRIVE}p1 bs=512 count=1
 
## Make sure posted writes are cleaned up
sync
sync
 
## Format the eMMC into 2 partitions
echo "Formatting the eMMC into 2 partitions..."
 
## Format the boot partition to fat32
mkfs.vfat -F 32 -n "boot" ${DRIVE}p1
 
## Format the rootfs to ext3 (or ext4, etc.) if using a tar file.
## We DO NOT need to format this partition if we are 'dd'ing an image
## Comment out this line if using 'dd' of an image.
mkfs.ext3 -L "rootfs" ${DRIVE}p2
 
## Make sure posted writes are cleaned up
sync
sync
echo "Formatting done."
 
## Make temp directories for mountpoints
mkdir tmp_boot
 
## Comment this line out if using 'dd' of an image. It is not needed.
mkdir tmp_rootfs
 
## Mount partitions for tarball extraction. NOT for 'dd'.
mount -t vfat ${DRIVE}p1 tmp_boot
 
## If 'dd'ing the rootfs, there is no need to mount it. Comment out the below.
mount -t ext3 ${DRIVE}p2 tmp_rootfs
 
## Wait for boot to finish tftp
echo "Copying Boot Files..."
time tar -xf ${BOOT_PARTITION} -C tmp_boot
sync
sync
umount ${DRIVE}p1
#rm ${BOOT_PARTITION}
 
sync
sync
 
echo "Boot partition done."
 
## Wait for rootfs to finish tftp
wait $rootfs_pid
## If using a tar archive, untar it with the below.
## If using 'dd' of an img, comment these lines out and use the below.
echo "Copying Rootfs Files..."
time tar -xf ${ROOTFS_PARTITION} -C tmp_rootfs
sync
sync
umount ${DRIVE}p2
#rm ${ROOTFS_PARTITION}
 
sync
sync
 
echo "RootFS partition done."
 
## If using 'dd' of an img, uncomment these lines.
## If using a tar archive, comment out these lines and use the above.
## time gunzip -c ${ROOTFS_PARTITION} | dd of=${DRIVE}p2 bs=4k
## sync
## sync
## echo "Rootfs partition done."
 
## The block below is only necessary if using 'dd'. 
## Force check the filesystem for consistency and fix errors if any.
## Resize partition to the length specified by the MBR.
## /sbin/e2fsck -fy ${DRIVE}p2
## /sbin/resize2fs ${DRIVE}p2
 
ENDTIME=$(date +%s)
echo "It took $(($ENDTIME - $STARTTIME)) seconds to complete this task..."
## Reboot
echo ""
echo "********************************************"
echo "Sitara Example Flash Script is complete."
echo ""
This post is licensed under CC BY 4.0 by the author.