Skip to main content
Topic: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...) (Read 63151 times) previous topic - next topic

Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Hello,

I just got a bus pirate a few days ago and wanted to get my hands in the firmware.
But current IDE is MPLAB8, not supported under linux.
So Ian told me to have a look to MPLABX, the release-to-come from Microchip, currently in beta but supporting amongst other OSes Linux & Mac :-)

It could be of interest also for Windows folks as MPLABX promises whistles & bells compared to MPLAB8.
See http://devupdates.microchip.com/mplab/F ... PLAB-X.pdf

Apparently it's a rather new topic within the bus pirate community so I'm starting this thread to share experiences & tips on that matter, to become a howto on the wiki once things will be sorted out I presume...

1) MPLABX Installation:
Visit http://devupdates.microchip.com/mplab/ and get the following components for your preferred OS:
* MPLAB X IDE
* MPLAB C Compiler for dsPIC DSCs and PIC24 MCUs (Lite)

1.1) Under a Debian Squeeze 64-bit here is the command I had to execute:
$ chmod 755 mplabxidebeta32.bin mplabc30.bin
$ sudo su -
# GTK_PATH=/usr/lib32/gtk-2.0 exec ./mplabxidebeta32.bin
# GTK_PATH=/usr/lib32/gtk-2.0 exec ./mplabc30.bin
Note that I had still a couple of "wrong ELF class: ELFCLASS64" errors because some GTK components (gio modules) were not available in 32-bit libraries but it seems to not having hurt the installation.

Under a 32-bit distribution you don't need to worry about the GTK_PATH and you can simply do
$ sudo ./mplabxidebeta32.bin
$ sudo ./mplabc30.bin

Files will be installed in /opt/microchip

2) Project migration:
We'll need a bit of discipline now as Linux is case-sensitive and only Windows accepts paths with "" while all OSes accept paths with "/".
Most (all?) changes were already done yesterday thanks to Stephan (see https://code.google.com/p/the-bus-pirat ... tail?id=55) so it should be ok by now (but maybe some of the child projects has still to be converted...)

To migrate the existing MPLAB8 project to MPLABX, one needs to use the included wizard:
* New project>  Microchip Embedded>  Existing MPLAB IDE v8>  busPirate.mcp
** Device: PIC24FJ64GA002
** Select Header: AC162088
** HW tool: PICkit3
** Compiler: C30
** Keep files in place

3) Compilation:
It could compile properly the ADDONS firmware but failed on the MAIN firmware by lack of space, which is according to Ian a known problem in the current SVN, so unrelated to MPLABX.

4) HEX file:
Current wiki notes on firmware compilation mention that we need to export the firmware as Intel HEX file.
But "Export" is currently documented as known unsupported feature in MPLABX (remember, it's a beta...)
Nevertheless one can find it in the new project structure as busPirate.X/busPirate/dist/default/production/busPirate.production.hex

If I try the firmware as such with pirate-loader_lnx, it gives a checksum error.
When I compared it with the released firmwares I see it's using small a-f while released firmware use capitalized A-F.
So I simply converted it:
$ cat busPirate.production.hex |tr a-f A-F>  busPirate.production2.hex
And I could successfully flash the bus pirate with it.

For this last point, I don't know what is the proper way to get rid of this case-sensitivity problem.
Make pirate-loader_lnx robust to the new HEX format?
How MPLABX is doing on the other OSes?
How the firmware loaders are doing on the other OSes?

Should we push the migrated MPLABX project to SVN too?

Do other people have experience to share with MPLABX?

Phil

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #1
My installation on a Linux system went much smoother than yours; I did not have any issues.  However I had problems building the Bus Pirate project with MPLAB X under both Linux and Windows.

See also this thread.

-Eric

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #2
I removed case sensitivity from pirate-loader source, and the Windows version, but I guess it hasn't been recompiled for Linux yet.

Is it ok to post this on the wiki under the development section? This topic is really heating up.

It would be fine (and great) to include a mplabx project in the source. Would you like SVN access?
Got a question? Please ask in the forum for the fastest answers.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #3
Thanks for the links Eric!
So to be complete in this thread, MPLABX installation was also discussed ath the following places:
* http://dangerousprototypes.com/2010/10/ ... linux-mac/
* http://dangerousprototypes.com/forum/in ... 1#msg11831
* http://dangerousprototypes.com/forum/in ... 1#msg12051
And there was a ref to the beta wiki of Microchip: http://microchip.wikidot.com/start

Ian it would be great indeed to have a wikipage to consolidate all the meaningful info about this matter.
Maybe 2 pages, one for general MPLABX installation & experience and one specific for Bus Pirate compilation under MPLABX?

I can push the mplabx project of bus pirate under SVN, I'll send you my Google ID by mail. Thanks.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #4
You're added.

Feel free to edit the wiki. I one general page:
http://dangerousprototypes.com/docs/MPLAB_X
and a section for MPLAB X in the Bus Pirate developer wiki page:
http://dangerousprototypes.com/docs/Com ... .2C_Mac.29

You can move your previous notes there, or I can do it with your permission.
Got a question? Please ask in the forum for the fastest answers.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #5
Thanks Ian!
http://dangerousprototypes.com/docs/MPLAB_X populated.
Once everything is settled in the bus pirate SVN I guess we won't need to explain much in the bus pirate specific section ;-)

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #6
Nice, thank you.
Got a question? Please ask in the forum for the fastest answers.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #7
[quote author="doegox"]
# GTK_PATH=/usr/lib32/gtk-2.0 exec ./mplabxidebeta32.bin
# GTK_PATH=/usr/lib32/gtk-2.0 exec ./mplabc30.bin
[/quote]

There is this thing called "linux32" which should change the envirnoment to 32bit. (At least it is on gentoo 64bit :-) ) Have a look at man linux32 page.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #8
Thanks robots but that didn't help.

