Skip to content

Commit c871c34

Browse files
committed
Merge branch 'bugfix/bootloader_common_get_sha256_of_partition' into 'master'
bootloader_support: Fix bootloader_common_get_sha256_of_partition(), can handle a long image Closes IDFGH-3594 See merge request espressif/esp-idf!9509
2 parents 49907bd + d95c89a commit c871c34

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

components/bootloader_support/src/bootloader_common.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "esp_flash_partitions.h"
2929
#include "bootloader_flash.h"
3030
#include "bootloader_common.h"
31+
#include "bootloader_utility.h"
3132
#include "soc/gpio_periph.h"
3233
#include "soc/rtc.h"
3334
#include "soc/efuse_reg.h"
@@ -186,22 +187,7 @@ esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t
186187
size = data.image_len;
187188
}
188189
// If image is type by data then hash is calculated for entire image.
189-
const void *partition_bin = bootloader_mmap(address, size);
190-
if (partition_bin == NULL) {
191-
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", address, size);
192-
return ESP_FAIL;
193-
}
194-
bootloader_sha256_handle_t sha_handle = bootloader_sha256_start();
195-
if (sha_handle == NULL) {
196-
bootloader_munmap(partition_bin);
197-
return ESP_ERR_NO_MEM;
198-
}
199-
bootloader_sha256_data(sha_handle, partition_bin, size);
200-
bootloader_sha256_finish(sha_handle, out_sha_256);
201-
202-
bootloader_munmap(partition_bin);
203-
204-
return ESP_OK;
190+
return bootloader_sha256_flash_contents(address, size, out_sha_256);
205191
}
206192

207193
int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, bool *valid_two_otadata, bool max)

components/spi_flash/test/test_partitions.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,27 @@ TEST_CASE("Test esp_partition_get_sha256() with app", "[spi_flash]")
122122
TEST_ASSERT_MESSAGE(found_valid_app, "At least one app partition should be a valid app partition");
123123
}
124124

125+
TEST_CASE("Test esp_partition_get_sha256() that it can handle a big partition", "[spi_flash]")
126+
{
127+
esp_partition_t partition;
128+
const void *ptr;
129+
spi_flash_mmap_handle_t handle;
130+
131+
uint8_t sha256[32] = { 0 };
132+
size_t size_flash_chip = spi_flash_get_chip_size();
133+
134+
printf("size_flash_chip = %d bytes\n", size_flash_chip);
135+
136+
ESP_ERROR_CHECK(spi_flash_mmap(0x00000000, size_flash_chip * 7 / 10, SPI_FLASH_MMAP_DATA, &ptr, &handle));
137+
TEST_ASSERT_NOT_NULL(ptr);
138+
139+
partition.address = 0x00000000;
140+
partition.size = size_flash_chip;
141+
partition.type = ESP_PARTITION_TYPE_DATA;
142+
143+
ESP_ERROR_CHECK(esp_partition_get_sha256(&partition, sha256));
144+
ESP_LOG_BUFFER_HEX("sha", sha256, sizeof(sha256));
145+
146+
spi_flash_munmap(handle);
147+
}
148+

0 commit comments

Comments
 (0)