# NanoPi Neo2 Porting Mender to Openwrt

**URL:** <https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300>\
**Category:** General Discussions\
**Tags:** yocto, thud\
**Created:** [March 5, 2019, 7:35pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300 "2019-03-05T19:35:27Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 1:40pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/21 "2019-03-08T13:40:52Z")

</div>

Hi Mirzak;

The differences between the updated RPi (config\_mender\_defines.h) were (now fixed):

- \*\_HEX values were expressed as 0xN as opposed to N
- commented: /\* #define MENDER\_MTD\_UBI\_DEVICE\_NAME “” \*/
- #define MENDER\_BOOTENV\_SIZE 0x4000 is missing and value was inherited from config:  
by config\_mender\_defines.h:  
/\* For sanity checks. _/  
/_ #define MENDER\_BOOTENV\_SIZE ${BOOTENV\_SIZE} \*/  
#define MENDER\_BOOTENV\_SIZE CONFIG\_ENV\_SIZE

Old:Symbol: ENV\_SIZE [=0x20000]  
│ Type : hex  
│ Prompt: Environment Size  
│ Location:  
│ (1) -\> Environment  
│ Defined at board/theobroma-systems/lion\_rk3368/Kconfig:15  
│ Depends on: ARM [=y] && ARCH\_ROCKCHIP [=n] && ROCKCHIP\_RK3368 [=n] && TARGET\_LION\_RK3368 [=n]

Added this to defconfig: echo CONFIG\_ENV\_SIZE=0x4000 \>\> $(PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig

New:Symbol: ENV\_SIZE [=0x4000]  
│ Type : hex  
│ Prompt: Environment Size  
│ Location:  
│ (1) -\> Environment  
│ Defined at board/theobroma-systems/lion\_rk3368/Kconfig:15  
│ Depends on: ARM [=y] && ARCH\_ROCKCHIP [=n] && ROCKCHIP\_RK3368 [=n] && TARGET\_LION\_RK3368 [=n]

As a sanity check: uboot/.config contains “CONFIG\_ENV\_SIZE=0x4000”

The reason I am getting ENV\_SIZE from uboot config is that I am trying to cover the entire sunxi family and avoid as many target specific files as I can.

Updated readme and config\_mender\_defines.h in tarball.

Result: same link errors

Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 1:44pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/22 "2019-03-08T13:44:22Z")

</div>

Didn’t notice your patches, downloading now…

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 2:26pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/23 "2019-03-08T14:26:15Z")

</div>

Hi Marek;

I have integrated your patches. Same link failures. Be aware that the failures happen AFTER passing the size test.

To see what I am seeing, trim some features, suggestions:  
echo CONFIG\_CMD\_MISC=n \>\> (PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig echo CONFIG\_VIDEO\_BPP8=n \>\> (PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig  
echo CONFIG\_VIDEO\_BPP16=n \>\> (PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig echo CONFIG\_CMD\_LOADB=n \>\> (PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig  
echo CONFIG\_CMD\_LOADS=n \>\> $(PKG\_BUILD\_DIR)/configs/nanopi\_neo2\_defconfig

Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 8, 2019, 2:30pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/24 "2019-03-08T14:30:13Z")

</div>

I think the trimming is causing the link errors.

I tried @MarekBelisko patches as well, but the way I worked around the size limit was by changing in include/configs/sunxi-common.h:

```auto
/*
 * This is actually (CONFIG_ENV_OFFSET -
 * (CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512)), but the value will be used
 * directly in a makefile, without the preprocessor expansion.
 */
#define CONFIG_BOARD_SIZE_LIMIT 0x7e000

```

to

```auto
/*
 * This is actually (CONFIG_ENV_OFFSET -
 * (CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512)), but the value will be used
 * directly in a makefile, without the preprocessor expansion.
 */
#define CONFIG_BOARD_SIZE_LIMIT 0x37e000

```

It is safe to do this, because we have changed the ENV\_OFFSET to `0x400000`, and the limit is there to not overflow the U-boot binary to overlap with the ENV\_OFFSET. The default value that they have in U-boot is silly low and that is why it is quite easy to hit it, but I guess it is hard to change in upstream because it would break functionality.

It compiled all the way now with my changes above.

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [March 8, 2019, 2:44pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/25 "2019-03-08T14:44:16Z")

</div>

@rossbcan I also added patch with dropped options to my patches and compile just fine ([patches)](https://www.dropbox.com/s/u5xo5h7yqxazjmi/mbox_tst_fixes.tar.gz?dl=0)

Maybe you have cached something on openwrt build system, pls try to clean build or so aftre applying patches (or use @mirzak proposal). Thanks.

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 3:49pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/26 "2019-03-08T15:49:38Z")

</div>

I have been cleaning u-boot b4 each build. I have changed CONFIG\_BOARD\_SIZE\_LIMIT as suggested by mirzak. The extra patch you provided just disables some of the features which I was already disabling, but prefer to keep, so I now pass the size test with no features disabled.

Still failing, same patches and config as you. That leaves two possibilities: toolchain and/or buildsystem state. So going to do a dirclean and complete rebuild, which takes several hours. Will advise.

Updated instructions, files and patches at [https://www.rossco.org/Downloads/OpenWrt/Mender\_U-boot\_New.tar.gz](https://www.rossco.org/Downloads/OpenWrt/Mender_U-boot_New.tar.gz)

Many thanks & Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 8, 2019, 6:26pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/27 "2019-03-08T18:26:21Z")

</div>

I created a branch here with the patches,

```
https://github.com/mirzak/u-boot-mender/commits/nanopi-neo2-2018.11 

```

I used an aarch64 tool chain from here,

[https://toolchains.bootlin.com/](https://toolchains.bootlin.com/)

And did:

```auto
export ARCH=aarch64
export CROSS_COMPILE=aarch64-linux-
git clone https://github.com/mirzak/u-boot-mender -b nanopi-neo2-2018.11
cd u-boot-mender
make nanopi_neo2_defconfig
make

```

Hope it helps.

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 6:58pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/28 "2019-03-08T18:58:41Z")

</div>

My build from clean failed in same manner which leaves the openwrt toolchain as the likely culprit.  
Thanks for you effort creating the git repo…  
I will do this:  
1 - alter my makefile to use the toolchain suggested, failing that  
2 - The full monty, using your git repo

Since I am creating a Mender solution for openwrt (which they will not accept without full integration), if this interests you, I can setup to allow you to poke around my buildsystem, provide simple instructions, if I have your ssh public key.

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 7:09pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/29 "2019-03-08T19:09:33Z")

</div>

Oops: Just checked the available versions for the toolchain.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/453b701f0444db4495305856738c8df1a2764ec2.png)

Here’s what I have:  
binutils-2.31.1 - OK  
gcc-7.4.0  
glibc-2.27  
Linux OpenWrt-NEO2 4.14.99 #0 SMP PREEMPT Thu Feb 14 20:43:07 2019 aarch64 GNU/Linux

So, I believe that I can compile using the suggested tools. Not so sure that it will play nice with the rest of openwrt.

What do you think?

Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 8, 2019, 7:11pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/30 "2019-03-08T19:11:26Z")

</div>

Note that I used the “stable” one when testing.

> What do you think?

I know very little about the OpenWRT build system so hard to comment.

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 8, 2019, 7:32pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/31 "2019-03-08T19:32:49Z")

</div>

Just remembered that u-boot is static, so no interaction with openwrt libraries, kernel (apart from loading), effectively standalone. So, I should be able to swap toolchain to build it, with no dire consequences.

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [March 12, 2019, 8:36am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/32 "2019-03-12T08:36:24Z")

</div>

@rossbcan any update on this issue? Does update of toolchain helps? Thanks.

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 12, 2019, 10:23am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/33 "2019-03-12T10:23:49Z")

</div>

> [@mirzak](#):
>
> aarch64-linux-

In openwrt, swapped out toolchain (for u-boot) to use aarch64-linux- tools from [bootlin.com](http://bootlin.com). Failed with same link errors. Compiled without openwrt patches, using both OpenWrt, Mender recommended toolchains. Same link errors. Mender patches appear to take openwrt u-boot into uncharted territory.

My production schedule forces me to take the out of tree u-boot / flash script approach using bootlin tools and do proper openwrt / Mender integration at some point in the future (give up for now).

We are proceeding with Mender. When I am done, will provide you with scripts and files for the out of tree approach.

I have two issues / suggestions for your neo2 git repo:

- The size patch (#define CONFIG\_BOARD\_SIZE\_LIMIT 0x37e000) is missing, so fails on size.
- Consider adding bl31.bin (secure boot) to repo

Mender integration is my highest priority task, so won’t take long.

I repeat my offer to provide access (your ssh key) to my build system, or support so you can replicate if you decide to pursue the link failures.

Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [March 12, 2019, 10:52am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/34 "2019-03-12T10:52:19Z")

</div>

@rossbcan there must be something wrong with openwrt build system. Can you try to enable verbose build for u-boot if it is build with correct toolchain and share log. As we both have no issues with building out of tree there must be something in openwrt build system which change something and thus u-boot build fails.

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 12, 2019, 11:25am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/35 "2019-03-12T11:25:25Z")

</div>

I also suspect something in the OpenWRT environment is causing this, because the out-of-tree build works. This could mean that OpenWRT applies additional patches that might conflict with the Mender patches, or applies other compile flags that exposes something that you normally do not see or builds different targets.

So I would try to investigate the verbose build log of U-boot and compare to an out-of-tree build to compare as suggested by @MarekBelisko

I do not know much of the OpenWRT build system to be able more specific and ssh access to the environment would not do me much good either as the patches have been verified to work out-of-tree and also together with Yocto (though slightly different bootloader version).

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 12, 2019, 11:46am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/36 "2019-03-12T11:46:48Z")

</div>

mirzak;

I agree with your conclusion. Have enabled verbose and no obvious problems. As stated: my production schedule prohibits spending a lot of time of full Mender integration.

Here’s the verbose logs for both openwrt and bootlin toolchain builds:

uboot\_bootlin\_compiler.txt  
uboot\_openwrt\_compiler.txt

at www dot rossco dot org/Downloads/OpenWrt/  
(getting, sorry, cannot post a link to that location)

Regards;  
Bill

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 12, 2019, 11:48am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/37 "2019-03-12T11:48:28Z")

