Created
December 19, 2016 15:15
-
-
Save Icenowy/2f4859ab1bc05814522fc7445179a8c9 to your computer and use it in GitHub Desktop.
Read H3 SID by register access with sunxi-fel
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
#! /bin/bash | |
SID_PRCTL=0x01c14040 | |
SID_PRKEY=0x01c14050 | |
SID_RDKEY=0x01c14060 | |
BIT() { | |
echo $(( 1 << $1 )) | |
} | |
SID_OP_LOCK=$((0xAC)) | |
SID_READ=$(BIT 1) | |
SID_WRITE=$(BIT 2) | |
INDEX_OFFSET=16 | |
INDEX_MASK=$(( 0x1ff << $INDEX_OFFSET )) | |
OP_OFFSET=8 | |
OP_MASK=$(( 0xff << $OP_OFFSET )) | |
RW_MASK=$(( $SID_READ | $SID_WRITE )) | |
readl() { | |
while ! sunxi-fel readl $1; do | |
true | |
done | |
} | |
writel() { | |
while ! sunxi-fel writel $2 $1; do | |
true | |
done | |
} | |
dec2hex() { | |
printf 0x%x $1 | |
} | |
hex2dec() { | |
echo $(($1)) | |
} | |
sid_read_key() { | |
local reg_val | |
reg_val=$(readl $SID_PRCTL) | |
reg_val=$(( $reg_val & (~$INDEX_MASK) )) | |
reg_val=$(( $reg_val & (~$RW_MASK) )) | |
reg_val=$(( $reg_val | ($1 << $INDEX_OFFSET) )) | |
writel $reg_val $SID_PRCTL | |
reg_val=$(( $reg_val & (~$OP_MASK) )) | |
reg_val=$(( $reg_val & (~$RW_MASK) )) | |
reg_val=$(( $reg_val | ($SID_OP_LOCK << $OP_OFFSET) )) | |
reg_val=$(( $reg_val | $SID_READ )) | |
writel $reg_val $SID_PRCTL | |
while (( $(readl $SID_PRCTL) & $SID_READ )) | |
do | |
true | |
done | |
reg_val=$(( $reg_val & (~$INDEX_MASK) )) | |
reg_val=$(( $reg_val & (~$OP_MASK) )) | |
reg_val=$(( $reg_val & (~$RW_MASK) )) | |
writel $reg_val $SID_PRCTL | |
readl $SID_RDKEY | |
} | |
echo $(sid_read_key 0x0) $(sid_read_key 0x4) $(sid_read_key 0x8) $(sid_read_key 0xc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment