Skip to content

Commit

Permalink
Import busybear-linux build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Clark committed Dec 15, 2017
0 parents commit 1a97f45
Show file tree
Hide file tree
Showing 25 changed files with 1,549 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*~
build/
archives/
busybear.bin
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all: busybear.bin

clean:
rm -fr build busybear.bin

distclean: clean
rm -fr archives

busybear.bin: scripts/build.sh scripts/image.sh
sh scripts/build.sh
sudo -E sh scripts/image.sh

archive:
tar --exclude build --exclude archives --exclude busybear.bin \
-C .. -cjf ../busybear-linux.tar.bz2 busybear-linux
220 changes: 220 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# busybear-linux

busybear-linux is a tiny RISC-V Linux root filesystem image that targets
the `virt` board in riscv-qemu. As the name suggests, busybear-linux is
a riscv-linux root image comprised of busybox and dropbear.

The root image is intended to demonstrate virtio-net and virtio-block in
riscv-qemu and features a dropbear ssh server which allows out-of-the-box
ssh access to a RISC-V virtual machine.

See the [releases](https://github.com/michaeljclark/busybear-linux/releases)
for pre-built kernel and filesystem images.

## Dependencies

- [riscv-gnu-toolchain](https://github.com/riscv/riscv-gnu-toolchain) (RISC-V Linux toolchain)
- [busybox](https://busybox.net/) (downloaded automatically)
- [dropbear](https://matt.ucc.asn.au/dropbear/dropbear.html) (downloaded automatically)
- sudo, curl, openssl and rsync

## Features

- `ntpd` for time configuration
- `klog` for kernel logging
- `syslog` for system logging
- `dropbear` for ssh access
- `busybox` with almost everything enabled

## Configuration

- `conf` contains the linux image build configuration
- `conf/linux.config` contains the linux-kernel configuration
- `conf/busybox.config` contains the busybox configuration
- `conf/busybear.config` contains the image build configuration
- `ROOT_PASSWORD=busybear`
- `IMAGE_FILE=busybear.bin`
- `etc` contains the linux guest system configuration
- `etc/network/interfaces` (guest 192.168.100.2, router 192.168.100.1)
- `etc/resolv.conf` (nameserver 8.8.8.8, nameserver 8.8.4.4)
- `etc/ntp.conf` (server 0.pool.ntp.org, server 1.pool.ntp.org)
- `etc/passwd`, `etc/shadow`, `etc/group` and `etc/hosts`

The default config assumes bridged networking with `192.168.100.1`
on the host and `192.168.100.2` in the guest.

## Build

The build process downloads busybox and dropbear, compiles them and prepares
a root filesystem image to the file `busybear.bin`. The build script needs
to be run in Linux, even if preparing a root filesystem image for macOS.

### busybear-linux

```
git clone https://github.com/michaeljclark/busybear-linux.git
cd busybear-linux
make
```

### QEMU

```
git clone https://github.com/riscv/riscv-qemu.git
cd riscv-qemu
./configure --target-list=riscv64-softmmu,riscv32-softmmu
make
```

### riscv-linux

```
git clone https://github.com/riscv/riscv-linux.git
cd riscv-linux
git checkout riscv-linux-4.14
cp ../busybear-linux/conf/linux.config .config
make ARCH=riscv olddefconfig
make ARCH=riscv vmlinux
```

### bbl

```
git clone https://github.com/riscv/riscv-pk.git
cd riscv-pk
mkdir build
cd build
../configure \
--enable-logo \
--host=riscv64-unknown-elf \
--with-payload=../../riscv-linux/vmlinux
make
```

## Running

busybear requires the riscv-qemu `virt` board with virtio-block
and virtio-net devices.

The following command starts busybear-linux.

```
sudo qemu-system-riscv64 -nographic -machine virt -kernel bbl \
-drive file=busybear.bin,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev type=tap,script=./ifup,downscript=./ifdown,id=net0 \
-device virtio-net-device,netdev=net0
```

After booting the virtual machine you should be able to ssh into it.

```
$ ssh [email protected]
The authenticity of host '192.168.100.2 (192.168.100.2)' can't be established.
ECDSA key fingerprint is 3f:4b:69:59:01:c8:b2:9c:fb:52:a5:d4:21:c9:3c:1b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.2' (ECDSA) to the list of known hosts.
[email protected]'s password:
____ ____ __ _
/ __ )__ _________ __/ __ )___ ____ ______ / / (_)___ __ ___ __
/ __ / / / / ___/ / / / __ / _ \/ __ `/ ___/ / / / / __ \/ / / / |/_/
/ /_/ / /_/ (__ ) /_/ / /_/ / __/ /_/ / / / /___/ / / / / /_/ /> <
/_____/\__,_/____/\__, /_____/\___/\__,_/_/ /_____/_/_/ /_/\__,_/_/|_|
/____/
root@ucbvax:~# uname -a
Linux ucbvax 4.14.0-00030-gc2d852cb2f3d #56 Thu Dec 14 10:12:10 NZDT 2017 riscv64 GNU/Linux
root@ucbvax:~# cat /proc/interrupts
CPU0
1: 107 riscv,plic0,c000000 10 ttyS0
7: 115 riscv,plic0,c000000 7 virtio1
8: 135 riscv,plic0,c000000 8 virtio0
root@ucbvax:~#
```

Note: the disk image is stateful and needs to be shutdown cleanly.

```
root@ucbvax:~# halt
```

## macOS bridged networking

These steps show how to setup tuntap bridged networking on macOS:

### install tuntap

Note: the tuntap driver installation requires authorization in the
macOS Security and Privacy section of System Preferences.

```
brew tap caskroom/cask
brew install caskroom/cask/tuntap
```

### create bridge

```
sudo ifconfig bridge1 create
sudo ifconfig bridge1 192.168.100.1/24
```

### ifup script

```
#!/bin/bash
ifconfig bridge1 addm $1
```

### ifdown script

```
#!/bin/bash
ifconfig bridge1 deletem $1
```

### pfctl.rules (packet filter rules)

```
nat on en0 from { 192.168.100.0/24 } to any -> (en0)
pass from {lo0, 192.168.100.0/24} to any keep state
```

### NAT forwarding (guest access to the Internet)

```
sudo sysctl -w net.inet.ip.forwarding=1
sudo pfctl -e
sudo pfctl -F all
sudo pfctl -f pfctl.rules
```

## linux configuration

The following is a minimal linux-kernel `.config` that can be used with
`make ARCH=riscv olddefconfig`.

```
CONFIG_HZ_100=y
CONFIG_PCI=y
CONFIG_CROSS_COMPILE="riscv64-unknown-elf-"
CONFIG_DEFAULT_HOSTNAME="ucbvax"
CONFIG_PARTITION_ADVANCED=y
CONFIG_NET=y
CONFIG_UNIX=y
CONFIG_INET=y
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_VIRTIO_BLK=y
CONFIG_NETDEVICES=y
CONFIG_VIRTIO_NET=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_VIRT_DRIVERS=y
CONFIG_VIRTIO_MMIO=y
CONFIG_EXT4_FS=y
CONFIG_TMPFS=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="root=/dev/vda ro"
CONFIG_PRINTK_TIME=y
```
2 changes: 2 additions & 0 deletions bin/ldd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
LD_TRACE_LOADED_OBJECTS=1 $*
6 changes: 6 additions & 0 deletions conf/busybear.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BUSYBOX_VERSION=1.27.2
DROPBEAR_VERSION=2017.75
COMPILER_PREFIX=riscv64-unknown-linux-gnu
IMAGE_FILE=busybear.bin
IMAGE_SIZE=64
ROOT_PASSWORD=busybear
Loading

0 comments on commit 1a97f45

Please sign in to comment.