Import bootloader from esp-idf v3
[apeos.git] / components / bootloader_support / test / test_verify_image.c
bloba7c3794922295bf9592549da9fc9c4d640d701ee
1 /*
2 * Tests for bootloader_support esp_load(ESP_IMAGE_VERIFY, ...)
3 */
5 #include <esp_types.h>
6 #include <stdio.h>
7 #include "rom/ets_sys.h"
9 #include "freertos/FreeRTOS.h"
10 #include "freertos/task.h"
11 #include "freertos/semphr.h"
12 #include "freertos/queue.h"
13 #include "freertos/xtensa_api.h"
14 #include "unity.h"
16 #include "esp_partition.h"
17 #include "esp_ota_ops.h"
18 #include "esp_image_format.h"
20 TEST_CASE("Verify bootloader image in flash", "[bootloader_support]")
22 const esp_partition_pos_t fake_bootloader_partition = {
23 .offset = ESP_BOOTLOADER_OFFSET,
24 .size = ESP_PARTITION_TABLE_OFFSET - ESP_BOOTLOADER_OFFSET,
26 esp_image_metadata_t data = { 0 };
27 TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_image_load(ESP_IMAGE_VERIFY, &fake_bootloader_partition, &data));
28 TEST_ASSERT_NOT_EQUAL(0, data.image_len);
30 uint32_t bootloader_length = 0;
31 TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_image_verify_bootloader(&bootloader_length));
32 TEST_ASSERT_EQUAL(data.image_len, bootloader_length);
35 TEST_CASE("Verify unit test app image", "[bootloader_support]")
37 esp_image_metadata_t data = { 0 };
38 const esp_partition_t *running = esp_ota_get_running_partition();
39 TEST_ASSERT_NOT_EQUAL(NULL, running);
40 const esp_partition_pos_t running_pos = {
41 .offset = running->address,
42 .size = running->size,
45 TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_image_load(ESP_IMAGE_VERIFY, &running_pos, &data));
46 TEST_ASSERT_NOT_EQUAL(0, data.image_len);
47 TEST_ASSERT_TRUE(data.image_len <= running->size);