-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsc.sh
32 lines (32 loc) · 908 Bytes
/
sc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DTBIMG=dtb.img
DTBSIG="00 00 d0 0d fe ed"
DTBSIGOFF=2
rm -rf ./phone_dts
mkdir -p phone_dts
hexdump -v -e "1/1 \"%02x \"" $DTBIMG >./phone_dts/dtb_hex.txt
unset OFFSETS
unset SIZES
declare -a OFFSETS
declare -a SIZES
BCNT=0
for OFF in `grep -oba "$DTBSIG" ./phone_dts/dtb_hex.txt | awk -F':' '{print $1}'`; \
do \
let "SIGOFF = OFF/3 + DTBSIGOFF"; \
let "OFFSETS[BCNT] = SIGOFF"; \
if [[ $BCNT > 0 ]]; then let "SIZES[BCNT-1] = SIGOFF - OFFSETS[BCNT-1]"; fi; \
let "BCNT += 1"; \
done
rm ./phone_dts/dtb_hex.txt
ACNT=0
for OFF in "${OFFSETS[@]}"; \
do \
DTNAME=$(printf "./phone_dts/dt_%02d" $ACNT); \
if [[ $ACNT == $(($BCNT-1)) ]]; then \
dd if=$DTBIMG of=$DTNAME.bin ibs=1 skip=$(($OFF)); \
else \
dd if=$DTBIMG of=$DTNAME.bin ibs=1 skip=$(($OFF)) count=$((${SIZES[$ACNT]})); \
fi; \
./dtc -I dtb $DTNAME.bin -O dts -o $DTNAME.dts; \
rm $DTNAME.bin; \
let "ACNT += 1"; \
done