avrp-1.0-beta3/COPYING100644 2117 311 43217 6603744704 13274 0ustar jonahguests 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. Copyright (C) 19yy 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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) 19yy 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. , 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. avrp-1.0-beta3/Makefile.amiga.gcc100644 2117 311 3323 6603744704 15463 0ustar jonahguests#******************************************************************** # Makefile for gcc (Geek Gadget) on Amiga #******************************************************************** CC = gcc LD = gcc CFLAGS = -O3 -Wall LDFLAGS = -s SOURCES = avrp.c io_amiga.c talking.c file.c memtalk.c OBJECTS = $(SOURCES:.c=.o) OBJ_ALL = $(OBJECTS) args.o stdextra.o DISTFILES = *.c *.h README Makefile.* avrp.def COPYING avrp.1 avrp.txt strip-headers ARCHFILES = $(DISTFILES) ex/* tab2space space2tab ToDo BINFILES = avrp avrp.def README COPYING avrp.1 avrp.txt VERSION = 1.0-beta3 #******************************************************************** all: avrp install: avrp copy avrp.def env: copy avrp.def envarc: copy avrp c: clean: rm -f avrp *.o *.p *~ avrp: $(OBJ_ALL) $(LD) -o avrp $(OBJ_ALL) $(LDFLAGS) $(OBJECTS): avrp.h args.h misc.h args.o: args.h misc.h stdextra.o: misc.h talking.o memtalk.o: talk.h avrp.txt: avrp.1 groff -man -Tascii avrp.1 | ./strip-headers | col -bx > avrp.txt #******************************************************************** disk: archive copy avrp.tar.gz pc0:avrp.tgz archive: avrp.tar.gz avrp.tar.gz: $(ARCHFILES) tar cvf avrp.tar $(ARCHFILES) gzip -9 -f avrp.tar dist: avrp-$(VERSION).tar.gz avrp-$(VERSION).tar.gz: $(DISTFILES) mkdir avrp-$(VERSION) cp $(DISTFILES) avrp-$(VERSION)/ tar cvf avrp-$(VERSION).tar avrp-$(VERSION)/* gzip -9 -f avrp-$(VERSION).tar rm -r avrp-$(VERSION) bin: avrp-$(VERSION)-Amiga-ixemul.lha avrp-$(VERSION)-Amiga-ixemul.lha: $(BINFILES) mkdir avrp-$(VERSION) cp $(BINFILES) avrp-$(VERSION)/ lha -xr u avrp-$(VERSION)-Amiga-ixemul.lha avrp-$(VERSION)/* rm -r avrp-$(VERSION) #******************************************************************** avrp-1.0-beta3/Makefile.amiga.sas100644 2117 311 3136 6603744704 15517 0ustar jonahguests#******************************************************************** # Makefile for SAS/C on Amiga #******************************************************************** CC = sc LD = sc CFLAGS = NOVERSION OPTIMIZE STRINGMERGE LDFLAGS = NOVERSION SOURCES = avrp.c io_amiga.c talking.c file.c memtalk.c OBJECTS = avrp.o io_amiga.o talking.o file.o memtalk.o OBJ_ALL = $(OBJECTS) args.o stdextra.o DISTFILES = *.c *.h README Makefile.* avrp.def COPYING avrp.1 ARCHFILES = $(DISTFILES) ex/* tab2space space2tab ToDo BINFILES = avrp avrp.def README COPYING avrp.1 avrp.txt VERSION = 1.0-beta3 #******************************************************************** all: avrp install: avrp copy avrp.def env: copy avrp.def envarc: copy avrp c: clean: delete avrp avrp.info \#?.o \#?.lnk avrp: $(OBJ_ALL) $(LD) link $(OBJ_ALL) $(LDFLAGS) $(OBJECTS): avrp.h args.h misc.h args.o: args.h misc.h stdextra.o: misc.h talking.o memtalk.o: talk.h #******************************************************************** disk: archive copy avrp.lha df0:avrp.lha archive: avrp.lha avrp.lha: #$(ARCHFILES) lha -xr u avrp.lha $(ARCHFILES) dist: avrp-$(VERSION).lha avrp-$(VERSION).lha: #$(DISTFILES) makedir avrp-$(VERSION) copy $(DISTFILES) TO avrp-$(VERSION)/ lha -xr u avrp-$(VERSION).lha avrp-$(VERSION)/* delete ALL avrp-$(VERSION) bin: avrp-$(VERSION)-Amiga.lha avrp-$(VERSION)-Amiga.lha: $(BINFILES) makedir avrp-$(VERSION) copy $(BINFILES) avrp-$(VERSION)/ lha -xr u avrp-$(VERSION)-Amiga.lha avrp-$(VERSION)/* delete ALL avrp-$(VERSION) #******************************************************************** avrp-1.0-beta3/Makefile.linux100644 2117 311 3061 6603744704 15010 0ustar jonahguests#******************************************************************** # Makefile for gcc on linux and FreeBSD #******************************************************************** CC = gcc LD = gcc CFLAGS = -O3 -Wall LDFLAGS = -s SOURCES = avrp.c io_linux.c talking.c file.c memtalk.c OBJECTS = $(SOURCES:.c=.o) OBJ_ALL = $(OBJECTS) args.o stdextra.o DISTFILES = *.c *.h README Makefile.* avrp.def COPYING avrp.1 avrp.txt strip-headers ARCHFILES = $(DISTFILES) ex/* tab2space space2tab ToDo BINFILES = avrp avrp.def README COPYING avrp.1 avrp.txt VERSION = 1.0-beta3 #******************************************************************** all: avrp install: avrp cp avrp.def /usr/local/etc cp avrp /usr/local/bin cp avrp.1 /usr/local/man/man1 chmod +r /usr/local/man/man1/avrp.1 clean: rm -f avrp *.o *.p *~ avrp: $(OBJ_ALL) $(LD) -o avrp $(OBJ_ALL) $(LDFLAGS) $(OBJECTS): avrp.h args.h misc.h args.o: args.h misc.h stdextra.o: misc.h talking.o memtalk.o: talk.h avrp.txt: avrp.1 groff -man -Tascii avrp.1 | ./strip-headers | col -bx > avrp.txt #******************************************************************** disk: archive mcopy -ovm avrp.tar.gz a:avrp.tgz archive: avrp.tar.gz avrp.tar.gz: $(ARCHFILES) tar cvf avrp.tar $(ARCHFILES) gzip -9 -f avrp.tar dist: avrp-$(VERSION).tar.gz avrp-$(VERSION).tar.gz: $(DISTFILES) mkdir avrp-$(VERSION) cp $(DISTFILES) avrp-$(VERSION)/ tar cvf avrp-$(VERSION).tar avrp-$(VERSION)/* gzip -9 -f avrp-$(VERSION).tar rm -r avrp-$(VERSION) #******************************************************************** avrp-1.0-beta3/Makefile.win32.mvc100700 2117 311 1553 6603744704 15374 0ustar jonahguests#******************************************************************** # Makefile for Mickeysoft visual c++ #******************************************************************** CC = cl LD = link CFLAGS = -nologo -Ox LDFLAGS = -nologo SOURCES = avrp.c io_win32.c talking.c file.c memtalk.c OBJECTS = $(SOURCES:.c=.obj) OBJ_ALL = $(OBJECTS) args.obj stdextra.obj VERSION = 1.0-beta3 #******************************************************************** all: avrp.exe install: avrp.exe copy avrp.def c:\bin\ copy avrp.exe c:\bin\ clean: del *.obj del avrp.exe avrp.exe: $(OBJ_ALL) $(LD) $(OBJ_ALL) $(LDFLAGS) $(OBJECTS): avrp.h args.h misc.h args.obj: args.h misc.h stdextra.obj: misc.h talking.obj memtalk.obj: talk.h #******************************************************************** #******************************************************************** avrp-1.0-beta3/README100644 2117 311 10372 6603744704 13115 0ustar jonahguests avrp - Ateml AVR programming software to use with Atmel's serial-port programmers. Copyright (C) 1997-1998 Jon Anders Haugum 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Author of avrp can be reached at: email: jonah@colargol.tihlde.hist.no www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html Postal address: Jon Anders Haugum Øvre Møllenbergsgt 52 7014 Trondheim ---------------------------------------------------------------------- 1. Introduction avrp works on serial-port programmers which use Atmel's communication standard for serial-port programmers. These programmers can program AVR (and other) chips both in serial and parallel mode. These programmers are known: AVR ICP - Atmel In-circuit programmer AVR PPR - Atmel parallel programmer AVR DEV - Atmel development board AVR A.G - Parallel mode programmer by Adrian Godwin Adrian Godwin's programmer can be found on http://www.fangorn.demon.co.uk Instruction on how to build Atmel's in-circuit programmer can be found on Atmel's homepage (http://www.atmel.com). Look for application note avr910 avrp is currently supporting these systems: Linux FreeBSD AmigaOS win32 (windows 95++ and NT) The source-code part of Atmel's application note AVR910 was used to determine how to communicate with these programmers. ---------------------------------------------------------------------- 2. Installation To install avrp you should copy the avrp-executeable to a apropriate location. avrp.def should be put in the system-dependent config dir. Although it's location can be overrided with the -d option or by setting the environment variable ARVP_DEFFILE to where avrp.def can be found. To compile you should rename the apropritate makefile, and do a make (use smake for Amiga SAS/C, and nmake for Mickeysoft visual c++). 2.1 Linux and FreeBSD First you should compile the source by typing make. avrp should be copied to /usr/local/bin/ or other apropriate directory. avrp.def should be copied to /usr/local/etc/ Doing a 'make install' will do the same thing. You should also consider to set the environment variable AVRP_SERIALPORT to the serial port you are using. Example (bash): export AVRP_SERIALPORT=/dev/ttyS1 2.2 AmigaOS avrp should be copied to c: or other apropriate directory. avrp.def should be located in env: (Or put it in envarc: to make it permament in the system.) If you are using the source-distribution a 'make install' will do the same. You should also consider to set the environment variable AVRP_SERIALPORT to the serial device and unit you are using. Example: setenv AVRP_SERIALPORT serial.device:0 2.3 win32 (Windows 95 (++) and Windows NT) avrp.exe should be copied to an apropriate location. A 'nmake install' will copy it and avrp.def to c:\bin\ avrp.def should be located in c:\bin\ but it can be overided if desireable. You should also consider to set the environment variable AVRP_SERIALPORT to the serial port you are using. This can be done with set in windows95 and in NT you must do it in system in your control panel. Example win95: set AVRP_SERIALPORT=COM2 ---------------------------------------------------------------------- 4. Adding support for other systems avrp is written mostly in ANSI-C, so it should be possible to port it to other 32-bit systems. Checklist to do a port: -Make a system dependent io_xxxxx.c file -Edit avrp.h to support your system -Make a system-dependent Makefile -Send your modification to the author, so they can be included in the next release. avrp-1.0-beta3/args.c100644 2117 311 11231 6603744703 13327 0ustar jonahguests/*********************************************************************** * args - Argument reading system * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of args can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include "misc.h" #include "args.h" struct args *alloc_args(int arg_count) { struct args *args; args = malloc(sizeof(struct args)); if(args) { args->arg = malloc(sizeof(struct arg) * arg_count); if(args->arg) { args->count = arg_count; args->first_data = NULL; return(args); } free(args); } printf("Error: Unable to allocate memory\n"); return(NULL); } int read_args(struct args *args, int argc, char *argv[]) { int i, j, k, ok = True, i_old; struct data_list **last_data, *data; args->first_data = NULL; last_data = &args->first_data; for(i = 1; (i < argc) && ok; i++) { if(argv[i][0] == '-') { if(argv[i][1] == '-') { j = 0; while((args->arg[j].longarg ? strcmp(&argv[i][2], args->arg[j].longarg) : True) && (j != args->count)) j++; if(j == args->count) { printf("Error: Unknown option: %s\n", argv[i]); ok = False; } else { switch(args->arg[j].type) { case ARGTYPE_STRING: if((i + 1) == argc) { printf("Error: No argument supplied with option: %s\n", argv[i]); ok = False; } else args->arg[j].data = argv[++i]; break; case ARGTYPE_BOOLEAN: args->arg[j].data = (char *)True; break; case ARGTYPE_STRING_MULTI: last_data = (struct data_list **)&args->arg[j].data; break; } } } else { last_data = &args->first_data; // ToDo: Sjekk for enkel - for(k = 1, i_old = i; (argv[i][k] != '\0') && ok && (i == i_old); k++) { j = 0; while((argv[i][k] != args->arg[j].letter) && (j != args->count)) j++; if(j == args->count) { printf("Error: Unknown option: -%c\n", argv[i][k]); ok = False; } else { switch(args->arg[j].type) { case ARGTYPE_STRING: if(argv[i][k + 1] != '\0') { printf("Error: Option -%c must be followed by it's argument\n", argv[i][k]); ok = False; } else { if((i + 1) == argc) { printf("Error: No argument supplied with option: -%c\n", argv[i][k]); ok = False; } else args->arg[j].data = argv[++i]; } break; case ARGTYPE_BOOLEAN: args->arg[j].data = (char *)True; break; case ARGTYPE_STRING_MULTI: last_data = (struct data_list **)&args->arg[j].data; break; } } } } } else { while(*last_data) last_data = &((*last_data)->next); data = malloc(sizeof(struct data_list)); if(data) { data->next = NULL; data->data = argv[i]; *last_data = data; last_data = &data->next; } else { printf("Error: Unable to allocate memory\n"); ok = False; } } } return(ok); } void free_args(struct args *args) { int i; struct data_list *data, *temp; for(data = args->first_data; data;) { temp = data; data = data->next; free(temp); } for(i = 0; i != args->count; i++) if(args->arg[i].type == ARGTYPE_STRING_MULTI) for(data = args->arg[i].data; data;) { temp = data; data = data->next; free(temp); } free(args); } void define_arg(struct args *args, int index, int type, char letter, char *longarg, void *def_value) { args->arg[index].type = type; args->arg[index].letter = letter; args->arg[index].longarg = longarg; args->arg[index].data = def_value; } avrp-1.0-beta3/args.h100644 2117 311 3645 6603744704 13327 0ustar jonahguests/*********************************************************************** * args - Argument reading system * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of args can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ enum { ARGTYPE_BOOLEAN = 0, /* boolean Value (0 = False) */ ARGTYPE_STRING, /* Stringpointer in Data */ ARGTYPE_STRING_MULTI /* List of strings in Data */ }; #define GET_ARG(args,argnum) (args->arg[argnum].data) #define SET_ARG(args,argnum,value) (args->arg[argnum].data = (void *)value) struct args { struct arg *arg; int count; struct data_list *first_data; }; struct arg { int type; char letter; char *longarg; void *data; }; struct data_list { struct data_list *next; void *data; }; struct args *alloc_args(int arg_count); int read_args(struct args *args, int argc, char *argv[]); void free_args(struct args *args); void define_arg(struct args *args, int index, int type, char letter, char *longarg, void *def_value); avrp-1.0-beta3/avrp.1100644 2117 311 11344 6603744704 13267 0ustar jonahguests.TH avrp 1 "28 September 1998" "Version 1.0 beta 3" .SH NAME avrp \- Atmel AVR programming software to use with Atmel's serial-port programmers .SH SYNOPSIS .B avrp [\-s ] [\-a ] [\-prv] [\-f ] [\-e ] [\-d ] [\-l ] [\-\-enable ] [\-\-disable ] [\-\-version] [\-\-help] [\-qIh] .SH DESCRIPTION .B avrp works on serial-port programmers which use Atmel's communication protocol for serial-port programmers. These programmers can program AVR (and other) chips both in serial and parallel mode. .PP These programmers are known: AVR ICP \- Atmel In-circuit programmer AVR PPR \- Atmel parallel programmer AVR DEV \- Atmel development board AVR A.G \- Parallel mode programmer by Adrian Godwin .PP Adrian Godwin's programmer can be found on http://www.fangorn.demon.co.uk .PP Instruction on how to build Atmel's in-circuit programmer can be found on Atmel's homepage (http://www.atmel.com). Look for application note avr910 .PP avrp is currently supporting these systems: Linux FreeBSD AmigaOS win32 (windows 95++ and NT) .PP The source-code part of Atmel's application note AVR910 was used to determine how to communicate with these programmers. .PP .SH OPTIONS Several option can be given after one '\-', but if an option requires an argument; the argument must be given after that option. .IP "\-s " Specifies which serial port to talk through. This option can be avoided if you set the environment variable AVRP_SERIALPORT .IP "\-a " Specifies what kind of chip to talk to. Use '-a list' for chip type to get a list of supported devices. You can use the shortest possible abbreviation to identify a chip. This option can be avoided if you set the environment variable AVRP_AVRTYPE .IP \-p Program a chip \-f and/or \-e must be specified to determine which files to read from. (\-f specifes flash, and \-e eeprom) .IP \-r Read a chip \-f and/or \-e must be specified to determine which files to write to. (\-f specifes flash, and \-e eeprom) .IP \-v Verify. Performs a standalone verify. (The program function will always do a inline verify) \-f and/or \-e must be specified to determine which files to read from. (\-f specifes flash, and \-e eeprom) .IP "\-f " Specifies which flash-file to read/write. Supportet formats are Intel HEX and Atmel's generic fileformat. .IP "\-e " Specifies which eeprom-file to read/write. Supportet formats are Intel HEX and Atmel's generic fileformat. .IP "\-l " Specifies lockmode to progam into the chip. Use '-l list' to get a list of possible lockmodes. .IP \-q Quiet. Don't write any progress information. Will speed up programming. .IP "\-d " Specifies the path and filename of avrp.def if default location is not possible. Can also be set with the environment variable AVRP_DEFFILE .IP \-I Ignores the signature in the chip. This is very useful if the signature in the chip have been destroyed in some way. .IP "\-\-enable " Enables specified fuses. .IP "\-\-disable " Disables specified fuses. .IP "\-\-autoinc" You can use this to speed up programming on newer programmer firmware. .IP \-\-version Print out version information. .IP "\-\-help \-h" Print out a short help text. .SH FILES .I /usr/local/etc/avrp.def .RS Definition file .RE .SH ENVIRONMENT .IP AVRP_SERIALPORT Specifies which serial port to use. .IP AVRP_AVRTYPE Specifies chip to talk to. .IP AVRP_DEFFILE Specifies the location of avrp.def .SH EXAMPLES Print out information on the programmer: avrp \-s /dev/ttyS1 Same as above, but also give information on the inserted chip: avrp \-s /dev/ttyS1 \-a AT90S1200-D/E/F Program a chip (flash only, and using a short chip-descriptor): avrp \-s /dev/ttyS1 \-a 1200-d \-p \-f avr910.rom Read a chip (flash and eeprom, AVRP_SERIALPORT is set): avrp \-a 8515 \-rf test.hex \-e test.eep.hex .SH COPYRIGHT Copyright (C) 1997-1998 Jon Anders Haugum 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place \- Suite 330, Boston, MA 02111-1307, USA. .SH AUTHOR Jon Anders Haugum avrp-1.0-beta3/avrp.c100644 2117 311 27075 6603744703 13360 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include "avrp.h" const char *Title = "avrp 1.0 beta 3 (28 September 1998)\n" "Copyright (C) 1997-1998 Jon Anders Haugum\n" " avrp comes with NO WARRANTY, to the extent permitted by law.\n" " You may redistribute copies of avrp under the terms\n" " of the GNU General Public License.\n" " For more information about these matters, see the files named COPYING.\n"; const char *Usage = #ifdef __amigaos__ "usage: avrp [-s ] [-a ] [-prv]\n" #else "usage: avrp [-s ] [-a ] [-prv]\n" #endif " [-f ] [-e ] [-l ]\n" " [--enable ] [--disable ]\n" " [-d ] [-qIh] [--version] [--help]\n" "\n" #ifdef __amigaos__ " -s : Specifies which serial port and unit to use (e.g. serial.device:0)\n" #elif _WIN32 " -s : Specifies which serial port to use (e.g. COM2)\n" #else " -s : Specifies which serial port to use (e.g. /dev/ttyS1)\n" #endif " -a : Specifies chip to program/read (use '-a list' to get a list)\n" " -p : Program a chip (-f or -e must be specified)\n" " -r : Read a chip (-f or -e must be specified)\n" " -v : Verify (-f or -e must be specified)\n" " -f : Flashfile to write/read\n" " -e : Eepromfile to write/read\n" " -l : Lockmode (use '-l list' to get a list of modes)\n" " -q : Quiet. Do not print out progress (little speedup)\n" " -d : Specifies name and path to avrp.def\n" " -I : Ignore chip signature\n" " --enable : Enable fuse(s)\n" " --disable : Disable fuse(s)\n" " --autoinc : Programmer support automatic address incrementation\n" " --version : Version information\n" " --help, -h : This help text\n" "\n" "Report bugs to jonah@colargol.tihlde.hist.no\n"; int main(int argc, char *argv[]) { int ShowUsage = False; char *temp_env; struct ProgramInfo *PI; struct args *args; args = alloc_args(ARG_COUNT); if(args) { define_arg(args, ARG_SERIALPORT, ARGTYPE_STRING, 's', NULL, getenv("AVRP_SERIALPORT")); define_arg(args, ARG_AVRTYPE , ARGTYPE_STRING, 'a', NULL, getenv("AVRP_AVRTYPE")); define_arg(args, ARG_PROG , ARGTYPE_BOOLEAN, 'p', NULL, False); define_arg(args, ARG_READ , ARGTYPE_BOOLEAN, 'r', NULL, False); define_arg(args, ARG_VERIFY , ARGTYPE_BOOLEAN, 'v', NULL, False); define_arg(args, ARG_FLASH , ARGTYPE_STRING, 'f', NULL, NULL); define_arg(args, ARG_EEPROM , ARGTYPE_STRING, 'e', NULL, NULL); define_arg(args, ARG_QUICK , ARGTYPE_BOOLEAN, 'q', NULL, False); temp_env = getenv("AVRP_DEFFILE"); define_arg(args, ARG_DEFFILE , ARGTYPE_STRING, 'd', NULL, temp_env ? temp_env : DEFFILENAME); define_arg(args, ARG_IGNORESIG , ARGTYPE_BOOLEAN, 'I', NULL, False); define_arg(args, ARG_LOCKMODE , ARGTYPE_STRING, 'l', NULL, NULL); define_arg(args, ARG_ENABLE , ARGTYPE_STRING_MULTI, 0, "enable", NULL); define_arg(args, ARG_DISABLE , ARGTYPE_STRING_MULTI, 0, "disable", NULL); define_arg(args, ARG_AUTOINC , ARGTYPE_BOOLEAN, 0, "autoinc", False); define_arg(args, ARG_VER , ARGTYPE_BOOLEAN, 0, "version", False); define_arg(args, ARG_HELP , ARGTYPE_BOOLEAN, 'h', "help", False); if(read_args(args, argc, argv)) { if(!GET_ARG(args, ARG_HELP) && ((argc != 1) || GET_ARG(args, ARG_SERIALPORT))) { if(!GET_ARG(args, ARG_VER)) { PI = GetPI(args); if(PI) { if(GET_ARG(args, ARG_SERIALPORT)) { PI->Ser = OpenSer((char *)GET_ARG(args, ARG_SERIALPORT)); if(PI->Ser) { if(InquireHW(PI)) { if(DetectAVRType(PI)) DoTheTalk(PI); } else printf("%s: No programmer found\n", (char *)GET_ARG(args, ARG_SERIALPORT)); CloseSer(PI->Ser); } } else printf("Missing argument: No serial port specified\n" #ifdef __amigaos__ "Use: -s \n" #else "Use: -s \n" #endif "Or set the environment variable: AVRP_SERIALPORT\n"); FreePI(PI); } } else printf("%s", Title); } else ShowUsage = True; } free_args(args); } else { ShowUsage = True; printf("\n"); } if(ShowUsage) { if(argc == 1) printf("%s\n", Title); printf("%s", Usage); } exit(EXIT_SUCCESS); } int DetectAVRType(struct ProgramInfo *PI) { int several_match = False, chiplist = False; struct ChipNode *CN; if(GET_ARG(PI->args, ARG_AVRTYPE)) { if(nocase_strcmp((char *)GET_ARG(PI->args, ARG_AVRTYPE), "list")) { for(CN = PI->FirstChipNode; CN; CN = CN->Next) if(nocase_strstr(CN->Name, (char *)GET_ARG(PI->args, ARG_AVRTYPE))) { if(PI->SelectedChipNode) several_match = True; PI->SelectedChipNode = CN; printf("Selected chip: %s %s %s with %dKB flash\n", CN->VendorNode->Name, CN->FamilyNode->Name, CN->Name, CN->FamilyNode->FlashSize); } } else chiplist = True; if(several_match) printf("Error: There were several chips that matched: %s\n" " You must be more specific\n", (char *)GET_ARG(PI->args, ARG_AVRTYPE)); else if(PI->SelectedChipNode) { if(PI->SelectedChipNode->Supported) return(True); else printf("Error: %s is not supported by your programmer\n", PI->SelectedChipNode->Name); } else { if(!chiplist) printf("Error: Unable to find a match to '%s' in %s\n", (char *)GET_ARG(PI->args, ARG_AVRTYPE), (char *)GET_ARG(PI->args, ARG_DEFFILE)); printf("The following chips are defined:\n"); for(CN = PI->FirstChipNode; CN; CN = CN->Next) { if(CN->Supported) printf(" %s (%s %s with %d kB flash)\n", CN->Name, CN->VendorNode->Name, CN->FamilyNode->Name, CN->FamilyNode->FlashSize); else printf(" %s (%s %s with %d kB flash) Not supported by programmer\n", CN->Name, CN->VendorNode->Name, CN->FamilyNode->Name, CN->FamilyNode->FlashSize); } } } else { printf("Missing argument: Type of AVR must be specified\n" "Use: -a \n" "Or set the environment variable: AVRP_AVRTYPE\n" "Shortest unique abbreviation can be used\n" "List of all supported chips can be obtained with: -a list\n"); } return(False); } struct ProgramInfo *GetPI(struct args *args) { int ok = False; struct ProgramInfo *PI; struct ChipNode *CN; struct VendorNode *VN; struct FamilyNode *FamN; struct ArchNode *AN; struct FuseNode *FuseN; struct LockNode *LN; PI = (struct ProgramInfo *)calloc(1, sizeof(struct ProgramInfo)); if(PI) { PI->args = args; if(ReadDefFile(PI)) { ok = True; for(FamN = PI->FirstFamilyNode; FamN; FamN = FamN->Next) { for(AN = PI->FirstArchNode; AN; AN = AN->Next) if(!strcmp(FamN->Name, AN->Name)) { FamN->ArchNode = AN; break; } if(!FamN->ArchNode) { ok = False; printf("Error: %s: Can't find architecture %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), FamN->Name); } } for(CN = PI->FirstChipNode; CN; CN = CN->Next) { for(VN = PI->FirstVendorNode; VN; VN = VN->Next) if(VN->Code == ((CN->Sig >> 16) & 0xFF)) { CN->VendorNode = VN; break; } for(FamN = PI->FirstFamilyNode; FamN; FamN = FamN->Next) if(FamN->Code == ((CN->Sig >> 8) & 0xFF)) { CN->FamilyNode = FamN; break; } if(!(CN->VendorNode && CN->FamilyNode)) { ok = False; printf("Error: %s: No vendor and family matched the signature of %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), CN->Name); } else if(!CN->VendorNode) { ok = False; printf("Error: %s: No vendor matched the signature of %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), CN->Name); } else if(!CN->FamilyNode) { ok = False; printf("Error: %s: No family matched the signature of %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), CN->Name); } if(CN->FuseType != 0) { for(FuseN = PI->FirstFuseNode; FuseN; FuseN = FuseN->Next) if(FuseN->Num == CN->FuseType) { CN->FuseNode = FuseN; break; } if(!CN->FuseNode) { ok = False; printf("Error: %s: Can't find fusetype %d for %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), CN->FuseType, CN->Name); } } if(CN->LockType != 0) { for(LN = PI->FirstLockNode; LN; LN = LN->Next) if(LN->Num == CN->LockType) { CN->LockNode = LN; break; } if(!CN->LockNode) { ok = False; printf("Error: %s: Can't find locktype %d for %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), CN->LockType, CN->Name); } } } } if(!ok) { FreePI(PI); PI = NULL; } } else printf("Error: Unable to allocate memory\n"); return(PI); } void FreePI(struct ProgramInfo *PI) { void *Node; struct ChipNode *CN; struct VendorNode *VN; struct FamilyNode *FamN; struct ArchNode *AN; struct FuseNode *FuseN; struct FuseBitNode *FBN; struct LockNode *LN; struct LockBitNode *LBN; for(CN = PI->FirstChipNode; CN;) { if(CN->Name) free(CN->Name); Node = CN; CN = CN->Next; free(Node); } for(VN = PI->FirstVendorNode; VN;) { if(VN->Name) free(VN->Name); Node = VN; VN = VN->Next; free(Node); } for(FamN = PI->FirstFamilyNode; FamN;) { if(FamN->Name) free(FamN->Name); Node = FamN; FamN = FamN->Next; free(Node); } for(AN = PI->FirstArchNode; AN;) { if(AN->Name) free(AN->Name); Node = AN; AN = AN->Next; free(Node); } for(FuseN = PI->FirstFuseNode; FuseN;) { for(FBN = FuseN->FirstFuseBitNode; FBN;) { if(FBN->ShortName) free(FBN->ShortName); if(FBN->LongName) free(FBN->LongName); Node = FBN; FBN = FBN->Next; free(Node); } Node = FuseN; FuseN = FuseN->Next; free(Node); } for(LN = PI->FirstLockNode; LN;) { for(LBN = LN->FirstLockBitNode; LBN;) { if(LBN->LongName) free(LBN->LongName); Node = LBN; LBN = LBN->Next; free(Node); } Node = LN; LN = LN->Next; free(Node); } free(PI); } avrp-1.0-beta3/avrp.def100644 2117 311 6606 6603744704 13652 0ustar jonahguests; For updates see: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html ; Set version of this define file. Do NOT change this line! AVRP.DEF 2.0 (28 September 1998) ; Mark start of chip section #CHIPS ;----------------------------------------------------------- ; Name: | Device | Eeprom | Signature: | Fuse | Lock | ; | code: | Size: | | bits | bits | ; | | | | type: | type: | ; | | (bytes) | | | | ;----------------------------------------------------------- AT90S1200-C 0x12 64 0x1E9001 1 1 AT90S1200-D/E/F 0x13 64 0x1E9001 1 1 AT90S2313 0x20 128 0x1E9101 2 1 AT90S2323 0x48 128 0x1E9102 2 1 AT90S4414 0x28 256 0x1E9201 2 1 AT90S8515 0x38 512 0x1E9301 2 1 ; Non AVR devices AT89S8252 0x86 2048 0x1E7200 3 2 ;AT89LS8252 0x 2048 0x1E8200 ;AT89S53 0x 0 0x1E5300 ;AT89LS53 0x 0 0x1E6300 #END ; End of CHIPS section ; Mark start of vendor section #VENDORS ;-------------------------------------------------------------------- ; Code: | Vendor: | ;-------------------------------------------------------------------- 0x1E Atmel #END ; End of VENDORS section ; Mark start of family section #FAMILIES ;-------------------------------------------------------------------- ; Code: | Type: | KB flash: | ;-------------------------------------------------------------------- 0x90 AVR 1 0x91 AVR 2 0x92 AVR 4 0x93 AVR 8 0x72 8XC51 8 0x82 8XC51 8 0x53 8XC51 12 0x63 8XC51 12 #END ; End of FAMILIES section #ARCHITECTURES ;-------------------------------------------------------------------- ; Name: | Word | Need ; | size: | Flash ; | | erase: ;-------------------------------------------------------------------- AVR 2 1 8XC51 1 0 #END ; End of ARCHITECHTURES section ; Mark start of fuse section #FUSES ;-------------------------------------------------------------------- ; #DEFFUSE ; ; #DEFEND ;-------------------------------------------------------------------- #DEFFUSE 1 RCEN 0 "internal RC oscillator" SPIEN 5 "Serial Programming Mode" #DEFEND #DEFFUSE 2 FSTRT 0 "short start-up time" SPIEN 5 "Serial Programming Mode" #DEFEND #DEFFUSE 3 SPIEN 0 "Serial Programming Mode" #DEFEND #END ; END of FUSES section ; Mark start of lock section #LOCKS ;-------------------------------------------------------------------- ; #DEFLOCK ; ... ... ; ; ... ; #DEFEND ;-------------------------------------------------------------------- #DEFLOCK 1 2 2 1 6 7 1 1 1 "No program lock" 2 1 0 "Further programming of flash disabled" 3 0 0 "Further programming and verifying of flash disabled" #DEFEND #DEFLOCK 2 3 5 6 7 0 1 2 1 1 1 1 "No internal memory lock" 2 1 1 0 "Further programming of flash disabled" 3 1 0 0 "Further programming and verifying of flash disabled" 4 0 0 0 "Further programming and verifying of flash disabled, and external execution is disabled" #DEFEND #END ; End of LOCKS section avrp-1.0-beta3/avrp.h100644 2117 311 13050 6603744704 13352 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include "args.h" #include "misc.h" /* Handle SAS/C and older gcc on the Amiga */ #ifndef __amigaos__ #if defined(_AMIGA) || defined(__amiga__) #define __amigaos__ #endif #endif #ifdef __amigaos__ #define DEFFILENAME "env:avrp.def" #endif #if defined(__linux__) || defined(__FreeBSD__) #define DEFFILENAME "/usr/local/etc/avrp.def" #endif #ifdef _WIN32 #define DEFFILENAME "C:\\bin\\avrp.def" #endif #ifndef DEFFILENAME #error "Your system is not supported!" #endif #define DEFFILEVERSION 2 #define DEFFILEREVISION 0 /* Option enumeration */ enum { ARG_SERIALPORT = 0, /* -s */ ARG_AVRTYPE, /* -a */ ARG_PROG, /* -p */ ARG_READ, /* -r */ ARG_VERIFY, /* -v */ ARG_FLASH, /* -f */ ARG_EEPROM, /* -e */ ARG_QUICK, /* -q */ ARG_DEFFILE, /* -d */ ARG_IGNORESIG, /* -I */ ARG_LOCKMODE, /* -l */ ARG_ENABLE, /* --enable */ ARG_DISABLE, /* --disable */ ARG_AUTOINC, /* --autoinc */ ARG_VER, /* --version */ ARG_HELP, /* -h --help */ ARG_COUNT }; enum { FILETYPE_UNKNOWN = 0, FILETYPE_INTEL_HEX8M, FILETYPE_ATMEL_GENERIC }; /* Structures */ struct ProgramInfo { void *Ser; struct args *args; int ProgType; struct ChipNode *SelectedChipNode; /* List starts */ struct ChipNode *FirstChipNode; struct VendorNode *FirstVendorNode; struct FamilyNode *FirstFamilyNode; struct ArchNode *FirstArchNode; struct FuseNode *FirstFuseNode; struct LockNode *FirstLockNode; }; struct ChipNode { struct ChipNode *Next; char *Name; int Code; int EepromSize; int Sig; int Supported; struct VendorNode *VendorNode; struct FamilyNode *FamilyNode; int FuseType; struct FuseNode *FuseNode; int LockType; struct LockNode *LockNode; }; struct VendorNode { struct VendorNode *Next; int Code; char *Name; }; struct FamilyNode { struct FamilyNode *Next; int Code; char *Name; int FlashSize; struct ArchNode *ArchNode; }; struct ArchNode { struct ArchNode *Next; char *Name; int WordSize; int NeedFlashErase; }; struct FuseNode { struct FuseNode *Next; int Num; struct FuseBitNode *FirstFuseBitNode; }; struct FuseBitNode { struct FuseBitNode *Next; char *ShortName; int BitNum; char *LongName; }; struct LockNode { struct LockNode *Next; int Num; int NumberOfBits; int WriteBits; int ReadBits; struct LockBitNode *FirstLockBitNode; }; struct LockBitNode { struct LockBitNode *Next; int Mode; int Mask; char *LongName; }; struct DataFile { FILE *FP; int FileType; }; /* Prototypes */ /* avrp.c */ struct ProgramInfo *GetPI(struct args *args); int DetectAVRType(struct ProgramInfo *PI); void FreePI(struct ProgramInfo *PI); /* talking.c */ int InquireHW(struct ProgramInfo *PI); int InquireID(struct ProgramInfo *PI); int DoTheTalk(struct ProgramInfo *PI); int CheckLockAndErase(struct ProgramInfo *PI, unsigned char *Sig); int CheckSig(struct ProgramInfo *PI, unsigned char *Sig); int DoMoreTalk(struct ProgramInfo *PI); int Erase(struct ProgramInfo *PI); int DoFuses(struct ProgramInfo *PI); void print_comm_err(char comm); /* memtalk.c */ int Program(struct ProgramInfo *PI, int ProgWhat, int DoWhat); int prog_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr); int verify_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr); int Read(struct ProgramInfo *PI, int What); void Progress(int *StatAdr, int Adr, char DidWhat); /* file.c */ struct DataFile *OpenDataFile(char *FileName); void CloseDataFile(struct DataFile *DataFile); int ReadDefFile(struct ProgramInfo *PI); char *GetNextString(char *Buff, int *index); /* io_[linux|amiga|win32].c */ void *OpenSer(char *SerPort); void CloseSer(void *Ser); void SerWriteByte(void *Ser, unsigned char Byte); int SerReadData(void *Ser, unsigned char *Buff, int Count); /* stdextra.c */ char *nocase_strcmp(char *s, char *t); char *nocase_strncmp(char *s, char *t, int n); char *nocase_strstr(char *s, char *t); int atox(char *s); int atoi_n(char *s, int n); int atox_n(char *s, int n); avrp-1.0-beta3/avrp.txt100644 2117 311 13346 6603744704 13752 0ustar jonahguestsNAME avrp - Atmel AVR programming software to use with Atmel's serial-port programmers SYNOPSIS avrp [-s ] [-a ] [-prv] [-f ] [-e ] [-d ] [-l ] [--enable ] [--disable ] [--version] [--help] [-qIh] DESCRIPTION avrp works on serial-port programmers which use Atmel's communication protocol for serial-port programmers. These programmers can program AVR (and other) chips both in serial and parallel mode. These programmers are known: AVR ICP - Atmel In-circuit programmer AVR PPR - Atmel parallel programmer AVR DEV - Atmel development board AVR A.G - Parallel mode programmer by Adrian Godwin Adrian Godwin's programmer can be found on http://www.fan- gorn.demon.co.uk Instruction on how to build Atmel's in-circuit programmer can be found on Atmel's homepage (http://www.atmel.com). Look for application note avr910 avrp is currently supporting these systems: Linux FreeBSD AmigaOS win32 (windows 95++ and NT) The source-code part of Atmel's application note AVR910 was used to determine how to communicate with these pro- grammers. OPTIONS Several option can be given after one '-', but if an option requires an argument; the argument must be given after that option. -s Specifies which serial port to talk through. This option can be avoided if you set the environment variable AVRP_SERIALPORT -a Specifies what kind of chip to talk to. Use '-a list' for chip type to get a list of supported devices. You can use the shortest possible abbreviation to identify a chip. This option can be avoided if you set the environment variable AVRP_AVRTYPE -p Program a chip -f and/or -e must be specified to determine which files to read from. (-f specifes flash, and -e eeprom) -r Read a chip -f and/or -e must be specified to determine which files to write to. (-f specifes flash, and -e eeprom) -v Verify. Performs a standalone verify. (The pro- gram function will always do a inline verify) -f and/or -e must be specified to determine which files to read from. (-f specifes flash, and -e eeprom) -f Specifies which flash-file to read/write. Sup- portet formats are Intel HEX and Atmel's generic fileformat. -e Specifies which eeprom-file to read/write. Sup- portet formats are Intel HEX and Atmel's generic fileformat. -l Specifies lockmode to progam into the chip. Use '-l list' to get a list of possible lockmodes. -q Quiet. Don't write any progress information. Will speed up programming. -d Specifies the path and filename of avrp.def if default location is not possible. Can also be set with the environment variable AVRP_DEFFILE -I Ignores the signature in the chip. This is very useful if the signature in the chip have been destroyed in some way. --enable Enables specified fuses. --disable Disables specified fuses. --autoinc You can use this to speed up programming on newer programmer firmware. --version Print out version information. --help -h Print out a short help text. FILES /usr/local/etc/avrp.def Definition file ENVIRONMENT AVRP_SERIALPORT Specifies which serial port to use. AVRP_AVRTYPE Specifies chip to talk to. AVRP_DEFFILE Specifies the location of avrp.def EXAMPLES Print out information on the programmer: avrp -s /dev/ttyS1 Same as above, but also give information on the inserted chip: avrp -s /dev/ttyS1 -a AT90S1200-D/E/F Program a chip (flash only, and using a short chip- descriptor): avrp -s /dev/ttyS1 -a 1200-d -p -f avr910.rom Read a chip (flash and eeprom, AVRP_SERIALPORT is set): avrp -a 8515 -rf test.hex -e test.eep.hex COPYRIGHT Copyright (C) 1997-1998 Jon Anders Haugum 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Tem- ple Place - Suite 330, Boston, MA 02111-1307, USA. AUTHOR Jon Anders Haugum avrp-1.0-beta3/file.c100600 2117 311 26244 6603744703 13314 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include #include "avrp.h" struct DataFile *OpenDataFile(char *FileName) { int ok = False; struct DataFile *DataFile; unsigned char buff[8] = {0}; DataFile = (struct DataFile *)malloc(sizeof(struct DataFile)); if(DataFile) { DataFile->FP = fopen(FileName, "r"); if(DataFile->FP) { DataFile->FileType = FILETYPE_UNKNOWN; fgets(buff, 8, DataFile->FP); fseek(DataFile->FP, 0, SEEK_SET); if(buff[0] == ':') { printf("(Filetype seems to be Intel Hex)\n"); DataFile->FileType = FILETYPE_INTEL_HEX8M; } else if((buff[6] == ':') || (buff[4] == ':')) { printf("(Filetype seems to be Atmel generic)\n"); DataFile->FileType = FILETYPE_ATMEL_GENERIC; } if(DataFile->FileType == FILETYPE_UNKNOWN) printf("\nError: Unknown filetype!\n"); else ok = True; } else { printf("\n"); perror(FileName); } } else printf("\nError: Unable to allocate memory\n"); if(!ok) { CloseDataFile(DataFile); DataFile = NULL; } return(DataFile); } void CloseDataFile(struct DataFile *DataFile) { if(DataFile->FP) fclose(DataFile->FP); free(DataFile); } enum { PART_NONE = 0, PART_CHIP, PART_VENDOR, PART_FAMILY, PART_ARCHITECTURES, PART_FUSE, PART_LOCK }; int ReadDefFile(struct ProgramInfo *PI) { int ok = False, loopok, part = PART_NONE, i, j, ver = 0, rev = 0, first_lockline; char Buff[256], *temp; FILE *FP; struct ChipNode *CN, **LastCN = &PI->FirstChipNode; struct VendorNode *VN, **LastVN = &PI->FirstVendorNode; struct FamilyNode *FamN, **LastFamN = &PI->FirstFamilyNode; struct ArchNode *AN, **LastAN = &PI->FirstArchNode; struct FuseNode *FuseN = NULL, **LastFuseN = &PI->FirstFuseNode; struct FuseBitNode *FBN, **LastFBN; struct LockNode *LN = NULL, **LastLN = &PI->FirstLockNode; struct LockBitNode *LBN, **LastLBN; FP = fopen((char *)GET_ARG(PI->args, ARG_DEFFILE), "r"); if(FP) { loopok = True; ok = True; while(loopok && ok) { if(fgets(Buff, 256, FP)) { for(i = 0; (Buff[i] == ' ') || (Buff[i] == 9);) i++; if((Buff[i] != ';') && (Buff[i] != 10) && (Buff[i] != 13)) { if(ver == 0) { if(!strncmp("AVRP.DEF", &Buff[i], 8)) { i += 8; while((Buff[i] == ' ') || (Buff[i] == 9)) i++; j = i; while(isdigit(Buff[i])) i++; if(Buff[i] == '.') { Buff[i++] = '\0'; rev = atoi(GetNextString(Buff, &i)); } else Buff[i] = '\0'; ver = atoi(&Buff[j]); if(ver < DEFFILEVERSION) { printf("Error: %s: Found file version %d, and it should be version %d\n" " You should update %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), ver, DEFFILEVERSION, (char *)GET_ARG(PI->args, ARG_DEFFILE)); ok = False; } else if(ver > DEFFILEVERSION) { printf("Error: %s: Found file version %d, and it should be version %d\n" " You should update the avrp program\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), ver, DEFFILEVERSION); ok = False; } else if(rev < DEFFILEREVISION) { printf("Error: %s: Found file version %d.%d, and it should be version %d.%d or higher\n" " You should update %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE), ver, rev, DEFFILEVERSION, DEFFILEREVISION, (char *)GET_ARG(PI->args, ARG_DEFFILE)); ok = False; } } } else if(!strncmp("#END", &Buff[i], 4)) part = PART_NONE; else if(!strncmp("#CHIPS", &Buff[i], 6)) part = PART_CHIP; else if(!strncmp("#VENDORS", &Buff[i], 8)) part = PART_VENDOR; else if(!strncmp("#FAMILIES", &Buff[i], 9)) part = PART_FAMILY; else if(!strncmp("#ARCHITECTURES", &Buff[i], 14)) part = PART_ARCHITECTURES; else if(!strncmp("#FUSES", &Buff[i], 6)) part = PART_FUSE; else if(!strncmp("#LOCKS", &Buff[i], 6)) part = PART_LOCK; else { if(part == PART_NONE); else if(part == PART_CHIP) { CN = (struct ChipNode *)malloc(sizeof(struct ChipNode)); if(!CN) goto shit; CN->Next = NULL; CN->Name = NULL; CN->VendorNode = NULL; CN->FamilyNode = NULL; CN->FuseNode = NULL; CN->LockNode = NULL; CN->Supported = False; temp = GetNextString(Buff, &i); CN->Name = malloc(strlen(temp) + 1); if(!CN->Name) goto shit; strcpy(CN->Name, temp); CN->Code = atox(GetNextString(Buff, &i) + 2); CN->EepromSize = atoi(GetNextString(Buff, &i)); CN->Sig = atox(GetNextString(Buff, &i) + 2); CN->FuseType = atoi(GetNextString(Buff, &i)); CN->LockType = atoi(GetNextString(Buff, &i)); *LastCN = CN; LastCN = &CN->Next; } else if(part == PART_VENDOR) { VN = (struct VendorNode *)malloc(sizeof(struct VendorNode)); if(!VN) goto shit; VN->Next = NULL; VN->Name = NULL; VN->Code = atox(GetNextString(Buff, &i) + 2); temp = GetNextString(Buff, &i); VN->Name = malloc(strlen(temp) + 1); if(!VN->Name) goto shit; strcpy(VN->Name, temp); *LastVN = VN; LastVN = &VN->Next; } else if(part == PART_FAMILY) { FamN = (struct FamilyNode *)malloc(sizeof(struct FamilyNode)); if(!FamN) goto shit; FamN->Next = NULL; FamN->Name = NULL; FamN->ArchNode = NULL; FamN->Code = atox(GetNextString(Buff, &i) + 2); temp = GetNextString(Buff, &i); FamN->Name = malloc(strlen(temp) + 1); if(!FamN->Name) goto shit; strcpy(FamN->Name, temp); FamN->FlashSize = atoi(GetNextString(Buff, &i)); *LastFamN = FamN; LastFamN = &FamN->Next; } else if(part == PART_ARCHITECTURES) { AN = (struct ArchNode *)malloc(sizeof(struct ArchNode)); if(!AN) goto shit; AN->Next = NULL; AN->Name = NULL; temp = GetNextString(Buff, &i); AN->Name = malloc(strlen(temp) + 1); if(!AN->Name) goto shit; strcpy(AN->Name, temp); AN->WordSize = atoi(GetNextString(Buff, &i)); AN->NeedFlashErase = atoi(GetNextString(Buff, &i)); *LastAN = AN; LastAN = &AN->Next; } else if(part == PART_FUSE) { if(!strncmp(&Buff[i], "#DEFFUSE", 8)) { FuseN = (struct FuseNode *)malloc(sizeof(struct FuseNode)); if(!FuseN) goto shit; FuseN->Next = NULL; LastFBN = &FuseN->FirstFuseBitNode; i += 8; FuseN->Num = atoi(GetNextString(Buff, &i)); *LastFuseN = FuseN; LastFuseN = &FuseN->Next; } else if(!strncmp(&Buff[i], "#DEFEND", 7)) FuseN = NULL; else if(FuseN) { FBN = (struct FuseBitNode *)malloc(sizeof(struct FuseBitNode)); if(!FBN) goto shit; FBN->Next = NULL; FBN->ShortName = NULL; FBN->LongName = NULL; temp = GetNextString(Buff, &i); FBN->ShortName = malloc(strlen(temp) + 1); if(!FBN->ShortName) goto shit; strcpy(FBN->ShortName, temp); FBN->BitNum = atoi(GetNextString(Buff, &i)); temp = GetNextString(Buff, &i); FBN->LongName = malloc(strlen(temp) + 1); if(!FBN->LongName) goto shit; strcpy(FBN->LongName, temp); *LastFBN = FBN; LastFBN = &FBN->Next; } } else if(part == PART_LOCK) { if(!strncmp(&Buff[i], "#DEFLOCK", 8)) { first_lockline = True; LN = (struct LockNode *)malloc(sizeof(struct LockNode)); if(!LN) goto shit; LN->Next = NULL; LastLBN = &LN->FirstLockBitNode; i += 8; LN->Num = atoi(GetNextString(Buff, &i)); *LastLN = LN; LastLN = &LN->Next; } else if(!strncmp(&Buff[i], "#DEFEND", 7)) LN = NULL; else if(LN) { if(first_lockline) { first_lockline = False; LN->NumberOfBits = atoi(GetNextString(Buff, &i)); LN->WriteBits = 0; for(j = 0; j < LN->NumberOfBits; j++) LN->WriteBits |= atoi(GetNextString(Buff, &i)) << (j * 4); LN->ReadBits = 0; for(j = 0; j < LN->NumberOfBits; j++) LN->ReadBits |= atoi(GetNextString(Buff, &i)) << (j * 4); } else { LBN = (struct LockBitNode *)malloc(sizeof(struct LockBitNode)); if(!LBN) goto shit; LBN->Next = NULL; LBN->LongName = NULL; LBN->Mode = atoi(GetNextString(Buff, &i)); LBN->Mask = 0; for(j = 0; j < LN->NumberOfBits; j++) LBN->Mask |= atoi(GetNextString(Buff, &i)) << j; temp = GetNextString(Buff, &i); LBN->LongName = malloc(strlen(temp) + 1); if(!LBN->LongName) goto shit; strcpy(LBN->LongName, temp); *LastLBN = LBN; LastLBN = &LBN->Next; } } } } } } else { loopok = False; if(!feof(FP)) { ok = False; perror((char *)GET_ARG(PI->args, ARG_DEFFILE)); } } } if(ver == 0) { ok = False; printf("Error: %s: No version string found\n", (char *)GET_ARG(PI->args, ARG_DEFFILE)); } fclose(FP); } else { perror((char *)GET_ARG(PI->args, ARG_DEFFILE)); printf("You should check if avrp.def is properly installed\n"); } return(ok); shit: printf("Error: Unable to allocate memory\n"); fclose(FP); return(False); } char *GetNextString(char *Buff, int *index) { int i; while((Buff[*index] == ' ') || (Buff[*index] == 9)) (*index)++; if(Buff[*index] == '\"') { i = ++(*index); while((Buff[*index] != '\"') && (Buff[*index] != 13) && (Buff[*index] != 10)) (*index)++; Buff[(*index)++] = '\0'; } else { i = *index; while((Buff[*index] != ' ') && (Buff[*index] != 9) && (Buff[*index] != 13) && (Buff[*index] != 10)) (*index)++; Buff[(*index)++] = '\0'; } return(&Buff[i]); } avrp-1.0-beta3/io_amiga.c100644 2117 311 14160 6603744703 14144 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include #include #include #include "avrp.h" struct ustimer { int ODok; struct timerequest *TimerIO; struct MsgPort *TimerMsgPort; }; struct Ser { char *Name; int ser_open; struct IOExtSer *IO; struct MsgPort *IO_port; struct ustimer *ust; }; void usDelay(struct ustimer *ust, int us); struct ustimer *usDelayInit(void); void usDelayFree(struct ustimer *ust); void *OpenSer(char *SerPort) { int i, err; struct Ser *Ser; char buff[64]; strncpy(buff, SerPort, 63); for(i = strlen(buff) - 1; (buff[i] != ':') && (i > 0); i--); if(buff[i] == ':') { buff[i] = '\0'; Ser = (struct Ser *)malloc(sizeof(struct Ser)); if(Ser) { Ser->Name = SerPort; Ser->ser_open = False; Ser->IO = NULL; Ser->ust = NULL; Ser->IO_port = CreateMsgPort(); if(Ser->IO_port) { Ser->IO = (struct IOExtSer *)CreateExtIO(Ser->IO_port, sizeof(struct IOExtSer)); if(Ser->IO) { err = OpenDevice(buff, atoi(&buff[i + 1]), (struct IORequest *)Ser->IO, 0); if(!err) { Ser->ser_open = True; Ser->IO->IOSer.io_Command = SDCMD_SETPARAMS; Ser->IO->io_RBufLen = 64; Ser->IO->io_Baud = 19200; Ser->IO->io_ReadLen = 8; Ser->IO->io_WriteLen = 8; Ser->IO->io_StopBits = 1; Ser->IO->io_ExtFlags = 0; Ser->IO->io_SerFlags = SERF_XDISABLED; DoIO((struct IORequest *)Ser->IO); Ser->ust = usDelayInit(); if(Ser->ust) return(Ser); } else { if(err == SerErr_DevBusy) printf("Error: Serial device is busy\n"); else printf("Error: Failed to open serial device (error: %d)\n", err); } } else printf("Error: Unable to allocate memory for IOExtSer\n"); } else printf("Error: Failed to create message port for serial device\n"); CloseSer(Ser); } else printf("Error: Unable to allocate memory\n"); } else printf("Error: Found no ':' in serial port argument\n"); return(0); } void CloseSer(void *Ser) { if(((struct Ser *)Ser)->ust) usDelayFree(((struct Ser *)Ser)->ust); if(((struct Ser *)Ser)->ser_open) CloseDevice((struct IORequest *)((struct Ser *)Ser)->IO); if(((struct Ser *)Ser)->IO) DeleteExtIO((struct IORequest *)((struct Ser *)Ser)->IO); if(((struct Ser *)Ser)->IO_port) DeleteMsgPort(((struct Ser *)Ser)->IO_port); free(Ser); } void SerWriteByte(void *Ser, unsigned char Byte) { ((struct Ser *)Ser)->IO->IOSer.io_Command = CMD_WRITE; ((struct Ser *)Ser)->IO->IOSer.io_Flags = 0; ((struct Ser *)Ser)->IO->IOSer.io_Length = 1; ((struct Ser *)Ser)->IO->IOSer.io_Data = &Byte; DoIO((struct IORequest *)((struct Ser *)Ser)->IO); } int SerReadData(void *Ser, unsigned char *Buff, int Count) { int i; ((struct Ser *)Ser)->IO->IOSer.io_Command = SDCMD_QUERY; DoIO((struct IORequest *)((struct Ser *)Ser)->IO); if(((struct Ser *)Ser)->IO->IOSer.io_Actual != Count) { for(i = 0; (((struct Ser *)Ser)->IO->IOSer.io_Actual != Count) && (i < 500); i++) { usDelay(((struct Ser *)Ser)->ust, 100); DoIO((struct IORequest *)((struct Ser *)Ser)->IO); } } if(((struct Ser *)Ser)->IO->IOSer.io_Actual != 0) { ((struct Ser *)Ser)->IO->IOSer.io_Command = CMD_READ; ((struct Ser *)Ser)->IO->IOSer.io_Flags = 0; ((struct Ser *)Ser)->IO->IOSer.io_Length = ((struct Ser *)Ser)->IO->IOSer.io_Actual; ((struct Ser *)Ser)->IO->IOSer.io_Data = Buff; DoIO((struct IORequest *)((struct Ser *)Ser)->IO); if(((struct Ser *)Ser)->IO->IOSer.io_Error) printf("IOError: %d\n", (int)((struct Ser *)Ser)->IO->IOSer.io_Error); } return((int)((struct Ser *)Ser)->IO->IOSer.io_Actual); } void usDelay(struct ustimer *ust, int us) { ust->TimerIO->tr_node.io_Command = TR_ADDREQUEST; ust->TimerIO->tr_time.tv_micro = us; ust->TimerIO->tr_time.tv_secs = 0; DoIO((struct IORequest *)ust->TimerIO); } struct ustimer *usDelayInit(void) { struct ustimer *ust; ust = calloc(1, sizeof(struct ustimer)); if(ust) { ust->ODok = FALSE; ust->TimerMsgPort = CreateMsgPort(); if(ust->TimerMsgPort) { ust->TimerIO = (struct timerequest *)CreateExtIO(ust->TimerMsgPort, sizeof(struct timerequest)); if(ust->TimerIO) { if(!OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)ust->TimerIO, 0)) { ust->ODok = TRUE; } else printf("Error: Unable to open timer.device\n"); } else printf("Error: Unable to create ExtIO for timer\n"); } else printf("Error: Unable to create messageport for timer\n"); if(!ust->ODok) { usDelayFree(ust); ust = NULL; } } else printf("Error: Unable to allocate memory for timer\n"); return(ust); } void usDelayFree(struct ustimer *ust) { if(ust->ODok) CloseDevice((struct IORequest *)ust->TimerIO); if(ust->TimerIO) DeleteExtIO((struct IORequest *)ust->TimerIO); if(ust->TimerMsgPort) DeleteMsgPort(ust->TimerMsgPort); free(ust); } avrp-1.0-beta3/io_linux.c100600 2117 311 5551 6603744703 14201 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include #include #include #include #include #include "avrp.h" #define BAUDRATE B19200 struct Ser { char *Name; int fd; struct termios oldtio, newtio; }; void *OpenSer(char *SerPort) { struct Ser *Ser = NULL; Ser = (struct Ser *)malloc(sizeof(struct Ser)); if(Ser) { Ser->Name = SerPort; if((Ser->fd = open(SerPort, O_RDWR | O_NOCTTY )) != -1) { tcgetattr(Ser->fd, &Ser->oldtio); /* save current port settings */ bzero(&Ser->newtio, sizeof(Ser->newtio)); Ser->newtio.c_cflag = CS8 | CLOCAL | CREAD; cfsetispeed(&Ser->newtio, BAUDRATE); cfsetospeed(&Ser->newtio, BAUDRATE); Ser->newtio.c_iflag = IGNPAR; Ser->newtio.c_oflag = 0; /* set input mode (non-canonical, no echo,...) */ Ser->newtio.c_lflag = 0; Ser->newtio.c_cc[VTIME] = 3; /* Timeout in value * 0.1s */ Ser->newtio.c_cc[VMIN] = 0; tcflush(Ser->fd, TCIFLUSH); tcsetattr(Ser->fd, TCSANOW, &Ser->newtio); } else { perror(SerPort); free(Ser); Ser = NULL; } } else printf("Error: Unable to allocate memory\n"); return(Ser); } void CloseSer(void *Ser) { tcsetattr(((struct Ser *)Ser)->fd, TCSANOW, &((struct Ser *)Ser)->oldtio); close(((struct Ser *)Ser)->fd); free(Ser); } void SerWriteByte(void *Ser, unsigned char Byte) { write(((struct Ser *)Ser)->fd, &Byte, 1); } int SerReadData(void *Ser, unsigned char *Buff, int Count) { int ret; ret = read(((struct Ser *)Ser)->fd, Buff, Count); if(ret == -1) { perror(((struct Ser *)Ser)->Name); return(0); } return(ret); } avrp-1.0-beta3/io_win32.c100700 2117 311 7370 6603744703 14006 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ /* * Serial port routines using win32 API (Windows 95/NT) */ #include #include #include "avrp.h" /* * Structure private to serial port functions */ struct Ser { char *Name; // Name of serial port HANDLE Comm; // Filehandle for serial port int comm_open; // Set to True when port is open COMMTIMEOUTS cto_old; // Storage for old timeout values }; /* * Open the serial port */ void *OpenSer(char *SerPort) { struct Ser *Ser = NULL; DCB dcb; COMMTIMEOUTS cto_new = {0}; if(Ser = (struct Ser *)malloc(sizeof(struct Ser))) { Ser->Name = SerPort; Ser->comm_open = False; Ser->Comm = CreateFile(SerPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(Ser->Comm != INVALID_HANDLE_VALUE) { Ser->comm_open = True; GetCommTimeouts(Ser->Comm, &Ser->cto_old); cto_new.ReadTotalTimeoutConstant = 300; // milliseconds SetCommTimeouts(Ser->Comm, &cto_new); FillMemory(&dcb, sizeof(dcb), 0); dcb.DCBlength = sizeof(dcb); if(BuildCommDCB("19200,n,8,1", &dcb)) { if(SetCommState(Ser->Comm, &dcb)) return(Ser); else printf("Error: SetCommState() failed\n"); } else printf("Error: BuildCommDCB() failed\n"); } else printf("Error: %s: No such port\n", SerPort); CloseSer(Ser); } else printf("Error: Unable to allocate memory\n"); return(NULL); } /* * Close the serial port */ void CloseSer(void *Ser) { if(((struct Ser *)Ser)->comm_open) { SetCommTimeouts(((struct Ser *)Ser)->Comm, &((struct Ser *)Ser)->cto_old); CloseHandle(((struct Ser *)Ser)->Comm); } free(Ser); } /* * Write a byte to serial port */ void SerWriteByte(void *Ser, unsigned char Byte) { int ret; WriteFile(((struct Ser *)Ser)->Comm, &Byte, 1, &ret, NULL); } /* * Read data from serial port * * INPUTS * Ser - Pointer to serial structure * Buff - Pointer to buffer * Count - Number of bytes to read * * RESULT * Actual number of bytes read */ int SerReadData(void *Ser, unsigned char *Buff, int Count) { int ret; ReadFile(((struct Ser *)Ser)->Comm, Buff, Count, &ret, NULL); return(ret); } avrp-1.0-beta3/memtalk.c100644 2117 311 27313 6603744703 14035 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * standard serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include "avrp.h" #include "talk.h" int Program(struct ProgramInfo *PI, int What, int DoWhat) { int ok = False, loopok = True, i, count, adr = 0, line, StatAdr = 0, data; struct DataFile *DataFile; unsigned char Buff[256], CheckSum; char *filename; if(What == WHAT_EEPROM) filename = (char *)GET_ARG(PI->args, ARG_EEPROM); else filename = (char *)GET_ARG(PI->args, ARG_FLASH); DataFile = OpenDataFile(filename); if(DataFile) { line = 0; while(loopok && !ok) { loopok = False; line++; if(fgets(Buff, 256, DataFile->FP)) { if(DataFile->FileType == FILETYPE_INTEL_HEX8M) { if(Buff[0] == ':') { count = atox_n(&Buff[1], 2); if(count != 0) /* ToDo: Sjekk count bedre */ { count *= 2; CheckSum = 0; for(i = 1; i < (count + 11); i += 2) CheckSum += atox_n(&Buff[i], 2); if(!CheckSum) { if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) { adr &= 0xffff8000; adr |= atox_n(&Buff[3], 4) / 2; } else { adr &= 0xffff0000; adr |= atox_n(&Buff[3], 4); } if(atox_n(&Buff[7], 2) == 0) { loopok = True; for(i = 9; (i < (count + 9)) && loopok;) { data = atox_n(&Buff[i], 2); if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) { data |= atox_n(&Buff[i + 2], 2) << 8; i += 2; } i += 2; if(DoWhat == DO_PROGRAM) { if(!prog_adr(PI, adr, data, What, &StatAdr)) loopok = False; } else { if(!verify_adr(PI, adr, data, What, &StatAdr)) loopok = False; } adr++; } } else if(atox_n(&Buff[7], 2) == 2) { if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) adr = atox_n(&Buff[3], 4) << 15; else adr = atox_n(&Buff[3], 4) << 16; } else printf("Error: %s: Line %4d: Wrong type. Should be :XXXXXX00 or :XXXXXX02\n", filename, line); } else printf("Error: %s: Line %4d: Faulty checksum\n", filename, line); } else if(!strncmp(&Buff[3], "000001FF", 8)) ok = True; } else printf("Error: %s: Line %4d: Missing ':' at linestart\n", filename, line); } else if(DataFile->FileType == FILETYPE_ATMEL_GENERIC) { if(What == WHAT_FLASH) i = 6; else i = 4; if(Buff[i] == ':') { Buff[i] = '\0'; adr = atox(Buff); if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) data = atox_n(&Buff[i + 1], 4); else data = atox_n(&Buff[i + 1], 2); if(DoWhat == DO_PROGRAM) { if(prog_adr(PI, adr, data, What, &StatAdr)) loopok = True; } else { if(verify_adr(PI, adr, data, What, &StatAdr)) loopok = True; } } else printf("Error: %s: Line %4d: Missing ':' between address and data fields\n", filename, line); } } else { if(feof(DataFile->FP)) { if(DataFile->FileType == FILETYPE_ATMEL_GENERIC) ok = True; } else perror((char *)GET_ARG(PI->args, ARG_FLASH)); } } if(ok) printf("\n"); CloseDataFile(DataFile); } return(ok); } int prog_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr) { unsigned char SerBuff[2]; if((What == WHAT_EEPROM) || !GET_ARG(PI->args, ARG_AUTOINC) || (*StatAdr != adr) || (*StatAdr == 0)) { SerWriteByte(PI->Ser, 'A'); SerWriteByte(PI->Ser, (unsigned char)(adr >> 8)); SerWriteByte(PI->Ser, (unsigned char)adr); if(!((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13))) { print_comm_err('A'); return(False); } } if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) { SerWriteByte(PI->Ser, 'c'); SerWriteByte(PI->Ser, (unsigned char)data); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { SerWriteByte(PI->Ser, 'C'); SerWriteByte(PI->Ser, (unsigned char)(data >> 8)); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { if(!GET_ARG(PI->args, ARG_QUICK)) Progress(StatAdr, adr, 'P'); else for(; *StatAdr <= adr; (*StatAdr)++); return(True); } else print_comm_err('C'); } else print_comm_err('c'); } else { if(What == WHAT_FLASH) SerWriteByte(PI->Ser, 'c'); else SerWriteByte(PI->Ser, 'D'); SerWriteByte(PI->Ser, (unsigned char)data); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { if(!GET_ARG(PI->args, ARG_QUICK)) Progress(StatAdr, adr, 'P'); else for(; *StatAdr <= adr; (*StatAdr)++); return(True); } else { if(What == WHAT_FLASH) print_comm_err('c'); else print_comm_err('D'); } } return(False); } int verify_adr(struct ProgramInfo *PI, int adr, int data, int What, int *StatAdr) { unsigned char SerBuff[2]; if((What == WHAT_EEPROM) || !GET_ARG(PI->args, ARG_AUTOINC) || (*StatAdr != adr) || (*StatAdr == 0)) { SerWriteByte(PI->Ser, 'A'); SerWriteByte(PI->Ser, (unsigned char)(adr >> 8)); SerWriteByte(PI->Ser, (unsigned char)adr); if(!((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13))) { print_comm_err('A'); return(False); } } if((PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 2) && (What == WHAT_FLASH)) { SerWriteByte(PI->Ser, 'R'); if(SerReadData(PI->Ser, SerBuff, 2)) { if(((SerBuff[0] << 8) | SerBuff[1]) == data) { if(!GET_ARG(PI->args, ARG_QUICK)) Progress(StatAdr, adr, 'V'); else for(; *StatAdr <= adr; (*StatAdr)++); return(True); } else printf("\nError: Verify failed! [Address: 0x%04x Filedata: 0x%04x Chipdata: 0x%04x]\n", adr, data, (int)(SerBuff[0] << 8) | SerBuff[1]); } else print_comm_err('R'); } else { if(What == WHAT_FLASH) SerWriteByte(PI->Ser, 'R'); else SerWriteByte(PI->Ser, 'd'); if(SerReadData(PI->Ser, SerBuff, 1)) { if(SerBuff[0] == data) { if(!GET_ARG(PI->args, ARG_QUICK)) Progress(StatAdr, adr, 'V'); else for(; *StatAdr <= adr; (*StatAdr)++); return(True); } else printf("\nError: Verify failed! [Address: 0x%04x Filedata: 0x%02x Chipdata: 0x%02x]\n", adr, data, (int)SerBuff[0]); } else { if(What == WHAT_FLASH) print_comm_err('R'); else print_comm_err('d'); } } return(False); } int Read(struct ProgramInfo *PI, int What) { int ok = False, loopok = True, i, flash_size, StatAdr = 0; unsigned char SerBuff[2], Checksum; char *filename; FILE *FP; if(What == WHAT_FLASH) filename = (char *)GET_ARG(PI->args, ARG_FLASH); else filename = (char *)GET_ARG(PI->args, ARG_EEPROM); FP = fopen(filename, "wb"); if(FP) { if(What == WHAT_FLASH) { flash_size = (PI->SelectedChipNode->FamilyNode->FlashSize * 1024) / PI->SelectedChipNode->FamilyNode->ArchNode->WordSize; for(i = 0; (i < flash_size) && loopok; i++) { ok = False; if(PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 1) { if((i % 16) == 0) { fprintf(FP, ":10%04X00", i); Checksum = 0; Checksum += 0x10; Checksum += i >> 8; Checksum += i & 0xFF; } } else { if((i % 8) == 0) { fprintf(FP, ":10%04X00", i * 2); Checksum = 0; Checksum += 0x10; Checksum += (i * 2) >> 8; Checksum += (i * 2) & 0xFF; } } if(!GET_ARG(PI->args, ARG_AUTOINC) || (StatAdr != i) || (StatAdr == 0)) { SerWriteByte(PI->Ser, 'A'); SerWriteByte(PI->Ser, (unsigned char)(i >> 8)); SerWriteByte(PI->Ser, (unsigned char)i); if(!((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13))) { print_comm_err('A'); loopok = False; } } if(loopok) { SerWriteByte(PI->Ser, 'R'); if(SerReadData(PI->Ser, SerBuff, PI->SelectedChipNode->FamilyNode->ArchNode->WordSize)) { if(PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 1) { fprintf(FP, "%02X", (int)SerBuff[0]); Checksum += SerBuff[0]; } else { fprintf(FP, "%02X%02X", (int)SerBuff[1], (int)SerBuff[0]); Checksum += SerBuff[1]; Checksum += SerBuff[0]; } ok = True; if(!GET_ARG(PI->args, ARG_QUICK)) Progress(&StatAdr, i, 'R'); else for(; StatAdr <= i; StatAdr++); } else { print_comm_err('R'); loopok = False; } } if(PI->SelectedChipNode->FamilyNode->ArchNode->WordSize == 1) { if((i % 16) == 15) fprintf(FP, "%02X\x0d\x0a", (int)(unsigned char)-Checksum); } else { if((i % 8) == 7) fprintf(FP, "%02X\x0d\x0a", (int)(unsigned char)-Checksum); } } } else { for(i = 0; (i < PI->SelectedChipNode->EepromSize) && loopok; i++) { ok = False; if((i % 16) == 0) { fprintf(FP, ":10%04X00", i); Checksum = 0; Checksum += 0x10; Checksum += i >> 8; Checksum += i & 0xFF; } SerWriteByte(PI->Ser, 'A'); SerWriteByte(PI->Ser, (unsigned char)(i >> 8)); SerWriteByte(PI->Ser, (unsigned char)i); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { SerWriteByte(PI->Ser, 'd'); if(SerReadData(PI->Ser, SerBuff, 1)) { fprintf(FP, "%02X", (int)SerBuff[0]); Checksum += SerBuff[0]; ok = True; if(!GET_ARG(PI->args, ARG_QUICK)) Progress(&StatAdr, i, 'R'); else for(; StatAdr <= i; StatAdr++); } else { print_comm_err('d'); loopok = False; } } else { print_comm_err('A'); loopok = False; } if((i % 16) == 15) fprintf(FP, "%02X\x0d\x0a", (int)(unsigned char)-Checksum); } } if(ok) { fprintf(FP, ":00000001FF\x0d\x0a"); printf("\n"); } fclose(FP); } else perror(filename); return(ok); } void Progress(int *StatAdr, int Adr, char DidWhat) { for(; *StatAdr <= Adr; (*StatAdr)++) { if((*StatAdr % 64) == 0) { if(*StatAdr) printf("\n"); printf("0x%04X: ", *StatAdr); } if(*StatAdr == Adr) printf("%c", DidWhat); else printf("-"); fflush(stdout); /* Friker med NULL som arg under SAS/C */ } } avrp-1.0-beta3/misc.h100600 2117 311 66 6603744704 13250 0ustar jonahguests/* * Misc stuff */ enum boolean {False = 0, True}; avrp-1.0-beta3/stdextra.c100600 2117 311 4435 6603744703 14211 0ustar jonahguests/******************************************************************** * Extra standard functions */ #include #include #include "misc.h" /******************************************************************** * Case insensetive strcmp() */ int nocase_strcmp(char *s, char *t) { int i; for(i = 0; tolower(s[i]) == tolower(t[i]); i++) if(s[i] == '\0') return(0); return(tolower(s[i]) - tolower(t[i])); } /******************************************************************** * Case insensetive strncmp() */ int nocase_strncmp(char *s, char *t, int n) { int i; for(i = 0; (tolower(s[i]) == tolower(t[i])); i++, n--) if((s[i] == '\0') || (n == 1)) return(0); return(tolower(s[i]) - tolower(t[i])); } /******************************************************************** * Case insensetive strstr() */ char *nocase_strstr(char *s, char *t) { int i = 0, j, found = False; while((s[i] != '\0') && !found) { j = 0; while(tolower(t[j]) == tolower(s[i + j])) { j++; if(t[j] == '\0') { found = True; break; } else if(s[i + j] == '\0') break; } i++; } i--; if(found) return(&s[i]); return(NULL); } /******************************************************************** * ascii to hex * ignores "0x" */ int atox(char *s) { int i = 0, ret = 0; while(s[i] != '\0') { ret <<= 4; if((s[i] <= 'F') && (s[i] >= 'A')) ret |= s[i] - 'A' + 10; else if((s[i] <= 'f') && (s[i] >= 'a')) ret |= s[i] - 'a' + 10; else if((s[i] <= '9') && (s[i] >= '0')) ret |= s[i] - '0'; i++; } return(ret); } /******************************************************************** * n ascii chars to int */ int atoi_n(char *s, int n) { int i = 0, ret = 0; while((s[i] != '\0') && n) { ret = 10 * ret + (s[i] - '0'); i++; n--; } return(ret); } /******************************************************************** * n ascii chars to hex * 0 < n <= 8 * ignores "0x" */ int atox_n(char *s, int n) { int i = 0, ret = 0; while((s[i] != '\0') && n) { ret <<= 4; if((s[i] <= 'F') && (s[i] >= 'A')) ret |= s[i] - 'A' + 10; else if((s[i] <= 'f') && (s[i] >= 'a')) ret |= s[i] - 'a' + 10; else if((s[i] <= '9') && (s[i] >= '0')) ret |= s[i] - '0'; i++; n--; } return(ret); } avrp-1.0-beta3/strip-headers100700 2117 311 475 6603744704 14666 0ustar jonahguests#!/usr/bin/perl -wn # make it slurp the whole file at once: undef $/; # delete first header: s/^\n*.*\n+//; # delete last footer: s/\n+.*\n+$/\n/g; # delete page breaks: s/\n\n+[^ \t].*\n\n+(\S+).*\1\n\n+/\n/g; # collapse two or more blank lines into a single one: s/\n{3,}/\n\n/g; # see what's left... print; avrp-1.0-beta3/talk.h100600 2117 311 203 6603744704 13261 0ustar jonahguestsenum { WHAT_FLASH = 0, WHAT_EEPROM }; enum { PROGTYPE_PAR = 0, PROGTYPE_SER }; enum { DO_PROGRAM = 0, DO_VERIFY }; avrp-1.0-beta3/talking.c100744 2117 311 41405 6603744703 14033 0ustar jonahguests/*********************************************************************** * avrp - Atmel AVR programming software to use with Atmel's * standard serial-port programmers. * Copyright (C) 1997-1998 Jon Anders Haugum * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * Author of avrp can be reached at: * email: jonah@colargol.tihlde.hist.no * www: http://www.colargol.tihlde.hist.no/~jonah/el/avrp.html * Postal address: Jon Anders Haugum * Øvre Møllenbergsgt 52 * 7014 Trondheim */ #include #include #include #include "avrp.h" #include "talk.h" int InquireHW(struct ProgramInfo *PI) { int i, found, count, unknown = False; unsigned char SerBuff[256]; struct ChipNode *CN; SerWriteByte(PI->Ser, 'L'); SerReadData(PI->Ser, SerBuff, 1); if(InquireID(PI)) { SerWriteByte(PI->Ser, 't'); count = SerReadData(PI->Ser, SerBuff, 256); if(count) { if(count != 1) { if(!GET_ARG(PI->args, ARG_AVRTYPE)) printf("Devices supported by programmer:\n"); for(i = 0; SerBuff[i] != 0x00; i++) { if(i == (count - 1)) { printf("Error: Device codes not terminated\n"); return(False); } found = False; for(CN = PI->FirstChipNode; CN; CN = CN->Next) { if(CN->Code == SerBuff[i]) { found = True; CN->Supported = True; if(!GET_ARG(PI->args, ARG_AVRTYPE)) printf(" %s %s %s with %dKB flash (0x%02x)\n", CN->VendorNode->Name, CN->FamilyNode->Name, CN->Name, CN->FamilyNode->FlashSize, (int)SerBuff[i]); } } if(!found) { if(!GET_ARG(PI->args, ARG_AVRTYPE)) printf(" Unknown device code: 0x%02x\n", (int)SerBuff[i]); unknown = True; } } if(unknown && !GET_ARG(PI->args, ARG_AVRTYPE)) printf("Warning: Connected programmer supports devices not supported by avrp\n" " You should update %s\n", (char *)GET_ARG(PI->args, ARG_DEFFILE)); return(True); } else printf("Error: Your programmer doesn't suppport any chips at all\n"); } else print_comm_err('t'); } return(False); } int InquireID(struct ProgramInfo *PI) { int count; unsigned char SerBuff[16]; SerWriteByte(PI->Ser, 'p'); if(SerReadData(PI->Ser, SerBuff, 1)) { if((SerBuff[0] == 'S') || (SerBuff[0] == 'P')) { if(SerBuff[0] == 'S') { PI->ProgType = PROGTYPE_SER; printf("Serial mode programmer of type: "); } else { PI->ProgType = PROGTYPE_PAR; printf("Parallel mode programmer of type: "); } SerWriteByte(PI->Ser, 'S'); count = SerReadData(PI->Ser, SerBuff, 15); if(count) { SerBuff[count] = '\0'; printf("%s\n", SerBuff); SerWriteByte(PI->Ser, 'v'); if(SerReadData(PI->Ser, SerBuff, 2) == 2) { printf("Hardware version: %c.%c", SerBuff[0], SerBuff[1]); SerWriteByte(PI->Ser, 'V'); if(SerReadData(PI->Ser, SerBuff, 2) == 2) { printf(" Firmware version: %c.%c\n", SerBuff[0], SerBuff[1]); return(True); } else print_comm_err('V'); } else print_comm_err('v'); } else print_comm_err('S'); } else printf("Error: Not a valid programmer type reported\n" " Possibly no programmer connected\n"); } else print_comm_err('p'); return(False); } int DoTheTalk(struct ProgramInfo *PI) { int ok = False; unsigned char SerBuff[3]; SerWriteByte(PI->Ser, 'T'); SerWriteByte(PI->Ser, (unsigned char)PI->SelectedChipNode->Code); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { SerWriteByte(PI->Ser, 'P'); if((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13)) { SerWriteByte(PI->Ser, 's'); if(SerReadData(PI->Ser, SerBuff, 3)) { if((SerBuff[0] != 0xFF) || (SerBuff[1] != 0xFF) || (SerBuff[2] != 0xFF) || GET_ARG(PI->args, ARG_IGNORESIG)) { if(CheckLockAndErase(PI, SerBuff)) { if(CheckSig(PI, SerBuff)) { if(GET_ARG(PI->args, ARG_PROG)|| GET_ARG(PI->args, ARG_READ) || GET_ARG(PI->args, ARG_VERIFY)|| GET_ARG(PI->args, ARG_LOCKMODE) || GET_ARG(PI->args, ARG_ENABLE) || GET_ARG(PI->args, ARG_DISABLE)) { ok = DoMoreTalk(PI); } else printf("Missing argument: No action argument specified\n" " -p : Program\n" " -r : Read\n" " -v : Verify (can be used standalone or together with -p or -r)\n" " -l : Lockmode (use '-l list' to get a list of modes)\n" " --enable : Fuses to enable\n" " --disable : Fuses to disable\n"); } } } else printf("Error: There seems to be no chip inserted in the programmer\n" " Use -I to ignore this signaturecheck\n"); } else print_comm_err('s'); } else print_comm_err('P'); SerWriteByte(PI->Ser, 'L'); if(!((SerReadData(PI->Ser, SerBuff, 1)) && (SerBuff[0] == 13))) print_comm_err('L'); } else print_comm_err('T'); return(ok); } int CheckLockAndErase(struct ProgramInfo *PI, unsigned char *SerBuff) { int ok; if((SerBuff[0] == 0x02) && (SerBuff[1] == 0x01) && (SerBuff[2] == 0x00)) { ok = False; printf("Device is locked!\n"); if(GET_ARG(PI->args, ARG_PROG)) { if(Erase(PI)) { SerWriteByte(PI->Ser, 's'); if(SerReadData(PI->Ser, SerBuff, 3)) { if((SerBuff[0] == 0x02) && (SerBuff[1] == 0x01) && (SerBuff[2] == 0x00)) printf("Error: Failed to erase device!\n"); else ok = True; } else { print_comm_err('s'); return(False); } } else return(False); } else if(GET_ARG(PI->args, ARG_READ)) printf("Error: Unable to read device\n"); else if(GET_ARG(PI->args, ARG_VERIFY)) printf("Error: Unable to verify device\n"); if(!ok) DoFuses(PI); return(ok); } else if(GET_ARG(PI->args, ARG_PROG) && GET_ARG(PI->args, ARG_FLASH) && PI->SelectedChipNode->FamilyNode->ArchNode->NeedFlashErase) return(Erase(PI)); else return(True); } int CheckSig(struct ProgramInfo *PI, unsigned char *Sig) { int ok = False, IntSig; struct ChipNode *CN, *FoundCN = NULL; struct VendorNode *VN, *FoundVN = NULL; struct FamilyNode *FN, *FoundFN = NULL; IntSig = Sig[0] | (Sig[1] << 8) | (Sig[2] << 16); if(IntSig == PI->SelectedChipNode->Sig) ok = True; else { printf("Warning: Signature does not match\n"); for(CN = PI->FirstChipNode; CN; CN = CN->Next) if(IntSig == CN->Sig) { if(!FoundCN) printf("Signature in chip matched: %s\n", CN->Name); else printf(" %s\n", CN->Name); FoundCN = CN; } if(!FoundCN) { printf("Inserted chip: Vendor: "); for(VN = PI->FirstVendorNode; VN; VN = VN->Next) if(VN->Code == Sig[2]) { FoundVN = VN; break; } if(FoundVN) printf("%s", FoundVN->Name); else printf("Unknown (0x%02x)", (int)Sig[2]); printf("\n Family: "); for(FN = PI->FirstFamilyNode; FN; FN = FN->Next) if(FN->Code == Sig[1]) { FoundFN = FN; break; } if(FoundFN) printf("%s with %dk flash", FoundFN->Name, FoundFN->FlashSize); else printf("Unknown (0x%02x)", (int)Sig[1]); printf("\n Part number: 0x%02x\n", (int)Sig[0]); } } if(!ok && GET_ARG(PI->args, ARG_IGNORESIG)) { printf("Ignoring incorrect signature\n"); ok = True; } return(ok); } int DoMoreTalk(struct ProgramInfo *PI) { int ok = False; if(GET_ARG(PI->args, ARG_PROG)) { if(GET_ARG(PI->args, ARG_FLASH) || GET_ARG(PI->args, ARG_EEPROM)) { if(GET_ARG(PI->args, ARG_FLASH)) { printf("Programming flash from file: %s ", (char *)GET_ARG(PI->args, ARG_FLASH)); ok = Program(PI, WHAT_FLASH, DO_PROGRAM); } if(ok || !GET_ARG(PI->args, ARG_FLASH)) if(GET_ARG(PI->args, ARG_EEPROM)) { printf("Programming eeprom from file: %s ", (char *)GET_ARG(PI->args, ARG_EEPROM)); ok = Program(PI, WHAT_EEPROM, DO_PROGRAM); } } else printf("Missing argument: One or more of these must be given:\n" " File to read flash data from: -f \n" " File to read eeprom data from: -e \n"); } else if(GET_ARG(PI->args, ARG_READ)) { if(GET_ARG(PI->args, ARG_FLASH) || GET_ARG(PI->args, ARG_EEPROM)) { if(GET_ARG(PI->args, ARG_FLASH)) { printf("Reading flash to file: %s\n", (char *)GET_ARG(PI->args, ARG_FLASH)); ok = Read(PI, WHAT_FLASH); } if(ok || !GET_ARG(PI->args, ARG_FLASH)) if(GET_ARG(PI->args, ARG_EEPROM)) { printf("Reading eeprom to file: %s\n", (char *)GET_ARG(PI->args, ARG_EEPROM)); ok = Read(PI, WHAT_EEPROM); } } else printf("Missing argument: One or more of these must be given:\n" " File to write flash data to: -f \n" " File to write eeprom data to: -e \n"); } else ok = True; if(GET_ARG(PI->args, ARG_VERIFY) && (ok || !GET_ARG(PI->args, ARG_PROG))) { if(GET_ARG(PI->args, ARG_FLASH) || GET_ARG(PI->args, ARG_EEPROM)) { if(GET_ARG(PI->args, ARG_FLASH)) { printf("Verifying flash with: %s ", (char *)GET_ARG(PI->args, ARG_FLASH)); ok = Program(PI, WHAT_FLASH, DO_VERIFY); } if(ok || !GET_ARG(PI->args, ARG_FLASH)) if(GET_ARG(PI->args, ARG_EEPROM)) { printf("Verifying eeprom with: %s ", (char *)GET_ARG(PI->args, ARG_EEPROM)); ok = Program(PI, WHAT_EEPROM, DO_VERIFY); } } else printf("Missing argument: One or more of these must be given:\n" " File to verify flash data with: -f \n" " File to verify eeprom data with: -e \n"); } if(ok) ok = DoFuses(PI); return(ok); } int Erase(struct ProgramInfo *PI) { unsigned char SerBuff; SerWriteByte(PI->Ser, 'e'); printf("Erasing device...\n"); if((SerReadData(PI->Ser, &SerBuff, 1)) && (SerBuff == 13)) { SerWriteByte(PI->Ser, 'L'); if((SerReadData(PI->Ser, &SerBuff, 1)) && (SerBuff == 13)) { SerWriteByte(PI->Ser, 'P'); if((SerReadData(PI->Ser, &SerBuff, 1)) && (SerBuff == 13)) return(True); else print_comm_err('P'); } else print_comm_err('L'); } else print_comm_err('e'); return(False); } int DoFuses(struct ProgramInfo *PI) { unsigned char SerBuff, mask = 0xff; int i, found, lockmode, lockmode_list = False; struct FuseBitNode *FBN; struct LockBitNode *LBN; struct data_list *data; if(PI->ProgType == PROGTYPE_PAR) { SerWriteByte(PI->Ser, 'F'); if(SerReadData(PI->Ser, &SerBuff, 1)) { if(PI->SelectedChipNode->FuseType != 0) { printf("Reading fuses...\n"); for(FBN = PI->SelectedChipNode->FuseNode->FirstFuseBitNode; FBN; FBN = FBN->Next) { if(~SerBuff & (1 << FBN->BitNum)) { printf(" Enabled: %-8s (%s)\n", FBN->ShortName, FBN->LongName); mask &= ~(1 << FBN->BitNum); } else printf(" Disabled: %-8s (%s)\n", FBN->ShortName, FBN->LongName); } } if(PI->SelectedChipNode->LockType != 0) { printf("Reading lockmode...\n"); lockmode = 0; for(i = 0; i < PI->SelectedChipNode->LockNode->NumberOfBits; i++) if((1 << ((PI->SelectedChipNode->LockNode->ReadBits >> (i * 4)) & 0x07)) & SerBuff) lockmode |= 1 << i; for(LBN = PI->SelectedChipNode->LockNode->FirstLockBitNode; LBN; LBN = LBN->Next) if(lockmode == LBN->Mask) break; if(LBN) printf(" Mode %d (%s)\n", LBN->Mode, LBN->LongName); else printf("Warning: Found no matching lockmode!\n"); } } else { print_comm_err('F'); return(False); } } if(GET_ARG(PI->args, ARG_ENABLE) || GET_ARG(PI->args, ARG_DISABLE)) { if(PI->ProgType == PROGTYPE_PAR) { printf("Programming fuses...\n"); for(data = GET_ARG(PI->args, ARG_ENABLE); data; data = data->next) { found = False; for(FBN = PI->SelectedChipNode->FuseNode->FirstFuseBitNode; FBN; FBN = FBN->Next) { if(!nocase_strcmp(data->data, FBN->ShortName)) { found = True; printf(" Enabling %-8s (%s)\n", FBN->ShortName, FBN->LongName); mask &= ~(1 << FBN->BitNum); break; } } if(!found) printf("Warning: Unknown fuse: %s\n", (char *)data->data); } for(data = GET_ARG(PI->args, ARG_DISABLE); data; data = data->next) { found = False; for(FBN = PI->SelectedChipNode->FuseNode->FirstFuseBitNode; FBN; FBN = FBN->Next) { if(!nocase_strcmp(data->data, FBN->ShortName)) { found = True; printf(" Disabling %-8s (%s)\n", FBN->ShortName, FBN->LongName); mask |= 1 << FBN->BitNum; break; } } if(!found) printf("Warning: Unknown fuse: %s\n", (char *)data->data); } for(FBN = PI->SelectedChipNode->FuseNode->FirstFuseBitNode; FBN; FBN = FBN->Next) { found = False; for(data = GET_ARG(PI->args, ARG_ENABLE); data; data = data->next) { if(!nocase_strcmp(data->data, FBN->ShortName)) { found = True; break; } } if(!found) for(data = GET_ARG(PI->args, ARG_DISABLE); data; data = data->next) { if(!nocase_strcmp(data->data, FBN->ShortName)) { found = True; break; } } if(!found) { if(~mask & (1 << FBN->BitNum)) printf(" Enabling %-8s (%s)\n", FBN->ShortName, FBN->LongName); else printf(" Disabling %-8s (%s)\n", FBN->ShortName, FBN->LongName); } } SerWriteByte(PI->Ser, 'f'); SerWriteByte(PI->Ser, mask); if(!((SerReadData(PI->Ser, &SerBuff, 1)) && (SerBuff == 13))) { print_comm_err('f'); return(False); } } else printf("Warning: Fuse programming is not supported by serial mode programmers\n"); } if(GET_ARG(PI->args, ARG_LOCKMODE)) { if(!nocase_strcmp((char *)GET_ARG(PI->args, ARG_LOCKMODE), "list")) lockmode_list = True; else { printf("Programming lockmode...\n"); for(LBN = PI->SelectedChipNode->LockNode->FirstLockBitNode; LBN; LBN = LBN->Next) if(LBN->Mode == atoi(GET_ARG(PI->args, ARG_LOCKMODE))) break; if(LBN) { printf(" Mode %d (%s)\n", LBN->Mode, LBN->LongName); mask = 0xff; for(i = 0; i < PI->SelectedChipNode->LockNode->NumberOfBits; i++) if(!(LBN->Mask & (1 << i))) mask &= ~(1 << ((PI->SelectedChipNode->LockNode->WriteBits >> (i * 4)) & 0x07)); SerWriteByte(PI->Ser, 'l'); SerWriteByte(PI->Ser, mask); if(!((SerReadData(PI->Ser, &SerBuff, 1)) && (SerBuff == 13))) { print_comm_err('l'); return(False); } } else { lockmode_list = True; printf("Warning: Unsupported lockmode %s\n", (char *)GET_ARG(PI->args, ARG_LOCKMODE)); } } if(lockmode_list) { printf("Available lockmodes:\n"); for(LBN = PI->SelectedChipNode->LockNode->FirstLockBitNode; LBN; LBN = LBN->Next) printf(" Mode %d: %s\n", LBN->Mode, LBN->LongName); } } return(True); } void print_comm_err(char comm) { printf("Error: No response to command: "); switch(comm) { case 'P': printf("Enter programming mode"); break; case 'A': printf("Set address"); break; case 'c': printf("Write program memory, low byte"); break; case 'C': printf("Write program memory, high byte"); break; case 'R': printf("Read program memory"); break; case 'D': printf("Write data memory"); break; case 'd': printf("Read data memory"); break; case 'e': printf("Chip erase"); break; case 'l': printf("Write lock bits"); break; case 'f': printf("Write fuse bits"); break; case 'F': printf("Read fuse and lock bits"); break; case 'L': printf("Leave programming mode"); break; case 'T': printf("Select device type"); break; case 's': printf("Read signature bytes"); break; case 't': printf("Return supported device codes"); break; case 'S': printf("Return software identifier"); break; case 'V': printf("Return software version"); break; case 'v': printf("Return hardware version"); break; case 'p': printf("Return programmer type"); break; case 'x': printf("Set LED"); break; case 'y': printf("Clear LED"); break; } printf(" (%c)\n", comm); }