mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-07 15:57:51 +01:00
Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
#include "temp_detect_pub.h"
|
||||
#elif defined(PLATFORM_LN882H)
|
||||
#elif defined(PLATFORM_TR6260)
|
||||
#elif defined(PLATFORM_REALTEK)
|
||||
#elif defined(PLATFORM_REALTEK) && !PLATFORM_REALTEK_NEW
|
||||
#include "wifi_structures.h"
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_conf.h"
|
||||
@@ -53,6 +53,11 @@
|
||||
extern hal_reset_reason_t reset_reason;
|
||||
#endif
|
||||
SemaphoreHandle_t scan_hdl;
|
||||
#elif PLATFORM_REALTEK_NEW
|
||||
#include "lwip_netconf.h"
|
||||
#include "ameba_soc.h"
|
||||
#include "ameba_ota.h"
|
||||
extern uint32_t current_fw_idx;
|
||||
#elif defined(PLATFORM_ESPIDF) || PLATFORM_ESP8266
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_system.h"
|
||||
@@ -948,7 +953,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 || PLATFORM_RTL8720D
|
||||
#elif PLATFORM_RTL8710B || PLATFORM_RTL8720D || PLATFORM_REALTEK_NEW
|
||||
hprintf255(request, "<h5>Current fw: FW%i</h5>", current_fw_idx + 1);
|
||||
#elif PLATFORM_ECR6600
|
||||
RST_TYPE reset_type = hal_get_reset_type();
|
||||
@@ -1433,7 +1438,7 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
{
|
||||
hprintf255(request, "[%i/%u] SSID: %s, Channel: %i, Signal %i<br>", i + 1, number, ap_info[i].ssid, ap_info[i].primary, ap_info[i].rssi);
|
||||
}
|
||||
#elif defined(PLATFORM_REALTEK)
|
||||
#elif defined(PLATFORM_REALTEK) && !PLATFORM_REALTEK_NEW
|
||||
#ifndef PLATFORM_RTL87X0C
|
||||
extern void rltk_wlan_enable_scan_with_ssid_by_extended_security(bool);
|
||||
#endif
|
||||
@@ -3201,15 +3206,8 @@ int http_fn_cfg_dgr(http_request_t* request) {
|
||||
#endif
|
||||
|
||||
void OTA_RequestDownloadFromHTTP(const char* s) {
|
||||
#if WINDOWS
|
||||
|
||||
#elif PLATFORM_BL602
|
||||
|
||||
#elif PLATFORM_LN882H
|
||||
|
||||
#elif PLATFORM_ESPIDF || PLATFORM_ESP8266
|
||||
#elif PLATFORM_TR6260
|
||||
#elif PLATFORM_REALTEK
|
||||
#if PLATFORM_BEKEN
|
||||
otarequest(s);
|
||||
#elif PLATFORM_ECR6600
|
||||
extern int http_client_download_file(const char* url);
|
||||
extern int ota_done(bool reset);
|
||||
@@ -3248,8 +3246,33 @@ void OTA_RequestDownloadFromHTTP(const char* s) {
|
||||
}
|
||||
|
||||
ota_reboot();
|
||||
#else
|
||||
otarequest(s);
|
||||
#elif PLATFORM_REALTEK_NEW
|
||||
ota_context* ctx = NULL;
|
||||
ctx = (ota_context*)malloc(sizeof(ota_context));
|
||||
if(ctx == NULL) goto exit;
|
||||
memset(ctx, 0, sizeof(ota_context));
|
||||
char url[256] = { 0 };
|
||||
char resource[256] = { 0 };
|
||||
uint16_t port;
|
||||
parser_url(s, &url, &port, &resource, 256);
|
||||
int ret = ota_update_init(ctx, &url, port, &resource, OTA_HTTP);
|
||||
if(ret != 0)
|
||||
{
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_HTTP, "ota_update_init failed");
|
||||
goto exit;
|
||||
}
|
||||
ret = ota_update_start(ctx);
|
||||
if(!ret)
|
||||
{
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "OTA finished");
|
||||
sys_clear_ota_signature();
|
||||
delay_ms(50);
|
||||
sys_reset();
|
||||
}
|
||||
exit:
|
||||
ota_update_deinit(ctx);
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_HTTP, "OTA failed");
|
||||
if(ctx) free(ctx);
|
||||
#endif
|
||||
}
|
||||
int http_fn_ota_exec(http_request_t* request) {
|
||||
|
||||
@@ -103,6 +103,15 @@ extern uint8_t flash_size_8720;
|
||||
#undef DEFAULT_FLASH_LEN
|
||||
#define DEFAULT_FLASH_LEN (flash_size_8720 << 20)
|
||||
|
||||
#elif PLATFORM_REALTEK_NEW
|
||||
|
||||
#include "ameba_ota.h"
|
||||
extern uint32_t current_fw_idx;
|
||||
extern uint32_t IMG_ADDR[OTA_IMGID_MAX][2];
|
||||
extern uint8_t flash_size_8720;
|
||||
#undef DEFAULT_FLASH_LEN
|
||||
#define DEFAULT_FLASH_LEN (flash_size_8720 << 20)
|
||||
|
||||
#endif
|
||||
|
||||
#elif PLATFORM_ECR6600
|
||||
@@ -302,7 +311,7 @@ static int http_rest_post(http_request_t* request) {
|
||||
return http_rest_post_flash(request, -1, -1);
|
||||
#elif PLATFORM_ESPIDF || PLATFORM_ESP8266
|
||||
return http_rest_post_flash(request, -1, -1);
|
||||
#elif PLATFORM_REALTEK
|
||||
#elif PLATFORM_REALTEK && !PLATFORM_RTL8720E
|
||||
return http_rest_post_flash(request, 0, -1);
|
||||
#elif PLATFORM_ECR6600 || PLATFORM_TR6260
|
||||
return http_rest_post_flash(request, -1, -1);
|
||||
@@ -310,7 +319,7 @@ static int http_rest_post(http_request_t* request) {
|
||||
return http_rest_post_flash(request, 0, -1);
|
||||
#else
|
||||
// TODO
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "No OTA");
|
||||
ADDLOG_ERROR(LOG_FEATURE_API, "No OTA");
|
||||
#endif
|
||||
}
|
||||
if (!strncmp(request->url, "api/flash/", 10)) {
|
||||
@@ -3238,6 +3247,128 @@ update_ota_exit:
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "OTA failed.");
|
||||
return http_rest_error(request, ret, "error");
|
||||
}
|
||||
#elif PLATFORM_REALTEK_NEW
|
||||
|
||||
// Bad implementation. While it somewhat works, it is not recommended to use. HTTP OTA is preferable.
|
||||
int ret = 0;
|
||||
|
||||
if(request->contentLength > 0)
|
||||
{
|
||||
towrite = request->contentLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -1;
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Content-length is 0");
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
flash_get_layout_info(IMG_BOOT, &IMG_ADDR[OTA_IMGID_BOOT][OTA_INDEX_1], NULL);
|
||||
flash_get_layout_info(IMG_BOOT_OTA2, &IMG_ADDR[OTA_IMGID_BOOT][OTA_INDEX_2], NULL);
|
||||
flash_get_layout_info(IMG_APP_OTA1, &IMG_ADDR[OTA_IMGID_APP][OTA_INDEX_1], NULL);
|
||||
flash_get_layout_info(IMG_APP_OTA2, &IMG_ADDR[OTA_IMGID_APP][OTA_INDEX_2], NULL);
|
||||
|
||||
ota_context ctx;
|
||||
memset(&ctx, 0, sizeof(ota_context));
|
||||
ctx.otactrl = malloc(sizeof(update_ota_ctrl_info));
|
||||
memset(ctx.otactrl, 0, sizeof(update_ota_ctrl_info));
|
||||
|
||||
ctx.otaTargetHdr = malloc(sizeof(update_ota_target_hdr));
|
||||
memset(ctx.otaTargetHdr, 0, sizeof(update_ota_target_hdr));
|
||||
writebuf = request->received;
|
||||
if(!writelen) writelen = recv(request->fd, writebuf, request->receivedLenmax, 0);
|
||||
// for some reason we receive data along with HTTP header. Skip it.
|
||||
int skip = 0;
|
||||
for(; skip < writelen - 5; skip++)
|
||||
{
|
||||
if(*(uint32_t*)&writebuf[skip] == 0xFFFFFFFF && writebuf[skip + 4] == 0x01) break;
|
||||
}
|
||||
writebuf += skip;
|
||||
writelen -= skip;
|
||||
towrite -= skip;
|
||||
update_file_hdr* pOtaFileHdr = (update_file_hdr*)(writebuf);
|
||||
ctx.otaTargetHdr->FileHdr.FwVer = pOtaFileHdr->FwVer;
|
||||
ctx.otaTargetHdr->FileHdr.HdrNum = pOtaFileHdr->HdrNum;
|
||||
|
||||
uint32_t RevHdrLen = pOtaFileHdr->HdrNum * SUB_HEADER_LEN + HEADER_LEN;
|
||||
if(writelen < RevHdrLen)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "failed to recv file header");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
if(!get_ota_tartget_header(&ctx, writebuf, RevHdrLen))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Get OTA header failed");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
if(!ota_checkimage_layout(ctx.otaTargetHdr))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "ota_checkimage_layout failed");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
ctx.otactrl->IsGetOTAHdr = 1;
|
||||
writebuf += RevHdrLen;
|
||||
// magic values to make it somewhat work.
|
||||
writelen -= RevHdrLen + 5 - 384;
|
||||
towrite -= RevHdrLen + 5 - 384;
|
||||
ctx.otactrl->NextImgLen = towrite;
|
||||
do
|
||||
{
|
||||
int size = download_packet_process(&ctx, writebuf, writelen);
|
||||
download_percentage(&ctx, size, ctx.otactrl->ImageLen);
|
||||
rtos_delay_milliseconds(10);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_OTA, "Writelen %i at %i", writelen, total);
|
||||
total += writelen;
|
||||
towrite -= writelen;
|
||||
|
||||
if(towrite > 0)
|
||||
{
|
||||
writebuf = request->received;
|
||||
writelen = recv(request->fd, writebuf, 2048 < towrite ? 2048 : towrite, 0);
|
||||
if(writelen < 0)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "recv returned %d - end of data - remaining %d", writelen, towrite);
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
}
|
||||
} while((towrite > 0) && (writelen >= 0));
|
||||
|
||||
//erase manifest
|
||||
flash_erase_sector(&flash, ctx.otactrl->FlashAddr);
|
||||
|
||||
if(!verify_ota_checksum(ctx.otaTargetHdr, ctx.otactrl->targetIdx, ctx.otactrl->index))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "The checksum is wrong!");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
if(!ota_update_manifest(ctx.otaTargetHdr, ctx.otactrl->targetIdx, ctx.otactrl->index))
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_OTA, "Change signature failed!");
|
||||
ret = -1;
|
||||
goto update_ota_exit;
|
||||
}
|
||||
|
||||
update_ota_exit:
|
||||
ota_update_deinit(&ctx);
|
||||
if(ret != -1)
|
||||
{
|
||||
ADDLOG_INFO(LOG_FEATURE_OTA, "OTA is successful");
|
||||
sys_clear_ota_signature();
|
||||
//sys_recover_ota_signature();
|
||||
}
|
||||
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