Skip to main content
Topic: "Diolan Plus" bootloader. (Read 54942 times) previous topic - next topic

"Diolan Plus" bootloader.

Due to the number of requests I have seem about in various forums I am reworking the Diolan bootloader and the new version will be called Diolan Plus bootloader.

This port is based on Ian's port that removed the extended instructions and the encryption system. The encryption probably can be put back in but this is out of scope for my efforts.

Main changes that I hope all will work are:

Support for every PIC18 (non-J) USB PIC.

18F14K50
18F13K50
18F2450
18F2455
18F2458
18F2550
18F2553
18F4450
18F4455
18F4458
18F4550
18F4553

Support for both instruction mode options using the same code.

Refactored so that only two files ever need to be modified and these are prefixed with USER_ in the file name.
    - Separate out the bootloader entry code into a USER file so that the main USB stack is a module that requires not user alteration
    - Reworked the config words into a separate USER file.

Single linker file for all PIC and all options.

I have added "noob assist" (TM) that allows users to define their crystal speed and required CPU speed. There is documentation and error checking to ensure that they are applicable to the target PIC.

To port over to a new PIC I would expect it to take less than 5 minutes the first time through and less than one minute once you know that really in most cases only two values need to be entered and the correct PIC selected in MPLAB.

I have the guts of it working now and it is in the tidy up, additional testing and feature creep stage. Oh, I have to do something with the VID and PID settings. forgot about that until now.

Hope to post this on my web site soonish.

Edit: Also fixed a bug with a missing return instruction in the bootloader read code...

Re: "Diolan Plus" bootloader.

Reply #1
It should support the J pics easily too, I ported it to the 18F24J50. As I recall there are two issues. 1. You need to bank switch before a few of the USB registers are used since it is pure ASM. 2. J does not like to Sleep between USB interrupts, so I changed the sleep level to something else (don't remember, but it is documented well in my version of the code). I can upload it for your reference, or I think it is in the diolan folder of the DP SVN.
Got a question? Please ask in the forum for the fastest answers.

Re: "Diolan Plus" bootloader.

Reply #2
Hi Ian, yes I have no doubt that the firmware can support the J series and that may well be something for the future. If I add it now then there is so much more testing and documentation to do. I seem to remember that the J series are not consistent with each other in the non access SPRs too. Not sure if that applies to the USB SPRs or not. Will be a hell of a headache if it does. Already the 18F1xK50 require banked instructions for some of the SPRs but there are only two family members and they are the same as each other.

Anyway, I do not have any hardware with a j series pic to test with and my bread board still has the PIC2464GB002 mock-up on it.

The problem with supporting the J-series is that the config word is stored in code space and at this time I do not know how the host side software addresses this. I am pretty sure that Diolan never wrote the software to be aware of the config word issue but there may be a work around or some way to fudge a workable solution.

For stage two I will look further into this. At this time I am not doing anything that requires changes to the host side code but maybe there is someone here who can collaborate on that.

I will check the Diolan folder to see what you have done and see if that sheds some more light. If it is n ot there please upload it so I can have a look.

For now this is just meant to be a quick recreational project and a good tutorial on USB config word settings etc.

The thing that I am really please about is that it is now compatible with either the standard or extended instruction set and can handle the WDT being enabled. All working well.

Re: "Diolan Plus" bootloader.

Reply #3
Turns out that all the J series have the same USB SPRs in the banks they are in with the 14K50 so most of the hard work is already done. :)

Re: "Diolan Plus" bootloader.

Reply #4
I have no experience (never heard of) diolan bootloader so in few sentences - how it differs (why is it better then) to mchip hid bootloader? God side of the mchip hid bootloader is that there's a client for every os out there (I made the linux and osx version myself) and is proven to work good. Is diolan bootloader smaller? public domain? (I understand that it allows for encryption but that's completely unimportant feature for open source projects)

Re: "Diolan Plus" bootloader.

Reply #5
Diolan is USB HID and licensed GPL. The original update utility is far too complicated, but we have a couple different ones now that also work with it under every OS. The main reason we use it is because A) compiles to 800words (or whatever, bootloader area) without optimizations (it is ASM), and B) we can actually distribute the source ;)
Got a question? Please ask in the forum for the fastest answers.

Re: "Diolan Plus" bootloader.

Reply #6
I hate the "asm" part
I love the 800words - wait, that means that original linker script works, no need for custom linker script?! How big is mchip's I haven't used it for a while?
We can distribute source - YEAH

Do we have a link to the work you guy's did on that bl?

Re: "Diolan Plus" bootloader.

Reply #7
Yes, what Ian said. You will not say get the microchip HID bootloader in the boot block of some PIC18s. It is w-a-y to big. The Diolan bootloader missed the boat by using the extended instruction set. Ian fixed that part and now I have made it very simple to adapt to the other PIC18s. I have little doubt that slowly it will become the defacto goto bootloader for PIC18 USB PICs. It even fits nicely in the PIC18F13K50. Try doing that with the microchip HID bootloader.  :)

