Skip to content

Commit

Permalink
Merge pull request #1 from espressif/master
Browse files Browse the repository at this point in the history
align with upstream
  • Loading branch information
Jason2866 authored Mar 21, 2022
2 parents baaca1a + eb98bb3 commit 76d5553
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
5 changes: 3 additions & 2 deletions docs/en/esptool/advanced-commands.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{IDF_TARGET_BOOTLOADER_OFFSET:default="0x0", esp8266="0x0", esp32="0x1000", esp32s2="0x1000", esp32s3="0x0", esp32c3="0x0"}

.. _advanced-commands:

Advanced Commands
Expand Down Expand Up @@ -27,8 +29,7 @@ The ``--diff yes`` option specifies that if the files are different, the details

.. list::

:esp8266: * If verifying a default boot image (offset 0 for ESP8266) then any ``--flash_mode``, ``--flash_size`` and ``--flash_freq`` arguments which were passed to `write_flash` must also be passed to ``verify_flash``. Otherwise, ``verify_flash`` will detect mismatches in the header of the image file.
:not esp8266: * If verifying a default boot image (offset 0x1000 for {IDF_TARGET_NAME}) then any ``--flash_mode``, ``--flash_size`` and ``--flash_freq`` arguments which were passed to `write_flash` must also be passed to ``verify_flash``. Otherwise, ``verify_flash`` will detect mismatches in the header of the image file.
* If verifying a default boot image (offset {IDF_TARGET_BOOTLOADER_OFFSET} for {IDF_TARGET_NAME}) then any ``--flash_mode``, ``--flash_size`` and ``--flash_freq`` arguments which were passed to `write_flash` must also be passed to ``verify_flash``. Otherwise, ``verify_flash`` will detect mismatches in the header of the image file.
* Another way to compare flash contents is to use the ``read_flash`` command, and then use binary diffing tools on the host.

.. _dump-mem:
Expand Down
11 changes: 3 additions & 8 deletions docs/en/esptool/flash-modes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{IDF_TARGET_BOOTLOADER_OFFSET:default="0x0", esp8266="0x0", esp32="0x1000", esp32s2="0x1000", esp32s3="0x0", esp32c3="0x0"}

.. _flash-modes:

Flash Modes
Expand All @@ -12,14 +14,7 @@ To override these values, the options ``--flash_mode``, ``--flash_size`` and/or

esptool.py --port /dev/ttyUSB1 write_flash --flash_mode dio --flash_size 4MB 0x0 bootloader.bin

.. only:: esp8266

These options are only consulted when flashing a bootable image to an {IDF_TARGET_NAME} at offset 0x0. These are addresses used by the ROM bootloader to load from flash. When flashing at all other offsets, these arguments are not used.

.. only:: not esp8266

These options are only consulted when flashing a bootable image to an {IDF_TARGET_NAME} at offset 0x1000. These are addresses used by the ROM bootloader to load from flash. When flashing at all other offsets, these arguments are not used.

These options are only consulted when flashing a bootable image to an {IDF_TARGET_NAME} at offset {IDF_TARGET_BOOTLOADER_OFFSET}. These are addresses used by the ROM bootloader to load from flash. When flashing at all other offsets, these arguments are not used.

Flash Mode (--flash_mode, -fm)
-------------------------------
Expand Down
6 changes: 4 additions & 2 deletions docs/en/troubleshooting.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{IDF_TARGET_BOOTLOADER_OFFSET:default="0x0", esp8266="0x0", esp32="0x1000", esp32s2="0x1000", esp32s3="0x0", esp32c3="0x0"}

.. _troubleshooting:

Troubleshooting
Expand Down Expand Up @@ -65,14 +67,14 @@ Missing Bootloader
.. only:: esp8266

The `ESP8266 SDK <https://github.com/espressif/ESP8266_RTOS_SDK>`_ uses a small firmware bootloader program. The hardware bootloader in ROM loads this firmware bootloader from flash, and then it runs the program.
On ESP8266, firmware bootloader image (with a filename like ``boot_v1.x.bin``) has to be flashed at offset 0. If the firmware bootloader is missing then the ESP8266 will not boot.
On ESP8266, firmware bootloader image (with a filename like ``boot_v1.x.bin``) has to be flashed at offset {IDF_TARGET_BOOTLOADER_OFFSET}. If the firmware bootloader is missing then the ESP8266 will not boot.

Refer to ESP8266 SDK documentation for details regarding which binaries need to be flashed at which offsets.

.. only:: not esp8266

`ESP-IDF <https://github.com/espressif/esp-idf>`_ and uses a small firmware bootloader program. The hardware bootloader in ROM loads this firmware bootloader from flash, and then it runs the program.
On {IDF_TARGET_NAME}, the bootloader image should be flashed by ESP-IDF at offset 0x1000.
On {IDF_TARGET_NAME}, the bootloader image should be flashed by ESP-IDF at offset {IDF_TARGET_BOOTLOADER_OFFSET}.

Refer to ESP-IDF documentation for details regarding which binaries need to be flashed at which offsets.

Expand Down
44 changes: 40 additions & 4 deletions esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,14 @@ def parse_flash_size_arg(cls, arg):
raise FatalError("Flash size '%s' is not supported by this chip type. Supported sizes: %s"
% (arg, ", ".join(cls.FLASH_SIZES.keys())))

