| Author |
Message |
|
|
Posted: Mar 03, 2006 - 04:46 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
After all this noise about the Butterfly bootloader failures, I took the liberty to disassemble the official "butterfly_boot_rev03.hex", where I think I have found a few minor inconsistencies and a lot of code bloating, of course.
I have written from scratch a new bootloader for the Butterfly unit, being guided by the structure of the dissasembled file above, and using the program flow of my fully functioning bootloader libraries.
I believe that you will be impressed, firstly by the firmware size: It is 938 Bytes only, or 469 Program Memory Words!
If you wish, you can safely dedicate another one kilobyte of program memory to your application code! You can set it free by presetting the bootstart at the third position (512W, at address 0x1E00) instead of the standard fourth position (1024W, at address 0x1C00), by changing the boot fuses.
This bootloader supports all the programming modes (Word mode and Block mode) at 19200bps for both the memories (FLASH and EERPOM), and responds faster than the original one. I have only disabled the Lock-bits writing routines, to ensure that nothing can go wrong, but they can be re-enabled by uncommenting the related code at the source file.
You might wonder why this file has half the size only of the original one. I have not removed any functionality from this bootloader. I have just written this piece of software in assembly. Please, don't get me wrong but I am not trying to start another one of those legendary, delectable though, Assembly vs. C wars, we always manage to have over here...
Unfortunately, I did not have a Butterfly unit available or an m169 chip, so I have not been able to test this piece of code properly. I have successfully tested though a slightly modified version of this code for the m162, which is the most related chip to the m169, I had in hand.
Please, let me know if you can see any strange behaviour or malfunctions. Provide me with the details in order to fix them.
I hope you will find this piece of software handy. Download your copy of the Butterfly bootloader and have fun!
George.
EDIT 1 (2006.Mar.06): Bug-fix update. "ButterflyBoot v1.1.hex" released.
Although the "ButterflyBoot v1.0" worked fine using the AVRProg front-end, it would not work properly using the Avrdude: Fixed.
The Write_Lock_bit command has been disabled, therefore the chip cannot be locked.
The firmware size is below the 512W barrier: Only 471W long!
Reference: http://www.avrfreaks.net/index.php?name ... 611#208611
EDIT 2 (2006.Mar.12): Major enhancements. "ButterflyBoot v1.2.hex" released: Low power consumption, and better programming engine.
Based on the "ButterflyBoot v1.1", using extensively the sleep modes to minimize the power consumption.
The Rev1.2 improved programming-engine must now eliminate the known 0x940C bug.
The Read/Write_Lock_Bits and the Write_Fuse_Bits routines have been disabled: They gave way to the power management routines.
Green operation: Extended battery life! Tests have been done resulted to lower power consumption: Down to 40% of the Rev1.1 and the official firmwares.
The firmware size is still below the 512W barrier.
Reference: http://www.avrfreaks.net/index.php?name ... 547#210547
EDIT 3 (2006.Mar.13): Note: I will have to withdraw the "ButterflyBoot v1.2" firmware release, until I receive the Butterfly unit I am expecting to, to test this new bootloader thoroughly.
Thank you for your support. I will keep you posted. |
Last edited by Giorgos_K on Mar 13, 2006 - 09:28 PM; edited 16 times in total
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 04:53 AM |
|


Joined: Aug 04, 2005
Posts: 1267
|
|
Hi Giorgos_K
WoW! 1/2 the size!
You are a genius!
Just WELL DONE.... |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 04:56 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
|
|
|
|
|
Posted: Mar 03, 2006 - 05:03 AM |
|


Joined: Sep 10, 2005
Posts: 459
Location: Louisiana,USA
|
|
| Very Nice!......and it shows up as an ATmega169 BOOT now!(in AVRProg) Programs quick! |
_________________
My AVR Site
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 05:10 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
Yes, LCD, this comes from the "CPU specific parameters" definitions. Check it out!
It does quick programming because the firmware supports the Block-modes. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 05:37 AM |
|


Joined: Jan 23, 2004
Posts: 9878
Location: Trondheim, Norway
|
|
Actually, yours is a quarter of the size of the official bootloader. The official release requires 1024 words (2Kb) of space which caused me much ButtLoad-related grief.
Great work! I was in fact just about to start writing my own. Does yours have error checking on the fuse and lock byte setting commands?
- Dean  |
_________________ Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 05:47 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
No, not mine nor the official program have error checking routines.
As I said before, I have disabled the Lock writing routines. If you like I can upload the fully functional .hex file. Download the .asm. It is very well commented (for anyone can understand my greeklish!).
George.
PS. As a Butterfly expert you are, can you please test my program extensively? I do not have a Butterfly device to do this on my own, and I would not like to afflict any unsuspicious users...
EDIT: BTW, this program may be -literally- mine, but it is also a free, open source software, I wish to share with the community. Read the included license! |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 06:05 AM |
|


