Skip to content

Commit

Permalink
Merge pull request #6 from andni233/master
Browse files Browse the repository at this point in the history
NanoPi R2S support
  • Loading branch information
Risca authored Aug 23, 2021
2 parents ba60d1f + 1a35177 commit 3c5db7c
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 11 deletions.
30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ help:
@echo " Packaging:"
@echo ""
@echo " pypi Build PyPi packages"
@echo " image Build a Raspberry Pi image"
@echo " image Build all image types"
@echo " raspbian_image Build a Raspbian image suitable for use with most Raspberry Pi models"
@echo " armbian_image Build a Armbian image suitable for use with the NanoPi R2S"
@echo ""
@echo " Clean:"
@echo ""
Expand Down Expand Up @@ -117,14 +119,34 @@ build/pi-gen:
mkdir -p build
cd build && git clone --branch 2020-02-13-raspbian-buster https://github.com/RPi-Distro/pi-gen.git

.PHONY: image
image: pypi | build/pi-gen
.PHONY: raspbian_image
raspbian_image: pypi | build/pi-gen
mkdir -p dist/image
rm -rf build/pi-gen/stage3 build/pi-gen/stage4 build/pi-gen/stage5
cp -r image/* build/pi-gen/
cp -r image/raspbian/* build/pi-gen/
cp -r requirements.txt dist/pypi/*.whl build/pi-gen/stage3/01-install-python-packages/files
cp -r image/common/files/* build/pi-gen/stage3/02-install-services/files
cd build/pi-gen && ./build-docker.sh
mv build/pi-gen/deploy/* dist/image/

build/armbian:
mkdir -p build
# It would be nice to be able to checkout specific branch or commit here to
# get builds that are reproducible, but this does not seem well supported by
# Armbian. For example, checking out branch v2021.05 yields a broken build
# due to upstream changes. As such, checkout the main branch.
cd build && git clone https://github.com/armbian/build.git armbian

.PHONY: armbian_image
armbian_image: pypi | build/armbian
mkdir -p dist/image build/armbian/userpatches/overlay
cp -r image/armbian/userpatches/* build/armbian/userpatches
cp -r requirements.txt dist/pypi/*.whl image/common/files/* build/armbian/userpatches/overlay
cd ./build/armbian && ./compile.sh docker znail-nanopi-r2s
mv build/armbian/output/images/* dist/image

.PHONY: image
image: raspbian_image armbian_image

cleanimage:
rm -rf build/image
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

![Znail Logo](/artwork/znail_x10.png)

Znail is a network emulator inteded to run on a Raspberry Pi.
Equipped with two network interfaces, the Raspberry Pi acts as a network bridge.
Znail is a network emulator inteded to run on a computer with two network interfaces.
Equipped with two network interfaces, Znail acts as a network bridge.
Znail can then control network traffic passing through the bridge.

With a system under test connected to the network through this bridge,
Expand All @@ -27,11 +27,19 @@ Znail can be managed in one of two ways, using its web interface or its REST API

# Getting Started

The easiest way to get started with Znail is to [download](https://github.com/znailnetem/znail/releases/latest) a Rasbian image with Znail pre-installed.
The easiest way to get started with Znail is to [download](https://github.com/znailnetem/znail/releases/latest) an image with Znail pre-installed.

The image can then be [installed](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) on a Raspberry Pi.
The image can then be installed on a suitable target system, for example a [Raspberry Pi](https://www.raspberrypi.org/documentation/installation/installing-images/README.md).

# Generating a Custom Image
## Raspberry Pi

The default SSH username for the pre-built image is `pi` and the password is `raspberry`.

## NanoPi R2S

The default SSH username for the pre-built image is `root` and the password is `1234`.

# Generating Custom Images

To set up the environment on an Ubuntu 20.04 system, run the following commands:

Expand All @@ -42,8 +50,11 @@ To generate an image:

make image

The resulting image can be found in the `dist/image` directory.
Note that due to the way `pi-gen` works, portions of the `make image` target needs to run as root.
The resulting images can be found in the `dist/image` directory.

Generating the different images can take quite some time.
If you are looking to only build one specific kind of image more narrow `make` targets are available.
See `make help` for more information.

# Development

Expand Down
30 changes: 30 additions & 0 deletions image/armbian/userpatches/config-znail-nanopi-r2s.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Read build script documentation https://docs.armbian.com/Developer-Guide_Build-Options/
# for detailed explanation of these options and for additional options not listed here

KERNEL_ONLY="no" # leave empty to select each time, set to "yes" or "no" to skip dialog prompt
KERNEL_CONFIGURE="no" # leave empty to select each time, set to "yes" or "no" to skip dialog prompt
BUILD_MINIMAL="yes"
CLEAN_LEVEL="make,debs,oldcache" # comma-separated list of clean targets: "make" = make clean for selected kernel and u-boot,
# "debs" = delete packages in "./output/debs" for current branch and family,
# "alldebs" = delete all packages in "./output/debs", "images" = delete "./output/images",
# "cache" = delete "./output/cache", "sources" = delete "./sources"
# "oldcache" = remove old cached rootfs except for the newest 8 files

REPOSITORY_INSTALL="" # comma-separated list of core modules which will be installed from repository
# "u-boot", "kernel", "bsp", "armbian-config", "armbian-firmware"
# leave empty to build from sources or use local cache

DEST_LANG="C.UTF-8" # sl_SI.UTF-8, en_US.UTF-8

# advanced
EXTERNAL_NEW="prebuilt" # compile and install or install prebuilt additional packages
INSTALL_HEADERS="no" # install kernel headers package
LIB_TAG="master" # change to "branchname" to use any branch currently available.
USE_TORRENT="yes" # use torrent network for faster toolchain and cache download
DOWNLOAD_MIRROR="" # set to "china" to use mirrors.tuna.tsinghua.edu.cn
CARD_DEVICE="" # device name /dev/sdx of your SD card to burn directly to the card when done

BRANCH="current"
RELEASE="buster"
BOARD="nanopi-r2s"
HOST="znail"
63 changes: 63 additions & 0 deletions image/armbian/userpatches/customize-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# arguments: $RELEASE $LINUXFAMILY $BOARD $BUILD_DESKTOP
#
# This is the image customization script

# NOTE: It is copied to /tmp directory inside the image
# and executed there inside chroot environment
# so don't reference any files that are not already installed

# NOTE: If you want to transfer files between chroot and host
# userpatches/overlay directory on host is bind-mounted to /tmp/overlay in chroot
# The sd card's root path is accessible via $SDCARD variable.

RELEASE=$1
LINUXFAMILY=$2
BOARD=$3
BUILD_DESKTOP=$4
OVERLAY="/tmp/overlay"

EnableKernelModules() {
echo "sch_netem" >> /etc/modules
echo "br_netfilter" >> /etc/modules
}

ConfigureNetwork() {
install -v -m 700 "${OVERLAY}/update-network-interfaces" "/usr/local/bin"
install -v -m 644 "${OVERLAY}/update-network-interfaces.service" "/etc/systemd/system/"
rm -f "/etc/systemd/system/multi-user.target.wants/update-network-interfaces.service"
ln -s "/etc/systemd/system/update-network-interfaces.service" "/etc/systemd/system/multi-user.target.wants/update-network-interfaces.service"
# nanopi-r2s board support installs a udev rule to rename eth1 -> lan0.
# We don't need that.
rm -f "/etc/udev/rules.d/70-rename-lan.rules"
}

FixupHaveged() {
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866306
sed -i -e 's/DAEMON_ARGS="\?\([^"]*\)"\?/DAEMON_ARGS="\1 -d 16"/g' "/etc/default/haveged"
}

InstallZnail() {
install -d "/opt/znail"
install -v -m 600 "${OVERLAY}/requirements.txt" "/opt/znail/requirements.txt"
install -v -m 600 -D -t "/opt/znail" "${OVERLAY}"/*.whl
pushd "/opt/znail"
python3 -m venv venv
source "venv/bin/activate"
pip3 install wheel
pip3 install -r requirements.txt
pip3 install *.whl
popd
install -v -m 644 "${OVERLAY}/znail.service" "/etc/systemd/system/"
rm -f "/etc/systemd/system/multi-user.target.wants/znail.service"
ln -s "/etc/systemd/system/znail.service" "/etc/systemd/system/multi-user.target.wants/znail.service"
# Fake hub-ctrl to make znail start
rm -f "/usr/local/bin/hub-ctrl"
ln -s "/usr/bin/true" "/usr/local/bin/hub-ctrl"
}

EnableKernelModules "$@"
ConfigureNetwork "$@"
FixupHaveged "$@"
InstallZnail "$@"
2 changes: 2 additions & 0 deletions image/armbian/userpatches/lib.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PACKAGE_LIST_ADDITIONAL="$PACKAGE_LIST_ADDITIONAL bridge-utils ebtables iptables dnsmasq python3 python3-pip python3-venv python3-wheel git tcpdump vim"
PACKAGE_LIST_RM="$PACKAGE_LIST_RM smartmontools"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3c5db7c

Please sign in to comment.