Skip to main content
Topic: Bootloader v4 (ds30 Loader) (Read 57253 times) previous topic - next topic

Re: Bootloader v4 (ds30 Loader)

Reply #165
I think the last steps could be even easier:

Code: [Select]
 btsc WFWJUMP,#0x00   ; skip next if bit0 is 0 (=not jumped from bp)
 btss  PORTB,#RB1         ; skip next if RB1 is 1
 bra setup

Not that there isn't any room left :P

Re: Bootloader v4 (ds30 Loader)

Reply #166
Good call. I sat and stared and thought there had to be an easier way, but I'm not that ASM savvy yet :)
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #167
hehe, did you try it and did it work? (it was all from the top of my head ;) was a terrible day at work :D)

Re: Bootloader v4 (ds30 Loader)

Reply #168
The v4.3 branch is totally untested. I'll try it, and the v4 to v4 updater, hopefully tomorrow. A couple PCBs came in (Bus Pirate PIC programming adapter and logic analyzer) and I've been busy soldering and writing firmware for them.
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #169
OK, no need to hurry ;) It's afterall friday ;)

Will those be commercial (or through seeed) available?

Re: Bootloader v4 (ds30 Loader)

Reply #170
Yeah, they're all future projects. I tested the high-voltage programming adapter yesterday and it works as expected. If anyone wants to help with the PIC programming port (PC or micro side) I'd be happy to send a PCB and/or (partial) kit (with the parts I have).
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #171
I did check in a new version of the BL installer.

changes:
- universal binary (should work with old and new BL)
- displays current and packaged bootloader version
- changed the text and comments a bit (serial comma joke deleted)
- debug mode (if still needed) is controlled by the release/debug setting in the IDE
- modeled is more consistant for error checking (led is of, and blinks after the upgrade)

screenshot of debug build:

Code: [Select]
Universal DS30 Loader installer v0.3 (C)hris 2010

Released under Creative Commons null license.
RUNNING IN DEBUG MODE!!!!
Found bootloader v4.1
Will install bootloader v4.1

Type 'Yes' to program the new bootloader.
Disconnect power if unsure (no harm done).

yes

Erasing 0x8C00... done
Erasing 0x9000... done
Writing row 0 1 2 3 4 5 6 7 done

Success!
Upload new firmware with the ds30 Loader app to complete the upgrade.

Re: Bootloader v4 (ds30 Loader)

Reply #172
Great work.

I like the auto identification of the version. Will it work for v2? Maybe check if oxffff and say 'probably v2'.

With the v2 bootloader the user reset vector is located at 0xc04, it was declared in the v3 firmware as:
Code: [Select]
unsigned int userReset  __attribute__ ((space(prog),section(".init"))) = 0xC04 ;
unsigned char timeout  __attribute__ ((space(prog),section(".init"))) = 0x00 ;
This isn't in the universal updater, but isn't in the v2 to v4 updater either. I know that P24QP.exe relocated the 0x0000 jump instruction to the user location, and I think that's hard coded as 0xc04 in the v2 bootloader and P24QP.ini config file. I think this might be a minor bug in the v2 to v4 bootloader, but I'm unsure of the impact.
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #173
I don't have a v2 anymore :P but I gues it is 0xFFFF at that location. So the version would something like 255.255. I can add a new check no problem. If it is 0xFFFF  I'll make the message 'pre-4'

Where was that declared? I think the p24Qp program does simular things as the new ds30loader (regarding the startup of the payload and modifying memory locations)'

[s:]edit: isn't that to reset the app without starting the bootloader?[/s:]

