blob: 63edf1eb5c980cc46def143746129a36703f0e97 [file] [log] [blame]
Andrew Walbranbc342d42019-02-05 16:56:02 +00001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdalign.h>
18#include <stdint.h>
19
20#include "hf/fdt.h"
21#include "hf/memiter.h"
David Brazdil711fbe92019-08-06 13:39:58 +010022#include "hf/mm.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000023
24#include "hftest.h"
25#include "hftest_common.h"
26
27alignas(4096) uint8_t kstack[4096];
28
29extern struct hftest_test hftest_begin[];
30extern struct hftest_test hftest_end[];
31
32void kmain(const struct fdt_header *fdt)
33{
34 struct fdt_node n;
35 const char *bootargs;
36 uint32_t bootargs_size;
37 struct memiter bootargs_iter;
38 struct memiter command;
39
David Brazdil711fbe92019-08-06 13:39:58 +010040 /*
41 * Initialize the stage-1 MMU and identity-map the entire address space.
42 */
43 if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) {
44 HFTEST_LOG("Memory initialization failed.");
45 return;
46 }
47
Andrew Walbranbc342d42019-02-05 16:56:02 +000048 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
49
50 if (!fdt_root_node(&n, fdt)) {
51 HFTEST_LOG("FDT failed validation.");
52 return;
53 }
54
55 if (!fdt_find_child(&n, "")) {
56 HFTEST_LOG("Unable to find root node in FDT.");
57 return;
58 }
59
60 if (!fdt_find_child(&n, "chosen")) {
61 HFTEST_LOG("Unable to find 'chosen' node in FDT.");
62 return;
63 }
64
65 if (!fdt_read_property(&n, "bootargs", &bootargs, &bootargs_size)) {
66 HFTEST_LOG("Unable to read bootargs.");
67 return;
68 }
69
70 /* Remove null terminator. */
71 memiter_init(&bootargs_iter, bootargs, bootargs_size - 1);
72
73 if (!memiter_parse_str(&bootargs_iter, &command)) {
74 HFTEST_LOG("Unable to parse command.");
75 return;
76 }
77
78 if (memiter_iseq(&command, "json")) {
79 hftest_json();
80 return;
81 }
82
83 if (memiter_iseq(&command, "run")) {
84 struct memiter suite_name;
85 struct memiter test_name;
86
87 if (!memiter_parse_str(&bootargs_iter, &suite_name)) {
88 HFTEST_LOG("Unable to parse test suite.");
89 return;
90 }
91
92 if (!memiter_parse_str(&bootargs_iter, &test_name)) {
93 HFTEST_LOG("Unable to parse test.");
94 return;
95 }
Andrew Walbranafabe852019-03-20 17:55:11 +000096 hftest_run(suite_name, test_name, fdt);
Andrew Walbranbc342d42019-02-05 16:56:02 +000097 return;
98 }
99
100 hftest_help();
101}