Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/stand/efiboot Deduplicate lazy /chosen node creation logic.
details: https://anonhg.NetBSD.org/src/rev/70e6787c1434
branches: trunk
changeset: 932738:70e6787c1434
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu May 14 19:21:53 2020 +0000
description:
Deduplicate lazy /chosen node creation logic.
diffstat:
sys/stand/efiboot/efifdt.c | 55 ++++++++++++++++++---------------------------
1 files changed, 22 insertions(+), 33 deletions(-)
diffs (104 lines):
diff -r db13ed4bf663 -r 70e6787c1434 sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c Thu May 14 19:21:35 2020 +0000
+++ b/sys/stand/efiboot/efifdt.c Thu May 14 19:21:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.22 2020/05/14 19:20:08 riastradh Exp $ */
+/* $NetBSD: efifdt.c,v 1.23 2020/05/14 19:21:53 riastradh Exp $ */
/*-
* Copyright (c) 2019 Jason R. Thorpe
@@ -185,6 +185,22 @@
printf("]\n");
}
+static int
+efi_fdt_chosen(void)
+{
+ int chosen;
+
+ chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
+ if (chosen < 0)
+ chosen = fdt_add_subnode(fdt_data,
+ fdt_path_offset(fdt_data, "/"),
+ FDT_CHOSEN_NODE_NAME);
+ if (chosen < 0)
+ panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+
+ return chosen;
+}
+
void
efi_fdt_memory_map(void)
{
@@ -200,11 +216,7 @@
if (memory < 0)
panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
- chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
- if (chosen < 0)
- chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
- if (chosen < 0)
- panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+ chosen = efi_fdt_chosen();
fdt_delprop(fdt_data, memory, "reg");
@@ -335,11 +347,7 @@
uint8_t macaddr[6];
int chosen;
- chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
- if (chosen < 0)
- chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
- if (chosen < 0)
- panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+ chosen = efi_fdt_chosen();
if (*bootargs)
fdt_setprop_string(fdt_data, chosen, "bootargs", bootargs);
@@ -381,12 +389,7 @@
if (initrd_size == 0)
return;
- chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
- if (chosen < 0)
- chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
- if (chosen < 0)
- panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+ chosen = efi_fdt_chosen();
fdt_setprop_u64(fdt_data, chosen, "linux,initrd-start", initrd_addr);
fdt_setprop_u64(fdt_data, chosen, "linux,initrd-end", initrd_addr + initrd_size);
}
@@ -400,14 +403,7 @@
if (rndseed_size == 0)
return;
- chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
- if (chosen < 0)
- chosen = fdt_add_subnode(fdt_data,
- fdt_path_offset(fdt_data, "/"),
- FDT_CHOSEN_NODE_NAME);
- if (chosen < 0)
- panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+ chosen = efi_fdt_chosen();
fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-start",
rndseed_addr);
fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-end",
@@ -423,14 +419,7 @@
if (efirng_size == 0)
return;
- chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
- if (chosen < 0)
- chosen = fdt_add_subnode(fdt_data,
- fdt_path_offset(fdt_data, "/"),
- FDT_CHOSEN_NODE_NAME);
- if (chosen < 0)
- panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+ chosen = efi_fdt_chosen();
fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-start",
efirng_addr);
fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",
Home |
Main Index |
Thread Index |
Old Index