summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-07-09 23:33:56 +0200
committerDimitri Sokolyuk <demon@dim13.org>2019-07-09 23:33:56 +0200
commitc85434831114270daf1dd37783cf15b090b09e01 (patch)
treed9e0795862c16296e647be249338ee289216832e
parent8fff282c06c2b895e5b57b564f4cbbdc5a9204ba (diff)
Sync with v2.1.2, switch to amd64HEADv2.1.2master
-rw-r--r--_sp12dev40
-rw-r--r--changes.txt26
-rw-r--r--sp12.txt38
-rw-r--r--src/Makefile65
-rw-r--r--src/Makefile.bsd-wrapper2
-rw-r--r--src/buffer.c7
-rw-r--r--src/sp12.c204
7 files changed, 237 insertions, 145 deletions
diff --git a/_sp12dev b/_sp12dev
index b6639e0..a17dfd4 100644
--- a/_sp12dev
+++ b/_sp12dev
@@ -601,6 +601,40 @@ EXTD_FUSES_MESSAGE = xxxxxxx0 - self-programming enabled
READ_CALIBRATION = llhh hlll lllx xxxx llll llll oooo oooo
CALIB_MESSAGE = single calibration byte (page 24, 25, 159)
+begin 0D92
+-iD92
+-iT4313
+DEVICENAME = ATtiny4313
+FLASHSIZE = 2048
+EEPROMSIZE = 256
+PAGEMODE = 1
+PAGESIZE = 16
+POLL_RDY_BSY = hhhh llll llll llll xxxx xxxx xxxx xxxo
+READ_LOCK = lhlh hlll llll llll xxxx xxxx xxoo oooo
+WRITE_LOCK = hlhl hhll hhhx xxxx xxxx xxxx hhii iiii
+LOCK_MESSAGE = xxxx11 - no lock
+LOCK_MESSAGE = xxxx10 - write protected
+LOCK_MESSAGE = xxxx00 - read/write protected
+WRITE_FUSES = hlhl hhll hlhl llll xxxx xxxx iiii iiii
+READ_FUSES = lhlh llll llll llll xxxx xxxx oooo oooo
+FUSES_MESSAGE = 0xxxxxxx - CKDIV8 - divide clock by 8 (page 22)
+FUSES_MESSAGE = x0xxxxxx - CKOUT output clock on pin D2
+FUSES_MESSAGE = xxSUxxxx - start-up time (datasheet page 24)
+FUSES_MESSAGE = xxxxCKSE - CKSEL (datasheet page 22-24)
+WRITE_HIGH_FUSES = hlhl hhll hlhl hlll xxxx xxxx hili iiih
+READ_HIGH_FUSES = lhlh hlll llll hlll xxxx xxxx oooo oooo
+HIGH_FUSES_MESSAGE = 0xxxxxxx - debugWire enabled
+HIGH_FUSES_MESSAGE = x0xxxxxx - EEPROM preserved in chip erase
+HIGH_FUSES_MESSAGE = xx0xxxxx - serial programming enabled
+HIGH_FUSES_MESSAGE = xxx0xxxx - WDT always on (page 41)
+HIGH_FUSES_MESSAGE = xxxxBODx - BODLEVEL (page 34)
+HIGH_FUSES_MESSAGE = xxxxxxx1 - reset-pin enabled (page 52)
+WRITE_EXTD_FUSES = hlhl hhll hlhl lhll xxxx xxxx xxxx xxxi
+READ_EXTD_FUSES = lhlh llll llll hlll xxxx xxxx oooo oooo
+EXTD_FUSES_MESSAGE = xxxxxxx0 - self-programming enabled
+READ_CALIBRATION = llhh hlll lllx xxxx llll llll oooo oooo
+CALIB_MESSAGE = single calibration byte (page 24, 25, 159)
+
begin 0790
-i790
-iT13
@@ -1121,7 +1155,7 @@ FUSES_MESSAGE = 0xxxxxxx - CKDIV8 - divide clock by 8 (page 35)
FUSES_MESSAGE = x0xxxxxx - CKOUT output clock on pin B0
FUSES_MESSAGE = xxSUxxxx - start-up time (datasheet page 33)
FUSES_MESSAGE = xxxxCKSE - CKSEL (page 33)
-WRITE_HIGH_FUSES = hlhl hhll hlhl hlll llll llll iiii iiii
+WRITE_HIGH_FUSES = hlhl hhll hlhl hlll llll llll hhli iiii
READ_HIGH_FUSES = lhlh hlll llll hlll llll llll oooo oooo
HIGH_FUSES_MESSAGE = 0xxxxxxx - reset-pin disabled (page 85)
HIGH_FUSES_MESSAGE = x0xxxxxx - debugWire enabled
@@ -1131,8 +1165,8 @@ HIGH_FUSES_MESSAGE = xxxx0xxx - EEPROM preserved in chip erase
HIGH_FUSES_MESSAGE = xxxxxBZx - boot size (page 291)
HIGH_FUSES_MESSAGE = xxxxxxx0 - reset at boot loader (page 66)
WRITE_EXTD_FUSES = hlhl hhll hlhl lhll llll llll xxxx xiii
-READ_EXTD_FUSES = lhlh llll llll hlll llll llll xxxx xooo
-EXTD_FUSES_MESSAGE = BOD - BODLEVEL (datasheet page 43, 273)
+READ_EXTD_FUSES = lhlh llll llll hlll llll llll oooo oooo
+EXTD_FUSES_MESSAGE = xxxxxBOD - BODLEVEL (datasheet page 43, 273)
READ_CALIBRATION = llhh hlll llll llll llll llll oooo oooo
CALIB_MESSAGE = single calibration byte (datasheet page 298)
diff --git a/changes.txt b/changes.txt
index 2a380d9..e591a3c 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,3 +1,29 @@
+ CHANGES FROM VERSION 2.1.1 TO 2.1.2
+
+ Bug fixed in checksum calculation, which sometimes altered
+ content of a buffer used elsewhere. Unless you used the 'query
+ function' - query=1 in _sp12rc, to get sp12log.txt lines like:
+
+ ATtiny2313 -wpf RX433.hex checksum 37a7 Tue Aug 26 15:48:30 2014
+ ATtiny2313 -wef RX433.eep checksum f075 Tue Aug 26 15:48:30 2014
+
+ You won't have noticed. Other than that, this version is BSD-compatible
+ thanks to Dimitri Sokolyuk, who wrote:
+
+ Hallo Steven,
+
+ I have just ported your SP12 programmer to OpenBSD platform and would
+ like to contribute my changes back at you.
+ The essential part is just a few lines long, but I have also done some
+ code cleanup to keep the compiler quite by replacing strcat() a.o. with
+ strlcat() versions and by renaming `struct logging log' with `struct
+ logging logging' due to collision with math's log() as suggested by
+ compiler.
+ The final code compiles and works fine both at Linux and OpenBSD.
+
+ Have a nice day,
+ Dima
+
CHANGES FROM VERSION 2.1.0 TO 2.1.1
Artur Pundsack added support for the extended addressing
diff --git a/sp12.txt b/sp12.txt
index b5c3856..c2aee3d 100644
--- a/sp12.txt
+++ b/sp12.txt
@@ -330,7 +330,7 @@ INSTALLATION
DESCRIPTION
- The present version (2.0) should be suitable for all AVR uCs;
+ The present version (2.1) should be suitable for all AVR uCs;
but _sp12dev only contains definitions for the ones mentioned in
the table below. You can easily add definitions for others - have
a look at sp12dev.txt.
@@ -395,7 +395,7 @@ DESCRIPTION
on or off causes some bits in flash to flip, so it has to be
done *before* programming the uC. The 2343s don't have this
slight disadvantage.
- The supplied _sp12dev makes sp12 version 2.0 assume that
+ The supplied _sp12dev makes sp12 version 2.1 assume that
a uC with device code 0391 has a switchable RCEN fuse. It's
up to the user to determine or find out the use of of the
-R0/R1 option.
@@ -708,7 +708,7 @@ OPTIONS
When this option is not on the command line, the default
is used. Unless you change it (in _sp12rc), the default
- makes sp12 version 1.0 behave like previous versions, which
+ makes sp12 version 2.1 behave like previous versions, which
means that the Sck frequency and wave form will be suitable
for uCs running on an internal RC clock, at fairly low Vcc.
WARNING: When -Mn.n is set too high, the uC will misread
@@ -1001,9 +1001,9 @@ ACKNOWLEDGEMENTS
This product includes software developed by the University of
California, Berkeley and its contributors.
- The authors would like to thank Chris Jackson for pointing out
- the timing problems version 0.5 has on very fast machines, and
- for testing this version on those same machines.
+ The authors would like to thank Chris Jackson for pointing
+ out the timing problems an early version had on very fast
+ machines, and for testing a later version on those same machines.
Kevin Towers improved the code for reading Intel HEX files, to be
compatible with flash data as generated by the IAR C compiler.
@@ -1026,18 +1026,20 @@ BUGS & BOTHER
Please report them to the authors.
SP12 is known to run in Linux, in MS-DOS, in a Windows 3.X
- Dosbox and in a Windows 9X Dosbox, on machines ranging from a
- slow 386 to a 450MHz Pentium-II. Windows NT does not provide
- the access to the parallel port required by SP12.
-
- As reported by Chris Jackson:
- "One of the machines that I tried it on had a Parallel Port
- PCMCIA adapter installed. Unless the machine was powered up with
- this device fully disconnected, the driver for it was loaded by
- Windows. This meant that whenever SP12 set the port lines high,
- the driver would kick in and set them back low again. Depending on
- the speed of the driver's response, the programmer would sometimes
- work, and sometimes not - which caused a bit of confusion at first."
+ Dosbox and in a Windows Dosbox, on machines ranging from a
+ slow 386 to a 450MHz Pentium-II. Windows NT, XP and later
+ versions do not provide the access to the parallel port
+ required by SP12, but there are workarounds; see readme.win.
+
+ As reported by Chris Jackson: "One of the machines
+ that I tried it on had a Parallel Port PCMCIA adapter
+ installed. Unless the machine was powered up with this
+ device fully disconnected, the driver for it was loaded
+ by Windows. This meant that whenever SP12 set the port
+ lines high, the driver would kick in and set them back low
+ again. Depending on the speed of the driver's response, the
+ programmer would sometimes work, and sometimes not - which
+ caused a bit of confusion at first."
AUTHORS
Software: Steven Bolt (sbolt@xs4all.nl)
diff --git a/src/Makefile b/src/Makefile
index c3a8818..0b3fd18 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,21 +1,58 @@
-# $Id$
+#
+# Makefile for the Free Software Foundations gcc compiler
+# Optimize flag = 1 to achieve correct timing
+#
+CC=gcc
+LINK=gcc
+#
+# LINUX FLAGS
+CFLAGS=-c -O1 -Wall -DLINUX
+LFLAGS=-s -o
+TARGET=sp12
+ERASE=rm -f
+OBJECTS=sp12.o init.o flash.o device.o buffer.o eeprom.o
-PROG= sp12
-SRCS= buffer.c device.c eeprom.c flash.c init.c sp12.c
-HDRS= dos_cpt.h sp12.h
-CFLAGS+= -Wall -ggdb
-#LDADD+= -li386
-OBJS= ${SRCS:.c=.o}
+# DOS FLAGS
+#CFLAGS=-c -O1 -Wall
+#LFLAGS=-lemu -s -o
+#TARGET=sp12.exe
+#ERASE=del
+#OBJECTS=sp12.o init.o flash.o device.o buffer.o eeprom.o
-all: ${SRCS} ${HDRS} ${PROG}
+# Win FLAGS - MingW
+#CFLAGS=-c -O1 -Wall -mwindows -mconsole
+#LFLAGS=-s -o
+#TARGET=sp12.exe
+#ERASE=del
+#OBJECTS=sp12.o init.o flash.o device.o buffer.o eeprom.o winnt.o
-${PROG}: ${OBJS}
- ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
+all: $(TARGET)
-.c.o:
- ${CC} ${CFLAGS} -c $<
+sp12.o: sp12.c
+ $(CC) $(CFLAGS) sp12.c
+
+init.o: init.c
+ $(CC) $(CFLAGS) init.c
+
+flash.o: flash.c
+ $(CC) $(CFLAGS) flash.c
+
+device.o: device.c
+ $(CC) $(CFLAGS) device.c
+
+buffer.o: buffer.c
+ $(CC) $(CFLAGS) buffer.c
+
+eeprom.o: eeprom.c
+ $(CC) $(CFLAGS) eeprom.c
+
+winnt.o: winnt.c
+ $(CC) $(CFLAGS) winnt.c
+
+$(TARGET): makefile $(OBJECTS)
+ $(LINK) $(LFLAGS) $(TARGET) $(OBJECTS)
clean:
- rm -f a.out core *.core ${PROG} ${OBJS}
+ $(ERASE) $(TARGET)
+ $(ERASE) *.o
-.PHONY: clean ctags
diff --git a/src/Makefile.bsd-wrapper b/src/Makefile.bsd-wrapper
index 40a29a9..9aed8ae 100644
--- a/src/Makefile.bsd-wrapper
+++ b/src/Makefile.bsd-wrapper
@@ -5,7 +5,7 @@ BINDIR= /usr/local/bin
BINMODE= 4755
SRCS= buffer.c device.c eeprom.c flash.c init.c sp12.c
CFLAGS+= -Wall
-LDADD+= -li386
+LDADD+= -lamd64
NOMAN=
.include <bsd.prog.mk>
diff --git a/src/buffer.c b/src/buffer.c
index e6f4804..40822d4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -283,6 +283,7 @@ int readEepromFile(char eepromPath[], unsigned int eepromBuf[], long bufLimit) {
unsigned int checksum(unsigned int buffer[], long bufLimit) {
long idx;
+ long element;
unsigned int chksum = 0;
/*
@@ -290,8 +291,10 @@ unsigned int checksum(unsigned int buffer[], long bufLimit) {
*/
for (idx = 0; idx < bufLimit; idx++) {
if (buffer[idx] == 0xfff)
- buffer[idx] = 0xff;
- chksum = ((chksum>>1) + ((chksum & 1) ?0x8000:0) + buffer[idx]) & 0xffff;
+ element = 0xff;
+ else
+ element = buffer[idx];
+ chksum = ((chksum>>1) + ((chksum & 1) ?0x8000:0) + element) & 0xffff;
}
return(chksum);
}
diff --git a/src/sp12.c b/src/sp12.c
index 0f219ab..7c59a0d 100644
--- a/src/sp12.c
+++ b/src/sp12.c
@@ -34,25 +34,25 @@
#include <time.h>
#include "sp12.h"
-#define VERSION "2.1.1"
+#define VERSION "2.1.2"
const char USAGE[] = {
" SP12/32 version %s: A serial programmer for Atmel AVR uCs.\n"
" Copyright (C) 1997-2008 Ken Huntington, Kevin Towers,\n"
" Artur Pundsack, Pitronics.\n"
- "SYNOPSIS\n"
+ "SYNOPSIS\n"
" sp12 {-options} [filename or address(:data)] {-options} [filename...\n"
"OPTIONS\n"
" i[nnn] - init E - chip erase\n"
- " e - eprom area B - blank check\n"
+ " e - eprom area B - blank check\n"
" p - program area C - calculate checksum\n"
" w - write to L[n...n] - lock fuses\n"
" r - read from F[n...n] - fuses\n"
- " a - address(:data) next H[n...n] - high fuses\n"
+ " a - address(:data) next H[n...n] - high fuses\n"
" f - filename next X[n...n] - extended fuses\n"
- " I - create Intel Hex file c[nn] - calibration byte(s)\n"
- " h - hex dump with ascii M<n.n> - match Sck to uC clock\n"
+ " I - create Intel Hex file c[nn] - calibration byte(s)\n"
+ " h - hex dump with ascii M<n.n> - match Sck to uC clock\n"
" o0, o1 - optimization P<nnn> - parallel port control\n"
" s - show supported uCs t - timing check\n"
"EXAMPLES\n"
@@ -105,22 +105,24 @@ static unsigned int *flashBuf; /* flash buffer */
static unsigned int *eepromBuf; /* eeprom buffer */
static clock_t sp12Start, sp12End;
static double sp12Elapsed;
-
+
void exitSp12(int exitState) {
-
+
char binary[9] = "76543210"; /* Stores conversion num to binary */
-
+
portControl(DEFAULT_EXIT_STATE, 1);
num2bin((unsigned char) DEFAULT_EXIT_STATE, binary);
- printf("Writing %#04x (%d, B%s) ",
+ printf("Writing %#04x (%d, B%s) ",
DEFAULT_EXIT_STATE, DEFAULT_EXIT_STATE, binary);
printf("to the parallel port data bits.\n");
sp12End = clock();
sp12Elapsed = ((double) (sp12End - sp12Start)) / CLOCKS_PER_SEC;
printf("Sp12 was active for %#3.2f seconds.\n", sp12Elapsed);
- free(flashBuf);
- free(eepromBuf);
+ if (flashBuf)
+ free(flashBuf);
+ if (eepromBuf)
+ free(eepromBuf);
exit(exitState);
}
@@ -129,7 +131,7 @@ void exitSp12(int exitState) {
/* A or U was used, and say something about it. */
void reportLEFHXcFlag(void) {
-
+
if (lockFlag) {
printf("You have selected option -L to read or write lock fuses,\n");
printf("which has had no effect. Use this option only in combination\n ");
@@ -173,7 +175,7 @@ void reportLEFHXcFlag(void) {
/* and say something about it. */
void reportBflag(void) {
-
+
if (blankChkFlag) {
printf("You have selected option -B for blank check, which has had \n");
printf("no effect. Options -w, -p and -f together cause an automatic\n");
@@ -190,7 +192,7 @@ void reportBflag(void) {
int blank_check(void) {
int signal = 0;
-
+
printf("Performing blank check...\n");
signal = blankCheck(device.flashLimit, device.eepromLimit);
if (signal == 0)
@@ -215,7 +217,7 @@ void processCommand(void) {
int idx = 0;
/*
- * If it hasn't been done yet, then set the device parameters
+ * If it hasn't been done yet, then set the device parameters
* according to device code and option -i[NN]
*/
if (!device.initPerformed) {
@@ -241,10 +243,10 @@ void processCommand(void) {
/*
* It doesn't look like a 1200. If a uC is connected,
* the SPI shiftregister is not in synch. We'll now fail
- * if it is an out of synch 1200, but other uCs do
- * echo 0x53 on the third byte of PROGRAM_ENABLE.
+ * if it is an out of synch 1200, but other uCs do
+ * echo 0x53 on the third byte of PROGRAM_ENABLE.
* So we'll try synch pulses for a while.
- */
+ */
enableSPI(0);
deviceCode = setDevicePars(initFlag, identifier);
if (deviceCode == 1) {
@@ -261,14 +263,14 @@ void processCommand(void) {
printf(" device, which may be locked mode 3. \n");
printf(" Access to a supported, mode 3 locked \n");
printf(" device can be regained, but only by \n");
- printf(" erasing it first.\n");
+ printf(" erasing it first.\n");
printf(" Check SP12.doc for details.\n\n");
}
}
if (initFlag == 0) {
- printf("The device code bytes 0,1,2: %#x, %#x, %#x were read\n",
+ printf("The device code bytes 0,1,2: %#x, %#x, %#x were read\n",
device.sigByte_0, device.sigByte_1, device.sigByte_2);
- printf("from parallel port %#x and indicate the following:\n",
+ printf("from parallel port %#x and indicate the following:\n",
portAddress);
printf("You have connected an %s\n", device.name);
printf("The device was made by %s\n\n", device.madeBy);
@@ -278,7 +280,7 @@ void processCommand(void) {
exitSp12(1);
}
if (initFlag != 0 && device.flashLimit != 0) {
- printf("Device code check OVERRULED! Assuming an %s\n\n",
+ printf("Device code check OVERRULED! Assuming an %s\n\n",
device.name);
}
/*
@@ -342,7 +344,7 @@ void processCommand(void) {
prevClkSpeed = clkSpeed;
}
clkSpeed = 0;
- /*
+ /*
* if r --> p || e || F || L
* rp --> rpf --> read program area; write to file
* rpa --> read program address to stdout
@@ -381,7 +383,7 @@ void processCommand(void) {
if (addressAvailable) {
addressAvailable = 0;
flashData = readCodeWord(flashAddress);
- printf("The word %#06x was read from program address %#08x\n",
+ printf("The word %#06x was read from program address %#08x\n",
flashData, flashAddress);
} else {
printf("Reading program area.\n");
@@ -389,7 +391,7 @@ void processCommand(void) {
if (pathAvailable) {
pathAvailable = 0;
printf("Writing program area content to %s\n", flashPath);
- if (fileFlashBuf(flashBuf, device.flashLimit,
+ if (fileFlashBuf(flashBuf, device.flashLimit,
flashPath, IntelFlag, hexAsciiFlag) != 0) {
printf("%s %s\n", FILE_WRITE_ERROR, flashPath);
exitSp12(2);
@@ -409,7 +411,7 @@ void processCommand(void) {
if (checksumFlag) {
checksumFlag = 0;
readFlashArea(flashBuf, device.flashLimit);
- printf("Checksum program area: %04x\n",
+ printf("Checksum program area: %04x\n",
checksum(flashBuf, device.flashLimit));
}
}
@@ -428,7 +430,7 @@ void processCommand(void) {
if (pathAvailable) {
pathAvailable = 0;
printf("Writing eeprom area content to %s\n", eepromPath);
- if (fileEepromBuf(eepromBuf, device.eepromLimit,
+ if (fileEepromBuf(eepromBuf, device.eepromLimit,
eepromPath, IntelFlag, hexAsciiFlag) != 0) {
printf("%s %s\n", FILE_WRITE_ERROR, eepromPath);
exitSp12(2);
@@ -443,8 +445,8 @@ void processCommand(void) {
printf("Address: Data in hex, dec, oct, bin\n");
for (address = 0; address < device.eepromLimit; address++) {
num2bin((unsigned char) eepromBuf[address], binary);
- printf( " %#04lx: %#04x %3d %#4o %s\n",
- address, eepromBuf[address], eepromBuf[address],
+ printf( " %#04lx: %#04x %3d %#4o %s\n",
+ address, eepromBuf[address], eepromBuf[address],
eepromBuf[address], binary);
}
}
@@ -453,7 +455,7 @@ void processCommand(void) {
if (checksumFlag) {
checksumFlag = 0;
readEepromArea(eepromBuf, device.eepromLimit);
- printf("Checksum eeprom area: %04x\n",
+ printf("Checksum eeprom area: %04x\n",
checksum(eepromBuf, device.eepromLimit));
}
}
@@ -461,10 +463,10 @@ void processCommand(void) {
fusesFlag = 0;
rFlag = readFuses(READ_FUSES, fusesBits, R_FUSESLSB, R_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Read_fuses not defined in _sp12dev.\n",
+ fprintf(stderr, "For the %s: Read_fuses not defined in _sp12dev.\n",
device.name);
} else {
- printf("%s are the fuse bits read from an %s\n",
+ printf("%s are the fuse bits read from an %s\n",
fusesBits, device.name);
printf("%s\n", FUSES_MESSAGE);
}
@@ -473,10 +475,10 @@ void processCommand(void) {
highFFlag = 0;
rFlag = readFuses(READ_HIGH_FUSES, fusesBits, RH_FUSESLSB, RH_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Read_high_fuses not defined in _sp12dev.\n",
+ fprintf(stderr, "For the %s: Read_high_fuses not defined in _sp12dev.\n",
device.name);
} else {
- printf("%s are the high fuse bits read from an %s\n",
+ printf("%s are the high fuse bits read from an %s\n",
fusesBits, device.name);
printf("%s\n", H_FUSES_MESSAGE);
}
@@ -485,10 +487,10 @@ void processCommand(void) {
extdFFlag = 0;
rFlag = readFuses(READ_EXTD_FUSES, fusesBits, RX_FUSESLSB, RX_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Read_extd_fuses not defined in _sp12dev.\n",
+ fprintf(stderr, "For the %s: Read_extd_fuses not defined in _sp12dev.\n",
device.name);
} else {
- printf("%s are the extended fuse bits read from an %s\n",
+ printf("%s are the extended fuse bits read from an %s\n",
fusesBits, device.name);
printf("%s\n", X_FUSES_MESSAGE);
}
@@ -497,7 +499,7 @@ void processCommand(void) {
lockFlag = 0;
rFlag = readFuses(READ_LOCK, lockBits, R_LOCKLSB, R_LOCKLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Read_locks not defined in _sp12dev.\n",
+ fprintf(stderr, "For the %s: Read_locks not defined in _sp12dev.\n",
device.name);
} else {
printf("%s are the lock bits read from an %s\n", lockBits, device.name);
@@ -509,10 +511,10 @@ void processCommand(void) {
command = READ_CALIBRATION | (calibAddress << 8);
rFlag = readFuses(command, calibByte, CALIBLSB, CALIBLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Read_calibration not defined in _sp12dev.\n",
+ fprintf(stderr, "For the %s: Read_calibration not defined in _sp12dev.\n",
device.name);
} else {
- printf("0x%02lx is the calibration byte read from address 0x%02lx\n",
+ printf("0x%02lx is the calibration byte read from address 0x%02lx\n",
strtol(calibByte, NULL, 2), calibAddress);
printf("%s\n", CALIB_MESSAGE);
}
@@ -520,20 +522,20 @@ void processCommand(void) {
reportLEFHXcFlag();
reportBflag();
- }
+ }
/*
* If w --> p || e
* wp --> f || a
- * wpf --> chip erase;
- * write file to program area
- * wpa --> NO chip erase (warning);
+ * wpf --> chip erase;
+ * write file to program area
+ * wpa --> NO chip erase (warning);
* write address:data
* we --> f || a
* wef --> write file to eeprom area
* wpa --> write address:data
* wF --> write the fuse bits, if possible
* wL --> write the lock bits, if possible
- * check for C; complete write before reading p || e
+ * check for C; complete write before reading p || e
* back into array to compute the checksum
* check for E, R, S but just report them
*/
@@ -557,19 +559,19 @@ void processCommand(void) {
printf(" Chip erase is not automatic; unless you \n");
printf(" used a separate -E command, it may not be \n");
printf(" possible to correctly write new data.\n");
- printf("Writing %#06x into address %#08x in program area.\n",
+ printf("Writing %#06x into address %#08x in program area.\n",
flashData, flashAddress);
error = writeFlashVerified(flashAddress, flashData, optimizeFlag);
if (logWrites(commandStr, flashAddress, flashData, flashPath,
flashBuf, overlayFlag, &error) != 0)
printf("%s %s\n", FILE_WRITE_ERROR, "sp12log.txt");
if (error) {
- printf("Readback ERROR at program address %#06x\n",
+ printf("Readback ERROR at program address %#06x\n",
flashAddress);
exitSp12(3);
}
-
- } else if (pathAvailable) { /* Write file to flash ////////////*/
+
+ } else if (pathAvailable) { /* Write file to flash ////////////*/
pathAvailable = 0;
if (!overlayFlag) {
printf("Performing chip erase...\n");
@@ -582,13 +584,13 @@ void processCommand(void) {
}
/* Read the HEX file */
printf("Writing content of %s into program area.\n", flashPath);
- error = readFlashFile(flashPath, flashBuf, device.flashLimit);
+ error = readFlashFile(flashPath, flashBuf, device.flashLimit);
if (error) {
printf("%s %s\n", flashPath, FILE_ERROR);
exitSp12(2);
}
/* Now copy file to flash */
- error = writeFlashArea(flashBuf, device.flashLimit, optimizeFlag);
+ error = writeFlashArea(flashBuf, device.flashLimit, optimizeFlag);
if (logWrites(commandStr, flashAddress, flashData, flashPath,
flashBuf, overlayFlag, &error) != 0)
printf("%s %s\n", FILE_WRITE_ERROR, "sp12log.txt");
@@ -600,13 +602,13 @@ void processCommand(void) {
} else {
printf("%s written and verified.\n", flashPath);
printf("write retries: %d\n", writeRetries);
- }
+ }
} /* Up to here the file to flash functions///////////////////*/
if (checksumFlag) {
checksumFlag = 0;
readFlashArea(flashBuf, device.flashLimit);
- printf("Checksum program area: %04x\n",
+ printf("Checksum program area: %04x\n",
checksum(flashBuf, device.flashLimit));
}
}
@@ -614,14 +616,14 @@ void processCommand(void) {
eepromFlag = 0;
if (addressAvailable) {
addressAvailable = 0;
- printf("Writing %#x into address %#x in eeprom area.\n",
+ printf("Writing %#x into address %#x in eeprom area.\n",
eepromData, eepromAddress);
error=writeEepromVerified(eepromAddress, eepromData, optimizeFlag);
if (logWrites(commandStr, eepromAddress, eepromData, eepromPath,
eepromBuf, overlayFlag, &error) != 0)
printf("%s %s\n", FILE_WRITE_ERROR, "sp12log.txt");
if (error) {
- printf("Readback ERROR at eeprom address %#04x\n",
+ printf("Readback ERROR at eeprom address %#04x\n",
eepromAddress);
exitSp12(3);
}
@@ -633,7 +635,7 @@ void processCommand(void) {
printf("%s %s\n", eepromPath, FILE_ERROR);
exitSp12(2);
}
- error = writeEepromArea(eepromBuf, device.eepromLimit,
+ error = writeEepromArea(eepromBuf, device.eepromLimit,
optimizeFlag, overlayFlag);
if (logWrites(commandStr, eepromAddress, eepromData, eepromPath,
eepromBuf, overlayFlag, &error) != 0)
@@ -644,14 +646,14 @@ void processCommand(void) {
} else {
printf("%s written and verified.\n", eepromPath);
printf("write retries: %d, byteWrite: %ld percent of default\n",
- writeRetries,
+ writeRetries,
(timeConst.byteWrite * 100) / timeConst.byteWriteDefault);
- }
+ }
}
if (checksumFlag) {
checksumFlag = 0;
readEepromArea(eepromBuf, device.eepromLimit);
- printf("Checksum eeprom area: %04x\n",
+ printf("Checksum eeprom area: %04x\n",
checksum(eepromBuf, device.eepromLimit));
}
reportBflag();
@@ -662,13 +664,14 @@ void processCommand(void) {
rFlag = writeFuses(WRITE_LOCK_HM, WRITE_LOCK_LM, lockBits, \
W_LOCKLSB, W_LOCKLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Write_lock not defined in _sp12dev.\n", device.name);
+ fprintf(stderr, "For the %s: Write_lock not defined in _sp12dev.\n",
+ device.name);
} else if (rFlag == 2) {
- fprintf(stderr, "For the %s: Wrong number of lock bits, expect %d.\n", device.name, W_LOCKLEN);
+ fprintf(stderr, "For the %s: Wrong number of lock bits.\n", device.name);
} else {
for (idx = 0; idx < R_LOCKLEN - W_LOCKLEN; idx++)
printf(" ");
- printf("%s are the lock bits written into an %s\n%s\n",
+ printf("%s are the lock bits written into an %s\n%s\n",
lockBits, device.name, LOCK_MESSAGE);
}
}
@@ -677,13 +680,14 @@ void processCommand(void) {
rFlag = writeFuses(WRITE_FUSES_HM, WRITE_FUSES_LM, fusesBits, \
W_FUSESLSB, W_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Write_fuses not defined in _sp12dev.\n", device.name);
+ fprintf(stderr, "For the %s: Write_fuses not defined in _sp12dev.\n",
+ device.name);
} else if (rFlag == 2) {
- fprintf(stderr, "For the %s; Wrong number of fuse bits, expect %d.\n", device.name, W_FUSESLEN);
+ fprintf(stderr, "For the %s; Wrong number of fuse bits.\n", device.name);
} else {
for (idx = 0; idx < (R_FUSESLEN - W_FUSESLEN) - W_FUSESLSB; idx++)
printf(" ");
- printf("%s are the fuse bits written into an %s\n%s\n",
+ printf("%s are the fuse bits written into an %s\n%s\n",
fusesBits, device.name, FUSES_MESSAGE);
}
}
@@ -692,13 +696,15 @@ void processCommand(void) {
rFlag = writeFuses(WRITE_HIGH_FUSES_HM, WRITE_HIGH_FUSES_LM, fusesBits, \
WH_FUSESLSB, WH_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Write_high_fuses not defined in _sp12dev.\n", device.name);
+ fprintf(stderr, "For the %s: Write_high_fuses not defined in _sp12dev.\n",
+ device.name);
} else if (rFlag == 2) {
- fprintf(stderr, "For the %s; Wrong number of high fuse bits, expect %d.\n", device.name, WH_FUSESLEN);
+ fprintf(stderr, "For the %s; Wrong number of high fuse bits.\n",
+ device.name);
} else {
for (idx = 0; idx < (RH_FUSESLEN - WH_FUSESLEN) - WH_FUSESLSB; idx++)
printf(" ");
- printf("%s are the high fuse bits written into an %s\n%s\n",
+ printf("%s are the high fuse bits written into an %s\n%s\n",
fusesBits, device.name, H_FUSES_MESSAGE);
}
}
@@ -707,13 +713,15 @@ void processCommand(void) {
rFlag = writeFuses(WRITE_EXTD_FUSES_HM, WRITE_EXTD_FUSES_LM, fusesBits, \
WX_FUSESLSB, WX_FUSESLEN);
if (rFlag == 9) {
- fprintf(stderr, "For the %s: Write_extd_fuses not defined in _sp12dev.\n", device.name);
+ fprintf(stderr, "For the %s: Write_extd_fuses not defined in _sp12dev.\n",
+ device.name);
} else if (rFlag == 2) {
- fprintf(stderr, "For the %s; Wrong number of extended fuse bits, expect %d.\n", device.name, WX_FUSESLEN);
+ fprintf(stderr, "For the %s; Wrong number of high fuse bits.\n",
+ device.name);
} else {
for (idx = 0; idx < (RX_FUSESLEN - WX_FUSESLEN) - WX_FUSESLSB; idx++)
printf(" ");
- printf("%s are the extended fuse bits written into an %s\n%s\n",
+ printf("%s are the extended fuse bits written into an %s\n%s\n",
fusesBits, device.name, X_FUSES_MESSAGE);
}
}
@@ -722,11 +730,11 @@ void processCommand(void) {
}
/*
* if C --> (p || e) || ((p || e) && f)
- * Cp(f) --> read program area (file) into
- * device.flashLimit word array;
+ * Cp(f) --> read program area (file) into
+ * device.flashLimit word array;
* calculate checksum for array
- * Ce(f) --> read eeprom area (file) into
- * device.eepromLimit byte array;
+ * Ce(f) --> read eeprom area (file) into
+ * device.eepromLimit byte array;
* calculate checksum for array
* check for L, E, B, F, R, S but just report them
*/
@@ -736,17 +744,17 @@ void processCommand(void) {
eepromFlag = 0;
if (pathAvailable) {
pathAvailable = 0;
- if (readEepromFile(checksumPath, eepromBuf,
+ if (readEepromFile(checksumPath, eepromBuf,
device.eepromLimit) != 0) {
printf("%s %s\n", checksumPath, FILE_ERROR);
exitSp12(2);
} else {
- printf("Checksum eeprom file %s: %04x\n",
+ printf("Checksum eeprom file %s: %04x\n",
checksumPath, checksum(eepromBuf, device.eepromLimit));
}
} else {
readEepromArea(eepromBuf, device.eepromLimit);
- printf("Checksum eeprom area: %04x\n",
+ printf("Checksum eeprom area: %04x\n",
checksum(eepromBuf, device.eepromLimit));
}
} else if (flashFlag) {
@@ -757,12 +765,12 @@ void processCommand(void) {
printf("%s %s\n", checksumPath, FILE_ERROR);
exitSp12(2);
} else {
- printf("Checksum program file %s: %04x\n",
+ printf("Checksum program file %s: %04x\n",
checksumPath, checksum(flashBuf, device.flashLimit));
}
} else {
readFlashArea(flashBuf, device.flashLimit);
- printf("Checksum program area: %04x\n",
+ printf("Checksum program area: %04x\n",
checksum(flashBuf, device.flashLimit));
}
} else {
@@ -801,9 +809,6 @@ int main(int argc, char *argv[])
char *dataPtr; /* for separating address:data */
int exitFlag = 0;
char binary[9] = "76543210"; /* Stores conversion num to binary */
-#if defined(__OpenBSD__)
- u_long iomap[32];
-#endif
device.initPerformed = 0;
flashPath[0] = '\0';
@@ -822,23 +827,8 @@ int main(int argc, char *argv[])
if (ioperm(0x378,3,1)) {perror("ioperm error at 0x378");exit(1);}
if (ioperm(0x3BC,3,1)) {perror("ioperm error at 0x3BC");exit(1);}
#elif defined(__OpenBSD__)
-#define enable(a, i) do { \
- ((a)[((i) + 0) >> 5] &= ~(1 << (((i) + 0) & 0x1F))); \
- ((a)[((i) + 1) >> 5] &= ~(1 << (((i) + 1) & 0x1F))); \
- ((a)[((i) + 2) >> 5] &= ~(1 << (((i) + 2) & 0x1F))); \
-} while (0)
-
- if (i386_get_ioperm(iomap) != 0) {
- perror("i386_get_ioperm error");
- exit(1);
- }
-
- enable(iomap, 0x278);
- enable(iomap, 0x378);
- enable(iomap, 0x3BC);
-
- if (i386_set_ioperm(iomap) != 0) {
- perror("i386_set_ioperm error");
+ if (amd64_iopl(1) == -1) {
+ perror("amd64_iopl error");
exit(1);
}
#endif
@@ -862,7 +852,7 @@ int main(int argc, char *argv[])
printf("SP12 version %s performing init...\n", VERSION);
initSp12(argv[0]);
}
- /*
+ /*
* allocate our memory buffers
*/
flashBuf = malloc(FLASHBUF_UPPERLIMIT * sizeof (unsigned int));
@@ -970,7 +960,7 @@ int main(int argc, char *argv[])
exitFlag = 0;
portControl(portFlag, exitFlag);
num2bin((unsigned char) portFlag, binary);
- printf("Writing %#04x (%d, B%s) ",
+ printf("Writing %#04x (%d, B%s) ",
portFlag, portFlag, binary);
printf("to the parallel port data bits.\n");
if ((idx + 1) < argc)
@@ -1119,18 +1109,18 @@ int main(int argc, char *argv[])
}
/*
* Exiting with the byte `portFlag' on the parallel port data bits.
- * When the -Tnn option is not (also) used as the final option on
+ * When the -Tnn option is not (also) used as the final option on
* the command line, this defaults to 0x00.
*/
if (SCK == S_SCK && testFlag) {
switch(testFlag) {
- case 1:
+ case 1:
portFlag = RESET;
break;
- case 2:
+ case 2:
portFlag = RESET | PORTPOWER;
break;
- default:
+ default:
break;
}
} else if (testFlag) {
@@ -1139,7 +1129,7 @@ int main(int argc, char *argv[])
if (!portFlag) {
portFlag = DEFAULT_EXIT_STATE;
num2bin((unsigned char) portFlag, binary);
- printf("Writing %#04x (%d, B%s) ",
+ printf("Writing %#04x (%d, B%s) ",
portFlag, portFlag, binary);
printf("to the parallel port data bits.\n");
}