fix to ensure updatekernel does not work with Amd blackfin flash and a kernel older than the current one

This commit is contained in:
maliakal_d 2021-11-23 15:23:16 +01:00
parent d9686e0b6a
commit a101e18d60
4 changed files with 52 additions and 4 deletions

View File

@ -14,6 +14,7 @@ int FPGATouchFlash(char *mess);
int resetFPGA(char *mess);
int emptyTempFolder(char *mess);
int allowKernelUpdate(char *mess);
/**
* deletes old file
* verify memory available to copy

View File

@ -403,7 +403,8 @@ int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
if (strcmp(clientChecksum, checksum)) {
sprintf(mess,
"Could not %s. Checksum of %s does not match. Client "
"checksum:%s, copied checksum:%s\n",
"checksum:%s, copied checksum:%. Please try again before "
"rebooting.\n",
functionType, msg, clientChecksum, checksum);
LOG(logERROR, (mess));
return FAIL;

View File

@ -35,6 +35,9 @@
#define CMD_GET_FPGA_FLASH_DRIVE "awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd"
#define CMD_GET_KERNEL_FLASH_DRIVE "awk \'$4== \"\\\"linux\" {print $1}\' /proc/mtd"
#define CMD_GET_AMD_FLASH "dmesg | grep Amd"
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
// clang-format on
@ -245,6 +248,41 @@ int emptyTempFolder(char *mess) {
#endif
}
int allowKernelUpdate(char *mess) {
LOG(logINFO, ("\tVerifying kernel update allowed...\n"));
#ifdef VIRTUAL
return OK;
#endif
char retvals[MAX_STR_LENGTH] = {0};
if (executeCommand(CMD_GET_AMD_FLASH, retvals, logDEBUG1) == FAIL) {
snprintf(
mess, MAX_STR_LENGTH,
"Could not update %s. (Could not figure out if Amd flash: %s)\n",
messageType, retvals);
LOG(logERROR, (mess));
return FAIL;
}
// amd flash found
if (strlen(retvals) > 1) {
LOG(logINFO, ("\tAmd Flash found\n"));
// only current kernel works with amd flash
if (validateKernelVersion(KERNEL_DATE_VRSN_3GPIO) == FAIL) {
getKernelVersion(retvals);
snprintf(mess, MAX_STR_LENGTH,
"Could not update %s. Kernel version %s is too old to "
"update the Amd flash\n",
messageType, retvals);
LOG(logERROR, (mess));
return FAIL;
}
} else {
LOG(logINFO, ("\tNot Amd Flash\n"));
}
LOG(logINFO, ("\tKernel and flash ok for updating kernel\n"));
return OK;
}
int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
uint64_t fsize) {

View File

@ -9257,7 +9257,8 @@ int get_kernel_version(int file_des) {
if (snprintf(mess, MAX_STR_LENGTH, "Could not get kernel version. %s\n",
retvals) >= MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not get kernel version. Reason too long to copy\n");
strcpy(mess,
"Could not get kernel version. Reason too long to copy\n");
}
LOG(logERROR, (mess));
} else {
@ -9372,6 +9373,13 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
functionType);
LOG(logERROR, (mess));
#else
// check kernel update is allowed (Non Amd OR AMD + current kernel)
ret = allowKernelUpdate(mess);
if (ret == FAIL) {
Server_SendResult(file_des, INT32, NULL, 0);
return;
}
// open file and allocate memory for part program
FILE *fd = NULL;
ret = preparetoCopyProgram(mess, functionType, &fd, filesize);