Bus Pirate: Firmware upgrades on Linux, OSX

p24qp-tux.ii

STOP!!! You probably need the v2 to v4 upgrade guide instead!!!

See the latest version in the documentation wiki.

Bus Pirate firmware updates can be done from Linux or OSX using the Python PIC24F programmer developed by broeggle and JoseJX. The programmer works on all operating systems that support Python and pySerial: Linux, OSX, and Windows, too. Thanks for a great script!

Our step-by-step guide to the Python PIC24F programmer continues after the break.

Here’s some key stuff to get:

  1. The programmer works with Python 2.x, not 3.x.
  2. Get the pySerial module to give Python serial port access.
  3. Download the latest Python PIC24F programmer script. Future firmware releases (>2.0) will include the Python programmer script.
  4. Download the latest firmware. Copy the P24qp.ini configuration file and firmware .HEX to the same directory as the programmer script.
  5. Get a 0.1″ jumper to place between the PGC and PGD pins, as described in the Windows quick programmer tutorial.

Install Python 2.x and the pySerial module. Download the firmware and programmer, move the required files into a convenient directory.

jumper

Disconnect the Bus Pirate from the USB cable (and power supply if applicable). Place a jumper between the PGC and PGD pins (A), as described in the Windows quick programmer tutorial. Plug the Bus Pirate back in.

C:\>cd python26

C:\Python26>python P24qp.py
Bus Pirate Programmer v1.0

P24qp <command>
-a –auto=FILE          – Erase, Program and Quit the Bootloader
-c –config=FILE        – P24qp compatible configuration file
(Default: ./P24qp.ini)
-e –erase              – Erase the flash programming
-f –finalize   – Finalize the programming and go to user mode
-i –info               – Information about the bootloader
-q –quiet              – Quiet messages about writing progress
-r –read=FILE          – Read programming from flash
-s –serial=DEVICE      – Override serial device path
-t –reset              – Reset the bootloader
-v                      – Enable verification of write commands
-w –write=FILE – Write programming file to flash

C:\Python26>

Run the programmer from the command prompt for a short description of the flags and options.

JoseJX recommends auto mode with verify, using the command:

P24qp.py -a <hexfile> -s <serial port> -v

Substitute <hexfile> with the name of the firmware .HEX file, something like v25-Firmware-v2.hex for the Bus Pirate v2go. Replace <serial port> with the device name you system assigned to the Bus Pirate’s FTDI USB->serial converter chip.

  • Linux: /dev/ttyUSBx (/dev/ttyUSB0) or /dev/ttySx (/dev/ttyS1)
  • OSX(?): /dev/cu.KeySerialx (/dev/cu.KeySerial1)
  • Windows: COMx (COM3)

The serial port name can be tricky, hopefully these examples help. Replace ‘x’ with the number for your system. Look in the system dmesg to find the Bus Pirate on Linux, or in the control panel on Windows.

C:\Python26>python P24qp.py -a v25-Firmware-v2.hex -s COM5 -v
Using Serial Port COM5 @ 115200
Reading 4 bytes from address 0×00FF0000
Found PIC24FJ64GA002
Erase Flash:
Erasing 43 pages, starting at 0×00000000
Erase complete
Writing 256 bytes to address 0×00000000
Reading 256 bytes from address 0×00000000
Verification failed at 0×00000000: 0 != 4
Verification failed at 0×00000001: 4 != 12
Writing 256 bytes to address 0×00000080
Reading 256 bytes from address 0×00000080
Writing 256 bytes to address 0×00000100
<<< This continues for awhile
Reading 256 bytes from address 0×0000AA80
Writing 256 bytes to address 0×0000AB00
Reading 256 bytes from address 0×0000AB00
Writing 256 bytes to address 0×0000AB80
Reading 256 bytes from address 0×0000AB80
Verified Okay.
Verification complete, switching to user mode

C:\Python26>

Ignore any verify errors at the beginning (0×0, 0×1) and between 0×400 and 0xbff, these are bootloader protected locations. A really nice thing about the Python programmer is that it knows to ignore errors in the protected bootloader section.

[Tux image]

Tags: , ,

  1. One step missing… where you tie PGC & PGD together, otherwise worked fine for OS X!

    Reply

  2. Glad it worked. We added the missing step and illustration, thanks so much for pointing out the omission.

    Reply

  3. P24qp.py is at http://the-bus-pirate.googlecode.com/svn/trunk/firmware/v2-nightly/P24qp.py instead of the the URL mentioned above. Other than that it worked. I’m now on fw 2.3-nightly :-)

    Reply

  4. Thanks, I updated the link.

    Reply

  5. To find serial devices on OS X I have always just done a quick

    • ls /dev/tty.*

    or

    • ls /dev/cu.*

    Too bad I missed the preorder… Order page is saying 8-9 weeks now. I wonder from what date that particular estimate was valid.

    -Matt

    Reply

  6. @mpare – Thanks for the tip. Seeed already ordered the chips, so it should only be 7 or so weeks from today.

    Reply

  7. Thanks for the guide; unfortunately, I keep getting verification errors outside of the protected areas. E.g.


    Writing 256 bytes to address 0×0000A800
    Reading 256 bytes from address 0×0000A800
    Verification failed at 0×0000A8F8: 15 != 255
    Verification failed at 0×0000A8F9: 0 != 255
    Verification failed at 0×0000A8FA: 0 != 255
    Verification failed at 0×0000A8FC: 0 != 255
    Verification failed at 0×0000A8FD: 0 != 255
    Verification failed at 0×0000A8FE: 0 != 255
    Writing 256 bytes to address 0×0000A880
    Reading 256 bytes from address 0×0000A880

    Would this indicate a problem with my Bus Pirate v3?

    I’m using the python programmer scripts on Linux.

    Thanks,
    -Jason

    Reply

  8. Hi Jason,

    Does the Bus Pirate work when you try to use it? I don’t use the Python updater often, but I recall someone saying that the errors were OK, or that you had to flash it twice sometimes.

    It could indicate an error, but please try Microchip’s ‘official’ Windows updater if possible.

    Reply

  9. I often use the the python updater and always get some errors outside the protected range. However the BP seems to run all right so I ignore them. Jason – if BP runs after flashing don’t worry about the errors.

    Reply

  10. I wonder what the difference is in error reporting between the versions? I’m guessing that the python version is more verbose and isn’t ignoring one errors that Microchip’s updater doesn’t report. There could also be a minor error in the Python updater, but as you noted nobody has ever has ‘problems’*.

    *For some values of problem.

    Reply

  11. I do have exactly the same error as Jason, but I’m using the microchip windows client. All the extra errors appears after 0xA800 (like jason). It looks like the pages are writeprotected like the bootloader (i.e. cannot erased, but written once??) Unlike what is suggested the errors are serious (weird text and such) and should never be ignored in my opinion!! flashing/clearing multiple times didn’t help and the error remains the same.

    I got an BP from the preorder 2 from seeedstudio. More people with the same problem?

    Reply

    1. I found it already:

      the option to preserve the fuses prevent the memory area (a800 and up) to be erased and thus written properly (the verify errors). disabling this option solves this. All the compiles I’ve done so far (as described in the how-to-compile wiki entry) include the fuses so it should be ok (stress on should ;)) I just tested it and it did work (no indept testing so far)

      Reply

  12. @Chris – thanks for the confirmation, we’ve been discussing this in the forum. Did you load one of the translations? They’re the only version that should reach past 0xa800. I try to verify each before release.

    I’ll do some testing with erasing the configuration bits, I worry that a chip without config bits won’t have the wherewithal to get loaded again. How is the chip supposed to know what clock source to use with the bootloader if the config bits are erased? There may be some mechanism to address this, but I’d like to know for sure before recommending that everyone do it.

    Reply

    1. I’ve done some testing, and PLEASE NOTE: if you uncheck ‘preserve flash configuration words on erase’, and fail to complete the upgrade, the bootloader will not connect again!

      Reply

  13. I have a BPv3:
    Firmware v2.4-Seeed
    DEVID:0×0447 REVID:0×3003 (A3)

    I can use it without a problem, but there is no way to update bootloader or anything.
    I’ve used P24qp of v2tov41-bootloader-update-va3 package with all versions of python that are avalaible on Debian (2.1, 2.2, 2.3, 2.4, 2.5), and always got this:

    Using Serial Port /dev/ttyUSB1 @ 9600
    Reading 4 bytes from address 0×00FF0000
    RX Error: 0 bytes received
    Error reading from device!
    Device with ID: 65535 not listed in the config file!

    The port is there, the user have access, I can conect to de BP with any terminal, but looks like the pyton updater even doesn’t see the port.

    ¿Any clue.?
    Thanks

    Reply

    1. Hi Stendal,

      Did you place a jumper between the PGC and PGD pins? Does the MODE LED light when you plug in the Bus Pirate with the jumper attached?

      What command did you use to upload the bootloader update?

      There’s also more help in the forum.

      Reply

      1. Yup, jumper atached and the BP lights up pwr and mode leds.
        python P24qp.py -a BPv3-v2blupdaterVa3-v4.1.hex -s /dev/ttyUSB0
        Thx for help

  14. The link to the python installer seems to have changed to http://dev.gentoo.org/~josejx/bus_pirate/

    But i can’t find any configuration file for it. I am trying to get the AVR STK500 installer to Bus Pirate v3 Firmware v3.0.

    Reply

    1. The latest python installer should be included in the firmware archive download. If you’re using v3.0 (and bootloader v2) be sure to use the STK500 firmware for the v2 bootloader. You can also upgrade to the new v4 bootloader:
      http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/

      Reply

  15. I had a version 2.4, BL 1.2 (Im running linux)

    Tried upgrading the bootloader first:
    python P24qp.py -a BPv3-v2blupdaterVa3-v4.1.hex -s /dev/ttyUSB0

    That worked fine, except for the verification errors mentioned above.
    But ‘P24qp.py -i’ now says:
    Using Serial Port /dev/ttyUSB0 @ 9600
    Reading 4 bytes from address 0×00FF0000
    Found PIC24FJ64GA002
    Reading Bootloader Version Information:
    Bootloader Version: 1.2

    Tried upgrading the firmware, but that kind of bricked it. I can still do P24qp -i, so my guess is that the bootloader still works.

    What now?

    Reply

    1. The upgrade requires that you connect to the Bus Pirate with a terminal and confirm the upgrade. After that, you use the new ds30Loader or Pirate loader updater to load a v4 firmware. Please check out the v4 bootloader upgrade instructions:
      http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/

      Reply

      1. I did not open the terminal indeed… and so missed a crucial step. So that explains that the bootloader was still 1.2.
        I now tried to upload the upgrade BPv3-v2blupdaterVa3-v4.1.hex firmware again but that only gives as many verification errors as there are bytes in the file.. So my guess is the BP is dead now? (Wrong config word?)

        No terminal either. But i can still use P24qp to ‘info’ the bootloader: v1.2

        Is there still a procedure i can use to fix the BP or do i need a 3.3v programmer? (Only got a 5v programmer)

      2. I’m not really sure, the updater contains the config bits and you should be able to bootload it as much as you want without problem. Did you try to upload the actual v4 firmware with the .py uploader as well? That will do it every time :(

        I’m not sure about the programmer. SparkFun shipped a bunch with 5volt regulators instead of 3v3 regulators, and they worked fine (for a while…). You might be able to get away with programming the PIC at 5volts if the programmer supports the 24fj64ga002.

      3. Yes i did try to upload the v4 firmware. (Because i thought the bootloader upgrade worked)
        After that i was able to connect to the BP once and it said “Firmware version 4.1, bootloader 255.255″ Next powerup it was gone.

        I think the v4 fw try screwed the config word indeed and it now runs with the wrong clock in mind. Ill try to flash it with the 5v programmer…

        Does the v4 firmware contain everything? config+firmware+bootloader? I mean if i get that hex in, is the procedure then completed? Or should i just try to set the config word only and then install the bootloader again? (since 1.2 is obviously still in there..)
        And what is the config word then?

      4. Thanx by the way ;)

      5. No problem, sorry about the confusion. The bootloader and firmware are separate. Program the bootloader .hex with the programmer, then connect with the bootloader and load the firmware.

  16. So the bootloader hex (BPv3-v2blupdaterVa3-v4.1.hex) does contain the config word? (I dont want to keep programming the pic with 5v… So hoping that once will be enough)

    Reply

    1. the updater does, but you shouldn’t use that, it installs the new bootloader using the old one. Download the latest firmware archive and use the bootloader.hex from there.

      Reply

      1. I downloaded the laters (4.2) bootloader hex into the BP with a pic programmer, used the bootloader to install the firmware. Everything is working fine again! (needed a programmer though, so for anybody else: DO NOT USE P24qp.py TO PROGRAM v4 firm, NEVER. Only the bootloader-upgrader. As stated above..)

        Thanx Ian.

      2. No problem, I glad you got it working. Thanks for the update.

  17. Well, I got impatient and it looks like I bricked my brand new BP within 20 minutes of unsealing it.
    I did the first part of the bootloader upgrade:
    python ./P24qp.py -a BPv3-v2blupdaterVa3-v4.1.hex -s /dev/ttyUSB0 -v
    …..
    Reading 256 bytes from address 0×0000AB80
    Write operation complete.
    Verified Okay.
    Verification complete, switching to user mode

    Then rebooted it with minicom attached and typed “yes” when it asked me if I was sure I wanted to overwrite the bootloader:
    Found bootloader v unknown (probably v2)
    Will install bootloader v4.1

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

    yes

    Erasing 0xA400… done
    Erasing 0xA800… done
    Writing row 0 1 2 3 4 5 6 7 done
    Erasing 0×0000… done
    Writing row 0… done

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

    This is where I screwed up.
    I tried to upload a second .hex file:
    johng@bugsy:~/tmp/upgrader$ python ./P24qp.py -a ../v4firmware/BPv3-Firmware-v4.1.hex -s /dev/ttyUSB0 -v
    Using Serial Port /dev/ttyUSB0 @ 9600
    Reading 4 bytes from address 0×00FF0000
    RX Error: 0 bytes received
    Error reading from device!
    Device with ID: 65535 not listed in the config file!

    and now I’ve got nothing. even P24qp.py -i -s /dev/ttyUSB0 returns nothing but an error. I get nothing at the serial prompt, either.
    I don’t own a PIC programmer (yet).

    Where do I go from here?
    John

    Reply

    1. I panicked too soon. I continued to follow the instructions (derp) and ran this next (with the jumper in place):
      ./pirate-loader_lnx –dev=/dev/ttyUSB0 –hex=BPv3\&v2go/BPv3-Firmware-v5.0.hex

      and lo and behold, success. Sorry I got jumpy, thanks to the devs for making this more idiot-proof than I anticipated.

      John

      Reply

  18. what should I do if I accidentaly used version 5.7 with bootloader version 2??

    Reply

    1. Hi Dave – sorry about the upgrade problems. I added a big link to the top of this post to the upgrade procedure.

      Please contact me through the contact form, I’d be happy to reflash your Bus Pirate, or put you in touch with someone who can.

      Reply

  19. IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    ***STOP*** DO NOT UPLOAD A V4 FIRMWARE TO A V2 BOOTLOADER WITH P24QP.PY!!! The Python utility erases the entire chip, including the ‘configuration words’ that determine how the pic behaves on start-up. The v4 firmware does not contain replacement configuration words, so the Bus Pirate won’t start from the correct clock after programming a v4 firmware to a v2 bootloader with p24qp.py. Only Upload v2 firmware or BPv3-v2blupdaterVa3-v4.1.hex with P24QP.PY.

    I LOST MY BUS PIRATE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

    Reply

  20. BE CAREFUL WITH STEP 3!!!!!!!!!!!!!

    Download the latest Python PIC24F programmer script. Future firmware releases (>2.0) will include the Python programmer script.

    IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    ***STOP*** DO NOT UPLOAD A V4 FIRMWARE TO A V2 BOOTLOADER WITH P24QP.PY!!! The Python utility erases the entire chip, including the ‘configuration words’ that determine how the pic behaves on start-up. The v4 firmware does not contain replacement configuration words, so the Bus Pirate won’t start from the correct clock after programming a v4 firmware to a v2 bootloader with p24qp.py. Only Upload v2 firmware or BPv3-v2blupdaterVa3-v4.1.hex with P24QP.PY.

    I LOST MY BUS PIRATE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

    Reply