Welcome! Log In Create A New Profile

Advanced

NSA325v2 - A question and how to boot stock OS with uBoot 2017.07

Posted by l.scorcia 
NSA325v2 - A question and how to boot stock OS with uBoot 2017.07
December 24, 2021 11:41AM
Hi, I followed the guide at https://forum.doozan.com/read.php?3,12381 to install the new uBoot in the mtd0 partition in order to boot Debian on my NSA325v2 from an USB stick. It works, but I have two questions:

1) While following the guide, I skipped step 8 (Flashing default u-boot envs image). I didn't flash it because my (stock) /etc/fw_env.config was different from what is described in the guide (uses /dev/mtd1) and I was afraid of breaking something by flashing the wrong partition:

~ # cat /etc/fw_env.config
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR.

# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
# NAND example
/dev/mtd1               0x0000          0x20000         0x20000                 4

However, I found out that even by skipping this step, I could boot Debian from the USB stick apparently without any issue.

This is the stock mtd partition list:

~ # cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00100000 00020000 "uboot"
mtd1: 00080000 00020000 "uboot_env"
mtd2: 00080000 00020000 "key_store"
mtd3: 00080000 00020000 "info"
mtd4: 00a00000 00020000 "etc"
mtd5: 00a00000 00020000 "kernel_1"
mtd6: 02fc0000 00020000 "rootfs1"
mtd7: 00a00000 00020000 "kernel_2"
mtd8: 02fc0000 00020000 "rootfs2"

What would be the appropriate command to flash the new environment vars on this setup?

2) How do I boot the stock firmware from the new uBoot? Ideally I would like to boot Debian only if the USB stick is inserted, otherwise I'd like to boot from the old nand partition. I've seen comments in the forum that say that you cannot boot the old firmware from the new uBoot, but I don't understand why. It should still be on the NAND, right?

Thanks for the incredible amount of information on this forum, it is invaluable!
--
Luca
Re: NSA325v2 - A question and how to boot stock OS with uBoot 2017.07
December 24, 2021 03:28PM
Luca,

> 1) While following the guide, I skipped step 8
> (Flashing default u-boot envs image). I didn't
> flash it because my (stock) /etc/fw_env.config was
> different from what is described in the guide
> (uses /dev/mtd1) and I was afraid of breaking
> something by flashing the wrong partition:

It's OK to flash the envs image. As I mentioned in the installation instruction:

Quote

Note: for boxes such as Pogo V4 and Zyxel NSA3xx, the mtd partition definition are kept the same as stock definition, therefore is different from the one above.

If you don't have /etc/fw_env.config file in your system then go ahead and create this file with the above content. MTD parts are not important for booting and it can be adjusted later. For users who like to keep the stock mtd definition, there is no need to adjust it to the above definition. As long as mtd0 is defined as 1MB (0x00100000) or greater then it will be OK:
mtd0: 00100000 00020000 "u-boot"


> However, I found out that even by skipping this
> step, I could boot Debian from the USB stick
> apparently without any issue.

Right now, the envs being used to boot your box is the internal envs inside the new u-boot. If you have serial console, you would see that the old envs in NAND were not used (it is unrecognized by the new u-boot). And since you did not flash envs image, there is a CRC error when u-boot reads the NAND block 0xc0000 where new envs are, so it falls back to the internal envs.


> This is the stock mtd partition list:
>
>
> ~ # cat /proc/mtd
> dev:    size   erasesize  name
> mtd0: 00100000 00020000 "uboot"
> mtd1: 00080000 00020000 "uboot_env"
> mtd2: 00080000 00020000 "key_store"
> mtd3: 00080000 00020000 "info"
> mtd4: 00a00000 00020000 "etc"
> mtd5: 00a00000 00020000 "kernel_1"
> mtd6: 02fc0000 00020000 "rootfs1"
> mtd7: 00a00000 00020000 "kernel_2"
> mtd8: 02fc0000 00020000 "rootfs2"
>
>
> What would be the appropriate command to flash the
> new environment vars on this setup?

The same one in the installation thread. Because it only writes to mtd0. As mentioned in the installation instruction:

Quote

d. Flash u-boot envs to NAND location 0xC0000.

Be extra careful with the next 2 commands, you should see output that look like below. If there is error, then do not reboot, post your problem here so we can help.

/usr/sbin/flash_erase /dev/mtd0 0xc0000 1
Expected output:
Erase Total 1 Units
Performing Flash Erase of length 131072 at offset 0xc0000 done

/usr/sbin/nandwrite -s 786432 /dev/mtd0 uboot.2016.05-tld-1.environment.img
Expected output:
Writing data to block 6 at offset 0xc0000


> 2) How do I boot the stock firmware from the new
> uBoot? Ideally I would like to boot Debian only if
> the USB stick is inserted, otherwise I'd like to
> boot from the old nand partition. I've seen
> comments in the forum that say that you cannot
> boot the old firmware from the new uBoot, but I
> don't understand why. It should still be on the
> NAND, right?

Because the new u-boot is very different from the old stock u-boot. And the stock kernel on NAND was a custom kernel built to work with stock u-boot. So new u-boot does not boot the old kernel on NAND.

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

