Bus Pirate: Firmware upgrades on Linux, OSX

in Bus Pirate by Ian | 40 comments

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 0x00FF0000
Found PIC24FJ64GA002
Erase Flash:
Erasing 43 pages, starting at 0x00000000
Erase complete
Writing 256 bytes to address 0x00000000
Reading 256 bytes from address 0x00000000
Verification failed at 0x00000000: 0 != 4
Verification failed at 0x00000001: 4 != 12
Writing 256 bytes to address 0x00000080
Reading 256 bytes from address 0x00000080
Writing 256 bytes to address 0x00000100
<<< This continues for awhile
Reading 256 bytes from address 0x0000AA80
Writing 256 bytes to address 0x0000AB00
Reading 256 bytes from address 0x0000AB00
Writing 256 bytes to address 0x0000AB80
Reading 256 bytes from address 0x0000AB80
Verified Okay.
Verification complete, switching to user mode

C:\Python26>

Ignore any verify errors at the beginning (0x0, 0x1) and between 0x400 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]

This entry was posted in Bus Pirate and tagged , , .

Comments

  1. ninjabong says:

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

  2. Ian Lesnet says:

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

  3. Michal says:

    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 :-)

  4. Ian says:

    Thanks, I updated the link.

  5. mpare says:

    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

  6. Ian says:

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

  7. Jason says:

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


    Writing 256 bytes to address 0x0000A800
    Reading 256 bytes from address 0x0000A800
    Verification failed at 0x0000A8F8: 15 != 255
    Verification failed at 0x0000A8F9: 0 != 255
    Verification failed at 0x0000A8FA: 0 != 255
    Verification failed at 0x0000A8FC: 0 != 255
    Verification failed at 0x0000A8FD: 0 != 255
    Verification failed at 0x0000A8FE: 0 != 255
    Writing 256 bytes to address 0x0000A880
    Reading 256 bytes from address 0x0000A880

    Would this indicate a problem with my Bus Pirate v3?

    I’m using the python programmer scripts on Linux.

    Thanks,
    -Jason

  8. Ian says:

    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.

  9. Michal says:

    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.

  10. Ian says:

    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.

  11. Chris says:

    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?

    • Chris says:

      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)

  12. Ian says:

    @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.

    • Ian says:

      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!

  13. Stendall says:

    I have a BPv3:
    Firmware v2.4-Seeed
    DEVID:0x0447 REVID:0x3003 (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 0x00FF0000
    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

    • Ian says:

      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.

      • Stendall says:

        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

    • ptor says:

      Hi Stendall,

      Hopefully, you’ve long since solved your problem, but if not…I just went through upgrading my Seeed BPv3 from FW “v2.4-Seeed” to “Firmware v5.10 (r559) Bootloader v4.1″ . Maybe the details will be helpful for you.

      The key piece for me was manually setting the serial port speed to 115k. Before running the bootloader upgrader.

      regards,
      ptor

      Details:
      ————————————————————————————————————-
      Su 2011.03.13

      http://code.google.com/p/the-bus-pirate/downloads/detail?name=v2tov41-bootloader-update-va3.zip

      For my Debian system, the pySerial library is available as…

      geode:~# aptitude install python-serial

      geode:/home/ptor/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade/upgrader# python ./P24qp.py -s /dev/ttyUSB1 -a BPv3-v2blupdaterVa3-v4.1.hex -v

      This failed with something about Device=ffffff not recognized. What this really was about, was that the bootloader upgrader was opening the serial port at 9600 instead of 115200. Manually set the speed to 115k and check in the next two steps…

      geode:/home/ptor/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade/upgrader# stty -F /dev/ttyUSB1 115200

      geode:/home/ptor/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade/upgrader# stty -F /dev/ttyUSB1

      Now the upgrader will run…

      geode:/home/ptor/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade/upgrader# python ./P24qp.py -s /dev/ttyUSB1 -a BPv3-v2blupdaterVa3-v4.1.hex -v

      Connecting with minicom at 115k, and tell the upgrader code we want to upgrade the bootloader….

      Universal DS30 Loader installer v0.3 (C)hris 2010

      Released under Creative Commons null license.
      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 0x0000… done
      Writing row 0… done

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

      Now, back to Google Code for a newest firmware and then upgrade after resetting BP with an unplug and replug. Let’s be ambitious and go for the latest…

      In the latest code, there’s a ELF binary for doing the upgrade, pirate-loader_lnx . I had to set the executable bit for the tool…

      ptor@geode:~/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade$ chmod +x pirate-loader_lnx

      ptor@geode:~/projects/20100502 Bus Pirate protocol sniffer/firmware upgrade$ ./pirate-loader_lnx –dev=/dev/ttyUSB1 –hex=BPv3\&v2go/BPv3-Firmware-v5.10.hex

      Lastly, I used minicom at 115k to chat with the Bus Pirate again…

      HiZ>i
      Bus Pirate v3a
      Firmware v5.10 (r559) Bootloader v4.1
      DEVID:0x0447 REVID:0x3043 (24FJ64GA002 B5)
      http://dangerousprototypes.com

      So, success!

  14. Jimmie Lahti says:

    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.

  15. Tijs says:

    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 0x00FF0000
    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?

    • Ian says:

      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/

      • Tijs says:

        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)

      • Ian says:

        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.

      • Tijs says:

        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?

      • Tijs says:

        Thanx by the way ;)

      • Ian says:

        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. Tijs says:

    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)

    • Ian says:

      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.

      • Tijs says:

        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.

      • Ian says:

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

  17. John says:

    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 0x0000AB80
    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 0x0000… 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 0x00FF0000
    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

    • John says:

      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

  18. Dave says:

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

    • Ian says:

      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.

  19. Dave says:

    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

  20. Dave says:

    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

  21. Garrett says:

    Dave, your bus pirate can probably be re-programed with a microchip programmer (I think a different bus pirate can also be used to program a pic24F but I could be wrong)

    But to the point… so this reference is incorrect? Does it or doesn’t it work???

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.