Dangerous Prototypes

Dangerous Prototypes => Bus Pirate Development => Topic started by: tnt on June 27, 2010, 07:52:46 pm

Title: Howto rebuild the firmware
Post by: tnt on June 27, 2010, 07:52:46 pm
Hi,

I was wondering if there was something special needed to rebuild the firmware ?

I downloaded MPLAB and the C compiler evaluation, installed them. Then cloned the SVN and loaded the project file in source/ and build that.
Then I tried flashing the output/busPirate.hex resulting of this but the loaded doesn't even want to load the .hex file ...

    Sylvain
Title: Re: Howto rebuild the firmware
Post by: ian on June 28, 2010, 08:16:57 am
Hi tnt - The loader throws an error if there's any data in the protected bootloader area. Sjaak setup the MPLAB project so the generated .HEX file can also be loaded directly, but it sounds like that isn't working for you.

An alternative is to export it manually. Try file->export, change the end range to a7fa, and uncheck 'config words', the resulting HEX should compile.
Title: Re: Howto rebuild the firmware
Post by: Sjaak on June 28, 2010, 09:27:13 am
If You are using the pirateloader for updating the firmware it doesn't work. Pirateloader can't cope with lowercase .hex files. To fix it you need to do the export step Ian described (export program memory 0x0000 - 0xA7FF and NO fuses!)

Hmm 0xa7fa is better ;)
Title: Re: Howto rebuild the firmware
Post by: ian on June 28, 2010, 09:34:39 am
a7fa only requires changing 1 digit instead of two :) Also, it leaves free the area where we store the modified modified jump instruction (as I recall) for an extra measure of protection.

@Sjaak - so that is what you meant when you asked if I could fix pump-loader earlier. Sure, I'll fix this now :)
Title: Re: Howto rebuild the firmware
Post by: Sjaak on June 28, 2010, 09:49:55 am
[quote author="ian"]
a7fa only requires changing 1 digit instead of two :) Also, it leaves free the area where we store the modified modified jump instruction (as I recall) for an extra measure of protection.
[/quote]

You lazy #@$% ;P

Lets also upgrade pirateloader ;)
Title: Re: Howto rebuild the firmware
Post by: tnt on June 28, 2010, 09:52:04 am
Thanks to the both of you.

I was indeed using pirateloader. With the export, I get an hex that's the same length as the official one. I'll try flashing it tonight see if it works.
Title: Re: Howto rebuild the firmware
Post by: robots on June 28, 2010, 10:03:56 am
a7fa ? ... is that "alfa" in 133t speech ? ;)
Title: Re: Howto rebuild the firmware
Post by: Sjaak on June 28, 2010, 10:15:30 am
J35500rr!!!!111111111 Ph34r 7h4 1337 h4c<50rs
/me went back to his corner and waits till his mood passes ;)
Title: Re: Howto rebuild the firmware
Post by: ian on June 28, 2010, 10:23:05 am
Here's an updated compile in the SVN (direct download link):
http://the-bus-pirate.googlecode.com/sv ... loader.exe (http://the-bus-pirate.googlecode.com/svn/trunk/bootloader-v4/pirate-loader/pirate-loader.exe)

It tests fine for me (with lower case), I didn't think to try uppercase again though.

I took the nice terse ?: hex->dec statement and made an ugly if-elseif-else statement, but so is life.

Here's my commit note:
Log: updated pirate-loader to read hex with lower-case hex digits. Includes new Windows compile (GCC/MinGW) only. One thing to note is that the GCC compile for win32 was about 4 times smaller than the only version made in VC, if there's problems that might be something to look at.
http://code.google.com/p/the-bus-pirate ... =393&nbsp; (http://code.google.com/p/the-bus-pirate/source/detail?r=393&nbsp;)


It is alfa isn't it :) There are lots of 1337 and hidden geek references in DP PCBs, source, etc, but this one is an accident. The most obvious is the #twatch with it's back door port 1337 :) Like Seeed says, Electronic can be art.
Title: Re: Howto rebuild the firmware
Post by: Sjaak on June 28, 2010, 10:44:22 am
I believe VC has standard several included libraries (statically linked in).

I once tried to compile a int main(void) { return 0; } several years ago. The resuilt was several 100K (200k iirc)

The solution with 1337 ?: is somewhere in the forum: http://dangerousprototypes.com/forum/in ... opic=437.0 (http://dangerousprototypes.com/forum/index.php?topic=437.0)

Take a strol ;)
Title: Re: Howto rebuild the firmware
Post by: ian on June 28, 2010, 11:04:04 am
It looks like there's several 'nicer' options.

Here's mine (not great, but 30 seconds of mindless work gets it going):

Code: [Select]
unsigned char hexdec(const char* pc)
{ unsigned char temp;

if(pc[0]>='a'){
temp=pc[0]-'a'+10;
}else if(pc[0] >= 'A'){
temp=pc[0]-'A'+10;
}else{
temp=pc[0] - '0';
}
temp=temp<<4;

if(pc[1]>='a'){
temp|=pc[1]-'a'+10;
}else if(pc[1] >= 'A'){
temp|=pc[1]-'A'+10;
}else{
temp|=pc[1] - '0';
}

return(temp & 0x0FF);
}

Here's another, nicer but also more obfuscated:
Code: [Select]
unsigned char hexdec(const char* pc)
        char    c0, c1;
        c0 = (pc[0] < 'a')?pc[0]:(pc[0]-'a'+'A');
        c1 = (pc[1] < 'a')?pc[1]:(pc[1]-'a'+'A');
        return (((c0 >= 'A') ? ( c0 - 'A' + 10 ) : ( c0 - '0' ) ) << 4 |
                        ((c1 >= 'A') ? ( c1 - 'A' + 10 ) : ( c1 - '0' ) )) & 0x0FF;
}

And the strtol:
Code: [Select]
strtol(pc, NULL, 16);

I just tested the strtol, but there are some more things that would need to be worked out because it seems to effect other parts of the code:

Code: [Select]
C:MinGW>pirate-loader.exe --dev=COM3 --hex=buspirate.hex
+++++++++++++++++++++++++++++++++++++++++++
  Pirate-Loader for BP with Bootloader v4+
  Loader version: 1.0.2  OS: WINDOWS
+++++++++++++++++++++++++++++++++++++++++++

Parsing HEX file [buspirate.hex]
Checksum does not match, line 1
Could not load HEX file, result=-1

C:MinGW>pause
Press any key to continue . . .

I didn't look into it closely, could be really simple. I'm happy with it the way it is unless there are objections.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01522092224session_write_close ( )...(null):0
20.01552223816ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01552224592Database_MySQL->query( ).../DatabaseHandler.php:119
40.06032363320Database_MySQL->error( ).../Db-mysql.class.php:273