[tuxdroid-svn] r1217 - in firmware: . dfu-programmer dfu-programmer/trunk dfu-programmer/trunk/libs
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-06-05 08:38:08
|
Author: Paul_R Date: 2008-06-05 10:38:07 +0200 (Thu, 05 Jun 2008) New Revision: 1217 Added: firmware/dfu-programmer/ firmware/dfu-programmer/branches/ firmware/dfu-programmer/tags/ firmware/dfu-programmer/trunk/ firmware/dfu-programmer/trunk/AUTHORS firmware/dfu-programmer/trunk/COPYING firmware/dfu-programmer/trunk/ChangeLog firmware/dfu-programmer/trunk/Makefile firmware/dfu-programmer/trunk/NEWS firmware/dfu-programmer/trunk/README firmware/dfu-programmer/trunk/libs/ firmware/dfu-programmer/trunk/libs/libusb.lib firmware/dfu-programmer/trunk/src/ firmware/dfu-programmer/trunk/src/arguments.c firmware/dfu-programmer/trunk/src/arguments.h firmware/dfu-programmer/trunk/src/atmel.c firmware/dfu-programmer/trunk/src/atmel.h firmware/dfu-programmer/trunk/src/commands.c firmware/dfu-programmer/trunk/src/commands.h firmware/dfu-programmer/trunk/src/config.h firmware/dfu-programmer/trunk/src/dfu.c firmware/dfu-programmer/trunk/src/dfu.h firmware/dfu-programmer/trunk/src/intel_hex.c firmware/dfu-programmer/trunk/src/intel_hex.h firmware/dfu-programmer/trunk/src/main.c firmware/dfu-programmer/trunk/src/tux_misc.c firmware/dfu-programmer/trunk/src/tux_misc.h firmware/dfu-programmer/trunk/src/usb.h firmware/dfu-programmer/trunk/src/util.c firmware/dfu-programmer/trunk/src/util.h Log: * Added dfu-programmer for windows. This is an adapted version of dfu-programmer for linux created by Weston Schmidt. (http://dfu-programmer.sourceforge.net/). The base is the version 0.4.4 for Linux. To compile it, you have to install MinGWStudio. Main changes made on the originals sources : - Created a specific Makefile for windows - Changed all #include <usb.h> by #include "usb.h". The libusb library has been added on the project. - Added set_configuration before claiming the interface. - Fixed some compatibility issues with errno.h Tested on Windows Vista 32 Added: firmware/dfu-programmer/trunk/AUTHORS =================================================================== --- firmware/dfu-programmer/trunk/AUTHORS (rev 0) +++ firmware/dfu-programmer/trunk/AUTHORS 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,21 @@ +Original Author: + - Weston Schmidt <wes...@al...> + +Contributors: + - Reinhard Arlt + - at89c5131 chip support + - Anton Blad + - at90usb162 and at90usb82 chip support + - David Brownell + - compiler flag improvements + - command line argument processing improvements + - debugging system improvements + - significant man page improvements + - support for the at90usb series AVR chips + - the beginnings of the move over to using stdint.h + - Nick Hibma + - bug fixes + - Markus Schneider + - OS X porting issues + - Geoffrey Wossum + - added reset command Added: firmware/dfu-programmer/trunk/COPYING =================================================================== --- firmware/dfu-programmer/trunk/COPYING (rev 0) +++ firmware/dfu-programmer/trunk/COPYING 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Added: firmware/dfu-programmer/trunk/ChangeLog =================================================================== --- firmware/dfu-programmer/trunk/ChangeLog (rev 0) +++ firmware/dfu-programmer/trunk/ChangeLog 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,344 @@ +2007-11-19 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * docs/dfu-programmer.1, src/arguments.c, src/arguments.h, + src/commands.c, AUTHORS: Applied the patch that Geoffrey + Wossum provided to add a reset command. + * fedora/*: Adding udev rules for and permissions so that + the console owner will automatically be able to flash + any of the devices supported by dfu-programmer. + * dfu-programmer.spec.in, Makefile.am, configure.ac: + Moved the spec file into the fedora specific + directory and excluded from the tar dist. + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.4.4 release + +2007-08-15 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * dfu-programmer.spec.in: Updating the license tag. + +2007-08-12 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * AUTHORS: added Anton Blad (for new devices) and Nick Hibma + (for bug fixes) to the list of contributors. + * configure.ac: Incremented the release number + * docs/dfu-programmer.1: Added at90usb162 and at90usb82 + devices + * dfu-programmer.spec.in: Added the newly supported chips + * NEWS: Updated the latest news about the 0.4.3 release + * src/arguments.c, src/arguments.h: Applied the patch that + Anton Blad provided to add support for the at90usb162 + and at90usb82. + +2007-07-22 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/atmel.c: Fix the incorrect status to string conversion + that Nick Hibma found and pointed out. + * dfu-programmer.spec.in: Updating the file to be compliant + with the Fedora requirements for packaging (again) + +2007-07-07 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.4.2 release + * dfu-programmer.spec.in: Updating the file to be compliant + with the Fedora requirements for packaging + +2007-04-29 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.4.1 release + +2007-04-25 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * docs/dfu-programmer.1: Added a KNOWN ISSUES section, + updated the BUGS section, and corrected the Free + Software Foundation address. + * src/arguments.c: Adjusted the memory sizes for the at90 + series of chips so they can take advantage of the entire + amount of flash memory. + * src/atmel.c, src/atmel.h: Add the concept and support for + paged flash memory. I added this so that only devices + that actually go into paged memory will try to make calls + to the memory paging routine. I also did a bit of cleanup + to allow a clean transition between the pages (so there + are not regions of memory being flashed that overlap a + flash memory page boundary). + +2007-03-28 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * m4/depcomp, m4/missing, src/dfu.c, src/intel_hex.c, + src/commands.c, src/atmel.c, src/util.h, src/dfu.h, + src/intel_hex.h, src/main.c, src/arguments.c, + src/commands.h, src/atmel.h, src/arguments.h, + src/util.c, COPYING: Updated the FSF address in the + GPL license. + +2007-01-27 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.4.0 release + * src/arguments.c, src/arguments.h: add two fields to the + chip configuration structures to handle the two + inconsistencies in the dfu firmware - the at90 chips + need to be aborted initially, and the at90 chips don't + return valid interface class and subclass information. + Originally, the interface problem was thought to be + related to OS X, but it now looks like it is the chipset. + * src/dfu.c, src/dfu.h, src/main.c: add the handing of + the new initial abort and interface class/subclass workarounds. + +2007-01-16 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/intel_hex.c: change the sscanf() parameter to an int + from a char to be compliant with the sscanf() %x documentation + stating that the output of %x is an int. + +2007-01-14 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/arguments.c: added the flash_page_size data and values + to the data structure. I checked to make sure that the + flash page size is correct for all of the processors. + * src/arguments.h: added the flash_page_size data member to + the programmer_arguments data structure. + * src/atmel.c: updated the atmel_flash() functionality so that + only the memory pages that need to be flashed are flashed. + * src/atmel.h: updated the external interface for atmel_flash() + to refelect the changes in src/atmel.c + * src/commands.c: changed the passing of the argument structure + to be a pointer instead of the actual full structure. + Updated the execute_flash() functionality to support the + changes made in src/atmel.x. + * src/commands.h: updated the function prototype. + * src/intel_hex.c: changed the processing of the hex strutures + to allow the support of only flashing the memory locations + that are actually programmed. + * src/intel_hex.h: updated the function prototypes. + * src/main.c: pass the pointer to the argument structure instead + of passing the entire structure. + +2007-01-07 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * AUTHORS: added Markus Schneider for his OS X contributions + * configure.ac: changed AC_CONFIG_HEADER to AM_CONFIG_HEADER + to allow easier compiling on OS X. + * src/dfu.c: added a workaround for OS X because it was + not finding devices since the DFU interface information + is not being correctly reported. + +2007-01-06 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * config.h.in: added the autogenerated information from + autoheader. + * configure.ac: added checking for errno.h stdarg.h and + stddef.h to be more thorough in checking for required + headers. + * src/dfu.c: added an #ifdef around the EREMOTEIO case + * src/intel_hex.c: refactored intel_read_data() to not + use getline(), but to simply walk the file via fgets() + and fgetc(). As it turns out, getline() wasn't really + adding much value. + +2006-11-28 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/atmel.c: remove the dfu_make_idle() calls + * src/dfu.c: large changes to allow the dfu module to + discover and acquire the usb device. This change was + required to allow the dfu module to try to transition + a USB device from its runtime mode into its DFU mode. + Part of this transition requires resetting, re-enumerating, + and re-acquiring the device. All of this was not possible + before because the main function held onto the device + and it's handle. Additionally, when acquiring the device + for the first time, the dfu module tries to put the device + into the correct state, instead of punting this process + to the later steps, when it is impossible to recover from. + Finally, the variables named "device" were changed to be + "handle" since that's what they really are and there are + references to the actual "device" structure in dfu.c now. + * src/dfu.h: updated the prototypes to reflect the changes in + dfu.c. + * src/main.c: remove the dfu_make_idle() calls and simplify + the main function since most of the work is now being done + in dfu.c. Additionally, move the device discovery to dfu.c + +2006-11-19 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/atmel.c: Added the dfu_make_idle() call before + operations that communicate with the device being flashed. + This should make the communications more reliable as it + puts the device in a known state. Additionally, I added + some better error messages in the hopes that it will be + easier to diagnose the problem when commands to the + device fail. Finally, I adjusted the return code checking + for dfu_get_statue() to reflect the new interface of 0 for + success or < 0 for errors. + * src/commands.c: I fixed a poor error message. + * src/dfu.c: I updated the dfu_get_status() function to simply + return 0 on a success, or < 0 on an error. I added + dfu_make_idle() to allow the device to be put in a known + state or to force an early bailout. + * src/dfu.h: dfu_make_idle() is publically available. + +2006-11-19 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/dfu.c: Added a DFU status to string conversion method + and when debug is enabled, dfu_get_status() shows both the + string and the number for the status. + * src/dfu.h: the dfu_status_to_string() is made publically + available. + +2006-11-15 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/atmel.c: Remove the init function since it is no longer + needed. This re-works the debug message support so there is + a simple macro DEBUG() that takes care of all the work. + Additionally, this fixes an erasing problem where when the + entire chip was supposed to be erased, it was not. This + could cause problems because when the security bits are set, + they could never be unset. + * src/atmel.h: Remove the init function since it is no longer + needed. + * src/commands.c: This re-works the debug message support so + there is a simple macro DEBUG() that takes care of all the + work. + * src/dfu.c: This re-works the debug message support so there + is a simple macro DEBUG() that takes care of all the work. + Additionally, there is no reason to have the init function + since we are going to use the one external debug variable. + This normalized all of the functions so they produce useful + information when debug messages are enabled. Finally, this + adds an error number to message converter so that tracking + down errors is a bit easier. + * src/dfu.h: Remove the init & debug functions. + * src/main.c: Adjust the level needed to turn the libusb + debugging messages on. Removed the atmel_init() call. + * src/Makefile.am: Added util.c and util.h to be built. + * src/util.c: Added the dfu_debug() function in a common + location. + * src/util.h: Added the dfu_debug() function in a common + location. + +2006-10-21 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * dfu-programmer.spec.in: This resolves several of the problems + present in the spec file. The goal is to be able to make this + package part of the fedora extras. + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.3.1 release + * docs/dfu-programmer.1: Update the SEE ALSO section, AUTHOR + section and added the copyright information. + +2006-06-24 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * dfu-programmer.spec.in: Update the supported chips + * NEWS: Updated the latest news about the 0.3.0 release + * src/arguments.c: Adjusted the 8051 based chip memory sizes to + be accurate, and the top memory address is calculated based off + of the memory size. + * src/arguments.h: Added top_memory_address to differentiate the + memory size and top memory address. This resolves my question + about the +1 offset. + * src/atmel.c: Fix a bug where the last byte of memory was not being + transferred from the device for validation purposes. + * src/commands.c: Updated to use memory_size and top_memory_address + depending on which value is needed, instead of using one value + to serve both purposes. + +2006-06-24 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * dfu-programmer.spec.in: Update the supported chips + * README: Added an instruction about building the source from CVS. + +2006-06-19 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * AUTHORS: Updated David Brownell's contributions - which makes + up almost this entire check-in! + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.3.0 release + * src/arguments.c: Added the new targets, made the target names + case insensitive, added a version command line "command", updated + the mechanism for matching commands, and updated debugging output. + * src/arguments.h: Added new targets, and cleaned the arguments + structure up a bit. + * src/atmel.c: Applied general cleanup, matched the atmel.h + interfaces and added an AVR a configuration reading function. + * src/atmel.h: Updated the interface to allow for 8051 vs AVR + differences. This also starts the use of stdint.h values. + * src/commands.c: Updated to a more standard debugging system and + added command checking for 8051 vs AVR differences. There is + an open question about why we switch between args.memory_size + and args.memory_size+1 in comparisons. I need to re-read up + on why in the world I did args.memory_size+1 in the first + place, then follow up with David about implications around + the AVR chips. + * src/dfu.c: Updated to a more standard debugging system and + removed an overly verbose debug message. + * src/intel_hex.c: Added comments about the record types, and + added 20 bit address types for the larger amount of addressable + flash memory. + * src/main.c: Updated to a more standard debugging system, + updated the failure messages to include the package information. + * README: Updated description and list of supported chips + +2006-06-18 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * AUTHORS: Added David Brownell as a contributor. + * configure: Removed because it is generated by bootstrap.sh + * Makefile.in: Removed because it is generated + * docs/Makefile.in: Removed because it is generated + * src/Makefile.in: Removed because it is generated + * src/Makefile.am: Applied David Brownell's patch that adds -Wall + as a compiler option. + +2005-05-07 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * AUTHORS: Updated my email address + * configure.ac: Incremented the release number + * dfu-programmer.spec.in: Update the release to Fedora Core 5 + * NEWS: Updated the latest news about the 0.2.2 release + * src/main.c: Fix the failure cases so that if the USB interface was + not acquired then it is not errantly released. + +2005-11-21 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.2.1 release + +2005-11-21 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * docs/dfu-programmer.1: Bring the man page in-line with the + built in help, plus a bit more info. + +2005-11-21 Weston Schmidt <weston_schmidt AT alumni.purdue.edu> + + * src/main.c: Two minor fixes to allow it to work with newer 2.6.xx + kernels. The first had to do with using a function call to get + the buses to iterate over, and the second has to do with not + setting a configuration. Apparently this doesn't need to be done. + +2005-09-24 Weston Schmidt <weston_schmidt AT yahoo.com> + + * configure.ac: Incremented the release number + * NEWS: Updated the latest news about the 0.2.0 release + * src/commands.c: Removed the hard-coded restrictions on sizes and + instead malloc the space needed. Additionally the size is gotten + from the arguments data structure, so that adding future devices + should be easier. + * src/arguments.h: Added memory_size to the programmer_arguments + data structure. Restructured the targets_enum so that it can + be used as keys into the target_map data structure for target + to name resolution without needing to duplicate data. + * src/arguments.c: Made the changes needed to take advantage of the + memory size restructuring and changed the usage() function to + use iteration instead of duplication to display supported chips + +2005-09-24 Weston Schmidt <weston_schmidt AT yahoo.com> + + * src/{*.c,*.h}, AUTHORS: removed the copyright information from the + file so that the AUTHORS file can manage this information for the + entire project + +2005-09-24 Weston Schmidt <weston_schmidt AT yahoo.com> + + * src/{arguments.c,arguments.h,atmel.c,commands.c}: applied + Reinhard Arlt's patch that adds support for the at89c5131 chip Added: firmware/dfu-programmer/trunk/Makefile =================================================================== --- firmware/dfu-programmer/trunk/Makefile (rev 0) +++ firmware/dfu-programmer/trunk/Makefile 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,88 @@ +## General Flags +CC = "gcc.exe" +DEFS = -DWIN32 +C_INCLUDE_DIRS = -I"C:\bin\MinGWStudio\MinGW\include\ddk" +CFLAGS = -pipe -Wall -g2 -O0 +LIB_DIRS = -L"libs" +LIBS = -lwinmm -llibusb +SRC_DIR = src +TARGET = dfu-programmer + +## Libraries + +## Objects that must be built in order to link + +## Compile and link +SRC_OBJS = $(SRC_DIR)/main.o \ + $(SRC_DIR)/arguments.o \ + $(SRC_DIR)/atmel.o \ + $(SRC_DIR)/commands.o \ + $(SRC_DIR)/dfu.o \ + $(SRC_DIR)/intel_hex.o \ + $(SRC_DIR)/util.o + +define build_target +@echo Linking... +@$(CC) -o "$(TARGET)" $(SRC_OBJS) $(LIB_DIRS) $(LIBS) $(LDFLAGS) +endef + +define compile_source +@echo Compiling $< +@$(CC) $(CFLAGS) $(C_INCLUDE_DIRS) -c "$<" -o "$@" +endef + +.PHONY: print_header +$(TARGET): print_header $(SRC_OBJS) + $(build_target) + +print_header: + @echo Start compiling + +main.o: $(SRC_DIR)/main.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/dfu.h \ +$(SRC_DIR)/atmel.h \ +$(SRC_DIR)/arguments.h \ +$(SRC_DIR)/commands.h + $(compile_source) + +arguments.o: $(SRC_DIR)/arguments.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/arguments.h + $(compile_source) + +atmel.o: $(SRC_DIR)/atmel.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/arguments.h \ +$(SRC_DIR)/dfu.h \ +$(SRC_DIR)/atmel.h \ +$(SRC_DIR)/util.h + $(compile_source) + +commands.o: $(SRC_DIR)/commands.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/commands.h \ +$(SRC_DIR)/arguments.h \ +$(SRC_DIR)/intel_hex.h \ +$(SRC_DIR)/atmel.h \ +$(SRC_DIR)/util.h + $(compile_source) + +dfu.o: $(SRC_DIR)/dfu.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/dfu.h \ +$(SRC_DIR)/util.h + $(compile_source) + +intel_hex.o: $(SRC_DIR)/intel_hex.c \ +$(SRC_DIR)/usb.h \ +$(SRC_DIR)/intel_hex.h + $(compile_source) + +util.o: $(SRC_DIR)/util.c \ +$(SRC_DIR)/util.h + $(compile_source) + +clean : + rm -f $(TARGET).exe $(SRC_OBJS) + Added: firmware/dfu-programmer/trunk/NEWS =================================================================== --- firmware/dfu-programmer/trunk/NEWS (rev 0) +++ firmware/dfu-programmer/trunk/NEWS 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,39 @@ +Release 0.4.4 +* Added new reset command +* Added out of the box permission changes to allow the console owner + to flash a device without needing to be root. +Release 0.4.3 +* Added support for the at90usb162 and at90usb82 chips. +* Applied path for incorrect status string conversion. +Release 0.4.2 +* Minor spec file changes to be Fedora compliant +Release 0.4.1 +* Added support for flashing both memory pages for the at90usb128x + chips. +* Updated the man page. +Release 0.4.0 +* Major set of fixes added for the at90xxx chips. +* Optimized the flashing algorithm that only flashes the blocks needed + based on the data being flashed, instead of flashing the entire chip + each time (potentially saves s good deal of time during development) +* The chip should be initialized better than before, increasing the + likelihood of a successful operation. +* Refined the code to allow OS X to compile and run dfu-programmer. +Release 0.3.1 +* Minor documentation changes and polishing of the spec file to get the + project inline with what is needed to be part of the fedora extras. +Release 0.3.0 +* Added support for (AVR) at90usb1287, at90usb1286, at90usb647, at90usb646 + chips. +* Fixes a minor validation bug where the last byte of flash was not being + correctly validated. +Release 0.2.2 +* Minor bug fix for a segmentation fault if only the usage is displayed. +Release 0.2.1 +* Minor bug fixes and documentation updates. +Release 0.2 +* Limited support for the at89c5132, at89c5131 and at89c5130 chip is added. + where the known limitations now have to do with P1_CF, P3_CF, P4_CF not + being supported (read or write). +Release 0.1 +* Initial release Added: firmware/dfu-programmer/trunk/README =================================================================== --- firmware/dfu-programmer/trunk/README (rev 0) +++ firmware/dfu-programmer/trunk/README 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,66 @@ +dfu-programmer is an implementation of the Device Firmware Upgrade class +USB driver that enables firmware upgrades for various USB enabled (with the +correct bootloader) Atmel chips. This program was created because the +Atmel "FLIP" program for flashing devices does not support flashing via USB +on Linux, and because standard DFU loaders do not work for Atmel's chips. + +Check out the Atmel website for more information. They are kind enough to +provide generally correct specifications this implementation is based on. + +The project website is http://dfu-programmer.sourceforge.net and you can +use that to check for updates. + +Currently Supported Chips +========================= +8051 based: + at89c51snd1c + at89c5130 + at89c5131 + at89c5132 + +AVR based: + at90usb1287 + at90usb1286 + at90usb647 + at90usb646 + +Simple install procedure +======================== + + % tar -xzf dfu-programmer-<version>.tar.gz # unpack the sources + % cd dfu-programmer # change to the top-level + # directory + + [ If the source was checked-out from CVS, run the following command ] + % ./bootstrap.sh # regenerate base config + # files + + % ./configure # regenerate configure and + # run it + + [ Optionally you can specify where dfu-programmer gets installed + using the --prefix= option to the ./configure command. See + % ./configure --help for more details. ] + + % make # build dfu-programmer + [ Become root if necessary ] + % make install # install dfu-programmer + +Building RPM Binary Packages +============================ +This section is intended to make it easier for those people that wish to +build RPMs from the source included in this package, but aren't sure how. + +1) Copy dfu-programmer-<version>.tar.gz to your RPM SOURCES directory. Usually + this is /usr/src/redhat/SOURCES/. + +2) Extract or copy dfu-programmer.spec into your RPM SPECS directory. Usually + this is /usr/src/redhat/SPECS/. + +3) In your RPM SPECS directory, issue the command 'rpm -ba dfu-programmer.spec'. + This will cause rpm to extract the dfu-programmer sources to a temporary + directory, build them, and build rpm packages based on the information in + the spec file. The binary rpms will be put into your RPM RPMS directory. + Usually this is /usr/src/redhat/RPMS/<platform>/. + +If you have any further questions, please refer to the RPM documentation. Added: firmware/dfu-programmer/trunk/libs/libusb.lib =================================================================== (Binary files differ) Property changes on: firmware/dfu-programmer/trunk/libs/libusb.lib ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: firmware/dfu-programmer/trunk/src/arguments.c =================================================================== --- firmware/dfu-programmer/trunk/src/arguments.c (rev 0) +++ firmware/dfu-programmer/trunk/src/arguments.c 2008-06-05 08:38:07 UTC (rev 1217) @@ -0,0 +1,498 @@ +/* + * dfu-programmer + * + * $Id: arguments.c 58 2007-11-20 01:24:54Z schmidtw $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "config.h" +#include "arguments.h" + +struct option_mapping_structure { + const char *name; + int value; +}; + +struct target_mapping_structure { + const char *name; + enum targets_enum value; + enum device_type_enum device_type; + unsigned short chip_id; + unsigned short vendor_id; + unsigned int memory_size; + unsigned short flash_page_size; + bool initial_abort; + bool honor_interfaceclass; +}; + +/* NOTE FOR: at90usb1287, at90usb1286, at90usb647, at90usb646, at90usb162, at90usb82 + * + * The actual size of the user-programmable section is limited by the + * space needed by the bootloader. The size of the bootloader is set + * by BOOTSZ0/BOOTSZ1 fuse bits; here we assume the factory default and + * maximum of 4K words. The window used for the bootloader is at the top + * of the of memory. + */ + +/* ----- target specific structures ----------------------------------------- */ +static struct target_mapping_structure target_map[] = { + { "at89c51snd1c", tar_at89c51snd1c, device_8051, 0x2FFF, 0x03eb, 0x10000, 128, false, true }, + { "at89c5130", tar_at89c5130, device_8051, 0x2FFD, 0x03eb, 0x04000, 128, false, true }, + { "at89c5131", tar_at89c5131, device_8051, 0x2FFD, 0x03eb, 0x08000, 128, false, true }, + { "at89c5132", tar_at89c5132, device_8051, 0x2FFF, 0x03eb, 0x10000, 128, false, true }, + { "at90usb1287", tar_at90usb1287, device_AVR, 0x2FFB, 0x03eb, 0x1E000, 128, true, false }, + { "at90usb1286", tar_at90usb1286, device_AVR, 0x2FFB, 0x03eb, 0x1E000, 128, true, false }, + { "at90usb647", tar_at90usb647, device_AVR, 0x2FFB, 0x03eb, 0x0E000, 128, true, false }, + { "at90usb646", tar_at90usb646, device_AVR, 0x2FFB, 0x03eb, 0x0E000, 128, true, false }, + { "at90usb162", tar_at90usb162, device_AVR, 0x2FFA, 0x03eb, 0x03000, 128, true, false }, + { "at90usb82", tar_at90usb82, device_AVR, 0x2FFA, 0x03eb, 0x01000, 128, true, false }, + { NULL } +}; + +/* ----- command specific structures ---------------------------------------- */ +static struct option_mapping_structure command_map[] = { + { "configure", com_configure }, + { "dump", com_dump }, + { "erase", com_erase }, + { "flash", com_flash }, + { "get", com_get }, + { "reset", com_reset }, + { "start", com_start_app }, + { "version", com_version }, + { NULL } +}; + +/* ----- configure specific structures -------------------------------------- */ +static struct option_mapping_structure configure_map[] = { + { "BSB", conf_BSB }, + { "SBV", conf_SBV }, + { "SSB", conf_SSB }, + { "EB", conf_EB }, + { "HSB", conf_HSB }, + { NULL } +}; + +/* ----- get specific structures -------------------------------------- */ +static struct option_mapping_structure get_map[] = { + { "bootloader-version", get_bootloader }, + { "ID1", get_ID1 }, + { "ID2", get_ID2 }, + { "BSB", get_BSB }, + { "SBV", get_SBV }, + { "SSB", get_SSB }, + { "EB", get_EB }, + { "manufacturer", get_manufacturer }, + { "family", get_family }, + { "product-name", get_product_name }, + { "product-revision", get_product_rev }, + { "HSB", get_HSB }, + { NULL } +}; + + +static void usage() +{ + struct target_mapping_structure *map = NULL; + + map = target_map; + + fprintf( stderr, PACKAGE_STRING "\n"); + fprintf( stderr, "Usage: dfu-programmer target command [command-options] " + "[global-options] [file|data]\n" ); + fprintf( stderr, "targets:\n" ); + while( 0 != *((int *) map) ) { + fprintf( stderr, " %s\n", map->name ); + map++; + } + fprintf( stderr, "global-options: --quiet, --debug level\n" ); + fprintf( stderr, "commands:\n" ); + fprintf( stderr, " configure {BSB|SBV|SSB|EB|HSB} " + "[--suppress-validation] [global-options] data\n" ); + fprintf( stderr, " dump " + "[global-options]\n" ); + fprintf( stderr, " erase " + "[--suppress-validation] [global-options]\n" ); + fprintf( stderr, " flash " + "[--suppress-validation] [global-options] file\n" ); + fprintf( stderr, " get {bootloader-version|ID1|ID2|BSB|SBV|SSB|EB|\n" + " manufacturer|family|product-name|\n" + " product-revision|HSB} " + "[global-options]\n" ); + fprintf( stderr, " reset [global-options]\n" ); + fprintf( stderr, " start [global-options]\n" ); + fprintf( stderr, " version [global-options]\n" ); +} + +static int assign_option( int *arg, + char *value, + struct option_mapping_structure *map ) +{ + while( 0 != *((int *) map) ) { + if( 0 == strcasecmp(value, map->name) ) { + *arg = map->value; + return 0; + } + + map++; + } + + return -1; +} + + +static int assign_target( struct programmer_arguments *args, + char *value, + struct target_mapping_structure *map ) +{ + while( 0 != *((int *) map) ) { + if( 0 == strcasecmp(value, map->name) ) { + args->target = map->value; + args->chip_id = map->chip_id; + args->vendor_id = map->vendor_id; + args->device_type = map->device_type; + args->memory_size = map->memory_size; + args->flash_page_size = map->flash_page_size; + args->initial_abort = map->initial_abort; + args->honor_interfaceclass = map->honor_interfaceclass; + args->top_memory_address = map->memory_size - 1; + switch( args->device_type ) { + case device_8051: + strncpy( args->device_type_string, "8051", + DEVICE_TYPE_STRING_MAX_LENGTH ); + break; + case device_AVR: + strncpy( args->device_type_string, "AVR", + DEVICE_TYPE_STRING_MAX_LENGTH ); + break; + } + return 0; + } + + map++; + } + + return -1; +} + + +static int assign_global_options( struct programmer_arguments *args, + int argc, + char **argv ) +{ + int i = 0; + + /* Find '--quiet' if it is here */ + for( i = 0; i < argc; i++ ) { + if( 0 == strcmp("--quiet", argv[i]) ) { + *argv[i] = '\0'; + args->quiet = 1; + break; + } + } + /* Find '--suppress-validation' if it is here - even though it is not + * used by all this is easier. */ + for( i = 0; i < argc; i++ ) { + if( 0 == strcmp("--suppress-validation", argv[i]) ) { + *argv[i] = '\0'; + + switch( args->command ) { + case com_configure: + args->com_configure_data.suppress_validation = 1; + break; + case com_erase: + args->com_erase_data.suppress_validation = 1; + break; + case com_flash: + args->com_flash_data.suppress_validation = 1; + break; + default: + /* not supported. */ + return -1; + } + + break; + } + } + + + /* Find '--debug' if it is here */ + for( i = 0; i < argc; i++ ) { + if( 0 == strncmp("--debug", argv[i], 7) ) { + + if( 0 == strncmp("--debug=", argv[i], 8) ) { + if( 1 != sscanf(argv[i], "--debug=%i", &debug) ) + return -2; + } else { + if( (i+1) >= argc ) + return -3; + + if( 1 != sscanf(argv[i+1], "%i", &debug) ) + return -4; + + *argv[i+1] = '\0'; + } + *argv[i] = '\0'; + break; + } + } + + return 0; +} + + +static int assign_com_configure_option( struct programmer_arguments *args, + int parameter, + char *value ) +{ + /* name & value */ + if( 0 == parameter ) { + /* name */ + if( 0 != assign_option((int *) &(args->com_configure_data.name), + value, configure_map) ) + { + return -1; + } + } else { + int temp = 0; + /* value */ + if( 1 != sscanf(value, "%i", &(temp)) ) + return -2; + + /* ensure the range is greater than 0 */ + if( temp < 0 ) + return -3; + + args->com_configure_data.value = temp; + } + + return 0; +} + + +static int assign_com_flash_option( struct programmer_arguments *args, + int parameter, + char *value ) +{ + /* file */ + args->com_flash_data.original_first_char = *value; + args->com_flash_data.file = value; + + return 0; +} + + +static int assign_com_get_option( struct programmer_arguments *args, + int parameter, + char *value ) +{ + /* name */ + if( 0 != assign_option((int *) &(args->com_get_data.name), + value, get_map) ) + { + return -1; + } + + return 0; +} + + +static int assign_command_options( struct programmer_arguments *args, + int argc, + char **argv ) +{ + int i = 0; + int param = 0; + int required_params = 0; + + /* Deal with all remaining command-specific arguments. */ + for( i = 0; i < argc; i++ ) { + if( '\0' == *argv[i] ) + continue; + + switch( args->command ) { + case com_configure: + required_params = 2; + if( 0 != assign_com_configure_option(args, param, argv[i]) ) + return -1; + break; + + case com_flash: + required_params = 1; + if( 0 != assign_com_flash_option(args, param, argv[i]) ) + return -3; + break; + + case com_get: + required_params = 1; + if( 0 != assign_com_get_option(args, param, argv[i]) ) + return -4; + break; + + default: + return -5; + } + + *argv[i] = '\0'; + param++; + } + + if( required_params != param ) + return -6; + + return 0; +} + + +static void print_args( struct programmer_arguments *args ) +{ + const char *command = "(unknown)"; + const char *target = "(unknown)"; + int i; + + for( i = 0; i < sizeof(target_map) / sizeof(target_map[0]); i++ ) { + if( args->target == target_map[i].value ) { + target = target_map[i].name; + break; + } + } + + for( i = 0; i < sizeof(command_map) / sizeof(command_map[0]); i++ ) { + if( args->command == command_map[i].value ) { + command = command_map[i].name; + break; + } + } + + printf( " target: %s\n", target ); + printf( " chip_id: 0x%04x\n", args->chip_id ); + printf( " vendor_id: 0x%04x\n", args->vendor_id ); + printf( " command: %s\n", command ); + printf( " quiet: %s\n", (0 == args->quiet) ? "false" : "true" ); + printf( " debug: %d\n", debug ); + printf( "device_type: %s\n", args->device_type_string ); + printf( "------ command specific below ------\n" ); + + switch( args->command ) { + case com_configure: + printf( " name: %d\n", args->com_configure_data.name ); + printf( " validate: %s\n", + (args->com_configure_data.suppress_validation) ? + "false" : "true" ); + printf( " value: %d\n", args->com_configure_data.value ); + break; + case com_erase: + printf( " validate: %s\n", + (args->com_erase_data.suppress_validation) ? + "false" : "true" ); + break; + case com_flash: + printf( " validate: %s\n", + (args->com_flash_data.suppress_validation) ? + "false" : "true" ); + printf( " hex file: %s\n", args->com_flash_data.file ); + break; + case com_get: + printf( " name: %d\n", args->com_get_data.name ); + break; + default: + break; + } + printf( "\n" ); + fflush( stdout ); +} + + +int parse_arguments( struct programmer_arguments *args, + int argc, + char **argv ) +{ + int i; + int status = 0; + + if( NULL == args ) + return -1; + + /* initialize the argument block to empty, known values */ + args->target = tar_none; + args->command = com_none; + args->quiet = 0; + + /* Make sure there are the minimum arguments */ + if( argc < 3 ) { + status = -2; + goto done; + } + + if( 0 != assign_target(args, argv[1], target_map) ) { + status = -3; + goto done; + } + + if( 0 != assign_option((int *) &(args->command), argv[2], command_map) ) { + status = -4; + goto done; + } + + /* These were taken care of above. */ + *argv[0] = '\0'; + *argv[1] = '\0'; + *argv[2] = '\0'; + + if( 0 != assign_global_options(args, argc, argv) ) { + status = -5; + goto done; + } + + if( 0 != assign_command_options(args, argc, ar... [truncated message content] |