Skip to content

Commit

Permalink
arch/xtensa/esp32s3: Adding an ioctl interface ota_set_bootseq()
Browse files Browse the repository at this point in the history
to the ESP32-S3 partitions, by deleting the corresponding otadata,
makes the boot sequence (ota_0/1) invalid.
  • Loading branch information
nuttxs committed Sep 25, 2024
1 parent 8288fe4 commit 7cbc6eb
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions arch/xtensa/src/esp32s3/esp32s3_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
enum ota_img_ctrl_e
{
OTA_IMG_GET_BOOT = 0xe1,
OTA_IMG_SET_BOOT = 0xe2
OTA_IMG_SET_BOOT = 0xe2,
OTA_IMG_INVALIDATE_BOOT = 0xe3,
};

/* OTA image state */
Expand Down Expand Up @@ -355,6 +356,53 @@ static int ota_set_bootseq(struct mtd_dev_priv_s *dev, int num)
return 0;
}

/****************************************************************************
* Name: ota_invalidate_bootseq
*
* Description:
* Invalidate boot sequence by deleting the corresponding otadata
*
* Input Parameters:
* dev - Partition private MTD data
* num - boot sequence buffer
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/

static int ota_invalidate_bootseq(struct mtd_dev_priv_s *dev, int num)
{
int ret;
int id;

finfo("INFO: num=%d\n", num);

switch (num)
{
case OTA_IMG_BOOT_OTA_0:
case OTA_IMG_BOOT_OTA_1:
{
id = num - 1;

ret = MTD_ERASE(dev->part_mtd, id, 1);
if (ret != 1)
{
ferr("ERROR: Failed to erase OTA%d data error=%d\n",
id, ret);
return -EIO;
}
}

break;
default:
ferr("ERROR: num=%d is error\n", num);
return -EINVAL;
}

return 0;
}

/****************************************************************************
* Name: esp32s3_part_erase
*
Expand Down Expand Up @@ -484,7 +532,7 @@ static ssize_t esp32s3_part_bwrite(struct mtd_dev_s *dev, off_t startblock,
* Name: esp32s3_part_ioctl
*
* Description:
* Set/Get option to/from ESP32-S3 SPI Flash MTD device data.
* Set/Get/Invaliate option to/from ESP32-S3 SPI Flash MTD device data.
*
* Input Parameters:
* dev - ESP32-S3 MTD device data
Expand Down Expand Up @@ -527,6 +575,16 @@ static int esp32s3_part_ioctl(struct mtd_dev_s *dev, int cmd,
}
}

break;
case OTA_IMG_INVALIDATE_BOOT:
{
ret = ota_invalidate_bootseq(mtd_priv, arg);
if (ret < 0)
{
ferr("ERROR: Failed to invalidate boot img\n");
}
}

break;
default:
{
Expand Down

0 comments on commit 7cbc6eb

Please sign in to comment.