All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] Writing to SD partitions from u-boot
@ 2014-02-28  9:46 David Cemin
  2014-02-28 11:23 ` Wolfgang Denk
  0 siblings, 1 reply; 5+ messages in thread
From: David Cemin @ 2014-02-28  9:46 UTC (permalink / raw)
  To: u-boot

Hi,

I am trying to use u-boot to replace kernel and filesystem in the SD card.
 I have this set of partitions:

SOCFPGA_CYCLONE5 # mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     2121728         1000001         00000000-01     0b
  2     14336           2097153         00000000-02     83
  3     2048            2049            00000000-03     a2


First partition is used to store kernel and dtb files. Second, to store
filesystem and the third stores preloader and u-boot.

Currently, i boot the board by calling mmcload and mmcboot.

mmcboot=setenv bootargs console=ttyS0,57600 root=${mmcroot} rw
rootwait;bootz ${loadaddr} - ${fdtaddr}
mmcload=mmc rescan;${mmcloadcmd} mmc 0:${mmcloadpart} ${loadaddr}
${bootimage};${mmcloadcmd} mmc 0:${mmcloadpart} ${fdtaddr} ${fdtimage}
mmcloadcmd=fatload
mmcloadpart=1
mmcroot=/dev/mmcblk0p2

mmcload script loads kernel and dtb from sdcard to memory and mmcboot boots
using this values and setting root do the second partition of the sdcard.


My first idea would be:

1) tftp rootfs to memory and rewrite the partition 2 from my card.
2) tftp kernel and dtb files and boot from there.

The item 2) can be achieved by calling the script getkernel below:
getkernel=setenv bootargs console=ttyS0,57600 root=${mmcroot} rw
rootwait;tftp ${loadaddr} ${bootimage}; tftp ${fdtaddr} ${fdtimage}; bootz
${loadaddr} - ${fdtaddr}


I am having troubles with the first step though.

First I downloaded the rootfs.img to an address that its not in use
($fpgadata = 0x200000 and $fsimage=rootfs.dtb) :
tftp ${fpgadata} ${fsimage}

My second partition is fomated as ext3 (type 83), but u-boot doesnt have
commands to write to ext partitions. I tried using fatwrite, but it didnt
work, and my first guess is that fatwrite is used to write to partitions
using fat.

 fatwrite mmc 0:2 ${fpgadata} rootfs.img 52428800

** Unable to use mmc 0:2 for fatwrite **

So another option would be using mmc write, but i cant change the partition
from it so that i can write. mmc write has the following syntax:
mmc write addr blk# cnt

So it will write in the current mmc partition the content of the address
addr with size indexed by blk# and cnt.

SOCFPGA_CYCLONE5 # mmc dev 0 2
Card doesn't support part_switch


So i dont know what actually would be easier to do. I could:

1) Change partition 2 to ubifs, and hope that the ubi utilities have
read/write functions implemented;
2) Write the functions in c to write to ext filesystems and export that to
use in the macros on boot prompt

So does anyone have any idea ? It can be another approach or even some
thoughts in what I am trying to do. That would be very helpful !

Thank you.

-- 
David Cemin
+49 0152-3670-8342

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] Writing to SD partitions from u-boot
  2014-02-28  9:46 [U-Boot] Writing to SD partitions from u-boot David Cemin
@ 2014-02-28 11:23 ` Wolfgang Denk
  2014-02-28 12:12   ` David Cemin
       [not found]   ` <CADqAesiqEdc41z1zc7nAQJXLaKe5q-cTUbXwi3N_bPJTJeyKaQ@mail.gmail.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Wolfgang Denk @ 2014-02-28 11:23 UTC (permalink / raw)
  To: u-boot

Dear David,

In message <CADqAesiEy5dwjZ5V7qHSVSsEDiOFLzWRWRzY4xgRKdd=gri3uw@mail.gmail.com> you wrote:
>
> First partition is used to store kernel and dtb files. Second, to store
> filesystem and the third stores preloader and u-boot.

Actually this information is mostly irrelevant.  Partitions do not
play a big role here - what matters are file systems.

> I am having troubles with the first step though.
> 
> First I downloaded the rootfs.img to an address that its not in use
> ($fpgadata = 0x200000 and $fsimage=rootfs.dtb) :
> tftp ${fpgadata} ${fsimage}
> 
> My second partition is fomated as ext3 (type 83), but u-boot doesnt have
> commands to write to ext partitions. I tried using fatwrite, but it didnt
> work, and my first guess is that fatwrite is used to write to partitions
> using fat.

This makes no sense.  If you download a file system _image_ then you
cannot use any file system level commands to write such an image - you
must write the image directly to the storage device.  In your case,
with a MMC based storage device, that would be done using "mmc write".

There are more errors in your posting:

- U-Boot does support writing to ext file system - EXT4, to be
  precise. See CONFIG_CMD_EXT4_WRITE

- fatwrite (and the other fat* commands) operate on FAT file systems;
  it does not matter of these are on partitions with FAT partition
  type.  If you like, you can also put a FAT file system on a partitin
  marked as "swap space" (type 82) and it will just work fine.

