# 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:** 4

<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 19, 2019, 9:35am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/61 "2019-03-19T09:35:30Z")

</div>

> [@kacf](#):
>
> SRC\_URI

what’s SRC\_URI?

---

<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 19, 2019, 9:40am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/62 "2019-03-19T09:40:45Z")

</div>

`SRC_URI` is a Yocto thing and you can ignore that.

@kacf, I was primarily asking about this (below),

```auto
“ClientProtocol”: “http”,
“HttpsClient”: {
“Certificate”: “”,
“Key”: “”
},

```

> FYI and IMHO. Because golang is used for the mender app, it is bloated (6M+) by the statically included go libraries. This will be an impediment to mender usage on storage “challenged” devices. Suggestion: Create a C/C++ version of the mender app which can be linked to already existing standard libraries, reducing size, allowing deeper penetration into the embedded market. I’m sure you have heard this before.

@rossbcan, yes heard this before 🙂

---

<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 19, 2019, 10:11am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/63 "2019-03-19T10:11:08Z")

</div>

is this the artifact format I should be using?

> <https://github.com/mendersoftware/mender-artifact/blob/2.4.0/Documentation/artifact-format-v3.md>

…and(faint hope) has anyone created a bash script for packaging artifacts?

---

<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 19, 2019, 10:13am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/64 "2019-03-19T10:13:49Z")

</div>

Yes that is the artifact format.

You can use the “mender-artifact” CLI tool to create these,

> **[mendersoftware/mender-artifact](https://github.com/mendersoftware/mender-artifact)**
>
> Library for managing Mender artifact files. Contribute to mendersoftware/mender-artifact development by creating an account on GitHub.

You typically run something like this,

```auto
mender-artifact write rootfs-image \
    --update ${BINARIES_DIR}/rootfs.ext4 \
    --output-path ${BINARIES_DIR}/${artifact_name}.mender \
    --artifact-name ${artifact_name} \
    --device-type ${device_type}

```

---

<div class="post-metadata">

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

</div>

Oh, sorry I misunderstood. `Certificate` is I believe a remnant from when we wanted to use client certificates to identify the client. It has never been used, and should be removed completely. `ServerCertificate` is definitely the way to go.

---

<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 19, 2019, 10:49am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/66 "2019-03-19T10:49:32Z")

</div>

So; mender.conf should like this:  
{  
“ClientProtocol”: “http”,  
},  
“RootfsPartA”: “/dev/mmcblk0p2”,  
“RootfsPartB”: “/dev/mmcblk0p3”,  
“UpdatePollIntervalSeconds”: 86400,  
“InventoryPollIntervalSeconds”: 86400,  
“RetryPollIntervalSeconds”: 30,  
“ServerURL”: “[https://mender.example.com/”](https://mender.example.com/%E2%80%9D),  
“ServerCertificate”: “”  
}  
or, this?:  
{  
“RootfsPartA”: “/dev/mmcblk0p2”,  
“RootfsPartB”: “/dev/mmcblk0p3”,  
“UpdatePollIntervalSeconds”: 86400,  
“InventoryPollIntervalSeconds”: 86400,  
“RetryPollIntervalSeconds”: 30,  
“ServerURL”: “[https://mender.example.com/”](https://mender.example.com/%E2%80%9D),  
“ServerCertificate”: “”  
}

---

<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 19, 2019, 11:01am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/67 "2019-03-19T11:01:18Z")

</div>

The second one

---

<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 19, 2019, 11:04am UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/68 "2019-03-19T11:04:17Z")

</div>

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 19, 2019, 4:18pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/69 "2019-03-19T16:18:44Z")

</div>

I now know how to create artifacts and, am now pondering HOW to simply get the artifacts (from buildbots) to mender server.

According to the docs, we need  
bash script / artifact creation \<-\> something \<-\> mender server get/put deployment API

The “something” is a black hole to our team, alternatives look ugly. Suggestions?

or, even better, an API bypass mechanism where we can just SCP or whatever files over. In addition, perhaps accept compressed image file and create artifacts on server? If not exist, consider this a feature request.

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 19, 2019, 4:21pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/70 "2019-03-19T16:21:36Z")

</div>

The options are,

1. Using the [server API](https://docs.mender.io/1.7/server-integration/using-the-apis)
2. Using the [mender-cli tool](https://github.com/mendersoftware/mender-cli)

---

<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 19, 2019, 4:26pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/71 "2019-03-19T16:26:32Z")

</div>

Thanks, looking into it…

---

<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 20, 2019, 4:44pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/72 "2019-03-20T16:44:51Z")

</div>

Not gonna make the mistake of not “reading the docs” again…

hit a snag (filling in niggly details in order to create mender artifacts). Mender depends on fw\_setenv (linux command) to alter u-boot environment. The default env (from mender u-boot) is OK and boots. Yet, when I save the default env (u-boot command prompt: env default -a; saveenv) which writes current env to raw flash). the result is a cyclic boot scenario. Yes, I have checked that the flash env address and sizes are correct. (matches config\_mender\_defines.h)

/etc/fw\_env.config:

```auto
# MTD device name	Device offset Env. size	Flash sector size	Number of sectors
/dev/mmcblk0 0x400000 0x4000
/dev/mmcblk0 0x800000 0x4000

```

How do I insert Markdown for u-boot log to show where it goes off the rails?

uboot log:  
apart from (bad) loading env from mmc - ok versus (good) loading default env, identical to and including here:

[0.000000] earlycon: uart0 at MMIO32 0x0000000001c28000 (options ‘’)  
then;  
(good): bootconsole [uart0] enabled  
(bad): [0.000000] Internal error: undefined instruction: 0 [#1] PREEMPT SMP

The bad used to work until I (u-boot prompt): env default -a, then saveenv

Seen this before?

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 20, 2019, 8:21pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/73 "2019-03-20T20:21:19Z")

</div>

To get markdown highlighting you just enclose the text you want to highlight with

````
```
log here
```
````

---

<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 20, 2019, 8:23pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/74 "2019-03-20T20:23:22Z")

</div>

Waiting for full logs before I attempt to comment,

But could you also post output of

```
fdisk -l <your disk image

```

There might be a problem with overlaps between your first partition and U-boot environment, mostly guessing here as you run in to problems after running `saveenv`.

---

<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 20, 2019, 8:30pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/75 "2019-03-20T20:30:14Z")

</div>

I agree with your diagnosis, especially if u-boot uses the fw\_saveenv command in rootfs, since…

making boot progress: openwrt fw\_printenv (which also sets u-boot env vars) is completely separate from u-boot config and version. Need to alter or delete this package and incorporate it to u-boot package so mender config is picked up. I suspect the cyclic boot problem (symptom, u-boot log " [0.000000] Internal error: undefined instruction: 0 [#1] PREEMPT SMP") is due to disconnect between u-boot config and fw\_printenv config, resulting in writes to wrong flash locations). Pondering best way (minimal openwrt disruption) how to fix.

```auto
bad log:
U-Boot SPL 2018.11 (Feb 14 2019 - 20:43:07 +0000)
DRAM: 512 MiB
Trying to boot from MMC1
NOTICE: BL31: v2.0(release):reboot-9355-g94993a7-dirty
NOTICE: BL31: Built : 20:43:07, Feb 14 2019
NOTICE: BL31: Detected Allwinner H5 SoC (1718)
NOTICE: BL31: STUB PMIC setup code called

U-Boot 2018.11 (Feb 14 2019 - 20:43:07 +0000) Allwinner Technology

CPU: Allwinner H5 (SUN50I)
Model: FriendlyARM NanoPi NEO 2
DRAM: 512 MiB
MMC: SUNXI SD/MMC: 0
Loading Environment from MMC... OK
In: serial
Out: serial
Err: serial
Net: phy interface7
eth0: ethernet@1c30000
starting USB...
USB0: USB EHCI 1.00
USB1: USB OHCI 1.0
USB2: USB EHCI 1.00
USB3: USB OHCI 1.0
scanning bus 0 for devices... 1 USB Device(s) found
scanning bus 2 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
384 bytes read in 1 ms (375 KiB/s)
## Executing script at 4fc00000
8894472 bytes read in 391 ms (21.7 MiB/s)
14258 bytes read in 2 ms (6.8 MiB/s)
## Flattened Device Tree blob at 4fa00000
   Booting using the fdt blob at 0x4fa00000
EHCI failed to shut down host controller.
EHCI failed to shut down host controller.
   Loading Device Tree to 0000000049ff9000, end 0000000049fff7b1 ... OK

Starting kernel ...

[0.000000] Booting Linux on physical CPU 0x0
[0.000000] Linux version 4.14.99 (rossb@localhost.localdomain) (gcc version
7.4.0 (OpenWrt GCC 7.4.0 r9355-94993a7)) #0 SMP PREEMPT Thu Feb 14 20:43:07 2019

[0.000000] Boot CPU: AArch64 Processor [410fd034]
[0.000000] Machine model: FriendlyARM NanoPi NEO 2
[0.000000] earlycon: uart0 at MMIO32 0x0000000001c28000 (options '')
[0.000000] Internal error: undefined instruction: 0 [#1] PREEMPT SMP
[0.000000] Modules linked in:
[0.000000] CPU: 0 PID: 0 Comm: swapper 4.14.99 #0
[0.000000] Hardware name: FriendlyARM NanoPi NEO 2 (DT)
[0.000000] task: ffffff800888e400 task.stack: ffffff8008880000
[0.000000] PC is at console_sysfs_notify+0x0/0x38
[0.000000] LR is at register_console+0x318/0x3e8
[0.000000] pc : [<ffffff80083703a0>] lr : [<ffffff80081007f8>] pstate: 60000
1c5
[0.000000] sp : ffffff8008883d80
[0.000000] x29: ffffff8008883d80 x28: ffffff8008769648
[0.000000] x27: ffffff800882029c x26: 0000000000000000
[0.000000] x25: ffffff800885686f x24: ffffff8008867450
[0.000000] x23: ffffff8008903300 x22: 0000000000000000
[0.000000] x21: ffffff8008903000 x20: ffffff80089032d0
[0.000000] x19: ffffff80088c8f28 x18: 0000000059f50de0
[0.000000] x17: 0000000049fff7b2 x16: 0000000000000002
[0.000000] x15: ffffffffffffffff x14: 37303a33343a3032
[0.000000] x13: 2034312062654620 x12: 7568542054504d45
[0.000000] x11: ffffff8008883c70 x10: 0000000000000000
[0.000000] x9 : ffffffffffffffff x8 : 0000000000000000
[0.000000] x7 : 0000000000000007 x6 : 0000000000000005
[0.000000] x5 : 0000000000000000 x4 : 0000000000000000
[0.000000] x3 : ffffffffffffffff x2 : 0000000000000000
[0.000000] x1 : ffffff800888e400 x0 : 0000000000000000
[0.000000] Process swapper (pid: 0, stack limit = 0xffffff8008880000)
[0.000000] Call trace:

```

