mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bbbede07d0
The size of partition of type APP should be multiple of 4 KB. Partition generation tool now make this as a mandatory requirement. This is minimum flash erase size. If the size of the APP type partition is not aligned to 4 KB then the last erase operation could go beyond the allocated partition and hence may fail. This issue would only be observed when the firmware size grows very close to the allocated partition size, and hence causing the OTA update to fail. For already deployed devices on-field with the size of APP partition not aligned to flash sector boundary, it is best to ensure that firmware size always remains within the lower 4 KB boundary of the total allocated space. While migrating to ESP-IDF 5.3 release, partition table for an existing project can be adjusted accordingly for the build to succeed. Found during discussion in https://github.com/espressif/esp-idf/pull/12460
45 lines
2.2 KiB
Python
45 lines
2.2 KiB
Python
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import logging
|
|
import os
|
|
import re
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from test_build_system_helpers import EnvDict, IdfPyFunc, append_to_file, replace_in_file
|
|
|
|
|
|
@pytest.mark.usefixtures('test_app_copy')
|
|
def test_partition_table(idf_py: IdfPyFunc) -> None:
|
|
logging.info('Displays partition table when executing target partition_table')
|
|
ret = idf_py('partition-table')
|
|
assert re.search('# ESP-IDF.+Partition Table', ret.stdout)
|
|
|
|
|
|
def test_partitions_dont_fit_in_flash(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
|
|
logging.info("Build fails if partitions don't fit in flash")
|
|
append_to_file(test_app_copy / 'sdkconfig', 'CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y')
|
|
ret = idf_py('build', check=False)
|
|
assert ret.returncode == 2
|
|
assert 'does not fit in configured flash size 1MB' in ret.stdout
|
|
|
|
|
|
def test_partition_nearly_full_warning(idf_py: IdfPyFunc, test_app_copy: Path, default_idf_env: EnvDict) -> None:
|
|
logging.info('Warning is given if smallest partition is nearly full')
|
|
ret = idf_py('build')
|
|
# Build a first time to get the binary size and to check that no warning is issued.
|
|
assert 'partition is nearly full' not in ret.stdout, 'Warning for nearly full smallest partition was given when the condition is not fulfilled'
|
|
# Get the size of the binary, in KB. Convert it to next multiple of 4.
|
|
# The goal is to create an app partition which is slightly bigger than the binary itself
|
|
updated_file_size = int((os.stat(test_app_copy / 'build' / 'build_test_app.bin').st_size + 4095) / 4096) * 4
|
|
idf_path = Path(default_idf_env['IDF_PATH'])
|
|
shutil.copy2(idf_path / 'components' / 'partition_table' / 'partitions_singleapp.csv', test_app_copy / 'partitions.csv')
|
|
replace_in_file(test_app_copy / 'partitions.csv',
|
|
'factory, app, factory, , 1M',
|
|
f'factory, app, factory, , {updated_file_size}K')
|
|
(test_app_copy / 'sdkconfig').write_text('\n'.join(['CONFIG_PARTITION_TABLE_CUSTOM=y', 'CONFIG_FREERTOS_SMP=n']))
|
|
ret = idf_py('build', check=False)
|
|
assert 'partition is nearly full' in ret.stdout
|