But as mentioned - using any file system level commands is inherently
wrong when you try to store a file system image.

> So another option would be using mmc write, but i cant change the partition
> from it so that i can write. mmc write has the following syntax:
> mmc write addr blk# cnt

s is the correct thing to do.

> So it will write in the current mmc partition the content of the address
> addr with size indexed by blk# and cnt.
> 
> SOCFPGA_CYCLONE5 # mmc dev 0 2
> Card doesn't support part_switch

Well, not this is your real problem.  Fix it.

> 1) Change partition 2 to ubifs, and hope that the ubi utilities have
> read/write functions implemented;

It makes no sense to use UBIFS on a MMC device.

> 2) Write the functions in c to write to ext filesystems and export that to
> use in the macros on boot prompt

You do not want to write to an ext (or any other) file system - you
want to write to the raw storage device.  For MMC, this is done with
the "mmc write" command.  If this is not working for you (because you
cannot switch partitions), then you should fix the root cause - the
failing partition switch.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Remember that the best relationship is one in  which  your  love  for
each other exceeds your need for each other.             - Dalai Lama

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] Writing to SD partitions from u-boot
  2014-02-28 11:23 ` Wolfgang Denk
@ 2014-02-28 12:12   ` David Cemin
       [not found]   ` <CADqAesiqEdc41z1zc7nAQJXLaKe5q-cTUbXwi3N_bPJTJeyKaQ@mail.gmail.com>
  1 sibling, 0 replies; 5+ messages in thread
From: David Cemin @ 2014-02-28 12:12 UTC (permalink / raw)
  To: u-boot

Hi,

I figured that it supports writing to ext4 filesystems and I changed it
already. It works.

But that doesnt actually matter because what I do want to do is to write to
the raw storage device.

So, browsing the code, i found that I cant switch partitions when my SD
card has mmc->part_config = 0xff. This is the default value which is set on
the function mmc_startup, on drivers/mmc/mmc.c.

This value is set below if my sd card is a mmc and if version is >= than 4.
 So, I was all the time using a SD card and not an MMC card, but i double
checked it and the statement:

if (!IS_SD(mmc) && (mmc->version >= MMC_VERSION_4)) {


Wont be true, because:
 IS_SD(mmc) = 0x20000 and mmc->version = 0x20020

Apparently I should use a mmc card in order to use the mmc functions, which
makes perfect sense to me :)

Do we have on u-boot flash write / flash read functions implemented, so
that I can write / read the sd card ?

Thank you.

best regards,

--
David


On Fri, Feb 28, 2014 at 12:23 PM, Wolfgang Denk <wd@denx.de> wrote:

> Dear David,
>
> In message <CADqAesiEy5dwjZ5V7qHSVSsEDiOFLzWRWRzY4xgRKdd=
> gri3uw at mail.gmail.com> you wrote:
> >
> > First partition is used to store kernel and dtb files. Second, to store
> > filesystem and the third stores preloader and u-boot.
>
> Actually this information is mostly irrelevant.  Partitions do not
> play a big role here - what matters are file systems.
>
> > I am having troubles with the first step though.
> >
> > First I downloaded the rootfs.img to an address that its not in use
> > ($fpgadata = 0x200000 and $fsimage=rootfs.dtb) :
> > tftp ${fpgadata} ${fsimage}
> >
> > My second partition is fomated as ext3 (type 83), but u-boot doesnt have
> > commands to write to ext partitions. I tried using fatwrite, but it didnt
> > work, and my first guess is that fatwrite is used to write to partitions
> > using fat.
>
> This makes no sense.  If you download a file system _image_ then you
> cannot use any file system level commands to write such an image - you
> must write the image directly to the storage device.  In your case,
> with a MMC based storage device, that would be done using "mmc write".
>
> There are more errors in your posting:
>
> - U-Boot does support writing to ext file system - EXT4, to be
>   precise. See CONFIG_CMD_EXT4_WRITE
>
> - fatwrite (and the other fat* commands) operate on FAT file systems;
>   it does not matter of these are on partitions with FAT partition
>   type.  If you like, you can also put a FAT file system on a partitin
>   marked as "swap space" (type 82) and it will just work fine.
>
> But as mentioned - using any file system level commands is inherently
> wrong when you try to store a file system image.
>
> > So another option would be using mmc write, but i cant change the
> partition
> > from it so that i can write. mmc write has the following syntax:
> > mmc write addr blk# cnt
>
> s is the correct thing to do.
>
> > So it will write in the current mmc partition the content of the address
> > addr with size indexed by blk# and cnt.
> >
> > SOCFPGA_CYCLONE5 # mmc dev 0 2
> > Card doesn't support part_switch
>
> Well, not this is your real problem.  Fix it.
>
> > 1) Change partition 2 to ubifs, and hope that the ubi utilities have
> > read/write functions implemented;
>
> It makes no sense to use UBIFS on a MMC device.
>
> > 2) Write the functions in c to write to ext filesystems and export that
> to
> > use in the macros on boot prompt
>
> You do not want to write to an ext (or any other) file system - you
> want to write to the raw storage device.  For MMC, this is done with
> the "mmc write" command.  If this is not working for you (because you
> cannot switch partitions), then you should fix the root cause - the
> failing partition switch.
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> Remember that the best relationship is one in  which  your  love  for
> each other exceeds your need for each other.             - Dalai Lama
>



-- 
David Cemin
+49 0152-3670-8342

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] Writing to SD partitions from u-boot
       [not found]   ` <CADqAesiqEdc41z1zc7nAQJXLaKe5q-cTUbXwi3N_bPJTJeyKaQ@mail.gmail.com>
@ 2014-02-28 14:50     ` Wolfgang Denk
       [not found]     ` <20140228145054.9B5C4381338@gemini.denx.de>
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfgang Denk @ 2014-02-28 14:50 UTC (permalink / raw)
  To: u-boot

Dear David,

In message <CADqAesiqEdc41z1zc7nAQJXLaKe5q-cTUbXwi3N_bPJTJeyKaQ@mail.gmail.com> you wrote:
>
> This value is set below if my sd card is a mmc and if version is >= than 4.
>  So, I was all the time using a SD card and not an MMC card, but i double
> checked it and the statement:
> 
> if (!IS_SD(mmc) && (mmc->version >= MMC_VERSION_4)) {
> 
> 
> Wont be true, because:
>  IS_SD(mmc) = 0x20000 and mmc->version = 0x20020
> 
> Apparently I should use a mmc card in order to use the mmc functions, which
> makes perfect sense to me :)

"mmc read" and "mmc write" work just fine on SDcards, too.

> On Fri, Feb 28, 2014 at 12:23 PM, Wolfgang Denk <wd@denx.de> wrote:
> 
> > Dear David,
...
[full quote deleted]

Please stop top-posting / full-quoting.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I see that Microsoft's campaign  to  destroy  all  knowledge  of  any
operating   environment   but  its  own  environment-of-the-year  has
succeeded in creating a generation of users who don't understand  the
concept of a shell...
            -- L. Peter Deutsch in <m0x5jNX-000R2UC@lamp.aladdin.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] Writing to SD partitions from u-boot
       [not found]       ` <CADqAesgH4uFznSFYZutvsB64Tr6gD3DwL4kttUGqinWUmhKcMQ@mail.gmail.com>
@ 2014-02-28 17:56         ` Wolfgang Denk
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Denk @ 2014-02-28 17:56 UTC (permalink / raw)
  To: u-boot

Dear David,

please make sure to keep the mailing list on Cc:

In message <CADqAesgH4uFznSFYZutvsB64Tr6gD3DwL4kttUGqinWUmhKcMQ@mail.gmail.com> you wrote:
>
> Ok, thats good to know, thank you. That doesnt explain though what kind of
> sd cards I should use to be able to switch partitions. Am I
> misunderstanding the function that does that? From the code, i will only be
> able to do that when mmc->part_config is different than 0xff
> (MMCPART_NOAVAILABLE). What should I do with my card to get it to work ?

I don't see why exactly you need to switch partitions...

The "mme part" command will print you the numbers of the first sector
in each partition, so it's trivial to write an image.

For example, assume we want to write the file system image
"rootfs.img" into the second partition of an SDcard:

=> tftp $loadaddr rootfs.img
Using FEC device
TFTP from server 192.168.1.1; our IP address is 192.168.20.56
Filename 'rootfs.img'.
Load address: 0x70800000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ############
         763.7 KiB/s
done
Bytes transferred = 16385024 (fa0400 hex)
=> setexpr cnt $filesize + 0x1ff
=> setexpr cnt $cnt / 0x200
=> mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     8192            131072          00000000-01     83
  2     139264          7753728         00000000-02     83
=> mmc write $loadaddr 0x22000 $cnt

MMC write: dev # 0, block # 139264, count 32002 ... 32002 blocks write: OK


The only "tricky" part here is to convert the decimal number 139264
for the start sector of partition 2 into hexadecimal format as
expected by "mmc write": decimal 139264 = 0x22000.

[Note that even the conversion of the file size in bytes into block
numbers can be scripted with two simple "setexpr" commands.]


Hope this helps.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
When in doubt, mumble;   when in trouble, delegate;  when in  charge,
ponder.                                             -- James H. Boren

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-28 17:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-28  9:46 [U-Boot] Writing to SD partitions from u-boot David Cemin
2014-02-28 11:23 ` Wolfgang Denk
2014-02-28 12:12   ` David Cemin
     [not found]   ` <CADqAesiqEdc41z1zc7nAQJXLaKe5q-cTUbXwi3N_bPJTJeyKaQ@mail.gmail.com>
2014-02-28 14:50     ` Wolfgang Denk
     [not found]     ` <20140228145054.9B5C4381338@gemini.denx.de>
     [not found]       ` <CADqAesgH4uFznSFYZutvsB64Tr6gD3DwL4kttUGqinWUmhKcMQ@mail.gmail.com>
2014-02-28 17:56         ` Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.