|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ricardo Pardini <ricardo@pardini.net> |
| 3 | +Date: Mon, 12 Jan 2026 18:26:25 +0100 |
| 4 | +Subject: fdt_fixup_ethernet: add logs |
| 5 | + |
| 6 | +--- |
| 7 | + boot/fdt_support.c | 56 +++++++--- |
| 8 | + boot/image-fdt.c | 18 +++ |
| 9 | + 2 files changed, 59 insertions(+), 15 deletions(-) |
| 10 | + |
| 11 | +diff --git a/boot/fdt_support.c b/boot/fdt_support.c |
| 12 | +index 111111111111..222222222222 100644 |
| 13 | +--- a/boot/fdt_support.c |
| 14 | ++++ b/boot/fdt_support.c |
| 15 | +@@ -632,27 +632,31 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size) |
| 16 | + |
| 17 | + void fdt_fixup_ethernet(void *fdt) |
| 18 | + { |
| 19 | ++ log_info("[fdt_fixup_ethernet] called\n"); |
| 20 | + int i = 0, j, prop; |
| 21 | + char *tmp, *end; |
| 22 | + char mac[16]; |
| 23 | + const char *path; |
| 24 | + unsigned char mac_addr[ARP_HLEN]; |
| 25 | + int offset; |
| 26 | ++ int total_aliases = 0, total_attempted = 0, total_skipped = 0, total_patched = 0; |
| 27 | + #ifdef FDT_SEQ_MACADDR_FROM_ENV |
| 28 | + int nodeoff; |
| 29 | + const struct fdt_property *fdt_prop; |
| 30 | + #endif |
| 31 | + |
| 32 | +- if (fdt_path_offset(fdt, "/aliases") < 0) |
| 33 | ++ int aliases_off = fdt_path_offset(fdt, "/aliases"); |
| 34 | ++ if (aliases_off < 0) { |
| 35 | ++ log_info("[fdt_fixup_ethernet] /aliases node not found\n"); |
| 36 | + return; |
| 37 | ++ } |
| 38 | + |
| 39 | + /* Cycle through all aliases */ |
| 40 | + for (prop = 0; ; prop++) { |
| 41 | + const char *name; |
| 42 | + |
| 43 | + /* FDT might have been edited, recompute the offset */ |
| 44 | +- offset = fdt_first_property_offset(fdt, |
| 45 | +- fdt_path_offset(fdt, "/aliases")); |
| 46 | ++ offset = fdt_first_property_offset(fdt, aliases_off); |
| 47 | + /* Select property number 'prop' */ |
| 48 | + for (j = 0; j < prop; j++) |
| 49 | + offset = fdt_next_property_offset(fdt, offset); |
| 50 | +@@ -660,7 +664,10 @@ void fdt_fixup_ethernet(void *fdt) |
| 51 | + if (offset < 0) |
| 52 | + break; |
| 53 | + |
| 54 | ++ total_aliases++; |
| 55 | + path = fdt_getprop_by_offset(fdt, offset, &name, NULL); |
| 56 | ++ log_info("[fdt_fixup_ethernet] alias #%d: name='%s', path='%s'\n", prop, name, path ? path : "<null>"); |
| 57 | ++ |
| 58 | + if (!strncmp(name, "ethernet", 8)) { |
| 59 | + /* Treat plain "ethernet" same as "ethernet0". */ |
| 60 | + if (!strcmp(name, "ethernet") |
| 61 | +@@ -679,33 +686,52 @@ void fdt_fixup_ethernet(void *fdt) |
| 62 | + else |
| 63 | + sprintf(mac, "eth%daddr", i); |
| 64 | + } else { |
| 65 | ++ log_info("[fdt_fixup_ethernet] Skipping alias '%s' (invalid index)\n", name); |
| 66 | ++ total_skipped++; |
| 67 | + continue; |
| 68 | + } |
| 69 | + #ifdef FDT_SEQ_MACADDR_FROM_ENV |
| 70 | + nodeoff = fdt_path_offset(fdt, path); |
| 71 | +- fdt_prop = fdt_get_property(fdt, nodeoff, "status", |
| 72 | +- NULL); |
| 73 | +- if (fdt_prop && !strcmp(fdt_prop->data, "disabled")) |
| 74 | ++ fdt_prop = fdt_get_property(fdt, nodeoff, "status", NULL); |
| 75 | ++ if (fdt_prop && !strcmp(fdt_prop->data, "disabled")) { |
| 76 | ++ log_info("[fdt_fixup_ethernet] Node '%s' is disabled, skipping\n", path); |
| 77 | ++ total_skipped++; |
| 78 | + continue; |
| 79 | ++ } |
| 80 | + i++; |
| 81 | + #endif |
| 82 | ++ total_attempted++; |
| 83 | + tmp = env_get(mac); |
| 84 | +- if (!tmp) |
| 85 | ++ log_info("[fdt_fixup_ethernet] env var for alias '%s' is '%s', value='%s'\n", name, mac, tmp ? tmp : "<not set>"); |
| 86 | ++ if (!tmp) { |
| 87 | ++ log_info("[fdt_fixup_ethernet] env var '%s' not set, skipping\n", mac); |
| 88 | ++ total_skipped++; |
| 89 | + continue; |
| 90 | +- |
| 91 | ++ } |
| 92 | ++ int nodeoff = fdt_path_offset(fdt, path); |
| 93 | ++ if (nodeoff < 0) { |
| 94 | ++ log_info("[fdt_fixup_ethernet] Node path '%s' not found, skipping\n", path); |
| 95 | ++ total_skipped++; |
| 96 | ++ continue; |
| 97 | ++ } |
| 98 | ++ const struct fdt_property *status_prop = fdt_get_property(fdt, nodeoff, "status", NULL); |
| 99 | ++ if (status_prop && strcmp((const char *)status_prop->data, "okay")) { |
| 100 | ++ log_info("[fdt_fixup_ethernet] Node '%s' status is '%s', skipping\n", path, (const char *)status_prop->data); |
| 101 | ++ total_skipped++; |
| 102 | ++ continue; |
| 103 | ++ } |
| 104 | + for (j = 0; j < 6; j++) { |
| 105 | +- mac_addr[j] = tmp ? |
| 106 | +- hextoul(tmp, &end) : 0; |
| 107 | ++ mac_addr[j] = tmp ? hextoul(tmp, &end) : 0; |
| 108 | + if (tmp) |
| 109 | + tmp = (*end) ? end + 1 : end; |
| 110 | + } |
| 111 | +- |
| 112 | +- do_fixup_by_path(fdt, path, "mac-address", |
| 113 | +- &mac_addr, 6, 0); |
| 114 | +- do_fixup_by_path(fdt, path, "local-mac-address", |
| 115 | +- &mac_addr, 6, 1); |
| 116 | ++ log_info("[fdt_fixup_ethernet] Patching node '%s' (offset %d) with MAC %02x:%02x:%02x:%02x:%02x:%02x\n", path, nodeoff, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); |
| 117 | ++ do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0); |
| 118 | ++ do_fixup_by_path(fdt, path, "local-mac-address", &mac_addr, 6, 1); |
| 119 | ++ total_patched++; |
| 120 | + } |
| 121 | + } |
| 122 | ++ log_info("[fdt_fixup_ethernet] SUMMARY: aliases found=%d, attempted=%d, skipped=%d, patched=%d\n", total_aliases, total_attempted, total_skipped, total_patched); |
| 123 | + } |
| 124 | + |
| 125 | + int fdt_record_loadable(void *blob, u32 index, const char *name, |
| 126 | +diff --git a/boot/image-fdt.c b/boot/image-fdt.c |
| 127 | +index 111111111111..222222222222 100644 |
| 128 | +--- a/boot/image-fdt.c |
| 129 | ++++ b/boot/image-fdt.c |
| 130 | +@@ -1,3 +1,4 @@ |
| 131 | ++#warning "Building image-fdt.c: fdt fixup call chain instrumented for MAC debugging." |
| 132 | + // SPDX-License-Identifier: GPL-2.0+ |
| 133 | + /* |
| 134 | + * Copyright (c) 2013, Google Inc. |
| 135 | +@@ -586,11 +587,25 @@ __weak int ft_verify_fdt(void *fdt) |
| 136 | + |
| 137 | + __weak int arch_fixup_fdt(void *blob) |
| 138 | + { |
| 139 | ++ log_info("[arch_fixup_fdt] called (weak stub)\n"); |
| 140 | ++ return 0; |
| 141 | ++} |
| 142 | ++ |
| 143 | ++__weak int ft_board_setup(void *blob, struct bd_info *bd) |
| 144 | ++{ |
| 145 | ++ log_info("[ft_board_setup] called (weak stub)\n"); |
| 146 | ++ return 0; |
| 147 | ++} |
| 148 | ++ |
| 149 | ++__weak int ft_system_setup(void *blob, struct bd_info *bd) |
| 150 | ++{ |
| 151 | ++ log_info("[ft_system_setup] called (weak stub)\n"); |
| 152 | + return 0; |
| 153 | + } |
| 154 | + |
| 155 | + int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) |
| 156 | + { |
| 157 | ++ log_info("[image_setup_libfdt] called\n"); |
| 158 | + ulong *initrd_start = &images->initrd_start; |
| 159 | + ulong *initrd_end = &images->initrd_end; |
| 160 | + bool skip_board_fixup = false; |
| 161 | +@@ -638,6 +653,7 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) |
| 162 | + strlen(images->fit_uname_cfg) + 1, 1); |
| 163 | + |
| 164 | + /* Update ethernet nodes */ |
| 165 | ++ log_info("[image_setup_libfdt] calling fdt_fixup_ethernet\n"); |
| 166 | + fdt_fixup_ethernet(blob); |
| 167 | + #if IS_ENABLED(CONFIG_CMD_PSTORE) |
| 168 | + /* Append PStore configuration */ |
| 169 | +@@ -651,6 +667,7 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) |
| 170 | + } |
| 171 | + |
| 172 | + if (IS_ENABLED(CONFIG_OF_BOARD_SETUP) && !skip_board_fixup) { |
| 173 | ++ log_info("[image_setup_libfdt] calling ft_board_setup\n"); |
| 174 | + fdt_ret = ft_board_setup(blob, gd->bd); |
| 175 | + if (fdt_ret) { |
| 176 | + printf("ERROR: board-specific fdt fixup failed: %s\n", |
| 177 | +@@ -659,6 +676,7 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) |
| 178 | + } |
| 179 | + } |
| 180 | + if (IS_ENABLED(CONFIG_OF_SYSTEM_SETUP)) { |
| 181 | ++ log_info("[image_setup_libfdt] calling ft_system_setup\n"); |
| 182 | + fdt_ret = ft_system_setup(blob, gd->bd); |
| 183 | + if (fdt_ret) { |
| 184 | + printf("ERROR: system-specific fdt fixup failed: %s\n", |
| 185 | +-- |
| 186 | +Armbian |
| 187 | + |
0 commit comments