summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cc3200/bootmgr/flc.h7
-rw-r--r--cc3200/ftp/ftp.c30
-rw-r--r--cc3200/ftp/updater.c70
-rw-r--r--cc3200/ftp/updater.h26
4 files changed, 102 insertions, 31 deletions
diff --git a/cc3200/bootmgr/flc.h b/cc3200/bootmgr/flc.h
index 869c4cd49f..7415d1ef61 100644
--- a/cc3200/bootmgr/flc.h
+++ b/cc3200/bootmgr/flc.h
@@ -48,12 +48,17 @@ extern "C"
#define IMG_SRVPACK "/sys/servicepack.ucf"
#define SRVPACK_SIGN "/sys/servicepack.sig"
+#define CA_FILE "/cert/ca.pem"
+#define CERT_FILE "/cert/cert.pem"
+#define KEY_FILE "/cert/private.key"
+
/******************************************************************************
- Image file sizes
+ Special file sizes
*******************************************************************************/
#define IMG_SIZE (232 * 1024) /* 16KB are reserved for the bootloader and at least 8KB for the heap*/
#define SRVPACK_SIZE (16 * 1024)
#define SIGN_SIZE (2 * 1024)
+#define CA_KEY_SIZE (4 * 1024)
/******************************************************************************
Active Image
diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c
index 889b4191e5..be7fc8364c 100644
--- a/cc3200/ftp/ftp.c
+++ b/cc3200/ftp/ftp.c
@@ -137,17 +137,16 @@ typedef struct {
uint8_t e_open;
bool closechild;
bool enabled;
- bool swupdating;
-
+ bool special_file;
} ftp_data_t;
typedef struct {
char * cmd;
-}ftp_cmd_t;
+} ftp_cmd_t;
typedef struct {
char * month;
-}ftp_month_t;
+} ftp_month_t;
typedef enum {
E_FTP_CMD_NOT_SUPPORTED = -1,
@@ -174,7 +173,7 @@ typedef enum {
E_FTP_CMD_NOOP,
E_FTP_CMD_QUIT,
E_FTP_NUM_FTP_CMDS
-}ftp_cmd_index_t;
+} ftp_cmd_index_t;
/******************************************************************************
DECLARE PRIVATE DATA
@@ -243,7 +242,7 @@ void ftp_init (void) {
ftp_data.e_open = E_FTP_NOTHING_OPEN;
ftp_data.state = E_FTP_STE_DISABLED;
ftp_data.substate.data = E_FTP_STE_SUB_DISCONNECTED;
- ftp_data.swupdating = false;
+ ftp_data.special_file = false;
}
void ftp_run (void) {
@@ -325,7 +324,7 @@ void ftp_run (void) {
ftp_data.dtimeout = 0;
ftp_data.ctimeout = 0;
// its a software update
- if (ftp_data.swupdating) {
+ if (ftp_data.special_file) {
if (updater_write(ftp_data.dBuffer, len)) {
break;
}
@@ -345,8 +344,8 @@ void ftp_run (void) {
}
}
else {
- if (ftp_data.swupdating) {
- ftp_data.swupdating = false;
+ if (ftp_data.special_file) {
+ ftp_data.special_file = false;
updater_finnish();
}
ftp_close_files();
@@ -578,8 +577,8 @@ static void ftp_send_from_fifo (void) {
// close the listening and the data sockets
servers_close_socket(&ftp_data.ld_sd);
servers_close_socket(&ftp_data.d_sd);
- if (ftp_data.swupdating) {
- ftp_data.swupdating = false;
+ if (ftp_data.special_file) {
+ ftp_data.special_file = false;
}
}
}
@@ -759,11 +758,8 @@ static void ftp_process_cmd (void) {
ftp_get_param_and_open_child (&bufptr);
// first check if a software update is being requested
if (updater_check_path (ftp_path)) {
- // start by erasing the previous status file
- // must be done before starting the updater
- f_unlink(ftp_path);
if (updater_start()) {
- ftp_data.swupdating = true;
+ ftp_data.special_file = true;
ftp_data.state = E_FTP_STE_CONTINUE_FILE_RX;
ftp_send_reply(150, NULL);
}
@@ -861,9 +857,9 @@ static void ftp_close_files (void) {
static void ftp_close_filesystem_on_error (void) {
ftp_close_files();
- if (ftp_data.swupdating) {
+ if (ftp_data.special_file) {
updater_finnish ();
- ftp_data.swupdating = false;
+ ftp_data.special_file = false;
}
}
diff --git a/cc3200/ftp/updater.c b/cc3200/ftp/updater.c
index 4c215d68aa..974b2f72d7 100644
--- a/cc3200/ftp/updater.c
+++ b/cc3200/ftp/updater.c
@@ -1,3 +1,29 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Daniel Campora
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include <stdint.h>
#include <stdbool.h>
@@ -18,6 +44,9 @@
#define UPDATER_IMG_PATH "/flash/sys/mcuimg.bin"
#define UPDATER_SRVPACK_PATH "/flash/sys/servicepack.ucf"
#define UPDATER_SIGN_PATH "/flash/sys/servicepack.sig"
+#define UPDATER_CA_PATH "/flash/cert/ca.pem"
+#define UPDATER_CERT_PATH "/flash/cert/cert.pem"
+#define UPDATER_KEY_PATH "/flash/cert/private.key"
/******************************************************************************
DEFINE TYPES
@@ -41,24 +70,32 @@ bool updater_check_path (void *path) {
if (!strcmp(UPDATER_IMG_PATH, path)) {
updater_data.path = IMG_UPDATE;
updater_data.fsize = IMG_SIZE;
- return true;
- }
- else if (!strcmp(UPDATER_SRVPACK_PATH, path)) {
+ } else if (!strcmp(UPDATER_SRVPACK_PATH, path)) {
updater_data.path = IMG_SRVPACK;
updater_data.fsize = SRVPACK_SIZE;
- return true;
- }
- else if (!strcmp(UPDATER_SIGN_PATH, path)) {
+ } else if (!strcmp(UPDATER_SIGN_PATH, path)) {
updater_data.path = SRVPACK_SIGN;
updater_data.fsize = SIGN_SIZE;
- return true;
+ } else if (!strcmp(UPDATER_CA_PATH, path)) {
+ updater_data.path = CA_FILE;
+ updater_data.fsize = CA_KEY_SIZE;
+ } else if (!strcmp(UPDATER_CERT_PATH, path)) {
+ updater_data.path = CERT_FILE;
+ updater_data.fsize = CA_KEY_SIZE;
+ } else if (!strcmp(UPDATER_KEY_PATH, path)) {
+ updater_data.path = KEY_FILE;
+ updater_data.fsize = CA_KEY_SIZE;
+ } else {
+ return false;
}
- return false;
+ return true;
}
bool updater_start (void) {
_u32 AccessModeAndMaxSize = FS_MODE_OPEN_WRITE;
SlFsFileInfo_t FsFileInfo;
+ bool result = false;
+
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
if (0 != sl_FsGetInfo((_u8 *)updater_data.path, 0, &FsFileInfo)) {
// file doesn't exist, create it
@@ -66,18 +103,24 @@ bool updater_start (void) {
}
if (!sl_FsOpen((_u8 *)updater_data.path, AccessModeAndMaxSize, NULL, &updater_data.fhandle)) {
updater_data.foffset = 0;
- return true;
+ result = true;
}
sl_LockObjUnlock (&wlan_LockObj);
- return false;
+
+ return result;
}
bool updater_write (uint8_t *buf, uint32_t len) {
+ bool result = false;
+
+ sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
if (len == sl_FsWrite(updater_data.fhandle, updater_data.foffset, buf, len)) {
updater_data.foffset += len;
- return true;
+ result = true;
}
- return false;
+ sl_LockObjUnlock (&wlan_LockObj);
+
+ return result;
}
void updater_finnish (void) {
@@ -85,6 +128,7 @@ void updater_finnish (void) {
_i32 fhandle;
if (updater_data.fhandle > 0) {
+ sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
// close the file being updated
sl_FsClose(updater_data.fhandle, NULL, NULL, 0);
@@ -108,7 +152,7 @@ void updater_finnish (void) {
ASSERT (sizeof(sBootInfo_t) == sl_FsWrite(fhandle, 0, (unsigned char *)&sBootInfo, sizeof(sBootInfo_t)));
sl_FsClose(fhandle, 0, 0, 0);
}
+ sl_LockObjUnlock (&wlan_LockObj);
}
updater_data.fhandle = -1;
- sl_LockObjUnlock (&wlan_LockObj);
}
diff --git a/cc3200/ftp/updater.h b/cc3200/ftp/updater.h
index 3f1e791766..518d76c4c7 100644
--- a/cc3200/ftp/updater.h
+++ b/cc3200/ftp/updater.h
@@ -1,3 +1,29 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Daniel Campora
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef UPDATER_H_
#define UPDATER_H_