Eddie James | 1a55a7a | 2023-10-24 10:43:51 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for measured boot functions |
| 4 | * |
| 5 | * Copyright 2023 IBM Corp. |
| 6 | * Written by Eddie James <eajames@linux.ibm.com> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootm.h> |
| 11 | #include <malloc.h> |
| 12 | #include <test/suites.h> |
| 13 | #include <test/test.h> |
| 14 | #include <test/ut.h> |
| 15 | #include <asm/io.h> |
| 16 | |
| 17 | #define MEASUREMENT_TEST(_name, _flags) \ |
| 18 | UNIT_TEST(_name, _flags, measurement_test) |
| 19 | |
| 20 | static int measure(struct unit_test_state *uts) |
| 21 | { |
| 22 | struct bootm_headers images; |
| 23 | const size_t size = 1024; |
| 24 | u8 *kernel; |
| 25 | u8 *initrd; |
| 26 | size_t i; |
| 27 | |
| 28 | kernel = malloc(size); |
| 29 | initrd = malloc(size); |
| 30 | |
| 31 | images.os.image_start = map_to_sysmem(kernel); |
| 32 | images.os.image_len = size; |
| 33 | |
| 34 | images.rd_start = map_to_sysmem(initrd); |
| 35 | images.rd_end = images.rd_start + size; |
| 36 | |
| 37 | images.ft_addr = malloc(size); |
| 38 | images.ft_len = size; |
| 39 | |
| 40 | env_set("bootargs", "measurement testing"); |
| 41 | |
| 42 | for (i = 0; i < size; ++i) { |
| 43 | kernel[i] = 0xf0 | (i & 0xf); |
| 44 | initrd[i] = (i & 0xf0) | 0xf; |
| 45 | images.ft_addr[i] = i & 0xff; |
| 46 | } |
| 47 | |
| 48 | ut_assertok(bootm_measure(&images)); |
| 49 | |
| 50 | free(images.ft_addr); |
| 51 | free(initrd); |
| 52 | free(kernel); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | MEASUREMENT_TEST(measure, 0); |
| 57 | |
| 58 | int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc, |
| 59 | char *const argv[]) |
| 60 | { |
| 61 | struct unit_test *tests = UNIT_TEST_SUITE_START(measurement_test); |
| 62 | const int n_ents = UNIT_TEST_SUITE_COUNT(measurement_test); |
| 63 | |
| 64 | return cmd_ut_category("measurement", "measurement_test_", tests, |
| 65 | n_ents, argc, argv); |
| 66 | } |