Sunday, July 1, 2012

Getting Fedora-17 ARM images to understand booting LVM volumes

In order to get your uInitrd to understand booting from a LVM volume, you need to regenerate the initramfs and uInitrd images with the LVM bits.  To do so, follow these steps (substitute your versions as necessary):
  1. Install LVM (yum -y install lvm2)
  2. Update initramfs image (in /boot run dracut -f initramfs-3.3.6-3.fc17.armv5tel.kirkwood.img 3.3.6-3.fc17.armv5tel.k
    irkwood)
  3. Update uInitrd image (in /boot/uboot run mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n initramfs -d /boot/ini
    tramfs-3.3.6-3.fc17.armv5tel.kirkwood.img uInitrd-kirkwood)
So now you're wondering how to do this if you don't already have a running system?  Well, in theory you can run dracut and mkimage from a host system, but I've been unsuccessful getting a working image that way.  So to create my bootstrap uInitrd, I built a throwaway system, then used uInitrd to boot my LVM enabled system. 

The easiest approach would be to do the above steps, the move the boot media to a another computer, and copy the root filesystem to a temporary file, delete the partition with the root filesystem, and add it to a volume group (as a PV) and create a LV and copy the root filesystem back.  It sounds complicated but it's not.

GuruPlug booting from MMC

Back in 2010, I wrote how to put Fedora 12 on a GuruPlug.  Now in 2012, I find myself wanting a more modern operating system.  Knowing that a Fedora 17 image is available, I want to prepare my GuruPlug to boot Fedora 17.  One goal that I didn't achieve last time was to boot using an initrd so that I could have LVM volume management (and presumably encryption) of the root filesystem.  At the time, the uboot code to support loading an image from MMC was not yet available, so instead I opted to use the GuruPlug flash for the kernel (using a non-Fedora kernel) and boot directly to the partitioned ext3 formatted root.

I was having to use a non-Fedora kernel which was less than optimal.  Also, having the kernel in nand made it harder to update.  If we have it on the micro SD card, its easy to update using standard update utilities (yum).

Now the uboot image is available, and we can load both uImage and uInitrd from MMC, so I'm going to do some upgrades.

First item is to get that updated uboot code loaded.  Again, we are lucky that someone else had done the work of compiling for us.  On this page, you can download the updated uboot 2011.12 (Jan 08 2012) image (u-boot.kwb).  In my previous explanation of upgrading, I explained tftp loading of the  images.  This time, I'm going to use a usb stick.  Newer uboots seem much less finicky.

Be sure and printenv a copy of your environment as you will lose all these settings on upgrade.

U-Boot 2010.03-01161-gd91b0a9 (Apr 22 2010 - 03:24:41)                         
Marvell-GuruPlug                                                               
                                                                               
SoC:   Kirkwood 88F6281_A0                                                     
DRAM:  512 MB                                                                  
NAND:  512 MiB                                                                 
In:    serial                                                                  
Out:   serial                                                                  
Err:   serial                                                                  
Net:   egiga0, egiga1                                                          
88E1121 Initialized on egiga0                                                  
88E1121 Initialized on egiga1                                                  
Hit any key to stop autoboot:  0                                               

Marvell>> printenv                                                             
bootcmd=${x_bootcmd_usb}; ${x_bootcmd_kernel}; setenv bootargs ${x_bootargs} ${x_bootargs_root}; bootm 0x6400000
bootdelay=3                                                                    
baudrate=115200                                                                
x_bootcmd_usb=usb start                                                        
x_bootcmd_kernel=nand read.e 0x6400000 0x100000 0x400000                       
x_bootargs=console=ttyS0,115200                                                
ethact=egiga0                                                                  
ethaddr=01:02:03:04:05:06                                                      
eth1addr=01:02:03:04:05:07                                                     
x_bootargs_root=ubi.mtd=2 root=0811 rootdelay=10                               
stdin=serial                                                                   
stdout=serial                                                                  
stderr=serial                                                                  
                                                                               
Environment size: 412/131068 bytes                                             
                                                                

