BPI-R2 new image: OpenWrt 18.06.2 source code fork

Last few months I’ve been working on getting BPi R2 upstream OpenWrt support into a better state. Finally the project is in good enough shape to be shared with wider public.

Welcome aboard:

To build use the standard OpenWrt build procedure:

$ git clone https://github.com/lexa2/openwrt.git
$ cd openwrt
$ git checkout v18.06.2-bpir2-rc1
$ { echo CONFIG_TARGET_mediatek=y; echo CONFIG_TARGET_mediatek_mt7623=y; echo CONFIG_TARGET_mediatek_mt7623_DEVICE_7623n-bananapi-bpi-r2=y; } > .config
$ { echo CONFIG_DEVEL=y; echo CONFIG_CCACHE=y; } >> .config
$ make defconfig
$ make menuconfig
$ make -j16

Important: make sure to disable generation of initramfs and squashfs images in menuconfig. It is located under “Target Images —>” menu. Only ext4-based images are supported at current state. I’m working on getting squashfs support into a better shape.

Note: boot and root partition sizes are defined under “Target Images —>” menu in menuconfig. Default sizes are 32Mb for boot and 256Mb for root. It is OK to resize any of these using partition management utilities after writing the image to the SD card.

Warning: Moving the start of the boot partition is forbidden and might lead to an unbootable image. Space from the start of SD card and up to the start of the boot partition is reserved for board boot purposes and should not be touched.

In case compilation fails with some error rerun make like this: make -j1 V=s. Details will be revealed showing what’s going on and what went wrong. Upon successful compilation resulting image will be available in bin/targets/mediatek/mt7623:

$ ls -1 bin/targets/mediatek/mt7623
config.seed
openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img.gz
openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sysupgrade.tar.gz
openwrt-mediatek-mt7623-device-7623n-bananapi-bpi-r2.manifest
packages
sha256sums

Write the image to the SD card like this (assuming /dev/mmdblk1 is your SD card):

$ zcat openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img.gz | dd of=/dev/mmcblk1 bs=1M
$ sync

With luck your SD card should be ready to boot R2 into the OpenWrt 18.06.2.

P.S. Please do not report usage-related issues/quiestions to my github page - it is only for reporting code-related build system issues. Direct usage questions into this thread or better luck would be to post to OpenWrt users forum.

5 Likes

I have a problem:

<ASSERT> mt_rtc_6323.c:line 106 0
[PLFM] preloader fatal error...

Something like this

Asserts are obviously different. Providing full bootlog will be a good idea :wink: . Also please provide (and compare to what I got) the output for the following commands:

$ cd /into/your/openwrt/buildroot/

$ sha1sum ./staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/bpi-r2-preloader.bin
51f2d73d6e1e47f9b961ec86b1cd624c8bc5e5d9 *./staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/bpi-r2-preloader.bin

$ SIZE=$(stat -c '%s' ./staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/bpi-r2-preloader.bin); zcat ./bin/targets/mediatek/mt7623/openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img.gz | dd bs=1 skip=2048 count=$SIZE 2>/dev/null| sha1sum
51f2d73d6e1e47f9b961ec86b1cd624c8bc5e5d9 *-

$ zcat ./bin/targets/mediatek/mt7623/openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img.gz | dd bs=1 count=20 2>/dev/null | md5sum
e1b8ea1c8320eb08f212c6576517d7c3 *-

$ zcat ./bin/targets/mediatek/mt7623/openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img.gz | dd bs=1 skip=512 count=48 2>/dev/null | md5sum
e03b8edee9ddcc97139f664b8bc4a3a8 *-

First two command calculate and compare sha1sum for preloader. Third and fourth generate checksums for required boot signatures (SDMMC_BOOT and BRLYT).

My guess would be that your host compiler for some reason (I believe I’ve seen a bug report some time ago about u-boot failing to boot when compiled with recent gcc; wasn’t able to quickly find it now) failed to generate a proper u-boot binary.

You can check if u-boot is a culprit by downloading this one I built moment ago:
7623n-bananapi-bpi-r2-uboot-mediatek.bin (290.2 KB)

Implant it into your SD card like this:

$ dd if=7623n-bananapi-bpi-r2-uboot-mediatek.bin of=<your SD card block device> bs=1024 seek=320 conv=notrunc

