Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | #include <common.h> |
| 4 | #include <command.h> |
| 5 | #include <env.h> |
| 6 | #include <fs.h> |
Simon Glass | 262cfb5 | 2021-10-14 12:48:00 -0600 | [diff] [blame] | 7 | #include <pxe_utils.h> |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 8 | |
| 9 | static char *fs_argv[5]; |
| 10 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 11 | static int do_get_ext2(struct pxe_context *ctx, const char *file_path, |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | char *file_addr) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 13 | { |
| 14 | #ifdef CONFIG_CMD_EXT2 |
| 15 | fs_argv[0] = "ext2load"; |
| 16 | fs_argv[3] = file_addr; |
| 17 | fs_argv[4] = (void *)file_path; |
| 18 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 19 | if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv)) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 20 | return 1; |
| 21 | #endif |
| 22 | return -ENOENT; |
| 23 | } |
| 24 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 25 | static int do_get_fat(struct pxe_context *ctx, const char *file_path, |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | char *file_addr) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 27 | { |
| 28 | #ifdef CONFIG_CMD_FAT |
| 29 | fs_argv[0] = "fatload"; |
| 30 | fs_argv[3] = file_addr; |
| 31 | fs_argv[4] = (void *)file_path; |
| 32 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 33 | if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv)) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 34 | return 1; |
| 35 | #endif |
| 36 | return -ENOENT; |
| 37 | } |
| 38 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 39 | static int do_get_any(struct pxe_context *ctx, const char *file_path, |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 40 | char *file_addr) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 41 | { |
| 42 | #ifdef CONFIG_CMD_FS_GENERIC |
| 43 | fs_argv[0] = "load"; |
| 44 | fs_argv[3] = file_addr; |
| 45 | fs_argv[4] = (void *)file_path; |
| 46 | |
Simon Glass | b1ead6b | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 47 | if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY)) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 48 | return 1; |
| 49 | #endif |
| 50 | return -ENOENT; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Boots a system using a local disk syslinux/extlinux file |
| 55 | * |
| 56 | * Returns 0 on success, 1 on error. |
| 57 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 58 | static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, |
| 59 | char *const argv[]) |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 60 | { |
| 61 | unsigned long pxefile_addr_r; |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 62 | pxe_getfile_func getfile; |
Simon Glass | fd3fa5c | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 63 | struct pxe_context ctx; |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 64 | char *pxefile_addr_str; |
| 65 | char *filename; |
| 66 | int prompt = 0; |
Simon Glass | 9e62e7c | 2021-10-14 12:48:03 -0600 | [diff] [blame] | 67 | int ret; |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 68 | |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 69 | if (argc > 1 && strstr(argv[1], "-p")) { |
| 70 | prompt = 1; |
| 71 | argc--; |
| 72 | argv++; |
| 73 | } |
| 74 | |
| 75 | if (argc < 4) |
| 76 | return cmd_usage(cmdtp); |
| 77 | |
| 78 | if (argc < 5) { |
| 79 | pxefile_addr_str = from_env("pxefile_addr_r"); |
| 80 | if (!pxefile_addr_str) |
| 81 | return 1; |
| 82 | } else { |
| 83 | pxefile_addr_str = argv[4]; |
| 84 | } |
| 85 | |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 86 | if (argc < 6) { |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 87 | filename = env_get("bootfile"); |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 88 | } else { |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 89 | filename = argv[5]; |
| 90 | env_set("bootfile", filename); |
| 91 | } |
| 92 | |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 93 | if (strstr(argv[3], "ext2")) { |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 94 | getfile = do_get_ext2; |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 95 | } else if (strstr(argv[3], "fat")) { |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 96 | getfile = do_get_fat; |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 97 | } else if (strstr(argv[3], "any")) { |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 98 | getfile = do_get_any; |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 99 | } else { |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 100 | printf("Invalid filesystem: %s\n", argv[3]); |
| 101 | return 1; |
| 102 | } |
| 103 | fs_argv[1] = argv[1]; |
| 104 | fs_argv[2] = argv[2]; |
| 105 | |
| 106 | if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) { |
| 107 | printf("Invalid pxefile address: %s\n", pxefile_addr_str); |
| 108 | return 1; |
| 109 | } |
| 110 | |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 111 | if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) { |
| 112 | printf("Out of memory\n"); |
| 113 | return CMD_RET_FAILURE; |
| 114 | } |
| 115 | |
Simon Glass | fd3fa5c | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 116 | if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) { |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 117 | printf("Error reading config file\n"); |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 118 | pxe_destroy_ctx(&ctx); |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 119 | return 1; |
| 120 | } |
| 121 | |
Simon Glass | 9e62e7c | 2021-10-14 12:48:03 -0600 | [diff] [blame] | 122 | ret = pxe_process(&ctx, pxefile_addr_r, prompt); |
Simon Glass | 12df842 | 2021-10-14 12:48:04 -0600 | [diff] [blame^] | 123 | pxe_destroy_ctx(&ctx); |
Simon Glass | 9e62e7c | 2021-10-14 12:48:03 -0600 | [diff] [blame] | 124 | if (ret) |
| 125 | return CMD_RET_FAILURE; |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Patrice Chotard | 51843ea | 2019-11-25 09:07:40 +0100 | [diff] [blame] | 130 | U_BOOT_CMD(sysboot, 7, 1, do_sysboot, |
| 131 | "command to get and boot from syslinux files", |
| 132 | "[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n" |
| 133 | " - load and parse syslinux menu file 'filename' from ext2, fat\n" |
| 134 | " or any filesystem on 'dev' on 'interface' to address 'addr'" |
Patrice Chotard | 993c912 | 2019-11-25 09:07:38 +0100 | [diff] [blame] | 135 | ); |