After you flashed the envs image to mtd0 as instruction stated, adjust your fw_env.config

Quote

1. uBoot envs config should be defined as followed in your /etc/fw_env.config

cat /etc/fw_env.config
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000

Note: you do need to do everything in Step 8. From 8.a to 8.i.

Especially Step 8.f is quite important:

Quote

f. Adjust the DTB name to boot with a rootfs that has FDT kernel 3.17+ (this is the normal case):

Find your box DTB file in the rootfs /boot/dts directory and adjust the env to it. For example, if the box is the Dockstar
fw_setenv dtb_file '/boot/dts/kirkwood-dockstar.dtb'

For this box, it would be

fw_setenv dtb_file '/boot/dts/kirkwood-nsa325.dtb'

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: NSA325v2 - A question and how to boot stock OS with uBoot 2017.07
December 26, 2021 04:20AM
Thank you Bodhi! I completed the steps as described and it works great, no more CRC warning and now it uses the correct mac address. I also activated systemd using uEnv.txt and updated the kernel to the latest you published with no issues. I get a few warnings in dmesg but I guess those are alright:

[    9.096906] nand: device found, Manufacturer ID: 0xec, Chip ID: 0xf1
[    9.104061] nand: Samsung NAND 128MiB 3,3V 8-bit
[    9.109398] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    9.117739] Scanning device for bad blocks
[    9.219084] Bad eraseblock 1010 at 0x000007e40000
[    9.225844] 9 fixed-partitions partitions found on MTD device orion_nand
[    9.233292] Creating 9 MTD partitions on "orion_nand":
[    9.239156] 0x000000000000-0x000000100000 : "uboot"
[    9.245291] mtdblock: MTD device 'uboot' is NAND, please consider using UBI block devices instead.
[    9.255839] 0x000000100000-0x000000180000 : "uboot_env"
[    9.262199] mtdblock: MTD device 'uboot_env' is NAND, please consider using UBI block devices instead.
[    9.273063] 0x000000180000-0x000000200000 : "key_store"
[    9.279455] mtdblock: MTD device 'key_store' is NAND, please consider using UBI block devices instead.
[    9.290309] 0x000000200000-0x000000280000 : "info"
[    9.296265] mtdblock: MTD device 'info' is NAND, please consider using UBI block devices instead.
[    9.306680] 0x000000280000-0x000000c80000 : "etc"
[    9.312554] mtdblock: MTD device 'etc' is NAND, please consider using UBI block devices instead.
[    9.322869] 0x000000c80000-0x000001680000 : "kernel_1"
[    9.329251] mtdblock: MTD device 'kernel_1' is NAND, please consider using UBI block devices instead.
[    9.340053] 0x000001680000-0x000004640000 : "rootfs1"
[    9.346477] mtdblock: MTD device 'rootfs1' is NAND, please consider using UBI block devices instead.
[    9.357175] 0x000004640000-0x000005040000 : "kernel_2"
[    9.363537] mtdblock: MTD device 'kernel_2' is NAND, please consider using UBI block devices instead.
[    9.374348] 0x000005040000-0x000008000000 : "rootfs2"
[    9.380730] mtdblock: MTD device 'rootfs2' is NAND, please consider using UBI block devices instead.

If I understood correctly the guide, if I ever wanted to boot stock again, I would have to flash the stock mtd0 partition that I saved using the command described in the guide:

nanddump --omitoob -l 0x80000 -f mtd0 /dev/mtd0

Would those two commands be correct?

flash_erase /dev/mtd0 0 4
nandwrite /dev/mtd0 stock_mtd0

Thanks a lot!



Edited 1 time(s). Last edit at 12/26/2021 04:21AM by l.scorcia.
Re: NSA325v2 - A question and how to boot stock OS with uBoot 2017.07
December 26, 2021 03:22PM
> NAND, please consider using UBI block devices
> instead.
> [ 9.374348] 0x000005040000-0x000008000000 : "rootfs2"
> [ 9.380730] mtdblock: MTD device 'rootfs2' is NAND, please consider using UBI block devices instead.

This is only an info message. It's safe to ignore it.

> If I understood correctly the guide, if I ever
> wanted to boot stock again, I would have to flash
> the stock mtd0 partition that I saved using the
> command described in the guide:

>
> nanddump --omitoob -l 0x80000 -f mtd0 /dev/mtd0
>
>
> Would those two commands be correct?
>
>
> flash_erase /dev/mtd0 0 4
> nandwrite /dev/mtd0 stock_mtd0
>

Basically correct! But I would do a bit more.

Save the current mtd0 (that will save the new envs also):

nanddump --omitoob  -f mtd0.nsa25.new /dev/mtd0

And then restore to stock

flash_erase /dev/mtd0 0 4
nandwrite /dev/mtd0 stock_mtd0

So later when you restore back to the new u-boot to boot Debian, it will be easier because the changes in new envs are restored also:

flash_erase /dev/mtd0 0 0
nandwrite /dev/mtd0 mtd0.nsa25.new

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: NSA325v2 - A question and how to boot stock OS with uBoot 2017.07
December 28, 2021 04:58AM
That's really helpful! Thanks!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: