How to rebuild bootloader for 4M flash BW16 OTA application?

Hi,

We are using a 4M BW16 module and we need OTA from AWS. The MQTT example is more than 1MB so we suppose the 2MB module would not work for us.

However, The Arduino IDE seems grab the pre-compiled km0_boot_all.bin and km4_boot_all.bin. The application note mentioned OTA_Region change is needed. So I’m wondering how should I change the address to move OTA2 from 0x08106000 to 0x08206000?

Or I can download the pre-compiled bootloader somewhere?

I tried to download https://github.com/ambiot/ambd_sdk/archive/refs/tags/v1.0.1.zip and build the km0_boot_all.bin for my Arduino 3.1.7 and it gave me #[MODULE_BOOT-LEVEL_ERROR]:IMG2 SIGN Invalid error. And when I tried to modify the Arduino bootloader binary from 00 60 00 08 00 60 10 08 to 00 60 00 08 00 60 20 08, the OTA seems still can not be activated, even I used the ImageTool to flash the km0_km4_image2.bin to 0x08206000.

Some update.

The bootloader that was built from https://github.com/Ameba-AIoT/ameba-rtos-d actually works with Arduino code. Some rtl8721d_usi*.h are missing but they can be copied from https://github.com/ambiot/ambd_sdk.

Also I can confirm a binary patch of the Arduino bootloader binary from 00 60 00 08 00 60 10 08 to 00 60 00 08 00 60 20 08 actually works. It was the array OTA_Region and it was the only info in bootloader about the IMG2 location.

My problem for the Arduino code was actually the ota_get_cur_index(). Without any modification to Arduino package (I’m trying to avoid), the ota_get_cur_index considers any PhyAddr that was not 0x8106000 as IMG1. Even the bootloader boots from 0x8206000, the ota_get_cur_index() still consider it as IMG1, and that leads to my confusion.

Copy the code inside ota_get_cur_index() to a new customized function solves the problem.