configs: stm32mp15: Enable ENV_IS_IN_UBI
[oweals/u-boot.git] / lib / efi_selftest / efi_selftest_memory.c
index 0623e8e62daef25686b0e8b91da6b65ce6dbd0d9..e71732dc6db93aa108a7372d281b7516311dc7bd 100644 (file)
@@ -4,15 +4,19 @@
  *
  * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
  *
- * This unit test checks the following runtime services:
+ * This unit test checks the following boottime services:
  * AllocatePages, FreePages, GetMemoryMap
+ *
+ * The memory type used for the device tree is checked.
  */
 
 #include <efi_selftest.h>
 
 #define EFI_ST_NUM_PAGES 8
 
+static const efi_guid_t fdt_guid = EFI_FDT_GUID;
 static struct efi_boot_services *boottime;
+static u64 fdt_addr;
 
 /**
  * setup() - setup unit test
@@ -24,8 +28,20 @@ static struct efi_boot_services *boottime;
 static int setup(const efi_handle_t handle,
                 const struct efi_system_table *systable)
 {
+       size_t i;
+
        boottime = systable->boottime;
 
+       for (i = 0; i < systable->nr_tables; ++i) {
+               if (!memcmp(&systable->tables[i].guid, &fdt_guid,
+                           sizeof(efi_guid_t))) {
+                       if (fdt_addr) {
+                               efi_st_error("Duplicate device tree\n");
+                               return EFI_ST_FAILURE;
+                       }
+                       fdt_addr = (uintptr_t)systable->tables[i].table;
+               }
+       }
        return EFI_ST_SUCCESS;
 }
 
@@ -49,6 +65,11 @@ static int find_in_memory_map(efi_uintn_t map_size,
        for (i = 0; map_size; ++i, map_size -= desc_size) {
                struct efi_mem_desc *entry = &memory_map[i];
 
+               if (entry->physical_start != entry->virtual_start) {
+                       efi_st_error("Physical and virtual addresses do not match\n");
+                       return EFI_ST_FAILURE;
+               }
+
                if (addr >= entry->physical_start &&
                    addr < entry->physical_start +
                            (entry->num_pages << EFI_PAGE_SHIFT)) {
@@ -152,6 +173,14 @@ static int execute(void)
                return EFI_ST_FAILURE;
        }
 
+       /* Check memory reservation for the device tree */
+       if (fdt_addr &&
+           find_in_memory_map(map_size, memory_map, desc_size, fdt_addr,
+                              EFI_BOOT_SERVICES_DATA) != EFI_ST_SUCCESS) {
+               efi_st_error
+                       ("Device tree not marked as boot services data\n");
+               return EFI_ST_FAILURE;
+       }
        return EFI_ST_SUCCESS;
 }