NanoPi Neo2 Porting Mender to Openwrt

Hi;

I am in the process of porting Mender for the NanoPi Neo2 using openwrt. Yocto is not an option, but do have the go compiler available. I am starting with u-boot, since porting the Mender app seems straightforward.

I am following these guides:
https://docs.mender.io/1.7/devices (Yocto buildsystem)
https://mender.io/blog/porting-mender-to-a-non-yocto-build-system

Thus far, I have accomplished this:

  • added “config_mender_defines.h” to uboot/include
  • added CONFIG_BOOTCOUNT_LIMIT=y, CONFIG_BOOTCOUNT_ENV=y, CONFIG_ENV_IS_IN_MMC=y to default uboot config for my board (nanopi_neo2_defconfig)

When compiling uboot, get this error:
“include/config_mender.h:59:5: error: #error CONFIG_ENV_OFFSET is not the same as MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_1. Either set it to the same value (check for example in the defconfig file), or make sure it is not defined at all…”

Looking into this, MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_1 appears to come from the uboot environment and I see no config value for it.

Question: what should I set CONFIG_ENV_OFFSET to, to get past this?, Or, is there something else I should be doing?

If this question is in wrong place, please move it and let me know.

Thanks;
Bill

You can get some inspiration about values in : https://github.com/mendersoftware/uboot-mender/commits/mender-rpi-2017.09 (specifically commit https://github.com/mendersoftware/uboot-mender/commit/5226dbc3870fd621d8a5fcd3463e0b16a88c7698 - please note that it’s extracted from generated yocto image). Basically mender using for storing u-boot env unpartitioned (raw) sdcard space with specific offset + also same for redundant env. I think you can copy values from mentioned commit but please adjust then partition layout (keep ~ 10M of free space at the beginning of SDcard).

Thanks; That was incredibly helpful, in terms of defines I had not yet got to.

I still have the error above, here’s my updated config_mender_defines.h:

#ifndef HEADER_CONFIG_MENDER_DEFINES_H
#define HEADER_CONFIG_MENDER_DEFINES_H

#include <generated/autoconf.h>

/* Shell variables */
#define MENDER_BOOT_PART_NUMBER 1
#define MENDER_BOOT_PART_NUMBER_HEX $MENDER_BOOT_PART_NUMBER_HEX
#define MENDER_ROOTFS_PART_A_NUMBER 2
#define MENDER_ROOTFS_PART_A_NUMBER_HEX $MENDER_ROOTFS_PART_A_NUMBER_HEX
#define MENDER_ROOTFS_PART_B_NUMBER 3
#define MENDER_ROOTFS_PART_B_NUMBER_HEX $MENDER_ROOTFS_PART_B_NUMBER_HEX
#define MENDER_UBOOT_STORAGE_INTERFACE “mmc”
#define MENDER_UBOOT_STORAGE_DEVICE 0

/* BB variables. */
#define MENDER_STORAGE_DEVICE_BASE “/dev/mmcblk0”
#define MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_1 0x400000
#define MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_2 0x800000
#define MENDER_ROOTFS_PART_A_NAME “/dev/mmcblk0p2”
#define MENDER_ROOTFS_PART_B_NAME “/dev/mmcblk0p3”
#define MENDER_MTD_UBI_DEVICE_NAME “”

/* For sanity checks. /
/
#define MENDER_BOOTENV_SIZE ${BOOTENV_SIZE} */
#define MENDER_BOOTENV_SIZE CONFIG_ENV_SIZE

#define MENDER_BOOT_KERNEL_TYPE “bootm”
#define MENDER_KERNEL_NAME “uImage”
#define MENDER_DTB_NAME “dtb”
#define MENDER_UBOOT_PRE_SETUP_COMMANDS “$MENDER_UBOOT_PRE_SETUP_COMMANDS”
#define MENDER_UBOOT_POST_SETUP_COMMANDS “$MENDER_UBOOT_POST_SETUP_COMMANDS”

#endif /* HEADER_CONFIG_MENDER_DEFINES_H */

do I need the defines defined in terms of “$MENDER_*”?

Thanks;
Bill

set CONFIG_ENV_OFFSET = 0x400000 (same as MENDER_UBOOT_ENV_STORAGE_DEVICE_OFFSET_1)
U-boot compiled OK, now have this error, which means I have to do my math…

start=$(aarch64-openwrt-linux-gnu-nm u-boot | grep __rel_dyn_start | cut -f 1 -d ’ '); end=$(aarch64-openwrt-linux-gnu-nm u-boot | grep __rel_dyn_end | cut -f 1 -d ’ '); tools/relocate-rela u-boot-nodtb.bin 0x4a000000 $start $end
u-boot-nodtb.bin exceeds file size limit:
limit: 516096 bytes
actual: 522544 bytes
excess: 6448 bytes

apparently, u-boot on arm64 has a bloat issue:
http://u-boot.10912.n7.nabble.com/PATCH-00-11-sunxi-arm64-binary-size-fixes-td315480.html

We do have patches for sunxi boards in Yocto,

Some inspiration hopefully

2 Likes

You guys have been incredibly helpful, THANKS!

Still dealing with this:
start=$(aarch64-openwrt-linux-gnu-nm u-boot | grep __rel_dyn_start | cut -f 1 -d ’ '); end=$(aarch64-openwrt-linux-gnu-nm u-boot | grep __rel_dyn_end | cut -f 1 -d ’ '); tools/relocate-rela u-boot-nodtb.bin 0x4a000000 $start $end
u-boot-nodtb.bin exceeds file size limit:
limit: 516096 bytes
actual: 521000 bytes
excess: 4904 bytes
make[3]: *** [u-boot-nodtb.bin] Error 1

but, thanks to your help, I am days ahead

I’m trying to integrate mender for the Nanopi Neo Plus 2 right now and have the same problem with the u-boot size.
I found the patch that fixed the size issue for u-boot 2018.01, see: http://u-boot.10912.n7.nabble.com/PATCH-00-11-sunxi-arm64-binary-size-fixes-td315480.html

The commit was later reverted (2018.05): https://github.com/u-boot/u-boot/commit/d14db11d76e154a03e3fbaedb2fe4f13da7bb65f#diff-e249c6d66723fe56e388892f0fa8e482

So you can try to use u-boot 2018.03

I’m sticking to u-boot 2018-11 (current openwrt trunk) and had to refresh the Mender patches:
[root@localhost trunk]# ls Custom/package/boot/uboot-sunxi/files/*.patch
Custom/package/boot/uboot-sunxi/files/0001-env-Kconfig-remove-defaults-for-SUNXI.patch
Custom/package/boot/uboot-sunxi/files/0002-configs-sunxi-add-Mender-required-options.patch
Custom/package/boot/uboot-sunxi/files/0002-Generic-boot-code-for-Mender.patch
Custom/package/boot/uboot-sunxi/files/0003-Integration-of-Mender-boot-code-into-U-Boot.patch

I got around the u-boot size issue by un-reverting some of the (feature removal) patches in mrsch’s link above.

now, I am stuck at many gpio* link failures, for example:
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_mmc_getcd_legacy': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/mmc/sunxi_mmc.c:478: undefined reference togpio_get_value’

@mrsch: what is your build system?

any insight?
Thanks;
Bill

Had a discussion with my employer. They are willing to place my openwrt changes in public domain. Are you interested in hosting this and maintaining once done?

@rossbcan did you try to build u-boot without mender patches first? It looks like that there are some missing symbols which should be fixable. I’ll check tomorrow and get back to you. Thanks.