</div>

I have fixed your permissions and can you retry adding the links

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 12, 2019, 11:52am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/38 "2019-03-12T11:52:44Z")

</div>

[https://www.rossco.org/Downloads/OpenWrt/uboot\_bootlin\_compiler.txt](https://www.rossco.org/Downloads/OpenWrt/uboot_bootlin_compiler.txt)  
[https://www.rossco.org/Downloads/OpenWrt/uboot\_openwrt\_compiler.txt](https://www.rossco.org/Downloads/OpenWrt/uboot_openwrt_compiler.txt)

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 12, 2019, 12:01pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/39 "2019-03-12T12:01:10Z")

</div>

As suspected there are patches that are applied by OpenWRT,

```auto
Applying ./patches/002-add-olimex-a13-som.patch using plaintext: 
patching file configs/OLIMEX_A13_SOM_defconfig

Applying ./patches/003-add-theobroma-a31-pangolin.patch using plaintext: 
patching file arch/arm/dts/Makefile
patching file arch/arm/dts/sun6i-a31.dtsi
patching file arch/arm/dts/sun6i-a31-pangolin.dts
patching file configs/pangolin_defconfig
patching file arch/arm/mach-sunxi/Kconfig

Applying ./patches/062-A20-improve-gmac-upload.patch using plaintext: 
patching file configs/A20-OLinuXino-Lime2_defconfig

Applying ./patches/091-sun6i-sync-PLL1-multdiv-with-Boot1.patch using plaintext: 
patching file arch/arm/mach-sunxi/clock_sun6i.c

Applying ./patches/093-sun6i-fix-PLL-LDO-voltselect.patch using plaintext: 
patching file arch/arm/mach-sunxi/clock_sun6i.c
patching file arch/arm/include/asm/arch-sunxi/prcm.h

Applying ./patches/100-sun6i-alternate-on-UART2.patch using plaintext: 
patching file arch/arm/include/asm/arch-sunxi/gpio.h

Applying ./patches/101-sun6i-support-console-on-UART2.patch using plaintext: 
patching file arch/arm/mach-sunxi/board.c
patching file include/configs/sunxi-common.h

Applying ./patches/102-sunxi-make_CONS_INDEX-configurable.patch using plaintext: 
patching file arch/arm/mach-sunxi/Kconfig

Applying ./patches/200-mkimage-check-environment-for-dtc-binary-location.patch using plaintext: 
patching file tools/fit_image.c

Applying ./patches/210-sunxi-deactivate-binman.patch using plaintext: 
patching file Makefile
patching file arch/arm/Kconfig

Applying ./patches/221-compatible-old-dtc.patch using plaintext: 
patching file scripts/Kbuild.include
patching file scripts/Makefile.extrawarn

Applying ./patches/230-disable-axp209-on-a13-olinuxino.diff using plaintext: 
patching file configs/A13-OLinuXino_defconfig

Applying ./patches/240-sun50i-h5-Orange-Pi-Zero-Plus-Fix-SdCard-detection.patch using plaintext: 
patching file configs/orangepi_zero_plus_defconfig

```

So definitely some kind of conflict with above and the patches that are applied at the next stage (the mender patches)

Also based on the log it seems that the SPL build is failing, which could mean that one of the options enabled trough Mender might need a `#ifndef CONFIG_SPL_BUILD` guard.

If you can upload the OpenWRT patches (from above log) somewhere I could test this and probably would be re-producible in a out-of-tree build

---

<div class="post-metadata">

**Author:** ![rossbcan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/rossbcan/32/1441_2.png) [@rossbcan](https://hub.mender.io/u/rossbcan)\
**Post date:** [March 12, 2019, 12:19pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/40 "2019-03-12T12:19:54Z")

</div>

I have built (both toolchains) without openwrt patches - same result. The Mender patches have been refreshed to apply properly after the openwrt patches.

Here are the openwrt and my refreshed Mender patches:  
[https://www.rossco.org/Downloads/OpenWrt/OpenWrt\_Mender\_patches.tar.gz](https://www.rossco.org/Downloads/OpenWrt/OpenWrt_Mender_patches.tar.gz)

The patches/\* are openwrt patches, to be applied first  
The files/\* are Mender patches, to be applied second

Really appreciate you interest, since my preferred course is also full openwrt / Mender integration.

Regards;  
Bill

[Previous page](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300.md?page=1)

[Next page](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300.md?page=3)
