return 0;
}
-static void distro_efi_get_fdt_name(char *fname, int size)
+/**
+ * distro_efi_get_fdt_name() - Get the filename for reading the .dtb file
+ *
+ * @fname: Place to put filename
+ * @size: Max size of filename
+ * @seq: Sequence number, to cycle through options (0=first)
+ * Returns: 0 on success, -ENOENT if the "fdtfile" env var does not exist,
+ * -EINVAL if there are no more options, -EALREADY if the control FDT should be
+ * used
+ */
+static int distro_efi_get_fdt_name(char *fname, int size, int seq)
{
const char *fdt_fname;
+ const char *prefix;
+
+ /* select the prefix */
+ switch (seq) {
+ case 0:
+ /* this is the default */
+ prefix = "/dtb";
+ break;
+ case 1:
+ prefix = "";
+ break;
+ case 2:
+ prefix = "/dtb/current";
+ break;
+ default:
+ return log_msg_ret("pref", -EINVAL);
+ }
fdt_fname = env_get("fdtfile");
if (fdt_fname) {
- snprintf(fname, size, "dtb/%s", fdt_fname);
+ snprintf(fname, size, "%s/%s", prefix, fdt_fname);
log_debug("Using device tree: %s\n", fname);
- } else {
+ } else if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE)) {
+ strcpy(fname, "<prior>");
+ return log_msg_ret("pref", -EALREADY);
+ /* Use this fallback only for 32-bit ARM */
+ } else if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_ARM64)) {
const char *soc = env_get("soc");
const char *board = env_get("board");
const char *boardver = env_get("boardver");
/* cf the code in label_boot() which seems very complex */
- snprintf(fname, size, "dtb/%s%s%s%s.dtb",
+ snprintf(fname, size, "%s/%s%s%s%s.dtb", prefix,
soc ? soc : "", soc ? "-" : "", board ? board : "",
boardver ? boardver : "");
log_debug("Using default device tree: %s\n", fname);
+ } else {
+ return log_msg_ret("env", -ENOENT);
}
+
+ return 0;
}
static int distro_efi_read_bootflow_file(struct udevice *dev,
struct blk_desc *desc = NULL;
ulong fdt_addr, size;
char fname[256];
- int ret;
+ int ret, seq;
/* We require a partition table */
if (!bflow->part)
if (ret)
return log_msg_ret("read", -EINVAL);
- distro_efi_get_fdt_name(fname, sizeof(fname));
+ fdt_addr = env_get_hex("fdt_addr_r", 0);
+
+ /* try the various available names */
+ ret = -ENOENT;
+ for (seq = 0; ret; seq++) {
+ ret = distro_efi_get_fdt_name(fname, sizeof(fname), seq);
+ if (ret == -EALREADY) {
+ bflow->flags = BOOTFLOWF_USE_PRIOR_FDT;
+ break;
+ }
+ if (ret)
+ return log_msg_ret("nam", ret);
+ ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr,
+ &size);
+ }
+
bflow->fdt_fname = strdup(fname);
if (!bflow->fdt_fname)
return log_msg_ret("fil", -ENOMEM);
- fdt_addr = env_get_hex("fdt_addr_r", 0);
- ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr, &size);
if (!ret) {
bflow->fdt_size = size;
bflow->fdt_addr = fdt_addr;
fdt_addr = hextoul(fdt_addr_str, NULL);
sprintf(file_addr, "%lx", fdt_addr);
- distro_efi_get_fdt_name(fname, sizeof(fname));
+ /* We only allow the first prefix with PXE */
+ ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0);
+ if (ret)
+ return log_msg_ret("nam", ret);
+
bflow->fdt_fname = strdup(fname);
if (!bflow->fdt_fname)
return log_msg_ret("fil", -ENOMEM);