Partition Tool (Parttool.py) - Espressif ESP32-S2 Programming Manual

Table of Contents

Advertisement

Chapter 4. API Guides
Note: Note that updating the partition table doesn't 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
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 tool's 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"]
parttool_dir
=
os.path.join(idf_path, "components", "partition_table")
py lives in $IDF_PATH/components/partition_table
sys.path.append(parttool_dir)
from
parttool
import
The starting point for using the tool's 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
parttool.py
# get value of IDF_PATH from environment
# this enables Python to find parttool module
*
# import all names inside parttool module
1438
Submit Document Feedback
for performing partition-related operations on a target
# parttool.
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Table of Contents

Save PDF