mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-07 15:57:51 +01:00
RTL8720D (#1550)
* ambd * update sdk, get current fw idx * test * ota * reset if hard fault * revert and fix * uart flow control * disable uart tcp debug by default * test * wifi test * adjust lwip adjust scan * increase timeout * enable ssdp, close uart tcp sockets on restart * test * pwm * fix bl0942 * cut some code
This commit is contained in:
committed by
GitHub
parent
23e67076c3
commit
969e5bfa50
@@ -20,8 +20,6 @@
|
||||
#include "../driver/drv_ntp.h"
|
||||
#include "../driver/drv_local.h"
|
||||
|
||||
static char SUBMIT_AND_END_FORM[] = "<br><input type=\"submit\" value=\"Submit\"></form>";
|
||||
|
||||
#ifdef WINDOWS
|
||||
// nothing
|
||||
#elif PLATFORM_BL602
|
||||
@@ -41,12 +39,16 @@ static char SUBMIT_AND_END_FORM[] = "<br><input type=\"submit\" value=\"Submit\"
|
||||
#include "temp_detect_pub.h"
|
||||
#elif defined(PLATFORM_LN882H)
|
||||
#elif defined(PLATFORM_TR6260)
|
||||
#elif defined(PLATFORM_RTL87X0C)
|
||||
#include "hal_sys_ctrl.h"
|
||||
extern hal_reset_reason_t reset_reason;
|
||||
extern uint32_t current_fw_idx;
|
||||
#elif defined(PLATFORM_RTL8710B)
|
||||
extern uint32_t current_fw_idx;
|
||||
#elif defined(PLATFORM_REALTEK)
|
||||
#include "wifi_structures.h"
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_conf.h"
|
||||
extern uint32_t current_fw_idx;
|
||||
#ifdef PLATFORM_RTL87X0C
|
||||
#include "hal_sys_ctrl.h"
|
||||
extern hal_reset_reason_t reset_reason;
|
||||
#endif
|
||||
SemaphoreHandle_t scan_hdl;
|
||||
#elif defined(PLATFORM_ESPIDF)
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_system.h"
|
||||
@@ -63,6 +65,8 @@ int tuya_os_adapt_wifi_all_ap_scan(AP_IF_S** ap_ary, unsigned int* num);
|
||||
int tuya_os_adapt_wifi_release_ap(AP_IF_S* ap);
|
||||
#endif
|
||||
|
||||
static const char SUBMIT_AND_END_FORM[] = "<br><input type=\"submit\" value=\"Submit\"></form>";
|
||||
|
||||
|
||||
const char* g_typesOffLowMidHigh[] = { "Off","Low","Mid","High" };
|
||||
const char* g_typesOffLowMidHighHighest[] = { "Off", "Low","Mid","High","Highest" };
|
||||
@@ -909,7 +913,7 @@ typedef enum {
|
||||
}
|
||||
hprintf255(request, "<h5>Reboot reason: %i - %s</h5>", reset_reason, s);
|
||||
hprintf255(request, "<h5>Current fw: FW%i</h5>", current_fw_idx);
|
||||
#elif PLATFORM_RTL8710B
|
||||
#elif PLATFORM_RTL8710B || PLATFORM_RTL8720D
|
||||
hprintf255(request, "<h5>Current fw: FW%i</h5>", current_fw_idx + 1);
|
||||
#endif
|
||||
#if ENABLE_MQTT
|
||||
@@ -1289,11 +1293,6 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
#ifdef WINDOWS
|
||||
|
||||
poststr(request, "Not available on Windows<br>");
|
||||
#elif PLATFORM_XR809
|
||||
poststr(request, "TODO XR809<br>");
|
||||
|
||||
#elif PLATFORM_W600 || PLATFORM_W800
|
||||
poststr(request, "TODO W800<br>");
|
||||
#elif PLATFORM_BL602
|
||||
wifi_mgmr_ap_item_t *ap_info;
|
||||
uint32_t i, ap_num;
|
||||
@@ -1332,9 +1331,6 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
hprintf255(request, "[%i/%i] SSID: %s, Channel: %i, Signal %i<br>", i + 1, (int)num, ar[i].ssid, ar[i].channel, ar[i].rssi);
|
||||
}
|
||||
tuya_os_adapt_wifi_release_ap(ar);
|
||||
#elif PLATFORM_LN882H
|
||||
// TODO:LN882H action
|
||||
poststr(request, "TODO LN882H<br>");
|
||||
#elif PLATFORM_ESPIDF
|
||||
// doesn't work in ap mode, only sta/apsta
|
||||
uint16_t ap_count = 0, number = 30;
|
||||
@@ -1352,12 +1348,35 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
#elif PLATFORM_TR6260
|
||||
poststr(request, "TODO TR6260<br>");
|
||||
#elif defined(PLATFORM_REALTEK)
|
||||
poststr(request, "TODO Realtek<br>");
|
||||
#elif PLATFORM_BEKEN_NEW
|
||||
poststr(request, "TODO BEKEN_NEW<br>");
|
||||
#ifndef PLATFORM_RTL87X0C
|
||||
extern void rltk_wlan_enable_scan_with_ssid_by_extended_security(bool);
|
||||
#endif
|
||||
|
||||
rtw_result_t scan_result_handler(rtw_scan_handler_result_t* result)
|
||||
{
|
||||
http_request_t* request = (http_request_t*)result->user_data;
|
||||
|
||||
if(result->scan_complete == RTW_TRUE)
|
||||
{
|
||||
xSemaphoreGive(scan_hdl);
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
rtw_scan_result_t* record = &result->ap_details;
|
||||
record->SSID.val[record->SSID.len] = 0;
|
||||
hprintf255(request, "SSID: %s, Channel: %i, Signal %i<br>", record->SSID.val, record->channel, record->signal_strength);
|
||||
}
|
||||
|
||||
scan_hdl = xSemaphoreCreateBinary();
|
||||
rltk_wlan_enable_scan_with_ssid_by_extended_security(1);
|
||||
xSemaphoreTake(scan_hdl, 1);
|
||||
if(wifi_scan_networks(scan_result_handler, request) != RTW_SUCCESS)
|
||||
{
|
||||
poststr(request, "Wifi scan failed!<br>");
|
||||
}
|
||||
xSemaphoreTake(scan_hdl, pdMS_TO_TICKS(10 * 1000));
|
||||
vSemaphoreDelete(scan_hdl);
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
poststr(request, "Unknown platform<br>");
|
||||
hprintf255(request, "TODO %s<br>", PLATFORM_MCU_NAME);
|
||||
#endif
|
||||
}
|
||||
poststr(request, "<form action=\"/cfg_wifi\">\
|
||||
@@ -2145,8 +2164,10 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
}
|
||||
if (1) {
|
||||
//use -1 for channel as these don't correspond to channels
|
||||
#ifndef NO_CHIP_TEMPERATURE
|
||||
dev_info = hass_init_sensor_device_info(HASS_TEMP, -1, -1, -1, 1);
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
#endif
|
||||
dev_info = hass_init_sensor_device_info(HASS_RSSI, -1, -1, -1, 1);
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
@@ -3033,8 +3054,7 @@ void OTA_RequestDownloadFromHTTP(const char* s) {
|
||||
|
||||
#elif PLATFORM_ESPIDF
|
||||
#elif PLATFORM_TR6260
|
||||
#elif PLATFORM_RTL87X0C
|
||||
#elif PLATFORM_RTL8710B || PLATFORM_RTL8710A
|
||||
#elif PLATFORM_REALTEK
|
||||
#elif PLATFORM_W600 || PLATFORM_W800
|
||||
t_http_fwup(s);
|
||||
#elif PLATFORM_XR809
|
||||
|
||||
@@ -588,7 +588,7 @@ void setupAllWB2SPinsAsButtons() {
|
||||
// call with str == NULL to force send. - can be binary.
|
||||
// supply length
|
||||
int postany(http_request_t* request, const char* str, int len) {
|
||||
#if PLATFORM_BL602 || PLATFORM_BEKEN_NEW
|
||||
#if PLATFORM_BL602 || PLATFORM_BEKEN_NEW || PLATFORM_RTL8720D
|
||||
send(request->fd, str, len, 0);
|
||||
return 0;
|
||||
#else
|
||||
|
||||
@@ -237,6 +237,11 @@ static void tcp_server_thread(beken_thread_arg_t arg)
|
||||
{
|
||||
sock[new_idx].fd = accept(listen_sock, (struct sockaddr*)&source_addr, &addr_len);
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 30;
|
||||
tv.tv_usec = 0;
|
||||
setsockopt(sock[new_idx].fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof(tv));
|
||||
|
||||
if(sock[new_idx].fd < 0)
|
||||
{
|
||||
switch(errno)
|
||||
|
||||
@@ -58,14 +58,18 @@ uint32_t flash_read(uint32_t flash, uint32_t addr, void* buf, uint32_t size);
|
||||
|
||||
#elif PLATFORM_ESPIDF
|
||||
|
||||
#elif PLATFORM_RTL87X0C
|
||||
#elif PLATFORM_REALTEK
|
||||
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#include "ota_8710c.h"
|
||||
#include "sys_api.h"
|
||||
|
||||
extern flash_t flash;
|
||||
|
||||
#if PLATFORM_RTL87X0C
|
||||
|
||||
#include "ota_8710c.h"
|
||||
|
||||
extern uint32_t sys_update_ota_get_curr_fw_idx(void);
|
||||
extern uint32_t sys_update_ota_prepare_addr(void);
|
||||
extern void sys_disable_fast_boot(void);
|
||||
@@ -74,26 +78,31 @@ static flash_t flash_ota;
|
||||
|
||||
#elif PLATFORM_RTL8710B
|
||||
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#include "sys_api.h"
|
||||
#include "rtl8710b_ota.h"
|
||||
|
||||
extern flash_t flash;
|
||||
extern uint32_t current_fw_idx;
|
||||
|
||||
#elif PLATFORM_RTL8710A
|
||||
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#include "sys_api.h"
|
||||
|
||||
extern flash_t flash;
|
||||
extern uint32_t current_fw_idx;
|
||||
|
||||
#undef DEFAULT_FLASH_LEN
|
||||
#define DEFAULT_FLASH_LEN 0x400000
|
||||
|
||||
#elif PLATFORM_RTL8720D
|
||||
|
||||
#include "rtl8721d_boot.h"
|
||||
#include "rtl8721d_ota.h"
|
||||
#include "diag.h"
|
||||
#include "wdt_api.h"
|
||||
|
||||
extern uint32_t current_fw_idx;
|
||||
|
||||
#undef DEFAULT_FLASH_LEN
|
||||
#define DEFAULT_FLASH_LEN 0x400000
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
extern UINT32 flash_read(char* user_buf, UINT32 count, UINT32 address);
|
||||
@@ -2593,6 +2602,269 @@ update_ota_exit:
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "OTA failed");
|
||||
return http_rest_error(request, ret, "error");
|
||||
}
|
||||
|
||||
#elif PLATFORM_RTL8720D
|
||||
|
||||
int ret = -1;
|
||||
uint32_t ota_target_index = OTA_INDEX_2;
|
||||
update_file_hdr* pOtaFileHdr;
|
||||
update_file_img_hdr* pOtaFileImgHdr;
|
||||
update_ota_target_hdr OtaTargetHdr;
|
||||
uint32_t ImageCnt, TempLen;
|
||||
update_dw_info DownloadInfo[MAX_IMG_NUM];
|
||||
|
||||
int size = 0;
|
||||
int read_bytes;
|
||||
int read_bytes_buf;
|
||||
uint8_t* buf;
|
||||
uint32_t OtaFg = 0;
|
||||
uint32_t IncFg = 0;
|
||||
int RemainBytes = 0;
|
||||
uint32_t SigCnt = 0;
|
||||
uint32_t TempCnt = 0;
|
||||
uint8_t* signature;
|
||||
uint32_t sector_cnt = 0;
|
||||
|
||||
if(request->contentLength > 0)
|
||||
{
|
||||
towrite = request->contentLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -1;
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Content-length is 0");
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
memset((uint8_t*)&OtaTargetHdr, 0, sizeof(update_ota_target_hdr));
|
||||
|
||||
DBG_INFO_MSG_OFF(MODULE_FLASH);
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_OTA, "Current firmware index is %d", current_fw_idx + 1);
|
||||
if(current_fw_idx == OTA_INDEX_1)
|
||||
{
|
||||
ota_target_index = OTA_INDEX_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ota_target_index = OTA_INDEX_1;
|
||||
}
|
||||
|
||||
// get ota header
|
||||
writebuf = request->received;
|
||||
writelen = recv(request->fd, writebuf, 16, 0);
|
||||
if(writelen != 16)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "failed to recv file header");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
pOtaFileHdr = (update_file_hdr*)writebuf;
|
||||
pOtaFileImgHdr = (update_file_img_hdr*)(writebuf + 8);
|
||||
|
||||
OtaTargetHdr.FileHdr.FwVer = pOtaFileHdr->FwVer;
|
||||
OtaTargetHdr.FileHdr.HdrNum = pOtaFileHdr->HdrNum;
|
||||
|
||||
writelen = recv(request->fd, writebuf + 16, (pOtaFileHdr->HdrNum * pOtaFileImgHdr->ImgHdrLen) - 8, 0);
|
||||
writelen = (pOtaFileHdr->HdrNum * pOtaFileImgHdr->ImgHdrLen) + 8;
|
||||
|
||||
// verify ota header
|
||||
if(!get_ota_tartget_header((uint8_t*)writebuf, writelen, &OtaTargetHdr, ota_target_index))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Get OTA header failed");
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_OTA, "Erasing...");
|
||||
for(int i = 0; i < OtaTargetHdr.ValidImgCnt; i++)
|
||||
{
|
||||
ADDLOG_INFO(LOG_FEATURE_OTA, "Target addr:0x%08x, img len: %i", OtaTargetHdr.FileImgHdr[i].FlashAddr, OtaTargetHdr.FileImgHdr[i].ImgLen);
|
||||
if(OtaTargetHdr.FileImgHdr[i].ImgLen >= 0x1A8000)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Img%i too big, skipping", i);
|
||||
OtaTargetHdr.FileImgHdr[i].ImgLen = 0;
|
||||
continue;
|
||||
}
|
||||
//watchdog_stop();
|
||||
//erase_ota_target_flash(OtaTargetHdr.FileImgHdr[i].FlashAddr, OtaTargetHdr.FileImgHdr[i].ImgLen);
|
||||
//watchdog_start();
|
||||
}
|
||||
|
||||
memset((uint8_t*)DownloadInfo, 0, MAX_IMG_NUM * sizeof(update_dw_info));
|
||||
|
||||
ImageCnt = OtaTargetHdr.ValidImgCnt;
|
||||
for(uint32_t i = 0; i < ImageCnt; i++)
|
||||
{
|
||||
if(OtaTargetHdr.FileImgHdr[i].ImgLen == 0)
|
||||
{
|
||||
DownloadInfo[i].ImageLen = 0;
|
||||
continue;
|
||||
}
|
||||
/* get OTA image and Write New Image to flash, skip the signature,
|
||||
not write signature first for power down protection*/
|
||||
DownloadInfo[i].ImgId = OTA_IMAG;
|
||||
DownloadInfo[i].FlashAddr = OtaTargetHdr.FileImgHdr[i].FlashAddr - SPI_FLASH_BASE + 8;
|
||||
DownloadInfo[i].ImageLen = OtaTargetHdr.FileImgHdr[i].ImgLen - 8; /*skip the signature*/
|
||||
DownloadInfo[i].ImgOffset = OtaTargetHdr.FileImgHdr[i].Offset;
|
||||
}
|
||||
|
||||
/*initialize the reveiving counter*/
|
||||
TempLen = (OtaTargetHdr.FileHdr.HdrNum * OtaTargetHdr.FileImgHdr[0].ImgHdrLen) + sizeof(update_file_hdr);
|
||||
|
||||
for(uint32_t i = 0; i < ImageCnt; i++)
|
||||
{
|
||||
if(DownloadInfo[i].ImageLen == 0) continue;
|
||||
/*the next image length*/
|
||||
RemainBytes = DownloadInfo[i].ImageLen;
|
||||
ADDLOG_DEBUG(LOG_FEATURE_OTA, "Remain: %i", RemainBytes);
|
||||
signature = &(OtaTargetHdr.Sign[i][0]);
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
FLASH_EraseXIP(EraseSector, DownloadInfo[i].FlashAddr - SPI_FLASH_BASE);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
/*download the new firmware from server*/
|
||||
while(RemainBytes > 0)
|
||||
{
|
||||
buf = (uint8_t*)request->received;
|
||||
if(IncFg == 1)
|
||||
{
|
||||
IncFg = 0;
|
||||
read_bytes = read_bytes_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(buf, 0, request->receivedLenmax);
|
||||
read_bytes = recv(request->fd, buf, request->receivedLenmax, 0);
|
||||
if(read_bytes == 0)
|
||||
{
|
||||
break; // Read end
|
||||
}
|
||||
if(read_bytes < 0)
|
||||
{
|
||||
//OtaImgSize = -1;
|
||||
//printf("\n\r[%s] Read socket failed", __FUNCTION__);
|
||||
//ret = -1;
|
||||
//goto update_ota_exit;
|
||||
break;
|
||||
}
|
||||
read_bytes_buf = read_bytes;
|
||||
TempLen += read_bytes;
|
||||
}
|
||||
|
||||
if(TempLen > DownloadInfo[i].ImgOffset)
|
||||
{
|
||||
if(!OtaFg)
|
||||
{
|
||||
/*reach the desired image, the first packet process*/
|
||||
OtaFg = 1;
|
||||
TempCnt = TempLen - DownloadInfo[i].ImgOffset;
|
||||
if(TempCnt < 8)
|
||||
{
|
||||
SigCnt = TempCnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
SigCnt = 8;
|
||||
}
|
||||
|
||||
memcpy(signature, buf + read_bytes - TempCnt, SigCnt);
|
||||
|
||||
if((SigCnt < 8) || (TempCnt - 8 == 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
buf = buf + (read_bytes - TempCnt + 8);
|
||||
read_bytes = TempCnt - 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*normal packet process*/
|
||||
if(SigCnt < 8)
|
||||
{
|
||||
if(read_bytes < (int)(8 - SigCnt))
|
||||
{
|
||||
memcpy(signature + SigCnt, buf, read_bytes);
|
||||
SigCnt += read_bytes;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(signature + SigCnt, buf, (8 - SigCnt));
|
||||
buf = buf + (8 - SigCnt);
|
||||
read_bytes -= (8 - SigCnt);
|
||||
SigCnt = 8;
|
||||
if(!read_bytes)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RemainBytes -= read_bytes;
|
||||
if(RemainBytes < 0)
|
||||
{
|
||||
read_bytes = read_bytes - (-RemainBytes);
|
||||
}
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
if(DownloadInfo[i].FlashAddr + size >= DownloadInfo[i].FlashAddr + sector_cnt * 4096)
|
||||
{
|
||||
sector_cnt++;
|
||||
FLASH_EraseXIP(EraseSector, DownloadInfo[i].FlashAddr - SPI_FLASH_BASE + sector_cnt * 4096);
|
||||
}
|
||||
if(ota_writestream_user(DownloadInfo[i].FlashAddr + size, read_bytes, buf) < 0)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Writing failed");
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_OTA, "Written %i bytes at 0x%08x", read_bytes, DownloadInfo[i].FlashAddr + size);
|
||||
rtos_delay_milliseconds(5);
|
||||
size += read_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
if((uint32_t)size != (OtaTargetHdr.FileImgHdr[i].ImgLen - 8))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Received size != ota size");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
/*update flag status*/
|
||||
size = 0;
|
||||
OtaFg = 0;
|
||||
IncFg = 1;
|
||||
}
|
||||
|
||||
if(verify_ota_checksum(&OtaTargetHdr))
|
||||
{
|
||||
if(!change_ota_signature(&OtaTargetHdr, ota_target_index))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Change signature failed");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
update_ota_exit:
|
||||
if(ret != -1)
|
||||
{
|
||||
ADDLOG_INFO(LOG_FEATURE_OTA, "OTA is successful");
|
||||
total = RemainBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "OTA failed");
|
||||
return http_rest_error(request, ret, "error");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
init_ota(startaddr);
|
||||
|
||||
Reference in New Issue
Block a user