mirror of
https://github.com/ole00/afterburner.git
synced 2024-11-22 21:32:09 +00:00
Added support for securing/protecting the GAL
credits: GALmate software
This commit is contained in:
parent
ba15a74dee
commit
317b3520d8
@ -83,6 +83,7 @@
|
||||
#define COMMAND_SET_GAL_TYPE 'g'
|
||||
#define COMMAND_ENABLE_CHECK_TYPE 'f'
|
||||
#define COMMAND_DISABLE_CHECK_TYPE 'F'
|
||||
#define COMMAND_ENABLE_SECURITY 's'
|
||||
|
||||
#define READGAL 0
|
||||
#define VERIFYGAL 1
|
||||
@ -866,14 +867,14 @@ void printPes(char type) {
|
||||
case GAL16V8: Serial.print(F("GAL16V8 ")); break;
|
||||
case GAL20V8: Serial.print(F("GAL20V8 ")); break;
|
||||
case GAL22V10: Serial.print(F("GAL20V10 ")); break;
|
||||
case ATF16V8B: Serial.print(F("ATF16V8B ")); break;
|
||||
case ATF16V8B: Serial.print(0 == (flagBits & FLAG_BIT_ATF16V8C) ? F("ATF16V8B "): F("ATF16V8C ")); break;
|
||||
case ATF22V10B: Serial.print(F("ATF22V10B ")); break;
|
||||
case ATF22V10C: Serial.print(F("ATF22V10C ")); break;
|
||||
}
|
||||
|
||||
//programming info
|
||||
if (UNKNOWN != type) {
|
||||
Serial.print(F(" VPP=")); //without the front space chars the print causes issues (why?)
|
||||
Serial.print(F(" VPP="));
|
||||
Serial.print(vpp >> 2, DEC);
|
||||
Serial.print(F("."));
|
||||
Serial.print((vpp & 3) * 25, DEC);
|
||||
@ -1279,6 +1280,17 @@ static void eraseGAL(void)
|
||||
turnOff();
|
||||
}
|
||||
|
||||
// sets security bit - disables fuse reading
|
||||
static void secureGAL(void)
|
||||
{
|
||||
turnOn(WRITEGAL);
|
||||
|
||||
setPV(1);
|
||||
strobeRow(61, BIT_ONE); // strobe row and send one bit with value 1
|
||||
|
||||
setPV(0);
|
||||
turnOff();
|
||||
}
|
||||
|
||||
static char checkGalTypeViaPes(void)
|
||||
{
|
||||
@ -1669,6 +1681,13 @@ void loop() {
|
||||
}
|
||||
} break;
|
||||
|
||||
// sets the security bit
|
||||
case COMMAND_ENABLE_SECURITY: {
|
||||
if (doTypeCheck()) {
|
||||
secureGAL();
|
||||
}
|
||||
} break;
|
||||
|
||||
// toggles terminal echo
|
||||
case COMMAND_ECHO : {
|
||||
echoEnabled = 1 - echoEnabled;
|
||||
|
@ -117,6 +117,7 @@ char opErase = 0;
|
||||
char opInfo = 0;
|
||||
char opVerify = 0;
|
||||
char opTestVPP = 0;
|
||||
char opSecureGal = 0;
|
||||
|
||||
|
||||
static int waitForSerialPrompt(char* buf, int bufSize, int maxDelay);
|
||||
@ -141,6 +142,7 @@ static void printHelp() {
|
||||
printf(" -d <serial_device> : name of the serial device. Default is: %s\n", DEFAULT_SERIAL_DEVICE_NAME);
|
||||
printf(" serial params are: 38400, 8N1\n");
|
||||
printf(" -nc : do not check device GAL type before operation: force the GAL type set on command line\n");
|
||||
printf(" -sec: enable security - protect the chip. Use with 'w' or 'v' commands.\n");
|
||||
printf("examples:\n");
|
||||
printf(" afterburner i -t ATF16V8B : reads and prints the device info\n");
|
||||
printf(" afterburner r -t ATF16V8B : reads the fuse map from the GAL chip and displays it\n");
|
||||
@ -151,7 +153,7 @@ static void printHelp() {
|
||||
printf(" of the chip. If the programing voltage is unknown use 10V.\n");
|
||||
printf(" - known VPP voltages as tested on Afterburner with Arduino UNO: \n");
|
||||
printf(" Lattice GAL16V8D, GAL22V10D: 12V \n");
|
||||
printf(" Atmel ATF16V8D, ATF22V10C: 10V \n");
|
||||
printf(" Atmel ATF16V8B, AFT16V8C, ATF22V10C: 10V \n");
|
||||
}
|
||||
|
||||
static char checkArgs(int argc, char** argv) {
|
||||
@ -176,7 +178,10 @@ static char checkArgs(int argc, char** argv) {
|
||||
deviceName = argv[i];
|
||||
} else if (strcmp("-nc", param) == 0) {
|
||||
noGalCheck = 1;
|
||||
} else if (param[0] != '-') {
|
||||
} else if (strcmp("-sec", param) == 0) {
|
||||
opSecureGal = 1;
|
||||
}
|
||||
else if (param[0] != '-') {
|
||||
modes = param;
|
||||
}
|
||||
}
|
||||
@ -844,6 +849,20 @@ static char operationSetGalType(Galtype type) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static char operationSecureGal() {
|
||||
int readSize;
|
||||
char result;
|
||||
|
||||
if (openSerial() != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (verbose) {
|
||||
printf("sending 's' command...\n");
|
||||
}
|
||||
result = sendGenericCommand("s\r", "secure GAL failed ?", 4000, 0);
|
||||
closeSerial();
|
||||
return result;
|
||||
}
|
||||
|
||||
static char operationEraseGal(void) {
|
||||
char buf[MAX_LINE];
|
||||
@ -947,6 +966,11 @@ int main(int argc, char** argv) {
|
||||
} else if (opTestVPP) {
|
||||
result = operationTestVpp();
|
||||
}
|
||||
if (0 == result && (opWrite || opVerify)) {
|
||||
if (opSecureGal) {
|
||||
operationSecureGal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
|
Loading…
Reference in New Issue
Block a user