Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/sys/stand/efiboot Deduplicate lazy /chosen node creati...



details:   https://anonhg.NetBSD.org/src-all/rev/b99107cdca9f
branches:  trunk
changeset: 932719:b99107cdca9f
user:      Taylor R Campbell <riastradh%NetBSD.org@localhost>
date:      Thu May 14 16:33:03 2020 +0000

description:
Deduplicate lazy /chosen node creation logic.

diffstat:

 sys/stand/efiboot/efifdt.c |  53 ++++++++++++++++++---------------------------
 1 files changed, 21 insertions(+), 32 deletions(-)

diffs (98 lines):

diff -r 494e921a6fca -r b99107cdca9f sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c        Mon May 11 02:12:09 2020 +0000
+++ b/sys/stand/efiboot/efifdt.c        Thu May 14 16:33:03 2020 +0000
@@ -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