test_verify_image.c 1.5 KB

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