|
|
@@ -9,6 +9,7 @@ block_size=
|
|
|
code_openwrt=
|
|
|
code_factory=
|
|
|
code_offset=
|
|
|
+read_mask=
|
|
|
|
|
|
read_nand() {
|
|
|
dd "if=$part" "of=$file" "bs=$block_size" "skip=$offset_blocks" count=1 2>/dev/null
|
|
|
@@ -29,6 +30,24 @@ part_named() {
|
|
|
echo "/dev/$pn"
|
|
|
}
|
|
|
|
|
|
+mask() {
|
|
|
+ if [ -z "$2" ]; then
|
|
|
+ echo "$1"
|
|
|
+ return
|
|
|
+ fi
|
|
|
+ echo "$1 $2" | awk '{
|
|
|
+ a=$1; b=$2;
|
|
|
+ res="";
|
|
|
+ for(i=1;i<=length(a);i++){
|
|
|
+ abit=substr(a,i,1);
|
|
|
+ bbit=substr(b,i,1);
|
|
|
+ if(bbit=="X") res=res""abit;
|
|
|
+ else res=res"0";
|
|
|
+ }
|
|
|
+ print res;
|
|
|
+ }'
|
|
|
+}
|
|
|
+
|
|
|
to_hex() {
|
|
|
hexdump -v -e '1/1 "%02x"'
|
|
|
}
|
|
|
@@ -38,16 +57,19 @@ from_hex() {
|
|
|
}
|
|
|
|
|
|
check() {
|
|
|
- stored_code=$(dd \
|
|
|
+ local stored_code=$(dd \
|
|
|
"if=$part" \
|
|
|
bs=1 \
|
|
|
skip=$((offset_blocks * block_size + code_offset)) \
|
|
|
count=$((${#code_openwrt} / 2)) \
|
|
|
2>/dev/null | to_hex
|
|
|
)
|
|
|
- if [ "$stored_code" = "$code_openwrt" ]; then
|
|
|
+ stored_code=$(mask "$stored_code" "$read_mask")
|
|
|
+ local code_owrt=$(mask "$code_openwrt" "$read_mask")
|
|
|
+ local code_fact=$(mask "$code_factory" "$read_mask")
|
|
|
+ if [ "$stored_code" = "$code_owrt" ]; then
|
|
|
echo "Current boot flag set to OS A (OpenWrt)"
|
|
|
- elif [ "$stored_code" = "$code_factory" ]; then
|
|
|
+ elif [ "$stored_code" = "$code_fact" ]; then
|
|
|
echo "Current boot flag set to OS B (Factory)"
|
|
|
else
|
|
|
echo "Current boot flag unknown: $stored_code"
|
|
|
@@ -86,6 +108,14 @@ main() {
|
|
|
code_offset=0
|
|
|
code_openwrt=0000000101000002
|
|
|
code_factory=0000000101010003
|
|
|
+ elif [ "$machine" = "Nokia G-240G-E" ]; then
|
|
|
+ part=$(part_named '"flag"')
|
|
|
+ offset_blocks=0
|
|
|
+ block_size=$((1024 * 128))
|
|
|
+ code_offset=0
|
|
|
+ code_openwrt=000000000000000000000001000000010000000000000000
|
|
|
+ code_factory=000000000000000100000001000000010000000000000000
|
|
|
+ read_mask=000000000000000X00000000000000000000000000000000
|
|
|
elif [ "$machine" = "SmartFiber XP8421-B" ]; then
|
|
|
# 0dfc0000
|
|
|
part=$(part_named '"reservearea"')
|