Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | // SPDX-License-Identifier: GPL-2.0+ /* * Common functions for extlinux and PXE * * Copyright 2024 Collabora * Written by Martyn Welch <martyn.welch@collabora.com> */ #define LOG_CATEGORY UCLASS_BOOTSTD #include <dm.h> #include <extlinux.h> #include <mapmem.h> #include <linux/string.h> enum extlinux_option_type { EO_FALLBACK, EO_INVALID }; struct extlinux_option { char *name; enum extlinux_option_type option; }; static const struct extlinux_option options[] = { {"fallback", EO_FALLBACK}, {NULL, EO_INVALID} }; static enum extlinux_option_type extlinux_get_option(const char *option) { int i = 0; while (options[i].name) { if (!strcmp(options[i].name, option)) return options[i].option; i++; } return EO_INVALID; }; int extlinux_set_property(struct udevice *dev, const char *property, const char *value) { struct extlinux_plat *plat; static enum extlinux_option_type option; plat = dev_get_plat(dev); option = extlinux_get_option(property); if (option == EO_INVALID) { printf("Invalid option\n"); return -EINVAL; } switch (option) { case EO_FALLBACK: if (!strcmp(value, "1")) { plat->use_fallback = true; } else if (!strcmp(value, "0")) { plat->use_fallback = false; } else { printf("Unexpected value '%s'\n", value); return -EINVAL; } break; default: printf("Unrecognised property '%s'\n", property); return -EINVAL; } return 0; } static int extlinux_setup(struct udevice *dev, struct bootflow *bflow, pxe_getfile_func getfile, bool allow_abs_path, const char *bootfile, struct pxe_context *ctx) { struct extlinux_plat *plat = dev_get_plat(dev); int ret; plat->info.dev = dev; plat->info.bflow = bflow; ret = pxe_setup_ctx(ctx, getfile, &plat->info, allow_abs_path, bootfile, false, plat->use_fallback, bflow); if (ret) return log_msg_ret("ctx", ret); log_debug("bootfl flags %x\n", bflow->flags); if (bflow->flags & BOOTFLOWF_FAKE_GO) ctx->fake_go = true; return 0; } int extlinux_boot(struct udevice *dev, struct bootflow *bflow, pxe_getfile_func getfile, bool allow_abs_path, const char *bootfile, bool restart) { struct extlinux_plat *plat = dev_get_plat(dev); ulong addr; int ret; /* if we have already selected a label, just boot it */ if (plat->ctx.label) { plat->ctx.fake_go = bflow->flags & BOOTFLOWF_FAKE_GO; ret = pxe_do_boot(&plat->ctx); } else { ret = extlinux_setup(dev, bflow, getfile, allow_abs_path, bootfile, &plat->ctx); if (ret) return log_msg_ret("elb", ret); plat->ctx.restart = restart; addr = map_to_sysmem(bflow->buf); ret = pxe_process(&plat->ctx, addr, false); } if (ret) return log_msg_ret("elb", -EFAULT); return 0; } int extlinux_read_all(struct udevice *dev, struct bootflow *bflow, pxe_getfile_func getfile, bool allow_abs_path, const char *bootfile) { struct extlinux_plat *plat = dev_get_plat(dev); ulong addr; int ret; ret = extlinux_setup(dev, bflow, getfile, allow_abs_path, bootfile, &plat->ctx); if (ret) return log_msg_ret("era", ret); addr = map_to_sysmem(bflow->buf); ret = pxe_probe(&plat->ctx, addr, false); if (ret) return log_msg_ret("elb", -EFAULT); return 0; } |