mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* How to overwrite an ext partition on eMMC
@ 2016-07-04 12:32 Martin Hollingsworth
  2016-07-05  6:55 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Hollingsworth @ 2016-07-04 12:32 UTC (permalink / raw)
  To: barebox

Hello folks,
I'm a little lost when trying to overwrite an ext partition on an eMMC memory inside of barebox. Your help finding the mistake is appreciated.

My Setup:
- Custom board with iMX6, 4GB eMMC and SD card reader (similar to Freescale SabreSD board)
- Using PTXdist to build barebox 2016.05.0 and linux
- The eMMC chip offers wear levelling, so I write a filesystem directly to it (using ptxdist created hd.img file flashed directly)
- The eMMC is partitioned as follows:
0x0, Size 1k --> partition table
0x400, Size 8M --> barebox and barebox_env (offset 0x400 forced by iMX6)
0x800400, Size 1G --> ext filesystem with rootfs and kernel

With this layout so far everything works fine. Now I would like to implement an update mechanism, where barebox erases the complete ext partition and replaces it. Under linux I would use something like dd and let it start at 0x800400. On barebox I have to use memcpy (thanks to Sascha for the hint http://lists.infradead.org/pipermail/barebox/2011-April/003308.html ) and this is where I get stuck.

So I first add partitions so that the memory area is listed under /dev:
devfs_add_partition("mmc3", 0x0, SZ_1K, DEVFS_PARTITION_FIXED, "mmc3.partable"); 
devfs_add_partition("mmc3", SZ_1K, SZ_8M, DEVFS_PARTITION_FIXED, "mmc3.barebox");
devfs_add_partition("mmc3", ( SZ_1K + SZ_8M ), SZ_1G, DEVFS_PARTITION_FIXED, "mmc3.rootfs");

This works for clearing the partitions data using memset:
memset -d /dev/mmc3.rootfs 0x0 0x0 1073741824 

However when I try to copy the root.ext2 filesystem onto this memory area, I can't mount the partition afterwards:
memcpy -s /mnt/sd/root.ext2 -d /dev/mmc3.rootfs 0 536870912
mount /dev/mmc3.rootfs /mnt/mmc/
mount: No such file or directory

I am questioning my approach, as I am not sure if it is correct to write an ext2 file directly to memory. Or am I making some other basic mistake here?

Thanks for your help and cheers,
Martin

--
M.Eng. Martin Hollingsworth
Medical Systems Engineering
 
ITK Engineering AG
Im Speyerer Tal 6
D-76761 Rülzheim
Tel.: +49 7272 7703-510
Fax: +49 7272 7703-100
 
mailto:martin.hollingsworth@itk-engineering.de

_____________________________________________________________
ITK Engineering AG  Im Speyerer Tal 6  76761 Rülzheim
Tel.: +49 7272 7703-0 Fax: +49 7272 7703-100 mailto:info@itk-engineering.de http://www.itk-engineering.de

Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Josef Würth Vorstand/Executive Board: Michael Englert (Vorsitzender), Dr. Helmuth Stahl Sitz der Gesellschaft/Registered Office: 76773 Kuhardt/Pfalz Registergericht/Registered Court: Amtsgericht Landau, HRB 30139 USt.-ID-Nr./VAT-ID-No. DE813165046
 _____________________________________________________________



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: How to overwrite an ext partition on eMMC
  2016-07-04 12:32 How to overwrite an ext partition on eMMC Martin Hollingsworth
@ 2016-07-05  6:55 ` Sascha Hauer
  2016-07-05  9:32   ` AW: " Martin Hollingsworth
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2016-07-05  6:55 UTC (permalink / raw)
  To: Martin Hollingsworth; +Cc: barebox

On Mon, Jul 04, 2016 at 12:32:04PM +0000, Martin Hollingsworth wrote:
> Hello folks,
> I'm a little lost when trying to overwrite an ext partition on an eMMC
> memory inside of barebox. Your help finding the mistake is
> appreciated.
> 
> My Setup:
> - Custom board with iMX6, 4GB eMMC and SD card reader (similar to Freescale SabreSD board)
> - Using PTXdist to build barebox 2016.05.0 and linux
> - The eMMC chip offers wear levelling, so I write a filesystem directly to it (using ptxdist created hd.img file flashed directly)
> - The eMMC is partitioned as follows:
> 0x0, Size 1k --> partition table
> 0x400, Size 8M --> barebox and barebox_env (offset 0x400 forced by iMX6)
> 0x800400, Size 1G --> ext filesystem with rootfs and kernel
> 
> With this layout so far everything works fine. Now I would like to
> implement an update mechanism, where barebox erases the complete ext
> partition and replaces it. Under linux I would use something like dd
> and let it start at 0x800400. On barebox I have to use memcpy (thanks
> to Sascha for the hint
> http://lists.infradead.org/pipermail/barebox/2011-April/003308.html )
> and this is where I get stuck.
> 
> So I first add partitions so that the memory area is listed under /dev:
> devfs_add_partition("mmc3", 0x0, SZ_1K, DEVFS_PARTITION_FIXED, "mmc3.partable"); 
> devfs_add_partition("mmc3", SZ_1K, SZ_8M, DEVFS_PARTITION_FIXED, "mmc3.barebox");
> devfs_add_partition("mmc3", ( SZ_1K + SZ_8M ), SZ_1G, DEVFS_PARTITION_FIXED, "mmc3.rootfs");

Why don't you use the partitions from the partition table on the device?
I would assume you use /dev/mmc3.2 for the rootfs.

> 
> This works for clearing the partitions data using memset:
> memset -d /dev/mmc3.rootfs 0x0 0x0 1073741824 
> 
> However when I try to copy the root.ext2 filesystem onto this memory area, I can't mount the partition afterwards:
> memcpy -s /mnt/sd/root.ext2 -d /dev/mmc3.rootfs 0 536870912

memcpy needs <src> <dest> <count> positional arguments. With the above
536870912 is the offset in the destination file and not the size to
copy. What you want is:

memcpy -s /mnt/sd/root.ext2 -d /dev/mmc3.rootfs 0 0 536870912

Anyway, you don't need memset/memcpy at all to accomplish your task, the
following should do it:

cp /dev/zero /dev/mmc3.rootfs
cp /mnt/sd/root.ext2 /dev/mmc3.rootfs

Also I have never seen that it's necessary to erase the remaining parts
of a partition when the new image is smaller than the partition.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* AW: How to overwrite an ext partition on eMMC
  2016-07-05  6:55 ` Sascha Hauer
@ 2016-07-05  9:32   ` Martin Hollingsworth
  2016-07-05 10:06     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Hollingsworth @ 2016-07-05  9:32 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi Sascha,
huge thanks, that was just the right push in the right direction. Both suggested methods - cp and memcpy - work fine. Problem solved.

> Why don't you use the partitions from the partition table on the device?
> I would assume you use /dev/mmc3.2 for the rootfs.

I assume you are referring to using "detect -a" to find the device, which is then registered as mmc3.0 (for first partition). As I was struggling to write the root.ext2 onto that device I decided to try using the devfs_add_partition() method, as all nand flash based devices I have as reference use this approach. However I just verified, using the detected partition works as well and it is probably the better way of doing it, as the partitions can be moved around more easily.

In another side question you write: "I would assume you use /dev/mmc3.2 for the rootfs". As I currently only copy the Barebox raw onto the eMMC offset 0x400 for iMX6 it is not listed as partition under /dev/. What is the standard approach here, should the Barebox best be a FAT32 partition so it is listed?

Thanks and regards,
Martin

--
M.Eng. Martin Hollingsworth
Medical Systems Engineering
 
ITK Engineering AG
Im Speyerer Tal 6
D-76761 Rülzheim
Tel.: +49 7272 7703-510
Fax: +49 7272 7703-100
 
mailto:martin.hollingsworth@itk-engineering.de

_____________________________________________________________
ITK Engineering AG  Im Speyerer Tal 6  76761 Rülzheim
Tel.: +49 7272 7703-0 Fax: +49 7272 7703-100 mailto:info@itk-engineering.de http://www.itk-engineering.de

Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Josef Würth Vorstand/Executive Board: Michael Englert (Vorsitzender), Dr. Helmuth Stahl Sitz der Gesellschaft/Registered Office: 76773 Kuhardt/Pfalz Registergericht/Registered Court: Amtsgericht Landau, HRB 30139 USt.-ID-Nr./VAT-ID-No. DE813165046
 _____________________________________________________________

-----Ursprüngliche Nachricht-----
Von: Sascha Hauer [mailto:s.hauer@pengutronix.de] 
Gesendet: Dienstag, 5. Juli 2016 08:55
An: Martin Hollingsworth
Cc: barebox@lists.infradead.org
Betreff: Re: How to overwrite an ext partition on eMMC

On Mon, Jul 04, 2016 at 12:32:04PM +0000, Martin Hollingsworth wrote:
> Hello folks,
> I'm a little lost when trying to overwrite an ext partition on an eMMC 
> memory inside of barebox. Your help finding the mistake is 
> appreciated.
> 
> My Setup:
> - Custom board with iMX6, 4GB eMMC and SD card reader (similar to 
> Freescale SabreSD board)
> - Using PTXdist to build barebox 2016.05.0 and linux
> - The eMMC chip offers wear levelling, so I write a filesystem 
> directly to it (using ptxdist created hd.img file flashed directly)
> - The eMMC is partitioned as follows:
> 0x0, Size 1k --> partition table
> 0x400, Size 8M --> barebox and barebox_env (offset 0x400 forced by 
> iMX6) 0x800400, Size 1G --> ext filesystem with rootfs and kernel
> 
> With this layout so far everything works fine. Now I would like to 
> implement an update mechanism, where barebox erases the complete ext 
> partition and replaces it. Under linux I would use something like dd 
> and let it start at 0x800400. On barebox I have to use memcpy (thanks 
> to Sascha for the hint 
> http://lists.infradead.org/pipermail/barebox/2011-April/003308.html ) 
> and this is where I get stuck.
> 
> So I first add partitions so that the memory area is listed under /dev:
> devfs_add_partition("mmc3", 0x0, SZ_1K, DEVFS_PARTITION_FIXED, 
> "mmc3.partable"); c("mmc3", SZ_1K, SZ_8M, 
> DEVFS_PARTITION_FIXED, "mmc3.barebox"); devfs_add_partition("mmc3", ( 
> SZ_1K + SZ_8M ), SZ_1G, DEVFS_PARTITION_FIXED, "mmc3.rootfs");

Why don't you use the partitions from the partition table on the device?
I would assume you use /dev/mmc3.2 for the rootfs.

> 
> This works for clearing the partitions data using memset:
> memset -d /dev/mmc3.rootfs 0x0 0x0 1073741824
> 
> However when I try to copy the root.ext2 filesystem onto this memory area, I can't mount the partition afterwards:
> memcpy -s /mnt/sd/root.ext2 -d /dev/mmc3.rootfs 0 536870912

memcpy needs <src> <dest> <count> positional arguments. With the above
536870912 is the offset in the destination file and not the size to copy. What you want is:

memcpy -s /mnt/sd/root.ext2 -d /dev/mmc3.rootfs 0 0 536870912

Anyway, you don't need memset/memcpy at all to accomplish your task, the following should do it:

cp /dev/zero /dev/mmc3.rootfs
cp /mnt/sd/root.ext2 /dev/mmc3.rootfs

Also I have never seen that it's necessary to erase the remaining parts of a partition when the new image is smaller than the partition.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: How to overwrite an ext partition on eMMC
  2016-07-05  9:32   ` AW: " Martin Hollingsworth
@ 2016-07-05 10:06     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-07-05 10:06 UTC (permalink / raw)
  To: Martin Hollingsworth; +Cc: barebox

On Tue, Jul 05, 2016 at 09:32:30AM +0000, Martin Hollingsworth wrote:
> Hi Sascha,
> huge thanks, that was just the right push in the right direction. Both suggested methods - cp and memcpy - work fine. Problem solved.
> 
> > Why don't you use the partitions from the partition table on the device?
> > I would assume you use /dev/mmc3.2 for the rootfs.
> 
> I assume you are referring to using "detect -a" to find the device,
> which is then registered as mmc3.0 (for first partition). As I was
> struggling to write the root.ext2 onto that device I decided to try
> using the devfs_add_partition() method, as all nand flash based
> devices I have as reference use this approach. However I just
> verified, using the detected partition works as well and it is
> probably the better way of doing it, as the partitions can be moved
> around more easily.
> 
> In another side question you write: "I would assume you use
> /dev/mmc3.2 for the rootfs". As I currently only copy the Barebox raw
> onto the eMMC offset 0x400 for iMX6 it is not listed as partition
> under /dev/. What is the standard approach here, should the Barebox
> best be a FAT32 partition so it is listed?

For updating barebox you should use a barebox update handler. Register
it with imx6_bbu_internal_mmc_register_handler() and use the
barebox_update command to update barebox. This way you can be sure that
you only write suitable files on the device and also the partition table
is preserved properly.

eMMC devices also often have boot partitions which can be used to store
barebox. These allow to put barebox away from the regular storage where
it can't be overwritten that easily. You can copy barebox to
/dev/mmc3.boot0 (Or let the mentioned update handler point to that
place) and set mmc3.boot=boot0 to let the i.MX6 ROM know that it should
boot from there.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2016-07-05 10:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04 12:32 How to overwrite an ext partition on eMMC Martin Hollingsworth
2016-07-05  6:55 ` Sascha Hauer
2016-07-05  9:32   ` AW: " Martin Hollingsworth
2016-07-05 10:06     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox