diff options
-rw-r--r-- | commandline/Makefile | 66 | ||||
-rw-r--r-- | commandline/Makefile.windows | 18 | ||||
-rw-r--r-- | commandline/Readme | 10 | ||||
-rwxr-xr-x | commandline/bootloadHID | bin | 15048 -> 0 bytes | |||
-rw-r--r-- | commandline/cdc232.hex | 173 | ||||
-rw-r--r-- | commandline/examples/micronucleus.c | 252 | ||||
-rwxr-xr-x | commandline/hidsdi.h | 50 | ||||
-rw-r--r-- | commandline/library/littleWire_util.c | 12 | ||||
-rw-r--r-- | commandline/library/littleWire_util.h | 13 | ||||
-rw-r--r-- | commandline/library/micronucleus_lib.c | 102 | ||||
-rw-r--r-- | commandline/library/micronucleus_lib.h | 87 | ||||
-rw-r--r-- | commandline/library/opendevice.c | 203 | ||||
-rw-r--r-- | commandline/library/opendevice.h | 81 | ||||
-rw-r--r-- | commandline/littleWire_v11.hex | 356 | ||||
-rw-r--r-- | commandline/main.c | 265 | ||||
-rw-r--r-- | commandline/main.o | bin | 6128 -> 0 bytes | |||
-rw-r--r-- | commandline/usb-libusb.c | 203 | ||||
-rwxr-xr-x | commandline/usb-windows.c | 180 | ||||
-rw-r--r-- | commandline/usbcalls.c | 20 | ||||
-rw-r--r-- | commandline/usbcalls.h | 81 | ||||
-rw-r--r-- | commandline/usbcalls.o | bin | 4012 -> 0 bytes |
21 files changed, 1320 insertions, 852 deletions
diff --git a/commandline/Makefile b/commandline/Makefile index 5c8f81a..e05f7a6 100644 --- a/commandline/Makefile +++ b/commandline/Makefile @@ -1,46 +1,42 @@ -# Name: Makefile -# Project: Automator -# Author: Christian Starkjohann -# Creation Date: 2006-02-01 -# Tabsize: 4 -# Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH -# License: Proprietary, free under certain conditions. See Documentation. -# This Revision: $Id: Makefile 281 2007-03-20 13:22:10Z cs $ -# Please read the definitions below and edit them as appropriate for your -# system: +# Makefile initially writen for Little-Wire by Omer Kilic <omerkilic@gmail.com> +# Later on modified by ihsan Kehribar <ihsan@kehribar.me> for Micronucleus bootloader application. -# Use the following 3 lines on Unix and Mac OS X: -USBFLAGS= `libusb-config --cflags` -USBLIBS= `libusb-config --libs` -EXE_SUFFIX= +CC=gcc -# Use the following 3 lines on Windows and comment out the 3 above: -#USBFLAGS= -#USBLIBS= -lhid -lusb -lsetupapi -#EXE_SUFFIX= .exe +# FIXME: Need to add OSX stuff +ifeq ($(shell uname), Linux) + USBFLAGS = `libusb-config --cflags` + USBLIBS = `libusb-config --libs` + EXE_SUFFIX = + OSFLAG = -D LINUX +else + USBFLAGS = -I C:\MinGW\include + USBLIBS = -L C:\MinGW\lib -lusb + EXE_SUFFIX = .exe + OSFLAG = -D WIN +endif -CC= gcc -CXX= g++ -CFLAGS= -O2 -Wall $(USBFLAGS) -LIBS= $(USBLIBS) -ARCH_COMPILE= -ARCH_LINK= +LIBS = $(USBLIBS) +INCLUDE = library +CFLAGS = $(USBFLAGS) $(LIBS) -I$(INCLUDE) -O -g $(OSFLAG) -OBJ= main.o usbcalls.o -PROGRAM= bootloadHID$(EXE_SUFFIX) +LWLIBS = opendevice micronucleus_lib littleWire_util +EXAMPLES = micronucleus -all: $(PROGRAM) +.PHONY: clean library -$(PROGRAM): $(OBJ) - $(CC) $(ARCH_LINK) $(CFLAGS) -o $(PROGRAM) $(OBJ) $(LIBS) +all: library $(EXAMPLES) +library: $(LWLIBS) -strip: $(PROGRAM) - strip $(PROGRAM) +$(LWLIBS): + @echo Building library: $@... + $(CC) $(CFLAGS) -c library/$@.c -clean: - rm -f $(OBJ) $(PROGRAM) +$(EXAMPLES): $(addsuffix .o, $(LWLIBS)) + @echo Building example: $@... + $(CC) $(CFLAGS) -o $@$(EXE_SUFFIX) examples/$@.c $^ $(LIBS) -.c.o: - $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o +clean: + rm -f $(EXAMPLES)$(EXE_SUFFIX) *.o *.exe diff --git a/commandline/Makefile.windows b/commandline/Makefile.windows deleted file mode 100644 index 16f3ba8..0000000 --- a/commandline/Makefile.windows +++ /dev/null @@ -1,18 +0,0 @@ -# Name: Makefile.windows -# Project: Automator -# Author: Christian Starkjohann -# Creation Date: 2006-02-20 -# Tabsize: 4 -# Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH -# License: Proprietary, free under certain conditions. See Documentation. -# This Revision: $Id$ - -# You may use this file with -# make -f Makefile.windows -# on Windows with MinGW instead of editing the main Makefile. - -include Makefile - -USBFLAGS= -USBLIBS= -lhid -lusb -lsetupapi -EXE_SUFFIX= .exe diff --git a/commandline/Readme b/commandline/Readme new file mode 100644 index 0000000..45df377 --- /dev/null +++ b/commandline/Readme @@ -0,0 +1,10 @@ +This commandline application for the Micronucleus bootloader is written by ihsan Kehribar <ihsan@kehribar.me> + +I have only tested this application on my Ubuntu machine so far. Might need little tweaks for the Windows and Mac platforms. + +Usage example: + sudo ./micronucleus name_of_the_file.hex + +Binary file writing and program memory reading hasn't been implemented yet. + +Program sometimes sporadicly crashes and fails to upload the user application. User should unplug and re-plug the device and restart the application if such situation happens. I hope this problem will be solved in the future. diff --git a/commandline/bootloadHID b/commandline/bootloadHID Binary files differdeleted file mode 100755 index 4f4b3be..0000000 --- a/commandline/bootloadHID +++ /dev/null diff --git a/commandline/cdc232.hex b/commandline/cdc232.hex new file mode 100644 index 0000000..81fc38f --- /dev/null +++ b/commandline/cdc232.hex @@ -0,0 +1,173 @@ +:1000000054C019C4F9C124C46BC06AC069C068C0B7 +:1000100067C066C065C064C063C062C03BC40403FF +:10002000090422037700770077002E007200650034 +:10003000630075007200730069006F006E002E008F +:100040006A00700010035500530042002D0032007A +:10005000330032001201100102000008C016E10551 +:10006000000101020001090243000201008032097F +:100070000400000102020100052400100104240212 +:100080000205240600010524010301070583030876 +:1000900000FF09040100020A000000070501020236 +:1000A0000000070581020800000011241FBECFE5F3 +:1000B000D2E0DEBFCDBF10E0A0E6B0E0EEEAFAE0AD +:1000C00002C005900D92AC36B107D9F711E0ACE64D +:1000D000B0E001C01D92AF33B107E1F758D3E5C4DA +:1000E0008FCFAC9A8BB780628BBF8BE480937C0000 +:1000F0008093A7008AE580937B008093A6000895F3 +:100100001F93CF93DF93DC01162FEA01888184FFD0 +:1001100005C0898198E88927898302C08AE5888398 +:10012000AE014E5F5F4F212FFA018D9181932150D7 +:100130001216DCF3CA01612F48D11C5F1883DF91CE +:10014000CF911F91089546EA50E0DADF08954BE71A +:1001500050E0D6DF08951F93CF93DF9360918C001A +:10016000635067FDB3C080918900CCE0D0E0C81B2C +:10017000D109C057DF4F80918800803118F4CE013B +:10018000EAD29EC08D3209F08BC0683009F098C069 +:1001900083EC809370008AE58093600010926C007D +:1001A0008881807621F0CE01A8D2282F66C09A815E +:1001B000109279008981882321F410927A0022E03C +:1001C00055C0853019F490938D004FC08630B9F535 +:1001D0008B81813041F484E590E090938B00809393 +:1001E0008A0022E128C0823021F4CE0171D2282F6A +:1001F00022C08330F9F48A81882341F48EE190E0B3 +:1002000090938B0080938A0024E015C0813041F4E4 +:1002100082E290E090938B0080938A0022E20BC0F0 +:10022000823041F484E490E090938B0080938A00C4 +:1002300020E101C020E080E480936C001EC0883083 +:1002400021F421E08FE890E013C0893019F49093F5 +:100250008F000BC08A3011F421E008C08B3029F4E4 +:100260008BE480937C008093A70020E089E790E0F6 +:1002700090938B0080938A0009C02F3F39F48881C6 +:1002800087FD2E8180E880936C0006C08F818823D3 +:1002900019F48E81821708F0822F8093610010C0BC +:1002A00080916C0087FF0CC0CE01B7D28F3F21F444 +:1002B0008EE18093600004C0882311F010926100E9 +:1002C00080918C00181614F410928C0080916000BC +:1002D00084FF58C0809161008F3F09F453C0182FEC +:1002E000893008F018E0811B8093610080917000D4 +:1002F00098E8892780937000112391F180916C0018 +:1003000087FF08C081E790E0612F16D2182F89304F +:1003100098F526C020918A0030918B0086FF0DC091 +:10032000A1E7B0E080E090E0F901E80FF91FE49167 +:10033000ED9301961817C1F708C0912FD901E1E795 +:10034000F0E08D9181939150E1F71150812F90E071 +:100350001F5F0196820F931F90938B0080938A00FA +:1003600081E790E0612F31D0612F6C5F6C3041F0FC +:100370008FEF8093610004C08FEF809361006EE186 +:100380006093600094E186B3887131F49150D9F79D +:1003900010928D0010928700DF91CF911F910895E8 +:1003A000A82FB92F80E090E041E050EA609530E05E +:1003B00009C02D9182279795879510F0842795275E +:1003C000305EC8F36F5FA8F30895EADF8D939D93C5 +:1003D0000895A6E088279927AA9569F00197E1F387 +:1003E000B399FCCFB39BFECF81E09927A6B30196CA +:1003F00011F0A871D9F70895CF93CFB7CF93C395D4 +:10040000B39BE9F7B39B0BC0B39B09C0B39B07C079 +:10041000B39B05C0B39B03C0B39B01C0D8C00F9270 +:10042000DF93C0918900DD27C057DF4F012EB39BBA +:1004300003C0DF910F90E6CF2F930F931F934F933D +:100440002FEF4F6F06B303FB20F95F933F9350E00C +:100450003BE065C016B30126502953FDC89556B33D +:10046000012703FB25F92F7306B3B1F0502710279E +:1004700013FB26F906B22230F0F000C016B30127B4 +:1004800003FB27F90126502906B22430E8F54F77FF +:10049000206816B30000F6CF50274F7D206206B2C9 +:1004A000102F000000C006B300265029102713FBB0 +:1004B00026F906B2E2CF4F7B06B3206400C0DACF44 +:1004C00001265029187106B269F14E7F2160012F73 +:1004D00016B328C0002650294D7F06B22260102F87 +:1004E00029C0012650294B7F06B22460012F2DC060 +:1004F00016B301265029477F2860000006B22EC09F +:100500004F7E06B3206130C0422706B349930026D0 +:100510005029102706B24FEF13FB20F9297F16B39D +:1005200079F2187159F10126502906B2012703FB0F +:1005300021F9237F06B371F2002650293150D0F003 +:1005400006B2102713FB22F9277E16B351F20126BB +:100550005029012703FB06B223F92F7C49F2000042 +:1005600006B3102713FB24F90026502906B22F7971 +:1005700039F270CF10E21ABF00271CC03B503195F2 +:10058000C31BD04010E21ABF0881033C21F10B3499 +:1005900011F1209187001981110F1213EDCF4A81BB +:1005A000441F093669F10D3211F0013E29F74F70F1 +:1005B00009F0042F00938E003F915F914F911F919E +:1005C0000F912F91DF910F90CAB7C5FD18CFCF9132 +:1005D000CFBFCF91189520918E00222369F31091FF +:1005E0008C001123D1F53430D2F130938C0020935C +:1005F0008800109189003BE0311B309389002FC0A7 +:1006000000918C0001304CF50AE54F7049F43091AF +:10061000600034FD25C000936000C0E7D0E024C036 +:10062000433049F030917B0034FD1AC000937B00C9 +:10063000CCE7D0E019C03091A60034FD11C0009382 +:10064000A600C7EAD0E010C0052710E000C021C016 +:10065000052710E0C89508BB14C03AE501C032ED8B +:10066000032EC0E0D0E032E017B31861C39A08B39C +:1006700017BB58E120E84FEF20FF052708BB27955F +:1006800017951C3F28F700004552B0F720FF0527BB +:10069000279508BB17951C3FB8F629913A9561F745 +:1006A000077E10918D00110F08BBC250D04011F091 +:1006B0001093870010E21ABF086017B3177E402F0F +:1006C000477E54E05A95F1F708BB17BB48BB74CF7F +:1006D000FC018381813049F484E590E090938B00A4 +:1006E00080938A0080915400089586E690E090936C +:1006F0008B0080938A0083E40895FC012081822F7F +:1007000080768032B9F49181892F8052823010F442 +:100710008FEF0895923239F480916D00882319F497 +:1007200082E080936D0027FD05C081E08093B200D8 +:1007300080E0089580E00895FC0180916E00808340 +:1007400080916F008183128213821482158288E067 +:10075000868387E00895DC010BC0E92FF0E0E454C4 +:10076000FF4F8D9180839F5F9F7790933D016150F4 +:1007700090913D01662389F780913E018150891B4C +:100780008F77823018F48FEF80938C0008952EE0DD +:1007900088E190E00FB6F894A89581BD0FBE21BD09 +:1007A00080E090E07AD18F3F09F081BF87EE88BB6F +:1007B00088E187BBA89584EC99E02CE931E0F90148 +:1007C0003197F1F70197D9F717BA80EC92E190933E +:1007D0006F0080936E0080D084DC10926D001092C8 +:1007E000B2007894A895B7DCC2D090916D0099239F +:1007F000C9F38091A60084FFF5CF923021F482E600 +:1008000090E068E003C08AE690E062E09CDC8091C2 +:100810006D00815080936D00E5CFFC018081809355 +:100820006E00818180936F0080916E0090916F00C7 +:1008300053D081E00895B299189501BB05B50FBD5D +:1008400009E00DBD07E000BF00E20BBF01B3189542 +:1008500001BB0FB702BB0DB50A950DBD79F00BB505 +:100860000695B29900680BBD13BB0FB51EB5011BF1 +:100870000FBD13B302B30FBF01B3189500BF04BD82 +:100880000BB50DBB00E40ABF00E60BBF02B30FBF00 +:1008900001B3189501BBF09907C00BE40EB90EBB6C +:1008A00008B50FB901B3189500E40EB900E003BF15 +:1008B00001B31895881F9795881F9795881F97955E +:1008C000881F9795881F9795881F9795881F9795DC +:1008D000881F9795892F08959C0181E080BD80E84D +:1008E00088B9B99ABA988BB78F7B8BBF1ABC13BEE5 +:1008F00010BE80EE8EB984E58DB98FEF8FB9B90146 +:100900007695679580E090E06C5E70418C4F9F4FCC +:1009100040E050E085D021502EBD8EB589BD1DBC74 +:100920008EB590E0019695958795959587958195DB +:1009300085BD95B58EB5891718F08EB58F5F85BDCD +:1009400082E08ABD81E084BD90E499BF85B78C7F49 +:10095000826085BF9ABF8BB780648BBF10923E01C7 +:100960001092BB0010923C0110923D01089584B595 +:10097000882379F49091BB00983058F48DB3E92F17 +:10098000F0E0ED54FF4F80839F5F9093BB0081E0C8 +:1009900084BD80917B0084FF12C06091BB00662300 +:1009A00021F48091B200882351F083EB90E0CFDBFB +:1009B0008091BB0088708093B2001092BB0083B717 +:1009C000882369F5E0913E0180913D018E1739F150 +:1009D000F0E0E454FF4F80816DDF20913E012F5FF6 +:1009E0002F7720933E0112BE9BE49EB91EBA982F2A +:1009F0009295907F9F6098BD8695F8948FB983E01B +:100A000083BF789480918C0087FF09C080913D015D +:100A10008095820F8F77823010F010928C000895AD +:100A200097FB092E05260ED057FD04D014D00AD00E +:100A3000001C38F450954095309521953F4F4F4F0D +:100A40005F4F0895F6F790958095709561957F4F6B +:100A50008F4F9F4F0895A1E21A2EAA1BBB1BFD01C9 +:100A60000DC0AA1FBB1FEE1FFF1FA217B307E4078D +:100A7000F50720F0A21BB30BE40BF50B661F771FE5 +:100A8000881F991F1A9469F76095709580959095C5 +:100A90009B01AC01BD01CF010895E199FECF9FBB41 +:0E0AA0008EBBE09A99278DB30895F894FFCF8E +:0C0AAE005AFFA12000000000020003001D +:00000001FF diff --git a/commandline/examples/micronucleus.c b/commandline/examples/micronucleus.c new file mode 100644 index 0000000..1a6299e --- /dev/null +++ b/commandline/examples/micronucleus.c @@ -0,0 +1,252 @@ +/* + Created: September 2012 + by ihsan Kehribar <ihsan@kehribar.me> + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include "micronucleus_lib.h" +#include "littleWire_util.h" + +/****************************************************************************** +* Global definitions +******************************************************************************/ +unsigned int availableMemory; +unsigned char pageSize; +unsigned char sleepAmount; +unsigned int eraseSleep; +unsigned int pages; +unsigned char dataBuffer[65536 + 256]; /* buffer for file data */ +unsigned int startAddress, endAddress; +unsigned int i; +unsigned int k; +/*****************************************************************************/ + +/****************************************************************************** +* Function prototypes +******************************************************************************/ +static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAddr); /* taken from bootloadHID example from obdev */ +static int parseUntilColon(FILE *fp); /* taken from bootloadHID example from obdev */ +static int parseHex(FILE *fp, int numDigits); /* taken from bootloadHID example from obdev */ +/*****************************************************************************/ + +/****************************************************************************** +* Main function! +******************************************************************************/ +int main(int argc, char **argv) +{ + int res; + char *file = NULL; + micronucleus *myDevice = NULL; + + if(argc < 2) + { + printf("usage: %s [-r] [<intel-hexfile>]\n", argv[0]); + return 0; + } + if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) + { + printf("usage: %s [-r] [<intel-hexfile>]\n", argv[0]); + return 0; + } + if(strcmp(argv[1], "-r") == 0) + { + if(argc >= 3){ + file = argv[2]; + } + } + else + file = argv[1]; + + printf("> Please plug the device ... \n"); + printf("> Press CTRL+C to terminate the program.\n"); + + while(myDevice == NULL) + { + myDevice = micronucleus_connect(); + delay(250); + } + + printf("> Device is found!\n"); + + delay(750); + myDevice = micronucleus_connect(); + + res = micronucleus_getDeviceInfo(myDevice, &availableMemory, &pageSize, &sleepAmount); + if(res!=0) + { + printf(">> Abort mission! An error has occured ...\n"); + printf(">> Please unplug the device and restart the program. \n"); + return 0; + } + + if(pageSize==64) + { + printf("> Device is based on Attiny85!\n"); + } + else if(pageSize==32) + { + printf("> Device is based on Attiny45!\n"); + } + else + { + printf("> Unsupported device!\n"); + return 0; + } + + printf("> Available space for user application: %d bytes\n",availableMemory); + printf("> Suggested sleep time between sending pages: %u miliseconds\n",sleepAmount); + + pages = availableMemory/pageSize; + if((pages*pageSize) < availableMemory) pages++; + eraseSleep = sleepAmount*pages; + + printf("> Whole page count: %d\n",pages); + printf("> Erase function sleep duration: %d miliseconds\n",eraseSleep); + + startAddress = sizeof(dataBuffer); + endAddress = 0; + memset(dataBuffer, 0xFF, sizeof(dataBuffer)); + + if(parseIntelHex(file, dataBuffer, &startAddress, &endAddress)) + return 0; + + if(startAddress >= endAddress) + { + printf("> No data in input file, exiting.\n"); + return 0; + } + + if((endAddress-startAddress)>availableMemory) + { + printf("> Program file is too big for the bootloader!\n"); + return 0; + } + + /* Prints the decoded intel hex file */ + /*printf("> Decoded hex file starts ... \n"); + for(i=startAddress;i<endAddress;i+=16) + { + printf("%5d:\t",i); + for(k=0;k<16;k++) + printf("%2X ",dataBuffer[i+k]); + printf("\n"); + } + printf("> Decoded hex file ends ... \n");*/ + + printf("> Erasing the memory ...\n"); + res = micronucleus_eraseFlash(myDevice,eraseSleep); + if(res!=0) + { + printf(">> Abort mission! An error has occured ...\n"); + printf(">> Please unplug the device and restart the program. \n"); + return 0; + } + + printf("> Starting to upload ...\n"); + res = micronucleus_writeFlash(myDevice,startAddress,endAddress,dataBuffer,sleepAmount); + if(res!=0) + { + printf(">> Abort mission! An error has occured ...\n"); + printf(">> Please unplug the device and restart the program. \n"); + return 0; + } + + printf("> Starting the user app ...\n"); + res = micronucleus_startApp(myDevice); + if(res!=0) + { + printf(">> Abort mission! An error has occured ...\n"); + printf(">> Please unplug the device and restart the program. \n"); + return 0; + } + + printf(">> Micronucleus done. Thank you!\n"); + + return 0; +} +/******************************************************************************/ + +/******************************************************************************/ +static int parseUntilColon(FILE *fp) +{ +int c; + + do{ + c = getc(fp); + }while(c != ':' && c != EOF); + return c; +} +/******************************************************************************/ + +/******************************************************************************/ +static int parseHex(FILE *fp, int numDigits) +{ +int i; +char temp[9]; + + for(i = 0; i < numDigits; i++) + temp[i] = getc(fp); + temp[i] = 0; + return strtol(temp, NULL, 16); +} +/******************************************************************************/ + +/******************************************************************************/ +static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAddr) +{ +int address, base, d, segment, i, lineLen, sum; +FILE *input; + + input = fopen(hexfile, "r"); + if(input == NULL){ + printf("> Error opening %s: %s\n", hexfile, strerror(errno)); + return 1; + } + while(parseUntilColon(input) == ':'){ + sum = 0; + sum += lineLen = parseHex(input, 2); + base = address = parseHex(input, 4); + sum += address >> 8; + sum += address; + sum += segment = parseHex(input, 2); /* segment value? */ + if(segment != 0) /* ignore lines where this byte is not 0 */ + continue; + for(i = 0; i < lineLen ; i++){ + d = parseHex(input, 2); + buffer[address++] = d; + sum += d; + } + sum += parseHex(input, 2); + if((sum & 0xff) != 0){ + printf("> Warning: Checksum error between address 0x%x and 0x%x\n", base, address); + } + if(*startAddr > base) + *startAddr = base; + if(*endAddr < address) + *endAddr = address; + } + fclose(input); + return 0; +} +/******************************************************************************/ diff --git a/commandline/hidsdi.h b/commandline/hidsdi.h deleted file mode 100755 index cabb995..0000000 --- a/commandline/hidsdi.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Name: hidsdi.h - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: hidsdi.h 281 2007-03-20 13:22:10Z cs $ - */ - -/* -General Description -This file is a replacement for hidsdi.h from the Windows DDK. It defines some -of the types and function prototypes of this header for our project. If you -have the Windows DDK version of this file or a version shipped with MinGW, use -that instead. -*/ - -#ifndef _HIDSDI_H -#define _HIDSDI_H - -#include <pshpack4.h> - -#include <ddk/hidusage.h> -#include <ddk/hidpi.h> - -typedef struct{ - ULONG Size; - USHORT VendorID; - USHORT ProductID; - USHORT VersionNumber; -}HIDD_ATTRIBUTES; - -void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid); - -BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes); - -BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); -BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); -BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); - -BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen); -BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen); - -BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers); -BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers); - -#include <poppack.h> - -#endif diff --git a/commandline/library/littleWire_util.c b/commandline/library/littleWire_util.c new file mode 100644 index 0000000..d711302 --- /dev/null +++ b/commandline/library/littleWire_util.c @@ -0,0 +1,12 @@ + +#include <littleWire_util.h> + +/* Delay in miliseconds */ +void delay(unsigned int duration) +{ + #ifdef LINUX + usleep(duration*1000); + #else + Sleep(duration); + #endif +} diff --git a/commandline/library/littleWire_util.h b/commandline/library/littleWire_util.h new file mode 100644 index 0000000..dac8623 --- /dev/null +++ b/commandline/library/littleWire_util.h @@ -0,0 +1,13 @@ +#ifndef LITTLEWIRE_UTIL_H +#define LITTLEWIRE_UTIL_H + +#ifdef LINUX + #include <unistd.h> +#else + #include <windows.h> +#endif + +/* Delay in miliseconds */ +void delay(unsigned int duration); + +#endif diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c new file mode 100644 index 0000000..8e01427 --- /dev/null +++ b/commandline/library/micronucleus_lib.c @@ -0,0 +1,102 @@ +/* + Created: September 2012 + by ihsan Kehribar <ihsan@kehribar.me> + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/***************************************************************/ +/* See the micronucleus_lib.h for the function descriptions/comments */ +/***************************************************************/ +#include "micronucleus_lib.h" +#include "littleWire_util.h" + +micronucleus* micronucleus_connect() +{ + micronucleus *tempHandle = NULL; + + usb_init(); + usbOpenDevice(&tempHandle, VENDOR_ID, "*", PRODUCT_ID, "*", "*", NULL, NULL ); + + return tempHandle; +} + +int micronucleus_getDeviceInfo(micronucleus* deviceHandle, unsigned int* availableMemory, unsigned char* deviceSize, unsigned char* sleepAmount) +{ + int res; + res = usb_control_msg(deviceHandle, 0xC0, 0, 0, 0, rxBuffer, 4, USB_TIMEOUT); + + if(res!=4) + return -1; + + *availableMemory = (rxBuffer[0]<<8) + rxBuffer[1]; + *deviceSize = rxBuffer[2]; + *sleepAmount = rxBuffer[3]; + + return 0; +} + +int micronucleus_eraseFlash(micronucleus* deviceHandle, unsigned int sleepAmount) +{ + int res; + res = usb_control_msg(deviceHandle, 0xC0, 2, 0, 0, rxBuffer, 0, USB_TIMEOUT); + delay(sleepAmount); + if(res!=0) + return -1; + else + return 0; +} + +int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int startAddress, unsigned int endAddress, unsigned char* buffer, unsigned char sleepAmount) +{ + unsigned char tempBuffer[64]; + unsigned int i; + unsigned int k; + unsigned int res; + + for(i=startAddress;i<(endAddress);i+=64) + { + for(k=0;k<64;k++) + tempBuffer[k]=buffer[i+k]; + + res = usb_control_msg(deviceHandle, + USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 1, + 64,i, + tempBuffer, 64, + USB_TIMEOUT); + delay(sleepAmount); + if(res!=64) return -1; + } + + return 0; +} + +int micronucleus_startApp(micronucleus* deviceHandle) +{ + int res; + res = usb_control_msg(deviceHandle, 0xC0, 4, 0, 0, rxBuffer, 0, USB_TIMEOUT); + if(res!=0) + return -1; + else + return 0; +} + + + diff --git a/commandline/library/micronucleus_lib.h b/commandline/library/micronucleus_lib.h new file mode 100644 index 0000000..8a004e4 --- /dev/null +++ b/commandline/library/micronucleus_lib.h @@ -0,0 +1,87 @@ +#ifndef MICRONUCLEUS_LIB_H +#define MICRONUCLEUS_LIB_H + +/* + Created: September 2012 + by ihsan Kehribar <ihsan@kehribar.me> + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/******************************************************************************** +* Header files +********************************************************************************/ +#if defined(LINUX) + #include <usb.h> // this is libusb, see http://libusb.sourceforge.net/ +#else + #include <lusb0_usb.h> // this is libusb, see http://libusb.sourceforge.net/ +#endif +#include "opendevice.h" // common code moved to separate module +/*******************************************************************************/ + +/******************************************************************************** +* USB details +********************************************************************************/ +#define VENDOR_ID 0x16D0 +#define PRODUCT_ID 0x0753 +#define USB_TIMEOUT 0xFFFF +#define RX_BUFFER_SIZE 64 +#define TX_BUFFER_SIZE 64 +/*******************************************************************************/ + +/******************************************************************************** +* Declearations +********************************************************************************/ +typedef usb_dev_handle micronucleus; +unsigned char rxBuffer[RX_BUFFER_SIZE]; /* This has to be unsigned for the data's sake */ +unsigned char tBuffer[TX_BUFFER_SIZE]; /* This has to be unsigned for the data's sake */ +/*******************************************************************************/ + +/******************************************************************************** +* Try to connect to the device +* Returns: device handle for success, NULL for fail +********************************************************************************/ +micronucleus* micronucleus_connect(); +/*******************************************************************************/ + +/******************************************************************************** +* Get the device info +********************************************************************************/ +int micronucleus_getDeviceInfo(micronucleus* deviceHandle, unsigned int* availableMemory, unsigned char* deviceSize, unsigned char* sleepAmount); +/*******************************************************************************/ + +/******************************************************************************** +* Erase the flash memory +********************************************************************************/ +int micronucleus_eraseFlash(micronucleus* deviceHandle,unsigned int sleepAmount); +/*******************************************************************************/ + +/******************************************************************************** +* Write the flash memory +********************************************************************************/ +int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int startAddress, unsigned int endAddress, unsigned char* buffer, unsigned char sleepAmount); +/*******************************************************************************/ + +/******************************************************************************** +* Starts the user application +********************************************************************************/ +int micronucleus_startApp(micronucleus* deviceHandle); +/*******************************************************************************/ + +#endif diff --git a/commandline/library/opendevice.c b/commandline/library/opendevice.c new file mode 100644 index 0000000..137f50c --- /dev/null +++ b/commandline/library/opendevice.c @@ -0,0 +1,203 @@ +/* Name: opendevice.c + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +The functions in this module can be used to find and open a device based on +libusb or libusb-win32. +*/ + +#include <stdio.h> +#include "opendevice.h" + +/* ------------------------------------------------------------------------- */ + +#define MATCH_SUCCESS 1 +#define MATCH_FAILED 0 +#define MATCH_ABORT -1 + +/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ +static int _shellStyleMatch(char *text, char *p) +{ +int last, matched, reverse; + + for(; *p; text++, p++){ + if(*text == 0 && *p != '*') + return MATCH_ABORT; + switch(*p){ + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if(*text != *p) + return MATCH_FAILED; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while(*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if(*p == 0) + /* Trailing star matches everything. */ + return MATCH_SUCCESS; + while(*text) + if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) + return matched; + return MATCH_ABORT; + case '[': + reverse = p[1] == '^'; + if(reverse) /* Inverted character class. */ + p++; + matched = MATCH_FAILED; + if(p[1] == ']' || p[1] == '-') + if(*++p == *text) + matched = MATCH_SUCCESS; + for(last = *p; *++p && *p != ']'; last = *p) + if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) + matched = MATCH_SUCCESS; + if(matched == reverse) + return MATCH_FAILED; + continue; + } + } + return *text == 0; +} + +/* public interface for shell style matching: returns 0 if fails, 1 if matches */ +static int shellStyleMatch(char *text, char *pattern) +{ + if(pattern == NULL) /* NULL pattern is synonymous to "*" */ + return 1; + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i<rval;i++){ + if(i > buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +/* ------------------------------------------------------------------------- */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; + + usb_find_busses(); + usb_find_devices(); + for(bus = usb_get_busses(); bus; bus = bus->next){ + for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ + if((vendorID == 0 || dev->descriptor.idVendor == vendorID) + && (productID == 0 || dev->descriptor.idProduct == productID)){ + char vendor[256], product[256], serial[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + continue; + } + /* now check whether the names match: */ + len = vendor[0] = 0; + if(dev->descriptor.iManufacturer > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen device from vendor ->%s<-\n", vendor); */ + if(shellStyleMatch(vendor, vendorNamePattern)){ + len = product[0] = 0; + if(dev->descriptor.iProduct > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen product ->%s<-\n", product); */ + if(shellStyleMatch(product, productNamePattern)){ + len = serial[0] = 0; + if(dev->descriptor.iSerialNumber > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + } + if(shellStyleMatch(serial, serialNamePattern)){ + if(printMatchingDevicesFp != NULL){ + if(serial[0] == 0){ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); + }else{ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); + } + }else{ + break; + } + } + } + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) /* we have found a deice */ + break; + } + if(handle != NULL){ + errorCode = 0; + *device = handle; + } + if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ + errorCode = 0; + return errorCode; +} + +/* ------------------------------------------------------------------------- */ diff --git a/commandline/library/opendevice.h b/commandline/library/opendevice.h new file mode 100644 index 0000000..a23ed41 --- /dev/null +++ b/commandline/library/opendevice.h @@ -0,0 +1,81 @@ +/* Name: opendevice.h + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $ + */ + +/* +General Description: +This module offers additional functionality for host side drivers based on +libusb or libusb-win32. It includes a function to find and open a device +based on numeric IDs and textual description. It also includes a function to +obtain textual descriptions from a device. + +To use this functionality, simply copy opendevice.c and opendevice.h into your +project and add them to your Makefile. You may modify and redistribute these +files according to the GNU General Public License (GPL) version 2 or 3. +*/ + +#ifndef __OPENDEVICE_H_INCLUDED__ +#define __OPENDEVICE_H_INCLUDED__ + +#if defined(LINUX) + #include <usb.h> // this is libusb, see http://libusb.sourceforge.net/ +#else + #include <lusb0_usb.h> // this is libusb, see http://libusb.sourceforge.net/ +#endif +#include <stdio.h> + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); +/* This function gets a string descriptor from the device. 'index' is the + * string descriptor index. The string is returned in ISO Latin 1 encoding in + * 'buf' and it is terminated with a 0-character. The buffer size must be + * passed in 'buflen' to prevent buffer overflows. A libusb device handle + * must be given in 'dev'. + * Returns: The length of the string (excluding the terminating 0) or + * a negative number in case of an error. If there was an error, use + * usb_strerror() to obtain the error message. + */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); +/* This function iterates over all devices on all USB busses and searches for + * a device. Matching is done first by means of Vendor- and Product-ID (passed + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). + * When a device matches by its IDs, matching by names is performed. Name + * matching can be done on textual vendor name ('vendorNamePattern'), product + * name ('productNamePattern') and serial number ('serialNamePattern'). A + * device matches only if all non-null pattern match. If you don't care about + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: + * '*' stands for 0 or more characters, '?' for one single character, a list + * of characters in square brackets for a single character from the list + * (dashes are allowed to specify a range) and if the lis of characters begins + * with a caret ('^'), it matches one character which is NOT in the list. + * Other parameters to the function: If 'warningsFp' is not NULL, warning + * messages are printed to this file descriptor with fprintf(). If + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching + * devices are printed to the given file descriptor with fprintf(). + * If a device is opened, the resulting USB handle is stored in '*device'. A + * pointer to a "usb_dev_handle *" type variable must be passed here. + * Returns: 0 on success, an error code (see defines below) on failure. + */ + +/* usbOpenDevice() error codes: */ +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + + +/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ + +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ + +#endif /* __OPENDEVICE_H_INCLUDED__ */ diff --git a/commandline/littleWire_v11.hex b/commandline/littleWire_v11.hex new file mode 100644 index 0000000..a5c07e5 --- /dev/null +++ b/commandline/littleWire_v11.hex @@ -0,0 +1,356 @@ +:1000000042C05CC0DDC15AC059C058C057C056C0BC +:1000100055C054C053C052C051C050C04FC0B9CADF +:1000200065C8B6C8D4C8FDC82DC944C961C9A1C92D +:10003000A2C95AC8BFC9EDC9F0C954C851C886CAB7 +:1000400004030904160355005300420074006900BC +:100050006E007900530050004900120110010000A9 +:10006000000881179F0C0401000200010902190019 +:1000700001010080640904000001FF000000070581 +:1000800081030800640011241FBECFE5D2E0DEBF6B +:10009000CDBF10E0A0E6B0E0E0E2F6E102C00590DE +:1000A0000D92A636B107D9F710E0A6E6B0E001C080 +:1000B0001D92AD3CB107E1F7C1D7B0CAA1CF1F93E4 +:1000C000162F2091910024FF07C02091920038E85C +:1000D00023272093920003C02AE520939100212F2B +:1000E000DC01E3E9F0E08D91819321501216DCF3FD +:1000F00083E990E0612F4DD11C5F109391001F9117 +:1001000008951F93CF93DF936091A200635067FD22 +:10011000A7C080919F00CCE0D0E0C81BD109CA5590 +:10012000DF4F80919E008D3209F088C0683009F061 +:1001300095C083EC809386008AE5809360001092DE +:1001400066008881807631F0CE01DAD38F3F09F4E2 +:1001500064C06AC09A8110928F008981882331F42B +:10016000109290002FE830E082E052C0853019F400 +:100170009093A3004AC0863091F58B81813041F481 +:100180008AE590E09093A1008093A00082E123C0D3 +:10019000823041F48CE690E09093A1008093A0001F +:1001A00089E119C08330B1F4992341F480E490E0EF +:1001B0009093A1008093A00084E00DC0913051F095 +:1001C000923041F484E490E09093A1008093A000E9 +:1001D00086E101C080E090E49093660025C08830FD +:1001E00069F0893019F49093A5000FC08A3049F066 +:1001F0008B3059F48BE48093920007C025EA30E0FD +:1002000002C02FE830E081E003C02FE830E080E05A +:100210003093A1002093A00007C0988197FD8E81A4 +:1002200090E89093660007C09F81992321F49E81F6 +:10023000981708F4892F8093610010C080916600A0 +:1002400087FF0CC0CE010FD38F3F21F48EE1809346 +:10025000600004C0882311F0109261001092A20087 +:100260008091600084FF5BC0809161008F3F09F442 +:1002700056C0182F893008F018E0811B8093610068 +:100280008091860098E88927809386001123B1F138 +:100290008091660087FF08C087E890E0612FC2D296 +:1002A000182F8930B0F52AC02091A0003091A1000C +:1002B000412F415086FF0EC050E0EA01C857DF4F82 +:1002C000F901A7E8B0E084918D933196AC17BD0792 +:1002D000D1F70CC0D90150E0CA0188579F4FE7E819 +:1002E000F0E06D916193E817F907D9F74F5F5F4F21 +:1002F000420F531F5093A1004093A00087E890E065 +:10030000612F47D01C5F1C3041F08FEF809361005C +:1003100004C08FEF809361001EE11093600084E1C0 +:1003200096B3987131F48150D9F71092A3001092CE +:100330009D0011E0811110E080916700811729F084 +:10034000112309F4F6D410936700DF91CF911F9128 +:100350000895AC9A8BB780628BBF8BE48093920038 +:100360008AE5809391000895A82FB92F80E090E04E +:1003700041E050EA609530E009C02D9182279795C1 +:10038000879510F084279527305EC8F36F5FA8F338 +:100390000895EADF8D939D930895A6E08827992715 +:1003A000AA9569F00197E1F3B399FCCFB39BFECF17 +:1003B00081E09927A6B3019611F0A871D9F70895A5 +:1003C000CF93CFB7CF93C395B39BE9F7B39B0BC044 +:1003D000B39B09C0B39B07C0B39B05C0B39B03C0CD +:1003E000B39B01C0D5C00F92DF93C0919F00DD2762 +:1003F000CA55DF4F012EB39B03C0DF910F90E6CFAC +:100400002F930F931F934F932FEF4F6F06B303FB61 +:1004100020F95F933F9350E03BE065C016B301269F +:10042000502953FDC89556B3012703FB25F92F73B7 +:1004300006B3B1F05027102713FB26F906B222307D +:10044000F0F000C016B3012703FB27F9012650295D +:1004500006B22430E8F54F77206816B30000F6CFD7 +:1004600050274F7D206206B2102F000000C006B357 +:1004700000265029102713FB26F906B2E2CF4F7B46 +:1004800006B3206400C0DACF01265029187106B2E5 +:1004900069F14E7F2160012F16B328C00026502934 +:1004A0004D7F06B22260102F29C0012650294B7FB4 +:1004B00006B22460012F2DC016B301265029477FB4 +:1004C0002860000006B22EC04F7E06B3206130C007 +:1004D000422706B3499300265029102706B24FEF52 +:1004E00013FB20F9297F16B379F2187159F101260F +:1004F000502906B2012703FB21F9237F06B371F2CD +:10050000002650293150D0F006B2102713FB22F9F3 +:10051000277E16B351F201265029012703FB06B2AC +:1005200023F92F7C49F2000006B3102713FB24F9AE +:100530000026502906B22F7939F270CF10E21ABF87 +:10054000002719C03B503195C31BD04010E21ABFA1 +:100550000881033C09F10B34F9F020919D001981C9 +:10056000110F1213EDCF4A81441F093651F10D329C +:1005700011F0013E29F70093A4003F915F914F9144 +:100580001F910F912F91DF910F90CAB7C5FD1BCF1F +:10059000CF91CFBFCF9118952091A400222369F36A +:1005A0001091A200112379F534307AF13093A20032 +:1005B00020939E0010919F003BE0311B30939F00E1 +:1005C00024C00091A2000130F4F40AE54F7049F410 +:1005D0003091600034FD1AC000936000C6E8D0E09E +:1005E00019C03091910034FD11C000939100C2E90F +:1005F000D0E010C0052710E000C021C0052710E0A2 +:10060000C89508BB14C03AE501C032ED032EC0E026 +:10061000D0E032E017B31861C39A08B317BB58E1B2 +:1006200020E84FEF20FF052708BB279517951C3FB3 +:1006300028F700004552B0F720FF0527279508BB93 +:1006400017951C3FB8F629913A9561F7077E1091EE +:10065000A300110F08BBC250D04011F010939D00B1 +:1006600010E21ABF086017B3177E402F477E54E090 +:100670005A95F1F708BB17BB48BB7FCFFC015091DF +:100680006500862F972FDC0194E0619128E030E02F +:1006900040E880E0742F762309F0C09A052E00C050 +:1006A0000000000000000A94D1F7C29A052E00C095 +:1006B0000000000000000A94D1F7880FB1998F5F05 +:1006C000C098C29846952150304021F78D939150A3 +:1006D000E1F6089580917800909179009C012F5F58 +:1006E0003F4F309379002093780020917A0027FFC4 +:1006F00002C0880F991F20937E0080FF03C02860EE +:1007000020937E00292F269520937F00969587952C +:10071000809380008EE790E062E870E0AFDF08959C +:10072000B99A24E030E0E1E09E2F982321F098B3BD +:100730009C7F926002C098B39C7F98BBEE0F109292 +:10074000750007C045E04A95F1F700C09F5F9093A0 +:10075000750090917500692F70E040916300509191 +:1007600064006417750770F3C09A1092750007C093 +:1007700045E04A95F1F700C09F5F90937500909116 +:100780007500692F70E04091630050916400641718 +:10079000750770F32150304039F688B38C7F88BBE1 +:1007A0000895B99A28E030E0E1E09E2F982321F0E7 +:1007B00098B39C7F926002C098B39C7F98BBEE0F69 +:1007C0001092750007C045E04A95F1F700C09F5FA1 +:1007D0009093750090917500692F70E040916300CF +:1007E000509164006417750770F3C09A10927500F9 +:1007F00007C045E04A95F1F700C09F5F90937500F0 +:1008000090917500692F70E04091630050916400F1 +:100810006417750770F32150304039F688B38C7F28 +:1008200088BB0895EF92FF921F93DF93CF930F92AF +:10083000CDB7DEB7182F862F612F792F7B0108C027 +:10084000898348DF90918500F70191937F01898129 +:100850009E2D911B9817A0F30F90CF91DF911F91C0 +:10086000FF90EF900895DF92EF92FF920F931F9306 +:10087000CF93DF93F82EE62E0F2D192F50E6D52EAD +:1008800032C0F80181918F018093810023DF809134 +:100890007E008D2580937E00C0E0D0E01DC08EE7F5 +:1008A00090E062E870E0EADE80918500909181003E +:1008B000891741F490917600891721F09091770083 +:1008C000891789F42091650030E045E0220F331F3D +:1008D0004A95E1F7C20FD31F20917B0030917C0035 +:1008E000C217D307E0F2802F8F198E1550F281E0E6 +:1008F000DF91CF911F910F91FF90EF90DF900895BE +:10090000CF93DF93EC014981442341F481E2898351 +:10091000D093A100C093A00088E008C2413011F438 +:1009200086B307C15A81423011F458BBFEC102960A +:10093000652F677021E030E0062E02C0220F331FC2 +:100940000A94E2F7433029F498B3822F80958923E3 +:1009500093C0443019F488B3822B8EC0453049F4DB +:1009600050936500B99887B3856287BB88B3887D4B +:1009700083C0463049F4B898C098B998C098BA98DE +:10098000C09880E287BB78C0473041F4BE0176DE74 +:10099000D093A100C093A00084E0C8C1483031F4D6 +:1009A000509376008B8180937700BFC18C819D81AD +:1009B0009093790080937800493011F480E211C05F +:1009C0004B3011F480EA0DC08A819B8190937C00AA +:1009D00080937B004A3011F480E403C04C3029F44A +:1009E00080EC80937A008FEFA1C14D3029F487B35A +:1009F0002095282327BB99C14E3021F487B3822B41 +:100A000087BB93C14F3009F5552329F480917D00B0 +:100A100087B9A59A0CC0513031F480917D00816076 +:100A200087B9A29A04C0523011F48FE887B9369A78 +:100A30003699FECF84B1888385B18983D093A10094 +:100A4000C093A00014BA82E071C1403159F4B89A41 +:100A5000B99A8AB5806A8ABD8AB583608ABD83B730 +:100A6000856038C0413121F459BD8C8188BD5DC19C +:100A7000423121F488B3822B88BB57C1433129F41A +:100A800088B32095282328BB50C1443151F486B344 +:100A900090E08223932302C0959587956A95E2F7AB +:100AA00048C0463169F5552319F483B78B7F24C0BC +:100AB000513031F483B78B7F83BF83B7826013C01B +:100AC000523051F483B78B7F83BF83B7826083BF7B +:100AD00083B7816083BF29C1533049F483B78460F1 +:100AE00083BF83B78D7F83BF83B78E7FF3CF5430AF +:100AF00009F01BC183B7846083BF83B78D7FE7CFC5 +:100B00004F3149F49B8180E0850F911D90936400E3 +:100B1000809363000AC1403219F41ABC13BE05C1A8 +:100B2000413221F45093C50081E0B5C0423241F416 +:100B300081E18883D093A100C093A00081E0F6C03A +:100B40004332D9F4379A86B19A81892B86B98B8141 +:100B5000813049F0813020F0823009F0E6C007C0D2 +:100B600010927D00E2C080917D00806803C080917A +:100B70007D00806980937D00D8C0483249F48CEBB9 +:100B800090E09093A1008093A0008091C400CEC01B +:100B9000493211F482E07FC04A3211F483E00BC085 +:100BA0004B3211F484E077C04C3211F488E073C00A +:100BB0004D3239F489E0809368008A818093C500C2 +:100BC000B4C04E3259F48BE0809368008A818093E0 +:100BD000C5008B818093C6008C8134C04F3259F49C +:100BE000513031F4B89AB99ABA9A509374009DC0B2 +:100BF000109274009AC0403349F450936E008B8178 +:100C000080936F008C81809370008FC0413329F4F2 +:100C10005093690010926A0088C0423311F485E055 +:100C20003AC0433321F45093C50086E034C04433C6 +:100C300061F4509368008B818093C5008C81809310 +:100C4000C6008D818093C70070C0453369F450930E +:100C5000C5008B818093C6008C818093C7008D81F5 +:100C60008093C80080E117C0842F90E0807F90704F +:100C7000803D910599F447704093C5008A81809327 +:100C8000C6008B818093C7008C818093C8008D81C2 +:100C90008093C9008EE08093680047C0803E910534 +:100CA00001F58AE080936800842F87708093C500E7 +:100CB00048704093C6001092750080E00BC090E031 +:100CC0000296FE01E80FF91F30818B539F4FFC0104 +:100CD0003083822F9091C500282F2F5F891778F3DA +:100CE00022C0803F910509F587E080936800842F3A +:100CF00088708093C50047704093C60010927500BD +:100D000080E00BC090E00296FE01E80FF91F3081F1 +:100D10008B539F4FFC013083822F9091C600282F68 +:100D20002F5F891778F38093750080E0DF91CF9172 +:100D30000895DF92EF92FF920F931F93CF93DF936B +:100D4000C8E0D0E0FF2460E8E62EDE2CDF0CD1BE48 +:100D500024DB082F192F89E0043318070CF4FD2C2D +:100D6000E694219791F78F2D815081BFCF2DD0E050 +:100D7000219610C012DB8453994097FF03C09095D1 +:100D800081959F4F8017910714F4F1B68C0181B7BC +:100D90008F5F81BF81B790E0C817D9075CF7F1BEBC +:100DA00061B780E090E02CD4DF91CF911F910F913B +:100DB000FF90EF90DF900895882311F0B99801C05B +:100DC000B99ABA981092750007C025E02A95F1F7F4 +:100DD00000C09F5F9093750090917500492F50E07F +:100DE0002091690030916A004217530770F3BA9A54 +:100DF0001092750007C025E02A95F1F700C09F5FAB +:100E00009093750090917500492F50E020916900F2 +:100E100030916A004217530770F38111B99A08950F +:100E2000B998BA981092750007C025E02A95F1F795 +:100E300000C04F5F4093750040917500242F30E053 +:100E40008091690090916A002817390770F386B382 +:100E5000BA9A1092750007C025E02A95F1F700C0F4 +:100E60009F5F9093750090917500492F50E02091FD +:100E7000690030916A004217530770F386958170BC +:100E8000089588B3897F88BBBA98B9981092750085 +:100E900007C085E08A95F1F700C04F5F4093750069 +:100EA00040917500242F30E08091690090916A0094 +:100EB0002817390770F3089587B3897F87BB10928D +:100EC000750007C085E08A95F1F700C04F5F409339 +:100ED000750040917500242F30E080916900909159 +:100EE0006A002817390770F3B99A1092750007C085 +:100EF00085E08A95F1F700C04F5F409375004091FF +:100F00007500242F30E08091690090916A002817C5 +:100F1000390770F3BA9A1092750007C085E08A9578 +:100F2000F1F700C04F5F4093750040917500242F8A +:100F300030E08091690090916A002817390770F3BA +:100F40000895B99ABA9A1092750007C085E08A95FB +:100F5000F1F700C04F5F4093750040917500242F5A +:100F600030E08091690090916A002817390770F38A +:100F7000BA981092750007C085E08A95F1F700C015 +:100F80004F5F4093750040917500242F30E08091B1 +:100F9000690090916A002817390770F3B998109288 +:100FA000750007C085E08A95F1F700C04F5F409358 +:100FB000750040917500242F30E080916900909178 +:100FC0006A002817390770F308950F931F93082FAD +:100FD00018E0802F8078F0DE000F1150D1F720DF6D +:100FE0001F910F910895FF920F931F93F82E08E021 +:100FF00010E0110F15DF182B0150D9F7FF2011F069 +:1010000080E001C081E0D8DE1092750007C095E055 +:101010009A95F1F700C08F5F8093750080917500FD +:10102000482F50E02091690030916A004217530721 +:1010300070F3812F1F910F91FF900895DF92EF922F +:10104000FF920F931F93CF93DF9380E287BB88BB00 +:1010500080E090E0CDD28F3F09F081BFBB9A84E160 +:10106000E2EBF1EF3197F1F700C000008150C1F7DA +:10107000BB9885E090E090936A008093690010929D +:101080006400109263002EE088E190E00FB6F894BF +:10109000A89581BD0FBE21BD10926B0010926C000F +:1010A00010926D0010926E0010926F0010927000FE +:1010B00010927100109268004CD97894BBE1EB2E2D +:1010C000AAE1FA2E00E410E8A8951BD8E091680088 +:1010D000F0E0E131F10508F05AC2E15FFF4F0994F9 +:1010E00060E02AC2DD24D9C1DD2457C1B89AB9987D +:1010F000BA9AC29A1092BC008091C5008093720087 +:10110000109373003FC0C09840E005C0F5E0FA9529 +:10111000F1F700C04F5F242F30E080916300909181 +:1011200064002817390790F3809173009091720042 +:10113000892309F0C09AC2988091BC00880F8093DF +:10114000BC002091BC0086B390E0827090709595B1 +:101150008795280F2093BC0040E005C025E02A9524 +:10116000F1F700C04F5F242F30E080916300909131 +:1011700064002817390790F3C29A8091730086950E +:101180008093730080917300882309F0BCCF1DC049 +:10119000BA9AC2988BEB97E00197F1F700C0000074 +:1011A0009FB7F894C29AE0E2F1E03197F1F700C0FE +:1011B000BA9881E0B29980E08093BC009FBF8BE930 +:1011C00096E00197F1F7BA9AC29A81E0BCC180918A +:1011D000C50080937300BA9A88E02FB7F894C2983C +:1011E0009091730090FF0BC091E29A95F1F7C29A2B +:1011F000E7E0F1E03197F1F700C0000009C0E7EF48 +:10120000F0E03197F1F70000C29AF7E3FA95F1F7B1 +:10121000909173009695909373002FBF8150E9F6DB +:10122000B6C11092BC0028E08091BC0086958093E6 +:10123000BC00BA9A3FB7F894C29881E28A95F1F758 +:10124000C29A97E39A95F1F7BA9886B390E08470C2 +:1012500090709595879595958795809373003FBF7E +:10126000E2EEF0E03197F1F700C0000080917300EA +:10127000882329F08091BC0080688093BC002150B5 +:1012800099F6A3CFBA9A2FB7F894C298F1E2FA95DB +:10129000F1F7C29A87E38A95F1F7BA9886B390E09E +:1012A0008470907095958795959587958093BC00EF +:1012B0002FBF8BCFBA9A8FB7F894C2989091C50080 +:1012C00090FF0BC091E29A95F1F7C29AE7E0F1E046 +:1012D0003197F1F700C0000009C0E7EFF0E0319767 +:1012E000F1F70000C29AF7E3FA95F1F78FBF4FC10B +:1012F000B99AB898BA9AC298E0927200FDB88091F3 +:10130000C5008111C5981092730026C0F0E0E95322 +:10131000FF4F80818FB90EB9809172008DB940E086 +:1013200005C025E02A95F1F700C04F5F242F30E07B +:1013300080916300909164002817390790F3769BA1 +:10134000EBCF80917300E82FF0E09FB1E454FF4FA2 +:1013500090838F5F80937300E09173008091C6004B +:10136000E817A0F28091C5008111C59AE093C400EE +:101370000EC187DD0CC180E090E09EDD8091C5004C +:1013800024DE8093730013C0ED2DF0E0E953FF4F8E +:1013900080811BDE80937300D3948091C500D816A2 +:1013A00098F38091C6008111CCDD80917300809309 +:1013B000BC000BCF8091C500882311F4DD241EC032 +:1013C000DD2404C081E00FDE8883D3942D2D30E02E +:1013D0008091C60090E00197E901C454DF4F2817BF +:1013E000390784F380E0FFDD88830CC0CD2DD0E089 +:1013F00081E0F9DDC454DF4F8883D3948091C60027 +:10140000D816A0F38091C700882309F49AC099DD0B +:1014100098C08091C60084D9BAC04091C600B99ADC +:101420002FC088B38C7F88BB41501092750007C0D5 +:1014300085E08A95F1F700C05F5F50937500509189 +:101440007500252F30E0809163009091640028178B +:10145000390770F3C09A1092750007C095E09A950D +:10146000F1F700C05F5F5093750050917500252F14 +:1014700030E080916300909164002817390770F381 +:10148000442379F688B38C7F88BB81C0ED2DF0E0D2 +:10149000EA53FF4F808185D9D3948091C500D81637 +:1014A000A8F375C0B998C19A88E090E071E01092F5 +:1014B000750007C0F5E0FA95F1F700C0EF5FE09323 +:1014C0007500E09175004E2F50E02091630030913F +:1014D00064004217530770F3C09A1092750007C05A +:1014E00025E02A95F1F700C0EF5FE0937500E091E9 +:1014F00075004E2F50E02091630030916400421738 +:10150000530770F330917300B19B04C0372B3093B5 +:10151000730005C0272F2095232320937300C098C4 +:10152000770F019721F6C198E62FF0E080917300C4 +:10153000E454FF4F80836F5F8091C600681708F402 +:10154000B1CF8091C6008093C40021C080E0E8D86C +:101550008091C60026D98091C70023D98091C80008 +:1015600020D9109273000DC080E0DAD880E019D93C +:1015700080E017D980E015D9809173008F5F809348 +:1015800073008091C50090917300981768F31092D2 +:10159000680080917400882309F496CD80917100D1 +:1015A000882369F490916E0090936B0090916F0086 +:1015B00090936C009091700090936D0015C0909185 +:1015C0006B00981710F4C09801C0C09A90916C00FD +:1015D000981710F4C19801C0C19A90916D009817A6 +:1015E00010F4C29801C0C29A8F5F809371006CCDD5 +:1015F000E199FECF9FBB8EBBE09A99278DB30895EA +:10160000262FE199FECF1CBA9FBB8EBB2DBB0FB618 +:10161000F894E29AE19A0FBE01960895F894FFCFEC +:061620005AFF110A002828 +:00000001FF diff --git a/commandline/main.c b/commandline/main.c deleted file mode 100644 index 725e2ea..0000000 --- a/commandline/main.c +++ /dev/null @@ -1,265 +0,0 @@ -/* Name: main.c - * Project: AVR bootloader HID - * Author: Christian Starkjohann - * Creation Date: 2007-03-19 - * Tabsize: 4 - * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: main.c 787 2010-05-30 20:54:25Z cs $ - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include "usbcalls.h" - -#define IDENT_VENDOR_NUM 0x16c0 -#define IDENT_VENDOR_STRING "creativepony.com" -#define IDENT_PRODUCT_NUM 1503 -#define IDENT_PRODUCT_STRING "uBoot" - -// extra delays before more USB requests for tiny85 compatibility while chip frozen -// this number could be lower than 16000 - minimum will be greater than 9000 (erase and write) -#define TINY85_POSTWRITE_DELAY 16000 - -/* ------------------------------------------------------------------------- */ - -static char dataBuffer[65536 + 256]; /* buffer for file data */ -static int startAddress, endAddress; -static char leaveBootLoader = 0; - -/* ------------------------------------------------------------------------- */ - -static int parseUntilColon(FILE *fp) -{ -int c; - - do{ - c = getc(fp); - }while(c != ':' && c != EOF); - return c; -} - -static int parseHex(FILE *fp, int numDigits) -{ -int i; -char temp[9]; - - for(i = 0; i < numDigits; i++) - temp[i] = getc(fp); - temp[i] = 0; - return strtol(temp, NULL, 16); -} - -/* ------------------------------------------------------------------------- */ - -static int parseIntelHex(char *hexfile, char buffer[65536 + 256], int *startAddr, int *endAddr) -{ -int address, base, d, segment, i, lineLen, sum; -FILE *input; - - input = fopen(hexfile, "r"); - if(input == NULL){ - fprintf(stderr, "error opening %s: %s\n", hexfile, strerror(errno)); - return 1; - } - while(parseUntilColon(input) == ':'){ - sum = 0; - sum += lineLen = parseHex(input, 2); - base = address = parseHex(input, 4); - sum += address >> 8; - sum += address; - sum += segment = parseHex(input, 2); /* segment value? */ - if(segment != 0) /* ignore lines where this byte is not 0 */ - continue; - for(i = 0; i < lineLen ; i++){ - d = parseHex(input, 2); - buffer[address++] = d; - sum += d; - } - sum += parseHex(input, 2); - if((sum & 0xff) != 0){ - fprintf(stderr, "Warning: Checksum error between address 0x%x and 0x%x\n", base, address); - } - if(*startAddr > base) - *startAddr = base; - if(*endAddr < address) - *endAddr = address; - } - fclose(input); - return 0; -} - -/* ------------------------------------------------------------------------- */ - -char *usbErrorMessage(int errCode) -{ -static char buffer[80]; - - switch(errCode){ - case USB_ERROR_ACCESS: return "Access to device denied"; - case USB_ERROR_NOTFOUND: return "The specified device was not found"; - case USB_ERROR_BUSY: return "The device is used by another application"; - case USB_ERROR_IO: return "Communication error with device"; - default: - sprintf(buffer, "Unknown USB error %d", errCode); - return buffer; - } - return NULL; /* not reached */ -} - -static int getUsbInt(char *buffer, int numBytes) -{ -int shift = 0, value = 0, i; - - for(i = 0; i < numBytes; i++){ - value |= ((int)*buffer & 0xff) << shift; - shift += 8; - buffer++; - } - return value; -} - -static void setUsbInt(char *buffer, int value, int numBytes) -{ -int i; - - for(i = 0; i < numBytes; i++){ - *buffer++ = value; - value >>= 8; - } -} - -/* ------------------------------------------------------------------------- */ - -typedef struct deviceInfo{ - char reportId; - char pageSize[2]; // TODO: change this to one byte? - char flashSize[4]; // TODO: change this to two bytes? -}deviceInfo_t; - -typedef struct deviceData{ - char reportId; - char address[3]; - char data[64]; -}deviceData_t; - -static int uploadData(char *dataBuffer, int startAddr, int endAddr) -{ -usbDevice_t *dev = NULL; -int err = 0, len, pageSize, deviceSize; -union{ - char bytes[1]; - deviceInfo_t info; - deviceData_t data; -} buffer; - - if((err = usbOpenDevice(&dev, IDENT_VENDOR_NUM, IDENT_VENDOR_STRING, IDENT_PRODUCT_NUM, IDENT_PRODUCT_STRING, 1)) != 0){ - fprintf(stderr, "Error opening HIDBoot device: %s\n", usbErrorMessage(err)); - goto errorOccurred; - } - len = sizeof(buffer); - if(endAddr > startAddr){ // we need to upload data - if((err = usbGetReport(dev, USB_HID_REPORT_TYPE_FEATURE, 1, buffer.bytes, &len)) != 0){ - fprintf(stderr, "Error reading page size: %s\n", usbErrorMessage(err)); - goto errorOccurred; - } - if(len < sizeof(buffer.info)){ - fprintf(stderr, "Not enough bytes in device info report (%d instead of %d)\n", len, (int)sizeof(buffer.info)); - err = -1; - goto errorOccurred; - } - pageSize = getUsbInt(buffer.info.pageSize, 2); - deviceSize = getUsbInt(buffer.info.flashSize, 4); - printf("Page size = %d (0x%x)\n", pageSize, pageSize); - printf("Device size = %d (0x%x)\n", deviceSize, deviceSize); - if(endAddr > deviceSize){ - fprintf(stderr, "Data (%d bytes) exceeds remaining flash size!\n", endAddr); - err = -1; - goto errorOccurred; - } - - startAddr -= startAddr % pageSize; // round down to start of page - endAddr = (endAddr - (endAddr % pageSize)) + pageSize; // round up to next whole page - printf("Uploading %d (0x%x) bytes starting at %d (0x%x)\n", endAddr - startAddr, endAddr - startAddr, startAddr, startAddr); - while(startAddr < endAddr){ - buffer.data.reportId = 2; - memcpy(buffer.data.data, dataBuffer + startAddr, pageSize); - setUsbInt(buffer.data.address, startAddr, 3); - printf("\r0x%05x ... 0x%05x", startAddr, startAddr + pageSize); - fflush(stdout); - if((err = usbSetReport(dev, USB_HID_REPORT_TYPE_FEATURE, buffer.bytes, sizeof(buffer.data))) != 0){ - fprintf(stderr, "Error uploading data block: %s\n", usbErrorMessage(err)); - goto errorOccurred; - } - startAddr += pageSize; - - // special tiny85 chillout session - chip freezes during write, so we - // need to make sure we don't send it any requests while it's busy - // erasing and writing - usleep(TINY85_POSTWRITE_DELAY); // regular page write duration - } - printf("\n"); - } - if(leaveBootLoader){ - /* and now leave boot loader: */ - buffer.info.reportId = 1; - usbSetReport(dev, USB_HID_REPORT_TYPE_FEATURE, buffer.bytes, sizeof(buffer.info)); - /* Ignore errors here. If the device reboots before we poll the response, - * this request fails. - */ - } -errorOccurred: - if(dev != NULL) - usbCloseDevice(dev); - return err; -} - -/* ------------------------------------------------------------------------- */ - -static void printUsage(char *pname) -{ - fprintf(stderr, "usage: %s [-r] [<intel-hexfile>]\n", pname); -} - -int main(int argc, char **argv) -{ -char *file = NULL; - - if(argc < 2){ - printUsage(argv[0]); - return 1; - } - if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0){ - printUsage(argv[0]); - return 1; - } - if(strcmp(argv[1], "-r") == 0){ - leaveBootLoader = 1; - if(argc >= 3){ - file = argv[2]; - } - }else{ - file = argv[1]; - } - startAddress = sizeof(dataBuffer); - endAddress = 0; - if(file != NULL){ // an upload file was given, load the data - memset(dataBuffer, -1, sizeof(dataBuffer)); - if(parseIntelHex(file, dataBuffer, &startAddress, &endAddress)) - return 1; - if(startAddress >= endAddress){ - fprintf(stderr, "No data in input file, exiting.\n"); - return 0; - } - } - // if no file was given, endAddress is less than startAddress and no data is uploaded - if(uploadData(dataBuffer, startAddress, endAddress)) - return 1; - return 0; -} - -/* ------------------------------------------------------------------------- */ - - diff --git a/commandline/main.o b/commandline/main.o Binary files differdeleted file mode 100644 index ff30f64..0000000 --- a/commandline/main.o +++ /dev/null diff --git a/commandline/usb-libusb.c b/commandline/usb-libusb.c deleted file mode 100644 index 886da3b..0000000 --- a/commandline/usb-libusb.c +++ /dev/null @@ -1,203 +0,0 @@ -/* Name: usb-libusb.c - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: usb-libusb.c 323 2007-03-29 17:25:03Z cs $ - */ - -/* -General Description: -This module implements USB HID report receiving/sending based on libusb. It -does not read and parse the report descriptor. You must therefore be careful -to pass correctly formatted data blocks of correct size. In order to be -compatible with the Windows implementation, we add a zero report ID for all -reports which don't have an ID. Since we don't parse the descriptor, the caller -must tell us whether report IDs are used or not in usbOpenDevice(). - -The implementation of dummy report IDs is a hack. Whether they are used is -stored in a global variable, not in the device structure (just laziness, don't -want to allocate memory for that). If you open more than one device and the -devices differ in report ID usage, you must change the code. -*/ - -#include <stdio.h> -#include <string.h> -#include <usb.h> - -#define usbDevice usb_dev_handle /* use libusb's device structure */ -#include "usbcalls.h" - -/* ------------------------------------------------------------------------- */ - -#define USBRQ_HID_GET_REPORT 0x01 -#define USBRQ_HID_SET_REPORT 0x09 - -static int usesReportIDs; - -/* ------------------------------------------------------------------------- */ - -static int usbGetStringAscii(usb_dev_handle *dev, int index, int langid, char *buf, int buflen) -{ -char buffer[256]; -int rval, i; - - if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer, sizeof(buffer), 1000)) < 0) - return rval; - if(buffer[1] != USB_DT_STRING) - return 0; - if((unsigned char)buffer[0] < rval) - rval = (unsigned char)buffer[0]; - rval /= 2; - /* lossy conversion to ISO Latin1 */ - for(i=1;i<rval;i++){ - if(i > buflen) /* destination buffer overflow */ - break; - buf[i-1] = buffer[2 * i]; - if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ - buf[i-1] = '?'; - } - buf[i-1] = 0; - return i-1; -} - -int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs) -{ -struct usb_bus *bus; -struct usb_device *dev; -usb_dev_handle *handle = NULL; -int errorCode = USB_ERROR_NOTFOUND; -static int didUsbInit = 0; - - if(!didUsbInit){ - usb_init(); - didUsbInit = 1; - } - usb_find_busses(); - usb_find_devices(); - for(bus=usb_get_busses(); bus; bus=bus->next){ - for(dev=bus->devices; dev; dev=dev->next){ - if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ - char string[256]; - int len; - handle = usb_open(dev); /* we need to open the device in order to query strings */ - if(!handle){ - errorCode = USB_ERROR_ACCESS; - fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); - continue; - } - if(vendorName == NULL && productName == NULL){ /* name does not matter */ - break; - } - /* now check whether the names match: */ - len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string)); - if(len < 0){ - errorCode = USB_ERROR_IO; - fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror()); - }else{ - errorCode = USB_ERROR_NOTFOUND; - /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ - if(strcmp(string, vendorName) == 0){ - len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string)); - if(len < 0){ - errorCode = USB_ERROR_IO; - fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror()); - }else{ - errorCode = USB_ERROR_NOTFOUND; - /* fprintf(stderr, "seen product ->%s<-\n", string); */ - if(strcmp(string, productName) == 0) - break; - } - } - } - usb_close(handle); - handle = NULL; - } - } - if(handle) - break; - } - if(handle != NULL){ - int rval, retries = 3; - if(usb_set_configuration(handle, 1)){ - fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); - } - /* now try to claim the interface and detach the kernel HID driver on - * linux and other operating systems which support the call. - */ - while((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0){ -#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP - if(usb_detach_kernel_driver_np(handle, 0) < 0){ - fprintf(stderr, "Warning: could not detach kernel HID driver: %s\n", usb_strerror()); - } -#endif - } -#ifndef __APPLE__ - if(rval != 0) - fprintf(stderr, "Warning: could not claim interface\n"); -#endif -/* Continue anyway, even if we could not claim the interface. Control transfers - * should still work. - */ - errorCode = 0; - *device = handle; - usesReportIDs = _usesReportIDs; - } - return errorCode; -} - -/* ------------------------------------------------------------------------- */ - -void usbCloseDevice(usbDevice_t *device) -{ - if(device != NULL) - usb_close(device); -} - -/* ------------------------------------------------------------------------- */ - -int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) -{ -int bytesSent; - - if(!usesReportIDs){ - buffer++; /* skip dummy report ID */ - len--; - } - bytesSent = usb_control_msg(device, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_OUT, USBRQ_HID_SET_REPORT, reportType << 8 | buffer[0], 0, buffer, len, 5000); - if(bytesSent != len){ - if(bytesSent < 0) - fprintf(stderr, "Error sending message: %s\n", usb_strerror()); - return USB_ERROR_IO; - } - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) -{ -int bytesReceived, maxLen = *len; - - if(!usesReportIDs){ - buffer++; /* make room for dummy report ID */ - maxLen--; - } - bytesReceived = usb_control_msg(device, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, reportType << 8 | reportNumber, 0, buffer, maxLen, 5000); - if(bytesReceived < 0){ - fprintf(stderr, "Error sending message: %s\n", usb_strerror()); - return USB_ERROR_IO; - } - *len = bytesReceived; - if(!usesReportIDs){ - buffer[-1] = reportNumber; /* add dummy report ID */ - *len++; - } - return 0; -} - -/* ------------------------------------------------------------------------- */ - - diff --git a/commandline/usb-windows.c b/commandline/usb-windows.c deleted file mode 100755 index fac3b02..0000000 --- a/commandline/usb-windows.c +++ /dev/null @@ -1,180 +0,0 @@ -/* Name: usb-windows.c - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: usb-windows.c 281 2007-03-20 13:22:10Z cs $ - */ - -/* -General Description: -This module implements USB HID report receiving and sending with native -Windows API functions. If you compile with MinGW, no software from Microsoft -(no DDK) is needed. We supply the missing types and function prototypes in -hidsdi.h. -*/ - -#include <stdio.h> -#include <windows.h> -#include <setupapi.h> -#include "hidsdi.h" -#include <ddk/hidpi.h> - -#include "usbcalls.h" - -#ifdef DEBUG -#define DEBUG_PRINT(arg) printf arg -#else -#define DEBUG_PRINT(arg) -#endif - -/* ------------------------------------------------------------------------ */ - -static void convertUniToAscii(char *buffer) -{ -unsigned short *uni = (void *)buffer; -char *ascii = buffer; - - while(*uni != 0){ - if(*uni >= 256){ - *ascii++ = '?'; - }else{ - *ascii++ = *uni++; - } - } - *ascii++ = 0; -} - -int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) -{ -GUID hidGuid; /* GUID for HID driver */ -HDEVINFO deviceInfoList; -SP_DEVICE_INTERFACE_DATA deviceInfo; -SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; -DWORD size; -int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ -int errorCode = USB_ERROR_NOTFOUND; -HANDLE handle = INVALID_HANDLE_VALUE; -HIDD_ATTRIBUTES deviceAttributes; - - HidD_GetHidGuid(&hidGuid); - deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); - deviceInfo.cbSize = sizeof(deviceInfo); - for(i=0;;i++){ - if(handle != INVALID_HANDLE_VALUE){ - CloseHandle(handle); - handle = INVALID_HANDLE_VALUE; - } - if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) - break; /* no more entries */ - /* first do a dummy call just to determine the actual size required */ - SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); - if(deviceDetails != NULL) - free(deviceDetails); - deviceDetails = malloc(size); - deviceDetails->cbSize = sizeof(*deviceDetails); - /* this call is for real: */ - SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); - DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); - /* attempt opening for R/W -- we don't care about devices which can't be accessed */ - handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); - if(handle == INVALID_HANDLE_VALUE){ - DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); - /* errorCode = USB_ERROR_ACCESS; opening will always fail for mouse -- ignore */ - continue; - } - deviceAttributes.Size = sizeof(deviceAttributes); - HidD_GetAttributes(handle, &deviceAttributes); - DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); - if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) - continue; /* ignore this device */ - errorCode = USB_ERROR_NOTFOUND; - if(vendorName != NULL && productName != NULL){ - char buffer[512]; - if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ - DEBUG_PRINT(("error obtaining vendor name\n")); - errorCode = USB_ERROR_IO; - continue; - } - convertUniToAscii(buffer); - DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); - if(strcmp(vendorName, buffer) != 0) - continue; - if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ - DEBUG_PRINT(("error obtaining product name\n")); - errorCode = USB_ERROR_IO; - continue; - } - convertUniToAscii(buffer); - DEBUG_PRINT(("productName = \"%s\"\n", buffer)); - if(strcmp(productName, buffer) != 0) - continue; - } - break; /* we have found the device we are looking for! */ - } - SetupDiDestroyDeviceInfoList(deviceInfoList); - if(deviceDetails != NULL) - free(deviceDetails); - if(handle != INVALID_HANDLE_VALUE){ - *device = (usbDevice_t *)handle; - errorCode = 0; - } - return errorCode; -} - -/* ------------------------------------------------------------------------ */ - -void usbCloseDevice(usbDevice_t *device) -{ - CloseHandle((HANDLE)device); -} - -/* ------------------------------------------------------------------------ */ - -int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) -{ -HANDLE handle = (HANDLE)device; -BOOLEAN rval = 0; -DWORD bytesWritten; - - switch(reportType){ - case USB_HID_REPORT_TYPE_INPUT: - break; - case USB_HID_REPORT_TYPE_OUTPUT: - rval = WriteFile(handle, buffer, len, &bytesWritten, NULL); - break; - case USB_HID_REPORT_TYPE_FEATURE: - rval = HidD_SetFeature(handle, buffer, len); - break; - } - return rval == 0 ? USB_ERROR_IO : 0; -} - -/* ------------------------------------------------------------------------ */ - -int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) -{ -HANDLE handle = (HANDLE)device; -BOOLEAN rval = 0; -DWORD bytesRead; - - switch(reportType){ - case USB_HID_REPORT_TYPE_INPUT: - buffer[0] = reportNumber; - rval = ReadFile(handle, buffer, *len, &bytesRead, NULL); - if(rval) - *len = bytesRead; - break; - case USB_HID_REPORT_TYPE_OUTPUT: - break; - case USB_HID_REPORT_TYPE_FEATURE: - buffer[0] = reportNumber; - rval = HidD_GetFeature(handle, buffer, *len); - break; - } - return rval == 0 ? USB_ERROR_IO : 0; -} - -/* ------------------------------------------------------------------------ */ diff --git a/commandline/usbcalls.c b/commandline/usbcalls.c deleted file mode 100644 index f8a1857..0000000 --- a/commandline/usbcalls.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Name: usbcalls.c - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: usbcalls.c 281 2007-03-20 13:22:10Z cs $ - */ - -/* This file includes the appropriate implementation based on platform - * specific defines. - */ - -#if defined(WIN32) -# include "usb-windows.c" -#else -/* e.g. defined(__APPLE__) */ -# include "usb-libusb.c" -#endif diff --git a/commandline/usbcalls.h b/commandline/usbcalls.h deleted file mode 100644 index 3f329b2..0000000 --- a/commandline/usbcalls.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Name: usbcalls.h - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: usbcalls.h 281 2007-03-20 13:22:10Z cs $ - */ - -#ifndef __usbcalls_h_INCLUDED__ -#define __usbcalls_h_INCLUDED__ - -/* -General Description: -This module implements an abstraction layer for access to USB/HID communication -functions. An implementation based on libusb (portable to Linux, FreeBSD and -Mac OS X) and a native implementation for Windows are provided. -*/ - -/* ------------------------------------------------------------------------ */ - -#define USB_HID_REPORT_TYPE_INPUT 1 -#define USB_HID_REPORT_TYPE_OUTPUT 2 -#define USB_HID_REPORT_TYPE_FEATURE 3 -/* Numeric constants for 'reportType' parameters */ - -#define USB_ERROR_NONE 0 -#define USB_ERROR_ACCESS 1 -#define USB_ERROR_NOTFOUND 2 -#define USB_ERROR_BUSY 16 -#define USB_ERROR_IO 5 -/* These are the error codes which can be returned by functions of this - * module. - */ - -/* ------------------------------------------------------------------------ */ - -typedef struct usbDevice usbDevice_t; -/* This type represents a USB device internally. Only opaque pointers to this - * type are available outside the module implementation. - */ - -/* ------------------------------------------------------------------------ */ - -int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs); -/* This function opens a USB device. 'vendor' and 'product' are the numeric - * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and - * 'productName' are both not NULL, only devices with matching manufacturer- - * and product name strings are accepted. If the device uses report IDs, - * 'usesReportIDs' must be set to a non-zero value. - * Returns: If a matching device has been found, USB_ERROR_NONE is returned and - * '*device' is set to an opaque pointer representing the device. The device - * must be closed with usbCloseDevice(). If the device has not been found or - * opening failed, an error code is returned. - */ -void usbCloseDevice(usbDevice_t *device); -/* Every device opened with usbOpenDevice() must be closed with this function. - */ -int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len); -/* This function sends a report to the device. 'reportType' specifies the type - * of report (see USB_HID_REPORT_TYPE* constants). The report ID must be in the - * first byte of buffer and the length 'len' of the report is specified - * including this report ID. If no report IDs are used, buffer[0] must be set - * to 0 (dummy report ID). - * Returns: 0 on success, an error code otherwise. - */ -int usbGetReport(usbDevice_t *device, int reportType, int reportID, char *buffer, int *len); -/* This function obtains a report from the device. 'reportType' specifies the - * type of report (see USB_HID_REPORT_TYPE* constants). The requested report ID - * is passed in 'reportID'. The caller must pass a buffer of the size of the - * expected report in 'buffer' and initialize the variable in '*len' to the - * total size of this buffer. Upon successful return, the report (prefixed with - * a report ID) is in 'buffer' and the actual length of the report is returned - * in '*len'. - * Returns: 0 on success, an error code otherwise. - */ - -/* ------------------------------------------------------------------------ */ - -#endif /* __usbcalls_h_INCLUDED__ */ diff --git a/commandline/usbcalls.o b/commandline/usbcalls.o Binary files differdeleted file mode 100644 index 4a43f0f..0000000 --- a/commandline/usbcalls.o +++ /dev/null |