espressif / esp-hosted

Hosted Solution (Linux/MCU) with ESP32 (Wi-Fi + BT + BLE)
Other
674 stars 158 forks source link

FG mode: OTA end failed #498

Open lwj850533527 opened 2 days ago

lwj850533527 commented 2 days ago

Checklist

How often does this bug occurs?

always

Expected behavior

OTA success

Actual behavior (suspected bug)

OTA failed

Error logs or terminal output

I (19659) slave_ctrl: OTA update started                                        
I (19659) slave_ctrl: Prepare partition for OTA   
I (23589) slave_ctrl: Flashing image                                                          
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
.............
I (70579) esp_image: segment 0: paddr=00110020 vaddr=3c0b0020 size=2b620h (177696) map                                                             
E (70599) esp_image: invalid segment length 0x5f70756e                          
E (70599) slave_ctrl: Image validation failed, image is corrupted 

Steps to reproduce the behavior

OTA

Project release version

0.0.5

Operating system

STM32

Additional context

Hi @mantriyogesh FG mode, I only send "network_adapter.bin" to esp32, OTA begin and OTA write success But OTA end failed

Do I need to send other files image

mantriyogesh commented 2 days ago
  1. please avoid opening as feature request, if you treat this as bug. This helps us in categorisation.

  2. network_adapter.bin is the only file need to be sent. no other partitions are needed or supported in ota.

  3. Is it possible to flash this image on your ESP32 directly and confirm it works fine?

  4. What is the host (Linux/MCU, details) and transport medium (SPI/SDIO)?

  5. Can you please include git commits used at both sides?

lwj850533527 commented 17 hours ago

Hi @mantriyogesh

  1. Is it possible to flash this image on your ESP32 directly and confirm it works fine?

I flash this image on my ESP32 directly, and confirm it works fine

I (30) boot: ESP-IDF 8fceee7 2nd stage bootloader                               
I (30) boot: compile time Aug 26 2024 14:02:21                                  
I (30) boot: chip revision: v0.4                                                
I (33) boot.esp32c3: SPI Speed      : 80MHz                                     
I (38) boot.esp32c3: SPI Mode       : DIO                                       
I (43) boot.esp32c3: SPI Flash Size : 4MB                                       
I (47) boot: Enabling RNG early entropy source...                               
I (53) boot: Partition Table:                                                   
I (56) boot: ## Label            Usage          Type ST Offset   Length         
I (64) boot:  0 nvs              WiFi data        01 02 00009000 00004000       
I (71) boot:  1 otadata          OTA data         01 00 0000d000 00002000       
I (79) boot:  2 phy_init         RF data          01 01 0000f000 00001000       
I (86) boot:  3 factory          factory app      00 00 00010000 00100000       
I (94) boot:  4 ota_0            OTA app          00 10 00110000 00100000       
I (101) boot:  5 ota_1            OTA app          00 11 00210000 00100000      
I (109) boot: End of partition table                                            
I (113) boot: Defaulting to factory image                                       
I (118) esp_image: segment 0: paddr=00010020 vaddr=3c0b0020 size=2b620h (177696) map                                                                            
I (154) esp_image: segment 1: paddr=0003b648 vaddr=3fc97000 size=033fch ( 13308) load                                                                           
I (157) esp_image: segment 2: paddr=0003ea4c vaddr=40380000 size=015cch (  5580) load                                                                           
I (161) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=a7d5ch (687452) map                                                                            
I (278) esp_image: segment 4: paddr=000e7d84 vaddr=403815cc size=159b8h ( 88504) load                                                                           
I (295) esp_image: segment 5: paddr=000fd744 vaddr=50000000 size=00020h (    32) load                                                                           
I (303) boot: Loaded app from partition at offset 0x10000                       
I (303) boot: Disabling RNG early entropy source...                             
I (316) cpu_start: Unicore app                                                  
I (316) cpu_start: Pro cpu up.                                                  
I (325) cpu_start: Pro cpu start user code                                      
I (325) cpu_start: cpu freq: 160000000 Hz                                       
I (325) cpu_start: Application information:                                     
I (328) cpu_start: Project name:     network_adapter                            
I (333) cpu_start: App version:      FG-0.0.6.0.1                               
I (339) cpu_start: Compile time:     Sep 23 2024 17:19:05                       
I (345) cpu_start: ELF file SHA256:  5c922f0f1deb3f41...                        
I (351) cpu_start: ESP-IDF:          v5.1.3-dirty                               
I (356) cpu_start: Min chip rev:     v0.3                                       
I (361) cpu_start: Max chip rev:     v1.99                                      
I (366) cpu_start: Chip rev:         v0.4   
  1. What is the host (Linux/MCU, details) and transport medium (SPI/SDIO)?

host is stm32, transport medium is SPI

  1. Can you please include git commits used at both sides?

commits is https://github.com/espressif/esp-hosted/commit/490d2c3ed03139650d82b09f079d6fc4b1c48e49 I update the code to the latest version, It also has the same issue

Do I need to modify the content or format of “network_adapter.bin”, after compilation completed

mantriyogesh commented 17 hours ago

stm32 as in the microprocessor (esp_hosted_fg/host/stm32) or Linux (esp_hosted_fg/host/linux)?

lwj850533527 commented 17 hours ago

esp_hosted_fg/host/stm32

mantriyogesh commented 17 hours ago

There might be issue on your transport that the packets are being lost silently.

Also change, https://github.com/espressif/esp-hosted/blob/250e29294a740a45dd853115a25b62f1b2cfc51b/esp_hosted_fg/host/stm32/driver/transport/spi/spi_drv.c#L305-L338

such that

static void check_and_execute_spi_transaction(void)
{
    uint8_t * txbuff = NULL;
    uint8_t is_valid_tx_buf = 0;
    GPIO_PinState gpio_handshake = GPIO_PIN_RESET;
    GPIO_PinState gpio_rx_data_ready = GPIO_PIN_RESET;
/* move here */
xSemaphoreTake(mutex_spi_trans, portMAX_DELAY);

    /* handshake line SET -> slave ready for next transaction */
    gpio_handshake = HAL_GPIO_ReadPin(GPIO_HANDSHAKE_GPIO_Port,
            GPIO_HANDSHAKE_Pin);

    /* data ready line SET -> slave wants to send something */
    gpio_rx_data_ready = HAL_GPIO_ReadPin(GPIO_DATA_READY_GPIO_Port,
            GPIO_DATA_READY_Pin);

    if (gpio_handshake == GPIO_PIN_SET) {

        /* Get next tx buffer to be sent */
        txbuff = get_tx_buffer(&is_valid_tx_buf);

        if ( (gpio_rx_data_ready == GPIO_PIN_SET) ||
             (is_valid_tx_buf) ) {

            /* Execute transaction only if EITHER holds true-
             * a. A valid tx buffer to be transmitted towards slave
             * b. Slave wants to send something (Rx for host)
             */
            //xSemaphoreTake(mutex_spi_trans, portMAX_DELAY);
            spi_trans_func[hardware_type](txbuff);
            //xSemaphoreGive(mutex_spi_trans);
        }
    }

/* move here */
xSemaphoreGive(mutex_spi_trans);

}
mantriyogesh commented 17 hours ago

in general, this is old code, many fixes done for MCU only branch, at

https://github.com/espressif/esp-hosted/tree/feature/esp_as_mcu_host

But you would need porting efforts to move to this branch. Many such issues like one above stated are fixed in that branch.