Problems to Allwinner H3's eFUSE/SID
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register accessing, or directly access 0x01c14200.
Quoted 1 line
From http://linux-sunxi.org/SID_Register_Guide we can see a difference between
the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in legacy kernel).
According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last byte of the first word of SID. (0x42 and 0x83 is H2+, 0x00 and 0x81 is H3, 0x58 is H3D (currently not known SoC) )
However, all the SIDs retrieved by sunxi-fel sid, both H2+ and H3, start with 0x02004620, which do not match this rule.
The readout by devmem2 is satisfying this rule: their first word is 0x02c00081, matches H3.
Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with /dev/mem), I got "02c00081 74004620 50358720 3c27048e" on my Orange Pi One. ("02004620 74358720 5027048e 3c0000c3" with sunxi-fel sid) And, after accessing to the SID by registers, the value of *0x01c14200 become also "02c00081".
With direct access to 0x01c14200 after boot with mainline kernel, I got also "02004620".
Then I altered the program to do the register operations with sunxi-fel, the result is also "02c00081", and changed sunxi-fel sid result to "02c00081".
Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+
According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by accessing 0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID by registers and then abandoned the value.
- This mismatch do not exist on A64.
I think that: Allwinner designed a "cache" to the SID to make the simplify the code to read it, and it automatically loaded the cache when booting; however, when doing first cache on H3, some byte shifts occured, and the value become wrong. A manual read on H3 can make the cache right again. This is a silicon bug, and fixed in A64.
This raises a problem: currently many systems has used the misread SID value to generated lots of MAC addresses, and workaround this SID bug will change them.
However, if this bug is not workarounded, the sun8i-ths driver won't work well (as some calibartion value lies in eFUSE). I think some early user of this driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)
And many wrong SID values have been generated by sunxi-fel sid. (Although I think sunxi-fel must have the workaround)
Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 at 0x01c14000, which is a OTP memory implemented by eFUSE technique.
Furthermore, A83T may also have this problem, testers are welcome!
[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.c
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via /dev/mem with register access by KotCzarny. (with statically compiled binary)
Regards,
Icenowy
Hi,
Quoted 85 lines · Icenowy Zheng
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register accessing, or directly access
0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference between the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in legacy kernel).
According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3,0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) And, after accessing to the SID by registers, the value of *0x01c14200 become also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got also "02004620".Then I altered the program to do the register operations with sunxi-fel, the result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by accessing0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID by registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the simplify the code to read it, and it automatically loaded the cache when booting; however, when doing first cache on H3, some byte shifts occured, and the value become wrong. A manual read on H3 can make the cache right again. This is a silicon bug, and fixed in A64.
This raises a problem: currently many systems has used the misread SID value to generated lots of MAC addresses, and workaround this SID bug will change them.
However, if this bug is not workarounded, the sun8i-ths driver won't work well (as some calibartion value lies in eFUSE). I think some early user of this driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid. (Although I think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 at
0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.c
Quoted 6 lines
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)
Good detective work!
I believe this would best be fixed by making u-boot use the register access method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.
Can you write a patch for this ?
Regards,
Hans
19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 95 lines
Hi,
Quoted 85 lines · Icenowy Zheng
?Hi everyone,
?Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID ?controller of H3 (incl. H2+).
?See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
?Two read method of the H3 eFUSE is used in the BSP: by register accessing, or ?directly access
0x01c14200.?From http://linux-sunxi.org/SID_Register_Guide we can see a difference between ?the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in ?legacy kernel).
?According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last ?byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3, ?0x58 is H3D (currently not known SoC) )?However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start ?with0x02004620, which do not match this rule.?The readout by devmem2 is satisfying this rule: their first word is ?0x02c00081, matches H3.
?Then I found the SID-reading code from BSP U-Boot[2], which is based on ?register operations. With this kind of code (I wrote one prototype in ?userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on ?my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) ?And, after accessing to the SID by registers, the value of *0x01c14200 become ?also "02c00081".?With direct access to
0x01c14200after boot with mainline kernel, I got also ?"02004620".?Then I altered the program to do the register operations with sunxi-fel, the ?result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".?Summary:
?+-----------------------------------------------+----------------+ ?| Read situation | The first word | ?+-----------------------------------------------+----------------+
?| Direct read by sunxi-fel | 02004620 | ?| Direct read in mainline /dev/mem | 02004620 | ?| Direct read in legacy /dev/mem | 02c00081 | ?| Register access in FEL | 02c00081 | ?| Register access in mainline | 02c00081 | ?| Direct read after register access in FEL | 02c00081 | ?| Direct read after register access in mainline | 02c00081 |?+-----------------------------------------------+----------------+
?According to some facts:
?- The register based access to SID is weird: it needs ~5 register ???operations per word of SID.
?- Reading via register access will change the value when reading by accessing ???0x01c14200.
?- In the u-boot code[2] there's some functions which read out the SID by ???registers and then abandoned the value.
?- This mismatch do not exist on A64.?I think that: Allwinner designed a "cache" to the SID to make the simplify the ?code to read it, and it automatically loaded the cache when booting; however, ?when doing first cache on H3, some byte shifts occured, and the value become ?wrong. A manual read on H3 can make the cache right again. This is a silicon ?bug, and fixed in A64.
?This raises a problem: currently many systems has used the misread SID value to ?generated lots of MAC addresses, and workaround this SID bug will change them.
?However, if this bug is not workarounded, the sun8i-ths driver won't work well ?(as some calibartion value lies in eFUSE). I think some early user of this ?driver has already experienced bad readout value.
?(The calibration value differs on my opi1 and KotCzarny's opipc)?And many wrong SID values have been generated by
sunxi-fel sid. (Although I ?think sunxi-fel must have the workaround)?Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 ?at
0x01c14000, which is a OTP memory implemented by eFUSE technique.?Furthermore, A83T may also have this problem, testers are welcome!
?[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
?[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
?Experiments:
?- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
???A SID readout shell script via FEL with register access. ?- https://31.135.195.151:20281/d/efuse/
???A SID readout program via/dev/memwith register access by KotCzarny. ???(with statically compiled binary)
Quoted 5 lines
Good detective work!
I believe this would best be fixed by making u-boot use the register access method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.
Yes.
However, what I considered is that fixing this bug will change H3 devices' MAC addresses, as they are derived from SID.
Maybe we should add #ifdef's to MAC generation code after this fix.
(This is why I will create this discussion)
P.S. Are you still the maintainer of sunxi boards support of u-boot? The MAINTAINER file in board/sunxi indicates this.
I've sent out a new board support several days ago (Orange Pi Zero), and got one "Reviewd-By". Could you look at it?
Quoted 6 lines
Can you write a patch for this ?
Regards,
Hans
Hi,
Quoted 100 lines · Icenowy Zheng
19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 97 lines
Hi,
Quoted 85 lines · Icenowy Zheng
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register accessing, or directly access
0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference between the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in legacy kernel).
According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3,0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) And, after accessing to the SID by registers, the value of *0x01c14200 become also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got also "02004620".Then I altered the program to do the register operations with sunxi-fel, the result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by accessing0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID by registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the simplify the code to read it, and it automatically loaded the cache when booting; however, when doing first cache on H3, some byte shifts occured, and the value become wrong. A manual read on H3 can make the cache right again. This is a silicon bug, and fixed in A64.
This raises a problem: currently many systems has used the misread SID value to generated lots of MAC addresses, and workaround this SID bug will change them.
However, if this bug is not workarounded, the sun8i-ths driver won't work well (as some calibartion value lies in eFUSE). I think some early user of this driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid. (Although I think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 at
0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)Good detective work!
Quoted 8 lines
Quoted 3 lines
I believe this would best be fixed by making u-boot use the register access method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.
Yes.
However, what I considered is that fixing this bug will change H3 devices' MAC addresses, as they are derived from SID.
I know, but I think we will just need to accept this onetime change of the fixed MAC addresses to fix this bug. I don't think this is a big problem since the driver for the H3 ethernet has not been merged into the mainline kernel yet.
Quoted 1 line
Maybe we should add #ifdef's to MAC generation code after this fix.
I would rather not see #ifdefs for this, see above, but that is no longer my call, see below.
Quoted 5 lines
(This is why I will create this discussion)
P.S. Are you still the maintainer of sunxi boards support of u-boot? The MAINTAINER file in board/sunxi indicates this.
No I'm no longer the maintainer, I'm still the MAINTAINER file because I have a lot of boards and as such I'm still the point of contact for those boards (if there are any board specific issues / questions), but as indicated in the main MAINTAINERS file Jagan Teki <[email protected]> is the maintainer now.
Regards,
Hans
20.12.2016, 00:17, "Hans de Goede" <[email protected]>:
Quoted 122 lines
Hi,
Quoted 98 lines · Icenowy Zheng
?19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 97 lines
?Hi,
Quoted 85 lines · Icenowy Zheng
??Hi everyone,
??Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID ??controller of H3 (incl. H2+).
??See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
??Two read method of the H3 eFUSE is used in the BSP: by register accessing, or ??directly access
0x01c14200.??From http://linux-sunxi.org/SID_Register_Guide we can see a difference between ??the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in ??legacy kernel).
??According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last ??byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3, ??0x58 is H3D (currently not known SoC) )??However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start ??with0x02004620, which do not match this rule.??The readout by devmem2 is satisfying this rule: their first word is ??0x02c00081, matches H3.
??Then I found the SID-reading code from BSP U-Boot[2], which is based on ??register operations. With this kind of code (I wrote one prototype in ??userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on ??my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) ??And, after accessing to the SID by registers, the value of *0x01c14200 become ??also "02c00081".??With direct access to
0x01c14200after boot with mainline kernel, I got also ??"02004620".??Then I altered the program to do the register operations with sunxi-fel, the ??result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".??Summary:
??+-----------------------------------------------+----------------+ ??| Read situation | The first word | ??+-----------------------------------------------+----------------+
??| Direct read by sunxi-fel | 02004620 | ??| Direct read in mainline /dev/mem | 02004620 | ??| Direct read in legacy /dev/mem | 02c00081 | ??| Register access in FEL | 02c00081 | ??| Register access in mainline | 02c00081 | ??| Direct read after register access in FEL | 02c00081 | ??| Direct read after register access in mainline | 02c00081 |??+-----------------------------------------------+----------------+
??According to some facts:
??- The register based access to SID is weird: it needs ~5 register ????operations per word of SID.
??- Reading via register access will change the value when reading by accessing ????0x01c14200.
??- In the u-boot code[2] there's some functions which read out the SID by ????registers and then abandoned the value.
??- This mismatch do not exist on A64.??I think that: Allwinner designed a "cache" to the SID to make the simplify the ??code to read it, and it automatically loaded the cache when booting; however, ??when doing first cache on H3, some byte shifts occured, and the value become ??wrong. A manual read on H3 can make the cache right again. This is a silicon ??bug, and fixed in A64.
??This raises a problem: currently many systems has used the misread SID value to ??generated lots of MAC addresses, and workaround this SID bug will change them.
??However, if this bug is not workarounded, the sun8i-ths driver won't work well ??(as some calibartion value lies in eFUSE). I think some early user of this ??driver has already experienced bad readout value.
??(The calibration value differs on my opi1 and KotCzarny's opipc)??And many wrong SID values have been generated by
sunxi-fel sid. (Although I ??think sunxi-fel must have the workaround)??Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 ??at
0x01c14000, which is a OTP memory implemented by eFUSE technique.??Furthermore, A83T may also have this problem, testers are welcome!
??[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
??[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
??Experiments:
??- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
????A SID readout shell script via FEL with register access. ??- https://31.135.195.151:20281/d/efuse/
????A SID readout program via/dev/memwith register access by KotCzarny. ????(with statically compiled binary)?Good detective work!
Quoted 8 lines
Quoted 3 lines
?I believe this would best be fixed by making u-boot use the register access ?method to get the SID on affected chips, and make sure u-boot reads the ?SID at-least once.
?Yes.
?However, what I considered is that fixing this bug will change H3 devices' ?MAC addresses, as they are derived from SID.
I know, but I think we will just need to accept this onetime change of the fixed MAC addresses to fix this bug. I don't think this is a big problem since the driver for the H3 ethernet has not been merged into the mainline kernel yet.
Quoted 1 line
?Maybe we should add #ifdef's to MAC generation code after this fix.
I would rather not see #ifdefs for this, see above, but that is no longer my call, see below.
Quoted 2 lines
?(This is why I will create this discussion)
Quoted 8 lines
Quoted 2 lines
?P.S. Are you still the maintainer of sunxi boards support of u-boot? The ?MAINTAINER file in board/sunxi indicates this.
No I'm no longer the maintainer, I'm still the MAINTAINER file because I have a lot of boards and as such I'm still the point of contact for those boards (if there are any board specific issues / questions), but as indicated in the main
MAINTAINERSfile Jagan Teki <[email protected]> is the maintainer now.
But the current status of the file will indicates you are the maintainer of boards support of sunxi.
Quoted 4 lines
Regards,
Hans
Hi,
Quoted 128 lines · Icenowy Zheng
20.12.2016, 00:17, "Hans de Goede" <[email protected]>:
Quoted 125 lines
Hi,
Quoted 98 lines · Icenowy Zheng
19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 97 lines
Hi,
Quoted 85 lines · Icenowy Zheng
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register accessing, or directly access
0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference between the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in legacy kernel).
According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3,0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) And, after accessing to the SID by registers, the value of *0x01c14200 become also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got also "02004620".Then I altered the program to do the register operations with sunxi-fel, the result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by accessing0x01c14200.- In the u-boot code[2] there's some functions which read out the SID by registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the simplify the code to read it, and it automatically loaded the cache when booting; however, when doing first cache on H3, some byte shifts occured, and the value become wrong. A manual read on H3 can make the cache right again. This is a silicon bug, and fixed in A64.
This raises a problem: currently many systems has used the misread SID value to generated lots of MAC addresses, and workaround this SID bug will change them.
However, if this bug is not workarounded, the sun8i-ths driver won't work well (as some calibartion value lies in eFUSE). I think some early user of this driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid. (Although I think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 at
0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)Good detective work!
Quoted 8 lines
Quoted 3 lines
I believe this would best be fixed by making u-boot use the register access method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.
Yes.
However, what I considered is that fixing this bug will change H3 devices' MAC addresses, as they are derived from SID.
I know, but I think we will just need to accept this onetime change of the fixed MAC addresses to fix this bug. I don't think this is a big problem since the driver for the H3 ethernet has not been merged into the mainline kernel yet.
Quoted 1 line
Maybe we should add #ifdef's to MAC generation code after this fix.
I would rather not see #ifdefs for this, see above, but that is no longer my call, see below.
Quoted 4 lines
(This is why I will create this discussion)
P.S. Are you still the maintainer of sunxi boards support of u-boot? The MAINTAINER file in board/sunxi indicates this.
Quoted 8 lines
Quoted 5 lines
No I'm no longer the maintainer, I'm still the MAINTAINER file because I have a lot of boards and as such I'm still the point of contact for those boards (if there are any board specific issues / questions), but as indicated in the main
MAINTAINERSfile Jagan Teki <[email protected]> is the maintainer now.But the current status of the file will indicates you are the maintainer of boards support of sunxi.
No it indicates that I'm the maintainer for the defconfig files for a whole list of boards, nothing more and nothing less.
If you think it needs to be clarified, feel free to submit a patch to make this more clear.
Regards,
Hans
Quoted 142 lines · Hans de Goede
Hi,
Quoted 138 lines · Icenowy Zheng
19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 124 lines
Hi,
Quoted 112 lines · Icenowy Zheng
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register
accessing, or
directly access0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference
between
the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2
(in
legacy kernel).According to the source of H2+ BSP[1], H2+ and H3 can be differed by
the last
byte of the first word of SID. (0x42and0x83is H2+,0x00and0x81is
H3,
0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3,
start
with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e"
on
my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel
sid)
And, after accessing to the SID by registers, the value of *0x01c14200
become
also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got
also
"02004620".Then I altered the program to do the register operations with
sunxi-fel, the
result is also "02c00081", and changedsunxi-fel sidresult to
"02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by
accessing
0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID
by
registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the
simplify the
code to read it, and it automatically loaded the cache when booting;
however,
when doing first cache on H3, some byte shifts occured, and the value
become
wrong. A manual read on H3 can make the cache right again. This is a
silicon
bug, and fixed in A64.This raises a problem: currently many systems has used the misread SID
value to
generated lots of MAC addresses, and workaround this SID bug will
change them.However, if this bug is not workarounded, the sun8i-ths driver won't
work well
(as some calibartion value lies in eFUSE). I think some early user of
this
driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid.
(Although I
think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on
H3/A64
at0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1]
http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2]
http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)Quoted 6 lines
Good detective work!
I believe this would best be fixed by making u-boot use the register access
method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.Yes.
Quoted 8 lines
Quoted 2 lines
However, what I considered is that fixing this bug will change H3 devices' MAC addresses, as they are derived from SID.
I know, but I think we will just need to accept this onetime change of the fixed MAC addresses to fix this bug. I don't think this is a big problem since the driver for the H3 ethernet has not been merged into the mainline kernel yet.
Do we still need to do the CRC32 across the SID values to generate the MAC addresses?
ChenYu
Quoted 30 lines
Quoted 1 line
Maybe we should add #ifdef's to MAC generation code after this fix.
I would rather not see #ifdefs for this, see above, but that is no longer my call, see below.
Quoted 5 lines
(This is why I will create this discussion)
P.S. Are you still the maintainer of sunxi boards support of u-boot? The MAINTAINER file in board/sunxi indicates this.No I'm no longer the maintainer, I'm still the MAINTAINER file because I have a lot of boards and as such I'm still the point of contact for those boards (if there are any board specific issues / questions), but as indicated in the main
MAINTAINERSfile Jagan Teki <[email protected]> is the maintainer now.Regards,
Hans
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,
Quoted 147 lines · Chen-Yu Tsai
Quoted 146 lines · Hans de Goede
Hi,
Quoted 140 lines · Icenowy Zheng
19.12.2016, 23:30, "Hans de Goede" <[email protected]>:
Quoted 124 lines
Hi,
Quoted 112 lines · Icenowy Zheng
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register
accessing, or
directly access0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference
between
the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2
(in
legacy kernel).According to the source of H2+ BSP[1], H2+ and H3 can be differed by
the last
byte of the first word of SID. (0x42and0x83is H2+,0x00and0x81is
H3,
0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3,
start
with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e"
on
my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel
sid)
And, after accessing to the SID by registers, the value of *0x01c14200
become
also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got
also
"02004620".Then I altered the program to do the register operations with
sunxi-fel, the
result is also "02c00081", and changedsunxi-fel sidresult to
"02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by
accessing
0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID
by
registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the
simplify the
code to read it, and it automatically loaded the cache when booting;
however,
when doing first cache on H3, some byte shifts occured, and the value
become
wrong. A manual read on H3 can make the cache right again. This is a
silicon
bug, and fixed in A64.This raises a problem: currently many systems has used the misread SID
value to
generated lots of MAC addresses, and workaround this SID bug will
change them.However, if this bug is not workarounded, the sun8i-ths driver won't
work well
(as some calibartion value lies in eFUSE). I think some early user of
this
driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid.
(Although I
think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on
H3/A64
at0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1]
http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2]
http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cQuoted 6 lines
Experiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)Quoted 6 lines
Good detective work!
I believe this would best be fixed by making u-boot use the register access
method to get the SID on affected chips, and make sure u-boot reads the SID at-least once.Yes.
However, what I considered is that fixing this bug will change H3 devices' MAC addresses, as they are derived from SID.
Quoted 7 lines
Quoted 4 lines
I know, but I think we will just need to accept this onetime change of the fixed MAC addresses to fix this bug. I don't think this is a big problem since the driver for the H3 ethernet has not been merged into the mainline kernel yet.
Do we still need to do the CRC32 across the SID values to generate the MAC addresses?
Yes this does not change that a single word has not enough randomness in it.
Regards,
Hans
Hi all!
This is rather interesting stuff. Actually it's possible to find partial documentation for this method (of reading SID/efuse values) even for older SoCs. There's an early version of the A20 User Manual (Revision 1.0 - Feb. 18, 2013) available on the net, where chapter 1.18 describes the registers involved. This section seems to have been removed in later editions. (Search for the file A20_UM-V1.020130322.pdf)
The U-Boot code that Allwinner published also has source files for various SoCs that contain corresponding implementations of sid_program_key() and sid_read_key() (in efuse.c),
see https://github.com/allwinner-zh/bootloader/search?q=sid_read_key.
Regards, B. Nortmann
Am 19.12.2016 um 16:22 schrieb Icenowy Zheng:
Quoted 95 lines
Hi everyone,
Today, I and KotCzarny on IRC of linux-sunxi found a problem in the SID controller of H3 (incl. H2+).
See https://irclog.whitequark.org/linux-sunxi/2016-12-19 .
Two read method of the H3 eFUSE is used in the BSP: by register accessing, or directly access
0x01c14200.From http://linux-sunxi.org/SID_Register_Guide we can see a difference between
the H3 SIDs read out by sunxi-fel and the H3 SIDs read out by devmem2 (in legacy kernel).According to the source of H2+ BSP[1], H2+ and H3 can be differed by the last byte of the first word of SID. (
0x42and0x83is H2+,0x00and0x81is H3,0x58is H3D (currently not known SoC) )However, all the SIDs retrieved by
sunxi-fel sid, both H2+ and H3, start with0x02004620, which do not match this rule.The readout by devmem2 is satisfying this rule: their first word is
0x02c00081, matches H3.Then I found the SID-reading code from BSP U-Boot[2], which is based on register operations. With this kind of code (I wrote one prototype in userspace with
/dev/mem), I got "02c0008174004620 503587203c27048e" on my Orange Pi One. ("02004620 743587205027048e3c0000c3" with sunxi-fel sid) And, after accessing to the SID by registers, the value of *0x01c14200 become also "02c00081".With direct access to
0x01c14200after boot with mainline kernel, I got also "02004620".Then I altered the program to do the register operations with sunxi-fel, the result is also "
02c00081", and changedsunxi-fel sidresult to "02c00081".Summary:
+-----------------------------------------------+----------------+ | Read situation | The first word | +-----------------------------------------------+----------------+ | Direct read by sunxi-fel | 02004620 | | Direct read in mainline /dev/mem | 02004620 | | Direct read in legacy /dev/mem | 02c00081 | | Register access in FEL | 02c00081 | | Register access in mainline | 02c00081 | | Direct read after register access in FEL | 02c00081 | | Direct read after register access in mainline | 02c00081 | +-----------------------------------------------+----------------+According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
- Reading via register access will change the value when reading by accessing0x01c14200.
- In the u-boot code[2] there's some functions which read out the SID by registers and then abandoned the value.
- This mismatch do not exist on A64.I think that: Allwinner designed a "cache" to the SID to make the simplify the code to read it, and it automatically loaded the cache when booting; however, when doing first cache on H3, some byte shifts occured, and the value become wrong. A manual read on H3 can make the cache right again. This is a silicon bug, and fixed in A64.
This raises a problem: currently many systems has used the misread SID value to generated lots of MAC addresses, and workaround this SID bug will change them.
However, if this bug is not workarounded, the sun8i-ths driver won't work well (as some calibartion value lies in eFUSE). I think some early user of this driver has already experienced bad readout value.
(The calibration value differs on my opi1 and KotCzarny's opipc)And many wrong SID values have been generated by
sunxi-fel sid. (Although I think sunxi-fel must have the workaround)Note: in this email, "SID" and "eFUSE" both indicate the controller on H3/A64 at
0x01c14000, which is a OTP memory implemented by eFUSE technique.Furthermore, A83T may also have this problem, testers are welcome!
[1] http://filez.zoobab.com/allwinner/h2/201609022/lichee/linux-3.4/arch/arm/mach-sunxi/sun8i.c
[2] http://filez.zoobab.com/allwinner/h2/201609022/lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw7/efuse.cExperiments:
- https://gist.github.com/Icenowy/2f4859ab1bc05814522fc7445179a8c9
A SID readout shell script via FEL with register access.
- https://31.135.195.151:20281/d/efuse/
A SID readout program via/dev/memwith register access by KotCzarny. (with statically compiled binary)Regards,
Icenowy
Side note:
Am 19.12.2016 um 16:22 schrieb Icenowy Zheng:
Quoted 7 lines
[...]
According to some facts:
- The register based access to SID is weird: it needs ~5 register operations per word of SID.
[...]
My experiments seem to indicate that Allwinner's implementation might be overly complicated. I have used an alternative approach and did not notice any issues so far.
They start by reading SID_PRCTL and use bit mask operations to get in the key index value (PG_INDEX), then use a second write to set OP_LOCK and READ_START. As far as I can tell, it's sufficient to construct (and write) a single value from these three components. Allwinner finally clears out the used bits by another mask operation, simply writing zero seems to get that job done equally well.
My implementation can be seen in
https://github.com/n1tehawk/sunxi-tools/blob/20161220_sid-fix/uart0-helloworld-sdboot.c#L242-L256
or as assembler code in
https://github.com/n1tehawk/sunxi-tools/blob/20161220_sid-fix/sid_read_root.S#L43-L65
A corresponding PR is at
https://github.com/linux-sunxi/sunxi-tools/pull/91 , or you may clone my branch directly
("git clone https://github.com/n1tehawk/sunxi-tools.git -b 20161220_sid-fix").
Testers would be very welcome.
Regards, B. Nortmann