Joined: Jan 23, 2004
Posts: 9878
Location: Trondheim, Norway
|
|
Sure, i'd be happy to test it out. I'll get back to you with the results.
I was tossing around the idea of cutting up ButtLoad to make a bootloader which uses a subset of the STK500V2 protocol. It would be more robust, and usable from the "Program AVR..." menu item inside AVRStudio (not AVRPROG). Of course some of the functions would be disabled due to being not applicable with a bootloader, but do you think it's a good idea? I could probably jam it into 2Kb...
- Dean  |
_________________ Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 06:24 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
Dean, in my opinion, it could be done in assembler. You can see how efficient the assembly can be. I'll see what I can do about the STK500V2 bootloader.
This bootloader I wrote is 100% compatible with the official one, and even better, though it is half the size of the original. No, I am not good; I am just a little better at this, than the IAR compiler seems to have been... Also, do not forget that this is a two-days-only project. It HAS TO HAVE errors...
Anyway, thank you for being eager to mess with this program! There is also my email at the source file, if you will need anything. Thanks again. |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 06:31 AM |
|


Joined: Sep 10, 2005
Posts: 459
Location: Louisiana,USA
|
|
|
|
|
|
|
Posted: Mar 03, 2006 - 06:37 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
LCD, thank you for the pointer.
I can see that there is no source code but only the executables (the .hex). I think that it will be easier and faster for me to write my own code, snce the STK500v2 protocol is already public, than disassembling and struggling to understand those ones... |
_________________ I hope for nothing; I fear nothing; I am free! (Nikos Kazantzakis)
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 06:37 AM |
|


Joined: Jan 23, 2004
Posts: 9878
Location: Trondheim, Norway
|
|
Damn, all my ideas have already been done. Oh well, less work for me!
- Dean  |
_________________ Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 06:44 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
|
|
|
|
|
Posted: Mar 03, 2006 - 06:57 AM |
|


Joined: Mar 06, 2001
Posts: 564
Location: Norway
|
|
|
Giorgos_K wrote:
Yes, LCD, this comes from the "CPU specific parameters" definitions. Check it out!
It does quick programming because the firmware supports the Block-modes.
Nice one ! I'll try to "port" Your code to GNU ASM / Mega168 and see how it goes ! (ie. is it faster than My M168 bootloader )
Thanks for sharing ! (again: I miss a 'thumbs up' smiley...)
Stupid question: This word mode/block mode that keeps popping up when talking about bootloaders ? What's it all about ? As far as I can see there is only one way to use the SPM stuff (temp buf, page erase, page write...) ...
/J |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:05 AM |
|


Joined: Aug 04, 2005
Posts: 1267
|
|
|
Quote:
I'll try to "port" Your code to GNU ASM / Mega168
Yippeee! my favorite AVR  |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:09 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
Thanks, Jussi
The Block-mode is faster because it reads from and wriites directly to the RAM. The com-talk is also in the faster burst-mode than in the slower single get/put.
Good luck porting it to GNU, because I think that it will become more readable for the vast majority.
I did not even try to do it, since I am much better at the assembly than I am at C. And I think that I do not even want to try to master the embedded C. Anyway, I know, shame on me, but this is who I am... |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:20 AM |
|


Joined: Sep 10, 2005
Posts: 459
Location: Louisiana,USA
|
|
| I'm going to be putting your bootloader through some rigorous tests. This is also to help in finding the real problem with a small percentage of BFs. I will run my Butterfly with just the low power coin battery.(this seems to be one hypothosis in the problem) |
_________________
My AVR Site
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:23 AM |
|


Joined: Mar 06, 2001
Posts: 564
Location: Norway
|
|
|
Giorgos_K wrote:
Thanks, Jussi
The Block-mode is faster because it reads from and wriites directly to the RAM. The com-talk is also in the faster burst-mode than in the slower single get/put.
Good luck porting it to GNU, because I think that it will become more readable for the vast majority.
I did not even try to do it, since I am much better at the assembly than I am at C. And I think that I do not even want to try to master the embedded C. Anyway, I know, shame on me, but this is who I am...
Ok, so my bootloader operates in "word mode" then ... ie. receive a word into r0/r1, write to tempbuf, receive next word ... e.t.c ... until PAGE FULL -> ERASE/WRITE PAGE and start over again ...
Correction : I'.ve got no plans whatsoever to rewrite anything in C ...
I'm currently using GNU ASM for my AVR stuff, and the syntax is a bit different from AVRASM ...
Getting Your code to work for the M168 shouldn't be too much of a challenge, but the AVRASM -> GNU ASM bit is a bit more "scary" ...
/J |
|
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:29 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
Thank you, LCD
Be careful though, because I am not sure that my code is bug-free. It took me one day and a half to disassemble and sort out the official firmware, and the rest half of the second day to build mine. Especially because I did not have a Butterfly unit, to test my firmware, and did my tests using a similar MCU.
If you need anything, do not hesitate!
George. |
_________________ I hope for nothing; I fear nothing; I am free! (Nikos Kazantzakis)
|
| |
|
|
|
|
|
Posted: Mar 03, 2006 - 07:35 AM |
|


Joined: Mar 27, 2002
Posts: 854
Location: Athens, Hellas
|
|
|
Quote:
Correction : I'.ve got no plans whatsoever to rewrite anything in C ...
Now, you've got me!!!
Porting the code to m168 should not be difficult, because I think that those chips' memories are the same. And if they were not, I do not use magic numbers; just trim the definitions. |
_________________ I hope for nothing; I fear nothing; I am free! (Nikos Kazantzakis)
|
| |
|
|
|
|
|