mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* memcpy strange behaviour
@ 2015-11-04  8:04 Antony Pavlov
  2015-11-04  8:36 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Antony Pavlov @ 2015-11-04  8:04 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Peter Mamonov, barebox

Hi!

Peter has reported on strange barebox memcpy command behaviour on his MIPS board:

  he copies a file to memory using memcpy and then copyies appropriate memory contents
  back to another file. Next he checks files md5sum and the sums are differ.

I have reproduced the problem on Qemu VersatilePB ARM board.

Here is an instruction.

Configure barebox:

$ cd barebox.git
$ export ARCH=arm
$ export CROSS_COMPILE=<your cross compiler prefix>
$ make versatilepb_defconfig
$ sed -i "s/^# CONFIG_CMD_MD5SUM.*$/CONFIG_CMD_MD5SUM=y/" .config

Prepare testfile on host and compile:

$ dd if=/dev/zero bs=1 count=4414 | tr "\000" "\377" > defaultenv/defaultenv-2-base/testfile
$ make
...

Run barebox under qemu:

$ qemu-system-arm -M versatilepb -nographic -monitor null -kernel arch/arm/pbl/zbarebox -serial stdio
...
barebox# memcpy -s /env/testfile 0 0x01000000

barebox# memcpy -d _testfile 0x01000000 0 4414

barebox# md5sum /env/testfile _testfile
bf8278051ba8de868def083bcc209002  /env/testfile 0x00000000 ... 0xffffffffffffffff
e295c2bfe32498e03531017443120e89  _testfile     0x00000000 ... 0xffffffffffffffff

barebox# memcmp -s /env/testfile -d _testfile 0 0
files differ at offset 4408

barebox# md -s /env/testfile 4400
00001130: ffffffff ffffffff ffffffff ffffffff                ..............

barebox# md -s _testfile 4400
00001130: ffffffff ffffffff 00000000 ffff0000                ..............

barebox# md -b 0x01001130+0xe
01001130: ff ff ff ff ff ff ff ff 00 00 00 00 00 00          ..............

barebox# md -b -s /env/testfile 0x1130+0xe
00001130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff          ..............

So you see that last 6 bytes have not been copied.

Please comment this report!

-- 
Best regards,
  Antony Pavlov

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

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

* Re: memcpy strange behaviour
  2015-11-04  8:04 memcpy strange behaviour Antony Pavlov
@ 2015-11-04  8:36 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-11-04  8:36 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: Peter Mamonov, barebox

On Wed, Nov 04, 2015 at 11:04:33AM +0300, Antony Pavlov wrote:
> Hi!
> 
> Peter has reported on strange barebox memcpy command behaviour on his MIPS board:
> 
>   he copies a file to memory using memcpy and then copyies appropriate memory contents
>   back to another file. Next he checks files md5sum and the sums are differ.
> 
> I have reproduced the problem on Qemu VersatilePB ARM board.
> 
> Here is an instruction.
> 
> Configure barebox:
> 
> $ cd barebox.git
> $ export ARCH=arm
> $ export CROSS_COMPILE=<your cross compiler prefix>
> $ make versatilepb_defconfig
> $ sed -i "s/^# CONFIG_CMD_MD5SUM.*$/CONFIG_CMD_MD5SUM=y/" .config
> 
> Prepare testfile on host and compile:
> 
> $ dd if=/dev/zero bs=1 count=4414 | tr "\000" "\377" > defaultenv/defaultenv-2-base/testfile
> $ make
> ...
> 
> Run barebox under qemu:
> 
> $ qemu-system-arm -M versatilepb -nographic -monitor null -kernel arch/arm/pbl/zbarebox -serial stdio
> ...
> barebox# memcpy -s /env/testfile 0 0x01000000
> 
> barebox# memcpy -d _testfile 0x01000000 0 4414
> 
> barebox# md5sum /env/testfile _testfile
> bf8278051ba8de868def083bcc209002  /env/testfile 0x00000000 ... 0xffffffffffffffff
> e295c2bfe32498e03531017443120e89  _testfile     0x00000000 ... 0xffffffffffffffff
> 
> barebox# memcmp -s /env/testfile -d _testfile 0 0
> files differ at offset 4408
> 
> barebox# md -s /env/testfile 4400
> 00001130: ffffffff ffffffff ffffffff ffffffff                ..............
> 
> barebox# md -s _testfile 4400
> 00001130: ffffffff ffffffff 00000000 ffff0000                ..............
> 
> barebox# md -b 0x01001130+0xe
> 01001130: ff ff ff ff ff ff ff ff 00 00 00 00 00 00          ..............
> 
> barebox# md -b -s /env/testfile 0x1130+0xe
> 00001130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff          ..............
> 
> So you see that last 6 bytes have not been copied.
> 
> Please comment this report!

This is fixed by:

http://www.spinics.net/lists/u-boot-v2/msg24850.html

Which I forgot to apply, but did now. The problem is that the newly
introduced O_RWSIZE_8 flag clashed with the O_CREAT flag. This means
that when a file is created (it's always set in memcpy) then we also do
8byte reads/writes which of course leads to the last bytes missing when
the length is not 8byte aligned. Fixed in current master.

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] 2+ messages in thread

end of thread, other threads:[~2015-11-04  8:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04  8:04 memcpy strange behaviour Antony Pavlov
2015-11-04  8:36 ` Sascha Hauer

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