summaryrefslogtreecommitdiff
path: root/recipes-images/images/files/library/create_configblock.sh
blob: 63e9951c8843c22d3ceb88e0d008d29d6c8f3b3b (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#! /bin/sh

# exit on error
set -e

Usage()
{
	echo "create_configblock creates a configblock binary from the info on the module sticker."
	echo "This can be used when the configblock got lost during a failed update attempt."
	echo ""
	echo "The created config-block will be copied to the choosen output directory when running"
	echo "the update.sh command."
	echo ""
	echo "In order to write the config block enter on the U-Boot commandline:"
	echo "run update"
	echo "run update_configblock"
	echo ""
	echo "For Colibri VF modules the boot configuration block needs to be recreated first:"
	echo "run update"
	echo "run create_bcb"
	echo "run update_configblock"
	echo ""
}

while getopts "h" Option ; do
        case $Option in
                h) Usage
                        # Exit if only usage (-h) was specfied.
                        if [[ $# -eq 1 ]] ; then
                                exit 10
                        fi
                        exit 0
                        ;;
        esac
done

#sanity check for some programs
AWKTEST=`echo 12345678abcdefgh | awk 'BEGIN{ FIELDWIDTHS = "8 8"} {print $2}'` || true
[ "${AWKTEST}x" = "abcdefghx" ] || { echo >&2 "Program gawk not available.  Aborting."; exit 1; }

# autotect MODTYPE from from rootfs directory
CNT=`grep -c "VF" rootfs/etc/issue || true`
if [ "$CNT" -ge 1 ] ; then
	echo "Colibri VF rootfs detected"
	MODTYPE=colibri-vf
else
	CNT=`grep -c "Colibri_iMX6" rootfs/etc/issue || true`
	if [ "$CNT" -ge 1 ] ; then
		echo "Colibri iMX6 rootfs detected"
		MODTYPE=colibri-imx6
	else
		CNT=`grep -ic "imx6" rootfs/etc/issue || true`
		if [ "$CNT" -ge 1 ] ; then
			echo "Apalis iMX6 rootfs detected"
			MODTYPE=apalis-imx6
		else
			echo "can not detect modulue type from ./rootfs/etc/issue"
			echo "exiting"
			exit 1
		fi
	fi
fi

echo "Enter the modules serial number on the modules sticker or"
echo "use a barcode scanner to enter the content of the stickers barcode"

# read a barcode and test it to be 8 or 16 numbers only 0025100102489109 0115100000000024
#                                                       1234567890123456 1234567890123456
until [ "${BARCODE}x" != "x" ]
do
	read BARCODE
	#remove all whitespace
	BARCODE=`echo $BARCODE | tr -d ' '`	
	#get strlen and the number of numeric characters
	STRLEN=`echo $BARCODE  | wc -c`
	NUMCNT=`echo $BARCODE | sed 's/[^0-9]//g' | wc -c`
	if [ $STRLEN -ne 17 ] ; then 
		if [ $STRLEN -ne 9 ] ; then
			echo "The serial number must be 8 numbers long (the barcode 16)"
			BARCODE=""
		fi
	fi
	if [ $NUMCNT -ne $STRLEN ] ; then
		echo "The serial number must contain all numeric characters"
		BARCODE=""
	fi
done
DATECODE=19700101000000
if [ $STRLEN -eq 17 ] ; then
	SERIALNR=`echo $BARCODE | awk 'BEGIN{ FIELDWIDTHS = "8 8"} {print $2}'`
	PRODUCTNR=`echo $BARCODE | awk 'BEGIN{ FIELDWIDTHS = "8 8"} {print $1}'`
else
	SERIALNR=$BARCODE
	case ${MODTYPE} in
	"apalis-imx6")
		RAM_SIZE=1024
		echo "Enter the RAM size ( 512 / 1024 / 2048 ):"
		read RAM_SIZE
		case ${RAM_SIZE} in
		"512")
			PROD_ID="0029"
			;;
		"1024") 
			PROD_ID="0027"
			;;
		"2048")
			PROD_ID="0028"
			;;
		esac
		;;
	"colibri-imx6")
		RAM_SIZE=256
		echo "Enter the RAM size ( 256 / 512 ):"
		read RAM_SIZE
		echo "Enter I for IT version, nothing otherwise"
		read IT
		if [ $RAM_SIZE -eq 512 ] ; then
			if [ "$IT"x = "Ix" ] ; then
				PROD_ID="0017"
			else
				PROD_ID="0015"
			fi
		else
			if [ "$IT"x = "Ix" ] ; then
				PROD_ID="0016"
			else
				PROD_ID="0014"
			fi
		fi
		;;
	"colibri-vf")
		VF_TYPE=50
		echo "Enter the Module Type (50 for a Colibri VF50 or 61 for a Colibri VF61)"
		read VF_TYPE

		echo "Enter I for IT version, nothing otherwise"
		read IT
		if [ "$VF_TYPE" = "50" ] ; then
			if [ "$IT"x = "Ix" ] ; then
				PROD_ID="0013"
			else
				PROD_ID="0010"
			fi
		elif [ "$VF_TYPE" = "61" ] ; then
			if [ "$IT"x = "I"x ] ; then
				PROD_ID="0012"
			else
				PROD_ID="0011"
			fi
		fi
		;;
	esac

	echo "Enter the module version, e.g. V1.2 C"
	read PRODVERSION
	VER_MAJ=`echo $PRODVERSION | awk 'BEGIN{ FIELDWIDTHS = "1 1 1 1 1 1"} {print $2}'`
	VER_MIN=`echo $PRODVERSION | awk 'BEGIN{ FIELDWIDTHS = "1 1 1 1 1 1"} {print $4}'`
	#VARIANT: A=0, B=1 ...
	VARIANT=`echo $PRODVERSION | awk 'BEGIN{ FIELDWIDTHS = "1 1 1 1 1 1"} {print $6}'`
	VARIANT=`printf "%d\n" "'$VARIANT"`
	VARIANT=`expr $VARIANT - 65`
	if [ "$VARIANT" -lt 10 ] ; then
		VARIANT=0$VARIANT
	fi
	PRODUCTNR=${PROD_ID}${VER_MAJ}${VER_MIN}${VARIANT}
