Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootloader: Cleanup code, reduce duplication #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kallisti5
Copy link

  • Take latest pirate-loader since it should work
    for BPv3 and BPv4. (to test)
  • Old BPv3 stuff saved for now in old directory

@kallisti5
Copy link
Author

kallisti5 commented Sep 25, 2017

$ find Bootloaders/ -maxdepth 3
Bootloaders/
Bootloaders/pirate-loader
Bootloaders/pirate-loader/CMakeLists.txt
Bootloaders/pirate-loader/pirate-loader.c
Bootloaders/pirate-loader/test.bat
Bootloaders/pirate-loader/test.sh
Bootloaders/BPv3
Bootloaders/BPv3/COPYING.txt
Bootloaders/BPv3/old
Bootloaders/BPv3/old/ds30_Loader_GUI
Bootloaders/BPv3/old/firmware-v4.1
Bootloaders/BPv3/old/firmware-v4.3
Bootloaders/BPv3/old/upgrader-v2tov4
Bootloaders/BPv3/old/upgrader-v4tov4
Bootloaders/BPv3/old/v2tov4-bootloader-update
Bootloaders/BPv3/old/v4xtov43-bootloader-update
Bootloaders/BPv3/old/hex2prog.html
Bootloaders/BPv3/devices.inc
Bootloaders/BPv3/ds30loader.s
Bootloaders/BPv3/ds30loader.X
Bootloaders/BPv3/ds30loader.X/Makefile
Bootloaders/BPv3/ds30loader.X/nbproject
Bootloaders/BPv3/p24FJ64GA002.gld
Bootloaders/BPv3/settings.inc
Bootloaders/BPv4
Bootloaders/BPv4/boot_config.h
Bootloaders/BPv4/bootloader.c
Bootloaders/BPv4/bootloader.h
Bootloaders/BPv4/bpv4-bootloader.X
Bootloaders/BPv4/bpv4-bootloader.X/Makefile
Bootloaders/BPv4/bpv4-bootloader.X/nbproject
Bootloaders/BPv4/cdc.c
Bootloaders/BPv4/cdc.h
Bootloaders/BPv4/descriptors.h
Bootloaders/BPv4/globals.h
Bootloaders/BPv4/main.c
Bootloaders/BPv4/p24FJ256GB106.gld
Bootloaders/BPv4/picusb.h
Bootloaders/BPv4/usb_lang.h
Bootloaders/BPv4/usb_stack.c
Bootloaders/BPv4/usb_stack.h

* Take latest pirate-loader since it should work
  for BPv3 and BPv4. (to test)
* Old BPv3 stuff saved for now in old directory
@kallisti5
Copy link
Author

Waiting on my testing to ensure the pirate-loader works on BPv3 and BPv4

@kallisti5
Copy link
Author

kallisti5 commented Sep 25, 2017

Ok.. the BPv4 is in a pretty dire shape with pirate-loader... The latest BPv4 bootloader doesn't seem to be working (unless i'm programming it wrong with pk2cmd? http://dangerousprototypes.com/docs/Bus_Pirate_v4_and_Pickit2_(bootloader_and_firmware_updates) seems to say i'm doing it right)

