First working DFU capable u-boot
Werner Almesberger
werner at openmoko.org
Sun Feb 25 04:51:02 CET 2007
Harald Welte wrote:
> JFYI: I've just committed (svn REv. 1107) the first 'mostly working but
> still lots of known bugs' version of the DFU capable u-boot.
Yipeee, thanks !!
Regarding bug #209:
To avoid race conditions, I'd propose the following scheme. Assumes that
- there are no other interrupts doing serious I/O during a DFU interrupt,
- DFU runs only from interrupts,
- if not ready, DFU can drop/ignore requests,
- foreground polls input frequenty,
- user input can polled, i.e., we don't need to call any "sleep until
data is ready" sort of function.
Shared:
extern volatile enum { DFU_NONE, DFU_REQ, DFU_ACK } dfu_req = DFU_NONE;
Foreground (menu, etc.):
int getchar(void)
{
while (!have_char_input()) { /* quick poll */
cli();
if (dfu_req != DFU_REQ)
sti();
else {
dfu_req = DFU_ACK;
sti();
while (dfu_req == DFU_ACK);
}
}
return obtain_char();
}
Background (DFU interrupt):
void dfu_interrupt(void)
{
...
if (enter_dfu_mode()) {
if (dfu_req == DFU_NORMAL)
dfu_req = DFU_REQ;
}
else {
/* already in DFU mode */
if (dfu_req != DFU_ACK)
drop_interrupt_and_packet();
else {
/* do work */
dfu_req = DFU_NORMAL; /* when done with DFU */
}
}
}
Special:
- the code above already handles attempts to enter DFU mode twice
(not sure if this can happen)
All this is rough pseudo-code. I think something like this would
avoid pretty much all possible races, without putting too heavy
requirements on instrumentation. (I.e., it's more like RCUs than
semaphores.)
- Werner
--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina werner at almesberger.net /
/_http://www.almesberger.net/____________________________________________/
More information about the openmoko-uboot
mailing list