Maxim Integrated / Mbed OS MAXREFDES220#

Dependencies:   USBDevice max32630fthr

Committer:
Shaun Kelsey
Date:
Thu May 24 14:40:48 2018 -0700
Revision:
5:795cffb6f01a
Parent:
0:da5f5b56060a
Bootloader feature additions

New configuration options for bootloader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Shaun Kelsey 0:da5f5b56060a 1 /*******************************************************************************
Shaun Kelsey 0:da5f5b56060a 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
Shaun Kelsey 0:da5f5b56060a 3 *
Shaun Kelsey 0:da5f5b56060a 4 * Permission is hereby granted, free of charge, to any person obtaining a
Shaun Kelsey 0:da5f5b56060a 5 * copy of this software and associated documentation files (the "Software"),
Shaun Kelsey 0:da5f5b56060a 6 * to deal in the Software without restriction, including without limitation
Shaun Kelsey 0:da5f5b56060a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Shaun Kelsey 0:da5f5b56060a 8 * and/or sell copies of the Software, and to permit persons to whom the
Shaun Kelsey 0:da5f5b56060a 9 * Software is furnished to do so, subject to the following conditions:
Shaun Kelsey 0:da5f5b56060a 10 *
Shaun Kelsey 0:da5f5b56060a 11 * The above copyright notice and this permission notice shall be included
Shaun Kelsey 0:da5f5b56060a 12 * in all copies or substantial portions of the Software.
Shaun Kelsey 0:da5f5b56060a 13 *
Shaun Kelsey 0:da5f5b56060a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Shaun Kelsey 0:da5f5b56060a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Shaun Kelsey 0:da5f5b56060a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Shaun Kelsey 0:da5f5b56060a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Shaun Kelsey 0:da5f5b56060a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Shaun Kelsey 0:da5f5b56060a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Shaun Kelsey 0:da5f5b56060a 20 * OTHER DEALINGS IN THE SOFTWARE.
Shaun Kelsey 0:da5f5b56060a 21 *
Shaun Kelsey 0:da5f5b56060a 22 * Except as contained in this notice, the name of Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 24 * Products, Inc. Branding Policy.
Shaun Kelsey 0:da5f5b56060a 25 *
Shaun Kelsey 0:da5f5b56060a 26 * The mere transfer of this software does not imply any licenses
Shaun Kelsey 0:da5f5b56060a 27 * of trade secrets, proprietary technology, copyrights, patents,
Shaun Kelsey 0:da5f5b56060a 28 * trademarks, maskwork rights, or any other form of intellectual
Shaun Kelsey 0:da5f5b56060a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Shaun Kelsey 0:da5f5b56060a 30 * ownership rights.
Shaun Kelsey 0:da5f5b56060a 31 *******************************************************************************
Shaun Kelsey 0:da5f5b56060a 32 */
Shaun Kelsey 0:da5f5b56060a 33
Shaun Kelsey 0:da5f5b56060a 34 #ifndef _SSBOOTLOADERCOMM_H_
Shaun Kelsey 0:da5f5b56060a 35 #define _SSBOOTLOADERCOMM_H_
Shaun Kelsey 0:da5f5b56060a 36
Shaun Kelsey 0:da5f5b56060a 37 #include "mbed.h"
Shaun Kelsey 0:da5f5b56060a 38 #include "SensorComm.h"
Shaun Kelsey 0:da5f5b56060a 39 #include "USBSerial.h"
Shaun Kelsey 0:da5f5b56060a 40 #include "SSInterface.h"
Shaun Kelsey 0:da5f5b56060a 41
Shaun Kelsey 0:da5f5b56060a 42 #define SS_BOOTLOADER_ERASE_DELAY 2000
Shaun Kelsey 0:da5f5b56060a 43
Shaun Kelsey 0:da5f5b56060a 44 /**
Shaun Kelsey 0:da5f5b56060a 45 * @brief SSBootloaderComm Command handler class for bootloader routines on SmartSensor
Shaun Kelsey 0:da5f5b56060a 46 * @details
Shaun Kelsey 0:da5f5b56060a 47 */
Shaun Kelsey 0:da5f5b56060a 48 class SSBootloaderComm: public SensorComm
Shaun Kelsey 0:da5f5b56060a 49 {
Shaun Kelsey 0:da5f5b56060a 50 public:
Shaun Kelsey 0:da5f5b56060a 51
Shaun Kelsey 0:da5f5b56060a 52 /* PUBLIC FUNCTION DECLARATIONS */
Shaun Kelsey 0:da5f5b56060a 53 /**
Shaun Kelsey 0:da5f5b56060a 54 * @brief SSBootloaderComm constructor.
Shaun Kelsey 0:da5f5b56060a 55 *
Shaun Kelsey 0:da5f5b56060a 56 */
Shaun Kelsey 0:da5f5b56060a 57 SSBootloaderComm(USBSerial* USB, SSInterface* ssInterface, DSInterface* dsInterface);
Shaun Kelsey 0:da5f5b56060a 58
Shaun Kelsey 0:da5f5b56060a 59 /**
Shaun Kelsey 0:da5f5b56060a 60 * @brief Parses DeviceStudio-style commands.
Shaun Kelsey 0:da5f5b56060a 61 * @details Parses and executes commands. Prints return code to i/o device.
Shaun Kelsey 0:da5f5b56060a 62 * @returns true if sensor acted upon the command, false if command was unknown
Shaun Kelsey 0:da5f5b56060a 63 */
Shaun Kelsey 0:da5f5b56060a 64 bool parse_command(const char* cmd);
Shaun Kelsey 0:da5f5b56060a 65
Shaun Kelsey 0:da5f5b56060a 66 private:
Shaun Kelsey 0:da5f5b56060a 67
Shaun Kelsey 0:da5f5b56060a 68 /* PRIVATE METHODS */
Shaun Kelsey 0:da5f5b56060a 69 int parse_auth(const char* cmd, uint8_t *auth_bytes);
Shaun Kelsey 0:da5f5b56060a 70 int parse_iv(const char* cmd, uint8_t* iv_bytes);
Shaun Kelsey 0:da5f5b56060a 71 void flash_page_data(void);
Shaun Kelsey 0:da5f5b56060a 72
Shaun Kelsey 0:da5f5b56060a 73 /* PRIVATE TYPE DEFINITIONS */
Shaun Kelsey 0:da5f5b56060a 74 typedef enum _cmd_state_t {
Shaun Kelsey 0:da5f5b56060a 75 cmd_enter_bootldr=0,
Shaun Kelsey 0:da5f5b56060a 76 cmd_exit_bootldr,
Shaun Kelsey 0:da5f5b56060a 77 cmd_reset,
Shaun Kelsey 0:da5f5b56060a 78 cmd_page_size,
Shaun Kelsey 0:da5f5b56060a 79 cmd_num_pages,
Shaun Kelsey 0:da5f5b56060a 80 cmd_set_iv,
Shaun Kelsey 0:da5f5b56060a 81 cmd_set_auth,
Shaun Kelsey 0:da5f5b56060a 82 cmd_erase,
Shaun Kelsey 5:795cffb6f01a 83 cmd_page_erase,
Shaun Kelsey 0:da5f5b56060a 84 cmd_flash,
Shaun Kelsey 5:795cffb6f01a 85 cmd_setcfg_bl_enter_mode,
Shaun Kelsey 5:795cffb6f01a 86 cmd_setcfg_bl_ebl_pin,
Shaun Kelsey 5:795cffb6f01a 87 cmd_setcfg_bl_ebl_pol,
Shaun Kelsey 5:795cffb6f01a 88 cmd_setcfg_bl_exit_mode,
Shaun Kelsey 5:795cffb6f01a 89 cmd_setcfg_bl_timeout,
Shaun Kelsey 5:795cffb6f01a 90 cmd_setcfg_bl_save,
Shaun Kelsey 0:da5f5b56060a 91 NUM_CMDS,
Shaun Kelsey 0:da5f5b56060a 92 } cmd_state_t;
Shaun Kelsey 0:da5f5b56060a 93
Shaun Kelsey 0:da5f5b56060a 94 /* PRIVATE VARIABLES */
Shaun Kelsey 0:da5f5b56060a 95 USBSerial *m_USB;
Shaun Kelsey 0:da5f5b56060a 96 SSInterface *ss_int;
Shaun Kelsey 0:da5f5b56060a 97 DSInterface *ds_int;
Shaun Kelsey 0:da5f5b56060a 98
Shaun Kelsey 0:da5f5b56060a 99 char bootldr_version[128];
Shaun Kelsey 0:da5f5b56060a 100
Shaun Kelsey 0:da5f5b56060a 101 int num_pages;
Shaun Kelsey 0:da5f5b56060a 102 int page_size;
Shaun Kelsey 0:da5f5b56060a 103
Shaun Kelsey 0:da5f5b56060a 104 bool got_page_size;
Shaun Kelsey 0:da5f5b56060a 105 bool sent_num_pages;
Shaun Kelsey 0:da5f5b56060a 106
Shaun Kelsey 0:da5f5b56060a 107 /* PRIVATE CONST VARIABLES */
Shaun Kelsey 0:da5f5b56060a 108 static const int AES_NONCE_SIZE = 11;
Shaun Kelsey 0:da5f5b56060a 109 static const int AES_AUTH_SIZE = 16;
Shaun Kelsey 0:da5f5b56060a 110 static const int MAX_PAGE_SIZE = 8192;
Shaun Kelsey 0:da5f5b56060a 111 static const int CHECKBYTES_SIZE = 16;
Shaun Kelsey 0:da5f5b56060a 112
Shaun Kelsey 0:da5f5b56060a 113 };
Shaun Kelsey 0:da5f5b56060a 114
Shaun Kelsey 0:da5f5b56060a 115 #endif /* _SSBOOTLOADERCOMM_H_ */