BPv4

  • PicKit 2 -> Erase
  • PicKit 2 -> v1 bootloader
    • pk2cmd /PPIC24FJ256GB106 /F BPv4-bootloader-v1.hex /M
  • PicKit 2 -> v6.1 Firmware
    • pk2cmd /PPIC24FJ256GB106 /F BPv4-frimware-v6.1.hex /M
  • Bootloader jump via $ non-functional
  • Bootloader jump via jumper non-functional
  • PicKit 2 -> latest BPv4 (v1.1 we've been calling it) bootloader from this repo.
  • Firmware non-functional (expected)
  • Bootloader jump via jumper functional
  • pirate-loader --hello Bootloader version 4,11 (successful)
  • pirate-loader non-functional
    • --hello only works once. After that a device reset is needed for it to work again
    • Programming the firmware fails while writing...
$ sudo ./pirate-loader --dev=/dev/ttyACM0 --hex=busPirate.X.production.hex
+++++++++++++++++++++++++++++++++++++++++++
  Pirate-Loader for BP with Bootloader v4+  
  Loader version: 1.0.3  OS: Linux
+++++++++++++++++++++++++++++++++++++++++++

Parsing HEX file [busPirate.X.production.hex]
Found 30112 words (90336 bytes)
Opening serial device /dev/ttyACM0...OK
Configuring serial port settings...OK
Sending Hello to the Bootloader...OK

Bootloader version: 4,11
Device ID [f1]:PIC24FJ256GB106
Erasing page 0, 0000...OK
Writing page 0 row 0, 0000...OK
Writing page 0 row 1, 0080...ERROR

Error updating firmware :(
  • PicKit 2 -> Latest 7.1 firmware
    • pk2cmd /PPIC24FJ256GB106 /F busPirate.X.production.hex /M
  • Firmware: OK
  • Bootloader jump via $ non-functional
  • Bootloader jump via jumper non-functional (no hello)

@agatti
Copy link

agatti commented Sep 25, 2017

I remember I used MPLAB-X IPE to flash the bootloader on my board - I'm not sure if it's available on Linux. I can take a look at that tomorrow my time to see if there's any underlying issue.

@kallisti5
Copy link
Author

I programmed it with the MPLab IDE and saw the same result. FW works, bootloader goes MIA

@agatti
Copy link

agatti commented Sep 29, 2017

Ok, I gave it a quick test. Here's what I did:

  • Bring git repo to 1ee562a
  • Erase BPv4 via MPLAB-X IPE
  • Clean bootloader project
  • Build bootloader with standard options
  • Flash bootloader
  • Verify bootloader
  • Unplug BPv4 and PicKit
  • Remove PicKit cable from BPv4
  • Clean firmware project
  • Build firmware with standard options
  • Short PGC and PGD pins
  • Plug BPv4
  • Rebuild pirate-loader for v4
  • Reflash via ./pirate-loader --dev=/dev/cu.usbmodem00000001 --hex=../../../Firmware/busPirate.X/dist/BusPirate_v4/production/busPirate.X.production.hex --verbose
  • Unplug BPv4
  • Remove PGC/PGD short
  • Reconnect BPv4
  • Connect to BPv4 via screen /dev/cu.usbmodem00000001
  • Enter into bootloader mode via $
  • Check via ./pirate-loader --dev=/dev/cu.usbmodem00000001 --hello

and it works.

bootloader_flash.txt
bpv4connect.txt
fw_flash.txt
pirateloader_hello.txt

I'll try to attempt upgrades and see what happens...

@agatti
Copy link

agatti commented Sep 29, 2017

Ok, I tried the same steps as you did and noticed the following things:

  • The old pre-built bootloader in the repo is indeed faulty in not allowing any further updates (sigh).
  • The new bootloader does not recover after a pirate-loader --hello session, but if you press the reset button on the v4 board things recover right away.
  • My BPv4 lets me flash the new firmware even with pirate-loader --hello -> reset -> pirate-loader --hex

@agatti
Copy link

agatti commented Sep 29, 2017

That said, we can do the following things:

  • File a new bug for v7.2 for the bootloader, it should recover after pirate-loader --hello.
  • Write a step-by-step guide on how to overwrite the old bootloader with something newer on v4 if an old bootloader is present.

Now, this is a major bummer since one of the biggest reasons for this community firmware to exist is indeed how DP dropped the ball on v4...

@agatti
Copy link

agatti commented Sep 29, 2017

Speaking of which, maybe we can show how to set up an Arduino to act as a ICSP programmer and use that to flash the new bootloader. There are more chances that folks have one of those laying around somewhere rather than having a PicKit at their disposal.

@agatti
Copy link

agatti commented Sep 30, 2017

Expanding more on the Arduino as a makeshift PicKit, according to http://ww1.microchip.com/downloads/en/DeviceDoc/30009907c.pdf there are three interesting things worth noting:

  • There's no need for MCLR being 12v when high (also known as high voltage programming, like older PIC parts) but 5v is fine.
  • PGC/PGD lines might not be ok being driven at 5v - which is what a standard Arduino board outputs, unfortunately.
  • The PIC24FJ series contains a "smarter" programming rom that simplifies the ICSP code quite a bit (it's called Enhanced ICSP now), like being able to program whole code blocks without having to upload some PIC code into the device's memory to shuffle data around first and the like.

I had a quick look and I haven't found any Arduino sketch that can program a PIC24F, and I hope to be proven wrong here, or I'll have to write my own.

This way the hardware components needed to program the whole lot (besides for cabling) are essentially a NPN transistor with appropriate resistors on the base and collector pins to provide appropriate power to the VDD pin on the ICSP connector, a '125 (quad level shifter) for bringing VDD, PGC, and PGD down to 3v, and then a handful of resistors for fine-tuning the voltages on VDD. Extra bypass capacitors could be used as well but I don't think they're essential as of now.

The table at page 48 of the document linked above contains all the electric characteristics of the various pins at various stages of programming. There's some quite tight requirements over there though. I wish Arduinos had a DAC on board so all the level shifting/fine tuning work wouldn't be necessary anymore...

@agatti
Copy link

agatti commented Oct 1, 2017

Or, more simply, require a Raspberry PI and use https://github.com/WallaceIT/picberry/ instead to reflash the bootloader.

@kallisti5
Copy link
Author

I opened this a while ago.. I don't think it's relevant anymore? I'm cool with closing if @agatti is.

@Rondom
Copy link

Rondom commented Jan 17, 2019

I think the pirate-loader part is still not done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants