Author Topic: Using u-boot from NAND to boot to SATA SSD?  (Read 6787 times)

Offline hvergelmir

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Using u-boot from NAND to boot to SATA SSD?
« on: May 31, 2015, 09:26:43 am »
Hi,

I've read a bit here on the forum and also elsewhere. In general I think I understand how to put certain of the things together, but I'm missing some pieces of the puzzle. I'm by far not new to Linux, but I'm relatively new to Linux on CubieTruck.

Now used Igor's SD card image for Ubuntu 14.04 with kernel 3.4.107. It boots perfectly fine from SD card as expected. After partitioning my /dev/sda (a SATA SSD) I used the /root/nand-sata-install script to install the system to the SATA drive (I did some other customizations, but they are not relevant here).

Now I'd like to get rid of having to use the microSD to boot. I'd also like to use the NAND as a fallback ("rescue mode", if you will) if the SATA drive should ever fail or should I ever break the system there.

I partitioned my NAND thus using: nand-part -f a20 /dev/nand 32768 'bootloader 131072' 'rootfs 14778368', since I'm using the 16 GB NAND version of CT; nand-part shows the layout accordingly:

Code: [Select]
# nand-part -f a20 /dev/nand
check partition table copy 0: mbr: version 0x00000200, magic softw411
OK
check partition table copy 1: mbr: version 0x00000200, magic softw411
OK
check partition table copy 2: mbr: version 0x00000200, magic softw411
OK
check partition table copy 3: mbr: version 0x00000200, magic softw411
OK
mbr: version 0x00000200, magic softw411
2 partitions
partition  1: class =         DISK, name =   bootloader, partition start =    32768, partition size =   131072 user_type=0
partition  2: class =         DISK, name =       rootfs, partition start =   163840, partition size = 14778368 user_type=0
# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk
├─sda1        8:1    0    64G  0 part /
├─sda2        8:2    0   400G  0 part
└─sda3        8:3    0   1.8G  0 part
nand         93:0    0  14.9G  0 disk
├─nand1      93:1    0    64M  0 part
└─nand2      93:2    0  14.8G  0 part
mmcblk0     179:0    0   3.7G  0 disk
└─mmcblk0p1 179:1    0   3.7G  0 part /media/mmc

I then used the /root/nand-sata-install script once again, this time targeting the NAND. Simply removing the micrSD card, however, didn't cut it. I couldn't boot from it.

I didn't modify the boot.ini on /dev/nand1 (which is a FAT partition, yes). However, I slightly adjusted the uEnv.txt in an attempt to teach the kernel the correct display mode.

Code: [Select]
# cat boot.ini
[system]
start_os_name = linux
timeout       = -1
display_device= 0
display_mode  = 0


[linux]

# cat uEnv.txt
console=tty0
nand_root=/dev/nand2 rootwait
extraargs=rootfstype=ext4 sunxi_ve_mem_reserve=0 sunxi_g2d_mem_reserve=0 sunxi_no_mali_mem_reserve sunxi_fb_mem_reserve=16 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:1920x1080p50 panic=10 consoleblank=0
script=script.bin
kernel=uImage

So from what I understood from reading all these various articles and forum questions and answers is that the u-boot image for the NAND boot is quite different (internally) from the one used to boot the microSD card.

I read that /dev/nand1 -> boot.axf is used to kickstart the boot. Using /dev/nand1 -> boot.ini to locate systems to boot and that in the case of my above boot.ini this will lead straight to /dev/nand1 -> linux/linux.ini:

Code: [Select]
# cat linux/linux.ini
[segment]
img_name = c:\linux\u-boot.bin
img_size = 0x80000
img_base = 0x4A000000

[script_info]
script_base = 0x43000000
script_size = 0x10000

[logo_info]
logo_name = c:\linux\linux.bmp
logo_show = 0

The u-boot.bin exists in the referenced location.

Now I've got a number of questions to put the puzzle pieces together. Pointers to documentation will be perfectly fine, but if you can offer an explanation I'll take that as well.
  • How do the files on /dev/nand1 interact?
  • What is uImage on /dev/nand1? Is this another u-boot image?
  • How can I turn a u-boot script back into a human-readable form?
  • Where can I find a documentation of the parameters accepted inside linux/linux.ini on /dev/nand1?
  • Since I overwrote the NAND, is there something that needs to be written to some offset of the device outside of the partitions to get it to boot from there?
  • If I want the boot from NAND to use a root on SATA, may I use the nand_root parameter or do I have to use another (like root)?
  • Does the linux/u-boot.bin still get to use the settings from uEnv.txt in the root of /dev/nand1 or where do they come from?

So to reiterate I'd like to use the bootloader on NAND to boot to my SATA SSD.

Thank you in advance!

