├── .cvsignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── ChangeLog-2001 ├── ChangeLog-2002 ├── ChangeLog-2003 ├── ChangeLog-2004-2006 ├── ChangeLog-2007 ├── ChangeLog-2008 ├── ChangeLog-2009 ├── Makefile.am ├── NEWS ├── README ├── arduino.c ├── arduino.h ├── avr.c ├── avr.h ├── avr910.c ├── avr910.h ├── avrdude.1 ├── avrdude.conf.in ├── avrdude.h ├── avrdude.spec.in ├── avrpart.c ├── avrpart.h ├── bitbang.c ├── bitbang.h ├── bootstrap ├── buspirate.c ├── buspirate.h ├── butterfly.c ├── butterfly.h ├── config.c ├── config.h ├── config_gram.y ├── configure.ac ├── confwin.c ├── confwin.h ├── crc16.c ├── crc16.h ├── doc ├── .cvsignore ├── Makefile.am ├── TODO └── avrdude.texi ├── fileio.c ├── fileio.h ├── freebsd_ppi.h ├── jtagmkI.c ├── jtagmkI.h ├── jtagmkII.c ├── jtagmkII.h ├── jtagmkII_private.h ├── jtagmkI_private.h ├── lexer.l ├── linux_ppdev.h ├── lists.c ├── lists.h ├── main.c ├── my_ddk_hidsdi.h ├── par.c ├── par.h ├── pgm.c ├── pgm.h ├── pindefs.h ├── ppi.c ├── ppi.h ├── ppiwin.c ├── safemode.c ├── safemode.h ├── ser_avrdoper.c ├── ser_posix.c ├── ser_win32.c ├── serbb.h ├── serbb_posix.c ├── serbb_win32.c ├── serial.h ├── solaris_ecpp.h ├── stk500.c ├── stk500.h ├── stk500_private.h ├── stk500generic.c ├── stk500generic.h ├── stk500v2.c ├── stk500v2.h ├── stk500v2_private.h ├── term.c ├── term.h ├── tools ├── get-dw-params.xsl ├── get-hv-params.xsl ├── get-stk600-cards.xsl └── get-stk600-devices.xsl ├── update.c ├── update.h ├── usb_libusb.c ├── usbasp.c ├── usbasp.h ├── usbdevs.h ├── usbtiny.c ├── usbtiny.h └── windows ├── .cvsignore ├── Makefile.am ├── giveio.c ├── giveio.sys ├── install_giveio.bat ├── loaddrv.c ├── loaddrv.h ├── remove_giveio.bat └── status_giveio.bat /.cvsignore: -------------------------------------------------------------------------------- 1 | *.diff 2 | *.patch 3 | y.output 4 | y.tab.h 5 | lexer.c 6 | config_gram.c 7 | config_gram.h 8 | .cvsignore 9 | .depend 10 | .deps 11 | INSTALL 12 | Makefile.in 13 | Makefile 14 | ac_cfg.h.in 15 | aclocal.m4 16 | autom4te.cache 17 | configure 18 | depcomp 19 | install-sh 20 | compile 21 | missing 22 | mkinstalldirs 23 | stamp-h.in 24 | stamp-h1 25 | ac_cfg.h 26 | avrdude.conf 27 | avrdude.conf.tmp 28 | avrdude.spec 29 | config.guess 30 | config.log 31 | config.status 32 | config.sub 33 | avrdude 34 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | AVRDUDE was written by: 2 | 3 | Brian S. Dean 4 | 5 | Contributors: 6 | 7 | Joerg Wunsch 8 | Eric Weddington 9 | Jan-Hinnerk Reichert 10 | Alex Shepherd 11 | Martin Thomas 12 | Theodore A. Roth 13 | Michael Holzt 14 | Colin O'Flynn 15 | Thomas Fischl 16 | David Hoerl 17 | Michal Ludvig 18 | 19 | For minor contributions, please see the ChangeLog files. 20 | 21 | -------------------------------------------------------------------------------- /ChangeLog-2002: -------------------------------------------------------------------------------- 1 | 2002-12-12 Brian S. Dean 2 | 3 | * main.c: minor cleanup 4 | 5 | 2002-12-07 Brian S. Dean 6 | 7 | * avrdude.1, main.c: 8 | If the stk500 is being used, default to using the first serial port. 9 | 10 | 2002-12-03 Brian S. Dean 11 | 12 | * avrdude.1: Mention STK500 support. 13 | 14 | 2002-12-01 Brian S. Dean 15 | 16 | * stk500.c: Remove unused code. 17 | 18 | * CHANGELOG, stk500.c: 19 | Document changes since the previous version in the CHANGELOG. 20 | 21 | Cleanup stk500.c a bit. 22 | 23 | * stk500.c: Fix cut and paste braino. 24 | 25 | * avr.c, avrdude.conf.sample, main.c, pgm.h, stk500.c: 26 | The STK500 can perform paged read/write operations even on standard 27 | "non-paged" parts. Take advantage of that and use the faster internal 28 | routines of the STK500 for those parts as well. 29 | 30 | * avr.c, avr.h, avrpart.h, main.c, pgm.c, pgm.h, stk500.c: 31 | Optimize reading and writing for the STK500 programmer if the part 32 | supports paged reads and writes. This greatly decreases the 33 | program/verify time from about 4.5 minutes down to about 10 seconds in 34 | a 12K program size test case. 35 | 36 | Print out the hardware and firmware version for the STK500 if verbose 37 | is enabled. 38 | 39 | * avrdude.conf.sample, avrpart.h, config_gram.y, lexer.l, pgm.h: 40 | * ppi.c, ppi.h, stk500.c, stk500.h, stk500_private.h: 41 | Add basic support for STK500. 42 | 43 | 2002-11-30 Brian S. Dean 44 | 45 | * avrdude.conf.sample, config.c, config.h, config_gram.y, lexer.l: 46 | * main.c, pgm.c, pgm.h, ppi.c, ppi.h, term.c, term.h, Makefile: 47 | * avr.c, avr.h: 48 | Seperate programmer operations out into a driver-like interface so 49 | that programmers other than the direct parallel port connection can be 50 | supported. 51 | 52 | 2002-11-23 Brian S. Dean 53 | 54 | * CHANGELOG, main.c, term.c: 55 | term.c - when in interactive terminal mode and dumping memory using 56 | the 'dump ' command without any address information, 57 | and the end of memory is reached, wrap back around to zero on 58 | the next invocation. 59 | 60 | CHANGELOG - describe changes 61 | 62 | main.c - update version number 63 | 64 | * main.c: 65 | When getting ready to initiate communications with the AVR device, 66 | first pull /RESET low for a short period of time before enabling the 67 | buffer chip. This sequence allows the AVR to be reset before the 68 | buffer is enabled to avoid a short period of time where the AVR may be 69 | driving the programming lines at the same time the programmer tries 70 | to. Of course, if a buffer is being used, then the /RESET line from 71 | the programmer needs to be directly connected to the AVR /RESET line 72 | and not via the buffer chip. 73 | 74 | 2002-11-06 Brian S. Dean 75 | 76 | * CHANGELOG: Update changelog. 77 | 78 | * avr.c, avr.h, main.c: Fix -Y option. Reported by Joerg Wunsch. 79 | 80 | 2002-11-01 Brian S. Dean 81 | 82 | * CHANGELOG, main.c: Version update and CHANGELOG entry. 83 | 84 | * avr.c: 85 | Be backward compatible with the 2-byte rewrite cycle counter which 86 | appeared in version 2.1.0, but was changed to a 4 byte counter in 87 | version 2.1.1. Reminded by Joerg Wunsch. 88 | 89 | 2002-10-29 Brian S. Dean 90 | 91 | * CHANGELOG, avrdude.1, main.c: 92 | Add '-V' (no verify) flag requested by Joerg Wunsch. Update the man 93 | page. 94 | 95 | 2002-10-13 Brian S. Dean 96 | 97 | * CHANGELOG, avrdude.1: Update man page and changelog. 98 | 99 | * main.c: Update version number. 100 | 101 | 2002-10-12 Brian S. Dean 102 | 103 | * Makefile: Remove --pedantic and -g from the compiler options. 104 | 105 | 2002-10-11 Brian S. Dean 106 | 107 | * avr.c, term.c: 108 | Use a four byte value instead of a two byte value for the programming 109 | cycle count stored at the end of EEPROM. It seems as though Atmel was 110 | greatly conservative in claiming a 1000 count reliability for the 111 | FLASH. I current have a part that has been reprogrammed 173330 times, 112 | and counting. 113 | 114 | Fix a compiler warning. 115 | 116 | * avrdude.conf.sample: 117 | Fix ATMega128 instruction encoding for reading the low and high fuse 118 | bits. Thanks to Joerg Wunsch for tripping over this. 119 | 120 | 2002-08-01 Brian S. Dean 121 | 122 | * avr.c, avrdude.1, main.c: 123 | Move erase-rewrite cycle increment to within the chip erase routine so 124 | that it is tracked no matter where the erase was initiated: command 125 | line mode or interactive mode, without code duplicaiton. 126 | 127 | * CHANGELOG: Recent updates. 128 | 129 | * avr.c: Eliminate unused variables. 130 | 131 | * avr.c, avr.h, avrdude.1, fileio.c, main.c: 132 | Implement a way of tracking how many erase-rewrite cycles a part has 133 | undergone. This utilizes the last two bytes of EEPROM to maintain a 134 | counter that is incremented each time the part is erased. 135 | 136 | 2002-07-27 Brian S. Dean 137 | 138 | * avr.c, main.c: 139 | Fix a typo in a comment. Display the size of memory being written. 140 | Display the correct memory name in an error message (previously 141 | hardcoded). 142 | 143 | 2002-06-22 Brian S. Dean 144 | 145 | * CHANGELOG, avrdude.conf.sample: 146 | Add support for ATtiny15 - contributed by Asher Hoskins 147 | 148 | 149 | 2002-04-23 Brian S. Dean 150 | 151 | * CHANGELOG: Say what changed. 152 | 153 | 2002-04-07 Brian S. Dean 154 | 155 | * Makefile, avrdude.conf.sample: 156 | Backup the config file to a timestamped name to keep from possibly 157 | overwriting user-modified configs. 158 | 159 | Add read/write instructions for all memory types for ATMEGA103, 160 | ATMEGA128, ATMEGA16, and ATMEGA8. 161 | 162 | 2002-04-05 Brian S. Dean 163 | 164 | * avrdude.conf.sample: 165 | Add support for ATMEGA128; untested; requested by Jeff Gardner 166 | . 167 | 168 | 2002-02-15 Brian S. Dean 169 | 170 | * avrdude.conf.sample: Minor ordering. 171 | 172 | * CHANGELOG, main.c: Update version numbers. 173 | 174 | 2002-02-14 Brian S. Dean 175 | 176 | * CHANGELOG: Summarize latest updates. 177 | 178 | * avrdude.conf.sample, config_gram.y: 179 | Make pwroff_after_write a yes/no field instead of a numeric. 180 | 181 | * avrdude.conf.sample: Document the pwroff_after_write flag. 182 | 183 | * avr.c: Enable the extra part verbosity when verbosity >= 3. 184 | 185 | * avr.c, avr.h, avrdude.conf.sample, config_gram.y, lexer.l: 186 | * main.c, term.c: 187 | Fix error reporting by avr_write_byte(). 188 | 189 | Fix setting of status LEDs under various write-fail conditions. 190 | 191 | Add a flag to indicate that a memory type requires the device to 192 | possibly be powered off and back on after a write to it. This is due 193 | to a hardware problem on some Atmel devices, see: 194 | 195 | http://www.atmel.com/atmel/acrobat/doc1280.pdf 196 | 197 | Add greater verbosity to the part-display code when verbose>1 to 198 | display avrprog's encoding of the defined programming instructions. 199 | This is primarily for debugging purposes. 200 | 201 | 202 | Part updates: 203 | 204 | * add the AT90S4414 part 205 | 206 | * add fuse and lock bit access instructions for the AT90S1200, 207 | AT90S4434, and AT90S8515. 208 | 209 | * add the pwroff_after_write flag to the fuse bits for the AT90S2333 210 | and AT90S4433 parts 211 | 212 | 2002-02-09 Brian S. Dean 213 | 214 | * avrdude.conf.sample: 215 | Updates to the 2333 and 4433 parts, contributed by Joerg Wunsh. 216 | 217 | 2002-01-18 Brian S. Dean 218 | 219 | * CHANGELOG: Add changelog. 220 | 221 | 2002-01-12 Brian S. Dean 222 | 223 | * main.c: Add (c) to copyright. 224 | 225 | * fileio.c, fileio.h, lexer.l, lists.c, lists.h, main.c: 226 | * pindefs.h, ppi.c, ppi.h, term.c, term.h, avr.c, avr.h: 227 | * config.c, config.h, config_gram.y: 228 | Update version number. Update copyright. 229 | 230 | * avrdude.1: Update copyright and add description of "default". 231 | 232 | Submitted by: Joerg Wunsch 233 | 234 | * avr.c, term.c: 235 | Fix programming of write-only memories (such as lock bits on the 236 | 2313). 237 | 238 | -------------------------------------------------------------------------------- /ChangeLog-2003: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigmike/avrdude/f3d3c3c126e916e0f5591f18f18d05b35a33bbc2/ChangeLog-2003 -------------------------------------------------------------------------------- /ChangeLog-2008: -------------------------------------------------------------------------------- 1 | 2008-11-20 Joerg Wunsch 2 | 3 | * avrdude.h: Change the prototype for usleep() to be more Cygwin- 4 | friendly. 5 | * ppiwin.c: (Ditto.) 6 | 7 | 2008-11-06 Joerg Wunsch 8 | 9 | Submitted by limor 10 | * usbtiny.c (usbtiny_cmd): Replace sizeof() by a fixed constant 11 | 4 for the result array, because otherwise it would take the size 12 | of a pointer which miserably fails on 64-bit machines. 13 | 14 | 2008-11-05 Joerg Wunsch 15 | 16 | patch #6609: Using PCI parallel port cards on Windows 17 | * ppiwin.c (ppi_open): If the port parameter passed from the 18 | -p option is neither lpt1/2/3, try interpreting it directly as 19 | a base address. 20 | * avrdude.1: Document the change. 21 | * doc/avrdude.texi: (Ditto.) 22 | 23 | 2008-11-04 Joerg Wunsch 24 | 25 | bug #22882: Erase Cycle Counter does not work for stk500v2 26 | * stk500v2.c (stk500v2_chip_erase,stk500hv_chip_erase): Return 27 | the expected 0 for success rather than a protocol-dependant 28 | number. 29 | 30 | 2008-11-04 Joerg Wunsch 31 | 32 | bug #22883: Chip Erase performed even with no-write flag (-n) 33 | * main.c: Do not erase the chip if both, -e and -n options have 34 | been specified. 35 | 36 | 2008-11-04 Joerg Wunsch 37 | 38 | bug #24589: AT90USB64* have wrong signature 39 | * avrdude.conf.in: Uncomment the correct, and delete the wrong 40 | signature for AT90USB646/647. Alas, the datasheet has never been 41 | corrected for years. 42 | 43 | 2008-10-31 Joerg Wunsch 44 | 45 | * jtagmkII.c: Fix a serious memory corruption that happened when 46 | using the JTAG ICE mkII (or AVR Dragon) in ISP mode. The wrong 47 | set of per-programmer private data had been allocated (stk500v2 48 | vs. jtagmkII) which was too small to hold the actual data. 49 | * jtagmkII.h: (Ditto.) 50 | * stk500v2.c: (Ditto.) 51 | 52 | 2008-07-29 Joerg Wunsch 53 | 54 | * jtagmkII.c: Implement Xmega JTAG support. 55 | * jtagmkII_private.h: Add EMULATOR_MODE_JTAG_XMEGA. 56 | 57 | 2008-07-29 Joerg Wunsch 58 | 59 | * main.c: Remember whether the device initialization worked, and 60 | allow to continue with -F if it failed yet do not attempt to 61 | perform anything on the device itself. That way, -tF could be 62 | specified for programmers like the STK500/STK600 even without a 63 | device connected, just in order to allow changing parameters on 64 | the programmer itself. 65 | * avrdude.1: Document that possible use of the -F option. 66 | * doc/avrdude.texi: (Ditto.) 67 | 68 | 2008-07-29 Joerg Wunsch 69 | 70 | * stk500v2.c (stk600_xprog_paged_write): Fix a fatal miscalculation 71 | of the number of bytes to be written which caused a malloc chunk 72 | corruption. 73 | 74 | 2008-07-27 Joerg Wunsch 75 | 76 | First implementation of ATxmega support. By now, only the 77 | PDI mode of the STK600 is supported. Single-byte EEPROM 78 | (and flash) updates do not work yet. 79 | * avr.c: "boot" memory is a candidate memory region for paged 80 | operations, besides "flash" and "eeprom". 81 | * avrdude.conf.in: add ATxmega128A1 and ATxmega128A1revD 82 | * avrpart.h: add the AVRPART_HAS_PDI flag (used to distinguish 83 | ATxmega parts from classic AVRs), the nvm_base part field, and 84 | the offset field for a memory region. 85 | * config_gram.y: add "has_pdi", "nvm_base", and "offset" 86 | * lexer.l: (Ditto.) 87 | * main.c: disable auto_erase for ATxmega parts 88 | * stk500v2.c: implement the XPROG functionality, and divert to 89 | this for ATxmega parts 90 | * avrdude.1: Document the changes. 91 | * doc/avrdude.texi: (Ditto.) 92 | 93 | 2008-07-25 Joerg Wunsch 94 | 95 | Fix a bunch of warnings. 96 | * avr910.c (avr910_paged_load): possible unitialized use of 97 | rd_size 98 | * jtagmkI.c (jtagmkI_initialize): pointer signedness mixup 99 | * jtagmkII.c (jtagmkII_print_parms1): propagate const'ness 100 | of parameter 101 | * usbasp.c (usbasp_transmit): pointer signedness mixup 102 | * ser_avrdoper.c (usbGetReport): remove useless pointer deref 103 | 104 | 2008-07-25 Joerg Wunsch 105 | 106 | Contributed by Ville Voipio: 107 | patch #6501: New autotools support for avrdude 108 | * Makefile.am: add @WINDOWS_DIRS@ to SUBDIR 109 | * bootstrap: allow for autconf-2.61 and automake-1.10, too 110 | * configure.ac: fix @WINDOWS_DIRS@ recursion, replace 111 | AC_PROG_CC by AM_PROG_CC_C_O, for esoteric reasons 112 | 113 | 2008-06-13 Joerg Wunsch 114 | 115 | Contributed by Janos Sallai : 116 | patch #6074: added support for crossbow's MIB510 programmer 117 | * avrdude.conf.in: Add entry for mib510. 118 | * stk500.c: Add special hooks to handle the MIB510 programmer. 119 | It mostly talks STK500v1 protocol but has a special hello and 120 | goodbye sequence, and uses a fixed block size of 256 bytes. 121 | * doc/avrdude.texi: Document support for mib510. 122 | 123 | 2008-06-07 Joerg Wunsch 124 | 125 | Contributed by Klaus Leidinger : 126 | * main.c: Realign verbose messages. 127 | * avrpart.c: (Ditto.) 128 | * avr910.c: Print the device code selected in verbose mode. 129 | * butterfly.c: (Ditto.) 130 | 131 | 2008-06-07 Joerg Wunsch 132 | 133 | Contributed by Klaus Leidinger : 134 | Add check for buffermode feature, and use it if present. Can be 135 | turned off using -x no_blockmode. 136 | * avr910.c: Implement buffermode test and usage. 137 | * avrdude.1: Document -x no_blockmode. 138 | * doc/avrdude.texi: (Ditto.) 139 | 140 | 2008-03-24 Joerg Wunsch 141 | 142 | * usb_libusb.c: #undef interface for Win32 143 | 144 | 2008-03-24 Joerg Wunsch 145 | 146 | * avr910.c: Add support for the -x devcode option. 147 | * avrdude.1: Document -x devcode for avr910. 148 | * doc/avrdude.texi: (Ditto.) 149 | 150 | 2008-03-14 Joerg Wunsch 151 | 152 | Add initial support for the Atmel STK600, for 153 | "classic" AVRs (AT90, ATtiny, ATmega) in both, 154 | ISP and high-voltage programming modes. 155 | * Makefile.am: Add -lm. 156 | * avrdude.conf.in: Add stk600, stk600pp, and stk600hvsp. 157 | * config_gram.y: Add support for the stk600* keywords. 158 | * lexer.l: (Ditto.) 159 | * pgm.h: Add the "chan" parameter to set_varef(). 160 | * stk500.c: (Ditto.) 161 | * serial.h: Add USB endpoint support to struct filedescriptor. 162 | * stk500v2.c: Implement the meat of the STK600 support. 163 | * stk500v2.h: Add new prototypes for stk600*() programmers. 164 | * stk500v2_private.h: Add new constants used in the STK600. 165 | * term.c: Add AREF channel support. 166 | * usb_libusb.c: Automatically determine the correct write 167 | endpoint ID, the STK600 uses 0x83 while all other tools use 168 | 0x82. Propagate the EP to use through struct filedescriptor. 169 | * usbdevs.h: Add the STK600 USB product ID. 170 | * tools/get-stk600-cards.xsl: XSL transformation for 171 | targetboards.xml to obtain the list of socket and routing 172 | card IDs, to be used in stk500v2.c (for displaying the 173 | names). 174 | * tools/get-stk600-devices.xsl: XSL transformation for 175 | targetboards.xml to obtain the table of socket/routing cards 176 | and their respective AVR device support for doc/avrdude.texi. 177 | * avrdude.1: Document all the STK600 stuff. 178 | * doc/avrdude.texi: Ditto. Added a new chapter for 179 | Programmer Specific Information. 180 | 181 | 2008-01-26 Joerg Wunsch 182 | 183 | * stk500v2.c (stk500v2_recv): Make length computation unsigned so 184 | it cannot accidentally become negative. 185 | 186 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # avrdude - A Downloader/Uploader for AVR device programmers 3 | # Copyright (C) 2003, 2004 Theodore A. Roth 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | # 19 | 20 | # 21 | # $Id$ 22 | # 23 | 24 | EXTRA_DIST = \ 25 | ChangeLog \ 26 | ChangeLog-2001 \ 27 | ChangeLog-2002 \ 28 | ChangeLog-2003 \ 29 | ChangeLog-2004-2006 \ 30 | ChangeLog-2007 \ 31 | ChangeLog-2008 \ 32 | ChangeLog-2009 \ 33 | avrdude.1 \ 34 | avrdude.spec \ 35 | bootstrap 36 | 37 | CLEANFILES = \ 38 | config_gram.c \ 39 | config_gram.h \ 40 | lexer.c 41 | 42 | #SUBDIRS = doc @WINDOWS_DIRS@ 43 | #DIST_SUBDIRS = doc windows 44 | 45 | SUBDIRS = @SUBDIRS_AC@ 46 | SUBDIRS += @WINDOWS_DIRS@ 47 | DIST_SUBDIRS = @DIST_SUBDIRS_AC@ 48 | 49 | AM_YFLAGS = -d 50 | 51 | avrdude_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" 52 | 53 | libavrdude_a_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" 54 | 55 | avrdude_CFLAGS = @ENABLE_WARNINGS@ 56 | 57 | libavrdude_a_CFLAGS = @ENABLE_WARNINGS@ 58 | 59 | avrdude_LDADD = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB@ @LIBUSB_1_0@ @LIBHID@ -lm 60 | 61 | bin_PROGRAMS = avrdude 62 | 63 | noinst_LIBRARIES = libavrdude.a 64 | 65 | # automake thinks these generated files should be in the distribution, 66 | # but this might cause trouble for some users, so we rather don't want 67 | # to have them there. 68 | # 69 | # See 70 | # 71 | # https://savannah.nongnu.org/bugs/index.php?func=detailitem&item_id=15536 72 | # 73 | # for why we don't want to have them. 74 | dist-hook: 75 | rm -f \ 76 | $(distdir)/lexer.c \ 77 | $(distdir)/config_gram.c \ 78 | $(distdir)/config_gram.h 79 | 80 | libavrdude_a_SOURCES = \ 81 | config_gram.y \ 82 | lexer.l \ 83 | arduino.h \ 84 | arduino.c \ 85 | avr.c \ 86 | avr.h \ 87 | avr910.c \ 88 | avr910.h \ 89 | avrdude.h \ 90 | avrpart.c \ 91 | avrpart.h \ 92 | bitbang.c \ 93 | bitbang.h \ 94 | buspirate.c \ 95 | buspirate.h \ 96 | butterfly.c \ 97 | butterfly.h \ 98 | config.c \ 99 | config.h \ 100 | confwin.c \ 101 | confwin.h \ 102 | crc16.c \ 103 | crc16.h \ 104 | fileio.c \ 105 | fileio.h \ 106 | freebsd_ppi.h \ 107 | jtagmkI.c \ 108 | jtagmkI.h \ 109 | jtagmkI_private.h \ 110 | jtagmkII.c \ 111 | jtagmkII.h \ 112 | jtagmkII_private.h \ 113 | linux_ppdev.h \ 114 | lists.c \ 115 | lists.h \ 116 | my_ddk_hidsdi.h \ 117 | par.c \ 118 | par.h \ 119 | pgm.c \ 120 | pgm.h \ 121 | pindefs.h \ 122 | ppi.c \ 123 | ppi.h \ 124 | ppiwin.c \ 125 | safemode.c \ 126 | safemode.h \ 127 | serial.h \ 128 | serbb.h \ 129 | serbb_posix.c \ 130 | serbb_win32.c \ 131 | ser_avrdoper.c \ 132 | ser_posix.c \ 133 | ser_win32.c \ 134 | solaris_ecpp.h \ 135 | stk500.c \ 136 | stk500.h \ 137 | stk500_private.h \ 138 | stk500v2.c \ 139 | stk500v2.h \ 140 | stk500v2_private.h \ 141 | stk500generic.c \ 142 | stk500generic.h \ 143 | usbasp.c \ 144 | usbasp.h \ 145 | usbdevs.h \ 146 | usb_libusb.c \ 147 | usbtiny.h \ 148 | usbtiny.c \ 149 | update.h \ 150 | update.c 151 | 152 | avrdude_SOURCES = \ 153 | main.c \ 154 | term.c \ 155 | term.h 156 | 157 | man_MANS = avrdude.1 158 | 159 | sysconf_DATA = avrdude.conf 160 | 161 | install-exec-local: backup-avrdude-conf 162 | 163 | distclean-local: 164 | rm -f avrdude.conf 165 | 166 | # This will get run before the config file is installed. 167 | backup-avrdude-conf: 168 | @echo "Backing up avrdude.conf in ${DESTDIR}${sysconfdir}" 169 | @if test -e ${DESTDIR}${sysconfdir}/avrdude.conf; then \ 170 | cp -pR ${DESTDIR}${sysconfdir}/avrdude.conf \ 171 | ${DESTDIR}${sysconfdir}/avrdude.conf.bak; \ 172 | fi 173 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigmike/avrdude/f3d3c3c126e916e0f5591f18f18d05b35a33bbc2/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See the documentation file for the details. 2 | 3 | The latest version of AVRDUDE is always available here: 4 | 5 | http://savannah.nongnu.org/projects/avrdude 6 | 7 | -------------------------------------------------------------------------------- /arduino.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2009 Lars Immisch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /* 23 | * avrdude interface for Arduino programmer 24 | * 25 | * The Arduino programmer is mostly a STK500v1, just the signature bytes 26 | * are read differently. 27 | */ 28 | 29 | #include "ac_cfg.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "avrdude.h" 36 | #include "pgm.h" 37 | #include "stk500_private.h" 38 | #include "stk500.h" 39 | #include "serial.h" 40 | 41 | /* read signature bytes - arduino version */ 42 | static int arduino_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m) 43 | { 44 | unsigned char buf[32]; 45 | 46 | /* Signature byte reads are always 3 bytes. */ 47 | 48 | if (m->size < 3) { 49 | fprintf(stderr, "%s: memsize too small for sig byte read", progname); 50 | return -1; 51 | } 52 | 53 | buf[0] = Cmnd_STK_READ_SIGN; 54 | buf[1] = Sync_CRC_EOP; 55 | 56 | serial_send(&pgm->fd, buf, 2); 57 | 58 | if (serial_recv(&pgm->fd, buf, 5) < 0) 59 | return -1; 60 | if (buf[0] == Resp_STK_NOSYNC) { 61 | fprintf(stderr, "%s: stk500_cmd(): programmer is out of sync\n", 62 | progname); 63 | return -1; 64 | } else if (buf[0] != Resp_STK_INSYNC) { 65 | fprintf(stderr, 66 | "\n%s: arduino_read_sig_bytes(): (a) protocol error, " 67 | "expect=0x%02x, resp=0x%02x\n", 68 | progname, Resp_STK_INSYNC, buf[0]); 69 | return -2; 70 | } 71 | if (buf[4] != Resp_STK_OK) { 72 | fprintf(stderr, 73 | "\n%s: arduino_read_sig_bytes(): (a) protocol error, " 74 | "expect=0x%02x, resp=0x%02x\n", 75 | progname, Resp_STK_OK, buf[4]); 76 | return -3; 77 | } 78 | 79 | m->buf[0] = buf[1]; 80 | m->buf[1] = buf[2]; 81 | m->buf[2] = buf[3]; 82 | 83 | return 3; 84 | } 85 | 86 | static int arduino_open(PROGRAMMER * pgm, char * port) 87 | { 88 | strcpy(pgm->port, port); 89 | if (serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd)==-1) { 90 | return -1; 91 | } 92 | 93 | /* Clear DTR and RTS to unload the RESET capacitor 94 | * (for example in Arduino) */ 95 | serial_set_dtr_rts(&pgm->fd, 0); 96 | usleep(50*1000); 97 | /* Set DTR and RTS back to high */ 98 | serial_set_dtr_rts(&pgm->fd, 1); 99 | usleep(50*1000); 100 | 101 | /* 102 | * drain any extraneous input 103 | */ 104 | stk500_drain(pgm, 0); 105 | 106 | if (stk500_getsync(pgm) < 0) 107 | return -1; 108 | 109 | return 0; 110 | } 111 | 112 | static void arduino_close(PROGRAMMER * pgm) 113 | { 114 | serial_set_dtr_rts(&pgm->fd, 0); 115 | serial_close(&pgm->fd); 116 | pgm->fd.ifd = -1; 117 | } 118 | 119 | void arduino_initpgm(PROGRAMMER * pgm) 120 | { 121 | /* This is mostly a STK500; just the signature is read 122 | differently than on real STK500v1 123 | and the DTR signal is set when opening the serial port 124 | for the Auto-Reset feature */ 125 | stk500_initpgm(pgm); 126 | 127 | strcpy(pgm->type, "Arduino"); 128 | pgm->read_sig_bytes = arduino_read_sig_bytes; 129 | pgm->open = arduino_open; 130 | pgm->close = arduino_close; 131 | } 132 | -------------------------------------------------------------------------------- /arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2009 Lars Immisch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef arduino_h__ 23 | #define arduino_h__ 24 | 25 | void arduino_initpgm (PROGRAMMER * pgm); 26 | 27 | #endif 28 | 29 | 30 | -------------------------------------------------------------------------------- /avr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef __avr_h__ 23 | #define __avr_h__ 24 | 25 | #include 26 | 27 | #include "avrpart.h" 28 | #include "pgm.h" 29 | 30 | typedef void (*FP_UpdateProgress)(int percent, double etime, char *hdr); 31 | 32 | extern struct avrpart parts[]; 33 | 34 | extern FP_UpdateProgress update_progress; 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, 41 | unsigned long addr, unsigned char * value); 42 | 43 | int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, 44 | int verbose); 45 | 46 | int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, 47 | unsigned long addr); 48 | 49 | int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, 50 | unsigned long addr, unsigned char data); 51 | 52 | int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, 53 | unsigned long addr, unsigned char data); 54 | 55 | int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, 56 | int verbose); 57 | 58 | int avr_signature(PROGRAMMER * pgm, AVRPART * p); 59 | 60 | int avr_verify(AVRPART * p, AVRPART * v, char * memtype, int size); 61 | 62 | int avr_get_cycle_count(PROGRAMMER * pgm, AVRPART * p, int * cycles); 63 | 64 | int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles); 65 | 66 | int avr_mem_hiaddr(AVRMEM * mem); 67 | 68 | int avr_chip_erase(PROGRAMMER * pgm, AVRPART * p); 69 | 70 | void report_progress (int completed, int total, char *hdr); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /avr910.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Theodore A. Roth 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef avr910_h 23 | #define avr910_h 24 | 25 | #include "avrpart.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | void avr910_initpgm (PROGRAMMER * pgm); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* avr910_h */ 38 | -------------------------------------------------------------------------------- /avrdude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2007 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef avrdude_h 23 | #define avrdude_h 24 | 25 | extern char * progname; /* name of program, for messages */ 26 | extern char progbuf[]; /* spaces same length as progname */ 27 | 28 | extern int do_cycles; /* track erase-rewrite cycles (-y) */ 29 | extern int ovsigck; /* override signature check (-F) */ 30 | extern int verbose; /* verbosity level (-v, -vv, ...) */ 31 | extern int quell_progress; /* quiteness level (-q, -qq) */ 32 | 33 | #if defined(WIN32NATIVE) 34 | 35 | #include "ac_cfg.h" 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #if !defined(HAVE_USLEEP) 43 | int usleep(unsigned int us); 44 | #endif 45 | 46 | #if !defined(HAVE_GETTIMEOFDAY) 47 | struct timezone; 48 | int gettimeofday(struct timeval *tv, struct timezone *tz); 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | #endif /* HAVE_GETTIMEOFDAY */ 53 | 54 | #endif /* defined(WIN32NATIVE) */ 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /avrdude.spec.in: -------------------------------------------------------------------------------- 1 | ## -*- mode: rpm-spec; -*- 2 | ## 3 | ## $Id$ 4 | ## 5 | ## @configure_input@ 6 | ## 7 | 8 | %define debug_package %{nil} 9 | 10 | %define _with_docs 1 11 | %{?_without_docs: %define _with_docs 0} 12 | 13 | Summary: AVRDUDE is software for programming Atmel AVR Microcontrollers. 14 | Name: avrdude 15 | Version: @VERSION@ 16 | Release: 1 17 | URL: http://savannah.nongnu.org/projects/avrdude 18 | Source0: %{name}-%{version}.tar.gz 19 | License: GPL 20 | Group: Development/Tools 21 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 22 | 23 | %description 24 | AVRDUDE is software for programming Atmel AVR Microcontrollers. 25 | 26 | %if %{_with_docs} 27 | ## The avrdude-docs subpackage 28 | %package docs 29 | Summary: Documentation for AVRDUDE. 30 | Group: Documentation 31 | %description docs 32 | Documentation for avrdude in info, html, postscript and pdf formats. 33 | %endif 34 | 35 | %prep 36 | %setup -q 37 | 38 | %build 39 | 40 | ./configure --prefix=%{_prefix} --sysconfdir=/etc --mandir=%{_mandir} \ 41 | --infodir=%{_infodir} \ 42 | %if %{_with_docs} 43 | --enable-doc=yes 44 | %else 45 | --enable-doc=no 46 | %endif 47 | 48 | make 49 | 50 | %install 51 | rm -rf $RPM_BUILD_ROOT 52 | make prefix=$RPM_BUILD_ROOT%{_prefix} \ 53 | sysconfdir=$RPM_BUILD_ROOT/etc \ 54 | mandir=$RPM_BUILD_ROOT%{_mandir} \ 55 | infodir=$RPM_BUILD_ROOT%{_infodir} \ 56 | install 57 | 58 | rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/%{name}-%{version} 59 | rm -f $RPM_BUILD_ROOT%{_infodir}/dir 60 | 61 | %clean 62 | rm -rf $RPM_BUILD_ROOT 63 | 64 | %if %{_with_docs} 65 | %post docs 66 | [ -f %{_infodir}/avrdude.info ] && \ 67 | /sbin/install-info %{_infodir}/avrdude.info %{_infodir}/dir || : 68 | [ -f %{_infodir}/avrdude.info.gz ] && \ 69 | /sbin/install-info %{_infodir}/avrdude.info.gz %{_infodir}/dir || : 70 | 71 | %preun docs 72 | if [ $1 = 0 ]; then 73 | [ -f %{_infodir}/avrdude.info ] && \ 74 | /sbin/install-info --delete %{_infodir}/avrdude.info %{_infodir}/dir || : 75 | [ -f %{_infodir}/avrdude.info.gz ] && \ 76 | /sbin/install-info --delete %{_infodir}/avrdude.info.gz %{_infodir}/dir || : 77 | fi 78 | %endif 79 | 80 | %files 81 | %defattr(-,root,root) 82 | %{_prefix}/bin/avrdude 83 | %{_mandir}/man1/avrdude.1.gz 84 | %attr(0644,root,root) %config /etc/avrdude.conf 85 | 86 | %if %{_with_docs} 87 | %files docs 88 | %doc %{_infodir}/*info* 89 | %doc doc/avrdude-html/*.html 90 | %doc doc/TODO 91 | %doc doc/avrdude.ps 92 | %doc doc/avrdude.pdf 93 | %endif 94 | 95 | %changelog 96 | * Fri Sep 23 2005 Galen Seitz 97 | - Default to enable-doc=yes during configure. 98 | - Move info file to docs package. 99 | - Make building of docs package conditional. Basic idea copied from avr-gcc. 100 | 101 | * Wed Aug 27 2003 Theodore A. Roth 102 | [Thanks to Artur Lipowski ] 103 | - Do not build debug package. 104 | - Remove files not packaged to quell RH9 rpmbuild complaints. 105 | 106 | * Wed Mar 05 2003 Theodore A. Roth 107 | - Add docs sub-package. 108 | - Add %post and %preun scriptlets for handling info files. 109 | 110 | * Wed Feb 26 2003 Theodore A. Roth 111 | - Initial build. 112 | 113 | 114 | -------------------------------------------------------------------------------- /avrpart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Brian S. Dean 4 | * Copyright (C) 2006 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #ifndef avrpart_h 24 | #define avrpart_h 25 | 26 | #include 27 | 28 | #include "lists.h" 29 | 30 | 31 | /* 32 | * AVR serial programming instructions 33 | */ 34 | enum { 35 | AVR_OP_READ, 36 | AVR_OP_WRITE, 37 | AVR_OP_READ_LO, 38 | AVR_OP_READ_HI, 39 | AVR_OP_WRITE_LO, 40 | AVR_OP_WRITE_HI, 41 | AVR_OP_LOADPAGE_LO, 42 | AVR_OP_LOADPAGE_HI, 43 | AVR_OP_LOAD_EXT_ADDR, 44 | AVR_OP_WRITEPAGE, 45 | AVR_OP_CHIP_ERASE, 46 | AVR_OP_PGM_ENABLE, 47 | AVR_OP_MAX 48 | }; 49 | 50 | 51 | enum { 52 | AVR_CMDBIT_IGNORE, /* bit is ignored on input and output */ 53 | AVR_CMDBIT_VALUE, /* bit is set to 0 or 1 for input or output */ 54 | AVR_CMDBIT_ADDRESS, /* this bit represents an input address bit */ 55 | AVR_CMDBIT_INPUT, /* this bit is an input bit */ 56 | AVR_CMDBIT_OUTPUT /* this bit is an output bit */ 57 | }; 58 | 59 | enum { /* these are assigned to reset_disposition of AVRPART */ 60 | RESET_DEDICATED, /* reset pin is dedicated */ 61 | RESET_IO /* reset pin might be configured as an I/O pin */ 62 | }; 63 | 64 | enum ctl_stack_t { 65 | CTL_STACK_NONE, /* no control stack defined */ 66 | CTL_STACK_PP, /* parallel programming control stack */ 67 | CTL_STACK_HVSP /* high voltage serial programming control stack */ 68 | }; 69 | 70 | /* 71 | * serial programming instruction bit specifications 72 | */ 73 | typedef struct cmdbit { 74 | int type; /* AVR_CMDBIT_* */ 75 | int bitno; /* which input bit to use for this command bit */ 76 | int value; /* bit value if type == AVR_CMDBIT_VALUD */ 77 | } CMDBIT; 78 | 79 | typedef struct opcode { 80 | CMDBIT bit[32]; /* opcode bit specs */ 81 | } OPCODE; 82 | 83 | 84 | #define AVRPART_SERIALOK 0x0001 /* part supports serial programming */ 85 | #define AVRPART_PARALLELOK 0x0002 /* part supports parallel programming */ 86 | #define AVRPART_PSEUDOPARALLEL 0x0004 /* part has pseudo parallel support */ 87 | #define AVRPART_HAS_JTAG 0x0008 /* part has a JTAG i/f */ 88 | #define AVRPART_ALLOWFULLPAGEBITSTREAM 0x0010 /* JTAG ICE mkII param. */ 89 | #define AVRPART_ENABLEPAGEPROGRAMMING 0x0020 /* JTAG ICE mkII param. */ 90 | #define AVRPART_HAS_DW 0x0040 /* part has a debugWire i/f */ 91 | #define AVRPART_HAS_PDI 0x0080 /* part has PDI i/f rather than ISP (ATxmega) */ 92 | #define AVRPART_AVR32 0x0100 /* part is in AVR32 family */ 93 | #define AVRPART_INIT_SMC 0x0200 /* part will undergo chip erase */ 94 | #define AVRPART_WRITE 0x0400 /* at least one write operation specified */ 95 | #define AVRPART_HAS_TPI 0x0800 /* part has TPI i/f rather than ISP (ATtiny4/5/9/10) */ 96 | 97 | #define AVR_DESCLEN 64 98 | #define AVR_IDLEN 32 99 | #define CTL_STACK_SIZE 32 100 | #define FLASH_INSTR_SIZE 3 101 | #define EEPROM_INSTR_SIZE 20 102 | typedef struct avrpart { 103 | char desc[AVR_DESCLEN]; /* long part name */ 104 | char id[AVR_IDLEN]; /* short part name */ 105 | int stk500_devcode; /* stk500 device code */ 106 | int avr910_devcode; /* avr910 device code */ 107 | int chip_erase_delay; /* microseconds */ 108 | unsigned char pagel; /* for parallel programming */ 109 | unsigned char bs2; /* for parallel programming */ 110 | unsigned char signature[3]; /* expected value of signature bytes */ 111 | int reset_disposition; /* see RESET_ enums */ 112 | int retry_pulse; /* retry program enable by pulsing 113 | this pin (PIN_AVR_*) */ 114 | unsigned flags; /* see AVRPART_ masks */ 115 | 116 | int timeout; /* stk500 v2 xml file parameter */ 117 | int stabdelay; /* stk500 v2 xml file parameter */ 118 | int cmdexedelay; /* stk500 v2 xml file parameter */ 119 | int synchloops; /* stk500 v2 xml file parameter */ 120 | int bytedelay; /* stk500 v2 xml file parameter */ 121 | int pollindex; /* stk500 v2 xml file parameter */ 122 | unsigned char pollvalue; /* stk500 v2 xml file parameter */ 123 | int predelay; /* stk500 v2 xml file parameter */ 124 | int postdelay; /* stk500 v2 xml file parameter */ 125 | int pollmethod; /* stk500 v2 xml file parameter */ 126 | 127 | enum ctl_stack_t ctl_stack_type; /* what to use the ctl stack for */ 128 | unsigned char controlstack[CTL_STACK_SIZE]; /* stk500v2 PP/HVSP ctl stack */ 129 | unsigned char flash_instr[FLASH_INSTR_SIZE]; /* flash instructions (debugWire, JTAG) */ 130 | unsigned char eeprom_instr[EEPROM_INSTR_SIZE]; /* EEPROM instructions (debugWire, JTAG) */ 131 | 132 | int hventerstabdelay; /* stk500 v2 hv mode parameter */ 133 | int progmodedelay; /* stk500 v2 hv mode parameter */ 134 | int latchcycles; /* stk500 v2 hv mode parameter */ 135 | int togglevtg; /* stk500 v2 hv mode parameter */ 136 | int poweroffdelay; /* stk500 v2 hv mode parameter */ 137 | int resetdelayms; /* stk500 v2 hv mode parameter */ 138 | int resetdelayus; /* stk500 v2 hv mode parameter */ 139 | int hvleavestabdelay; /* stk500 v2 hv mode parameter */ 140 | int resetdelay; /* stk500 v2 hv mode parameter */ 141 | int chiperasepulsewidth; /* stk500 v2 hv mode parameter */ 142 | int chiperasepolltimeout; /* stk500 v2 hv mode parameter */ 143 | int chiperasetime; /* stk500 v2 hv mode parameter */ 144 | int programfusepulsewidth; /* stk500 v2 hv mode parameter */ 145 | int programfusepolltimeout; /* stk500 v2 hv mode parameter */ 146 | int programlockpulsewidth; /* stk500 v2 hv mode parameter */ 147 | int programlockpolltimeout; /* stk500 v2 hv mode parameter */ 148 | int synchcycles; /* stk500 v2 hv mode parameter */ 149 | int hvspcmdexedelay; /* stk500 v2 xml file parameter */ 150 | 151 | unsigned char idr; /* JTAG ICE mkII XML file parameter */ 152 | unsigned char rampz; /* JTAG ICE mkII XML file parameter */ 153 | unsigned char spmcr; /* JTAG ICE mkII XML file parameter */ 154 | unsigned short eecr; /* JTAC ICE mkII XML file parameter */ 155 | unsigned int nvm_base; /* Base address of NVM controller in ATxmega devices */ 156 | 157 | OPCODE * op[AVR_OP_MAX]; /* opcodes */ 158 | 159 | LISTID mem; /* avr memory definitions */ 160 | char config_file[PATH_MAX]; /* config file where defined */ 161 | int lineno; /* config file line number */ 162 | } AVRPART; 163 | 164 | #define AVR_MEMDESCLEN 64 165 | typedef struct avrmem { 166 | char desc[AVR_MEMDESCLEN]; /* memory description ("flash", "eeprom", etc) */ 167 | int paged; /* page addressed (e.g. ATmega flash) */ 168 | int size; /* total memory size in bytes */ 169 | int page_size; /* size of memory page (if page addressed) */ 170 | int num_pages; /* number of pages (if page addressed) */ 171 | unsigned int offset; /* offset in IO memory (ATxmega) */ 172 | int min_write_delay; /* microseconds */ 173 | int max_write_delay; /* microseconds */ 174 | int pwroff_after_write; /* after this memory type is written to, 175 | the device must be powered off and 176 | back on, see errata 177 | http://www.atmel.com/atmel/acrobat/doc1280.pdf */ 178 | unsigned char readback[2]; /* polled read-back values */ 179 | 180 | int mode; /* stk500 v2 xml file parameter */ 181 | int delay; /* stk500 v2 xml file parameter */ 182 | int blocksize; /* stk500 v2 xml file parameter */ 183 | int readsize; /* stk500 v2 xml file parameter */ 184 | int pollindex; /* stk500 v2 xml file parameter */ 185 | 186 | unsigned char * buf; /* pointer to memory buffer */ 187 | OPCODE * op[AVR_OP_MAX]; /* opcodes */ 188 | } AVRMEM; 189 | 190 | #ifdef __cplusplus 191 | extern "C" { 192 | #endif 193 | 194 | /* Functions for OPCODE structures */ 195 | OPCODE * avr_new_opcode(void); 196 | int avr_set_bits(OPCODE * op, unsigned char * cmd); 197 | int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr); 198 | int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data); 199 | int avr_get_output(OPCODE * op, unsigned char * res, unsigned char * data); 200 | 201 | /* Functions for AVRMEM structures */ 202 | AVRMEM * avr_new_memtype(void); 203 | int avr_initmem(AVRPART * p); 204 | AVRMEM * avr_dup_mem(AVRMEM * m); 205 | AVRMEM * avr_locate_mem(AVRPART * p, char * desc); 206 | void avr_mem_display(const char * prefix, FILE * f, AVRMEM * m, int type, 207 | int verbose); 208 | 209 | /* Functions for AVRPART structures */ 210 | AVRPART * avr_new_part(void); 211 | AVRPART * avr_dup_part(AVRPART * d); 212 | AVRPART * locate_part(LISTID parts, char * partdesc); 213 | AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode); 214 | void avr_display(FILE * f, AVRPART * p, const char * prefix, int verbose); 215 | 216 | typedef void (*walk_avrparts_cb)(const char *name, const char *desc, 217 | const char *cfgname, int cfglineno, 218 | void *cookie); 219 | void walk_avrparts(LISTID programmers, walk_avrparts_cb cb, void *cookie); 220 | 221 | #ifdef __cplusplus 222 | } 223 | #endif 224 | 225 | #endif /* avrpart_h */ 226 | -------------------------------------------------------------------------------- /bitbang.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean 4 | * Copyright (C) 2005 Michael Holzt 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | /* $Id$ */ 21 | 22 | #ifndef bitbang_h 23 | #define bitbang_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int bitbang_setpin(int fd, int pin, int value); 30 | int bitbang_getpin(int fd, int pin); 31 | int bitbang_highpulsepin(int fd, int pin); 32 | void bitbang_delay(unsigned int us); 33 | 34 | void bitbang_check_prerequisites(PROGRAMMER *pgm); 35 | 36 | int bitbang_rdy_led (PROGRAMMER * pgm, int value); 37 | int bitbang_err_led (PROGRAMMER * pgm, int value); 38 | int bitbang_pgm_led (PROGRAMMER * pgm, int value); 39 | int bitbang_vfy_led (PROGRAMMER * pgm, int value); 40 | int bitbang_cmd (PROGRAMMER * pgm, unsigned char cmd[4], 41 | unsigned char res[4]); 42 | int bitbang_spi (PROGRAMMER * pgm, unsigned char cmd[], 43 | unsigned char res[], int count); 44 | int bitbang_chip_erase (PROGRAMMER * pgm, AVRPART * p); 45 | int bitbang_program_enable (PROGRAMMER * pgm, AVRPART * p); 46 | void bitbang_powerup (PROGRAMMER * pgm); 47 | void bitbang_powerdown (PROGRAMMER * pgm); 48 | int bitbang_initialize (PROGRAMMER * pgm, AVRPART * p); 49 | void bitbang_disable (PROGRAMMER * pgm); 50 | void bitbang_enable (PROGRAMMER * pgm); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # autoconf-2.59 or 2.61, 2.62 is known to work 4 | 5 | : ${AUTOHEADER="autoheader${AC_VER}"} 6 | : ${AUTOCONF="autoconf${AC_VER}"} 7 | 8 | # automake-1.9.x or 1.10 is known to work 9 | 10 | : ${ACLOCAL="aclocal${AM_VER}"} 11 | : ${AUTOMAKE="automake${AM_VER}"} 12 | 13 | # Verify autoconf version 14 | 15 | AUTOCONF_VER=`(${AUTOCONF} --version 2>/dev/null | head -n 1 | \ 16 | cut -d ' ' -f 4) 2>/dev/null` 17 | if [ "$AUTOCONF_VER" != "2.59" -a "$AUTOCONF_VER" != "2.61" -a "$AUTOCONF_VER" != "2.62" ] 18 | then 19 | echo "Warning: This program is tested with autoconf version 2.59, 2.61 and 2.62." 20 | echo "You are using `${AUTOCONF} --version | head -n 1`." 21 | fi 22 | 23 | # Verify automake version 24 | 25 | AUTOMAKE_VER=`(${AUTOMAKE} --version | head -n 1 | \ 26 | cut -d ' ' -f 4 | cut -d '.' -f -2) 2>/dev/null` 27 | if [ "$AUTOMAKE_VER" != "1.9" -a "$AUTOMAKE_VER" != "1.10" ] 28 | then 29 | echo "Warning: This program is tested with automake version 1.9 and 1.10." 30 | echo "You are using `${AUTOMAKE} --version | head -n 1`." 31 | fi 32 | 33 | export ACLOCAL AUTOHEADER AUTOCONF AUTOMAKE 34 | 35 | # Bootstrap the build system. 36 | 37 | set -x 38 | 39 | rm -rf autom4te.cache 40 | 41 | ${ACLOCAL} 42 | ${AUTOHEADER} 43 | ${AUTOCONF} 44 | ${AUTOMAKE} -a -c 45 | -------------------------------------------------------------------------------- /buspirate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * 4 | * avrdude support for The Bus Pirate - universal serial interface 5 | * 6 | * Copyright (C) 2009 Michal Ludvig 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | /* $Id$ */ 24 | 25 | #ifndef buspirate_h 26 | #define buspirate_h 27 | 28 | void buspirate_initpgm (struct programmer_t *pgm); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /butterfly.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Theodore A. Roth 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef butterfly_h 23 | #define butterfly_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void butterfly_initpgm (PROGRAMMER * pgm); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* butterfly_h */ 36 | -------------------------------------------------------------------------------- /config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #include "ac_cfg.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "avrdude.h" 31 | #include "avr.h" 32 | #include "config.h" 33 | #include "config_gram.h" 34 | 35 | char default_programmer[MAX_STR_CONST]; 36 | char default_parallel[PATH_MAX]; 37 | char default_serial[PATH_MAX]; 38 | 39 | char string_buf[MAX_STR_CONST]; 40 | char *string_buf_ptr; 41 | 42 | LISTID string_list; 43 | LISTID number_list; 44 | PROGRAMMER * current_prog; 45 | AVRPART * current_part; 46 | AVRMEM * current_mem; 47 | LISTID part_list; 48 | LISTID programmers; 49 | 50 | int lineno; 51 | const char * infile; 52 | 53 | extern char * yytext; 54 | 55 | #define DEBUG 0 56 | 57 | 58 | int init_config(void) 59 | { 60 | string_list = lcreat(NULL, 0); 61 | number_list = lcreat(NULL, 0); 62 | current_prog = NULL; 63 | current_part = NULL; 64 | current_mem = 0; 65 | part_list = lcreat(NULL, 0); 66 | programmers = lcreat(NULL, 0); 67 | 68 | lineno = 1; 69 | infile = NULL; 70 | 71 | return 0; 72 | } 73 | 74 | 75 | 76 | int yywrap() 77 | { 78 | return 1; 79 | } 80 | 81 | 82 | int yyerror(char * errmsg) 83 | { 84 | fprintf(stderr, "%s at %s:%d\n", errmsg, infile, lineno); 85 | exit(1); 86 | } 87 | 88 | 89 | TOKEN * new_token(int primary) 90 | { 91 | TOKEN * tkn; 92 | 93 | tkn = (TOKEN *)malloc(sizeof(TOKEN)); 94 | if (tkn == NULL) { 95 | fprintf(stderr, "new_token(): out of memory\n"); 96 | exit(1); 97 | } 98 | 99 | memset(tkn, 0, sizeof(TOKEN)); 100 | 101 | tkn->primary = primary; 102 | 103 | return tkn; 104 | } 105 | 106 | 107 | void free_token(TOKEN * tkn) 108 | { 109 | if (tkn) { 110 | switch (tkn->primary) { 111 | case TKN_STRING: 112 | case TKN_ID: 113 | if (tkn->value.string) 114 | free(tkn->value.string); 115 | tkn->value.string = NULL; 116 | break; 117 | } 118 | 119 | free(tkn); 120 | } 121 | } 122 | 123 | 124 | void free_tokens(int n, ...) 125 | { 126 | TOKEN * t; 127 | va_list ap; 128 | 129 | va_start(ap, n); 130 | while (n--) { 131 | t = va_arg(ap, TOKEN *); 132 | free_token(t); 133 | } 134 | va_end(ap); 135 | } 136 | 137 | 138 | 139 | TOKEN * number(char * text) 140 | { 141 | struct token_t * tkn; 142 | 143 | tkn = new_token(TKN_NUMBER); 144 | tkn->value.type = V_NUM; 145 | tkn->value.number = atof(text); 146 | 147 | #if DEBUG 148 | fprintf(stderr, "NUMBER(%g)\n", tkn->value.number); 149 | #endif 150 | 151 | return tkn; 152 | } 153 | 154 | 155 | TOKEN * hexnumber(char * text) 156 | { 157 | struct token_t * tkn; 158 | char * e; 159 | 160 | tkn = new_token(TKN_NUMBER); 161 | tkn->value.type = V_NUM; 162 | tkn->value.number = strtoul(text, &e, 16); 163 | if ((e == text) || (*e != 0)) { 164 | fprintf(stderr, "error at %s:%d: can't scan hex number \"%s\"\n", 165 | infile, lineno, text); 166 | exit(1); 167 | } 168 | 169 | #if DEBUG 170 | fprintf(stderr, "HEXNUMBER(%g)\n", tkn->value.number); 171 | #endif 172 | 173 | return tkn; 174 | } 175 | 176 | 177 | TOKEN * string(char * text) 178 | { 179 | struct token_t * tkn; 180 | int len; 181 | 182 | tkn = new_token(TKN_STRING); 183 | 184 | len = strlen(text); 185 | 186 | tkn->value.type = V_STR; 187 | tkn->value.string = (char *) malloc(len+1); 188 | if (tkn->value.string == NULL) { 189 | fprintf(stderr, "id(): out of memory\n"); 190 | exit(1); 191 | } 192 | strcpy(tkn->value.string, text); 193 | 194 | #if DEBUG 195 | fprintf(stderr, "STRING(%s)\n", tkn->value.string); 196 | #endif 197 | 198 | return tkn; 199 | } 200 | 201 | 202 | TOKEN * id(char * text) 203 | { 204 | struct token_t * tkn; 205 | int len; 206 | 207 | tkn = new_token(TKN_ID); 208 | 209 | len = strlen(text); 210 | 211 | tkn->value.type = V_STR; 212 | tkn->value.string = (char *) malloc(len+1); 213 | if (tkn->value.string == NULL) { 214 | fprintf(stderr, "id(): out of memory\n"); 215 | exit(1); 216 | } 217 | strcpy(tkn->value.string, text); 218 | 219 | #if DEBUG 220 | fprintf(stderr, "ID(%s)\n", tkn->value.string); 221 | #endif 222 | 223 | return tkn; 224 | } 225 | 226 | 227 | TOKEN * keyword(int primary) 228 | { 229 | struct token_t * tkn; 230 | 231 | tkn = new_token(primary); 232 | 233 | return tkn; 234 | } 235 | 236 | 237 | void print_token(TOKEN * tkn) 238 | { 239 | if (!tkn) 240 | return; 241 | 242 | fprintf(stderr, "token = %d = ", tkn->primary); 243 | switch (tkn->primary) { 244 | case TKN_NUMBER: 245 | fprintf(stderr, "NUMBER, value=%g", tkn->value.number); 246 | break; 247 | 248 | case TKN_STRING: 249 | fprintf(stderr, "STRING, value=%s", tkn->value.string); 250 | break; 251 | 252 | case TKN_ID: 253 | fprintf(stderr, "ID, value=%s", tkn->value.string); 254 | break; 255 | 256 | default: 257 | fprintf(stderr, ""); 258 | break; 259 | } 260 | 261 | fprintf(stderr, "\n"); 262 | } 263 | 264 | 265 | void pyytext(void) 266 | { 267 | #if DEBUG 268 | fprintf(stderr, "TOKEN: \"%s\"\n", yytext); 269 | #endif 270 | } 271 | 272 | 273 | char * dup_string(const char * str) 274 | { 275 | char * s; 276 | 277 | s = strdup(str); 278 | if (s == NULL) { 279 | fprintf(stderr, "dup_string(): out of memory\n"); 280 | exit(1); 281 | } 282 | 283 | return s; 284 | } 285 | 286 | int read_config(const char * file) 287 | { 288 | FILE * f; 289 | 290 | f = fopen(file, "r"); 291 | if (f == NULL) { 292 | fprintf(stderr, "%s: can't open config file \"%s\": %s\n", 293 | progname, file, strerror(errno)); 294 | return -1; 295 | } 296 | 297 | lineno = 1; 298 | infile = file; 299 | yyin = f; 300 | 301 | yyparse(); 302 | 303 | fclose(f); 304 | 305 | return 0; 306 | } 307 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef config_h 23 | #define config_h 24 | 25 | #include "lists.h" 26 | #include "pindefs.h" 27 | #include "avr.h" 28 | 29 | 30 | #define MAX_STR_CONST 1024 31 | 32 | enum { V_NONE, V_NUM, V_STR }; 33 | typedef struct value_t { 34 | int type; 35 | double number; 36 | char * string; 37 | } VALUE; 38 | 39 | 40 | typedef struct token_t { 41 | int primary; 42 | VALUE value; 43 | } TOKEN; 44 | typedef struct token_t *token_p; 45 | 46 | 47 | extern FILE * yyin; 48 | extern PROGRAMMER * current_prog; 49 | extern AVRPART * current_part; 50 | extern AVRMEM * current_mem; 51 | extern int lineno; 52 | extern const char * infile; 53 | extern LISTID string_list; 54 | extern LISTID number_list; 55 | extern LISTID part_list; 56 | extern LISTID programmers; 57 | extern char default_programmer[]; 58 | extern char default_parallel[]; 59 | extern char default_serial[]; 60 | 61 | 62 | 63 | #if !defined(HAS_YYSTYPE) 64 | #define YYSTYPE token_p 65 | #endif 66 | extern YYSTYPE yylval; 67 | 68 | extern char string_buf[MAX_STR_CONST]; 69 | extern char *string_buf_ptr; 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | int yyparse(void); 76 | 77 | 78 | int init_config(void); 79 | 80 | TOKEN * new_token(int primary); 81 | 82 | void free_token(TOKEN * tkn); 83 | 84 | void free_tokens(int n, ...); 85 | 86 | TOKEN * number(char * text); 87 | 88 | TOKEN * hexnumber(char * text); 89 | 90 | TOKEN * string(char * text); 91 | 92 | TOKEN * id(char * text); 93 | 94 | TOKEN * keyword(int primary); 95 | 96 | void print_token(TOKEN * tkn); 97 | 98 | void pyytext(void); 99 | 100 | char * dup_string(const char * str); 101 | 102 | int read_config(const char * file); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # avrdude - A Downloader/Uploader for AVR device programmers 3 | # Copyright (C) 2003, 2004 Theodore A. Roth 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | # 19 | 20 | # 21 | # $Id$ 22 | # 23 | 24 | # Process this file with autoconf to produce a configure script. 25 | 26 | AC_PREREQ(2.57) 27 | AC_INIT(avrdude, 5.10svn, avrdude-dev@nongnu.org) 28 | 29 | AC_CANONICAL_BUILD 30 | AC_CANONICAL_HOST 31 | AC_CANONICAL_TARGET 32 | 33 | AC_CONFIG_SRCDIR([main.c]) 34 | AM_INIT_AUTOMAKE 35 | AM_CONFIG_HEADER(ac_cfg.h) 36 | 37 | # Checks for programs. 38 | AC_PROG_CC 39 | AC_PROG_INSTALL 40 | AC_PROG_YACC 41 | AC_PROG_LEX 42 | AC_PROG_RANLIB 43 | 44 | dnl Makefile.am:77: compiling `config_gram.c' with per-target flags requires `AM_PROG_CC_C_O' in `configure.ac' 45 | AM_PROG_CC_C_O 46 | 47 | # Checks for libraries. 48 | AC_CHECK_LIB([termcap], [tputs]) 49 | AC_CHECK_LIB([ncurses], [tputs]) 50 | AC_CHECK_LIB([readline], [readline]) 51 | AC_SEARCH_LIBS([gethostent], [nsl]) 52 | AC_SEARCH_LIBS([setsockopt], [socket]) 53 | AH_TEMPLATE([HAVE_LIBUSB], 54 | [Define if USB support is enabled via libusb]) 55 | AC_CHECK_LIB([usb], [usb_get_string_simple], [have_libusb=yes]) 56 | if test x$have_libusb = xyes; then 57 | case $target in 58 | *-*-darwin*) 59 | LIBUSB="-lusb -framework CoreFoundation -framework IOKit" 60 | ;; 61 | *) 62 | LIBUSB="-lusb" 63 | ;; 64 | esac 65 | AC_DEFINE([HAVE_LIBUSB]) 66 | fi 67 | AC_SUBST(LIBUSB, $LIBUSB) 68 | 69 | AH_TEMPLATE([HAVE_LIBUSB_1_0], 70 | [Define if USB support is enabled via libusb 1.0]) 71 | AC_CHECK_LIB([usb-1.0], [libusb_init], [have_libusb_1_0=yes]) 72 | if test x$have_libusb_1_0 = xyes; then 73 | case $target in 74 | *-*-darwin*) 75 | LIBUSB_1_0="-lusb-1.0 -framework CoreFoundation -framework IOKit" 76 | ;; 77 | *) 78 | LIBUSB_1_0="-lusb-1.0" 79 | ;; 80 | esac 81 | AC_DEFINE([HAVE_LIBUSB_1_0]) 82 | AC_CHECK_HEADERS([libusb-1.0/libusb.h]) 83 | AC_CHECK_HEADERS([libusb.h]) 84 | fi 85 | AC_SUBST(LIBUSB_1_0, $LIBUSB_1_0) 86 | 87 | # Checks for header files. 88 | AC_CHECK_HEADERS([limits.h stdlib.h string.h]) 89 | AC_CHECK_HEADERS([fcntl.h sys/ioctl.h sys/time.h termios.h unistd.h]) 90 | AC_CHECK_HEADERS([ddk/hidsdi.h],,,[#include 91 | #include ]) 92 | 93 | 94 | # Checks for typedefs, structures, and compiler characteristics. 95 | AC_C_CONST 96 | AC_HEADER_TIME 97 | 98 | # Checks for library functions. 99 | AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul gettimeofday usleep]) 100 | 101 | AC_MSG_CHECKING([for a Win32 HID libray]) 102 | SAVED_LIBS="${LIBS}" 103 | case $target in 104 | *-*-mingw32* | *-*-cygwin* | *-*-windows*) 105 | LIBHID="-lhid -lsetupapi" 106 | if test $ac_cv_header_ddk_hidsdi_h = yes 107 | then 108 | HIDINCLUDE="#include " 109 | else 110 | HIDINCLUDE="#include \"my_ddk_hidsdi.h\"" 111 | fi 112 | ;; 113 | *) 114 | LIBHID="" 115 | ;; 116 | esac 117 | LIBS="${LIBS} ${LIBHID}" 118 | 119 | AH_TEMPLATE([HAVE_LIBHID], 120 | [Define if HID support is enabled via the Win32 DDK]) 121 | AC_TRY_RUN([#include 122 | #include 123 | $HIDINCLUDE 124 | 125 | int 126 | main(void) 127 | { 128 | GUID hidGuid; 129 | HidD_GetHidGuid(&hidGuid); 130 | 131 | return 0; 132 | } 133 | ], [have_libhid=yes], [have_libhid=no], [have_libhid=no]) 134 | AC_MSG_RESULT([$have_libhid]) 135 | if test x$have_libhid = xyes; then 136 | AC_DEFINE([HAVE_LIBHID]) 137 | else 138 | LIBHID="" 139 | fi 140 | LIBS="${SAVED_LIBS}" 141 | AC_SUBST(LIBHID, $LIBHID) 142 | 143 | # Check for types 144 | 145 | # Solaris has uint_t and ulong_t typedefs in , avoid 146 | # the redeclaration in usbtiny.c. 147 | AC_CHECK_TYPES([uint_t], [], [], [#include ]) 148 | AC_CHECK_TYPES([ulong_t], [], [], [#include ]) 149 | 150 | # Checks for misc stuff. 151 | 152 | AC_ARG_ENABLE( 153 | [versioned-doc], 154 | AC_HELP_STRING( 155 | [--enable-versioned-doc], 156 | [install docs in directory with version name (default)]), 157 | [case "${enableval}" in 158 | yes) versioned_doc=yes ;; 159 | no) versioned_doc=no ;; 160 | *) AC_MSG_ERROR(bad value ${enableval} for versioned-doc option) ;; 161 | esac], 162 | [versioned_doc=yes]) 163 | 164 | if test "$versioned_doc" = "yes"; then 165 | DOC_INST_DIR='$(DESTDIR)$(datadir)/doc/avrdude-$(VERSION)' 166 | else 167 | DOC_INST_DIR='$(DESTDIR)$(datadir)/doc/avrdude' 168 | fi 169 | 170 | AC_ARG_ENABLE( 171 | [doc], 172 | AC_HELP_STRING( 173 | [--enable-doc], 174 | [Enable building documents]), 175 | [case "${enableval}" in 176 | yes) enabled_doc=yes ;; 177 | no) enabled_doc=no ;; 178 | *) AC_MSG_ERROR(bad value ${enableval} for disable-doc option) ;; 179 | esac], 180 | [enabled_doc=no]) 181 | 182 | AC_ARG_ENABLE( 183 | [parport], 184 | AC_HELP_STRING( 185 | [--enable-parport], 186 | [Enable accessing parallel ports(default)]), 187 | [case "${enableval}" in 188 | yes) enabled_parport=yes ;; 189 | no) enabled_parport=no ;; 190 | *) AC_MSG_ERROR(bad value ${enableval} for enable-parport option) ;; 191 | esac], 192 | [enabled_parport=yes]) 193 | 194 | DIST_SUBDIRS_AC='doc windows' 195 | 196 | if test "$enabled_doc" = "yes"; then 197 | SUBDIRS_AC='doc' 198 | else 199 | SUBDIRS_AC='' 200 | fi 201 | 202 | AC_SUBST(DOC_INST_DIR, $DOC_INST_DIR) 203 | AC_SUBST(SUBDIRS_AC, $SUBDIRS_AC) 204 | AC_SUBST(DIST_SUBDIRS_AC, $DIST_SUBDIRS_AC) 205 | 206 | 207 | # Find the parallel serial device files based on target system 208 | # If a system doesn't have a PC style parallel, mark it as unknown. 209 | case $target in 210 | i[[3456]]86-*-linux*|x86_64-*-linux*) 211 | DEFAULT_PAR_PORT="/dev/parport0" 212 | DEFAULT_SER_PORT="/dev/ttyS0" 213 | ;; 214 | *-*-linux*) 215 | DEFAULT_PAR_PORT="unknown" 216 | DEFAULT_SER_PORT="/dev/ttyS0" 217 | ;; 218 | i[[3456]]86-*-*freebsd*|amd64-*-*freebsd*) 219 | DEFAULT_PAR_PORT="/dev/ppi0" 220 | DEFAULT_SER_PORT="/dev/cuad0" 221 | ;; 222 | *-*-*freebsd*) 223 | DEFAULT_PAR_PORT="unknown" 224 | DEFAULT_SER_PORT="/dev/cuad0" 225 | ;; 226 | *-*-solaris*) 227 | DEFAULT_PAR_PORT="/dev/printers/0" 228 | DEFAULT_SER_PORT="/dev/term/a" 229 | ;; 230 | *-*-msdos* | *-*-mingw32* | *-*-cygwin* | *-*-windows*) 231 | DEFAULT_PAR_PORT="lpt1" 232 | DEFAULT_SER_PORT="com1" 233 | ;; 234 | *) 235 | DEFAULT_PAR_PORT="unknown" 236 | DEFAULT_SER_PORT="unknown" 237 | ;; 238 | esac 239 | 240 | if test "$enabled_parport" = "yes"; then 241 | AC_MSG_CHECKING([for parallel device]) 242 | if test "$DEFAULT_PAR_PORT" = "unknown"; then 243 | AC_MSG_NOTICE([parallel port access disabled for this system]) 244 | enabled_parport=no 245 | else 246 | AC_MSG_RESULT([$DEFAULT_PAR_PORT]) 247 | fi 248 | AC_SUBST(DEFAULT_PAR_PORT, $DEFAULT_PAR_PORT) 249 | fi 250 | 251 | AC_MSG_CHECKING([for serial device]) 252 | AC_MSG_RESULT([$DEFAULT_SER_PORT]) 253 | AC_SUBST(DEFAULT_SER_PORT, $DEFAULT_SER_PORT) 254 | 255 | if test "$enabled_parport" = "yes"; then 256 | AC_DEFINE(HAVE_PARPORT, 1, [parallel port access enabled]) 257 | confsubst="-e /^@HAVE_PARPORT_/d" 258 | else 259 | confsubst="-e /^@HAVE_PARPORT_BEGIN@/,/^@HAVE_PARPORT_END@/d" 260 | fi 261 | export confsubst 262 | 263 | # If we are compiling with gcc, enable all warning and make warnings errors. 264 | if test "$GCC" = yes; then 265 | ENABLE_WARNINGS="-Wall" 266 | 267 | # does this compiler support -Wno-pointer-sign ? 268 | AC_MSG_CHECKING([if gcc accepts -Wno-pointer-sign ]) 269 | 270 | safe_CFLAGS=$CFLAGS 271 | CFLAGS="$ENABLE_WARNINGS -Wno-pointer-sign" 272 | 273 | AC_TRY_COMPILE(, [ int main () { return 0 ; } ], [ 274 | no_pointer_sign=yes 275 | AC_MSG_RESULT([yes]) 276 | ], [ 277 | no_pointer_sign=no 278 | AC_MSG_RESULT([no]) 279 | ]) 280 | CFLAGS=$safe_CFLAGS 281 | 282 | if test x$no_pointer_sign = xyes; then 283 | ENABLE_WARNINGS="$ENABLE_WARNINGS -Wno-pointer-sign" 284 | fi 285 | fi 286 | AC_SUBST(ENABLE_WARNINGS,$ENABLE_WARNINGS) 287 | 288 | # See if we need to drop into the windows subdir. 289 | case $target in 290 | *-*-mingw32* | *-*-cygwin* | *-*-windows*) 291 | if test "$GCC" = yes -a \( "$CC" = "cc" -o "$CC" = "gcc" \); then 292 | # does this compiler support -mno-cygwin? 293 | AC_MSG_CHECKING([if $CC accepts -mno-cygwin]) 294 | 295 | safe_CFLAGS="$CFLAGS" 296 | CFLAGS="$ENABLE_WARNINGS -mno-cygwin" 297 | 298 | AC_TRY_COMPILE(, [ int main () { return 0 ; } ], [ 299 | no_cygwin=yes 300 | AC_MSG_RESULT([yes]) 301 | ], [ 302 | no_cygwin=no 303 | AC_MSG_RESULT([no]) 304 | ]) 305 | CFLAGS="$safe_CFLAGS" 306 | 307 | if test x$no_cygwin = xyes; then 308 | CFLAGS="${CFLAGS} -mno-cygwin" 309 | else 310 | AC_MSG_NOTICE([Your compiler does not understand the -mno-cygwin option.]) 311 | AC_MSG_NOTICE([You might want to select an alternative compiler, like]) 312 | AC_MSG_NOTICE([]) 313 | AC_MSG_NOTICE([CC=mingw32-gcc ./configure]) 314 | AC_MSG_NOTICE([]) 315 | fi 316 | fi 317 | 318 | AC_MSG_CHECKING([if linker accepts -static]) 319 | 320 | safe_LDFLAGS="$LDFLAGS" 321 | LDFLAGS="${LDFLAGS} -static" 322 | AC_TRY_LINK(, [ int main () { return 0 ; } ], [ 323 | can_link_static=yes 324 | AC_MSG_RESULT([yes]) 325 | ], [ 326 | can_link_static_cygwin=no 327 | AC_MSG_RESULT([no]) 328 | ]) 329 | LDFLAGS="$safe_LDFLAGS" 330 | 331 | if test x$can_link_static = xyes; then 332 | LDFLAGS="${LDFLAGS} -static" 333 | fi 334 | 335 | WINDOWS_DIRS="windows" 336 | CFLAGS="${CFLAGS} -DWIN32NATIVE" 337 | ;; 338 | esac 339 | AC_SUBST(WINDOWS_DIRS,$WINDOWS_DIRS) 340 | 341 | AC_CONFIG_FILES([ 342 | doc/Makefile 343 | windows/Makefile 344 | avrdude.spec 345 | Makefile 346 | ]) 347 | 348 | # The procedure to create avrdude.conf involves two steps. First, 349 | # normal autoconf substitution will be applied, resulting in 350 | # avrdude.conf.tmp. Finally, a sed command will be applied to filter 351 | # out unwanted parts (currently the parallel port programmer types) 352 | # based on previous configuration results, thereby producing the final 353 | # avrdude.conf file. 354 | 355 | AC_CONFIG_FILES([avrdude.conf.tmp:avrdude.conf.in], 356 | [sed $confsubst avrdude.conf.tmp > avrdude.conf]) 357 | 358 | AC_OUTPUT 359 | -------------------------------------------------------------------------------- /confwin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Eric B. Weddington 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #include "avrdude.h" 22 | 23 | #if defined(WIN32NATIVE) 24 | 25 | #include 26 | #include 27 | 28 | 29 | static char *filename; 30 | 31 | 32 | void win_sys_config_set(char sys_config[PATH_MAX]) 33 | { 34 | sys_config[0] = 0; 35 | 36 | /* Use Windows API call to search for the Windows default system config file.*/ 37 | SearchPath(NULL, "avrdude.conf", NULL, PATH_MAX, sys_config, &filename); 38 | return; 39 | } 40 | 41 | 42 | void win_usr_config_set(char usr_config[PATH_MAX]) 43 | { 44 | usr_config[0] = 0; 45 | 46 | /* Use Windows API call to search for the Windows default user config file. */ 47 | SearchPath(NULL, "avrdude.rc", NULL, PATH_MAX, usr_config, &filename); 48 | return; 49 | } 50 | 51 | 52 | #endif 53 | 54 | 55 | -------------------------------------------------------------------------------- /confwin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Eric B. Weddington 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | 22 | #if defined(WIN32NATIVE) 23 | #ifndef confwin_h 24 | #define confwin_h 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | void win_sys_config_set(char sys_config[PATH_MAX]); 31 | void win_usr_config_set(char usr_config[PATH_MAX]); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | #endif 39 | 40 | 41 | -------------------------------------------------------------------------------- /crc16.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Derived from CRC algorithm for JTAG ICE mkII, published in Atmel 3 | * Appnote AVR067. Converted from C++ to C. 4 | */ 5 | #include "crc16.h" 6 | 7 | /* CRC16 Definitions */ 8 | static const unsigned short crc_table[256] = { 9 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 10 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 11 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 12 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 13 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 14 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 15 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 16 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 17 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 18 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 19 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 20 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 21 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 22 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 23 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 24 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 25 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 26 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 27 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 28 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 29 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 30 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 31 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 32 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 33 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 34 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 35 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 36 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 37 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 38 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 39 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 40 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 41 | }; 42 | 43 | /* CRC calculation macros */ 44 | #define CRC_INIT 0xFFFF 45 | #define CRC(crcval,newchar) crcval = (crcval >> 8) ^ \ 46 | crc_table[(crcval ^ newchar) & 0x00ff] 47 | 48 | unsigned short 49 | crcsum(const unsigned char* message, unsigned long length, 50 | unsigned short crc) 51 | { 52 | unsigned long i; 53 | 54 | for(i = 0; i < length; i++) 55 | { 56 | CRC(crc, message[i]); 57 | } 58 | return crc; 59 | } 60 | 61 | int 62 | crcverify(const unsigned char* message, unsigned long length) 63 | { 64 | /* 65 | * Returns true if the last two bytes in a message is the crc of the 66 | * preceding bytes. 67 | */ 68 | unsigned short expected; 69 | 70 | expected = crcsum(message, length - 2, CRC_INIT); 71 | return (expected & 0xff) == message[length - 2] && 72 | ((expected >> 8) & 0xff) == message[length - 1]; 73 | } 74 | 75 | void 76 | crcappend(unsigned char* message, unsigned long length) 77 | { 78 | unsigned long crc; 79 | 80 | crc = crcsum(message, length, CRC_INIT); 81 | message[length] = (unsigned char)(crc & 0xff); 82 | message[length+1] = (unsigned char)((crc >> 8) & 0xff); 83 | } 84 | -------------------------------------------------------------------------------- /crc16.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC16_H 2 | #define CRC16_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * Derived from CRC algorithm for JTAG ICE mkII, published in Atmel 10 | * Appnote AVR067. Converted from C++ to C. 11 | */ 12 | 13 | extern unsigned short crcsum(const unsigned char* message, 14 | unsigned long length, 15 | unsigned short crc); 16 | /* 17 | * Verify that the last two bytes is a (LSB first) valid CRC of the 18 | * message. 19 | */ 20 | extern int crcverify(const unsigned char* message, 21 | unsigned long length); 22 | /* 23 | * Append a two byte CRC (LSB first) to message. length is size of 24 | * message excluding crc. Space for the CRC bytes must be allocated 25 | * in advance! 26 | */ 27 | extern void crcappend(unsigned char* message, 28 | unsigned long length); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /doc/.cvsignore: -------------------------------------------------------------------------------- 1 | .cvsignore 2 | Makefile 3 | Makefile.in 4 | avrdude-html 5 | avrdude.aux 6 | avrdude.cp 7 | avrdude.cps 8 | avrdude.dvi 9 | avrdude.fn 10 | avrdude.info 11 | avrdude.ky 12 | avrdude.log 13 | avrdude.pdf 14 | avrdude.pg 15 | avrdude.ps 16 | avrdude.toc 17 | avrdude.tp 18 | avrdude.vr 19 | mdate-sh 20 | stamp-vti 21 | texinfo.tex 22 | version.texi 23 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # avrdude - A Downloader/Uploader for AVR device programmers 3 | # Copyright (C) 2003 Theodore A. Roth 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | # 19 | 20 | # 21 | # $Id$ 22 | # 23 | 24 | CLEANFILES = \ 25 | version.texi \ 26 | stamp-vti 27 | 28 | info_TEXINFOS = avrdude.texi 29 | 30 | all-local: info html ps pdf 31 | 32 | html: avrdude-html/avrdude.html 33 | 34 | avrdude-html/avrdude.html: $(srcdir)/$(info_TEXINFOS) 35 | texi2html -split_node $(srcdir)/$(info_TEXINFOS) 36 | if [ -e ./avrdude.html -o -e ./avrdude_1.html ]; then \ 37 | mkdir -p avrdude-html ; \ 38 | mv -f *.html avrdude-html ; \ 39 | else \ 40 | mv -f avrdude avrdude-html; \ 41 | fi; 42 | 43 | clean-local: 44 | rm -rf avrdude-html *.info 45 | 46 | install-data-local: install-docs 47 | 48 | install-docs: html ps pdf 49 | $(mkinstalldirs) $(DOC_INST_DIR) 50 | $(INSTALL_DATA) avrdude.ps $(DOC_INST_DIR)/avrdude.ps 51 | $(INSTALL_DATA) avrdude.pdf $(DOC_INST_DIR)/avrdude.pdf 52 | $(mkinstalldirs) $(DOC_INST_DIR)/avrdude-html 53 | @list=`echo avrdude-html/*.html`; \ 54 | for file in $$list; \ 55 | do \ 56 | $(INSTALL_DATA) $$file $(DOC_INST_DIR)/$$file; \ 57 | done 58 | 59 | uninstall-local: 60 | rm -rf $(DOC_INST_DIR) 61 | -------------------------------------------------------------------------------- /doc/TODO: -------------------------------------------------------------------------------- 1 | 2 | - Man page needs updated for avr910 info. 3 | 4 | - Website needs to link to docs: 5 | http://savannah.nongnu.org/download/avrdude/doc/avrdude-html/ 6 | 7 | - Add "skip empty pages" optimization on avr910 paged write. The stk500 has 8 | this optimization already. 9 | 10 | - Fix "overfull \hbox" issues in building documentation. 11 | 12 | - FIXME: term.c: terminal_get_input(): strip newlines in non-readline input 13 | code. 14 | 15 | - FIXME: avr910.c: avr910_cmd(): Insert version check here. 16 | 17 | - FIXME: ser_posix.c: serial_close(): Should really restore the terminal to 18 | original state here. 19 | 20 | - FIXME: main.c, par.c: exitspecs don't work if RESET-pin is controlled over 21 | PPICTRL. 22 | 23 | - transfer ppi-speedtuning to the windows version (CAVEAT: This will make 24 | programming too fast for chips with 500kHz clock) 25 | 26 | - make SCK-period configurable for PPI-programmers 27 | -------------------------------------------------------------------------------- /fileio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef fileio_h 23 | #define fileio_h 24 | 25 | typedef enum { 26 | FMT_AUTO, 27 | FMT_SREC, 28 | FMT_IHEX, 29 | FMT_RBIN, 30 | FMT_IMM, 31 | FMT_HEX, 32 | FMT_DEC, 33 | FMT_OCT, 34 | FMT_BIN 35 | } FILEFMT; 36 | 37 | struct fioparms { 38 | int op; 39 | char * mode; 40 | char * iodesc; 41 | char * dir; 42 | char * rw; 43 | }; 44 | 45 | enum { 46 | FIO_READ, 47 | FIO_WRITE 48 | }; 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | char * fmtstr(FILEFMT format); 55 | 56 | int fileio_setparms(int op, struct fioparms * fp); 57 | 58 | int fileio(int op, char * filename, FILEFMT format, 59 | struct avrpart * p, char * memtype, int size); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /freebsd_ppi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2005 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef freebsd_ppi_h 23 | #define freebsd_ppi_h 24 | 25 | #include 26 | 27 | #define ppi_claim(fd) {} 28 | 29 | #define ppi_release(fd) {} 30 | 31 | #define DO_PPI_READ(fd, reg, valp) \ 32 | (void)ioctl(fd, \ 33 | (reg) == PPIDATA? PPIGDATA: ((reg) == PPICTRL? PPIGCTRL: PPIGSTATUS), \ 34 | valp) 35 | #define DO_PPI_WRITE(fd, reg, valp) \ 36 | (void)ioctl(fd, \ 37 | (reg) == PPIDATA? PPISDATA: ((reg) == PPICTRL? PPISCTRL: PPISSTATUS), \ 38 | valp) 39 | 40 | #endif /* freebsd_ppi_h */ 41 | -------------------------------------------------------------------------------- /jtagmkI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef jtagmkI_h 23 | #define jtagmkI_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void jtagmkI_initpgm (PROGRAMMER * pgm); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /jtagmkII.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2004, 2006 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef jtagmkII_h 23 | #define jtagmkII_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int jtagmkII_send(PROGRAMMER * pgm, unsigned char * data, size_t len); 30 | int jtagmkII_recv(PROGRAMMER * pgm, unsigned char **msg); 31 | void jtagmkII_close(PROGRAMMER * pgm); 32 | int jtagmkII_getsync(PROGRAMMER * pgm, int mode); 33 | int jtagmkII_getparm(PROGRAMMER * pgm, unsigned char parm, 34 | unsigned char * value); 35 | 36 | void jtagmkII_initpgm (PROGRAMMER * pgm); 37 | void jtagmkII_avr32_initpgm (PROGRAMMER * pgm); 38 | void jtagmkII_dw_initpgm (PROGRAMMER * pgm); 39 | void jtagmkII_pdi_initpgm (PROGRAMMER * pgm); 40 | void jtagmkII_dragon_initpgm (PROGRAMMER * pgm); 41 | void jtagmkII_dragon_dw_initpgm (PROGRAMMER * pgm); 42 | void jtagmkII_dragon_pdi_initpgm (PROGRAMMER * pgm); 43 | 44 | /* 45 | * These functions are referenced from stk500v2.c for JTAG ICE mkII 46 | * and AVR Dragon programmers running in one of the STK500v2 47 | * modi. 48 | */ 49 | void jtagmkII_setup(PROGRAMMER * pgm); 50 | void jtagmkII_teardown(PROGRAMMER * pgm); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /jtagmkI_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2005 Joerg Wunsch 4 | * 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | 24 | /* 25 | * JTAG ICE mkI definitions 26 | */ 27 | 28 | /* ICE command codes */ 29 | /* 0x20 Get Synch [Resp_OK] */ 30 | #define CMD_GET_SYNC ' ' 31 | 32 | /* 0x31 Single Step [Sync_CRC/EOP] [Resp_OK] */ 33 | /* 0x32 Read PC [Sync_CRC/EOP] [Resp_OK] [program counter] 34 | * [Resp_OK] */ 35 | /* 0x33 Write PC [program counter] [Sync_CRC/EOP] [Resp_OK] 36 | * [Resp_OK] */ 37 | /* 0xA2 Firmware Upgrade [upgrade string] [Sync_CRC/EOP] [Resp_OK] 38 | * [Resp_OK] */ 39 | /* 0xA0 Set Device Descriptor [device info] [Sync_CRC/EOP] [Resp_OK] 40 | * [Resp_OK] */ 41 | #define CMD_SET_DEVICE_DESCRIPTOR 0xA0 42 | 43 | /* 0x42 Set Parameter [parameter] [setting] [Sync_CRC/EOP] [Resp_OK] 44 | * [Resp_OK] */ 45 | #define CMD_SET_PARAM 'B' 46 | 47 | /* 0x46 Forced Stop [Sync_CRC/EOP] [Resp_OK] [checksum][program 48 | * counter] [Resp_OK] */ 49 | #define CMD_STOP 'F' 50 | 51 | /* 0x47 Go [Sync_CRC/EOP] [Resp_OK] */ 52 | #define CMD_GO 'G' 53 | 54 | /* 0x52 Read Memory [memory type] [word count] [start address] 55 | * [Sync_CRC/EOP] [Resp_OK] [word 0] ... [word n] [checksum] 56 | * [Resp_OK] */ 57 | #define CMD_READ_MEM 'R' 58 | 59 | /* 0x53 Get Sign On [Sync_CRC/EOP] [Resp_OK] ["AVRNOCD"] [Resp_OK] */ 60 | #define CMD_GET_SIGNON 'S' 61 | 62 | /* 0XA1 Erase Page spm [address] [Sync_CRC/EOP] [Resp_OK] [Resp_OK] */ 63 | 64 | /* 0x57 Write Memory [memory type] [word count] [start address] 65 | * [Sync_CRC/EOP] [Resp_OK] [Cmd_DATA] [word 0] ... [word n] */ 66 | #define CMD_WRITE_MEM 'W' 67 | 68 | /* Second half of write memory: the data command. Undocumented. */ 69 | #define CMD_DATA 'h' 70 | 71 | /* 0x64 Get Debug Info [Sync_CRC/EOP] [Resp_OK] [0x00] [Resp_OK] */ 72 | /* 0x71 Get Parameter [parameter] [Sync_CRC/EOP] [Resp_OK] [setting] 73 | * [Resp_OK] */ 74 | #define CMD_GET_PARAM 'q' 75 | 76 | /* 0x78 Reset [Sync_CRC/EOP] [Resp_OK] [Resp_OK] */ 77 | #define CMD_RESET 'x' 78 | 79 | /* 0xA3 Enter Progmode [Sync_CRC/EOP] [Resp_OK] [Resp_OK] */ 80 | #define CMD_ENTER_PROGMODE 0xa3 81 | 82 | /* 0xA4 Leave Progmode [Sync_CRC/EOP] [Resp_OK] [Resp_OK] */ 83 | #define CMD_LEAVE_PROGMODE 0xa4 84 | 85 | /* 0xA5 Chip Erase [Sync_CRC/EOP] [Resp_OK] [Resp_OK] */ 86 | #define CMD_CHIP_ERASE 0xa5 87 | 88 | 89 | /* ICE responses */ 90 | #define RESP_OK 'A' 91 | #define RESP_BREAK 'B' 92 | #define RESP_INFO 'G' 93 | #define RESP_FAILED 'F' 94 | #define RESP_SYNC_ERROR 'E' 95 | #define RESP_SLEEP 'H' 96 | #define RESP_POWER 'I' 97 | 98 | #define PARM_BITRATE 'b' 99 | #define PARM_SW_VERSION 0x7b 100 | #define PARM_HW_VERSION 0x7a 101 | #define PARM_IREG_HIGH 0x81 102 | #define PARM_IREG_LOW 0x82 103 | #define PARM_OCD_VTARGET 0x84 104 | #define PARM_OCD_BREAK_CAUSE 0x85 105 | #define PARM_CLOCK 0x86 106 | #define PARM_EXTERNAL_RESET 0x8b 107 | #define PARM_FLASH_PAGESIZE_LOW 0x88 108 | #define PARM_FLASH_PAGESIZE_HIGH 0x89 109 | #define PARM_EEPROM_PAGESIZE 0x8a 110 | #define PARM_TIMERS_RUNNING 0xa0 111 | #define PARM_BP_FLOW 0xa1 112 | #define PARM_BP_X_HIGH 0xa2 113 | #define PARM_BP_X_LOW 0xa3 114 | #define PARM_BP_Y_HIGH 0xa4 115 | #define PARM_BP_Y_LOW 0xa5 116 | #define PARM_BP_MODE 0xa6 117 | #define PARM_JTAGID_BYTE0 0xa7 118 | #define PARM_JTAGID_BYTE1 0xa8 119 | #define PARM_JTAGID_BYTE2 0xa9 120 | #define PARM_JTAGID_BYTE3 0xaa 121 | #define PARM_UNITS_BEFORE 0xab 122 | #define PARM_UNITS_AFTER 0xac 123 | #define PARM_BIT_BEFORE 0xad 124 | #define PARM_BIT_AFTER 0xae 125 | #define PARM_PSB0_LOW 0xaf 126 | #define PARM_PSBO_HIGH 0xb0 127 | #define PARM_PSB1_LOW 0xb1 128 | #define PARM_PSB1_HIGH 0xb2 129 | #define PARM_MCU_MODE 0xb3 130 | 131 | #define JTAG_BITRATE_1_MHz 0xff 132 | #define JTAG_BITRATE_500_kHz 0xfe 133 | #define JTAG_BITRATE_250_kHz 0xfd 134 | #define JTAG_BITRATE_125_kHz 0xfb 135 | 136 | /* memory types for CMND_{READ,WRITE}_MEMORY */ 137 | #define MTYPE_IO_SHADOW 0x30 /* cached IO registers? */ 138 | #define MTYPE_SRAM 0x20 /* target's SRAM or [ext.] IO registers */ 139 | #define MTYPE_EEPROM 0x22 /* EEPROM, what way? */ 140 | #define MTYPE_EVENT 0x60 /* ICE event memory */ 141 | #define MTYPE_SPM 0xA0 /* flash through LPM/SPM */ 142 | #define MTYPE_FLASH_PAGE 0xB0 /* flash in programming mode */ 143 | #define MTYPE_EEPROM_PAGE 0xB1 /* EEPROM in programming mode */ 144 | #define MTYPE_FUSE_BITS 0xB2 /* fuse bits in programming mode */ 145 | #define MTYPE_LOCK_BITS 0xB3 /* lock bits in programming mode */ 146 | #define MTYPE_SIGN_JTAG 0xB4 /* signature in programming mode */ 147 | #define MTYPE_OSCCAL_BYTE 0xB5 /* osccal cells in programming mode */ 148 | 149 | struct device_descriptor 150 | { 151 | unsigned char ucReadIO[8]; /*LSB = IOloc 0, MSB = IOloc63 */ 152 | unsigned char ucWriteIO[8]; /*LSB = IOloc 0, MSB = IOloc63 */ 153 | unsigned char ucReadIOShadow[8]; /*LSB = IOloc 0, MSB = IOloc63 */ 154 | unsigned char ucWriteIOShadow[8]; /*LSB = IOloc 0, MSB = IOloc63 */ 155 | unsigned char ucReadExtIO[20]; /*LSB = IOloc 96, MSB = IOloc255 */ 156 | unsigned char ucWriteExtIO[20]; /*LSB = IOloc 96, MSB = IOloc255 */ 157 | unsigned char ucReadIOExtShadow[20]; /*LSB = IOloc 96, MSB = IOloc255 */ 158 | unsigned char ucWriteIOExtShadow[20];/*LSB = IOloc 96, MSB = IOloc255 */ 159 | unsigned char ucIDRAddress; /*IDR address */ 160 | unsigned char ucSPMCRAddress; /*SPMCR Register address and dW BasePC */ 161 | unsigned char ucRAMPZAddress; /*RAMPZ Register address in SRAM I/O */ 162 | /*space */ 163 | unsigned char uiFlashPageSize[2]; /*Device Flash Page Size, Size = */ 164 | /*2 exp ucFlashPageSize */ 165 | unsigned char ucEepromPageSize; /*Device Eeprom Page Size in bytes */ 166 | unsigned char ulBootAddress[4]; /*Device Boot Loader Start Address */ 167 | unsigned char uiUpperExtIOLoc; /*Topmost (last) extended I/O */ 168 | /*location, 0 if no external I/O */ 169 | }; 170 | -------------------------------------------------------------------------------- /linux_ppdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003, 2005 Theodore A. Roth 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef linux_ppdev_h 23 | #define linux_ppdev_h 24 | 25 | #define OBSOLETE__IOW _IOW 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #define ppi_claim(fd) \ 34 | if (ioctl(fd, PPCLAIM)) { \ 35 | fprintf(stderr, "%s: can't claim device \"%s\": %s\n\n", \ 36 | progname, port, strerror(errno)); \ 37 | close(fd); \ 38 | exit(1); \ 39 | } 40 | 41 | #define ppi_release(fd) \ 42 | if (ioctl(fd, PPRELEASE)) { \ 43 | fprintf(stderr, "%s: can't release device: %s\n\n", \ 44 | progname, strerror(errno)); \ 45 | exit(1); \ 46 | } 47 | 48 | #define DO_PPI_READ(fd, reg, valp) \ 49 | (void)ioctl(fd, \ 50 | (reg) == PPIDATA? PPRDATA: ((reg) == PPICTRL? PPRCONTROL: PPRSTATUS), \ 51 | valp) 52 | #define DO_PPI_WRITE(fd, reg, valp) \ 53 | (void)ioctl(fd, \ 54 | (reg) == PPIDATA? PPWDATA: ((reg) == PPICTRL? PPWCONTROL: PPWSTATUS), \ 55 | valp) 56 | 57 | #endif /* linux_ppdev_h */ 58 | -------------------------------------------------------------------------------- /lists.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 1990-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /*---------------------------------------------------------------------- 23 | Id: lists.h,v 1.2 2001/08/19 23:13:17 bsd Exp $ 24 | ----------------------------------------------------------------------*/ 25 | /*---------------------------------------------------------------------- 26 | General purpose linked list routines - header file declarations. 27 | 28 | Author : Brian Dean 29 | Date : 10 January, 1990 30 | ----------------------------------------------------------------------*/ 31 | #ifndef lists_h 32 | #define lists_h 33 | 34 | #include 35 | 36 | typedef void * LISTID; 37 | typedef void * LNODEID; 38 | 39 | 40 | /*---------------------------------------------------------------------- 41 | several defines to access the LIST structure as as stack or a queue 42 | --- use for program readability 43 | ----------------------------------------------------------------------*/ 44 | #define STACKID LISTID 45 | #define SNODEID LNODEID 46 | #define QUEUEID LISTID 47 | #define QNODEID LNODEID 48 | 49 | 50 | #define PUSH(s,d) lins_n(s,d,1) /* push 'd' onto the stack */ 51 | #define POP(s) lrmv_n(s,1) /* pop the stack */ 52 | #define LOOKSTACK(s) lget_n(s,1) /* look at the top of the stack, 53 | but don't pop */ 54 | 55 | 56 | #define ENQUEUE(q,d) lins_n(q,d,1) /* put 'd' on the end of the queue */ 57 | #define DEQUEUE(q) lrmv(q) /* remove next item from the front of 58 | the queue */ 59 | #define REQUEUE(q,d) ladd(q,d) /* re-insert (push) item back on the 60 | front of the queue */ 61 | #define LOOKQUEUE(q) lget(q) /* return next item on the queue, 62 | but don't dequeue */ 63 | #define QUEUELEN(q) lsize(q) /* length of the queue */ 64 | 65 | 66 | #define LISTADD(l,d) ladd(l,d) /* add to end of the list */ 67 | #define LISTRMV(l,d) lrmv_d(l,d) /* remove from end of the list */ 68 | 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | /* .................... Function Prototypes .................... */ 75 | 76 | LISTID lcreat ( void * liststruct, int poolsize ); 77 | void ldestroy ( LISTID lid ); 78 | void ldestroy_cb ( LISTID lid, void (*ucleanup)() ); 79 | 80 | LNODEID lfirst ( LISTID ); /* head of the list */ 81 | LNODEID llast ( LISTID ); /* tail of the list */ 82 | LNODEID lnext ( LNODEID ); /* next item in the list */ 83 | LNODEID lprev ( LNODEID ); /* previous item in the list */ 84 | void * ldata ( LNODEID ); /* data at the current position */ 85 | int lsize ( LISTID ); /* number of elements in the list */ 86 | 87 | int ladd ( LISTID lid, void * p ); 88 | int laddo ( LISTID lid, void *p, 89 | int (*compare)(const void *p1,const void *p2), 90 | LNODEID * firstdup ); 91 | int laddu ( LISTID lid, void * p, 92 | int (*compare)(const void *p1,const void *p2)); 93 | int lins_n ( LISTID lid, void * d, unsigned int n ); 94 | int lins_ln ( LISTID lid, LNODEID lnid, void * data_ptr ); 95 | 96 | void * lget ( LISTID lid ); 97 | void * lget_n ( LISTID lid, unsigned int n ); 98 | LNODEID lget_ln ( LISTID lid, unsigned int n ); 99 | 100 | void * lrmv ( LISTID lid ); 101 | void * lrmv_n ( LISTID lid, unsigned int n ); 102 | void * lrmv_ln ( LISTID lid, LNODEID lnid ); 103 | void * lrmv_d ( LISTID lid, void * data_ptr ); 104 | 105 | LISTID lcat ( LISTID lid1, LISTID lid2 ); 106 | 107 | void * lsrch ( LISTID lid, void * p, int (*compare)(void *p1,void *p2)); 108 | 109 | int lprint ( FILE * f, LISTID lid ); 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /my_ddk_hidsdi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2006 Christian Starkjohann 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /* 23 | The following is a replacement for hidsdi.h from the Windows DDK. It defines some 24 | of the types and function prototypes of this header for our project. If you 25 | have the Windows DDK version of this file or a version shipped with MinGW, use 26 | that instead. 27 | */ 28 | #ifndef MY_DDK_HIDSDI_H 29 | #define MY_DDK_HIDSDI_H 30 | #include 31 | #include 32 | #include 33 | typedef struct{ 34 | ULONG Size; 35 | USHORT VendorID; 36 | USHORT ProductID; 37 | USHORT VersionNumber; 38 | }HIDD_ATTRIBUTES; 39 | void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid); 40 | BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes); 41 | BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 42 | BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 43 | BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 44 | BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen); 45 | BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen); 46 | BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers); 47 | BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers); 48 | #include 49 | #endif /* MY_DDK_HIDSDI_H */ 50 | -------------------------------------------------------------------------------- /par.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef par_h 23 | #define par_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void par_initpgm (PROGRAMMER * pgm); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /pgm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2004 Brian S. Dean 4 | * Copyright 2007 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #include "ac_cfg.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "avrdude.h" 30 | #include "pgm.h" 31 | 32 | static int pgm_default_2 (struct programmer_t *, AVRPART *); 33 | static int pgm_default_3 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem, 34 | unsigned long addr, unsigned char * value); 35 | static void pgm_default_4 (struct programmer_t *); 36 | static int pgm_default_5 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem, 37 | unsigned long addr, unsigned char data); 38 | static void pgm_default_6 (struct programmer_t *, const char *); 39 | 40 | 41 | static int pgm_default_open (struct programmer_t *pgm, char * name) 42 | { 43 | fprintf (stderr, "\n%s: Fatal error: Programmer does not support open()", 44 | progname); 45 | exit(1); 46 | } 47 | 48 | static int pgm_default_led (struct programmer_t * pgm, int value) 49 | { 50 | /* 51 | * If programmer has no LEDs, just do nothing. 52 | */ 53 | return 0; 54 | } 55 | 56 | 57 | static void pgm_default_powerup_powerdown (struct programmer_t * pgm) 58 | { 59 | /* 60 | * If programmer does not support powerup/down, just do nothing. 61 | */ 62 | } 63 | 64 | 65 | PROGRAMMER * pgm_new(void) 66 | { 67 | int i; 68 | PROGRAMMER * pgm; 69 | 70 | pgm = (PROGRAMMER *)malloc(sizeof(*pgm)); 71 | if (pgm == NULL) { 72 | fprintf(stderr, "%s: out of memory allocating programmer structure\n", 73 | progname); 74 | exit(1); 75 | } 76 | 77 | memset(pgm, 0, sizeof(*pgm)); 78 | 79 | pgm->id = lcreat(NULL, 0); 80 | pgm->desc[0] = 0; 81 | pgm->type[0] = 0; 82 | pgm->config_file[0] = 0; 83 | pgm->lineno = 0; 84 | pgm->baudrate = 0; 85 | 86 | for (i=0; ipinno[i] = 0; 88 | 89 | /* 90 | * mandatory functions - these are called without checking to see 91 | * whether they are assigned or not 92 | */ 93 | pgm->initialize = pgm_default_2; 94 | pgm->display = pgm_default_6; 95 | pgm->enable = pgm_default_4; 96 | pgm->disable = pgm_default_4; 97 | pgm->powerup = pgm_default_powerup_powerdown; 98 | pgm->powerdown = pgm_default_powerup_powerdown; 99 | pgm->program_enable = pgm_default_2; 100 | pgm->chip_erase = pgm_default_2; 101 | pgm->open = pgm_default_open; 102 | pgm->close = pgm_default_4; 103 | pgm->read_byte = pgm_default_3; 104 | pgm->write_byte = pgm_default_5; 105 | 106 | /* 107 | * predefined functions - these functions have a valid default 108 | * implementation. Hence, they don't need to be defined in 109 | * the programmer. 110 | */ 111 | pgm->rdy_led = pgm_default_led; 112 | pgm->err_led = pgm_default_led; 113 | pgm->pgm_led = pgm_default_led; 114 | pgm->vfy_led = pgm_default_led; 115 | 116 | /* 117 | * optional functions - these are checked to make sure they are 118 | * assigned before they are called 119 | */ 120 | pgm->cmd = NULL; 121 | pgm->spi = NULL; 122 | pgm->paged_write = NULL; 123 | pgm->paged_load = NULL; 124 | pgm->write_setup = NULL; 125 | pgm->read_sig_bytes = NULL; 126 | pgm->set_vtarget = NULL; 127 | pgm->set_varef = NULL; 128 | pgm->set_fosc = NULL; 129 | pgm->perform_osccal = NULL; 130 | pgm->parseextparams = NULL; 131 | pgm->setup = NULL; 132 | pgm->teardown = NULL; 133 | 134 | return pgm; 135 | } 136 | 137 | 138 | static void pgm_default(void) 139 | { 140 | fprintf(stderr, "%s: programmer operation not supported\n", progname); 141 | } 142 | 143 | 144 | static int pgm_default_2 (struct programmer_t * pgm, AVRPART * p) 145 | { 146 | pgm_default(); 147 | return -1; 148 | } 149 | 150 | static int pgm_default_3 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem, 151 | unsigned long addr, unsigned char * value) 152 | { 153 | pgm_default(); 154 | return -1; 155 | } 156 | 157 | static void pgm_default_4 (struct programmer_t * pgm) 158 | { 159 | pgm_default(); 160 | } 161 | 162 | static int pgm_default_5 (struct programmer_t * pgm, AVRPART * p, AVRMEM * mem, 163 | unsigned long addr, unsigned char data) 164 | { 165 | pgm_default(); 166 | return -1; 167 | } 168 | 169 | static void pgm_default_6 (struct programmer_t * pgm, const char * p) 170 | { 171 | pgm_default(); 172 | } 173 | 174 | 175 | void programmer_display(PROGRAMMER * pgm, const char * p) 176 | { 177 | fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type); 178 | fprintf(stderr, "%sDescription : %s\n", p, pgm->desc); 179 | 180 | pgm->display(pgm, p); 181 | } 182 | 183 | PROGRAMMER * locate_programmer(LISTID programmers, const char * configid) 184 | { 185 | LNODEID ln1, ln2; 186 | PROGRAMMER * p = NULL; 187 | const char * id; 188 | int found; 189 | 190 | found = 0; 191 | 192 | for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) { 193 | p = ldata(ln1); 194 | for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) { 195 | id = ldata(ln2); 196 | if (strcasecmp(configid, id) == 0) 197 | found = 1; 198 | } 199 | } 200 | 201 | if (found) 202 | return p; 203 | 204 | return NULL; 205 | } 206 | 207 | /* 208 | * Iterate over the list of programmers given as "programmers", and 209 | * call the callback function cb for each entry found. cb is being 210 | * passed the following arguments: 211 | * . the name of the programmer (for -c) 212 | * . the descriptive text given in the config file 213 | * . the name of the config file this programmer has been defined in 214 | * . the line number of the config file this programmer has been defined at 215 | * . the "cookie" passed into walk_programmers() (opaque client data) 216 | */ 217 | void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie) 218 | { 219 | LNODEID ln1; 220 | PROGRAMMER * p; 221 | 222 | for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) { 223 | p = ldata(ln1); 224 | cb((char *)ldata(lfirst(p->id)), p->desc, p->config_file, p->lineno, cookie); 225 | } 226 | } 227 | 228 | -------------------------------------------------------------------------------- /pgm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2004 Brian S. Dean 4 | * Copyright 2007 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #ifndef pgm_h 24 | #define pgm_h 25 | 26 | #include 27 | 28 | #include "avrpart.h" 29 | #include "lists.h" 30 | #include "pindefs.h" 31 | #include "serial.h" 32 | 33 | #define ON 1 34 | #define OFF 0 35 | 36 | #define PGM_DESCLEN 80 37 | #define PGM_PORTLEN PATH_MAX 38 | #define PGM_TYPELEN 32 39 | 40 | typedef enum { 41 | EXIT_VCC_UNSPEC, 42 | EXIT_VCC_ENABLED, 43 | EXIT_VCC_DISABLED 44 | } exit_vcc_t; 45 | 46 | typedef enum { 47 | EXIT_RESET_UNSPEC, 48 | EXIT_RESET_ENABLED, 49 | EXIT_RESET_DISABLED 50 | } exit_reset_t; 51 | 52 | typedef struct programmer_t { 53 | LISTID id; 54 | char desc[PGM_DESCLEN]; 55 | char type[PGM_TYPELEN]; 56 | char port[PGM_PORTLEN]; 57 | unsigned int pinno[N_PINS]; 58 | exit_vcc_t exit_vcc; 59 | exit_reset_t exit_reset; 60 | int ppidata; 61 | int ppictrl; 62 | int baudrate; 63 | double bitclock; /* JTAG ICE clock period in microseconds */ 64 | int ispdelay; /* ISP clock delay */ 65 | union filedescriptor fd; 66 | int page_size; /* page size if the programmer supports paged write/load */ 67 | int (*rdy_led) (struct programmer_t * pgm, int value); 68 | int (*err_led) (struct programmer_t * pgm, int value); 69 | int (*pgm_led) (struct programmer_t * pgm, int value); 70 | int (*vfy_led) (struct programmer_t * pgm, int value); 71 | int (*initialize) (struct programmer_t * pgm, AVRPART * p); 72 | void (*display) (struct programmer_t * pgm, const char * p); 73 | void (*enable) (struct programmer_t * pgm); 74 | void (*disable) (struct programmer_t * pgm); 75 | void (*powerup) (struct programmer_t * pgm); 76 | void (*powerdown) (struct programmer_t * pgm); 77 | int (*program_enable) (struct programmer_t * pgm, AVRPART * p); 78 | int (*chip_erase) (struct programmer_t * pgm, AVRPART * p); 79 | int (*cmd) (struct programmer_t * pgm, unsigned char cmd[4], 80 | unsigned char res[4]); 81 | int (*spi) (struct programmer_t * pgm, unsigned char cmd[], 82 | unsigned char res[], int count); 83 | int (*open) (struct programmer_t * pgm, char * port); 84 | void (*close) (struct programmer_t * pgm); 85 | int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, 86 | int page_size, int n_bytes); 87 | int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, 88 | int page_size, int n_bytes); 89 | void (*write_setup) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m); 90 | int (*write_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, 91 | unsigned long addr, unsigned char value); 92 | int (*read_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, 93 | unsigned long addr, unsigned char * value); 94 | int (*read_sig_bytes) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m); 95 | void (*print_parms) (struct programmer_t * pgm); 96 | int (*set_vtarget) (struct programmer_t * pgm, double v); 97 | int (*set_varef) (struct programmer_t * pgm, unsigned int chan, double v); 98 | int (*set_fosc) (struct programmer_t * pgm, double v); 99 | int (*set_sck_period) (struct programmer_t * pgm, double v); 100 | int (*setpin) (struct programmer_t * pgm, int pin, int value); 101 | int (*getpin) (struct programmer_t * pgm, int pin); 102 | int (*highpulsepin) (struct programmer_t * pgm, int pin); 103 | int (*parseexitspecs) (struct programmer_t * pgm, char *s); 104 | int (*perform_osccal) (struct programmer_t * pgm); 105 | int (*parseextparams) (struct programmer_t * pgm, LISTID xparams); 106 | void (*setup) (struct programmer_t * pgm); 107 | void (*teardown) (struct programmer_t * pgm); 108 | char config_file[PATH_MAX]; /* config file where defined */ 109 | int lineno; /* config file line number */ 110 | void *cookie; /* for private use by the programmer */ 111 | char flag; /* for private use of the programmer */ 112 | } PROGRAMMER; 113 | 114 | #ifdef __cplusplus 115 | extern "C" { 116 | #endif 117 | 118 | PROGRAMMER * pgm_new(void); 119 | 120 | void programmer_display(PROGRAMMER * pgm, const char * p); 121 | PROGRAMMER * locate_programmer(LISTID programmers, const char * configid); 122 | 123 | typedef void (*walk_programmers_cb)(const char *name, const char *desc, 124 | const char *cfgname, int cfglineno, 125 | void *cookie); 126 | void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie); 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /pindefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef __pindefs_h__ 23 | #define __pindefs_h__ 24 | 25 | enum { 26 | PPI_AVR_VCC=1, 27 | PPI_AVR_BUFF, 28 | PIN_AVR_RESET, 29 | PIN_AVR_SCK, 30 | PIN_AVR_MOSI, 31 | PIN_AVR_MISO, 32 | PIN_LED_ERR, 33 | PIN_LED_RDY, 34 | PIN_LED_PGM, 35 | PIN_LED_VFY, 36 | N_PINS 37 | }; 38 | #define PIN_INVERSE 0x80 /* flag for inverted pin in serbb */ 39 | #define PIN_MASK 0x7f 40 | 41 | #define LED_ON(fd,pin) ppi_setpin(fd,pin,0) 42 | #define LED_OFF(fd,pin) ppi_setpin(fd,pin,1) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ppi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | 23 | #if !defined(WIN32NATIVE) 24 | 25 | #include "ac_cfg.h" 26 | 27 | #if HAVE_PARPORT 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 37 | # include "freebsd_ppi.h" 38 | #elif defined(__linux__) 39 | # include "linux_ppdev.h" 40 | #elif defined(__sun__) || defined(__sun) /* Solaris */ 41 | # include "solaris_ecpp.h" 42 | #endif 43 | 44 | #include "avrdude.h" 45 | #include "avr.h" 46 | #include "pindefs.h" 47 | #include "pgm.h" 48 | #include "ppi.h" 49 | 50 | enum { 51 | PPI_READ, 52 | PPI_WRITE, 53 | PPI_SHADOWREAD 54 | }; 55 | 56 | static int ppi_shadow_access(union filedescriptor *fdp, int reg, 57 | unsigned char *v, unsigned char action) 58 | { 59 | static unsigned char shadow[3]; 60 | int shadow_num; 61 | 62 | switch (reg) { 63 | case PPIDATA: 64 | shadow_num = 0; 65 | break; 66 | case PPICTRL: 67 | shadow_num = 1; 68 | break; 69 | case PPISTATUS: 70 | shadow_num = 2; 71 | break; 72 | default: 73 | fprintf(stderr, "%s: avr_set(): invalid register=%d\n", 74 | progname, reg); 75 | return -1; 76 | break; 77 | } 78 | 79 | switch (action) { 80 | case PPI_SHADOWREAD: 81 | *v = shadow[shadow_num]; 82 | break; 83 | case PPI_READ: 84 | DO_PPI_READ(fdp->ifd, reg, v); 85 | shadow[shadow_num]=*v; 86 | break; 87 | case PPI_WRITE: 88 | shadow[shadow_num]=*v; 89 | DO_PPI_WRITE(fdp->ifd, reg, v); 90 | break; 91 | } 92 | return 0; 93 | } 94 | 95 | /* 96 | * set the indicated bit of the specified register. 97 | */ 98 | int ppi_set(union filedescriptor *fdp, int reg, int bit) 99 | { 100 | unsigned char v; 101 | int rc; 102 | 103 | rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD); 104 | v |= bit; 105 | rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE); 106 | 107 | if (rc) 108 | return -1; 109 | 110 | return 0; 111 | } 112 | 113 | 114 | /* 115 | * clear the indicated bit of the specified register. 116 | */ 117 | int ppi_clr(union filedescriptor *fdp, int reg, int bit) 118 | { 119 | unsigned char v; 120 | int rc; 121 | 122 | rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD); 123 | v &= ~bit; 124 | rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE); 125 | 126 | if (rc) 127 | return -1; 128 | 129 | return 0; 130 | } 131 | 132 | 133 | /* 134 | * get the indicated bit of the specified register. 135 | */ 136 | int ppi_get(union filedescriptor *fdp, int reg, int bit) 137 | { 138 | unsigned char v; 139 | int rc; 140 | 141 | rc = ppi_shadow_access(fdp, reg, &v, PPI_READ); 142 | v &= bit; 143 | 144 | if (rc) 145 | return -1; 146 | 147 | return v; /* v == bit */ 148 | } 149 | 150 | /* 151 | * toggle the indicated bit of the specified register. 152 | */ 153 | int ppi_toggle(union filedescriptor *fdp, int reg, int bit) 154 | { 155 | unsigned char v; 156 | int rc; 157 | 158 | rc = ppi_shadow_access(fdp, reg, &v, PPI_SHADOWREAD); 159 | v ^= bit; 160 | rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE); 161 | 162 | if (rc) 163 | return -1; 164 | 165 | return 0; 166 | } 167 | 168 | 169 | /* 170 | * get all bits of the specified register. 171 | */ 172 | int ppi_getall(union filedescriptor *fdp, int reg) 173 | { 174 | unsigned char v; 175 | int rc; 176 | 177 | rc = ppi_shadow_access(fdp, reg, &v, PPI_READ); 178 | 179 | if (rc) 180 | return -1; 181 | 182 | return v; /* v == bit */ 183 | } 184 | 185 | /* 186 | * set all bits of the specified register to val. 187 | */ 188 | int ppi_setall(union filedescriptor *fdp, int reg, int val) 189 | { 190 | unsigned char v; 191 | int rc; 192 | 193 | v = val; 194 | rc = ppi_shadow_access(fdp, reg, &v, PPI_WRITE); 195 | 196 | if (rc) 197 | return -1; 198 | 199 | return 0; 200 | } 201 | 202 | 203 | void ppi_open(char * port, union filedescriptor *fdp) 204 | { 205 | int fd; 206 | unsigned char v; 207 | 208 | fd = open(port, O_RDWR); 209 | if (fd < 0) { 210 | fprintf(stderr, "%s: can't open device \"%s\": %s\n", 211 | progname, port, strerror(errno)); 212 | fdp->ifd = -1; 213 | return; 214 | } 215 | 216 | ppi_claim (fd); 217 | 218 | /* 219 | * Initialize shadow registers 220 | */ 221 | 222 | ppi_shadow_access (fdp, PPIDATA, &v, PPI_READ); 223 | ppi_shadow_access (fdp, PPICTRL, &v, PPI_READ); 224 | ppi_shadow_access (fdp, PPISTATUS, &v, PPI_READ); 225 | 226 | fdp->ifd = fd; 227 | } 228 | 229 | 230 | void ppi_close(union filedescriptor *fdp) 231 | { 232 | ppi_release (fdp->ifd); 233 | close(fdp->ifd); 234 | } 235 | 236 | #endif /* HAVE_PARPORT */ 237 | 238 | #endif /* !WIN32NATIVE */ 239 | -------------------------------------------------------------------------------- /ppi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef ppi_h 23 | #define ppi_h 24 | 25 | /* 26 | * PPI registers 27 | */ 28 | enum { 29 | PPIDATA, 30 | PPICTRL, 31 | PPISTATUS 32 | }; 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | int ppi_get (union filedescriptor *fdp, int reg, int bit); 39 | 40 | int ppi_set (union filedescriptor *fdp, int reg, int bit); 41 | 42 | int ppi_clr (union filedescriptor *fdp, int reg, int bit); 43 | 44 | int ppi_getall (union filedescriptor *fdp, int reg); 45 | 46 | int ppi_setall (union filedescriptor *fdp, int reg, int val); 47 | 48 | int ppi_toggle (union filedescriptor *fdp, int reg, int bit); 49 | 50 | void ppi_open (char * port, union filedescriptor *fdp); 51 | 52 | void ppi_close (union filedescriptor *fdp); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | 60 | 61 | -------------------------------------------------------------------------------- /ppiwin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003, 2004, 2006 4 | * Eric B. Weddington 5 | * Copyright 2008, Joerg Wunsch 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | /* $Id$ */ 23 | 24 | /* 25 | This is the parallel port interface for Windows built using Cygwin. 26 | 27 | In the ppi_* functions that access the parallel port registers, 28 | fd = parallel port address 29 | reg = register as defined in an enum in ppi.h. This must be converted 30 | to a proper offset of the base address. 31 | */ 32 | 33 | 34 | #include "ac_cfg.h" 35 | #include "avrdude.h" 36 | 37 | #if defined (WIN32NATIVE) 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "serial.h" 50 | #include "ppi.h" 51 | 52 | #define DEVICE_LPT1 "lpt1" 53 | #define DEVICE_LPT2 "lpt2" 54 | #define DEVICE_LPT3 "lpt3" 55 | 56 | #define DEVICE_MAX 3 57 | 58 | typedef struct 59 | { 60 | const char *name; 61 | int base_address; 62 | } winpp; 63 | 64 | static const winpp winports[DEVICE_MAX] = 65 | { 66 | {DEVICE_LPT1, 0x378}, 67 | {DEVICE_LPT2, 0x278}, 68 | {DEVICE_LPT3, 0x3BC}, 69 | }; 70 | 71 | 72 | 73 | 74 | 75 | /* FUNCTION PROTOTYPES */ 76 | static int winnt_pp_open(void); 77 | static unsigned short port_get(union filedescriptor *fdp, int reg); 78 | static unsigned char reg2offset(int reg); 79 | static unsigned char inb(unsigned short port); 80 | static void outb(unsigned char value, unsigned short port); 81 | 82 | 83 | 84 | /* FUNCTION DEFINITIONS */ 85 | 86 | void ppi_open(char *port, union filedescriptor *fdp) 87 | { 88 | unsigned char i; 89 | int fd; 90 | 91 | fd = winnt_pp_open(); 92 | 93 | if(fd < 0) 94 | { 95 | fprintf(stderr, "%s: can't open device \"giveio\"\n\n", progname); 96 | fdp->ifd = -1; 97 | return; 98 | } 99 | 100 | /* Search the windows port names for a match */ 101 | fd = -1; 102 | for(i = 0; i < DEVICE_MAX; i++) 103 | { 104 | if(strcmp(winports[i].name, port) == 0) 105 | { 106 | /* Set the file descriptor with the Windows parallel port base address. */ 107 | fd = winports[i].base_address; 108 | break; 109 | } 110 | } 111 | if(fd == -1) 112 | { 113 | /* 114 | * Supplied port name did not match any of the pre-defined 115 | * names. Try interpreting it as a numeric 116 | * (hexadecimal/decimal/octal) address. 117 | */ 118 | char *cp; 119 | 120 | fd = strtol(port, &cp, 0); 121 | if(*port == '\0' || *cp != '\0') 122 | { 123 | fprintf(stderr, 124 | "%s: port name \"%s\" is neither lpt1/2/3 nor valid number\n", 125 | progname, port); 126 | fd = -1; 127 | } 128 | } 129 | if(fd < 0) 130 | { 131 | fprintf(stderr, "%s: can't open device \"%s\"\n\n", progname, port); 132 | fdp->ifd = -1; 133 | return; 134 | } 135 | 136 | fdp->ifd = fd; 137 | } 138 | 139 | 140 | #define DRIVERNAME "\\\\.\\giveio" 141 | static int winnt_pp_open(void) 142 | { 143 | // Only try to use giveio under Windows NT/2000/XP. 144 | OSVERSIONINFO ver_info; 145 | 146 | memset(&ver_info, 0, sizeof(ver_info)); 147 | 148 | ver_info.dwOSVersionInfoSize = sizeof(ver_info); 149 | 150 | if(!GetVersionEx(&ver_info)) 151 | { 152 | return(-1); 153 | } 154 | else if(ver_info.dwPlatformId == VER_PLATFORM_WIN32_NT) 155 | { 156 | HANDLE h = CreateFile(DRIVERNAME, 157 | GENERIC_READ, 158 | 0, 159 | NULL, 160 | OPEN_EXISTING, 161 | FILE_ATTRIBUTE_NORMAL, 162 | NULL); 163 | 164 | if(h == INVALID_HANDLE_VALUE) 165 | { 166 | return(-1); 167 | } 168 | 169 | /* Close immediately. The process now has the rights it needs. */ 170 | if(h != NULL) 171 | { 172 | CloseHandle(h); 173 | } 174 | } 175 | return(0); 176 | } 177 | 178 | 179 | 180 | 181 | void ppi_close(union filedescriptor *fdp) 182 | { 183 | return; 184 | } 185 | 186 | 187 | 188 | /* 189 | * set the indicated bit of the specified register. 190 | */ 191 | int ppi_set(union filedescriptor *fdp, int reg, int bit) 192 | { 193 | unsigned char v; 194 | unsigned short port; 195 | 196 | port = port_get(fdp, reg); 197 | v = inb(port); 198 | v |= bit; 199 | outb(v, port); 200 | return 0; 201 | } 202 | 203 | 204 | /* 205 | * clear the indicated bit of the specified register. 206 | */ 207 | int ppi_clr(union filedescriptor *fdp, int reg, int bit) 208 | { 209 | unsigned char v; 210 | unsigned short port; 211 | 212 | port = port_get(fdp, reg); 213 | v = inb(port); 214 | v &= ~bit; 215 | outb(v, port); 216 | 217 | return 0; 218 | } 219 | 220 | 221 | /* 222 | * get the indicated bit of the specified register. 223 | */ 224 | int ppi_get(union filedescriptor *fdp, int reg, int bit) 225 | { 226 | unsigned char v; 227 | 228 | v = inb(port_get(fdp, reg)); 229 | v &= bit; 230 | 231 | return(v); 232 | } 233 | 234 | 235 | 236 | 237 | /* 238 | * toggle the indicated bit of the specified register. 239 | */ 240 | int ppi_toggle(union filedescriptor *fdp, int reg, int bit) 241 | { 242 | unsigned char v; 243 | unsigned short port; 244 | 245 | port = port_get(fdp, reg); 246 | 247 | v = inb(port); 248 | v ^= bit; 249 | outb(v, port); 250 | 251 | return 0; 252 | } 253 | 254 | 255 | /* 256 | * get all bits of the specified register. 257 | */ 258 | int ppi_getall(union filedescriptor *fdp, int reg) 259 | { 260 | unsigned char v; 261 | 262 | v = inb(port_get(fdp, reg)); 263 | 264 | return((int)v); 265 | } 266 | 267 | 268 | 269 | 270 | /* 271 | * set all bits of the specified register to val. 272 | */ 273 | int ppi_setall(union filedescriptor *fdp, int reg, int val) 274 | { 275 | outb((unsigned char)val, port_get(fdp, reg)); 276 | return 0; 277 | } 278 | 279 | 280 | 281 | 282 | /* Calculate port address to access. */ 283 | static unsigned short port_get(union filedescriptor *fdp, int reg) 284 | { 285 | return((unsigned short)(fdp->ifd + reg2offset(reg))); 286 | } 287 | 288 | 289 | /* Convert register enum to offset of base address. */ 290 | static unsigned char reg2offset(int reg) 291 | { 292 | unsigned char offset = 0; 293 | 294 | switch(reg) 295 | { 296 | case PPIDATA: 297 | { 298 | offset = 0; 299 | break; 300 | } 301 | case PPISTATUS: 302 | { 303 | offset = 1; 304 | break; 305 | } 306 | case PPICTRL: 307 | { 308 | offset = 2; 309 | break; 310 | } 311 | } 312 | 313 | return(offset); 314 | } 315 | 316 | 317 | /* Read in value from port. */ 318 | static unsigned char inb(unsigned short port) 319 | { 320 | unsigned char t; 321 | 322 | asm volatile ("in %1, %0" 323 | : "=a" (t) 324 | : "d" (port)); 325 | 326 | return t; 327 | } 328 | 329 | 330 | /* Write value to port. */ 331 | static void outb(unsigned char value, unsigned short port) 332 | { 333 | asm volatile ("out %1, %0" 334 | : 335 | : "d" (port), "a" (value) ); 336 | 337 | return; 338 | } 339 | 340 | #if !defined(HAVE_GETTIMEOFDAY) 341 | struct timezone; 342 | int gettimeofday(struct timeval *tv, struct timezone *unused){ 343 | // i've found only ms resolution, avrdude expects us 344 | 345 | SYSTEMTIME st; 346 | GetSystemTime(&st); 347 | 348 | tv->tv_sec=(long)(st.wSecond+st.wMinute*60+st.wHour*3600); 349 | tv->tv_usec=(long)(st.wMilliseconds*1000); 350 | 351 | return 0; 352 | } 353 | #endif /* HAVE_GETTIMEOFDAY */ 354 | 355 | // #define W32USLEEPDBG 356 | 357 | #ifdef W32USLEEPDBG 358 | 359 | # define DEBUG_QueryPerformanceCounter(arg) QueryPerformanceCounter(arg) 360 | # define DEBUG_DisplayTimingInfo(start, stop, freq, us, has_highperf) \ 361 | do { \ 362 | unsigned long dt; \ 363 | dt = (unsigned long)((stop.QuadPart - start.QuadPart) * 1000 * 1000 \ 364 | / freq.QuadPart); \ 365 | fprintf(stderr, \ 366 | "hpt:%i usleep usec:%lu sleep msec:%lu timed usec:%lu\n", \ 367 | has_highperf, us, ((us + 999) / 1000), dt); \ 368 | } while (0) 369 | 370 | #else 371 | 372 | # define DEBUG_QueryPerformanceCounter(arg) 373 | # define DEBUG_DisplayTimingInfo(start, stop, freq, us, has_highperf) 374 | 375 | #endif 376 | 377 | #if !defined(HAVE_USLEEP) 378 | int usleep(unsigned int us) 379 | { 380 | int has_highperf; 381 | LARGE_INTEGER freq,start,stop,loopend; 382 | 383 | // workaround: although usleep is very precise if using 384 | // high-performance-timers there are sometimes problems with 385 | // verify - increasing the delay helps sometimes but not 386 | // realiably. There must be some other problem. Maybe just 387 | // with my test-hardware maybe in the code-base. 388 | //// us=(unsigned long) (us*1.5); 389 | 390 | has_highperf=QueryPerformanceFrequency(&freq); 391 | 392 | //has_highperf=0; // debug 393 | 394 | if (has_highperf) { 395 | QueryPerformanceCounter(&start); 396 | loopend.QuadPart=start.QuadPart+freq.QuadPart*us/(1000*1000); 397 | do { 398 | QueryPerformanceCounter(&stop); 399 | } while (stop.QuadPart<=loopend.QuadPart); 400 | } 401 | else { 402 | DEBUG_QueryPerformanceCounter(&start); 403 | 404 | Sleep(1); 405 | Sleep( (DWORD)((us+999)/1000) ); 406 | 407 | DEBUG_QueryPerformanceCounter(&stop); 408 | } 409 | 410 | DEBUG_DisplayTimingInfo(start, stop, freq, us, has_highperf); 411 | 412 | return 0; 413 | } 414 | #endif /* !HAVE_USLEEP */ 415 | 416 | #endif 417 | 418 | 419 | -------------------------------------------------------------------------------- /safemode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * avrdude is Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This file: Copyright (C) 2005 Colin O'Flynn 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | 23 | #ifndef safemode_h 24 | #define safemode_h 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Writes the specified fuse in fusename (can be "lfuse", "hfuse", or "efuse") and verifies it. Will try up to tries 31 | amount of times before giving up */ 32 | int safemode_writefuse (unsigned char fuse, char * fusename, PROGRAMMER * pgm, AVRPART * p, int tries, int verbose); 33 | 34 | /* Reads the fuses three times, checking that all readings are the same. This will ensure that the before values aren't in error! */ 35 | int safemode_readfuses (unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse, PROGRAMMER * pgm, AVRPART * p, int verbose); 36 | 37 | /* This routine will store the current values pointed to by lfuse, hfuse, and efuse into an internal buffer in this routine 38 | when save is set to 1. When save is 0 (or not 1 really) it will copy the values from the internal buffer into the locations 39 | pointed to be lfuse, hfuse, and efuse. This allows you to change the fuse bits if needed from another routine (ie: have it so 40 | if user requests fuse bits are changed, the requested value is now verified */ 41 | int safemode_memfuses (int save, unsigned char * lfuse, unsigned char * hfuse, unsigned char * efuse, unsigned char * fuse); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* safemode_h */ 48 | -------------------------------------------------------------------------------- /ser_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003, 2004 Martin J. Thomas 4 | * Copyright (C) 2006 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | /* 24 | * Native Win32 serial interface for avrdude. 25 | */ 26 | 27 | #include "avrdude.h" 28 | 29 | #if defined(WIN32NATIVE) 30 | 31 | #include 32 | #include 33 | #include /* for isprint */ 34 | 35 | #include "serial.h" 36 | 37 | long serial_recv_timeout = 5000; /* ms */ 38 | 39 | #define W32SERBUFSIZE 1024 40 | 41 | struct baud_mapping { 42 | long baud; 43 | DWORD speed; 44 | }; 45 | 46 | /* HANDLE hComPort=INVALID_HANDLE_VALUE; */ 47 | 48 | static struct baud_mapping baud_lookup_table [] = { 49 | { 1200, CBR_1200 }, 50 | { 2400, CBR_2400 }, 51 | { 4800, CBR_4800 }, 52 | { 9600, CBR_9600 }, 53 | { 19200, CBR_19200 }, 54 | { 38400, CBR_38400 }, 55 | { 57600, CBR_57600 }, 56 | { 115200, CBR_115200 }, 57 | { 0, 0 } /* Terminator. */ 58 | }; 59 | 60 | static DWORD serial_baud_lookup(long baud) 61 | { 62 | struct baud_mapping *map = baud_lookup_table; 63 | 64 | while (map->baud) { 65 | if (map->baud == baud) 66 | return map->speed; 67 | map++; 68 | } 69 | 70 | /* 71 | * If a non-standard BAUD rate is used, issue 72 | * a warning (if we are verbose) and return the raw rate 73 | */ 74 | if (verbose > 0) 75 | fprintf(stderr, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld", 76 | progname, baud); 77 | 78 | return baud; 79 | } 80 | 81 | 82 | static BOOL serial_w32SetTimeOut(HANDLE hComPort, DWORD timeout) // in ms 83 | { 84 | COMMTIMEOUTS ctmo; 85 | ZeroMemory (&ctmo, sizeof(COMMTIMEOUTS)); 86 | ctmo.ReadIntervalTimeout = timeout; 87 | ctmo.ReadTotalTimeoutMultiplier = timeout; 88 | ctmo.ReadTotalTimeoutConstant = timeout; 89 | 90 | return SetCommTimeouts(hComPort, &ctmo); 91 | } 92 | 93 | static int ser_setspeed(union filedescriptor *fd, long baud) 94 | { 95 | DCB dcb; 96 | HANDLE hComPort = (HANDLE)fd->pfd; 97 | 98 | ZeroMemory (&dcb, sizeof(DCB)); 99 | dcb.DCBlength = sizeof(DCB); 100 | dcb.BaudRate = serial_baud_lookup (baud); 101 | dcb.fBinary = 1; 102 | dcb.fDtrControl = DTR_CONTROL_DISABLE; 103 | dcb.fRtsControl = RTS_CONTROL_DISABLE; 104 | dcb.ByteSize = 8; 105 | dcb.Parity = NOPARITY; 106 | dcb.StopBits = ONESTOPBIT; 107 | 108 | if (!SetCommState(hComPort, &dcb)) 109 | return -1; 110 | 111 | return 0; 112 | } 113 | 114 | 115 | static int ser_open(char * port, long baud, union filedescriptor *fdp) 116 | { 117 | LPVOID lpMsgBuf; 118 | HANDLE hComPort=INVALID_HANDLE_VALUE; 119 | char *newname = 0; 120 | 121 | /* 122 | * If the port is of the form "net::", then 123 | * handle it as a TCP connection to a terminal server. 124 | * 125 | * This is curently not implemented for Win32. 126 | */ 127 | if (strncmp(port, "net:", strlen("net:")) == 0) { 128 | fprintf(stderr, 129 | "%s: ser_open(): network connects are currently not" 130 | "implemented for Win32 environments\n", 131 | progname); 132 | return -1; 133 | } 134 | 135 | if (strncasecmp(port, "com", strlen("com")) == 0) { 136 | 137 | // prepend "\\\\.\\" to name, required for port # >= 10 138 | newname = malloc(strlen("\\\\.\\") + strlen(port) + 1); 139 | 140 | if (newname == 0) { 141 | fprintf(stderr, 142 | "%s: ser_open(): out of memory\n", 143 | progname); 144 | exit(1); 145 | } 146 | strcpy(newname, "\\\\.\\"); 147 | strcat(newname, port); 148 | 149 | port = newname; 150 | } 151 | 152 | hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, 153 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 154 | 155 | if (hComPort == INVALID_HANDLE_VALUE) { 156 | FormatMessage( 157 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 158 | FORMAT_MESSAGE_FROM_SYSTEM | 159 | FORMAT_MESSAGE_IGNORE_INSERTS, 160 | NULL, 161 | GetLastError(), 162 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 163 | (LPTSTR) &lpMsgBuf, 164 | 0, 165 | NULL); 166 | fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n", 167 | progname, port, (char*)lpMsgBuf); 168 | LocalFree( lpMsgBuf ); 169 | return -1; 170 | } 171 | 172 | if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE)) 173 | { 174 | CloseHandle(hComPort); 175 | fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n", 176 | progname, port); 177 | return -1; 178 | } 179 | 180 | fdp->pfd = (void *)hComPort; 181 | if (ser_setspeed(fdp, baud) != 0) 182 | { 183 | CloseHandle(hComPort); 184 | fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n", 185 | progname, port); 186 | return -1; 187 | } 188 | 189 | if (!serial_w32SetTimeOut(hComPort,0)) 190 | { 191 | CloseHandle(hComPort); 192 | fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n", 193 | progname, port); 194 | return -1; 195 | } 196 | 197 | if (newname != 0) { 198 | free(newname); 199 | } 200 | return 0; 201 | } 202 | 203 | 204 | static void ser_close(union filedescriptor *fd) 205 | { 206 | HANDLE hComPort=(HANDLE)fd->pfd; 207 | if (hComPort != INVALID_HANDLE_VALUE) 208 | CloseHandle (hComPort); 209 | 210 | hComPort = INVALID_HANDLE_VALUE; 211 | } 212 | 213 | static int ser_set_dtr_rts(union filedescriptor *fd, int is_on) 214 | { 215 | HANDLE hComPort=(HANDLE)fd->pfd; 216 | 217 | if (is_on) { 218 | EscapeCommFunction(hComPort, SETDTR); 219 | EscapeCommFunction(hComPort, SETRTS); 220 | } else { 221 | EscapeCommFunction(hComPort, CLRDTR); 222 | EscapeCommFunction(hComPort, CLRRTS); 223 | } 224 | return 0; 225 | } 226 | 227 | 228 | static int ser_send(union filedescriptor *fd, unsigned char * buf, size_t buflen) 229 | { 230 | size_t len = buflen; 231 | unsigned char c='\0'; 232 | DWORD written; 233 | unsigned char * b = buf; 234 | 235 | HANDLE hComPort=(HANDLE)fd->pfd; 236 | 237 | if (hComPort == INVALID_HANDLE_VALUE) { 238 | fprintf(stderr, "%s: ser_send(): port not open\n", 239 | progname); 240 | exit(1); 241 | } 242 | 243 | if (!len) 244 | return 0; 245 | 246 | if (verbose > 3) 247 | { 248 | fprintf(stderr, "%s: Send: ", progname); 249 | 250 | while (len) { 251 | c = *b; 252 | if (isprint(c)) { 253 | fprintf(stderr, "%c ", c); 254 | } 255 | else { 256 | fprintf(stderr, ". "); 257 | } 258 | fprintf(stderr, "[%02x] ", c); 259 | b++; 260 | len--; 261 | } 262 | fprintf(stderr, "\n"); 263 | } 264 | 265 | serial_w32SetTimeOut(hComPort,500); 266 | 267 | if (!WriteFile (hComPort, buf, buflen, &written, NULL)) { 268 | fprintf(stderr, "%s: ser_send(): write error: %s\n", 269 | progname, "sorry no info avail"); // TODO 270 | exit(1); 271 | } 272 | 273 | if (written != buflen) { 274 | fprintf(stderr, "%s: ser_send(): size/send mismatch\n", 275 | progname); 276 | exit(1); 277 | } 278 | 279 | return 0; 280 | } 281 | 282 | 283 | static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen) 284 | { 285 | unsigned char c; 286 | unsigned char * p = buf; 287 | DWORD read; 288 | 289 | HANDLE hComPort=(HANDLE)fd->pfd; 290 | 291 | if (hComPort == INVALID_HANDLE_VALUE) { 292 | fprintf(stderr, "%s: ser_read(): port not open\n", 293 | progname); 294 | exit(1); 295 | } 296 | 297 | serial_w32SetTimeOut(hComPort, serial_recv_timeout); 298 | 299 | if (!ReadFile(hComPort, buf, buflen, &read, NULL)) { 300 | LPVOID lpMsgBuf; 301 | FormatMessage( 302 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 303 | FORMAT_MESSAGE_FROM_SYSTEM | 304 | FORMAT_MESSAGE_IGNORE_INSERTS, 305 | NULL, 306 | GetLastError(), 307 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 308 | (LPTSTR) &lpMsgBuf, 309 | 0, 310 | NULL ); 311 | fprintf(stderr, "%s: ser_recv(): read error: %s\n", 312 | progname, (char*)lpMsgBuf); 313 | LocalFree( lpMsgBuf ); 314 | exit(1); 315 | } 316 | 317 | p = buf; 318 | 319 | if (verbose > 3) 320 | { 321 | fprintf(stderr, "%s: Recv: ", progname); 322 | 323 | while (read) { 324 | c = *p; 325 | if (isprint(c)) { 326 | fprintf(stderr, "%c ", c); 327 | } 328 | else { 329 | fprintf(stderr, ". "); 330 | } 331 | fprintf(stderr, "[%02x] ", c); 332 | 333 | p++; 334 | read--; 335 | } 336 | fprintf(stderr, "\n"); 337 | } 338 | return 0; 339 | } 340 | 341 | 342 | static int ser_drain(union filedescriptor *fd, int display) 343 | { 344 | // int rc; 345 | unsigned char buf[10]; 346 | BOOL readres; 347 | DWORD read; 348 | 349 | HANDLE hComPort=(HANDLE)fd->pfd; 350 | 351 | if (hComPort == INVALID_HANDLE_VALUE) { 352 | fprintf(stderr, "%s: ser_drain(): port not open\n", 353 | progname); 354 | exit(1); 355 | } 356 | 357 | serial_w32SetTimeOut(hComPort,250); 358 | 359 | if (display) { 360 | fprintf(stderr, "drain>"); 361 | } 362 | 363 | while (1) { 364 | readres=ReadFile(hComPort, buf, 1, &read, NULL); 365 | if (!readres) { 366 | LPVOID lpMsgBuf; 367 | FormatMessage( 368 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 369 | FORMAT_MESSAGE_FROM_SYSTEM | 370 | FORMAT_MESSAGE_IGNORE_INSERTS, 371 | NULL, 372 | GetLastError(), 373 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 374 | (LPTSTR) &lpMsgBuf, 375 | 0, 376 | NULL ); 377 | fprintf(stderr, "%s: ser_drain(): read error: %s\n", 378 | progname, (char*)lpMsgBuf); 379 | LocalFree( lpMsgBuf ); 380 | exit(1); 381 | } 382 | 383 | if (read) { // data avail 384 | if (display) fprintf(stderr, "%02x ", buf[0]); 385 | } 386 | else { // no more data 387 | if (display) fprintf(stderr, " 4 | * Copyright (C) 2005 Michael Holzt 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | /* $Id$ */ 21 | 22 | #ifndef serbb_h 23 | #define serbb_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void serbb_initpgm (PROGRAMMER * pgm); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | 37 | 38 | -------------------------------------------------------------------------------- /serbb_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean 4 | * Copyright (C) 2005 Michael Holzt 5 | * Copyright (C) 2006 Joerg Wunsch 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | /* $Id$ */ 22 | 23 | /* 24 | * Posix serial bitbanging interface for avrdude. 25 | */ 26 | 27 | #if !defined(WIN32NATIVE) 28 | 29 | #include "ac_cfg.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "avrdude.h" 41 | #include "avr.h" 42 | #include "pindefs.h" 43 | #include "pgm.h" 44 | #include "bitbang.h" 45 | 46 | #undef DEBUG 47 | 48 | static struct termios oldmode; 49 | 50 | /* 51 | serial port/pin mapping 52 | 53 | 1 cd <- 54 | 2 (rxd) <- 55 | 3 txd -> 56 | 4 dtr -> 57 | 5 GND 58 | 6 dsr <- 59 | 7 rts -> 60 | 8 cts <- 61 | 9 ri <- 62 | */ 63 | 64 | #define DB9PINS 9 65 | 66 | static int serregbits[DB9PINS + 1] = 67 | { 0, TIOCM_CD, 0, 0, TIOCM_DTR, 0, TIOCM_DSR, TIOCM_RTS, TIOCM_CTS, TIOCM_RI }; 68 | 69 | #ifdef DEBUG 70 | static char *serpins[DB9PINS + 1] = 71 | { "NONE", "CD", "RXD", "TXD", "DTR", "GND", "DSR", "RTS", "CTS", "RI" }; 72 | #endif 73 | 74 | static int serbb_setpin(PROGRAMMER * pgm, int pin, int value) 75 | { 76 | unsigned int ctl; 77 | int r; 78 | 79 | if (pin & PIN_INVERSE) 80 | { 81 | value = !value; 82 | pin &= PIN_MASK; 83 | } 84 | 85 | if ( pin < 1 || pin > DB9PINS ) 86 | return -1; 87 | 88 | #ifdef DEBUG 89 | printf("%s to %d\n",serpins[pin],value); 90 | #endif 91 | 92 | switch ( pin ) 93 | { 94 | case 3: /* txd */ 95 | r = ioctl(pgm->fd.ifd, value ? TIOCSBRK : TIOCCBRK, 0); 96 | if (r < 0) { 97 | perror("ioctl(\"TIOCxBRK\")"); 98 | return -1; 99 | } 100 | break; 101 | 102 | case 4: /* dtr */ 103 | case 7: /* rts */ 104 | r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl); 105 | if (r < 0) { 106 | perror("ioctl(\"TIOCMGET\")"); 107 | return -1; 108 | } 109 | if ( value ) 110 | ctl |= serregbits[pin]; 111 | else 112 | ctl &= ~(serregbits[pin]); 113 | r = ioctl(pgm->fd.ifd, TIOCMSET, &ctl); 114 | if (r < 0) { 115 | perror("ioctl(\"TIOCMSET\")"); 116 | return -1; 117 | } 118 | break; 119 | 120 | default: /* impossible */ 121 | return -1; 122 | } 123 | 124 | if (pgm->ispdelay > 1) 125 | bitbang_delay(pgm->ispdelay); 126 | 127 | return 0; 128 | } 129 | 130 | static int serbb_getpin(PROGRAMMER * pgm, int pin) 131 | { 132 | unsigned int ctl; 133 | unsigned char invert; 134 | int r; 135 | 136 | if (pin & PIN_INVERSE) 137 | { 138 | invert = 1; 139 | pin &= PIN_MASK; 140 | } else 141 | invert = 0; 142 | 143 | if ( pin < 1 || pin > DB9PINS ) 144 | return(-1); 145 | 146 | switch ( pin ) 147 | { 148 | case 2: /* rxd, currently not implemented, FIXME */ 149 | return(-1); 150 | 151 | case 1: /* cd */ 152 | case 6: /* dsr */ 153 | case 8: /* cts */ 154 | case 9: /* ri */ 155 | r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl); 156 | if (r < 0) { 157 | perror("ioctl(\"TIOCMGET\")"); 158 | return -1; 159 | } 160 | if ( !invert ) 161 | { 162 | #ifdef DEBUG 163 | printf("%s is %d\n",serpins[pin],(ctl & serregbits[pin]) ? 1 : 0 ); 164 | #endif 165 | return ( (ctl & serregbits[pin]) ? 1 : 0 ); 166 | } 167 | else 168 | { 169 | #ifdef DEBUG 170 | printf("%s is %d (~)\n",serpins[pin],(ctl & serregbits[pin]) ? 0 : 1 ); 171 | #endif 172 | return (( ctl & serregbits[pin]) ? 0 : 1 ); 173 | } 174 | 175 | default: /* impossible */ 176 | return(-1); 177 | } 178 | } 179 | 180 | static int serbb_highpulsepin(PROGRAMMER * pgm, int pin) 181 | { 182 | if ( (pin & PIN_MASK) < 1 || (pin & PIN_MASK) > DB9PINS ) 183 | return -1; 184 | 185 | serbb_setpin(pgm, pin, 1); 186 | serbb_setpin(pgm, pin, 0); 187 | 188 | return 0; 189 | } 190 | 191 | 192 | 193 | static void serbb_display(PROGRAMMER *pgm, const char *p) 194 | { 195 | /* MAYBE */ 196 | } 197 | 198 | static void serbb_enable(PROGRAMMER *pgm) 199 | { 200 | /* nothing */ 201 | } 202 | 203 | static void serbb_disable(PROGRAMMER *pgm) 204 | { 205 | /* nothing */ 206 | } 207 | 208 | static void serbb_powerup(PROGRAMMER *pgm) 209 | { 210 | /* nothing */ 211 | } 212 | 213 | static void serbb_powerdown(PROGRAMMER *pgm) 214 | { 215 | /* nothing */ 216 | } 217 | 218 | static int serbb_open(PROGRAMMER *pgm, char *port) 219 | { 220 | struct termios mode; 221 | int flags; 222 | int r; 223 | 224 | bitbang_check_prerequisites(pgm); 225 | 226 | /* adapted from uisp code */ 227 | 228 | pgm->fd.ifd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); 229 | 230 | if (pgm->fd.ifd < 0) { 231 | perror(port); 232 | return(-1); 233 | } 234 | 235 | r = tcgetattr(pgm->fd.ifd, &mode); 236 | if (r < 0) { 237 | fprintf(stderr, "%s: ", port); 238 | perror("tcgetattr"); 239 | return(-1); 240 | } 241 | oldmode = mode; 242 | 243 | mode.c_iflag = IGNBRK | IGNPAR; 244 | mode.c_oflag = 0; 245 | mode.c_cflag = CLOCAL | CREAD | CS8 | B9600; 246 | mode.c_cc [VMIN] = 1; 247 | mode.c_cc [VTIME] = 0; 248 | 249 | r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode); 250 | if (r < 0) { 251 | fprintf(stderr, "%s: ", port); 252 | perror("tcsetattr"); 253 | return(-1); 254 | } 255 | 256 | /* Clear O_NONBLOCK flag. */ 257 | flags = fcntl(pgm->fd.ifd, F_GETFL, 0); 258 | if (flags == -1) 259 | { 260 | fprintf(stderr, "%s: Can not get flags: %s\n", 261 | progname, strerror(errno)); 262 | return(-1); 263 | } 264 | flags &= ~O_NONBLOCK; 265 | if (fcntl(pgm->fd.ifd, F_SETFL, flags) == -1) 266 | { 267 | fprintf(stderr, "%s: Can not clear nonblock flag: %s\n", 268 | progname, strerror(errno)); 269 | return(-1); 270 | } 271 | 272 | return(0); 273 | } 274 | 275 | static void serbb_close(PROGRAMMER *pgm) 276 | { 277 | if (pgm->fd.ifd != -1) 278 | { 279 | (void)tcsetattr(pgm->fd.ifd, TCSANOW, &oldmode); 280 | pgm->setpin(pgm, pgm->pinno[PIN_AVR_RESET], 1); 281 | close(pgm->fd.ifd); 282 | } 283 | return; 284 | } 285 | 286 | void serbb_initpgm(PROGRAMMER *pgm) 287 | { 288 | strcpy(pgm->type, "SERBB"); 289 | 290 | pgm->rdy_led = bitbang_rdy_led; 291 | pgm->err_led = bitbang_err_led; 292 | pgm->pgm_led = bitbang_pgm_led; 293 | pgm->vfy_led = bitbang_vfy_led; 294 | pgm->initialize = bitbang_initialize; 295 | pgm->display = serbb_display; 296 | pgm->enable = serbb_enable; 297 | pgm->disable = serbb_disable; 298 | pgm->powerup = serbb_powerup; 299 | pgm->powerdown = serbb_powerdown; 300 | pgm->program_enable = bitbang_program_enable; 301 | pgm->chip_erase = bitbang_chip_erase; 302 | pgm->cmd = bitbang_cmd; 303 | pgm->open = serbb_open; 304 | pgm->close = serbb_close; 305 | pgm->setpin = serbb_setpin; 306 | pgm->getpin = serbb_getpin; 307 | pgm->highpulsepin = serbb_highpulsepin; 308 | pgm->read_byte = avr_read_byte_default; 309 | pgm->write_byte = avr_write_byte_default; 310 | } 311 | 312 | #endif /* WIN32NATIVE */ 313 | -------------------------------------------------------------------------------- /serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2003-2004 Theodore A. Roth 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /* This is the API for the generic serial interface. The implementations are 23 | actually provided by the target dependant files: 24 | 25 | ser_posix.c : posix serial interface. 26 | ser_win32.c : native win32 serial interface. 27 | 28 | The target file will be selected at configure time. */ 29 | 30 | #ifndef serial_h 31 | #define serial_h 32 | 33 | extern long serial_recv_timeout; 34 | union filedescriptor 35 | { 36 | int ifd; 37 | void *pfd; 38 | struct 39 | { 40 | void *handle; 41 | int ep; 42 | } usb; 43 | }; 44 | 45 | struct serial_device 46 | { 47 | // open should return -1 on error, other values on success 48 | int (*open)(char * port, long baud, union filedescriptor *fd); 49 | int (*setspeed)(union filedescriptor *fd, long baud); 50 | void (*close)(union filedescriptor *fd); 51 | 52 | int (*send)(union filedescriptor *fd, unsigned char * buf, size_t buflen); 53 | int (*recv)(union filedescriptor *fd, unsigned char * buf, size_t buflen); 54 | int (*drain)(union filedescriptor *fd, int display); 55 | 56 | int (*set_dtr_rts)(union filedescriptor *fd, int is_on); 57 | 58 | int flags; 59 | #define SERDEV_FL_NONE 0x0000 /* no flags */ 60 | #define SERDEV_FL_CANSETSPEED 0x0001 /* device can change speed */ 61 | }; 62 | 63 | extern struct serial_device *serdev; 64 | extern struct serial_device serial_serdev; 65 | extern struct serial_device usb_serdev; 66 | extern struct serial_device usb_serdev_frame; 67 | extern struct serial_device avrdoper_serdev; 68 | 69 | #define serial_open (serdev->open) 70 | #define serial_setspeed (serdev->setspeed) 71 | #define serial_close (serdev->close) 72 | #define serial_send (serdev->send) 73 | #define serial_recv (serdev->recv) 74 | #define serial_drain (serdev->drain) 75 | #define serial_set_dtr_rts (serdev->set_dtr_rts) 76 | 77 | #endif /* serial_h */ 78 | -------------------------------------------------------------------------------- /solaris_ecpp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2005 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef solaris_ecpp_h 23 | #define solaris_ecpp_h 24 | 25 | #include 26 | 27 | #define ppi_claim(fd) \ 28 | do { \ 29 | struct ecpp_transfer_parms p; \ 30 | (void)ioctl(fd, ECPPIOC_GETPARMS, &p); \ 31 | p.mode = ECPP_DIAG_MODE; \ 32 | (void)ioctl(fd, ECPPIOC_SETPARMS, &p); \ 33 | } while(0); 34 | 35 | #define ppi_release(fd) 36 | 37 | #define DO_PPI_READ(fd, reg, valp) \ 38 | do { struct ecpp_regs r; \ 39 | if ((reg) == PPIDATA) { (void)ioctl(fd, ECPPIOC_GETDATA, valp); } \ 40 | else { (void)ioctl(fd, ECPPIOC_GETREGS, &r); \ 41 | *(valp) = ((reg) == PPICTRL)? r.dcr: r.dsr; } \ 42 | } while(0) 43 | #define DO_PPI_WRITE(fd, reg, valp) \ 44 | do { struct ecpp_regs r; \ 45 | if ((reg) == PPIDATA) { (void)ioctl(fd, ECPPIOC_SETDATA, valp); } \ 46 | else { if ((reg) == PPICTRL) r.dcr = *(valp); else r.dsr = *(valp); \ 47 | (void)ioctl(fd, ECPPIOC_SETREGS, &r); } \ 48 | } while(0) 49 | 50 | 51 | #endif /* solaris_ecpp_h */ 52 | -------------------------------------------------------------------------------- /stk500.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef stk500_h 23 | #define stk500_h 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void stk500_initpgm (PROGRAMMER * pgm); 30 | 31 | /* used by arduino.c to avoid duplicate code */ 32 | int stk500_getsync(PROGRAMMER * pgm); 33 | int stk500_drain(PROGRAMMER * pgm, int display); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | 41 | 42 | -------------------------------------------------------------------------------- /stk500_private.h: -------------------------------------------------------------------------------- 1 | //**** ATMEL AVR - A P P L I C A T I O N N O T E ************************ 2 | //* 3 | //* Title: AVR061 - STK500 Communication Protocol 4 | //* Filename: command.h 5 | //* Version: 1.0 6 | //* Last updated: 09.09.2002 7 | //* 8 | //* Support E-mail: avr@atmel.com 9 | //* 10 | //************************************************************************** 11 | 12 | // *****************[ STK Message constants ]*************************** 13 | 14 | #define STK_SIGN_ON_MESSAGE "AVR STK" // Sign on string for Cmnd_STK_GET_SIGN_ON 15 | 16 | // *****************[ STK Response constants ]*************************** 17 | 18 | #define Resp_STK_OK 0x10 // ' ' 19 | #define Resp_STK_FAILED 0x11 // ' ' 20 | #define Resp_STK_UNKNOWN 0x12 // ' ' 21 | #define Resp_STK_NODEVICE 0x13 // ' ' 22 | #define Resp_STK_INSYNC 0x14 // ' ' 23 | #define Resp_STK_NOSYNC 0x15 // ' ' 24 | 25 | #define Resp_ADC_CHANNEL_ERROR 0x16 // ' ' 26 | #define Resp_ADC_MEASURE_OK 0x17 // ' ' 27 | #define Resp_PWM_CHANNEL_ERROR 0x18 // ' ' 28 | #define Resp_PWM_ADJUST_OK 0x19 // ' ' 29 | 30 | // *****************[ STK Special constants ]*************************** 31 | 32 | #define Sync_CRC_EOP 0x20 // 'SPACE' 33 | 34 | // *****************[ STK Command constants ]*************************** 35 | 36 | #define Cmnd_STK_GET_SYNC 0x30 // ' ' 37 | #define Cmnd_STK_GET_SIGN_ON 0x31 // ' ' 38 | 39 | #define Cmnd_STK_SET_PARAMETER 0x40 // ' ' 40 | #define Cmnd_STK_GET_PARAMETER 0x41 // ' ' 41 | #define Cmnd_STK_SET_DEVICE 0x42 // ' ' 42 | #define Cmnd_STK_SET_DEVICE_EXT 0x45 // ' ' 43 | 44 | #define Cmnd_STK_ENTER_PROGMODE 0x50 // ' ' 45 | #define Cmnd_STK_LEAVE_PROGMODE 0x51 // ' ' 46 | #define Cmnd_STK_CHIP_ERASE 0x52 // ' ' 47 | #define Cmnd_STK_CHECK_AUTOINC 0x53 // ' ' 48 | #define Cmnd_STK_LOAD_ADDRESS 0x55 // ' ' 49 | #define Cmnd_STK_UNIVERSAL 0x56 // ' ' 50 | #define Cmnd_STK_UNIVERSAL_MULTI 0x57 // ' ' 51 | 52 | #define Cmnd_STK_PROG_FLASH 0x60 // ' ' 53 | #define Cmnd_STK_PROG_DATA 0x61 // ' ' 54 | #define Cmnd_STK_PROG_FUSE 0x62 // ' ' 55 | #define Cmnd_STK_PROG_LOCK 0x63 // ' ' 56 | #define Cmnd_STK_PROG_PAGE 0x64 // ' ' 57 | #define Cmnd_STK_PROG_FUSE_EXT 0x65 // ' ' 58 | 59 | #define Cmnd_STK_READ_FLASH 0x70 // ' ' 60 | #define Cmnd_STK_READ_DATA 0x71 // ' ' 61 | #define Cmnd_STK_READ_FUSE 0x72 // ' ' 62 | #define Cmnd_STK_READ_LOCK 0x73 // ' ' 63 | #define Cmnd_STK_READ_PAGE 0x74 // ' ' 64 | #define Cmnd_STK_READ_SIGN 0x75 // ' ' 65 | #define Cmnd_STK_READ_OSCCAL 0x76 // ' ' 66 | #define Cmnd_STK_READ_FUSE_EXT 0x77 // ' ' 67 | #define Cmnd_STK_READ_OSCCAL_EXT 0x78 // ' ' 68 | 69 | // *****************[ STK Parameter constants ]*************************** 70 | 71 | #define Parm_STK_HW_VER 0x80 // ' ' - R 72 | #define Parm_STK_SW_MAJOR 0x81 // ' ' - R 73 | #define Parm_STK_SW_MINOR 0x82 // ' ' - R 74 | #define Parm_STK_LEDS 0x83 // ' ' - R/W 75 | #define Parm_STK_VTARGET 0x84 // ' ' - R/W 76 | #define Parm_STK_VADJUST 0x85 // ' ' - R/W 77 | #define Parm_STK_OSC_PSCALE 0x86 // ' ' - R/W 78 | #define Parm_STK_OSC_CMATCH 0x87 // ' ' - R/W 79 | #define Parm_STK_RESET_DURATION 0x88 // ' ' - R/W 80 | #define Parm_STK_SCK_DURATION 0x89 // ' ' - R/W 81 | 82 | #define Parm_STK_BUFSIZEL 0x90 // ' ' - R/W, Range {0..255} 83 | #define Parm_STK_BUFSIZEH 0x91 // ' ' - R/W, Range {0..255} 84 | #define Parm_STK_DEVICE 0x92 // ' ' - R/W, Range {0..255} 85 | #define Parm_STK_PROGMODE 0x93 // ' ' - 'P' or 'S' 86 | #define Parm_STK_PARAMODE 0x94 // ' ' - TRUE or FALSE 87 | #define Parm_STK_POLLING 0x95 // ' ' - TRUE or FALSE 88 | #define Parm_STK_SELFTIMED 0x96 // ' ' - TRUE or FALSE 89 | #define Param_STK500_TOPCARD_DETECT 0x98 // ' ' - Detect top-card attached 90 | 91 | // *****************[ STK status bit definitions ]*************************** 92 | 93 | #define Stat_STK_INSYNC 0x01 // INSYNC status bit, '1' - INSYNC 94 | #define Stat_STK_PROGMODE 0x02 // Programming mode, '1' - PROGMODE 95 | #define Stat_STK_STANDALONE 0x04 // Standalone mode, '1' - SM mode 96 | #define Stat_STK_RESET 0x08 // RESET button, '1' - Pushed 97 | #define Stat_STK_PROGRAM 0x10 // Program button, ' 1' - Pushed 98 | #define Stat_STK_LEDG 0x20 // Green LED status, '1' - Lit 99 | #define Stat_STK_LEDR 0x40 // Red LED status, '1' - Lit 100 | #define Stat_STK_LEDBLINK 0x80 // LED blink ON/OFF, '1' - Blink 101 | 102 | 103 | // *****************************[ End Of COMMAND.H ]************************** 104 | -------------------------------------------------------------------------------- /stk500generic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2006 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /* 23 | * avrdude interface for Atmel STK500 programmer 24 | * 25 | * This is a wrapper around the STK500[v1] and STK500v2 programmers. 26 | * Try to select the programmer type that actually responds, and 27 | * divert to the actual programmer implementation if successful. 28 | */ 29 | 30 | #include "ac_cfg.h" 31 | 32 | #include 33 | #include 34 | 35 | #include "avrdude.h" 36 | #include "pgm.h" 37 | #include "stk500.h" 38 | #include "stk500v2.h" 39 | 40 | static int stk500generic_open(PROGRAMMER * pgm, char * port) 41 | { 42 | stk500_initpgm(pgm); 43 | if (pgm->open(pgm, port) >= 0) 44 | { 45 | fprintf(stderr, 46 | "%s: successfully opened stk500v1 device -- please use -c stk500v1\n", 47 | progname); 48 | return 0; 49 | } 50 | 51 | pgm->close(pgm); 52 | 53 | stk500v2_initpgm(pgm); 54 | if (pgm->open(pgm, port) >= 0) 55 | { 56 | fprintf(stderr, 57 | "%s: successfully opened stk500v2 device -- please use -c stk500v2\n", 58 | progname); 59 | return 0; 60 | } 61 | 62 | fprintf(stderr, 63 | "%s: cannot open either stk500v1 or stk500v2 programmer\n", 64 | progname); 65 | return -1; 66 | } 67 | 68 | static void stk500generic_setup(PROGRAMMER * pgm) 69 | { 70 | /* 71 | * Only STK500v2 needs setup/teardown. 72 | */ 73 | stk500v2_initpgm(pgm); 74 | pgm->setup(pgm); 75 | } 76 | 77 | static void stk500generic_teardown(PROGRAMMER * pgm) 78 | { 79 | stk500v2_initpgm(pgm); 80 | pgm->teardown(pgm); 81 | } 82 | 83 | 84 | void stk500generic_initpgm(PROGRAMMER * pgm) 85 | { 86 | strcpy(pgm->type, "STK500GENERIC"); 87 | 88 | pgm->open = stk500generic_open; 89 | pgm->setup = stk500generic_setup; 90 | pgm->teardown = stk500generic_teardown; 91 | } 92 | -------------------------------------------------------------------------------- /stk500generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2006 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef stk500generic_h__ 23 | #define stk500generic_h__ 24 | 25 | void stk500generic_initpgm (PROGRAMMER * pgm); 26 | 27 | #endif 28 | 29 | 30 | -------------------------------------------------------------------------------- /stk500v2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2002-2005 Brian S. Dean 4 | * Copyright (C) 2006 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #ifndef stk500v2_h 24 | #define stk500v2_h 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | void stk500v2_initpgm (PROGRAMMER * pgm); 31 | void stk500hvsp_initpgm (PROGRAMMER * pgm); 32 | void stk500pp_initpgm (PROGRAMMER * pgm); 33 | void stk500v2_jtagmkII_initpgm(PROGRAMMER * pgm); 34 | void stk500v2_dragon_hvsp_initpgm(PROGRAMMER * pgm); 35 | void stk500v2_dragon_isp_initpgm(PROGRAMMER * pgm); 36 | void stk500v2_dragon_pp_initpgm(PROGRAMMER * pgm); 37 | void stk600_initpgm (PROGRAMMER * pgm); 38 | void stk600hvsp_initpgm (PROGRAMMER * pgm); 39 | void stk600pp_initpgm (PROGRAMMER * pgm); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | 47 | 48 | -------------------------------------------------------------------------------- /term.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2004 Brian S. Dean 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef term_h 23 | #define term_h 24 | 25 | #include "avr.h" 26 | #include "pgm.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | int terminal_mode(PROGRAMMER * pgm, struct avrpart * p); 33 | char * terminal_get_input(const char *prompt); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tools/get-dw-params.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 30 | 31 | 32 | 33 | 35 | 39 | 43 | 45 | 47 | 48 | 49 | 50 | 51 | 52 | #------------------------------------------------------------ 53 | # 54 | 55 | 56 | #------------------------------------------------------------ 57 | part desc = " 58 | 59 | "; has_debugwire = yes; 60 | 61 | flash_instr = 62 | 63 | 64 | 65 | 66 | ; 67 | 68 | eeprom_instr = 69 | 70 | 71 | 72 | 73 | ; 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 0 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 0 98 | 99 | 100 | 0x 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 128 | 129 | 130 | 131 | , 132 | 133 | 134 | , 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /tools/get-stk600-cards.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 36 | 37 | 38 | 39 | 40 | 41 | { 42 | 43 | , " 44 | 45 | " }, 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | { 54 | 55 | , " 56 | 57 | " }, 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /tools/get-stk600-devices.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 33 | 34 | 35 | @multitable @columnfractions .15 .15 .6 36 | Routing card @tab Socket card @tab Devices 37 | 38 | @item @code{ 39 | 40 | } @tab @code{ 41 | 42 | } @tab 43 | 44 | 45 | 46 | 47 | 48 | 49 | @end multitable 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /update.c: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2005 Brian S. Dean 4 | * Copyright (C) 2007 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "avrdude.h" 30 | #include "avr.h" 31 | #include "config.h" 32 | #include "confwin.h" 33 | #include "fileio.h" 34 | #include "update.h" 35 | 36 | UPDATE * parse_op(char * s) 37 | { 38 | char buf[1024]; 39 | char * p, * cp, c; 40 | UPDATE * upd; 41 | int i; 42 | size_t fnlen; 43 | 44 | upd = (UPDATE *)malloc(sizeof(UPDATE)); 45 | if (upd == NULL) { 46 | fprintf(stderr, "%s: out of memory\n", progname); 47 | exit(1); 48 | } 49 | 50 | i = 0; 51 | p = s; 52 | while ((i < (sizeof(buf)-1) && *p && (*p != ':'))) 53 | buf[i++] = *p++; 54 | buf[i] = 0; 55 | 56 | if (*p != ':') { 57 | upd->memtype = (char *)malloc(strlen("flash")+1); 58 | if (upd->memtype == NULL) { 59 | outofmem: 60 | fprintf(stderr, "%s: out of memory\n", progname); 61 | exit(1); 62 | } 63 | strcpy(upd->memtype, "flash"); 64 | upd->op = DEVICE_WRITE; 65 | upd->filename = (char *)malloc(strlen(buf) + 1); 66 | if (upd->filename == NULL) 67 | goto outofmem; 68 | strcpy(upd->filename, buf); 69 | upd->format = FMT_AUTO; 70 | return upd; 71 | } 72 | 73 | upd->memtype = (char *)malloc(strlen(buf)+1); 74 | if (upd->memtype == NULL) { 75 | fprintf(stderr, "%s: out of memory\n", progname); 76 | exit(1); 77 | } 78 | strcpy(upd->memtype, buf); 79 | 80 | p++; 81 | if (*p == 'r') { 82 | upd->op = DEVICE_READ; 83 | } 84 | else if (*p == 'w') { 85 | upd->op = DEVICE_WRITE; 86 | } 87 | else if (*p == 'v') { 88 | upd->op = DEVICE_VERIFY; 89 | } 90 | else { 91 | fprintf(stderr, "%s: invalid I/O mode '%c' in update specification\n", 92 | progname, *p); 93 | fprintf(stderr, 94 | " allowed values are:\n" 95 | " r = read device\n" 96 | " w = write device\n" 97 | " v = verify device\n"); 98 | free(upd->memtype); 99 | free(upd); 100 | return NULL; 101 | } 102 | 103 | p++; 104 | 105 | if (*p != ':') { 106 | fprintf(stderr, "%s: invalid update specification\n", progname); 107 | free(upd->memtype); 108 | free(upd); 109 | return NULL; 110 | } 111 | 112 | p++; 113 | 114 | /* 115 | * Now, parse the filename component. Instead of looking for the 116 | * leftmost possible colon delimiter, we look for the rightmost one. 117 | * If we found one, we do have a trailing :format specifier, and 118 | * process it. Otherwise, the remainder of the string is our file 119 | * name component. That way, the file name itself is allowed to 120 | * contain a colon itself (e. g. C:/some/file.hex), except the 121 | * optional format specifier becomes mandatory then. 122 | */ 123 | cp = p; 124 | p = strrchr(cp, ':'); 125 | if (p == NULL) { 126 | upd->format = FMT_AUTO; 127 | fnlen = strlen(cp); 128 | upd->filename = (char *)malloc(fnlen + 1); 129 | } else { 130 | fnlen = p - cp; 131 | upd->filename = (char *)malloc(fnlen +1); 132 | c = *++p; 133 | if (c && p[1]) 134 | /* More than one char - force failure below. */ 135 | c = '?'; 136 | switch (c) { 137 | case 'a': upd->format = FMT_AUTO; break; 138 | case 's': upd->format = FMT_SREC; break; 139 | case 'i': upd->format = FMT_IHEX; break; 140 | case 'r': upd->format = FMT_RBIN; break; 141 | case 'm': upd->format = FMT_IMM; break; 142 | case 'b': upd->format = FMT_BIN; break; 143 | case 'd': upd->format = FMT_DEC; break; 144 | case 'h': upd->format = FMT_HEX; break; 145 | case 'o': upd->format = FMT_OCT; break; 146 | default: 147 | fprintf(stderr, "%s: invalid file format '%s' in update specifier\n", 148 | progname, p); 149 | free(upd->memtype); 150 | free(upd); 151 | return NULL; 152 | } 153 | } 154 | 155 | if (upd->filename == NULL) { 156 | fprintf(stderr, "%s: out of memory\n", progname); 157 | free(upd->memtype); 158 | free(upd); 159 | return NULL; 160 | } 161 | memcpy(upd->filename, cp, fnlen); 162 | upd->filename[fnlen] = 0; 163 | 164 | return upd; 165 | } 166 | 167 | UPDATE * dup_update(UPDATE * upd) 168 | { 169 | UPDATE * u; 170 | 171 | u = (UPDATE *)malloc(sizeof(UPDATE)); 172 | if (u == NULL) { 173 | fprintf(stderr, "%s: out of memory\n", progname); 174 | exit(1); 175 | } 176 | 177 | memcpy(u, upd, sizeof(UPDATE)); 178 | 179 | u->memtype = strdup(upd->memtype); 180 | u->filename = strdup(upd->filename); 181 | 182 | return u; 183 | } 184 | 185 | UPDATE * new_update(int op, char * memtype, int filefmt, char * filename) 186 | { 187 | UPDATE * u; 188 | 189 | u = (UPDATE *)malloc(sizeof(UPDATE)); 190 | if (u == NULL) { 191 | fprintf(stderr, "%s: out of memory\n", progname); 192 | exit(1); 193 | } 194 | 195 | u->memtype = strdup(memtype); 196 | u->filename = strdup(filename); 197 | u->op = op; 198 | u->format = filefmt; 199 | 200 | return u; 201 | } 202 | 203 | int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite, 204 | int verify) 205 | { 206 | struct avrpart * v; 207 | AVRMEM * mem; 208 | int size, vsize; 209 | int rc; 210 | 211 | mem = avr_locate_mem(p, upd->memtype); 212 | if (mem == NULL) { 213 | fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", 214 | upd->memtype, p->desc); 215 | return -1; 216 | } 217 | 218 | if (upd->op == DEVICE_READ) { 219 | /* 220 | * read out the specified device memory and write it to a file 221 | */ 222 | if (quell_progress < 2) { 223 | fprintf(stderr, "%s: reading %s memory:\n", 224 | progname, mem->desc); 225 | } 226 | report_progress(0,1,"Reading"); 227 | rc = avr_read(pgm, p, upd->memtype, 0, 1); 228 | if (rc < 0) { 229 | fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", 230 | progname, mem->desc, rc); 231 | return -1; 232 | } 233 | report_progress(1,1,NULL); 234 | size = rc; 235 | 236 | if (quell_progress < 2) { 237 | fprintf(stderr, 238 | "%s: writing output file \"%s\"\n", 239 | progname, 240 | strcmp(upd->filename, "-")==0 ? "" : upd->filename); 241 | } 242 | rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size); 243 | if (rc < 0) { 244 | fprintf(stderr, "%s: write to file '%s' failed\n", 245 | progname, upd->filename); 246 | return -1; 247 | } 248 | } 249 | else if (upd->op == DEVICE_WRITE) { 250 | /* 251 | * write the selected device memory using data from a file; first 252 | * read the data from the specified file 253 | */ 254 | if (quell_progress < 2) { 255 | fprintf(stderr, 256 | "%s: reading input file \"%s\"\n", 257 | progname, 258 | strcmp(upd->filename, "-")==0 ? "" : upd->filename); 259 | } 260 | rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); 261 | if (rc < 0) { 262 | fprintf(stderr, "%s: write to file '%s' failed\n", 263 | progname, upd->filename); 264 | return -1; 265 | } 266 | size = rc; 267 | 268 | /* 269 | * write the buffer contents to the selected memory type 270 | */ 271 | if (quell_progress < 2) { 272 | fprintf(stderr, "%s: writing %s (%d bytes):\n", 273 | progname, mem->desc, size); 274 | } 275 | 276 | if (!nowrite) { 277 | report_progress(0,1,"Writing"); 278 | rc = avr_write(pgm, p, upd->memtype, size, 1); 279 | report_progress(1,1,NULL); 280 | } 281 | else { 282 | /* 283 | * test mode, don't actually write to the chip, output the buffer 284 | * to stdout in intel hex instead 285 | */ 286 | rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, upd->memtype, size); 287 | } 288 | 289 | if (rc < 0) { 290 | fprintf(stderr, "%s: failed to write %s memory, rc=%d\n", 291 | progname, mem->desc, rc); 292 | return -1; 293 | } 294 | 295 | vsize = rc; 296 | 297 | if (quell_progress < 2) { 298 | fprintf(stderr, "%s: %d bytes of %s written\n", progname, 299 | vsize, mem->desc); 300 | } 301 | 302 | } 303 | else if (upd->op == DEVICE_VERIFY) { 304 | /* 305 | * verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM]) 306 | * is the same as what is on the chip 307 | */ 308 | pgm->vfy_led(pgm, ON); 309 | 310 | v = avr_dup_part(p); 311 | 312 | if (quell_progress < 2) { 313 | fprintf(stderr, "%s: verifying %s memory against %s:\n", 314 | progname, mem->desc, upd->filename); 315 | 316 | fprintf(stderr, "%s: load data %s data from input file %s:\n", 317 | progname, mem->desc, upd->filename); 318 | } 319 | 320 | rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); 321 | if (rc < 0) { 322 | fprintf(stderr, "%s: read from file '%s' failed\n", 323 | progname, upd->filename); 324 | return -1; 325 | } 326 | size = rc; 327 | if (quell_progress < 2) { 328 | fprintf(stderr, "%s: input file %s contains %d bytes\n", 329 | progname, upd->filename, size); 330 | fprintf(stderr, "%s: reading on-chip %s data:\n", 331 | progname, mem->desc); 332 | } 333 | 334 | report_progress (0,1,"Reading"); 335 | rc = avr_read(pgm, v, upd->memtype, size, 1); 336 | if (rc < 0) { 337 | fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", 338 | progname, mem->desc, rc); 339 | pgm->err_led(pgm, ON); 340 | return -1; 341 | } 342 | report_progress (1,1,NULL); 343 | 344 | 345 | 346 | if (quell_progress < 2) { 347 | fprintf(stderr, "%s: verifying ...\n", progname); 348 | } 349 | rc = avr_verify(p, v, upd->memtype, size); 350 | if (rc < 0) { 351 | fprintf(stderr, "%s: verification error; content mismatch\n", 352 | progname); 353 | pgm->err_led(pgm, ON); 354 | return -1; 355 | } 356 | 357 | if (quell_progress < 2) { 358 | fprintf(stderr, "%s: %d bytes of %s verified\n", 359 | progname, rc, mem->desc); 360 | } 361 | 362 | pgm->vfy_led(pgm, OFF); 363 | } 364 | else { 365 | fprintf(stderr, "%s: invalid update operation (%d) requested\n", 366 | progname, upd->op); 367 | return -1; 368 | } 369 | 370 | return 0; 371 | } 372 | 373 | -------------------------------------------------------------------------------- /update.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2000-2005 Brian S. Dean 4 | * Copyright (C) 2007 Joerg Wunsch 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #ifndef update_h 24 | #define update_h 25 | 26 | enum { 27 | DEVICE_READ, 28 | DEVICE_WRITE, 29 | DEVICE_VERIFY 30 | }; 31 | 32 | 33 | typedef struct update_t { 34 | char * memtype; 35 | int op; 36 | char * filename; 37 | int format; 38 | } UPDATE; 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | extern UPDATE * parse_op(char * s); 45 | extern UPDATE * dup_update(UPDATE * upd); 46 | extern UPDATE * new_update(int op, char * memtype, int filefmt, 47 | char * filename); 48 | extern int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, 49 | int nowrite, int verify); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /usbasp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2006 Thomas Fischl 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | #ifndef usbasp_h 23 | #define usbasp_h 24 | 25 | #include "avrpart.h" 26 | 27 | /* USB identifiers */ 28 | #define USBASP_SHARED_VID 0x16C0 /* VOTI */ 29 | #define USBASP_SHARED_PID 0x05DC /* Obdev's free shared PID */ 30 | 31 | #define USBASP_OLD_VID 0x03EB /* ATMEL */ 32 | #define USBASP_OLD_PID 0xC7B4 /* (unoffical) USBasp */ 33 | 34 | #define USBASP_NIBOBEE_VID 0x16C0 /* VOTI */ 35 | #define USBASP_NIBOBEE_PID 0x092F /* NIBObee PID */ 36 | 37 | /* USB function call identifiers */ 38 | #define USBASP_FUNC_CONNECT 1 39 | #define USBASP_FUNC_DISCONNECT 2 40 | #define USBASP_FUNC_TRANSMIT 3 41 | #define USBASP_FUNC_READFLASH 4 42 | #define USBASP_FUNC_ENABLEPROG 5 43 | #define USBASP_FUNC_WRITEFLASH 6 44 | #define USBASP_FUNC_READEEPROM 7 45 | #define USBASP_FUNC_WRITEEEPROM 8 46 | #define USBASP_FUNC_SETLONGADDRESS 9 47 | #define USBASP_FUNC_SETISPSCK 10 48 | 49 | /* Block mode flags */ 50 | #define USBASP_BLOCKFLAG_FIRST 1 51 | #define USBASP_BLOCKFLAG_LAST 2 52 | 53 | /* Block mode data size */ 54 | #define USBASP_READBLOCKSIZE 200 55 | #define USBASP_WRITEBLOCKSIZE 200 56 | 57 | /* ISP SCK speed identifiers */ 58 | #define USBASP_ISP_SCK_AUTO 0 59 | #define USBASP_ISP_SCK_0_5 1 /* 500 Hz */ 60 | #define USBASP_ISP_SCK_1 2 /* 1 kHz */ 61 | #define USBASP_ISP_SCK_2 3 /* 2 kHz */ 62 | #define USBASP_ISP_SCK_4 4 /* 4 kHz */ 63 | #define USBASP_ISP_SCK_8 5 /* 8 kHz */ 64 | #define USBASP_ISP_SCK_16 6 /* 16 kHz */ 65 | #define USBASP_ISP_SCK_32 7 /* 32 kHz */ 66 | #define USBASP_ISP_SCK_93_75 8 /* 93.75 kHz */ 67 | #define USBASP_ISP_SCK_187_5 9 /* 187.5 kHz */ 68 | #define USBASP_ISP_SCK_375 10 /* 375 kHz */ 69 | #define USBASP_ISP_SCK_750 11 /* 750 kHz */ 70 | #define USBASP_ISP_SCK_1500 12 /* 1.5 MHz */ 71 | 72 | typedef struct sckoptions_t { 73 | int id; 74 | double frequency; 75 | } CLOCKOPTIONS; 76 | 77 | /* USB error identifiers */ 78 | #define USB_ERROR_NOTFOUND 1 79 | #define USB_ERROR_ACCESS 2 80 | #define USB_ERROR_IO 3 81 | 82 | #ifdef __cplusplus 83 | extern "C" { 84 | #endif 85 | 86 | void usbasp_initpgm (PROGRAMMER * pgm); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* usbasp_h */ 93 | -------------------------------------------------------------------------------- /usbdevs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2006 Joerg Wunsch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* $Id$ */ 21 | 22 | /* 23 | * defines for the USB interface 24 | */ 25 | 26 | #ifndef usbdevs_h 27 | #define usbdevs_h 28 | 29 | #define USB_VENDOR_ATMEL 1003 30 | #define USB_DEVICE_JTAGICEMKII 0x2103 31 | #define USB_DEVICE_AVRISPMKII 0x2104 32 | #define USB_DEVICE_STK600 0x2106 33 | #define USB_DEVICE_AVRDRAGON 0x2107 34 | 35 | /* 36 | * Should we query the endpoint number and max transfer size from USB? 37 | * After all, the JTAG ICE mkII docs document these values. 38 | */ 39 | #define USBDEV_BULK_EP_WRITE 0x02 40 | #define USBDEV_BULK_EP_READ 0x82 41 | #define USBDEV_MAX_XFER 64 42 | 43 | #endif /* usbdevs_h */ 44 | -------------------------------------------------------------------------------- /usbtiny.h: -------------------------------------------------------------------------------- 1 | /* 2 | * avrdude - A Downloader/Uploader for AVR device programmers 3 | * Copyright (C) 2007 Limor Fried 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef usbtiny_h 22 | #define usbtiny_h 23 | 24 | #include "avrpart.h" 25 | 26 | // these are specifically assigned to USBtiny, 27 | // if you need your own VID and PIDs you can get them for cheap from 28 | // www.mecanique.co.uk so please don't reuse these. Thanks! 29 | #define USBTINY_VENDOR 0x1781 30 | #define USBTINY_PRODUCT 0x0C9F 31 | 32 | // Generic requests to the USBtiny 33 | #define USBTINY_ECHO 0 // echo test 34 | #define USBTINY_READ 1 // read byte (wIndex:address) 35 | #define USBTINY_WRITE 2 // write byte (wIndex:address, wValue:value) 36 | #define USBTINY_CLR 3 // clear bit (wIndex:address, wValue:bitno) 37 | #define USBTINY_SET 4 // set bit (wIndex:address, wValue:bitno) 38 | 39 | // Programming requests 40 | #define USBTINY_POWERUP 5 // apply power (wValue:SCK-period, wIndex:RESET) 41 | #define USBTINY_POWERDOWN 6 // remove power from chip 42 | #define USBTINY_SPI 7 // issue SPI command (wValue:c1c0, wIndex:c3c2) 43 | #define USBTINY_POLL_BYTES 8 // set poll bytes for write (wValue:p1p2) 44 | #define USBTINY_FLASH_READ 9 // read flash (wIndex:address) 45 | #define USBTINY_FLASH_WRITE 10 // write flash (wIndex:address, wValue:timeout) 46 | #define USBTINY_EEPROM_READ 11 // read eeprom (wIndex:address) 47 | #define USBTINY_EEPROM_WRITE 12 // write eeprom (wIndex:address, wValue:timeout) 48 | 49 | 50 | 51 | // Flags to indicate how to set RESET on power up 52 | #define RESET_LOW 0 53 | #define RESET_HIGH 1 54 | 55 | // The SCK speed can be set by avrdude, to allow programming of slow-clocked parts 56 | #define SCK_MIN 1 // usec delay (target clock >= 4 MHz) 57 | #define SCK_MAX 250 // usec (target clock >= 16 KHz) 58 | #define SCK_DEFAULT 10 // usec (target clock >= 0.4 MHz) 59 | 60 | // How much data, max, do we want to send in one USB packet? 61 | #define CHUNK_SIZE 128 // must be power of 2 less than 256 62 | 63 | // The default USB Timeout 64 | #define USB_TIMEOUT 500 // msec 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | 70 | void usbtiny_initpgm (PROGRAMMER * pgm); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* usbtiny_h */ 77 | -------------------------------------------------------------------------------- /windows/.cvsignore: -------------------------------------------------------------------------------- 1 | .cvsignore 2 | .deps 3 | Makefile 4 | Makefile.in 5 | -------------------------------------------------------------------------------- /windows/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # avrdude - A Downloader/Uploader for AVR device programmers 3 | # Copyright (C) 2003 Theodore A. Roth 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | # 19 | 20 | # 21 | # $Id$ 22 | # 23 | 24 | # 25 | # This Makefile will only be used on windows based systems. 26 | # 27 | 28 | local_install_list = \ 29 | giveio.sys \ 30 | install_giveio.bat \ 31 | remove_giveio.bat \ 32 | status_giveio.bat 33 | 34 | EXTRA_DIST = \ 35 | giveio.c \ 36 | $(local_install_list) 37 | 38 | bin_PROGRAMS = loaddrv 39 | 40 | loaddrv_SOURCES = \ 41 | loaddrv.c \ 42 | loaddrv.h 43 | 44 | install-exec-local: 45 | $(mkinstalldirs) $(DESTDIR)$(bindir) 46 | @list='$(local_install_list)'; for file in $$list; do \ 47 | echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) \ 48 | $(srcdir)/$$file $(DESTDIR)$(bindir)/$$file"; \ 49 | $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $(srcdir)/$$file \ 50 | $(DESTDIR)$(bindir)/$$file; \ 51 | done 52 | 53 | uninstall-local: 54 | @for file in $(local_install_list); do \ 55 | echo " rm -f $(DESTDIR)$(bindir)/$$file"; \ 56 | rm -f $(DESTDIR)$(bindir)/$$file; \ 57 | done 58 | 59 | -------------------------------------------------------------------------------- /windows/giveio.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | 3 | Author: Dale Roberts 4 | Date: 8/30/95 5 | Program: GIVEIO.SYS 6 | Compile: Use DDK BUILD facility 7 | 8 | Purpose: Give direct port I/O access to a user mode process. 9 | 10 | *********************************************************************/ 11 | #include 12 | 13 | /* 14 | * The name of our device driver. 15 | */ 16 | #define DEVICE_NAME_STRING L"giveio" 17 | 18 | /* 19 | * This is the "structure" of the IOPM. It is just a simple 20 | * character array of length 0x2000. 21 | * 22 | * This holds 8K * 8 bits -> 64K bits of the IOPM, which maps the 23 | * entire 64K I/O space of the x86 processor. Any 0 bits will give 24 | * access to the corresponding port for user mode processes. Any 1 25 | * bits will disallow I/O access to the corresponding port. 26 | */ 27 | #define IOPM_SIZE 0x2000 28 | typedef UCHAR IOPM[IOPM_SIZE]; 29 | 30 | /* 31 | * This will hold simply an array of 0's which will be copied 32 | * into our actual IOPM in the TSS by Ke386SetIoAccessMap(). 33 | * The memory is allocated at driver load time. 34 | */ 35 | IOPM *IOPM_local = 0; 36 | 37 | /* 38 | * These are the two undocumented calls that we will use to give 39 | * the calling process I/O access. 40 | * 41 | * Ke386IoSetAccessMap() copies the passed map to the TSS. 42 | * 43 | * Ke386IoSetAccessProcess() adjusts the IOPM offset pointer so that 44 | * the newly copied map is actually used. Otherwise, the IOPM offset 45 | * points beyond the end of the TSS segment limit, causing any I/O 46 | * access by the user mode process to generate an exception. 47 | */ 48 | void Ke386SetIoAccessMap(int, IOPM *); 49 | void Ke386QueryIoAccessMap(int, IOPM *); 50 | void Ke386IoSetAccessProcess(PEPROCESS, int); 51 | 52 | /********************************************************************* 53 | Release any allocated objects. 54 | *********************************************************************/ 55 | VOID GiveioUnload(IN PDRIVER_OBJECT DriverObject) 56 | { 57 | WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING; 58 | UNICODE_STRING uniDOSString; 59 | 60 | if(IOPM_local) 61 | MmFreeNonCachedMemory(IOPM_local, sizeof(IOPM)); 62 | 63 | RtlInitUnicodeString(&uniDOSString, DOSNameBuffer); 64 | IoDeleteSymbolicLink (&uniDOSString); 65 | IoDeleteDevice(DriverObject->DeviceObject); 66 | } 67 | 68 | /********************************************************************* 69 | Set the IOPM (I/O permission map) of the calling process so that it 70 | is given full I/O access. Our IOPM_local[] array is all zeros, so 71 | the IOPM will be all zeros. If OnFlag is 1, the process is given I/O 72 | access. If it is 0, access is removed. 73 | *********************************************************************/ 74 | VOID SetIOPermissionMap(int OnFlag) 75 | { 76 | Ke386IoSetAccessProcess(PsGetCurrentProcess(), OnFlag); 77 | Ke386SetIoAccessMap(1, IOPM_local); 78 | } 79 | 80 | void GiveIO(void) 81 | { 82 | SetIOPermissionMap(1); 83 | } 84 | 85 | /********************************************************************* 86 | Service handler for a CreateFile() user mode call. 87 | 88 | This routine is entered in the driver object function call table by 89 | the DriverEntry() routine. When the user mode application calls 90 | CreateFile(), this routine gets called while still in the context of 91 | the user mode application, but with the CPL (the processor's Current 92 | Privelege Level) set to 0. This allows us to do kernel mode 93 | operations. GiveIO() is called to give the calling process I/O 94 | access. All the user mode application needs do to obtain I/O access 95 | is open this device with CreateFile(). No other operations are 96 | required. 97 | *********************************************************************/ 98 | NTSTATUS GiveioCreateDispatch( 99 | IN PDEVICE_OBJECT DeviceObject, 100 | IN PIRP Irp 101 | ) 102 | { 103 | GiveIO(); // give the calling process I/O access 104 | 105 | Irp->IoStatus.Information = 0; 106 | Irp->IoStatus.Status = STATUS_SUCCESS; 107 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 108 | return STATUS_SUCCESS; 109 | } 110 | 111 | /********************************************************************* 112 | Driver Entry routine. 113 | 114 | This routine is called only once after the driver is initially 115 | loaded into memory. It allocates everything necessary for the 116 | driver's operation. In our case, it allocates memory for our IOPM 117 | array, and creates a device which user mode applications can open. 118 | It also creates a symbolic link to the device driver. This allows 119 | a user mode application to access our driver using the \\.\giveio 120 | notation. 121 | *********************************************************************/ 122 | NTSTATUS DriverEntry( 123 | IN PDRIVER_OBJECT DriverObject, 124 | IN PUNICODE_STRING RegistryPath 125 | ) 126 | { 127 | PDEVICE_OBJECT deviceObject; 128 | NTSTATUS status; 129 | WCHAR NameBuffer[] = L"\\Device\\" DEVICE_NAME_STRING; 130 | WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING; 131 | UNICODE_STRING uniNameString, uniDOSString; 132 | 133 | // 134 | // Allocate a buffer for the local IOPM and zero it. 135 | // 136 | IOPM_local = MmAllocateNonCachedMemory(sizeof(IOPM)); 137 | if(IOPM_local == 0) 138 | return STATUS_INSUFFICIENT_RESOURCES; 139 | RtlZeroMemory(IOPM_local, sizeof(IOPM)); 140 | 141 | // 142 | // Set up device driver name and device object. 143 | // 144 | RtlInitUnicodeString(&uniNameString, NameBuffer); 145 | RtlInitUnicodeString(&uniDOSString, DOSNameBuffer); 146 | 147 | status = IoCreateDevice(DriverObject, 0, 148 | &uniNameString, 149 | FILE_DEVICE_UNKNOWN, 150 | 0, FALSE, &deviceObject); 151 | 152 | if(!NT_SUCCESS(status)) 153 | return status; 154 | 155 | status = IoCreateSymbolicLink (&uniDOSString, &uniNameString); 156 | 157 | if (!NT_SUCCESS(status)) 158 | return status; 159 | 160 | // 161 | // Initialize the Driver Object with driver's entry points. 162 | // All we require are the Create and Unload operations. 163 | // 164 | DriverObject->MajorFunction[IRP_MJ_CREATE] = GiveioCreateDispatch; 165 | DriverObject->DriverUnload = GiveioUnload; 166 | return STATUS_SUCCESS; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /windows/giveio.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigmike/avrdude/f3d3c3c126e916e0f5591f18f18d05b35a33bbc2/windows/giveio.sys -------------------------------------------------------------------------------- /windows/install_giveio.bat: -------------------------------------------------------------------------------- 1 | @set DIRVERNAME=giveio 2 | @set DIRVERFILE=%DIRVERNAME%.sys 3 | 4 | @echo Copying the driver to the windows directory 5 | @echo target file: %WINDIR%\%DIRVERFILE% 6 | @copy %DIRVERFILE% %WINDIR%\%DIRVERFILE% 7 | 8 | @echo Remove a running service if needed... 9 | @loaddrv stop %DIRVERNAME% >NUL 10 | @if errorlevel 2 goto install 11 | 12 | @loaddrv remove %DIRVERNAME% >NUL 13 | @if errorlevel 1 goto install 14 | 15 | :install 16 | @echo Installing Windows NT/2k/XP driver: %DIRVERNAME% 17 | 18 | @loaddrv install %DIRVERNAME% %WINDIR%\%DIRVERFILE% 19 | @if errorlevel 3 goto error 20 | 21 | @loaddrv start %DIRVERNAME% 22 | @if errorlevel 1 goto error 23 | 24 | @loaddrv starttype %DIRVERNAME% auto 25 | @if errorlevel 1 goto error 26 | 27 | @echo Success 28 | @goto exit 29 | 30 | :error 31 | @echo ERROR: Installation of %DIRVERNAME% failed 32 | 33 | :exit 34 | 35 | -------------------------------------------------------------------------------- /windows/loaddrv.h: -------------------------------------------------------------------------------- 1 | #ifndef LOADDRV_H 2 | #define LOADDRV_H 3 | 4 | #include 5 | 6 | #define OKAY 0 7 | #define UNEXPECTED_ERROR 9999 8 | 9 | //prototypes 10 | DWORD LoadDriverInit(void); 11 | void LoadDriverCleanup(void); 12 | DWORD DriverInstall(LPSTR, LPSTR); 13 | DWORD DriverStart(LPSTR); 14 | DWORD DriverStop(LPSTR); 15 | DWORD DriverRemove(LPSTR); 16 | DWORD DriverStatus(LPSTR); 17 | DWORD DriverStartType(LPSTR, DWORD); 18 | #endif //LOADDRV_H 19 | 20 | 21 | -------------------------------------------------------------------------------- /windows/remove_giveio.bat: -------------------------------------------------------------------------------- 1 | @set DIRVERNAME=giveio 2 | 3 | @loaddrv stop %DIRVERNAME% 4 | @if errorlevel 2 goto error 5 | 6 | @loaddrv remove %DIRVERNAME% 7 | @if errorlevel 1 goto error 8 | 9 | @goto exit 10 | 11 | :error 12 | @echo ERROR: Deinstallation of %DIRVERNAME% failed 13 | 14 | :exit 15 | -------------------------------------------------------------------------------- /windows/status_giveio.bat: -------------------------------------------------------------------------------- 1 | @set DIRVERNAME=giveio 2 | 3 | @loaddrv status %DIRVERNAME% 4 | @if errorlevel 1 goto error 5 | 6 | @goto exit 7 | 8 | :error 9 | @echo ERROR: Status querry for %DIRVERNAME% failed 10 | 11 | :exit 12 | 13 | --------------------------------------------------------------------------------