Revert "Merge 24Q3 to AOSP main"
This reverts commit f45adc631a06355db0a6d04ca121cf3c6ecc9590.
Reason for revert: This part will be moved out from the project.
Bug: 382137940
Test: None
Change-Id: I84d7cbe3f45bde1edb14ff73674267d1fcf58fff
Merged-In: I217615a2e7038fe90153b65359cbe2a3f22afdfc
diff --git a/Android.bp b/Android.bp
index 95745ce..45ad9cb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -17,7 +17,6 @@
name: "chip",
values: [
"SR1XX",
- "SR200",
],
}
@@ -37,15 +36,6 @@
name: "uwb_defaults",
soong_config_variables: {
chip: {
- SR200: {
- cflags: ["-DSR200=TRUE"],
- srcs: [
- "halimpl/hal/sr200/*.cc",
- ],
- local_include_dirs: [
- "halimpl/hal/sr200",
- ],
- },
conditions_default: {
cflags: ["-DSR1XX=TRUE"],
srcs: [
diff --git a/halimpl/hal/sr200/NxpUwbChipSr200.cc b/halimpl/hal/sr200/NxpUwbChipSr200.cc
deleted file mode 100644
index c1d3d79..0000000
--- a/halimpl/hal/sr200/NxpUwbChipSr200.cc
+++ /dev/null
@@ -1,166 +0,0 @@
-#include "NxpUwbChip.h"
-#include "phNxpConfig.h"
-#include "phNxpUciHal.h"
-#include "phNxpUciHal_ext.h"
-#include "phUwbStatus.h"
-#include "phUwbTypes.h"
-#include "phNxpUwbCalib.h"
-#include "uci_defs.h"
-
-#define UCI_MSG_UWB_ESE_BINDING_LEN 11
-#define UCI_MSG_UWB_ESE_BINDING_OFFSET_COUNT 5
-#define UCI_MSG_UWB_ESE_BINDING_OFFSET_BINDING_STATE 6
-
-extern phNxpUciHal_Control_t nxpucihal_ctrl;
-extern int hdll_fw_download();
-
-class NxpUwbChipSr200 final : public NxpUwbChip {
-public:
- NxpUwbChipSr200();
- virtual ~NxpUwbChipSr200();
-
- tHAL_UWB_STATUS chip_init();
- tHAL_UWB_STATUS core_init();
- device_type_t get_device_type(const uint8_t *param, size_t param_len);
- tHAL_UWB_STATUS read_otp(extcal_param_id_t id, uint8_t *data, size_t data_len, size_t *retlen);
- tHAL_UWB_STATUS apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len);
-private:
- bool on_binding_status_ntf(size_t packet_len, const uint8_t* packet);
-
- tHAL_UWB_STATUS check_binding_done();
- int16_t extra_group_delay(void);
-
- UciHalRxHandler bindingStatusNtfHandler_;
- UciHalSemaphore bindingStatusNtfWait_;
- uint8_t bindingStatus_;
-};
-
-NxpUwbChipSr200::NxpUwbChipSr200() :
- bindingStatus_(UWB_DEVICE_UNKNOWN)
-{
-}
-
-NxpUwbChipSr200::~NxpUwbChipSr200()
-{
-}
-
-bool NxpUwbChipSr200::on_binding_status_ntf(size_t packet_len, const uint8_t* packet)
-{
- if (packet_len >= UCI_RESPONSE_STATUS_OFFSET) {
- bindingStatus_ = packet[UCI_RESPONSE_STATUS_OFFSET];
- NXPLOG_UCIHAL_D("BINDING_STATUS_NTF: 0x%x", bindingStatus_);
- bindingStatusNtfWait_.post(UWBSTATUS_SUCCESS);
- }
- return true;
-}
-
-tHAL_UWB_STATUS NxpUwbChipSr200::check_binding_done()
-{
- // Wait for Binding status notification
- if (bindingStatusNtfWait_.getStatus() != UWBSTATUS_SUCCESS) {
- bindingStatusNtfWait_.wait();
- }
- if (bindingStatusNtfWait_.getStatus() != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("Binding status notification timeout");
-
- // Stop HAL init when it didn't receive the binding notification
- if (nxpucihal_ctrl.fw_boot_mode == USER_FW_BOOT_MODE)
- return UWBSTATUS_FAILED;
- else
- return UWBSTATUS_SUCCESS;
- }
-
- switch (bindingStatus_) {
- case UWB_DEVICE_NOT_BOUND:
- NXPLOG_UCIHAL_E("Binding status: Unbound.");
- break;
- case UWB_DEVICE_BOUND_UNLOCKED:
- NXPLOG_UCIHAL_E("Binding status: bound & unlocked.");
- break;
- case UWB_DEVICE_BOUND_LOCKED:
- NXPLOG_UCIHAL_D("Binding status: bound & locked.");
- break;
- case UWB_DEVICE_UNKNOWN:
- NXPLOG_UCIHAL_D("Binding status: Unknown.");
- break;
- default:
- NXPLOG_UCIHAL_E("Unknown binding status: 0x%x", bindingStatus_);
- return UWBSTATUS_FAILED;
- }
-
- return UWBSTATUS_SUCCESS;
-}
-
-tHAL_UWB_STATUS NxpUwbChipSr200::chip_init()
-{
- tHAL_UWB_STATUS status;
-
- // system in FW download mode
- // This will be cleared on first Device Status NTF
- nxpucihal_ctrl.fw_dwnld_mode = true;
-
- NXPLOG_UCIHAL_D("Start SR200 FW download");
-
- for (int i = 0; i < 5; i++) {
- phTmlUwb_Chip_Reset();
-
- status = hdll_fw_download();
-
- if (status == UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_D("Complete SR200 FW download");
- break;
- } else if(status == UWBSTATUS_FILE_NOT_FOUND) {
- NXPLOG_UCIHAL_E("FW file Not found.");
- break;
- } else {
- NXPLOG_UCIHAL_E("FW download failed, status= 0x%x, retry.", status);
- }
- }
-
- // register binding status ntf handler
- bindingStatusNtfHandler_ = UciHalRxHandler(
- UCI_MT_NTF, UCI_GID_PROPRIETARY, UCI_MSG_BINDING_STATUS_NTF,
- std::bind(&NxpUwbChipSr200::on_binding_status_ntf, this, std::placeholders::_1, std::placeholders::_2));
-
- return status;
-}
-
-tHAL_UWB_STATUS NxpUwbChipSr200::core_init()
-{
- return check_binding_done();
-}
-
-device_type_t NxpUwbChipSr200::get_device_type(const uint8_t *param, size_t param_len)
-{
- // should be 'SR200..'
- const char marker[] = { 'S', 'R', '2', '0', '0' };
- if (param_len >= sizeof(marker)) {
- if (!memcmp(param, marker, sizeof(marker)))
- return DEVICE_TYPE_SR200;
- }
- return DEVICE_TYPE_UNKNOWN;
-}
-
-tHAL_UWB_STATUS
-NxpUwbChipSr200::read_otp(extcal_param_id_t id,
- uint8_t *data, size_t data_len, size_t *retlen)
-{
- return UWBSTATUS_NOT_ALLOWED;
-}
-
-tHAL_UWB_STATUS
-NxpUwbChipSr200::apply_calibration(extcal_param_id_t id, const uint8_t ch,
- const uint8_t *data, size_t data_len)
-{
- return phNxpUwbCalib_apply_calibration(id, ch, data, data_len);
-}
-
-int16_t NxpUwbChipSr200::extra_group_delay(void) {
- // Only for SR100. Not for SR2XX
- return 0;
-}
-
-std::unique_ptr<NxpUwbChip> GetUwbChip()
-{
- return std::make_unique<NxpUwbChipSr200>();
-}
diff --git a/halimpl/hal/sr200/fwd_hdll.cc b/halimpl/hal/sr200/fwd_hdll.cc
deleted file mode 100644
index 45145ca..0000000
--- a/halimpl/hal/sr200/fwd_hdll.cc
+++ /dev/null
@@ -1,2168 +0,0 @@
-/*
- * Copyright 2021-2023 NXP
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/ioctl.h>
-#include <dlfcn.h>
-
-#include "fwd_hdll.h"
-#include "phNxpConfig.h"
-#include "phNxpLog.h"
-#include "phNxpUciHal_fwd_utils.h"
-#include "phNxpUciHal_utils.h"
-#include "phTmlUwb_spi.h"
-
-#define MAX_FRAME_LEN 4200
-static uint8_t is_fw_download_log_enabled = 0x00;
-
-static phFWD_Status_t openFwBinFile(phUwbFWImageContext_t *pfwImageCtx);
-static phFWD_Status_t openFwSoFile(phUwbFWImageContext_t *pfwImageCtx);
-static phFWD_Status_t phNxpUciHal_fw_recovery(phUwbFWImageContext_t *pfwImageCtx);
-
-char default_fw_path[FILEPATH_MAXLEN] = "/vendor/firmware/uwb/";
-const char *default_dev_fw_bin = "libsr200t_fw.bin";
-const char *default_dev_fw_so = "libsr200t_fw.so";
-const char *default_so_file_extn = ".so";
-extern uint32_t timeoutTimerId;
-static bool isHdllReadTmeoutExpired = false;
-static bool bSkipEdlCheck = false;
-static bool glcRotation = false;
-
-phUwbFWImageContext_t fwImageCtx;
-
-/*******************************************************************************
-**
-** Function : phGenericSendAndRecv
-**
-** Description : This function sends the HDLL commands to HeliosX chip over
- SPI using phHdll_PutApdu() and gets the response using
- phHdll_GetApdu().
-**
-** Parameters : payload - HDLL command to be sent
- len - HDLL command length
- readbuff - HDLL command response buffer
- rsp_buf_len - HDLL command rsponse buffer length
-**
-** Returns : phFWD_Status_t : 0 - success
- 1 - failure
-**
-**
-*******************************************************************************/
-phFWD_Status_t phGenericSendAndRecv(uint8_t *payload, uint16_t len,
- uint8_t *read_buff, uint16_t *rsp_buf_len) {
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- if (FW_DNLD_SUCCESS != (ret = phHdll_PutApdu((uint8_t *)&payload[0], len))) {
- return ret;
- }
- if (FW_DNLD_SUCCESS !=
- (ret = phHdll_GetApdu((uint8_t *)&read_buff[0], HDLL_READ_BUFF_SIZE,
- rsp_buf_len))) {
- return ret;
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : print_getInfoRsp
-**
-** Description : This function prints the HDLL GetInfo command's response
-**
-** Parameters : getInfoRsp - Struct which has the GetInfo response details.
-**
-** Returns : None
-**
-**
-*******************************************************************************/
-void print_getInfoRsp(phHDLLGetInfo_t *getInfoRsp) {
- uint8_t i = 0, offset = 0;
- char buff[HDLL_READ_BUFF_SIZE] = {0};
- if (NULL == getInfoRsp) {
- return;
- }
- NXPLOG_FWDNLD_D("=====================GET_INFO =======================\n");
- NXPLOG_FWDNLD_D("Boot Status: 0x%02X\n", getInfoRsp->boot_status);
- NXPLOG_FWDNLD_D("Session Control: 0x%02X\n", getInfoRsp->session_control);
- NXPLOG_FWDNLD_D("Session Type: 0x%02X\n", getInfoRsp->session_type);
- NXPLOG_FWDNLD_D("ROM Version: 0x%02X\n", getInfoRsp->rom_version);
- NXPLOG_FWDNLD_D("AT Page Status: 0x%02X\n", getInfoRsp->AT_page_status);
- NXPLOG_FWDNLD_D("Chip Version: Major.Minor: %02X.%02X\n",
- getInfoRsp->chip_major_ver, getInfoRsp->chip_minor_ver);
- NXPLOG_FWDNLD_D("FW Version: Major.Minor: %02X.%02X\n",
- getInfoRsp->fw_major_ver, getInfoRsp->fw_minor_ver);
-
- for (i = 0; i != 8; i += 2) { // 4bytes
- sprintf(&buff[i], "%02X", getInfoRsp->chip_variant[offset++]);
- }
- buff[i] = '\0';
- NXPLOG_FWDNLD_D("Chip Variant: 0x%s\n", buff);
- NXPLOG_FWDNLD_D("Device Lifecycle: 0x%X\n", getInfoRsp->device_life_cycle);
-
- for (i = 0, offset = 0; i != 32; i += 2) { // 16bytes
- sprintf(&buff[i], "%02X", getInfoRsp->chip_id[offset++]);
- }
- buff[i] = '\0';
- NXPLOG_FWDNLD_D("Chip ID: 0x%s\n", buff);
-
- for (i = 0, offset = 0; i != 8; i += 2) { // 4bytes
- sprintf(&buff[i], "%02X", getInfoRsp->chip_id_crc[offset++]);
- }
- buff[i] = '\0';
- NXPLOG_FWDNLD_D("Chip ID CRC:0x%s\n", buff);
- NXPLOG_FWDNLD_D("=====================================================\n");
-}
-
-/*******************************************************************************
-**
-** Function : process_getInfo_rsp
-**
-** Description : This function processes the HDLL GetInfo command's response
-**
-** Parameters : payload - Struct in which the processed info will be kept
-**
-** Returns : On failure - NULL
- On success - Pointer to the phHDLLGetInfo_t struct
-**
-**
-*******************************************************************************/
-phHDLLGetInfo_t *process_getInfo_rsp(uint8_t *payload) {
- uint8_t offset = 0;
- phHDLLGetInfo_t *getInfoRsp = NULL;
- uint8_t device_lc_mode[4] = {0};
-
- getInfoRsp = (phHDLLGetInfo_t *)malloc(sizeof(phHDLLGetInfo_t));
- if (NULL == getInfoRsp) {
- return NULL;
- }
- memset(getInfoRsp, 0, sizeof(phHDLLGetInfo_t));
- getInfoRsp->boot_status = payload[offset++];
- getInfoRsp->session_control = payload[offset++];
- getInfoRsp->session_type = payload[offset++];
- getInfoRsp->rom_version = (eUWBD_Rom_Version_t)payload[offset++];
- getInfoRsp->AT_page_status = (eUWBD_AT_Page_status_t)payload[offset++];
- offset += 2; // padding bytes
- getInfoRsp->chip_major_ver = payload[offset++];
- getInfoRsp->chip_minor_ver = payload[offset++];
- getInfoRsp->fw_major_ver = payload[offset++];
- getInfoRsp->fw_minor_ver = payload[offset++];
- memcpy(getInfoRsp->chip_variant, payload + offset, sizeof(uint8_t) * 4);
- offset += 4;
- memcpy(device_lc_mode, payload + offset, sizeof(uint8_t) * 4);
- getInfoRsp->device_life_cycle = (eUWBD_LC_mode_t)(device_lc_mode[0] | (device_lc_mode[1] << 8) | (device_lc_mode[2] << 16) | (device_lc_mode[3] << 24));
- offset += 4;
- memcpy(getInfoRsp->chip_id, payload + offset, sizeof(uint8_t) * 16);
- offset += 16;
- memcpy(getInfoRsp->chip_id_crc, payload + offset, sizeof(uint8_t) * 4);
- return getInfoRsp;
-}
-
-/*******************************************************************************
-**
-** Function : getFwImageCtx
-**
-** Description : This function use to get the FW image context
-**
-** Parameters : pfwImageCtx -> pointer to fw image context
-**
-** Returns : On failure - returns FW_DNLD_FAILURE
- - or FW_DNLD_FILE_NOT_FOUND if FW file not present
- in the MW.
- On success - returns FW_DNLD_SUCCESS.
-**
-**
-*******************************************************************************/
-phFWD_Status_t getFwImageCtx(phUwbFWImageContext_t *pfwImageCtx) {
- phFWD_Status_t status = FW_DNLD_SUCCESS;
- char *configured_fw_name = NULL;
- const uint16_t fw_file_max_len = FILENAME_MAXLEN;
- const char *pDefaultFwFileName = NULL;
- char* ret = NULL;
-
- configured_fw_name = (char *)malloc(fw_file_max_len * sizeof(char));
- int maxSrcLen = (FILEPATH_MAXLEN - strlen(pfwImageCtx->default_fw_path)) - 1;
- if (configured_fw_name == NULL) {
- NXPLOG_FWDNLD_E("malloc of configured_fw_name failed ");
- return FW_DNLD_FAILURE;
- }
-
- /* Default FW download configset to bin file */
- pDefaultFwFileName = default_dev_fw_bin;
-
- if (!NxpConfig_GetStr(NAME_NXP_UWB_FW_FILENAME, configured_fw_name,
- fw_file_max_len)) {
- NXPLOG_FWDNLD_D("Invalid Dev Fw name keeping the default name: %s",
- pDefaultFwFileName);
- strncat(pfwImageCtx->default_fw_path, pDefaultFwFileName, maxSrcLen);
- } else {
- NXPLOG_FWDNLD_D("configured_fw_name : %s", configured_fw_name);
- strncat(pfwImageCtx->default_fw_path, configured_fw_name, maxSrcLen);
- }
-
- NXPLOG_FWDNLD_D("fw file path : %s", pfwImageCtx->default_fw_path);
- // Search for so extension in filename
- ret = strstr(configured_fw_name, default_so_file_extn);
- if(ret) {
- pfwImageCtx->fw_dnld_config = SO_FILE_BASED_FW_DOWNLOAD;
- /* Get Fw Context from so file */
- status = openFwSoFile(pfwImageCtx);
- } else {
- /* Get Fw Context from bin file */
- status = openFwBinFile(pfwImageCtx);
- }
-
- if (configured_fw_name != NULL) {
- free(configured_fw_name);
- }
- memset(pfwImageCtx->default_fw_path, '\0', sizeof(char) * FILEPATH_MAXLEN);
- strcpy(pfwImageCtx->default_fw_path, "/vendor/firmware/uwb/");
- return status;
-}
-
-/*******************************************************************************
-**
-** Function : printManifestInfo
-**
-** Description : This function is use to get UWB Manifest info
-**
-** Parameters : pfwImageCtx -> pointer to fw image context
-**
-** Returns : On failure - returns FW_DNLD_FAILURE
- - or FW_DNLD_FILE_NOT_FOUND if FW file not present
- in the MW.
- On success - returns FW_DNLD_SUCCESS.
-**
-**
-*******************************************************************************/
-void printManifest_info(UWBManifest_t *fwLibManifest) {
-
- if(fwLibManifest == NULL) {
- return;
- }
- NXPLOG_FWDNLD_D("================= FW Lib Manifest ====================\n");
- NXPLOG_FWDNLD_D("UWB manifest version = %x\n",fwLibManifest->layout_version);
- NXPLOG_FWDNLD_D("UWB manifest creation year = %d\n",fwLibManifest->creation_date_yy);
- NXPLOG_FWDNLD_D("UWB manifest creation month = %d\n",fwLibManifest->creation_date_month);
- NXPLOG_FWDNLD_D("UWB manifest creation day = %d\n",fwLibManifest->creation_date_day);
- NXPLOG_FWDNLD_D("UWB manifest creation hour = %d\n",fwLibManifest->creation_date_hour);
- NXPLOG_FWDNLD_D("UWB manifest creation minutes = %d\n",fwLibManifest->creation_date_minutes);
- NXPLOG_FWDNLD_D("UWB manifest creation seconds = %d\n",fwLibManifest->creation_date_seconds);
- NXPLOG_FWDNLD_D("UWB manifest count = %d\n",fwLibManifest->countMWCESFW);
-
- return;
-
-}
-
-/*******************************************************************************
-**
-** Function : openFwSoFile
-**
-** Description : This function loads the FW shared library context
- if the FW file exists otherwise returns failure.
-**
-** Parameters : pfwImageCtx -> pointer to fw image context
-**
-** Returns : On failure - returns FW_DNLD_FAILURE
- - or FW_DNLD_FILE_NOT_FOUND if FW file not present
- in the MW.
- On success - returns FW_DNLD_SUCCESS.
-**
-**
-*******************************************************************************/
-static phFWD_Status_t openFwSoFile(phUwbFWImageContext_t *pfwImageCtx) {
- void *flibptr = NULL;
- UWBManifest_t *currentFwLib = NULL;
- pfwImageCtx->gFwLib = NULL;
- phFWD_Status_t status = FW_DNLD_SUCCESS;
-
- NXPLOG_FWDNLD_D("%s:%d enter", __func__,__LINE__);
-
- pfwImageCtx->gFwLib = dlopen(pfwImageCtx->default_fw_path, RTLD_LAZY);
- if (pfwImageCtx->gFwLib == NULL) {
- // Apparently, the library could not be opened
- NXPLOG_FWDNLD_E("%s: Error! opening FW file %s\n", __func__,
- pfwImageCtx->default_fw_path);
- status = FW_DNLD_FILE_NOT_FOUND;
- goto cleanup;
- }
- flibptr = dlsym(pfwImageCtx->gFwLib, "gUWBManifest");
- if (!flibptr) {
- NXPLOG_FWDNLD_E("%s: Could not get function pointer\n", __func__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- }
-
- currentFwLib = (UWBManifest_t *)flibptr;
- if (currentFwLib == NULL) {
- NXPLOG_FWDNLD_E("%s:%d UwbManifest is null exiting.....", __func__, __LINE__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- }
-
- printManifest_info(currentFwLib);
-
- // read the FW bytes into buffer
- if (pfwImageCtx->deviceInfo->rom_version == VER_A1V1) {
- if(currentFwLib->mwCESFW[MWCESFW_A1V1_RECOVERY_FW_OFFSET] == NULL || currentFwLib->mwCESFW[MWCESFW_A1V1_FW_OFFSET] == NULL) {
- NXPLOG_FWDNLD_E("%s:%d UwbManifest mwCESFW is null exiting.....", __func__, __LINE__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- }
- if(pfwImageCtx->deviceInfo->AT_page_status == STATUS_PAGE_ERROR) {
- pfwImageCtx->fwRecovery = true;
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V1_RECOVERY_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V1_RECOVERY_FW_OFFSET]->pCESFW;
- } else if((pfwImageCtx->deviceInfo->device_life_cycle == CUSTOMER_MODE) && glcRotation == true) {
- if(currentFwLib->mwCESFW[MWCESFW_A1V1_LC_FW_OFFSET] == NULL ) {
- NXPLOG_FWDNLD_E("%s:%d LC FW does not exist.....", __func__, __LINE__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- } else {
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V1_LC_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V1_LC_FW_OFFSET]->pCESFW;
- }
- }else {
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V1_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V1_FW_OFFSET]->pCESFW;
- }
- }
- else if (pfwImageCtx->deviceInfo->rom_version == VER_A1V2) {
- if(currentFwLib->mwCESFW[MWCESFW_A1V2_RECOVERY_FW_OFFSET] == NULL || currentFwLib->mwCESFW[MWCESFW_A1V2_FW_OFFSET] == NULL) {
- NXPLOG_FWDNLD_E("%s:%d UwbManifest mwCESFW is null exiting.....", __func__, __LINE__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- }
- if(pfwImageCtx->deviceInfo->AT_page_status == STATUS_PAGE_ERROR) {
- pfwImageCtx->fwRecovery = true;
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V2_RECOVERY_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V2_RECOVERY_FW_OFFSET]->pCESFW;
- } else if((pfwImageCtx->deviceInfo->device_life_cycle == CUSTOMER_MODE) && glcRotation == true) {
- if(currentFwLib->mwCESFW[MWCESFW_A1V2_LC_FW_OFFSET] == NULL ) {
- NXPLOG_FWDNLD_E("%s:%d LC FW does not exist.....", __func__, __LINE__);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- } else {
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V2_LC_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V2_LC_FW_OFFSET]->pCESFW;
- }
- } else {
- pfwImageCtx->fwImgSize = currentFwLib->mwCESFW[MWCESFW_A1V2_FW_OFFSET]->lenCESFW;
- pfwImageCtx->fwImage = currentFwLib->mwCESFW[MWCESFW_A1V2_FW_OFFSET]->pCESFW;
- }
- }
- if ((!(pfwImageCtx->fwImgSize)) || (NULL == pfwImageCtx->fwImage)) {
- NXPLOG_FWDNLD_E("%s: Error! File %s is empty\n", __func__, pfwImageCtx->default_fw_path);
- status = FW_DNLD_FAILURE;
- goto cleanup;
- }
-
- NXPLOG_FWDNLD_E("exiting %s fwImgSize %d" , __func__, pfwImageCtx->fwImgSize);
-
- return status;
-
-cleanup:
- if (pfwImageCtx->gFwLib != NULL) {
- dlclose(pfwImageCtx->gFwLib);
- pfwImageCtx->gFwLib = NULL;
- }
- return status;
-
-}
-
-/*******************************************************************************
-**
-** Function : openFwBinFile
-**
-** Description : This function copies the entire Bin FW file content into a buffer
- if the FW file exists otherwise returns failure.
-**
-** Parameters : pfwImageCtx -> pointer to fw image context
-**
-** Returns : On failure - returns FW_DNLD_FAILURE
- - or FW_DNLD_FILE_NOT_FOUND if FW file not present
- in the MW.
- On success - returns FW_DNLD_SUCCESS.
-**
-**
-*******************************************************************************/
-static phFWD_Status_t openFwBinFile(phUwbFWImageContext_t *pfwImageCtx) {
- phFWD_Status_t status = FW_DNLD_SUCCESS;
- long int file_size = 0;
- size_t ret_size = 0;
- FILE *fptr = NULL;
-
- NXPLOG_FWDNLD_D("%s:%d enter", __func__,__LINE__);
-
- // open FW binary file
- if ((fptr = fopen(pfwImageCtx->default_fw_path, "rb")) == NULL) {
- NXPLOG_FWDNLD_E("%s: Error! opening FW file %s\n", __func__,
- pfwImageCtx->default_fw_path);
- status = FW_DNLD_FILE_NOT_FOUND;
- goto exit;
- }
-
- // find the FW binary file size
- fseek(fptr, 0L, SEEK_END);
- file_size = ftell(fptr);
- if (!file_size || (-1L == file_size)) {
- NXPLOG_FWDNLD_E("%s: Error! File %s is empty\n", __func__, pfwImageCtx->default_fw_path);
- status = FW_DNLD_FAILURE;
- goto exit;
- }
- else {
- pfwImageCtx->fwImgSize = file_size;
- }
-
- // read the FW bytes into buffer
- pfwImageCtx->fwImage = (uint8_t *)malloc(sizeof(uint8_t) * pfwImageCtx->fwImgSize);
- if (NULL == pfwImageCtx->fwImage)
- {
- status = FW_DNLD_FAILURE;
- NXPLOG_FWDNLD_E("%s: Error in allocating memory\n", __func__);
- goto exit;
- }
- rewind(fptr);
- ret_size = fread(pfwImageCtx->fwImage, sizeof(uint8_t), pfwImageCtx->fwImgSize, fptr);
- if (ret_size != pfwImageCtx->fwImgSize) {
- if (feof(fptr))
- {
- NXPLOG_FWDNLD_E("%s: Error reading file %s, unexpected end of file\n",
- __func__, pfwImageCtx->default_fw_path);
- }
- else if (ferror(fptr))
- {
- NXPLOG_FWDNLD_E("%s: Error reading file %s\n", __func__, pfwImageCtx->default_fw_path);
- }
- status = FW_DNLD_FAILURE;
- goto exit;
- }
-
-exit:
- if (NULL != fptr)
- {
- fclose(fptr);
- }
-
- return status;
-}
-
-/*******************************************************************************
-**
-** Function : check_fw_update_required
-**
-** Description : This function checks whether FW update is required or not
- based on FW version from MW binary and FW version present in
- the HeliosX chip.
-**
-** Parameters : getInfoRsp - Struct which has the GetInfo response details.
-**
-** Returns : FW_DNLD_FAILURE - If any un expected failure
- FW_DNLD_NOT_REQUIRED - FW update not required
- FW_DNLD_REQUIRED - FW update required
- FW_DNLD_FILE_NOT_FOUND - if the FW bin file is unable to
- open or not present
-**
-**
-*******************************************************************************/
-phFWD_Status_t check_fw_update_required(phHDLLGetInfo_t *getInfoRsp) {
- uint32_t next_frame_first_byte_index = 0;
- uint32_t index = 0;
- uint8_t mw_fw_major_ver = 0;
- uint8_t mw_fw_minor_ver = 0;
- uint32_t frame_payload_length = 0;
- uint32_t frame_length = 0;
- unsigned long num = 0;
- phFWD_Status_t status = FW_DNLD_FAILURE;
-
- fwImageCtx.deviceInfo = getInfoRsp;
- fwImageCtx.fw_dnld_config = BIN_FILE_BASED_FW_DOWNLOAD;
- fwImageCtx.fw_flash_config = FLASH_UPPER_VER_UPDATE;
- fwImageCtx.fwRecovery = false;
- strcpy(fwImageCtx.default_fw_path, default_fw_path);
-
- status = getFwImageCtx(&fwImageCtx);
- if (status != FW_DNLD_SUCCESS) {
- return status;
- }
-
- if (NxpConfig_GetNum(NAME_NXP_UWB_FLASH_CONFIG, &num, sizeof(num))) {
- fwImageCtx.fw_flash_config = (uint8_t)num;
- NXPLOG_FWDNLD_D("NAME_NXP_UWB_FLASH_CONFIG: 0x%02x\n", fwImageCtx.fw_flash_config);
- if (!(fwImageCtx.fw_flash_config == FLASH_UPPER_VER_UPDATE ||
- fwImageCtx.fw_flash_config == FLASH_DIFFERENT_VER_UPDATE ||
- fwImageCtx.fw_flash_config == FLASH_FORCE_UPDATE))
- {
- fwImageCtx.fw_flash_config = FLASH_UPPER_VER_UPDATE;
- }
- }
- else {
- NXPLOG_FWDNLD_D("NAME_NXP_UWB_FLASH_CONFIG: failed 0x%02x\n",
- fwImageCtx.fw_flash_config);
- }
-
- frame_payload_length = (fwImageCtx.fwImage[next_frame_first_byte_index] << 8) +
- (fwImageCtx.fwImage[next_frame_first_byte_index + 1]);
- frame_length = frame_payload_length + HDLL_HEADER_LEN + HDLL_FOOTER_LEN;
-
- // get the index of first_write_cmd_payload
- next_frame_first_byte_index = next_frame_first_byte_index + frame_length;
- index = next_frame_first_byte_index;
- mw_fw_major_ver = fwImageCtx.fwImage[index + MW_MAJOR_FW_VER_OFFSET];
- mw_fw_minor_ver = fwImageCtx.fwImage[index + MW_MINOR_FW_VER_OFFSET];
- NXPLOG_FWDNLD_D("mw_fw_ver: %02X.%02X chip_fw_ver: %02X.%02X\n",
- mw_fw_major_ver, mw_fw_minor_ver, getInfoRsp->fw_major_ver,
- getInfoRsp->fw_minor_ver);
-
- if(getInfoRsp->session_control == SESSION_CONTROL_OPEN){
- NXPLOG_FWDNLD_D("FW Update required as session control is open \n");
- status = FW_DNLD_REQUIRED;
- } else {
- switch (fwImageCtx.fw_flash_config) {
- case FLASH_UPPER_VER_UPDATE: {
- if (mw_fw_major_ver > getInfoRsp->fw_major_ver) {
- NXPLOG_FWDNLD_D("FLASH_UPPER_VER_UPDATE:FW Update required\n");
- status = FW_DNLD_REQUIRED;
- } else if (mw_fw_major_ver == getInfoRsp->fw_major_ver) {
- if (mw_fw_minor_ver > getInfoRsp->fw_minor_ver) {
- NXPLOG_FWDNLD_D("FLASH_UPPER_VER_UPDATE:FW Update required\n");
- status = FW_DNLD_REQUIRED;
- } else {
- NXPLOG_FWDNLD_E(
- "FLASH_UPPER_VER_UPDATE:FW lower Minor version is not supported\n");
- status = FW_DNLD_NOT_REQUIRED;
- }
- } else {
- NXPLOG_FWDNLD_E(
- "FLASH_UPPER_VER_UPDATE:FW lower Major version is not supported\n");
- status = FW_DNLD_NOT_REQUIRED;
- }
- } break;
- case FLASH_FORCE_UPDATE: {
- if (mw_fw_major_ver < getInfoRsp->fw_major_ver) {
- NXPLOG_FWDNLD_E(
- "FLASH_FORCE_UPDATE:FW lower Major version is not supported\n");
- status = FW_DNLD_NOT_REQUIRED;
- } else {
- NXPLOG_FWDNLD_D("FLASH_FORCE_UPDATE:FW Update required\n");
- status = FW_DNLD_REQUIRED;
- }
- } break;
- case FLASH_DIFFERENT_VER_UPDATE: {
- if (mw_fw_major_ver > getInfoRsp->fw_major_ver) {
- NXPLOG_FWDNLD_D("FLASH_DIFFERENT_VER_UPDATE:FW Update required\n");
- status = FW_DNLD_REQUIRED;
- } else if(mw_fw_major_ver == getInfoRsp->fw_major_ver) {
- if(mw_fw_minor_ver == getInfoRsp->fw_minor_ver) {
- NXPLOG_FWDNLD_E(
- "FLASH_DIFFERENT_VER_UPDATE:Same Minor FW version update is not supported\n");
- status = FW_DNLD_NOT_REQUIRED;
- } else {
- NXPLOG_FWDNLD_E(
- "FLASH_DIFFERENT_VER_UPDATE:FW Update required\n");
- status = FW_DNLD_REQUIRED;
- }
- } else {
- NXPLOG_FWDNLD_D("FLASH_DIFFERENT_VER_UPDATE:lower Major FW version update is not supported\n");
- status = FW_DNLD_NOT_REQUIRED;;
- }
- } break;
- }
- }
- return status;
-}
-
-/*******************************************************************************
-**
-** Function : handleGetInfoRsp
-**
-** Description : This function handles the GetInfo response that is received
- from the HeliosX chip.
-**
-** Parameters : hdll_payload - HDLL response buffer
-**
-** Returns : FW_DNLD_FAILURE - If any un expected failure
- FW_DNLD_NOT_REQUIRED - FW update not required
- FW_DNLD_REQUIRED - FW update required
- FW_DNLD_FILE_NOT_FOUND - if the FW bin file is unable to
- open or not present
-**
-**
-*******************************************************************************/
-phFWD_Status_t handleGetInfoRsp(uint8_t *hdll_payload) {
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- phHDLLGetInfo_t *getInfoRsp = NULL;
-
- getInfoRsp = process_getInfo_rsp(hdll_payload);
- if (NULL == getInfoRsp) {
- return ret;
- }
- print_getInfoRsp(getInfoRsp);
- ret = check_fw_update_required(getInfoRsp);
-
- if (NULL != getInfoRsp) {
- free(getInfoRsp);
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : printHDLLRspStatus
-**
-** Description : This function prints the HDLL response status string based on
- the given status code
-
-** Parameters : status - status code
-**
-** Returns : None
-**
-**
-*******************************************************************************/
-
-void printHDLLRspStatus(uint8_t status) {
- switch (status) {
- case GENERIC_SUCCESS:
- NXPLOG_FWDNLD_D("Received status: GENERIC_SUCCESS");
- break;
- case ACKNOWLEDGE:
- NXPLOG_FWDNLD_D("Received status: ACKNOWLEDGE");
- break;
- case READY:
- NXPLOG_FWDNLD_D("Received status: READY");
- break;
- case GENERIC_ERROR:
- NXPLOG_FWDNLD_D("Received status: GENERIC_ERROR");
- break;
- case MEMORY_ERROR:
- NXPLOG_FWDNLD_D("Received status: MEMORY_ERROR");
- break;
- case TIMEOUT_ERROR:
- NXPLOG_FWDNLD_D("Received status: TIMEOUT_ERROR");
- break;
- case CRC_ERROR:
- NXPLOG_FWDNLD_D("Received status: CRC_ERROR");
- break;
- case INVALID_ERROR:
- NXPLOG_FWDNLD_D("Received status: INVALID_ERROR");
- break;
- case INVALID_LENGTH_ERROR:
- NXPLOG_FWDNLD_D("Received status: INVALID_LENGTH_ERROR");
- break;
- case INVALID_ADDRESS_ERROR:
- NXPLOG_FWDNLD_D("Received status: INVALID_ADDRESS_ERROR");
- break;
- case ECC_SIGNATURE_ERROR:
- NXPLOG_FWDNLD_D("Received status: ECC_SIGNATURE_ERROR");
- break;
- case SHA384_HASH_ERROR:
- NXPLOG_FWDNLD_D("Received status: SHA384_HASH_ERROR");
- break;
- case LIFECYCLE_VALIDITY_ERROR:
- NXPLOG_FWDNLD_D("Received status: LIFECYCLE_VALIDITY_ERROR");
- break;
- case CHIP_ID_ERROR:
- NXPLOG_FWDNLD_D("Received status: CHIP_ID_ERROR");
- break;
- case CHIP_VERSION_ERROR:
- NXPLOG_FWDNLD_D("Received status: CHIP_VERSION_ERROR");
- break;
- case CERTIFICATE_VERSION_ERROR:
- NXPLOG_FWDNLD_D("Received status: CERTIFICATE_VERSION_ERROR");
- break;
- case FIRMWARE_VERSION_ERROR:
- NXPLOG_FWDNLD_D("Received status: FIRMWARE_VERSION_ERROR");
- break;
- case SRAM_DOWNLOAD_ALLOW_ERROR:
- NXPLOG_FWDNLD_D("Received status: SRAM_DOWNLOAD_ALLOW_ERROR");
- break;
- case KEY_DERIVATION_ERROR:
- NXPLOG_FWDNLD_D("Received status: KEY_DERIVATION_ERROR");
- break;
- case ENCRYPTED_PAYLOAD_DECRYPTION_ERROR:
- NXPLOG_FWDNLD_D("Received status: ENCRYPTED_PAYLOAD_DECRYPTION_ERROR");
- break;
- case INVALID_ENCRYPTED_PAYLOAD_ERROR:
- NXPLOG_FWDNLD_D("Received status: INVALID_ENCRYPTED_PAYLOAD_ERROR");
- break;
- case PROTECTED_CACHE_LOAD_ERROR:
- NXPLOG_FWDNLD_D("Received status: PROTECTED_CACHE_LOAD_ERROR");
- break;
- case PROTECTED_CACHE_DEPLOY_ERROR:
- NXPLOG_FWDNLD_D("Received status: PROTECTED_CACHE_DEPLOY_ERROR");
- break;
- case LIFECYCLE_UPDATE_ERROR:
- NXPLOG_FWDNLD_D("Received status: LIFECYCLE_UPDATE_ERROR");
- break;
- case FLASH_BLANK_PAGE_ERROR:
- NXPLOG_FWDNLD_D("Received status: FLASH_BLANK_PAGE_ERROR");
- break;
- case FLASH_CHECK_MARGIN_ERROR:
- NXPLOG_FWDNLD_D("Received status: FLASH_CHECK_MARGIN_ERROR");
- break;
- default:
- break;
- };
-}
-
-/*******************************************************************************
-**
-** Function : process_hdll_response
-**
-** Description : This function processes the HDLL response
-
-** Parameters : hdllCmdRsp - HDLL command response structure which has the
- received response info as well as the expected
- response info.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-
-/*
- * HDLL Response:
- * <-------HDLL Header--->|<------------------HDLL payload--------------------->
- * <-------HDLL (2bytes)->|<-----HCP (2bytes)------->|<-Application--> <--CRC-->
- * <31 30> <29> <28 -16> |<15 -14><13 - 8> <7 - 0> |<status><Payload><2 bytes>
- * <--R--><Chunk><length> |< Type ><Group><Operation>|<1 byte>
- *
- */
-phFWD_Status_t process_hdll_response(phHDLLCmdRsp_t *hdllCmdRsp) {
- uint8_t hdll_msg_type = 0;
- uint8_t hdll_rsp_status = 0;
- uint16_t hdll_packet_len = 0;
- uint8_t hdll_group = 0;
- uint8_t hdll_operation = 0;
- uint8_t *hdll_payload = NULL;
- uint16_t hdll_payload_len = 0;
- phFWD_Status_t ret = FW_DNLD_FAILURE;
-
- if (hdllCmdRsp == NULL || hdllCmdRsp->rsp_buf == NULL) {
- NXPLOG_FWDNLD_E("%s HDLL response buffer is NULL\n", __func__);
- return ret;
- }
- if (hdllCmdRsp->rsp_buf_len < HDLL_MIN_RSP_LEN) {
- NXPLOG_FWDNLD_E(
- "%s Error! HDLL response buffer length is %d, expected min %d bytes\n",
- __func__, hdllCmdRsp->rsp_buf_len, HDLL_MIN_RSP_LEN);
- return ret;
- }
-
- // parse hdll frame
- hdll_packet_len = (uint16_t)(hdllCmdRsp->rsp_buf[0] << 8) |
- (hdllCmdRsp->rsp_buf[HDLL_LEN_OFFSET]);
- hdll_packet_len &= HDLL_PKT_LEN_BITMASK;
- NXPLOG_FWDNLD_D("Received RSP packet len :0x%04X\n", hdll_packet_len);
- if (hdll_packet_len == 0) {
- NXPLOG_FWDNLD_D("Error in hdll response.. hdll_packet_len = 0\n");
- return ret;
- }
-
- hdll_msg_type = hdllCmdRsp->rsp_buf[HDLL_TYPE_OFFSET] >> HCP_GROUP_LEN;
- hdll_group =
- (hdllCmdRsp->rsp_buf[HDLL_GROUP_OFFSET] & HDLL_RSP_GROUP_BIT_MASK);
- hdll_operation = hdllCmdRsp->rsp_buf[HDLL_OPERATION_OFFSET];
- hdll_rsp_status = hdllCmdRsp->rsp_buf[HDLL_RSP_STATUS_OFFSET];
-
- NXPLOG_FWDNLD_D("Received RSP msg type :0x%02X\n", hdll_msg_type);
- NXPLOG_FWDNLD_D("Received RSP group operation :0x%02X%02X\n", hdll_group,
- hdll_operation);
- NXPLOG_FWDNLD_D("Received RSP status code :0x%02X\n", hdll_rsp_status);
- printHDLLRspStatus(hdll_rsp_status);
-
- hdll_payload_len = hdllCmdRsp->rsp_buf_len - (HDLL_RSP_PAYLOAD_OFFSET + HDLL_CRC_LEN);
- NXPLOG_FWDNLD_D("hdll payload len = 0x%02x" , hdll_payload_len);
-
- if (hdll_payload_len > 0) {
- hdll_payload = (uint8_t *)malloc(
- sizeof(uint8_t) *
- (hdll_payload_len));
- if (NULL == hdll_payload) {
- return ret;
- }
- memcpy(hdll_payload, &hdllCmdRsp->rsp_buf[HDLL_RSP_PAYLOAD_OFFSET],
- hdll_payload_len);
- }
-
- // validate the response
- if (hdllCmdRsp->status != hdll_rsp_status) {
- NXPLOG_FWDNLD_D("Error! expected response status code is 0x%02X but "
- "received 0x%02X\n",
- hdllCmdRsp->status, hdll_rsp_status);
- ret = FW_DNLD_FAILURE;
- } else if (hdllCmdRsp->type != hdll_msg_type) {
- NXPLOG_FWDNLD_D(
- "Error! expected HDLL type code is 0x%02X but received 0x%02X\n",
- hdllCmdRsp->type, hdll_msg_type);
- ret = FW_DNLD_FAILURE;
- } else if ((hdllCmdRsp->group != hdll_group) ||
- (hdllCmdRsp->operation != hdll_operation)) {
- NXPLOG_FWDNLD_D("Error! expected response operation code is 0x%02X%02X but "
- "received 0x%02X%02X \n",
- hdllCmdRsp->group, hdllCmdRsp->operation, hdll_group,
- hdll_operation);
- ret = FW_DNLD_FAILURE;
- } else
- {
- ret = FW_DNLD_SUCCESS;
- }
-
- if (ret == FW_DNLD_FAILURE){
- goto exit;
- }
-
- // Handle the response according to the operation
- switch (hdll_group) {
- case HCP_OPERATION_GROUP_PROTOCOL: {
- switch (hdll_operation) {
- case PROTOCOL_GROUP_OP_CODE_HDLL: {
- NXPLOG_FWDNLD_D("Received PROTOCOL_GROUP_HDLL_OP_CODE\n");
- } break;
- case PROTOCOL_GROUP_OP_CODE_HCP: {
- NXPLOG_FWDNLD_D("Received PROTOCOL_GROUP_HCP_OP_CODE\n");
- } break;
- case PROTOCOL_GROUP_OP_CODE_EDL: {
- NXPLOG_FWDNLD_D("Received PROTOCOL_GROUP_EDL_OP_CODE\n");
- } break;
- }
- } break;
-
- case HCP_OPERATION_GROUP_GENERIC: {
- switch (hdll_operation) {
- case GENERIC_GROUP_OP_CODE_RESET: {
- NXPLOG_FWDNLD_D("Received OP_GENERIC_RESET\n");
- // Generic reset cmd will have the rsp only in case of error.
- // How to handle the situation.
- } break;
- case GENERIC_GROUP_OP_CODE_GETINFO: {
- NXPLOG_FWDNLD_D("Received OP_GENERIC_GET_INFO\n");
- if (hdll_payload != NULL) {
- ret = handleGetInfoRsp(hdll_payload);
- }
- } break;
- }
- } break;
-
- case HCP_OPERATION_GROUP_EDL: {
- switch (hdll_operation) {
- case EDL_DOWNLOAD_CERTIFICATE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_CERTIFICATE\n");
- } break;
- case EDL_DOWNLOAD_FLASH_WRITE_FIRST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_FLASH_WRITE_FIRST\n");
- }
- break;
- case EDL_DOWNLOAD_FLASH_WRITE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_FLASH_WRITE\n");
- } break;
- case EDL_DOWNLOAD_FLASH_WRITE_LAST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_FLASH_WRITE_LAST\n");
- } break;
- case EDL_DOWNLOAD_SRAM_WRITE_FIRST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_SRAM_WRITE_FIRST\n");
- } break;
- case EDL_DOWNLOAD_SRAM_WRITE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_SRAM_WRITE\n");
- } break;
- case EDL_DOWNLOAD_SRAM_WRITE_LAST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_DOWNLOAD_SRAM_WRITE_LAST\n");
- } break;
- case EDL_LIFECYCLE_CERTIFICATE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_LIFECYCLE_CERTIFICATE\n");
- } break;
- case EDL_LIFECYCLE_WRITE_FIRST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_LIFECYCLE_WRITE_FIRST\n");
- } break;
- case EDL_LIFECYCLE_WRITE_LAST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_LIFECYCLE_WRITE_LAST\n");
- } break;
- case EDL_PATCH_SRAM_WRITE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_PATCH_SRAM_WRITE\n");
- } break;
- case EDL_PATCH_SRAM_WRITE_LAST: {
- NXPLOG_FWDNLD_D("Received OP_EDL_PATCH_SRAM_WRITE_LAST\n");
- } break;
- case EDL_PATCH_FLASH_WRITE: {
- NXPLOG_FWDNLD_D("Received OP_EDL_PATCH_FLASH_WRITE\n");
- } break;
- }
- } break;
- default:
- break;
- }
-
-exit:
- if (hdll_payload != NULL) {
- free(hdll_payload);
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlDownloadCertificateCmd
-**
-** Description : This function frames the EdlDownloadCertificateCmd which
- needs to be sent as part of FW download sequence.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlDownloadCertificateCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
-
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving OP_EDL_DOWNLOAD_CERTIFICATE "
- "cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_DOWNLOAD_CERTIFICATE;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlFlashWriteFirstCmd
-**
-** Description : This function frames the EdlFlashWriteFirstCmd which
- needs to be sent as part of FW download sequence.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlFlashWriteFirstCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving "
- "OP_EDL_DOWNLOAD_FLASH_WRITE_FIRST cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_DOWNLOAD_FLASH_WRITE_FIRST;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlFlashWriteCmd
-**
-** Description : This function frames the sendEdlFlashWriteCmd which
- will have the actual FW chunk.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlFlashWriteCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving OP_EDL_DOWNLOAD_FLASH_WRITE "
- "cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_DOWNLOAD_FLASH_WRITE;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlFlashWriteLastCmd
-**
-** Description : This function frames the EdlFlashWriteLastCmd which
- needs to be sent as part of FW download sequence.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlFlashWriteLastCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving "
- "OP_EDL_DOWNLOAD_FLASH_WRITE_LAST cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_DOWNLOAD_FLASH_WRITE_LAST;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlLifecycleCertificateCmd
-**
-** Description : This function frames the EdlLifecycleCertificateCmd which
- needs to be sent as part of Lifecycle update.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlLifecycleCertificateCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving "
- "EDL_LIFECYCLE_CERTIFICATE cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_LIFECYCLE_CERTIFICATE;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlLifecycleWriteFirstCmd
-**
-** Description : This function frames the EdlLifecycleWriteFirstCmd which
- needs to be sent as part of Lifecycle update.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlLifecycleWriteFirstCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving "
- "EDL_LIFECYCLE_WRITE_FIRST cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_LIFECYCLE_WRITE_FIRST;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlLifecycleWriteLastCmd
-**
-** Description : This function frames the EdlLifecycleWriteLastCmd which
- needs to be sent as part of Lifecycle update.
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlLifecycleWriteLastCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving "
- "EDL_LIFECYCLE_WRITE_LAST cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_LIFECYCLE_WRITE_LAST;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlPatchFlashWriteCmd
-**
-** Description : This function frames the sendEdlPatchlFlashWriteCmd which
- will send the EDL Patch Flash Write cmd
-**
-** Parameters : payload - HDLL command buffer
- len - command buffer length
- rsp_buf - response buffer that will be received from the
- HeliosX chip.
-**
-** Returns : FW_DNLD_FAILURE - If any undesired response received
- FW_DNLD_SUCCESS - On proper response
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlPatchFlashWriteCmd(uint8_t *payload, uint16_t len,
- uint8_t *rsp_buf) {
- uint16_t rsp_buf_len = 0x0;
- phFWD_Status_t ret = FW_DNLD_SUCCESS;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- ret = phGenericSendAndRecv(payload, len, rsp_buf, &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving OP_EDL_PATCH_FLASH_WRITE "
- "cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_EDL;
- hdllCmdRsp->operation = EDL_PATCH_FLASH_WRITE;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phHal_Host_CalcCrc16
-**
-** Description : This function calculates the HDLL command's CRC
-**
-** Parameters : p - HDLL command buffer
- dwLength - command buffer length
-**
-** Returns : the calculated CRC value
-**
-**
-*******************************************************************************/
-static uint16_t phHal_Host_CalcCrc16(uint8_t *p, uint32_t dwLength) {
- uint32_t i;
- uint16_t crc_new;
- uint16_t crc = 0xffffU;
-
- for (i = 0; i < dwLength; i++) {
- crc_new = (uint8_t)(crc >> 8) | (crc << 8);
- crc_new ^= p[i];
- crc_new ^= (uint8_t)(crc_new & 0xff) >> 4;
- crc_new ^= crc_new << 12;
- crc_new ^= (crc_new & 0xff) << 5;
- crc = crc_new;
- }
- return crc;
-}
-
-/*******************************************************************************
-**
-** Function : phBuildHdllCmd
-**
-** Description : This function frames the final HDLL command (HDLL header +
- HDLL payload + CRC) by framing HDLL payload and HDLL frame
- using 2 different APIs.
-**
-** Parameters : hdllCmd - HDLL command structure which has the information
- to build the corresponding HDLL command.
-**
-** Returns : NULL - on failure
- HDLL command buffer - On success
-**
-**
-*******************************************************************************/
-
-/*
- * HDLL Command:
- * <--------HDLL Header---->|<------------------HDLL payload------------------->
- * <--------HDLL (2bytes)-->|<-----HCP (2bytes)------->|<-Application-><--CRC-->
- * <31 30> <29> <28 -16> |<15 -14><13 - 8><7 - 0> |<---Payload---><2 bytes>
- * <--R--> <Chunk> <length> |< Type ><Group><Operation>|
- *
- */
-
-uint8_t *phBuildHdllCmd(phHDLLCmd_t *hdllCmd) {
- uint8_t type = 0;
- uint8_t *hdll_frame = NULL;
- uint16_t hdll_frame_size = 0;
- uint16_t hdll_crc = 0x0;
- uint16_t hdll_header = 0x0;
- NXPLOG_FWDNLD_D("phBuildHdllCmd:\n");
-
- if (NULL == hdllCmd) {
- return NULL;
- }
- // header len =2 bytes + hdll_payload_len + crc =2 bytes
- hdll_frame_size = HDLL_HEADER_LEN + HCP_MSG_HEADER_LEN +
- hdllCmd->payload_len + HDLL_CRC_LEN;
- hdll_frame = (uint8_t *)malloc(sizeof(uint8_t) * hdll_frame_size);
- if (NULL == hdll_frame) {
- return hdll_frame;
- }
-
- // build hdll frame
- hdll_header |= hdllCmd->payload_len + HCP_MSG_HEADER_LEN;
- hdll_header &= HDLL_PKT_LEN_BITMASK;
- hdll_header = hdllCmd->chunk_size ? (HDLL_PKT_CHUNK_BITMASK | hdll_header)
- : hdll_header;
-
- // hdll_header uint16 to uint8
- hdll_frame[HDLL_CHUNK_OFFSET] = (hdll_header >> 8);
- hdll_frame[HDLL_LEN_OFFSET] = (hdll_header & 0xFF);
-
- type = HCP_TYPE_COMMAND;
- type <<= HCP_GROUP_LEN;
- hdll_frame[HDLL_TYPE_OFFSET] = type | hdllCmd->group;
- hdll_frame[HDLL_OPERATION_OFFSET] = hdllCmd->operation;
-
- if (hdllCmd->payload_len > 0 && hdllCmd->payload != NULL) {
- // copy hdll payload into hdll frame
- memcpy(&hdll_frame[HDLL_PAYLOAD_OFFSET], hdllCmd->payload,
- hdllCmd->payload_len);
- }
-
- hdll_crc = phHal_Host_CalcCrc16(hdll_frame, hdll_frame_size - 2);
- hdll_frame[hdll_frame_size - 2] = (hdll_crc >> 8);
- hdll_frame[hdll_frame_size - 1] = (hdll_crc & 0xFF);
-
- hdllCmd->frame_size = hdll_frame_size;
- return hdll_frame;
-}
-
-/*******************************************************************************
-**
-** Function : sendEdlResetCmd
-**
-** Description : This function frames the EdlResetCmd and sends to the HeliosX
- chip
-**
-** Parameters : None
-**
-** Returns : FW_DNLD_FAILURE - If any failure occurs while framing or
- sending the command or while receiving the
- response
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-phFWD_Status_t sendEdlResetCmd() {
- uint8_t rsp_buf[HDLL_READ_BUFF_SIZE] = {0};
- uint8_t *hdll_frame = NULL;
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- uint16_t rsp_buf_len = 0x0;
- phHDLLCmd_t *hdllCmd = NULL;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- hdllCmd = (phHDLLCmd_t *)malloc(sizeof(phHDLLCmd_t));
- if (NULL == hdllCmd) {
- goto exit;
- }
-
- hdllCmd->group = HCP_OPERATION_GROUP_GENERIC;
- hdllCmd->operation = GENERIC_GROUP_OP_CODE_RESET;
- hdllCmd->chunk_size = 0;
- hdllCmd->frame_size = 0;
- hdllCmd->payload = NULL;
- hdllCmd->payload_len = 0;
-
- hdll_frame = phBuildHdllCmd(hdllCmd);
- if (NULL == hdll_frame) {
- goto exit;
- }
- NXPLOG_FWDNLD_D("Sending operation: OP_GENERIC_RESET\n");
- ret = phGenericSendAndRecv(hdll_frame, hdllCmd->frame_size, rsp_buf,
- &rsp_buf_len);
- if (ret == FW_DNLD_FAILURE) {
- // treat is as success as generic reset will have response only if there
- // is an error.
- ret = FW_DNLD_SUCCESS;
- }
- if (rsp_buf_len > 0) {
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- ret = FW_DNLD_FAILURE;
- goto exit;
- }
- hdllCmdRsp->group = HCP_OPERATION_GROUP_GENERIC;
- hdllCmdRsp->operation = GENERIC_GROUP_OP_CODE_RESET;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
- }
-exit:
- if (hdll_frame != NULL) {
- free(hdll_frame);
- }
- if (NULL != hdllCmd) {
- free(hdllCmd);
- }
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phGetEdlReadyNtf
-**
-** Description : This function frames the GetEdlReadyNtf command and sends to
- the HeliosX chip
-**
-** Parameters : None
-**
-** Returns : FW_DNLD_FAILURE - If any failure occurs while framing or
- sending the command or while receiving the
- response
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-phFWD_Status_t phGetEdlReadyNtf() {
- uint8_t rsp_buf[HDLL_READ_BUFF_SIZE] = {0};
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- uint16_t rsp_buf_len = 0x0;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- NXPLOG_FWDNLD_D("Wait for EDL_READY notification\n");
- ret =
- phHdll_GetApdu((uint8_t *)&rsp_buf[0], HDLL_READ_BUFF_SIZE, &rsp_buf_len);
-
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving GET_EDL_READY cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_PROTOCOL;
- hdllCmdRsp->operation = PROTOCOL_GROUP_OP_CODE_EDL;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = READY;
- hdllCmdRsp->type = HCP_TYPE_NOTIFICATION;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phGenericGetInfo
-**
-** Description : This function frames the GenericGetInfo command and sends to
- the HeliosX chip
-**
-** Parameters : None
-**
-** Returns : FW_DNLD_FAILURE - If any failure occurs while framing or
- sending the command or while receiving the
- response
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-phFWD_Status_t phGenericGetInfo() {
- uint8_t rsp_buf[HDLL_READ_BUFF_SIZE] = {0};
- uint8_t *hdll_frame = NULL;
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- uint16_t rsp_buf_len = 0x0;
- phHDLLCmd_t *hdllCmd = NULL;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- hdllCmd = (phHDLLCmd_t *)malloc(sizeof(phHDLLCmd_t));
- if (NULL == hdllCmd) {
- ret = FW_DNLD_FAILURE;
- goto exit;
- }
- hdllCmd->group = HCP_OPERATION_GROUP_GENERIC;
- hdllCmd->operation = GENERIC_GROUP_OP_CODE_GETINFO;
- hdllCmd->chunk_size = 0;
- hdllCmd->frame_size = 0;
- hdllCmd->payload = NULL;
- hdllCmd->payload_len = 0;
-
- hdll_frame = phBuildHdllCmd(hdllCmd);
- if (NULL == hdll_frame) {
- goto exit;
- }
- NXPLOG_FWDNLD_D("Sending operation: OP_GENERIC_GET_INFO\n");
- ret = phGenericSendAndRecv(hdll_frame, hdllCmd->frame_size, rsp_buf,
- &rsp_buf_len);
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in sending/receiving hdll cmd/response\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- ret = FW_DNLD_FAILURE;
- goto exit;
- }
- hdllCmdRsp->group = HCP_OPERATION_GROUP_GENERIC;
- hdllCmdRsp->operation = GENERIC_GROUP_OP_CODE_GETINFO;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = GENERIC_SUCCESS;
- hdllCmdRsp->type = HCP_TYPE_RESPONSE;
- ret = process_hdll_response(hdllCmdRsp);
-exit:
- if (NULL != hdll_frame) {
- free(hdll_frame);
- }
- if (NULL != hdllCmd) {
- free(hdllCmd);
- }
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phHdll_GetHdllReadyNtf
-**
-** Description : This function frames the GetHdllReadyNtf command and sends to
- the HeliosX chip
-**
-** Parameters : None
-**
-** Returns : FW_DNLD_FAILURE - If any failure occurs while framing or
- sending the command or while receiving the
- response
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-phFWD_Status_t phHdll_GetHdllReadyNtf() {
- uint8_t rsp_buf[HDLL_READ_BUFF_SIZE] = {0};
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- uint16_t rsp_buf_len = 0x0;
- phHDLLCmdRsp_t *hdllCmdRsp = NULL;
-
- NXPLOG_FWDNLD_D("Wait for HDL_READY notification\n");
- ret =
- phHdll_GetApdu((uint8_t *)&rsp_buf[0], HDLL_READ_BUFF_SIZE, &rsp_buf_len);
-
- if (!rsp_buf_len || ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_D("Error in reading GET_HDL_READY notification\n");
- return ret;
- }
-
- hdllCmdRsp = (phHDLLCmdRsp_t *)malloc(sizeof(phHDLLCmdRsp_t));
- if (NULL == hdllCmdRsp) {
- return ret;
- }
-
- hdllCmdRsp->group = HCP_OPERATION_GROUP_PROTOCOL;
- hdllCmdRsp->operation = PROTOCOL_GROUP_OP_CODE_HDLL;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = READY;
- hdllCmdRsp->type = HCP_TYPE_NOTIFICATION;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (FW_DNLD_SUCCESS != ret) {
- // check whether we received EDL ready notification or not
- // if yes, perform FW download directly.
- hdllCmdRsp->group = HCP_OPERATION_GROUP_PROTOCOL;
- hdllCmdRsp->operation = PROTOCOL_GROUP_OP_CODE_EDL;
- hdllCmdRsp->rsp_buf = rsp_buf;
- hdllCmdRsp->rsp_buf_len = rsp_buf_len;
- hdllCmdRsp->status = READY;
- hdllCmdRsp->type = HCP_TYPE_NOTIFICATION;
- ret = process_hdll_response(hdllCmdRsp);
-
- if (FW_DNLD_SUCCESS == ret) {
- bSkipEdlCheck = true;
- }
- }
-
- if (NULL != hdllCmdRsp) {
- free(hdllCmdRsp);
- }
-
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phEdl_send_and_recv
-**
-** Description : This function sends and receives the EDL group commands and
- responses based on the given operation code.
-**
-** Parameters : hdll_data - HDLL command buffer
- hdll_data_len - HDLL command buffer len
- group - HCP group code
- operation - operation code.
-**
-** Returns : FW_DNLD_FAILURE - If any failure occurs while framing or
- sending the command or while receiving the
- response
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-
-phFWD_Status_t phEdl_send_and_recv(uint8_t *hdll_data, uint32_t hdll_data_len,
- uint8_t group, uint8_t operation) {
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- uint8_t rsp_buff[HDLL_READ_BUFF_SIZE] = {0};
-
- if (group != HCP_OPERATION_GROUP_EDL) {
- NXPLOG_FWDNLD_D("Error! HCP operation group is not EDL\n");
- return ret;
- }
- switch (operation) {
- case EDL_DOWNLOAD_CERTIFICATE: {
- ret = sendEdlDownloadCertificateCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_DOWNLOAD_FLASH_WRITE_FIRST: {
- ret = sendEdlFlashWriteFirstCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_DOWNLOAD_FLASH_WRITE: {
- ret = sendEdlFlashWriteCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_DOWNLOAD_FLASH_WRITE_LAST: {
- ret = sendEdlFlashWriteLastCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_LIFECYCLE_CERTIFICATE: {
- ret = sendEdlLifecycleCertificateCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_LIFECYCLE_WRITE_FIRST: {
- ret = sendEdlLifecycleWriteFirstCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_LIFECYCLE_WRITE_LAST: {
- ret = sendEdlLifecycleWriteLastCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
- case EDL_PATCH_FLASH_WRITE: {
- ret = sendEdlPatchFlashWriteCmd(hdll_data, hdll_data_len, rsp_buff);
- } break;
-
- default:
- break;
- }
- return ret;
-}
-
-/*******************************************************************************
-**
-** Function : phLoadFwBinary
-**
-** Description : This function reads the MW FW binary file and writes to
- HeliosX chip.
-**
-** Parameters : pfwImageCtx -> pointer to fw image context
-**
-** Returns : FW_DNLD_FAILURE - on failure
- FW_DNLD_SUCCESS - On success
-**
-**
-*******************************************************************************/
-phFWD_Status_t phLoadFwBinary(phUwbFWImageContext_t *pfwImageCtx) {
- uint32_t next_frame_first_byte_index = 0;
- uint8_t current_op_group;
- uint8_t current_op;
- uint32_t frame_payload_length = 0;
- uint32_t frame_length = 0;
- phFWD_Status_t status = FW_DNLD_FAILURE;
- uint8_t current_frame[MAX_FRAME_LEN] = {0};
-
- if (NULL == pfwImageCtx->fwImage) {
- return status;
- }
- NXPLOG_FWDNLD_D("phLoadFwBinary\n");
- while (1) {
- // compute next frame payload length
- // TODO: warning this is not HDLL fragmentation compatible (valid header can
- // have chunk flag (biy 10 (13)) set) Assuming header length is 2 bytes
- frame_payload_length = (pfwImageCtx->fwImage[next_frame_first_byte_index] << 8) +
- (pfwImageCtx->fwImage[next_frame_first_byte_index + 1]);
-
- // if max_payload_length is not None and (frame_payload_length >=
- // max_payload_length): raise Exception('Invalid SFWU content (not an HDLL
- // header).')
-
- // copy the header, the payload and the footer (crc) from the file bytes
- // into a byte array
- frame_length = frame_payload_length + HDLL_HEADER_LEN + HDLL_FOOTER_LEN;
- if (frame_length > MAX_FRAME_LEN) {
- NXPLOG_FWDNLD_E("%s: Error while performing FW download frame_length > "
- "MAX_FRAME_LEN\n",
- __func__);
- status = FW_DNLD_FAILURE;
- break;
- }
- memcpy(current_frame, &pfwImageCtx->fwImage[next_frame_first_byte_index],
- frame_length);
- current_op_group = current_frame[2];
- current_op = current_frame[3];
-
- status = phEdl_send_and_recv(current_frame, frame_length, current_op_group,
- current_op);
- if (status != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s: Error while performing FW download\n", __func__);
- break;
- }
-
- // update byte index
- next_frame_first_byte_index = next_frame_first_byte_index + frame_length;
-
- // check end of file
- if (next_frame_first_byte_index >= pfwImageCtx->fwImgSize) {
- break;
- }
- }
-
- // clean-up
- if (pfwImageCtx->fwImage != NULL) {
- if (pfwImageCtx->fw_dnld_config == BIN_FILE_BASED_FW_DOWNLOAD) {
- free(pfwImageCtx->fwImage);
- } else if (pfwImageCtx->fw_dnld_config == SO_FILE_BASED_FW_DOWNLOAD) {
- if (pfwImageCtx->gFwLib != NULL) {
- dlclose(pfwImageCtx->gFwLib);
- pfwImageCtx->gFwLib = NULL;
- }
- }
-
- pfwImageCtx->fwImage = NULL;
- }
- return status;
-}
-
-/******************************************************************************
- * Function phHandle_hdll_read_timeout_cb
- *
- * Description Timer call back function
- *
- * Returns None
- *
- ******************************************************************************/
-static void phHandle_hdll_read_timeout_cb(uint32_t timerId, void *pContext) {
- UNUSED(timerId);
- UNUSED(pContext);
- NXPLOG_FWDNLD_E("ERROR: phHandle_hdll_read_timeout_cb - HDLL read timeout\n");
- ioctl((intptr_t)tPalConfig.pDevHandle, SRXXX_SET_PWR, ABORT_READ_PENDING);
- isHdllReadTmeoutExpired = true;
-}
-
-/******************************************************************************/
-/* GLOBAL FUNCTIONS */
-/******************************************************************************/
-
-/*******************************************************************************
-**
-** Function : phHdll_GetApdu
-**
-** Description : This function reads the HDLL command's response from HeliosX
- chip over SPI.
-**
-** Parameters : pApdu - HDLL response buffer
- sz - Max buffer size to be read
- rsp_buf_len - HDLL response buffer length
-**
-** Returns : phFWD_Status_t : 0 - success
- 1 - failure
-**
-**
-*******************************************************************************/
-
-phFWD_Status_t phHdll_GetApdu(uint8_t *pApdu, uint16_t sz,
- uint16_t *rsp_buf_len) {
- // NXPLOG_FWDNLD_D("phHdll_GetApdu Enter\n");
- int ret_len = 0;
- int status = 0;
-
- if (sz == 0 || sz > PHHDLL_MAX_LEN_PAYLOAD_MISO) {
- NXPLOG_FWDNLD_E("ERROR: phHdll_GetApdu data len is 0 or greater than max "
- "palyload length supported\n");
- return FW_DNLD_FAILURE;
- }
-
- /* Start timer */
- status = phOsalUwb_Timer_Start(timeoutTimerId, HDLL_READ_OP_TIMEOUT,
- &phHandle_hdll_read_timeout_cb, NULL);
- if (UWBSTATUS_SUCCESS != status) {
- NXPLOG_FWDNLD_E("%s: Response timer not started!!!", __func__);
- return FW_DNLD_FAILURE;
- }
- ret_len = read((intptr_t)tPalConfig.pDevHandle, (void *)pApdu, (sz));
-
- if (true == isHdllReadTmeoutExpired) {
- isHdllReadTmeoutExpired = false;
- return FW_DNLD_FAILURE;
- } else {
- /* Stop Timer */
- status = phOsalUwb_Timer_Stop(timeoutTimerId);
- if (UWBSTATUS_SUCCESS != status) {
- NXPLOG_FWDNLD_E("%s: Response timer stop ERROR!!!", __func__);
- return FW_DNLD_FAILURE;
- }
- }
-
- if (ret_len <= 0) {
- NXPLOG_FWDNLD_E("ERROR: Get APDU %u bytes failed!\n", sz);
- return FW_DNLD_FAILURE;
- }
- *rsp_buf_len = ret_len;
- if (is_fw_download_log_enabled == 0x01) {
- phNxpUciHal_print_packet(NXP_TML_FW_DNLD_RSP_UWBS_2_AP, pApdu, ret_len);
- }
-
- return FW_DNLD_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function : phHdll_PutApdu
-**
-** Description : This function sends the HDLL command to HeliosX chip over SPI
-**
-** Parameters : pApdu - HDLL command to be sent
- sz - HDLL command length
-**
-** Returns : phFWD_Status_t : 0 - success
- 1 - failure
-**
-**
-*******************************************************************************/
-
-phFWD_Status_t phHdll_PutApdu(uint8_t *pApdu, uint16_t sz) {
- int ret;
- int numWrote = 0;
- if (is_fw_download_log_enabled == 0x01) {
- phNxpUciHal_print_packet(NXP_TML_FW_DNLD_CMD_AP_2_UWBS, pApdu, sz);
- }
-
- ret = write((intptr_t)tPalConfig.pDevHandle, pApdu, sz);
- if (ret > 0) {
- numWrote += ret;
- } else if (ret == 0) {
- NXPLOG_FWDNLD_E("_spi_write() EOF");
- return FW_DNLD_FAILURE;
- } else {
- NXPLOG_FWDNLD_E("_spi_write() errno : %x", ret);
- return FW_DNLD_FAILURE;
- }
- return FW_DNLD_SUCCESS;
-}
-
-/*******************************************************************************
- * Function hdll_fw_download
- *
- * Description This function is called by jni when wired mode is
- * performed.First SRXXX driver will give the access
- * permission whether wired mode is allowed or not
- * arg (0):
- * Returns FW_DNLD_SUCCESS - on success
- FW_DNLD_FAILURE - on failure
- FW_DNLD_FILE_NOT_FOUND - if the FW binary is not found or
- unable to open
- *
- ******************************************************************************/
-int hdll_fw_download()
-{
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- unsigned long num = 0;
- NXPLOG_FWDNLD_D("hdll_fw_download enter.....\n");
-
- isHdllReadTmeoutExpired = false;
- bSkipEdlCheck = false;
- if (NxpConfig_GetNum(NAME_UWB_FW_DOWNLOAD_LOG, &num, sizeof(num))) {
- is_fw_download_log_enabled = (uint8_t)num;
- ALOGD("NAME_UWB_FW_DOWNLOAD_LOG: 0x%02x\n", is_fw_download_log_enabled);
- } else {
- ALOGD("NAME_UWB_FW_DOWNLOAD_LOG: failed 0x%02x\n",
- is_fw_download_log_enabled);
- }
- ioctl((intptr_t)tPalConfig.pDevHandle, SRXXX_SET_FWD, PWR_ENABLE);
-
- ret = phHdll_GetHdllReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the hdll ready notification...\n",
- __func__,__LINE__);
- return ret;
- }
- /* Get the Device information */
- ret = phGenericGetInfo();
- if (ret == FW_DNLD_FILE_NOT_FOUND) {
- goto exit;
- }
-
- if (ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_E("%s: error in getting the getInfo notification...\n",
- __func__);
- return ret;
- }
-
- if (!bSkipEdlCheck) {
- if (ret == FW_DNLD_NOT_REQUIRED)
- {
- goto exit;
- }
- ret = phGetEdlReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s: error in getting the EDL ready notification...\n",
- __func__);
- return ret;
- }
- }
-
- if(fwImageCtx.fwRecovery)
- {
- /* perform FW recovery */
- ret = phNxpUciHal_fw_recovery(&fwImageCtx);
- if (ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_E("%s: error downloading recovery FW...\n",
- __func__);
- return ret;
- }
- // TODO: Remove this after recovrry FW tested added to avoid endless loop of fw download.
- fwImageCtx.fwRecovery = false;
- }
-
- /* */
- ret = phLoadFwBinary(&fwImageCtx);
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s: error in phLoadFwBinary...\n", __func__);
- return ret;
- }
-
-exit:
- // do chip reset
- phTmlUwb_Chip_Reset();
- ret = phHdll_GetHdllReadyNtf();
-
- ioctl((intptr_t)tPalConfig.pDevHandle, SRXXX_SET_FWD, PWR_DISABLE);
- NXPLOG_FWDNLD_D("hdll_fw_download completed.....\n");
- return ret;
-}
-
-/*******************************************************************************
- * Function phNxpUciHal_fw_recovery
- *
- * Description This function is use to download recovery FW
- * Returns FW_DNLD_SUCCESS - on success
- FW_DNLD_FAILURE - on failure
- FW_DNLD_FILE_NOT_FOUND - if the FW binary is not found or
- unable to open
- *
- ******************************************************************************/
-
-static phFWD_Status_t phNxpUciHal_fw_recovery(phUwbFWImageContext_t *pfwImageCtx) {
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- NXPLOG_FWDNLD_D("phNxpUciHal_fw_recovery enter.....\n");
-
- ret = phLoadFwBinary(pfwImageCtx);
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s: error in phLoadFwBinary...\n", __func__);
- return ret;
- }
-
- // do chip reset
- phTmlUwb_Chip_Reset();
- ret = phHdll_GetHdllReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the hdll ready notification...\n",
- __func__,__LINE__);
- return ret;
- }
- /* Get the Device information */
- ret = phGenericGetInfo();
- if (ret == FW_DNLD_FAILURE || ret == FW_DNLD_FILE_NOT_FOUND) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the getInfo notification...\n",
- __func__,__LINE__);
- return ret;
- }
-
- if (!bSkipEdlCheck) {
- if (ret == FW_DNLD_NOT_REQUIRED) {
- return ret;
- }
-
- ret = phGetEdlReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the EDL ready notification...\n",
- __func__,__LINE__);
- return ret;
- }
- }
-
- return ret;
-}
-
-/*******************************************************************************
- * Function phNxpUciHal_fw_lcrotation
- *
- * Description This function is use to download recovery FW
- * Returns FW_DNLD_SUCCESS - on success
- FW_DNLD_FAILURE - on failure
- FW_DNLD_FILE_NOT_FOUND - if the FW binary is not found or
- unable to open
- *
- ******************************************************************************/
-
-phFWD_Status_t phNxpUciHal_fw_lcrotation() {
- phFWD_Status_t ret = FW_DNLD_FAILURE;
- glcRotation = true;
- NXPLOG_FWDNLD_D("phNxpUciHal_fw_lcrotation enter.....\n");
-
- ioctl((intptr_t)tPalConfig.pDevHandle, SRXXX_SET_FWD, PWR_ENABLE);
-
- ret = phHdll_GetHdllReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the hdll ready notification...\n",
- __func__,__LINE__);
- return ret;
- }
- /* Get the Device information */
- ret = phGenericGetInfo();
- if (ret == FW_DNLD_FILE_NOT_FOUND) {
- goto exit;
- }
-
- if (ret == FW_DNLD_FAILURE) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the getInfo notification...\n",
- __func__,__LINE__);
- return ret;
- }
-
- if (!bSkipEdlCheck) {
-
- ret = phGetEdlReadyNtf();
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s:%d error in getting the EDL ready notification...\n",
- __func__,__LINE__);
- return ret;
- }
- }
- ret = phLoadFwBinary(&fwImageCtx);
- if (ret != FW_DNLD_SUCCESS) {
- NXPLOG_FWDNLD_E("%s: error in phLoadFwBinary...\n", __func__);
- glcRotation = false;
- return ret;
- }
- glcRotation = false;
-
-exit:
- // do chip reset
- phTmlUwb_Chip_Reset();
- ret = phHdll_GetHdllReadyNtf();
-
- ioctl((intptr_t)tPalConfig.pDevHandle, SRXXX_SET_FWD, PWR_DISABLE);
- NXPLOG_FWDNLD_D("hdll_fw_download completed.....\n");
- return ret;
-}
-
-/*******************************************************************************
- * Function setDeviceHandle
- *
- * Description This function sets the SPI device handle that needs to be
- used in this file for SPI communication
- * Parameters pDevHandle - SPI device handle
- * Returns None
- *
- ******************************************************************************/
-void setDeviceHandle(void *pDevHandle) {
- NXPLOG_FWDNLD_D("Set the device handle!\n");
- if (pDevHandle == NULL) {
- NXPLOG_FWDNLD_E("device handle is NULL!\n");
- } else {
- tPalConfig.pDevHandle = (void *)((intptr_t)pDevHandle);
- }
-}
diff --git a/halimpl/hal/sr200/fwd_hdll.h b/halimpl/hal/sr200/fwd_hdll.h
deleted file mode 100644
index 7b54a49..0000000
--- a/halimpl/hal/sr200/fwd_hdll.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright 2021-2023 NXP
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _PHNXPUCIHAL_FW_H
-#define _PHNXPUCIHAL_FW_H
-#include <stdint.h>
-
-#define PHHDLL_LEN_LRC (1U)
-#define PHHDLL_MAX_MISO_DATA_LEN (256U)
-#define PHHDLL_MAX_LEN_PAYLOAD_MISO (PHHDLL_MAX_MISO_DATA_LEN + PHHDLL_LEN_LRC)
-
-#define FILEPATH_MAXLEN 500
-#define FILENAME_MAXLEN 260
-
-#define HCP_MSG_HEADER_LEN 2
-#define HDLL_HEADER_LEN 2
-#define HDLL_FOOTER_LEN 2
-#define HDLL_CRC_LEN 2
-#define HDLL_PKT_CHUNK_BITMASK 0x2000
-#define HDLL_PKT_LEN_BITMASK 0x1FFF
-#define HCP_GROUP_LEN 6 // bits
-
-#define HDLL_CHUNK_OFFSET 0
-#define HDLL_LEN_OFFSET 1
-#define HDLL_TYPE_OFFSET 2
-#define HDLL_GROUP_OFFSET 2
-#define HDLL_OPERATION_OFFSET 3
-#define HDLL_PAYLOAD_OFFSET 4
-
-#define HDLL_RSP_STATUS_OFFSET 4
-#define HDLL_RSP_PAYLOAD_OFFSET 5
-
-#define HDLL_RSP_GROUP_BIT_MASK 0x3F
-#define HDLL_MIN_RSP_LEN 8
-#define MW_MAJOR_FW_VER_OFFSET 4
-#define MW_MINOR_FW_VER_OFFSET 5
-
-#define HDLL_READ_BUFF_SIZE 64
-#define HDLL_READ_OP_TIMEOUT 2000 /* 2 seconds timeout */
-
-#define BIN_FILE_BASED_FW_DOWNLOAD 0x00
-#define SO_FILE_BASED_FW_DOWNLOAD 0x01
-#define SESSION_CONTROL_OPEN 0x55
-
-/* Struct to frame HDLL command */
-typedef struct phHDLLCmd {
- uint8_t group;
- uint8_t operation;
- uint8_t chunk_size;
- uint16_t payload_len;
- uint16_t frame_size;
- uint8_t *payload;
-} phHDLLCmd_t;
-
-/* Struct to process HDLL response */
-typedef struct phHDLLCmdRsp {
- uint8_t *rsp_buf;
- uint8_t rsp_buf_len;
- uint8_t group;
- uint8_t operation;
- uint8_t status;
- uint8_t type;
-} phHDLLCmdRsp_t;
-
-/* HCP Operation Group */
-typedef enum {
- HCP_OPERATION_GROUP_PROTOCOL = 0x01,
- HCP_OPERATION_GROUP_GENERIC,
- HCP_OPERATION_GROUP_EDL
-} eHCP_OPERATION_GROUP_t;
-
-/* operation codes under protocol group */
-typedef enum {
- PROTOCOL_GROUP_OP_CODE_HDLL = 0x01,
- PROTOCOL_GROUP_OP_CODE_HCP,
- PROTOCOL_GROUP_OP_CODE_EDL
-} ePROTOCOL_GROUP_OP_CODE_t;
-
-/* operation codes under generic group */
-typedef enum {
- GENERIC_GROUP_OP_CODE_RESET = 0x01,
- GENERIC_GROUP_OP_CODE_GETINFO
-} eGENERIC_GROUP_OP_CODE_t;
-
-/* operation code under EDL group */
-typedef enum {
- EDL_DOWNLOAD_CERTIFICATE = 0x01,
- EDL_DOWNLOAD_FLASH_WRITE_FIRST = 0x02,
- EDL_DOWNLOAD_FLASH_WRITE = 0x03,
- EDL_DOWNLOAD_FLASH_WRITE_LAST = 0x04,
- EDL_DOWNLOAD_SRAM_WRITE_FIRST = 0x05,
- EDL_DOWNLOAD_SRAM_WRITE = 0x06,
- EDL_DOWNLOAD_SRAM_WRITE_LAST = 0x07,
- EDL_LIFECYCLE_CERTIFICATE = 0x11,
- EDL_LIFECYCLE_WRITE_FIRST = 0x12,
- EDL_LIFECYCLE_WRITE_LAST = 0x13,
- EDL_PATCH_SRAM_WRITE = 0x21,
- EDL_PATCH_SRAM_WRITE_LAST = 0x22,
- EDL_PATCH_FLASH_WRITE = 0x23
-} eEDL_GROUP_OP_CODE_t;
-
-/* UWB Device ROM Version */
-typedef enum {
- VER_A1V1 = 0x02,
- VER_A1V2 = 0x03,
-} eUWBD_Rom_Version_t;
-
-/* UWB AT page status */
-typedef enum {
- STATUS_PAGE_OK = 0x55,
- STATUS_RECOVERED_N_1 = 0x5A,
- STATUS_RECOVERED_N_2 = 0xA5,
- STATUS_PAGE_ERROR = 0xAA,
-} eUWBD_AT_Page_status_t;
-
-/* UWB Device lifecycle mode */
-typedef enum {
- UNKNOWN = 0xCCCCCCCC,
- DEGRADED_MODE = 0x5C5C5C5C,
- FLASH_TEST_MODE = 0xAAAAAAAA,
- DEVELOPMENT_MODE = 0xC5C5C5C5,
- CUSTOMER_MODE = 0xA5A5A5A5,
- PROTECTED_MODE = 0x55555555,
- NXP_RMA_MODE = 0x5A5A5A5A,
-} eUWBD_LC_mode_t;
-
-/* Struct to store the getinfo response */
-typedef struct phHDLLGetInfo {
- uint8_t boot_status;
- uint8_t session_control;
- uint8_t session_type;
- eUWBD_Rom_Version_t rom_version;
- eUWBD_AT_Page_status_t AT_page_status;
- uint8_t chip_major_ver;
- uint8_t chip_minor_ver;
- uint8_t fw_minor_ver;
- uint8_t fw_major_ver;
- uint8_t chip_variant[4];
- eUWBD_LC_mode_t device_life_cycle;
- uint8_t chip_id[16];
- uint8_t chip_id_crc[4];
-} phHDLLGetInfo_t;
-
-/* HCP type */
-typedef enum {
- HCP_TYPE_COMMAND = 0x00,
- HCP_TYPE_RESPONSE,
- HCP_TYPE_NOTIFICATION
-} eHCP_TYPE_t;
-
-/* Application status codes */
-typedef enum {
- /* Success */
- GENERIC_SUCCESS = 0x00,
- ACKNOWLEDGE = 0x01,
- READY = 0x02,
-
- /* Generic errors */
- GENERIC_ERROR = 0x80,
- MEMORY_ERROR = 0x81,
- TIMEOUT_ERROR = 0x82,
- CRC_ERROR = 0x83,
- INVALID_ERROR = 0x84,
-
- /* Verification errors */
- INVALID_LENGTH_ERROR = 0x90,
- INVALID_ADDRESS_ERROR = 0x91,
- ECC_SIGNATURE_ERROR = 0x92,
- SHA384_HASH_ERROR = 0x93,
- LIFECYCLE_VALIDITY_ERROR = 0x94,
- CHIP_ID_ERROR = 0x95,
- CHIP_VERSION_ERROR = 0x96,
- CERTIFICATE_VERSION_ERROR = 0x97,
- FIRMWARE_VERSION_ERROR = 0x98,
- SRAM_DOWNLOAD_ALLOW_ERROR = 0x99,
-
- /* Encryption errors */
- KEY_DERIVATION_ERROR = 0xA0,
- ENCRYPTED_PAYLOAD_DECRYPTION_ERROR = 0xA1,
- INVALID_ENCRYPTED_PAYLOAD_ERROR = 0xA2,
-
- /* N-1 & N-2 errors */
- PROTECTED_CACHE_LOAD_ERROR = 0xB0,
- PROTECTED_CACHE_DEPLOY_ERROR = 0xB1,
- LIFECYCLE_UPDATE_ERROR = 0xB2,
-
- /* Flash errors */
- FLASH_BLANK_PAGE_ERROR = 0xC0,
- FLASH_CHECK_MARGIN_ERROR = 0xC1
-} eAPPLICATION_STATUS_CODES_t;
-
-/* FW download status */
-typedef enum phFWD_Status {
- FW_DNLD_SUCCESS = 0x00,
- FW_DNLD_FAILURE = 0x01,
- FW_DNLD_REQUIRED = 0x02,
- FW_DNLD_NOT_REQUIRED = 0x03,
- FW_DNLD_FILE_NOT_FOUND = 0x14,
-} phFWD_Status_t;
-
-/* FW download flash config status */
-typedef enum phFWD_flash_Status {
- FLASH_UPPER_VER_UPDATE = 0x01,
- FLASH_FORCE_UPDATE = 0x02,
- FLASH_DIFFERENT_VER_UPDATE = 0x03,
-} phFWD_flash_Status_t;
-
-typedef struct phUwbFWImageContext
-{
- /* pointer to the FW image to be used */
- uint8_t *fwImage;
- /* size of fw image */
- uint32_t fwImgSize;
- /* FW FLASH update Options Configurations */
- uint8_t fw_flash_config;
- /* FW Download file Options Configurations */
- uint8_t fw_dnld_config;
- /* FW recovery */
- bool fwRecovery;
- void *gFwLib;
- /* default fw file path */
- char default_fw_path[FILEPATH_MAXLEN];
- /* Device Info */
- phHDLLGetInfo_t *deviceInfo;
-} phUwbFWImageContext_t;
-
-/* SR200 device config */
-typedef struct phPalSr200_Config {
- void* pDevHandle;
-} phPalSr200_Config_t;
-
-/* PWR States */
-typedef enum phSetPwrState{
- PWR_DISABLE = 0,
- PWR_ENABLE,
- ABORT_READ_PENDING
-} phSetPwrState_t;
-
-phPalSr200_Config_t tPalConfig;
-
-phFWD_Status_t phHdll_GetApdu(uint8_t *pApdu, uint16_t sz,
- uint16_t *rsp_buf_len);
-phFWD_Status_t phHdll_PutApdu(uint8_t *pApdu, uint16_t sz);
-
-#endif /* _PHNXPUCIHAL_FW_H */
diff --git a/halimpl/hal/sr200/phNxpUciHal_LC.cc b/halimpl/hal/sr200/phNxpUciHal_LC.cc
deleted file mode 100644
index 1a3d56f..0000000
--- a/halimpl/hal/sr200/phNxpUciHal_LC.cc
+++ /dev/null
@@ -1,498 +0,0 @@
-/*
- * Copyright 2012-2019, 2022-2023 NXP
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if 0
-
-#include <log/log.h>
-#include <phNxpLog.h>
-#include <cutils/properties.h>
-#include <phNxpUciHal.h>
-#include <phNxpUciHal_Adaptation.h>
-#include <phNxpUciHal_ext.h>
-#include <phTmlUwb.h>
-#include <phTmlUwb_spi.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <array>
-#include "hal_nxpuwb.h"
-#include "phNxpConfig.h"
-#include <android-base/stringprintf.h>
-
-#if (NXP_UWB_EXTNS == TRUE)
-#include "phNxpUciHalProp.h"
-#endif
-#include <phNxpUciHal_LC.h>
-
-using android::base::StringPrintf;
-
-phNxpUciHal_lcfwdl_Control_t nxpucihal_lcfwdl_ctrl;
-extern phNxpUciHal_Control_t nxpucihal_ctrl;
-extern bool uwb_get_platform_id;
-extern bool uwb_device_initialized;
-static uint8_t Rx_buffer[UCI_MAX_DATA_LEN];
-
-/**************** local methods used in this file only ************************/
-static tHAL_UWB_STATUS phNxpUciHal_performLcRotation();
-static void* phNxpUciHal_lcfwdl_thread(void* arg);
-
-/******************************************************************************
- * Function phNxpUciHal_lcfwdl_thread
- *
- * Description This function is a thread handler which handles all TML and
- * UCI messages.
- *
- * Returns void
- *
- ******************************************************************************/
-static void* phNxpUciHal_lcfwdl_thread(void* arg) {
- phNxpUciHal_lcfwdl_Control_t* p_nxpucihal_lcfwdl_ctrl = (phNxpUciHal_lcfwdl_Control_t*)arg;
- tHAL_UWB_STATUS status = UWBSTATUS_FAILED;
-
- NXPLOG_UCIHAL_D("lcfwdl thread started");
- p_nxpucihal_lcfwdl_ctrl->lcfwdl_thread_running = 1;
-
- while (p_nxpucihal_lcfwdl_ctrl->lcfwdl_thread_running == 1) {
-
- if (p_nxpucihal_lcfwdl_ctrl->lcfwdl_thread_running == 0) {
- break;
- }
-
- if(p_nxpucihal_lcfwdl_ctrl->isPlatformIdSet) {
- status = phNxpUciHal_performLcRotation();
- if (nxpucihal_ctrl.p_uwb_stack_cback != NULL) {
- /* Send binding status cached ntf event */
- if ((nxpucihal_ctrl.p_uwb_stack_data_cback != NULL) && (nxpucihal_lcfwdl_ctrl.rcv_data_len <= UCI_MAX_PAYLOAD_LEN)) {
- if(status != UWBSTATUS_SUCCESS) {
- /* lc rotation FW fwdl failed cased */
- NXPLOG_UCIHAL_E("phNxpUciHal_performLcRotation failed...");
- nxpucihal_lcfwdl_ctrl.rcv_data[4] = 0x04;
- }
- (*nxpucihal_ctrl.p_uwb_stack_data_cback)(nxpucihal_lcfwdl_ctrl.rcv_data_len, nxpucihal_lcfwdl_ctrl.rcv_data);
- }
- }
- } else {
- if (nxpucihal_ctrl.p_uwb_stack_cback != NULL) {
- /* Send binding status cached ntf event */
- if ((nxpucihal_ctrl.p_uwb_stack_data_cback != NULL) && (nxpucihal_lcfwdl_ctrl.rcv_data_len <= UCI_MAX_PAYLOAD_LEN)) {
- /* lc rotation FW fwdl failed cased */
- NXPLOG_UCIHAL_E("%s Platform Id is not set...", __func__);
- nxpucihal_lcfwdl_ctrl.rcv_data[4] = 0x04;
- (*nxpucihal_ctrl.p_uwb_stack_data_cback)(nxpucihal_lcfwdl_ctrl.rcv_data_len, nxpucihal_lcfwdl_ctrl.rcv_data);
- }
- }
- }
- p_nxpucihal_lcfwdl_ctrl->isLcRotationOngoing = 0;
- p_nxpucihal_lcfwdl_ctrl->lcfwdl_thread_running = 0;
-
- break;
- }
-
- NXPLOG_UCIHAL_D("lcfwdl thread stopped");
- pthread_attr_destroy(&nxpucihal_lcfwdl_ctrl.attr_thread);
- pthread_exit(NULL);
- return NULL;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_parsePlatformId
- *
- * Description This function parse GetPlatformId response.
- *
- * Returns void
- *
- ******************************************************************************/
-void phNxpUciHal_parsePlatformId(uint8_t * p_rx_data , uint16_t rx_data_len) {
- uint8_t index = UCI_MSG_HDR_SIZE; // Excluding the header and Versions
- uint8_t * pUwbsRsp = NULL;
- uint16_t uwbsRspLen = 0;
- uint8_t getCalibStatus = UWBSTATUS_FAILED;
- uint8_t getCalibState;
- uint8_t count = 0;
- NXPLOG_UCIHAL_D("phNxpUciHal_parsePlatformId enter ....");
-
- pUwbsRsp = (uint8_t*)malloc(sizeof(uint8_t) * rx_data_len);
- if(pUwbsRsp == NULL) {
- NXPLOG_UCIHAL_E("pUwbsRsp memory allocation failed");
- return;
- }
- memcpy(&pUwbsRsp[0], &p_rx_data[0], rx_data_len);
- if (rx_data_len < UCI_MSG_HDR_SIZE){
- NXPLOG_UCIHAL_E("%s : Invalid rsp length", __func__);
- free(pUwbsRsp);
- return;
- }
- uwbsRspLen = rx_data_len ;
- getCalibStatus = pUwbsRsp[index++];
- NXPLOG_UCIHAL_D("getCalibStatus %d" , getCalibStatus);
- if(getCalibStatus == UWBSTATUS_SUCCESS) {
- getCalibState = pUwbsRsp[index++];
- if (getCalibState == 0x08) {
- NXPLOG_UCIHAL_D("Platform ID not Set");
- uwb_get_platform_id = false;
- free(pUwbsRsp);
- return;
- } else {
- do {
- nxpucihal_lcfwdl_ctrl.uwbsPlatformId[count++] = pUwbsRsp[index++];
- } while(index < uwbsRspLen);
- }
- nxpucihal_lcfwdl_ctrl.isPlatformIdSet = true;
- uwb_get_platform_id = false;
- NXPLOG_UCIHAL_D("Platform ID: %s", nxpucihal_lcfwdl_ctrl.uwbsPlatformId);
- }
- free(pUwbsRsp);
- return;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_parseUWBSLifecycle
- *
- * Description This function parse UWBS Lifecycle response.
- *
- * Returns UWBS Lifecycle.
- *
- ******************************************************************************/
-uint32_t phNxpUciHal_parseUWBSLifecycle(uint8_t * p_rx_data , uint16_t rx_data_len) {
- uint8_t index = UCI_MSG_HDR_SIZE; // Excluding the header and Versions
- uint8_t paramId = 0;
- uint8_t length = 0;
- uint32_t uwbsLc = 0;
- uint8_t * pUwbsDeviceInfo = NULL;
- uint16_t pUwbsDeviceInfoLen = 0;
- uint8_t getDeviceInfostatus = UWBSTATUS_FAILED;
- NXPLOG_UCIHAL_D("phNxpUciHal_parseUWBSLifecycle enter ....");
-
- pUwbsDeviceInfo = (uint8_t*)malloc(sizeof(uint8_t) * rx_data_len);
- if(pUwbsDeviceInfo == NULL) {
- NXPLOG_UCIHAL_E("pUwbsDeviceInfo memory allocation failed");
- return uwbsLc;
- }
- memcpy(&pUwbsDeviceInfo[0], &p_rx_data[0], rx_data_len);
- pUwbsDeviceInfoLen = rx_data_len ;
- getDeviceInfostatus = pUwbsDeviceInfo[index++];
- NXPLOG_UCIHAL_D("getDeviceInfostatus %d" , getDeviceInfostatus);
- if(getDeviceInfostatus == UWBSTATUS_SUCCESS)
- {
- index = index + UWB_INDEX_TO_RETRIEVE_PARAMS;
- uint8_t parameterLength = pUwbsDeviceInfo[index++];
- if (parameterLength > 0) {
- do {
- paramId = pUwbsDeviceInfo[index++];
- length = pUwbsDeviceInfo[index++];
- if ((paramId == UWBS_LIFECYCLE) && (length == UWBS_LIFECYCLE_LENGTH)) {
- uwbsLc = (pUwbsDeviceInfo[index] | (pUwbsDeviceInfo[index+1] << 8) | (pUwbsDeviceInfo[index+2] <<16) | (pUwbsDeviceInfo[index+3] <<24));
- break;
- } else {
- index = index + length;
- }
- } while(index < pUwbsDeviceInfoLen);
- }
- }
- NXPLOG_UCIHAL_D("UWBS Lifecycle: 0x%x", uwbsLc);
- free(pUwbsDeviceInfo);
- return uwbsLc;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_sendSetCoreConfigurations
- *
- * Description This function send Core device Config command.
- *
- * Returns status.
- *
- ******************************************************************************/
-static uint8_t phNxpUciHal_sendSetCoreConfigurations(){
- /* Disable Low power mode */
- const uint8_t setCoreConfigurations[] = {0x20, 0x04, 0x00, 0x04, 0x01, 0x01, 0x01, 0x00};
- tHAL_UWB_STATUS status = phNxpUciHal_send_ext_cmd(sizeof(setCoreConfigurations), setCoreConfigurations);
- if(status != UWBSTATUS_SUCCESS) {
- return status;
- }
- return status;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_sendGetDeviceCapInfo
- *
- * Description This function send Device Caps Info command.
- *
- * Returns status.
- *
- ******************************************************************************/
-static uint8_t phNxpUciHal_sendGetDeviceCapInfo(){
- const uint8_t buffer[] = {0x20, 0x03, 0x00, 0x00};
- tHAL_UWB_STATUS status = phNxpUciHal_send_ext_cmd(sizeof(buffer), buffer);
- if(status != UWBSTATUS_SUCCESS) {
- return status;
- }
- return status;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_setSecureConfig
- *
- * Description This function set secure calibration parameters from config file.
- *
- * Returns tHAL_UWB_STATUS.
- *
- ******************************************************************************/
-tHAL_UWB_STATUS phNxpUciHal_setSecureConfig() {
- NXPLOG_UCIHAL_D(" phNxpUciHal_setSecureConfig Enter..");
- std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
- uint8_t* vendorConfig = NULL;
- tHAL_UWB_STATUS status;
- buffer.fill(0);
- long retlen = 0;
- // Apply secure calibration
- for(int i = 1;i <= 10;i++) {
- std::string str = NAME_NXP_SECURE_CONFIG_BLK;
- std::string value = std::to_string(i);
- std::string name = str + value;
- NXPLOG_UCIHAL_D(" phNxpUciHal_setSecureConfig :: Name of the config block is %s", name.c_str());
- if (GetNxpConfigByteArrayValue(name.c_str(), (char*)buffer.data(), buffer.size(), &retlen)) {
- if ((retlen > 0) && (retlen <= UCI_MAX_DATA_LEN)) {
- vendorConfig = buffer.data();
- status = phNxpUciHal_send_ext_cmd(retlen,vendorConfig);
- NXPLOG_UCIHAL_D(" phNxpUciHal_send_ext_cmd :: status value for %s is %d ", name.c_str(),status);
- if(status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_D(" phNxpUciHal_send_ext_cmd :: setting %s is failed ", name.c_str());
- //skip returning error and go ahead with remaining blocks
- continue;
- }
- }
- } else {
- NXPLOG_UCIHAL_D(" phNxpUciHal_setSecureConfig::%s not available in the config file", name.c_str());
- }
- }
- return UWBSTATUS_SUCCESS;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_getPlatformId
- *
- * Description This function use to get platform ID.
- *
- * Returns tHAL_UWB_STATUS.
- *
- ******************************************************************************/
-tHAL_UWB_STATUS phNxpUciHal_getPlatformId() {
- NXPLOG_UCIHAL_D(" phNxpUciHal_getPlatformId Enter..");
- const uint8_t buffer[] = {0x2F, EXT_UCI_MSG_GET_CALIBRATION, 0x00, 0x02, 0x00, UCI_CALIB_PARAM_PLATFORM_ID};
- uwb_get_platform_id = true;
- tHAL_UWB_STATUS status = phNxpUciHal_send_ext_cmd(sizeof(buffer), buffer);
- if(status != UWBSTATUS_SUCCESS) {
- return status;
- }
- return UWBSTATUS_SUCCESS;
-}
-
-/******************************************************************************
- * Function phNxpUciHal_setPlatformId
- *
- * Description This function set platform ID given in config file.
- *
- * Returns tHAL_UWB_STATUS.
- *
- ******************************************************************************/
-tHAL_UWB_STATUS phNxpUciHal_setPlatformId() {
- NXPLOG_UCIHAL_D(" phNxpUciHal_setPlatformId Enter..");
- uint8_t *platformId = NULL;
- uint8_t buffer[UCI_MAX_DATA_LEN] = {0x00};
- tHAL_UWB_STATUS status;
-
- platformId = (uint8_t *)malloc(NXP_MAX_CONFIG_STRING_LEN * sizeof(uint8_t));
- if (platformId == NULL) {
- NXPLOG_FWDNLD_E("malloc of platformId failed ");
- return UWBSTATUS_FAILED;
- }
-
- if (GetNxpConfigStrValue(NAME_PLATFORM_ID, (char *)platformId, NXP_MAX_CONFIG_STRING_LEN)) {
- int platformIdLen = strlen((char*)platformId);
- NXPLOG_UCIHAL_D(" %s Platform ID: %s",__func__, platformId);
- buffer[0] = 0x2F;
- buffer[1] = EXT_UCI_MSG_SET_CALIBRATION;
- buffer[2] = 0x00;
- buffer[3] = platformIdLen + 3; //payload (channelid+calibparam+length+calibValue)
- buffer[4] = 0x00; //channel id
- buffer[5] = UCI_CALIB_PARAM_PLATFORM_ID;
- buffer[6] = platformIdLen;
- for(int i = 0 ; i < platformIdLen ; i++)
- {
- buffer[7 + i] = platformId[i];
- }
- int cmdLen = buffer[3] + UCI_MSG_HDR_SIZE;
-
- status = phNxpUciHal_send_ext_cmd(cmdLen,buffer);
- NXPLOG_UCIHAL_D(" phNxpUciHal_send_ext_cmd :: status value for PLATFORM_ID is %d ", status);
- } else {
- NXPLOG_UCIHAL_D(" %s :: PLATFORM_ID not available in the config file", __func__);
- status = UWBSTATUS_FAILED;
- }
-
- if (platformId != NULL) {
- free(platformId);
- }
- return status;
-}
-
-tHAL_UWB_STATUS phNxpUciHal_start_lcfwdl_thread() {
- NXPLOG_UCIHAL_D("phNxpUciHal_start_lcfwdl_thread enter....");
-
- nxpucihal_lcfwdl_ctrl.rcv_data_len = nxpucihal_ctrl.rx_data_len;
- memcpy(&nxpucihal_lcfwdl_ctrl.rcv_data[0], nxpucihal_ctrl.p_rx_data, nxpucihal_lcfwdl_ctrl.rcv_data_len);
-
- CONCURRENCY_LOCK();
- pthread_attr_init(&nxpucihal_lcfwdl_ctrl.attr_thread);
- pthread_attr_setdetachstate(&nxpucihal_lcfwdl_ctrl.attr_thread, PTHREAD_CREATE_DETACHED);
- if (pthread_create(&nxpucihal_lcfwdl_ctrl.lcfwdl_tread, &nxpucihal_lcfwdl_ctrl.attr_thread,
- phNxpUciHal_lcfwdl_thread, &nxpucihal_lcfwdl_ctrl) != 0) {
- NXPLOG_UCIHAL_E("pthread_create failed");
- CONCURRENCY_UNLOCK();
- return UWBSTATUS_FAILED;
- }
- CONCURRENCY_UNLOCK();
- return UWBSTATUS_SUCCESS;
-}
-
-static tHAL_UWB_STATUS phNxpUciHal_performLcRotation() {
- tHAL_UWB_STATUS status = UWBSTATUS_FAILED;
- uint8_t fwd_retry_count = 0;
-
- phTmlUwb_Spi_Reset();
- NXPLOG_UCIHAL_D(" Start LC rotation FW download");
- /* Create the local semaphore */
- if (phNxpUciHal_init_cb_data(&nxpucihal_ctrl.dev_status_ntf_wait, NULL) !=
- UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("Create dev_status_ntf_wait failed");
- return status;
- }
-
- uwb_device_initialized = false;
-fwd_retry:
- nxpucihal_ctrl.fw_dwnld_mode = true; /* system in FW download mode*/
- nxpucihal_ctrl.uwbc_device_state = UWB_DEVICE_STATE_UNKNOWN;
- status = phNxpUciHal_fw_lcrotation();
- if(status == UWBSTATUS_SUCCESS) {
- nxpucihal_ctrl.isSkipPacket = 1;
- status = phTmlUwb_Read( Rx_buffer, UCI_MAX_DATA_LEN,
- (pphTmlUwb_TransactCompletionCb_t)&phNxpUciHal_read_complete, NULL);
- if (status != UWBSTATUS_PENDING) {
- NXPLOG_UCIHAL_E("read status error status = %x", status);
- goto failure;
- }
- phNxpUciHal_sem_timed_wait(&nxpucihal_ctrl.dev_status_ntf_wait);
- if (nxpucihal_ctrl.dev_status_ntf_wait.status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY dev_status_ntf_wait semaphore timed out");
- goto failure;
- }
- NXPLOG_UCIHAL_D("uwbc_device_state: %d",nxpucihal_ctrl.uwbc_device_state);
- if(nxpucihal_ctrl.uwbc_device_state != UWB_DEVICE_READY) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY not received uwbc_device_state = %x",nxpucihal_ctrl.uwbc_device_state);
- goto failure;
- }
- nxpucihal_ctrl.isSkipPacket = 0;
- status = phNxpUciHal_set_board_config();
- if (status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("%s: Set Board Config Failed", __func__);
- goto failure;
- }
- phNxpUciHal_sem_timed_wait(&nxpucihal_ctrl.dev_status_ntf_wait);
- if (nxpucihal_ctrl.dev_status_ntf_wait.status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY dev_status_ntf_wait semaphore timed out");
- goto failure;
- }
- if(nxpucihal_ctrl.uwbc_device_state != UWB_DEVICE_READY) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY not received uwbc_device_state = %x",nxpucihal_ctrl.uwbc_device_state);
- goto failure;
- }
- NXPLOG_UCIHAL_D("%s: Send device reset", __func__);
- status = phNxpUciHal_uwb_reset();
- if (status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("%s: device reset Failed", __func__);
- goto failure;
- }
- phNxpUciHal_sem_timed_wait(&nxpucihal_ctrl.dev_status_ntf_wait);
- if (nxpucihal_ctrl.dev_status_ntf_wait.status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY dev_status_ntf_wait semaphore timed out");
- goto failure;
- }
- if(nxpucihal_ctrl.uwbc_device_state != UWB_DEVICE_READY) {
- NXPLOG_UCIHAL_E("UWB_DEVICE_READY not received uwbc_device_state = %x",nxpucihal_ctrl.uwbc_device_state);
- goto failure;
- }
-
- status = phNxpUciHal_applyVendorConfig();
- if (status != UWBSTATUS_SUCCESS) {
- // If vendor config is failed after LC rotation , as of now skip reporting error
- NXPLOG_UCIHAL_E("%s: Apply vendor Config Failed", __func__);
- }
-
- status = phNxpUciHal_setSecureConfig();
- if (status != UWBSTATUS_SUCCESS) {
- // If set secure calib param failed , as of now skip reporting error
- NXPLOG_UCIHAL_E("%s: Apply secure Config Failed", __func__);
- }
-
- status = phNxpUciHal_sendGetCoreDeviceInfo();
- if (status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("%s: phNxpUciHal_sendGetCoreDeviceInfo Failed", __func__);
- goto failure;
- }
-
- status = phNxpUciHal_sendSetCoreConfigurations();
- if (status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("%s: phNxpUciHal_setCoreConfigurations Failed", __func__);
- goto failure;
- }
- status = phNxpUciHal_sendGetDeviceCapInfo();
- if (status != UWBSTATUS_SUCCESS) {
- NXPLOG_UCIHAL_E("%s: phNxpUciHal_sendGetDeviceCapInfo Failed", __func__);
- goto failure;
- }
- uwb_device_initialized = true;
- } else if(status == UWBSTATUS_FILE_NOT_FOUND) {
- NXPLOG_UCIHAL_E("FW download File Not found: status= %x", status);
- goto failure;
- } else {
- NXPLOG_UCIHAL_E("FW download is failed FW download recovery starts: status= %x", status);
- fwd_retry_count++;
- if(fwd_retry_count <= FWD_MAX_RETRY_COUNT) {
- phTmlUwb_Chip_Reset();
- usleep(5000);
- goto fwd_retry;
- } else {
- goto failure;
- }
- }
- phNxpUciHal_cleanup_cb_data(&nxpucihal_ctrl.dev_status_ntf_wait);
- return status;
- failure:
- if(nxpucihal_ctrl.uwbc_device_state == UWB_DEVICE_ERROR) {
- phNxpUciHalProp_dump_fw_crash_log();
- if (UWBSTATUS_SUCCESS != phNxpUciHal_uwb_reset()) {
- NXPLOG_UCIHAL_E("%s: device reset Failed", __func__);
- } else {
- NXPLOG_UCIHAL_E("%s: device reset success", __func__);
- }
- phTmlUwb_Spi_Reset();
- goto fwd_retry;
- }
- phNxpUciHal_cleanup_cb_data(&nxpucihal_ctrl.dev_status_ntf_wait);
-
- return UWBSTATUS_FAILED;
-}
-
-#endif
\ No newline at end of file
diff --git a/halimpl/hal/sr200/phNxpUciHal_LC.h b/halimpl/hal/sr200/phNxpUciHal_LC.h
deleted file mode 100644
index 077b8a1..0000000
--- a/halimpl/hal/sr200/phNxpUciHal_LC.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2012-2020, 2023 NXP
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _PHNXPUCIHAL_LC_H_
-#define _PHNXPUCIHAL_LC_H_
-
-#include <phNxpUciHal.h>
-
-/* Macros for parsing GetDeviceInfo response */
-#define UWB_INDEX_TO_RETRIEVE_PARAMS 0x08
-#define UWBS_LIFECYCLE 0x06
-#define UWBS_LIFECYCLE_LENGTH 0x04
-
-/* LC Rotation data structure */
-typedef struct {
- pthread_attr_t attr_thread;
- pthread_t lcfwdl_tread; /* lcfwdl thread handle */
- uint8_t lcfwdl_thread_running;
- /* Rx data */
- uint8_t rcv_data[100];
- uint16_t rcv_data_len;
- /* To check LC rotation process*/
- uint8_t isLcRotationOngoing;
- /* UWBs device lifecycle */
- uint32_t uwbsDeviceLc;
- /* To check platformId */
- bool isPlatformIdSet;
- /* Platform ID */
- uint8_t uwbsPlatformId[NXP_MAX_CONFIG_STRING_LEN];
-}phNxpUciHal_lcfwdl_Control_t;
-
-#define UWBS_LC_DEVELOPMENT_MODE 0xC5C5C5C5
-#define UWBS_LC_CUSTOMER_MODE 0xA5A5A5A5
-#define UWBS_LC_PROTECTED_MODE 0x55555555
-
-extern phNxpUciHal_lcfwdl_Control_t nxpucihal_lcfwdl_ctrl;
-
-extern int phNxpUciHal_fw_lcrotation();
-tHAL_UWB_STATUS phNxpUciHal_start_lcfwdl_thread();
-uint32_t phNxpUciHal_parseUWBSLifecycle(uint8_t * p_rx_data , uint16_t rx_data_len);
-void phNxpUciHal_parsePlatformId(uint8_t * p_rx_data , uint16_t rx_data_len);
-tHAL_UWB_STATUS phNxpUciHal_getPlatformId();
-tHAL_UWB_STATUS phNxpUciHal_setPlatformId();
-tHAL_UWB_STATUS phNxpUciHal_setSecureConfig();
-
-#endif
diff --git a/halimpl/hal/sr200/phNxpUciHal_fwd_utils.h b/halimpl/hal/sr200/phNxpUciHal_fwd_utils.h
deleted file mode 100644
index 4b07a4e..0000000
--- a/halimpl/hal/sr200/phNxpUciHal_fwd_utils.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2022-2023 NXP
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdint.h>
-#include <stdio.h>
-
-#define __PACKED__ __attribute__((packed))
-
-#define MWCESFW_COUNT 0x08
-
-#define MWCESFW_A1V1_FW_OFFSET 0x00
-#define MWCESFW_A1V1_RECOVERY_FW_OFFSET 0x01
-#define MWCESFW_A1V2_FW_OFFSET 0x02
-#define MWCESFW_A1V2_RECOVERY_FW_OFFSET 0x03
-#define MWCESFW_A1V1_LC_FW_OFFSET 0x04
-#define MWCESFW_A1V2_LC_FW_OFFSET 0x05
-
-typedef struct __PACKED__ MWCESFW
-{
- uint32_t layout_version;
- uint8_t fw_ver_major;
- uint8_t fw_ver_minor;
- uint8_t fw_ver_dev;
- uint8_t fw_ver_is_to;
- uint8_t fw_ver_git_sha1[32];
- uint32_t fw_artifact_number;
- uint32_t lenCESFW;
- uint8_t *pCESFW;
-} MWCESFW_t;
-
-typedef struct __PACKED__ UWBManifest
-{
- uint32_t layout_version;
- uint8_t creation_date_yy;
- uint8_t creation_date_month;
- uint8_t creation_date_day;
- uint8_t creation_date_hour;
- uint8_t creation_date_minutes;
- uint8_t creation_date_seconds;
- uint8_t padding;
- uint8_t countMWCESFW;
- MWCESFW_t *mwCESFW[MWCESFW_COUNT];
-} UWBManifest_t;