Skip to content

Instantly share code, notes, and snippets.

@yoursunny
Created August 27, 2019 11:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoursunny/36270b072a595cc5e9b57dccb64c2015 to your computer and use it in GitHub Desktop.
Save yoursunny/36270b072a595cc5e9b57dccb64c2015 to your computer and use it in GitHub Desktop.
OpenWrt 18.06.4 SD eMMC image for Banana Pi R2
#!/bin/bash
# OpenWrt 18.06.4 for Banana Pi R2
# Make SD or eMMC image from official kernel and rootfs images.
# Inspired by https://github.com/BPI-SINOVOIP/openwrt/commit/b4dfaeca4d33ad88364bfb7df353b3dfca2883fe
set -e
KIND=$1
if [[ $KIND != sd ]] && [[ $KIND != emmc ]]; then
echo Usage: $0 '<sd|emmc> [outfile]' >/dev/stderr
exit 2
fi
OUTFILE=${2:-bpi-r2-$KIND.bin}
MTKBASE=https://github.com/BPI-SINOVOIP/openwrt/raw/b4dfaeca4d33ad88364bfb7df353b3dfca2883fe/staging_dir/target-arm_cortex-a7%2Bneon-vfpv4_musl_eabi/image/
PRELOADER=mtk-bpi-r2-preloader-$KIND.bin
UBOOT=mtk-bpi-r2-uboot.bin
OPENWRTVER=18.06.4
OPENWRTBASE=https://downloads.openwrt.org/releases/$OPENWRTVER/targets/mediatek/mt7623/
KERNEL=openwrt-$OPENWRTVER-mediatek-mt7623-7623n-bananapi-bpi-r2-initramfs-kernel.bin
ROOTFS=openwrt-$OPENWRTVER-mediatek-mt7623-7623n-bananapi-bpi-r2-squashfs-sysupgrade.bin
[[ -f $PRELOADER ]] || wget $MTKBASE/$PRELOADER
[[ -f $UBOOT ]] || wget $MTKBASE/$UBOOT
[[ -f $KERNEL ]] || wget $OPENWRTBASE/$KERNEL
[[ -f $ROOTFS ]] || wget $OPENWRTBASE/$ROOTFS
rm -f $OUTFILE
dd bs=1024 if=$PRELOADER of=$OUTFILE seek=0
dd bs=1024 if=$UBOOT of=$OUTFILE seek=320
dd bs=1024 if=$KERNEL of=$OUTFILE seek=2048
dd bs=1024 if=$ROOTFS of=$OUTFILE seek=67584
@gotthardanger
Copy link

Could you please explain, howto calculate the offset for $ROOTFS? Because I created my own kernel and rootfs, I get unusable image, if I replace kernel.bin and sysupgrade.bin by my own.

@yoursunny
Copy link
Author

Could you please explain, howto calculate the offset for $ROOTFS?

Sadly, I don't know. It's copied from the "inspired by" commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment