hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
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
if itest.s a$uboot_defconfig == a; then
        echo "Please set uboot_defconfig to the appropriate value"
        exit
fi
 
offset=0x400
erase_size=0xC0000
qspi_offset=0x0
a_base=0x12000000
 
if itest.s x51 == "x${imx_cpu}"; then
   a_base=0x92000000
elif itest.s x53 == "x${imx_cpu}"; then
   a_base=0x72000000
elif itest.s x6SX == "x${imx_cpu}" || itest.s x7D == "x${imx_cpu}"; then
   a_base=0x82000000
fi
 
qspi_match=1
setexpr a_qspi1 ${a_base}
setexpr a_qspi2 ${a_qspi1} + 0x400000
setexpr a_uImage1 ${a_qspi1} + 0x400
setexpr a_uImage2 ${a_qspi2} + 0x400
setexpr a_script ${a_base}
 
setenv stdout serial,vga
 
if sf probe || sf probe || sf probe 1 27000000 || sf probe 1 27000000 ; then
   echo "probed SPI ROM" ;
else
   echo "Error initializing EEPROM"
   exit
fi
 
if itest.s x7D == "x${imx_cpu}"; then
   echo "check qspi parameter block" ;
   if ${fs}load ${devtype} ${devnum}:1 ${a_qspi1} qspi-${sfname}.${uboot_defconfig} ; then
   else
       echo "parameter file qspi-${sfname}.${uboot_defconfig} not found on SD card"
       exit
   fi
   if itest ${filesize} != 0x200 ; then
       echo "------- qspi-${sfname}.${uboot_defconfig} 0x${filesize} != 0x200 bytes" ;
       exit
   fi
   setexpr a_marker ${a_qspi1} + 0x1fc
   if itest *${a_marker} != c0ffee01 ; then
       echo "------- qspi-${sfname}.${uboot_defconfig} c0ffee01 marker missing" ;
       exit
   fi
   if sf read ${a_qspi2} ${qspi_offset} 0x200 ; then
   else
       echo "Error reading qspi parameter from EEPROM"
       exit
   fi
   if cmp.b ${a_qspi1} ${a_qspi2} 0x200 ; then
       echo "------- qspi parameters match"
   else
       echo "------- qspi parameters mismatch"
       qspi_match=0
   fi
fi
 
echo "check U-Boot" ;
 
if ${fs}load ${devtype} ${devnum}:1 ${a_uImage1} u-boot.$uboot_defconfig ; then
else
   echo "File u-boot.$uboot_defconfig not found on SD card" ;
   exit
fi
echo "read $filesize bytes from SD card" ;
if sf read ${a_uImage2} $offset $filesize ; then
else
   echo "Error reading boot loader from EEPROM" ;
   exit
fi
 
if cmp.b ${a_uImage1} ${a_uImage2} $filesize ; then
   echo "------- U-Boot versions match" ;
   if itest.s "${qspi_match}" == "1" ; then
       echo "------- upgrade not needed" ;
       if itest.s "x" != "x${next}" ; then
           if ${fs}load ${devtype} ${devnum}:1 ${a_script} ${next} ; then
               source ${a_script}
           else
               echo "${next} not found on SD card"
           fi
       fi
       exit
   fi
   erase_size=0x1000
   if itest.s xMX25L6405D == "x${sfname}"; then
       erase_size=0x10000
   fi
   setexpr filesize ${erase_size} - ${offset}
fi
 
echo "Need U-Boot upgrade" ;
echo "Program in 5 seconds" ;
for n in 5 4 3 2 1 ; do
   echo $n ;
   sleep 1 ;
done
echo "erasing" ;
sf erase 0 ${erase_size} ;
 
# two steps to prevent bricking
echo "programming" ;
setexpr a1 ${a_uImage1} + 0x400
setexpr o1 ${offset} + 0x400
setexpr s1 ${filesize} - 0x400
sf write ${a1} ${o1} ${s1} ;
sf write ${a_uImage1} $offset 0x400 ;
 
if itest.s x7D == "x${imx_cpu}"; then
   sf write ${a_qspi1} ${qspi_offset} 0x200
fi
 
echo "verifying" ;
if sf read ${a_uImage2} $offset $filesize ; then
else
   echo "Error re-reading EEPROM" ;
   exit
fi
if cmp.b ${a_uImage1} ${a_uImage2} $filesize ; then
else
   echo "Read verification error" ;
   exit
fi
 
if itest.s x7D == "x${imx_cpu}"; then
   if sf read ${a_qspi2} ${qspi_offset} 0x200 ; then
   else
       echo "Error re-reading qspi" ;
       exit
   fi
   if cmp.b ${a_qspi1} ${a_qspi2} 0x200 ; then
   else
       echo "qspi parameter block verification error" ;
       exit
   fi
fi
 
if itest.s "x" != "x${next}" ; then
   if ${fs}load ${devtype} ${devnum}:1 ${a_script} ${next} ; then
       source ${a_script}
   else
       echo "${next} not found on ${devtype} ${devnum}"
   fi
fi
 
while echo "---- U-Boot upgraded. reset" ; do
   sleep 120
done