summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2023-05-08 14:31:04 -0400
committerTom Rini <[email protected]>2023-05-08 14:31:04 -0400
commit11910550b65e6072b9542d462c0aa93f4ca81836 (patch)
tree8308c98ffad76d9693654a28090b03f270a7d250 /cmd
parent9876c8c147144db2c120fcc9ffa6de27f6894441 (diff)
parentf1d33a44ca04fdca241c1d89fd79e2e56c930c7e (diff)
Merge branch 'master' into next
Diffstat (limited to 'cmd')
-rw-r--r--cmd/2048.c397
-rw-r--r--cmd/Kconfig65
-rw-r--r--cmd/Makefile2
-rw-r--r--cmd/abootimg.c75
-rw-r--r--cmd/bdinfo.c33
-rw-r--r--cmd/blk_common.c15
-rw-r--r--cmd/blkmap.c233
-rw-r--r--cmd/bmp.c162
-rw-r--r--cmd/bootflow.c27
-rw-r--r--cmd/console.c11
-rw-r--r--cmd/date.c2
-rw-r--r--cmd/fastboot.c25
-rw-r--r--cmd/ide.c22
-rw-r--r--cmd/mmc.c18
-rw-r--r--cmd/mvebu/bubt.c10
-rw-r--r--cmd/net.c46
-rw-r--r--cmd/pci.c1
-rw-r--r--cmd/pxe.c85
-rw-r--r--cmd/regulator.c1
-rw-r--r--cmd/sysboot.c2
-rw-r--r--cmd/tlv_eeprom.c107
-rw-r--r--cmd/tpm_test.c1
22 files changed, 1051 insertions, 289 deletions
diff --git a/cmd/2048.c b/cmd/2048.c
new file mode 100644
index 00000000000..fa60aa94aad
--- /dev/null
+++ b/cmd/2048.c
@@ -0,0 +1,397 @@
+// SPDX-License-Identifier: MIT
+// SPDX-FileCopyrightText: © 2014 Maurits van der Schee
+
+/* Console version of the game "2048" for GNU/Linux */
+
+#include <common.h>
+#include <cli.h>
+#include <command.h>
+#include <rand.h>
+#include <linux/delay.h>
+
+#define SIZE 4
+static uint score;
+
+static void getColor(uint value, char *color, size_t length)
+{
+ u8 original[] = {
+ 8, 255, 1, 255, 2, 255, 3, 255,
+ 4, 255, 5, 255, 6, 255, 7, 255,
+ 9, 0, 10, 0, 11, 0, 12, 0, 13,
+ 0, 14, 0, 255, 0, 255, 0};
+ u8 *scheme = original;
+ u8 *background = scheme + 0;
+ u8 *foreground = scheme + 1;
+
+ if (value > 0) {
+ while (value >>= 1) {
+ if (background + 2 < scheme + sizeof(original)) {
+ background += 2;
+ foreground += 2;
+ }
+ }
+ }
+ snprintf(color, length, "\033[38;5;%d;48;5;%dm", *foreground,
+ *background);
+}
+
+static void drawBoard(u16 board[SIZE][SIZE])
+{
+ int x, y;
+ char color[40], reset[] = "\033[0m";
+
+ printf("\033[H");
+ printf("2048.c %17d pts\n\n", score);
+
+ for (y = 0; y < SIZE; y++) {
+ for (x = 0; x < SIZE; x++) {
+ getColor(board[x][y], color, 40);
+ printf("%s", color);
+ printf(" ");
+ printf("%s", reset);
+ }
+ printf("\n");
+ for (x = 0; x < SIZE; x++) {
+ getColor(board[x][y], color, 40);
+ printf("%s", color);
+ if (board[x][y] != 0) {
+ char s[8];
+ s8 t;
+
+ snprintf(s, 8, "%u", board[x][y]);
+ t = 7 - strlen(s);
+ printf("%*s%s%*s", t - t / 2, "", s, t / 2, "");
+ } else {
+ printf(" · ");
+ }
+ printf("%s", reset);
+ }
+ printf("\n");
+ for (x = 0; x < SIZE; x++) {
+ getColor(board[x][y], color, 40);
+ printf("%s", color);
+ printf(" ");
+ printf("%s", reset);
+ }
+ printf("\n");
+ }
+ printf("\n");
+ printf(" ←, ↑, →, ↓ or q \n");
+ printf("\033[A");
+}
+
+static int8_t findTarget(u16 array[SIZE], int x, int stop)
+{
+ int t;
+
+ /* if the position is already on the first, don't evaluate */
+ if (x == 0)
+ return x;
+ for (t = x - 1; t >= 0; t--) {
+ if (array[t]) {
+ if (array[t] != array[x]) {
+ /* merge is not possible, take next position */
+ return t + 1;
+ }
+ return t;
+ }
+
+ /* we should not slide further, return this one */
+ if (t == stop)
+ return t;
+ }
+ /* we did not find a */
+ return x;
+}
+
+static bool slideArray(u16 array[SIZE])
+{
+ bool success = false;
+ int x, t, stop = 0;
+
+ for (x = 0; x < SIZE; x++) {
+ if (array[x] != 0) {
+ t = findTarget(array, x, stop);
+ /*
+ * if target is not original position, then move or
+ * merge
+ */
+ if (t != x) {
+ /*
+ * if target is not zero, set stop to avoid
+ * double merge
+ */
+ if (array[t]) {
+ score += array[t] + array[x];
+ stop = t + 1;
+ }
+ array[t] += array[x];
+ array[x] = 0;
+ success = true;
+ }
+ }
+ }
+ return success;
+}
+
+static void rotateBoard(u16 board[SIZE][SIZE])
+{
+ s8 i, j, n = SIZE;
+ int tmp;
+
+ for (i = 0; i < n / 2; i++) {
+ for (j = i; j < n - i - 1; j++) {
+ tmp = board[i][j];
+ board[i][j] = board[j][n - i - 1];
+ board[j][n - i - 1] = board[n - i - 1][n - j - 1];
+ board[n - i - 1][n - j - 1] = board[n - j - 1][i];
+ board[n - j - 1][i] = tmp;
+ }
+ }
+}
+
+static bool moveUp(u16 board[SIZE][SIZE])
+{
+ bool success = false;
+ int x;
+
+ for (x = 0; x < SIZE; x++)
+ success |= slideArray(board[x]);
+
+ return success;
+}
+
+static bool moveLeft(u16 board[SIZE][SIZE])
+{
+ bool success;
+
+ rotateBoard(board);
+ success = moveUp(board);
+ rotateBoard(board);
+ rotateBoard(board);
+ rotateBoard(board);
+ return success;
+}
+
+static bool moveDown(u16 board[SIZE][SIZE])
+{
+ bool success;
+
+ rotateBoard(board);
+ rotateBoard(board);
+ success = moveUp(board);
+ rotateBoard(board);
+ rotateBoard(board);
+ return success;
+}
+
+static bool moveRight(u16 board[SIZE][SIZE])
+{
+ bool success;
+
+ rotateBoard(board);
+ rotateBoard(board);
+ rotateBoard(board);
+ success = moveUp(board);
+ rotateBoard(board);
+ return success;
+}
+
+static bool findPairDown(u16 board[SIZE][SIZE])
+{
+ bool success = false;
+ int x, y;
+
+ for (x = 0; x < SIZE; x++) {
+ for (y = 0; y < SIZE - 1; y++) {
+ if (board[x][y] == board[x][y + 1])
+ return true;
+ }
+ }
+
+ return success;
+}
+
+static int16_t countEmpty(u16 board[SIZE][SIZE])
+{
+ int x, y;
+ int count = 0;
+
+ for (x = 0; x < SIZE; x++) {
+ for (y = 0; y < SIZE; y++) {
+ if (board[x][y] == 0)
+ count++;
+ }
+ }
+ return count;
+}
+
+static bool gameEnded(u16 board[SIZE][SIZE])
+{
+ bool ended = true;
+
+ if (countEmpty(board) > 0)
+ return false;
+ if (findPairDown(board))
+ return false;
+ rotateBoard(board);
+ if (findPairDown(board))
+ ended = false;
+ rotateBoard(board);
+ rotateBoard(board);
+ rotateBoard(board);
+
+ return ended;
+}
+
+static void addRandom(u16 board[SIZE][SIZE])
+{
+ int x, y;
+ int r, len = 0;
+ u16 n, list[SIZE * SIZE][2];
+
+ for (x = 0; x < SIZE; x++) {
+ for (y = 0; y < SIZE; y++) {
+ if (board[x][y] == 0) {
+ list[len][0] = x;
+ list[len][1] = y;
+ len++;
+ }
+ }
+ }
+
+ if (len > 0) {
+ r = rand() % len;
+ x = list[r][0];
+ y = list[r][1];
+ n = ((rand() % 10) / 9 + 1) * 2;
+ board[x][y] = n;
+ }
+}
+
+static int test(void)
+{
+ u16 array[SIZE];
+ u16 data[] = {
+ 0, 0, 0, 2, 2, 0, 0, 0,
+ 0, 0, 2, 2, 4, 0, 0, 0,
+ 0, 2, 0, 2, 4, 0, 0, 0,
+ 2, 0, 0, 2, 4, 0, 0, 0,
+ 2, 0, 2, 0, 4, 0, 0, 0,
+ 2, 2, 2, 0, 4, 2, 0, 0,
+ 2, 0, 2, 2, 4, 2, 0, 0,
+ 2, 2, 0, 2, 4, 2, 0, 0,
+ 2, 2, 2, 2, 4, 4, 0, 0,
+ 4, 4, 2, 2, 8, 4, 0, 0,
+ 2, 2, 4, 4, 4, 8, 0, 0,
+ 8, 0, 2, 2, 8, 4, 0, 0,
+ 4, 0, 2, 2, 4, 4, 0, 0
+ };
+ u16 *in, *out;
+ u16 t, tests;
+ int i;
+ bool success = true;
+
+ tests = (sizeof(data) / sizeof(data[0])) / (2 * SIZE);
+ for (t = 0; t < tests; t++) {
+ in = data + t * 2 * SIZE;
+ out = in + SIZE;
+ for (i = 0; i < SIZE; i++)
+ array[i] = in[i];
+ slideArray(array);
+ for (i = 0; i < SIZE; i++) {
+ if (array[i] != out[i])
+ success = false;
+ }
+ if (!success) {
+ for (i = 0; i < SIZE; i++)
+ printf("%d ", in[i]);
+ printf(" = > ");
+ for (i = 0; i < SIZE; i++)
+ printf("%d ", array[i]);
+ printf("expected ");
+ for (i = 0; i < SIZE; i++)
+ printf("%d ", in[i]);
+ printf(" = > ");
+ for (i = 0; i < SIZE; i++)
+ printf("%d ", out[i]);
+ printf("\n");
+ break;
+ }
+ }
+ if (success)
+ printf("All %u tests executed successfully\n", tests);
+
+ return !success;
+}
+
+static int do_2048(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cli_ch_state cch_s, *cch = &cch_s;
+ u16 board[SIZE][SIZE];
+ bool success;
+
+ if (argc == 2 && strcmp(argv[1], "test") == 0)
+ return test();
+
+ score = 0;
+
+ printf("\033[?25l\033[2J\033[H");
+
+ memset(board, 0, sizeof(board));
+ addRandom(board);
+ addRandom(board);
+ drawBoard(board);
+ cli_ch_init(cch);
+ while (true) {
+ int c;
+
+ c = cli_ch_process(cch, 0);
+ if (!c) {
+ c = getchar();
+ c = cli_ch_process(cch, c);
+ }
+ switch (c) {
+ case CTL_CH('b'): /* left arrow */
+ success = moveLeft(board);
+ break;
+ case CTL_CH('f'): /* right arrow */
+ success = moveRight(board);
+ break;
+ case CTL_CH('p'):/* up arrow */
+ success = moveUp(board);
+ break;
+ case CTL_CH('n'): /* down arrow */
+ success = moveDown(board);
+ break;
+ default:
+ success = false;
+ }
+ if (success) {
+ drawBoard(board);
+ mdelay(150);
+ addRandom(board);
+ drawBoard(board);
+ if (gameEnded(board)) {
+ printf(" GAME OVER \n");
+ break;
+ }
+ }
+ if (c == 'q') {
+ printf(" QUIT \n");
+ break;
+ }
+ }
+
+ printf("\033[?25h");
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ 2048, 2, 1, do_2048,
+ "The 2048 game",
+ "Use your arrow keys to move the tiles. When two tiles with "
+ "the same number touch, they merge into one!"
+);
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 8c9b430f99f..65957da7f57 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1446,7 +1446,8 @@ config CMD_SATA
config CMD_SCSI
bool "scsi - Access to SCSI devices"
- default y if SCSI
+ depends on SCSI
+ default y
help
This provides a 'scsi' command which provides access to SCSI (Small
Computer System Interface) devices. The command provides a way to
@@ -1672,6 +1673,15 @@ config CMD_DHCP
help
Boot image via network using DHCP/TFTP protocol
+config CMD_DHCP6
+ bool "dhcp6"
+ depends on IPV6
+ help
+ Boot image via network using DHCPv6/TFTP protocol using IPv6.
+
+ Will perform 4-message exchange with DHCPv6 server, requesting
+ the minimum required options to TFTP boot. Complies with RFC 8415.
+
config BOOTP_MAY_FAIL
bool "Allow for the BOOTP/DHCP server to not be found"
depends on CMD_BOOTP
@@ -1785,6 +1795,23 @@ config BOOTP_VCI_STRING
default "U-Boot.arm" if ARM
default "U-Boot"
+if CMD_DHCP6
+
+config DHCP6_PXE_CLIENTARCH
+ hex
+ default 0x16 if ARM64
+ default 0x15 if ARM
+ default 0xFF
+
+config DHCP6_PXE_DHCP_OPTION
+ bool "Request & store 'pxe_configfile' from DHCP6 server"
+
+config DHCP6_ENTERPRISE_ID
+ int "Enterprise ID to send in DHCPv6 Vendor Class Option"
+ default 0
+
+endif
+
config CMD_TFTPBOOT
bool "tftpboot"
default y
@@ -1915,6 +1942,12 @@ config CMD_NCSI
Normally this happens automatically before other network
operations.
+config IPV6_ROUTER_DISCOVERY
+ bool "Do IPv6 router discovery"
+ depends on IPV6
+ help
+ Will automatically perform router solicitation on first IPv6
+ network operation
endif
config CMD_ETHSW
@@ -1940,6 +1973,17 @@ endif
menu "Misc commands"
+config CMD_2048
+ bool "Play 2048"
+ help
+ This is a simple sliding block puzzle game designed by Italian web
+ developer Gabriele Cirulli. The game's objective is to slide numbered
+ tiles on a grid to combine them to create a tile with the number
+ 2048.
+
+ This needs ANSI support on your terminal to work. It is not fully
+ functional on a video device.
+
config CMD_BMP
bool "Enable 'bmp' command"
depends on VIDEO
@@ -1980,6 +2024,25 @@ config CMD_BLOCK_CACHE
during development, but also allows the cache to be disabled when
it might hurt performance (e.g. when using the ums command).
+config CMD_BLKMAP
+ bool "blkmap - Composable virtual block devices"
+ depends on BLKMAP
+ default y if BLKMAP
+ help
+ Create virtual block devices that are backed by various sources,
+ e.g. RAM, or parts of an existing block device. Though much more
+ rudimentary, it borrows a lot of ideas from Linux's device mapper
+ subsystem.
+
+ Example use-cases:
+ - Treat a region of RAM as a block device, i.e. a RAM disk. This let's
+ you extract files from filesystem images stored in RAM (perhaps as a
+ result of a TFTP transfer).
+ - Create a virtual partition on an existing device. This let's you
+ access filesystems that aren't stored at an exact partition
+ boundary. A common example is a filesystem image embedded in an FIT
+ image.
+
config CMD_BUTTON
bool "button"
depends on BUTTON
diff --git a/cmd/Makefile b/cmd/Makefile
index e032091621d..6c37521b4e2 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -12,6 +12,7 @@ obj-y += panic.o
obj-y += version.o
# command
+obj-$(CONFIG_CMD_2048) += 2048.o
obj-$(CONFIG_CMD_ACPI) += acpi.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_AES) += aes.o
@@ -27,6 +28,7 @@ obj-$(CONFIG_CMD_BCB) += bcb.o
obj-$(CONFIG_CMD_BDI) += bdinfo.o
obj-$(CONFIG_CMD_BIND) += bind.o
obj-$(CONFIG_CMD_BINOP) += binop.o
+obj-$(CONFIG_CMD_BLKMAP) += blkmap.o
obj-$(CONFIG_CMD_BLOBLIST) += bloblist.o
obj-$(CONFIG_CMD_BLOCK_CACHE) += blkcache.o
obj-$(CONFIG_CMD_BMP) += bmp.o
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index f48a9dcb021..2653b555b10 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -15,17 +15,28 @@
/* Please use abootimg_addr() macro to obtain the boot image address */
static ulong _abootimg_addr = -1;
+static ulong _avendor_bootimg_addr = -1;
+
+ulong get_abootimg_addr(void)
+{
+ return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
+}
+
+ulong get_avendor_bootimg_addr(void)
+{
+ return _avendor_bootimg_addr;
+}
static int abootimg_get_ver(int argc, char *const argv[])
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
int res = CMD_RET_SUCCESS;
if (argc > 1)
return CMD_RET_USAGE;
hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
- if (android_image_check_header(hdr)) {
+ if (!is_android_boot_image_header(hdr)) {
printf("Error: Boot Image header is incorrect\n");
res = CMD_RET_FAILURE;
goto exit;
@@ -65,33 +76,43 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
{
- const struct andr_img_hdr *hdr;
- int res = CMD_RET_SUCCESS;
-
if (argc > 1)
return CMD_RET_USAGE;
+ struct andr_image_data img_data = {0};
+ const struct andr_boot_img_hdr_v0 *hdr;
+ const struct andr_vnd_boot_img_hdr *vhdr;
hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
- if (android_image_check_header(hdr)) {
- printf("Error: Boot Image header is incorrect\n");
- res = CMD_RET_FAILURE;
- goto exit;
+ if (get_avendor_bootimg_addr() != -1)
+ vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr));
+
+ if (!android_image_get_data(hdr, vhdr, &img_data)) {
+ if (get_avendor_bootimg_addr() != -1)
+ unmap_sysmem(vhdr);
+ unmap_sysmem(hdr);
+ return CMD_RET_FAILURE;
}
- if (hdr->header_version < 2) {
+ if (get_avendor_bootimg_addr() != -1)
+ unmap_sysmem(vhdr);
+ unmap_sysmem(hdr);
+
+ if (img_data.header_version < 2) {
printf("Error: header_version must be >= 2 for this\n");
- res = CMD_RET_FAILURE;
- goto exit;
+ return CMD_RET_FAILURE;
+ }
+
+ if (!img_data.dtb_load_addr) {
+ printf("Error: failed to read dtb_load_addr\n");
+ return CMD_RET_FAILURE;
}
if (argc == 0)
- printf("%lx\n", (ulong)hdr->dtb_addr);
+ printf("%lx\n", (ulong)img_data.dtb_load_addr);
else
- env_set_hex(argv[0], (ulong)hdr->dtb_addr);
+ env_set_hex(argv[0], (ulong)img_data.dtb_load_addr);
-exit:
- unmap_sysmem(hdr);
- return res;
+ return CMD_RET_SUCCESS;
}
static int abootimg_get_dtb_by_index(int argc, char *const argv[])
@@ -117,7 +138,8 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[])
return CMD_RET_FAILURE;
}
- if (!android_image_get_dtb_by_index(abootimg_addr(), num,
+ if (!android_image_get_dtb_by_index(abootimg_addr(),
+ get_avendor_bootimg_addr(), num,
&addr, &size)) {
return CMD_RET_FAILURE;
}
@@ -158,7 +180,7 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
char *endp;
ulong img_addr;
- if (argc != 2)
+ if (argc < 2 || argc > 3)
return CMD_RET_USAGE;
img_addr = hextoul(argv[1], &endp);
@@ -168,6 +190,17 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
}
_abootimg_addr = img_addr;
+
+ if (argc == 3) {
+ img_addr = simple_strtoul(argv[2], &endp, 16);
+ if (*endp != '\0') {
+ printf("Error: Wrong vendor image address\n");
+ return CMD_RET_FAILURE;
+ }
+
+ _avendor_bootimg_addr = img_addr;
+ }
+
return CMD_RET_SUCCESS;
}
@@ -211,7 +244,7 @@ static int do_abootimg_dump(struct cmd_tbl *cmdtp, int flag, int argc,
}
static struct cmd_tbl cmd_abootimg_sub[] = {
- U_BOOT_CMD_MKENT(addr, 2, 1, do_abootimg_addr, "", ""),
+ U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
};
@@ -239,7 +272,7 @@ static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc,
U_BOOT_CMD(
abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg,
"manipulate Android Boot Image",
- "addr <addr>\n"
+ "addr <boot_img_addr> [<vendor_boot_img_addr>]>\n"
" - set the address in RAM where boot image is located\n"
" ($loadaddr is used by default)\n"
"abootimg dump dtb\n"
diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index f709904c516..365357ca545 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -11,6 +11,7 @@
#include <dm.h>
#include <env.h>
#include <lmb.h>
+#include <mapmem.h>
#include <net.h>
#include <video.h>
#include <vsprintf.h>
@@ -41,17 +42,26 @@ void bdinfo_print_num_ll(const char *name, unsigned long long value)
printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong), value);
}
-static void print_eth(int idx)
+static void print_eth(void)
{
- char name[10], *val;
+ const int idx = eth_get_dev_index();
+ uchar enetaddr[6];
+ char name[10];
+ int ret;
+
if (idx)
sprintf(name, "eth%iaddr", idx);
else
strcpy(name, "ethaddr");
- val = env_get(name);
- if (!val)
- val = "(not set)";
- printf("%-12s= %s\n", name, val);
+
+ ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr);
+
+ printf("current eth = %s\n", eth_get_name());
+ if (!ret)
+ printf("%-12s= (not set)\n", name);
+ else
+ printf("%-12s= %pM\n", name, enetaddr);
+ printf("IP addr = %s\n", env_get("ipaddr"));
}
void bdinfo_print_mhz(const char *name, unsigned long hz)
@@ -123,13 +133,10 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
bdinfo_print_num_l("relocaddr", gd->relocaddr);
bdinfo_print_num_l("reloc off", gd->reloc_off);
printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
- if (IS_ENABLED(CONFIG_CMD_NET)) {
- printf("current eth = %s\n", eth_get_name());
- print_eth(0);
- printf("IP addr = %s\n", env_get("ipaddr"));
- }
- bdinfo_print_num_l("fdt_blob", (ulong)gd->fdt_blob);
- bdinfo_print_num_l("new_fdt", (ulong)gd->new_fdt);
+ if (IS_ENABLED(CONFIG_CMD_NET))
+ print_eth();
+ bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
+ bdinfo_print_num_l("new_fdt", (ulong)map_to_sysmem(gd->new_fdt));
bdinfo_print_num_l("fdt_size", (ulong)gd->fdt_size);
if (IS_ENABLED(CONFIG_VIDEO))
show_video_info();
diff --git a/cmd/blk_common.c b/cmd/blk_common.c
index 75a072caf51..9f9d4327a99 100644
--- a/cmd/blk_common.c
+++ b/cmd/blk_common.c
@@ -11,6 +11,7 @@
#include <common.h>
#include <blk.h>
#include <command.h>
+#include <mapmem.h>
int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
int *cur_devnump)
@@ -63,31 +64,37 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
default: /* at least 4 args */
if (strcmp(argv[1], "read") == 0) {
- ulong addr = hextoul(argv[2], NULL);
+ phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
+ void *vaddr;
ulong n;
printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
+ vaddr = map_sysmem(paddr, 512 * cnt);
n = blk_read_devnum(uclass_id, *cur_devnump, blk, cnt,
- (ulong *)addr);
+ vaddr);
+ unmap_sysmem(vaddr);
printf("%ld blocks read: %s\n", n,
n == cnt ? "OK" : "ERROR");
return n == cnt ? 0 : 1;
} else if (strcmp(argv[1], "write") == 0) {
- ulong addr = hextoul(argv[2], NULL);
+ phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
+ void *vaddr;
ulong n;
printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
+ vaddr = map_sysmem(paddr, 512 * cnt);
n = blk_write_devnum(uclass_id, *cur_devnump, blk, cnt,
- (ulong *)addr);
+ vaddr);
+ unmap_sysmem(vaddr);
printf("%ld blocks written: %s\n", n,
n == cnt ? "OK" : "ERROR");
diff --git a/cmd/blkmap.c b/cmd/blkmap.c
new file mode 100644
index 00000000000..b34c0130728
--- /dev/null
+++ b/cmd/blkmap.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023 Addiva Elektronik
+ * Author: Tobias Waldekranz <[email protected]>
+ */
+
+#include <blk.h>
+#include <blkmap.h>
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <dm/device.h>
+
+static int blkmap_curr_dev;
+
+struct map_ctx {
+ struct udevice *dev;
+ lbaint_t blknr, blkcnt;
+};
+
+typedef int (*map_parser_fn)(struct map_ctx *ctx, int argc, char *const argv[]);
+
+struct map_handler {
+ const char *name;
+ map_parser_fn fn;
+};
+
+int do_blkmap_map_linear(struct map_ctx *ctx, int argc, char *const argv[])
+{
+ struct blk_desc *lbd;
+ int err, ldevnum;
+ lbaint_t lblknr;
+
+ if (argc < 4)
+ return CMD_RET_USAGE;
+
+ ldevnum = dectoul(argv[2], NULL);
+ lblknr = dectoul(argv[3], NULL);
+
+ lbd = blk_get_devnum_by_uclass_idname(argv[1], ldevnum);
+ if (!lbd) {
+ printf("Found no device matching \"%s %d\"\n",
+ argv[1], ldevnum);
+ return CMD_RET_FAILURE;
+ }
+
+ err = blkmap_map_linear(ctx->dev, ctx->blknr, ctx->blkcnt,
+ lbd->bdev, lblknr);
+ if (err) {
+ printf("Unable to map \"%s %d\" at block 0x" LBAF ": %d\n",
+ argv[1], ldevnum, ctx->blknr, err);
+
+ return CMD_RET_FAILURE;
+ }
+
+ printf("Block 0x" LBAF "+0x" LBAF " mapped to block 0x" LBAF " of \"%s %d\"\n",
+ ctx->blknr, ctx->blkcnt, lblknr, argv[1], ldevnum);
+ return CMD_RET_SUCCESS;
+}
+
+int do_blkmap_map_mem(struct map_ctx *ctx, int argc, char *const argv[])
+{
+ phys_addr_t addr;
+ int err;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ addr = hextoul(argv[1], NULL);
+
+ err = blkmap_map_pmem(ctx->dev, ctx->blknr, ctx->blkcnt, addr);
+ if (err) {
+ printf("Unable to map %#llx at block 0x" LBAF ": %d\n",
+ (unsigned long long)addr, ctx->blknr, err);
+ return CMD_RET_FAILURE;
+ }
+
+ printf("Block 0x" LBAF "+0x" LBAF " mapped to %#llx\n",
+ ctx->blknr, ctx->blkcnt, (unsigned long long)addr);
+ return CMD_RET_SUCCESS;
+}
+
+struct map_handler map_handlers[] = {
+ { .name = "linear", .fn = do_blkmap_map_linear },
+ { .name = "mem", .fn = do_blkmap_map_mem },
+
+ { .name = NULL }
+};
+
+static int do_blkmap_map(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ struct map_handler *handler;
+ struct map_ctx ctx;
+
+ if (argc < 5)
+ return CMD_RET_USAGE;
+
+ ctx.dev = blkmap_from_label(argv[1]);
+ if (!ctx.dev) {
+ printf("\"%s\" is not the name of any known blkmap\n", argv[1]);
+ return CMD_RET_FAILURE;
+ }
+
+ ctx.blknr = hextoul(argv[2], NULL);
+ ctx.blkcnt = hextoul(argv[3], NULL);
+ argc -= 4;
+ argv += 4;
+
+ for (handler = map_handlers; handler->name; handler++) {
+ if (!strcmp(handler->name, argv[0]))
+ return handler->fn(&ctx, argc, argv);
+ }
+
+ printf("Unknown map type \"%s\"\n", argv[0]);
+ return CMD_RET_USAGE;
+}
+
+static int do_blkmap_create(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ const char *label;
+ int err;
+
+ if (argc != 2)
+ return CMD_RET_USAGE;
+
+ label = argv[1];
+
+ err = blkmap_create(label, NULL);
+ if (err) {
+ printf("Unable to create \"%s\": %d\n", label, err);
+ return CMD_RET_FAILURE;
+ }
+
+ printf("Created \"%s\"\n", label);
+ return CMD_RET_SUCCESS;
+}
+
+static int do_blkmap_destroy(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ struct udevice *dev;
+ const char *label;
+ int err;
+
+ if (argc != 2)
+ return CMD_RET_USAGE;
+
+ label = argv[1];
+
+ dev = blkmap_from_label(label);
+ if (!dev) {
+ printf("\"%s\" is not the name of any known blkmap\n", label);
+ return CMD_RET_FAILURE;
+ }
+
+ err = blkmap_destroy(dev);
+ if (err) {
+ printf("Unable to destroy \"%s\": %d\n", label, err);
+ return CMD_RET_FAILURE;
+ }
+
+ printf("Destroyed \"%s\"\n", label);
+ return CMD_RET_SUCCESS;
+}
+
+static int do_blkmap_get(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ struct udevice *dev;
+ const char *label;
+ int err;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ label = argv[1];
+
+ dev = blkmap_from_label(label);
+ if (!dev) {
+ printf("\"%s\" is not the name of any known blkmap\n", label);
+ return CMD_RET_FAILURE;
+ }
+
+ if (!strcmp(argv[2], "dev")) {
+ if (argc == 3) {
+ printf("%d\n", dev_seq(dev));
+ } else {
+ err = env_set_hex(argv[3], dev_seq(dev));
+ if (err)
+ return CMD_RET_FAILURE;
+ }
+ } else {
+ return CMD_RET_USAGE;
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
+static int do_blkmap_common(struct cmd_tbl *cmdtp, int flag,
+ int argc, char *const argv[])
+{
+ /* The subcommand parsing pops the original argv[0] ("blkmap")
+ * which blk_common_cmd expects. Push it back again.
+ */
+ argc++;
+ argv--;
+
+ return blk_common_cmd(argc, argv, UCLASS_BLKMAP, &blkmap_curr_dev);
+}
+
+U_BOOT_CMD_WITH_SUBCMDS(
+ blkmap, "Composeable virtual block devices",
+ "info - list configured devices\n"
+ "blkmap part - list available partitions on current blkmap device\n"
+ "blkmap dev [<dev>] - show or set current blkmap device\n"
+ "blkmap read <addr> <blk#> <cnt>\n"
+ "blkmap write <addr> <blk#> <cnt>\n"
+ "blkmap get <label> dev [<var>] - store device number in variable\n"
+ "blkmap create <label> - create device\n"
+ "blkmap destroy <label> - destroy device\n"
+ "blkmap map <label> <blk#> <cnt> linear <interface> <dev> <blk#> - device mapping\n"
+ "blkmap map <label> <blk#> <cnt> mem <addr> - memory mapping\n",
+ U_BOOT_SUBCMD_MKENT(info, 2, 1, do_blkmap_common),
+ U_BOOT_SUBCMD_MKENT(part, 2, 1, do_blkmap_common),
+ U_BOOT_SUBCMD_MKENT(dev, 4, 1, do_blkmap_common),
+ U_BOOT_SUBCMD_MKENT(read, 5, 1, do_blkmap_common),
+ U_BOOT_SUBCMD_MKENT(write, 5, 1, do_blkmap_common),
+ U_BOOT_SUBCMD_MKENT(get, 5, 1, do_blkmap_get),
+ U_BOOT_SUBCMD_MKENT(create, 2, 1, do_blkmap_create),
+ U_BOOT_SUBCMD_MKENT(destroy, 2, 1, do_blkmap_destroy),
+ U_BOOT_SUBCMD_MKENT(map, 32, 1, do_blkmap_map));
diff --git a/cmd/bmp.c b/cmd/bmp.c
index 46d0d916e86..8f43a40dafd 100644
--- a/cmd/bmp.c
+++ b/cmd/bmp.c
@@ -9,84 +9,12 @@
*/
#include <common.h>
-#include <bmp_layout.h>
#include <command.h>
-#include <dm.h>
-#include <gzip.h>
#include <image.h>
-#include <log.h>
-#include <malloc.h>
#include <mapmem.h>
#include <splash.h>
#include <video.h>
-#include <asm/byteorder.h>
-
-static int bmp_info (ulong addr);
-
-/*
- * Allocate and decompress a BMP image using gunzip().
- *
- * Returns a pointer to the decompressed image data. This pointer is
- * aligned to 32-bit-aligned-address + 2.
- * See doc/README.displaying-bmps for explanation.
- *
- * The allocation address is passed to 'alloc_addr' and must be freed
- * by the caller after use.
- *
- * Returns NULL if decompression failed, or if the decompressed data
- * didn't contain a valid BMP signature.
- */
-#ifdef CONFIG_VIDEO_BMP_GZIP
-struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
- void **alloc_addr)
-{
- void *dst;
- unsigned long len;
- struct bmp_image *bmp;
-
- /*
- * Decompress bmp image
- */
- len = CONFIG_VIDEO_LOGO_MAX_SIZE;
- /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
- dst = malloc(CONFIG_VIDEO_LOGO_MAX_SIZE + 3);
- if (!dst) {
- puts("Error: malloc in gunzip failed!\n");
- return NULL;
- }
-
- /* align to 32-bit-aligned-address + 2 */
- bmp = dst + 2;
-
- if (gunzip(bmp, CONFIG_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
- &len)) {
- free(dst);
- return NULL;
- }
- if (len == CONFIG_VIDEO_LOGO_MAX_SIZE)
- puts("Image could be truncated (increase CONFIG_VIDEO_LOGO_MAX_SIZE)!\n");
-
- /*
- * Check for bmp mark 'BM'
- */
- if (!((bmp->header.signature[0] == 'B') &&
- (bmp->header.signature[1] == 'M'))) {
- free(dst);
- return NULL;
- }
-
- debug("Gzipped BMP image detected!\n");
-
- *alloc_addr = dst;
- return bmp;
-}
-#else
-struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
- void **alloc_addr)
-{
- return NULL;
-}
-#endif
+#include <stdlib.h>
static int do_bmp_info(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
@@ -137,7 +65,7 @@ static int do_bmp_display(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_USAGE;
}
- return (bmp_display(addr, x, y));
+ return (bmp_display(addr, x, y));
}
static struct cmd_tbl cmd_bmp_sub[] = {
@@ -145,22 +73,6 @@ static struct cmd_tbl cmd_bmp_sub[] = {
U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
};
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-void bmp_reloc(void) {
- fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
-}
-#endif
-
-/*
- * Subroutine: do_bmp
- *
- * Description: Handler for 'bmp' command..
- *
- * Inputs: argv[1] contains the subcommand
- *
- * Return: None
- *
- */
static int do_bmp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct cmd_tbl *c;
@@ -183,73 +95,3 @@ U_BOOT_CMD(
"info <imageAddr> - display image info\n"
"bmp display <imageAddr> [x y] - display image at x,y"
);
-
-/*
- * Subroutine: bmp_info
- *
- * Description: Show information about bmp file in memory
- *
- * Inputs: addr address of the bmp file
- *
- * Return: None
- *
- */
-static int bmp_info(ulong addr)
-{
- struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
- void *bmp_alloc_addr = NULL;
- unsigned long len;
-
- if (!((bmp->header.signature[0]=='B') &&
- (bmp->header.signature[1]=='M')))
- bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
-
- if (bmp == NULL) {
- printf("There is no valid bmp file at the given address\n");
- return 1;
- }
-
- printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
- le32_to_cpu(bmp->header.height));
- printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
- printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
-
- if (bmp_alloc_addr)
- free(bmp_alloc_addr);
-
- return(0);
-}
-
-int bmp_display(ulong addr, int x, int y)
-{
- struct udevice *dev;
- int ret;
- struct bmp_image *bmp = map_sysmem(addr, 0);
- void *bmp_alloc_addr = NULL;
- unsigned long len;
-
- if (!((bmp->header.signature[0]=='B') &&
- (bmp->header.signature[1]=='M')))
- bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
-
- if (!bmp) {
- printf("There is no valid bmp file at the given address\n");
- return 1;
- }
- addr = map_to_sysmem(bmp);
-
- ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
- if (!ret) {
- bool align = false;
-
- if (x == BMP_ALIGN_CENTER || y == BMP_ALIGN_CENTER)
- align = true;
-
- ret = video_bmp_display(dev, addr, x, y, align);
- }
-
- if (bmp_alloc_addr)
- free(bmp_alloc_addr);
-
- return ret ? CMD_RET_FAILURE : 0;
-}
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 42f6e14a437..cfe34226989 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -181,6 +181,9 @@ static int do_bootflow_scan(struct cmd_tbl *cmdtp, int flag, int argc,
if (list)
show_footer(i, num_valid);
+ if (IS_ENABLED(CONFIG_CMD_BOOTFLOW_FULL) && !num_valid && !list)
+ printf("No bootflows found; try again with -l\n");
+
return 0;
}
@@ -387,6 +390,11 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc,
bool text_mode = false;
int ret;
+ if (!IS_ENABLED(CONFIG_EXPO)) {
+ printf("Menu not supported\n");
+ return CMD_RET_FAILURE;
+ }
+
if (argc > 1 && *argv[1] == '-')
text_mode = strchr(argv[1], 't');
@@ -394,20 +402,15 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc,
if (ret)
return CMD_RET_FAILURE;
- if (IS_ENABLED(CONFIG_EXPO)) {
- ret = bootflow_menu_run(std, text_mode, &bflow);
- if (ret) {
- if (ret == -EAGAIN)
- printf("Nothing chosen\n");
- else
- printf("Menu failed (err=%d)\n", ret);
+ ret = bootflow_menu_run(std, text_mode, &bflow);
+ if (ret) {
+ if (ret == -EAGAIN)
+ printf("Nothing chosen\n");
+ else {
+ printf("Menu failed (err=%d)\n", ret);
+ return CMD_RET_FAILURE;
}
- } else {
- printf("Menu not supported\n");
- ret = -ENOSYS;
}
- if (ret)
- return CMD_RET_FAILURE;
printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name);
std->cur_bootflow = bflow;
diff --git a/cmd/console.c b/cmd/console.c
index 620a961cdef..58c2cf1c894 100644
--- a/cmd/console.c
+++ b/cmd/console.c
@@ -9,6 +9,7 @@
*/
#include <common.h>
#include <command.h>
+#include <iomux.h>
#include <stdio_dev.h>
extern void _do_coninfo (void);
@@ -33,9 +34,15 @@ static int do_coninfo(struct cmd_tbl *cmd, int flag, int argc,
(dev->flags & DEV_FLAGS_OUTPUT) ? "O" : "");
for (l = 0; l < MAX_FILES; l++) {
- if (stdio_devices[l] == dev) {
- printf("| |-- %s\n", stdio_names[l]);
+ if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+ if (iomux_match_device(console_devices[l],
+ cd_count[l], dev) >= 0)
+ printf("| |-- %s\n", stdio_names[l]);
+ } else {
+ if (stdio_devices[l] == dev)
+ printf("| |-- %s\n", stdio_names[l]);
}
+
}
}
return 0;
diff --git a/cmd/date.c b/cmd/date.c
index 58505e6e1d3..fe9c8c6534e 100644
--- a/cmd/date.c
+++ b/cmd/date.c
@@ -98,7 +98,7 @@ static int do_date(struct cmd_tbl *cmdtp, int flag, int argc,
puts("## Get date failed\n");
}
}
- /* FALL TROUGH */
+ fallthrough;
case 1: /* get date & time */
#ifdef CONFIG_DM_RTC
rcode = dm_rtc_get(dev, &tm);
diff --git a/cmd/fastboot.c b/cmd/fastboot.c
index 97dc02ce748..3d5ff951eb6 100644
--- a/cmd/fastboot.c
+++ b/cmd/fastboot.c
@@ -26,7 +26,7 @@ static int do_fastboot_udp(int argc, char *const argv[],
return CMD_RET_FAILURE;
}
- err = net_loop(FASTBOOT);
+ err = net_loop(FASTBOOT_UDP);
if (err < 0) {
printf("fastboot udp error: %d\n", err);
@@ -36,6 +36,26 @@ static int do_fastboot_udp(int argc, char *const argv[],
return CMD_RET_SUCCESS;
}
+static int do_fastboot_tcp(int argc, char *const argv[],
+ uintptr_t buf_addr, size_t buf_size)
+{
+ int err;
+
+ if (!IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)) {
+ pr_err("Fastboot TCP not enabled\n");
+ return CMD_RET_FAILURE;
+ }
+
+ err = net_loop(FASTBOOT_TCP);
+
+ if (err < 0) {
+ printf("fastboot tcp error: %d\n", err);
+ return CMD_RET_FAILURE;
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
static int do_fastboot_usb(int argc, char *const argv[],
uintptr_t buf_addr, size_t buf_size)
{
@@ -141,7 +161,8 @@ NXTARG:
if (!strcmp(argv[1], "udp"))
return do_fastboot_udp(argc, argv, buf_addr, buf_size);
-
+ if (!strcmp(argv[1], "tcp"))
+ return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
if (!strcmp(argv[1], "usb")) {
argv++;
argc--;
diff --git a/cmd/ide.c b/cmd/ide.c
index 6739f0b12d1..ddc87d3a0bb 100644
--- a/cmd/ide.c
+++ b/cmd/ide.c
@@ -10,12 +10,15 @@
#include <common.h>
#include <blk.h>
+#include <dm.h>
#include <config.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <asm/byteorder.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
#include <ide.h>
#include <ata.h>
@@ -31,8 +34,25 @@ int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
if (argc == 2) {
if (strncmp(argv[1], "res", 3) == 0) {
+ struct udevice *dev;
+ int ret;
+
puts("\nReset IDE: ");
- ide_init();
+ ret = uclass_find_first_device(UCLASS_IDE, &dev);
+ ret = device_remove(dev, DM_REMOVE_NORMAL);
+ if (!ret)
+ ret = device_chld_unbind(dev, NULL);
+ if (ret) {
+ printf("Cannot remove IDE (err=%dE)\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ ret = uclass_first_device_err(UCLASS_IDE, &dev);
+ if (ret) {
+ printf("Init failed (err=%dE)\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
return 0;
}
}
diff --git a/cmd/mmc.c b/cmd/mmc.c
index 94deb9a1686..c6bd81cebbc 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
curr_device = 0;
else {
puts("No MMC device available\n");
- return 1;
+ return CMD_RET_FAILURE;
}
}
@@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
- int dev;
+ int ret, dev;
struct mmc *mmc;
u8 ack, part_num, access;
@@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
access = dectoul(argv[4], NULL);
/* acknowledge to be sent during boot operation */
- return mmc_set_part_conf(mmc, ack, part_num, access);
+ ret = mmc_set_part_conf(mmc, ack, part_num, access);
+ if (ret != 0)
+ return CMD_RET_FAILURE;
+
+ return CMD_RET_SUCCESS;
}
static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
- int dev;
+ int ret, dev;
struct mmc *mmc;
u8 enable;
@@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
return CMD_RET_FAILURE;
}
- return mmc_set_rst_n_function(mmc, enable);
+ ret = mmc_set_rst_n_function(mmc, enable);
+ if (ret != 0)
+ return CMD_RET_FAILURE;
+
+ return CMD_RET_SUCCESS;
}
#endif
static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 49797b23144..ca24a5c1c4b 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -223,8 +223,7 @@ static int mmc_burn_image(size_t image_size)
orig_part = mmc->block_dev.hwpart;
#endif
- part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
-
+ part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
if (part == 7)
part = 0;
@@ -925,8 +924,11 @@ static int check_image_header(void)
offset = le32_to_cpu(hdr->srcaddr);
size = le32_to_cpu(hdr->blocksize);
- if (hdr->blockid == 0x78) /* SATA id */
- offset *= 512;
+ if (hdr->blockid == 0x78) { /* SATA id */
+ struct blk_desc *blk_dev = IS_ENABLED(BLK) ? blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0) : NULL;
+ unsigned long blksz = blk_dev ? blk_dev->blksz : 512;
+ offset *= blksz;
+ }
if (offset % 4 != 0 || size < 4 || size % 4 != 0) {
printf("Error: Bad A38x image blocksize.\n");
diff --git a/cmd/net.c b/cmd/net.c
index d5e20843dda..68d406291ef 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -111,6 +111,29 @@ U_BOOT_CMD(
);
#endif
+#if defined(CONFIG_CMD_DHCP6)
+static int do_dhcp6(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ int i;
+ int dhcp_argc;
+ char *dhcp_argv[] = {NULL, NULL, NULL, NULL};
+
+ /* Add -ipv6 flag for autoload */
+ for (i = 0; i < argc; i++)
+ dhcp_argv[i] = argv[i];
+ dhcp_argc = argc + 1;
+ dhcp_argv[dhcp_argc - 1] = USE_IP6_CMD_PARAM;
+
+ return netboot_common(DHCP6, cmdtp, dhcp_argc, dhcp_argv);
+}
+
+U_BOOT_CMD(dhcp6, 3, 1, do_dhcp6,
+ "boot image via network using DHCPv6/TFTP protocol.\n"
+ "Use IPv6 hostIPaddr framed with [] brackets",
+ "[loadAddress] [[hostIPaddr:]bootfilename]");
+#endif
+
#if defined(CONFIG_CMD_DHCP)
static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
@@ -186,7 +209,7 @@ U_BOOT_CMD(
static void netboot_update_env(void)
{
- char tmp[22];
+ char tmp[44];
if (net_gateway.s_addr) {
ip_to_string(net_gateway, tmp);
@@ -247,6 +270,27 @@ static void netboot_update_env(void)
env_set("ntpserverip", tmp);
}
#endif
+
+ if (IS_ENABLED(CONFIG_IPV6)) {
+ if (!ip6_is_unspecified_addr(&net_ip6) ||
+ net_prefix_length != 0) {
+ sprintf(tmp, "%pI6c", &net_ip6);
+ if (net_prefix_length != 0)
+ sprintf(tmp, "%s/%d", tmp, net_prefix_length);
+
+ env_set("ip6addr", tmp);
+ }
+
+ if (!ip6_is_unspecified_addr(&net_server_ip6)) {
+ sprintf(tmp, "%pI6c", &net_server_ip6);
+ env_set("serverip6", tmp);
+ }
+
+ if (!ip6_is_unspecified_addr(&net_gateway6)) {
+ sprintf(tmp, "%pI6c", &net_gateway6);
+ env_set("gatewayip6", tmp);
+ }
+ }
}
/**
diff --git a/cmd/pci.c b/cmd/pci.c
index 58a74755c8b..78b661d15b1 100644
--- a/cmd/pci.c
+++ b/cmd/pci.c
@@ -517,6 +517,7 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
addr = hextoul(argv[3], NULL);
if (argc > 4)
value = hextoul(argv[4], NULL);
+ fallthrough;
case 'h': /* header */
case 'b': /* bars */
if (argc < 3)
diff --git a/cmd/pxe.c b/cmd/pxe.c
index db8e4697f24..677142520bb 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -8,6 +8,8 @@
#include <command.h>
#include <fs.h>
#include <net.h>
+#include <net6.h>
+#include <malloc.h>
#include "pxe_utils.h"
@@ -29,12 +31,20 @@ static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
{
char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
int ret;
+ int num_args;
tftp_argv[1] = file_addr;
tftp_argv[2] = (void *)file_path;
+ if (ctx->use_ipv6) {
+ tftp_argv[3] = USE_IP6_CMD_PARAM;
+ num_args = 4;
+ } else {
+ num_args = 3;
+ }
- if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
+ if (do_tftpb(ctx->cmdtp, 0, num_args, tftp_argv))
return -ENOENT;
+
ret = pxe_get_file_size(sizep);
if (ret)
return log_msg_ret("tftp", ret);
@@ -44,6 +54,22 @@ static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
}
/*
+ * Looks for a pxe file with specified config file name,
+ * which is received from DHCPv4 option 209 or
+ * DHCPv6 option 60.
+ *
+ * Returns 1 on success or < 0 on error.
+ */
+static int pxe_dhcp_option_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
+{
+ int ret = get_pxe_file(ctx, pxelinux_configfile, pxefile_addr_r);
+
+ free(pxelinux_configfile);
+
+ return ret;
+}
+
+/*
* Looks for a pxe file with a name based on the pxeuuid environment variable.
*
* Returns 1 on success or < 0 on error.
@@ -105,15 +131,24 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_
return -ENOENT;
}
-int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep)
+int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep, bool use_ipv6)
{
struct cmd_tbl cmdtp[] = {}; /* dummy */
struct pxe_context ctx;
int i;
if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
- env_get("bootfile")))
+ env_get("bootfile"), use_ipv6))
return -ENOMEM;
+
+ if (IS_ENABLED(CONFIG_DHCP6_PXE_DHCP_OPTION) &&
+ pxelinux_configfile && use_ipv6) {
+ if (pxe_dhcp_option_path(&ctx, pxefile_addr_r) > 0)
+ goto done;
+
+ goto error_exit;
+ }
+
/*
* Keep trying paths until we successfully get a file we're looking
* for.
@@ -131,6 +166,7 @@ int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep)
i++;
}
+error_exit:
pxe_destroy_ctx(&ctx);
return -ENOENT;
@@ -169,9 +205,18 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
char *fname;
ulong size;
int ret;
+ bool use_ipv6 = false;
- if (argc != 1)
- return CMD_RET_USAGE;
+ if (IS_ENABLED(CONFIG_IPV6)) {
+ if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM))
+ use_ipv6 = true;
+
+ if (!(argc == 1 || (argc == 2 && use_ipv6)))
+ return CMD_RET_USAGE;
+ } else {
+ if (argc != 1)
+ return CMD_RET_USAGE;
+ }
pxefile_addr_str = from_env("pxefile_addr_r");
@@ -183,7 +228,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
if (ret < 0)
return 1;
- ret = pxe_get(pxefile_addr_r, &fname, &size);
+ ret = pxe_get(pxefile_addr_r, &fname, &size, use_ipv6);
switch (ret) {
case 0:
printf("Config file '%s' found\n", fname);
@@ -211,13 +256,19 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
char *pxefile_addr_str;
struct pxe_context ctx;
int ret;
+ bool use_ipv6 = false;
+
+ if (IS_ENABLED(CONFIG_IPV6)) {
+ if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM))
+ use_ipv6 = true;
+ }
- if (argc == 1) {
+ if (argc == 1 || (argc == 2 && use_ipv6)) {
pxefile_addr_str = from_env("pxefile_addr_r");
if (!pxefile_addr_str)
return 1;
- } else if (argc == 2) {
+ } else if (argc == 2 || (argc == 3 && use_ipv6)) {
pxefile_addr_str = argv[1];
} else {
return CMD_RET_USAGE;
@@ -229,7 +280,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
}
if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
- env_get("bootfile"))) {
+ env_get("bootfile"), use_ipv6)) {
printf("Out of memory\n");
return CMD_RET_FAILURE;
}
@@ -244,8 +295,8 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
}
static struct cmd_tbl cmd_pxe_sub[] = {
- U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
- U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
+ U_BOOT_CMD_MKENT(get, 2, 1, do_pxe_get, "", ""),
+ U_BOOT_CMD_MKENT(boot, 3, 1, do_pxe_boot, "", "")
};
static void __maybe_unused pxe_reloc(void)
@@ -281,9 +332,11 @@ static int do_pxe(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return CMD_RET_USAGE;
}
-U_BOOT_CMD(pxe, 3, 1, do_pxe,
- "commands to get and boot from pxe files",
- "get - try to retrieve a pxe file using tftp\n"
- "pxe boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
+U_BOOT_CMD(pxe, 4, 1, do_pxe,
+ "commands to get and boot from pxe files\n"
+ "To use IPv6 add -ipv6 parameter",
+ "get [" USE_IP6_CMD_PARAM "] - try to retrieve a pxe file using tftp\n"
+ "pxe boot [pxefile_addr_r] [-ipv6] - boot from the pxe file at pxefile_addr_r\n"
);
-#endif
+
+#endif /* CONFIG_CMD_NET */
diff --git a/cmd/regulator.c b/cmd/regulator.c
index ed4996dbd2b..8988c901087 100644
--- a/cmd/regulator.c
+++ b/cmd/regulator.c
@@ -37,6 +37,7 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
printf("Can't get the regulator: %s!\n", name);
return failure(ret);
}
+ fallthrough;
case 1:
if (!currdev) {
printf("Regulator device is not set!\n\n");
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 04c07020269..63a7806debe 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -101,7 +101,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
}
if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true,
- filename)) {
+ filename, false)) {
printf("Out of memory\n");
return CMD_RET_FAILURE;
}
diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c
index 4591ff336bb..79796394c5c 100644
--- a/cmd/tlv_eeprom.c
+++ b/cmd/tlv_eeprom.c
@@ -29,26 +29,23 @@ DECLARE_GLOBAL_DATA_PTR;
/* File scope function prototypes */
static bool is_checksum_valid(u8 *eeprom);
-static int read_eeprom(u8 *eeprom);
-static void show_eeprom(u8 *eeprom);
+static int read_eeprom(int devnum, u8 *eeprom);
+static void show_eeprom(int devnum, u8 *eeprom);
static void decode_tlv(struct tlvinfo_tlv *tlv);
static void update_crc(u8 *eeprom);
-static int prog_eeprom(u8 *eeprom);
+static int prog_eeprom(int devnum, u8 *eeprom);
static bool tlvinfo_find_tlv(u8 *eeprom, u8 tcode, int *eeprom_index);
static bool tlvinfo_delete_tlv(u8 *eeprom, u8 code);
static bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval);
static int set_mac(char *buf, const char *string);
static int set_date(char *buf, const char *string);
static int set_bytes(char *buf, const char *string, int *converted_accum);
-static void show_tlv_devices(void);
+static void show_tlv_devices(int current_dev);
-/* Set to 1 if we've read EEPROM into memory */
-static int has_been_read;
/* The EERPOM contents after being read into memory */
static u8 eeprom[TLV_INFO_MAX_LEN];
static struct udevice *tlv_devices[MAX_TLV_DEVICES];
-static unsigned int current_dev;
#define to_header(p) ((struct tlvinfo_header *)p)
#define to_entry(p) ((struct tlvinfo_tlv *)p)
@@ -125,22 +122,20 @@ static bool is_checksum_valid(u8 *eeprom)
*
* Read the EEPROM into memory, if it hasn't already been read.
*/
-static int read_eeprom(u8 *eeprom)
+static int read_eeprom(int devnum, u8 *eeprom)
{
int ret;
struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
struct tlvinfo_tlv *eeprom_tlv = to_entry(&eeprom[HDR_SIZE]);
- if (has_been_read)
- return 0;
-
/* Read the header */
- ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, current_dev);
+ ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, devnum);
/* If the header was successfully read, read the TLVs */
if (ret == 0 && is_valid_tlvinfo_header(eeprom_hdr))
ret = read_tlv_eeprom((void *)eeprom_tlv, HDR_SIZE,
- be16_to_cpu(eeprom_hdr->totallen),
- current_dev);
+ be16_to_cpu(eeprom_hdr->totallen), devnum);
+ else if (ret == -ENODEV)
+ return ret;
// If the contents are invalid, start over with default contents
if (!is_valid_tlvinfo_header(eeprom_hdr) ||
@@ -151,10 +146,8 @@ static int read_eeprom(u8 *eeprom)
update_crc(eeprom);
}
- has_been_read = 1;
-
#ifdef DEBUG
- show_eeprom(eeprom);
+ show_eeprom(devnum, eeprom);
#endif
return ret;
@@ -165,7 +158,7 @@ static int read_eeprom(u8 *eeprom)
*
* Display the contents of the EEPROM
*/
-static void show_eeprom(u8 *eeprom)
+static void show_eeprom(int devnum, u8 *eeprom)
{
int tlv_end;
int curr_tlv;
@@ -180,7 +173,7 @@ static void show_eeprom(u8 *eeprom)
return;
}
- printf("TLV: %u\n", current_dev);
+ printf("TLV: %u\n", devnum);
printf("TlvInfo Header:\n");
printf(" Id String: %s\n", eeprom_hdr->signature);
printf(" Version: %d\n", eeprom_hdr->version);
@@ -389,7 +382,7 @@ static void update_crc(u8 *eeprom)
*
* Write the EEPROM data from CPU memory to the hardware.
*/
-static int prog_eeprom(u8 *eeprom)
+static int prog_eeprom(int devnum, u8 *eeprom)
{
int ret = 0;
struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
@@ -398,7 +391,7 @@ static int prog_eeprom(u8 *eeprom)
update_crc(eeprom);
eeprom_len = HDR_SIZE + be16_to_cpu(eeprom_hdr->totallen);
- ret = write_tlv_eeprom(eeprom, eeprom_len);
+ ret = write_tlv_eeprom(eeprom, eeprom_len, devnum);
if (ret) {
printf("Programming failed.\n");
return -1;
@@ -433,11 +426,23 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
char cmd;
struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
+ static unsigned int current_dev;
+ /* Set to 1 if we've read EEPROM into memory */
+ static int has_been_read;
+ int ret;
// If no arguments, read the EERPOM and display its contents
if (argc == 1) {
- read_eeprom(eeprom);
- show_eeprom(eeprom);
+ if (!has_been_read) {
+ ret = read_eeprom(current_dev, eeprom);
+ if (ret) {
+ printf("Failed to read EEPROM data from device.\n");
+ return 0;
+ }
+
+ has_been_read = 1;
+ }
+ show_eeprom(current_dev, eeprom);
return 0;
}
@@ -445,12 +450,33 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
// "reset" will both be treated as "read".
cmd = argv[1][0];
+ // select device
+ if (cmd == 'd') {
+ /* 'dev' command */
+ unsigned int devnum;
+
+ devnum = simple_strtoul(argv[2], NULL, 0);
+ if (devnum >= MAX_TLV_DEVICES) {
+ printf("Invalid device number\n");
+ return 0;
+ }
+ current_dev = devnum;
+ has_been_read = 0;
+
+ return 0;
+ }
+
// Read the EEPROM contents
if (cmd == 'r') {
has_been_read = 0;
- if (!read_eeprom(eeprom))
- printf("EEPROM data loaded from device to memory.\n");
- return 0;
+ ret = read_eeprom(current_dev, eeprom);
+ if (ret) {
+ printf("Failed to read EEPROM data from device.\n");
+ return 0;
+ }
+
+ printf("EEPROM data loaded from device to memory.\n");
+ has_been_read = 1;
}
// Subsequent commands require that the EEPROM has already been read.
@@ -463,7 +489,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
if (argc == 2) {
switch (cmd) {
case 'w': /* write */
- prog_eeprom(eeprom);
+ prog_eeprom(current_dev, eeprom);
break;
case 'e': /* erase */
strcpy(eeprom_hdr->signature, TLV_INFO_ID_STRING);
@@ -476,7 +502,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
show_tlv_code_list();
break;
case 'd': /* dev */
- show_tlv_devices();
+ show_tlv_devices(current_dev);
break;
default:
return CMD_RET_USAGE;
@@ -498,16 +524,6 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
tlvinfo_delete_tlv(eeprom, tcode);
if (argc == 4)
tlvinfo_add_tlv(eeprom, tcode, argv[3]);
- } else if (cmd == 'd') { /* 'dev' command */
- unsigned int devnum;
-
- devnum = simple_strtoul(argv[2], NULL, 0);
- if (devnum > MAX_TLV_DEVICES || !tlv_devices[devnum]) {
- printf("Invalid device number\n");
- return 0;
- }
- current_dev = devnum;
- has_been_read = 0;
} else {
return CMD_RET_USAGE;
}
@@ -883,7 +899,7 @@ static int set_bytes(char *buf, const char *string, int *converted_accum)
return 0;
}
-static void show_tlv_devices(void)
+static void show_tlv_devices(int current_dev)
{
unsigned int dev;
@@ -953,14 +969,14 @@ int read_tlv_eeprom(void *eeprom, int offset, int len, int dev_num)
/**
* write_tlv_eeprom - write the hwinfo to i2c EEPROM
*/
-int write_tlv_eeprom(void *eeprom, int len)
+int write_tlv_eeprom(void *eeprom, int len, int dev)
{
if (!(gd->flags & GD_FLG_RELOC))
return -ENODEV;
- if (!tlv_devices[current_dev])
+ if (!tlv_devices[dev])
return -ENODEV;
- return i2c_eeprom_write(tlv_devices[current_dev], 0, eeprom, len);
+ return i2c_eeprom_write(tlv_devices[dev], 0, eeprom, len);
}
int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
@@ -1015,10 +1031,11 @@ int mac_read_from_eeprom(void)
int maccount;
u8 macbase[6];
struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
+ int devnum = 0; // TODO: support multiple EEPROMs
puts("EEPROM: ");
- if (read_eeprom(eeprom)) {
+ if (read_eeprom(devnum, eeprom)) {
printf("Read failed.\n");
return -1;
}
@@ -1083,7 +1100,7 @@ int mac_read_from_eeprom(void)
*
* This function must be called after relocation.
*/
-int populate_serial_number(void)
+int populate_serial_number(int devnum)
{
char serialstr[257];
int eeprom_index;
@@ -1092,7 +1109,7 @@ int populate_serial_number(void)
if (env_get("serial#"))
return 0;
- if (read_eeprom(eeprom)) {
+ if (read_eeprom(devnum, eeprom)) {
printf("Read failed.\n");
return -1;
}
diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
index b35eae81dc3..c4ed8e59012 100644
--- a/cmd/tpm_test.c
+++ b/cmd/tpm_test.c
@@ -471,6 +471,7 @@ static int test_write_limit(struct udevice *dev)
break;
case TPM_MAXNVWRITES:
assert(i >= TPM_MAX_NV_WRITES_NOOWNER);
+ break;
default:
pr_err("\tunexpected error code %d (0x%x)\n",
result, result);