summaryrefslogtreecommitdiff
path: root/sys/arch/armv7
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-03-30 11:55:48 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-03-30 11:55:48 +0000
commit7655bdf1fde7b7bd87f8b007ceec537f5759d51c (patch)
tree9c1ddb7b0b2b01ca670f17e3c8abbee0a26a6211 /sys/arch/armv7
parentb64a0f7033b0cf30794781452a6b0451b986899b (diff)
Port "mach dtb" code from arm64.
ok patrick@
Diffstat (limited to 'sys/arch/armv7')
-rw-r--r--sys/arch/armv7/stand/efiboot/conf.c4
-rw-r--r--sys/arch/armv7/stand/efiboot/efiboot.c90
2 files changed, 86 insertions, 8 deletions
diff --git a/sys/arch/armv7/stand/efiboot/conf.c b/sys/arch/armv7/stand/efiboot/conf.c
index aae1ae245bb..36a04364997 100644
--- a/sys/arch/armv7/stand/efiboot/conf.c
+++ b/sys/arch/armv7/stand/efiboot/conf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf.c,v 1.24 2020/03/22 14:59:11 kettenis Exp $ */
+/* $OpenBSD: conf.c,v 1.25 2020/03/30 11:55:47 kettenis Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -42,7 +42,7 @@
#include "efidev.h"
#include "efipxe.h"
-const char version[] = "1.11";
+const char version[] = "1.12";
int debug = 0;
struct fs_ops file_system[] = {
diff --git a/sys/arch/armv7/stand/efiboot/efiboot.c b/sys/arch/armv7/stand/efiboot/efiboot.c
index 904fe4979f8..740dd35396b 100644
--- a/sys/arch/armv7/stand/efiboot/efiboot.c
+++ b/sys/arch/armv7/stand/efiboot/efiboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: efiboot.c,v 1.27 2020/03/22 14:59:11 kettenis Exp $ */
+/* $OpenBSD: efiboot.c,v 1.28 2020/03/30 11:55:47 kettenis Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -63,6 +63,7 @@ static void efi_heap_init(void);
static void efi_memprobe_internal(void);
static void efi_timer_init(void);
static void efi_timer_cleanup(void);
+static EFI_STATUS efi_memprobe_find(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *);
EFI_STATUS
efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
@@ -466,6 +467,7 @@ efi_console(void)
fdt_node_add_property(node, "stdout-path", path, strlen(path) + 1);
}
+void *fdt = NULL;
char *bootmac = NULL;
static EFI_GUID fdt_guid = FDT_TABLE_GUID;
@@ -474,7 +476,6 @@ static EFI_GUID fdt_guid = FDT_TABLE_GUID;
void *
efi_makebootargs(char *bootargs, uint32_t *board_id)
{
- void *fdt = NULL;
u_char bootduid[8];
u_char zero[8] = { 0 };
uint64_t uefi_system_table = htobe64((uintptr_t)ST);
@@ -482,10 +483,12 @@ efi_makebootargs(char *bootargs, uint32_t *board_id)
size_t len;
int i;
- for (i = 0; i < ST->NumberOfTableEntries; i++) {
- if (efi_guidcmp(&fdt_guid,
- &ST->ConfigurationTable[i].VendorGuid) == 0)
- fdt = ST->ConfigurationTable[i].VendorTable;
+ if (fdt == NULL) {
+ for (i = 0; i < ST->NumberOfTableEntries; i++) {
+ if (efi_guidcmp(&fdt_guid,
+ &ST->ConfigurationTable[i].VendorGuid) == 0)
+ fdt = ST->ConfigurationTable[i].VendorTable;
+ }
}
if (!fdt_init(fdt))
@@ -871,20 +874,95 @@ efi_memprobe_internal(void)
mmap_version = mmver;
}
+static EFI_STATUS
+efi_memprobe_find(UINTN pages, UINTN align, EFI_PHYSICAL_ADDRESS *addr)
+{
+ EFI_MEMORY_DESCRIPTOR *mm;
+ int i, j;
+
+ if (align < EFI_PAGE_SIZE)
+ return EFI_INVALID_PARAMETER;
+
+ efi_memprobe_internal(); /* sync the current map */
+
+ for (i = 0, mm = mmap; i < mmap_ndesc;
+ i++, mm = NextMemoryDescriptor(mm, mmap_descsiz)) {
+ if (mm->Type != EfiConventionalMemory)
+ continue;
+
+ if (mm->NumberOfPages < pages)
+ continue;
+
+ for (j = 0; j < mm->NumberOfPages; j++) {
+ EFI_PHYSICAL_ADDRESS paddr;
+
+ if (mm->NumberOfPages - j < pages)
+ break;
+
+ paddr = mm->PhysicalStart + (j * EFI_PAGE_SIZE);
+ if (paddr & (align - 1))
+ continue;
+
+ if (EFI_CALL(BS->AllocatePages, AllocateAddress,
+ EfiLoaderData, pages, &paddr) == EFI_SUCCESS) {
+ *addr = paddr;
+ return EFI_SUCCESS;
+ }
+ }
+ }
+ return EFI_OUT_OF_RESOURCES;
+}
+
/*
* Commands
*/
+int Xdtb_efi(void);
int Xexit_efi(void);
int Xpoweroff_efi(void);
const struct cmd_table cmd_machine[] = {
+ { "dtb", CMDT_CMD, Xdtb_efi },
{ "exit", CMDT_CMD, Xexit_efi },
{ "poweroff", CMDT_CMD, Xpoweroff_efi },
{ NULL, 0 }
};
int
+Xdtb_efi(void)
+{
+ EFI_PHYSICAL_ADDRESS addr;
+ char path[MAXPATHLEN];
+ struct stat sb;
+ int fd;
+
+#define O_RDONLY 0
+
+ if (cmd.argc != 2)
+ return (1);
+
+ snprintf(path, sizeof(path), "%s:%s", cmd.bootdev, cmd.argv[1]);
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0 || fstat(fd, &sb) == -1) {
+ printf("cannot open %s\n", path);
+ return (1);
+ }
+ if (efi_memprobe_find(EFI_SIZE_TO_PAGES(sb.st_size),
+ 0x1000, &addr) != EFI_SUCCESS) {
+ printf("cannot allocate memory for %s\n", path);
+ return (1);
+ }
+ if (read(fd, (void *)addr, sb.st_size) != sb.st_size) {
+ printf("cannot read from %s\n", path);
+ return (1);
+ }
+
+ fdt = (void *)addr;
+ return (0);
+}
+
+int
Xexit_efi(void)
{
EFI_CALL(BS->Exit, IH, 0, 0, NULL);