Another possibility is that the preloader image I use for OpenWRT is a bad one. It work for my boards but whatever. Vendor remains silent w.r.t. my requests on what preloader image should be used with OpenWrt:

Still hadn’t got any response. You can try your luck with other preloaders from here:

Download any file having BPI-R2 in the beginning of its name and 2k at any part of the name. Then extract preloader from it and implant into your SD card:

$ zcat <file you had downloaded named like BPI-R2*2k*.gz> | dd of=preloader.bin bs=1024 count=300
$ dd if=preloader.bin of=<your SD card block device> bs=1024 seek=2 conv=notrunc

Good luck with hunting it down, please report back your findings here.

Full bootlog
[USBD] USB PRB0 LineState: 0

[USBD] USB cable/ No Cable inserted!

[PLFM] Keep stay in USB Mode
Platform initialization is ok
wait for frequency meter finish, CLK26CALI = 0x81
mt_pll_post_init: mt_get_cpu_freq = 1040000Khz
wait for frequency meter finish, CLK26CALI = 0x90
mt_pll_post_init: mt_get_bus_freq = 273000Khz
wait for frequency meter finish, CLK26CALI = 0x81
mt_pll_post_init: mt_get_mem_freq = 133250Khz
[PWRAP] pwrap_init_preloader
[PWRAP] pwrap_init
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=0,rdata=2D52
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=1,rdata=2D52
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=2,rdata=2D52
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=3,rdata=800
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=4 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=5 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=6 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=7 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=8 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=9 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] pass,index=10 rdata=5AA5
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=11,rdata=1001
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=12,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=13,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=14,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=15,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=16,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=17,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=18,rdata=B54B
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=19,rdata=2003
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=20,rdata=6A97
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=21,rdata=6A97
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=22,rdata=6A97
[PWRAP] _pwrap_init_sistrobe [Read Test] fail,index=23,rdata=6A97
[PWRAP] _pwrap_init_reg_clock
[PMIC_WRAP]wrap_init pass,the return value=0.
[pmic6323_init] Preloader Start..................
[pmic6323_init] PMIC CHIP Code = 0x2023
INT_MISC_CON: 1  TOP_RST_MISC: 1
pl pmic powerkey Press
[pmic6323_init] powerKey = 1
[pmic6323_init] is USB in = 0xB004
[pmic6323_init] Reg[0x11A]=0x1B
pmic setup LED
[pmic6323_init] Done...................
mt7623 disable long press reset ->>>>>
mt7623 disable long press reset <<<<<-
mt7623 VPA supplied by 1.0V to MT7530 ->
mt7623 VPA supplied by 1.0V to MT7530 <-
mt7623 enables RG_VGP1_EN for LCM ->
mt7623 enables RG_VGP1_EN for LCM <-
MT7623 E2 setting =>
MT7623 E2 setting <=
[PLFM] Init I2C: OK(0)
[PLFM] Init PWRAP: OK(0)
[PLFM] Init PMIC: OK(0)
[PLFM] chip[CA00]

[BLDR] [Support SD/eMMC] Build Time: 20170114-170026
==== Dump RGU Reg ========
RGU MODE:     4D
RGU LENGTH:   FFE0
RGU STA:      0
RGU INTERVAL: FFF
RGU SWSYSRST: 0
==== Dump RGU Reg End ====
RGU: g_rgu_satus:0
 mtk_wdt_mode_config  mode value=10, tmp:22000010
PL P ON
WDT does not trigger reboot
RGU mtk_wdt_init:MTK_WDT_DEBUG_CTL(590200F3)
kpd read addr: 0x0040: data:0x4001
Enter mtk_kpd_gpio_set!
kpd debug column : 0, 0, 0, 0, 0, 0, 0, 0
kpd debug row : 0, 0, 0, 0, 0, 0, 0, 0
after set KP enable: KP_SEL = 0x0 !
MTK_PMIC_RST_KEY is used for this project!
[RTC] get_frequency_meter: input=0x0, ouput=5
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=4173
[RTC] RTC 32K mode setting wrong. Enter first boot/recovery.
[RTC] bbpu = 0x40, con = 0x8000
rtc_first_boot_init
[RTC] rtc cbusy time out!!!!!
rtc_recovery_flow
[RTC] get_frequency_meter: input=0x0, ouput=5
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=5
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=4172
<ASSERT> mt_rtc_6323.c:line 106 0
[PLFM] preloader fatal error...

