├── .gitignore ├── CHANGELOG.md ├── Makefile ├── README.md ├── getcaldata ├── DIST │ └── getcaldata.c.DIST ├── MEMO.txt ├── Makefile └── getcaldata.c ├── tdsNvramFloppyTool-extra ├── info-extra.txt └── tdsNvramEepromFloppyDumper │ ├── dumpall.app │ └── startup.bat ├── tdsNvramFloppyTool ├── DIST │ └── tdsNvramFloppyTools_v5.zip ├── README.txt ├── TDSNvrCV_2_1.jar ├── info.txt ├── tdsAcqEEPROMFloppyDumper │ ├── acqedump.app │ └── startup.bat ├── tdsAcqEEPROMFloppyWriter │ ├── acqewrte.app │ └── startup.bat ├── tdsAcqEEPROMMinimalFloppyDumper │ └── startup.bat ├── tdsAcqEEPROMMinimalFloppyWriter │ └── startup.bat ├── tdsNvramFloppyDumper │ ├── nvdump.app │ └── startup.bat ├── tdsNvramFloppyWriter │ ├── nvwrite.app │ └── startup.bat ├── tdsNvramMinimalFloppyDumper │ └── startup.bat └── tdsNvramMinimalFloppyWriter │ └── startup.bat ├── tekfwtool ├── .dir-locals.el ├── DIST │ ├── README.txt │ ├── tekfwtool.github │ │ ├── Makefile │ │ ├── dosdefs.h │ │ ├── doslib │ │ │ ├── DECL.H │ │ │ ├── MCIB.LIB │ │ │ ├── getopt.c │ │ │ ├── getopt.h │ │ │ ├── notes.txt │ │ │ ├── stdint.h │ │ │ └── tgtdummy.h │ │ ├── gen-procs.sh │ │ ├── gpib-32.obj │ │ ├── ni488.h │ │ ├── target.c │ │ ├── target.ld │ │ ├── tekfwtool.c │ │ ├── tekfwtool.h │ │ └── tfdos │ └── tekfwtool.stackframe.org │ │ ├── Makefile │ │ ├── gen-procs.sh │ │ ├── gpib-32.obj │ │ ├── index.html │ │ ├── ni488.h │ │ ├── reg │ │ ├── target-procs.h │ │ ├── target.bin │ │ ├── target.c │ │ ├── target.elf │ │ ├── target.ld │ │ ├── tekfwtool.c │ │ ├── tekfwtool.exe │ │ ├── tekfwtool.h │ │ └── tmp ├── Makefile ├── Makefile.target-bin ├── gen-procs.sh ├── target-procs.h ├── target.bin ├── target.c ├── target.ld ├── tekfwtool.c └── tekfwtool.h └── tektool ├── .dir-locals.el ├── DIST ├── Nvrams.zip └── tektool1.c.DIST ├── Makefile └── tektool.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.pyc 4 | *.class 5 | *.o 6 | *.so 7 | getcaldata/getcaldata 8 | tekfwtool/tekfwtool 9 | tekfwtool/target.elf 10 | tektool/tektool 11 | 12 | # Backup files # 13 | ################ 14 | *~ 15 | 16 | # Temporary stuff # 17 | *.tmp 18 | 19 | # OS generated files # 20 | ###################### 21 | .DS_Store 22 | .DS_Store? 23 | ._* 24 | .Spotlight-V100 25 | *.dSYM 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## HEAD - *Changes still not in a named release* 4 | - none yet 5 | 6 | --- 7 | 8 | ## v0.1.0 (2020-01-26) 9 | 10 | #### Enhancements: 11 | - Enabled as many compiler warnings as possible 12 | - General cleanup of code 13 | - Added printout of version string from git and build time in tektool, tekfwtool and getcaldata 14 | - Support for building on MacOS with NI 488.2 driver 15 | - tektool - added better support for compiling on windows 16 | - updated tdsNvramFloppyTool to v5, with the possibility to write to the EEPROMs. 17 | - moved the extra tdsNvramFloppyTool script to a new directory called tdsNvramFloppyTool-extra 18 | 19 | #### Bug Fixes: 20 | - tektool - flash is now reset to read mode after identify 21 | - tektool - does not send password before writing - not needed in bootloader mode, and may be a problem with some firmware versions 22 | - tekfwtool - erasing 28F016SA flash now works (target.c/target.bin) 23 | - tekfwtool - flashing used bad indexing, fixed now (target.c/target.bin) 24 | 25 | --- 26 | 27 | ## v0.0.0 (2020-01-01) 28 | 29 | Initial release 30 | - Support for building on Linux with linux-gpib, ARM (raspbian) 31 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Register all subdirectories in the project's root directory. 2 | SUBDIRS := getcaldata tekfwtool tektool 3 | 4 | default: all 5 | 6 | # Top-level phony targets. 7 | all clean: $(SUBDIRS) FORCE 8 | 9 | # Recurse `make` into each subdirectory. 10 | $(SUBDIRS): FORCE 11 | $(MAKE) -C $@ $(MAKECMDGOALS) 12 | 13 | # A target without prerequisites and a recipe, and there is no file named `FORCE`. 14 | # `make` will always run this and any other target that depends on it. 15 | FORCE: 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tektronix TDS 5xx/6xx/7xx/8xx tools on Linux, ARM, and MacOS 2 | 3 | These are tools for backing up and restoring NVRAM, Flash and EEPROMs 4 | in certain Tektronix oscilloscopes such as the TDS 5xx/6xx/7xx series, 5 | with minor modifications so that they can be used with Linux, and 6 | optionally ARM CPUs e.g. a Raspberry Pi, and MacOS with NI drivers. 7 | 8 | (What is special with ARM is that C compilers for efficiency often 9 | defaults to char being unsigned, which some programs do not expect.) 10 | 11 | ### Changelog 12 | 13 | Release notes / change history is in [CHANGELOG.md](CHANGELOG.md) 14 | 15 | ### Prerequisites 16 | 17 | You need some system to run it on, e.g.: 18 | * Linux based: 19 | * A Linux system 20 | * linux-gpib - [https://linux-gpib.sourceforge.io](https://linux-gpib.sourceforge.io) 21 | * A GPIB adapter 22 | * MacOS based: 23 | * A MacOS system 24 | * A 488.2 library, e.g. National Instruments 488.2 drivers 25 | * A GPIB adapter 26 | 27 | The programs have been tested for reading (making backups) with these setups: 28 | * Linux based: 29 | * Raspberry Pi (3B+) 30 | * Raspbian (version 9.11) 31 | * linux-gpib (version 4.3.0) 32 | * USB to GPIB adapter, Agilent 82357B (from Ebay) 33 | * MacOS based: 34 | * Mac 35 | * National Instruments 488.2 drivers 36 | * USB to GPIB adapter, National Instruments 37 | 38 | These programs will likely work with just minor modifications on many 39 | other POSIX compliant systems with an NI-488.2 compliant GPIB API, but 40 | this has not been tested. 41 | 42 | #### linux-gpib 43 | 44 | linux-gpib can be a little tricky to install and get working. If the 45 | linker has problems finding the gpib libraries when you run the 46 | programs, try running `sudo ldconfig`. The GPIB adapter may need 47 | firmware for booting, check the linux-gpib documentation. The 48 | /dev/gpibN device files may be accessible only by root - if so, try 49 | e.g. `sudo chgrp dialout /dev/gpib*`. 50 | 51 | To test the linux-gpib installaton and GPIB connectivity, use ibterm, 52 | for example: 53 | ``` 54 | /usr/local/bin/ibterm -d N 55 | ``` 56 | where N is the GPIB address of the instrument. 57 | 58 | At the ibterm prompt, type `*IDN?` and check that you get a reasonable 59 | identification response from the instrument: 60 | ``` 61 | ibterm>*IDN? 62 | TEKTRONIX,TDS 694C,0,CF:91.1CT FV:v6.4e 63 | ``` 64 | 65 | ### Installing 66 | 67 | To get and compile the programs, clone the git repository, go to the tektools directory and run `make`: 68 | ``` 69 | git clone https://github.com/ragges/tektools.git 70 | cd tektools 71 | make 72 | ``` 73 | 74 | ## Running the programs 75 | 76 | ### tektool, tekfwtool 77 | 78 | These programs read and write the NVRAMs containing user settings, 79 | stored waveforms, and on older instruments calibration data, and the 80 | flash that contains the firmware. 81 | 82 | tekfwtool downloads a piece of 68k code to be able to write firmware 83 | to the flash faster, tektool does not. 84 | 85 | * tektool supports flash type 28F016SA (there is experimental support 86 | for 28F160S5 that can be enabled with a `#define` in the program) 87 | * tektfwool supports flash types 28F016SA and 28F160S5 88 | 89 | The scope must be started with the NVRAM protection switch set to 90 | unprotected mode (the rocker switch behind the small holes on the 91 | right side of the scope). The scope starts in bootloader mode and 92 | appears almost dead, it does not show anything on the screen and all 93 | LEDs on the front stays lit, but it responds on GPIB, typically on 94 | address 29. 95 | 96 | tekfwtool looks for the 68k code in the file "target.bin" in the 97 | current directory. It must either be run when standing in the 98 | directory of the program, or there must be a copy of that file, or a 99 | link to it, in the current working directory. 100 | 101 | You could for example dump NVRAM and firmware from the scope using: 102 | ``` 103 | # NOTE - Addresses and lengths may have to be adjusted depending 104 | # on model 105 | ./tektool -r NVRAM_all.bin -b 0x04000000 -l 0x100000 106 | ./tektool -r firmware.bin -b 0x01000000 -l 0x400000 107 | ``` 108 | 109 | ### getcaldata 110 | 111 | getcaldata reads and writes the calibration data in the EEPROMs on the 112 | acquisition board on newer models, typically models ending with B or 113 | higher. 114 | 115 | The EEPROM chips may be called e.g. U1052 and U1055, or U1055 and 116 | U1056. This program calls them U1052 and U1055 and ignores what is 117 | printed on the board. 118 | 119 | The scope should be booted normally. 120 | 121 | The program assumes the GPIB address of the scope is 1, this can 122 | be changed in the program. 123 | 124 | Just run it and it will dump the EEPROMs. 125 | 126 | You may want to double check that the addresses and sizes of the 127 | NVRAMs are correct for your model. 128 | 129 | ### tdsNvramFloppyTool and TDSNvrCV_2_1 130 | 131 | **tdsNvramFloppyTool** is a set of scripts that are to be put on a 132 | floppy disk that will let the scope itself read and write NVRAM and 133 | EEPROM data to/from floppy disks - no GPIB is needed. 134 | 135 | In tdsNvramFloppyTool-extra there is also an extra version, 136 | tdsNvramEepromFloppyDumper, that dumps both the NVRAM and the EEPROMs 137 | to the floppy in one sweep. 138 | 139 | To use the tdsNvramFloppyTool, format a floppy (preferably in the 140 | scope), copy the file(s) that do what you want to the floppy, and boot 141 | the scope with the floppy inserted. 142 | 143 | **TDSNvrCV_2_1** is a tool for checksumming NVRAM and EEPROM dumps, 144 | written in Java. 145 | 146 | Note that for checking EEPROM dumps taken with the getcaldata tool, 147 | you need to concatenate the two 256 byte files into one 512 byte 148 | file, and run the check on the new combined file: 149 | ``` 150 | cat U1052.bin U1055.bin > EEPROM_combined.bin 151 | java -cp TDSNvrCV_2_1.zip TDSNvramChecksumVerifier EEPROM_combined.bin 152 | ``` 153 | 154 | For more information about using these scripts and the checksumming 155 | tool, see the 156 | [thread on eevblog](https://www.eevblog.com/forum/testgear/tektronix-tds500600700-nvram-floppy-dump-tool/) 157 | (or the file README.txt), and the info.txt and info-2.txt files in the 158 | directory. 159 | 160 | There is nothing OS specific about these, but they are very nice 161 | tools, so they are included in this kit anyway. 162 | 163 | ## Hint 164 | 165 | You can use tektool, tekfwtool and getcaldata to get the data using 166 | GPIB, and tdsNvramFloppyTool to get it using a floppy, and compare the 167 | results to check that you have likely got correct and error free 168 | data. Note that the first few bytes of one of the the NVRAM chips is 169 | the clock, so it constantly changes. 170 | 171 | You can also use the NVRAM and EEPROM checksumming tool TDSNvrCV_2_1 172 | to check your dumps. 173 | 174 | If you use the floppy method first, and then immediately flip the 175 | NVRAM protection switch and reboot it for GPIB dumping using 176 | tektool/tekfwtool, only the first few bytes of the NVRAM, the date and 177 | time, should differ. 178 | 179 | ## Built With 180 | 181 | * Linux 182 | * [linux-gpib](https://linux-gpib.sourceforge.io) - The GPIB driver and libraries 183 | * MacOS 184 | * [National Instruments 488.2 drivers](http://www.ni.com/sv-se/support/downloads/drivers.html) 185 | 186 | ## Links to sources 187 | 188 | * [tektool](https://forum.tek.com/download/file.php?id=24983&sid=de2267bdadfd0a11ce92f2d5648d656e) - tektool in a zip file on forum.tek.com 189 | * [tekfwtool](https://github.com/fenugrec/tekfwtool) - tekfwtool on github 190 | * [tekfwtool](https://stackframe.org/tekfwtool/) - tekfwtool on stackframe.org 191 | * [tdsNvramFloppyTool](https://www.eevblog.com/forum/testgear/tektronix-tds500600700-nvram-floppy-dump-tool/) - information about tdsNvramFloppyTool 192 | * [getcaldata.c](https://drive.google.com/file/d/0Bz230ThydfRGYWFZbE5kWWhnVkk/view) - getcaldata.c 193 | 194 | ## DIST directories 195 | 196 | In the program directories there are subdirectories called DIST that 197 | contain the original programs and in some cases other stuff that came 198 | with it. 199 | 200 | ## Acknowledgments 201 | 202 | * All the helpful people in the community that has made this possible 203 | * flyte at eevblog.com forum 204 | * Sven Schnelle (svens@stackframe.org) 205 | * Dr. Albert Roseiro at Tantratron 206 | -------------------------------------------------------------------------------- /getcaldata/DIST/getcaldata.c.DIST: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * CAL EEPROM backup - for TDS520B,TDS540B,TDS724A,TDS744A,TDS754A,TDS782A,TDS784A 4 | * 5 | * compiled with MinGW gcc on Windows Vista / Win7 6 | * tested with Agilent I/O 16.x and S82357 from http://bmjd.biz/index.php 7 | * 8 | * 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | /* for NI adapters uncomment following line */ 18 | 19 | /* for Agilent adapters uncomment following line */ 20 | #include "ni488.h" 21 | 22 | #define ARRAYSIZE 100 // Size of read buffer 23 | 24 | int Dev; // Device handle 25 | char ReadBuffer[ARRAYSIZE + 1]; // Read data buffer 26 | char ErrorMnemonic[21][5] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", 27 | "ESAC", "EABO", "ENEB", "EDMA", "", 28 | "EOIP", "ECAP", "EFSO", "", "EBUS", 29 | "ESTB", "ESRQ", "", "", "", "ETAB"}; 30 | 31 | 32 | void GPIBCleanup(int Dev, char* ErrorMsg); 33 | static int debug; 34 | 35 | 36 | int _cdecl main(void) { 37 | 38 | /* 39 | * ======================================================================== 40 | * 41 | * INITIALIZATION SECTION 42 | * 43 | * ======================================================================== 44 | */ 45 | 46 | /* 47 | * Assign a unique identifier to the device and store in the variable 48 | * Dev. If the ERR bit is set in ibsta, call GPIBCleanup with an 49 | * error message. Otherwise, the device handle, Dev, is returned and 50 | * is used in all subsequent calls to the device. 51 | */ 52 | 53 | #define BDINDEX 0 // Board Index 54 | #define PRIMARY_ADDR_OF_DMM 1 // Primary address of device 55 | #define NO_SECONDARY_ADDR 0 // Secondary address of device 56 | #define TIMEOUT T10s // Timeout value = 10 seconds 57 | #define EOTMODE 1 // Enable the END message 58 | #define EOSMODE 0 // Disable the EOS mode 59 | 60 | FILE *outfile; 61 | int f,g; 62 | unsigned long addr; 63 | unsigned char str[255]; 64 | 65 | // addr = 0x00040000L; /* CAL data base address on TDS5xxB,6xxA,7xxA*/ 66 | addr = 262144; /* CAL data base address on TDS5xxB,6xxA,7xxA*/ 67 | 68 | 69 | Dev = ibdev (BDINDEX, PRIMARY_ADDR_OF_DMM, NO_SECONDARY_ADDR, 70 | TIMEOUT, EOTMODE, EOSMODE); 71 | if (ibsta & ERR) 72 | { 73 | GPIBCleanup(Dev, "Unable to open device"); 74 | return 1; 75 | } 76 | 77 | /* 78 | * Clear the internal or device functions of the device. If the error 79 | * bit ERR is set in ibsta, call GPIBCleanup with an error message. 80 | */ 81 | 82 | ibclr (Dev); 83 | if (ibsta & ERR) 84 | { 85 | GPIBCleanup(Dev, "Unable to clear device"); 86 | return 1; 87 | } 88 | 89 | /* 90 | * ======================================================================== 91 | * 92 | * MAIN BODY SECTION 93 | * 94 | * In this application, the Main Body communicates with the instrument 95 | * by writing a command to it and reading its response. 96 | * 97 | * ======================================================================== 98 | */ 99 | 100 | 101 | ibwrt (Dev, "*IDN?", 5L); 102 | if (ibsta & ERR) 103 | { 104 | GPIBCleanup(Dev, "Unable to write to device"); 105 | return 1; 106 | } 107 | 108 | ibrd (Dev, ReadBuffer, ARRAYSIZE); 109 | if (ibsta & ERR) 110 | { 111 | GPIBCleanup(Dev, "Unable to read data from device"); 112 | return 1; 113 | } 114 | 115 | ReadBuffer[ibcntl] = '\0'; 116 | printf("DSO IDN: %s\n", ReadBuffer); 117 | 118 | outfile = fopen("U1052.bin","wb"); 119 | printf("dumping U1052.bin\n"); 120 | printf("\nPlease wait ...\n"); 121 | 122 | 123 | /* the first 8 bytes of the U1052 EEPROM are not mapped and empty (0x00h) 124 | so we write as well 8 time 0x00h to dump file */ 125 | 126 | for(f = 0; f < 8; f++) 127 | { 128 | fputc(0x00, outfile); 129 | } 130 | 131 | 132 | /* send first TEKTRONIX Password fr TDS5xxB/7xxA models to allow memory dump */ 133 | ibwrt (Dev, "PASSWORD PITBULL", 17L); 134 | if (ibsta & ERR) 135 | { 136 | GPIBCleanup(Dev, "Unable to write to device"); 137 | return 1; 138 | } 139 | 140 | unsigned char calbuf[255]; 141 | int caldata; 142 | 143 | 144 | for(f = 0; f < 124; f++) 145 | { 146 | unsigned char cmdbuf[64] = "WORDCONSTANT:ATOFFSET? 262144,"; 147 | unsigned char cmdnr[16]; 148 | sprintf(cmdnr,"%d",f); 149 | strcat(cmdbuf, cmdnr); 150 | 151 | if (debug > 1) printf("DSO IDN: %s\n", cmdbuf); 152 | 153 | ibwrt (Dev, cmdbuf, sizeof(cmdbuf)); 154 | if (ibsta & ERR) 155 | { 156 | GPIBCleanup(Dev, "Unable to write to device"); 157 | return 1; 158 | } 159 | ibrd(Dev, calbuf, 6); 160 | if (ibsta & ERR) 161 | { 162 | GPIBCleanup(Dev, "Unable to write to device"); 163 | return 1; 164 | } 165 | 166 | caldata = atoi(calbuf); 167 | if (debug > 1) printf("CAL DATA: %X\n", caldata); 168 | 169 | unsigned char* abuffer = (char *)&caldata; 170 | fputc(abuffer[1], outfile); 171 | fputc(abuffer[0], outfile); 172 | } 173 | fclose(outfile); 174 | 175 | outfile = fopen("U1055.bin","wb"); 176 | printf("dumping U1055.bin\n"); 177 | printf("\nPlease wait ...\n"); 178 | 179 | for(f = 0; f < 128; f++) 180 | { 181 | unsigned char cmdbuf[64] = "WORDCONSTANT:ATOFFSET? 262144,"; 182 | unsigned char cmdnr[16]; 183 | sprintf(cmdnr,"%d",f+124); 184 | strcat(cmdbuf, cmdnr); 185 | 186 | if (debug > 1) printf("DSO IDN: %s\n", cmdbuf); 187 | 188 | ibwrt (Dev, cmdbuf, sizeof(cmdbuf)); 189 | if (ibsta & ERR) 190 | { 191 | GPIBCleanup(Dev, "Unable to write to device"); 192 | return 1; 193 | } 194 | ibrd(Dev, calbuf, 6); 195 | if (ibsta & ERR) 196 | { 197 | GPIBCleanup(Dev, "Unable to write to device"); 198 | return 1; 199 | } 200 | 201 | caldata = atoi(calbuf); 202 | if (debug > 1) printf("CAL DATA: %X\n", caldata); 203 | 204 | unsigned char* abuffer = (char *)&caldata; 205 | fputc(abuffer[1], outfile); 206 | fputc(abuffer[0], outfile); 207 | } 208 | fclose(outfile); 209 | 210 | printf("\nCalibration data has been successful dumped\n"); 211 | 212 | /* 213 | * ======================================================================== 214 | * 215 | * CLEANUP SECTION 216 | * 217 | * ======================================================================== 218 | */ 219 | 220 | /* Take the device offline. */ 221 | 222 | 223 | ibonl (Dev, 0); 224 | 225 | return 0; 226 | 227 | } 228 | 229 | 230 | /* 231 | * After each GPIB call, the application checks whether the call 232 | * succeeded. If an NI-488.2 call fails, the GPIB driver sets the 233 | * corresponding bit in the global status variable. If the call 234 | * failed, this procedure prints an error message, takes the 235 | * device offline and exits. 236 | */ 237 | void GPIBCleanup(int ud, char* ErrorMsg) 238 | { 239 | printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n", 240 | ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]); 241 | if (ud != -1) 242 | { 243 | printf("Cleanup: Taking device offline\n"); 244 | ibonl (ud, 0); 245 | } 246 | } 247 | 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /getcaldata/MEMO.txt: -------------------------------------------------------------------------------- 1 | 2 | Run with instrument booted normally 3 | 4 | Configured for GPIB address 1 5 | -------------------------------------------------------------------------------- /getcaldata/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # identify platform 3 | ifeq ($(OS),Windows_NT) 4 | OS_NAME := windows_nt 5 | else 6 | OS_NAME := $(shell uname -s) 7 | ifeq ($(OS_NAME), Linux) 8 | # Linux with linux-gpib 9 | CFLAGS += -g -fsigned-char -Wall -Wextra -pedantic -l gpib -L/usr/local/lib 10 | endif 11 | ifeq ($(OS_NAME), Darwin) 12 | # Darwin with NI 488.2 driver 13 | CFLAGS += -g -fsigned-char /Library/Frameworks/NI4882.framework/Resources/ni4882.o -framework CoreFoundation -I/Library/Frameworks/NI4882.framework/Headers 14 | endif 15 | endif 16 | 17 | 18 | # get version and build time strings 19 | GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" 20 | ifneq ($(GIT_VERSION), "") 21 | CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" 22 | endif 23 | BUILD_TIME := "$(shell date -u "+%Y-%m-%d %H:%M:%S")" 24 | ifneq ($(BUILD_TIME), "") 25 | CFLAGS += -DBUILD_TIME=\"$(BUILD_TIME)\" 26 | endif 27 | 28 | 29 | CFLAGS += -DPROG_NAME=\"$@\" 30 | 31 | 32 | getcaldata : getcaldata.c 33 | # gcc $(CFLAGS) getcaldata.c -o getcaldata 34 | 35 | .PHONY : clean 36 | clean : 37 | -rm -fv getcaldata 38 | -rm -rfv getcaldata.dSYM 39 | -------------------------------------------------------------------------------- /getcaldata/getcaldata.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * CAL EEPROM backup - for TDS520B,TDS540B,TDS724A,TDS744A,TDS754A,TDS782A,TDS784A 4 | * 5 | * compiled with MinGW gcc on Windows Vista / Win7 6 | * tested with Agilent I/O 16.x and S82357 from http://bmjd.biz/index.php 7 | * 8 | * 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 17 | #include 18 | #include 19 | /* for NI adapters uncomment following line */ 20 | 21 | /* for Agilent adapters uncomment following line */ 22 | #include "ni488.h" 23 | #elif defined(__linux__) 24 | /* linux with linux-gpib */ 25 | #include 26 | #elif defined(__APPLE__) 27 | /* MacOS with NI GPIB drivers */ 28 | #include 29 | #else 30 | #error "Unknown compiler environment!" 31 | #endif 32 | 33 | 34 | #if !defined (PROG_NAME) 35 | #define PROG_NAME __FILE__ 36 | #endif 37 | #if !defined (GIT_VERSION) 38 | #define GIT_VERSION "unknown" 39 | #endif 40 | #if !defined (BUILD_TIME) 41 | #define BUILD_TIME __DATE__ " " __TIME__ 42 | #endif 43 | 44 | 45 | 46 | #define ARRAYSIZE 100 // Size of read buffer 47 | 48 | int Dev; // Device handle 49 | char ReadBuffer[ARRAYSIZE + 1]; // Read data buffer 50 | char ErrorMnemonic[21][5] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", 51 | "ESAC", "EABO", "ENEB", "EDMA", "", 52 | "EOIP", "ECAP", "EFSO", "", "EBUS", 53 | "ESTB", "ESRQ", "", "", "", "ETAB"}; 54 | 55 | 56 | void GPIBCleanup(int Dev, char* ErrorMsg); 57 | static int debug; 58 | 59 | 60 | static char* ident = PROG_NAME " Version: " GIT_VERSION " Build time: " BUILD_TIME; 61 | static void print_version(void) 62 | { 63 | fprintf(stderr, "# %s\n", ident); 64 | } 65 | 66 | 67 | int main(void) { 68 | /* 69 | * ======================================================================== 70 | * 71 | * INITIALIZATION SECTION 72 | * 73 | * ======================================================================== 74 | */ 75 | 76 | /* 77 | * Assign a unique identifier to the device and store in the variable 78 | * Dev. If the ERR bit is set in ibsta, call GPIBCleanup with an 79 | * error message. Otherwise, the device handle, Dev, is returned and 80 | * is used in all subsequent calls to the device. 81 | */ 82 | 83 | #define BDINDEX 0 // Board Index 84 | #define PRIMARY_ADDR_OF_DMM 1 // Primary address of device 85 | #define NO_SECONDARY_ADDR 0 // Secondary address of device 86 | #define TIMEOUT T10s // Timeout value = 10 seconds 87 | #define EOTMODE 1 // Enable the END message 88 | #define EOSMODE 0 // Disable the EOS mode 89 | 90 | FILE *outfile; 91 | int f; 92 | #if 0 93 | unsigned long addr; 94 | // addr = 0x00040000L; /* CAL data base address on TDS5xxB,6xxA,7xxA*/ 95 | addr = 262144; /* CAL data base address on TDS5xxB,6xxA,7xxA*/ 96 | #endif 97 | 98 | print_version(); 99 | 100 | Dev = ibdev (BDINDEX, PRIMARY_ADDR_OF_DMM, NO_SECONDARY_ADDR, 101 | TIMEOUT, EOTMODE, EOSMODE); 102 | if (ibsta & ERR) 103 | { 104 | GPIBCleanup(Dev, "Unable to open device"); 105 | return 1; 106 | } 107 | 108 | /* 109 | * Clear the internal or device functions of the device. If the error 110 | * bit ERR is set in ibsta, call GPIBCleanup with an error message. 111 | */ 112 | 113 | ibclr (Dev); 114 | if (ibsta & ERR) 115 | { 116 | GPIBCleanup(Dev, "Unable to clear device"); 117 | return 1; 118 | } 119 | 120 | /* 121 | * ======================================================================== 122 | * 123 | * MAIN BODY SECTION 124 | * 125 | * In this application, the Main Body communicates with the instrument 126 | * by writing a command to it and reading its response. 127 | * 128 | * ======================================================================== 129 | */ 130 | 131 | 132 | ibwrt (Dev, "*IDN?", 5L); 133 | if (ibsta & ERR) 134 | { 135 | GPIBCleanup(Dev, "Unable to write to device"); 136 | return 1; 137 | } 138 | 139 | ibrd (Dev, ReadBuffer, ARRAYSIZE); 140 | if (ibsta & ERR) 141 | { 142 | GPIBCleanup(Dev, "Unable to read data from device"); 143 | return 1; 144 | } 145 | 146 | ReadBuffer[ibcntl] = '\0'; 147 | printf("DSO IDN: %s\n", ReadBuffer); 148 | 149 | outfile = fopen("U1052.bin","wb"); 150 | printf("dumping U1052.bin\n"); 151 | printf("\nPlease wait ...\n"); 152 | 153 | 154 | /* the first 8 bytes of the U1052 EEPROM are not mapped and empty (0x00h) 155 | so we write as well 8 time 0x00h to dump file */ 156 | 157 | for(f = 0; f < 8; f++) 158 | { 159 | fputc(0x00, outfile); 160 | } 161 | 162 | 163 | /* send first TEKTRONIX Password fr TDS5xxB/7xxA models to allow memory dump */ 164 | ibwrt (Dev, "PASSWORD PITBULL", 17L); 165 | if (ibsta & ERR) 166 | { 167 | GPIBCleanup(Dev, "Unable to write to device"); 168 | return 1; 169 | } 170 | 171 | unsigned char calbuf[255]; 172 | int caldata; 173 | 174 | 175 | for(f = 0; f < 124; f++) 176 | { 177 | char cmdbuf[64] = "WORDCONSTANT:ATOFFSET? 262144,"; 178 | char cmdnr[16]; 179 | sprintf(cmdnr,"%d",f); 180 | strcat(cmdbuf, cmdnr); 181 | 182 | if (debug > 1) printf("DSO IDN: %s\n", cmdbuf); 183 | 184 | ibwrt (Dev, cmdbuf, sizeof(cmdbuf)); 185 | if (ibsta & ERR) 186 | { 187 | GPIBCleanup(Dev, "Unable to write to device"); 188 | return 1; 189 | } 190 | ibrd(Dev, calbuf, 6); 191 | if (ibsta & ERR) 192 | { 193 | GPIBCleanup(Dev, "Unable to write to device"); 194 | return 1; 195 | } 196 | 197 | caldata = atoi((char *) calbuf); 198 | if (debug > 1) printf("CAL DATA: %X\n", caldata); 199 | 200 | unsigned char* abuffer = (unsigned char *)&caldata; 201 | fputc(abuffer[1], outfile); 202 | fputc(abuffer[0], outfile); 203 | } 204 | fclose(outfile); 205 | 206 | outfile = fopen("U1055.bin","wb"); 207 | printf("dumping U1055.bin\n"); 208 | printf("\nPlease wait ...\n"); 209 | 210 | for(f = 0; f < 128; f++) 211 | { 212 | char cmdbuf[64] = "WORDCONSTANT:ATOFFSET? 262144,"; 213 | char cmdnr[16]; 214 | sprintf(cmdnr,"%d",f+124); 215 | strcat(cmdbuf, cmdnr); 216 | 217 | if (debug > 1) printf("DSO IDN: %s\n", cmdbuf); 218 | 219 | ibwrt (Dev, cmdbuf, sizeof(cmdbuf)); 220 | if (ibsta & ERR) 221 | { 222 | GPIBCleanup(Dev, "Unable to write to device"); 223 | return 1; 224 | } 225 | ibrd(Dev, calbuf, 6); 226 | if (ibsta & ERR) 227 | { 228 | GPIBCleanup(Dev, "Unable to write to device"); 229 | return 1; 230 | } 231 | 232 | caldata = atoi((char *) calbuf); 233 | if (debug > 1) printf("CAL DATA: %X\n", caldata); 234 | 235 | unsigned char* abuffer = (unsigned char *)&caldata; 236 | fputc(abuffer[1], outfile); 237 | fputc(abuffer[0], outfile); 238 | } 239 | fclose(outfile); 240 | 241 | printf("\nCalibration data has been successful dumped\n"); 242 | 243 | /* 244 | * ======================================================================== 245 | * 246 | * CLEANUP SECTION 247 | * 248 | * ======================================================================== 249 | */ 250 | 251 | /* Take the device offline. */ 252 | 253 | 254 | ibonl (Dev, 0); 255 | 256 | return 0; 257 | 258 | } 259 | 260 | 261 | /* 262 | * After each GPIB call, the application checks whether the call 263 | * succeeded. If an NI-488.2 call fails, the GPIB driver sets the 264 | * corresponding bit in the global status variable. If the call 265 | * failed, this procedure prints an error message, takes the 266 | * device offline and exits. 267 | */ 268 | void GPIBCleanup(int ud, char* ErrorMsg) 269 | { 270 | printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n", 271 | ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]); 272 | if (ud != -1) 273 | { 274 | printf("Cleanup: Taking device offline\n"); 275 | ibonl (ud, 0); 276 | } 277 | } 278 | 279 | 280 | 281 | 282 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool-extra/info-extra.txt: -------------------------------------------------------------------------------- 1 | 2 | tdsNvramEepromFloppyDumper: 3 | 4 | A modified version of the dump scripts that dumps both the NVRAM and 5 | EEPROM in one sweep. 6 | 7 | NOTE - only works on the 5xx/6xx/7xx models -B, -C and -D series 8 | scopes, starting with firmware v4.x. 9 | 10 | Puts interactive messages on screen. Dumps the nvram to a file called 11 | nvram.bin, and the acquistion calibration eeproms to a file called 12 | acqeeprm.bin. 13 | This script uses an intermediate buffer and takes a fast snapshot of 14 | the NVRAM, so other processes cannot interfere with the procedure 15 | while writing to disk. 16 | The original is reported to work only on more recent scopes and 17 | firmwares such as the -C and -D series. 18 | 19 | 20 | Many thanks to flyte at eevblog.com forum 21 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool-extra/tdsNvramEepromFloppyDumper/dumpall.app: -------------------------------------------------------------------------------- 1 | nulldev = open("/null",3,0666) 2 | taskSpawn "Redirect",1,0,0x4000,ioGlobalStdSet,1,nulldev 3 | taskDelay (600) 4 | GpibInput("WAITICON OPEN") 5 | 6 | GpibInput("mess:box 40,80,490,400") 7 | GpibInput("mess:show \"\n\n\n\n NVRAM dump to floppy started, please wait.\"") 8 | 9 | nvrBase=0x4000000 10 | nvrSize=0xA0000 11 | 12 | tempBuf=malloc(nvrSize) 13 | 14 | memcpy(tempBuf,nvrBase,nvrSize) 15 | 16 | ls "fd0:/" 17 | fd=open("fd0:/nvram.bin",0x0202,0777) 18 | nvbytesWritten=write(fd,tempBuf,nvrSize) 19 | close(fd) 20 | 21 | confmsg=malloc(1000) 22 | sprintf(confmsg, "mess:show \"\n\n\n\n NVRAM Dump completed.\n") 23 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written: %d\n", nvrSize, nvbytesWritten) 24 | sprintf(confmsg+strlen(confmsg), " Starting EEPROM dump...\"") 25 | GpibInput(confmsg) 26 | 27 | acqEEPROMSize=0x200 28 | tempBuf=malloc(acqEEPROMSize) 29 | _gtlX24c02Bcopy(0x10A00000,tempBuf,acqEEPROMSize) 30 | fdee=open("fd0:/acqeeprm.bin",0x0202,0777) 31 | eebytesWritten=write(fdee,tempBuf,acqEEPROMSize) 32 | close(fdee) 33 | 34 | confmsg=malloc(1000) 35 | sprintf(confmsg, "mess:show \"\n\n\n\n NVRAM Dump completed.\n") 36 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written: %d\n", nvrSize, nvbytesWritten) 37 | sprintf(confmsg+strlen(confmsg), " EEPROM dump completed.\n") 38 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written: %d\n\n", acqEEPROMSize, eebytesWritten) 39 | sprintf(confmsg+strlen(confmsg), " Dump completed, power off instrument.\"") 40 | GpibInput(confmsg) 41 | 42 | GpibInput("WAITICON CLOSE") 43 | GpibInput("bel") 44 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool-extra/tdsNvramEepromFloppyDumper/startup.bat: -------------------------------------------------------------------------------- 1 | taskSpawn ("dumpall",1,0x0,40000,sysExecScript,"fd0:/dumpall.app") 2 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/DIST/tdsNvramFloppyTools_v5.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tdsNvramFloppyTool/DIST/tdsNvramFloppyTools_v5.zip -------------------------------------------------------------------------------- /tdsNvramFloppyTool/README.txt: -------------------------------------------------------------------------------- 1 | 2 | From: 3 | https://www.eevblog.com/forum/testgear/tektronix-tds500600700-nvram-floppy-dump-tool/ 4 | 5 | Tektronix TDS500/600/700 NVRAM floppy backup and restore tool 6 | 7 | ##### 8 | 9 | Tektronix TDS500/600/700 NVRAM floppy backup and restore tool 10 | « on: January 17, 2019, 05:48:31 pm » 11 | 12 | Hi all, 13 | 14 | As many of these great Tektronix TDS scopes are ageing, they will have their NVRAMs sooner or later wiped due to battery failure and because AFAIK the only way to safely dump the NVRAMs contents is via a GPIB interface, which not every scope owner has, I've decided to write a small script which simply dumps the NVRAM contents to a floppy disk. As most TDS scopes, and certainly the higher spec'd ones, have a floppy disk option, taking a backup this way would be a quick win for anyone looking to do so or worrying about imminent battery doom. 15 | 16 | The script is based on the JRE installer script and reads 0xA0000 bytes from the base address 0x4000000 (contiguous 128K DS1486 and 512K DS1250Y), so it should work with the TDS700C/D and TDS600C series. It has been tested on TDS754D, TDS784D and TDS694C. Adapting it to TDS series with different NVRAM addresses should be easy. 17 | 18 | Simply put the attachment's contents into an (old) FAT formatted floppy and start up the scope with the disk mounted. About 10s after boot, it will dump the NVRAMs to dump.bin on the floppy. Use an error-free floppy and preferably first format it on the scope itself using the normal file utilities for best compatibility. 19 | 20 | Make sure you rename the dump.bin right away to include the scope model and serial number, as there is no way to derive that from the binary dump afterwards. 21 | 22 | Have fun saving your equipment! :) 23 | 24 | flyte 25 | 26 | -- EDIT/UPDATE: 27 | 28 | If we can read this way, we can also write! ;) 29 | 30 | So I've made a second script which will load an NVRAM dump back into the scope via floppy. Works the same way as the dumper, but expects a file writedmp.bin on the disk. Tested on a TDS754D scope, works perfectly. Note that loading a dump from a different scope will mess up all calibration values, so please be honest when offering scopes "repaired" this way and mention it to your buyer. 31 | 32 | BTW, if you are looking for a factory new genuine Dallas DS1486, I have some left from known distributor origins. It's likely to be one of the very last batches, as the production stopped years ago and worldwide stocks are now depleted, and what now remains are Ebay floods of Asian counterfeits with all sorts of issues. 33 | 34 | -- EDIT/UPDATE 2: 35 | 36 | Made a new set of scripts v3, the previous download's nvram restore/write script did not write correctly in some cases which lead to a corrupt nvram, even if the file was fine, as it appeared. Also, the backup/dump script seemed to hang on A-series scopes, a TDS524A in the case tested. Please delete your old downloads, replace them with the new scripts and check info.txt in the archive. 37 | 38 | -- EDIT/UPDATE 3: 39 | 40 | Added a checksum verification tool so everyone can verify the dump taken has valid checksums on critical calibration data. Even though it contains checksum locations for a range of firmware versions and models, you may encounter an unrecognized NVRAM firmware prototype. Also, there may be locations in the NVRAM with other checksums than what is supported by the tool, but those verified by it are the critical ones regarding calibration and proper startup. It's written in Java, you need to install a Java JRE on your computer in order to use it. Run command example: 41 | 42 | Code: [Select] 43 | java -cp TDSNvrCV_1_0.zip TDSNvramChecksumVerifier DUMP.BIN 44 | 45 | -- EDIT/UPDATE 4: 46 | 47 | Added scripts to backup the factory calibration constants in the EEPROMs on acquisition boards of -B, -C and -D series scopes, starting with firmware v4.x. Check info.txt inside the archive. The checksum verifier has been updated to allow verification of the acquisition EEPROM dumps, and the tool will attempt to detect based on file size whether the dump is an NVRAM or acquisition EEPROM. 48 | 49 | Code: [Select] 50 | java -cp TDSNvrCV_2_0.zip TDSNvramChecksumVerifier DUMP.BIN 51 | 52 | -- EDIT/UPDATE 5: 53 | 54 | New version of the scripts which allow you to also write the EEPROMs on acquisition boards of -B, -C and -D series scopes, starting with firmware v4.x. Be very careful when using this function, you may permanently destroy your scope. Check info.txt inside the archive. The checksum verifier is now part of the archive. 55 | * tdsNvramFloppyTools_v5.zip (18.41 kB - downloaded 11 times.) 56 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/TDSNvrCV_2_1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tdsNvramFloppyTool/TDSNvrCV_2_1.jar -------------------------------------------------------------------------------- /tdsNvramFloppyTool/info.txt: -------------------------------------------------------------------------------- 1 | These tools allow you to backup and restore the NVRAM contents 2 | of the Tektronix TDS500/600/700 series using the internal 3 | floppy disk. 4 | 5 | By default, all scripts are set to an export size of 640kB (0xA0000), 6 | which corresponds to the memory range of a 128kB DS1486 plus a 7 | 512kB DS1250Y in th -C/-D scope models. Early models like the TDS524A 8 | A-series, only have 0x80000 size of NVRAM, so you should adapt it 9 | accordingly. 10 | 11 | Extract the contents of each script folder, according to your 12 | requirement, to the root of an error-free FAT (not exFAT nor FAT32!) 13 | formatted floppy disk. For best compatibility, format it on 14 | the scope itself. 15 | 16 | 17 | The scripts: 18 | 19 | 20 | tdsNvramFloppyDumper: 21 | 22 | Puts interactive messages on screen, dumps the nvram to a file called 23 | dump.bin. This script uses an intermediate buffer and takes a fast 24 | snapshot of the NVRAM, so other processes cannot interfere with the 25 | procedure while writing to disk. Is reported to work only on more 26 | recent scopes and firmwares such as the -C and -D series. 27 | 28 | 29 | tdsNvramFloppyWriter: 30 | 31 | Puts interactive messages on screen, writes the nvram from a file 32 | called WRITEDMP.BIN. This script uses an intermediate loading buffer 33 | and only writes data to the NVRAM at the very last moment before 34 | automatic reboot, so chances are minimal other processes can interfere 35 | with the procedure. Is reported to work only on more recent scopes and 36 | firmwares such as the -C and -D series. 37 | Due to several regions of the NVRAM being write protected, on some scopes 38 | (like -A series) is it necessary to flip the calibration switch to 39 | enable writing. It must be done at the exact moment the floppy light 40 | comes on, as booting with the switch set may only start the device 41 | in bootloader mode and it will not proceed to execute the script. 42 | 43 | 44 | tdsNvramMinimalFloppyDumper: 45 | 46 | Same as the above dumper, with a very minimal set of commands and no 47 | warnings. Should work on any scope including the early -A series, and 48 | performs the dump right during the booting process. 49 | 50 | 51 | tdsNvramMinimalFloppyWriter: 52 | 53 | 54 | Same as the above writer, with a very minimal set of commands, no 55 | buffering and no warnings. Should work on any scope including the early 56 | -A series, and performs the writing right during the booting process. 57 | May yield incomplete or bad writing due to the import from floppy disk 58 | not being buffered. Remove disk upon automatic reboot. The device may 59 | also hang instead of reboot upon completion of the writing. Due to 60 | several regions of the NVRAM being write protected, on some scopes 61 | (like -A series) is it necessary to flip the calibration switch to 62 | enable writing. It must be done at the exact moment the floppy light 63 | comes on, as booting with the switch set may only start the device 64 | in bootloader mode and it will not proceed to execute the script. 65 | 66 | 67 | tdsAcqEEPROMFloppyDumper and tdsAcqEEPROMMinimalFloppyDumper: 68 | 69 | 70 | Dumps the contents of the calibration constants 24C02 EEPROMs located 71 | on the acquisition boards of the -B, -C and -D series scopes, to a file. 72 | -A series scopes have no such EEPROMs on the acquisition board and 73 | store these constants in regular NVRAM, albeit in a hardware-protected 74 | region. Both 24C02 EEPROMs are read as 0x200 bytes in a single file, 75 | where the first EEPROM is the top 0x100 half of the file, and the second 76 | one the bottom half. 77 | 78 | 79 | tdsAcqEEPROMFloppyWriter and tdsAcqEEPROMMinimalFloppyWriter: 80 | 81 | Writes the contents of the given file EEWRDMP.BIN back into the 24C02 82 | EEPROMs found on the acquisition boards of the -B, -C and -D series scopes. 83 | The tool expects 0x200 bytes of dump data in this file, as produced 84 | by the corresponding read tool above. During the procedure, the calibration 85 | or write protection switch of the scope must be flipped. Follow the 86 | on-screen instructions. Do not forget to flip the switch back when done, 87 | or the scope will stay into bootloader mode and it won't start up. 88 | 89 | CAUTION: This tool may permanently destroy your scope. If the file is 90 | not present, the EEPROM will be erased with 0x00 data bytes! 91 | 92 | CAUTION: The minimal version of this tool is DANGEROUS as it attempts 93 | to write the EEPROMs without confirmation and then reboots. The write- 94 | protection switch must be flipped when device boots up, approximately 95 | when the display tests run. Use only as a last resort. 96 | 97 | 98 | 99 | Checksum verifier tool: 100 | 101 | 102 | A checksum verifier tool is included which enables you to verify if the 103 | dumps taken are valid. The tool verifies sections of the dumps, and 104 | computes the checksums which the firmware expects to be present. The 105 | tool will automatically detect whether the file is an NVRAM dump or 106 | acquisition EEPROM dump. Java runtime needs to be installed in order to 107 | use it. 108 | 109 | In general, always use this tool to make sure the dumps you've made are 110 | actually valid backups! 111 | 112 | Command line usage: 113 | 114 | java -cp TDSNvrCV_2_1.jar TDSNvramChecksumVerifier MY-DUMP.bin 115 | 116 | 117 | 118 | 119 | No warranties and full disclaimer apply, be careful, these tools might 120 | permanently disable an oscilloscope if errors occur or if used improperly! 121 | Use at your own risk! 122 | 123 | 124 | You can use and/or modify these tools as you wish, but please be 125 | responsible and inform your buyer when "repairing" a scope with a dump 126 | from a different device, as measurements will no longer be accurate as 127 | calibrated. 128 | 129 | 130 | - flyte at eevblog.com forum -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMFloppyDumper/acqedump.app: -------------------------------------------------------------------------------- 1 | nulldev = open("/null",3,0666) 2 | taskSpawn "Redirect",1,0,0x4000,ioGlobalStdSet,1,nulldev 3 | taskDelay (600) 4 | GpibInput("WAITICON OPEN") 5 | 6 | GpibInput("mess:box 80,80,450,200") 7 | GpibInput("mess:show \"\n\n\n\n ACQ EEPROM dump to floppy started, please wait.\"") 8 | 9 | acqEEPROMSize=0x200 10 | tempBuf=malloc(acqEEPROMSize) 11 | _gtlX24c02Bcopy(0x10A00000,tempBuf,acqEEPROMSize) 12 | ls "fd0:/" 13 | fd=open("fd0:/acqeeprm.bin",0x0202,0777) 14 | bytesWritten=write(fd,tempBuf,acqEEPROMSize) 15 | close(fd) 16 | 17 | confmsg=malloc(500) 18 | sprintf(confmsg, "mess:show \"\n\n\n\n Dump completed, power off instrument.\n\n") 19 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written to disk: %d \n\"", acqEEPROMSize, bytesWritten) 20 | 21 | GpibInput(confmsg) 22 | GpibInput("WAITICON CLOSE") 23 | GpibInput("bel") 24 | 25 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMFloppyDumper/startup.bat: -------------------------------------------------------------------------------- 1 | taskSpawn ("acqeepdumper",1,0x0,40000,sysExecScript,"fd0:/acqedump.app") 2 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMFloppyWriter/acqewrte.app: -------------------------------------------------------------------------------- 1 | nulldev = open("/null",3,0666) 2 | taskSpawn "Redirect",1,0,0x4000,ioGlobalStdSet,1,nulldev 3 | taskDelay (60) 4 | GpibInput("WAITICON OPEN") 5 | 6 | confmsg=malloc(1000) 7 | GpibInput("mess:box 80,80,575,300") 8 | sprintf(confmsg, "mess:show \"\n\n\n\n ACQ EEPROM WRITING WILL START IN 30 SEC,\n") 9 | sprintf(confmsg+strlen(confmsg), " POWER OFF INSTRUMENT NOW TO CANCEL.\n\n\n") 10 | sprintf(confmsg+strlen(confmsg), " +++ SET THE WRITE PROTECTION SWITCH TO OFF NOW +++\"") 11 | 12 | GpibInput(confmsg) 13 | 14 | GpibInput("bel") 15 | taskDelay (20) 16 | GpibInput("bel") 17 | 18 | taskDelay (1200) 19 | 20 | confmsg[49]='1' 21 | 22 | GpibInput(confmsg) 23 | 24 | GpibInput("bel") 25 | taskDelay (20) 26 | GpibInput("bel") 27 | 28 | taskDelay (600) 29 | 30 | GpibInput("mess:show \"\n\n\n\n ACQ EEPROM writing started, please wait.\"") 31 | 32 | fileName="fd0:/eewrdmp.bin" 33 | acqEEPROMSize=0x200 34 | tempBuf=malloc(acqEEPROMSize) 35 | bfill(tempBuf,acqEEPROMSize,0) 36 | ls "fd0:/" 37 | fd=open(fileName,0,0777) 38 | bytesRead=read(fd,tempBuf,acqEEPROMSize) 39 | close(fd) 40 | 41 | taskDelay (120) 42 | 43 | _gtlX24c02Bcopy(tempBuf,0x10A00000,acqEEPROMSize) 44 | 45 | taskDelay (60) 46 | 47 | GpibInput("mess:show \"\n\n\n\n Verifying EEPROM contents, please wait.\"") 48 | 49 | cmpBuf=malloc(acqEEPROMSize) 50 | 51 | bfill(tempBuf,acqEEPROMSize,0) 52 | 53 | ls "fd0:/" 54 | fd2=open(fileName,0,0777) 55 | bytesRead=read(fd2,tempBuf,acqEEPROMSize) 56 | close(fd2) 57 | 58 | taskDelay (120) 59 | 60 | _gtlX24c02Bcopy(0x10A00000,cmpBuf,acqEEPROMSize) 61 | 62 | taskDelay (60) 63 | 64 | cmpResult=memcmp(cmpBuf,tempBuf,acqEEPROMSize) 65 | 66 | sprintf(confmsg, "mess:show \"\n\n\n\n Write completed, power off instrument.\n\n") 67 | sprintf(confmsg+strlen(confmsg), " Bytes read: %d \n Verification result value: %d ", bytesRead, cmpResult) 68 | sprintf(confmsg+strlen(confmsg), " (0 = OK, other value = FAIL)\n") 69 | sprintf(confmsg+strlen(confmsg), "\n\n\n SET THE WRITE PROTECTION SWITCH BACK TO ON NOW\"") 70 | 71 | GpibInput(confmsg) 72 | GpibInput("bel;WAITICON CLOSE") 73 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMFloppyWriter/startup.bat: -------------------------------------------------------------------------------- 1 | taskSpawn ("acqewrte",1,0x0,40000,sysExecScript,"fd0:/acqewrte.app") 2 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMMinimalFloppyDumper/startup.bat: -------------------------------------------------------------------------------- 1 | acqEEPROMSize=0x200 2 | tempBuf=malloc(acqEEPROMSize) 3 | _gtlX24c02Bcopy(0x10A00000,tempBuf,acqEEPROMSize) 4 | ls "fd0:/" 5 | fd=open("fd0:/acqeeprm.bin",0x0202,0777) 6 | bytesWritten=write(fd,tempBuf,acqEEPROMSize) 7 | close(fd) -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsAcqEEPROMMinimalFloppyWriter/startup.bat: -------------------------------------------------------------------------------- 1 | acqEEPROMSize=0x200 2 | tempBuf=malloc(acqEEPROMSize) 3 | bfill(tempBuf,acqEEPROMSize,0) 4 | ls "fd0:/" 5 | fd=open("fd0:/eewrdmp.bin",0,0777) 6 | bytesRead=read(fd,tempBuf,acqEEPROMSize) 7 | close(fd) 8 | _gtlX24c02Bcopy(tempBuf,0x10A00000,acqEEPROMSize) 9 | reboot 10 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramFloppyDumper/nvdump.app: -------------------------------------------------------------------------------- 1 | nulldev = open("/null",3,0666) 2 | taskSpawn "Redirect",1,0,0x4000,ioGlobalStdSet,1,nulldev 3 | taskDelay (600) 4 | GpibInput("WAITICON OPEN") 5 | 6 | GpibInput("mess:box 80,80,450,200") 7 | GpibInput("mess:show \"\n\n\n\n NVRAM dump to floppy started, please wait.\"") 8 | 9 | nvrBase=0x4000000 10 | nvrSize=0xA0000 11 | 12 | tempBuf=malloc(nvrSize) 13 | 14 | memcpy(tempBuf,nvrBase,nvrSize) 15 | 16 | ls "fd0:/" 17 | fd=open("fd0:/dump.bin",0x0202,0777) 18 | bytesWritten=write(fd,tempBuf,nvrSize) 19 | close(fd) 20 | 21 | confmsg=malloc(500) 22 | sprintf(confmsg, "mess:show \"\n\n\n\n Dump completed, power off instrument.\n\n") 23 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written to disk: %d \n\"", nvrSize, bytesWritten) 24 | 25 | GpibInput(confmsg) 26 | GpibInput("WAITICON CLOSE") 27 | GpibInput("bel") 28 | 29 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramFloppyDumper/startup.bat: -------------------------------------------------------------------------------- 1 | taskSpawn ("nvramdumper",1,0x0,40000,sysExecScript,"fd0:/nvdump.app") 2 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramFloppyWriter/nvwrite.app: -------------------------------------------------------------------------------- 1 | nulldev = open("/null",3,0666) 2 | taskSpawn "Redirect",1,0,0x4000,ioGlobalStdSet,1,nulldev 3 | taskDelay (60) 4 | GpibInput("WAITICON OPEN") 5 | 6 | GpibInput("mess:box 80,80,550,200") 7 | GpibInput("mess:show \"\n\n\n\n NVRAM WRITING WILL START IN 30 SEC,\n POWER OFF INSTRUMENT NOW TO CANCEL.\"") 8 | 9 | GpibInput("bel") 10 | taskDelay (20) 11 | GpibInput("bel") 12 | 13 | taskDelay (1200) 14 | 15 | GpibInput("mess:show \"\n\n\n\n NVRAM WRITING WILL START IN 10 SEC,\n POWER OFF INSTRUMENT NOW TO CANCEL.\"") 16 | 17 | GpibInput("bel") 18 | taskDelay (20) 19 | GpibInput("bel") 20 | 21 | taskDelay (600) 22 | 23 | GpibInput("mess:show \"\n\n\n\n NVRAM writing started, please wait.\"") 24 | 25 | nvrBase=0x4000000 26 | nvrSize=0xA0000 27 | 28 | tempBuf=malloc(nvrSize) 29 | 30 | ls "fd0:/" 31 | fd=open("fd0:/writedmp.bin",0,0777) 32 | bytesRead=read(fd,tempBuf,nvrSize) 33 | close(fd) 34 | 35 | confmsg=malloc(500) 36 | sprintf(confmsg, "mess:show \"\n\n\n\n NVRAM write will be executed in 10s.\n") 37 | sprintf(confmsg+strlen(confmsg), " DO NOT power off, wait for automatic reboot.\n") 38 | sprintf(confmsg+strlen(confmsg), " Bytes requested: %d \n Bytes written to temporary buffer: %d \n\"", nvrSize, bytesRead) 39 | 40 | GpibInput(confmsg) 41 | GpibInput("bel;WAITICON CLOSE") 42 | 43 | taskDelay (600) 44 | 45 | memcpy(nvrBase,tempBuf,nvrSize); reboot -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramFloppyWriter/startup.bat: -------------------------------------------------------------------------------- 1 | taskSpawn ("nvramwriter",1,0x0,40000,sysExecScript,"fd0:/nvwrite.app") 2 | -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramMinimalFloppyDumper/startup.bat: -------------------------------------------------------------------------------- 1 | nvrBase=0x4000000 2 | nvrSize=0xA0000 3 | ls "fd0:/" 4 | fd=open("fd0:/dump.bin",0x0202,0777) 5 | bytesWritten=write(fd,nvrBase,nvrSize) 6 | close(fd) -------------------------------------------------------------------------------- /tdsNvramFloppyTool/tdsNvramMinimalFloppyWriter/startup.bat: -------------------------------------------------------------------------------- 1 | nvrBase=0x4000000 2 | nvrSize=0xA0000 3 | ls "fd0:/" 4 | fd=open("fd0:/writedmp.bin",0,0777) 5 | bytesRead=read(fd,nvrBase,nvrSize) 6 | close(fd) 7 | reboot -------------------------------------------------------------------------------- /tekfwtool/.dir-locals.el: -------------------------------------------------------------------------------- 1 | ; Indentation settings for C in Emacs 2 | ; tektool.c is written in several different indentation styles, but the 3 | ; style mostly used seems quite close to Emacs "linux" style. 4 | ;((c-mode . ((c-file-style . "linux") 5 | ; (subdirs . nil))) 6 | ; ) 7 | ( 8 | ("tekfwtool.c" . ((c-mode . ((c-file-style . "linux"))))) 9 | ("target.c" . ((c-mode . ((c-file-style . "linux"))))) 10 | ) 11 | -------------------------------------------------------------------------------- /tekfwtool/DIST/README.txt: -------------------------------------------------------------------------------- 1 | tekfwtool.github - from https://stackframe.org/tekfwtool/ 2 | tekfwtool.stackframe.org - from https://github.com/fenugrec/tekfwtool/tree/775b27c698e4efe9d047abb585a20cbffe17546a 3 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/Makefile: -------------------------------------------------------------------------------- 1 | CC=/cygdrive/c/mingw/bin/gcc 2 | CFLAGS=-Wextra -Wall -O2 -Wno-unused -ggdb 3 | M68K=m68k-elf- 4 | M68KCC=$(M68K)gcc 5 | M68CCKFLAGS=-Wall -Wextra -Os -ggdb 6 | M68KOBJCOPY=$(M68K)objcopy 7 | M68KNM=$(M68K)nm 8 | 9 | all: tekfwtool.exe target.bin 10 | 11 | 12 | tekfwtool.exe: tekfwtool.c target-procs.h 13 | $(CC) $(CFLAGS) ./gpib-32.obj -o $@ tekfwtool.c 14 | 15 | target.bin: target.elf 16 | $(M68KOBJCOPY) -O binary $< $@ 17 | 18 | target.elf: target.o target.ld 19 | $(M68KCC) -nostdlib -Wl,-T target.ld -o $@ target.o 20 | 21 | target-procs.h: target.elf gen-procs.sh 22 | ./gen-procs.sh >$@ 23 | 24 | target.o: target.c 25 | $(M68KCC) $(M68KCCFLAGS) -c -o $@ $< 26 | clean: 27 | rm -f tekfwtool.exe target.o target.elf target.bin 28 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/dosdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef _DOSDEFS_H 2 | #define _DOSDEFS_H 3 | 4 | /* Useful defs for compiling for DOS target 5 | * 6 | * 7 | * 8 | */ 9 | 10 | #include "DECL.H" //NI stuff 11 | 12 | #define __FUNCTION__ "" //no known MS C equivalent 13 | #define BYTE_ORDER LITTLE_ENDIAN 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/DECL.H: -------------------------------------------------------------------------------- 1 | /* decl.h -- NI488.2 header file */ 2 | 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | extern int ibsta; 10 | extern int iberr; 11 | extern unsigned short ibcnt; 12 | extern long ibcntl; 13 | 14 | 15 | #define UNL 0x3f /* GPIB unlisten command */ 16 | #define UNT 0x5f /* GPIB untalk command */ 17 | #define GTL 0x01 /* GPIB go to local */ 18 | #define SDC 0x04 /* GPIB selected device clear */ 19 | #define PPC 0x05 /* GPIB parallel poll configure */ 20 | #define GET 0x08 /* GPIB group execute trigger */ 21 | #define TCT 0x09 /* GPIB take control */ 22 | #define LLO 0x11 /* GPIB local lock out */ 23 | #define DCL 0x14 /* GPIB device clear */ 24 | #define PPU 0x15 /* GPIB parallel poll unconfigure */ 25 | #define SPE 0x18 /* GPIB serial poll enable */ 26 | #define SPD 0x19 /* GPIB serial poll disable */ 27 | #define PPE 0x60 /* GPIB parallel poll enable */ 28 | #define PPD 0x70 /* GPIB parallel poll disable */ 29 | 30 | /* GPIB status bit vector : */ 31 | /* global variable ibsta and wait mask */ 32 | 33 | #define ERR (1<<15) /* Error detected */ 34 | #define TIMO (1<<14) /* Timeout */ 35 | #define END (1<<13) /* EOI or EOS detected */ 36 | #define SRQI (1<<12) /* SRQ detected by CIC */ 37 | #define RQS (1<<11) /* Device needs service */ 38 | #define SPOLL (1<<10) /* Board has been serially polled */ 39 | #define EVENT (1<<9) /* An event has occured */ 40 | #define CMPL (1<<8) /* I/O completed */ 41 | #define LOK (1<<7) /* Local lockout state */ 42 | #define REM (1<<6) /* Remote state */ 43 | #define CIC (1<<5) /* Controller-in-Charge */ 44 | #define ATN (1<<4) /* Attention asserted */ 45 | #define TACS (1<<3) /* Talker active */ 46 | #define LACS (1<<2) /* Listener active */ 47 | #define DTAS (1<<1) /* Device trigger state */ 48 | #define DCAS (1<<0) /* Device clear state */ 49 | 50 | /* Error messages returned in global variable iberr */ 51 | 52 | #define EDVR 0 /* System error */ 53 | #define ECIC 1 /* Function requires GPIB board to be CIC */ 54 | #define ENOL 2 /* Write function detected no Listeners */ 55 | #define EADR 3 /* Interface board not addressed correctly*/ 56 | #define EARG 4 /* Invalid argument to function call */ 57 | #define ESAC 5 /* Function requires GPIB board to be SAC */ 58 | #define EABO 6 /* I/O operation aborted */ 59 | #define ENEB 7 /* Non-existent interface board */ 60 | #define EDMA 8 /* Error performing DMA */ 61 | #define EOIP 10 /* I/O operation started before previous */ 62 | /* operation completed */ 63 | #define ECAP 11 /* No capability for intended operation */ 64 | #define EFSO 12 /* File system operation error */ 65 | #define EBUS 14 /* Command error during device call */ 66 | #define ESTB 15 /* Serial poll status byte lost */ 67 | #define ESRQ 16 /* SRQ remains asserted */ 68 | #define ETAB 20 /* The return buffer is full. */ 69 | #define ELCK 21 /* Address or board is locked. */ 70 | 71 | /* EOS mode bits */ 72 | 73 | #define BIN (1<<12) /* Eight bit compare */ 74 | #define XEOS (1<<11) /* Send END with EOS byte */ 75 | #define REOS (1<<10) /* Terminate read on EOS */ 76 | 77 | /* Timeout values and meanings */ 78 | 79 | #define TNONE 0 /* Infinite timeout (disabled) */ 80 | #define T10us 1 /* Timeout of 10 us (ideal) */ 81 | #define T30us 2 /* Timeout of 30 us (ideal) */ 82 | #define T100us 3 /* Timeout of 100 us (ideal) */ 83 | #define T300us 4 /* Timeout of 300 us (ideal) */ 84 | #define T1ms 5 /* Timeout of 1 ms (ideal) */ 85 | #define T3ms 6 /* Timeout of 3 ms (ideal) */ 86 | #define T10ms 7 /* Timeout of 10 ms (ideal) */ 87 | #define T30ms 8 /* Timeout of 30 ms (ideal) */ 88 | #define T100ms 9 /* Timeout of 100 ms (ideal) */ 89 | #define T300ms 10 /* Timeout of 300 ms (ideal) */ 90 | #define T1s 11 /* Timeout of 1 s (ideal) */ 91 | #define T3s 12 /* Timeout of 3 s (ideal) */ 92 | #define T10s 13 /* Timeout of 10 s (ideal) */ 93 | #define T30s 14 /* Timeout of 30 s (ideal) */ 94 | #define T100s 15 /* Timeout of 100 s (ideal) */ 95 | #define T300s 16 /* Timeout of 300 s (ideal) */ 96 | #define T1000s 17 /* Timeout of 1000 s (ideal) */ 97 | 98 | 99 | /* IBLN Constants */ 100 | #define NO_SAD 0 101 | #define ALL_SAD -1 102 | 103 | /* IBEVENT Constants */ 104 | #define EventDTAS 1 105 | #define EventDCAS 2 106 | #define EventIFC 3 107 | 108 | /* 109 | * GotoMultAddr (VXI) flags 110 | */ 111 | #define MultAddrPrimary 0x00 112 | #define MultAddrSecondary 0x01 113 | 114 | #define MultAddrListen 0x00 115 | #define MultAddrTalk 0x01 116 | #define MultAddrSerialPoll 0x81 117 | 118 | 119 | /* The following constants are used for the second parameter of the 120 | * ibconfig function. They are the "option" selection codes. 121 | */ 122 | #define IbcPAD 0x0001 /* Primary Address */ 123 | #define IbcSAD 0x0002 /* Secondary Address */ 124 | #define IbcTMO 0x0003 /* Timeout Value */ 125 | #define IbcEOT 0x0004 /* Send EOI with last data byte? */ 126 | #define IbcPPC 0x0005 /* Parallel Poll Configure */ 127 | #define IbcREADDR 0x0006 /* Repeat Addressing */ 128 | #define IbcAUTOPOLL 0x0007 /* Disable Auto Serial Polling */ 129 | #define IbcCICPROT 0x0008 /* Use the CIC Protocol? */ 130 | #define IbcIRQ 0x0009 /* Use PIO for I/O */ 131 | #define IbcSC 0x000A /* Board is System Controller? */ 132 | #define IbcSRE 0x000B /* Assert SRE on device calls? */ 133 | #define IbcEOSrd 0x000C /* Terminate reads on EOS */ 134 | #define IbcEOSwrt 0x000D /* Send EOI with EOS character */ 135 | #define IbcEOScmp 0x000E /* Use 7 or 8-bit EOS compare */ 136 | #define IbcEOSchar 0x000F /* The EOS character. */ 137 | #define IbcPP2 0x0010 /* Use Parallel Poll Mode 2. */ 138 | #define IbcTIMING 0x0011 /* NORMAL, HIGH, or VERY_HIGH timing. */ 139 | #define IbcDMA 0x0012 /* Use DMA for I/O */ 140 | #define IbcReadAdjust 0x0013 /* Swap bytes during an ibrd. */ 141 | #define IbcWriteAdjust 0x0014 /* Swap bytes during an ibwrt. */ 142 | #define IbcEventQueue 0x0015 /* Enable/disable the event queue. */ 143 | #define IbcSPollBit 0x0016 /* Enable/disable the visibility of SPOLL. */ 144 | #define IbcSendLLO 0x0017 /* Enable/disable the sending of LLO. */ 145 | #define IbcSPollTime 0x0018 /* Set the timeout value for serial polls. */ 146 | #define IbcPPollTime 0x0019 /* Set the parallel poll length period. */ 147 | #define IbcEndBitIsNormal 0x001A /* Remove EOS from END bit of IBSTA. */ 148 | #define IbcUnAddr 0x001B /* Enable/disable device unaddressing. */ 149 | #define IbcSignalNumber 0x001C /* Set UNIX signal number - unsupported */ 150 | #define IbcBlockIfLocked 0x001D /* Enable/disable blocking for locked boards/devices */ 151 | #define IbcHSCableLength 0x001F /* Length of cable specified for high speed timing. */ 152 | #define IbcIst 0x0020 /* Set the IST bit. */ 153 | #define IbcRsv 0x0021 /* Set the RSV byte. */ 154 | #define IbcLON 0x0022 /* Enter listen only mode. */ 155 | 156 | /* 157 | * Constants that can be used (in addition to the ibconfig constants) 158 | * when calling the ibask() function. 159 | */ 160 | 161 | #define IbaPAD IbcPAD 162 | #define IbaSAD IbcSAD 163 | #define IbaTMO IbcTMO 164 | #define IbaEOT IbcEOT 165 | #define IbaPPC IbcPPC 166 | #define IbaREADDR IbcREADDR 167 | #define IbaAUTOPOLL IbcAUTOPOLL 168 | #define IbaCICPROT IbcCICPROT 169 | #define IbaIRQ IbcIRQ 170 | #define IbaSC IbcSC 171 | #define IbaSRE IbcSRE 172 | #define IbaEOSrd IbcEOSrd 173 | #define IbaEOSwrt IbcEOSwrt 174 | #define IbaEOScmp IbcEOScmp 175 | #define IbaEOSchar IbcEOSchar 176 | #define IbaPP2 IbcPP2 177 | #define IbaTIMING IbcTIMING 178 | #define IbaDMA IbcDMA 179 | #define IbaReadAdjust IbcReadAdjust 180 | #define IbaWriteAdjust IbcWriteAdjust 181 | #define IbaEventQueue IbcEventQueue 182 | #define IbaSPollBit IbcSPollBit 183 | #define IbaSendLLO IbcSendLLO 184 | #define IbaSPollTime IbcSPollTime 185 | #define IbaPPollTime IbcPPollTime 186 | #define IbaEndBitIsNormal IbcEndBitIsNormal 187 | #define IbaUnAddr IbcUnAddr 188 | #define IbaSignalNumber IbcSignalNumber 189 | #define IbaBlockIfLocked IbcBlockIfLocked 190 | #define IbaHSCableLength IbcHSCableLength 191 | #define IbaLON IbcLON 192 | #define IbaIst IbcIst 193 | #define IbaRsv IbcRsv 194 | 195 | #define IbaBNA 0x0200 /* A device's access board. */ 196 | #define IbaBaseAddr 0x0201 /* A GPIB board's base I/O address. */ 197 | #define IbaDmaChannel 0x0202 /* A GPIB board's DMA channel. */ 198 | #define IbaIrqLevel 0x0203 /* A GPIB board's IRQ level. */ 199 | #define IbaBaud 0x0204 /* Baud rate used to communicate to CT box. */ 200 | #define IbaParity 0x0205 /* Parity setting for CT box. */ 201 | #define IbaStopBits 0x0206 /* Stop bits used for communicating to CT. */ 202 | #define IbaDataBits 0x0207 /* Data bits used for communicating to CT. */ 203 | #define IbaComPort 0x0208 /* System COM port used for CT box. */ 204 | #define IbaComIrqLevel 0x0209 /* System COM port's interrupt level. */ 205 | #define IbaComPortBase 0x020A /* System COM port's base I/O address. */ 206 | #define IbaDmaType 0x020B /* Type of DMA transfer mode used. */ 207 | #define IbaSingleCycleDma 0x020B /* Does the board use single cycle DMA? */ 208 | #define IbaSlotNumber 0x020C /* Slot number, if appropriate. */ 209 | #define IbaSocketNumber 0x020C /* PCMCIA only - socket number. */ 210 | #define IbaLPTNumber 0x020D /* Parallel port number */ 211 | #define IbaLPTType 0x020E /* Parallel port protocol */ 212 | 213 | 214 | /* Values used by the Send 488.2 command. */ 215 | 216 | #define NULLend 0x00 /* Do nothing at the end of a transfer.*/ 217 | #define NLend 0x01 /* Send NL with EOI after a transfer. */ 218 | #define DABend 0x02 /* Send EOI with the last DAB. */ 219 | 220 | /* Value used by the 488.2 Receive command. 221 | */ 222 | #define STOPend 0x0100 223 | 224 | 225 | /* Address type (for 488.2 calls) */ 226 | 227 | typedef short Addr4882_t; /* System dependent: must be 16 bits */ 228 | 229 | /* 230 | * This macro can be used to easily create an entry in address list 231 | * that is required by many of the 488.2 functions. The primary address goes in the 232 | * lower 8-bits and the secondary address goes in the upper 8-bits. 233 | */ 234 | #define MakeAddr(pad, sad) ((Addr4882_t)(((pad)&0xFF) | ((sad)<<8))) 235 | 236 | /* 237 | * This value is used to terminate an address list. It should be 238 | * assigned to the last entry. 239 | */ 240 | #define NOADDR (Addr4882_t)0xFFFF 241 | 242 | /* 243 | * The following two macros are used to "break apart" an address list 244 | * entry. They take an unsigned integer and return either the primary 245 | * or secondary address stored in the integer. 246 | */ 247 | #define GetPAD(val) ((val) & 0xFF) 248 | #define GetSAD(val) (((val) >> 8) & 0xFF) 249 | 250 | /* iblines constants */ 251 | 252 | #define ValidEOI (short)0x0080 253 | #define ValidATN (short)0x0040 254 | #define ValidSRQ (short)0x0020 255 | #define ValidREN (short)0x0010 256 | #define ValidIFC (short)0x0008 257 | #define ValidNRFD (short)0x0004 258 | #define ValidNDAC (short)0x0002 259 | #define ValidDAV (short)0x0001 260 | #define BusEOI (short)0x8000 261 | #define BusATN (short)0x4000 262 | #define BusSRQ (short)0x2000 263 | #define BusREN (short)0x1000 264 | #define BusIFC (short)0x0800 265 | #define BusNRFD (short)0x0400 266 | #define BusNDAC (short)0x0200 267 | #define BusDAV (short)0x0100 268 | 269 | /* Function prototypes */ 270 | 271 | extern int _far _cdecl ibask(int handle, int option, int _far *retval); 272 | extern int _far _cdecl ibbna(int handle, char _far *bdname); 273 | extern int _far _cdecl ibcac(int handle, int v); 274 | extern int _far _cdecl ibclr(int handle); 275 | extern int _far _cdecl ibcmd(int handle, void _far *buffer, long cnt); 276 | extern int _far _cdecl ibcmda(int handle, void _far *buffer, long cnt); 277 | extern int _far _cdecl ibconfig(int handle, int option, int value); 278 | extern int _far _cdecl ibdev(int boardID, int pad, int sad, int tmo, int eot, int eos); 279 | extern int _far _cdecl ibdma(int handle, int v); 280 | extern int _far _cdecl ibeos(int handle, int v); 281 | extern int _far _cdecl ibeot(int handle, int v); 282 | extern int _far _cdecl ibevent(int handle, short _far *event); 283 | extern int _far _cdecl ibfind(char _far *bdname); 284 | extern int _far _cdecl ibgts(int handle, int v); 285 | extern int _far _cdecl ibist(int handle, int v); 286 | extern int _far _cdecl iblines(int handle, short _far *lines); 287 | extern int _far _cdecl ibln(int handle, int padval, int sadval, short _far *listenflag); 288 | extern int _far _cdecl ibloc(int handle); 289 | extern int _far _cdecl ibonl(int handle, int v); 290 | extern int _far _cdecl ibpad(int handle, int v); 291 | extern int _far _cdecl ibpct(int handle); 292 | extern int _far _cdecl ibppc(int handle, int v); 293 | extern int _far _cdecl ibrd(int handle, void _far *buffer, long cnt); 294 | extern int _far _cdecl ibrda(int handle, void _far *buffer, long cnt); 295 | extern int _far _cdecl ibrdf(int handle, char _far *flname); 296 | extern int _far _cdecl ibrpp(int handle, char _far *ppr); 297 | extern int _far _cdecl ibrsc(int handle, int v); 298 | extern int _far _cdecl ibrsp(int handle, char _far *spr); 299 | extern int _far _cdecl ibrsv(int handle, int v); 300 | extern int _far _cdecl ibsad(int handle, int v); 301 | extern int _far _cdecl ibsic(int handle); 302 | extern int _far _cdecl ibsre(int handle, int v); 303 | extern void _far _cdecl ibsrq(void (_far *func)(void)); 304 | extern int _far _cdecl ibstop(int handle); 305 | extern int _far _cdecl ibtmo(int handle, int v); 306 | extern void _far _cdecl ibtrap(int mask, int mode); 307 | extern int _far _cdecl ibtrg(int handle); 308 | extern int _far _cdecl ibwait(int handle, int mask); 309 | extern int _far _cdecl ibwrt(int handle, void _far *buffer, long cnt); 310 | extern int _far _cdecl ibwrta(int handle, void _far *buffer, long cnt); 311 | extern int _far _cdecl ibwrtf(int handle, char _far *flname); 312 | 313 | extern int _far _cdecl ibpoke(int handle, int option, int value); 314 | extern int _far _cdecl ibdiag(int handle, void _far *buffer, long cnt); 315 | extern int _far _cdecl ibxtrc(int handle, void _far *buffer, long cnt); 316 | 317 | extern int _far _cdecl ibwrtkey(int handle, void _far *buffer, int cnt); 318 | extern int _far _cdecl ibrdkey(int handle, void _far *buffer, int cnt); 319 | 320 | 321 | extern void _far _cdecl AllSpoll(int boardID, Addr4882_t _far *addrlist, short _far *resultlist); 322 | extern void _far _cdecl DevClear(int boardID, Addr4882_t address); 323 | extern void _far _cdecl DevClearList(int boardID, Addr4882_t _far *addrlist); 324 | extern void _far _cdecl EnableLocal(int boardID, Addr4882_t _far *addrlist); 325 | extern void _far _cdecl EnableRemote(int boardID, Addr4882_t _far *addrlist); 326 | extern void _far _cdecl FindLstn(int boardID, Addr4882_t _far *padlist, Addr4882_t _far *resultlist, int limit); 327 | extern void _far _cdecl FindRQS(int boardID, Addr4882_t _far *addrlist, short _far *result); 328 | extern void _far _cdecl PPoll(int boardID, short _far *result); 329 | extern void _far _cdecl PPollConfig(int boardID, Addr4882_t address, int dataLine, int lineSense); 330 | extern void _far _cdecl PPollUnconfig(int boardID, Addr4882_t _far *addrlist); 331 | extern void _far _cdecl PassControl(int boardID, Addr4882_t address); 332 | extern void _far _cdecl RcvRespMsg(int boardID, void _far *buffer, long cnt, int termination); 333 | extern void _far _cdecl ReadStatusByte(int boardID, Addr4882_t address, short _far *result); 334 | extern void _far _cdecl Receive(int boardID, Addr4882_t address, void _far *buffer, long cnt, int termination); 335 | extern void _far _cdecl ReceiveSetup(int boardID, Addr4882_t address); 336 | extern void _far _cdecl ResetSys(int boardID, Addr4882_t _far *addrlist); 337 | extern void _far _cdecl Send(int boardID, Addr4882_t address, void _far *buffer, long datacnt, int eotmode); 338 | extern void _far _cdecl SendCmds(int boardID, void _far *buffer, long cnt); 339 | extern void _far _cdecl SendDataBytes(int boardID, void _far *buffer, long cnt, int eotmode); 340 | extern void _far _cdecl SendIFC(int boardID); 341 | extern void _far _cdecl SendLLO(int boardID); 342 | extern void _far _cdecl SendList(int boardID, Addr4882_t _far *addrlist, void _far *buffer, long datacnt, int eotmode); 343 | extern void _far _cdecl SendSetup(int boardID, Addr4882_t _far *addrlist); 344 | extern void _far _cdecl SetRWLS(int boardID, Addr4882_t _far *addrlist); 345 | extern void _far _cdecl TestSRQ(int boardID, short _far *result); 346 | extern void _far _cdecl TestSys(int boardID, Addr4882_t _far *addrlist, short _far *resultlist); 347 | extern void _far _cdecl Trigger(int boardID, Addr4882_t address); 348 | extern void _far _cdecl TriggerList(int boardID, Addr4882_t _far *addrlist); 349 | extern void _far _cdecl WaitSRQ(int boardID, short _far *result); 350 | 351 | extern void _far _cdecl GotoMultAddr(int boardID, 352 | unsigned short type, 353 | unsigned short (_far *addrfunc)(), 354 | unsigned short (_far *spollfunc)()); 355 | extern void _far _cdecl GenerateREQT(int boardID, unsigned short addr); 356 | extern void _far _cdecl GenerateREQF(int boardID, unsigned short addr); 357 | 358 | 359 | #ifdef __cplusplus 360 | } 361 | #endif 362 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/MCIB.LIB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.github/doslib/MCIB.LIB -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published by the 6 | Free Software Foundation; either version 2, or (at your option) any 7 | later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 | 18 | #ifndef _GETOPT_H 19 | #define _GETOPT_H 1 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* For communication from `getopt' to the caller. 26 | When `getopt' finds an option that takes an argument, 27 | the argument value is returned here. 28 | Also, when `ordering' is RETURN_IN_ORDER, 29 | each non-option ARGV-element is returned here. */ 30 | 31 | extern char *optarg; 32 | 33 | /* Index in ARGV of the next element to be scanned. 34 | This is used for communication to and from the caller 35 | and for communication between successive calls to `getopt'. 36 | 37 | On entry to `getopt', zero means this is the first call; initialize. 38 | 39 | When `getopt' returns EOF, this is the index of the first of the 40 | non-option elements that the caller should itself scan. 41 | 42 | Otherwise, `optind' communicates from one call to the next 43 | how much of ARGV has been scanned so far. */ 44 | 45 | extern int optind; 46 | 47 | /* Callers store zero here to inhibit the error message `getopt' prints 48 | for unrecognized options. */ 49 | 50 | extern int opterr; 51 | 52 | /* Set to an option character which was unrecognized. */ 53 | 54 | extern int optopt; 55 | 56 | /* Describe the long-named options requested by the application. 57 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 58 | of `struct option' terminated by an element containing a name which is 59 | zero. 60 | 61 | The field `has_arg' is: 62 | no_argument (or 0) if the option does not take an argument, 63 | required_argument (or 1) if the option requires an argument, 64 | optional_argument (or 2) if the option takes an optional argument. 65 | 66 | If the field `flag' is not NULL, it points to a variable that is set 67 | to the value given in the field `val' when the option is found, but 68 | left unchanged if the option is not found. 69 | 70 | To have a long-named option do something other than set an `int' to 71 | a compiled-in constant, such as set a value from `optarg', set the 72 | option's `flag' field to zero and its `val' field to a nonzero 73 | value (the equivalent single-letter option character, if there is 74 | one). For long options that have a zero `flag' field, `getopt' 75 | returns the contents of the `val' field. */ 76 | 77 | struct option 78 | { 79 | #if __STDC__ 80 | const char *name; 81 | #else 82 | char *name; 83 | #endif 84 | /* has_arg can't be an enum because some compilers complain about 85 | type mismatches in all the code that assumes it is an int. */ 86 | int has_arg; 87 | int *flag; 88 | int val; 89 | }; 90 | 91 | /* Names for the values of the `has_arg' field of `struct option'. */ 92 | 93 | #define no_argument 0 94 | #define required_argument 1 95 | #define optional_argument 2 96 | 97 | #if __STDC__ || defined(PROTO) 98 | #if defined(__GNU_LIBRARY__) 99 | /* Many other libraries have conflicting prototypes for getopt, with 100 | differences in the consts, in stdlib.h. To avoid compilation 101 | errors, only prototype getopt for the GNU C library. */ 102 | extern int getopt (int argc, char *const *argv, const char *shortopts); 103 | #endif /* not __GNU_LIBRARY__ */ 104 | extern int getopt_long (int argc, char *const *argv, const char *shortopts, 105 | const struct option *longopts, int *longind); 106 | 107 | 108 | extern int getopt_long_only (int argc, char *const *argv, 109 | const char *shortopts, 110 | const struct option *longopts, int *longind); 111 | 112 | /* Internal only. Users should not call this directly. */ 113 | extern int _getopt_internal (int argc, char *const *argv, 114 | const char *shortopts, 115 | const struct option *longopts, int *longind, 116 | int long_only); 117 | #else /* not __STDC__ */ 118 | extern int getopt (); 119 | extern int getopt_long (); 120 | extern int getopt_long_only (); 121 | 122 | extern int _getopt_internal (); 123 | #endif /* not __STDC__ */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* _GETOPT_H */ 130 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/notes.txt: -------------------------------------------------------------------------------- 1 | Extra files required to build a DOS .exe. 2 | 3 | **GPIB driver 4 | DECL.H, MCIB.LIB: from NI 2.7.2 driver for DOS; they provide a .LIB file in Microsof C format. 5 | 6 | **getopt 7 | tekfwtool needs libgetopt; easy to compile. 8 | source used: 9 | https://www.flashrom.org/File:Libgetopt.tar.gz 10 | 11 | **djgpp : 12 | There's apparently no way to convert MCIB.LIB to a format understood by djgpp-gcc, 13 | partly due to memory model issues 14 | 15 | ** MSC 16 | -compiling the whole thing with MS C (say v5) 17 | -solves the NI driver lib issue. 18 | -sizeof(size_t) == sizeof(unsigned int) !! code assumes 32bit int, anticipate problems 19 | -MSC5 make.exe v4 sucks 20 | -MSC6 nmake is different, but sucks also 21 | -lots of tweaks needed for 8.3 filenames and other garbage 22 | -MSC looks for its own "SLIBCE.LIB" ? wtf. Give it slibc7.lib 23 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDINT_H 2 | #define _STDINT_H 3 | 4 | #include 5 | 6 | #if (USHRT_MAX != 0xFFFFUL) 7 | #error Bad unsigned short ! 8 | #elif (ULONG_MAX != 0xFFFFFFFFUL) 9 | #error Bad unsigned long ! 10 | #endif 11 | 12 | typedef unsigned char uint8_t; 13 | typedef unsigned short uint16_t; 14 | typedef unsigned long uint32_t; 15 | 16 | 17 | #endif // _STDINT_H 18 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/doslib/tgtdummy.h: -------------------------------------------------------------------------------- 1 | #ifndef __TARGET_PROCS_H 2 | #define __TARGET_PROCS_H 3 | 4 | #define TARGET_flash_program 0 5 | #define TARGET_flash_erase 0 6 | #define TARGET_init 0 7 | #endif 8 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/gen-procs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "#ifndef __TARGET_PROCS_H" 4 | echo -e "#define __TARGET_PROCS_H\n" 5 | 6 | m68k-elf-nm target.elf|while read addr type name 7 | do 8 | #echo "[$name]" 9 | if [ $type == "t" -a $name != "gcc2_compiled." ]; then 10 | echo "#define TARGET_$name 0x$addr" 11 | fi 12 | done 13 | 14 | echo "#endif" 15 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/gpib-32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.github/gpib-32.obj -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/ni488.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * Include file for accessing the NI-488.2 API 5 | * 6 | * 7 | * Contains user variables (ibsta, iberr, ibcnt, ibcntl), 8 | * function prototypes and useful defined constants for 9 | * calling NI-488 and NI-488.2 routines from a C/C++ 10 | * application. 11 | * 12 | * 13 | * Copyright 2001 National Instruments Corporation 14 | * 15 | */ 16 | 17 | #ifndef NI488_H // ensure we are only included once 18 | #define NI488_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /***************************************************************************/ 25 | /* HANDY CONSTANTS FOR USE BY APPLICATION PROGRAMS ... */ 26 | /***************************************************************************/ 27 | #define UNL 0x3f /* GPIB unlisten command */ 28 | #define UNT 0x5f /* GPIB untalk command */ 29 | #define GTL 0x01 /* GPIB go to local */ 30 | #define SDC 0x04 /* GPIB selected device clear */ 31 | #define PPC 0x05 /* GPIB parallel poll configure */ 32 | #define GET 0x08 /* GPIB group execute trigger */ 33 | #define TCT 0x09 /* GPIB take control */ 34 | #define LLO 0x11 /* GPIB local lock out */ 35 | #define DCL 0x14 /* GPIB device clear */ 36 | #define PPU 0x15 /* GPIB parallel poll unconfigure */ 37 | #define SPE 0x18 /* GPIB serial poll enable */ 38 | #define SPD 0x19 /* GPIB serial poll disable */ 39 | #define PPE 0x60 /* GPIB parallel poll enable */ 40 | #define PPD 0x70 /* GPIB parallel poll disable */ 41 | 42 | /* GPIB status bit vector : */ 43 | /* global variable ibsta and wait mask */ 44 | 45 | #define ERR (1<<15) /* Error detected */ 46 | #define TIMO (1<<14) /* Timeout */ 47 | #define END (1<<13) /* EOI or EOS detected */ 48 | #define SRQI (1<<12) /* SRQ detected by CIC */ 49 | #define RQS (1<<11) /* Device needs service */ 50 | #define CMPL (1<<8) /* I/O completed */ 51 | #define LOK (1<<7) /* Local lockout state */ 52 | #define REM (1<<6) /* Remote state */ 53 | #define CIC (1<<5) /* Controller-in-Charge */ 54 | #define ATN (1<<4) /* Attention asserted */ 55 | #define TACS (1<<3) /* Talker active */ 56 | #define LACS (1<<2) /* Listener active */ 57 | #define DTAS (1<<1) /* Device trigger state */ 58 | #define DCAS (1<<0) /* Device clear state */ 59 | 60 | /* Error messages returned in global variable iberr */ 61 | 62 | #define EDVR 0 /* System error */ 63 | #define ECIC 1 /* Function requires GPIB board to be CIC */ 64 | #define ENOL 2 /* Write function detected no Listeners */ 65 | #define EADR 3 /* Interface board not addressed correctly */ 66 | #define EARG 4 /* Invalid argument to function call */ 67 | #define ESAC 5 /* Function requires GPIB board to be SAC */ 68 | #define EABO 6 /* I/O operation aborted */ 69 | #define ENEB 7 /* Non-existent interface board */ 70 | #define EDMA 8 /* Error performing DMA */ 71 | #define EOIP 10 /* I/O operation started before previous */ 72 | /* operation completed */ 73 | #define ECAP 11 /* No capability for intended operation */ 74 | #define EFSO 12 /* File system operation error */ 75 | #define EBUS 14 /* Command error during device call */ 76 | #define ESTB 15 /* Serial poll status byte lost */ 77 | #define ESRQ 16 /* SRQ remains asserted */ 78 | #define ETAB 20 /* The return buffer is full. */ 79 | #define ELCK 21 /* Address or board is locked. */ 80 | #define EARM 22 /* The ibnotify Callback failed to rearm */ 81 | #define EHDL 23 /* The input handle is invalid */ 82 | #define EWIP 26 /* Wait already in progress on input ud */ 83 | #define ERST 27 /* The event notification was cancelled */ 84 | /* due to a reset of the interface */ 85 | #define EPWR 28 /* The system or board has lost power or */ 86 | /* gone to standby */ 87 | 88 | /* Warning messages returned in global variable iberr */ 89 | 90 | #define WCFG 24 /* Configuration warning */ 91 | #define ECFG WCFG 92 | 93 | /* EOS mode bits */ 94 | 95 | #define BIN (1<<12) /* Eight bit compare */ 96 | #define XEOS (1<<11) /* Send END with EOS byte */ 97 | #define REOS (1<<10) /* Terminate read on EOS */ 98 | 99 | /* Timeout values and meanings */ 100 | 101 | #define TNONE 0 /* Infinite timeout (disabled) */ 102 | #define T10us 1 /* Timeout of 10 us (ideal) */ 103 | #define T30us 2 /* Timeout of 30 us (ideal) */ 104 | #define T100us 3 /* Timeout of 100 us (ideal) */ 105 | #define T300us 4 /* Timeout of 300 us (ideal) */ 106 | #define T1ms 5 /* Timeout of 1 ms (ideal) */ 107 | #define T3ms 6 /* Timeout of 3 ms (ideal) */ 108 | #define T10ms 7 /* Timeout of 10 ms (ideal) */ 109 | #define T30ms 8 /* Timeout of 30 ms (ideal) */ 110 | #define T100ms 9 /* Timeout of 100 ms (ideal) */ 111 | #define T300ms 10 /* Timeout of 300 ms (ideal) */ 112 | #define T1s 11 /* Timeout of 1 s (ideal) */ 113 | #define T3s 12 /* Timeout of 3 s (ideal) */ 114 | #define T10s 13 /* Timeout of 10 s (ideal) */ 115 | #define T30s 14 /* Timeout of 30 s (ideal) */ 116 | #define T100s 15 /* Timeout of 100 s (ideal) */ 117 | #define T300s 16 /* Timeout of 300 s (ideal) */ 118 | #define T1000s 17 /* Timeout of 1000 s (ideal) */ 119 | 120 | /* IBLN Constants */ 121 | #define NO_SAD 0 122 | #define ALL_SAD -1 123 | 124 | /* The following constants are used for the second parameter of the 125 | * ibconfig function. They are the "option" selection codes. 126 | */ 127 | #define IbcPAD 0x0001 /* Primary Address */ 128 | #define IbcSAD 0x0002 /* Secondary Address */ 129 | #define IbcTMO 0x0003 /* Timeout Value */ 130 | #define IbcEOT 0x0004 /* Send EOI with last data byte? */ 131 | #define IbcPPC 0x0005 /* Parallel Poll Configure */ 132 | #define IbcREADDR 0x0006 /* Repeat Addressing */ 133 | #define IbcAUTOPOLL 0x0007 /* Disable Auto Serial Polling */ 134 | #define IbcCICPROT 0x0008 /* Use the CIC Protocol? */ 135 | #define IbcIRQ 0x0009 /* Use PIO for I/O */ 136 | #define IbcSC 0x000A /* Board is System Controller? */ 137 | #define IbcSRE 0x000B /* Assert SRE on device calls? */ 138 | #define IbcEOSrd 0x000C /* Terminate reads on EOS */ 139 | #define IbcEOSwrt 0x000D /* Send EOI with EOS character */ 140 | #define IbcEOScmp 0x000E /* Use 7 or 8-bit EOS compare */ 141 | #define IbcEOSchar 0x000F /* The EOS character. */ 142 | #define IbcPP2 0x0010 /* Use Parallel Poll Mode 2. */ 143 | #define IbcTIMING 0x0011 /* NORMAL, HIGH, or VERY_HIGH timing. */ 144 | #define IbcDMA 0x0012 /* Use DMA for I/O */ 145 | #define IbcReadAdjust 0x0013 /* Swap bytes during an ibrd. */ 146 | #define IbcWriteAdjust 0x014 /* Swap bytes during an ibwrt. */ 147 | #define IbcSendLLO 0x0017 /* Enable/disable the sending of LLO. */ 148 | #define IbcSPollTime 0x0018 /* Set the timeout value for serial polls. */ 149 | #define IbcPPollTime 0x0019 /* Set the parallel poll length period. */ 150 | #define IbcEndBitIsNormal 0x001A /* Remove EOS from END bit of IBSTA. */ 151 | #define IbcUnAddr 0x001B /* Enable/disable device unaddressing. */ 152 | #define IbcSignalNumber 0x001C /* Set UNIX signal number - unsupported */ 153 | #define IbcBlockIfLocked 0x001D /* Enable/disable blocking for locked boards/devices */ 154 | #define IbcHSCableLength 0x001F /* Length of cable specified for high speed timing.*/ 155 | #define IbcIst 0x0020 /* Set the IST bit. */ 156 | #define IbcRsv 0x0021 /* Set the RSV byte. */ 157 | #define IbcLON 0x0022 /* Enter listen only mode */ 158 | 159 | /* 160 | * Constants that can be used (in addition to the ibconfig constants) 161 | * when calling the ibask() function. 162 | */ 163 | 164 | #define IbaPAD IbcPAD 165 | #define IbaSAD IbcSAD 166 | #define IbaTMO IbcTMO 167 | #define IbaEOT IbcEOT 168 | #define IbaPPC IbcPPC 169 | #define IbaREADDR IbcREADDR 170 | #define IbaAUTOPOLL IbcAUTOPOLL 171 | #define IbaCICPROT IbcCICPROT 172 | #define IbaIRQ IbcIRQ 173 | #define IbaSC IbcSC 174 | #define IbaSRE IbcSRE 175 | #define IbaEOSrd IbcEOSrd 176 | #define IbaEOSwrt IbcEOSwrt 177 | #define IbaEOScmp IbcEOScmp 178 | #define IbaEOSchar IbcEOSchar 179 | #define IbaPP2 IbcPP2 180 | #define IbaTIMING IbcTIMING 181 | #define IbaDMA IbcDMA 182 | #define IbaReadAdjust IbcReadAdjust 183 | #define IbaWriteAdjust IbcWriteAdjust 184 | #define IbaSendLLO IbcSendLLO 185 | #define IbaSPollTime IbcSPollTime 186 | #define IbaPPollTime IbcPPollTime 187 | #define IbaEndBitIsNormal IbcEndBitIsNormal 188 | #define IbaUnAddr IbcUnAddr 189 | #define IbaSignalNumber IbcSignalNumber 190 | #define IbaBlockIfLocked IbcBlockIfLocked 191 | #define IbaHSCableLength IbcHSCableLength 192 | #define IbaIst IbcIst 193 | #define IbaRsv IbcRsv 194 | #define IbaLON IbcLON 195 | #define IbaSerialNumber 0x0023 196 | 197 | #define IbaBNA 0x0200 /* A device's access board. */ 198 | 199 | 200 | /* Values used by the Send 488.2 command. */ 201 | #define NULLend 0x00 /* Do nothing at the end of a transfer.*/ 202 | #define NLend 0x01 /* Send NL with EOI after a transfer. */ 203 | #define DABend 0x02 /* Send EOI with the last DAB. */ 204 | 205 | /* Value used by the 488.2 Receive command. 206 | */ 207 | #define STOPend 0x0100 208 | 209 | 210 | /* Address type (for 488.2 calls) */ 211 | 212 | typedef short Addr4882_t; /* System dependent: must be 16 bits */ 213 | 214 | /* 215 | * This macro can be used to easily create an entry in address list 216 | * that is required by many of the 488.2 functions. The primary address goes in the 217 | * lower 8-bits and the secondary address goes in the upper 8-bits. 218 | */ 219 | #define MakeAddr(pad, sad) ((Addr4882_t)(((pad)&0xFF) | ((sad)<<8))) 220 | 221 | /* 222 | * This value is used to terminate an address list. It should be 223 | * assigned to the last entry. 224 | */ 225 | #ifndef NOADDR 226 | #define NOADDR (Addr4882_t)((unsigned short)0xFFFF) 227 | #endif 228 | 229 | /* 230 | * The following two macros are used to "break apart" an address list 231 | * entry. They take an unsigned integer and return either the primary 232 | * or secondary address stored in the integer. 233 | */ 234 | #define GetPAD(val) ((val) & 0xFF) 235 | #define GetSAD(val) (((val) >> 8) & 0xFF) 236 | 237 | /* iblines constants */ 238 | 239 | #define ValidEOI (short)0x0080 240 | #define ValidATN (short)0x0040 241 | #define ValidSRQ (short)0x0020 242 | #define ValidREN (short)0x0010 243 | #define ValidIFC (short)0x0008 244 | #define ValidNRFD (short)0x0004 245 | #define ValidNDAC (short)0x0002 246 | #define ValidDAV (short)0x0001 247 | #define BusEOI (short)0x8000 248 | #define BusATN (short)0x4000 249 | #define BusSRQ (short)0x2000 250 | #define BusREN (short)0x1000 251 | #define BusIFC (short)0x0800 252 | #define BusNRFD (short)0x0400 253 | #define BusNDAC (short)0x0200 254 | #define BusDAV (short)0x0100 255 | 256 | /**** 257 | **** typedef for ibnotify callback **** 258 | ****/ 259 | typedef int (__stdcall * GpibNotifyCallback_t)(int, int, int, long, PVOID); 260 | 261 | /*************************************************************************/ 262 | /* */ 263 | /* iblockx and ibunlockx definitions --- deprecated, use iblck */ 264 | /* */ 265 | /*************************************************************************/ 266 | #define TIMMEDIATE -1 267 | #define TINFINITE -2 268 | #define MAX_LOCKSHARENAME_LENGTH 64 269 | 270 | #if defined(UNICODE) 271 | #define iblockx iblockxW 272 | #else 273 | #define iblockx iblockxA 274 | #endif 275 | 276 | extern int __stdcall iblockxA (int ud, int LockWaitTime, PCHAR LockShareName); 277 | extern int __stdcall iblockxW (int ud, int LockWaitTime, PWCHAR LockShareName); 278 | extern int __stdcall ibunlockx (int ud); 279 | 280 | 281 | /***************************************************************************/ 282 | /* IBSTA, IBERR, IBCNT, IBCNTL and FUNCTION PROTOTYPES */ 283 | /* ( only included if not accessing the 32-bit DLL directly ) */ 284 | /***************************************************************************/ 285 | #if !defined(GPIB_DIRECT_ACCESS) 286 | 287 | /* 288 | * Set up access to the user variables (ibsta, iberr, ibcnt, ibcntl). 289 | * These are declared and exported by the 32-bit DLL. Separate copies 290 | * exist for each process that accesses the DLL. They are shared by 291 | * multiple threads of a single process. 292 | */ 293 | 294 | extern int ibsta; 295 | extern int iberr; 296 | extern int ibcnt; 297 | extern long ibcntl; 298 | 299 | #if defined(UNICODE) 300 | #define ibbna ibbnaW 301 | #define ibfind ibfindW 302 | #define ibrdf ibrdfW 303 | #define ibwrtf ibwrtfW 304 | #else 305 | #define ibbna ibbnaA 306 | #define ibfind ibfindA 307 | #define ibrdf ibrdfA 308 | #define ibwrtf ibwrtfA 309 | #endif 310 | 311 | /* 312 | * Extern 32-bit GPIB DLL functions 313 | */ 314 | 315 | /* NI-488 Function Prototypes */ 316 | extern int __stdcall ibfindA (LPCSTR udname); 317 | extern int __stdcall ibbnaA (int ud, LPCSTR udname); 318 | extern int __stdcall ibrdfA (int ud, LPCSTR filename); 319 | extern int __stdcall ibwrtfA (int ud, LPCSTR filename); 320 | 321 | extern int __stdcall ibfindW (LPCWSTR udname); 322 | extern int __stdcall ibbnaW (int ud, LPCWSTR udname); 323 | extern int __stdcall ibrdfW (int ud, LPCWSTR filename); 324 | extern int __stdcall ibwrtfW (int ud, LPCWSTR filename); 325 | 326 | extern int __stdcall ibask (int ud, int option, PINT v); 327 | extern int __stdcall ibcac (int ud, int v); 328 | extern int __stdcall ibclr (int ud); 329 | extern int __stdcall ibcmd (int ud, PVOID buf, long cnt); 330 | extern int __stdcall ibcmda (int ud, PVOID buf, long cnt); 331 | extern int __stdcall ibconfig (int ud, int option, int v); 332 | extern int __stdcall ibdev (int boardID, int pad, int sad, int tmo, int eot, int eos); 333 | extern int __stdcall ibdiag (int ud, PVOID buf, long cnt); 334 | extern int __stdcall ibdma (int ud, int v); 335 | extern int __stdcall ibexpert (int ud, int option, void * Input, void * Output); 336 | extern int __stdcall ibeos (int ud, int v); 337 | extern int __stdcall ibeot (int ud, int v); 338 | extern int __stdcall ibgts (int ud, int v); 339 | extern int __stdcall ibist (int ud, int v); 340 | extern int __stdcall iblck (int ud, int v, unsigned int LockWaitTime, void * Reserved); 341 | extern int __stdcall iblines (int ud, PSHORT result); 342 | extern int __stdcall ibln (int ud, int pad, int sad, PSHORT listen); 343 | extern int __stdcall ibloc (int ud); 344 | extern int __stdcall ibnotify (int ud, int mask, GpibNotifyCallback_t Callback, PVOID RefData); 345 | extern int __stdcall ibonl (int ud, int v); 346 | extern int __stdcall ibpad (int ud, int v); 347 | extern int __stdcall ibpct (int ud); 348 | extern int __stdcall ibpoke (int ud, long option, long v); 349 | extern int __stdcall ibppc (int ud, int v); 350 | extern int __stdcall ibrd (int ud, PVOID buf, long cnt); 351 | extern int __stdcall ibrda (int ud, PVOID buf, long cnt); 352 | extern int __stdcall ibrpp (int ud, PCHAR ppr); 353 | extern int __stdcall ibrsc (int ud, int v); 354 | extern int __stdcall ibrsp (int ud, PCHAR spr); 355 | extern int __stdcall ibrsv (int ud, int v); 356 | extern int __stdcall ibsad (int ud, int v); 357 | extern int __stdcall ibsic (int ud); 358 | extern int __stdcall ibsre (int ud, int v); 359 | extern int __stdcall ibstop (int ud); 360 | extern int __stdcall ibtmo (int ud, int v); 361 | extern int __stdcall ibtrg (int ud); 362 | extern int __stdcall ibwait (int ud, int mask); 363 | extern int __stdcall ibwrt (int ud, PVOID buf, long cnt); 364 | extern int __stdcall ibwrta (int ud, PVOID buf, long cnt); 365 | 366 | // GPIB-ENET only functions to support locking across machines 367 | // Deprecated - Use iblck 368 | extern int __stdcall iblock (int ud); 369 | extern int __stdcall ibunlock (int ud); 370 | 371 | /**************************************************************************/ 372 | /* Functions to access Thread-Specific copies of the GPIB global vars */ 373 | 374 | extern int __stdcall ThreadIbsta (void); 375 | extern int __stdcall ThreadIberr (void); 376 | extern int __stdcall ThreadIbcnt (void); 377 | extern long __stdcall ThreadIbcntl (void); 378 | 379 | 380 | /**************************************************************************/ 381 | /* NI-488.2 Function Prototypes */ 382 | 383 | extern void __stdcall AllSpoll (int boardID, Addr4882_t * addrlist, PSHORT results); 384 | extern void __stdcall DevClear (int boardID, Addr4882_t addr); 385 | extern void __stdcall DevClearList (int boardID, Addr4882_t * addrlist); 386 | extern void __stdcall EnableLocal (int boardID, Addr4882_t * addrlist); 387 | extern void __stdcall EnableRemote (int boardID, Addr4882_t * addrlist); 388 | extern void __stdcall FindLstn (int boardID, Addr4882_t * addrlist, Addr4882_t * results, int limit); 389 | extern void __stdcall FindRQS (int boardID, Addr4882_t * addrlist, PSHORT dev_stat); 390 | extern void __stdcall PPoll (int boardID, PSHORT result); 391 | extern void __stdcall PPollConfig (int boardID, Addr4882_t addr, int dataLine, int lineSense); 392 | extern void __stdcall PPollUnconfig (int boardID, Addr4882_t * addrlist); 393 | extern void __stdcall PassControl (int boardID, Addr4882_t addr); 394 | extern void __stdcall RcvRespMsg (int boardID, PVOID buffer, long cnt, int Termination); 395 | extern void __stdcall ReadStatusByte(int boardID, Addr4882_t addr, PSHORT result); 396 | extern void __stdcall Receive (int boardID, Addr4882_t addr, PVOID buffer, long cnt, int Termination); 397 | extern void __stdcall ReceiveSetup (int boardID, Addr4882_t addr); 398 | extern void __stdcall ResetSys (int boardID, Addr4882_t * addrlist); 399 | extern void __stdcall Send (int boardID, Addr4882_t addr, PVOID databuf, long datacnt, int eotMode); 400 | extern void __stdcall SendCmds (int boardID, PVOID buffer, long cnt); 401 | extern void __stdcall SendDataBytes (int boardID, PVOID buffer, long cnt, int eot_mode); 402 | extern void __stdcall SendIFC (int boardID); 403 | extern void __stdcall SendLLO (int boardID); 404 | extern void __stdcall SendList (int boardID, Addr4882_t * addrlist, PVOID databuf, long datacnt, int eotMode); 405 | extern void __stdcall SendSetup (int boardID, Addr4882_t * addrlist); 406 | extern void __stdcall SetRWLS (int boardID, Addr4882_t * addrlist); 407 | extern void __stdcall TestSRQ (int boardID, PSHORT result); 408 | extern void __stdcall TestSys (int boardID, Addr4882_t * addrlist, PSHORT results); 409 | extern void __stdcall Trigger (int boardID, Addr4882_t addr); 410 | extern void __stdcall TriggerList (int boardID, Addr4882_t * addrlist); 411 | extern void __stdcall WaitSRQ (int boardID, PSHORT result); 412 | 413 | #endif 414 | 415 | 416 | #ifdef __cplusplus 417 | } 418 | #endif 419 | 420 | 421 | #endif // NI488_H 422 | 423 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/target.c: -------------------------------------------------------------------------------- 1 | typedef unsigned char uint8_t; 2 | typedef unsigned short uint16_t; 3 | typedef unsigned int uint32_t; 4 | 5 | #define NULL (void *)0 6 | #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(_x[0])) 7 | 8 | uint32_t bss_begin, bss_end; 9 | 10 | void (*_console_log)(char *fmt, ...) = (void *)0x16ba; 11 | 12 | #define console_log 13 | //_console_log 14 | struct gpib_hdr { 15 | uint8_t cmd; 16 | uint8_t csum; 17 | uint16_t len; 18 | }; 19 | 20 | struct gpib_flash_program_cmd { 21 | uint32_t arg0; 22 | uint32_t arg1; 23 | uint32_t function; 24 | uint32_t *base; 25 | uint32_t data[128]; 26 | }; 27 | 28 | struct gpib_flash_erase_cmd { 29 | struct gpib_hdr *hdr; 30 | uint32_t *base; 31 | }; 32 | 33 | struct flash_descriptor { 34 | uint8_t manufacturer; 35 | uint8_t device; 36 | uint32_t size; 37 | uint32_t blocksize; 38 | int (*erase_chip)(uint32_t *base); 39 | int (*program_single)(uint32_t *base, uint32_t data); 40 | int (*program_page)(uint32_t *base, uint32_t *data, uint16_t len); 41 | }; 42 | 43 | static struct flash_descriptor *current_flash; 44 | 45 | static void _memset(void *dst, char c, int len) 46 | { 47 | int unaligned = len % 4; 48 | char *dst8 = (char *)dst; 49 | uint32_t *dst32 = (uint32_t *)dst; 50 | char c32; 51 | 52 | while(unaligned--) { 53 | *dst8++ = c; 54 | len--; 55 | } 56 | 57 | c32 = (c << 24) | (c << 16) | (c << 8) | c; 58 | len /= 4; 59 | 60 | while(len--) 61 | *dst32++ = c32; 62 | } 63 | 64 | static void udelay(int delay) 65 | { 66 | volatile int i; 67 | for(i = 0; i < delay; i++); 68 | } 69 | 70 | static int flash_wait_sr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 71 | { 72 | uint32_t buf; 73 | uint32_t _mask = (mask << 16) | mask; 74 | uint32_t _result = (result << 16) | result; 75 | int ret = -1; 76 | 77 | while(tries--) { 78 | //console_log("flash_wait_sr: %08x: %08x\n", base, *(uint32_t *)base); 79 | if (*base & _mask == _result) 80 | break; 81 | 82 | udelay(10000); 83 | } 84 | 85 | if (!tries) { 86 | console_log("flash_wait_gsr timeout\n"); 87 | return -1; 88 | } 89 | ret = 0; 90 | out: 91 | return ret; 92 | } 93 | 94 | static int flash_wait_gsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 95 | { 96 | uint32_t buf; 97 | uint32_t _mask = (mask << 16) | mask; 98 | uint32_t _result = (result << 16) | result; 99 | int ret = -1; 100 | 101 | base = (uint32_t *)(((uint32_t)base) & ~0x1fffff); 102 | base += 2; 103 | 104 | while(tries--) { 105 | console_log("flash_wait_gsr: %08x: %08x\n", base, *(uint32_t *)base); 106 | if ((*base & _mask) == _result) 107 | break; 108 | 109 | udelay(10); 110 | } 111 | 112 | if (!tries) { 113 | console_log("flash_wait_gsr timeout\n"); 114 | return -1; 115 | } 116 | ret = 0; 117 | out: 118 | return ret; 119 | } 120 | 121 | static int flash_wait_bsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 122 | { 123 | uint32_t buf; 124 | uint32_t _mask = (mask << 16) | mask; 125 | uint32_t _result = (result << 16) | result; 126 | int ret = -1; 127 | 128 | base = (uint32_t *)(((uint32_t)base) & ~0x1ffff); 129 | base += 1; 130 | 131 | while(tries--) { 132 | console_log("flash_wait_bsr: %08x: %08x (mask %08x/%08x\n", base, *base, _mask, _result); 133 | if ((*base & _mask) == _result) 134 | break; 135 | udelay(10); 136 | } 137 | 138 | if (!tries) 139 | return -1; 140 | ret = 0; 141 | out: 142 | return ret; 143 | } 144 | 145 | 146 | static int flash_erase_intel_s5(uint32_t *base) 147 | { 148 | *base = 0x30303030; 149 | *base = 0xd0d0d0d0; 150 | 151 | if (flash_wait_sr(base, 0x0080, 0x0080, 0x100000) == -1) 152 | return -1; 153 | 154 | *base = 0xffffffff; 155 | return 0; 156 | } 157 | 158 | static int flash_erase_intel_sa(uint32_t *base) 159 | { 160 | *base = 0xa7a7a7a7; 161 | *base = 0xd0d0d0d0; 162 | 163 | if (flash_wait_gsr(base, 0x0080, 0x0080, 0x100000) == -1) 164 | return -1; 165 | 166 | *base = 0xffffffff; 167 | return 0; 168 | } 169 | 170 | static uint8_t csum_hdr(struct gpib_hdr *hdr) 171 | { 172 | int i, csum; 173 | uint8_t *buf = (uint8_t *)&hdr; 174 | 175 | csum = buf[0]; 176 | 177 | for(i = 2; i < hdr->len + sizeof(struct gpib_hdr) - 2; i++) 178 | csum += buf[i]; 179 | return csum; 180 | } 181 | 182 | static int flash_load_to_pagebuffer_intel_sa(uint32_t *base, uint32_t *data) 183 | { 184 | uint32_t *buf; 185 | int i,ret = -1; 186 | 187 | *base = 0x71717171; 188 | 189 | if (flash_wait_gsr(base, 0x0004, 0x0004, 0x100000) == -1) 190 | goto out; 191 | 192 | *base = 0xe0e0e0e0; 193 | 194 | *base = 0x007f007f; 195 | *base = 0x00000000; 196 | 197 | buf = (uint32_t *)data; 198 | 199 | for(i = 0; i < 128; i++) 200 | *base++ = *buf++; 201 | ret = 0; 202 | out: 203 | *base = 0xffffffff; 204 | return ret; 205 | } 206 | 207 | static int flash_write_pagebuffer_intel_sa(uint32_t *base) 208 | { 209 | int ret = -1; 210 | uint32_t buf; 211 | 212 | *base = 0x71717171; 213 | 214 | if (flash_wait_bsr(base, 0x0008, 0x0000, 0x100000) == -1) 215 | goto out; 216 | 217 | *base = 0x0c0c0c0c; 218 | 219 | *base = 0x007f007f; 220 | *base = 0x00000000; 221 | 222 | *base = 0x71717171; 223 | 224 | if (flash_wait_bsr(base, 0x0080, 0x0080, 0x100000) == -1) 225 | goto out; 226 | 227 | *base = 0xffffffff; 228 | *base = 0xffffffff; 229 | ret = 0; 230 | out: 231 | return ret; 232 | 233 | } 234 | 235 | static void flash_erase(struct gpib_hdr *hdr) 236 | { 237 | struct gpib_flash_erase_cmd *cmd = (struct gpib_flash_erase_cmd *)hdr; 238 | uint32_t *base = (uint32_t *)0x01000000; 239 | 240 | console_log("flash_erase\n"); 241 | _memset(hdr, 0, sizeof(hdr)); 242 | hdr->cmd = '-'; 243 | 244 | if (!current_flash) 245 | goto out; 246 | 247 | if (current_flash->erase_chip(base) == -1) { 248 | console_log("flash_erase failed\n"); 249 | goto out; 250 | } 251 | 252 | hdr->cmd = 'P'; 253 | out: 254 | *base = 0xffffffff; 255 | hdr->csum = csum_hdr(hdr); 256 | 257 | } 258 | 259 | static int flash_program_single_cmd40(uint32_t *base, uint32_t data) 260 | { 261 | int i, ret = -1; 262 | 263 | *base = 0x40404040; 264 | *base = data; 265 | 266 | if (flash_wait_gsr(base, 0x0080, 0x0080, 1000) == -1) 267 | goto out; 268 | 269 | out: 270 | *base = 0xffffffff; 271 | } 272 | 273 | static int flash_program_page_intel_sa(uint32_t *base, uint32_t *data) 274 | { 275 | if (flash_load_to_pagebuffer_intel_sa(base, data) == -1) 276 | goto out; 277 | 278 | if (flash_write_pagebuffer_intel_sa(base) == -1) 279 | goto out; 280 | 281 | *base = 0x50505050; 282 | *base = 0xffffffff; 283 | return 0; 284 | out: 285 | return -1; 286 | } 287 | 288 | struct cmd_params { 289 | struct gpib_hdr hdr; 290 | struct gpib_flash_program_cmd *cmd; 291 | }; 292 | 293 | static void flash_program(struct cmd_params *params) 294 | { 295 | int i, ret = -1; 296 | uint32_t *base = params->cmd->base; 297 | uint32_t len = params->hdr.len - 16; 298 | uint32_t offset = 0; 299 | 300 | // console_log("flash_program: %d bytes @ %08x\n", len, base); 301 | 302 | _memset(¶ms->hdr, 0, sizeof(struct gpib_hdr)); 303 | params->hdr.cmd = '-'; 304 | 305 | if (!current_flash) 306 | goto out; 307 | 308 | if (len < 0) 309 | goto out; 310 | 311 | 312 | if (current_flash->program_page) { 313 | while (len >= 512) { 314 | current_flash->program_page(base + offset, params->cmd->data + offset, 512); 315 | len -= 512; 316 | offset += 512; 317 | } 318 | } 319 | 320 | len /= 4; 321 | for(i = 0; i < len; i++) { 322 | current_flash->program_single(base + offset, params->cmd->data[i]); 323 | offset += 4; 324 | } 325 | 326 | params->hdr.cmd = 'P'; 327 | out: 328 | *base = 0xffffffff; 329 | params->hdr.csum = csum_hdr(¶ms->hdr); 330 | } 331 | 332 | 333 | struct flash_descriptor flash_types[] = { 334 | /* Intel TE28F160S5 */ 335 | { .manufacturer = 0xb0, 336 | .device = 0xd0, 337 | .size = 0x200000, 338 | .blocksize = 0x200, 339 | .erase_chip = flash_erase_intel_s5, 340 | .program_single = flash_program_single_cmd40, 341 | },{ 342 | /* Intel E28F016SA */ 343 | .manufacturer = 0x89, 344 | .device = 0xa0, 345 | .size = 0x200000, 346 | .blocksize = 0x200, 347 | .erase_chip = flash_erase_intel_sa, 348 | .program_single = flash_program_single_cmd40, 349 | .program_page = flash_program_page_intel_sa, 350 | } 351 | }; 352 | 353 | static uint32_t identify_flash(uint32_t *base) 354 | { 355 | uint32_t id; 356 | *base = 0x90909090; 357 | id = (*base & 0x00ff00ff) << 8; 358 | id |= (*(base+1) & 0x00ff00ff); 359 | *base = 0xffffffff; 360 | return id; 361 | } 362 | 363 | static struct flash_descriptor *find_flash(void) 364 | { 365 | uint32_t id; 366 | int i; 367 | 368 | id = identify_flash((uint32_t *)0x01000000); 369 | if (id & 0xffff != (id >> 16) & 0xffff) 370 | return NULL; 371 | 372 | id &= 0xffff; 373 | 374 | for(i = 0; i < ARRAY_SIZE(flash_types); i++) { 375 | if ((flash_types[i].device == (id & 0xff)) && 376 | ((flash_types[i].manufacturer == (id >> 8)))) 377 | return flash_types + i; 378 | } 379 | console_log("Unknown flash with Vendor ID 0x%02X, Device ID 0x%02X\n", id >> 8, id & 0xff); 380 | return NULL; 381 | } 382 | 383 | static void init(struct gpib_hdr *hdr) 384 | { 385 | console_log("target init\n"); 386 | _memset(&bss_begin, 0, bss_end - bss_begin); 387 | 388 | current_flash = find_flash(); 389 | _memset(hdr, 0, sizeof(hdr)); 390 | if (current_flash) 391 | hdr->cmd = 'P'; 392 | else 393 | hdr->cmd = 'X'; 394 | hdr->csum = csum_hdr(hdr); 395 | } 396 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/target.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x05010000; 4 | .text : { *(.text) } 5 | _bss_begin = .; 6 | .bss : { *(.bss) } 7 | _bss_end = .; 8 | .data : { *(.data) } 9 | } 10 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/tekfwtool.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef __MSDOS__ 12 | #include "dosdefs.h" 13 | #include "tfdos.h" //simply tekfwtool.h renamed to 8.3-safe name 14 | #include "tgtdummy.h" 15 | #else 16 | #include "tekfwtool.h" 17 | #include "target-procs.h" 18 | #include 19 | #include "ni488.h" 20 | #endif 21 | 22 | 23 | #define DEFAULT_GPIBADDR 29 24 | 25 | int Dev; 26 | const char *ErrorMnemonic[] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", 27 | "ESAC", "EABO", "ENEB", "EDMA", "", 28 | "EOIP", "ECAP", "EFSO", "", "EBUS", 29 | "ESTB", "ESRQ", "", "", "", "ETAB"}; 30 | 31 | static int abort_requested = 0; 32 | static int debug; 33 | 34 | static void sigint_handler(int arg) 35 | { 36 | abort_requested = 1; 37 | } 38 | 39 | static void GPIBCleanup(int Dev, char* ErrorMsg) 40 | { 41 | printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n", 42 | ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]); 43 | if (Dev != -1) { 44 | printf("Cleanup: Taking device offline\n"); 45 | ibonl (Dev, 0); 46 | } 47 | } 48 | 49 | static int write_command(char *cmd) 50 | { 51 | ibwrt (Dev, cmd, strlen(cmd)); 52 | if (ibsta & ERR) 53 | return -1; 54 | return 0; 55 | } 56 | 57 | static int query(char *query, char *buf, int maxsize) 58 | { 59 | 60 | ibwrt (Dev, query, strlen(query)); 61 | if (ibsta & ERR) 62 | return -1; 63 | 64 | ibrd (Dev, buf, maxsize); 65 | if (ibsta & ERR) 66 | return -1; 67 | 68 | buf[ibcntl - 1] = '\0'; 69 | return ibcntl; 70 | } 71 | 72 | static void hexdump(void *_buf, int len) 73 | { 74 | int i; 75 | uint8_t *buf = (uint8_t *)_buf; 76 | for(i = 0; i < len; i++) 77 | fprintf(stderr, "%02X ", buf[i]); 78 | fprintf(stderr, "\n"); 79 | } 80 | 81 | static void build_csum(struct cmd_hdr *hdr) 82 | { 83 | uint8_t csum = 0; 84 | uint32_t i; 85 | for(i = 0; i < be16_to_cpu(hdr->len) + sizeof(struct cmd_hdr); i++) 86 | csum += ((uint8_t *)hdr)[i]; 87 | hdr->csum = csum; 88 | } 89 | 90 | static int write_memory(uint32_t addr, uint8_t *buf, int len) 91 | { 92 | struct memory_write_cmd cmd; 93 | struct cmd_hdr hdr; 94 | uint16_t responselen; 95 | char c; 96 | 97 | memset(&cmd, 0, sizeof(cmd)); 98 | cmd.hdr.cmd = 'M'; 99 | cmd.hdr.len = cpu_to_be16(len + 8); 100 | cmd.addr = cpu_to_be32(addr); 101 | cmd.len = cpu_to_be32(len); 102 | 103 | memcpy(cmd.buf, buf, len); 104 | 105 | build_csum((struct cmd_hdr *)&cmd); 106 | if (debug > 1) 107 | hexdump(&cmd, len + 12); 108 | 109 | ibwrt (Dev, &cmd, len + 12); 110 | if (ibsta & ERR) { 111 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 112 | return -1; 113 | } 114 | 115 | ibrd(Dev, &c, 1); 116 | if (ibcntl != 1 || c != '+') { 117 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 118 | return -1; 119 | } 120 | 121 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 122 | if (ibsta & ERR) { 123 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 124 | return -1; 125 | } 126 | 127 | if (ibcntl < (signed)sizeof(hdr)) { 128 | fprintf(stderr, "%s: short header\n", __FUNCTION__); 129 | return -1; 130 | } 131 | 132 | if (hdr.cmd != '=') { 133 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 134 | return -1; 135 | } 136 | c = '+'; 137 | ibwrt(Dev, &c, 1); 138 | return 0; 139 | } 140 | 141 | static int branch_cmd(uint32_t addr, uint32_t arg0, uint8_t *data, int *datalen) 142 | { 143 | struct branch_cmd cmd; 144 | uint8_t buf[1024]; 145 | struct cmd_hdr hdr; 146 | uint16_t responselen; 147 | char c; 148 | 149 | memset(&cmd, 0, sizeof(cmd)); 150 | cmd.hdr.cmd = 'B'; 151 | cmd.hdr.len = cpu_to_be16(16 + *datalen); 152 | cmd.function = cpu_to_be32(addr); 153 | // cmd.argc = cpu_to_be32(2); 154 | // cmd.unknown = cpu_to_be32(2); 155 | cmd.arg0 = cpu_to_be32(arg0); 156 | memcpy(&cmd.buffer, data, *datalen); 157 | 158 | build_csum((struct cmd_hdr *)&cmd); 159 | if (debug > 1) 160 | hexdump(&cmd, be16_to_cpu(cmd.hdr.len) + sizeof(struct cmd_hdr)); 161 | 162 | ibwrt (Dev, &cmd, 20 + *datalen); 163 | if (ibsta & ERR) { 164 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 165 | return -1; 166 | } 167 | 168 | ibrd(Dev, &c, 1); 169 | if (ibcntl != 1 || c != '+') { 170 | fprintf(stderr, "%s: response reading failed: ibcntl: %ld, %02x\n", __FUNCTION__, ibcntl, c); 171 | return -1; 172 | } 173 | 174 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 175 | if (ibsta & ERR) { 176 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 177 | return -1; 178 | } 179 | 180 | if (ibcntl < (signed)sizeof(hdr)) { 181 | fprintf(stderr, "%s: short header\n", __FUNCTION__); 182 | return -1; 183 | } 184 | 185 | if (debug > 1) 186 | hexdump(&hdr, 4); 187 | 188 | if (hdr.len) { 189 | printf("reading %u bytes\n", be16_to_cpu(hdr.len)); 190 | ibrd(Dev, buf, be16_to_cpu(hdr.len)); 191 | if (ibsta & ERR) { 192 | fprintf(stderr, "%s: reading of additional data failed\n", __FUNCTION__); 193 | return -1; 194 | } 195 | } 196 | 197 | if (hdr.len) 198 | hexdump(buf, be16_to_cpu(hdr.len)); 199 | 200 | if (hdr.cmd != 'P') { 201 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 202 | return -1; 203 | } 204 | c = '+'; 205 | ibwrt(Dev, &c, 1); 206 | return 0; 207 | } 208 | 209 | static int read_memory(uint32_t addr, uint8_t *buf, int len) 210 | { 211 | struct memory_read_cmd cmd; 212 | struct cmd_hdr hdr; 213 | int responselen; 214 | char c; 215 | 216 | memset(&cmd, 0, sizeof(cmd)); 217 | cmd.hdr.cmd = 'm'; 218 | cmd.hdr.len = cpu_to_be16(sizeof(cmd) - 4); 219 | cmd.addr = cpu_to_be32(addr); 220 | cmd.len = cpu_to_be32(len); 221 | 222 | build_csum((struct cmd_hdr *)&cmd); 223 | if (debug > 1) 224 | hexdump(&cmd, sizeof(cmd)); 225 | 226 | ibwrt (Dev, &cmd, sizeof(struct memory_read_cmd)); 227 | if (ibsta & ERR) { 228 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 229 | return -1; 230 | } 231 | 232 | ibrd(Dev, &c, 1); 233 | if (ibcntl != 1 || c != '+') { 234 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 235 | return -1; 236 | } 237 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 238 | if (ibsta & ERR) { 239 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 240 | return -1; 241 | } 242 | 243 | if (debug > 1) { 244 | hexdump(&hdr, sizeof(hdr)); 245 | } 246 | 247 | if (ibcntl < (signed)sizeof(hdr)) { 248 | fprintf(stderr, "%s: short header (ibcntl=%l)\n", __FUNCTION__, ibcntl); 249 | return -1; 250 | } 251 | 252 | if (hdr.cmd != '=') { 253 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 254 | return -1; 255 | } 256 | 257 | responselen = be16_to_cpu(hdr.len); 258 | 259 | if (responselen != len) { 260 | fprintf(stderr, "%s: short response (%d < %u)\n", 261 | __FUNCTION__, responselen, len); 262 | return -1; 263 | } 264 | ibrd(Dev, buf, responselen); 265 | if (ibsta & ERR || ibcntl < len) { 266 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 267 | return -1; 268 | } 269 | 270 | c = '+'; 271 | ibwrt(Dev, &c, 1); 272 | if (ibsta & ERR) { 273 | fprintf(stderr, "%s: unable to send ACK\n", __FUNCTION__); 274 | return -1; 275 | } 276 | 277 | return 0; 278 | } 279 | 280 | static struct option long_options[] = { 281 | { "addr", required_argument, 0, 'a' }, 282 | { "read", required_argument, 0, 'r' }, 283 | { "write", required_argument, 0, 'w' }, 284 | { "base", required_argument, 0, 'b' }, 285 | { "length", required_argument, 0, 'l' }, 286 | { "debug", no_argument, 0, 'd' }, 287 | { "flash-id", no_argument, 0, 'i' }, 288 | { "flash-erase", no_argument, 0, 'e' }, 289 | { "flash-program", required_argument, 0, 'p' }, 290 | { "help", no_argument, 0, 'h' }, 291 | { NULL, 0, 0, 0 } 292 | }; 293 | 294 | static void usage(void) 295 | { 296 | fprintf(stderr, "usage:\n" 297 | "--read -r read from memory to file\n" 298 | "--write -w read from file to memory\n" 299 | "--base -b base address for read/write/program\n" 300 | "--length -l length of data to be read or written\n" 301 | "--addr -a device's GPIB address (optional). Default 29\n" 302 | "--debug -d enable debug logging\n" 303 | "--flash-id -i print ID of flash chips\n" 304 | "--flash-erase -e erase flash at base address\n" 305 | "--flash-program -p program flash at base address\n" 306 | ""); 307 | } 308 | 309 | static uint32_t to_number(char *s) 310 | { 311 | uint32_t val; 312 | char *endp; 313 | 314 | if (*s == '0' && *(s+1) == 'x') { 315 | val = strtoul(s+2, &endp, 16); 316 | if (*endp != '\0') { 317 | fprintf(stderr, "failed to parse: [%s]\n", s); 318 | return 0; 319 | } 320 | } else { 321 | val = strtoul(s, &endp, 10); 322 | if (*endp != '\0') { 323 | fprintf(stderr, "failed to parse: [%s]\n", s); 324 | return 0; 325 | } 326 | } 327 | return val; 328 | } 329 | 330 | static int flash_program(uint32_t base, uint8_t *buf, int size) 331 | { 332 | int len = size; 333 | return branch_cmd(TARGET_flash_program, base, buf, &len); 334 | } 335 | 336 | static int flash_erase(uint32_t base) 337 | { 338 | int len = 0; 339 | printf("Erasing flash @ 0x%08lx\n", (unsigned long) base); 340 | return branch_cmd(TARGET_flash_erase, base, NULL, &len); 341 | } 342 | 343 | static int init_firmware(void) 344 | { 345 | int len = 0; 346 | return branch_cmd(TARGET_init, 0, NULL, &len); 347 | } 348 | 349 | static int download_firmware(void) 350 | { 351 | FILE *file = fopen("target.bin", "rb"); 352 | char buf[512]; 353 | size_t len, offset = 0; 354 | int ret = -1; 355 | 356 | if (!file) { 357 | fprintf(stderr, "failed to open target.bin: %s", strerror(errno)); 358 | return -1; 359 | } 360 | 361 | printf("Downloading firmware to scope\n"); 362 | while((len = fread(buf, 1, sizeof(buf), file)) > 0) { 363 | if (write_memory(TARGET_FIRMWARE_BASE + offset, (uint8_t *)&buf, len) == -1) { 364 | fprintf(stderr, "error downloading firmware\n"); 365 | goto out; 366 | } 367 | offset += len; 368 | } 369 | 370 | if (ferror(file)) { 371 | fprintf(stderr, "error reading firmware from file\n"); 372 | goto out; 373 | } 374 | 375 | printf("Pinging firmware\n"); 376 | if (init_firmware() == -1) { 377 | fprintf(stderr, "failed to ping firmware\n"); 378 | goto out; 379 | } 380 | printf("Firmware downloaded\n"); 381 | ret = 0; 382 | out: 383 | fclose(file); 384 | return ret; 385 | } 386 | 387 | int main(int argc, char **argv) 388 | { 389 | uint32_t len, addr, base = 0, length = 0; 390 | int devaddr = DEFAULT_GPIBADDR; 391 | char c; 392 | uint8_t buf[1024]; 393 | int val, optidx; 394 | FILE *file = NULL; 395 | int read_op = 0, write_op = 0, erase_flash_op = 0, flash_write_op = 0; 396 | int readlen, i; 397 | time_t start, now; 398 | 399 | while((c = getopt_long(argc, argv, "a:r:w:b:l:p:hied", 400 | long_options, &optidx)) != -1) { 401 | switch(c) { 402 | case 'h': 403 | usage(); 404 | return 0; 405 | case 'a': 406 | devaddr = (int) to_number(optarg); 407 | if ((devaddr < 0) || (devaddr > 30)) { 408 | printf("invalid GPIB address\n"); 409 | return 1; 410 | } 411 | break; 412 | case 'l': 413 | if (length) { 414 | fprintf(stderr, "length given twice"); 415 | return 1; 416 | } 417 | length = to_number(optarg); 418 | break; 419 | case 'b': 420 | if (base) { 421 | fprintf(stderr, "base given twice"); 422 | return 1; 423 | } 424 | base = to_number(optarg); 425 | break; 426 | case 'r': 427 | if (file) { 428 | fprintf(stderr, "read given twice"); 429 | return 1; 430 | } 431 | file = fopen(optarg, "wb"); 432 | if (!file) { 433 | fprintf(stderr, "failed to open output file: %s\n", strerror(errno)); 434 | return 1; 435 | 436 | } 437 | read_op = 1; 438 | break; 439 | case 'w': 440 | if (file) { 441 | fprintf(stderr, "read given twice"); 442 | return 1; 443 | } 444 | file = fopen(optarg, "rb"); 445 | if (!file) { 446 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 447 | return 1; 448 | 449 | } 450 | 451 | write_op = 1; 452 | break; 453 | case 'p': 454 | if (file) { 455 | fprintf(stderr, "read given twice"); 456 | return 1; 457 | } 458 | file = fopen(optarg, "rb"); 459 | if (!file) { 460 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 461 | return 1; 462 | 463 | } 464 | flash_write_op = 1; 465 | break; 466 | 467 | case 'e': 468 | erase_flash_op = 1; 469 | break; 470 | case 'd': 471 | debug++; 472 | break; 473 | default: 474 | usage(); 475 | goto bad_exit; 476 | } 477 | } 478 | if (optind <= 1) { 479 | usage(); 480 | return 1; 481 | } 482 | 483 | if (!read_op && !write_op && !erase_flash_op && !flash_write_op) { 484 | printf("No operation specified !\n"); 485 | usage(); 486 | goto bad_exit; 487 | } 488 | 489 | if (!length) { 490 | fprintf(stderr, "%s: length required\n", __FUNCTION__); 491 | goto bad_exit; 492 | } 493 | 494 | if ((erase_flash_op || flash_write_op) && (TARGET_init == 0)) { 495 | printf("Cannot flash: compiled without flash write support.\n"); 496 | goto bad_exit; 497 | } 498 | 499 | signal(SIGINT, sigint_handler); 500 | 501 | Dev = ibdev(0, devaddr, 0, T100s, 1, 0); 502 | if (ibsta & ERR) { 503 | printf("Unable to open device\nibsta = 0x%x iberr = %d\n", 504 | ibsta, iberr); 505 | goto bad_exit; 506 | } 507 | 508 | ibclr (Dev); 509 | if (ibsta & ERR) { 510 | GPIBCleanup(Dev, "Unable to clear device"); 511 | goto bad_exit; 512 | } 513 | 514 | if (erase_flash_op || flash_write_op) { 515 | if (download_firmware() == -1) 516 | goto bad_exit; 517 | } 518 | if (erase_flash_op) { 519 | flash_erase(base); 520 | return 0; 521 | } 522 | 523 | time(&start); 524 | for(addr = base; addr < base + length && !abort_requested;) { 525 | len = MIN(512, base + length - addr); 526 | if (read_op) { 527 | if (read_memory(addr, buf, len) == -1) 528 | goto bad_exit; 529 | 530 | if (fwrite(buf, 1, len, file) != len) { 531 | fprintf(stderr, "short fwrite\n"); 532 | goto bad_exit; 533 | } 534 | if ((addr % 0x1000) == 0) { 535 | time(&now); 536 | fprintf(stderr, "READ %08lx/%08lx, %3u%% %4ds\r", 537 | (unsigned long) (addr - base), (unsigned long) length, 538 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 539 | } 540 | 541 | addr += len; 542 | } else if (write_op) { 543 | readlen = fread(buf, 1, len, file); 544 | if (readlen == 0) 545 | break; 546 | 547 | if (readlen == -1) { 548 | fprintf(stderr, "fread: %s\n", strerror(errno)); 549 | goto bad_exit; 550 | } 551 | if (write_memory(addr, buf, readlen) == -1){ 552 | goto bad_exit; 553 | } 554 | if ((addr % 0x1000) == 0) { 555 | time(&now); 556 | fprintf(stderr, "WRITE %08lx/%08lx, %3u%% %4ds\r", 557 | (unsigned long) (addr - base), (unsigned long) length, 558 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 559 | } 560 | addr += readlen; 561 | } else if (flash_write_op) { 562 | len = MIN(512, base + length - addr); 563 | readlen = fread(buf, 1, len, file); 564 | if (readlen == 0) 565 | break; 566 | 567 | if (readlen == -1) { 568 | fprintf(stderr, "fread: %s\n", strerror(errno)); 569 | goto bad_exit; 570 | } 571 | 572 | if (flash_program(addr, buf, readlen) == -1) { 573 | fprintf(stderr, "flash programming failed\n"); 574 | goto bad_exit; 575 | } 576 | addr += readlen; 577 | if ((addr % 0x1000) == 0) { 578 | time(&now); 579 | fprintf(stderr, "FLASH WRITE %08lx/%08lx, %3u%% %4ds\r", 580 | (unsigned long) (addr - base), (unsigned long) length, 581 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 582 | } 583 | } else { 584 | fprintf(stderr, "either read or write required\n"); 585 | goto bad_exit; 586 | } 587 | } 588 | fprintf(stderr, "\n"); 589 | fclose(file); 590 | ibonl(Dev, 0); 591 | return 0; 592 | 593 | bad_exit: 594 | if (file) { 595 | fclose(file); 596 | } 597 | return 1; 598 | 599 | } 600 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/tekfwtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEKFW_TOOL_H 2 | #define __TEKFW_TOOL_H 3 | 4 | #include 5 | 6 | #define TARGET_FIRMWARE_BASE 0x05010000 7 | 8 | #ifndef BYTE_ORDER 9 | #error Unknown endianness ! 10 | #endif 11 | 12 | #if BYTE_ORDER == LITTLE_ENDIAN 13 | #define cpu_to_be16(_x) ((((uint16_t) (_x) & 0xff) << 8) | (((_x) >> 8) & 0xff)) 14 | #define be16_to_cpu cpu_to_be16 15 | #define cpu_to_be32(_x) (cpu_to_be16(((_x) >> 16) & 0xffff) | \ 16 | (cpu_to_be16(((uint32_t) (_x) & 0xffff)) << 16)) 17 | #define be32_to_cpu cpu_to_be32 18 | #else 19 | #define cpu_to_be16 20 | #define cpu_to_be32 21 | #define be16_to_cpu 22 | #define be32_to_cpu 23 | #endif 24 | 25 | #define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a)) 26 | 27 | struct cmd_hdr { 28 | uint8_t cmd; 29 | uint8_t csum; 30 | uint16_t len; 31 | }; 32 | 33 | struct memory_read_cmd { 34 | struct cmd_hdr hdr; 35 | uint32_t addr; 36 | uint32_t len; 37 | }; 38 | 39 | struct memory_write_cmd { 40 | struct cmd_hdr hdr; 41 | uint32_t addr; 42 | uint32_t len; 43 | uint8_t buf[1024]; 44 | }; 45 | 46 | struct branch_cmd { 47 | struct cmd_hdr hdr; 48 | uint32_t argc; 49 | uint32_t unknown; 50 | uint32_t function; 51 | uint32_t arg0; 52 | uint8_t buffer[512]; 53 | }; 54 | 55 | #define TARGET_FW_INIT 0 56 | #define TARGET_FW_FLASH_ERASE 1 57 | #define TARGET_FW_FLASH_PROGRAM 2 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.github/tfdos: -------------------------------------------------------------------------------- 1 | # Modified version to compile a DOS binary with native MS C6 compiler. 2 | # 3 | # v0 : uses dummy target-procs.h 4 | # To use : "nmake /f tfdos" 5 | # 6 | # Notes: 7 | # DOS sucks. 8.3 sucks. 8 | # 9 | # CL flags: 10 | # /Fc .COD source+asm listing 11 | # /Fs .LST source listing (prints compiler warnings inline) 12 | # 13 | # LINK flag: 14 | # /nod : don't link against default, for some reason it wants SLIBCE (emulated fpu) 15 | # 16 | 17 | cc=cl 18 | link=link 19 | cflags=/c /Idoslib /D__MSDOS__ /Fc 20 | 21 | 22 | tfdos.exe: tfdos.obj doslib\getopt.obj tfdos 23 | $(link) /nod \ 24 | tfdos.obj doslib\getopt.obj doslib\MCIB.LIB,\ 25 | tfdos.exe,tfdos.map,slibc7; 26 | 27 | tfdos.c: tekfwt~1.h tekfwt~2.c 28 | copy tekfwt~1.h tfdos.h 29 | copy tekfwt~2.c tfdos.c 30 | 31 | .c.obj: 32 | $(cc) $(cdebug) $(cflags) $(cvars) $*.c 33 | 34 | tfdos.obj: tfdos.c 35 | 36 | doslib\getopt.obj: doslib\getopt.c 37 | 38 | 39 | 40 | #can't do this 41 | #clean: 42 | # del *.obj 43 | # del tfdos.exe 44 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/Makefile: -------------------------------------------------------------------------------- 1 | CC=/cygdrive/c/mingw/bin/gcc 2 | CFLAGS=-Wextra -Wall -O2 -Wno-unused -ggdb 3 | M68K=m68k-elf- 4 | M68KCC=$(M68K)gcc 5 | M68CCKFLAGS=-Wall -Wextra -Os -ggdb 6 | M68KOBJCOPY=$(M68K)objcopy 7 | M68KNM=$(M68K)nm 8 | 9 | all: tekfwtool.exe target.bin 10 | 11 | 12 | tekfwtool.exe: tekfwtool.c target-procs.h 13 | $(CC) $(CFLAGS) ./gpib-32.obj -o $@ tekfwtool.c 14 | 15 | target.bin: target.elf 16 | $(M68KOBJCOPY) -O binary $< $@ 17 | 18 | target.elf: target.o target.ld 19 | $(M68KCC) -nostdlib -Wl,-T target.ld -o $@ target.o 20 | 21 | target-procs.h: target.elf gen-procs.sh 22 | ./gen-procs.sh >$@ 23 | 24 | target.o: target.c 25 | $(M68KCC) $(M68KCCFLAGS) -c -o $@ $< 26 | clean: 27 | rm -f tekfwtool.exe target.o target.elf target.bin 28 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/gen-procs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "#ifndef __TARGET_PROCS_H" 4 | echo -e "#define __TARGET_PROCS_H\n" 5 | 6 | m68k-elf-nm target.elf|while read addr type name 7 | do 8 | #echo "[$name]" 9 | if [ $type == "t" -a $name != "gcc2_compiled." ]; then 10 | echo "#define TARGET_$name 0x$addr" 11 | fi 12 | done 13 | 14 | echo "#endif" 15 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/gpib-32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/gpib-32.obj -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Index of /tekfwtool 5 | 6 | 7 |

Index of /tekfwtool

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory  -  
[   ]Makefile2013-02-15 19:47 634  
[   ]firmware-tds724d-v7.2e.bin2013-02-13 21:35 4.0M 
[   ]firmware-tds784d-v7.4e.bin2013-02-13 22:53 4.0M 
[   ]firmware-tds794d-v6.6e.bin2013-02-15 21:12 4.0M 
[TXT]gen-procs.sh2013-02-13 14:21 267  
[   ]gpib-32.obj2013-02-02 11:42 30K 
[TXT]ni488.h2013-02-02 11:39 19K 
[   ]reg2013-02-23 17:47 4  
[TXT]target-procs.h2013-02-15 22:50 788  
[   ]target.bin2013-02-13 22:44 1.9K 
[TXT]target.c2013-02-15 22:50 7.2K 
[   ]target.elf2013-02-13 22:44 11K 
[   ]target.ld2013-02-13 21:09 127  
[   ]target.o2013-02-15 22:50 3.9K 
[TXT]tekfwtool.c2013-02-23 17:45 12K 
[   ]tekfwtool.exe2013-02-13 22:44 99K 
[TXT]tekfwtool.h2013-02-13 22:37 1.0K 
[   ]tmp2013-02-21 21:55 4.0M 

32 |
Apache/2.4.29 (Ubuntu) Server at stackframe.org Port 443
33 | 34 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/ni488.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * Include file for accessing the NI-488.2 API 5 | * 6 | * 7 | * Contains user variables (ibsta, iberr, ibcnt, ibcntl), 8 | * function prototypes and useful defined constants for 9 | * calling NI-488 and NI-488.2 routines from a C/C++ 10 | * application. 11 | * 12 | * 13 | * Copyright 2001 National Instruments Corporation 14 | * 15 | */ 16 | 17 | #ifndef NI488_H // ensure we are only included once 18 | #define NI488_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /***************************************************************************/ 25 | /* HANDY CONSTANTS FOR USE BY APPLICATION PROGRAMS ... */ 26 | /***************************************************************************/ 27 | #define UNL 0x3f /* GPIB unlisten command */ 28 | #define UNT 0x5f /* GPIB untalk command */ 29 | #define GTL 0x01 /* GPIB go to local */ 30 | #define SDC 0x04 /* GPIB selected device clear */ 31 | #define PPC 0x05 /* GPIB parallel poll configure */ 32 | #define GET 0x08 /* GPIB group execute trigger */ 33 | #define TCT 0x09 /* GPIB take control */ 34 | #define LLO 0x11 /* GPIB local lock out */ 35 | #define DCL 0x14 /* GPIB device clear */ 36 | #define PPU 0x15 /* GPIB parallel poll unconfigure */ 37 | #define SPE 0x18 /* GPIB serial poll enable */ 38 | #define SPD 0x19 /* GPIB serial poll disable */ 39 | #define PPE 0x60 /* GPIB parallel poll enable */ 40 | #define PPD 0x70 /* GPIB parallel poll disable */ 41 | 42 | /* GPIB status bit vector : */ 43 | /* global variable ibsta and wait mask */ 44 | 45 | #define ERR (1<<15) /* Error detected */ 46 | #define TIMO (1<<14) /* Timeout */ 47 | #define END (1<<13) /* EOI or EOS detected */ 48 | #define SRQI (1<<12) /* SRQ detected by CIC */ 49 | #define RQS (1<<11) /* Device needs service */ 50 | #define CMPL (1<<8) /* I/O completed */ 51 | #define LOK (1<<7) /* Local lockout state */ 52 | #define REM (1<<6) /* Remote state */ 53 | #define CIC (1<<5) /* Controller-in-Charge */ 54 | #define ATN (1<<4) /* Attention asserted */ 55 | #define TACS (1<<3) /* Talker active */ 56 | #define LACS (1<<2) /* Listener active */ 57 | #define DTAS (1<<1) /* Device trigger state */ 58 | #define DCAS (1<<0) /* Device clear state */ 59 | 60 | /* Error messages returned in global variable iberr */ 61 | 62 | #define EDVR 0 /* System error */ 63 | #define ECIC 1 /* Function requires GPIB board to be CIC */ 64 | #define ENOL 2 /* Write function detected no Listeners */ 65 | #define EADR 3 /* Interface board not addressed correctly */ 66 | #define EARG 4 /* Invalid argument to function call */ 67 | #define ESAC 5 /* Function requires GPIB board to be SAC */ 68 | #define EABO 6 /* I/O operation aborted */ 69 | #define ENEB 7 /* Non-existent interface board */ 70 | #define EDMA 8 /* Error performing DMA */ 71 | #define EOIP 10 /* I/O operation started before previous */ 72 | /* operation completed */ 73 | #define ECAP 11 /* No capability for intended operation */ 74 | #define EFSO 12 /* File system operation error */ 75 | #define EBUS 14 /* Command error during device call */ 76 | #define ESTB 15 /* Serial poll status byte lost */ 77 | #define ESRQ 16 /* SRQ remains asserted */ 78 | #define ETAB 20 /* The return buffer is full. */ 79 | #define ELCK 21 /* Address or board is locked. */ 80 | #define EARM 22 /* The ibnotify Callback failed to rearm */ 81 | #define EHDL 23 /* The input handle is invalid */ 82 | #define EWIP 26 /* Wait already in progress on input ud */ 83 | #define ERST 27 /* The event notification was cancelled */ 84 | /* due to a reset of the interface */ 85 | #define EPWR 28 /* The system or board has lost power or */ 86 | /* gone to standby */ 87 | 88 | /* Warning messages returned in global variable iberr */ 89 | 90 | #define WCFG 24 /* Configuration warning */ 91 | #define ECFG WCFG 92 | 93 | /* EOS mode bits */ 94 | 95 | #define BIN (1<<12) /* Eight bit compare */ 96 | #define XEOS (1<<11) /* Send END with EOS byte */ 97 | #define REOS (1<<10) /* Terminate read on EOS */ 98 | 99 | /* Timeout values and meanings */ 100 | 101 | #define TNONE 0 /* Infinite timeout (disabled) */ 102 | #define T10us 1 /* Timeout of 10 us (ideal) */ 103 | #define T30us 2 /* Timeout of 30 us (ideal) */ 104 | #define T100us 3 /* Timeout of 100 us (ideal) */ 105 | #define T300us 4 /* Timeout of 300 us (ideal) */ 106 | #define T1ms 5 /* Timeout of 1 ms (ideal) */ 107 | #define T3ms 6 /* Timeout of 3 ms (ideal) */ 108 | #define T10ms 7 /* Timeout of 10 ms (ideal) */ 109 | #define T30ms 8 /* Timeout of 30 ms (ideal) */ 110 | #define T100ms 9 /* Timeout of 100 ms (ideal) */ 111 | #define T300ms 10 /* Timeout of 300 ms (ideal) */ 112 | #define T1s 11 /* Timeout of 1 s (ideal) */ 113 | #define T3s 12 /* Timeout of 3 s (ideal) */ 114 | #define T10s 13 /* Timeout of 10 s (ideal) */ 115 | #define T30s 14 /* Timeout of 30 s (ideal) */ 116 | #define T100s 15 /* Timeout of 100 s (ideal) */ 117 | #define T300s 16 /* Timeout of 300 s (ideal) */ 118 | #define T1000s 17 /* Timeout of 1000 s (ideal) */ 119 | 120 | /* IBLN Constants */ 121 | #define NO_SAD 0 122 | #define ALL_SAD -1 123 | 124 | /* The following constants are used for the second parameter of the 125 | * ibconfig function. They are the "option" selection codes. 126 | */ 127 | #define IbcPAD 0x0001 /* Primary Address */ 128 | #define IbcSAD 0x0002 /* Secondary Address */ 129 | #define IbcTMO 0x0003 /* Timeout Value */ 130 | #define IbcEOT 0x0004 /* Send EOI with last data byte? */ 131 | #define IbcPPC 0x0005 /* Parallel Poll Configure */ 132 | #define IbcREADDR 0x0006 /* Repeat Addressing */ 133 | #define IbcAUTOPOLL 0x0007 /* Disable Auto Serial Polling */ 134 | #define IbcCICPROT 0x0008 /* Use the CIC Protocol? */ 135 | #define IbcIRQ 0x0009 /* Use PIO for I/O */ 136 | #define IbcSC 0x000A /* Board is System Controller? */ 137 | #define IbcSRE 0x000B /* Assert SRE on device calls? */ 138 | #define IbcEOSrd 0x000C /* Terminate reads on EOS */ 139 | #define IbcEOSwrt 0x000D /* Send EOI with EOS character */ 140 | #define IbcEOScmp 0x000E /* Use 7 or 8-bit EOS compare */ 141 | #define IbcEOSchar 0x000F /* The EOS character. */ 142 | #define IbcPP2 0x0010 /* Use Parallel Poll Mode 2. */ 143 | #define IbcTIMING 0x0011 /* NORMAL, HIGH, or VERY_HIGH timing. */ 144 | #define IbcDMA 0x0012 /* Use DMA for I/O */ 145 | #define IbcReadAdjust 0x0013 /* Swap bytes during an ibrd. */ 146 | #define IbcWriteAdjust 0x014 /* Swap bytes during an ibwrt. */ 147 | #define IbcSendLLO 0x0017 /* Enable/disable the sending of LLO. */ 148 | #define IbcSPollTime 0x0018 /* Set the timeout value for serial polls. */ 149 | #define IbcPPollTime 0x0019 /* Set the parallel poll length period. */ 150 | #define IbcEndBitIsNormal 0x001A /* Remove EOS from END bit of IBSTA. */ 151 | #define IbcUnAddr 0x001B /* Enable/disable device unaddressing. */ 152 | #define IbcSignalNumber 0x001C /* Set UNIX signal number - unsupported */ 153 | #define IbcBlockIfLocked 0x001D /* Enable/disable blocking for locked boards/devices */ 154 | #define IbcHSCableLength 0x001F /* Length of cable specified for high speed timing.*/ 155 | #define IbcIst 0x0020 /* Set the IST bit. */ 156 | #define IbcRsv 0x0021 /* Set the RSV byte. */ 157 | #define IbcLON 0x0022 /* Enter listen only mode */ 158 | 159 | /* 160 | * Constants that can be used (in addition to the ibconfig constants) 161 | * when calling the ibask() function. 162 | */ 163 | 164 | #define IbaPAD IbcPAD 165 | #define IbaSAD IbcSAD 166 | #define IbaTMO IbcTMO 167 | #define IbaEOT IbcEOT 168 | #define IbaPPC IbcPPC 169 | #define IbaREADDR IbcREADDR 170 | #define IbaAUTOPOLL IbcAUTOPOLL 171 | #define IbaCICPROT IbcCICPROT 172 | #define IbaIRQ IbcIRQ 173 | #define IbaSC IbcSC 174 | #define IbaSRE IbcSRE 175 | #define IbaEOSrd IbcEOSrd 176 | #define IbaEOSwrt IbcEOSwrt 177 | #define IbaEOScmp IbcEOScmp 178 | #define IbaEOSchar IbcEOSchar 179 | #define IbaPP2 IbcPP2 180 | #define IbaTIMING IbcTIMING 181 | #define IbaDMA IbcDMA 182 | #define IbaReadAdjust IbcReadAdjust 183 | #define IbaWriteAdjust IbcWriteAdjust 184 | #define IbaSendLLO IbcSendLLO 185 | #define IbaSPollTime IbcSPollTime 186 | #define IbaPPollTime IbcPPollTime 187 | #define IbaEndBitIsNormal IbcEndBitIsNormal 188 | #define IbaUnAddr IbcUnAddr 189 | #define IbaSignalNumber IbcSignalNumber 190 | #define IbaBlockIfLocked IbcBlockIfLocked 191 | #define IbaHSCableLength IbcHSCableLength 192 | #define IbaIst IbcIst 193 | #define IbaRsv IbcRsv 194 | #define IbaLON IbcLON 195 | #define IbaSerialNumber 0x0023 196 | 197 | #define IbaBNA 0x0200 /* A device's access board. */ 198 | 199 | 200 | /* Values used by the Send 488.2 command. */ 201 | #define NULLend 0x00 /* Do nothing at the end of a transfer.*/ 202 | #define NLend 0x01 /* Send NL with EOI after a transfer. */ 203 | #define DABend 0x02 /* Send EOI with the last DAB. */ 204 | 205 | /* Value used by the 488.2 Receive command. 206 | */ 207 | #define STOPend 0x0100 208 | 209 | 210 | /* Address type (for 488.2 calls) */ 211 | 212 | typedef short Addr4882_t; /* System dependent: must be 16 bits */ 213 | 214 | /* 215 | * This macro can be used to easily create an entry in address list 216 | * that is required by many of the 488.2 functions. The primary address goes in the 217 | * lower 8-bits and the secondary address goes in the upper 8-bits. 218 | */ 219 | #define MakeAddr(pad, sad) ((Addr4882_t)(((pad)&0xFF) | ((sad)<<8))) 220 | 221 | /* 222 | * This value is used to terminate an address list. It should be 223 | * assigned to the last entry. 224 | */ 225 | #ifndef NOADDR 226 | #define NOADDR (Addr4882_t)((unsigned short)0xFFFF) 227 | #endif 228 | 229 | /* 230 | * The following two macros are used to "break apart" an address list 231 | * entry. They take an unsigned integer and return either the primary 232 | * or secondary address stored in the integer. 233 | */ 234 | #define GetPAD(val) ((val) & 0xFF) 235 | #define GetSAD(val) (((val) >> 8) & 0xFF) 236 | 237 | /* iblines constants */ 238 | 239 | #define ValidEOI (short)0x0080 240 | #define ValidATN (short)0x0040 241 | #define ValidSRQ (short)0x0020 242 | #define ValidREN (short)0x0010 243 | #define ValidIFC (short)0x0008 244 | #define ValidNRFD (short)0x0004 245 | #define ValidNDAC (short)0x0002 246 | #define ValidDAV (short)0x0001 247 | #define BusEOI (short)0x8000 248 | #define BusATN (short)0x4000 249 | #define BusSRQ (short)0x2000 250 | #define BusREN (short)0x1000 251 | #define BusIFC (short)0x0800 252 | #define BusNRFD (short)0x0400 253 | #define BusNDAC (short)0x0200 254 | #define BusDAV (short)0x0100 255 | 256 | /**** 257 | **** typedef for ibnotify callback **** 258 | ****/ 259 | typedef int (__stdcall * GpibNotifyCallback_t)(int, int, int, long, PVOID); 260 | 261 | /*************************************************************************/ 262 | /* */ 263 | /* iblockx and ibunlockx definitions --- deprecated, use iblck */ 264 | /* */ 265 | /*************************************************************************/ 266 | #define TIMMEDIATE -1 267 | #define TINFINITE -2 268 | #define MAX_LOCKSHARENAME_LENGTH 64 269 | 270 | #if defined(UNICODE) 271 | #define iblockx iblockxW 272 | #else 273 | #define iblockx iblockxA 274 | #endif 275 | 276 | extern int __stdcall iblockxA (int ud, int LockWaitTime, PCHAR LockShareName); 277 | extern int __stdcall iblockxW (int ud, int LockWaitTime, PWCHAR LockShareName); 278 | extern int __stdcall ibunlockx (int ud); 279 | 280 | 281 | /***************************************************************************/ 282 | /* IBSTA, IBERR, IBCNT, IBCNTL and FUNCTION PROTOTYPES */ 283 | /* ( only included if not accessing the 32-bit DLL directly ) */ 284 | /***************************************************************************/ 285 | #if !defined(GPIB_DIRECT_ACCESS) 286 | 287 | /* 288 | * Set up access to the user variables (ibsta, iberr, ibcnt, ibcntl). 289 | * These are declared and exported by the 32-bit DLL. Separate copies 290 | * exist for each process that accesses the DLL. They are shared by 291 | * multiple threads of a single process. 292 | */ 293 | 294 | extern int ibsta; 295 | extern int iberr; 296 | extern int ibcnt; 297 | extern long ibcntl; 298 | 299 | #if defined(UNICODE) 300 | #define ibbna ibbnaW 301 | #define ibfind ibfindW 302 | #define ibrdf ibrdfW 303 | #define ibwrtf ibwrtfW 304 | #else 305 | #define ibbna ibbnaA 306 | #define ibfind ibfindA 307 | #define ibrdf ibrdfA 308 | #define ibwrtf ibwrtfA 309 | #endif 310 | 311 | /* 312 | * Extern 32-bit GPIB DLL functions 313 | */ 314 | 315 | /* NI-488 Function Prototypes */ 316 | extern int __stdcall ibfindA (LPCSTR udname); 317 | extern int __stdcall ibbnaA (int ud, LPCSTR udname); 318 | extern int __stdcall ibrdfA (int ud, LPCSTR filename); 319 | extern int __stdcall ibwrtfA (int ud, LPCSTR filename); 320 | 321 | extern int __stdcall ibfindW (LPCWSTR udname); 322 | extern int __stdcall ibbnaW (int ud, LPCWSTR udname); 323 | extern int __stdcall ibrdfW (int ud, LPCWSTR filename); 324 | extern int __stdcall ibwrtfW (int ud, LPCWSTR filename); 325 | 326 | extern int __stdcall ibask (int ud, int option, PINT v); 327 | extern int __stdcall ibcac (int ud, int v); 328 | extern int __stdcall ibclr (int ud); 329 | extern int __stdcall ibcmd (int ud, PVOID buf, long cnt); 330 | extern int __stdcall ibcmda (int ud, PVOID buf, long cnt); 331 | extern int __stdcall ibconfig (int ud, int option, int v); 332 | extern int __stdcall ibdev (int boardID, int pad, int sad, int tmo, int eot, int eos); 333 | extern int __stdcall ibdiag (int ud, PVOID buf, long cnt); 334 | extern int __stdcall ibdma (int ud, int v); 335 | extern int __stdcall ibexpert (int ud, int option, void * Input, void * Output); 336 | extern int __stdcall ibeos (int ud, int v); 337 | extern int __stdcall ibeot (int ud, int v); 338 | extern int __stdcall ibgts (int ud, int v); 339 | extern int __stdcall ibist (int ud, int v); 340 | extern int __stdcall iblck (int ud, int v, unsigned int LockWaitTime, void * Reserved); 341 | extern int __stdcall iblines (int ud, PSHORT result); 342 | extern int __stdcall ibln (int ud, int pad, int sad, PSHORT listen); 343 | extern int __stdcall ibloc (int ud); 344 | extern int __stdcall ibnotify (int ud, int mask, GpibNotifyCallback_t Callback, PVOID RefData); 345 | extern int __stdcall ibonl (int ud, int v); 346 | extern int __stdcall ibpad (int ud, int v); 347 | extern int __stdcall ibpct (int ud); 348 | extern int __stdcall ibpoke (int ud, long option, long v); 349 | extern int __stdcall ibppc (int ud, int v); 350 | extern int __stdcall ibrd (int ud, PVOID buf, long cnt); 351 | extern int __stdcall ibrda (int ud, PVOID buf, long cnt); 352 | extern int __stdcall ibrpp (int ud, PCHAR ppr); 353 | extern int __stdcall ibrsc (int ud, int v); 354 | extern int __stdcall ibrsp (int ud, PCHAR spr); 355 | extern int __stdcall ibrsv (int ud, int v); 356 | extern int __stdcall ibsad (int ud, int v); 357 | extern int __stdcall ibsic (int ud); 358 | extern int __stdcall ibsre (int ud, int v); 359 | extern int __stdcall ibstop (int ud); 360 | extern int __stdcall ibtmo (int ud, int v); 361 | extern int __stdcall ibtrg (int ud); 362 | extern int __stdcall ibwait (int ud, int mask); 363 | extern int __stdcall ibwrt (int ud, PVOID buf, long cnt); 364 | extern int __stdcall ibwrta (int ud, PVOID buf, long cnt); 365 | 366 | // GPIB-ENET only functions to support locking across machines 367 | // Deprecated - Use iblck 368 | extern int __stdcall iblock (int ud); 369 | extern int __stdcall ibunlock (int ud); 370 | 371 | /**************************************************************************/ 372 | /* Functions to access Thread-Specific copies of the GPIB global vars */ 373 | 374 | extern int __stdcall ThreadIbsta (void); 375 | extern int __stdcall ThreadIberr (void); 376 | extern int __stdcall ThreadIbcnt (void); 377 | extern long __stdcall ThreadIbcntl (void); 378 | 379 | 380 | /**************************************************************************/ 381 | /* NI-488.2 Function Prototypes */ 382 | 383 | extern void __stdcall AllSpoll (int boardID, Addr4882_t * addrlist, PSHORT results); 384 | extern void __stdcall DevClear (int boardID, Addr4882_t addr); 385 | extern void __stdcall DevClearList (int boardID, Addr4882_t * addrlist); 386 | extern void __stdcall EnableLocal (int boardID, Addr4882_t * addrlist); 387 | extern void __stdcall EnableRemote (int boardID, Addr4882_t * addrlist); 388 | extern void __stdcall FindLstn (int boardID, Addr4882_t * addrlist, Addr4882_t * results, int limit); 389 | extern void __stdcall FindRQS (int boardID, Addr4882_t * addrlist, PSHORT dev_stat); 390 | extern void __stdcall PPoll (int boardID, PSHORT result); 391 | extern void __stdcall PPollConfig (int boardID, Addr4882_t addr, int dataLine, int lineSense); 392 | extern void __stdcall PPollUnconfig (int boardID, Addr4882_t * addrlist); 393 | extern void __stdcall PassControl (int boardID, Addr4882_t addr); 394 | extern void __stdcall RcvRespMsg (int boardID, PVOID buffer, long cnt, int Termination); 395 | extern void __stdcall ReadStatusByte(int boardID, Addr4882_t addr, PSHORT result); 396 | extern void __stdcall Receive (int boardID, Addr4882_t addr, PVOID buffer, long cnt, int Termination); 397 | extern void __stdcall ReceiveSetup (int boardID, Addr4882_t addr); 398 | extern void __stdcall ResetSys (int boardID, Addr4882_t * addrlist); 399 | extern void __stdcall Send (int boardID, Addr4882_t addr, PVOID databuf, long datacnt, int eotMode); 400 | extern void __stdcall SendCmds (int boardID, PVOID buffer, long cnt); 401 | extern void __stdcall SendDataBytes (int boardID, PVOID buffer, long cnt, int eot_mode); 402 | extern void __stdcall SendIFC (int boardID); 403 | extern void __stdcall SendLLO (int boardID); 404 | extern void __stdcall SendList (int boardID, Addr4882_t * addrlist, PVOID databuf, long datacnt, int eotMode); 405 | extern void __stdcall SendSetup (int boardID, Addr4882_t * addrlist); 406 | extern void __stdcall SetRWLS (int boardID, Addr4882_t * addrlist); 407 | extern void __stdcall TestSRQ (int boardID, PSHORT result); 408 | extern void __stdcall TestSys (int boardID, Addr4882_t * addrlist, PSHORT results); 409 | extern void __stdcall Trigger (int boardID, Addr4882_t addr); 410 | extern void __stdcall TriggerList (int boardID, Addr4882_t * addrlist); 411 | extern void __stdcall WaitSRQ (int boardID, PSHORT result); 412 | 413 | #endif 414 | 415 | 416 | #ifdef __cplusplus 417 | } 418 | #endif 419 | 420 | 421 | #endif // NI488_H 422 | 423 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/reg -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/target-procs.h: -------------------------------------------------------------------------------- 1 | #ifndef __TARGET_PROCS_H 2 | #define __TARGET_PROCS_H 3 | 4 | #define TARGET__memset 0x05010000 5 | #define TARGET_csum_hdr 0x05010340 6 | #define TARGET_find_flash 0x0501077c 7 | #define TARGET_flash_erase 0x050104c8 8 | #define TARGET_flash_erase_intel_s5 0x050102a4 9 | #define TARGET_flash_erase_intel_sa 0x050102f2 10 | #define TARGET_flash_load_to_pagebuffer_intel_sa 0x05010396 11 | #define TARGET_flash_program 0x050105da 12 | #define TARGET_flash_program_page_intel_sa 0x0501058e 13 | #define TARGET_flash_program_single_cmd40 0x05010544 14 | #define TARGET_flash_wait_bsr 0x05010200 15 | #define TARGET_flash_wait_gsr 0x0501015c 16 | #define TARGET_flash_wait_sr 0x050100ba 17 | #define TARGET_flash_write_pagebuffer_intel_sa 0x0501042c 18 | #define TARGET_identify_flash 0x05010732 19 | #define TARGET_init 0x05010864 20 | #define TARGET_udelay 0x05010092 21 | #endif 22 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/target.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/target.bin -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/target.c: -------------------------------------------------------------------------------- 1 | typedef unsigned char uint8_t; 2 | typedef unsigned short uint16_t; 3 | typedef unsigned int uint32_t; 4 | 5 | #define NULL (void *)0 6 | #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(_x[0])) 7 | 8 | uint32_t bss_begin, bss_end; 9 | 10 | void (*_console_log)(char *fmt, ...) = (void *)0x16ba; 11 | 12 | #define console_log 13 | //_console_log 14 | struct gpib_hdr { 15 | uint8_t cmd; 16 | uint8_t csum; 17 | uint16_t len; 18 | }; 19 | 20 | struct gpib_flash_program_cmd { 21 | uint32_t arg0; 22 | uint32_t arg1; 23 | uint32_t function; 24 | uint32_t *base; 25 | uint32_t data[128]; 26 | }; 27 | 28 | struct gpib_flash_erase_cmd { 29 | struct gpib_hdr *hdr; 30 | uint32_t *base; 31 | }; 32 | 33 | struct flash_descriptor { 34 | uint8_t manufacturer; 35 | uint8_t device; 36 | uint32_t size; 37 | uint32_t blocksize; 38 | int (*erase_chip)(uint32_t *base); 39 | int (*program_single)(uint32_t *base, uint32_t data); 40 | int (*program_page)(uint32_t *base, uint32_t *data, uint16_t len); 41 | }; 42 | 43 | static struct flash_descriptor *current_flash; 44 | 45 | static void _memset(void *dst, char c, int len) 46 | { 47 | int unaligned = len % 4; 48 | char *dst8 = (char *)dst; 49 | uint32_t *dst32 = (uint32_t *)dst; 50 | char c32; 51 | 52 | while(unaligned--) { 53 | *dst8++ = c; 54 | len--; 55 | } 56 | 57 | c32 = (c << 24) | (c << 16) | (c << 8) | c; 58 | len /= 4; 59 | 60 | while(len--) 61 | *dst32++ = c32; 62 | } 63 | 64 | static void udelay(int delay) 65 | { 66 | volatile int i; 67 | for(i = 0; i < delay; i++); 68 | } 69 | 70 | static int flash_wait_sr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 71 | { 72 | uint32_t buf; 73 | uint32_t _mask = (mask << 16) | mask; 74 | uint32_t _result = (result << 16) | result; 75 | int ret = -1; 76 | 77 | while(tries--) { 78 | //console_log("flash_wait_sr: %08x: %08x\n", base, *(uint32_t *)base); 79 | if (*base & _mask == _result) 80 | break; 81 | 82 | udelay(10000); 83 | } 84 | 85 | if (!tries) { 86 | console_log("flash_wait_gsr timeout\n"); 87 | return -1; 88 | } 89 | ret = 0; 90 | out: 91 | return ret; 92 | } 93 | 94 | static int flash_wait_gsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 95 | { 96 | uint32_t buf; 97 | uint32_t _mask = (mask << 16) | mask; 98 | uint32_t _result = (result << 16) | result; 99 | int ret = -1; 100 | 101 | base = (uint32_t *)(((uint32_t)base) & ~0x1fffff); 102 | base += 2; 103 | 104 | while(tries--) { 105 | console_log("flash_wait_gsr: %08x: %08x\n", base, *(uint32_t *)base); 106 | if ((*base & _mask) == _result) 107 | break; 108 | 109 | udelay(10); 110 | } 111 | 112 | if (!tries) { 113 | console_log("flash_wait_gsr timeout\n"); 114 | return -1; 115 | } 116 | ret = 0; 117 | out: 118 | return ret; 119 | } 120 | 121 | static int flash_wait_bsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 122 | { 123 | uint32_t buf; 124 | uint32_t _mask = (mask << 16) | mask; 125 | uint32_t _result = (result << 16) | result; 126 | int ret = -1; 127 | 128 | base = (uint32_t *)(((uint32_t)base) & ~0x1ffff); 129 | base += 1; 130 | 131 | while(tries--) { 132 | console_log("flash_wait_bsr: %08x: %08x (mask %08x/%08x\n", base, *base, _mask, _result); 133 | if ((*base & _mask) == _result) 134 | break; 135 | udelay(10); 136 | } 137 | 138 | if (!tries) 139 | return -1; 140 | ret = 0; 141 | out: 142 | return ret; 143 | } 144 | 145 | 146 | static int flash_erase_intel_s5(uint32_t *base) 147 | { 148 | *base = 0x30303030; 149 | *base = 0xd0d0d0d0; 150 | 151 | if (flash_wait_sr(base, 0x0080, 0x0080, 0x100000) == -1) 152 | return -1; 153 | 154 | *base = 0xffffffff; 155 | return 0; 156 | } 157 | 158 | static int flash_erase_intel_sa(uint32_t *base) 159 | { 160 | *base = 0xa7a7a7a7; 161 | *base = 0xd0d0d0d0; 162 | 163 | if (flash_wait_gsr(base, 0x0080, 0x0080, 0x100000) == -1) 164 | return -1; 165 | 166 | *base = 0xffffffff; 167 | return 0; 168 | } 169 | 170 | static uint8_t csum_hdr(struct gpib_hdr *hdr) 171 | { 172 | int i, csum; 173 | uint8_t *buf = (uint8_t *)&hdr; 174 | 175 | csum = buf[0]; 176 | 177 | for(i = 2; i < hdr->len + sizeof(struct gpib_hdr) - 2; i++) 178 | csum += buf[i]; 179 | return csum; 180 | } 181 | 182 | static int flash_load_to_pagebuffer_intel_sa(uint32_t *base, uint32_t *data) 183 | { 184 | uint32_t *buf; 185 | int i,ret = -1; 186 | 187 | *base = 0x71717171; 188 | 189 | if (flash_wait_gsr(base, 0x0004, 0x0004, 0x100000) == -1) 190 | goto out; 191 | 192 | *base = 0xe0e0e0e0; 193 | 194 | *base = 0x007f007f; 195 | *base = 0x00000000; 196 | 197 | buf = (uint32_t *)data; 198 | 199 | for(i = 0; i < 128; i++) 200 | *base++ = *buf++; 201 | ret = 0; 202 | out: 203 | *base = 0xffffffff; 204 | return ret; 205 | } 206 | 207 | static int flash_write_pagebuffer_intel_sa(uint32_t *base) 208 | { 209 | int ret = -1; 210 | uint32_t buf; 211 | 212 | *base = 0x71717171; 213 | 214 | if (flash_wait_bsr(base, 0x0008, 0x0000, 0x100000) == -1) 215 | goto out; 216 | 217 | *base = 0x0c0c0c0c; 218 | 219 | *base = 0x007f007f; 220 | *base = 0x00000000; 221 | 222 | *base = 0x71717171; 223 | 224 | if (flash_wait_bsr(base, 0x0080, 0x0080, 0x100000) == -1) 225 | goto out; 226 | 227 | *base = 0xffffffff; 228 | *base = 0xffffffff; 229 | ret = 0; 230 | out: 231 | return ret; 232 | 233 | } 234 | 235 | static void flash_erase(struct gpib_hdr *hdr) 236 | { 237 | struct gpib_flash_erase_cmd *cmd = (struct gpib_flash_erase_cmd *)hdr; 238 | uint32_t *base = (uint32_t *)0x01000000; 239 | 240 | console_log("flash_erase\n"); 241 | _memset(hdr, 0, sizeof(hdr)); 242 | hdr->cmd = '-'; 243 | 244 | if (!current_flash) 245 | goto out; 246 | 247 | if (current_flash->erase_chip(base) == -1) { 248 | console_log("flash_erase failed\n"); 249 | goto out; 250 | } 251 | 252 | hdr->cmd = 'P'; 253 | out: 254 | *base = 0xffffffff; 255 | hdr->csum = csum_hdr(hdr); 256 | 257 | } 258 | 259 | static int flash_program_single_cmd40(uint32_t *base, uint32_t data) 260 | { 261 | int i, ret = -1; 262 | 263 | *base = 0x40404040; 264 | *base = data; 265 | 266 | if (flash_wait_gsr(base, 0x0080, 0x0080, 1000) == -1) 267 | goto out; 268 | 269 | out: 270 | *base = 0xffffffff; 271 | } 272 | 273 | static int flash_program_page_intel_sa(uint32_t *base, uint32_t *data) 274 | { 275 | if (flash_load_to_pagebuffer_intel_sa(base, data) == -1) 276 | goto out; 277 | 278 | if (flash_write_pagebuffer_intel_sa(base) == -1) 279 | goto out; 280 | 281 | *base = 0x50505050; 282 | *base = 0xffffffff; 283 | return 0; 284 | out: 285 | return -1; 286 | } 287 | 288 | struct cmd_params { 289 | struct gpib_hdr hdr; 290 | struct gpib_flash_program_cmd *cmd; 291 | }; 292 | 293 | static void flash_program(struct cmd_params *params) 294 | { 295 | int i, ret = -1; 296 | uint32_t *base = params->cmd->base; 297 | uint32_t len = params->hdr.len - 16; 298 | uint32_t offset = 0; 299 | 300 | // console_log("flash_program: %d bytes @ %08x\n", len, base); 301 | 302 | _memset(¶ms->hdr, 0, sizeof(struct gpib_hdr)); 303 | params->hdr.cmd = '-'; 304 | 305 | if (!current_flash) 306 | goto out; 307 | 308 | if (len < 0) 309 | goto out; 310 | 311 | 312 | if (current_flash->program_page) { 313 | while (len >= 512) { 314 | current_flash->program_page(base + offset, params->cmd->data + offset, 512); 315 | len -= 512; 316 | offset += 512; 317 | } 318 | } 319 | 320 | len /= 4; 321 | for(i = 0; i < len; i++) { 322 | current_flash->program_single(base + offset, params->cmd->data[i]); 323 | offset += 4; 324 | } 325 | 326 | params->hdr.cmd = 'P'; 327 | out: 328 | *base = 0xffffffff; 329 | params->hdr.csum = csum_hdr(¶ms->hdr); 330 | } 331 | 332 | 333 | struct flash_descriptor flash_types[] = { 334 | /* Intel TE28F160S5 */ 335 | { .manufacturer = 0xb0, 336 | .device = 0xd0, 337 | .size = 0x200000, 338 | .blocksize = 0x200, 339 | .erase_chip = flash_erase_intel_s5, 340 | .program_single = flash_program_single_cmd40, 341 | },{ 342 | /* Intel E28F016SA */ 343 | .manufacturer = 0x89, 344 | .device = 0xa0, 345 | .size = 0x200000, 346 | .blocksize = 0x200, 347 | .erase_chip = flash_erase_intel_sa, 348 | .program_single = flash_program_single_cmd40, 349 | .program_page = flash_program_page_intel_sa, 350 | } 351 | }; 352 | 353 | static uint32_t identify_flash(uint32_t *base) 354 | { 355 | uint32_t id; 356 | *base = 0x90909090; 357 | id = (*base & 0x00ff00ff) << 8; 358 | id |= (*(base+1) & 0x00ff00ff); 359 | *base = 0xffffffff; 360 | return id; 361 | } 362 | 363 | static struct flash_descriptor *find_flash(void) 364 | { 365 | uint32_t id; 366 | int i; 367 | 368 | id = identify_flash((uint32_t *)0x01000000); 369 | if (id & 0xffff != (id >> 16) & 0xffff) 370 | return NULL; 371 | 372 | id &= 0xffff; 373 | 374 | for(i = 0; i < ARRAY_SIZE(flash_types); i++) { 375 | if ((flash_types[i].device == (id & 0xff)) && 376 | ((flash_types[i].manufacturer == (id >> 8)))) 377 | return flash_types + i; 378 | } 379 | console_log("Unknown flash with Vendor ID 0x%02X, Device ID 0x%02X\n", id >> 8, id & 0xff); 380 | return NULL; 381 | } 382 | 383 | static void init(struct gpib_hdr *hdr) 384 | { 385 | console_log("target init\n"); 386 | _memset(&bss_begin, 0, bss_end - bss_begin); 387 | 388 | current_flash = find_flash(); 389 | _memset(hdr, 0, sizeof(hdr)); 390 | if (current_flash) 391 | hdr->cmd = 'P'; 392 | else 393 | hdr->cmd = 'X'; 394 | hdr->csum = csum_hdr(hdr); 395 | } 396 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/target.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/target.elf -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/target.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x05010000; 4 | .text : { *(.text) } 5 | _bss_begin = .; 6 | .bss : { *(.bss) } 7 | _bss_end = .; 8 | .data : { *(.data) } 9 | } 10 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/tekfwtool.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "tekfwtool.h" 12 | #include "target-procs.h" 13 | #include "ni488.h" 14 | 15 | int Dev; 16 | const char *ErrorMnemonic[] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", 17 | "ESAC", "EABO", "ENEB", "EDMA", "", 18 | "EOIP", "ECAP", "EFSO", "", "EBUS", 19 | "ESTB", "ESRQ", "", "", "", "ETAB"}; 20 | 21 | static int abort_requested = 0; 22 | static int debug; 23 | 24 | static void sigint_handler(int arg) 25 | { 26 | abort_requested = 1; 27 | } 28 | 29 | static void GPIBCleanup(int Dev, char* ErrorMsg) 30 | { 31 | printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n", 32 | ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]); 33 | if (Dev != -1) { 34 | printf("Cleanup: Taking device offline\n"); 35 | ibonl (Dev, 0); 36 | } 37 | } 38 | 39 | static int write_command(char *cmd) 40 | { 41 | ibwrt (Dev, cmd, strlen(cmd)); 42 | if (ibsta & ERR) 43 | return -1; 44 | return 0; 45 | } 46 | 47 | static int query(char *query, char *buf, int maxsize) 48 | { 49 | 50 | ibwrt (Dev, query, strlen(query)); 51 | if (ibsta & ERR) 52 | return -1; 53 | 54 | ibrd (Dev, buf, maxsize); 55 | if (ibsta & ERR) 56 | return -1; 57 | 58 | buf[ibcntl - 1] = '\0'; 59 | return ibcntl; 60 | } 61 | 62 | static void hexdump(void *_buf, int len) 63 | { 64 | int i; 65 | uint8_t *buf = (uint8_t *)_buf; 66 | for(i = 0; i < len; i++) 67 | fprintf(stderr, "%02X ", buf[i]); 68 | fprintf(stderr, "\n"); 69 | } 70 | 71 | static void build_csum(struct cmd_hdr *hdr) 72 | { 73 | uint8_t csum = 0; 74 | uint32_t i; 75 | for(i = 0; i < be16_to_cpu(hdr->len) + sizeof(struct cmd_hdr); i++) 76 | csum += ((uint8_t *)hdr)[i]; 77 | hdr->csum = csum; 78 | } 79 | 80 | static int write_memory(uint32_t addr, uint8_t *buf, int len) 81 | { 82 | struct memory_write_cmd cmd; 83 | struct cmd_hdr hdr; 84 | uint16_t responselen; 85 | char c; 86 | 87 | memset(&cmd, 0, sizeof(cmd)); 88 | cmd.hdr.cmd = 'M'; 89 | cmd.hdr.len = cpu_to_be16(len + 8); 90 | cmd.addr = cpu_to_be32(addr); 91 | cmd.len = cpu_to_be32(len); 92 | 93 | memcpy(cmd.buf, buf, len); 94 | 95 | build_csum((struct cmd_hdr *)&cmd); 96 | if (debug > 1) 97 | hexdump(&cmd, len + 12); 98 | 99 | ibwrt (Dev, &cmd, len + 12); 100 | if (ibsta & ERR) { 101 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 102 | return -1; 103 | } 104 | 105 | ibrd(Dev, &c, 1); 106 | if (ibcntl != 1 || c != '+') { 107 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 108 | return -1; 109 | } 110 | 111 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 112 | if (ibsta & ERR) { 113 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 114 | return -1; 115 | } 116 | 117 | if (ibcntl < (signed)sizeof(hdr)) { 118 | fprintf(stderr, "%s: short header\n", __FUNCTION__); 119 | return -1; 120 | } 121 | 122 | if (hdr.cmd != '=') { 123 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 124 | return -1; 125 | } 126 | c = '+'; 127 | ibwrt(Dev, &c, 1); 128 | return 0; 129 | } 130 | 131 | static int branch_cmd(uint32_t addr, uint32_t arg0, uint8_t *data, int *datalen) 132 | { 133 | struct branch_cmd cmd; 134 | uint8_t buf[1024]; 135 | struct cmd_hdr hdr; 136 | uint16_t responselen; 137 | char c; 138 | 139 | memset(&cmd, 0, sizeof(cmd)); 140 | cmd.hdr.cmd = 'B'; 141 | cmd.hdr.len = cpu_to_be16(16 + *datalen); 142 | cmd.function = cpu_to_be32(addr); 143 | // cmd.argc = cpu_to_be32(2); 144 | // cmd.unknown = cpu_to_be32(2); 145 | cmd.arg0 = cpu_to_be32(arg0); 146 | memcpy(&cmd.buffer, data, *datalen); 147 | 148 | build_csum((struct cmd_hdr *)&cmd); 149 | if (debug > 1) 150 | hexdump(&cmd, be16_to_cpu(cmd.hdr.len) + sizeof(struct cmd_hdr)); 151 | 152 | ibwrt (Dev, &cmd, 20 + *datalen); 153 | if (ibsta & ERR) { 154 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 155 | return -1; 156 | } 157 | 158 | ibrd(Dev, &c, 1); 159 | if (ibcntl != 1 || c != '+') { 160 | fprintf(stderr, "%s: response reading failed: ibcntl: %ld, %02x\n", __FUNCTION__, ibcntl, c); 161 | return -1; 162 | } 163 | 164 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 165 | if (ibsta & ERR) { 166 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 167 | return -1; 168 | } 169 | 170 | if (ibcntl < (signed)sizeof(hdr)) { 171 | fprintf(stderr, "%s: short header\n", __FUNCTION__); 172 | return -1; 173 | } 174 | 175 | if (debug > 1) 176 | hexdump(&hdr, 4); 177 | 178 | if (hdr.len) { 179 | printf("reading %d bytes\n", be16_to_cpu(hdr.len)); 180 | ibrd(Dev, buf, be16_to_cpu(hdr.len)); 181 | if (ibsta & ERR) { 182 | fprintf(stderr, "%s: reading of additional data failed\n", __FUNCTION__); 183 | return -1; 184 | } 185 | } 186 | 187 | if (hdr.len) 188 | hexdump(buf, be16_to_cpu(hdr.len)); 189 | 190 | if (hdr.cmd != 'P') { 191 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 192 | return -1; 193 | } 194 | c = '+'; 195 | ibwrt(Dev, &c, 1); 196 | return 0; 197 | } 198 | 199 | static int read_memory(uint32_t addr, uint8_t *buf, int len) 200 | { 201 | struct memory_read_cmd cmd; 202 | struct cmd_hdr hdr; 203 | int responselen; 204 | char c; 205 | 206 | memset(&cmd, 0, sizeof(cmd)); 207 | cmd.hdr.cmd = 'm'; 208 | cmd.hdr.len = cpu_to_be16(sizeof(cmd) - 4); 209 | cmd.addr = cpu_to_be32(addr); 210 | cmd.len = cpu_to_be32(len); 211 | 212 | build_csum((struct cmd_hdr *)&cmd); 213 | if (debug > 1) 214 | hexdump(&cmd, sizeof(cmd)); 215 | 216 | ibwrt (Dev, &cmd, sizeof(struct memory_read_cmd)); 217 | if (ibsta & ERR) { 218 | fprintf(stderr, "%s: writing command failed\n", __FUNCTION__); 219 | return -1; 220 | } 221 | 222 | ibrd(Dev, &c, 1); 223 | if (ibcntl != 1 || c != '+') { 224 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 225 | return -1; 226 | } 227 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 228 | if (ibsta & ERR) { 229 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 230 | return -1; 231 | } 232 | if (ibcntl < (signed)sizeof(hdr)) { 233 | fprintf(stderr, "%s: short header\n", __FUNCTION__); 234 | return -1; 235 | } 236 | 237 | if (hdr.cmd != '=') { 238 | fprintf(stderr, "%s: invalid response: %c\n", __FUNCTION__, hdr.cmd); 239 | return -1; 240 | } 241 | 242 | responselen = be16_to_cpu(hdr.len); 243 | 244 | if (responselen != len) { 245 | fprintf(stderr, "%s: short response\n", __FUNCTION__); 246 | return -1; 247 | } 248 | ibrd(Dev, buf, responselen); 249 | if (ibsta & ERR || ibcntl < len) { 250 | fprintf(stderr, "%s: response reading failed\n", __FUNCTION__); 251 | return -1; 252 | } 253 | 254 | c = '+'; 255 | ibwrt(Dev, &c, 1); 256 | if (ibsta & ERR) { 257 | fprintf(stderr, "%s: unable to send ACK\n", __FUNCTION__); 258 | return -1; 259 | } 260 | 261 | return 0; 262 | } 263 | 264 | static struct option long_options[] = { 265 | { "read", required_argument, 0, 'r' }, 266 | { "write", required_argument, 0, 'w' }, 267 | { "base", required_argument, 0, 'b' }, 268 | { "length", required_argument, 0, 'l' }, 269 | { "debug", no_argument, 0, 'd' }, 270 | { "flash-id", no_argument, 0, 'i' }, 271 | { "flash-erase", no_argument, 0, 'e' }, 272 | { "flash-program", required_argument, 0, 'p' }, 273 | { "help", no_argument, 0, 'h' }, 274 | { NULL, 0, 0, 0 } 275 | }; 276 | 277 | static void usage(void) 278 | { 279 | fprintf(stderr, "usage:\n" 280 | "--read -r read from memory to file\n" 281 | "--write -w read from file to memory\n" 282 | "--base -b base address for read/write/program\n" 283 | "--length -l length of data to be read or written\n" 284 | "--debug -d enable debug logging\n" 285 | "--flash-id -i print ID of flash chips\n" 286 | "--flash-erase -e erase flash at base address\n" 287 | "--flsh-program -p program flash at base address\n" 288 | ""); 289 | } 290 | 291 | static uint32_t to_number(char *s) 292 | { 293 | uint32_t val; 294 | char *endp; 295 | 296 | if (*s == '0' && *(s+1) == 'x') { 297 | val = strtoul(s+2, &endp, 16); 298 | if (*endp != '\0') { 299 | fprintf(stderr, "failed to parse: [%s]\n", s); 300 | return 0; 301 | } 302 | } else { 303 | val = strtoul(s, &endp, 10); 304 | if (*endp != '\0') { 305 | fprintf(stderr, "failed to parse: [%s]\n", s); 306 | return 0; 307 | } 308 | } 309 | return val; 310 | } 311 | 312 | static int flash_program(uint32_t base, uint8_t *buf, int size) 313 | { 314 | int len = size; 315 | return branch_cmd(TARGET_flash_program, base, buf, &len); 316 | } 317 | 318 | static int flash_erase(uint32_t base) 319 | { 320 | int len = 0; 321 | printf("Erasing flash @ 0x%08x\n", base); 322 | return branch_cmd(TARGET_flash_erase, base, NULL, &len); 323 | } 324 | 325 | static int init_firmware(void) 326 | { 327 | int len = 0; 328 | return branch_cmd(TARGET_init, 0, NULL, &len); 329 | } 330 | 331 | static int download_firmware(void) 332 | { 333 | FILE *file = fopen("target.bin", "rb"); 334 | char buf[512]; 335 | size_t len, offset = 0; 336 | int ret = -1; 337 | 338 | if (!file) { 339 | fprintf(stderr, "failed to open target.bin: %s", strerror(errno)); 340 | return -1; 341 | } 342 | 343 | printf("Downloading firmware to scope\n"); 344 | while((len = fread(buf, 1, sizeof(buf), file)) > 0) { 345 | if (write_memory(TARGET_FIRMWARE_BASE + offset, (uint8_t *)&buf, len) == -1) { 346 | fprintf(stderr, "error downloading firmware\n"); 347 | goto out; 348 | } 349 | offset += len; 350 | } 351 | 352 | if (ferror(file)) { 353 | fprintf(stderr, "error reading firmware from file\n"); 354 | goto out; 355 | } 356 | 357 | printf("Pinging firmware\n"); 358 | if (init_firmware() == -1) { 359 | fprintf(stderr, "failed to ping firmware\n"); 360 | goto out; 361 | } 362 | printf("Firmware downloaded\n"); 363 | ret = 0; 364 | out: 365 | fclose(file); 366 | return ret; 367 | } 368 | 369 | int main(int argc, char **argv) 370 | { 371 | uint32_t len, addr, base = 0, length = 0; 372 | char c; 373 | uint8_t buf[1024]; 374 | int val, optidx; 375 | FILE *file = NULL; 376 | int read_op = 0, write_op = 0, erase_flash_op = 0, flash_write_op = 0; 377 | int readlen, i; 378 | time_t start, now; 379 | 380 | while((c = getopt_long(argc, argv, "r:w:b:l:p:hied", 381 | long_options, &optidx)) != -1) { 382 | switch(c) { 383 | case 'h': 384 | usage(); 385 | return 0; 386 | case 'l': 387 | if (length) { 388 | fprintf(stderr, "length given twice"); 389 | return 1; 390 | } 391 | length = to_number(optarg); 392 | break; 393 | case 'b': 394 | if (base) { 395 | fprintf(stderr, "base given twice"); 396 | return 1; 397 | } 398 | base = to_number(optarg); 399 | break; 400 | case 'r': 401 | if (file) { 402 | fprintf(stderr, "read given twice"); 403 | return 1; 404 | } 405 | file = fopen(optarg, "wb"); 406 | if (!file) { 407 | fprintf(stderr, "failed to open output file: %s\n", strerror(errno)); 408 | return 1; 409 | 410 | } 411 | read_op = 1; 412 | break; 413 | case 'w': 414 | if (file) { 415 | fprintf(stderr, "read given twice"); 416 | return 1; 417 | } 418 | file = fopen(optarg, "rb"); 419 | if (!file) { 420 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 421 | return 1; 422 | 423 | } 424 | 425 | write_op = 1; 426 | break; 427 | case 'p': 428 | if (file) { 429 | fprintf(stderr, "read given twice"); 430 | return 1; 431 | } 432 | file = fopen(optarg, "rb"); 433 | if (!file) { 434 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 435 | return 1; 436 | 437 | } 438 | flash_write_op = 1; 439 | break; 440 | 441 | case 'e': 442 | erase_flash_op = 1; 443 | break; 444 | case 'd': 445 | debug++; 446 | break; 447 | } 448 | } 449 | 450 | signal(SIGINT, sigint_handler); 451 | 452 | Dev = ibdev(0, 29, 0, T100s, 1, 0); 453 | if (ibsta & ERR) { 454 | printf("Unable to open device\nibsta = 0x%x iberr = %d\n", 455 | ibsta, iberr); 456 | return 1; 457 | } 458 | 459 | ibclr (Dev); 460 | if (ibsta & ERR) { 461 | GPIBCleanup(Dev, "Unable to clear device"); 462 | return 1; 463 | } 464 | 465 | if (erase_flash_op || flash_write_op) { 466 | if (download_firmware() == -1) 467 | return 1; 468 | } 469 | if (erase_flash_op) { 470 | flash_erase(base); 471 | return 0; 472 | } 473 | 474 | if (!length) { 475 | fprintf(stderr, "%s: length required\n", __FUNCTION__); 476 | return 1; 477 | } 478 | 479 | // write_memory(0x 480 | time(&start); 481 | for(addr = base; addr < base + length && !abort_requested;) { 482 | len = MIN(512, base + length - addr); 483 | if (read_op) { 484 | if (read_memory(addr, buf, len) == -1) 485 | return 1; 486 | 487 | if (fwrite(buf, 1, len, file) != len) { 488 | fprintf(stderr, "short write\n"); 489 | return 1; 490 | } 491 | if ((addr % 0x1000) == 0) { 492 | time(&now); 493 | fprintf(stderr, "READ %08x/%08x, %3d%% %4ds\r", addr - base, length, ((addr - base) * 100) / length, (int)(now - start)); 494 | } 495 | 496 | addr += len; 497 | } else if (write_op) { 498 | readlen = fread(buf, 1, len, file); 499 | if (readlen == 0) 500 | break; 501 | 502 | if (readlen == -1) { 503 | fprintf(stderr, "read: %s\n", strerror(errno)); 504 | return 1; 505 | } 506 | if (write_memory(addr, buf, readlen) == -1) 507 | return 1; 508 | if ((addr % 0x1000) == 0) { 509 | time(&now); 510 | fprintf(stderr, "WRITE %08x/%08x, %3d%% %4ds\r", addr - base, length, ((addr - base) * 100) / length, (int)(now - start)); 511 | } 512 | addr += readlen; 513 | } else if (flash_write_op) { 514 | len = MIN(512, base + length - addr); 515 | readlen = fread(buf, 1, len, file); 516 | if (readlen == 0) 517 | break; 518 | 519 | if (readlen == -1) { 520 | fprintf(stderr, "read: %s\n", strerror(errno)); 521 | return 1; 522 | } 523 | 524 | if (flash_program(addr, buf, readlen) == -1) { 525 | fprintf(stderr, "flash programming failed\n"); 526 | return 1; 527 | } 528 | addr += readlen; 529 | if ((addr % 0x1000) == 0) { 530 | time(&now); 531 | fprintf(stderr, "FLASH WRITE %08x/%08x, %3d%% %4ds\r", addr - base, length, ((addr - base) * 100) / length, (int)(now - start)); 532 | } 533 | } else { 534 | fprintf(stderr, "either read or write required\n"); 535 | return 1; 536 | } 537 | } 538 | fclose(file); 539 | ibonl(Dev, 0); 540 | return 0; 541 | } 542 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/tekfwtool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/tekfwtool.exe -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/tekfwtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEKFW_TOOL_H 2 | #define __TEKFW_TOOL_H 3 | 4 | #define TARGET_FIRMWARE_BASE 0x05010000 5 | 6 | #if BYTE_ORDER == LITTLE_ENDIAN 7 | #define cpu_to_be16(_x) ((((_x) & 0xff) << 8) | (((_x) >> 8) & 0xff)) 8 | #define be16_to_cpu cpu_to_be16 9 | #define cpu_to_be32(_x) (cpu_to_be16(((_x) >> 16) & 0xffff) | \ 10 | (cpu_to_be16(((_x) & 0xffff)) << 16)) 11 | #define be32_to_cpu cpu_to_be32 12 | #else 13 | #define cpu_to_be16 14 | #define cpu_to_be32 15 | #define be16_to_cpu 16 | #define be32_to_cpu 17 | #endif 18 | 19 | #define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a)) 20 | 21 | struct cmd_hdr { 22 | uint8_t cmd; 23 | uint8_t csum; 24 | uint16_t len; 25 | }; 26 | 27 | struct memory_read_cmd { 28 | struct cmd_hdr hdr; 29 | uint32_t addr; 30 | uint32_t len; 31 | }; 32 | 33 | struct memory_write_cmd { 34 | struct cmd_hdr hdr; 35 | uint32_t addr; 36 | uint32_t len; 37 | uint8_t buf[1024]; 38 | }; 39 | 40 | struct branch_cmd { 41 | struct cmd_hdr hdr; 42 | uint32_t argc; 43 | uint32_t unknown; 44 | uint32_t function; 45 | uint32_t arg0; 46 | uint8_t buffer[512]; 47 | }; 48 | 49 | #define TARGET_FW_INIT 0 50 | #define TARGET_FW_FLASH_ERASE 1 51 | #define TARGET_FW_FLASH_PROGRAM 2 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /tekfwtool/DIST/tekfwtool.stackframe.org/tmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/DIST/tekfwtool.stackframe.org/tmp -------------------------------------------------------------------------------- /tekfwtool/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # identify platform 3 | ifeq ($(OS),Windows_NT) 4 | OS_NAME := windows_nt 5 | else 6 | OS_NAME := $(shell uname -s) 7 | ifeq ($(OS_NAME), Linux) 8 | # Linux with linux-gpib 9 | CFLAGS += -g -fsigned-char -Wall -Wextra -pedantic -l gpib -L/usr/local/lib 10 | endif 11 | ifeq ($(OS_NAME), Darwin) 12 | # Darwin with NI 488.2 driver 13 | CFLAGS += -g -fsigned-char /Library/Frameworks/NI4882.framework/Resources/ni4882.o -framework CoreFoundation -I/Library/Frameworks/NI4882.framework/Headers 14 | endif 15 | endif 16 | 17 | 18 | # get version and build time strings 19 | GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" 20 | ifneq ($(GIT_VERSION), "") 21 | CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" 22 | endif 23 | BUILD_TIME := "$(shell date -u "+%Y-%m-%d %H:%M:%S")" 24 | ifneq ($(BUILD_TIME), "") 25 | CFLAGS += -DBUILD_TIME=\"$(BUILD_TIME)\" 26 | endif 27 | 28 | 29 | CFLAGS += -DPROG_NAME=\"$@\" 30 | 31 | 32 | tekfwtool : target-procs.h tekfwtool.c tekfwtool.h 33 | $(CC) $(CFLAGS) tekfwtool.c -o tekfwtool 34 | 35 | .PHONY : clean 36 | clean : 37 | -rm -fv tekfwtool 38 | -rm -rfv tekfwtool.dSYM 39 | -------------------------------------------------------------------------------- /tekfwtool/Makefile.target-bin: -------------------------------------------------------------------------------- 1 | M68K=m68k-linux-gnu- 2 | M68KCC=$(M68K)gcc 3 | M68KCCFLAGS=-Wall -Wextra -ggdb -Wno-unused -Werror 4 | M68KOBJCOPY=$(M68K)objcopy 5 | M68KNM=$(M68K)nm 6 | 7 | 8 | # get version and build time strings 9 | GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" 10 | ifneq ($(GIT_VERSION), "") 11 | CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" 12 | endif 13 | BUILD_TIME := "$(shell date -u "+%Y-%m-%d %H:%M:%S")" 14 | ifneq ($(BUILD_TIME), "") 15 | CFLAGS += -DBUILD_TIME=\"$(BUILD_TIME)\" 16 | endif 17 | 18 | M68KCCFLAGS += $(CFLAGS) 19 | 20 | 21 | all: target.bin target-procs.h 22 | 23 | target.bin: target.elf 24 | $(M68KOBJCOPY) -O binary $< $@ 25 | 26 | target-procs.h: target.elf gen-procs.sh 27 | ./gen-procs.sh >$@ 28 | 29 | target.elf: target.o target.ld 30 | $(M68KCC) -nostdlib -Wl,-T target.ld -o $@ target.o 31 | 32 | target.o: target.c 33 | $(M68KCC) $(M68KCCFLAGS) -c -o $@ $< 34 | clean: 35 | rm -f target.o target.elf 36 | -------------------------------------------------------------------------------- /tekfwtool/gen-procs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "#ifndef __TARGET_PROCS_H" 4 | echo -e "#define __TARGET_PROCS_H\n" 5 | 6 | m68k-linux-gnu-nm target.elf|while read addr type name 7 | do 8 | #echo "[$name]" 9 | if [ $type == "t" -a $name != "gcc2_compiled." ]; then 10 | echo "#define TARGET_$name 0x$addr" 11 | fi 12 | done 13 | 14 | echo "#endif" 15 | -------------------------------------------------------------------------------- /tekfwtool/target-procs.h: -------------------------------------------------------------------------------- 1 | #ifndef __TARGET_PROCS_H 2 | #define __TARGET_PROCS_H 3 | 4 | #define TARGET_csum_hdr 0x05010396 5 | #define TARGET_find_flash 0x050107c0 6 | #define TARGET_flash_erase 0x05010522 7 | #define TARGET_flash_erase_intel_s5 0x050102e4 8 | #define TARGET_flash_erase_intel_sa 0x05010342 9 | #define TARGET_flash_load_to_pagebuffer_intel_sa 0x050103e4 10 | #define TARGET_flash_program 0x05010640 11 | #define TARGET_flash_program_page_intel_sa 0x050105ee 12 | #define TARGET_flash_program_single_cmd40 0x050105a0 13 | #define TARGET_flash_wait_bsr 0x05010242 14 | #define TARGET_flash_wait_gsr 0x050101a0 15 | #define TARGET_flash_wait_sr 0x05010110 16 | #define TARGET_flash_write_pagebuffer_intel_sa 0x05010488 17 | #define TARGET_identify_flash 0x0501077e 18 | #define TARGET_init 0x0501088e 19 | #define TARGET__memset 0x05010024 20 | #define TARGET_udelay 0x050100ec 21 | #endif 22 | -------------------------------------------------------------------------------- /tekfwtool/target.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tekfwtool/target.bin -------------------------------------------------------------------------------- /tekfwtool/target.c: -------------------------------------------------------------------------------- 1 | typedef unsigned char uint8_t; 2 | typedef unsigned short uint16_t; 3 | typedef unsigned int uint32_t; 4 | 5 | #define NULL (void *)0 6 | #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(_x[0])) 7 | 8 | uint32_t bss_begin, bss_end; 9 | 10 | void (*_console_log)(char *fmt, ...) = (void *)0x16ba; 11 | 12 | #define console_log 13 | //_console_log 14 | struct gpib_hdr { 15 | uint8_t cmd; 16 | uint8_t csum; 17 | uint16_t len; 18 | }; 19 | 20 | struct gpib_flash_program_cmd { 21 | uint32_t arg0; 22 | uint32_t arg1; 23 | uint32_t function; 24 | uint32_t *base; 25 | uint32_t data[128]; 26 | }; 27 | 28 | struct gpib_flash_erase_cmd { 29 | struct gpib_hdr *hdr; 30 | uint32_t *base; 31 | }; 32 | 33 | struct flash_descriptor { 34 | uint8_t manufacturer; 35 | uint8_t device; 36 | uint32_t size; 37 | uint32_t blocksize; 38 | int (*erase_chip)(uint32_t *base); 39 | int (*program_single)(uint32_t *base, uint32_t data); 40 | int (*program_page)(uint32_t *base, uint32_t *data, uint16_t len); 41 | }; 42 | 43 | static struct flash_descriptor *current_flash; 44 | 45 | static void _memset(void *dst, char c, int len) 46 | { 47 | int unaligned = len % 4; 48 | char *dst8 = (char *)dst; 49 | uint32_t *dst32 = (uint32_t *)dst; 50 | char c32; 51 | 52 | while(unaligned--) { 53 | *dst8++ = c; 54 | len--; 55 | } 56 | 57 | c32 = (c << 24) | (c << 16) | (c << 8) | c; 58 | len /= 4; 59 | 60 | while(len--) 61 | *dst32++ = c32; 62 | } 63 | 64 | static void udelay(int delay) 65 | { 66 | volatile int i; 67 | for(i = 0; i < delay; i++); 68 | } 69 | 70 | static int flash_wait_sr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 71 | { 72 | uint32_t buf; 73 | uint32_t _mask = (mask << 16) | mask; 74 | uint32_t _result = (result << 16) | result; 75 | int ret = -1; 76 | 77 | while(tries--) { 78 | //console_log("flash_wait_sr: %08x: %08x\n", base, *(uint32_t *)base); 79 | if ((*base & _mask) == _result) 80 | break; 81 | 82 | udelay(10000); 83 | } 84 | 85 | if (!tries) { 86 | console_log("flash_wait_sr timeout\n"); 87 | return -1; 88 | } 89 | ret = 0; 90 | out: 91 | return ret; 92 | } 93 | 94 | static int flash_wait_gsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 95 | { 96 | uint32_t buf; 97 | uint32_t _mask = (mask << 16) | mask; 98 | uint32_t _result = (result << 16) | result; 99 | int ret = -1; 100 | 101 | base = (uint32_t *)(((uint32_t)base) & ~0x1fffff); 102 | base += 2; 103 | 104 | while(tries--) { 105 | //console_log("flash_wait_gsr: %08x: %08x\n", base, *(uint32_t *)base); 106 | if ((*base & _mask) == _result) 107 | break; 108 | 109 | udelay(10000); 110 | } 111 | 112 | if (!tries) { 113 | console_log("flash_wait_gsr timeout\n"); 114 | return -1; 115 | } 116 | ret = 0; 117 | out: 118 | return ret; 119 | } 120 | 121 | static int flash_wait_bsr(uint32_t *base, uint16_t mask, uint16_t result, int tries) 122 | { 123 | uint32_t buf; 124 | uint32_t _mask = (mask << 16) | mask; 125 | uint32_t _result = (result << 16) | result; 126 | int ret = -1; 127 | 128 | base = (uint32_t *)(((uint32_t)base) & ~0x1ffff); 129 | base += 1; 130 | 131 | while(tries--) { 132 | //console_log("flash_wait_bsr: %08x: %08x (mask %08x/%08x\n", base, *base, _mask, _result); 133 | if ((*base & _mask) == _result) 134 | break; 135 | udelay(10000); 136 | } 137 | 138 | if (!tries) 139 | return -1; 140 | ret = 0; 141 | out: 142 | return ret; 143 | } 144 | 145 | 146 | static int flash_erase_intel_s5(uint32_t *base) 147 | { 148 | *base = 0x30303030; /* erase all unlocked blocks */ 149 | *base = 0xd0d0d0d0; /* confirm erase */ 150 | 151 | *base = 0x70707070; /* read status register */ 152 | 153 | if (flash_wait_sr(base, 0x0080, 0x0080, 0x100000) == -1) 154 | return -1; 155 | 156 | *base = 0x50505050; /* clear status register */ 157 | 158 | *base = 0xffffffff; 159 | return 0; 160 | } 161 | 162 | static int flash_erase_intel_sa(uint32_t *base) 163 | { 164 | *base = 0xa7a7a7a7; /* erase all unlocked blocks */ 165 | *base = 0xd0d0d0d0; /* confirm erase */ 166 | 167 | *base = 0x71717171; /* read extended status register */ 168 | 169 | if (flash_wait_gsr(base, 0x00a0, 0x0080, 0x100000) == -1) 170 | return -1; 171 | 172 | *base = 0xffffffff; 173 | return 0; 174 | } 175 | 176 | static uint8_t csum_hdr(struct gpib_hdr *hdr) 177 | { 178 | uint32_t i; 179 | uint8_t csum; 180 | uint8_t *buf = (uint8_t *)&hdr; 181 | 182 | csum = buf[0]; 183 | 184 | for(i = 2; i < hdr->len + sizeof(struct gpib_hdr) - 2; i++) 185 | csum += buf[i]; 186 | return csum; 187 | } 188 | 189 | static int flash_load_to_pagebuffer_intel_sa(uint32_t *base, uint32_t *data) 190 | { 191 | uint32_t *buf; 192 | int i,ret = -1; 193 | 194 | *base = 0x71717171; 195 | 196 | if (flash_wait_gsr(base, 0x0004, 0x0004, 0x100000) == -1) 197 | goto out; 198 | 199 | *base = 0xe0e0e0e0; 200 | 201 | *base = 0x007f007f; 202 | *base = 0x00000000; 203 | 204 | buf = (uint32_t *)data; 205 | 206 | for(i = 0; i < 128; i++) 207 | *base++ = *buf++; 208 | ret = 0; 209 | out: 210 | *base = 0xffffffff; 211 | return ret; 212 | } 213 | 214 | static int flash_write_pagebuffer_intel_sa(uint32_t *base) 215 | { 216 | int ret = -1; 217 | uint32_t buf; 218 | 219 | *base = 0x71717171; 220 | 221 | if (flash_wait_bsr(base, 0x0008, 0x0000, 0x100000) == -1) 222 | goto out; 223 | 224 | *base = 0x0c0c0c0c; 225 | 226 | *base = 0x007f007f; 227 | *base = 0x00000000; 228 | 229 | *base = 0x71717171; 230 | 231 | if (flash_wait_bsr(base, 0x0080, 0x0080, 0x100000) == -1) 232 | goto out; 233 | 234 | *base = 0xffffffff; 235 | *base = 0xffffffff; 236 | ret = 0; 237 | out: 238 | return ret; 239 | 240 | } 241 | 242 | static void flash_erase(struct gpib_hdr *hdr) 243 | { 244 | struct gpib_flash_erase_cmd *cmd = (struct gpib_flash_erase_cmd *)hdr; 245 | uint32_t *base = (uint32_t *)0x01000000; 246 | 247 | console_log("flash_erase\n"); 248 | _memset(hdr, 0, sizeof(hdr)); 249 | hdr->cmd = '-'; 250 | 251 | if (!current_flash) 252 | goto out; 253 | 254 | if (current_flash->erase_chip(base) == -1) { 255 | console_log("flash_erase failed\n"); 256 | goto out; 257 | } 258 | 259 | hdr->cmd = 'P'; 260 | out: 261 | *base = 0xffffffff; 262 | hdr->csum = csum_hdr(hdr); 263 | 264 | } 265 | 266 | static int flash_program_single_cmd40(uint32_t *base, uint32_t data) 267 | { 268 | int i, ret = -1; 269 | 270 | *base = 0x40404040; 271 | *base = data; 272 | 273 | if (flash_wait_gsr(base, 0x0080, 0x0080, 1000) == -1) 274 | goto out; 275 | 276 | *base = 0xffffffff; 277 | return 0; 278 | out: 279 | return -1; 280 | } 281 | 282 | static int flash_program_page_intel_sa(uint32_t *base, uint32_t *data, uint16_t len) 283 | { 284 | if (flash_load_to_pagebuffer_intel_sa(base, data) == -1) 285 | goto out; 286 | 287 | if (flash_write_pagebuffer_intel_sa(base) == -1) 288 | goto out; 289 | 290 | *base = 0x50505050; 291 | *base = 0xffffffff; 292 | return 0; 293 | out: 294 | return -1; 295 | } 296 | 297 | struct cmd_params { 298 | struct gpib_hdr hdr; 299 | struct gpib_flash_program_cmd *cmd; 300 | }; 301 | 302 | static void flash_program(struct cmd_params *params) 303 | { 304 | int i, ret = -1; 305 | uint32_t *base = params->cmd->base; 306 | uint32_t len = params->hdr.len - 16; 307 | uint32_t offset = 0; 308 | 309 | // console_log("flash_program: %d bytes @ %08x\n", len, base); 310 | 311 | _memset(¶ms->hdr, 0, sizeof(struct gpib_hdr)); 312 | params->hdr.cmd = '-'; 313 | 314 | if (!current_flash) 315 | goto out; 316 | 317 | #if 0 318 | /* hard, since len is unsigned. */ 319 | if (len < 0) 320 | goto out; 321 | #endif 322 | 323 | 324 | if (current_flash->program_page) { 325 | while (len >= 512) { 326 | current_flash->program_page(base + offset, params->cmd->data + offset, 512); 327 | len -= 512; 328 | offset += (512/4); 329 | } 330 | } 331 | 332 | len /= 4; 333 | for(i = 0; i < (int) len; i++) { 334 | current_flash->program_single(base + offset, params->cmd->data[i]); 335 | offset += 1; 336 | } 337 | 338 | params->hdr.cmd = 'P'; 339 | out: 340 | *base = 0xffffffff; 341 | params->hdr.csum = csum_hdr(¶ms->hdr); 342 | } 343 | 344 | 345 | struct flash_descriptor flash_types[] = { 346 | /* Intel TE28F160S5 */ 347 | { .manufacturer = 0xb0, 348 | .device = 0xd0, 349 | .size = 0x200000, 350 | .blocksize = 0x200, 351 | .erase_chip = flash_erase_intel_s5, 352 | .program_single = flash_program_single_cmd40, 353 | },{ 354 | /* Intel E28F016SA */ 355 | .manufacturer = 0x89, 356 | .device = 0xa0, 357 | .size = 0x200000, 358 | .blocksize = 0x200, 359 | .erase_chip = flash_erase_intel_sa, 360 | .program_single = flash_program_single_cmd40, 361 | .program_page = flash_program_page_intel_sa, 362 | } 363 | }; 364 | 365 | static uint32_t identify_flash(uint32_t *base) 366 | { 367 | uint32_t id; 368 | *base = 0x90909090; 369 | id = (*base & 0x00ff00ff) << 8; 370 | id |= (*(base+1) & 0x00ff00ff); 371 | *base = 0xffffffff; 372 | return id; 373 | } 374 | 375 | static struct flash_descriptor *find_flash(void) 376 | { 377 | uint32_t id; 378 | int i; 379 | 380 | id = identify_flash((uint32_t *)0x01000000); 381 | if ((id & 0xffff) != ((id >> 16) & 0xffff)) 382 | return NULL; 383 | 384 | id &= 0xffff; 385 | 386 | for(i = 0; i < (int) ARRAY_SIZE(flash_types); i++) { 387 | if ((flash_types[i].device == (id & 0xff)) && 388 | ((flash_types[i].manufacturer == (id >> 8)))) 389 | return flash_types + i; 390 | } 391 | console_log("Unknown flash with Vendor ID 0x%02X, Device ID 0x%02X\n", id >> 8, id & 0xff); 392 | return NULL; 393 | } 394 | 395 | static void init(struct gpib_hdr *hdr) 396 | { 397 | console_log("target init\n"); 398 | _memset(&bss_begin, 0, bss_end - bss_begin); 399 | 400 | current_flash = find_flash(); 401 | _memset(hdr, 0, sizeof(hdr)); 402 | if (current_flash) 403 | hdr->cmd = 'P'; 404 | else 405 | hdr->cmd = 'X'; 406 | hdr->csum = csum_hdr(hdr); 407 | } 408 | -------------------------------------------------------------------------------- /tekfwtool/target.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x05010000; 4 | .text : { *(.text) } 5 | _bss_begin = .; 6 | .bss : { *(.bss) } 7 | _bss_end = .; 8 | .data : { *(.data) } 9 | } 10 | -------------------------------------------------------------------------------- /tekfwtool/tekfwtool.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(__MSDOS__) 13 | #include /* can this be removed? */ 14 | #include "dosdefs.h" 15 | #include "tfdos.h" //simply tekfwtool.h renamed to 8.3-safe name 16 | #include "tgtdummy.h" 17 | #else 18 | #include "target-procs.h" 19 | #include "tekfwtool.h" 20 | #endif 21 | 22 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 23 | #include /* can this be removed? */ 24 | #include 25 | #include "ni488.h" 26 | #elif defined(__linux__) 27 | /* linux with linux-gpib */ 28 | #include 29 | #elif defined(__APPLE__) 30 | /* MacOS with NI GPIB drivers */ 31 | #include 32 | #else 33 | #error "Unknown compiler environment!" 34 | #endif 35 | 36 | 37 | #define DEFAULT_GPIBADDR 29 38 | 39 | 40 | #if !defined (PROG_NAME) 41 | #define PROG_NAME __FILE__ 42 | #endif 43 | #if !defined (GIT_VERSION) 44 | #define GIT_VERSION "unknown" 45 | #endif 46 | #if !defined (BUILD_TIME) 47 | #define BUILD_TIME __DATE__ " " __TIME__ 48 | #endif 49 | 50 | 51 | 52 | int Dev; 53 | const char *ErrorMnemonic[] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", 54 | "ESAC", "EABO", "ENEB", "EDMA", "", 55 | "EOIP", "ECAP", "EFSO", "", "EBUS", 56 | "ESTB", "ESRQ", "", "", "", "ETAB"}; 57 | 58 | static int abort_requested = 0; 59 | static int debug; 60 | 61 | #define UNUSED(x) (void)(x) 62 | 63 | static void sigint_handler(int arg) 64 | { 65 | UNUSED(arg); 66 | abort_requested = 1; 67 | } 68 | 69 | static void GPIBCleanup(int Dev, char* ErrorMsg) 70 | { 71 | printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n", 72 | ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]); 73 | if (Dev != -1) { 74 | printf("Cleanup: Taking device offline\n"); 75 | ibonl (Dev, 0); 76 | } 77 | } 78 | 79 | #if 0 80 | /* currently not used */ 81 | static int write_command(char *cmd) 82 | { 83 | ibwrt (Dev, cmd, strlen(cmd)); 84 | if (ibsta & ERR) 85 | return -1; 86 | return 0; 87 | } 88 | #endif 89 | 90 | #if 0 91 | /* currently not used */ 92 | static int query(char *query, char *buf, int maxsize) 93 | { 94 | 95 | ibwrt (Dev, query, strlen(query)); 96 | if (ibsta & ERR) 97 | return -1; 98 | 99 | ibrd (Dev, buf, maxsize); 100 | if (ibsta & ERR) 101 | return -1; 102 | 103 | buf[ibcntl - 1] = '\0'; 104 | return ibcntl; 105 | } 106 | #endif 107 | 108 | static void hexdump(void *_buf, int len) 109 | { 110 | int i; 111 | uint8_t *buf = (uint8_t *)_buf; 112 | for(i = 0; i < len; i++) 113 | fprintf(stderr, "%02X ", buf[i]); 114 | fprintf(stderr, "\n"); 115 | } 116 | 117 | static void build_csum(struct cmd_hdr *hdr) 118 | { 119 | uint8_t csum = 0; 120 | uint32_t i; 121 | for(i = 0; i < be16_to_cpu(hdr->len) + sizeof(struct cmd_hdr); i++) 122 | csum += ((uint8_t *)hdr)[i]; 123 | hdr->csum = csum; 124 | } 125 | 126 | static int write_memory(uint32_t addr, uint8_t *buf, int len) 127 | { 128 | struct memory_write_cmd cmd; 129 | struct cmd_hdr hdr; 130 | char c; 131 | 132 | memset(&cmd, 0, sizeof(cmd)); 133 | cmd.hdr.cmd = 'M'; 134 | cmd.hdr.len = cpu_to_be16(len + 8); 135 | cmd.addr = cpu_to_be32(addr); 136 | cmd.len = cpu_to_be32(len); 137 | 138 | memcpy(cmd.buf, buf, len); 139 | 140 | build_csum((struct cmd_hdr *)&cmd); 141 | if (debug > 1) 142 | hexdump(&cmd, len + 12); 143 | 144 | ibwrt (Dev, &cmd, len + 12); 145 | if (ibsta & ERR) { 146 | fprintf(stderr, "%s: writing command failed\n", __func__); 147 | return -1; 148 | } 149 | 150 | ibrd(Dev, &c, 1); 151 | if (ibcntl != 1 || c != '+') { 152 | fprintf(stderr, "%s: response reading failed\n", __func__); 153 | return -1; 154 | } 155 | 156 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 157 | if (ibsta & ERR) { 158 | fprintf(stderr, "%s: response reading failed\n", __func__); 159 | return -1; 160 | } 161 | 162 | if (ibcntl < (signed)sizeof(hdr)) { 163 | fprintf(stderr, "%s: short header\n", __func__); 164 | return -1; 165 | } 166 | 167 | if (hdr.cmd != '=') { 168 | fprintf(stderr, "%s: invalid response: %c\n", __func__, hdr.cmd); 169 | return -1; 170 | } 171 | c = '+'; 172 | ibwrt(Dev, &c, 1); 173 | return 0; 174 | } 175 | 176 | static int branch_cmd(uint32_t addr, uint32_t arg0, uint8_t *data, int *datalen) 177 | { 178 | struct branch_cmd cmd; 179 | uint8_t buf[1024]; 180 | struct cmd_hdr hdr; 181 | char c; 182 | 183 | memset(&cmd, 0, sizeof(cmd)); 184 | cmd.hdr.cmd = 'B'; 185 | cmd.hdr.len = cpu_to_be16(16 + *datalen); 186 | cmd.function = cpu_to_be32(addr); 187 | // cmd.argc = cpu_to_be32(2); 188 | // cmd.unknown = cpu_to_be32(2); 189 | cmd.arg0 = cpu_to_be32(arg0); 190 | memcpy(&cmd.buffer, data, *datalen); 191 | 192 | build_csum((struct cmd_hdr *)&cmd); 193 | if (debug > 1) 194 | hexdump(&cmd, be16_to_cpu(cmd.hdr.len) + sizeof(struct cmd_hdr)); 195 | 196 | ibwrt (Dev, &cmd, 20 + *datalen); 197 | if (ibsta & ERR) { 198 | fprintf(stderr, "%s: writing command failed\n", __func__); 199 | return -1; 200 | } 201 | 202 | ibrd(Dev, &c, 1); 203 | if (ibcntl != 1 || c != '+') { 204 | fprintf(stderr, "%s: response reading failed: ibcntl: %u, %02x\n", __func__, (unsigned int) ibcntl, c); 205 | return -1; 206 | } 207 | 208 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 209 | if (ibsta & ERR) { 210 | fprintf(stderr, "%s: response reading failed\n", __func__); 211 | return -1; 212 | } 213 | 214 | if (ibcntl < (signed)sizeof(hdr)) { 215 | fprintf(stderr, "%s: short header\n", __func__); 216 | return -1; 217 | } 218 | 219 | if (debug > 1) 220 | hexdump(&hdr, 4); 221 | 222 | if (hdr.len) { 223 | printf("reading %u bytes\n", be16_to_cpu(hdr.len)); 224 | ibrd(Dev, buf, be16_to_cpu(hdr.len)); 225 | if (ibsta & ERR) { 226 | fprintf(stderr, "%s: reading of additional data failed\n", __func__); 227 | return -1; 228 | } 229 | } 230 | 231 | if (hdr.len) 232 | hexdump(buf, be16_to_cpu(hdr.len)); 233 | 234 | if (hdr.cmd != 'P') { 235 | fprintf(stderr, "%s: invalid response: %c\n", __func__, hdr.cmd); 236 | return -1; 237 | } 238 | c = '+'; 239 | ibwrt(Dev, &c, 1); 240 | return 0; 241 | } 242 | 243 | static int read_memory(uint32_t addr, uint8_t *buf, int len) 244 | { 245 | struct memory_read_cmd cmd; 246 | struct cmd_hdr hdr; 247 | int responselen; 248 | char c; 249 | 250 | memset(&cmd, 0, sizeof(cmd)); 251 | cmd.hdr.cmd = 'm'; 252 | cmd.hdr.len = cpu_to_be16(sizeof(cmd) - 4); 253 | cmd.addr = cpu_to_be32(addr); 254 | cmd.len = cpu_to_be32(len); 255 | 256 | build_csum((struct cmd_hdr *)&cmd); 257 | if (debug > 1) 258 | hexdump(&cmd, sizeof(cmd)); 259 | 260 | ibwrt (Dev, &cmd, sizeof(struct memory_read_cmd)); 261 | if (ibsta & ERR) { 262 | fprintf(stderr, "%s: writing command failed\n", __func__); 263 | return -1; 264 | } 265 | 266 | ibrd(Dev, &c, 1); 267 | if (ibcntl != 1 || c != '+') { 268 | fprintf(stderr, "%s: response reading failed\n", __func__); 269 | return -1; 270 | } 271 | ibrd(Dev, &hdr, sizeof(struct cmd_hdr)); 272 | if (ibsta & ERR) { 273 | fprintf(stderr, "%s: response reading failed\n", __func__); 274 | return -1; 275 | } 276 | 277 | if (debug > 1) { 278 | hexdump(&hdr, sizeof(hdr)); 279 | } 280 | 281 | if (ibcntl < (signed)sizeof(hdr)) { 282 | fprintf(stderr, "%s: short header (ibcntl=%u)\n", __func__, (unsigned int) ibcntl); 283 | return -1; 284 | } 285 | 286 | if (hdr.cmd != '=') { 287 | fprintf(stderr, "%s: invalid response: %c\n", __func__, hdr.cmd); 288 | return -1; 289 | } 290 | 291 | responselen = be16_to_cpu(hdr.len); 292 | 293 | if (responselen != len) { 294 | fprintf(stderr, "%s: short response (%d < %u)\n", 295 | __func__, responselen, len); 296 | return -1; 297 | } 298 | ibrd(Dev, buf, responselen); 299 | if (ibsta & ERR || ibcntl < len) { 300 | fprintf(stderr, "%s: response reading failed\n", __func__); 301 | return -1; 302 | } 303 | 304 | c = '+'; 305 | ibwrt(Dev, &c, 1); 306 | if (ibsta & ERR) { 307 | fprintf(stderr, "%s: unable to send ACK\n", __func__); 308 | return -1; 309 | } 310 | 311 | return 0; 312 | } 313 | 314 | static struct option long_options[] = { 315 | { "addr", required_argument, 0, 'a' }, 316 | { "read", required_argument, 0, 'r' }, 317 | { "write", required_argument, 0, 'w' }, 318 | { "base", required_argument, 0, 'b' }, 319 | { "length", required_argument, 0, 'l' }, 320 | { "debug", no_argument, 0, 'd' }, 321 | { "flash-id", no_argument, 0, 'i' }, 322 | { "flash-erase", no_argument, 0, 'e' }, 323 | { "flash-program", required_argument, 0, 'p' }, 324 | { "help", no_argument, 0, 'h' }, 325 | { NULL, 0, 0, 0 } 326 | }; 327 | 328 | static char* ident = PROG_NAME " Version: " GIT_VERSION " Build time: " BUILD_TIME; 329 | static void print_version(void) 330 | { 331 | fprintf(stderr, "# %s\n", ident); 332 | } 333 | 334 | static void usage(void) 335 | { 336 | print_version(); /* XXX should have it's own flag */ 337 | fprintf(stderr, "\nusage:\n" 338 | "--read -r read from memory to file\n" 339 | "--write -w read from file to memory\n" 340 | "--base -b base address for read/write/program\n" 341 | "--length -l length of data to be read or written\n" 342 | "--addr -a device's GPIB address (optional). Default 29\n" 343 | "--debug -d enable debug logging\n" 344 | "--flash-id -i print ID of flash chips\n" 345 | "--flash-erase -e erase flash at base address\n" 346 | "--flash-program -p program flash at base address\n" 347 | ""); 348 | } 349 | 350 | static uint32_t to_number(char *s) 351 | { 352 | uint32_t val; 353 | char *endp; 354 | 355 | if (*s == '0' && *(s+1) == 'x') { 356 | val = strtoul(s+2, &endp, 16); 357 | if (*endp != '\0') { 358 | fprintf(stderr, "failed to parse: [%s]\n", s); 359 | return 0; 360 | } 361 | } else { 362 | val = strtoul(s, &endp, 10); 363 | if (*endp != '\0') { 364 | fprintf(stderr, "failed to parse: [%s]\n", s); 365 | return 0; 366 | } 367 | } 368 | return val; 369 | } 370 | 371 | static int flash_program(uint32_t base, uint8_t *buf, int size) 372 | { 373 | int len = size; 374 | return branch_cmd(TARGET_flash_program, base, buf, &len); 375 | } 376 | 377 | static int flash_erase(uint32_t base) 378 | { 379 | int len = 0; 380 | printf("Erasing flash @ 0x%08lx\n", (unsigned long) base); 381 | return branch_cmd(TARGET_flash_erase, base, NULL, &len); 382 | } 383 | 384 | static int init_firmware(void) 385 | { 386 | int len = 0; 387 | return branch_cmd(TARGET_init, 0, NULL, &len); 388 | } 389 | 390 | static int download_firmware(void) 391 | { 392 | FILE *file = fopen("target.bin", "rb"); 393 | char buf[512]; 394 | size_t len, offset = 0; 395 | int ret = -1; 396 | 397 | if (!file) { 398 | fprintf(stderr, "failed to open target.bin: %s", strerror(errno)); 399 | return -1; 400 | } 401 | 402 | printf("Downloading firmware to scope\n"); 403 | while((len = fread(buf, 1, sizeof(buf), file)) > 0) { 404 | if (write_memory(TARGET_FIRMWARE_BASE + offset, (uint8_t *)&buf, len) == -1) { 405 | fprintf(stderr, "error downloading firmware\n"); 406 | goto out; 407 | } 408 | offset += len; 409 | } 410 | 411 | if (ferror(file)) { 412 | fprintf(stderr, "error reading firmware from file\n"); 413 | goto out; 414 | } 415 | 416 | printf("Pinging firmware\n"); 417 | if (init_firmware() == -1) { 418 | fprintf(stderr, "failed to ping firmware\n"); 419 | goto out; 420 | } 421 | printf("Firmware downloaded\n"); 422 | ret = 0; 423 | out: 424 | fclose(file); 425 | return ret; 426 | } 427 | 428 | int main(int argc, char **argv) 429 | { 430 | uint32_t len, addr, base = 0, length = 0; 431 | int devaddr = DEFAULT_GPIBADDR; 432 | char c; 433 | uint8_t buf[1024]; 434 | int optidx; 435 | FILE *file = NULL; 436 | int read_op = 0, write_op = 0, erase_flash_op = 0, flash_write_op = 0; 437 | int readlen; 438 | time_t start, now; 439 | 440 | while((c = getopt_long(argc, argv, "a:r:w:b:l:p:hied", 441 | long_options, &optidx)) != -1) { 442 | switch(c) { 443 | case 'h': 444 | usage(); 445 | return 0; 446 | case 'a': 447 | devaddr = (int) to_number(optarg); 448 | if ((devaddr < 0) || (devaddr > 30)) { 449 | printf("invalid GPIB address\n"); 450 | return 1; 451 | } 452 | break; 453 | case 'l': 454 | if (length) { 455 | fprintf(stderr, "length given twice"); 456 | return 1; 457 | } 458 | length = to_number(optarg); 459 | break; 460 | case 'b': 461 | if (base) { 462 | fprintf(stderr, "base given twice"); 463 | return 1; 464 | } 465 | base = to_number(optarg); 466 | break; 467 | case 'r': 468 | if (file) { 469 | fprintf(stderr, "read given twice"); 470 | return 1; 471 | } 472 | file = fopen(optarg, "wb"); 473 | if (!file) { 474 | fprintf(stderr, "failed to open output file: %s\n", strerror(errno)); 475 | return 1; 476 | 477 | } 478 | read_op = 1; 479 | break; 480 | case 'w': 481 | if (file) { 482 | fprintf(stderr, "read given twice"); 483 | return 1; 484 | } 485 | file = fopen(optarg, "rb"); 486 | if (!file) { 487 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 488 | return 1; 489 | 490 | } 491 | 492 | write_op = 1; 493 | break; 494 | case 'p': 495 | if (file) { 496 | fprintf(stderr, "read given twice"); 497 | return 1; 498 | } 499 | file = fopen(optarg, "rb"); 500 | if (!file) { 501 | fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); 502 | return 1; 503 | 504 | } 505 | flash_write_op = 1; 506 | break; 507 | 508 | case 'e': 509 | erase_flash_op = 1; 510 | break; 511 | case 'd': 512 | debug++; 513 | break; 514 | default: 515 | usage(); 516 | goto bad_exit; 517 | } 518 | } 519 | if (optind <= 1) { 520 | usage(); 521 | return 1; 522 | } 523 | 524 | if (!read_op && !write_op && !erase_flash_op && !flash_write_op) { 525 | printf("No operation specified !\n"); 526 | usage(); 527 | goto bad_exit; 528 | } 529 | 530 | if (!length) { 531 | fprintf(stderr, "%s: length required\n", __func__); 532 | goto bad_exit; 533 | } 534 | 535 | if ((erase_flash_op || flash_write_op) && (TARGET_init == 0)) { 536 | printf("Cannot flash: compiled without flash write support.\n"); 537 | goto bad_exit; 538 | } 539 | 540 | signal(SIGINT, sigint_handler); 541 | 542 | Dev = ibdev(0, devaddr, 0, T100s, 1, 0); 543 | if (ibsta & ERR) { 544 | printf("Unable to open device\nibsta = 0x%x iberr = %d\n", 545 | ibsta, iberr); 546 | goto bad_exit; 547 | } 548 | 549 | ibclr (Dev); 550 | if (ibsta & ERR) { 551 | GPIBCleanup(Dev, "Unable to clear device"); 552 | goto bad_exit; 553 | } 554 | 555 | if (erase_flash_op || flash_write_op) { 556 | if (download_firmware() == -1) 557 | goto bad_exit; 558 | } 559 | if (erase_flash_op) { 560 | flash_erase(base); 561 | return 0; 562 | } 563 | 564 | time(&start); 565 | for(addr = base; addr < base + length && !abort_requested;) { 566 | len = MIN(512, base + length - addr); 567 | if (read_op) { 568 | if (read_memory(addr, buf, len) == -1) 569 | goto bad_exit; 570 | 571 | if (fwrite(buf, 1, len, file) != len) { 572 | fprintf(stderr, "short fwrite\n"); 573 | goto bad_exit; 574 | } 575 | if ((addr % 0x1000) == 0) { 576 | time(&now); 577 | fprintf(stderr, "READ %08lx/%08lx, %3u%% %4ds\r", 578 | (unsigned long) (addr - base), (unsigned long) length, 579 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 580 | } 581 | 582 | addr += len; 583 | } else if (write_op) { 584 | readlen = fread(buf, 1, len, file); 585 | if (readlen == 0) 586 | break; 587 | 588 | if (readlen == -1) { 589 | fprintf(stderr, "fread: %s\n", strerror(errno)); 590 | goto bad_exit; 591 | } 592 | if (write_memory(addr, buf, readlen) == -1){ 593 | goto bad_exit; 594 | } 595 | if ((addr % 0x1000) == 0) { 596 | time(&now); 597 | fprintf(stderr, "WRITE %08lx/%08lx, %3u%% %4ds\r", 598 | (unsigned long) (addr - base), (unsigned long) length, 599 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 600 | } 601 | addr += readlen; 602 | } else if (flash_write_op) { 603 | len = MIN(512, base + length - addr); 604 | readlen = fread(buf, 1, len, file); 605 | if (readlen == 0) 606 | break; 607 | 608 | if (readlen == -1) { 609 | fprintf(stderr, "fread: %s\n", strerror(errno)); 610 | goto bad_exit; 611 | } 612 | 613 | if (flash_program(addr, buf, readlen) == -1) { 614 | fprintf(stderr, "flash programming failed\n"); 615 | goto bad_exit; 616 | } 617 | addr += readlen; 618 | if ((addr % 0x1000) == 0) { 619 | time(&now); 620 | fprintf(stderr, "FLASH WRITE %08lx/%08lx, %3u%% %4ds\r", 621 | (unsigned long) (addr - base), (unsigned long) length, 622 | (unsigned) ((addr - base) * 100 / length), (int)(now - start)); 623 | } 624 | } else { 625 | fprintf(stderr, "either read or write required\n"); 626 | goto bad_exit; 627 | } 628 | } 629 | fprintf(stderr, "\n"); 630 | fclose(file); 631 | ibonl(Dev, 0); 632 | return 0; 633 | 634 | bad_exit: 635 | if (file) { 636 | fclose(file); 637 | } 638 | return 1; 639 | 640 | } 641 | -------------------------------------------------------------------------------- /tekfwtool/tekfwtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEKFW_TOOL_H 2 | #define __TEKFW_TOOL_H 3 | 4 | #include 5 | #include 6 | 7 | #define TARGET_FIRMWARE_BASE 0x05010000 8 | 9 | /* change to using htonl, htons, ntohl, ntohs instead? */ 10 | #if defined(LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) 11 | #define cpu_to_be16(_x) ((((uint16_t) (_x) & 0xff) << 8) | (((_x) >> 8) & 0xff)) 12 | #define be16_to_cpu cpu_to_be16 13 | #define cpu_to_be32(_x) (cpu_to_be16(((_x) >> 16) & 0xffff) | \ 14 | (cpu_to_be16(((uint32_t) (_x) & 0xffff)) << 16)) 15 | #define be32_to_cpu cpu_to_be32 16 | #elif defined(BIG_ENDIAN) || defined(__BIG_ENDIAN) || defined(__BIG_ENDIAN__) 17 | #define cpu_to_be16 18 | #define cpu_to_be32 19 | #define be16_to_cpu 20 | #define be32_to_cpu 21 | #else 22 | #error Unknown endianness ! 23 | #endif 24 | 25 | #define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a)) 26 | 27 | struct cmd_hdr { 28 | uint8_t cmd; 29 | uint8_t csum; 30 | uint16_t len; 31 | }; 32 | 33 | struct memory_read_cmd { 34 | struct cmd_hdr hdr; 35 | uint32_t addr; 36 | uint32_t len; 37 | }; 38 | 39 | struct memory_write_cmd { 40 | struct cmd_hdr hdr; 41 | uint32_t addr; 42 | uint32_t len; 43 | uint8_t buf[1024]; 44 | }; 45 | 46 | struct branch_cmd { 47 | struct cmd_hdr hdr; 48 | uint32_t argc; 49 | uint32_t unknown; 50 | uint32_t function; 51 | uint32_t arg0; 52 | uint8_t buffer[512]; 53 | }; 54 | 55 | #define TARGET_FW_INIT 0 56 | #define TARGET_FW_FLASH_ERASE 1 57 | #define TARGET_FW_FLASH_PROGRAM 2 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tektool/.dir-locals.el: -------------------------------------------------------------------------------- 1 | ; Indentation settings for C in Emacs 2 | ; tektool.c is written in several different indentation styles, but the 3 | ; style mostly used seems quite close to Emacs "linux" style. 4 | ;((c-mode . ((c-file-style . "linux") 5 | ; (subdirs . nil))) 6 | ; ) 7 | (("tektool.c" . ((c-mode . ((c-file-style . "linux")))))) 8 | -------------------------------------------------------------------------------- /tektool/DIST/Nvrams.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragges/tektools/e27e36259f2089f05a18a798260b21e44bf87303/tektool/DIST/Nvrams.zip -------------------------------------------------------------------------------- /tektool/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # identify platform 3 | ifeq ($(OS),Windows_NT) 4 | OS_NAME := windows_nt 5 | else 6 | OS_NAME := $(shell uname -s) 7 | ifeq ($(OS_NAME), Linux) 8 | # Linux with linux-gpib 9 | CFLAGS += -g -fsigned-char -Wall -Wextra -pedantic -l gpib -L/usr/local/lib 10 | endif 11 | ifeq ($(OS_NAME), Darwin) 12 | # Darwin with NI 488.2 driver 13 | CFLAGS += -g -fsigned-char /Library/Frameworks/NI4882.framework/Resources/ni4882.o -framework CoreFoundation -I/Library/Frameworks/NI4882.framework/Headers 14 | endif 15 | endif 16 | 17 | 18 | # get version and build time strings 19 | GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" 20 | ifneq ($(GIT_VERSION), "") 21 | CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" 22 | endif 23 | BUILD_TIME := "$(shell date -u "+%Y-%m-%d %H:%M:%S")" 24 | ifneq ($(BUILD_TIME), "") 25 | CFLAGS += -DBUILD_TIME=\"$(BUILD_TIME)\" 26 | endif 27 | 28 | 29 | CFLAGS += -DPROG_NAME=\"$@\" 30 | 31 | 32 | tektool : tektool.c 33 | $(CC) $(CFLAGS) tektool.c -o tektool 34 | 35 | .PHONY : clean 36 | clean : 37 | -rm -fv tektool 38 | -rm -rfv tektool.dSYM 39 | --------------------------------------------------------------------------------