Issues with updating the Linux kernel partition from Linux

I am trying to update the Linux kernel for our product. Instead of doing it from U-boot, I need to do it within Linux because we do not have serial connection for the devices in the field.
I have done the following:
in Linux:

$cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00020000 "vf-bcb"
mtd1: 00160000 00020000 "u-boot"
mtd2: 00080000 00020000 "u-boot-env"
mtd3: 00800000 00020000 "kernel-ubi"    **** this is the image I want to replace ****
mtd4: 01000000 00020000 "rootfs-ubi"
mtd5: 06600000 00020000 "userfs-ubi"

$mtd_debug info /dev/mtd3
mtd.type = MTD_NANDFLASH
mtd.flags = MTD_WRITEABLE
mtd.size = 8388608 (8M)
mtd.erasesize = 131072 (128K)
mtd.writesize = 2048 (2K)
mtd.oobsize = 64
regions = 0

$./flash_erase /dev/mtd3 0 0
Erasing 128 Kibyte @ 64007e0000 --  0 % complete

$nandwrite /dev/mtd3 /mnt/sd/v3_kernel.img -p
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
Writing data to block 5 at offset 0xa0000
Writing data to block 6 at offset 0xc0000
Writing data to block 7 at offset 0xe0000
Writing data to block 8 at offset 0x100000
Writing data to block 9 at offset 0x120000
Writing data to block 10 at offset 0x140000
Writing data to block 11 at offset 0x160000
Writing data to block 12 at offset 0x180000
Writing data to block 13 at offset 0x1a0000
Writing data to block 14 at offset 0x1c0000
Writing data to block 15 at offset 0x1e0000
Writing data to block 16 at offset 0x200000
Writing data to block 17 at offset 0x220000
Writing data to block 18 at offset 0x240000
Writing data to block 19 at offset 0x260000

After rebooting, I received the following error in u-boot:

UBI error: ubi_read_volume_table: the layout volume was not found
UBI error: ubi_init: cannot attach mtd1
UBI error: ubi_init: UBI error: cannot initialize UBI, error -22
UBI init error 22

Please help… Did I miss something? I was actually re-programming the same kernel image in the process. I want to make sure it can bootup properly after re-programming before using the new Linux kernel.

thank you

To replace a kernel from Linux please use a

**ubiupdatevol /dev/ubi0_0 kernel_file **

command

if I do:

$ ls /sys/class/ubi
ubi1_0   ubi1     ubi0_0   ubi0     version

$ cat /sys/class/ubi/ubi0_0/name
rootfs

$ cat /sys/class/ubi/ubi1_0/name
userfs

It seems ubi0_0 is not where I want to write to, as it contains the rootfs instead of kernel

Could you run ubinfo -a command and post an output here?

And what is your Linux BSP version (post a uname -a output as well)?

my BSP is 2.3

$ uname -a
Linux ECU 3.0.15-encelium-svn63033 #9 PREEMPT Thu Jan 19 14:37:21 EST 2017 armv7l GNU/Linux

$ ubinfo -a
UBI version:                    1
Count of UBI devices:           2
UBI control device major/minor: 10:63
Present UBI devices:            ubi0, ubi1

ubi0
Volumes count:                           1
Logical eraseblock size:                 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks:     127 (16125952 bytes, 15.4 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       1
Count of reserved physical eraseblocks:  2
Current maximum erase counter value:     4
Minimum input/output unit size:          2048 bytes
Character device major/minor:            249:0
Present volumes:                         0

Volume ID:   0 (on ubi0)
Type:        dynamic
Alignment:   1
Size:        121 LEBs (15364096 bytes, 14.7 MiB)
State:       OK
Name:        rootfs
Character device major/minor: 249:1

===================================

ubi1
Volumes count:                           1
Logical eraseblock size:                 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks:     812 (103104512 bytes, 98.3 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       4
Count of reserved physical eraseblocks:  8
Current maximum erase counter value:     4
Minimum input/output unit size:          2048 bytes
Character device major/minor:            247:0
Present volumes:                         0

Volume ID:   0 (on ubi1)
Type:        dynamic
Alignment:   1
Size:        800 LEBs (101580800 bytes, 96.9 MiB)
State:       OK
Name:        userfs
Character device major/minor: 247:1

I have upgraded the BSP and Linux kernel to the latest in our products recently. I am working on the upgrade to the products in the customers’ site now. For those units, the kernel is very old.

Yes BSP 2.3 is very old and not supported anymore. You need to update not a kernel, but a whole system - U-Boot, Device Tree. Kernel and File System.

yes, I know it is very old. We actually have upgraded the whole system for our new products already (U-Boot, dtd, and Kernel). However, for the products in the customers’ site, we do not have access to the serical/uboot. My plan is to overwrite the u-boot configuration to make the units to boot into u-boot and flash the whole system from MMC. However, the u-boot configuration portion was configured as read-only, and I have no ways to modify that since I cannot go into u-boot for existing products in the customer’s site. I am planning to recompile the same old kernel 3.0 after modifying the source code to ignore the read-only flag. With the modified kernel 3.0, hopefully I can overwrite the u-boot config sector, plus, I can upgrade the whole system.

hi @weixiong100

This is a new very special case for us. We need to internally investigate on this.
Could you tell us about how many products without serial console you need to update?
Is there no UART or USB connection on the custom carrier board?
What about ethernet connection?

Best regards,
Jaski

We have over thousands of units without UART on the custom carrier board. We actually have USB ports on them, but I never tried anything with the USB port. Are there any chance that allows me to get into U-boot with the USB?

We do not have Ethernet connection in U-Boot. The Ethernet only works after Linux booted up. It is because the U-Boot Ethernet setting does not match our carrier board, and we modified the Linux Ethernet driver to make it work.

thank you.

The only solution meeting your advanced update requirements will involve a multi step approach like you already figured out. Depending on whether or not and how much existing data may need to be preserved resp. how big the new software is external communication or storage may be required at least during some of those steps. Please first make sure that the “new” software adheres to the latest raw NAND best practices (e.g. limiting separate MTD partitions to a minimum and using one big single UBI for most everything). One big issue you may face is that the underlying raw NAND data representation changed too significantly preventing the old BSP from easily writing in a way the new BSP may be able to read it or vice versa. One way to assess this may be to NFS boot the old BSP on a module running the new BSP trying to read/write from/to NAND. Good luck!