2019-11-25 08:07:38 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <env.h>
|
|
|
|
#include <fs.h>
|
2021-10-14 18:48:00 +00:00
|
|
|
#include <pxe_utils.h>
|
2019-11-25 08:07:38 +00:00
|
|
|
|
2021-10-14 18:48:09 +00:00
|
|
|
/**
|
|
|
|
* struct sysboot_info - useful information for sysboot helpers
|
|
|
|
*
|
|
|
|
* @fstype: Filesystem type (FS_TYPE_...)
|
|
|
|
* @ifname: Interface name (e.g. "ide", "scsi")
|
|
|
|
* @dev_part_str is in the format:
|
|
|
|
* <dev>.<hw_part>:<part> where <dev> is the device number,
|
|
|
|
* <hw_part> is the optional hardware partition number and
|
|
|
|
* <part> is the partition number
|
|
|
|
*/
|
|
|
|
struct sysboot_info {
|
|
|
|
int fstype;
|
|
|
|
const char *ifname;
|
|
|
|
const char *dev_part_str;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sysboot_read_file(struct pxe_context *ctx, const char *file_path,
|
|
|
|
char *file_addr, ulong *sizep)
|
2019-11-25 08:07:38 +00:00
|
|
|
{
|
2021-10-14 18:48:09 +00:00
|
|
|
struct sysboot_info *info = ctx->userdata;
|
|
|
|
loff_t len_read;
|
|
|
|
ulong addr;
|
2021-10-14 18:48:08 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-10-14 18:48:09 +00:00
|
|
|
addr = simple_strtoul(file_addr, NULL, 16);
|
|
|
|
ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype);
|
2021-10-14 18:48:08 +00:00
|
|
|
if (ret)
|
2021-10-14 18:48:09 +00:00
|
|
|
return ret;
|
|
|
|
ret = fs_read(file_path, addr, 0, 0, &len_read);
|
2021-10-14 18:48:08 +00:00
|
|
|
if (ret)
|
2021-10-14 18:48:09 +00:00
|
|
|
return ret;
|
|
|
|
*sizep = len_read;
|
2019-11-25 08:07:38 +00:00
|
|
|
|
2021-10-14 18:48:09 +00:00
|
|
|
return 0;
|
2019-11-25 08:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boots a system using a local disk syslinux/extlinux file
|
|
|
|
*
|
|
|
|
* Returns 0 on success, 1 on error.
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2019-11-25 08:07:38 +00:00
|
|
|
{
|
|
|
|
unsigned long pxefile_addr_r;
|
2021-10-14 18:47:56 +00:00
|
|
|
struct pxe_context ctx;
|
2019-11-25 08:07:38 +00:00
|
|
|
char *pxefile_addr_str;
|
2021-10-14 18:48:09 +00:00
|
|
|
struct sysboot_info info;
|
2019-11-25 08:07:38 +00:00
|
|
|
char *filename;
|
|
|
|
int prompt = 0;
|
2021-10-14 18:48:03 +00:00
|
|
|
int ret;
|
2019-11-25 08:07:38 +00:00
|
|
|
|
|
|
|
if (argc > 1 && strstr(argv[1], "-p")) {
|
|
|
|
prompt = 1;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 4)
|
|
|
|
return cmd_usage(cmdtp);
|
|
|
|
|
|
|
|
if (argc < 5) {
|
|
|
|
pxefile_addr_str = from_env("pxefile_addr_r");
|
|
|
|
if (!pxefile_addr_str)
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
pxefile_addr_str = argv[4];
|
|
|
|
}
|
|
|
|
|
2019-11-25 08:07:40 +00:00
|
|
|
if (argc < 6) {
|
2019-11-25 08:07:38 +00:00
|
|
|
filename = env_get("bootfile");
|
2019-11-25 08:07:40 +00:00
|
|
|
} else {
|
2019-11-25 08:07:38 +00:00
|
|
|
filename = argv[5];
|
|
|
|
env_set("bootfile", filename);
|
|
|
|
}
|
|
|
|
|
2019-11-25 08:07:40 +00:00
|
|
|
if (strstr(argv[3], "ext2")) {
|
2021-10-14 18:48:09 +00:00
|
|
|
info.fstype = FS_TYPE_EXT;
|
2019-11-25 08:07:40 +00:00
|
|
|
} else if (strstr(argv[3], "fat")) {
|
2021-10-14 18:48:09 +00:00
|
|
|
info.fstype = FS_TYPE_FAT;
|
2019-11-25 08:07:40 +00:00
|
|
|
} else if (strstr(argv[3], "any")) {
|
2021-10-14 18:48:09 +00:00
|
|
|
info.fstype = FS_TYPE_ANY;
|
2019-11-25 08:07:40 +00:00
|
|
|
} else {
|
2019-11-25 08:07:38 +00:00
|
|
|
printf("Invalid filesystem: %s\n", argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
2021-10-14 18:48:09 +00:00
|
|
|
info.ifname = argv[1];
|
|
|
|
info.dev_part_str = argv[2];
|
2019-11-25 08:07:38 +00:00
|
|
|
|
|
|
|
if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
|
|
|
|
printf("Invalid pxefile address: %s\n", pxefile_addr_str);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-10-14 18:48:09 +00:00
|
|
|
if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true,
|
|
|
|
filename)) {
|
2021-10-14 18:48:04 +00:00
|
|
|
printf("Out of memory\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2021-10-14 18:47:56 +00:00
|
|
|
if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
|
2019-11-25 08:07:38 +00:00
|
|
|
printf("Error reading config file\n");
|
2021-10-14 18:48:04 +00:00
|
|
|
pxe_destroy_ctx(&ctx);
|
2019-11-25 08:07:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-10-14 18:48:03 +00:00
|
|
|
ret = pxe_process(&ctx, pxefile_addr_r, prompt);
|
2021-10-14 18:48:04 +00:00
|
|
|
pxe_destroy_ctx(&ctx);
|
2021-10-14 18:48:03 +00:00
|
|
|
if (ret)
|
|
|
|
return CMD_RET_FAILURE;
|
2019-11-25 08:07:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-25 08:07:40 +00:00
|
|
|
U_BOOT_CMD(sysboot, 7, 1, do_sysboot,
|
|
|
|
"command to get and boot from syslinux files",
|
|
|
|
"[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n"
|
|
|
|
" - load and parse syslinux menu file 'filename' from ext2, fat\n"
|
|
|
|
" or any filesystem on 'dev' on 'interface' to address 'addr'"
|
2019-11-25 08:07:38 +00:00
|
|
|
);
|