Offline uelkfr

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Using u-boot from NAND to boot to SATA SSD?
« Reply #1 on: September 04, 2015, 03:41:18 pm »
1. Don't know sorry, I would like to know to
2. No, it is not u-boot image. The entire /dev/nand1 or in my case /dev/nanda is u-boot image. uImage is compiled linux kernel, should be 3.4.107 in your case.
3. Don't know, try to find it's source code. Perhaps git clone git://git.denx.de/u-boot.git; git checkout v2014.07.
4. Don't know, never touched it.
5. You need bootloader partition which should contain u-boot image on /dev/nand1 (or /dev/nanda) with offset 32768 sectors and size 131072 sectors. This is enough to boot from SATA. If you need to boot from NAND, you will need rootfs partion which should contain rootfs image (which has /bin, /boot, /dev, /etc, /home, /lib, /run, /tmp, /usr, /var and other folders). Nand-part in this case should be something like this:
Code: [Select]
linaro@cubietruck:~$ sudo nand-part -f a20 /dev/nand
check partition table copy 0: mbr: version 0x00000200, magic softw411
OK
check partition table copy 1: mbr: version 0x00000200, magic softw411
OK
check partition table copy 2: mbr: version 0x00000200, magic softw411
OK
check partition table copy 3: mbr: version 0x00000200, magic softw411
OK
mbr: version 0x00000200, magic softw411
3 partitions
partition  1: class =         DISK, name =   bootloader, partition start =    32768, partition size =   131072 user_type=0
partition  2: class =         DISK, name =       rootfs, partition start =   163840, partition size = 14680064 user_type=0
partition  3: class =         DISK, name =        UDISK, partition start = 14843904, partition size =    98304 user_type=0
6. I'm also don't know what it depends on. Depends on boot.axf, linux/u-boot.bin, uImage or something else. But I'm using nand_root on /dev/nanda and root on /dev/mmcblk0p1. So if you want to boot from SATA, you need to set nand_root=/dev/sda1. If your kernel haven't been compiled with CONFIG_USB_MASS_STORAGE=m you will need to remove all USB flash sticks/disks from devices before booting.
7. I think u-boot have some hardcoded settings and settings from uEnv.txt are overwriting them.
« Last Edit: September 04, 2015, 03:53:08 pm by uelkfr »

Offline hvergelmir

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Using u-boot from NAND to boot to SATA SSD?
« Reply #2 on: February 07, 2016, 03:50:01 pm »
2. No, it is not u-boot image. The entire /dev/nand1 or in my case /dev/nanda is u-boot image. uImage is compiled linux kernel, should be 3.4.107 in your case.
I think you're wrong here. On my system /dev/nand1 appears to be a FAT partition/volume.

5. You need bootloader partition which should contain u-boot image on /dev/nand1 (or /dev/nanda) with offset 32768 sectors and size 131072 sectors. This is enough to boot from SATA.
Well, in theory yes. But how do I teach the u-boot image about where to find the root partition (on the SATA drive)?

6. I'm also don't know what it depends on. Depends on boot.axf, linux/u-boot.bin, uImage or something else. But I'm using nand_root on /dev/nanda and root on /dev/mmcblk0p1. So if you want to boot from SATA, you need to set nand_root=/dev/sda1. If your kernel haven't been compiled with CONFIG_USB_MASS_STORAGE=m you will need to remove all USB flash sticks/disks from devices before booting.
That hint about the USB drives is worthwhile testing. The rest I had done already to no avail.

7. I think u-boot have some hardcoded settings and settings from uEnv.txt are overwriting them.
Yep, I think so too.

Offline phelum

  • Full Member
  • ***
  • Posts: 147
  • Karma: +5/-0
    • View Profile
Re: Using u-boot from NAND to boot to SATA SSD?
« Reply #3 on: February 07, 2016, 07:12:37 pm »
Now I've got a number of questions to put the puzzle pieces together. Pointers to documentation will be perfectly fine, but if you can offer an explanation I'll take that as well.
  • How do the files on /dev/nand1 interact?
  • What is uImage on /dev/nand1? Is this another u-boot image?
  • How can I turn a u-boot script back into a human-readable form?
  • Where can I find a documentation of the parameters accepted inside linux/linux.ini on /dev/nand1?
  • Since I overwrote the NAND, is there something that needs to be written to some offset of the device outside of the partitions to get it to boot from there?
  • If I want the boot from NAND to use a root on SATA, may I use the nand_root parameter or do I have to use another (like root)?
  • Does the linux/u-boot.bin still get to use the settings from uEnv.txt in the root of /dev/nand1 or where do they come from?

So to reiterate I'd like to use the bootloader on NAND to boot to my SATA SSD.

Hi,

NAND boot starts with BROM (in ROM) which chains to boot0 (in NAND block 0) which chains to boot1 (in NAND block 2) which chains to boot.axf (in nand1) which chains to u-boot.bin (in nand1) which loads uEnv.txt and script.bin and uImage then chains to uImage (the kernel).

There is a program called bin2fex that reads script.bin and creates a readable version.

You might have overwritten the NAND but are you sure you've affected the boot blocks.  They're not easy to access.

I have a program called bootfix that will load the boot blocks.  But before you try this it might be worth connecting a monitor to the debug serial port and noting how far the boot process gets.  If it gets past boot0 and boot1 then probably your boot blocks are okay and my program won't help.  But if your boot process doesn't get that far I'd try downloading CT_NandBoot from github.com/phelum and running it.  You will need another Linux box (e.g. another CT) and also a USB cable to connect to the USB OTG port on the CT.

Whether nand_root and/or root are significant depends on the scripts buried in u-boot.bin.  For safety I'd set both to the same value.

Cheers,
Steven