Attached is the zipped up PDF for the documentation.

Re: "Diolan Plus" bootloader.

Reply #8
I forgot about the extended instruction issues.

MCs will fit 800words, but you need full optimizations on (even the non-free ones).

Our ports (18F and 18FxxJ) are here:
http://code.google.com/p/dangerous-prot ... HID-Diolan
Got a question? Please ask in the forum for the fastest answers.


Re: "Diolan Plus" bootloader.

Reply #10
Quote from: ian
I forgot about the extended instruction issues.

MCs will fit 800words, but you need full optimizations on (even the non-free ones).
/
Quote

Me thinks you are confusing the microchip FS USB bootloader and the microchip HID bootloader. The FS USB bootloader can be squeeze into the boot block (0 - 0x7FF) but the microchip HID bootloader is substantially larger and and takes up the whole of Block 0 (0 - 0xFFF.)

A HID base bootloader is always going to require more space because they require extra code for the USB (HID class requests, HID descriptors etc.) The microchip HID bootloader is so large because there was never any chance that it was going to fit in the boot block (being written in C) so it made sense not to try to minimize the size as there was nothing to gain. It may as well be a full USB stack and not worry about using the extra code space up to the end of block 0 as that was not going to be available to the user app in any case (as the bootloader is going to be write protected.)

Freed from the constraints of having to be minimal, the microchip HID bootloader firmware was written to be universal. That is for the PIC18, PIC24 and PIC32. With all the extra code space it implements a bootloader descriptor system that holds all the various variables about the bootloader like the PIC family,  memory regions and size the bootloader space, size of the PIC, erase block size, write block size etc and passes them to the host.

This system means that anyone who writes a host side downloader for the PIC18 has in effect gone 95% of the way to also writing one compatible for the PIC24 and PIC32. The hard work (customization) is actually done inside the firmware and the host software is what becomes easily portable and not the firmware.

My personal opinion on this system is that it is great for the PIC24 and PIC32 but it is not so great for the PIC18 that is much more memory constrained. However I sort of think that microchip wanted the bootloader to be portable across families for marketing reasons. They have always pitched upward device "migration" as a strong point.

My reckoning is that a smaller HID based bootloader for the PIC18s is something that the world is missing. Now I think the work of Diolan -> Dangerous Prototypes -> JTR has provided it.

Re: "Diolan Plus" bootloader.

Reply #11
From the dangerous prototypes port (both 2550 and 24J50)

;-----------------------------------------------------------------------------
;      read_code
;-----------------------------------------------------------------------------
; DESCR :
; INPUT : boot_cmd
; OUTPUT: boot_rep
; NOTES : Assume TBLPTRU=0
;-----------------------------------------------------------------------------
read_code
   rcall   load_address_size8      ; TBLPTR=addr cntr=size8 & 0x3C
   lfsr   FSR0, boot_rep + CODE_OFFS   ; FSR0=&boot_rep.data

        ; while( cntr-- )
read_code_loop
   tblrd*+
   movff   TABLAT, POSTINC0
   decfsz   cntr
   bra   read_code_loop
   

;-----------------------------------------------------------------------------
;      write_code
;-----------------------------------------------------------------------------

Notice that the read code is missing a RETURN instruction and falls through to the write code...

Re: "Diolan Plus" bootloader.

Reply #12
You're probably right, I have not messed with Microchips bootloaders in years and probably got it all mixed up.

I'd have to look at our source and the original source to understand what is going on in read/write code. I thought it did the read loop until done (decfsz cntr) and then fell through to the next write loop for more data. I don't recall making any changes here, but that doesn't mean I didn't mess it up somehow :)
Got a question? Please ask in the forum for the fastest answers.

Re: "Diolan Plus" bootloader.

Reply #13
[quote author="ian"]You're probably right, I have not messed with Microchips bootloaders in years and probably got it all mixed up.

I'd have to look at our source and the original source to understand what is going on in read/write code. I thought it did the read loop until done (decfsz cntr) and then fell through to the next write loop for more data. I don't recall making any changes here, but that doesn't mean I didn't mess it up somehow :)[/quote]

Actually, you deleted the goto encrypt which of course would of had the return.

I have looked at the J series stuff and I see that your firmware sort of hard coded some stuff to work around the config word problem. I guess I could do that with all the J series but there are other issues. Like for example the 64k limit.

I cannot get the host side app to recompile and make the changes needed on the host side, I think I need the WDK installed or something.

It would be great to include all the J series but at this stage it seems out of reach unless I can recompile the host code. It is starting to look rather daunting.

Re: "Diolan Plus" bootloader.

Reply #14
I would forget the original diolan code and take a look at robot's multi-os version, way easier to compile app. Diolan's app was crazy hard to compile, and had WAY too much junk for such a simple app (not to mention the 5GB WDK download that failed on me 6 times...):
https://github.com/robots/ols-fwloader
Got a question? Please ask in the forum for the fastest answers.