aviralgarg05 commented on code in PR #18373:
URL: https://github.com/apache/nuttx/pull/18373#discussion_r2791674623


##########
boards/xtensa/esp32/common/src/esp32_boot_image.c:
##########
@@ -0,0 +1,247 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_boot_image.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <arch/esp32/partition.h>
+#include <nuttx/board.h>
+#include <nuttx/cache.h>
+#include <nuttx/irq.h>
+
+#include "esp_loader.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ESP32_APP_LOAD_HEADER_MAGIC 0xace637d3
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct esp32_load_header_s
+{
+  uint32_t header_magic;
+  uint32_t entry_addr;
+  uint32_t iram_dest_addr;
+  uint32_t iram_flash_offset;
+  uint32_t iram_size;
+  uint32_t dram_dest_addr;
+  uint32_t dram_flash_offset;
+  uint32_t dram_size;
+  uint32_t lp_rtc_iram_dest_addr;
+  uint32_t lp_rtc_iram_flash_offset;
+  uint32_t lp_rtc_iram_size;
+  uint32_t lp_rtc_dram_dest_addr;
+  uint32_t lp_rtc_dram_flash_offset;
+  uint32_t lp_rtc_dram_size;
+  uint32_t irom_map_addr;
+  uint32_t irom_flash_offset;
+  uint32_t irom_size;
+  uint32_t drom_map_addr;
+  uint32_t drom_flash_offset;
+  uint32_t drom_size;
+  uint32_t reserved[4];
+};
+
+struct esp32_boot_loader_args_s
+{
+  uint32_t entry_addr;
+  uint32_t drom_addr;
+  uint32_t drom_vaddr;
+  uint32_t drom_size;
+  uint32_t irom_addr;
+  uint32_t irom_vaddr;
+  uint32_t irom_size;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void IRAM_ATTR esp32_boot_loader_stub(void *arg);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_boot_loader_stub
+ *
+ * Description:
+ *   This function resides in IRAM and is responsible for switching MMU
+ *   mappings and jumping to the new application.
+ *
+ ****************************************************************************/
+
+static void IRAM_ATTR esp32_boot_loader_stub(void *arg)
+{
+  struct esp32_boot_loader_args_s *args =
+      (struct esp32_boot_loader_args_s *)arg;
+  void (*entry_point)(void) = (void (*)(void))args->entry_addr;
+
+  /* Disable interrupts */
+
+  up_irq_disable();
+
+  /* Disable cache */
+
+#ifdef CONFIG_ARCH_CHIP_ESP32
+  cache_read_disable(0);
+  cache_flush(0);
+#else
+  cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
+#endif
+
+  /* Map new segments */
+
+  map_rom_segments(args->drom_addr, args->drom_vaddr, args->drom_size,

Review Comment:
   I kept `map_rom_segments()` intentionally here because `board_boot_image()` 
can chain-boot from a non-primary OTA slot, while normal startup mapping is 
based on primary-slot assumptions. Remapping in this IRAM stub ensures 
IROM/DROM point to the selected image before entering it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to