New IT forum Follow us on Twitter
04 February 2012, 04:01:57 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: DreamPlug tutorial in Linux Format issue 145!
 
   Home   SHOP Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: [resolved] change nand partition sizes to boot on nand first and after load USB  (Read 3724 times)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« on: 05 June 2010, 11:11:02 pm »

Today my Sheeva run with Debian Squeeze installed in a USB disk and load uImage and uInitrd from the SD card to avoid USB latency.

After some days of running, the plug won't boot because it can't read correctly the SD.
So I format it and re-write in it the binaries to repair this.

I had thinking that it can be possible to put the Debian binaries in the nand, but I want to keep Ubuntu running to have a backup OS.

So, as the standart partitions are defined in three parts:
Quote
mtdparts=nand_mtd:0x100000@0x00000(u-boot),0x300000@0x100000(uImage)ro,0x1fc00000@0x400000(rootfs)rw

I would know if I can make a fourth partition to put the Debian binaries, for example :

Quote
mtdparts=nand_mtd:0x100000@0x00000(u-boot),0x300000@0x100000(uImage)ro,0x1fa00000@0x400000(rootfs)rw, 0x200000@0x1fe00000(deboot)ro

This resize the rootfs to 530579456 bytes (506Mo) and leave 2Mo for Debian bianries....

After this I can (I suppose) modify the 'runme.php' to flash only the binaries...


« Last Edit: 07 June 2010, 02:00:16 am by maisondouf » Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #1 on: 05 June 2010, 11:55:02 pm »

After seeing the size of debian's binairies, it's perhaps better to set the 4th partition to 12Mb
Quote
mtdparts=nand_mtd:0x100000@0x00000(u-boot),0x300000@0x100000(uImage)ro,0x1f000000@0x400000(rootfs)rw, 0xC00000@0x1f400000(deboot)ro

so occupation will be :
  • 1Mb for uboot
  • 3Mb for uImage
  • 496Mb for rootfs
  • 12Mb for '/boot' partition of debian
.

But I see that installer use other sizes :
Quote
mtdparts=orion_nand:0x400000@0x100000(uImage),0x1fb00000@0x500000(rootfs)

can apply the same modification ?

Quote
mtdparts=orion_nand:0x400000@0x100000(uImage),0x1ef00000@0x500000(rootfs),0xC00000@0x1f400000(deboot)ro

so the sizes change to :
  • 1Mb for uboot
  • 4Mb for uImage
  • 495Mb for rootfs
  • 12Mb for '/boot' partition of debian
.
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
NewIT_Marcus
Administrator
Hero Member
*****
Posts: 960


« Reply #2 on: 06 June 2010, 01:43:38 pm »

If you intend to modify the execution of the installer, you may want to look at /etc/init.d/rcS in the initrd on the USB stick.
Logged
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #3 on: 06 June 2010, 02:18:36 pm »

thanks,
I try to mount it with
Quote
mount -t ext2 initrd /mnt -o loop

I got errors !

(I try with ext3 also)
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #4 on: 06 June 2010, 04:31:48 pm »

I have set this in uboot environment
Quote
setenv mtdpartitions 'mtdparts=orion_mtd:0x400000@0x100000(uImage),0x1ef00000@0x500000(rootfs),0xc00000@0x1f400000(debian)'

When uImage is loaded (with initrd), I stop the process before flashing to enter manualy all commands.

So I can see that there is only nodes for 3 parts /dev/mtd0, /dev/mtd1 and /dev/mtd2

I try to live format mtd2 with new size with

Quote
# ubiformat -y /dev/mtd2
ubiformat: mtd2 (nand), size 531628032 bytes (507.0 MiB), 4056 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4055 -- 100 % complete 
ubiformat: 4053 eraseblocks have valid erase counter, mean value is 0
ubiformat: bad eraseblocks: 920, 921, 1945
ubiformat: formatting eraseblock 4055 -- 100 % complete 

But it seem to be always the same size 507Mb

Does I have to modify uImage to set the new sizes or is it also in initrd

Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #5 on: 06 June 2010, 04:36:29 pm »

what is the difference when we define "mtdparts" between
  • nand_mtd
  • orion_nand
  • orion_mtd

Thanks
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #6 on: 06 June 2010, 05:00:25 pm »

I finished to have this in "dmesg" :
Quote
NAND device: Manufacturer ID: 0xec, Chip ID: 0xdc (Samsung NAND 512MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 960 at 0x000007800000
Bad eraseblock 961 at 0x000007820000
Bad eraseblock 1985 at 0x00000f820000
3 cmdlinepart partitions found on MTD device orion_nand
Creating 3 MTD partitions on "orion_nand":
0x000000100000-0x000000500000 : "uImage"
0x000000500000-0x00001f400000 : "rootfs"
0x00001f400000-0x000020000000 : "debian"

but always only three nodes ...
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #7 on: 06 June 2010, 05:07:20 pm »

Bingo
Quote
# mdev -s
# ls /dev/mt*
/dev/mtd0       /dev/mtd1ro     /dev/mtdblock0
/dev/mtd0ro     /dev/mtd2       /dev/mtdblock1
/dev/mtd1       /dev/mtd2ro     /dev/mtdblock2
# ubiformat -y /dev/mtd2
ubiformat: mtd2 (nand), size 12582912 bytes (12.0 MiB), 96 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 95 -- 100 % complete 
ubiformat: 96 eraseblocks have valid erase counter, mean value is 1
ubiformat: formatting eraseblock 95 -- 100 % complete 
# ubiformat -y /dev/mtd1
ubiformat: mtd1 (nand), size 519045120 bytes (495.0 MiB), 3960 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 3959 -- 100 % complete 
ubiformat: 3957 eraseblocks have valid erase counter, mean value is 1
ubiformat: bad eraseblocks: 920, 921, 1945
ubiformat: formatting eraseblock 3959 -- 100 % complete 
#

in fact /dev/mtd0 is for uImage, /dev/mtd1 for rootfs and /dev/mtd2 for debian

I tought that /dev/mtd0 was for uboot....
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #8 on: 06 June 2010, 05:20:17 pm »

Now
Quote
***** uboot env.
mtdparts=orion_nand:0x100000@0x0(uboot),0x400000@0x100000(uImage),0x1ef00000@0x500000(rootfs),0xc00000@0x1f400000(debian)

***** dmesg
NAND device: Manufacturer ID: 0xec, Chip ID: 0xdc (Samsung NAND 512MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 960 at 0x000007800000
Bad eraseblock 961 at 0x000007820000
Bad eraseblock 1985 at 0x00000f820000
4 cmdlinepart partitions found on MTD device orion_nand
Creating 4 MTD partitions on "orion_nand":
0x000000000000-0x000000100000 : "uboot"
0x000000100000-0x000000500000 : "uImage"
0x000000500000-0x00001f400000 : "rootfs"
0x00001f400000-0x000020000000 : "debian"

**** nodes
# ls /dev/mtd*
/dev/mtd0       /dev/mtd1ro     /dev/mtd3       /dev/mtdblock1
/dev/mtd0ro     /dev/mtd2       /dev/mtd3ro     /dev/mtdblock2
/dev/mtd1       /dev/mtd2ro     /dev/mtdblock0  /dev/mtdblock3
#

Perhaps, it dangerous to allow access to 'uboot' partition, I keep it only for test period and I hide it after
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #9 on: 06 June 2010, 08:17:15 pm »

After formating in ext2 format the 4th part, I have copied the Squeeze binaries as this :

Quote
# mkfs.ext2 -L debian-boot /dev/mtdblock3
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=debian-boot
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
3072 inodes, 12288 blocks
614 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=12582912
2 block groups
8192 blocks per group, 8192 fragments per group
1536 inodes per group
Superblock backups stored on blocks:
   8193

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#
# ls /dev/m*
/dev/mem        /dev/mtd0       /dev/mtd2ro     /dev/mtdblock2
/dev/mice       /dev/mtd0ro     /dev/mtd3       /dev/mtdblock3
/dev/mmcblk0    /dev/mtd1       /dev/mtd3ro
/dev/mmcblk0p1  /dev/mtd1ro     /dev/mtdblock0
/dev/mmcblk0p2  /dev/mtd2       /dev/mtdblock1
#
# ls /mnt
# mkdir -p /mnt/SD
# mkdir -p /mnt/debian
# mount -t ext2 /dev/mmcblk0p1 /mnt/SD
# mount -t ext2 /dev/mtdblock3 /mnt/debian/
# cp -a /mnt/SD/* /mnt/debian/
#

I reboot the plug with "reboot" command.

I stop the boot proccess and under uboot, I don't find any way to load binaries in RAM for booting...

I try "ext2load nand 0:4 ...." but this out a format error,  "nand read.e 0x0800000 0x1fe00000 0x0c00000" load correctly but the "bootm" command falls also in error.

How I can load the binaries in RAM and boot them ?
 
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #10 on: 06 June 2010, 08:27:13 pm »

Do you think it's better to
   * create a file with the size of the partition filled with zero.
   * write in it at offset 0x0 the file uImage
   * write in it at offset 0x0900000 (0x01100000-0x00800000) the file uInitrd
   * copy with 'dd' the big file in the partition (without any format)
 
after arrived under uboot use the "nand read.e" to read all the part in RAM and "bootm" with same offsets as USB boot

I try this ...
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #11 on: 06 June 2010, 10:24:35 pm »

Finished !

In fact, the only read method form nand is binary read, so I have to make a image file of the 4th partition with uImage and uInitrd in it.

First I use the installer to re-write UBIFS ubuntu in the Flash-nand with the new sizes.
For this, I have modified "uboot-nand-custom.txt"
the line :
Quote
mtdpartitions mtdparts=orion_nand:0x400000@0x100000(uImage),0x1fb00000@0x500000(rootfs)
becomes
Quote
mtdpartitions mtdparts=orion_nand:0x400000@0x100000(uImage),0x1ef00000@0x500000(rootfs),0xc00000@0x1f400000(debian)
and I run the installer (without any mods in /etc/init.d.rcS)


Second after booting with the Ubuntu in the Nand, I mount the '/boot' partition of Debian Squeeze (in external USB disk) and copy 'uImage' and 'uInitrd' in a working directory.

Quote
root@ubuntu:~# mkdir squeeze
root@ubuntu:~# cd squeeze
root@ubuntu:~/squeeze# mount -t ext2 /dev/sda1 /mnt
root@ubuntu:~/squeeze# cp /mnt/uImage .
root@ubuntu:~/squeeze# cp /mnt/uInitrd .
root@ubuntu:~/squeeze# umount /mnt
root@ubuntu:~/squeeze#


Third I use a seflmade script to create the partition image file named "mkpart4"
Code:
#! /bin/sh

TOTAL_SIZE=12582912
UIMAGE_SIZE=3145728
UINITRD_SIZE=9437184

UIMAGE="uImage"
UINITRD="uInitrd"
OUTFILE="part4"
TMPFILE="tmp"

dd if=$UIMAGE bs=$UIMAGE_SIZE conv=sync of=1$TMPFILE
dd if=$UINITRD bs=$UINITRD_SIZE conv=sync of=2$TMPFILE
cat 1$TMPFILE 2$TMPFILE > $OUTFILE

rm ?$TMPFILE

ls -l

#copy to nand partition 4
#dd if=$OUTFILE of=/dev/mtdblock2 bs=65536

and I run it

Quote
root@ubuntu:~/sqeeze# ./mkpart4
0+1 records in
1+0 records out
3145728 bytes (3.1 MB) copied, 0.342115 s, 9.2 MB/s
0+1 records in
1+0 records out
9437184 bytes (9.4 MB) copied, 1.27071 s, 7.4 MB/s
total 31276
-rw-r--r-- 1 root root  3145728 Jun  6 22:26 1tmp
-rw-r--r-- 1 root root  9437184 Jun  6 22:26 2tmp
-rwxr-xr-x 1 root root      290 Jun  6 21:47 mkpart4
-rw-r--r-- 1 root root 12582912 Jun  6 22:26 part4
-rw-r--r-- 1 root root  1431260 Jun  6 21:51 uImage
-rw-r--r-- 1 root root  5422261 Jun  6 21:51 uInitrd
root@ubuntu:~/sqeeze#
I obtain a "part4" file with exactly the same size as the 4th partition

Fouth I write this file in the partition
Quote
root@ubuntu:~/sqeeze# dd if=part4 of=/dev/mtdblock2 bs=65536
192+0 records in
192+0 records out
12582912 bytes (13 MB) copied, 4.85796 s, 2.6 MB/s
root@ubuntu:~/sqeeze#

Fifth I reboot the plug and get control under uboot
Quote
root@ubuntu:~/sqeeze# reboot

I set new Uboot variables to boot

Quote
Marvell> setenv bootargs_console 'console=ttyS0,115200n8'
Marvell> setenv bootroot_usb 'root=/dev/sda2 rootdelay=10 rootfstype=ext4'
Marvell> setenv my_parts 'mtdparts=orion_nand:0x400000@0x100000(uImage),0x1ef00000@0x500000(rootfs),0xc00000@0x1f400000(debian)'
Marvell> setenv my_read 'nand read.e 0x0800000 0x1f400000 0x0c00000'
Marvell> setenv my_boot 'setenv bootargs $(bootargs_console) $(my_parts) $(bootroot_usb); run my_load; bootm 0x0800000 0x0b00000'
Marvell> saveenv
Marvell> reset

Last When I get control, I type
Quote
Marvell> run my_boot

Enjoy !
« Last Edit: 06 June 2010, 10:49:05 pm by maisondouf » Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
fragfutter
Newbie
*
Posts: 24


« Reply #12 on: 07 June 2010, 07:15:53 am »

What you are doing is copying parts of the flash to ram. Then tell u-boot where in the ram the starting points of kernel and ramdisk are. u-boot supports a combined kernel+initrd image. You just need to affix it with the correct header and it will find the ramdisk after the kernel.

You need a gzippedraw kernel (without headers) and a gzipped ext2 initrd.

To get a raw kernel from an uImage
Code:
dd if=uImage of=zImage bs=64 skip=1

same goes for uInitrd, just remove 64 bytes.

Then pack them together
Code:
mkimage -A arm -O linux -T multi -C gzip \
   -n 'my combined image' \
   -d zImage:zInitrd \
   uMulti

the resulting uMulti can be flashed or transfered with tftp and booted with no second memory address.
Logged
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #13 on: 08 June 2010, 06:50:27 pm »

Thanks a lot, I wouldn't know this...

I try this on saturday
Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
maisondouf
Jr. Member
**
Posts: 68


Crazy hacker's family since 1982


WWW
« Reply #14 on: 12 June 2010, 12:10:31 am »

Yeah ! It will be better than add zeros to the entire partition, thanks.

The mkimage run fine, but how I can say to the plug to load only the size of the uMulti rather than the entire size of the partition.

I use "nand read.e 0x0800000 0x1f400000 0x0c00000" and I would replace the last parameter '0x0c00000' (the maximum size) with the real size of uMulti.

This only to speed the boot !

Logged

NSLU2 owner since 4 years...
Very new owner of a black eSata Sheevaplug.
(Wiki en français http://plug.maisondouf.fr)
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!