Checksums is similar:

D:\OpenWRT\openwrt>sha1sum ./staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/bpi-r2-preloader.bin
51f2d73d6e1e47f9b961ec86b1cd624c8bc5e5d9  ./staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/bpi-r2-pre
# dd if=openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img bs=1 count=20 2>/dev/null | md5sum
e1b8ea1c8320eb08f212c6576517d7c3  -
# dd if=openwrt-mediatek-mt7623-7623n-bananapi-bpi-r2-ext4-sdcard.img bs=1 skip=512 count=48 2>/dev/null | md5sum
e03b8edee9ddcc97139f664b8bc4a3a8  -

I compare uboot with image in hexedit.

they have no differences:

But i found diff SDMMC_BOOT and BRLYT in my old image and your

your on left

SDMMC

That’s normal - differences are in the parts that are not checked. IIRC SDMMC_BOOT signarure is 20 bytes long and BRLYT is believed to be 32 bytes long but I’m using 48 bytes from original upstream images just to be on a safe side.

Your bootlog show that everything is OK w.r.t. signatures as preloader was loaded and started but had problems dealing with onboard RTC and treated this problems as fatal.

Here is how this part of boot looks like on my board:
MTK_PMIC_RST_KEY is used for this project!
[RTC] get_frequency_meter: input=0x0, ouput=5
[RTC] get_frequency_meter: input=0x0, ouput=3968
[RTC] get_frequency_meter: input=0x0, ouput=5
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] get_frequency_meter: input=0x0, ouput=0
[RTC] bbpu = 0xD, con = 0x426
[RTC] powerkey1 = 0xA357, powerkey2 = 0x67D2
Writeif_unlock
[RTC] RTC_SPAR0=0x40
rtc_2sec_reboot_check cali=1024
[RTC] irqsta = 0x0, pdn1 = 0x0, pdn2 = 0x201, spar0 = 0x40, spar1 = 0x800
[RTC] new_spare0 = 0x0, new_spare1 = 0x1, new_spare2 = 0x1, new_spare3 = 0x1
[RTC] bbpu = 0xD, con = 0x426, cali = 0x400
SW reset with bypass power key flag
SW reset with bypass power key flag
[PLFM] WDT reboot bypass power key!
[RTC] rtc_bbpu_power_on done

So it brings us back to a question if the preloader I chose for use with OpenWrt is a proper one. Here are two other preloaders to try:
BPI-R2-EMMC-boot0-0K-0905.img (90.5 KB)
BPI-R2-720P-2k.img (92 KB)

Please try implanting each of this one by one into your SD card starting from offset 2048 (2k) and report back results. I suspect that BPI-R2-720P-2k.img might initialize onboard memory to 1333 instead of expected 1600.

I think problem occurred due to the power supply. after additional connecting +5 to OTG port botting is normal:

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               126.0M      8.9M    114.5M   7% /
tmpfs                  1011.9M     48.0K   1011.8M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev

sounds like a problem only appear on power-cycle…i’ve read about a similar problem on guthub, but did not found the issue yet…maybe trying the other preloader (1333 vs. 1600)

We had settled down that it was an insufficient power related problem for @Tohin case. PSU in this case was an old 1.5A 12V brick in unknown condition w.r.t. ripple e.t.c. Providing additional stable 5V supply on the OTG port fixed the issue immediately.

https://bugs.linaro.org/show_bug.cgi?id=3917

this is true for older u-boot (like official 2014-04) and actual gcc-crosscompiler (>=5.5)

i don’t know which uboot-code you’re using…2018-11+ is compiling fine with gcc 7/8

It is 2019-01. Seems to compile fine even under cygwin (had to do some fiddling around with my cygwin installation to make it happen though).

mhm, so not affected by this bug…

have you persistent storage (overlayfs/normal ext4 rootfs) working in your build?

