Ardiuno Yùn, kernel size under 1280k requirement

On arduino Yun, the default mtd partitioning require that the kernel be below 1280k. It is actually not possible with the default configuration. What could be shipped in the lede project tree to generate a kernel image with a smaller size ? How to activate and deactivate some kernel options specifically for the arduino Yun ?

This patch applies to config-4.4 and reduce the kernel size by disabling many target architectures : https://github.com/nxhack/openwrt-yun-build-extra/blob/master/patches/LEDE-MIPS24Kc%2BPCI%2BFPU_EMU.patch
How to integrate into the lede-project tree ?

I am playing with this for a month but I can't find documentation and the lede-project tree files don't have comments for most of them. Any links to understand how to tweak and integrate a device would be welcome.

Does Yun bootloader (I assume U-Boot) allow change of bootargs and save them in environment (saveenv)?

Ok, I changed it, I set the kernel to be 2048KiB instead of 1280KiB and reduced the rootfs so that it is 13888KiB instead of 14656KiB.

To do that, I changed the uboot environment.

setenv board Yun
setenv mtdparts "spi0.0:256k(u-boot)ro,64k(u-boot-env),13888k(rootfs),2048k(kernel),64k(nvram),64k(art),15936k@0x50000(firmware)"
setenv bootcmd "run addboard; run addtty;run addparts; run addrootfs; bootm 0x9FDE0000"
saveenv

And I have a generik.mk set of rules who generate a proper "uImage-lzma.bin" kernel image and "root.squashfs".

define Device/yun-16m
  BOARDNAME := Yun
  DEVICE_TITLE := Arduino Yun (16MB flash)
  DEVICE_PACKAGES := kmod-usb-core kmod-usb2
  MTDPARTS := spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,13888k(rootfs),2048k(kernel),64k(nvram)ro,64k(art)ro,15936k@0x50000(firmware)
  CONSOLE = ttyATH0,250000
  IMAGE_SIZE := 15936k
  KERNEL_SIZE := 2048k
  ROOTFS_SIZE := 13888k
  IMAGE/sysupgrade.bin = append-rootfs | pad-rootfs | pad-to $$$$(ROOTFS_SIZE) | append-kernel | check-size $$$$(IMAGE_SIZE)
endef
TARGET_DEVICES += yun-16m

But I didn't manage to have a working sysupgrade image. I get "Bad magic number". Now I am a bit stuck, trying to read different Makefile but I don't manage to understand. How to investigate further why the generated sysupgrade image is not working ?

PS: I lost my "Zoha" account and had to create a new one. So Zoha==camille-hack :wink:

13888k != 0xDE0000

Your kernel, based on your Device/yun-16m definition, is placed at offset 0xD90000 (13888k) in the image, so the U-Boot cat boot it with bootm 0x9FD90000, not bootm 0x9FDE0000.

The kernel is placed at offset 0xDE0000 (256k + 64k + 13888k = 14208k) if we start from the very beginning of the flash.
With the default lininoOS custom openwrt distribution, the default offset was 0xEA0000 (256k + 64k + 14656k = 14976k) and it was working.
0xD90000 or 13888k, is the ROOTFS_SIZE, and not the kernel offset. The uboot partition and the uboot environment partition should be part of the math somehow.

I just get my calculator out again to check and I must say that I don't get the logic.

Anyway, I just sysupgrade and tried with bootm 0x9FD90000 and bootm 0x9FDE0000 and both returned "Bad Magic Number".

Ah, you are correct, I forgot about U-Boot and environment partitions!

Can you paste here full boot log output from U-Boot?

Whaou, thanks so much for your reactivity. You have been really supportive !
So here is the u-boot log, just after a sysupgrade, not so much is said :

U-Boot 1.1.5-linino-g17593166-dirty (Oct  4 2015 - 02:12:32)

Linino Board (ar9331) U-boot
DRAM:  64 MB
Top of RAM usable for U-Boot at: 84000000
Reserving 218k for U-Boot at: 83fc8000
Reserving 192k for malloc() at: 83f98000
Reserving 44 Bytes for Board Info at: 83f97fd4
Reserving 36 Bytes for Global Data at: 83f97fb0
Reserving 128k for boot params() at: 83f77fb0
Stack Pointer at: 83f77f98
Now running in RAM - U-Boot at: 83fc8000
Flash Manuf Id 0xef, DeviceId0 0x40, DeviceId1 0x18
flash size 16777216, sector count = 256
Flash: 16 MB
In:    serial
Out:   serial
Err:   serial
Net:   eth0: b4:21:8a:00:00:00
eth1: b4:21:8a:00:00:01
eth0, eth1
autoboot in 4 seconds (stop with 'lin')...
## Booting image at 9fde0000 ...
Bad Magic Number
linino>

I just tried again with using the kernel image and the rootfs image independantly and it worked (LEDE prompt appears and I can log in etc).

tftp 0x80060000 lede-ar71xx-generic/lede-ar71xx-generic-uImage-lzma.bin
erase 0x9FDE0000 +$filesize
cp.b $fileaddr 0x9FDE0000 $filesize
tftp 0x80060000 lede-ar71xx-generic/lede-ar71xx-generic-root.squashfs
erase 0x9F050000 +$filesize
cp.b $fileaddr 0x9F050000 $filesize
reset

Ok, I avoided this problem by using this new configuration:

define Device/yun-16m
  BOARDNAME := Yun
  DEVICE_TITLE := Arduino Yun (16MB flash)
  MTDPARTS := spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,15936k(firmware),64k(nvram)ro,64k(art)ro
  CONSOLE = ttyATH0,250000
  IMAGE_SIZE := 15936k
endef
TARGET_DEVICES += yun-16m

So now the kernel is at 0x050000, at the beginning of the firmware partition by default. Sysupgrade works and I am preparing a commit against the lede project tree. Thanks for your help @pepe2k !

@camille-hack
It's work in Lede git branch v17.0.3 or not sir?
because when I compile target profile to Arduino 16MB it's failed generated *.bin image for arduino yun...