Turns out there is quite a bit of overhead for a UBIFS (1.6MiB for an empty test directory).
Then, UBI reserves PEBs on each UBI device, depending on NAND size: http://linux-mtd.infradead.org/doc/ubi.html#L_max_beb
My 450gx4 kernel.ubifs is 4464KiB, for a 2847KiB kernel.
This was the only way I could get ubimkvol
& ubiupdatevol
to work on my small kernel UBI partition, on the big NAND device:
source /lib/upgrade/nand.sh
ubiformat /dev/mtd0
ubiattach -m 0 --max-beb-per1024=4
# otherwise, no room left for mkvol
ubirmvol "/dev/$(nand_find_ubi ubi_kernel)" -N kernel || true
ubimkvol "/dev/$(nand_find_ubi ubi_kernel)" -N kernel -m
ubiupdatevol "/dev/$(nand_find_volume $(nand_find_ubi ubi_kernel) kernel)" /tmp/mikrotik_rb450gx4-128k-kernel.bin.ubifs
This then booted from RouterBOOT, but I am using the OEM partition layout.
My ubiformat
ubinized
kernel sysupgrade method was simpler, as no custom ubiattach needed: https://github.com/openwrt/openwrt/compare/master...john-tho:450gx4
On the 128MiB NAND hapac3 flash UBI would reserve less space, but just to be sure: Have you checked your flashed kernel image volume mounts and validates, after ubiformat
& sysupgrade, from the netboot initramfs image? I also saw you were using a much bigger -c, --max-leb-cnt
for your mkfs.ubifs
than I am.
After testing nanddump
ed ubiformat
ubinize
images versus ubimkvol
with the nandsim kernel module on 512MiB NAND:
- The name of the test volume (part of the UBI volume layout information; even though RouterBOOT probably does not use volume name) can move around
- appears early (0x1010) for ubinized image
- or late (0x10021010) for
ubimkvol
, or after ubimkvol
is run after the ubiformat
ed image, or after ubiattach
with an autoresize flag in ubinized image
A guess: If RouterBOOT (to save boot time) limits the amount of NAND it will scan (to something like the OEM kernel partition size), it may miss the kernel if OpenWRT's UBI stores whatever it is that RouterBOOT is searching for beyond this limit (whether it is UBI volumes table, or UBIFS, or something else).
nandsim testing on 5.8 x86_64
# setup
sudo rmmod nandsim
sudo modprobe nandsim first_id_byte=0x20 second_id_byte=0xac third_id_byte=0x00 fourth_id_byte=0x15
# 512MiB, 2048, 128k
# https://elixir.bootlin.com/linux/v5.11.15/source/drivers/mtd/nand/raw/nandsim.c
sudo modprobe ubi
sudo modprobe mtd
sudo mtdinfo /dev/mtd1 --ubi-info
# ubimkvol
sudo ubiformat --sub-page-size=2048 /dev/mtd1
sudo ubiattach --vid-hdr-offset=2048 --dev-path=/dev/mtd1
#sudo nanddump /dev/mtd1 > nand.img
sudo ubimkvol /dev/ubi0 -N kernel -s 20MiB
sudo nanddump /dev/mtd1 > nand.img
binwalk --raw='kernel' nand.img
sudo ubidetach --dev-path=/dev/mtd1
#Dumping data starting at 0x00000000 and ending at 0x20000000...
#DECIMAL HEXADECIMAL DESCRIPTION
#--------------------------------------------------------------------------------
#268570640 0x10021010 Raw signature (kernel)
#268701712 0x10041010 Raw signature (kernel)
# ubinized
cat <<EOF > ubi.ini
[kernel]
mode=ubi
vol_id=0
vol_name=kernel
vol_type=dynamic
vol_alignment=1
vol_size=20MiB
[rootfs]
mode=ubi
vol_id=1
vol_name=rootfs
vol_type=dynamic
vol_alignment=1
vol_size=20MiB
[rootfs_data]
mode=ubi
vol_id=2
vol_name=rootfs_data
vol_type=dynamic
vol_alignment=1
vol_size=1MiB
#vol_flags=autoresize
EOF
ubinize --peb-size=128KiB --min-io-size=2048 --output=test.ubi ubi.ini
sudo ubiformat --sub-page-size=2048 /dev/mtd1 --flash-image=test.ubi
sudo nanddump /dev/mtd1 > nand.img
binwalk --raw='kernel' --raw='rootfs' nand.img
#DECIMAL HEXADECIMAL DESCRIPTION
#--------------------------------------------------------------------------------
#4112 0x1010 Raw signature (kernel)
#4284 0x10BC Raw signature (rootfs)
#4456 0x1168 Raw signature (rootfs)
#135184 0x21010 Raw signature (kernel)
#135356 0x210BC Raw signature (rootfs)
#135528 0x21168 Raw signature (rootfs)
# after attach
sudo ubiattach --vid-hdr-offset=2048 --dev-path=/dev/mtd1
sudo ubidetach --dev-path=/dev/mtd1
sudo nanddump /dev/mtd1 > nand.img
binwalk --raw='kernel' --raw='rootfs' nand.img
#DECIMAL HEXADECIMAL DESCRIPTION
#--------------------------------------------------------------------------------
#4112 0x1010 Raw signature (kernel)
#4284 0x10BC Raw signature (rootfs)
#4456 0x1168 Raw signature (rootfs)
#135184 0x21010 Raw signature (kernel)
#135356 0x210BC Raw signature (rootfs)
#135528 0x21168 Raw signature (rootfs)
# rmvol & mkvol
sudo ubiattach --vid-hdr-offset=2048 --dev-path=/dev/mtd1
sudo ubirmvol /dev/ubi0 -N rootfs_data
#sudo ubirmvol /dev/ubi0 -N rootfs
#sudo ubimkvol /dev/ubi0 -N rootfs -s 20MiB
#sudo ubirmvol /dev/ubi0 -N rootfs_data -s 20MiB
sudo ubidetach --dev-path=/dev/mtd1
sudo nanddump /dev/mtd1 > nand.img
binwalk --raw='kernel' --raw='rootfs' nand.img
#DECIMAL HEXADECIMAL DESCRIPTION
#--------------------------------------------------------------------------------
#269619216 0x10121010 Raw signature (kernel)
#269619388 0x101210BC Raw signature (rootfs)
#269750288 0x10141010 Raw signature (kernel)
#269750460 0x101410BC Raw signature (rootfs)