Skip to contentSkip to conversation

fw_env: Make env flash lock optional

PATCH New dirk.eibach at gdsys.cc 6 participants 9 messages Jun 2, 2016 – Jun 5, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

From: Dirk Eibach <[email protected]>

Since locking flash is horribly broken on some platforms, offer an option to build fw_env tools without locking.

---

 tools/env/fw_env.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/env/fw_env.c +4 -0
index 06cf63d..e47232a 100644
@@ -908,8 +908,10 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
 			return -1;
 		}
 
+#ifndef NO_MEMLOCK
 		if (mtd_type != MTD_ABSENT)
 			ioctl(fd, MEMLOCK, &erase);
+#endif
 
 		processed  += erasesize;
 		block_seek = 0;
@@ -941,7 +943,9 @@ static int flash_flag_obsolete (int dev, int fd, off_t offset)
 	}
 	ioctl (fd, MEMUNLOCK, &erase);
 	rc = write (fd, &obsolete_flag, sizeof (obsolete_flag));
+#ifndef NO_MEMLOCK
 	ioctl (fd, MEMLOCK, &erase);
+#endif
 	if (rc < 0)
 		perror ("Could not set obsolete flag");
 
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

On Thu, 2 Jun 2016 09:09:14 +0200 dirk.eibach at gdsys.cc dirk.eibach at gdsys.cc wrote:
...

tools/env/fw_env.c static int flash_flag_obsolete (int dev, int fd, off_t offset) · line 944

Quoted 3 lines
tools/env/fw_env.c +0 -0
@@ -941,7 +943,9 @@ static int flash_flag_obsolete (int dev, int fd, off_t offset)
 	}
 	ioctl (fd, MEMUNLOCK, &erase);

when MEMLOCK ist broken on a platform and disabled by your patch, shouldn't MEMUNLOCK be isolated as well?

--
Anatolij

#2 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

Hi Anatolij,

2016-06-02 10:14 GMT+02:00 Anatolij Gustschin <[email protected]>:
...

Quoted 2 lines

when MEMLOCK ist broken on a platform and disabled by your patch, shouldn't MEMUNLOCK be isolated as well?

There are cornercases where lock/unlock works properly in the kernel but not in u-boot. So we might have an environment that was locked by u-boot and are able to unlock it with fw_env.

Cheers
Dirk

#3 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

Hi,

I faced the same problem a while back, thanks for taking a look at this. Does it have to be compiled in? Why not make it a command line option, evtl. making the default a compile time option.

/Andi

2016-06-02 10:27 GMT+02:00 Dirk Eibach <[email protected]>:

Quoted 13 lines

Hi Anatolij,

2016-06-02 10:14 GMT+02:00 Anatolij Gustschin <[email protected]>:
...

Quoted 2 lines

when MEMLOCK ist broken on a platform and disabled by your patch, shouldn't MEMUNLOCK be isolated as well?

There are cornercases where lock/unlock works properly in the kernel but not in u-boot. So we might have an environment that was locked by u-boot and are able to unlock it with fw_env.

Cheers
Dirk

#4 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

In reply to Dirk Eibach

Dear Dirk,

Quoted 4 lines · In message <CANVMifJG+MdmMSjBpciuk0xcfdhMDywDkg9WZ4Skrez0ccFwYw@mail.gmail.com>…

There are cornercases where lock/unlock works properly in the kernel but not in u-boot. So we might have an environment that was locked by u-boot and are able to unlock it with fw_env.

But then such a "fix" looks wrong to me. If it works in Linux, why not fix the code so it works in U-Boot, too? I mean, if you have a working example, that should be possible, or not?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
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
That said, there may be good reasons for what you did beyond obsequi-
ous sycophantic parody. Perhaps you might be so kind as to elucidate.
         -- Tom Christiansen in <[email protected]>
#5 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

Hi Wolfgang,

2016-06-02 15:36 GMT+02:00 Wolfgang Denk <[email protected]>:

Quoted 9 lines

...

Quoted 3 lines

There are cornercases where lock/unlock works properly in the kernel but not in u-boot. So we might have an environment that was locked by u-boot and are able to unlock it with fw_env.

But then such a "fix" looks wrong to me. If it works in Linux, why not fix the code so it works in U-Boot, too? I mean, if you have a working example, that should be possible, or not?
...

Sometimes I simply need a tool to repair a device in the field where updating u-boot or kernel is not an option.
But uploading modified fw_env tools is.

Cheers
Dirk

#6 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

Quoted 8 lines · Dirk Eibach

Hi Wolfgang,

2016-06-02 15:36 GMT+02:00 Wolfgang Denk <[email protected]>:

Quoted 5 lines

...

Quoted 3 lines

There are cornercases where lock/unlock works properly in the kernel but not in u-boot. So we might have an environment that was locked by u-boot and are able to unlock it with fw_env.

Quoted 7 lines
Quoted 3 lines

But then such a "fix" looks wrong to me. If it works in Linux, why not fix the code so it works in U-Boot, too? I mean, if you have a working example, that should be possible, or not?

Sometimes I simply need a tool to repair a device in the field where updating u-boot or kernel is not an option.
But uploading modified fw_env tools is.

So in sum, things are already in a bad state and this is the only way to correct things? Can you please make this a cli option instead with appropriately scary help/man text? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160602/e7e0e07f/attachment.sig>
#7 lore raw

PATCH 1/1 fw_env: Make env flash lock optional

In reply to Dirk Eibach

Dear Dirk,

Quoted 8 lines · In message <CANVMifL_VKFX-G9Xsm7yJ-Bu6YrUPOqFbpbSus+f3OL184A0-w@mail.gmail.com>…
Quoted 4 lines

But then such a "fix" looks wrong to me. If it works in Linux, why not fix the code so it works in U-Boot, too? I mean, if you have a working example, that should be possible, or not?

Sometimes I simply need a tool to repair a device in the field where updating u-boot or kernel is not an option.
But uploading modified fw_env tools is.

Understood.

Am I interpreting this correctly, that the root cause is fixed in recent versions of U-Boot, and you need it only to fix old, broken versions?

Or is the problem still present in current mainline, too?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
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
In the realm of scientific observation, luck is granted only to those
who are prepared.                                     - Louis Pasteur