Yes, It builds correctly without patches. Currently pursuing whether CONFIG_DM_MMC should be set
Here’s the errors (legacy is what make me suspect DM issues):
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_mmc_getcd_legacy': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/mmc/sunxi_mmc.c:478: undefined reference to gpio_get_value’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function mmc_resource_init': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/mmc/sunxi_mmc.c:87: undefined reference to gpio_request’
aarch64-openwrt-linux-gnu-ld.bfd: /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/mmc/sunxi_mmc.c:90: undefined reference to gpio_direction_input' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function ns16550_serial_setbrg’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:326: undefined reference to dev_get_priv' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function ns16550_serial_pending’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:306: undefined reference to dev_get_priv' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function ns16550_serial_putc’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:286: undefined reference to dev_get_priv' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function ns16550_serial_getc’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:316: undefined reference to dev_get_priv' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function ns16550_serial_probe’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:339: undefined reference to dev_get_priv' aarch64-openwrt-linux-gnu-ld.bfd: /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/serial/ns16550.c:347: undefined reference to dev_get_platdata’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_gpio_set_value': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:195: undefined reference to dev_get_platdata’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_gpio_get_value': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:182: undefined reference to dev_get_platdata’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_gpio_get_function': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:204: undefined reference to dev_get_platdata’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_gpio_direction_output': /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:171: undefined reference to dev_get_platdata’
aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o:/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:161: more undefined references to dev_get_platdata' follow aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function gpio_sunxi_probe’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:264: undefined reference to dev_get_uclass_priv' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function gpio_sunxi_bind’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:287: undefined reference to dev_get_driver_data' aarch64-openwrt-linux-gnu-ld.bfd: /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:296: undefined reference to devfdt_get_addr’
aarch64-openwrt-linux-gnu-ld.bfd: /home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:308: undefined reference to device_bind' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_gpio_xlate’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:221: undefined reference to device_get_child' aarch64-openwrt-linux-gnu-ld.bfd: drivers/built-in.o: in function sunxi_name_to_gpio’:
/home/rossb/OpenWrt/trunk/build_dir/target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11/drivers/gpio/sunxi_gpio.c:154: undefined reference to `gpio_lookup_name’

I’m bit confused now. Without mender patches it builds or not (in previous post it still shows some issues)? Because mender didn’t add anything to sunxi mmc stuff. Do you use nanopi_neo2_defconfig and which toolchain version? Thanks.

@rossbcan can you please share updated patches. Thanks.

Hi Marek;

As requested…
Instructions, config changes, config_mender_defines.h, patches:
https://www.rossco.org/Downloads/OpenWrt/Mender_U-boot.tar.gz

Questions answered:

  • Using nanopi_neo2_defconfig with additions defined in ReadMe.rtf (in tar.gz, above)
  • Toolchain: toolchain-aarch64_cortex-a53_gcc-7.4.0_glibc
  • Target: target-aarch64_cortex-a53_glibc/u-boot-nanopi_neo2/u-boot-2018.11
  • Build or not: Without Mender patches, (with and without defconfig changes) builds OK. With Mender patches, two issues. (a) size, stripped some features (extra defconfig, ReadMe.rtf), (b) once past size issue, gpio* related link errors as above.

Caveat: apply patches after regular u-boot patches.

Thanks & Regards;
Bill

Had a quick look at your patches, this is a bit strange

/* Shell variables */
#define MENDER_BOOT_PART_NUMBER 1
#define MENDER_BOOT_PART_NUMBER_HEX $MENDER_BOOT_PART_NUMBER_HEX
#define MENDER_ROOTFS_PART_A_NUMBER 2
#define MENDER_ROOTFS_PART_A_NUMBER_HEX $MENDER_ROOTFS_PART_A_NUMBER_HEX
#define MENDER_ROOTFS_PART_B_NUMBER 3
#define MENDER_ROOTFS_PART_B_NUMBER_HEX $MENDER_ROOTFS_PART_B_NUMBER_HEX
#define MENDER_UBOOT_STORAGE_INTERFACE "mmc"
#define MENDER_UBOOT_STORAGE_DEVICE 0

The MENDER_ROOTFS_PART_A/B_NUMBER_HEX should be assigned a number, or is $MENDER_ROOTFS_PART_A_NUMBER_HEX something specific to OpenWRT, meaning that they will resolved to something somehow?

Same applies to the MENDER_UBOOT_PRE/POST_SETUP_COMMANDS commands.

Also in 0001-env-Kconfig-remove-defaults-for-SUNXI.patch you are missing this change,

Thanks mirzak;

The $MENDER_ defines came from Mender and are not part of openwrt. I note from the RPi example (add config_mender_defines.h · mendersoftware/uboot-mender@5226dbc · GitHub) that *_HEX (also from Mender) are not defined. Perhaps I should remove all of them?

I have updated the tarfile (config_mender_defines.h, 0001-env-Kconfig-remove-defaults-for-SUNXI.patch), cleaned and rebuilt.

Same gpio*, dev* link errors as shown above

Regards;
Bill

This is a better reference and is on a “closer” U-boot version,

So keep them.

@rossbcan I have refreshed patches and build fine (I still get issue with max size but you should have workaround for that). Psl test attached patches