├── Makefile ├── README ├── communication_api.c ├── communication_api.h ├── conv.pl ├── cybtldr_api.c ├── cybtldr_api.h ├── cybtldr_command.c ├── cybtldr_command.h ├── cybtldr_parse.c ├── cybtldr_parse.h ├── cybtldr_utils.h ├── main.c ├── run.gdb └── test ├── Bootloadable Blinking LED.cyacd ├── CY8CKIT-049-41XX_GPIO_Example.cyacd ├── CY8CKIT-049-41XX_PWM_Example.cyacd └── CY8CKIT-049-41XX_UART_Example.cyacd /Makefile: -------------------------------------------------------------------------------- 1 | SRC=main.c communication_api.c cybtldr_api.c cybtldr_command.c cybtldr_parse.c 2 | OBJ=$(subst .c,.o,$(SRC)) 3 | all: cybootload_linux 4 | 5 | %.o: %.c 6 | gcc -Wall -g -c $< -o $@ 7 | 8 | cybootload_linux: $(OBJ) 9 | gcc -Wall -g -o $@ $+ 10 | 11 | test1: 12 | ./cybootload_linux "test/Bootloadable Blinking LED.cyacd" 13 | test2: 14 | ./cybootload_linux test/CY8CKIT-049-41XX_GPIO_Example.cyacd 15 | test3: 16 | ./cybootload_linux test/CY8CKIT-049-41XX_PWM_Example.cyacd 17 | 18 | test4: 19 | ./cybootload_linux test/CY8CKIT-049-41XX_UART_Example.cyacd 20 | 21 | clean: 22 | -rm *.o cybootload_linux 23 | 24 | StringImage.h: "Bootloadable Blinking LED.cyacd" 25 | perl conv.pl "$<" 26 | 27 | 28 | gdb: cybootload_linux 29 | -rm -f gdb.log 30 | gdb -batch -x run.gdb 31 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gv1/cybootload_linux/5b59bb0702483d8bbf72c84e6136931e076ef9aa/README -------------------------------------------------------------------------------- /communication_api.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * File Name: communication_api.c 3 | * Version 1.0 4 | * 5 | * Description: 6 | * This file is created by the author . This contains definitions of APIs 7 | * used in structure 'CyBtldr_CommunicationsData' defined in cybtldr_api.h , 8 | * using SPI commuincations component 9 | ********************************************************************************/ 10 | 11 | #include "communication_api.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | static struct termios tio; 23 | static int tty_fd; 24 | extern int errno; 25 | 26 | /******************************************************************************* 27 | * Function Name: OpenConnection 28 | ******************************************************************************** 29 | * 30 | * Summary: 31 | * Initializes the communications component : In this case UART 32 | * 33 | * Parameters: 34 | * void 35 | * 36 | * Return: 37 | * Returns a flag to indicate whether the operation was successful or not 38 | * 39 | * 40 | *******************************************************************************/ 41 | extern char * serial_port; 42 | extern int serial_speed; 43 | int OpenConnection(void) 44 | { 45 | /* 46 | UART_Start(); 47 | */ 48 | int speed; 49 | if (serial_port == NULL) 50 | { 51 | if ((serial_port = strdup(MODEMDEV)) == NULL) { 52 | printf("[ERROR] malloc failed\n"); 53 | return(CYRET_ERR_FILE); 54 | } 55 | } 56 | // tty_fd=open(argv[1], O_RDWR | O_NONBLOCK); 57 | tty_fd=open(serial_port, O_RDWR | O_NOCTTY | O_SYNC); 58 | if ( tty_fd == -1) { 59 | printf("[ERROR] opening %s : %s\n",serial_port,strerror(errno)); 60 | exit(1); 61 | // return (CYRET_ERR_FILE); 62 | } 63 | memset(&tio,0,sizeof(tio)); 64 | tio.c_iflag=0; 65 | tio.c_oflag=0; 66 | tio.c_cflag=CS8|CREAD|CLOCAL; // 8n1, see termios.h for more information 67 | tio.c_lflag=0; 68 | tio.c_cc[VMIN]=1; 69 | tio.c_cc[VTIME]=5; 70 | 71 | 72 | switch(serial_speed) { 73 | case 9600: 74 | speed = B9600; 75 | break; 76 | case 19200: 77 | speed = B19200; 78 | break; 79 | case 38400: 80 | speed = B38400; 81 | break; 82 | case 57600: 83 | speed = B57600; 84 | break; 85 | case 115200: 86 | speed = B115200; 87 | break; 88 | default: 89 | speed = COMSPEED; 90 | printf("[INFO] unsupported speed %d, defaulting to %d\n",serial_speed,speed); 91 | break; 92 | } 93 | if ( cfsetospeed(&tio,speed) == -1) { // 115200 baud 94 | printf("[ERROR] %s\n",strerror(errno)); 95 | return (CYRET_ERR_FILE); 96 | } 97 | if (cfsetispeed(&tio,speed) == -1) { // 115200 baud 98 | printf("[ERROR] %s\n",strerror(errno)); 99 | return (CYRET_ERR_FILE); 100 | } 101 | if (tcsetattr(tty_fd,TCSANOW,&tio) == -1) { 102 | printf("[ERROR] %s\n",strerror(errno)); 103 | return (CYRET_ERR_FILE); 104 | } 105 | return(CYRET_SUCCESS); 106 | } 107 | 108 | 109 | /******************************************************************************* 110 | * Function Name: CloseConnection 111 | ******************************************************************************** 112 | * 113 | * Summary: 114 | * Clears the status and stops the communications component (UART). 115 | * 116 | * Parameters: 117 | * void 118 | * 119 | * Return: 120 | * Returns a flag to indicate whether the operation was successful or not 121 | * 122 | * 123 | *******************************************************************************/ 124 | int CloseConnection(void) 125 | { 126 | /* 127 | UART_Stop(); 128 | */ 129 | printf("[INFO] Closing UART connection\n"); 130 | close(tty_fd); 131 | return(CYRET_SUCCESS); 132 | } 133 | 134 | /******************************************************************************* 135 | * Function Name: WriteData 136 | ******************************************************************************** 137 | * 138 | * Summary: 139 | * Writes the specified number of bytes using the communications component (UART) 140 | * 141 | * Parameters: 142 | * wrData - Pointer to write data buffer 143 | * byteCnt - No. of bytes to be written 144 | * 145 | * Return: 146 | * Returns a flag to indicate whether the operation was successful or not 147 | * 148 | * 149 | *******************************************************************************/ 150 | int WriteData(uint8* wrData, int byteCnt) 151 | { 152 | if (write(tty_fd,wrData,byteCnt) == -1){ 153 | printf("[ERROR]: writing data to serial port: %s\n",strerror(errno)); 154 | return(CYRET_ERR_COMM_MASK); 155 | } 156 | return(CYRET_SUCCESS); 157 | } 158 | 159 | 160 | /******************************************************************************* 161 | * Function Name: ReadData 162 | ******************************************************************************** 163 | * 164 | * Summary: 165 | * Reads the specified number of bytes usign the communications component (UART) 166 | * 167 | * Parameters: 168 | * rdData - Pointer to read data buffer 169 | * byteCnt - No. of bytes to be read 170 | * 171 | * Return: 172 | * Returns a flag to indicate whether the operation was successful or not 173 | * 174 | * 175 | *******************************************************************************/ 176 | int ReadData(uint8* rdData, int byteCnt) 177 | { 178 | // read(tty_fd,rdData,byteCnt); 179 | /* Read the data bytes */ 180 | uint16 timeOut =1; 181 | uint8 dataIndexCntr = 0; 182 | while(read(tty_fd,&rdData[dataIndexCntr],1) == -1 ) { 183 | timeOut++; 184 | if(timeOut == 0) 185 | { 186 | printf("[ERROR] Read from target fail\n"); 187 | return(CYRET_ERR_COMM_MASK); 188 | } 189 | } 190 | dataIndexCntr++; 191 | byteCnt--; 192 | while (byteCnt>0) 193 | { 194 | if ( read(tty_fd,&rdData[dataIndexCntr++],1) == -1 ) { 195 | printf("[ERROR] Reading data from serial port: %s\n",strerror(errno)); 196 | return(CYRET_ERR_COMM_MASK); 197 | } 198 | if(usleep(1)==-1){ 199 | printf("[ERROR] usleep : %s\n",strerror(errno)); 200 | } 201 | byteCnt--; 202 | } 203 | return(CYRET_SUCCESS); 204 | } 205 | 206 | /* [] END OF FILE */ 207 | 208 | -------------------------------------------------------------------------------- /communication_api.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * File Name: communication_api.h 3 | * Version 1.0 4 | * 5 | * Description: 6 | * This is the header file for the communication module created by the author. 7 | * It contains function prototypes and constants for the users' convenience. 8 | ********************************************************************************/ 9 | 10 | #include 11 | #include "cybtldr_utils.h" 12 | 13 | typedef unsigned char uint8; 14 | typedef unsigned short uint16; 15 | 16 | #define MODEMDEV "/dev/ttyACM0" 17 | #define COMSPEED B115200 18 | 19 | /* Function declarations */ 20 | int OpenConnection(void); 21 | int CloseConnection(void); 22 | int ReadData(uint8* rdData, int byteCnt); 23 | int WriteData(uint8* wrData, int byteCnt); 24 | 25 | //[] END OF FILE 26 | 27 | -------------------------------------------------------------------------------- /conv.pl: -------------------------------------------------------------------------------- 1 | print "const char *stringImage[] = {\n"; 2 | while(<>) { 3 | chop; 4 | print "\"" . $_ . "\",\n" ; 5 | } 6 | print "};\n"; 7 | print "#define LINE_CNT " . $. . "\n"; 8 | 9 | -------------------------------------------------------------------------------- /cybtldr_api.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved. 3 | * You may use this file only in accordance with the license, terms, conditions, 4 | * disclaimers, and limitations in the end user license agreement accompanying 5 | * the software package with which this file was provided. 6 | ********************************************************************************/ 7 | 8 | #include "cybtldr_command.h" 9 | #include "cybtldr_api.h" 10 | 11 | /* The highest number of memory arrays for any device. This includes flash and EEPROM arrays */ 12 | #define MAX_DEV_ARRAYS 0x80 13 | /* The default value if a flash array has not yet received data */ 14 | #define NO_FLASH_ARRAY_DATA 0 15 | /* The maximum number of flash arrays */ 16 | #define MAX_FLASH_ARRAYS 0x40 17 | /* The minimum array id for EEPROM arrays. */ 18 | #define MIN_EEPROM_ARRAY 0x40 19 | 20 | unsigned long g_validRows[MAX_FLASH_ARRAYS]; 21 | static CyBtldr_CommunicationsData* g_comm; 22 | 23 | int CyBtldr_TransferData(unsigned char* inBuf, int inSize, unsigned char* outBuf, int outSize) 24 | { 25 | int err = g_comm->WriteData(inBuf, inSize); 26 | 27 | if (CYRET_SUCCESS == err) 28 | err = g_comm->ReadData(outBuf, outSize); 29 | 30 | if (CYRET_SUCCESS != err) 31 | err |= CYRET_ERR_COMM_MASK; 32 | 33 | return err; 34 | } 35 | 36 | int CyBtldr_ValidateRow(unsigned char arrayId, unsigned short rowNum) 37 | { 38 | unsigned long inSize; 39 | unsigned long outSize; 40 | unsigned short minRow = 0; 41 | unsigned short maxRow = 0; 42 | unsigned char inBuf[MAX_COMMAND_SIZE]; 43 | unsigned char outBuf[MAX_COMMAND_SIZE]; 44 | unsigned char status = CYRET_SUCCESS; 45 | int err = CYRET_SUCCESS; 46 | 47 | if (arrayId < MAX_FLASH_ARRAYS) 48 | { 49 | if (NO_FLASH_ARRAY_DATA == g_validRows[arrayId]) 50 | { 51 | err = CyBtldr_CreateGetFlashSizeCmd(arrayId, inBuf, &inSize, &outSize); 52 | if (CYRET_SUCCESS == err) 53 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 54 | if (CYRET_SUCCESS == err) 55 | err = CyBtldr_ParseGetFlashSizeCmdResult(outBuf, outSize, &minRow, &maxRow, &status); 56 | if (CYRET_SUCCESS != status) 57 | err = status | CYRET_ERR_BTLDR_MASK; 58 | 59 | if (CYRET_SUCCESS == err) 60 | { 61 | if (CYRET_SUCCESS == status) 62 | g_validRows[arrayId] = (minRow << 16) + maxRow; 63 | else 64 | err = status | CYRET_ERR_BTLDR_MASK; 65 | } 66 | } 67 | if (CYRET_SUCCESS == err) 68 | { 69 | minRow = (unsigned short)(g_validRows[arrayId] >> 16); 70 | maxRow = (unsigned short)g_validRows[arrayId]; 71 | if (rowNum < minRow || rowNum > maxRow) 72 | err = CYRET_ERR_ROW; 73 | } 74 | } 75 | else 76 | err = CYRET_ERR_ARRAY; 77 | 78 | return err; 79 | } 80 | 81 | 82 | int CyBtldr_StartBootloadOperation(CyBtldr_CommunicationsData* comm, unsigned long expSiId, unsigned char expSiRev, unsigned long* blVer) 83 | { 84 | const unsigned long SUPPORTED_BOOTLOADER = 0x010000; 85 | const unsigned long BOOTLOADER_VERSION_MASK = 0xFF0000; 86 | unsigned long i; 87 | unsigned long inSize = 0; 88 | unsigned long outSize = 0; 89 | unsigned long siliconId = 0; 90 | unsigned char inBuf[MAX_COMMAND_SIZE]; 91 | unsigned char outBuf[MAX_COMMAND_SIZE]; 92 | unsigned char siliconRev = 0; 93 | unsigned char status = CYRET_SUCCESS; 94 | int err; 95 | 96 | g_comm = comm; 97 | for (i = 0; i < MAX_FLASH_ARRAYS; i++) 98 | g_validRows[i] = NO_FLASH_ARRAY_DATA; 99 | 100 | err = g_comm->OpenConnection(); 101 | if (CYRET_SUCCESS != err) 102 | err |= CYRET_ERR_COMM_MASK; 103 | 104 | if (CYRET_SUCCESS == err) 105 | err = CyBtldr_CreateEnterBootLoaderCmd(inBuf, &inSize, &outSize); 106 | if (CYRET_SUCCESS == err) 107 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 108 | if (CYRET_SUCCESS == err) 109 | err = CyBtldr_ParseEnterBootLoaderCmdResult(outBuf, outSize, &siliconId, &siliconRev, blVer, &status); 110 | 111 | 112 | if (CYRET_SUCCESS == err) 113 | { 114 | if (CYRET_SUCCESS != status) 115 | err = status | CYRET_ERR_BTLDR_MASK; 116 | if (expSiId != siliconId || expSiRev != siliconRev) 117 | err = CYRET_ERR_DEVICE; 118 | else if ((*blVer & BOOTLOADER_VERSION_MASK) != SUPPORTED_BOOTLOADER) 119 | err = CYRET_ERR_VERSION; 120 | } 121 | 122 | return err; 123 | } 124 | 125 | int CyBtldr_GetApplicationStatus(unsigned char appID, unsigned char* isValid, unsigned char* isActive) 126 | { 127 | unsigned long inSize = 0; 128 | unsigned long outSize = 0; 129 | unsigned char inBuf[MAX_COMMAND_SIZE]; 130 | unsigned char outBuf[MAX_COMMAND_SIZE]; 131 | unsigned char status = CYRET_SUCCESS; 132 | int err; 133 | 134 | err = CyBtldr_CreateGetAppStatusCmd(appID, inBuf, &inSize, &outSize); 135 | if (CYRET_SUCCESS == err) 136 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 137 | if (CYRET_SUCCESS == err) 138 | err = CyBtldr_ParseGetAppStatusCmdResult(outBuf, outSize, isValid, isActive, &status); 139 | 140 | if (CYRET_SUCCESS == err) 141 | { 142 | if (CYRET_SUCCESS != status) 143 | err = status | CYRET_ERR_BTLDR_MASK; 144 | } 145 | 146 | return err; 147 | } 148 | 149 | int CyBtldr_SetApplicationStatus(unsigned char appID) 150 | { 151 | unsigned long inSize = 0; 152 | unsigned long outSize = 0; 153 | unsigned char inBuf[MAX_COMMAND_SIZE]; 154 | unsigned char outBuf[MAX_COMMAND_SIZE]; 155 | unsigned char status = CYRET_SUCCESS; 156 | int err; 157 | 158 | err = CyBtldr_CreateSetActiveAppCmd(appID, inBuf, &inSize, &outSize); 159 | if (CYRET_SUCCESS == err) 160 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 161 | if (CYRET_SUCCESS == err) 162 | err = CyBtldr_ParseSetActiveAppCmdResult(outBuf, outSize, &status); 163 | 164 | if (CYRET_SUCCESS == err) 165 | { 166 | if (CYRET_SUCCESS != status) 167 | err = status | CYRET_ERR_BTLDR_MASK; 168 | } 169 | 170 | return err; 171 | } 172 | 173 | int CyBtldr_EndBootloadOperation(void) 174 | { 175 | unsigned long inSize; 176 | unsigned long outSize; 177 | unsigned char inBuf[MAX_COMMAND_SIZE]; 178 | 179 | int err = CyBtldr_CreateExitBootLoaderCmd(inBuf, &inSize, &outSize); 180 | if (CYRET_SUCCESS == err) 181 | { 182 | err = g_comm->WriteData(inBuf, inSize); 183 | 184 | if (CYRET_SUCCESS == err) 185 | err = g_comm->CloseConnection(); 186 | 187 | if (CYRET_SUCCESS != err) 188 | err |= CYRET_ERR_COMM_MASK; 189 | } 190 | g_comm = NULL; 191 | 192 | return err; 193 | } 194 | 195 | int CyBtldr_ProgramRow(unsigned char arrayID, unsigned short rowNum, unsigned char* buf, unsigned short size) 196 | { 197 | const int TRANSFER_HEADER_SIZE = 11; 198 | 199 | unsigned char inBuf[MAX_COMMAND_SIZE]; 200 | unsigned char outBuf[MAX_COMMAND_SIZE]; 201 | unsigned long inSize; 202 | unsigned long outSize; 203 | unsigned long offset = 0; 204 | unsigned short subBufSize; 205 | unsigned char status = CYRET_SUCCESS; 206 | int err = CYRET_SUCCESS; 207 | 208 | if (arrayID < MAX_FLASH_ARRAYS) 209 | err = CyBtldr_ValidateRow(arrayID, rowNum); 210 | 211 | //Break row into pieces to ensure we don't send too much for the transfer protocol 212 | while ((CYRET_SUCCESS == err) && ((size - offset + TRANSFER_HEADER_SIZE) > g_comm->MaxTransferSize)) 213 | { 214 | subBufSize = (unsigned short)(g_comm->MaxTransferSize - TRANSFER_HEADER_SIZE); 215 | 216 | err = CyBtldr_CreateSendDataCmd(&buf[offset], subBufSize, inBuf, &inSize, &outSize); 217 | if (CYRET_SUCCESS == err) 218 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 219 | if (CYRET_SUCCESS == err) 220 | err = CyBtldr_ParseSendDataCmdResult(outBuf, outSize, &status); 221 | if (CYRET_SUCCESS != status) 222 | err = status | CYRET_ERR_BTLDR_MASK; 223 | 224 | offset += subBufSize; 225 | } 226 | 227 | if (CYRET_SUCCESS == err) 228 | { 229 | subBufSize = (unsigned short)(size - offset); 230 | 231 | err = CyBtldr_CreateProgramRowCmd(arrayID, rowNum, &buf[offset], subBufSize, inBuf, &inSize, &outSize); 232 | if (CYRET_SUCCESS == err) 233 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 234 | if (CYRET_SUCCESS == err) 235 | err = CyBtldr_ParseProgramRowCmdResult(outBuf, outSize, &status); 236 | if (CYRET_SUCCESS != status) 237 | err = status | CYRET_ERR_BTLDR_MASK; 238 | } 239 | 240 | return err; 241 | } 242 | 243 | int CyBtldr_EraseRow(unsigned char arrayID, unsigned short rowNum) 244 | { 245 | unsigned char inBuf[MAX_COMMAND_SIZE]; 246 | unsigned char outBuf[MAX_COMMAND_SIZE]; 247 | unsigned long inSize = 0; 248 | unsigned long outSize = 0; 249 | unsigned char status = CYRET_SUCCESS; 250 | int err = CYRET_SUCCESS; 251 | 252 | if (arrayID < MAX_FLASH_ARRAYS) 253 | err = CyBtldr_ValidateRow(arrayID, rowNum); 254 | if (CYRET_SUCCESS == err) 255 | err = CyBtldr_CreateEraseRowCmd(arrayID, rowNum, inBuf, &inSize, &outSize); 256 | if (CYRET_SUCCESS == err) 257 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 258 | if (CYRET_SUCCESS == err) 259 | err = CyBtldr_ParseEraseRowCmdResult(outBuf, outSize, &status); 260 | if (CYRET_SUCCESS != status) 261 | err = status | CYRET_ERR_BTLDR_MASK; 262 | 263 | return err; 264 | } 265 | 266 | int CyBtldr_VerifyRow(unsigned char arrayID, unsigned short rowNum, unsigned char checksum) 267 | { 268 | unsigned char inBuf[MAX_COMMAND_SIZE]; 269 | unsigned char outBuf[MAX_COMMAND_SIZE]; 270 | unsigned long inSize = 0; 271 | unsigned long outSize = 0; 272 | unsigned char rowChecksum = 0; 273 | unsigned char status = CYRET_SUCCESS; 274 | int err = CYRET_SUCCESS; 275 | 276 | if (arrayID < MAX_FLASH_ARRAYS) 277 | err = CyBtldr_ValidateRow(arrayID, rowNum); 278 | if (CYRET_SUCCESS == err) 279 | err = CyBtldr_CreateVerifyRowCmd(arrayID, rowNum, inBuf, &inSize, &outSize); 280 | if (CYRET_SUCCESS == err) 281 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 282 | if (CYRET_SUCCESS == err) 283 | err = CyBtldr_ParseVerifyRowCmdResult(outBuf, outSize, &rowChecksum, &status); 284 | if (CYRET_SUCCESS != status) 285 | err = status | CYRET_ERR_BTLDR_MASK; 286 | if ((CYRET_SUCCESS == err) && (rowChecksum != checksum)) 287 | err = CYRET_ERR_CHECKSUM; 288 | 289 | return err; 290 | } 291 | 292 | int CyBtldr_VerifyApplication(void) 293 | { 294 | unsigned char inBuf[MAX_COMMAND_SIZE]; 295 | unsigned char outBuf[MAX_COMMAND_SIZE]; 296 | unsigned long inSize = 0; 297 | unsigned long outSize = 0; 298 | unsigned char checksumValid = 0; 299 | unsigned char status = CYRET_SUCCESS; 300 | 301 | int err = CyBtldr_CreateVerifyChecksumCmd(inBuf, &inSize, &outSize); 302 | if (CYRET_SUCCESS == err) 303 | err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize); 304 | if (CYRET_SUCCESS == err) 305 | err = CyBtldr_ParseVerifyChecksumCmdResult(outBuf, outSize, &checksumValid, &status); 306 | if (CYRET_SUCCESS != status) 307 | err = status | CYRET_ERR_BTLDR_MASK; 308 | if ((CYRET_SUCCESS == err) && (!checksumValid)) 309 | err = CYRET_ERR_CHECKSUM; 310 | 311 | return err; 312 | } 313 | -------------------------------------------------------------------------------- /cybtldr_api.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gv1/cybootload_linux/5b59bb0702483d8bbf72c84e6136931e076ef9aa/cybtldr_api.h -------------------------------------------------------------------------------- /cybtldr_command.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved. 3 | * You may use this file only in accordance with the license, terms, conditions, 4 | * disclaimers, and limitations in the end user license agreement accompanying 5 | * the software package with which this file was provided. 6 | ********************************************************************************/ 7 | 8 | #include "cybtldr_command.h" 9 | 10 | 11 | /* Variable used to store the currently selected packet checksum type */ 12 | CyBtldr_ChecksumType CyBtldr_Checksum = SUM_CHECKSUM; 13 | 14 | unsigned short CyBtldr_ComputeChecksum(unsigned char* buf, unsigned long size) 15 | { 16 | if (CyBtldr_Checksum == CRC_CHECKSUM) 17 | { 18 | unsigned short crc = 0xffff; 19 | unsigned short tmp; 20 | int i; 21 | 22 | if (size == 0) 23 | return (~crc); 24 | 25 | do 26 | { 27 | for (i = 0, tmp = 0x00ff & *buf++; i < 8; i++, tmp >>= 1) 28 | { 29 | if ((crc & 0x0001) ^ (tmp & 0x0001)) 30 | crc = (crc >> 1) ^ 0x8408; 31 | else 32 | crc >>= 1; 33 | } 34 | } 35 | while (--size); 36 | 37 | crc = ~crc; 38 | tmp = crc; 39 | crc = (crc << 8) | (tmp >> 8 & 0xFF); 40 | 41 | return crc; 42 | } 43 | else /* SUM_CHECKSUM */ 44 | { 45 | unsigned short sum = 0; 46 | while (size-- > 0) 47 | sum += *buf++; 48 | 49 | return (1 + ~sum); 50 | } 51 | } 52 | 53 | void CyBtldr_SetCheckSumType(CyBtldr_ChecksumType chksumType) 54 | { 55 | CyBtldr_Checksum = chksumType; 56 | } 57 | 58 | int CyBtldr_ParseDefaultCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status) 59 | { 60 | int err = CYRET_SUCCESS; 61 | if (cmdSize != BASE_CMD_SIZE) 62 | err = CYRET_ERR_LENGTH; 63 | else if (cmdBuf[1] != CYRET_SUCCESS) 64 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 65 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != 0 || cmdBuf[3] != 0 || cmdBuf[6] != CMD_STOP) 66 | err = CYRET_ERR_DATA; 67 | else 68 | *status = cmdBuf[1]; 69 | 70 | return err; 71 | } 72 | 73 | int CyBtldr_CreateEnterBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 74 | { 75 | const unsigned long RESULT_DATA_SIZE = 8; 76 | unsigned short checksum; 77 | 78 | *resSize = BASE_CMD_SIZE + RESULT_DATA_SIZE; 79 | *cmdSize = BASE_CMD_SIZE; 80 | cmdBuf[0] = CMD_START; 81 | cmdBuf[1] = CMD_ENTER_BOOTLOADER; 82 | cmdBuf[2] = 0; 83 | cmdBuf[3] = 0; 84 | checksum = CyBtldr_ComputeChecksum(cmdBuf, BASE_CMD_SIZE - 3); 85 | cmdBuf[4] = (unsigned char)checksum; 86 | cmdBuf[5] = (unsigned char)(checksum >> 8); 87 | cmdBuf[6] = CMD_STOP; 88 | 89 | return CYRET_SUCCESS; 90 | } 91 | 92 | int CyBtldr_ParseEnterBootLoaderCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned long* siliconId, unsigned char* siliconRev, unsigned long* blVersion, unsigned char* status) 93 | { 94 | const unsigned long RESULT_DATA_SIZE = 8; 95 | const unsigned long RESULT_SIZE = BASE_CMD_SIZE + RESULT_DATA_SIZE; 96 | int err = CYRET_SUCCESS; 97 | 98 | if (cmdSize != RESULT_SIZE) 99 | err = CYRET_ERR_LENGTH; 100 | else if (cmdBuf[1] != CYRET_SUCCESS) 101 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 102 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != RESULT_DATA_SIZE || cmdBuf[3] != (RESULT_DATA_SIZE >> 8) || cmdBuf[RESULT_SIZE - 1] != CMD_STOP) 103 | err = CYRET_ERR_DATA; 104 | else 105 | { 106 | *siliconId = (cmdBuf[7] << 24) | (cmdBuf[6] << 16) | (cmdBuf[5] << 8) | cmdBuf[4]; 107 | *siliconRev = cmdBuf[8]; 108 | *blVersion = (cmdBuf[11] << 16) | (cmdBuf[10] << 8) | cmdBuf[9]; 109 | *status = cmdBuf[1]; 110 | } 111 | 112 | return err; 113 | } 114 | 115 | int CyBtldr_CreateExitBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 116 | { 117 | const unsigned long COMMAND_DATA_SIZE = 1; 118 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 119 | unsigned short checksum; 120 | 121 | *resSize = BASE_CMD_SIZE; 122 | *cmdSize = COMMAND_SIZE; 123 | cmdBuf[0] = CMD_START; 124 | cmdBuf[1] = CMD_EXIT_BOOTLOADER; 125 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 126 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 127 | cmdBuf[4] = 0; 128 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 129 | cmdBuf[5] = (unsigned char)checksum; 130 | cmdBuf[6] = (unsigned char)(checksum >> 8); 131 | cmdBuf[7] = CMD_STOP; 132 | 133 | return CYRET_SUCCESS; 134 | } 135 | 136 | int CyBtldr_CreateProgramRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 137 | { 138 | const unsigned long COMMAND_DATA_SIZE = 3; 139 | unsigned int checksum; 140 | unsigned long i; 141 | 142 | *resSize = BASE_CMD_SIZE; 143 | *cmdSize = BASE_CMD_SIZE + COMMAND_DATA_SIZE + size; 144 | cmdBuf[0] = CMD_START; 145 | cmdBuf[1] = CMD_PROGRAM_ROW; 146 | cmdBuf[2] = (unsigned char)(size + COMMAND_DATA_SIZE); 147 | cmdBuf[3] = (unsigned char)((size + COMMAND_DATA_SIZE) >> 8); 148 | cmdBuf[4] = arrayId; 149 | cmdBuf[5] = (unsigned char)rowNum; 150 | cmdBuf[6] = (unsigned char)(rowNum >> 8); 151 | for (i = 0; i < size; i++) 152 | cmdBuf[i + 7] = buf[i]; 153 | checksum = CyBtldr_ComputeChecksum(cmdBuf, (*cmdSize) - 3); 154 | cmdBuf[*cmdSize - 3] = (unsigned char)checksum; 155 | cmdBuf[*cmdSize - 2] = (unsigned char)(checksum >> 8); 156 | cmdBuf[*cmdSize - 1] = CMD_STOP; 157 | 158 | return CYRET_SUCCESS; 159 | } 160 | 161 | int CyBtldr_ParseProgramRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status) 162 | { 163 | return CyBtldr_ParseDefaultCmdResult(cmdBuf, cmdSize, status); 164 | } 165 | 166 | int CyBtldr_CreateVerifyRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 167 | { 168 | const unsigned long RESULT_DATA_SIZE = 1; 169 | const unsigned long COMMAND_DATA_SIZE = 3; 170 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 171 | unsigned short checksum; 172 | 173 | *resSize = BASE_CMD_SIZE + RESULT_DATA_SIZE; 174 | *cmdSize = COMMAND_SIZE; 175 | cmdBuf[0] = CMD_START; 176 | cmdBuf[1] = CMD_VERIFY_ROW; 177 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 178 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 179 | cmdBuf[4] = arrayId; 180 | cmdBuf[5] = (unsigned char)rowNum; 181 | cmdBuf[6] = (unsigned char)(rowNum >> 8); 182 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 183 | cmdBuf[7] = (unsigned char)checksum; 184 | cmdBuf[8] = (unsigned char)(checksum >> 8); 185 | cmdBuf[9] = CMD_STOP; 186 | 187 | return CYRET_SUCCESS; 188 | } 189 | 190 | int CyBtldr_ParseVerifyRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksum, unsigned char* status) 191 | { 192 | const unsigned long RESULT_DATA_SIZE = 1; 193 | const unsigned long RESULT_SIZE = BASE_CMD_SIZE + RESULT_DATA_SIZE; 194 | int err = CYRET_SUCCESS; 195 | 196 | if (cmdSize != RESULT_SIZE) 197 | err = CYRET_ERR_LENGTH; 198 | else if (cmdBuf[1] != CYRET_SUCCESS) 199 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 200 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != RESULT_DATA_SIZE || cmdBuf[3] != (RESULT_DATA_SIZE >> 8) || cmdBuf[RESULT_SIZE - 1] != CMD_STOP) 201 | err = CYRET_ERR_DATA; 202 | else 203 | { 204 | *checksum = cmdBuf[4]; 205 | *status = cmdBuf[1]; 206 | } 207 | 208 | return err; 209 | } 210 | 211 | int CyBtldr_CreateEraseRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 212 | { 213 | const unsigned long COMMAND_DATA_SIZE = 3; 214 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 215 | unsigned short checksum; 216 | 217 | *resSize = BASE_CMD_SIZE; 218 | *cmdSize = COMMAND_SIZE; 219 | cmdBuf[0] = CMD_START; 220 | cmdBuf[1] = CMD_ERASE_ROW; 221 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 222 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 223 | cmdBuf[4] = arrayId; 224 | cmdBuf[5] = (unsigned char)rowNum; 225 | cmdBuf[6] = (unsigned char)(rowNum >> 8); 226 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 227 | cmdBuf[7] = (unsigned char)checksum; 228 | cmdBuf[8] = (unsigned char)(checksum >> 8); 229 | cmdBuf[9] = CMD_STOP; 230 | 231 | return CYRET_SUCCESS; 232 | } 233 | 234 | int CyBtldr_ParseEraseRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status) 235 | { 236 | return CyBtldr_ParseDefaultCmdResult(cmdBuf, cmdSize, status); 237 | } 238 | 239 | int CyBtldr_CreateVerifyChecksumCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 240 | { 241 | const unsigned long RESULT_DATA_SIZE = 1; 242 | unsigned short checksum; 243 | 244 | *resSize = BASE_CMD_SIZE + RESULT_DATA_SIZE; 245 | *cmdSize = BASE_CMD_SIZE; 246 | cmdBuf[0] = CMD_START; 247 | cmdBuf[1] = CMD_VERIFY_CHECKSUM; 248 | cmdBuf[2] = 0; 249 | cmdBuf[3] = 0; 250 | checksum = CyBtldr_ComputeChecksum(cmdBuf, BASE_CMD_SIZE - 3); 251 | cmdBuf[4] = (unsigned char)checksum; 252 | cmdBuf[5] = (unsigned char)(checksum >> 8); 253 | cmdBuf[6] = CMD_STOP; 254 | 255 | return CYRET_SUCCESS; 256 | } 257 | 258 | int CyBtldr_ParseVerifyChecksumCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksumValid, unsigned char* status) 259 | { 260 | const unsigned long RESULT_DATA_SIZE = 1; 261 | const unsigned long RESULT_SIZE = BASE_CMD_SIZE + RESULT_DATA_SIZE; 262 | int err = CYRET_SUCCESS; 263 | 264 | if (cmdSize != RESULT_SIZE) 265 | err = CYRET_ERR_LENGTH; 266 | else if (cmdBuf[1] != CYRET_SUCCESS) 267 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 268 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != RESULT_DATA_SIZE || cmdBuf[3] != (RESULT_DATA_SIZE >> 8) || cmdBuf[RESULT_SIZE - 1] != CMD_STOP) 269 | err = CYRET_ERR_DATA; 270 | else 271 | { 272 | *checksumValid = cmdBuf[4]; 273 | *status = cmdBuf[1]; 274 | } 275 | 276 | return err; 277 | } 278 | 279 | int CyBtldr_CreateGetFlashSizeCmd(unsigned char arrayId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 280 | { 281 | const unsigned long RESULT_DATA_SIZE = 4; 282 | const unsigned long COMMAND_DATA_SIZE = 1; 283 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 284 | unsigned short checksum; 285 | 286 | *resSize = BASE_CMD_SIZE + RESULT_DATA_SIZE; 287 | *cmdSize = COMMAND_SIZE; 288 | cmdBuf[0] = CMD_START; 289 | cmdBuf[1] = CMD_GET_FLASH_SIZE; 290 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 291 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 292 | cmdBuf[4] = arrayId; 293 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 294 | cmdBuf[5] = (unsigned char)checksum; 295 | cmdBuf[6] = (unsigned char)(checksum >> 8); 296 | cmdBuf[7] = CMD_STOP; 297 | 298 | return CYRET_SUCCESS; 299 | } 300 | 301 | int CyBtldr_ParseGetFlashSizeCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned short* startRow, unsigned short* endRow, unsigned char* status) 302 | { 303 | const unsigned long RESULT_DATA_SIZE = 4; 304 | const unsigned long RESULT_SIZE = BASE_CMD_SIZE + RESULT_DATA_SIZE; 305 | int err = CYRET_SUCCESS; 306 | 307 | if (cmdSize != RESULT_SIZE) 308 | err = CYRET_ERR_LENGTH; 309 | else if (cmdBuf[1] != CYRET_SUCCESS) 310 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 311 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != RESULT_DATA_SIZE || cmdBuf[3] != (RESULT_DATA_SIZE >> 8) || cmdBuf[RESULT_SIZE - 1] != CMD_STOP) 312 | err = CYRET_ERR_DATA; 313 | else 314 | { 315 | *startRow = (cmdBuf[5] << 8) | cmdBuf[4]; 316 | *endRow = (cmdBuf[7] << 8) | cmdBuf[6]; 317 | *status = cmdBuf[1]; 318 | } 319 | 320 | return err; 321 | } 322 | 323 | int CyBtldr_CreateSendDataCmd(unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 324 | { 325 | unsigned short checksum; 326 | unsigned long i; 327 | 328 | *resSize = BASE_CMD_SIZE; 329 | *cmdSize = size + BASE_CMD_SIZE; 330 | cmdBuf[0] = CMD_START; 331 | cmdBuf[1] = CMD_SEND_DATA; 332 | cmdBuf[2] = (unsigned char)size; 333 | cmdBuf[3] = (unsigned char)(size >> 8); 334 | for (i = 0; i < size; i++) 335 | cmdBuf[i + 4] = buf[i]; 336 | checksum = CyBtldr_ComputeChecksum(cmdBuf, (*cmdSize) - 3); 337 | cmdBuf[(*cmdSize) - 3] = (unsigned char)checksum; 338 | cmdBuf[(*cmdSize) - 2] = (unsigned char)(checksum >> 8); 339 | cmdBuf[(*cmdSize) - 1] = CMD_STOP; 340 | 341 | return CYRET_SUCCESS; 342 | } 343 | 344 | int CyBtldr_ParseSendDataCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status) 345 | { 346 | return CyBtldr_ParseDefaultCmdResult(cmdBuf, cmdSize, status); 347 | } 348 | 349 | int CyBtldr_CreateSyncBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 350 | { 351 | unsigned short checksum; 352 | 353 | *resSize = BASE_CMD_SIZE; 354 | *cmdSize = BASE_CMD_SIZE; 355 | cmdBuf[0] = CMD_START; 356 | cmdBuf[1] = CMD_SYNC; 357 | cmdBuf[2] = 0; 358 | cmdBuf[3] = 0; 359 | checksum = CyBtldr_ComputeChecksum(cmdBuf, BASE_CMD_SIZE - 3); 360 | cmdBuf[4] = (unsigned char)checksum; 361 | cmdBuf[5] = (unsigned char)(checksum >> 8); 362 | cmdBuf[6] = CMD_STOP; 363 | 364 | return CYRET_SUCCESS; 365 | } 366 | 367 | int CyBtldr_CreateGetAppStatusCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 368 | { 369 | const unsigned long RESULT_DATA_SIZE = 2; 370 | const unsigned long COMMAND_DATA_SIZE = 1; 371 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 372 | unsigned short checksum; 373 | 374 | *resSize = BASE_CMD_SIZE + RESULT_DATA_SIZE; 375 | *cmdSize = COMMAND_SIZE; 376 | cmdBuf[0] = CMD_START; 377 | cmdBuf[1] = CMD_GET_APP_STATUS; 378 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 379 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 380 | cmdBuf[4] = appId; 381 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 382 | cmdBuf[5] = (unsigned char)checksum; 383 | cmdBuf[6] = (unsigned char)(checksum >> 8); 384 | cmdBuf[7] = CMD_STOP; 385 | 386 | return CYRET_SUCCESS; 387 | } 388 | 389 | int CyBtldr_ParseGetAppStatusCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* isValid, unsigned char* isActive, unsigned char* status) 390 | { 391 | const unsigned long RESULT_DATA_SIZE = 2; 392 | const unsigned long RESULT_SIZE = BASE_CMD_SIZE + RESULT_DATA_SIZE; 393 | int err = CYRET_SUCCESS; 394 | 395 | if (cmdSize != RESULT_SIZE) 396 | err = CYRET_ERR_LENGTH; 397 | else if (cmdBuf[1] != CYRET_SUCCESS) 398 | err = CYRET_ERR_BTLDR_MASK | (*status = cmdBuf[1]); 399 | else if (cmdBuf[0] != CMD_START || cmdBuf[2] != RESULT_DATA_SIZE || cmdBuf[3] != (RESULT_DATA_SIZE >> 8) || cmdBuf[RESULT_SIZE - 1] != CMD_STOP) 400 | err = CYRET_ERR_DATA; 401 | else 402 | { 403 | *isValid = cmdBuf[4]; 404 | *isActive = cmdBuf[5]; 405 | *status = cmdBuf[1]; 406 | } 407 | 408 | return err; 409 | } 410 | 411 | int CyBtldr_CreateSetActiveAppCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize) 412 | { 413 | const unsigned long COMMAND_DATA_SIZE = 1; 414 | const unsigned int COMMAND_SIZE = BASE_CMD_SIZE + COMMAND_DATA_SIZE; 415 | unsigned short checksum; 416 | 417 | *resSize = BASE_CMD_SIZE; 418 | *cmdSize = COMMAND_SIZE; 419 | cmdBuf[0] = CMD_START; 420 | cmdBuf[1] = CMD_SET_ACTIVE_APP; 421 | cmdBuf[2] = (unsigned char)COMMAND_DATA_SIZE; 422 | cmdBuf[3] = (unsigned char)(COMMAND_DATA_SIZE >> 8); 423 | cmdBuf[4] = appId; 424 | checksum = CyBtldr_ComputeChecksum(cmdBuf, COMMAND_SIZE - 3); 425 | cmdBuf[5] = (unsigned char)checksum; 426 | cmdBuf[6] = (unsigned char)(checksum >> 8); 427 | cmdBuf[7] = CMD_STOP; 428 | 429 | return CYRET_SUCCESS; 430 | } 431 | 432 | int CyBtldr_ParseSetActiveAppCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status) 433 | { 434 | return CyBtldr_ParseDefaultCmdResult(cmdBuf, cmdSize, status); 435 | } 436 | -------------------------------------------------------------------------------- /cybtldr_command.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved. 3 | * You may use this file only in accordance with the license, terms, conditions, 4 | * disclaimers, and limitations in the end user license agreement accompanying 5 | * the software package with which this file was provided. 6 | ********************************************************************************/ 7 | 8 | #ifndef __CYBTLDR_COMMAND_H__ 9 | #define __CYBTLDR_COMMAND_H__ 10 | 11 | #include "cybtldr_utils.h" 12 | 13 | /* Maximum number of bytes to allocate for a single command. */ 14 | #define MAX_COMMAND_SIZE 512 15 | 16 | 17 | //STANDARD PACKET FORMAT: 18 | // Multi byte entries are encoded in LittleEndian. 19 | /******************************************************************************* 20 | * [1-byte] [1-byte ] [2-byte] [n-byte] [ 2-byte ] [1-byte] 21 | * [ SOP ] [Command] [ Size ] [ Data ] [Checksum] [ EOP ] 22 | *******************************************************************************/ 23 | 24 | 25 | /* The first byte of any boot loader command. */ 26 | #define CMD_START 0x01 27 | /* The last byte of any boot loader command. */ 28 | #define CMD_STOP 0x17 29 | /* The minimum number of bytes in a bootloader command. */ 30 | #define BASE_CMD_SIZE 0x07 31 | 32 | /* Command identifier for verifying the checksum value of the bootloadable project. */ 33 | #define CMD_VERIFY_CHECKSUM 0x31 34 | /* Command identifier for getting the number of flash rows in the target device. */ 35 | #define CMD_GET_FLASH_SIZE 0x32 36 | /* Command identifier for getting info about the app status. This is only supported on multi app bootloader. */ 37 | #define CMD_GET_APP_STATUS 0x33 38 | /* Command identifier for reasing a row of flash data from the target device. */ 39 | #define CMD_ERASE_ROW 0x34 40 | /* Command identifier for making sure the bootloader host and bootloader are in sync. */ 41 | #define CMD_SYNC 0x35 42 | /* Command identifier for setting the active application. This is only supported on multi app bootloader. */ 43 | #define CMD_SET_ACTIVE_APP 0x36 44 | /* Command identifier for sending a block of data to the bootloader without doing anything with it yet. */ 45 | #define CMD_SEND_DATA 0x37 46 | /* Command identifier for starting the boot loader. All other commands ignored until this is sent. */ 47 | #define CMD_ENTER_BOOTLOADER 0x38 48 | /* Command identifier for programming a single row of flash. */ 49 | #define CMD_PROGRAM_ROW 0x39 50 | /* Command identifier for verifying the contents of a single row of flash. */ 51 | #define CMD_VERIFY_ROW 0x3A 52 | /* Command identifier for exiting the bootloader and restarting the target program. */ 53 | #define CMD_EXIT_BOOTLOADER 0x3B 54 | 55 | /* 56 | * This enum defines the different types of checksums that can be 57 | * used by the bootloader for ensuring data integrety. 58 | */ 59 | typedef enum 60 | { 61 | /* Checksum type is a basic inverted summation of all bytes */ 62 | SUM_CHECKSUM = 0x00, 63 | /* 16-bit CRC checksum using the CCITT implementation */ 64 | CRC_CHECKSUM = 0x01, 65 | } CyBtldr_ChecksumType; 66 | 67 | /******************************************************************************* 68 | * Function Name: CyBtldr_ComputeChecksum 69 | ******************************************************************************** 70 | * Summary: 71 | * Computes the 2byte checksum for the provided command data. The checksum is 72 | * the 2's complement of the 1-byte sum of all bytes. 73 | * 74 | * Parameters: 75 | * buf - The data to compute the checksum on 76 | * size - The number of bytes contained in buf. 77 | * 78 | * Returns: 79 | * The checksum for the provided data. 80 | * 81 | *******************************************************************************/ 82 | unsigned short CyBtldr_ComputeChecksum(unsigned char* buf, unsigned long size); 83 | 84 | /******************************************************************************* 85 | * Function Name: CyBtldr_SetCheckSumType 86 | ******************************************************************************** 87 | * Summary: 88 | * Updates what checksum algorithm is used when generating packets 89 | * 90 | * Parameters: 91 | * chksumType - The type of checksum to use when creating packets 92 | * 93 | * Returns: 94 | * NA 95 | * 96 | *******************************************************************************/ 97 | void CyBtldr_SetCheckSumType(CyBtldr_ChecksumType chksumType); 98 | 99 | /******************************************************************************* 100 | * Function Name: CyBtldr_ParseDefaultCmdResult 101 | ******************************************************************************** 102 | * Summary: 103 | * Parses the output from any command that returns the default result packet 104 | * data. The default result is just a status byte 105 | * 106 | * Parameters: 107 | * cmdBuf - The preallocated buffer to store command data in. 108 | * cmdSize - The number of bytes in the command. 109 | * status - The status code returned by the bootloader. 110 | * 111 | * Returns: 112 | * CYRET_SUCCESS - The command was constructed successfully 113 | * CYRET_ERR_LENGTH - The packet does not contain enough data 114 | * CYRET_ERR_DATA - The packet's contents are not correct 115 | * 116 | *******************************************************************************/ 117 | int CyBtldr_ParseDefaultCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status); 118 | 119 | /******************************************************************************* 120 | * Function Name: CyBtldr_CreateEnterBootLoaderCmd 121 | ******************************************************************************** 122 | * Summary: 123 | * Creates the command used to startup the bootloader. 124 | * NB: This command must be sent before the bootloader will respond to any 125 | * other command. 126 | * 127 | * Parameters: 128 | * protect - The flash protection settings. 129 | * cmdBuf - The preallocated buffer to store command data in. 130 | * cmdSize - The number of bytes in the command. 131 | * resSize - The number of bytes expected in the bootloader's response packet. 132 | * 133 | * Returns: 134 | * CYRET_SUCCESS - The command was constructed successfully 135 | * 136 | *******************************************************************************/ 137 | EXTERN int CyBtldr_CreateEnterBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 138 | 139 | /******************************************************************************* 140 | * Function Name: CyBtldr_ParseEnterBootLoaderCmdResult 141 | ******************************************************************************** 142 | * Summary: 143 | * Parses the output from the EnterBootLoader command to get the resultant 144 | * data. 145 | * 146 | * Parameters: 147 | * cmdBuf - The buffer containing the output from the bootloader. 148 | * cmdSize - The number of bytes in cmdBuf. 149 | * siliconId - The silicon ID of the device being communicated with. 150 | * siliconRev - The silicon Revision of the device being communicated with. 151 | * blVersion - The bootloader version being communicated with. 152 | * status - The status code returned by the bootloader. 153 | * 154 | * Returns: 155 | * CYRET_SUCCESS - The command was constructed successfully 156 | * CYRET_ERR_LENGTH - The packet does not contain enough data 157 | * CYRET_ERR_DATA - The packet's contents are not correct 158 | * 159 | *******************************************************************************/ 160 | EXTERN int CyBtldr_ParseEnterBootLoaderCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned long* siliconId, unsigned char* siliconRev, unsigned long* blVersion, unsigned char* status); 161 | 162 | /******************************************************************************* 163 | * Function Name: CyBtldr_CreateExitBootLoaderCmd 164 | ******************************************************************************** 165 | * Summary: 166 | * Creates the command used to stop communicating with the boot loader and to 167 | * trigger the target device to restart, running the new bootloadable 168 | * application. 169 | * 170 | * Parameters: 171 | * cmdBuf - The preallocated buffer to store command data in. 172 | * cmdSize - The number of bytes in the command. 173 | * resSize - The number of bytes expected in the bootloader's response packet. 174 | * 175 | * Returns: 176 | * CYRET_SUCCESS - The command was constructed successfully 177 | * 178 | *******************************************************************************/ 179 | EXTERN int CyBtldr_CreateExitBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 180 | 181 | /******************************************************************************* 182 | * Function Name: CyBtldr_CreateProgramRowCmd 183 | ******************************************************************************** 184 | * Summary: 185 | * Creates the command used to program a single flash row. 186 | * 187 | * Parameters: 188 | * arrayId - The array id to program. 189 | * rowNum - The row number to program. 190 | * buf - The buffer of data to program into the flash row. 191 | * size - The number of bytes in data for the row. 192 | * cmdBuf - The preallocated buffer to store command data in. 193 | * cmdSize - The number of bytes in the command. 194 | * resSize - The number of bytes expected in the bootloader's response packet. 195 | * 196 | * Returns: 197 | * CYRET_SUCCESS - The command was constructed successfully 198 | * 199 | *******************************************************************************/ 200 | EXTERN int CyBtldr_CreateProgramRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 201 | 202 | /******************************************************************************* 203 | * Function Name: CyBtldr_ParseProgramRowCmdResult 204 | ******************************************************************************** 205 | * Summary: 206 | * Parses the output from the ProgramRow command to get the resultant 207 | * data. 208 | * 209 | * Parameters: 210 | * cmdBuf - The preallocated buffer to store command data in. 211 | * cmdSize - The number of bytes in the command. 212 | * status - The status code returned by the bootloader. 213 | * 214 | * Returns: 215 | * CYRET_SUCCESS - The command was constructed successfully 216 | * CYRET_ERR_LENGTH - The packet does not contain enough data 217 | * CYRET_ERR_DATA - The packet's contents are not correct 218 | * 219 | *******************************************************************************/ 220 | EXTERN int CyBtldr_ParseProgramRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status); 221 | 222 | /******************************************************************************* 223 | * Function Name: CyBtldr_CreateVerifyRowCmd 224 | ******************************************************************************** 225 | * Summary: 226 | * Creates the command used to verify that the contents of flash match the 227 | * provided row data. 228 | * 229 | * Parameters: 230 | * arrayId - The array id to verify. 231 | * rowNum - The row number to verify. 232 | * cmdBuf - The preallocated buffer to store command data in. 233 | * cmdSize - The number of bytes in the command. 234 | * resSize - The number of bytes expected in the bootloader's response packet. 235 | * 236 | * Returns: 237 | * CYRET_SUCCESS - The command was constructed successfully 238 | * 239 | *******************************************************************************/ 240 | EXTERN int CyBtldr_CreateVerifyRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 241 | 242 | /******************************************************************************* 243 | * Function Name: CyBtldr_ParseVerifyRowCmdResult 244 | ******************************************************************************** 245 | * Summary: 246 | * Parses the output from the VerifyRow command to get the resultant 247 | * data. 248 | * 249 | * Parameters: 250 | * cmdBuf - The preallocated buffer to store command data in. 251 | * cmdSize - The number of bytes in the command. 252 | * checksum - The checksum from the row to verify. 253 | * status - The status code returned by the bootloader. 254 | * 255 | * Returns: 256 | * CYRET_SUCCESS - The command was constructed successfully 257 | * CYRET_ERR_LENGTH - The packet does not contain enough data 258 | * CYRET_ERR_DATA - The packet's contents are not correct 259 | * 260 | *******************************************************************************/ 261 | EXTERN int CyBtldr_ParseVerifyRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksum, unsigned char* status); 262 | 263 | /******************************************************************************* 264 | * Function Name: CyBtldr_CreateEraseRowCmd 265 | ******************************************************************************** 266 | * Summary: 267 | * Creates the command used to erase a single flash row. 268 | * 269 | * Parameters: 270 | * arrayId - The array id to erase. 271 | * rowNum - The row number to erase. 272 | * cmdBuf - The preallocated buffer to store command data in. 273 | * cmdSize - The number of bytes in the command. 274 | * resSize - The number of bytes expected in the bootloader's response packet. 275 | * 276 | * Returns: 277 | * CYRET_SUCCESS - The command was constructed successfully 278 | * 279 | *******************************************************************************/ 280 | EXTERN int CyBtldr_CreateEraseRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 281 | 282 | /******************************************************************************* 283 | * Function Name: CyBtldr_ParseEraseRowCmdResult 284 | ******************************************************************************** 285 | * Summary: 286 | * Parses the output from the EraseRow command to get the resultant 287 | * data. 288 | * 289 | * Parameters: 290 | * cmdBuf - The preallocated buffer to store command data in. 291 | * cmdSize - The number of bytes in the command. 292 | * status - The status code returned by the bootloader. 293 | * 294 | * Returns: 295 | * CYRET_SUCCESS - The command was constructed successfully 296 | * CYRET_ERR_LENGTH - The packet does not contain enough data 297 | * CYRET_ERR_DATA - The packet's contents are not correct 298 | * 299 | *******************************************************************************/ 300 | EXTERN int CyBtldr_ParseEraseRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status); 301 | 302 | /******************************************************************************* 303 | * Function Name: CyBtldr_CreateVerifyChecksumCmd 304 | ******************************************************************************** 305 | * Summary: 306 | * Creates the command used to verify that the checkusm value in flash matches 307 | * what is expected. 308 | * 309 | * Parameters: 310 | * cmdBuf - The preallocated buffer to store command data in. 311 | * cmdSize - The number of bytes in the command. 312 | * resSize - The number of bytes expected in the bootloader's response packet. 313 | * 314 | * Returns: 315 | * CYRET_SUCCESS - The command was constructed successfully 316 | * 317 | *******************************************************************************/ 318 | EXTERN int CyBtldr_CreateVerifyChecksumCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 319 | 320 | /******************************************************************************* 321 | * Function Name: CyBtldr_ParseVerifyChecksumCmdResult 322 | ******************************************************************************** 323 | * Summary: 324 | * Parses the output from the VerifyChecksum command to get the resultant 325 | * data. 326 | * 327 | * Parameters: 328 | * cmdBuf - The preallocated buffer to store command data in. 329 | * cmdSize - The number of bytes in the command. 330 | * checksumValid - Whether or not the full checksums match (1 = valid, 0 = invalid) 331 | * status - The status code returned by the bootloader. 332 | * 333 | * Returns: 334 | * CYRET_SUCCESS - The command was constructed successfully 335 | * CYRET_ERR_LENGTH - The packet does not contain enough data 336 | * CYRET_ERR_DATA - The packet's contents are not correct 337 | * 338 | *******************************************************************************/ 339 | EXTERN int CyBtldr_ParseVerifyChecksumCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksumValid, unsigned char* status); 340 | 341 | /******************************************************************************* 342 | * Function Name: CyBtldr_CreateGetFlashSizeCmd 343 | ******************************************************************************** 344 | * Summary: 345 | * Creates the command used to retreive the number of flash rows in the device. 346 | * 347 | * Parameters: 348 | * arrayId - The array ID to get the flash size of. 349 | * cmdBuf - The preallocated buffer to store command data in. 350 | * cmdSize - The number of bytes in the command. 351 | * resSize - The number of bytes expected in the bootloader's response packet. 352 | * 353 | * Returns: 354 | * CYRET_SUCCESS - The command was constructed successfully 355 | * 356 | *******************************************************************************/ 357 | EXTERN int CyBtldr_CreateGetFlashSizeCmd(unsigned char arrayId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 358 | 359 | /******************************************************************************* 360 | * Function Name: CyBtldr_ParseGetFlashSizeCmdResult 361 | ******************************************************************************** 362 | * Summary: 363 | * Parses the output from the GetFlashSize command to get the resultant 364 | * data. 365 | * 366 | * Parameters: 367 | * cmdBuf - The preallocated buffer to store command data in. 368 | * cmdSize - The number of bytes in the command. 369 | * startRow - The first available row number in the flash array. 370 | * endRow - The last available row number in the flash array. 371 | * status - The status code returned by the bootloader. 372 | * 373 | * Returns: 374 | * CYRET_SUCCESS - The command was constructed successfully 375 | * CYRET_ERR_LENGTH - The packet does not contain enough data 376 | * CYRET_ERR_DATA - The packet's contents are not correct 377 | * 378 | *******************************************************************************/ 379 | EXTERN int CyBtldr_ParseGetFlashSizeCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned short* startRow, unsigned short* endRow, unsigned char* status); 380 | 381 | /******************************************************************************* 382 | * Function Name: CyBtldr_CreateSendDataCmd 383 | ******************************************************************************** 384 | * Summary: 385 | * Creates the command used to send a block of data to the target. 386 | * 387 | * Parameters: 388 | * buf - The buffer of data data to program into the flash row. 389 | * size - The number of bytes in data for the row. 390 | * cmdBuf - The preallocated buffer to store command data in. 391 | * cmdSize - The number of bytes in the command. 392 | * resSize - The number of bytes expected in the bootloader's response packet. 393 | * 394 | * Returns: 395 | * CYRET_SUCCESS - The command was constructed successfully 396 | * 397 | *******************************************************************************/ 398 | EXTERN int CyBtldr_CreateSendDataCmd(unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 399 | 400 | /******************************************************************************* 401 | * Function Name: CyBtldr_ParseSendDataCmdResult 402 | ******************************************************************************** 403 | * Summary: 404 | * Parses the output from the SendData command to get the resultant 405 | * data. 406 | * 407 | * Parameters: 408 | * cmdBuf - The preallocated buffer to store command data in. 409 | * cmdSize - The number of bytes in the command. 410 | * status - The status code returned by the bootloader. 411 | * 412 | * Returns: 413 | * CYRET_SUCCESS - The command was constructed successfully 414 | * CYRET_ERR_LENGTH - The packet does not contain enough data 415 | * CYRET_ERR_DATA - The packet's contents are not correct 416 | * 417 | *******************************************************************************/ 418 | EXTERN int CyBtldr_ParseSendDataCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status); 419 | 420 | /******************************************************************************* 421 | * Function Name: CyBtldr_CreateSyncBootLoaderCmd 422 | ******************************************************************************** 423 | * Summary: 424 | * Creates the command used to ensure that the host application is in sync 425 | * with the bootloader application. 426 | * 427 | * Parameters: 428 | * cmdBuf - The preallocated buffer to store command data in. 429 | * cmdSize - The number of bytes in the command. 430 | * resSize - The number of bytes expected in the bootloader's response packet. 431 | * 432 | * Returns: 433 | * CYRET_SUCCESS - The command was constructed successfully 434 | * 435 | *******************************************************************************/ 436 | EXTERN int CyBtldr_CreateSyncBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 437 | 438 | /******************************************************************************* 439 | * Function Name: CyBtldr_CreateGetAppStatusCmd 440 | ******************************************************************************** 441 | * Summary: 442 | * Creates the command used to get information about the application. This 443 | * command is only supported by the multi application bootloaader. 444 | * 445 | * Parameters: 446 | * appId - The id for the application to get status for 447 | * cmdBuf - The preallocated buffer to store command data in. 448 | * cmdSize - The number of bytes in the command. 449 | * resSize - The number of bytes expected in the bootloader's response packet. 450 | * 451 | * Returns: 452 | * CYRET_SUCCESS - The command was constructed successfully 453 | * 454 | *******************************************************************************/ 455 | EXTERN int CyBtldr_CreateGetAppStatusCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 456 | 457 | /******************************************************************************* 458 | * Function Name: CyBtldr_ParseGetAppStatusCmdResult 459 | ******************************************************************************** 460 | * Summary: 461 | * Parses the output from the GetAppStatus command to get the resultant 462 | * data. 463 | * 464 | * Parameters: 465 | * cmdBuf - The preallocated buffer to store command data in. 466 | * cmdSize - The number of bytes in the command. 467 | * isValid - Is the application valid. 468 | * isActive- Is the application currently marked as active. 469 | * status - The status code returned by the bootloader. 470 | * 471 | * Returns: 472 | * CYRET_SUCCESS - The command was constructed successfully 473 | * CYRET_ERR_LENGTH - The packet does not contain enough data 474 | * CYRET_ERR_DATA - The packet's contents are not correct 475 | * 476 | *******************************************************************************/ 477 | EXTERN int CyBtldr_ParseGetAppStatusCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* isValid, unsigned char* isActive, unsigned char* status); 478 | 479 | /******************************************************************************* 480 | * Function Name: CyBtldr_CreateSetActiveAppCmd 481 | ******************************************************************************** 482 | * Summary: 483 | * Creates the command used to set the active application for the bootloader 484 | * to run. This command is only supported by the multi application 485 | * bootloaader. 486 | * 487 | * Parameters: 488 | * appId - The id for the application to get status for 489 | * cmdBuf - The preallocated buffer to store command data in. 490 | * cmdSize - The number of bytes in the command. 491 | * resSize - The number of bytes expected in the bootloader's response packet. 492 | * 493 | * Returns: 494 | * CYRET_SUCCESS - The command was constructed successfully 495 | * 496 | *******************************************************************************/ 497 | EXTERN int CyBtldr_CreateSetActiveAppCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize); 498 | 499 | /******************************************************************************* 500 | * Function Name: CyBtldr_ParseSetActiveAppCmdResult 501 | ******************************************************************************** 502 | * Summary: 503 | * Parses the output from the SetActiveApp command to get the resultant 504 | * data. 505 | * 506 | * Parameters: 507 | * cmdBuf - The preallocated buffer to store command data in. 508 | * cmdSize - The number of bytes in the command. 509 | * status - The status code returned by the bootloader. 510 | * 511 | * Returns: 512 | * CYRET_SUCCESS - The command was constructed successfully 513 | * CYRET_ERR_LENGTH - The packet does not contain enough data 514 | * CYRET_ERR_DATA - The packet's contents are not correct 515 | * 516 | *******************************************************************************/ 517 | EXTERN int CyBtldr_ParseSetActiveAppCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status); 518 | 519 | #endif 520 | -------------------------------------------------------------------------------- /cybtldr_parse.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved. 3 | * You may use this file only in accordance with the license, terms, conditions, 4 | * disclaimers, and limitations in the end user license agreement accompanying 5 | * the software package with which this file was provided. 6 | ********************************************************************************/ 7 | 8 | #include 9 | #include "cybtldr_parse.h" 10 | 11 | /* Pointer to the *.cyacd file containing the data that is to be read */ 12 | static FILE* dataFile; 13 | 14 | unsigned char CyBtldr_FromHex(char value) 15 | { 16 | if ('0' <= value && value <= '9') 17 | return (unsigned char)(value - '0'); 18 | if ('a' <= value && value <= 'f') 19 | return (unsigned char)(10 + value - 'a'); 20 | if ('A' <= value && value <= 'F') 21 | return (unsigned char)(10 + value - 'A'); 22 | return 0; 23 | } 24 | 25 | int CyBtldr_FromAscii(unsigned int bufSize, unsigned char* buffer, unsigned short* rowSize, unsigned char* rowData) 26 | { 27 | unsigned short i; 28 | int err = CYRET_SUCCESS; 29 | 30 | if (bufSize & 1) // Make sure even number of bytes 31 | err = CYRET_ERR_LENGTH; 32 | else 33 | { 34 | for (i = 0; i < bufSize / 2; i++) 35 | { 36 | rowData[i] = (CyBtldr_FromHex(buffer[i * 2]) << 4) | CyBtldr_FromHex(buffer[i * 2 + 1]); 37 | } 38 | *rowSize = i; 39 | } 40 | 41 | return err; 42 | } 43 | 44 | int CyBtldr_ReadLine(unsigned int* size, char* buffer) 45 | { 46 | int err = CYRET_SUCCESS; 47 | unsigned int len = 0; 48 | 49 | if (NULL != dataFile && !feof(dataFile)) 50 | { 51 | if (NULL != fgets(buffer, MAX_BUFFER_SIZE, dataFile)) 52 | { 53 | len = strlen(buffer); 54 | 55 | while (len > 0 && ('\n' == buffer[len - 1] || '\r' == buffer[len - 1])) 56 | --len; 57 | } 58 | else 59 | err = CYRET_ERR_EOF; 60 | } 61 | else 62 | err = CYRET_ERR_FILE; 63 | 64 | *size = len; 65 | return err; 66 | } 67 | 68 | int CyBtldr_OpenDataFile(const char* file) 69 | { 70 | dataFile = fopen(file, "r"); 71 | 72 | return (NULL == dataFile) 73 | ? CYRET_ERR_FILE 74 | : CYRET_SUCCESS; 75 | } 76 | 77 | int CyBtldr_ParseHeader(unsigned int bufSize, unsigned char* buffer, unsigned long* siliconId, unsigned char* siliconRev, unsigned char* chksum) 78 | { 79 | const unsigned int LENGTH_ID = 5; //4-silicon id, 1-silicon rev 80 | const unsigned int LENGTH_CHKSUM = LENGTH_ID + 1; //1-checksum type 81 | 82 | unsigned short rowSize; 83 | unsigned char rowData[MAX_BUFFER_SIZE]; 84 | 85 | int err = CyBtldr_FromAscii(bufSize, buffer, &rowSize, rowData); 86 | 87 | if (CYRET_SUCCESS == err) 88 | { 89 | if (rowSize >= LENGTH_CHKSUM) 90 | *chksum = rowData[5]; 91 | if (rowSize >= LENGTH_ID) 92 | { 93 | *siliconId = (rowData[0] << 24) | (rowData[1] << 16) | (rowData[2] << 8) | (rowData[3]); 94 | *siliconRev = rowData[4]; 95 | } 96 | else 97 | err = CYRET_ERR_LENGTH; 98 | } 99 | 100 | return err; 101 | } 102 | 103 | int CyBtldr_ParseRowData(unsigned int bufSize, unsigned char* buffer, unsigned char* arrayId, unsigned short* rowNum, unsigned char* rowData, unsigned short* size, unsigned char* checksum) 104 | { 105 | const unsigned short MIN_SIZE = 6; //1-array, 2-addr, 2-size, 1-checksum 106 | const int DATA_OFFSET = 5; 107 | 108 | unsigned int i; 109 | unsigned short hexSize = 0; 110 | unsigned char hexData[MAX_BUFFER_SIZE]; 111 | int err = CYRET_SUCCESS; 112 | 113 | if (bufSize <= MIN_SIZE) 114 | err = CYRET_ERR_LENGTH; 115 | else if (buffer[0] == ':') 116 | { 117 | err = CyBtldr_FromAscii(bufSize - 1, &buffer[1], &hexSize, hexData); 118 | 119 | *arrayId = hexData[0]; 120 | *rowNum = (hexData[1] << 8) | (hexData[2]); 121 | *size = (hexData[3] << 8) | (hexData[4]); 122 | *checksum = (hexData[hexSize - 1]); 123 | 124 | if ((*size + MIN_SIZE) == hexSize) 125 | { 126 | for (i = 0; i < *size; i++) 127 | { 128 | rowData[i] = (hexData[DATA_OFFSET + i]); 129 | } 130 | } 131 | else 132 | err = CYRET_ERR_DATA; 133 | } 134 | else 135 | err = CYRET_ERR_CMD; 136 | 137 | return err; 138 | } 139 | 140 | int CyBtldr_CloseDataFile(void) 141 | { 142 | int err = 0; 143 | if (NULL != dataFile) 144 | { 145 | err = fclose(dataFile); 146 | dataFile = NULL; 147 | } 148 | return (0 == err) 149 | ? CYRET_SUCCESS 150 | : CYRET_ERR_FILE; 151 | } 152 | -------------------------------------------------------------------------------- /cybtldr_parse.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved. 3 | * You may use this file only in accordance with the license, terms, conditions, 4 | * disclaimers, and limitations in the end user license agreement accompanying 5 | * the software package with which this file was provided. 6 | ********************************************************************************/ 7 | 8 | #ifndef __CYBTLDR_PARSE_H__ 9 | #define __CYBTLDR_PARSE_H__ 10 | 11 | #include "cybtldr_utils.h" 12 | 13 | /* Maximum number of bytes to allocate for a single row. */ 14 | /* NB: Rows should have a max of 592 chars (2-arrayID, 4-rowNum, 4-len, 576-data, 2-checksum, 4-newline) */ 15 | #define MAX_BUFFER_SIZE 768 16 | 17 | /******************************************************************************* 18 | * Function Name: CyBtldr_FromHex 19 | ******************************************************************************** 20 | * Summary: 21 | * Converts the provided ASCII char into its hexadecimal numerical equivilant. 22 | * 23 | * Parameters: 24 | * value - the ASCII char to convert into a number 25 | * 26 | * Returns: 27 | * The hexadecimal numerical equivilant of the provided ASCII char. If the 28 | * provided char is not a valid ASCII char, it will return 0. 29 | * 30 | *******************************************************************************/ 31 | unsigned char CyBtldr_FromHex(char value); 32 | 33 | /******************************************************************************* 34 | * Function Name: CyBtldr_FromAscii 35 | ******************************************************************************** 36 | * Summary: 37 | * Converts the provided ASCII array into its hexadecimal numerical equivilant. 38 | * 39 | * Parameters: 40 | * bufSize - The length of the buffer to convert 41 | * buffer - The buffer of ASCII characters to convert 42 | * rowSize - The number of bytes of equivilant hex data generated 43 | * rowData - The hex data generated for the buffer 44 | * 45 | * Returns: 46 | * CYRET_SUCCESS - The buffer was converted successfully 47 | * CYRET_ERR_LENGTH - The buffer does not have an even number of chars 48 | * 49 | *******************************************************************************/ 50 | int CyBtldr_FromAscii(unsigned int bufSize, unsigned char* buffer, unsigned short* rowSize, unsigned char* rowData); 51 | 52 | /******************************************************************************* 53 | * Function Name: CyBtldr_ReadLine 54 | ******************************************************************************** 55 | * Summary: 56 | * Reads a single line from the open data file. This function will remove 57 | * any Windows, Linux, or Unix line endings from the data. 58 | * 59 | * Parameters: 60 | * size - The number of bytes of data read from the line and stored in buffer 61 | * file - The preallocated buffer, with MAX_BUFFER_SIZE bytes, to store the 62 | * read data in. 63 | * 64 | * Returns: 65 | * CYRET_SUCCESS - The file was opened successfully. 66 | * CYRET_ERR_FILE - An error occurred opening the provided file. 67 | * CYRET_ERR_EOF - The end of the file has been reached 68 | * 69 | *******************************************************************************/ 70 | EXTERN int CyBtldr_ReadLine(unsigned int* size, char* buffer); 71 | 72 | /******************************************************************************* 73 | * Function Name: CyBtldr_OpenDataFile 74 | ******************************************************************************** 75 | * Summary: 76 | * Opens the provided file for reading. Once open, it is expected that the 77 | * first call will be to ParseHeader() to read the first line of data. After 78 | * that, successive calls to ParseRowData() are possible to read each line 79 | * of data, one at a time, from the file. Once all data has been read from 80 | * the file, a call to CloseDataFile() should be made to release resources. 81 | * 82 | * Parameters: 83 | * file - The full canonical path to the *.cyacd file to open 84 | * 85 | * Returns: 86 | * CYRET_SUCCESS - The file was opened successfully. 87 | * CYRET_ERR_FILE - An error occurred opening the provided file. 88 | * 89 | *******************************************************************************/ 90 | EXTERN int CyBtldr_OpenDataFile(const char* file); 91 | 92 | /******************************************************************************* 93 | * Function Name: CyBtldr_ParseHeader 94 | ******************************************************************************** 95 | * Summary: 96 | * Parses the hader information from the *.cyacd file. The header information 97 | * is stored as the first line, so this method should only be called once, 98 | * and only immediatly after calling OpenDataFile and reading the first line. 99 | * 100 | * Parameters: 101 | * bufSize - The number of bytes contained within buffer 102 | * buffer - The buffer containing the header data to parse 103 | * siliconId - The silicon ID that the provided *.cyacd file is for 104 | * siliconRev - The silicon Revision that the provided *.cyacd file is for 105 | * chksum - The type of checksum to use for packet integrety check 106 | * 107 | * Returns: 108 | * CYRET_SUCCESS - The file was opened successfully. 109 | * CYRET_ERR_LENGTH - The line does not contain enough data 110 | * 111 | *******************************************************************************/ 112 | EXTERN int CyBtldr_ParseHeader(unsigned int bufSize, unsigned char* buffer, unsigned long* siliconId, unsigned char* siliconRev, unsigned char* chksum); 113 | 114 | /******************************************************************************* 115 | * Function Name: CyBtldr_ParseRowData 116 | ******************************************************************************** 117 | * Summary: 118 | * Parses the contents of the provided buffer which is expected to contain 119 | * the row data from the *.cyacd file. This is expected to be called multiple 120 | * times. Once for each row of the *.cyacd file, excluding the header row. 121 | * 122 | * Parameters: 123 | * bufSize - The number of bytes contained within buffer 124 | * buffer - The buffer containing the row data to parse 125 | * arrayId - The flash array that the row of data belongs in 126 | * rowNum - The flash row number that the data corresponds to 127 | * rowData - The preallocated buffer to store the flash row data 128 | * size - The number of bytes of rowData 129 | * checksum - The checksum value for the entire row (rowNum, size, rowData) 130 | * 131 | * Returns: 132 | * CYRET_SUCCESS - The file was opened successfully. 133 | * CYRET_ERR_LENGTH - The line does not contain enough data 134 | * CYRET_ERR_DATA - The line does not contain a full row of data 135 | * CYRET_ERR_CMD - The line does not start with the cmd identifier ':' 136 | * 137 | *******************************************************************************/ 138 | EXTERN int CyBtldr_ParseRowData(unsigned int bufSize, unsigned char* buffer, unsigned char* arrayId, unsigned short* rowNum, unsigned char* rowData, unsigned short* size, unsigned char* checksum); 139 | 140 | /******************************************************************************* 141 | * Function Name: CyBtldr_CloseDataFile 142 | ******************************************************************************** 143 | * Summary: 144 | * Closes the data file pointer. 145 | * 146 | * Parameters: 147 | * void. 148 | * 149 | * Returns: 150 | * CYRET_SUCCESS - The file was opened successfully. 151 | * CYRET_ERR_FILE - An error occured opening the provided file. 152 | * 153 | *******************************************************************************/ 154 | EXTERN int CyBtldr_CloseDataFile(void); 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /cybtldr_utils.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gv1/cybootload_linux/5b59bb0702483d8bbf72c84e6136931e076ef9aa/cybtldr_utils.h -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include 2 | // #include "StringImage.h" 3 | #include "communication_api.h" 4 | #include "cybtldr_api.h" 5 | #include "cybtldr_command.h" 6 | #include "cybtldr_parse.h" 7 | #include "cybtldr_utils.h" 8 | #include 9 | #include 10 | #include 11 | 12 | CyBtldr_CommunicationsData comm1 ; 13 | typedef unsigned short uint16; 14 | uint16 BootloadStringImage(const char *bootloadImagePtr[],unsigned int lineCount ); 15 | 16 | char * serial_port = NULL; 17 | int serial_speed = 115200; 18 | 19 | uint16 readCyacd(const char * fn, int * lines, char *** ret) 20 | { 21 | FILE * fin = fopen(fn,"r"); 22 | ssize_t read = 0; 23 | size_t len = 0; 24 | char * line = NULL; 25 | int i=0; 26 | *lines = 0; 27 | if (fn == NULL){ 28 | printf("[ERROR] .cyacd file name is null\n"); 29 | return(CYRET_ERR_FILE); 30 | } 31 | printf("[INFO] Reading cyacd file %s\n",fn); 32 | if ( fin == NULL ) { 33 | printf("[ERROR] opening %s, %s\n",fn,strerror(errno)); 34 | return(CYRET_ERR_FILE) ; 35 | } 36 | while ( !feof(fin) ) { 37 | if(((getline(&line,&len,fin) == -1) && !feof(fin))) { 38 | printf("[ERROR] %s\n",strerror(errno)); 39 | return(CYRET_ERR_FILE); 40 | } 41 | (*lines)++; 42 | } 43 | (*lines)--; 44 | rewind(fin); 45 | *ret = (char **)malloc(sizeof(char*)*(*lines)); 46 | if (*ret == NULL) { 47 | printf("[ERROR] Cannot allocating memory %s\n",strerror(errno)); 48 | return(CYRET_ABORT); 49 | } 50 | i=0; 51 | while ( !feof(fin) ) { 52 | read = getline(&line,&len,fin); 53 | if (( read == -1 ) && !feof(fin)) { 54 | printf("[ERROR] %s\n",strerror(errno)); 55 | return CYRET_ERR_FILE; 56 | } 57 | line[strlen(line)-2]='\0'; // replace newline 58 | (*ret)[i++]=strdup(line); 59 | } 60 | printf("[INFO] Read in %d lines from %s\n",*lines,fn); 61 | return(CYRET_SUCCESS); 62 | } 63 | 64 | // see cybtldr_utils.h 65 | // host error 66 | void error_info_host(uint16 error) 67 | { 68 | switch(error) 69 | { 70 | case CYRET_ERR_FILE: 71 | printf("[ERROR] File is not accessable [0x%X]\n",error); 72 | break; 73 | case CYRET_ERR_EOF: 74 | printf("[ERROR] Reached the end of the file [0x%X]\n",error); 75 | break; 76 | case CYRET_ERR_LENGTH: 77 | printf("[ERROR] The amount of data available is outside the expected range [0x%X]\n",error); 78 | break; 79 | case CYRET_ERR_DATA: 80 | printf("[ERROR] The data is not of the proper form [0x%X]\n",error); 81 | break; 82 | case CYRET_ERR_CMD: 83 | printf("[ERROR] The command is not recognized [0x%X]\n",error); 84 | break; 85 | case CYRET_ERR_DEVICE: 86 | printf("[ERROR] The expected device does not match the detected device [0x%X]\n",error); 87 | break; 88 | case CYRET_ERR_VERSION: 89 | printf("[ERROR] The bootloader version detected is not supported [0x%X]\n",error); 90 | break; 91 | case CYRET_ERR_CHECKSUM: 92 | printf("[ERROR] The checksum does not match the expected value [0x%X]\n",error); 93 | break; 94 | case CYRET_ERR_ARRAY: 95 | printf("[ERROR] The flash array is not valid [0x%X]\n",error); 96 | break; 97 | case CYRET_ERR_ROW: 98 | printf("[ERROR] The flash row is not valid [0x%X]\n",error); 99 | break; 100 | case CYRET_ERR_BTLDR: 101 | printf("[ERROR] The bootloader is not ready to process data [0x%X]\n",error); 102 | break; 103 | case CYRET_ERR_ACTIVE: 104 | printf("[ERROR] The application is currently marked as active [0x%X]\n",error); 105 | break; 106 | case CYRET_ERR_UNK: 107 | printf("[ERROR] The operation was aborted [0x%X]\n",error); 108 | break; 109 | case CYRET_ABORT: 110 | printf("[ERROR] The operation was aborted [0x%X]\n",error); 111 | break; 112 | case CYRET_ERR_COMM_MASK: 113 | printf("[ERROR] The communications object reported an error [0x%X]\n",error); 114 | break; 115 | case CYRET_ERR_BTLDR_MASK: 116 | printf("[ERROR] The bootloader reported an error [0x%X]\n",error); 117 | break; 118 | default: 119 | printf("[ERROR] An unknown error occured [0x%X]\n",error); 120 | break; 121 | } 122 | } 123 | 124 | // bootloader error 125 | void error_info_bootldr(uint16 error) 126 | { 127 | switch(error) 128 | { 129 | case CYBTLDR_STAT_SUCCESS: 130 | printf("[ERROR] Completed successfully [0x%X]\n",error); 131 | break; 132 | case CYBTLDR_STAT_ERR_KEY: 133 | printf("[ERROR] The provided key does not match the expected value [0x%X]\n",error); 134 | break; 135 | case CYBTLDR_STAT_ERR_VERIFY: 136 | printf("[ERROR] The verification of flash failed [0x%X]\n",error); 137 | break; 138 | case CYBTLDR_STAT_ERR_LENGTH: 139 | printf("[ERROR] The amount of data available is outside the expected range [0x%X]\n",error); 140 | break; 141 | case CYBTLDR_STAT_ERR_DATA: 142 | printf("[ERROR] The data is not of the proper form [0x%X]\n",error); 143 | break; 144 | case CYBTLDR_STAT_ERR_CMD: 145 | printf("[ERROR] The command is not recognized [0x%X]\n",error); 146 | break; 147 | case CYBTLDR_STAT_ERR_DEVICE: 148 | printf("[ERROR] The expected device does not match the detected device [0x%X]\n",error); 149 | break; 150 | case CYBTLDR_STAT_ERR_VERSION: 151 | printf("[ERROR] The bootloader version detected is not supported [0x%X]\n",error); 152 | break; 153 | case CYBTLDR_STAT_ERR_CHECKSUM: 154 | printf("[ERROR] The checksum does not match the expected value [0x%X]\n",error); 155 | break; 156 | case CYBTLDR_STAT_ERR_ARRAY: 157 | printf("[ERROR] The flash array is not valid [0x%X]\n",error); 158 | break; 159 | case CYBTLDR_STAT_ERR_ROW: 160 | printf("[ERROR] The flash row is not valid [0x%X]\n",error); 161 | break; 162 | case CYBTLDR_STAT_ERR_PROTECT: 163 | printf("[ERROR] The flash row is protected and can not be programmed [0x%X]\n",error); 164 | break; 165 | case CYBTLDR_STAT_ERR_APP: 166 | printf("[ERROR] The application is not valid and cannot be set as active [0x%X]\n",error); 167 | break; 168 | case CYBTLDR_STAT_ERR_ACTIVE: 169 | printf("[ERROR] The application is currently marked as active [0x%X]\n",error); 170 | break; 171 | case CYBTLDR_STAT_ERR_UNK: 172 | default: 173 | printf("[ERROR] An unknown error occured [0x%X]\n",error); 174 | break; 175 | } 176 | } 177 | int main(int argc, char **argv) 178 | { 179 | uint16 error = 0; 180 | int lines; 181 | char *** stringImage = NULL; 182 | int opt; 183 | while ((opt = getopt(argc, argv, "d:s:")) != -1) { 184 | switch (opt) { 185 | case 'd': 186 | serial_port = optarg; 187 | break; 188 | case 's': 189 | serial_speed = atoi(optarg); 190 | break; 191 | default: /* '?' */ 192 | fprintf(stderr, "[INFO] Usage: %s [-d device] [-s speed] filename\n", 193 | argv[0]); 194 | exit(EXIT_FAILURE); 195 | } 196 | } 197 | 198 | if (optind >= argc) { 199 | fprintf(stderr, "[ERROR] Expected .cyacd filename after options\n"); 200 | exit(EXIT_FAILURE); 201 | } 202 | 203 | printf("[INFO] Starting boot loader operation\n"); 204 | printf("[INFO] Serial Port: %s\n",MODEMDEV); 205 | stringImage = (char ***)malloc(sizeof(char**)); 206 | readCyacd(argv[optind],&lines,stringImage); 207 | #if 0 208 | int i; 209 | for (i=0; i> 8) + rowSize + (rowSize >> 8)); 311 | err = CyBtldr_VerifyRow(arrayId, rowNum, checksum2); 312 | } 313 | } 314 | /* Increment the linCntr */ 315 | lineCntr++; 316 | } 317 | /* End Bootloader Operation */ 318 | CyBtldr_EndBootloadOperation(); 319 | } 320 | return(err); 321 | } 322 | 323 | -------------------------------------------------------------------------------- /run.gdb: -------------------------------------------------------------------------------- 1 | set pagination off 2 | set logging file gdb.log 3 | set logging on 4 | set $i = 0 5 | file cybootload_linux 6 | break main 7 | set args ./CY8CKIT-049-41XX_GPIO_Example.cyacd 8 | break WriteData 9 | # break CyBtldr_StartBootloadOperation 10 | commands 2 11 | set $i=1000 12 | print "commands 2 : %d",$i 13 | end 14 | run 15 | while ( $i < 1000 ) 16 | step 17 | # next 18 | # continue 19 | set $i = $i + 1 20 | # print "loop : %d",$i 21 | end 22 | # print "at %d\n",$i 23 | quit 24 | -------------------------------------------------------------------------------- /test/Bootloadable Blinking LED.cyacd: -------------------------------------------------------------------------------- 1 | 041611931100 2 | :00002100800010002091100000A1120000A112000080B500AF024B83F3088800F005F9C0460010002080B500AF104B104A12688021C9020A431A60032000F076FA0B4B0B4A11680B4A0A401A600A4B0B4A1A600B4B10221A600A4B802212061A60094B0A4A1A600A4B00221A60BD4680BD00010B40FFFFFBFF04010B40060000802002024047 3 | :000022008008010B4000000240B70B00800C020B4080B582B000AF72B6FB1D00221A7023E0FB1D1A78131C5B009B185B00324A9B183B603B681A78597809020A43997809040A43DB781B0613431A1C3B6819795B791B020B439BB2101C191C00F029F9FB1D1A78FB1D01321A70FB1D1B78012BD7D9224A234B101C191C00F02AF9214BC0227D 4 | :000023008092041A60204B00221A60204B00221A601F4B992212041A601E4B802292051A601D4B1E4A1A601E4B1D4A1278D2B202210A43D2B21A701B4B1A4A1278D2B23C218A43D2B214210A43D2B21A70144B144A1278D2B216210A43D2B21A70124B40221A60124BC02252031A60FFF75BFF00F02FF9BD4602B080BD741800008018000090 5 | :00002400808C180000040001400C0001400803044010500F4018500F40200105401000010000700F4001700F40000104400801044010B5064C2378002B07D1054B002B02D0044800E000BF0123237010BDE8000020000000007018000008B5084B002B03D00748084900E000BF07480368002B03D0064B002B00D0984708BDC04600000000ED 6 | :000025008070180000EC000020D00000200000000080B500AF00F02EF900F0A2FAFCE7C04680B500AFFEE7C04680B586B000AF214B7B61214B3B611F4B7B611F4B3B612FE03B691B68FB603B695B68BB603B699B683B6000237B600AE0BB681A1DBA60FA68111DF96012681A607B6804337B607A683B689A42F0D13B69DB683B6000237B60BD 7 | :000026008007E0BB681A1DBA6000221A607B6804337B607A683B689A42F3D13B6910333B617B695A1E7A61002BCAD100F073FAFFF7AFFFFEE701000000F018000080B582B000AF00237B600FE07B68032B04D8134B7A689200D35800E0114B124A796889008B507B6801337B607B682F2BECD9FFF7CFFE0D4B00221A600C4B1B68002B02D18D 8 | :00002700800A4B00221A608023DB058022D205126801210A431A60BD4602B080BD80100000A112000000000020C8000020C000002080B582B000AF786039607A683B68101C00211A1C00F04CFABD4602B080BDC04680B586B000AF7860396000233B6100237B612EE07B699B007A68D3181B68BB603B1C0F33BA681A70BB68FF229343BB6074 9 | :000028008017E03B695B003A68D3181B781A1CBB68D3183A69520039688A1852781A703B6901333B613B1C0F331A783B1C0F33013A1A703B1C0F331B78002BE2D17B6901337B617B69022BCDD9BD4606B080BDC04680B500AFBD4680BD80B500AF144B8422D2041A60124B124A1268802149020A431A600F4B0E4A1268802149000A431A60A4 10 | :00002900800C4BC32292001A60002000F06FF80A4B181C00F04FF8094B181C00F059F8064B181C00F039F8064B1C221A60BD4680BD0001054024010540DC050000EE0200002801054090B583B000AFFC1D00F065F8031C2370064B064A126801210A431A60FB1D1B78181C00F05CF8BD4603B090BD0000054080B500AF064B1B78002B04D1BB 11 | :00002A0080FFF7AAFF034B01221A70FFF7DBFFBD4680BDC0460401002080B582B000AF7860034B7A681204120C1A60BD4602B080BD0801054080B582B000AF7860034B7A681204120C1A60BD4602B080BD1401054080B582B000AF7860034B7A681204120C1A60BD4602B080BD0C01054080B582B000AF7860024B7A681A60BD4602B080BDC4 12 | :00002B008038010540000000000230800804D0C0460138FDD1C046C0467047EFF3108072B6704780F31088704790B587B000AF786030233B617B68022B00D8C7E07B68302B00D9C3E03C1C0B34FFF7E7FF031C23700023FB6011E0604AFB68D3181B781A1C5E4B19683F230B409A4203D1FB6803333B6105E0FB680133FB60FB682D2BEAD9C5 13 | :00002C0080574B1B78DBB21A1C7B689A420AD3554A3B1C173312781A70534A3B1C163312781A703FE0514B1B78DBB21A1C7B689A420AD34F4A3B1C173312781A704D4A3B1C163312781A702DE04B4B1B78DBB21A1C7B689A420AD3494A3B1C173312781A70474A3B1C163312781A701BE0454B1B78DBB21A1C7B689A420AD3434A3B1C173308 14 | :00002D008012781A70414A3B1C163312781A7009E03F4A3B1C173312781A703E4A3B1C163312781A703B692A2B0AD97B682A2B07D92A4B19221A600520FFF766FF18233B617A683B699A421DD9334B7A68314952181278D2B21A60314B3A1C173212781A602F4B3A1C163212781A60052000F064F81A4B7A68033A18498A5C1A600520FFF7F8 15 | :00002E008043FF1CE0154B7A68033A13498A5C1A600520FFF739FF204B7A681E4952181278D2B21A601D4B3A1C173212781A601C4B3A1C163212781A60052000F03DF83B1C0B331B78181CFFF72CFF02E0002000F029F8BD4607B090BD9C1800002CFF0B40C0F1FF0FC1F1FF0FC2F1FF0FC3F1FF0FC4F1FF0FC5F1FF0FC6F1FF0FC7F1FF0FAD 16 | :00002F0080C8F1FF0FC9F1FF0FCAF1FF0FCBF1FF0FCCF1FF0FCDF1FF0F28FF0B401CFF0B4020FF0B4080B582B000AF021CFB1D1A7001BEBD4602B080BD80B582B000AF021CBB1D1A80BB1D1B88044A12785343181CFFF7DAFEBD4602B080BDC046DC00002090B583B000AFFC1DFFF7D7FE031C2370074B074A126804218A431A6030BFFB1DFD 17 | :00003000801B78181CFFF7CDFEBD4603B090BDC04610ED00E070B50E4B0E4D0024ED1AAD101E1CAC4204D0A300F35898470134F8E700F04CF8084B094D0024ED1AAD101E1CAC4204D0A300F35898470134F8E770BDD8180000D8180000D8180000E0180000031C8218934202D019700133FAE770470000000000300F40000400400F400004E2 18 | :000031008001330F4003410F4004430F40E61062048E04D84018808C40C608E608030405060708090A0B0C0E0F101112131415161718191B1C1D1E1F2021222325262728292A2B2E2F3031323334350000F8B5C046F8BC08BC9E467047591200003D130000F8B5C046F8BC08BC9E4670473112000000190000D00000201800000020000000C2 19 | :000032008000000000C0C62D00B80B0000030000000000DC05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F4 20 | :0000FF00800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014911000002000000000090000000000000001000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000A1 21 | -------------------------------------------------------------------------------- /test/CY8CKIT-049-41XX_GPIO_Example.cyacd: -------------------------------------------------------------------------------- 1 | 041611931100 2 | :00001E008000100020110F0000291100002911000080B500AF024B83F3088800F009F9C0460010002080B500AF0D4B0D4A12688021C9020A431A60182000F006FA084B084A1168084A0A401A60074B084A1A60084B802212061A60074B00221A60BD4680BD00010B40FFFFFBFF04010B400600008008010B400C020B4080B582B000AF72B6CB 3 | :00001F0080FB1D00221A7023E0FB1D1A78131C5B009B185B00364A9B183B603B681A78597809020A43997809040A43DB781B0613431A1C3B6819795B791B020B439BB2101C191C00F039F9FB1D1A78FB1D01321A70FB1D1B78012BD7D9264A274B101C191C00F03AF9254BEE2212021A60244B992212041A60234B802212061A60224B99227F 4 | :000020008012041A60214B992212041A60204B204A1278D2B202210A43D2B21A701D4B1D4A1278D2B23C218A43D2B214210A43D2B21A70174B164A1278D2B216210A43D2B21A70154B80221A60144B8022D2031A60134BC02252031A60124BD82212011A60FFF760FF00F038F9BD4602B080BDC046001600000C160000101600000C00014063 5 | :000021008000500F4004500F4010500F4030500F4000700F4001700F400000044008000440080104400803044010B5064C2378002B07D1054B002B02D0044800E000BF0123237010BDE800002000000000FC15000008B5084B002B03D00748084900E000BF07480368002B03D0064B002B00D0984708BDC04600000000FC150000EC00002052 6 | :0000220080D00000200000000080B500AF00F0E8F8031C002B03D0002000F0F0F8F6E7012000F0ECF8F2E7C04680B500AFFEE7C04680B586B000AF214B7B61214B3B611F4B7B611F4B3B612FE03B691B68FB603B695B68BB603B699B683B6000237B600AE0BB681A1DBA60FA68111DF96012681A607B6804337B607A683B689A42F0D13B6926 7 | :0000230080DB683B6000237B6007E0BB681A1DBA6000221A607B6804337B607A683B689A42F3D13B6910333B617B695A1E7A61002BCAD100F0F5F9FFF7A7FFFEE7010000006816000080B582B000AF00237B600FE07B68032B04D8134B7A689200D35800E0114B124A796889008B507B6801337B607B682F2BECD9FFF7BFFE0D4B00221A60AD 8 | :00002400800C4B1B68002B02D10A4B00221A608023DB058022D205126801210A431A60BD4602B080BD000F00002911000000000020C8000020C000002080B582B000AF786039607A683B68101C00211A1C00F0CEF9BD4602B080BDC04680B586B000AF7860396000233B6100237B612EE07B699B007A68D3181B68BB603B1C0F33BA681A704D 9 | :0000250080BB68FF229343BB6017E03B695B003A68D3181B781A1CBB68D3183A69520039688A1852781A703B6901333B613B1C0F331A783B1C0F33013A1A703B1C0F331B78002BE2D17B6901337B617B69002BCDD0BD4606B080BDC04680B500AFBD4680BD80B500AF044B1A6880231340DB09DBB2181CBD4680BDC0460400044080B584B032 10 | :000026008000AF021CFB1D1A700E4B1B68DAB23B1C0F3340218A431A70FB1D1B789B01DAB240231340D9B23B1C0F333A1C0F3212780A431A70034B3A1C0F3212781A60BD4604B080BD0001044090B587B000AF786030233B617B68022B00D8C7E07B68302B00D9C3E03C1C0B3400F013F9031C23700023FB6011E0604AFB68D3181B781A1CBB 11 | :00002700805E4B19683F230B409A4203D1FB6803333B6105E0FB680133FB60FB682D2BEAD9574B1B78DBB21A1C7B689A420AD3554A3B1C173312781A70534A3B1C163312781A703FE0514B1B78DBB21A1C7B689A420AD34F4A3B1C173312781A704D4A3B1C163312781A702DE04B4B1B78DBB21A1C7B689A420AD3494A3B1C173312781A70EC 12 | :0000280080474A3B1C163312781A701BE0454B1B78DBB21A1C7B689A420AD3434A3B1C173312781A70414A3B1C163312781A7009E03F4A3B1C173312781A703E4A3B1C163312781A703B692A2B0AD97B682A2B07D92A4B19221A60052000F092F818233B617A683B699A421DD9334B7A68314952181278D2B21A60314B3A1C173212781A60DB 13 | :00002900802F4B3A1C163212781A60052000F064F81A4B7A68033A18498A5C1A60052000F06FF81CE0154B7A68033A13498A5C1A60052000F065F8204B7A681E4952181278D2B21A601D4B3A1C173212781A601C4B3A1C163212781A60052000F03DF83B1C0B331B78181C00F058F802E0002000F029F8BD4607B090BD141600002CFF0B4006 14 | :00002A0080C0F1FF0FC1F1FF0FC2F1FF0FC3F1FF0FC4F1FF0FC5F1FF0FC6F1FF0FC7F1FF0FC8F1FF0FC9F1FF0FCAF1FF0FCBF1FF0FCCF1FF0FCDF1FF0F28FF0B401CFF0B4020FF0B4080B582B000AF021CFB1D1A7001BEBD4602B080BD80B582B000AF021CBB1D1A80BB1D1B88044A12785343181C00F006F8BD4602B080BDC046DC0000201B 15 | :00002B00800230800804D0C0460138FDD1C046C0467047EFF3108072B6704780F31088704770B50E4B0E4D0024ED1AAD101E1CAC4204D0A300F35898470134F8E700F042F8084B094D0024ED1AAD101E1CAC4204D0A300F35898470134F8E770BD50160000501600005016000058160000031C8218934202D019700133FAE77047000000002C 16 | :00002C008000300F40000400400F40000402600F4002011101030405060708090A0B0C0E0F101112131415161718191B1C1D1E1F2021222325262728292A2B2E2F3031323334350000F8B5C046F8BC08BC9E467047D1100000C5110000F8B5C046F8BC08BC9E467047A910000078160000D000002018000000200000000000000000366E0131 17 | :00002D0080C05D0000180000000000E02E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010 18 | :0000FF008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B9110F00001D0000000008000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082 19 | -------------------------------------------------------------------------------- /test/CY8CKIT-049-41XX_PWM_Example.cyacd: -------------------------------------------------------------------------------- 1 | 041611931100 2 | :00001E008000100020110F0000911100009111000080B500AF024B83F3088800F03DF9C0460010002080B500AF104B104A12688021C9020A431A60182000F0B6FA0B4B0B4A11680B4A0A401A600A4B0B4A1A600B4B10221A600A4B802212061A60094B0A4A1A600A4B00221A60BD4680BD00010B40FFFFFBFF04010B40060000802002024060 3 | :00001F008008010B4000000240010000800C020B4080B582B000AF72B6FB1D00221A7023E0FB1D1A78131C5B009B185B00344A9B183B603B681A78597809020A43997809040A43DB781B0613431A1C3B6819795B791B020B439BB2101C191C00F061F9FB1D1A78FB1D01321A70FB1D1B78012BD7D9244A254B101C191C00F062F9234BC022C9 4 | :000020008092041A60224BEE2212021A60214B992212041A60204B802292051A601F4B992212041A601E4B1E4A1278D2B202210A43D2B21A701B4B1B4A1278D2B23C218A43D2B214210A43D2B21A70154B144A1278D2B216210A43D2B21A70134B40221A60124BC02252031A60114BD82212011A60FFF758FF00F064F9BD4602B080BDC0462C 5 | :00002100808817000094170000A0170000040001400C00014010500F4018500F4030500F4000700F4001700F4000010440080104400803044010B5064C2378002B07D1054B002B02D0044800E000BF0123237010BDE8000020000000008417000008B5084B002B03D00748084900E000BF07480368002B03D0064B002B00D0984708BDC04628 6 | :00002200800000000084170000EC000020D00000200000000080B500AF00F05CF9184B1B889AB2184B9A4202D9174B00221A70144B1B889AB2154B9A4202D8134B01221A70114B1B78DBB2002B08D00D4B1B889BB2F533FF339AB20A4B1A8007E0084B1B889BB2F53BFF3B9AB2054B1A80044B1B889BB2181C00F04EF9192000F09DFACDE771 7 | :000023008004010020F82A0000D4000020E703000080B500AFFEE7C04680B586B000AF214B7B61214B3B611F4B7B611F4B3B612FE03B691B68FB603B695B68BB603B699B683B6000237B600AE0BB681A1DBA60FA68111DF96012681A607B6804337B607A683B689A42F0D13B69DB683B6000237B6007E0BB681A1DBA6000221A607B6804337D 8 | :00002400807B607A683B689A42F3D13B6910333B617B695A1E7A61002BCAD100F085FAFFF779FFFEE7010000000418000080B582B000AF00237B600FE07B68032B04D8134B7A689200D35800E0114B124A796889008B507B6801337B607B682F2BECD9FFF797FE0D4B00221A600C4B1B68002B02D10A4B00221A608023DB058022D205126881 9 | :000025008001210A431A60BD4602B080BD000F00009111000000000020C8000020C000002080B582B000AF786039607A683B68101C00211A1C00F05EFABD4602B080BDC04680B586B000AF7860396000233B6100237B612EE07B699B007A68D3181B68BB603B1C0F33BA681A70BB68FF229343BB6017E03B695B003A68D3181B781A1CBB68EE 10 | :0000260080D3183A69520039688A1852781A703B6901333B613B1C0F331A783B1C0F33013A1A703B1C0F331B78002BE2D17B6901337B617B69022BCDD9BD4606B080BDC04680B500AFBD4680BD80B500AF0F4B8022D2041A600D4B0D4A12681A600B4B0B4A12681A600A4B0C221A60012000F07EF8084B181C00F040F8FA239B00181C00F090 11 | :000027008049F8054B31221A60BD4680BD0001054024010540E02E00002801054090B583B000AFFC1D00F079F8031C2370084B084A126801210A431A60FB1D1B78181C00F070F80120182100F033F8BD4603B090BD0000054080B500AF064B1B78002B04D1FFF7B2FF034B01221A70FFF7D7FFBD4680BDC0460601002080B582B000AF7860AF 12 | :0000280080034B7A681204120C1A60BD4602B080BD1401054080B582B000AF7860034B7A681204120C1A60BD4602B080BD0C01054090B585B000AF786039603C1C0F3400F02CF8031C2370084B3A687968081C9040021C1A603B1C0F331B78181C00F021F8BD4605B090BDC0460800054080B582B000AF7860024B7A681A60BD4602B080BD77 13 | :000029008038010540000000000230800804D0C0460138FDD1C046C0467047EFF3108072B6704780F31088704790B587B000AF786030233B617B68022B00D8C7E07B68302B00D9C3E03C1C0B34FFF7E7FF031C23700023FB6011E0604AFB68D3181B781A1C5E4B19683F230B409A4203D1FB6803333B6105E0FB680133FB60FB682D2BEAD9C7 14 | :00002A0080574B1B78DBB21A1C7B689A420AD3554A3B1C173312781A70534A3B1C163312781A703FE0514B1B78DBB21A1C7B689A420AD34F4A3B1C173312781A704D4A3B1C163312781A702DE04B4B1B78DBB21A1C7B689A420AD3494A3B1C173312781A70474A3B1C163312781A701BE0454B1B78DBB21A1C7B689A420AD3434A3B1C17330A 15 | :00002B008012781A70414A3B1C163312781A7009E03F4A3B1C173312781A703E4A3B1C163312781A703B692A2B0AD97B682A2B07D92A4B19221A600520FFF766FF18233B617A683B699A421DD9334B7A68314952181278D2B21A60314B3A1C173212781A602F4B3A1C163212781A60052000F088F81A4B7A68033A18498A5C1A600520FFF7D6 16 | :00002C008043FF1CE0154B7A68033A13498A5C1A600520FFF739FF204B7A681E4952181278D2B21A601D4B3A1C173212781A601C4B3A1C163212781A60052000F061F83B1C0B331B78181CFFF72CFF02E0002000F029F8BD4607B090BDB01700002CFF0B40C0F1FF0FC1F1FF0FC2F1FF0FC3F1FF0FC4F1FF0FC5F1FF0FC6F1FF0FC7F1FF0F78 17 | :00002D0080C8F1FF0FC9F1FF0FCAF1FF0FCBF1FF0FCCF1FF0FCDF1FF0F28FF0B401CFF0B4020FF0B4080B582B000AF021CFB1D1A7001BEBD4602B080BD80B582B000AF786008E00C4B1B68181CFFF7DEFE7B680A4A9B187B607A6880231B029A42F1D8074B1B687A685343181CFFF7CEFEBD4602B080BDC046E40000200080FFFFDC00002056 18 | :00002E008080B582B000AF021CBB1D1A80BB1D1B88044A12785343181CFFF7B6FEBD4602B080BDC046E000002070B50E4B0E4D0024ED1AAD101E1CAC4204D0A300F35898470134F8E700F04CF8084B094D0024ED1AAD101E1CAC4204D0A300F35898470134F8E770BDEC170000EC170000EC170000F4170000031C8218934202D0197001334F 19 | :00002F0080FAE770470000000000300F40000400400F40000401330F4003410F4004430F40E61062048E04D84018808C40C608E608030405060708090A0B0C0E0F101112131415161718191B1C1D1E1F2021222325262728292A2B2E2F3031323334350000F8B5C046F8BC08BC9E467047DD1000002D120000F8B5C046F8BC08BC9E46704729 20 | :0000300080B510000018180000D0000020180000002000000000000000000000000100000000366E01C05D0000180000000000E02E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004A 21 | :0000FF0080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002C110F00001D000000800900000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008E 22 | -------------------------------------------------------------------------------- /test/CY8CKIT-049-41XX_UART_Example.cyacd: -------------------------------------------------------------------------------- 1 | 041611931100 2 | :00001E008000100020110F0000451200004512000080B500AF024B83F3088800F097F9C0460010002080B584B000AF021CFB1D1A70224A3B1C0B3312781A70214A3B1C0A3312781A701F4B1B68013BFB601AE01E4B1868391C0B31FA68131C5B009B18C31801331B780B70184B1868391C0A31FA68131C5B009B18C31802331B780B70FB6830 3 | :00001F0080013BFB60FB68002B0ADB0F4B1968FA68131C5B009B185B5CFA1D12789A42D6D90A4B3A1C0B3212781A60094B3A1C0A3212781A60BD4604B080BDC046CCF1FF0FCDF1FF0FAC160000D40000201CFF0B4020FF0B4080B500AF164B164A12688021C9020A431A601820FFF79CFF124B19221A60052000F0E4FA104B114A1278D2B229 4 | :00002000801A60052000F0ECFA0A4B0A4A11680D4A0A401A600C4B10221A600C4B802212061A600B4B802212061A600A4B0A4A1A60BD4680BD00010B402CFF0B4028FF0B40E5F1FF0FFFFFFBFF0802024008010B4004010B40000002401000008080B582B000AF72B6FB1D00221A7023E0FB1D1A78131C5B009B185B00324A9B183B603B68AD 5 | :00002100801A78597809020A43997809040A43DB781B0613431A1C3B6819795B791B020B439BB2101C191C00F05DF9FB1DFA1D127801321A70FB1D1B78012BD7D9224A234B101C191C00F05EF9214BEE2212021A60204B99221A60204B80221A601F4B8022D2031A601E4BD82212011A601D4B02221A601D4B31221A601C4B02221A601C4B2F 6 | :0000220080992212041A601B4B802212061A601A4B992212041A60194B184A1278D2B202210A43D2B21A70154B144A1278D2B206210A43D2B21A70FFF74DFF00F063F9BD4602B080BD98160000A4160000A81600000C0001401000014000000440080004400803044000040440080404401804044000500F4004500F4030500F4000700F403E 7 | :000023008010B5064C2378002B07D10548002802D0044800E000BF0121217010BDE8000020000000008416000008B5084B002B03D00748084900E000BF07480168002903D0064A002A00D0904708BDC0460000000084160000EC000020D00000200000000080B582B000AF00F027F9C04600F00CFA031C002BFAD1FB1D00221A700BE0FB1DD3 8 | :00002400801B780F4AD35C181C00F04CF9FB1DFA1D127801321A70FB1D1B780D2BEFD900E0C04600F0A9F9021CBB1D1A70BB1D1B78002BF5D0BB1D1B78181C00F033F9EFE78816000080B500AFFEE7C04680B586B000AF254B7B61254B3B61234B7B61234B3B6132E03B691B68FB603B695B68BB603B699B683B6000237B600CE0FB681A6879 9 | :0000250080BB681A60BB680433BB60FB680433FB607B6804337B607A683B689A42EED13B69DB683B6000237B6008E0BB6800221A60BB680433BB607B6804337B607A683B689A42F2D13B6910333B617B695A1E9341DBB27A69013A7A61002BC3D100F0A2F9FFF77EFFFEE7C04601000000D416000080B582B000AF00237B600FE07B68032BAA 10 | :000026008004D8134B7A689200D35800E0114B124A796889008B507B6801337B607B682F2BECD9FFF79BFE0D4B00221A600C4B1B68002B02D10A4B00221A608023DB058022D205126801210A431A60BD4602B080BD000F00004512000000000020C8000020C000002080B582B000AF786039607A683B68101C00211A1C00F07AF9BD4602B01E 11 | :000027008080BDC04680B586B000AF7860396000233B6100237B612EE07B699B007A68D3181B68BB603B1C0F33BA681A70BB68FF229343BB6017E03B695B003A68D3181B781A1CBB68D3183A69520039688A1852781A703B6901333B613B1C0F333A1C0F321278013A1A703B1C0F331B78002BE2D17B6901337B617B69002BCDD0BD4606B01F 12 | :000028008080BDC04680B500AFBD4680BD80B500AF00F05EF8BD4680BD80B500AF054B054A1268802109060A431A6000F017F8BD4680BDC0460000064080B500AF064B1B78002B04D1FFF7E2FF034B01221A70FFF7E3FFBD4680BDC0460401002080B500AFBD4680BD80B582B000AF00237B60044B1B687B607B68181CBD4602B080BDC046B7 13 | :00002900804003064080B582B000AF054B1A680F2313407B607B68181CBD4602B080BDC0460803064080B582B000AF7860C046064B1A680F231340082BF9D0044B7A681A60BD4602B080BDC046080206404002064080B500AF174B184A1A60184B00221A60174B01221A60174B174A1A60174B07221A60174B00221A60164B01221A60164BA4 14 | :00002A0080114A1A60154B00221A60154B00221A60144B00221A60144B00221A60134B00221A60134B00221A60124B00221A60BD4680BDC046000006400B000002400006404800064000030640070000800403064010030640440006400002064004020640880E0640C80E0640480F0640080F0640C80F0640880F064080B582B000AF002340 15 | :00002B00807B60FFF77FFF031C002B03D0FFF76AFF031C7B60084B1A68D8239B00134005D000237B60044BD82292001A607B68181CBD4602B080BDC046C00F0640000000000230800804D0C0460138FDD1C046C0467047EFF3108072B6704780F31088704780B582B000AF021CBB1D1A80BB1D1B88044A12785343181CFFF7E2FFBD4602B0C6 16 | :00002C008080BDC046E000002080B500AF044B1A6880231340DB09DBB2181CBD4680BDC0460400044070B50E4B0E4D0024E81A85101E1CAC4204D0A100725890470134F8E700F036F80849094A0E1C541AA5100024AC4204D0A300F05880470134F8E770BDBC160000BC160000BC160000C416000000B58218031C934202D019700133FAE762 17 | :00002D008000BD00000000000048656C6C6F20576F726C64210A0D000000300F40000400400F40000402600F400201110104000000F8B5C046F8BC08BC9E467047A9110000F1120000F8B5C046F8BC08BC9E46704781110000E8160000D000002018000000280000000000000000000000C0F1FF0F00366E01C05D0000180000000000E02EB2 18 | :0000FF00800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000073110F00001D00000000080000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C8 19 | --------------------------------------------------------------------------------