source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/FlashSST.asm@ 621

Last change on this file since 621 was 621, checked in by Krister Nordvall, 3 years ago

Changes:

  • Fixed three different bugs all causing the boot menu to show drives using IRQs even though the BIOS had been built without MODULE_IRQ.
  • Fixed two bugs in XTIDECFG where loading a BIOS from file and then loading the old settings from EEPROM would
    • overwrite ROMVARS.wFlags in the loaded BIOS file (in RAM). The possibly resulting mismatch of module flags could make it impossible to change settings for modules included in the BIOS or allow changing settings for modules not included in the BIOS.
    • not copy the color theme over to the loaded BIOS.
  • Also fixed two very minor bugs in XTIDECFG in BiosFile_LoadFileFromDSSItoRamBuffer and BiosFile_SaveRamBufferToFileInDSSI where the error handling in these routines would close whatever file handle that happened to match the error code returned by DOS in AX.
  • Made significant changes to the new flash ROM programming routines to reduce the size. Also fixed a minor bug that would cause the second verification to be skipped and return success when programming a 64 KB block of data.
  • Changed the custom BIOS build file names to the 8.3 format.
  • Changed some help strings in XTIDECFG to clarify things.
  • Other minor optimizations and fixes.
File size: 7.4 KB
Line 
1; Project name : XTIDE Universal BIOS Configurator v2
2; Description : Functions for flashing SST flash devices.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2021 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; FlashSst_WithFlashvarsInDSSI
25; Parameters:
26; DS:BX: Ptr to FLASHVARS
27; Returns:
28; Updated FLASHVARS in DS:BX
29; Corrupts registers:
30; AX, DX, DI
31;--------------------------------------------------------------------
32ALIGN JUMP_ALIGN
33FlashSst_WithFlashvarsInDSBX:
34 push ds
35 push es
36 push bx
37 push cx
38 push si
39 push bp
40 mov bp, bx ; Flashvars now in SS:BP (Assumes SS=DS)
41
42 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DeviceNotDetected
43 call DetectSstDevice
44 jc SHORT .ExitOnError
45
46 call CalibrateSstTimeout
47
48 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError
49 mov cx, [bp+FLASHVARS.wPagesToFlash]
50 mov dx, [bp+FLASHVARS.wEepromPageSize]
51 les di, [bp+FLASHVARS.fpNextSourcePage]
52 lds si, [bp+FLASHVARS.fpNextDestinationPage]
53%ifdef CLD_NEEDED
54 cld
55%endif
56
57ALIGN JUMP_ALIGN
58.NextPage:
59 ; See if this page needs updating.
60 push si
61 push di
62 push cx
63 mov cx, dx
64 repe cmpsb
65 pop cx
66 pop di
67 pop si
68 jne SHORT .FlashThisPage
69 add si, dx
70 add di, dx
71 jmp SHORT .ContinueLoop
72
73.FlashThisPage:
74 call EraseSstPage
75 jc SHORT .ExitOnError
76 call WriteSstPage
77 jc SHORT .ExitOnError
78.ContinueLoop:
79 loop .NextPage
80
81 ; The write process has already confirmed the results one byte at a time.
82 ; Here we do an additional verify check just in case there was some
83 ; kind of oddity with pages / addresses.
84 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError
85%ifndef USE_186
86 mov ax, [bp+FLASHVARS.wPagesToFlash]
87 mov cl, SST_PAGE_SIZE_SHIFT - 1 ; -1 because we compare WORDs (verifying 64 KB won't work otherwise)
88 shl ax, cl
89 xchg cx, ax
90%else
91 mov cx, [bp+FLASHVARS.wPagesToFlash]
92 shl cx, SST_PAGE_SIZE_SHIFT - 1
93%endif
94 lds si, [bp+FLASHVARS.fpNextSourcePage]
95 les di, [bp+FLASHVARS.fpNextDestinationPage]
96 repe cmpsw
97 jne SHORT .ExitOnError
98
99%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
100%if FLASH_RESULT.success = 0 ; Just in case this should ever change
101 mov [bp+FLASHVARS.flashResult], cl
102%else
103 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
104%endif
105%endif
106ALIGN JUMP_ALIGN
107.ExitOnError:
108 pop bp
109 pop si
110 pop cx
111 pop bx
112 pop es
113 pop ds
114 ret
115
116;--------------------------------------------------------------------
117; DetectSstDevice
118; Parameters:
119; SS:BP: Ptr to FLASHVARS
120; Returns:
121; CF: Clear if supported SST device found
122; Set if supported SST device not found
123; Corrupts registers:
124; AX, BX, SI, DS
125;--------------------------------------------------------------------
126ALIGN JUMP_ALIGN
127DetectSstDevice:
128 lds si, [bp+FLASHVARS.fpNextDestinationPage]
129 mov bx, 5555h
130
131 cli
132 mov BYTE [bx], 0AAh ; Enter software ID sequence.
133 shr bx, 1 ; BX=2AAAh, CF=1
134 mov BYTE [bx], 55h
135 eRCL_IM bx, 1 ; BX=5555h
136 mov BYTE [bx], 90h
137 mov al, [si] ; Extra reads to be sure device
138 mov al, [si] ; has time to respond.
139 mov al, [si]
140 mov ah, [si] ; Vendor ID in AH.
141 mov al, [si+1] ; Device ID in AL.
142 mov BYTE [bx], 0F0h ; Exit software ID.
143 sti
144
145 cmp ax, 0BFB4h
146 jb SHORT .NotValidDevice
147 cmp ax, 0BFB7h+1
148 cmc
149.NotValidDevice:
150 ret
151
152;--------------------------------------------------------------------
153; CalibrateSstTimeout
154; Parameters:
155; SS:BP: Ptr to FLASHVARS
156; Returns:
157; FLASHVARS.wTimeoutCounter
158; Corrupts registers:
159; AX, BX, CX, SI, DI, DS, ES
160;--------------------------------------------------------------------
161ALIGN JUMP_ALIGN
162CalibrateSstTimeout:
163 LOAD_BDA_SEGMENT_TO es, cx, !
164 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2]
165 mov bx, BDA.dwTimerTicks
166 mov si, cx
167 mov di, cx
168 mov al, [di]
169 inc ax ; Forces poll to fail
170
171 mov ah, [es:bx] ; Read low byte only
172 inc ah
173.WaitForFirstIncrement:
174 cmp ah, [es:bx]
175 jne SHORT .WaitForFirstIncrement
176
177 inc ah
178
179.WaitForSecondIncrement:
180 inc ch ; CX now 0x0100
181.PollLoop: ; Identical to poll loop used
182 cmp [di], al ; during programming
183 loopne .PollLoop ; Will never be equal in this case
184 inc si ; Number of poll loops completed
185 jz SHORT .CountOverflow
186 cmp ah, [es:bx]
187 jne SHORT .WaitForSecondIncrement
188 SKIP1B al
189.CountOverflow:
190 ; Clamp on overflow, although it should not be possible on
191 ; real hardware. In principle SI could overflow on a very
192 ; fast CPU. However the SST device is on a slow bus. Even
193 ; running at the min read cycle time of fastest version of
194 ; the device, SI can not overflow.
195 dec si
196
197 ; SI ~= number of polling loops in 215us.
198 mov [bp+FLASHVARS.wTimeoutCounter], si
199 ret
200
201;--------------------------------------------------------------------
202; EraseSstPage
203; Parameters:
204; DS:SI: Destination ptr
205; Returns:
206; CF: Set on error.
207; Corrupts registers:
208; AX, BX
209;--------------------------------------------------------------------
210ALIGN JUMP_ALIGN
211EraseSstPage:
212 push cx
213
214 mov bx, 5555h
215 mov ax, 2AAAh
216
217 ; Sector erase sequence.
218 mov [bx], al ; [5555h] <- AAh
219 xchg bx, ax
220 mov [bx], al ; [2AAAh] <- 55h
221 xchg bx, ax
222 mov BYTE [bx], 80h ; [5555h] <- 80h
223 mov [bx], al ; [5555h] <- AAh
224 xchg bx, ax
225 mov [bx], al ; [2AAAh] <- 55h
226 mov BYTE [si], 30h
227
228 or bl, al ; BL = 0FFh
229 mov ax, 1163 ; 1163 x ~215us = 250ms = 10x datasheet max
230.TimeoutOuterLoop:
231 mov cx, [bp+FLASHVARS.wTimeoutCounter]
232.TimeoutInnerLoop:
233 cmp [si], bl ; Will return 0FFh when erase complete
234 loopne .TimeoutInnerLoop
235 je SHORT .Return
236 dec ax
237 jnz SHORT .TimeoutOuterLoop
238 ; Timed out (CF=1)
239.Return:
240 pop cx
241 ret
242
243;--------------------------------------------------------------------
244; WriteSstPage
245; Parameters:
246; DX: EEPROM page size
247; DS:SI: Destination ptr
248; ES:DI: Source ptr
249; Returns:
250; SI, DI: Each advanced forward 1 page.
251; CF: Set on error.
252; Corrupts registers:
253; AL, BX
254;--------------------------------------------------------------------
255ALIGN JUMP_ALIGN
256WriteSstPage:
257 push cx
258 push dx
259
260 mov bx, [bp+FLASHVARS.wTimeoutCounter]
261 xchg si, di
262 cli
263
264.NextByte:
265 es lodsb ; Read byte from ES:SI
266 mov BYTE [5555h], 0AAh ; Byte program sequence.
267 mov BYTE [2AAAh], 55h
268 mov BYTE [5555h], 0A0h
269 mov [di], al ; Write byte to DS:DI
270
271 mov cx, bx
272.WaitLoop:
273 cmp [di], al ; Device won't return actual data until write complete.
274 loopne .WaitLoop ; Timeout ~215us, or ~10x 20us max program time from datasheet.
275 jne SHORT .WriteTimeout
276
277 inc di
278 dec dx
279 jnz SHORT .NextByte
280 SKIP1B al
281.WriteTimeout:
282 stc
283 sti
284 xchg si, di
285 pop dx
286 pop cx
287 ret
Note: See TracBrowser for help on using the repository browser.