Marvell>> usb start                                                            
(Re)start USB...                                                               
USB:   Register 10011 NbrPorts 1                                               
USB EHCI 1.00                                                                  
scanning bus for devices... 3 USB Device(s) found                              
       scanning bus for storage devices... Device NOT ready                    
   Request Sense returned 02 3A 00                                             
1 Storage Device(s) found                                                      

Marvell>> usb part                                                             
## Unknown partition table                                                     
                                                                               
                                                                               
Partition Map for USB device 1  --   Partition Type: DOS                       
                                                                               
Partition     Start Sector     Num Sectors     Type                            
    1                   63        15794113       c                             
                                                                               
## Unknown partition table                                                     
                                                                               
## Unknown partition table                                                     
                                                                               
## Unknown partition table                                                     
Marvell>> fatload usb 1:1 0x0800000 u-boot.kwb                                 
reading u-boot.kwb                                                             
......................                                                         
                                                                               
227200 bytes read                                                              
Marvell>> nand erase 0x0 0x60000                                               
                                                                               
NAND erase: device 0 offset 0x0, size 0x60000                                  
Erasing at 0x40000 -- 100% complete.                                           
OK                                                                             
Marvell>> nand write 0x0800000 0x0 0x60000                                     
                                                                               
NAND write: device 0 offset 0x0, size 0x60000                                  
 393216 bytes written: OK                                                      
Marvell>> reset                                                                
resetting ...                                                                  
                                                                               
                                                                               
U-Boot 2011.12 (Jan 08 2012 - 21:46:50)                                        
Marvell-GuruPlug                                                               
                                                                               
SoC:   Kirkwood 88F6281_A0                                                     
DRAM:  512 MiB                                                                 
WARNING: Caches not enabled                                                    
NAND:  512 MiB                                                                 
*** Warning - bad CRC, using default environment                               
                                                                               
In:    serial                                                                  
Out:   serial                                                                  
Err:   serial                                                                  
Net:   egiga0, egiga1                                                          
88E1121 Initialized on egiga0                                                  
88E1121 Initialized on egiga1                                                  
Hit any key to stop autoboot:  0                                               
Marvell>>      
  

Note that I searched for partitions and uboot told me that my USB FAT filesystem was on USB (for GuruPlug MMC appears as USB) device 1, parition 1, or 1:1.

Now we need to fix the environment that was lost.

  
Marvell>> setenv ethaddr 01:02:03:04:05:06                                     
Marvell
>> setenv eth1addr 01:02:03:04:05:07                                    
Marvell
>> setenv x_bootcmd_usb 'usb start'                                       
Marvell
>> setenv x_bootcmd_kernel 'nand read.e 0x6400000 0x100000 0x400000'    
Marvell
>> setenv x_bootargs_root 'root=ubi.mtd=2 root=0811 rootdelay=10'       
Marvell
>> setenv bootcmd '${x_bootcmd_usb}; ${x_bootcmd_kernel}; setenv bootargs
 ${x_bootargs} ${x_bootargs_root}; bootm 0x6400000'                                      
Marvell
>> saveenv                                                              
Saving Environment to NAND...                                                  
Erasing Nand...                                                                
Erasing at 0x60000 -- 100% complete.                                           
Writing to Nand... done                                                        
Marvell
>>
             
That gets you back to where you were, but with the updated uboot.  If you want to go ahead and update to Fedora 17, you can then download the Kirkwood ARM image, copy it to a micro SD card, and then boot it by changing these variables:

bootargs=console=ttyS0,115200 root=LABEL=rootfs rootdelay=10
bootcmd=run x_bootcmd_usb; ${x_bootcmd_uimage}; ${x_bootcmd_uinitrd}; setenv bo}
x_boot_mem=bootm 0x00800000 0x01100000                                         
x_bootargs=console=ttyS0,115200                                                
x_bootargs_root=root=LABEL=rootfs rootdelay=10                                 
x_bootcmd_ethernet=ping 192.168.2.1                                            
x_bootcmd_kernel=nand read.e 0x6400000 0x100000 0x400000                       
x_bootcmd_uimage=fatload usb 1:1 0x00800000 uImage-kirkwood                    
x_bootcmd_uinitrd=fatload usb 1:1 0x01100000 uInitrd-kirkwood
x_bootcmd_usb=usb start; usb tree; usb part; fatinfo usb 1; fatls usb 1  
      
         
Then your boot will look something like this:

                                                                      U-Boot 2011.12 (Jan 08 2012 - 21:46:50)                                        
