a9ccef819830c07f5cb2d8e4c5faba0db83f2c38
[keystone-demos/matrix-apps.git] / utility_eeprom / cgi-bin / eepromread.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 Read</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
34 get_params()
35 {
36 busAddr=$(cat $TMPFILE | sed -n '4p' | sed 's/.$//')
37 eepromdev=$(find /sys -name eeprom)
38 readSz=65536
39 echo $busAddr
40 echo $eepromdev
42 TMPFILE_DATA="../i2c_"$busAddr".bin"
43 if [ "$busAddr" = "0x51" ] ; then
44 devOffset=$readSz
45 else
46 devOffset=0
47 fi
48 echo $devOffset
51 }
53 check_params()
54 {
55 echo
56 }
58 #Read EEPROM 
59 read_eeprom()
60 {
61 cat << EOM1
62 <div id='content'>
63 <p>Reading <i>$readSz</i> bytes from EEPROM Bus Address <i>$busAddr</i> ...</p>
64 </div>
65 EOM1
66 dd of=$TMPFILE_DATA if=$eepromdev bs=1 count=$readSz skip=$devOffset 2> /dev/null
67 sync
68 }
70 #Allow User to download the file
71 file_download()
72 {
73 cat << EOM1
74 <div id='content'>
75 <input type="button" name="Button" value="Save EEPROM data" onClick="window.open('$TMPFILE_DATA', 'download'); return false;">
76 </div>
77 EOM1
78 }
80 get_params
81 check_params
82 read_eeprom
83 file_download
85 display_footer
86 rm -f $TMPFILE
87 rm -f $TMPFILE_DATA