Difference between revisions of "Bootloader"

From NaWiki
Jump to: navigation, search
m
(removed spam)
Line 1: Line 1:
[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=72 ambien online] [http://students.hsc.unt.edu/housing/item.cfm?type=2862 buy vicodin] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30258 vicodin online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=182 funny ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2890 online zanaflex] [http://wc1.worldcrossing.com/WebX/.1de609dc albuterol online] [http://wc1.worldcrossing.com/WebX/.1de60a20 nexium online] [http://students.hsc.unt.edu/housing/item.cfm?type=2875 propecia online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=165 ambien] [http://wc1.worldcrossing.com/WebX/.1de609f8 nokia ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=350 online alprazolam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 cheap viagra] [http://students.hsc.unt.edu/housing/item.cfm?type=2874 cheap ultracet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=91 hoodia online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=175 cheap cyclobenzaprine] [http://news.engin.brown.edu/forums/thread-view.asp?tid=201 free free ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=153 phentermine online] [http://students.hsc.unt.edu/housing/item.cfm?type=2848 cheap soma] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30337 real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=94 free jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0a vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2896 zyban online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=178 free ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a01 free sagem ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1346 cheap diazepam] [http://news.engin.brown.edu/forums/thread-view.asp?tid=222 free sharp ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1d free cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 but adipex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=138 free verizon ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fe free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e4 cheap clonazepam] [http://wc1.worldcrossing.com/WebX/.1de60a31 buy zanaflex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=106 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1a free mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a15 free kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=218 sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=132 cheap tenuate] [http://students.hsc.unt.edu/housing/item.cfm?type=2904 free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=137 cheap valium] [http://news.engin.brown.edu/forums/thread-view.asp?tid=168 cheap paxil] [http://library.cshl.edu/wp/vb/member.php?u=1367 didrex online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30295 sildenafil online] [http://wc1.worldcrossing.com/WebX/.1de609f7 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f3 free midi ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1348 ativan online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=337 xanax online] [http://wc1.worldcrossing.com/WebX/.1de609e6 buy cyclobenzaprine] [http://library.cshl.edu/wp/vb/member.php?u=1360 lorazepam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 free alltel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=176 didrex online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=204 free mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2911 cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a07 tracfone ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30241 buy xanax] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=356 free tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=111 norco online] [http://wc1.worldcrossing.com/WebX/.1de60a13 fioricet online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 lorazepam online] [http://library.cshl.edu/wp/vb/member.php?u=1369 free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2858 cheap viagra] [http://news.engin.brown.edu/forums/thread-view.asp?tid=224 wwe ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2852 xanax online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30307 zoloft online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30331 free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a27 sildenafil] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=145 xenical online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30339 samsung ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30294 cheap prozac] [http://news.engin.brown.edu/forums/thread-view.asp?tid=176 ultracet online] [http://library.cshl.edu/wp/vb/member.php?u=1352 buy norco] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=189 but lipitor] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=362 free motorola ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=224 free sagem ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=101 meridia online] [http://wc1.worldcrossing.com/WebX/.1de609ee cheap hydrocodone] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30244 cheap diazepam] [http://wc1.worldcrossing.com/WebX/.1de609e0 cheap ativan] [http://students.hsc.unt.edu/housing/item.cfm?type=2861 cheap norco] [http://students.hsc.unt.edu/housing/item.cfm?type=2877 cheap prozac] [http://news.engin.brown.edu/forums/thread-view.asp?tid=216 sonyericsson ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=360 free qwest ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=190 cheap lisinopril] [http://wc1.worldcrossing.com/WebX/.1de60a10 didrex online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=228 ultram online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 online cialis] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30259 alprazolam online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=359 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e5 free cool ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2888 cheap lortab] [http://library.cshl.edu/wp/vb/member.php?u=1373 free nextel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=216 zyban online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=206 cheap pharmacy online] [http://library.cshl.edu/wp/vb/member.php?u=1344 xanax online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=344 ativan] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 sprint ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30248 ativan online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=131 sprint ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2871 wellbutrin online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=146 buy zanaflex] [http://news.engin.brown.edu/forums/thread-view.asp?tid=154 buy carisoprodol] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30280 cheap propecia] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=118 buy prozac] [http://library.cshl.edu/wp/vb/member.php?u=1341 valium online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=144 xanax online] [http://students.hsc.unt.edu/housing/item.cfm?type=2905 free motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=112 but ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=223 wellbutrin online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=169 cheap levitra] [http://news.engin.brown.edu/forums/thread-view.asp?tid=156 fioricet online] [http://library.cshl.edu/wp/vb/member.php?u=1377 free samsung ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30312 ortho online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30356 free cool ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f0 lorazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=187 celexa online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 tramadol online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=214 zanaflex online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=110 free nokia ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=189 ortho online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=237 samsung ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=151 cheap soma] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=99 cheap lorazepam] [http://students.hsc.unt.edu/housing/item.cfm?type=2912 free sagem ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2907 free sprint ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a17 buy lipitor] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30334 mp3 ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=234 sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=141 buy vigrx] [http://wc1.worldcrossing.com/WebX/.1de60a23 free polyphonic ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1f cheap lisinopril] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=197 free mp3 ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1349 cheap viagra] [http://library.cshl.edu/wp/vb/member.php?u=1382 free cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 cheap tenuate] [http://students.hsc.unt.edu/housing/item.cfm?type=2922 kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=206 qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f9 norco online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=351 clonazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2878 cheap sildenafil] [http://students.hsc.unt.edu/housing/item.cfm?type=2902 free nextel ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=357 funny ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1347 but cialis] [http://library.cshl.edu/wp/vb/member.php?u=1365 ultracet online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=210 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=158 diazepam online] [http://wc1.worldcrossing.com/WebX/.1de609ea free free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a25 samsung ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free free ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1358 hydrocodone online] [http://library.cshl.edu/wp/vb/member.php?u=1339 tramadol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://news.engin.brown.edu/forums/thread-view.asp?tid=228 free mtv ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=104 motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=89 free funny ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=211 free music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=80 cool ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1388 fioricet online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=361 real ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=172 lorazepam] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=333 cheap soma] [http://news.engin.brown.edu/forums/thread-view.asp?tid=182 clomid online] [http://library.cshl.edu/wp/vb/member.php?u=1355 clonazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 paxil online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=184 cheap lisinopril] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 free samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a04 free sonyericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 cheap phentermine] [http://library.cshl.edu/wp/vb/member.php?u=1387 free alltel ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a05 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=167 clonazepam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30283 buy didrex] [http://news.engin.brown.edu/forums/thread-view.asp?tid=157 cheap ultram] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=230 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30309 celexa online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=348 cheap norco] [http://wc1.worldcrossing.com/WebX/.1de60a11 diethylpropion online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=188 tenuate online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=212 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 lipitor online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=82 buy diazepam] [http://library.cshl.edu/wp/vb/member.php?u=1380 free verizon ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=163 cheap adipex] [http://students.hsc.unt.edu/housing/item.cfm?type=2859 meridia online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=209 samsung ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 cingular ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=78 clomid online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 lisinopril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=74 cheap carisoprodol] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=352 paxil online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=227 ericsson ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1386 mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=69 albuterol online] [http://wc1.worldcrossing.com/WebX/.1de60a12 ericsson ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=171 ambien online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=83 didrex online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30358 free midi ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2879 cheap clomid] [http://news.engin.brown.edu/forums/thread-view.asp?tid=186 lipitor online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=215 free sagem ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=201 free free ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=153 phentermine online] [http://students.hsc.unt.edu/housing/item.cfm?type=2848 soma online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read
+
== Overview ==
 +
 
 +
[[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 04:51, 23 July 2007

Overview

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 SPI Flash compatible command:

  1. DS sends the byte 0x9F (RDID)
  2. 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 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>