-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-uboot-env-img.sh
executable file
·86 lines (67 loc) · 1.55 KB
/
gen-uboot-env-img.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /bin/sh
#
# https://github.com/andrewintw
#
# 0x1000 - 0x4 in my uboot
ENV_DATA_SIZE=4092
CFG_DATA_BIN="config.data"
CFG_BASE_BIN="config.base"
CFG_CRC_BIN="config.crc32"
CFG_IMG="config.bin"
env_file="$1"
show_usage () {
cat <<EOF
Usage: `basename $0` <uboot-env.text>
EOF
}
do_init () {
rm -rf $CFG_DATA_BIN $CFG_BASE_BIN $CFG_CRC_BIN $CFG_IMG
if [ "$env_file" = "" ]; then
show_usage && exit 1
fi
if [ ! -f "$env_file" ]; then
echo "[Error] No such file: $env_file"
show_usage && exit 1
fi
}
gen_cfg_data () {
cat $env_file | sed '/^$/d' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr '\n' '\0' > $CFG_DATA_BIN
}
gen_cfg_base () {
dd if=/dev/zero of=$CFG_BASE_BIN bs=1 count=$ENV_DATA_SIZE 2>/dev/null
if [ -f "$CFG_DATA_BIN" ]; then
dd if=$CFG_DATA_BIN of=$CFG_BASE_BIN bs=1 count=`stat -c %s $CFG_DATA_BIN` conv=notrunc 2>/dev/null
else
echo "[Error] No such file: $CFG_DATA_BIN"
exit 1
fi
}
gen_cfg_crc () {
crc32 $CFG_BASE_BIN | sed 's/.\{2\}/& /g' | awk '{for (i=NF;i>=1;i--) printf "%s ", $i;}' | xxd -r -p > $CFG_CRC_BIN
}
gen_cfg_bin () {
if [ -f "$CFG_CRC_BIN" ] && [ -f "$CFG_BASE_BIN" ]; then
cat $CFG_CRC_BIN $CFG_BASE_BIN > $CFG_IMG
else
echo "[Error] No such file: $CFG_CRC_BIN or $CFG_BASE_BIN"
exit 1
fi
}
do_done () {
if [ -f "$CFG_IMG" ]; then
hexdump -C $CFG_IMG
else
echo "[Error] No such file: $CFG_IMG"
exit 1
fi
rm -rf $CFG_DATA_BIN $CFG_BASE_BIN $CFG_CRC_BIN
}
do_main () {
do_init && \
gen_cfg_data && \
gen_cfg_base && \
gen_cfg_crc && \
gen_cfg_bin && \
do_done
}
do_main