fi

#write the config block file
CONFIGBLOCK_FILE=${MODTYPE}_bin/configblock.bin
sudo chown ${USER}: `dirname $CONFIGBLOCK_FILE`
sudo rm -f $CONFIGBLOCK_FILE
#file header
awk 'function sc(c) {return (c<128?c:(c-256))} BEGIN{printf "%c%c%c%c",0,64,1,-49}' > $CONFIGBLOCK_FILE
#mac addr / serial
echo $SERIALNR | awk 'function sc(c) {return (c<128?c:(c-256))} {printf "%c%c%c%c%c%c%c%c%c%c%c%c",2,64,0,0, 0,20,45, sc(int($0/256/256)), sc(int($0/256)%256), sc($0%256),0,0 }' >> $CONFIGBLOCK_FILE
#product describtion, $1 char 0/1: ??, $2 char 2/3: ProdID, $3 char 4:VerMaj, $4 char 5:VerMin, $5 char 6/7:Variant
echo $PRODUCTNR | awk 'BEGIN{ FIELDWIDTHS = "2 2 1 1 2"} function sc(c) {return (c<128?c:(c-256))} {printf "%c%c%c%c%c%c%c%c%c%c%c%c",2,64,8,0 ,sc($3),0, sc($4),0, sc($5),0, sc($2),0 }' >> $CONFIGBLOCK_FILE
#fill to 32 bytes
awk 'function sc(c) {return (c<128?c:(c-256))} BEGIN{printf "%c%c%c%c",-1,-1,-1,-1}' >> $CONFIGBLOCK_FILE

exit 0