@classmethod
def parse_flash_freq_arg(cls, arg):
try:
return cls.FLASH_FREQUENCY[arg]
except KeyError:
raise FatalError("Flash frequency '%s' is not supported by this chip type. Supported frequencies: %s"
% (arg, ", ".join(cls.FLASH_FREQUENCY.keys())))

def run_stub(self, stub=None):
if stub is None:
stub = self.STUB_CODE
Expand Down Expand Up @@ -1312,6 +1320,13 @@ class ESP8266ROM(ESPLoader):
'16MB': 0x90,
}

FLASH_FREQUENCY = {
'80m': 0xf,
'40m': 0x0,
'26m': 0x1,
'20m': 0x2,
}

BOOTLOADER_FLASH_OFFSET = 0

MEMORY_MAP = [[0x3FF00000, 0x3FF00010, "DPORT"],
Expand Down Expand Up @@ -1492,6 +1507,13 @@ class ESP32ROM(ESPLoader):
'128MB': 0x70
}

FLASH_FREQUENCY = {
'80m': 0xf,
'40m': 0x0,
'26m': 0x1,
'20m': 0x2,
}

BOOTLOADER_FLASH_OFFSET = 0x1000

OVERRIDE_VDDSDIO_CHOICES = ["1.8V", "1.9V", "OFF"]
Expand Down Expand Up @@ -2312,6 +2334,13 @@ class ESP32H2BETA1ROM(ESP32ROM):

MEMORY_MAP = []

FLASH_FREQUENCY = {
'48m': 0xf,
'24m': 0x0,
'16m': 0x1,
'12m': 0x2,
}

def get_pkg_version(self):
num_word = 3
block1_addr = self.EFUSE_BASE + 0x044
Expand Down Expand Up @@ -2393,6 +2422,13 @@ class ESP32C2ROM(ESP32C3ROM):
EFUSE_BASE = 0x60008800
MAC_EFUSE_REG = EFUSE_BASE + 0x040

FLASH_FREQUENCY = {
'60m': 0xf,
'30m': 0x0,
'20m': 0x1,
'15m': 0x2,
}

def get_pkg_version(self):
num_word = 3
block1_addr = self.EFUSE_BASE + 0x044
Expand Down Expand Up @@ -3821,7 +3857,7 @@ def _update_image_flash_params(esp, address, args, image):

flash_freq = flash_size_freq & 0x0F
if args.flash_freq != 'keep':
flash_freq = {'40m': 0, '26m': 1, '20m': 2, '80m': 0xf}[args.flash_freq]
flash_freq = esp.parse_flash_freq_arg(args.flash_freq)

flash_size = flash_size_freq & 0xF0
if args.flash_size != 'keep':
Expand Down Expand Up @@ -4149,8 +4185,8 @@ def elf2image(args):
# ELFSection is a subclass of ImageSegment, so can use interchangeably
image.segments = e.segments if args.use_segments else e.sections

image.flash_size_freq = image.ROM_LOADER.FLASH_SIZES[args.flash_size]
image.flash_size_freq += {'40m': 0, '26m': 1, '20m': 2, '80m': 0xf}[args.flash_freq]
image.flash_size_freq = image.ROM_LOADER.parse_flash_size_arg(args.flash_size)
image.flash_size_freq += image.ROM_LOADER.parse_flash_freq_arg(args.flash_freq)

if args.elf_sha256_offset:
image.elf_sha256 = e.sha256()
Expand Down Expand Up @@ -4451,7 +4487,7 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect):
extra_fs_message = ""

parent.add_argument('--flash_freq', '-ff', help='SPI Flash frequency',
choices=extra_keep_args + ['40m', '26m', '20m', '80m'],
choices=extra_keep_args + ['80m', '60m', '48m', '40m', '30m', '26m', '24m', '20m', '16m', '15m', '12m'],
default=os.environ.get('ESPTOOL_FF', 'keep' if allow_keep else '40m'))
parent.add_argument('--flash_mode', '-fm', help='SPI Flash mode',
choices=extra_keep_args + ['qio', 'qout', 'dio', 'dout'],
Expand Down
4 changes: 2 additions & 2 deletions test/test_esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def setUp(self):
"esp32s3": "images/bootloader_esp32s3.bin",
"esp32c3": "images/bootloader_esp32c3.bin",
}[chip]
self.flash_offset = 0x1000 if chip in ("esp32", "esp32s2", "esp32s3") else 0 # bootloader offset
self.flash_offset = 0x1000 if chip in ("esp32", "esp32s2") else 0 # bootloader offset
with open(self.BL_IMAGE, "rb") as f:
self.header = f.read(8)

Expand Down Expand Up @@ -717,7 +717,7 @@ def test_deep_sleep_flash(self):


class TestBootloaderHeaderRewriteCases(EsptoolTestCase):
BL_OFFSET = 0x1000 if chip in ("esp32", "esp32s2", "esp32s3") else 0
BL_OFFSET = 0x1000 if chip in ("esp32", "esp32s2") else 0

def test_flash_header_rewrite(self):
bl_image = {"esp8266": "images/esp8266_sdk/boot_v1.4(b1).bin",
Expand Down

0 comments on commit 76d5553

Please sign in to comment.