undefined instruction is the “smoking gun”

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 20, 2019, 8:36pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/76 "2019-03-20T20:36:30Z")

</div>

fdisk -l image

```auto
Disk /tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img: 7948 MB, 7948206080 bytes, 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xf3a74622

                                                Device Boot Start End Blocks Id System
/tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img1 2048 43007 20480 c W95 FAT32 (LBA)
/tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img2 43008 7518207 3737600 83 Linux
/tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img3 7518208 14993407 3737600 83 Linux
/tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img4 14993408 15523839 265216 83 Linux

```

---

<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 20, 2019, 8:53pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/77 "2019-03-20T20:53:05Z")

</div>

Yeah this is your problem,

```
/tmp/mender/phero-neo2-openwrt-mender-ext4-sdcard.img1 2048 43007

```

The first partition starts at `0x100000`, but your environment starts at `0x400000`. So it will definitely overwrite your boot part when you run `saveenv`.

I would recommend to put your first partition at `0xC00000` (12MB offset, making it 4MB aligned)

> openwrt fw\_printenv (which also sets u-boot env vars) is completely separate from u-boot config and version. Need to alter or delete this package and incorporate it to u-boot package so mender config is picked up

~~Not necessarily. As long as the U-boot does the first `saveenv` it does not really matter what `fw_printenv/fw_setenv` has built-in as that will not be used as long as there is something stored on the flash.~~

~~There is also some logic in `mender_setup` which will make sure that the U-boot environment is saved **once** during first boot, specifically for this reason where fw\_setenv/fw\_getenv are built from different sources.~~

Ignore above, I misunderstood how this works.

Yes you need either need to fix-up fw\_printenv/fw\_setenv to make sure it has the same default env as U-boot, or make sure that U-boot writes the environment first.

---

<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 20, 2019, 9:05pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/79 "2019-03-20T21:05:52Z")

</div>

does u-boot not use fw\_setenv from rootfs?  
Is there a u-boot script way:  
if flash\_env==corrupt; then save default env

---

<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 20, 2019, 9:22pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/80 "2019-03-20T21:22:34Z")

</div>

> does u-boot not use fw\_setenv from rootfs?

No, it has its own commands `saveenv/printenv`. Though they probably share some code in the U-boot source.

> if flash\_env==corrupt; then save default env

Something like this could work,

```auto
"if test "${environment_saved}" != "1"; then " \
    "setenv environment_saved 1; " \
    "saveenv; " \
"fi; "

```

Assuming that `environment_saved` variable is not in the U-boot default environment.

---

<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 20, 2019, 9:27pm UTC](https://hub.mender.io/t/nanopi-neo2-porting-mender-to-openwrt/300/81 "2019-03-20T21:27:29Z")

</div>

Thanks; re-doing flash layout. Will show fdisk (tomorrow)

re the uboot script, I was thinking:

```auto
"if test "${environment_crc_bad}" != "1"; then " \
    "saveenv; " \
"fi; "

```

which is maybe a good idea, in general…

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

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