w800 + berry (#1629)

* w800 + berry

* fix w600

* Update XR and makefile

* Berry cmake

* BL602 lfs test

* Update w800

* Fix

* W600 heap

* sensors & bl602

* bl602 delay_us
This commit is contained in:
NonPIayerCharacter
2025-06-20 10:35:00 +03:00
committed by GitHub
parent 10e20f9a9b
commit fac2cf081c
85 changed files with 1556 additions and 4189 deletions

View File

@ -1773,7 +1773,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
// warning - this is 32 bit
int flagsChannelPublished;
int ch;
int dimmer, toggle, brightness_scale;
int dimmer, toggle, brightness_scale = 0;
// no channels published yet
flagsChannelPublished = 0;

View File

@ -24,7 +24,7 @@ void HTTPServer_Start();
typedef struct
{
int fd;
TaskHandle_t thread;
xTaskHandle thread;
bool isCompleted;
} tcp_thread_t;
@ -54,7 +54,7 @@ static void tcp_client_thread(tcp_thread_t* arg)
goto exit;
}
http_request_t request;
os_memset(&request, 0, sizeof(request));
memset(&request, 0, sizeof(request));
request.fd = fd;
request.received = buf;
@ -275,7 +275,7 @@ static void tcp_server_thread(beken_thread_arg_t arg)
}
}
}
vTaskDelay(pdMS_TO_TICKS(10));
rtos_delay_milliseconds(10);
}
error:

View File

