matrix utility apps: initial version
[keystone-demos/matrix-apps.git] / utility_eeprom / cgi-bin / eepromwrite.cgi
1 #!/bin/sh
2 echo Content-type: text/html
3 echo 
4 echo 
6 display_footer()
7 {
8 cat << EOM2
9 <div style='clear: both;'>&nbsp;</div>
10 </div>
11 <div id='footer'><p id='legal'>( c ) 2013 Texas Instruments Incorporated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></div>
12 </body>
13 </html>
14 EOM2
15 }
17 cat << EOM
18 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'>
19 <head><meta http-equiv='Pragma' CONTENT='no-cache' /> <meta http-equiv='content-type' content='text/html; charset=utf-8' /> <title>C6x Linux Web Control Panel</title>
20 </head>
21 <body>
22 <div id='wrapper'>
23 <div id='logo'><h1>EEPROM Write</h1></div>
24 <div id='header'>
25 <div id='menu'>
26 </div>
27 </div>
28 </div>
29 <div id='page'>
30 EOM
31 TMPFILE=`mktemp`
32 cat > $TMPFILE
33 get_params()
34 {
35 busAddr=$(cat $TMPFILE | sed -n '4p' | sed 's/.$//')
36 eepromdev=$(find /sys -name eeprom)
37 soffset=$(head -8 $TMPFILE | wc -c)
38 eoffset=$(tail -1 $TMPFILE | wc -c)
39 fsize=$(cat $TMPFILE | wc -c)
40 osize=$(((($fsize-$eoffset)-$soffset)-2))
41 eepromSz=65536
42 if [ "$busAddr" = "0x51" ] ; then
43 devOffset=$eepromSz
44 else
45 devOffset=0
46 fi
47 }
49 # write eeprom
50 write_eeprom()
51 {
52 wOffset=$devOffset
53 cat << EOM1
54 <div id='content'>
55 <p>Writing EEPROM <i>$osize</i> bytes to <i>$eepromdev</i> ...</p>
56 <p>This step would take few minutes ...</p>
57 </div>
58 EOM1
59 dd if=$TMPFILE of=$eepromdev bs=1 count=$osize seek=$wOffset skip=$soffset 2> /dev/null
60 sync
61 rm -f $TMPFILE
62 }
64 check_params()
65 {
66 if [ $osize -eq 0 ] ; then
67 cat << EOM1
68 <div id='content'>
69 <p>Bad Input file ...</p>
70 </div>
71 EOM1
72 display_footer
73 rm -f $TMPFILE
74 exit
75 fi
76 if [ $osize -gt $eepromSz ] ; then
77 cat << EOM1
78 <div id='content'>
79 <p>Input file Size greater than <i>$eepromSz</i> bytes ...</p>
80 </div>
81 EOM1
82 display_footer
83 rm -f $TMPFILE
84 exit
85 fi
86 }
88 get_params
89 check_params
90 write_eeprom
92 cat << EOM2
93 <div id='content'>
94 <p>EEPROM programming complete</p>
95 </div>
96 EOM2
98 display_footer