Yes it does work. Changes in my fork enable ext4 as the main rootfs type for BPi-R2 target. Other changes are various fixes like enabling 2GB of RAM instead of 512Mb and auto-generation of the SD card images using in-place built u-boot and one of preloader images provided by vendor on github.

Squashfs+jffs2 in overlay is not fully supported in currentl state of my github repo. I’ve got changes baked and ready for testing making this kind of rootfs available and working but they still need a bit of polishing before pushing/releasing. Hopefully I would be able to finish polishing on weekend this or next week, we’ll see. Plan is to push this work and then forward port changes to tag 18.06.4.

1 Like

Can you share your builds?

have uploaded here: https://drive.google.com/open?id=1Gx9BuU_QBlVZjadHr0vqEjna-MYm_cj8

currently default config from lexa2 (without luci, additional kernel options)

@LeXa2 i wonder why this image is so small (only a few mb)…but it was working after unpack and write with dd-command above

Thanks. Now I have got another router (old alix 2d2) and can test BPi R2

I tried to compile openwrt from your branch, and got this errors:

maciek@ubuntu-18-04:~/openwrt$ make
WARNING: Makefile 'package/utils/busybox/Makefile' has a dependency on 'libpam', which does not exist
WARNING: Makefile 'package/utils/busybox/Makefile' has a build dependency on 'libpam', which does not exist
WARNING: Makefile 'package/network/utils/curl/Makefile' has a dependency on 'libgnutls', which does not exist
WARNING: Makefile 'package/network/utils/curl/Makefile' has a dependency on 'libopenldap', which does not exist
WARNING: Makefile 'package/network/utils/curl/Makefile' has a dependency on 'libidn2', which does not exist
WARNING: Makefile 'package/network/utils/curl/Makefile' has a dependency on 'libssh2', which does not exist
WARNING: Makefile 'package/boot/kexec-tools/Makefile' has a dependency on 'liblzma', which does not exist
WARNING: Makefile 'package/network/services/lldpd/Makefile' has a dependency on 'libnetsnmp', which does not exist
 make[1] world
 make[2] target/compile
 make[3] -C target/linux compile
 make[2] diffconfig
 make[2] package/cleanup
 make[2] package/compile
 make[3] -C package/libs/libjson-c host-compile
 make[3] -C package/libs/libubox host-compile
 make[3] -C package/system/opkg host-compile
 make[3] -C package/libs/toolchain compile
 make[3] -C package/libs/libnl-tiny compile
 make[3] -C package/libs/libjson-c compile
 make[3] -C package/utils/lua compile
 make[3] -C package/libs/libubox compile
 make[3] -C package/system/ubus compile
 make[3] -C package/system/uci compile
 make[3] -C package/network/config/netifd compile
 make[3] -C package/firmware/linux-firmware compile
 make[3] -C package/firmware/prism54-firmware compile
 make[3] -C package/kernel/linux compile
 make[3] -C package/system/ubox compile
 make[3] -C package/libs/ncurses host-compile
 make[3] -C package/libs/zlib compile
 make[3] -C package/libs/ncurses compile
 make[3] -C package/utils/util-linux compile
 make[3] -C package/libs/lzo compile
 make[3] -C package/utils/mtd-utils compile
 make[3] -C package/system/fstools compile
 make[3] -C package/system/fwtool host-compile
 make[3] -C package/system/fwtool compile
 make[3] -C package/system/procd compile
 make[3] -C package/system/usign host-compile
 make[3] -C package/utils/jsonfilter compile
 make[3] -C package/system/openwrt-keyring compile
 make[3] -C package/system/usign compile
 make[3] -C package/base-files compile
 make[3] -C package/boot/uboot-envtools compile
 make[3] -C package/boot/uboot-mediatek compile
make -r world: build failed. Please re-run make with -j1 V=s or V=sc for a higher verbosity level to see what's going on
/home/maciek/openwrt/include/toplevel.mk:216: recipe for target 'world' failed
make: *** [world] Error 1

anyone can help me what should I do?

I’m using this: v18.06.2-cygwin-bpir2-rc1 branch

please do “make -j1 V=s”

./scripts/feeds update -a
./scripts/feeds install -a

To install the depencies…

I had install the dependencies then (log is to long I had to attach it as text file)

openwrt.txt (239,5 KB)

unable to execute 'swig': No such file

You need to install swig