Edit2: I found it in the source, by looking at it and compiling/examining the old v3.6. I would say it is for the bootloader to know what the timeout is and where to jump when the bootloader is finished. (see also page 2 from http://ww1.microchip.com/downloads/en/A ... 01157a.pdf ) Strange the old updater did work correctly.. I also see (in the linkerscript) some mentioning about storing it in a location at 0x0100. Very confusing :S

I do see some things in the linkscript but they don't write the correct value there, I assume the program did write them in flash to be safe. I'll [s:]adapt the linkerscript and[/s:] add the relevant things to main.c

Re: Bootloader v4 (ds30 Loader)

Reply #174
Added the changes to svn.

Although I don't think it is necessary to reserve 2 programwords as I think the old bootloader stores it elsewhere. But better safe then sorry! 

Re: Bootloader v4 (ds30 Loader)

Reply #175
Here's the words from a dump of a complete v3.2 firmware+bootloader that I sent Seeed:

:100C000004E8B7000040EB0005E8B7001E40900084

I'll look a bit closer and compare to a dump of the loaded updater later to see what's going on.

As you noted, the delay is at c00 (not used, I stripped that code from v2 bootloader) and the jump instruction location is at 0xc04. Like ds30 Loader, the old app read the jump location at 0x0000 and moved it to c04 when flashing. When the updater is loaded, p24qp must write the jump location to 0xc04(?) It seems like that would mess up the updater? I'll do a dump for us to look at to be sure.

We probably don't need to include the variables. Can we just increment the start location in the linker by two words?

Complete dump from a chip with v2 bootloader v3.2 firmware is attached to this post.
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #176
Sorry, here's the good dump. This is 0xc00 from the bootloader updater before bootloading:
:101800000F802000007F22000001880000000000FF

Here's the line after I bootloaded it then dumped the chip:
:10180000000C0000FFFFFF00000188000000000046

if you look at p24qp.ini, the last lines tell it where to relocate the values:
userresetvector="C00"
bootdelay="C02"

So the p24qp programmer IS overwriting the first two instructions of the updater. The reset instruction and an instruction that loads a value into W. They are both interpreted as NOP, so it walks it's way to the correct code although without reset, and without the correct value (0x27f0) in W0 before mov.w'ing it 0x0020.

Attached are two screenshots of the dissassembly. Also, a .zip with the original upgrader hex and the dump after bootloading it onto the chip.

I'm going to test the 'universal' bootloader upgrader now and release an update to the upgrade package. I'm not sure the impact of this bug, but it's clearly overwriting two instructions.
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #177
Ok, I made some changes to the universal updater (v4 to v4). It needs to have the config words for a v2 upgrade in case the user is using the p24qp.py upgrade script that erases the whole chip and requires the config words.

It seems to work well. Attached is a screenshot of the universal updater (now determines current BL version), a screenshot of the disassembly of a chip dump (looks good) and a .zip with an exported chip dump.

I uploaded the new upgrader to firmware/v2tov4upgrader/, after some testing I'll release a new upgrade package.
Got a question? Please ask in the forum for the fastest answers.

Re: Bootloader v4 (ds30 Loader)

Reply #178
Good work. ( shouldn't the files in the upgraderv2tov4 also be updated? or are we moving towards an universl binary?)

My analyse of the impact:

The move #0x800, W15 is to setup the stack pointer (which is probably also done by the bootloader) The program doesn't use the stack very much, so it isn't a very big problem (still a problem though). the other one is setting 0x27f0 to the stackpointer limit register which shouldn't be much of a problem either when not using the stack very much. But glad we slashed this bug also :P

To bad the fuses are need to be set, since the new bootloader won't program the .hex if you try to alter 'safe' locations (or is there a setting in defaultsettings.xml that adresses this ?)

Off topic: that programmer does it fit on top of the bp or do you need to have a cable for it? I like it (more) when it is stackable, just a thought

Re: Bootloader v4 (ds30 Loader)

Reply #179
I just used the new one for the universal binary.

It would be nice to have a setting in ds30 Loader to ignore the bootloader region, like the old programmer.

The programmer board could stack, it uses the same pin connection. Just put a female header on the bottom instead of a male header on the top. It would go out from the front though, instead of back over the Bus Pirate PCB. It would have been a good idea to make it stackable, but I didn't think about it. I didn't do a great job designing these PCBs at all, they'll need a second revision.
Got a question? Please ask in the forum for the fastest answers.