@ -25,13 +25,10 @@ uint32_t flash_read(uint32_t flash, uint32_t addr, void* buf, uint32_t size);
#include <utils_sha256.h>
#include <bl_mtd.h>
#include <bl_flash.h>
#elif PLATFORM_W600
#include "wm_socket_fwup.h"
#include "wm_fwup.h"
#elif PLATFORM_W800
#elif defined(PLATFORM_W800) || defined(PLATFORM_W600)
#include "wm_internal_flash.h"
#include "wm_socket_fwup.h"
#include "wm_fwup.h"
@ -42,6 +39,17 @@ uint32_t flash_read(uint32_t flash, uint32_t addr, void* buf, uint32_t size);
#elif PLATFORM_ESPIDF
#include "esp_system.h"
#include "esp_ota_ops.h"
#include "esp_app_format.h"
#include "esp_flash_partitions.h"
#include "esp_partition.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
#include "esp_pm.h"
#include "esp_flash_spi_init.h"
#elif PLATFORM_REALTEK
#include "flash_api.h"
@ -723,7 +731,7 @@ static int http_rest_post_lfs_file(http_request_t* request) {
if (!lfs_present()) {
request->responseCode = 400;
http_setup(request, httpMimeTypeText);
poststr(request, "LittleFS is not abailable");
poststr(request, "LittleFS is not available");
poststr(request, NULL);
return 0;
}
@ -1309,7 +1317,8 @@ typedef struct ota_header {
uint8_t ver_software[16];
uint8_t sha256[32];
} s;
uint32_t unpacked_len;//full len
} s;
uint8_t _pad[512];
} u;
} ota_header_t;
@ -1585,30 +1594,13 @@ static int ota_verify_download(void)
}
#endif
#if PLATFORM_ESPIDF
#include "esp_system.h"
#include "esp_ota_ops.h"
#include "esp_app_format.h"
#include "esp_flash_partitions.h"
#include "esp_partition.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
#include "esp_pm.h"
#endif
static int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr)
{
#if PLATFORM_XR809
#if PLATFORM_XR809 || PLATFORM_XR872
return 0; //Operation not supported yet
#endif
#if PLATFORM_XR872
return 0; //Operation not supported yet
#endif
int total = 0;
int towrite = request->bodylen;
char* writebuf = request->bodystart;
@ -1746,7 +1738,7 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
if(writelen < 0)
{
ADDLOG_DEBUG(LOG_FEATURE_OTA, "ABORTED: %d bytes to write", writelen);
ADDLOG_ERROR(LOG_FEATURE_OTA, "ABORTED: %d bytes to write", writelen);
return http_rest_error(request, -20, "writelen < 0");
}
@ -1759,6 +1751,12 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
#define MAX_BUFF_SIZE 2048
char* Buffer = (char*)os_malloc(MAX_BUFF_SIZE + FWUP_MSG_SIZE);
if(!Buffer)
{
ADDLOG_ERROR(LOG_FEATURE_OTA, "ABORTED: failed to allocate buffer");
return http_rest_error(request, -20, "");
}
if(request->contentLength >= 0)
{
towrite = request->contentLength;
@ -1766,7 +1764,6 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
int recvLen = 0;
int totalLen = 0;
uint8_t counter = 0;
printf("\ntowrite %d writelen=%d\n", towrite, writelen);
do
@ -1858,11 +1855,13 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
nRetCode = -17;
}
}
if (counter++ % 5 == 0) bk_printf("Downloaded %d / %d\n", recvLen, totalLen);
ADDLOG_DEBUG(LOG_FEATURE_OTA, "Downloaded %d / %d", recvLen, totalLen);
rtos_delay_milliseconds(10); // give some time for flashing - will else increase used memory fast
} while((nRetCode == 0) && (towrite > 0) && (writelen >= 0));
bk_printf("Download completed (%d / %d)\n", recvLen, totalLen);
tls_mem_free(Buffer);
if(Buffer) os_free(Buffer);
if(p) pbuf_free(p);
if(nRetCode != 0)
{
@ -1898,7 +1897,7 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
recv_buffer = pvPortMalloc(OTA_PROGRAM_SIZE);
unsigned int buffer_offset, flash_offset, ota_addr;
uint32_t bin_size, part_size;
uint32_t bin_size, part_size, running_size;
uint8_t activeID;
HALPartition_Entry_Config ptEntry;
@ -1918,6 +1917,7 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
ota_addr = ptEntry.Address[!ptEntry.activeIndex];
bin_size = ptEntry.maxLen[!ptEntry.activeIndex];
part_size = ptEntry.maxLen[!ptEntry.activeIndex];
running_size = ptEntry.maxLen[ptEntry.activeIndex];
(void)part_size;
/*XXX if you use bin_size is product env, you may want to set bin_size to the actual
* OTA BIN size, and also you need to splilt XIP_SFlash_Erase_With_Lock into
@ -2020,6 +2020,11 @@ static int http_rest_post_flash(http_request_t* request, int startaddr, int maxa
{
return http_rest_error(request, -20, "Too large bin");
}
if(ota_header->u.s.unpacked_len != 0xFFFFFFFF && running_size < ota_header->u.s.unpacked_len)
{
ADDLOG_ERROR(LOG_FEATURE_OTA, "Unpacked OTA image size (%u) is bigger than running partition size (%u)", ota_header->u.s.unpacked_len, running_size);
return http_rest_error(request, -20, "");
}
//ADDLOG_DEBUG(LOG_FEATURE_OTA, "%d bytes to write", writelen);
//add_otadata((unsigned char*)writebuf, writelen);
@ -3162,7 +3167,9 @@ static int http_rest_get_flash(http_request_t* request, int startaddr, int len)
if (readlen > 1024) {
readlen = 1024;
}
#if PLATFORM_XR809
#if PLATFORM_BEKEN
res = flash_read((char*)buffer, readlen, startaddr);
#elif PLATFORM_XR809
//uint32_t flash_read(uint32_t flash, uint32_t addr,void *buf, uint32_t size)
#define FLASH_INDEX_XR809 0
res = flash_read(FLASH_INDEX_XR809, startaddr, buffer, readlen);
@ -3171,11 +3178,11 @@ static int http_rest_get_flash(http_request_t* request, int startaddr, int len)
#elif PLATFORM_BL602
res = bl_flash_read(startaddr, (uint8_t *)buffer, readlen);
#elif PLATFORM_W600 || PLATFORM_W800
res = 0;
res = tls_fls_read(startaddr, (uint8_t*)buffer, readlen);
#elif PLATFORM_LN882H
res = hal_flash_read(startaddr, readlen, (uint8_t *)buffer);
#elif PLATFORM_ESPIDF
res = 0;
res = esp_flash_read(NULL, (void*)buffer, startaddr, readlen);
#elif PLATFORM_TR6260
res = hal_spiflash_read(startaddr, (uint8_t*)buffer, readlen);
#elif PLATFORM_ECR6600
@ -3185,7 +3192,7 @@ static int http_rest_get_flash(http_request_t* request, int startaddr, int len)
flash_stream_read(&flash, startaddr, readlen, (uint8_t*)buffer);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
#else
res = flash_read((char*)buffer, readlen, startaddr);
res = 0;
#endif
startaddr += readlen;
len -= readlen;