EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #1449 background imageLoading...
Page #1449 background image
Chapter 4. API Guides
Note: Note that updating the partition table doesnt erase data that may have been stored according to the old
partition table. You can use idf.py erase-flash (or esptool.py erase_flash) to erase the entire
flash contents.
4.22.7 Partition Tool (parttool.py)
The component partition_table provides a tool parttool.py for performing partition-related operations on a target
device. The following operations can be performed using the tool:
reading a partition and saving the contents to a file (read_partition)
writing the contents of a file to a partition (write_partition)
erasing a partition (erase_partition)
retrieving info such as name, offset, size and flag (encrypted) of a given partition (get_partition_info)
The tool can either be imported and used from another Python script or invoked from shell script for users wanting
to perform operation programmatically. This is facilitated by the tools Python API and command-line interface,
respectively.
Python API
Before anything else, make sure that the parttool module is imported.
import sys
import os
idf_path = os.environ["IDF_PATH"] # get value of IDF_PATH from environment
parttool_dir = os.path.join(idf_path, "components", "partition_table") # parttool.
,py lives in $IDF_PATH/components/partition_table
sys.path.append(parttool_dir) # this enables Python to find parttool module
from parttool import * # import all names inside parttool module
The starting point for using the tools Python API to do is create a ParttoolTarget object:
# Create a partool.py target device connected on serial port /dev/ttyUSB1
target = ParttoolTarget("/dev/ttyUSB1")
The created object can now be used to perform operations on the target device:
# Erase partition with name 'storage'
target.erase_partition(PartitionName("storage"))
# Read partition with type 'data' and subtype 'spiffs' and save to file 'spiffs.bin
,'
target.read_partition(PartitionType("data", "spiffs"), "spiffs.bin")
# Write to partition 'factory' the contents of a file named 'factory.bin'
target.write_partition(PartitionName("factory"), "factory.bin")
# Print the size of default boot partition
storage = target.get_partition_info(PARTITION_BOOT_DEFAULT)
print(storage.size)
The partition to operate on is specified using PartitionName or PartitionType or PARTITION_BOOT_DEFAULT.
As the name implies, these can be used to refer to partitions of a particular name, type-subtype combination, or the
default boot partition.
More information on the Python API is available in the docstrings for the tool.
Espressif Systems 1438
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP32-S2 and is the answer not in the manual?

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish