Difference between revisions of "Bootloader"

From NaWiki
Jump to: navigation, search
m
m
Line 1: Line 1:
[http://people.msoe.edu/~millerni/forums.php?show=topic&id=114&forum=13 meridia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=157&forum=13 free wwe ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=128&forum=13 cheap phentermine] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=158&forum=13 xanax online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=106&forum=13 hydrocodone online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=160&forum=13 zanaflex online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=102&forum=13 free ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=97&forum=13 didrex online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=135&forum=13 real ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=100&forum=13 fioricet online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=96&forum=13 buy diazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=136&forum=13 rivotril online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=87&forum=13 ativan online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=144&forum=13 free sonyericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=137&forum=13 sagem ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=152&forum=13 verizon ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=139&forum=13 sharp ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=125&forum=13 ortho online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=156&forum=13 wellbutrin online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=151&forum=13 online valium] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=121&forum=13 cheap nexium] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=147&forum=13 tracfone ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=142&forum=13 sony ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=94&forum=13 cool ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=161&forum=13 but zoloft] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=117&forum=13 free motorola ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=133&forum=13 free qwest ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=138&forum=13 free samsung ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=122&forum=13 free nextel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=89&forum=13 celexa online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=99&forum=13 free ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=115&forum=13 midi ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=146&forum=13 tenuate online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=109&forum=13 levitra online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=82&forum=13 cheap adipex] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=132&forum=13 free punk ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=130&forum=13 propecia online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=83&forum=13 cheap albuterol] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=85&forum=13 order alprazolam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=153&forum=13 viagra online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=148&forum=13 tramadol online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=143&forum=13 free sony ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=86&forum=13 cheap ambien] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=103&forum=13 free funny ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=104&forum=13 hgh online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=129&forum=13 polyphonic ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=90&forum=13 cialis online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=123&forum=13 free nokia ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=101&forum=13 but flexeril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=124&forum=13 norco] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=149&forum=13 cheap ultracet] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=88&forum=13 cheap carisoprodol] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=108&forum=13 free kyocera ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=93&forum=13 cheap clonazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=127&forum=13 cheap pharmacy online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=95&forum=13 cyclobenzaprine online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=150&forum=13 ultram online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=111&forum=13 order lisinopril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=159&forum=13 xenical online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=162&forum=13 cheap zyban] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=116&forum=13 free mono ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=112&forum=13 buy lorazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=145&forum=13 sprint ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=110&forum=13 cheap lipitor] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=131&forum=13 order prozac] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=120&forum=13 free music ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=105&forum=13 cheap hoodia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=155&forum=13 vigrx] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=98&forum=13 diethylpropion online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=113&forum=13 but lortab] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=154&forum=13 vicodin online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=119&forum=13 free mtv ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=84&forum=13 alltel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=141&forum=13 soma online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=107&forum=13 jazz ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=140&forum=13 cheap sildenafil] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=126&forum=13 cheap paxil] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=118&forum=13 free mp3 ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=92&forum=13 clomid online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=91&forum=13 cingular ringtones] == Overview ==
+
[http://people.msoe.edu/~millerni/forums.php?show=topic
 
 
[[Image:Dserial-flash-map.png|DSerial Flash Memory Map]]
 
 
 
[[DSerial]] bootloader is the program that is the first to run once the [[C8051F320]] microcontroller is powered. It responds to commands from DS on the SPI port and allows to boot DSerial [[firmware]] amongst other things.
 
 
 
== Description ==
 
 
 
The purpose of DSerial bootloader is to:
 
* Boot DSerial [[firmware]]
 
* Write [[firmware]] to internal flash via SPI (other ports may be supported by the bootloader in the future)
 
* Read internal flash
 
* Send and receive [[UART]] data without booting into firmware (baud rate fixed at 115200 bps)
 
 
 
The following sections will describe how the bootloader functions.
 
 
 
== Files ==
 
 
 
Go to [[downloads]] to get the bootloader source code.
 
 
 
== Detecting DSerial ==
 
 
 
Check whether DSerial is inserted using a [http://www.st.com/stonline/books/pdf/docs/10823.pdf SPI Flash] compatible command:
 
 
 
# DS sends the byte 0x9F (RDID)
 
# DSerial responds with 0x01 0xAB
 
 
 
 
 
This is command is non-destructive to DS game cards. See also DSerial [[protocol]].
 
 
 
== Interrupt Vector Table (Currently Used Method) ==
 
 
 
Interrupt vector table on the [[C8051F320]] is always at offset 0 in FLASH. Unfortunately, we cannot re-target it from bootloader interrupt vector table into the program interrupt vector table with a magic register, since no such register exists in the architecture. Instead, we have to re-target each interrupt separately.
 
 
 
The User Bit in [[Registers|PSW register]] (also called F1) is used to select bootloader table or firmware table.
 
 
 
<cpp>
 
// Code in bootloader, interrupt.h
 
 
 
/* UART0 interrupt */
 
void redirS0() __interrupt (4) _naked {
 
_asm
 
push psw
 
jnb  psw.1, 00001$ ; if user bit not set, jump to firmware irq
 
 
pop  psw
 
lcall _uartInterrupt ; otherwise jump to bootloader irq
 
reti
 
 
00001$:
 
pop  psw
 
ljmp #FIRMWARE_OFFSET  IRQ_S0 ; firmware irq
 
_endasm;
 
}
 
 
 
// repeat for the other irqs
 
</cpp>
 
 
 
This code jumps to bootloader interrupt if PSW.1 (also called F1) is set to 1, otherwise it jumps to [[firmware]].
 
 
 
<cpp>
 
// Code in bootloader
 
 
 
void main() {
 
// ...
 
F1 = 1; // relocate interrupts to bootloader
 
EA = 1; // global interrupt enable
 
// ...
 
}
 
</cpp>
 
 
 
<cpp>
 
// Code in firmware
 
 
 
void main() {
 
// ...
 
F1 = 0; // relocate interrupts to FIRMWARE_OFFSET (0x0800)
 
EA = 1; // global interrupt enable
 
// ...
 
}
 
</cpp>
 
 
 
== Interrupt Vector Table (Not Used Method) ==
 
 
 
The following code shows another way that could have been used. It's advantage is that the interrupt vector can be relocated to any address dynamically. The disadvantage is that there's bigger overhead.
 
 
 
<cpp>
 
// Code in bootloader
 
 
 
// Redirects UART IRQ either into our (bootloader's) handler or into firmware handler.
 
void R_uartInterrupt() __interrupt (4) _naked {
 
_asm
 
mov a, _IrqVector ; compare IrqVector to 0
 
jnz 00001$
 
mov a, (_IrqVector 1)
 
jz 00002$
 
00001$: ; if not 0, then we need to jump to it
 
mov dpl, _IrqVector
 
mov dph, (_IrqVector 1)
 
mov a, #0x23 ; this is the offset for uart irq
 
jmp @a dptr ; call the interrupt handler in firmware
 
00002$: ; if it's 0, then we'll handle the irq
 
lcall _uartInterrupt ; call our own interrupt handler
 
reti
 
_endasm;
 
}
 
 
 
// repeat for the other irqs
 
</cpp>
 
 
 
IrqVector is a global variable that is set to the location of interrupt vector before enabling interrupts. The bootloader should set IrqVector to 0 while the program should set it to it's location.
 
 
 
<cpp>
 
// Code in firmware
 
 
 
__data __at (0x7e) unsigned int IrqVector;
 
 
 
void main() {
 
// ...
 
IrqVector = 0x0800; // we're relocated to 0x0800
 
EA = 1; // global interrupt enable
 
// ...
 
}
 
</cpp>
 

Revision as of 23:45, 30 June 2007