Need guidance for full system install U-boot + kernel

I am working on the kernel (relatively recent pull from the rep), which seem to also build the U-boot.
The device I have is FriendlyElec NanoPi neo. It has default U-boot and some operating system within the onboard eMMC.
I boot Openwrt from the SD-card, and can see eMMC with its boot0 and boot1 partitions as well as kernel and user data partitions, and use SD-card for data only in the future.

I want to convert the eMMC to the device running the images of the Openwrt build I performed. There're a plenty guides on how to do it for various platforms and operating systems, is there one for Openwrt?

In particular, the kernel update will have to be performed from the /tmp directory using sysupgrade.

To my understanding, the task must be simple, but very precise -

  1. write u-boot into the eMMC, not sure what one use - with SPL or without it, with DTB or without it (can it work without device tree??);
  2. write default or ensure space for the u-boot environment variables, if they are not the part of the compiled u-boot image.
  3. create partition for the kernel and its other files like DTBs, write those files in there. Or probably just write the .img file into specific location within the eMMC, I am not sure.

Additional issue I caught is proper configuration of fw_setenv and fw_printenv, which must be supplied from some location I am unable to find - which depend on configuration of the u-boot. That's why I would prefer to update everything at once on the eMMC to ensure 100% consistency.

Advice and help is very appreciated. Most probably I'd be able to figure out things myself at the end of the day (month, year :slight_smile: ), but if you have insight you may save some of the time. Thanks in advance!

This device ?

That page mentions mainline U-Boot support for that device since 2017, so U-Boot page/forum should have detailed info about installing an updated Bootloader on that device.

Hardware Spec

CPU: Allwinner H3, Quad-core Cortex-A7 Up to 1.2GHz
DDR3 RAM: 256MB/512MB
Connectivity: 10/100M Ethernet
USB Host: Type-A x 1, 2.54 mm pin x 2

Here's the OpenWrt page with info for sunxi devices:

1 Like

Thank you so much. Strange this device is not on the list on that page, however in the list of configurations in the repo. And I guess the same algo applies.

I was promised that even if something happens in the process and I make eMMC unbootable - device will still boot from the SD-card. Let's see tomorrow.

Guide is great, but I can not execute it.

I am successful up to stage finishing fdisk.

  1. I can't reseat soldered eMMC. Because it is physically not removable. Found this and the only worked was partx -u. Anyway after all I decided to reboot, and it has successfully booted from SD-card, with devices changing their order - now SD-card is mmcblk0 and eMMC being mmcblk1.

  2. the step

# dd if=bin/sunxi/uboot-sunxi-Cubietruck/openwrt-sunxi-Cubietruck-u-boot-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

requires bin/sunxi folder, but it is not in my build, so I started looking for files in the project, with the understanding that this way it will not be portable at all with changed versions of any of the components. Looked into make menuconfig for option for it to create something similar explained op the page - no luck. Found u-boot in build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/u-boot-nanopi_neo/u-boot-2023.04/u-boot-sunxi-with-spl.bin.

  1. next step is
# cp bin/sunxi/uboot-sunxi-Cubietruck/openwrt-sunxi-Cubietruck-uEnv.txt /mnt/uEnv.txt

and this file is also missing, I found something in package/boot/uboot-sunxi/uEnv-default.txt.

  1. then
# cp bin/sunxi/sun7i-a20-cubietruck.scr /mnt/boot.scr

found in staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/image/friendlyarm_nanopi-neo-boot.scr.

  1. then
# cp bin/sunxi/sun7i-a20-cubietruck.dtb /mnt/dtb

found in build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-sunxi_cortexa7/linux-6.1.74/arch/arm/boot/dts/sun8i-h3-nanopi-neo.dtb.

  1. and the last one I am stuck with:
# cp bin/sunxi/openwrt-sunxi-uImage /mnt/uImage

I can't find this file. I have .img image which I write to the SD-card is located in bin/targets/sunxi/cortexa7/openwrt-sunxi-cortexa7-friendlyarm_nanopi-neo-ext4-sdcard.img.gz.

Regarding missing bin/sunxi and existing bin/targets/sunxi - there only an img file, no dtb, no u-boot, no scr file, no environment file.

Update: another problem - it seems that repo's device tree has mmc2 disabled which I enabled in linux device tree, but did not enable in u-boot device tree, therefore even if I flashed u-boot image per process, board says it can't find eMMC. For this, I guess, it is needed to also alter u-boot related device tree files, and recompile the u-boot. Too much custom work...

Update: I've got a "genius" idea to write img file as is onto the eMMC. Finally what is the difference between SD and eMMC in terms of data allocation?
It still works, and I suspect that it starts booting from SD-card (because without card it still says it can't find the eMMC), but then it loads kernel from the eMMC. I am totally confused. Let me try enabling the eMMC device in the u-boot device tree.

Update: no way - I checked .dtb file named u-boot.dtb in the u-boot directory is having mmc2 (mmc@1c11000) okay'ed, but still board says MMC device 1 not found.

The u-boot build sets booting variables/scripts from mmc0 only, while eMMC is the mmc1. I can boot into u-boot from SD-card, and then change scripts/variables and boot using eMMC with SD-card removed.

Tried this with no result.

There seems to be some link in the image hardcoded to the SD-card because it tries to start from MMC and then says SD-card is not there.

I performed dd from zero to the eMMC for first 512MB, and without SD-card the device is a brick. With SD-card it boots from SD-card.
Then I flashed u-boot like it is said in link above, and eMMC became alive with same ### ERROR ### error message.

So it seems initial loader is obtained from /dev/mmcblkXbootY part of the eMMC, not clear where exactly it is, and it is NOT in seek=8 within the MMC space, but then how it had been erased using dd for first 512 MB.