Marvell-GuruPlug                                                               
                                                                               
SoC:   Kirkwood 88F6281_A0                                                     
DRAM:  512 MiB                                                                 
WARNING: Caches not enabled                                                    
NAND:  512 MiB                                                                 
In:    serial                                                                  
Out:   serial                                                                  
Err:   serial                                                                  
Net:   egiga0, egiga1                                                          
88E1121 Initialized on egiga0                                                  
88E1121 Initialized on egiga1                                                  
Hit any key to stop autoboot:  0                                               
(Re)start USB...                                                               
USB:   Register 10011 NbrPorts 1                                               
USB EHCI 1.00                                                                  
scanning bus for devices... 3 USB Device(s) found                              
       scanning bus for storage devices... Device NOT ready                    
   Request Sense returned 02 3A 00                                             
2 Storage Device(s) found                                                      
                                                                               
Device Tree:                                                                   
  1  Hub (480 Mb/s, 0mA)                                                       
  |  u-boot EHCI Host Controller                                               
  |                                                                            
  +-2  Hub (480 Mb/s, 100mA)                                                   
    |   USB2.0 Hub                                                             
    |                                                                          
    +-3  Mass Storage (480 Mb/s, 500mA)                                        
          USB Storage 000000009909                                             
                                                                               
## Unknown partition table                                                     
                                                                               
                                                                               
Partition Map for USB device 1  --   Partition Type: DOS                       
                                                                               
Partition     Start Sector     Num Sectors     Type                            
    1                 2048          524288       c                             
    2               526336        15626240      8e                             
Interface:  USB                                                                
  Device 1: Vendor: Generic  Rev: 9909 Prod: STORAGE DEVICE                    
            Type: Removable Hard Disk                                          
            Capacity: 7887.0 MB = 7.7 GB (16152576 x 512)                      
Partition 1: Filesystem: FAT16 "uboot      "                                   
      436   readme.txt                                                         
       71   boot.scr                                                           
  3244464   uimage-3.3.6-3.fc17.armv5tel.kirkwood                              
  9808824   uinitrd-3.3.6-3.fc17.armv5tel.kirkwood                             
  3292112   uimage-kirkwood                                                    
 12165177   uinitrd-kirkwood                                                   
       93   klist.txt                                                                     
  3291896   uimage-3.4.2-3.fc17.armv5tel.kirkwood                              
 12142387   uinitrd-3.4.2-3.fc17.armv5tel.kirkwood                             
  3292112   uimage-3.4.3-1.fc17.armv5tel.kirkwood                              
 12165177   uinitrd-3.4.3-1.fc17.armv5tel.kirkwood                             
                                                                               
13 file(s), 0 dir(s)                                                           
                                                                               
reading uImage-kirkwood                                                        
                                                                               
3292112 bytes read                                                             
reading uInitrd-kirkwood                                                       
                                                                               
12165177 bytes read                                                            
## Booting kernel from Legacy Image at 00800000 ...                            
   Image Name:   3.4.3-1.fc17.armv5tel.kirkwood                                
   Image Type:   ARM Linux Kernel Image (uncompressed)                         
   Data Size:    3292048 Bytes = 3.1 MiB                                       
   Load Address: 00008000                                                      
   Entry Point:  00008000                                                      
   Verifying Checksum ... OK                                                   
## Loading init Ramdisk from Legacy Image at 01100000 ...                      
   Image Name:   initramfs                                                     
   Image Type:   ARM Linux RAMDisk Image (uncompressed)                        
   Data Size:    12165113 Bytes = 11.6 MiB                                     
   Load Address: 00000000                                                      
   Entry Point:  00000000                                                      
   Verifying Checksum ... OK                                                   
   Loading Kernel Image ... OK                                                 
OK                                                                             
                                                                               
Starting kernel ...                                                            
                                                                               
Uncompressing Linux... done, booting the kernel.                               
[    0.000000] Booting Linux on physical CPU 0                                 
...