Skip to contentSkip to conversation

cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

PATCH New Rostislav Lisovy 3 participants 6 messages Jul 16, 2014 – Jul 21, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

The environment variable 'filesize' is commonly used for storing information about the size of the last read/retrieved file. The variable is essential when writing U-boot scripts. This patch adds the capability of storing the information about the size of read data into the 'filesize' variable for other commands (nand read/ubi read/nboot) as well.

---
 common/cmd_nand.c | 2 ++
 common/cmd_ubi.c  | 1 +
 2 files changed, 3 insertions(+)
common/cmd_nand.c +2 -0
index f9ced9d..8368f5f 100644
@@ -730,6 +730,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 		printf(" %zu bytes %s: %s\n", rwsize,
 		       read ? "read" : "written", ret ? "ERROR" : "OK");
+		setenv_hex("filesize", rwsize);
 
 		return ret == 0 ? 0 : 1;
 	}
@@ -959,6 +960,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
 		return 1;
 	}
 	bootstage_mark(BOOTSTAGE_ID_NAND_READ);
+	setenv_hex("filesize", cnt);
 
 #if defined(CONFIG_FIT)
 	/* This cannot be done earlier, we need complete FIT image in RAM first */
common/cmd_ubi.c +1 -0
index 7c4d950..a9207c9 100644
@@ -675,6 +675,7 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (argc == 3) {
 			printf("Read %lld bytes from volume %s to %lx\n", size,
 			       argv[3], addr);
+			setenv_hex("filesize", size);
 
 			return ubi_volume_read(argv[3], (char *)addr, size);
 		}
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

Dear Rostislav Lisovy,

Quoted 6 lines · In message <[email protected]> you wrote:

The environment variable 'filesize' is commonly used for storing information about the size of the last read/retrieved file. The variable is essential when writing U-boot scripts. This patch adds the capability of storing the information about the size of read data into the 'filesize' variable for other commands (nand read/ubi read/nboot) as well.

I'm not happy with that. I think this is actually dangerous.

First, you mix two different concepts here. As the name "FILEsize" suggests, it is related to the size of a data object "file". This comes as natural name when loading data from a TFTP server or when reading a *file* from some file system. Extending this to mean any amount of data looks inconsistent and even broken to me.

Second, there might be scripts out there which get broken by your modification. For example, when I download a file over TFTP to RAM, I expect that "filesize" holds the exact amount of bytes of this file. When I now use "nand write ... +${filesize}", the write size would be rounded up to the next full erase block size of the NAND. Any later reference to "filesize" will now see a different (larger) value than expected.

There are problably other scenarios which may get broken by such unexpected (and new) behaviour.

Best regards,

Wolfgang Denk

Signature · 5 lines
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
Q:  Do you know what the death rate around here is?
A:  One per person.
#2 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

Quoted 26 lines · Wolfgang Denk

Dear Rostislav Lisovy,

Quoted 6 lines · In message <[email protected]> you wrote:

The environment variable 'filesize' is commonly used for storing information about the size of the last read/retrieved file. The variable is essential when writing U-boot scripts. This patch adds the capability of storing the information about the size of read data into the 'filesize' variable for other commands (nand read/ubi read/nboot) as well.

I'm not happy with that. I think this is actually dangerous.

First, you mix two different concepts here. As the name "FILEsize" suggests, it is related to the size of a data object "file". This comes as natural name when loading data from a TFTP server or when reading a *file* from some file system. Extending this to mean any amount of data looks inconsistent and even broken to me.

Second, there might be scripts out there which get broken by your modification. For example, when I download a file over TFTP to RAM, I expect that "filesize" holds the exact amount of bytes of this file. When I now use "nand write ... +${filesize}", the write size would be rounded up to the next full erase block size of the NAND. Any later reference to "filesize" will now see a different (larger) value than expected.

Quoted 2 lines

There are problably other scenarios which may get broken by such unexpected (and new) behaviour.

I agree we should NOT modify filesize on write. But what about on NAND/etc read?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140716/b04d23a5/attachment.pgp>
#3 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

In reply to Wolfgang Denk

Dear Mr. Denk;

Quoted 8 lines · Wolfgang Denk

I'm not happy with that. I think this is actually dangerous.

First, you mix two different concepts here. As the name "FILEsize" suggests, it is related to the size of a data object "file". This comes as natural name when loading data from a TFTP server or when reading a *file* from some file system. Extending this to mean any amount of data looks inconsistent and even broken to me.

Quoted 7 lines

Second, there might be scripts out there which get broken by your modification. For example, when I download a file over TFTP to RAM, I expect that "filesize" holds the exact amount of bytes of this file. When I now use "nand write ... +${filesize}", the write size would be rounded up to the next full erase block size of the NAND. Any later reference to "filesize" will now see a different (larger) value than expected.

Thank you for the review. I see your point.
One possible solution would be to add new environment variable called "datasize", but then there is the question if this variable should be updated any time the "filesize" is updated (+ in a few situations where the filesize will stay unchanged -- i.e. what adds this patch).

Best regards;
Rostislav Lisovy

#4 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

Dear Lisovy,

Quoted 5 lines · In message <[email protected]> you wrote:

One possible solution would be to add new environment variable called "datasize", but then there is the question if this variable should be updated any time the "filesize" is updated (+ in a few situations where the filesize will stay unchanged -- i.e. what adds this patch).

I have to admit that I don't even see the use case where such a new variable would be helpful.

Your patch was adding this to commands like "nand read" etc. All these commands require you to pass the size to be read as argument, so you already have the size information present.

Why would you want to store it in another variable?

Best regards,

Wolfgang Denk

Signature · 5 lines
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 really hate this damned machine     It never does quite what I want
I wish that they would sell it.              But only what I tell it.
#5 lore raw

PATCH 1/1 cmd_nand/cmd_ubi/cmd_nboot: Set environment variable 'filesize'

Quoted 8 lines · Wolfgang Denk

I have to admit that I don't even see the use case where such a new variable would be helpful.

Your patch was adding this to commands like "nand read" etc. All these commands require you to pass the size to be read as argument, so you already have the size information present.

Why would you want to store it in another variable?

The motivation for the "nand read" is that when the whole NAND flash partition is read (without passing the size as an argument) it may happen that the bad blocks are skipped thus amount of data read is not the same as the partition size. When we want to "nand write" the data to another partition, it would be nice to know the exact size. For the "nboot" case we use it to speed up copying of the kernel from the "image-for-upgrade" partition to the "production-kernel" partition. This helps us to avoid unnecessary copying of the whole partition (and saves some time).

Best regards;
Rostislav Lisovy