All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] spi and block bits
@ 2015-02-08 23:27 Michael Walle
  2015-04-16 18:32 ` Jagan Teki
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Walle @ 2015-02-08 23:27 UTC (permalink / raw)
  To: u-boot

Hi there,

I stumbled across a situation where the SPI flash on my board was write 
protected and i could not unlock it in the bootloader. This is 
especially unfortunate because the recovery mechanism relies on the 
bootloader to be able to erase the environment.

So any ideas how to fix this? I didn't see any code which unlocks the 
sectors yet.

We could add a lock/unlock function to the spi system, then call unlock 
in the beginning of saveenv() and lock at the end of saveenv(). Eg.

   lockbits = read_status() & LOCK_BITS
   spi_unlock_all()
   saveenv()
   spi_lock(lockbits)

Also this should be exposed to the CLI somehow. "sf lock/unlock"?

-michael

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

* [U-Boot] spi and block bits
  2015-02-08 23:27 [U-Boot] spi and block bits Michael Walle
@ 2015-04-16 18:32 ` Jagan Teki
  2015-04-17  7:15   ` Michael Walle
  0 siblings, 1 reply; 4+ messages in thread
From: Jagan Teki @ 2015-04-16 18:32 UTC (permalink / raw)
  To: u-boot

On 9 February 2015 at 04:57, Michael Walle <michael@walle.cc> wrote:
> Hi there,
>
> I stumbled across a situation where the SPI flash on my board was write
> protected and i could not unlock it in the bootloader. This is especially
> unfortunate because the recovery mechanism relies on the bootloader to be
> able to erase the environment.

Which flash vendor it is? seems like there is a hardware write protected
mechanism in ST MICRON flashes.

Please refer that, may be this looks similar to that W#/Vpp
CONFIG_SYS_SPI_ST_ENABLE_WP_PIN

>
> So any ideas how to fix this? I didn't see any code which unlocks the
> sectors yet.
>
> We could add a lock/unlock function to the spi system, then call unlock in
> the beginning of saveenv() and lock at the end of saveenv(). Eg.
>
>   lockbits = read_status() & LOCK_BITS
>   spi_unlock_all()
>   saveenv()
>   spi_lock(lockbits)
>
> Also this should be exposed to the CLI somehow. "sf lock/unlock"?

thanks!
-- 
Jagan.

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

* [U-Boot] spi and block bits
  2015-04-16 18:32 ` Jagan Teki
@ 2015-04-17  7:15   ` Michael Walle
  2015-04-21 12:58     ` Jagan Teki
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Walle @ 2015-04-17  7:15 UTC (permalink / raw)
  To: u-boot

Am 2015-04-16 20:32, schrieb Jagan Teki:
> On 9 February 2015 at 04:57, Michael Walle <michael@walle.cc> wrote:
>> Hi there,
>> 
>> I stumbled across a situation where the SPI flash on my board was 
>> write
>> protected and i could not unlock it in the bootloader. This is 
>> especially
>> unfortunate because the recovery mechanism relies on the bootloader to 
>> be
>> able to erase the environment.
> 
> Which flash vendor it is? seems like there is a hardware write 
> protected
> mechanism in ST MICRON flashes.

it is a st micron. (see include/configs/lsxl.h)

> Please refer that, may be this looks similar to that W#/Vpp
> CONFIG_SYS_SPI_ST_ENABLE_WP_PIN

But it isn't related to that.

My point was, if linux enables the lock bits, there is no way you can 
write to the flash in the bootloader anymore. Because it is not possible 
to clear these bits in u-boot. If you have a macronix or an ST flash the 
block protection bits are cleared on probe. see sf_probe.c:


         /* Flash powers up read-only, so clear BP# bits */
#if defined(CONFIG_SPI_FLASH_ATMEL) || \
         defined(CONFIG_SPI_FLASH_MACRONIX) || \
         defined(CONFIG_SPI_FLASH_SST)
                 spi_flash_cmd_write_status(flash, 0);
#endif

Although as the comment says, it is because these chips power up in 
read-only state by default. In my case, linux would set these bits.

To be more precise, the fw_setenv will leave the flash write protected 
and i cannot modify the environment in the bootloader anymore.


-michael

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

* [U-Boot] spi and block bits
  2015-04-17  7:15   ` Michael Walle
@ 2015-04-21 12:58     ` Jagan Teki
  0 siblings, 0 replies; 4+ messages in thread
From: Jagan Teki @ 2015-04-21 12:58 UTC (permalink / raw)
  To: u-boot

On 17 April 2015 at 12:45, Michael Walle <michael@walle.cc> wrote:
> Am 2015-04-16 20:32, schrieb Jagan Teki:
>>
>> On 9 February 2015 at 04:57, Michael Walle <michael@walle.cc> wrote:
>>>
>>> Hi there,
>>>
>>> I stumbled across a situation where the SPI flash on my board was write
>>> protected and i could not unlock it in the bootloader. This is especially
>>> unfortunate because the recovery mechanism relies on the bootloader to be
>>> able to erase the environment.
>>
>>
>> Which flash vendor it is? seems like there is a hardware write protected
>> mechanism in ST MICRON flashes.
>
>
> it is a st micron. (see include/configs/lsxl.h)
>
>> Please refer that, may be this looks similar to that W#/Vpp
>> CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
>
>
> But it isn't related to that.
>
> My point was, if linux enables the lock bits, there is no way you can write
> to the flash in the bootloader anymore. Because it is not possible to clear
> these bits in u-boot. If you have a macronix or an ST flash the block
> protection bits are cleared on probe. see sf_probe.c:
>
>
>         /* Flash powers up read-only, so clear BP# bits */
> #if defined(CONFIG_SPI_FLASH_ATMEL) || \
>         defined(CONFIG_SPI_FLASH_MACRONIX) || \
>         defined(CONFIG_SPI_FLASH_SST)
>                 spi_flash_cmd_write_status(flash, 0);
> #endif

So are you saying clearing BP# bits should also required for Micron as
you need to access it on bootloader?


>
> Although as the comment says, it is because these chips power up in
> read-only state by default. In my case, linux would set these bits.
>
> To be more precise, the fw_setenv will leave the flash write protected and i
> cannot modify the environment in the bootloader anymore.

I couldn't understand your point can you elaborate, if clearing BP# required for
Micron how could it accessed in Linux?

thanks!
-- 
Jagan.

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

end of thread, other threads:[~2015-04-21 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-08 23:27 [U-Boot] spi and block bits Michael Walle
2015-04-16 18:32 ` Jagan Teki
2015-04-17  7:15   ` Michael Walle
2015-04-21 12:58     ` Jagan Teki

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.