bootcount: flush after storing the bootcounter
PATCH 1/1 bootcount: flush after storing the bootcounter
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.
Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/bootcount/bootcount.c +3 -0
@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE ); }__weak ulong bootcount_load (void )
Signature · 1 line
2.7.4
PATCH 1/1 bootcount: flush after storing the bootcounter
Hi Stefano,
Quoted 16 lines
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
Signed-off-by Stefano Babic <[email protected]>--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)(quoted diff) +0
-0
b/drivers/bootcount/bootcount.cindex d5ce450..48594a6 100644
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 64
Quoted 6 lines
drivers/bootcount/bootcount.c +3
-0@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE );
Is it safe to flush the whole cache line?
For iMX6Q I do use SNVS_LPGR register (0x020CC068). It will preserve its content after reset caused by WDT (also reset command in u-boot). I also do use the SINGLEWORD to store "magic" and boot count in a single 32 bit number.
You may also want to consider using SRC_GPRx registers:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790
As it shall be safe to use them for bootcount scenario. However, I do prefer SNVS_LPGR.
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 67
Quoted 3 lines
drivers/bootcount/bootcount.c +0
-0}__weak ulong bootcount_load (void )
Best regards,
Lukasz Majewski
--
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 -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180222/e64bcd38/attachment.sig>
PATCH 1/1 bootcount: flush after storing the bootcounter
Hi Lukasz,
Quoted 13 lines · Lukasz Majewski
Hi Stefano,
Quoted 11 lines
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
Signed-off-by Stefano Babic <[email protected]>--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 13 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 64
Quoted 11 lines
(quoted diff) +0
-0
b/drivers/bootcount/bootcount.cindex d5ce450..48594a6 100644drivers/bootcount/bootcount.c +3
-0@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE );Is it safe to flush the whole cache line?
Is there is some drawbacks ?
flush_dcache_range() requires that addresses are aligned with CONFIG_SYS_CACHELINE_SIZE. I cannot flush a single word.
Quoted 2 lines
For iMX6Q I do use
SNVS_LPGRregister (0x020CC068).
It is a long story...
Quoted 5 lines
It will preserve
its content after reset caused by WDT (also reset command in u-boot). I also do use the SINGLEWORD to store "magic" and boot count in a single 32 bit number.
I used it in the past - Heiko found issues with recent kernel versions because kernel is using it. That means, after a rebootwe get what the kernel has written in it, not the bootcounter anymore.
It looks like, too, that SNVS behavior changes between i.MX6 variants. Even in manual, there are discordances (on i.MX6Q seems can be used, on DL seems to be reserved,...).
Due to recent issues, I searched for a suitable place in IRAM.
Anyway, this has nothing to do with the issue. If the storage with the bootcounter is cached, it must be flushed.
Quoted 2 lines
You may also want to consider using
SRC_GPRxregisters:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790
See above, waiting for Heiko's comment,too.
Quoted 2 lines
As it shall be safe to use them for bootcount scenario.
Rather, it looks like it is not safe. Or it was safe, it is not. Or it depends on i.MX6 revisions....
Quoted 2 lines
However, I do
preferSNVS_LPGR.
You're lucky you do not yet go into trouble :-)
Quoted 7 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 67
Quoted 4 lines
drivers/bootcount/bootcount.c +0
-0}__weak ulong bootcount_load (void )
Best regards,
Stefano
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 1/1 bootcount: flush after storing the bootcounter
Hi Stefano,
Quoted 30 lines
Hi Lukasz,
Quoted 13 lines · Lukasz Majewski
Hi Stefano,
Quoted 11 lines
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
Signed-off-by Stefano Babic <[email protected]>--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 13 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 64
Quoted 11 lines
(quoted diff) +0
-0
b/drivers/bootcount/bootcount.cindex d5ce450..48594a6 100644drivers/bootcount/bootcount.c +3
-0@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE );Is it safe to flush the whole cache line?
Quoted 1 line
Is there is some drawbacks ?
I think not - as we are now in u-boot.
(I do have patches, which add also support for bootcount in SPL - I will send them when Kconfig prerequisities go into mainline).
Quoted 3 lines
flush_dcache_range()requires that addresses are aligned withCONFIG_SYS_CACHELINE_SIZE. I cannot flush a single word.
Yes. Correct.
Quoted 5 lines
Quoted 3 lines
For iMX6Q I do use
SNVS_LPGRregister (0x020CC068).It is a long story...
:-)
Quoted 10 lines
Quoted 6 lines
It will preserve
its content after reset caused by WDT (also reset command in u-boot). I also do use the SINGLEWORD to store "magic" and boot count in a single 32 bit number.I used it in the past - Heiko found issues with recent kernel versions because kernel is using it. That means, after a rebootwe get what the kernel has written in it, not the bootcounter anymore.
You mean the SRC_GPRx registers?
Quoted 4 lines
It looks like, too, that SNVS behavior changes between i.MX6 variants. Even in manual, there are discordances (on i.MX6Q seems can be used, on DL seems to be reserved,...).
What I can say.... :/
Quoted 2 lines
Due to recent issues, I searched for a suitable place in IRAM.
Ok.
Quoted 3 lines
Anyway, this has nothing to do with the issue. If the storage with the bootcounter is cached, it must be flushed.
Yes. Of course.
Quoted 6 lines
Quoted 4 lines
You may also want to consider using
SRC_GPRxregisters:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790See above, waiting for Heiko's comment,too.
Ok. Maybe the reply from the NXP community is not complete...
Quoted 6 lines
Quoted 3 lines
As it shall be safe to use them for bootcount scenario.
Rather, it looks like it is not safe. Or it was safe, it is not. Or it depends on i.MX6 revisions....
It would be great if Heiko could share the problem with SRC_GPRx registers. I would like to know the root cause for the future usage.
Quoted 5 lines
Quoted 3 lines
However, I do
preferSNVS_LPGR.You're lucky you do not yet go into trouble :-)
Devlopment by luck :-)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/bootcount/bootcount.c +0
-0}
Quoted 9 lines
Quoted 4 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 67
Quoted 1 line
drivers/bootcount/bootcount.c +0
-0__weak ulong bootcount_load (void )Best regards,
Stefano
Best regards,
Lukasz Majewski
--
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 -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180222/9814b1b6/attachment.sig>
PATCH 1/1 bootcount: flush after storing the bootcounter
Hello Lukasz,
Am 22.02.2018 um 14:03 schrieb Lukasz Majewski:
Quoted 86 lines
Hi Stefano,
Quoted 30 lines
Hi Lukasz,
Quoted 13 lines · Lukasz Majewski
Hi Stefano,
Quoted 11 lines
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
Signed-off-by Stefano Babic <[email protected]>--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 13 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 64
Quoted 11 lines
(quoted diff) +0
-0
b/drivers/bootcount/bootcount.cindex d5ce450..48594a6 100644drivers/bootcount/bootcount.c +3
-0@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE );Is it safe to flush the whole cache line?
Quoted 1 line
Is there is some drawbacks ?
I think not - as we are now in u-boot.
(I do have patches, which add also support for bootcount in SPL - I will send them when
Kconfigprerequisities go into mainline).Quoted 3 lines
flush_dcache_range()requires that addresses are aligned withCONFIG_SYS_CACHELINE_SIZE. I cannot flush a single word.Yes. Correct.
Quoted 5 lines
Quoted 3 lines
For iMX6Q I do use
SNVS_LPGRregister (0x020CC068).It is a long story...
:-)
Quoted 10 lines
Quoted 6 lines
It will preserve
its content after reset caused by WDT (also reset command in u-boot). I also do use the SINGLEWORD to store "magic" and boot count in a single 32 bit number.I used it in the past - Heiko found issues with recent kernel versions because kernel is using it. That means, after a rebootwe get what the kernel has written in it, not the bootcounter anymore.
You mean the
SRC_GPRxregisters?Quoted 4 lines
It looks like, too, that SNVS behavior changes between i.MX6 variants. Even in manual, there are discordances (on i.MX6Q seems can be used, on DL seems to be reserved,...).
What I can say.... :/
Quoted 2 lines
Due to recent issues, I searched for a suitable place in IRAM.
Ok.
Quoted 3 lines
Anyway, this has nothing to do with the issue. If the storage with the bootcounter is cached, it must be flushed.
Yes. Of course.
Quoted 2 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
You may also want to consider using
SRC_GPRxregisters:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790See above, waiting for Heiko's comment,too.
Ok. Maybe the reply from the NXP community is not complete...
Hmm.. I have here an imx6dl based board:
CPU: Freescale i.MX6DL rev1.3 at 792 MHz
and I tried to put the bootcounter into the iram, but found no addr, which is stable over a reboot from linux into U-Boot ... I must admit, that I use the GPU may it use iram? Nevertheless, unsure place.
Tried SRC_GPRx registers, but also not stable after a "boot linux - reboot to U-Boot" cycle.
imx6 D/QL UML saysSRC_GPRx with x = 5-8 for quad only -> so not usable for me
and x=(1-8):
"Holds argument of entry function for coreX. The SRC ensures that the register value will persist across system resets."
with (X=0-3)
So, the core may uses them ...
The S/DL manual says to this registers:
"Read/write general purpose bits used to store an arbitrary value.
This register is used by the ROM code and should not be used by application software."
So also on S/DL no chance to use this registers without risk ...
I have on my hw a pfuze100 and I stored the bootcounter in the 4 8bit registers MEMA - MEMD ... as we have no battery attached to the pfuze this works fine... as you said "Development by luck" :-D
Hmm... SVN_LGPR regsiter ... sounds good. Tried it fast here on my hw, seems to work ... but may instability remains, UML says:
"When GPR_SL or GPR_HL bit is set, the register cannot be programmed."
Once GPR_SL bit is set, it can only cleared through System Reset ...
May a risk?
bye,
Heiko
Quoted 46 lines
Quoted 7 lines
Quoted 4 lines
As it shall be safe to use them for bootcount scenario.
Rather, it looks like it is not safe. Or it was safe, it is not. Or it depends on i.MX6 revisions....
It would be great if Heiko could share the problem with
SRC_GPRxregisters. I would like to know the root cause for the future usage.Quoted 5 lines
Quoted 3 lines
However, I do
preferSNVS_LPGR.You're lucky you do not yet go into trouble :-)
Devlopment by luck :-)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/bootcount/bootcount.c +0
-0}Quoted 9 lines
Quoted 4 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 67
Quoted 1 line
drivers/bootcount/bootcount.c +0
-0__weak ulong bootcount_load (void )Best regards,
StefanoBest regards,
Lukasz Majewski
--
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
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 1/1 bootcount: flush after storing the bootcounter
Hi Heiko,
Quoted 118 lines
Hello Lukasz,
Am 22.02.2018 um 14:03 schrieb Lukasz Majewski:
Quoted 87 lines
Hi Stefano,
Quoted 30 lines
Hi Lukasz,
Quoted 13 lines · Lukasz Majewski
Hi Stefano,
Quoted 11 lines
If the bootcounter address is in a cached memory,
a flush of dcache must occur after updateing the bootcounter.Issue found on i.MX6 where bootcounter is put into the internal (cached) IRAM.
Signed-off-by Stefano Babic <[email protected]>--- drivers/bootcount/bootcount.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 13 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 64
Quoted 11 lines
(quoted diff) +0
-0
b/drivers/bootcount/bootcount.cindex d5ce450..48594a6 100644drivers/bootcount/bootcount.c +3
-0@@ -59,6 +59,9 @@ __weak void bootcount_store(ulong a)raw_bootcount_store (reg, a);raw_bootcount_store (reg +4 ,BOOTCOUNT_MAGIC );#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ +flush_dcache_range (CONFIG_SYS_BOOTCOUNT_ADDR , +CONFIG_SYS_BOOTCOUNT_ADDR + +CONFIG_SYS_CACHELINE_SIZE );Is it safe to flush the whole cache line?
Quoted 1 line
Is there is some drawbacks ?
I think not - as we are now in u-boot.
(I do have patches, which add also support for bootcount in SPL - I will send them when
Kconfigprerequisities go into mainline).Quoted 3 lines
flush_dcache_range()requires that addresses are aligned withCONFIG_SYS_CACHELINE_SIZE. I cannot flush a single word.Yes. Correct.
Quoted 5 lines
Quoted 3 lines
For iMX6Q I do use
SNVS_LPGRregister (0x020CC068).It is a long story...
:-)
Quoted 11 lines
Quoted 6 lines
It will preserve
its content after reset caused by WDT (also reset command in u-boot). I also do use the SINGLEWORD to store "magic" and boot count in a single 32 bit number.I used it in the past - Heiko found issues with recent kernel versions because kernel is using it. That means, after a rebootwe get what the kernel has written in it, not the bootcounter anymore.
You mean the
SRC_GPRxregisters?Quoted 4 lines
It looks like, too, that SNVS behavior changes between i.MX6 variants. Even in manual, there are discordances (on i.MX6Q seems can be used, on DL seems to be reserved,...).
What I can say.... :/
Quoted 2 lines
Due to recent issues, I searched for a suitable place in IRAM.
Ok.
Quoted 3 lines
Anyway, this has nothing to do with the issue. If the storage with the bootcounter is cached, it must be flushed.
Yes. Of course.
Quoted 2 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
You may also want to consider using
SRC_GPRxregisters:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790See above, waiting for Heiko's comment,too.
Ok. Maybe the reply from the NXP community is not complete...
Hmm.. I have here an imx6dl based board:
CPU: Freescale i.MX6DL rev1.3 at 792 MHz
and I tried to put the bootcounter into the iram, but found no addr, which is stable over a reboot from linux into U-Boot ... I must admit, that I use the GPU may it use iram? Nevertheless, unsure place.
Tried
SRC_GPRxregisters, but also not stable after a "boot linux - reboot to U-Boot" cycle.imx6 D/QL UML says
SRC_GPRxwith x = 5-8 for quad only -> so not usable for meand x=(1-8):
"Holds argument of entry function for coreX. The SRC ensures that the register value will persist across system resets."
with (X=0-3)
Quoted 8 lines
So, the core may uses them ...
The S/DL manual says to this registers:
"Read/write general purpose bits used to store an arbitrary value. This register is used by the ROM code and should not be used by application software."So also on S/DL no chance to use this registers without risk ...
This was also my concern. Hence I've asked NXP community (support) explicitly:
https://community.nxp.com/message/985790?commentID=985790&et=watches.email.thread#comment-985790
Maybe the BootROM is different for different SoC versions? (My iMX6Q is rev. 1.5, yours iMX6DL is 1.3)?
Maybe it would be good to ask your case on the NXP community site as well?
Similar symptomps I had with some Samsung SoCs. In their case the FBL (not BootROM) from Samsung was using those registers to check if we go out from "sleep" mode.
However, what I've understood from iMX6 User Manual, the BootROM on iMX6 needs values from SRC_GPRx - and it shall restore the LInux without the need for bootloader intervention.
Quoted 4 lines
I have on my hw a pfuze100 and I stored the bootcounter in the 4 8bit registers MEMA - MEMD ... as we have no battery attached to the pfuze this works fine... as you said "Development by luck" :-D
:-)
The same case for me. I also don't have the battery attached - hence the SNVS_LGPR is OK to use.
Quoted 5 lines
Hmm...
SVN_LGPRregsiter ... sounds good. Tried it fast here on my hw, seems to work ... but may instability remains, UML says:"When
GPR_SLorGPR_HLbit is set, the register cannot be programmed."
But this would be need to be set by other user application. Also, this register is marked as the one to be used with "user application".
Quoted 4 lines
Once
GPR_SLbit is set, it can only cleared through System Reset ...May a risk?
If your user write an application, which will use this regsiter, then yes, it may be a risk.
Quoted 50 lines
bye,
HeikoQuoted 46 lines
Quoted 7 lines
Quoted 4 lines
As it shall be safe to use them for bootcount scenario.
Rather, it looks like it is not safe. Or it was safe, it is not. Or it depends on i.MX6 revisions....
It would be great if Heiko could share the problem with
SRC_GPRxregisters. I would like to know the root cause for the future usage.Quoted 5 lines
Quoted 3 lines
However, I do
preferSNVS_LPGR.You're lucky you do not yet go into trouble :-)
Devlopment by luck :-)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/bootcount/bootcount.c +0
-0}Quoted 9 lines
Quoted 4 lines
drivers/bootcount/bootcount.c __weak void bootcount_store(ulong a) · line 67
Quoted 1 line
drivers/bootcount/bootcount.c +0
-0__weak ulong bootcount_load (void )Best regards,
StefanoBest regards,
Lukasz Majewski
--
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
Best regards,
Lukasz Majewski
--
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 -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180223/0341578c/attachment.sig>