There is also a linux32 under Debian (which claims to only modify uname -m output).
So using linux32 doesn't solve this GTK issue.
See same bug on Ubuntu & all gory details here: https://bugs.edge.launchpad.net/ubuntu/ ... bug/369498

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #9
Migrating a discussion started in the bugreport page (https://code.google.com/p/the-bus-pirat ... tail?id=55)

There are now two working Makefile for linux in the source tree:
The one of Stephan in source/Makefile and the one generated by MPLABX in source/busPirate.X/busPirate/Makefile

Stephan had the great idea to try out the space optimization and it seems to work (but requires more tests of all modes)
Now both use the space optimization flag and I can see still the following differences:

* Stephan's Makefile compiles also ee.c & eetext.S objects, which are currently not used (commented out in procMain)
* MPLABX's is using elf format as intermediate format (-omf=elf)
* MPLABX defines a few internal symbols (-Wa,--defsym=__MPLAB_BUILD=1 &  -Wl,--defsym=__MPLAB_BUILD=1)
* Stephan's Makefile output is neat, contrary to the verbose MPLABX Makefile output

Question is, what do we do?
Keep both Makefiles or get rid of the first one? (MPLABX IDE generated anyway the second one)
Or make another Makefile in source/ to encapsulate MPLABX Makefile, with neater output?

For those who want to try, there is a firmware image built with MPLABX comprising all modes:
http://the-bus-pirate.googlecode.com/sv ... MPLABX.hex

 

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #10
I'll do a post on this and try to get some more testers.
Got a question? Please ask in the forum for the fastest answers.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #11
Hi everybody,

a few observations:
  • On such a small processor, we should definitely use -Os to conserve space. It might be a good idea to look at other GCC options, see http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html . AFAIK the Windows IDE also uses GCC, so there should be some way to enable size optimization
  • I like to enable all warnings with -Wall, this helps to catch some errors.
  • The use of ELF or COFF intermediate format should have no effect on the final HEX file.
  • I don't mind using the MPLABX Makefile. I managed to get a HEX file, although I always get an error at the end of the build.
So you can delete my Makefile, but then we should probably improve the MPLABX settings a bit.

Ian: you offered to give me SVN access. I'll be glad to help with this project, and of course I won't do large changes without discussing them first. My Google Code user name is xxxxxxxxx . Thanks!

-Stephan

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #12
Thanks, I added you and removed your email from the post.
Got a question? Please ask in the forum for the fastest answers.

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #13
Options for Controlling Optimization

The following options control compiler optimizations.

-O0  Do not optimize. (This is the default.)
Without -O, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.The compiler only allocates variables declared register in registers.
 
-O
-O1  Optimize. Optimizing compilation takes somewhat longer, and a lot more host memory for a large function. With -O, the compiler tries to reduce code size and execution time. When -O is specified, the compiler turns on -fthread-jumps and -fdefer-pop. The compiler turns on -fomit-frame-pointer. 

-O2  FULL VERSION ONLY
Optimize even more. The compiler performs nearly all supported optimizations that do not involve a space-speed trade-off. -O2 turns on all optional optimizations except for loop unrolling (-funroll-loops), function inlining (-finline-functions), and strict aliasing optimizations (-fstrict-aliasing). It also turns on force copy of memory operands (-fforce-mem) and Frame Pointer elimination (-fomit-frame-pointer). As compared to -O, this option increases both compilation time and the performance of the generated code. 

-O3  FULL VERSION ONLY
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the inline-functions option. 

-Os  FULL VERSION ONLY
Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.


This is from hlpMPLABC30.chm (windows), so you can only use options higher than -O1 while you are evaluating the compiler, then it reverts to the lite version

Re: Compiling Bus Pirate firmware with MPLABX (under linux, mac, ...)

Reply #14
I guess it's only a limitation of the IDE, do you know if it's still possible to use the option directly for pic30-gcc?
In that case we would need a separate Makefile...
Pfff I hate this non-free mentality.