1 // SPDX-License-Identifier: GPL-2.0+
10 * struct sysboot_info - useful information for sysboot helpers
12 * @fstype: Filesystem type (FS_TYPE_...)
13 * @ifname: Interface name (e.g. "ide", "scsi")
14 * @dev_part_str is in the format:
15 * <dev>.<hw_part>:<part> where <dev> is the device number,
16 * <hw_part> is the optional hardware partition number and
17 * <part> is the partition number
22 const char *dev_part_str;
25 static int sysboot_read_file(struct pxe_context *ctx, const char *file_path,
26 char *file_addr, ulong *sizep)
28 struct sysboot_info *info = ctx->userdata;
33 addr = simple_strtoul(file_addr, NULL, 16);
34 ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype);
37 ret = fs_read(file_path, addr, 0, 0, &len_read);
46 * Boots a system using a local disk syslinux/extlinux file
48 * Returns 0 on success, 1 on error.
50 static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
53 unsigned long pxefile_addr_r;
54 struct pxe_context ctx;
55 char *pxefile_addr_str;
56 struct sysboot_info info;
61 if (argc > 1 && strstr(argv[1], "-p")) {
68 return cmd_usage(cmdtp);
71 pxefile_addr_str = from_env("pxefile_addr_r");
72 if (!pxefile_addr_str)
75 pxefile_addr_str = argv[4];
79 filename = env_get("bootfile");
81 printf("Specify a filename or set the ${bootfile} environment variable\n");
86 env_set("bootfile", filename);
89 if (strstr(argv[3], "ext2")) {
90 info.fstype = FS_TYPE_EXT;
91 } else if (strstr(argv[3], "fat")) {
92 info.fstype = FS_TYPE_FAT;
93 } else if (strstr(argv[3], "any")) {
94 info.fstype = FS_TYPE_ANY;
96 printf("Invalid filesystem: %s\n", argv[3]);
99 info.ifname = argv[1];
100 info.dev_part_str = argv[2];
102 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
103 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
107 if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true,
108 filename, false, false)) {
109 printf("Out of memory\n");
110 return CMD_RET_FAILURE;
113 if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
114 printf("Error reading config file\n");
115 pxe_destroy_ctx(&ctx);
119 ret = pxe_process(&ctx, pxefile_addr_r, prompt);
120 pxe_destroy_ctx(&ctx);
122 return CMD_RET_FAILURE;
127 U_BOOT_CMD(sysboot, 7, 1, do_sysboot,
128 "command to get and boot from syslinux files",
129 "[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n"
130 " - load and parse syslinux menu file 'filename' from ext2, fat\n"
131 " or any filesystem on 'dev' on 'interface' to address 'addr'"