From 9c91a87cb36acfef0c6b9b18f76703569706599f Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:56:04 +0900 Subject: [PATCH 01/21] Remove unused file --- externals/LibTarget.mk | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 externals/LibTarget.mk diff --git a/externals/LibTarget.mk b/externals/LibTarget.mk deleted file mode 100644 index cba16a475..000000000 --- a/externals/LibTarget.mk +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# externals/LibTarget.mk -# -# Copyright 2018 Sony Semiconductor Solutions Corporation -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name of Sony Semiconductor Solutions Corporation nor -# the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -EXTERNAL_DIR := $(SDKDIR)$(DELIM)..$(DELIM)externals - -include $(wildcard $(EXTERNAL_DIR)/*/LibTarget.mk) From 0c86ec7623687309366cf29b578d4276da03c64d Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 25 Jun 2020 13:00:56 +0900 Subject: [PATCH 02/21] Use new API to be able to set tristate --- sdk/system/pmic/pmic_main.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sdk/system/pmic/pmic_main.c b/sdk/system/pmic/pmic_main.c index 15f9c76d6..90c05bedd 100644 --- a/sdk/system/pmic/pmic_main.c +++ b/sdk/system/pmic/pmic_main.c @@ -103,6 +103,7 @@ static void show_usage(FAR const char *progname) printf(" -l: Show power status of the target\n"); printf(" -e : Enable power to the target\n"); printf(" -d : Disable power to the target\n"); + printf(" -z : Set GPO to HiZ to the target\n"); printf(" -r : Single read from \n"); printf(" -w -v : Single write to \n"); printf(" -h: Show this message\n"); @@ -125,7 +126,7 @@ int pmic_main(int argc, char *argv[]) int ret; int i; int opt; - bool en; + int en; int id; uint8_t addr = 0; uint8_t value = 0; @@ -135,7 +136,7 @@ int pmic_main(int argc, char *argv[]) int txval = 0; optind = -1; - while ((opt = getopt(argc, argv, "le:d:r:w:v:h")) != -1) + while ((opt = getopt(argc, argv, "le:d:z:r:w:v:h")) != -1) { switch (opt) { @@ -143,17 +144,22 @@ int pmic_main(int argc, char *argv[]) list = 1; break; case 'e': - en = true; + en = 1; goto skip; case 'd': - en = false; + en = 0; + goto skip; + case 'z': + en = -1; skip: list = 1; id = getid(optarg); if (id) { - printf("%s: %s\n", (en) ? "Enable ": "Disable", optarg); - board_power_control(id, en); + printf("%s: %s\n", + (en > 0) ? "Enable" : (en == 0) ? "Disable" : "HiZ", + optarg); + board_power_control_tristate(id, en); } else { @@ -229,8 +235,9 @@ int pmic_main(int argc, char *argv[]) printf("%16s : %s\n", "-----------", "------"); for (i = 0; i < sizeof(g_list) / sizeof(g_list[0]); i++) { - en = board_power_monitor(g_list[i].target); - printf("%16s : %s\n", g_list[i].str, (en) ? "on" : "off"); + en = board_power_monitor_tristate(g_list[i].target); + printf("%16s : %s\n", g_list[i].str, + (en > 0) ? "on" : (en == 0) ? "off" : "hiz"); } } return 0; From ac53bb24eaa891545c82e904b7239900815e738a Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 2 Jul 2020 10:39:25 +0900 Subject: [PATCH 03/21] Fix FarAPI to nxstyle --- sdk/modules/fwuputils/manager/fwup_manager.c | 16 ++++++++-------- sdk/modules/fwuputils/manager/sys_update_mgr.h | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sdk/modules/fwuputils/manager/fwup_manager.c b/sdk/modules/fwuputils/manager/fwup_manager.c index b82ba5a6f..8ad6e56e4 100644 --- a/sdk/modules/fwuputils/manager/fwup_manager.c +++ b/sdk/modules/fwuputils/manager/fwup_manager.c @@ -91,7 +91,7 @@ static int fwup_init(void) { int ret = 0; - ret = UM_Init(false); + ret = fw_um_init(false); return ret; } @@ -142,7 +142,7 @@ static int fwup_open(enum fw_type_e fwtype, uint32_t fwsize) return ret; } - mgr->handle = UM_Open(keyfile, fwsize, type); + mgr->handle = fw_um_open(keyfile, fwsize, type); mgr->remain = fwsize; return ret; @@ -153,7 +153,7 @@ static int fwup_write(void *data, uint32_t size) int ret = 0; struct fwup_mgr_s *mgr = get_manager(); - ret = UM_Commit(mgr->handle, data, size); + ret = fw_um_commit(mgr->handle, data, size); mgr->remain -= size; @@ -165,7 +165,7 @@ static int fwup_close(void) int ret = 0; struct fwup_mgr_s *mgr = get_manager(); - ret = UM_Close(mgr->handle); + ret = fw_um_close(mgr->handle); mgr->remain = 0; return ret; @@ -211,7 +211,7 @@ static int fwup_update(void) { int ret = 0; - ret = UM_DoUpdateSequence(); + ret = fw_um_doupdatesequence(); return ret; } @@ -220,7 +220,7 @@ static int fwup_suspend(void) { int ret = 0; - ret = UM_CheckPoint(); + ret = fw_um_checkpoint(); return ret; } @@ -229,14 +229,14 @@ static int fwup_resume(void) { int ret = 0; - ret = UM_Init(true); + ret = fw_um_init(true); return ret; } static int fwup_abort(void) { - //UM_Abort(); + //fw_um_abort(); return 0; } diff --git a/sdk/modules/fwuputils/manager/sys_update_mgr.h b/sdk/modules/fwuputils/manager/sys_update_mgr.h index 5213508ee..b8585a588 100644 --- a/sdk/modules/fwuputils/manager/sys_update_mgr.h +++ b/sdk/modules/fwuputils/manager/sys_update_mgr.h @@ -70,7 +70,7 @@ typedef void * UM_Handle; /** * Initialize Update Manager * - * @param[in] need_recovery: true to need recovery from check point. see UM_CheckPoint(). + * @param[in] need_recovery: true to need recovery from check point. see fw_um_checkpoint(). * * @return 0 on success, otherwise error * @retval -ENOMEM: memory allocation failure @@ -83,7 +83,7 @@ typedef void * UM_Handle; * @par Reentrant * No */ -int UM_Init(bool need_recovery); +int fw_um_init(bool need_recovery); /** * Create update manager object for scheduling firmware will be update. @@ -101,7 +101,7 @@ int UM_Init(bool need_recovery); * @par Reentrant * Yes */ -UM_Handle UM_Open(const char *keyfile, uint32_t filesize, uint32_t type); +UM_Handle fw_um_open(const char *keyfile, uint32_t filesize, uint32_t type); /** * Commit firmware data. @@ -123,7 +123,7 @@ UM_Handle UM_Open(const char *keyfile, uint32_t filesize, uint32_t type); * @par Reentrant * Yes */ -int UM_Commit(UM_Handle handle, const void *data, uint32_t size); +int fw_um_commit(UM_Handle handle, const void *data, uint32_t size); /** * Close and delete update manager object. @@ -146,13 +146,13 @@ int UM_Commit(UM_Handle handle, const void *data, uint32_t size); * @par Reentrant * Yes */ -int UM_Close(UM_Handle handle); +int fw_um_close(UM_Handle handle); /** * Create recovery check point. * * User can use this feature to stop downloading (also shutdown). - * Pass true to need_recovery on UM_Init() to restart downloading, + * Pass true to need_recovery on fw_um_init() to restart downloading, * all of closed objects are scheduled again until this check point. * * Check point is always overwritten. @@ -167,7 +167,7 @@ int UM_Close(UM_Handle handle); * @par Reentrant * Yes */ -int UM_CheckPoint(void); +int fw_um_checkpoint(void); /** * Reboot and into update sequence. @@ -178,7 +178,7 @@ int UM_CheckPoint(void); * @attention This API force reboot immediately. User make sure to ready to * shutting down. All of updating firmwares are must be closed. */ -int UM_DoUpdateSequence(void); +int fw_um_doupdatesequence(void); /** * Abort update manager @@ -188,7 +188,7 @@ int UM_DoUpdateSequence(void); * User can be use this API to pause/resume or restart download sequence without * heap dirty. */ -void UM_Abort(void); +void fw_um_abort(void); /** @} */ From c0a5bd6ae10faae0e23c61eaa547178ef90aff86 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Fri, 26 Jun 2020 18:17:54 +0900 Subject: [PATCH 04/21] Add EULA check in config.py --- sdk/tools/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/tools/config.py b/sdk/tools/config.py index d89677bb7..beb14957f 100755 --- a/sdk/tools/config.py +++ b/sdk/tools/config.py @@ -42,6 +42,8 @@ import shutil import re +import eula + MODE_MENUCONFIG = "menuconfig" MODE_QCONFIG = "qconfig" MODE_GCONFIG = "gconfig" @@ -413,6 +415,9 @@ def prepare_config(topdir, sdkdir): dest.saveas(os.path.join(topdir, '.config')) + # Check loader version + eula.EULAhander().check() + ret = do_olddefconfig() if ret != 0: sys.exit(ret) From 881e6c6bb65a321ac01b4c84c80c83cd37b4c921 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 30 Jun 2020 20:30:45 +0900 Subject: [PATCH 05/21] Change module name for check bootloader version --- sdk/tools/{eula.py => bootloader.py} | 137 +++++++++++---------------- sdk/tools/config.py | 9 +- sdk/tools/flash.sh | 4 +- 3 files changed, 60 insertions(+), 90 deletions(-) rename sdk/tools/{eula.py => bootloader.py} (60%) diff --git a/sdk/tools/eula.py b/sdk/tools/bootloader.py similarity index 60% rename from sdk/tools/eula.py rename to sdk/tools/bootloader.py index 414ab46e1..098ac2c68 100755 --- a/sdk/tools/eula.py +++ b/sdk/tools/bootloader.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 # -*- coding:utf-8 -*- ############################################################################ -# tools/eula.py +# tools/bootloader.py # -# Copyright 2018 Sony Semiconductor Solutions Corporation +# Copyright 2018,2020 Sony Semiconductor Solutions Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -35,9 +35,9 @@ # ############################################################################ -# eula.py: +# bootloader.py: # This tool is for checking and update firmware binaries that needed to take EULA. -# Usage: eula.py [-h] [-c] [-i spresense-binaries.zip] +# Usage: bootloader.py [-h] [-c] [-i spresense-binaries.zip] import argparse import json @@ -49,10 +49,7 @@ SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) # Firmware(loader.espk, gnssfw.espk) path -FIRMWARE_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..", "firmware")) - -# SDK .config file path -CONFIG_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..", "nuttx", ".config")) +FIRMWARE_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..", "firmware", "spresense")) # Json file name for describe required version VERSION_JSON = "version.json" @@ -61,93 +58,65 @@ STORED_VERSION_JSON = "stored_version.json" -# Name : EULAhander -# Description: For check and extract EULA binaries -class EULAhander: +# Name : BootloaderVersion +# Description: For bootloader check version and extract archive +class BootloaderVersion: # Name : __init__ # Description: Initialize def __init__(self): - self.firmware_path = os.path.join(FIRMWARE_PATH, self.getBoardName()) - self.download_url = "" - self.loader_version = "" - self.loadVersion() - - # Name : loadConfiguration - # Description: Load SDK build configuration to dictionary - # Return : Configuratin dictonary - def loadConfiguration(self): - ret = {} - - # File open - file = open(CONFIG_PATH) - read = file.read() - file.close() - lines = read.split("\n") - for line in lines: - # Put configuration to dictionary - if "=" in line: - splt = line.split("=") - left = splt[0] - right = re.sub("\"", "", splt[1]) - ret[left] = right - return ret + pass + + # Get version json file from file path + def getVersionJson(self, filename): + version_file = open(filename) + version_json = json.load(version_file) + version_file.close() + return version_json + + # Get bootloader download URL from version.json path + def getDownloadURL(self, filename): + if os.path.isfile(filename): + return self.getVersionJson(filename)["DownloadURL"]; + else: + return None + + # Get bootloader version from json file path + def getLoaderVersion(self, filename): + if os.path.isfile(filename): + return self.getVersionJson(filename)["LoaderVersion"]; + else: + return None - # Name : getBoardName - # Description: Get board name from SDK build configuration - # Return : Board name - def getBoardName(self): - return self.loadConfiguration()["CONFIG_ARCH_BOARD"] - - # Name : loadVersion - # Description: Load required version and download URL from version.json - def loadVersion(self): - version_file_name = os.path.join(self.firmware_path, VERSION_JSON) - if os.path.isfile(version_file_name): - version_file = open(version_file_name) - version_json = json.load(version_file) - version_file.close() - version = version_json["LoaderVersion"] - self.loader_version = version - self.download_url = version_json["DownloadURL"] - - def getDownloadURL(self): - return self.download_url - - def getLoaderVersion(self): - return self.loader_version + # Check update necessity + def isNeedToUpdate(self): + ret = False + requre_version = self.getLoaderVersion(os.path.join(FIRMWARE_PATH, VERSION_JSON)) + current_version = self.getLoaderVersion(os.path.join(FIRMWARE_PATH, STORED_VERSION_JSON)) + + if requre_version != None: + if requre_version != current_version: + ret = True + return ret # Name : check # Description: Check version for update and print warning. - def check(self): - is_need_to_update = False - current_file_name = os.path.join(self.firmware_path, STORED_VERSION_JSON) - - if self.loader_version != "": - if os.path.isfile(current_file_name): - current_file = open(current_file_name) - current_json = json.load(current_file) - current_file.close() - current_version = current_json["LoaderVersion"] - if self.loader_version != current_version: - is_need_to_update = True - else: - is_need_to_update = True - - if is_need_to_update: - version = self.getLoaderVersion() - url = self.getDownloadURL() + def checkBootloaderVersion(self): + if self.isNeedToUpdate(): + version = self.getLoaderVersion(os.path.join(FIRMWARE_PATH, VERSION_JSON)) + url = self.getDownloadURL(os.path.join(FIRMWARE_PATH, VERSION_JSON)) print("WARNING: New loader %s is required, please download and install." % version) print(" Download URL : %s" % url) print(" Install command:") print(" 1. Extract loader archive into host PC.") print(" ./tools/flash.sh -e ") print(" 2. Flash loader into Board.") - print(" ./tools/flash.sh -l %s -c " % self.firmware_path) + print(" ./tools/flash.sh -l %s -c " % FIRMWARE_PATH) # Name : update # Description: Update EULA binaries from zip archive - def update(self, file_path): + def updateBootloaderBinary(self, file_path): + requre_version = self.getLoaderVersion(os.path.join(FIRMWARE_PATH, VERSION_JSON)) # Check file is zip archive or not if file_path.endswith(".zip"): # Open zip archive @@ -159,12 +128,12 @@ def update(self, file_path): update_line = binzip.read(STORED_VERSION_JSON).decode('utf-8') update_json = json.loads(update_line) update_version = update_json["LoaderVersion"] - if update_version == self.loader_version: + if update_version == requre_version: # If same with target version, do u pdate - binzip.extractall(self.firmware_path) + binzip.extractall(FIRMWARE_PATH) print("Update succeed.") else: - print("Error: Please use correct loader version (Selected: %s, Required: %s)." % (update_version, self.loader_version)) + print("Error: Please use correct loader version (Selected: %s, Required: %s)." % (update_version, requre_version)) else: print("ERROR: Please select correct zip file") else: @@ -177,11 +146,11 @@ def update(self, file_path): parser.add_argument('-i', '--input', metavar='spresense-binaries.zip', type=str, help='Loader update zip file') args = parser.parse_args() - eula_handler = EULAhander() + bootloader_version = BootloaderVersion() if args.check: # for '-c' - eula_handler.check() + bootloader_version.checkBootloaderVersion() else: # for '-i' - eula_handler.update(args.input) + bootloader_version.updateBootloaderBinary(args.input) diff --git a/sdk/tools/config.py b/sdk/tools/config.py index beb14957f..cd3e55ccc 100755 --- a/sdk/tools/config.py +++ b/sdk/tools/config.py @@ -42,7 +42,7 @@ import shutil import re -import eula +import bootloader MODE_MENUCONFIG = "menuconfig" MODE_QCONFIG = "qconfig" @@ -415,9 +415,6 @@ def prepare_config(topdir, sdkdir): dest.saveas(os.path.join(topdir, '.config')) - # Check loader version - eula.EULAhander().check() - ret = do_olddefconfig() if ret != 0: sys.exit(ret) @@ -430,3 +427,7 @@ def prepare_config(topdir, sdkdir): if menumode == None and len(opts.configname) == 0: parser.print_usage() sys.exit(9) + + # Since every developer use this script, to notice a necessity of bootloader update, + # check the saved bootloader version and if necessary, show warning message. + bootloader.BootloaderVersion().checkBootloaderVersion() diff --git a/sdk/tools/flash.sh b/sdk/tools/flash.sh index 79b1cc014..46f217057 100755 --- a/sdk/tools/flash.sh +++ b/sdk/tools/flash.sh @@ -103,12 +103,12 @@ done shift $(($OPTIND - 1)) if [ "${UPDATE_ZIP}" != "" ]; then - ${SCRIPT_DIR}/eula.py -i ${UPDATE_ZIP} + ${SCRIPT_DIR}/bootloader.py -i ${UPDATE_ZIP} exit fi # Check loader version -${SCRIPT_DIR}/eula.py -c +${SCRIPT_DIR}/bootloader.py -c if [ "${FLASH_MODE}" == "SPK" ]; then # Pickup spk and espk files From a67030e32eef42dc6a34a6e0a87ca6e80dbe0b15 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 1 Sep 2020 12:39:13 +0900 Subject: [PATCH 06/21] kconfig: apply changes --- sdk/tools/gentmpkconfig.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/tools/gentmpkconfig.py b/sdk/tools/gentmpkconfig.py index e0eec09d1..de869415a 100755 --- a/sdk/tools/gentmpkconfig.py +++ b/sdk/tools/gentmpkconfig.py @@ -60,9 +60,7 @@ # Add kconfigs from user application if 'SPRESENSE_HOME' in os.environ: - myapp_root = os.environ['SPRESENSE_HOME'] - if os.path.isdir(myapp_root): - kconfigs = kconfigs + glob.glob(os.path.join(myapp_root, "Kconfig")) + kconfigs = kconfigs + glob.glob(os.path.join(os.environ['SPRESENSE_HOME'], "Kconfig")) for c in kconfigs: dn = os.path.dirname(c).split('/')[-1] From 2abf4702179d44fdcd0ecceebfeed1babc4a732d Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:08:21 +0900 Subject: [PATCH 07/21] Fix bug in the LTE daemon termination process Change to use pipe for termination request. --- sdk/modules/lte/net/daemon/daemon.c | 180 ++++++++++++++++------------ 1 file changed, 103 insertions(+), 77 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index fe58248ee..f3a375a29 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -117,6 +117,7 @@ #endif #define SELECT_ASYNC_RETRY_MAX 1 +#define DAEMON_TASK_STACKSIZE 4096 /**************************************************************************** * Private Data Types @@ -144,9 +145,6 @@ struct daemon_s { int selectid; int event_outfd; - int event_infd; - int apireq_outfd; - int apireq_infd; int session_id; sem_t sync_sem; int pid; @@ -2808,13 +2806,13 @@ static int main_loop(FAR struct daemon_s *priv) daemon_debug_printf("open event pipe event_infd: %d\n", fd[1]); - fd[2] = g_daemon->apireq_infd; + fd[2] = open(APIREQ_PIPE, O_RDONLY); + ASSERT(fd[2] >= 0); ret = altcom_initialize(); ASSERT(ret >= 0); close(priv->event_outfd); - close(priv->apireq_outfd); /* Open fifo for retry event */ @@ -2921,11 +2919,10 @@ static int main_loop(FAR struct daemon_s *priv) { close(fd[i]); } - close(priv->apireq_infd); close(retry_fd); + remove(EVENT_PIPE); remove(EVENT_PIPE2); - sem_destroy(&priv->sync_sem); netdev_unregister(&priv->net_dev); daemon_debug_printf("daemon finished.\n"); @@ -2957,9 +2954,9 @@ int lte_daemon(int argc, FAR char *argv[]) int32_t lte_daemon_init(lte_apn_setting_t *apn) { int ret; - int local_errno; + int apireq_fd; - if (false == g_daemonisrunnning) + if (!g_daemonisrunnning) { g_daemon = calloc(sizeof(struct daemon_s), 1); if (!g_daemon) @@ -2975,76 +2972,62 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) memcpy(&g_daemon->apn, apn, sizeof(lte_apn_setting_t)); } + /* Create a pipe to communicate with the daemon */ + ret = mkfifo(APIREQ_PIPE, 0666); - if (0 > ret) + if (ret < 0) { - local_errno = errno; + ret = -errno; free(g_daemon); g_daemon = NULL; - daemon_error_printf("mkfifo failed = %d\n", errno); - return -local_errno; - } - g_daemon->apireq_outfd = open(APIREQ_PIPE, (O_WRONLY | O_CREAT)); - if (0 > g_daemon->apireq_outfd) - { - local_errno = errno; - remove(APIREQ_PIPE); - free(g_daemon); - g_daemon = NULL; - daemon_error_printf("pipe open failed = %d\n", errno); - return -local_errno; + daemon_error_printf("mkfifo(%s) failed = %d\n", APIREQ_PIPE, -ret); + return ret; } - g_daemon->apireq_infd = open(APIREQ_PIPE, (O_RDONLY | O_CREAT)); - if (0 > g_daemon->apireq_infd) + /* Open a pipe to communicate with the daemon */ + + apireq_fd = open(APIREQ_PIPE, O_WRONLY); + if (apireq_fd < 0) { - local_errno = errno; - close(g_daemon->apireq_outfd); + ret = -errno; remove(APIREQ_PIPE); free(g_daemon); g_daemon = NULL; - daemon_error_printf("pipe open failed = %d\n", errno); - return -local_errno; - } - daemon_debug_printf("open apireq pipe apireq_outfd: %d\n", - g_daemon->apireq_outfd); - daemon_debug_printf("open apireq pipe apireq_infd: %d\n", - g_daemon->apireq_infd); + daemon_error_printf("pipe open failed = %d\n", -ret); + return ret; + } ret = sem_init(&g_daemon->sync_sem, 0, 0); - if (0 > ret) - { - local_errno = errno; - close(g_daemon->apireq_outfd); - close(g_daemon->apireq_infd); - remove(APIREQ_PIPE); - free(g_daemon); - g_daemon = NULL; - daemon_error_printf("semaphore init fail %d\n", errno); - return -local_errno; - } + ASSERT(ret >= 0); g_daemonisrunnning = true; - g_daemon->pid = task_create("lte_daemon", CONFIG_LTE_DAEMON_TASK_PRIORITY, - 4096, lte_daemon, NULL); - if (0 > g_daemon->pid) + g_daemon->pid = task_create("lte_daemon", + CONFIG_LTE_DAEMON_TASK_PRIORITY, + DAEMON_TASK_STACKSIZE, lte_daemon, NULL); + if (g_daemon->pid < 0) { - local_errno = errno; - close(g_daemon->apireq_outfd); - close(g_daemon->apireq_infd); + ret = -errno; + close(apireq_fd); remove(APIREQ_PIPE); g_daemonisrunnning = false; sem_destroy(&g_daemon->sync_sem); free(g_daemon); g_daemon = NULL; - return -local_errno; + + daemon_error_printf("lte_daemon create task failed = %d\n", -ret); + return ret; } + + /* Wait for the daemon task to run */ + sem_wait(&g_daemon->sync_sem); + close(apireq_fd); } else { + daemon_error_printf("lte_daemon is running\n"); return -EALREADY; } @@ -3058,25 +3041,46 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) int32_t lte_daemon_power_on(void) { int ret; + int apireq_fd; int daemon_cmd_id = DAEMONAPI_REQUEST_POWER_ON; if (g_daemonisrunnning) { - ret = write(g_daemon->apireq_outfd, &daemon_cmd_id, - sizeof(daemon_cmd_id)); - if (0 > ret) + /* Open a pipe to communicate with the daemon */ + + apireq_fd = open(APIREQ_PIPE, O_WRONLY); + if (apireq_fd < 0) { - daemon_error_printf("%s write failed: %d\n", __func__, errno); - return -errno; + ret = -errno; + + daemon_error_printf("pipe open failed = %d\n", -ret); + return ret; + } + + /* Write request to poweron */ + + ret = write(apireq_fd, &daemon_cmd_id, sizeof(daemon_cmd_id)); + if (ret < 0) + { + ret = -errno; + close(apireq_fd); + + daemon_error_printf("write() failed: %d\n", -ret); + return ret; } + + /* Wait for the request to complete. */ + sem_wait(&g_daemon->sync_sem); ret = g_altcomresult; - daemon_debug_printf("lte_daemon_power_on() = %d\n", ret); + close(apireq_fd); + + daemon_debug_printf("lte_daemon_power_on() = %d\n", ret); } else { daemon_error_printf("lte_daemon is not running\n"); - ret = -EOPNOTSUPP; + return -ENETDOWN; } return ret; @@ -3095,13 +3099,14 @@ int32_t lte_daemon_set_cb(restart_report_cb_t restart_callback) return -EINVAL; } - if (g_daemon == NULL) + if (g_daemonisrunnning) { - return -EOPNOTSUPP; + g_daemon->user_restart_cb = restart_callback; } - else if (g_daemon->pid != -1) + else { - g_daemon->user_restart_cb = restart_callback; + daemon_error_printf("lte_daemon is not running\n"); + return -ENETDOWN; } return 0; @@ -3115,33 +3120,54 @@ int32_t lte_daemon_fin(void) { int ret; int rc; + int apireq_fd; + int daemon_cmd_id = DAEMONAPI_REQUEST_FIN; if (g_daemonisrunnning) { - g_daemonisrunnning = false; - ret = socket(AF_INET, SOCK_STREAM, 0); - if (ret >= 0) + /* Open a pipe to communicate with the daemon */ + + apireq_fd = open(APIREQ_PIPE, O_WRONLY); + if (apireq_fd < 0) { - close(ret); + ret = -errno; + + daemon_error_printf("open(%s) failed: %d\n", APIREQ_PIPE, -ret); + return ret; + } + + /* Write request to terminate the daemon */ + + ret = write(apireq_fd, &daemon_cmd_id, sizeof(daemon_cmd_id)); + if (ret < 0) + { + ret = -errno; + close(apireq_fd); + + daemon_error_printf("write() failed: %d\n", -ret); + return ret; } + /* Wait for the daemon task to terminate */ + ret = waitpid(g_daemon->pid, &rc, 0); if (0 > ret) { - if (errno != ECHILD) + ret = -errno; + + if (ret != -ECHILD) { - daemon_error_printf("%s waitpid failed: %d\n", __func__, - -errno); - return -errno; + close(apireq_fd); + + daemon_error_printf("waitpid failed: %d\n", -ret); + return ret; } - ret = 0; } - close(g_daemon->apireq_infd); - close(g_daemon->apireq_outfd); - remove(EVENT_PIPE); + close(apireq_fd); remove(APIREQ_PIPE); g_daemon->pid = -1; + sem_destroy(&g_daemon->sync_sem); if (g_daemon) { @@ -3152,8 +3178,8 @@ int32_t lte_daemon_fin(void) } else { - ret = -EALREADY; - daemon_error_printf("lte_daemon_fin() failed = %d\n", ret); + daemon_error_printf("lte_daemon is running\n"); + return -EALREADY; } return ret; From 0bfbad5fc379080fe09ba0457060856a602ba014 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 24 Jun 2020 17:45:04 +0900 Subject: [PATCH 08/21] Fix bug that lte_daemon_power_on() doesn't return Fix bug that lte_daemon_power_on() doesn't return when already powered on. --- sdk/modules/lte/net/daemon/daemon.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index f3a375a29..184df853f 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -146,6 +146,7 @@ struct daemon_s int selectid; int event_outfd; int session_id; + int poweron_result; sem_t sync_sem; int pid; lte_apn_setting_t apn; @@ -283,7 +284,6 @@ static const struct usrsock_req_handler_s struct daemon_s *g_daemon = NULL; static bool g_daemonisrunnning = false; -static int g_altcomresult; /**************************************************************************** * Private Functions @@ -2699,8 +2699,12 @@ static int daemon_api_request(int read_fd, struct daemon_s* priv) switch (daemon_api_cmd) { case DAEMONAPI_REQUEST_POWER_ON: - ret = altcom_power_on(); - g_altcomresult = ret; + priv->poweron_result = altcom_power_on(); + if (priv->poweron_result < 0) + { + sem_post(&g_daemon->sync_sem); + } + break; case DAEMONAPI_REQUEST_POWER_OFF: ret = altcom_power_off(); @@ -3072,9 +3076,10 @@ int32_t lte_daemon_power_on(void) /* Wait for the request to complete. */ sem_wait(&g_daemon->sync_sem); - ret = g_altcomresult; close(apireq_fd); + ret = g_daemon->poweron_result; + daemon_debug_printf("lte_daemon_power_on() = %d\n", ret); } else From 31c1165f8fb12f535c934917487f5fe9e5eeb574 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 7 Jul 2020 21:44:51 +0900 Subject: [PATCH 09/21] Add safety guard when the tile heap is empty When the size of tile heap is dynamically determined by linker, the size may be zero. Fix more safety to manage the tile heap area in such cases. --- sdk/modules/asmp/mm_tile/mm_tilealloc.c | 7 ++++++- sdk/modules/asmp/mm_tile/mm_tilefree.c | 7 +++++++ sdk/modules/asmp/mm_tile/mm_tileinit.c | 8 +++++++- sdk/modules/asmp/mm_tile/mm_tilerelease.c | 7 +++++-- sdk/modules/asmp/supervisor/mpshm.c | 12 +++++------- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/sdk/modules/asmp/mm_tile/mm_tilealloc.c b/sdk/modules/asmp/mm_tile/mm_tilealloc.c index e2cceac54..33e8b5c3f 100644 --- a/sdk/modules/asmp/mm_tile/mm_tilealloc.c +++ b/sdk/modules/asmp/mm_tile/mm_tilealloc.c @@ -79,7 +79,12 @@ static FAR void *tile_common_alloc(FAR struct tile_s *priv, size_t size, unsigned int ntiles; unsigned int step; - DEBUGASSERT(priv); + if (!priv) + { + /* If the tile heap structure is none, memory cannot be allocated */ + + return NULL; + } if (size == 0) { diff --git a/sdk/modules/asmp/mm_tile/mm_tilefree.c b/sdk/modules/asmp/mm_tile/mm_tilefree.c index ae70c0ef4..4a37d6134 100644 --- a/sdk/modules/asmp/mm_tile/mm_tilefree.c +++ b/sdk/modules/asmp/mm_tile/mm_tilefree.c @@ -133,6 +133,13 @@ void tile_free(FAR void *memory, size_t size) FAR struct tile_s *priv = g_tileinfo; size_t tsize; + if (!priv) + { + /* If the tile heap structure is none, do nothing */ + + return; + } + tile_common_free(priv, memory, size); /* Power off free tiles */ diff --git a/sdk/modules/asmp/mm_tile/mm_tileinit.c b/sdk/modules/asmp/mm_tile/mm_tileinit.c index 3b8d3fb33..22a737d74 100644 --- a/sdk/modules/asmp/mm_tile/mm_tileinit.c +++ b/sdk/modules/asmp/mm_tile/mm_tileinit.c @@ -94,7 +94,7 @@ tile_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2tile) * than or equal to the alignment size. */ - DEBUGASSERT(heapstart && heapsize > 0 && + DEBUGASSERT(heapstart && heapsize >= 0 && log2tile > 0 && log2tile < 32); if (log2tile != 16 && log2tile != 17) @@ -103,6 +103,12 @@ tile_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2tile) return NULL; } + if (heapsize == 0) + { + terr("Tile heap area is empty.\n"); + return NULL; + } + /* Allocate exact size of the structure, tile allocator supports less than * or equal to 32 tiles for now. */ diff --git a/sdk/modules/asmp/mm_tile/mm_tilerelease.c b/sdk/modules/asmp/mm_tile/mm_tilerelease.c index 0fc543f6c..7fa67cb40 100644 --- a/sdk/modules/asmp/mm_tile/mm_tilerelease.c +++ b/sdk/modules/asmp/mm_tile/mm_tilerelease.c @@ -104,8 +104,11 @@ static inline void tile_release_common(FAR struct tile_s *priv) void tile_release(void) { - tile_release_common(g_tileinfo); - g_tileinfo = NULL; + if (g_tileinfo) + { + tile_release_common(g_tileinfo); + g_tileinfo = NULL; + } } #endif /* CONFIG_MM_TILE */ diff --git a/sdk/modules/asmp/supervisor/mpshm.c b/sdk/modules/asmp/supervisor/mpshm.c index d4a868720..e9a45af77 100644 --- a/sdk/modules/asmp/supervisor/mpshm.c +++ b/sdk/modules/asmp/supervisor/mpshm.c @@ -534,13 +534,11 @@ void mpshm_initialize(void) ASSERT((MM_TILE_BASE & 0x1ffff) == 0); - if (MM_TILE_SIZE > 0) { - ret = tile_initialize((void *)MM_TILE_BASE, MM_TILE_SIZE, MPSHM_TILE_ALIGN); - if (ret < 0) - { - mperr("Tile memory initialization failure.\n"); - } - } + ret = tile_initialize((void *)MM_TILE_BASE, MM_TILE_SIZE, MPSHM_TILE_ALIGN); + if (ret < 0) + { + mperr("Tile memory initialization failure.\n"); + } /* Clear virtual address mapping except first 64KB block. * Because first virtual address is necessary for wake up from hot sleep. From 61bb457733ce34ca1ccb7cce44b8c137ce8e11bf Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 8 Jul 2020 11:07:17 +0900 Subject: [PATCH 10/21] Fix license description for bt_a2dp_snk and bt_hfp_hf --- examples/bluetooth_a2dp_snk/Make.defs | 9 +++++---- examples/bluetooth_hfp_hf/Make.defs | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/bluetooth_a2dp_snk/Make.defs b/examples/bluetooth_a2dp_snk/Make.defs index 2a4166730..8945aea37 100644 --- a/examples/bluetooth_a2dp_snk/Make.defs +++ b/examples/bluetooth_a2dp_snk/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # bluetooth_a2dp_snk/Make.defs # -# Copyright (C) 2019 Sony Corporation. All rights reserved. +# Copyright 2018 Sony Semiconductor Solutions Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -13,9 +13,10 @@ # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. -# 3. Neither the name NuttX nor Sony nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# 3. Neither the name of Sony Semiconductor Solutions Corporation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT diff --git a/examples/bluetooth_hfp_hf/Make.defs b/examples/bluetooth_hfp_hf/Make.defs index 52bff6a02..f958f9994 100644 --- a/examples/bluetooth_hfp_hf/Make.defs +++ b/examples/bluetooth_hfp_hf/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # bluetooth_hfp_hf/Make.defs # -# Copyright (C) 2018 Sony Corporation. All rights reserved. +# Copyright 2018 Sony Semiconductor Solutions Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -13,9 +13,10 @@ # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. -# 3. Neither the name NuttX nor Sony nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# 3. Neither the name of Sony Semiconductor Solutions Corporation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT From d9754deacfb8e294368cca7ce70db4cabc77ef50 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Fri, 17 Jul 2020 10:44:59 +0900 Subject: [PATCH 11/21] Fix typo of device/proximity defconfig --- sdk/configs/device/proximity/README.txt | 1 + sdk/configs/device/{proxymity => proximity}/defconfig | 0 sdk/configs/device/proxymity/README.txt | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 sdk/configs/device/proximity/README.txt rename sdk/configs/device/{proxymity => proximity}/defconfig (100%) delete mode 100644 sdk/configs/device/proxymity/README.txt diff --git a/sdk/configs/device/proximity/README.txt b/sdk/configs/device/proximity/README.txt new file mode 100644 index 000000000..d600b1a5c --- /dev/null +++ b/sdk/configs/device/proximity/README.txt @@ -0,0 +1 @@ +This configuration contains required options to use proximity sensor device. diff --git a/sdk/configs/device/proxymity/defconfig b/sdk/configs/device/proximity/defconfig similarity index 100% rename from sdk/configs/device/proxymity/defconfig rename to sdk/configs/device/proximity/defconfig diff --git a/sdk/configs/device/proxymity/README.txt b/sdk/configs/device/proxymity/README.txt deleted file mode 100644 index 23b10c4a4..000000000 --- a/sdk/configs/device/proxymity/README.txt +++ /dev/null @@ -1 +0,0 @@ -This configuration contains required options to use proxymity sensor device. From c369a4129bc923416c071288a7447530979a3e5b Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Fri, 17 Jul 2020 11:54:51 +0900 Subject: [PATCH 12/21] Fix config explanation of proximity example --- examples/proximity/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/proximity/README.txt b/examples/proximity/README.txt index d3010494b..f504a4bfe 100644 --- a/examples/proximity/README.txt +++ b/examples/proximity/README.txt @@ -35,7 +35,7 @@ examples/proximity Example Configuration: - CONFIG_EXAMPLES_PROXIMITY - Enable magnetometer sensor example + CONFIG_EXAMPLES_PROXIMITY - Enable proximity sensor example CONFIG_EXAMPLES_PROXIMITY_PROGNAME - Program name. CONFIG_EXAMPLES_PROXIMITY_PRIORITY - Example priority. Default: 100 CONFIG_EXAMPLES_PROXIMITY_STACKSIZE - Example stack size. Default: 2048 From 0437d1d5a1f8ac88a2c3db0df2a084eebf0aac0c Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Mon, 6 Jul 2020 15:14:57 +0900 Subject: [PATCH 13/21] Fix bug that ASSERT when perform "lte_daemon start" The waitpid() executed by the "lte_daemon stop" command always fails. Therefore, the command finishes without the daemon terminated completely. "lte_daemon start" may start multiple daemons at the same time. (because the daemon has not terminated completely.) ASSERT occurs in the newly started daemon. --- sdk/modules/lte/net/daemon/daemon.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index 184df853f..091b54327 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -148,7 +148,6 @@ struct daemon_s int session_id; int poweron_result; sem_t sync_sem; - int pid; lte_apn_setting_t apn; struct usock_s sockets[SOCKET_COUNT]; struct net_driver_s net_dev; @@ -2929,6 +2928,7 @@ static int main_loop(FAR struct daemon_s *priv) remove(EVENT_PIPE2); netdev_unregister(&priv->net_dev); + sem_post(&g_daemon->sync_sem); daemon_debug_printf("daemon finished.\n"); return ret; @@ -2958,6 +2958,7 @@ int lte_daemon(int argc, FAR char *argv[]) int32_t lte_daemon_init(lte_apn_setting_t *apn) { int ret; + int pid; int apireq_fd; if (!g_daemonisrunnning) @@ -2968,8 +2969,8 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) daemon_error_printf("daemon allocate failed.\n"); return -ENOBUFS; } + g_daemon->selectid = -1; - g_daemon->pid = -1; if (apn) { @@ -3007,10 +3008,9 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) ASSERT(ret >= 0); g_daemonisrunnning = true; - g_daemon->pid = task_create("lte_daemon", - CONFIG_LTE_DAEMON_TASK_PRIORITY, - DAEMON_TASK_STACKSIZE, lte_daemon, NULL); - if (g_daemon->pid < 0) + pid = task_create("lte_daemon", CONFIG_LTE_DAEMON_TASK_PRIORITY, + DAEMON_TASK_STACKSIZE, lte_daemon, NULL); + if (pid < 0) { ret = -errno; close(apireq_fd); @@ -3124,7 +3124,6 @@ int32_t lte_daemon_set_cb(restart_report_cb_t restart_callback) int32_t lte_daemon_fin(void) { int ret; - int rc; int apireq_fd; int daemon_cmd_id = DAEMONAPI_REQUEST_FIN; @@ -3155,23 +3154,10 @@ int32_t lte_daemon_fin(void) /* Wait for the daemon task to terminate */ - ret = waitpid(g_daemon->pid, &rc, 0); - if (0 > ret) - { - ret = -errno; - - if (ret != -ECHILD) - { - close(apireq_fd); - - daemon_error_printf("waitpid failed: %d\n", -ret); - return ret; - } - } + sem_wait(&g_daemon->sync_sem); close(apireq_fd); remove(APIREQ_PIPE); - g_daemon->pid = -1; sem_destroy(&g_daemon->sync_sem); if (g_daemon) From 470986b0b579c240323039d8ae46aac7ac3199ad Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 9 Jul 2020 12:07:19 +0900 Subject: [PATCH 14/21] Fix bug that assert when calling lte_daemon_init() lte_daemon_fin() finishes without the daemon terminated completely when calling after lte_power_on(). Because the semaphore is posted at wrong conditions when calling lte_power_on(). lte_daemon_init() may start multiple daemons at the same time. (Because the daemon has not terminated completely.) So ASSERT occurs in the newly started daemon. --- sdk/modules/lte/net/daemon/daemon.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index 091b54327..e02adc8a8 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -147,6 +147,7 @@ struct daemon_s int event_outfd; int session_id; int poweron_result; + bool poweron_inprogress; sem_t sync_sem; lte_apn_setting_t apn; struct usock_s sockets[SOCKET_COUNT]; @@ -2701,7 +2702,16 @@ static int daemon_api_request(int read_fd, struct daemon_s* priv) priv->poweron_result = altcom_power_on(); if (priv->poweron_result < 0) { - sem_post(&g_daemon->sync_sem); + priv->poweron_inprogress = false; + sem_post(&priv->sync_sem); + } + else + { + /* Here, the inprogress flag is set on and the semaphore is + * posted when the DAEMON API_REQUEST_RESTART event is received. + */ + + priv->poweron_inprogress = true; } break; @@ -2758,8 +2768,13 @@ static void daemon_restart_cb(uint32_t reason) #endif } - if (reason == LTE_RESTART_USER_INITIATED) + /* Post the semaphore here. + * Only when inprogress flag is on at DAEMONAPI_REQUEST_POWER_ON. + */ + + if (g_daemon->poweron_inprogress) { + g_daemon->poweron_inprogress = false; sem_post(&g_daemon->sync_sem); } From d32919f3fecab86c1a7922bc796e8eca97518e31 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 9 Jul 2020 13:55:05 +0900 Subject: [PATCH 15/21] Refactor API handling of lte_daemon - Add DAEMONAPI_REQUEST_INIT - Send DAEMONAPI_REQUEST_RESTART to the daemon when daemon_restart_cb() called (Peformed in daemon context) - Reassign the value of requset ID --- sdk/modules/lte/net/daemon/daemon.c | 206 +++++++++++++++++++++------- 1 file changed, 153 insertions(+), 53 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index e02adc8a8..6354c2943 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -88,9 +88,11 @@ #define EVENT_PIPE2 "/tmp/lte_event_pipe2" #define APIREQ_PIPE "/tmp/lte_api_req_pipe" -#define DAEMONAPI_REQUEST_POWER_ON 128 -#define DAEMONAPI_REQUEST_POWER_OFF 129 -#define DAEMONAPI_REQUEST_FIN 130 +#define DAEMONAPI_REQUEST_INIT 1 +#define DAEMONAPI_REQUEST_FIN 2 +#define DAEMONAPI_REQUEST_POWER_ON 3 +#define DAEMONAPI_REQUEST_POWER_OFF 4 +#define DAEMONAPI_REQUEST_RESTART 5 #ifndef CONFIG_LTE_DAEMON_TASK_PRIORITY # define CONFIG_LTE_DAEMON_TASK_PRIORITY (110) @@ -168,6 +170,17 @@ struct setsockopt_param int16_t option; }; +struct daemon_req_common_s +{ + int reqid; +}; + +struct daemon_req_restart_s +{ + struct daemon_req_common_s head; + uint32_t reason; +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -2683,21 +2696,39 @@ static int forwarding_usock(int dst_fd, int src_fd, struct daemon_s* priv) * Name: daemon_api_request ****************************************************************************/ -static int daemon_api_request(int read_fd, struct daemon_s* priv) +static int daemon_api_request(int read_fd, int usock_fd, + FAR struct daemon_s *priv) { int ret = 0; - int daemon_api_cmd; + struct daemon_req_common_s req; + struct daemon_req_restart_s restart; + size_t rsize; - ret = read(read_fd, &daemon_api_cmd, sizeof(daemon_api_cmd)); - if (0 > ret || ret != sizeof(daemon_api_cmd)) + ret = read(read_fd, &req, sizeof(req)); + if (ret < 0) { - return -errno; + ret = -errno; + daemon_error_printf("read() failed: %d\n", errno); + + return ret; + } + else if (ret != sizeof(req)) + { + daemon_error_printf("unexpected read size: %d, expect size: %d\n", + ret, sizeof(req)); + ret = -ENOSPC; + + return ret; } - daemon_print_recvevt("receive daemonapi_request %d\n", daemon_api_cmd); + daemon_print_recvevt("receive daemon request: %d\n", req.reqid); - switch (daemon_api_cmd) + switch (req.reqid) { + case DAEMONAPI_REQUEST_INIT: + sem_post(&priv->sync_sem); + break; + case DAEMONAPI_REQUEST_POWER_ON: priv->poweron_result = altcom_power_on(); if (priv->poweron_result < 0) @@ -2715,23 +2746,83 @@ static int daemon_api_request(int read_fd, struct daemon_s* priv) } break; + case DAEMONAPI_REQUEST_POWER_OFF: ret = altcom_power_off(); break; + case DAEMONAPI_REQUEST_FIN: g_daemonisrunnning = false; break; + + case DAEMONAPI_REQUEST_RESTART: + rsize = sizeof(restart) - sizeof(struct daemon_req_common_s); + + /* Read restart request */ + + ret = read(read_fd, &restart.reason, rsize); + if (ret < 0) + { + ret = -errno; + daemon_error_printf("read() failed: %d\n", errno); + + return ret; + } + else if (ret != rsize) + { + daemon_error_printf("unexpected read size: %d, expect size: %d\n", + ret, rsize); + ret = -ENOSPC; + + return ret; + } + + ret = daemon_socket_send_abort(priv, usock_fd); + if (ret < 0) + { + daemon_error_printf("daemon_socket_send_abort() failed: %d\n", + ret); + } + + if (priv->selectid != -1) + { + altcom_select_async_cancel(priv->selectid, false); + priv->selectid = -1; + } + + priv->net_dev.d_flags = IFF_DOWN; +#ifdef CONFIG_NET_IPv4 + memset(&priv->net_dev.d_ipaddr, 0, + sizeof(priv->net_dev.d_ipaddr)); +#endif +#ifdef CONFIG_NET_IPv6 + memset(&priv->net_dev.d_ipv6addr, 0, + sizeof(priv->net_dev.d_ipv6addr)); +#endif + + /* Post the semaphore here. + * Only when inprogress flag is on at DAEMONAPI_REQUEST_POWER_ON. + */ + + if (priv->poweron_inprogress) + { + priv->poweron_inprogress = false; + sem_post(&priv->sync_sem); + } + + if (priv->user_restart_cb != NULL) + { + priv->user_restart_cb(restart.reason); + } + + break; + default: - daemon_error_printf("no match daemon_api_cmd\n"); + daemon_error_printf("unexpected daemon request: %d\n", req.reqid); ret = -ENOTSUP; break; } - if (0 > ret) - { - return -errno; - } - return ret; } @@ -2742,47 +2833,33 @@ static int daemon_api_request(int read_fd, struct daemon_s* priv) static void daemon_restart_cb(uint32_t reason) { int ret; + int apireq_fd; + struct daemon_req_restart_s req; daemon_debug_printf("daemon_restart_cb called reason by %d\n", reason); - if (reason == LTE_RESTART_MODEM_INITIATED) + apireq_fd = open(APIREQ_PIPE, O_WRONLY); + if (apireq_fd < 0) { - ret = daemon_socket_send_abort(g_daemon, g_daemon->event_outfd); - if (0 > ret) - { - daemon_error_printf("daemon_socket_send_abort() ret = %d\n", ret); - } - if (g_daemon->selectid != -1) - { - altcom_select_async_cancel(g_daemon->selectid, false); - g_daemon->selectid = -1; - } - g_daemon->net_dev.d_flags = IFF_DOWN; -#ifdef CONFIG_NET_IPv4 - memset(&g_daemon->net_dev.d_ipaddr, 0, - sizeof(g_daemon->net_dev.d_ipaddr)); -#endif -#ifdef CONFIG_NET_IPv6 - memset(&g_daemon->net_dev.d_ipv6addr, 0, - sizeof(g_daemon->net_dev.d_ipv6addr)); -#endif + daemon_error_printf("open(%s) failed = %d\n", APIREQ_PIPE, errno); + + return; } - /* Post the semaphore here. - * Only when inprogress flag is on at DAEMONAPI_REQUEST_POWER_ON. - */ + /* Write event to restart */ - if (g_daemon->poweron_inprogress) - { - g_daemon->poweron_inprogress = false; - sem_post(&g_daemon->sync_sem); - } + memset(&req, 0, sizeof(req)); + req.head.reqid = DAEMONAPI_REQUEST_RESTART; + req.reason = reason; - if (g_daemon->user_restart_cb != NULL) + ret = write(apireq_fd, &req, sizeof(req)); + if (ret < 0) { - g_daemon->user_restart_cb(reason); + daemon_error_printf("write() failed: %d\n", errno); } + close(apireq_fd); + return; } @@ -2846,8 +2923,6 @@ static int main_loop(FAR struct daemon_s *priv) ret = altcom_set_report_restart(daemon_restart_cb); ASSERT(ret >= 0); - sem_post(&priv->sync_sem); - daemon_debug_printf("LTE daemon is starting !\n"); while (g_daemonisrunnning) { @@ -2883,7 +2958,7 @@ static int main_loop(FAR struct daemon_s *priv) if (fds[2].revents & POLLIN) { - ret = daemon_api_request(fd[2], priv); + ret = daemon_api_request(fd[2], fd[0], priv); } if (fds[3].revents & POLLIN) @@ -2975,6 +3050,7 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) int ret; int pid; int apireq_fd; + struct daemon_req_common_s req; if (!g_daemonisrunnning) { @@ -3039,6 +3115,26 @@ int32_t lte_daemon_init(lte_apn_setting_t *apn) return ret; } + /* Write request to initialize */ + + req.reqid = DAEMONAPI_REQUEST_INIT; + + ret = write(apireq_fd, &req, sizeof(req)); + if (ret < 0) + { + ret = -errno; + close(apireq_fd); + remove(APIREQ_PIPE); + g_daemonisrunnning = false; + sem_destroy(&g_daemon->sync_sem); + free(g_daemon); + g_daemon = NULL; + task_delete(pid); + + daemon_error_printf("write() failed: %d\n", -ret); + return ret; + } + /* Wait for the daemon task to run */ sem_wait(&g_daemon->sync_sem); @@ -3061,7 +3157,7 @@ int32_t lte_daemon_power_on(void) { int ret; int apireq_fd; - int daemon_cmd_id = DAEMONAPI_REQUEST_POWER_ON; + struct daemon_req_common_s req; if (g_daemonisrunnning) { @@ -3078,7 +3174,9 @@ int32_t lte_daemon_power_on(void) /* Write request to poweron */ - ret = write(apireq_fd, &daemon_cmd_id, sizeof(daemon_cmd_id)); + req.reqid = DAEMONAPI_REQUEST_POWER_ON; + + ret = write(apireq_fd, &req, sizeof(req)); if (ret < 0) { ret = -errno; @@ -3140,7 +3238,7 @@ int32_t lte_daemon_fin(void) { int ret; int apireq_fd; - int daemon_cmd_id = DAEMONAPI_REQUEST_FIN; + struct daemon_req_common_s req; if (g_daemonisrunnning) { @@ -3157,7 +3255,9 @@ int32_t lte_daemon_fin(void) /* Write request to terminate the daemon */ - ret = write(apireq_fd, &daemon_cmd_id, sizeof(daemon_cmd_id)); + req.reqid = DAEMONAPI_REQUEST_FIN; + + ret = write(apireq_fd, &req, sizeof(req)); if (ret < 0) { ret = -errno; From 6c87f26f90de4618bbef700d2cca7490b508e4a2 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:38:02 +0900 Subject: [PATCH 16/21] lte: daemon: Fix bug that ifup command does not error Fixed a bug that ifup command does not error even if LTE network connection fails. --- sdk/modules/lte/net/daemon/daemon.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index 6354c2943..ec8f8bd9c 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -2469,14 +2469,13 @@ static int ioctl_request(int fd, struct daemon_s *priv, FAR void *hdrbuf) #endif ret = altcom_activate_pdn_sync(&priv->apn, &pdn_info); - if (0 > ret) + if (ret < 0) { - ret = altcom_errno(); - ret = -ret; daemon_error_printf("lte_activate_pdn_sync() failed = %d\n", ret); goto send_resp; } + priv->net_dev.d_flags = IFF_UP; priv->session_id = pdn_info.session_id; for (i = 0; i < pdn_info.ipaddr_num; i++) From e4d493100f52f97544e46424a67d162e67a49d2e Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 14 Jul 2020 16:15:07 +0900 Subject: [PATCH 17/21] lte: daemon: Fix bug that ifup command fail after modem reset When execute the ifup command after modem reset, the LTE network connection fails because it is not in the radio on state. --- sdk/modules/lte/net/daemon/daemon.c | 28 ++++++++++++++++++++++------ sdk/system/lte_daemon/lte_daemon.c | 7 ------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/sdk/modules/lte/net/daemon/daemon.c b/sdk/modules/lte/net/daemon/daemon.c index ec8f8bd9c..cb127c5d9 100644 --- a/sdk/modules/lte/net/daemon/daemon.c +++ b/sdk/modules/lte/net/daemon/daemon.c @@ -147,7 +147,6 @@ struct daemon_s { int selectid; int event_outfd; - int session_id; int poweron_result; bool poweron_inprogress; sem_t sync_sem; @@ -2468,16 +2467,32 @@ static int ioctl_request(int fd, struct daemon_s *priv, FAR void *hdrbuf) altcom_set_report_localtime(localtime_callback); #endif + ret = altcom_radio_on_sync(); + if (ret < 0) + { + daemon_error_printf("altcom_radio_on_sync() failed = %d\n", + ret); +#ifdef CONFIG_LTE_DAEMON_SYNC_TIME + altcom_set_report_localtime(NULL); +#endif + goto send_resp; + } + ret = altcom_activate_pdn_sync(&priv->apn, &pdn_info); if (ret < 0) { daemon_error_printf("lte_activate_pdn_sync() failed = %d\n", ret); + + altcom_radio_off_sync(); + +#ifdef CONFIG_LTE_DAEMON_SYNC_TIME + altcom_set_report_localtime(NULL); +#endif goto send_resp; } priv->net_dev.d_flags = IFF_UP; - priv->session_id = pdn_info.session_id; for (i = 0; i < pdn_info.ipaddr_num; i++) { #ifdef CONFIG_NET_IPv4 @@ -2498,20 +2513,21 @@ static int ioctl_request(int fd, struct daemon_s *priv, FAR void *hdrbuf) #endif } } + if (if_req.ifr_flags & IFF_DOWN) { #ifdef CONFIG_LTE_DAEMON_SYNC_TIME altcom_set_report_localtime(NULL); #endif - ret = altcom_deactivate_pdn_sync(priv->session_id); - if (0 > ret) + ret = altcom_radio_off_sync(); + if (ret < 0) { - daemon_error_printf("lte_deactivate_pdn_sync() failed = %d\n", + daemon_error_printf("altcom_radio_off_sync() failed = %d\n", ret); } + priv->net_dev.d_flags = IFF_DOWN; - priv->session_id = -1; #ifdef CONFIG_NET_IPv4 memset(&priv->net_dev.d_ipaddr, 0, sizeof(priv->net_dev.d_ipaddr)); diff --git a/sdk/system/lte_daemon/lte_daemon.c b/sdk/system/lte_daemon/lte_daemon.c index d45813421..9e5981859 100644 --- a/sdk/system/lte_daemon/lte_daemon.c +++ b/sdk/system/lte_daemon/lte_daemon.c @@ -176,13 +176,6 @@ int main(int argc, FAR char *argv[]) printf("daemon_power_on() error. %d\n", ret); goto err_out; } - - ret = altcom_radio_on_sync(); - if (0 > ret) - { - printf("altcom_radio_on_sync() error. %d\n", ret); - goto err_out; - } } if (0 == strncmp(cmd, "stop", strlen(cmd))) From dd537e9a09e33fba13e724814cb70da72ec598ab Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 18 Aug 2020 21:15:05 +0900 Subject: [PATCH 18/21] Update SDK version to SDK2.0.2 --- sdk/tools/mkversion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tools/mkversion.sh b/sdk/tools/mkversion.sh index 2d752700f..2298bd18d 100755 --- a/sdk/tools/mkversion.sh +++ b/sdk/tools/mkversion.sh @@ -42,7 +42,7 @@ if [ "X${TOPDIR}" = "X" ]; then fi APP_VERSION="0.0.0" -SDK_VERSION="SDK2.0.1" +SDK_VERSION="SDK2.0.2" if [ -r sdk_version ]; then SDK_VERSION="SDK`cat sdk_version`" fi From af5800411a17df6ec0075e190cd4cce8907634ba Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 1 Sep 2020 14:16:11 +0900 Subject: [PATCH 19/21] Update version.json for release v2.0.2 In v2.0.2 release, bootloader was updated. So, update version.json for using new bootloader. --- firmware/spresense/version.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/spresense/version.json b/firmware/spresense/version.json index 7a452e482..ad860c1fe 100644 --- a/firmware/spresense/version.json +++ b/firmware/spresense/version.json @@ -1,5 +1,5 @@ { "BoardName": "SPRESENSE", - "LoaderVersion": "v2.0.0", - "DownloadURL": "https://developer.sony.com/file/download/download-spresense-firmware-v2-0-000" + "LoaderVersion": "v2.0.2", + "DownloadURL": "https://developer.sony.com/file/download/download-spresense-firmware-v2-0-002" } From 5b5f828fc38db05298ffcd141080a80b6439c31f Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 2 Sep 2020 11:26:52 +0900 Subject: [PATCH 20/21] configs: Fix a defconfig for dnnrt_lenet to use SDcard Fix a defconfig for dnnrt_lenet example to be able to use data from SDcard. --- sdk/configs/examples/dnnrt_lenet/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/configs/examples/dnnrt_lenet/defconfig b/sdk/configs/examples/dnnrt_lenet/defconfig index b42c33732..778ae66c7 100644 --- a/sdk/configs/examples/dnnrt_lenet/defconfig +++ b/sdk/configs/examples/dnnrt_lenet/defconfig @@ -1,3 +1,4 @@ ++CXD56_SDIO=y +DNN_RT=y +EXAMPLES_DNNRT_LENET=y +EXTERNALS_CMSIS=y From a479f86c2869dd2a252671bf91617a21ec213447 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Fri, 18 Sep 2020 15:56:47 +0900 Subject: [PATCH 21/21] Update submodules for v2.0.2 release --- nuttx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuttx b/nuttx index c9f3b6ce6..581da3d5d 160000 --- a/nuttx +++ b/nuttx @@ -1 +1 @@ -Subproject commit c9f3b6ce6cda169240926584994e5e5f7d58051d +Subproject commit 581da3d5ddc81c8eb73f084e91348ab1c516e2f6