SD card preparation for OpenWRT

I’ve bought Banana Pi R2 with plan to make it into my very custom OpenWRT-based router. This is my second type of Linux-friendly board, first one I had were Raspberry Pi 2, 3 and Zero where I am familiar with booting procedure and preparing the custom Linux systems with Buildroot. I’ve played a bit with the booting ecosystem of R2 (100MB for magic bytes, preloader and uboot, BPI-BOOT vfat partition for kernel and uboot config and BPI-ROOT ext4 for rootfs), using files from BPI-files github repository ( Thanks to Uboot and boot-root partition scheme I am able to launch Buildroot-compiled system, as long as it consists of kernel (eg. zImage) and root image I can flash to the second partition.

However, after compiling OpenWRT github repo for R2 (, the only thing I get *-initramfs-kernel.bin file. I’ve checked beginning of that file and it significantly differs from the files meant to be flashed in case of LEDE repository (BPI-R2 OpenWRT(LEDE) Support). SDMMC_BOOT magic bytes are missing, there is no preloader nor uboot starting with 2048 byte of the file.

After flashing LEDE’s image on the SD card I have no access to partitions where I could possibly put the bin file from my Linux desktop. How are things looking like in case of OpenWRT on Banana Pi? It clearly isn’t the same situation as in case where BPI-BOOT is available, yet the compiled bin file has to be placed in the SD card somehow. I admit I didn’t play nor compile the system with squashfs and jffs2 yet so I’m new to how Linux and OpenWRT handle that. If I had access to uboot configuration file, I guess I could figure it out from the kernel arguments, but as I said, there is no such file - at least not in an easily accessible form. :slight_smile:

I’m wondering how one could prepare an SD card from scratch by partitioning it and flashing necessary images from BPI-files repository (either with dd or bpi-tools) and finally use OpenWRT’s bin file to somehow put it on the SD card so that it boots up after plugging into the BPI? How does jffs2 partition handling and configuration look like (specifying size, location on the SD card etc)?

you have to flash the bin/img directly to card, replacing your existing partition sheme

openwrt does not use partitions because Partitiontables are for larger storages (>x GB)…a “normal router” has only a few (maybe 100) MB for storing OS.

that makes it hard to replace kernel or other things in this “image” and imho you cannot use the additional space

Bin file from the OpenWRT 18.06 repo cannot be flashed to the card - it lacks necessary things like the magic bytes and preloader that would make it possible for BPi to recognize and boot it. Unlike LEDE’s repository, the valid bootable img file is not created after compilation of 18.06 repo. I’m looking for a way to create such image manually from scratch, having OpenWRT compiled bin and BPi pre-made images with things like Uboot, preloader, magic bytes etc. I’ve been trying to figure out how it was done in LEDE repo so that after opening Buildroot’s menu (make menuconfig) there is Uboot entry in Bootloader branch which can be chosen and produces img as a result of make, but so far I didn’t find how to do a similar thing with OpenWRT.

I’m not planning to use all the SD card nor emmc size - from what I heard, JFFS doesn’t handle large partitions well, at least in terms of performance. According to boot log, OpenWRT initializes JFFS space during initial boot and after invoking firstboot command. I’m wondering if it’s possible to somehow adjust the size of that space and if not then how it is determined.

afair @jackzeng currently tries to include my uboot in openwrt because old uboot does nor work (imho it does not compile woth gcc 5.5+)

sorry for the late openwrt18.06 on R2, image and code will come soon.


1 Like

I’ve seen your commit in the repository @Jackzeng , thank you guys for your work! Not only I can compile working OpenWRT 18.06 for my R2, now I also know how to assemble all the built files into writeable image - no article nor documentation is a better learning material than a working example. Although the second image I compiled after adding few packages doesn’t seem to go past UBoot (shows the “couldn’t find kernel” error), I’m still looking into it. Thanks again!

1 Like

There is a small problem. OpenWRT compiled with the new UBoot script doesn’t seem to utilize overlayfs to persist data. There is interesting difference I managed to observe between compiled OpenWRT and LEDE which I downloaded from this forum (BPI-R2 new image: BPI-R2 OpenWrt(LEDE) Souce code : 2018-05-09). The difference is kernel command line, printed after starting kernel. For OpenWRT it is:

earlyprintk console=ttyS0,115200 rootfstype=squashfs,jffs2

while for LEDE it is much longer:

earlyprintk block2mtd.block2mtd=/dev/mmcblk1,65536,RootFs,5 mtdparts=RootFs:512k(mbr)ro,512k(uboot)ro,512k(config)ro,512k(factory)ro,32M(kernel),32M(recovery),1024M(rootfs),2048M(usrdata),-(bmtpool) rootfstype=squashfs,jffs2

I tried to hardcode the latter one in the kernel to be used during bootup (using kernel_menuconfig options) but although the new kernel arguments get displayed on startup, there is no persistence between reboots.

Here is the output for df and mount commands on the compiled OpenWRT:


For reference, here is the output from LEDE:


hai… do you have image for openwrt with kernel 4.9??