-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fel_lib: Implement thunk code for register-based retrieval of SID
The new function fel_get_sid_registers() uses ARM code for register access to the SID root key. This is necessary to retrieve correct values for certain SoCs, e.g. when not using this approach the H3 has been observed to return 'mangled' values (when reading SID from memory). See https://groups.google.com/forum/#!topic/linux-sunxi/ynyIP8c61Qs The FEL library provides a uniform fel_get_sid_root_key() wrapper that will automatically use the workaround method for SoCs that are tagged accordingly - so the application program does not have to bother with selecting memory vs. register-based access. Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
- Loading branch information
Showing
4 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2016 Bernhard Nortmann <bernhard.nortmann@web.de> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice (including the next | ||
* paragraph) shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/* | ||
* ARM thunk code to read the SID root key using register-based access. | ||
* | ||
* This is necessary for certain SoCs (e.g. H3), as the values read via | ||
* memory mapping might not be consistent. For background information see | ||
* https://groups.google.com/forum/#!topic/linux-sunxi/ynyIP8c61Qs | ||
*/ | ||
|
||
SID_BASE .req r0 | ||
sid_key_index .req r1 | ||
|
||
.set SID_PRCTL, 0x40 /* SID program/read control register */ | ||
.set SID_PRKEY, 0x50 /* SID program key value register */ | ||
.set SID_RDKEY, 0x60 /* SID read key value register */ | ||
|
||
.set SID_OP_LOCK, 0xAC /* Efuse operation lock value */ | ||
.set SID_READ_START, (1 << 1) /* bit 1 of SID_PRCTL, Software Read Start */ | ||
.set SID_PG_START, (1 << 0) /* bit 0 of SID_PRCTL, Software Program Start */ | ||
|
||
sid_read_root_key: | ||
ldr SID_BASE, sid_base | ||
mov sid_key_index, #0 | ||
adr r3, sid_result /* result pointer */ | ||
sid_read_loop: | ||
mov r2, sid_key_index, lsl #16 /* PG_INDEX value */ | ||
orr r2, #SID_OP_LOCK << 8 /* OP_LOCK to enable SID_READ_START */ | ||
orr r2, #SID_READ_START | ||
str r2, [SID_BASE, #SID_PRCTL] /* write SID_PRCTL */ | ||
sid_read_wait: | ||
ldr r2, [SID_BASE, #SID_PRCTL] /* read SID_PRCTL */ | ||
tst r2, #SID_READ_START /* check if read operation completed */ | ||
bne sid_read_wait /* loop while bit 1 still set */ | ||
|
||
ldr r2, [SID_BASE, #SID_RDKEY] /* read SID key value */ | ||
str r2, [r3, sid_key_index] /* store SID value */ | ||
|
||
add sid_key_index, #4 | ||
cmp sid_key_index, #16 | ||
blo sid_read_loop /* loop while (sid_key_index < 0x10) */ | ||
|
||
mov r2, #0 | ||
str r2, [SID_BASE, #SID_PRCTL] /* clear SID_PRCTL */ | ||
bx lr | ||
|
||
sid_base: .word 0 | ||
sid_result: .word 0 /* receives the four "root key" 32-bit words */ | ||
.word 0 | ||
.word 0 | ||
.word 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* <sid_read_root_key>: */ | ||
htole32(0xe59f0040), /* 0: ldr r0, [pc, #64] */ | ||
htole32(0xe3a01000), /* 4: mov r1, #0 */ | ||
htole32(0xe28f303c), /* 8: add r3, pc, #60 */ | ||
/* <sid_read_loop>: */ | ||
htole32(0xe1a02801), /* c: lsl r2, r1, #16 */ | ||
htole32(0xe3822b2b), /* 10: orr r2, r2, #44032 */ | ||
htole32(0xe3822002), /* 14: orr r2, r2, #2 */ | ||
htole32(0xe5802040), /* 18: str r2, [r0, #64] */ | ||
/* <sid_read_wait>: */ | ||
htole32(0xe5902040), /* 1c: ldr r2, [r0, #64] */ | ||
htole32(0xe3120002), /* 20: tst r2, #2 */ | ||
htole32(0x1afffffc), /* 24: bne 1c <sid_read_wait> */ | ||
htole32(0xe5902060), /* 28: ldr r2, [r0, #96] */ | ||
htole32(0xe7832001), /* 2c: str r2, [r3, r1] */ | ||
htole32(0xe2811004), /* 30: add r1, r1, #4 */ | ||
htole32(0xe3510010), /* 34: cmp r1, #16 */ | ||
htole32(0x3afffff3), /* 38: bcc c <sid_read_loop> */ | ||
htole32(0xe3a02000), /* 3c: mov r2, #0 */ | ||
htole32(0xe5802040), /* 40: str r2, [r0, #64] */ | ||
htole32(0xe12fff1e), /* 44: bx lr */ | ||
/* <sid_base>: */ | ||
htole32(0x00000000), /* 48: .word 0x00000000 */ | ||
/* <sid_result>: */ |