diff mbox series

[U-Boot,v2,14/17] cmd: fpga: Add support for missing fpga loadmk commands

Message ID 868e33476e534fe3de0ecf772f857834f4fb472d.1533728254.git.michal.simek@xilinx.com
State Accepted
Delegated to: Michal Simek
Headers show
Series cmd: fpga: Fix fpga command handling and add some fpga tests | expand

Commit Message

Michal Simek Aug. 8, 2018, 11:37 a.m. UTC
There are ways how to call fpga loadmk

1. Full command
fpga loadmk [dev] [address]

2. Dev setup via variable
set fpga [dev]
fpga loadmk [address]

3. Address setup via variable
set fpgadata [address]
fpga loadmk [dev]

4. Dev and address setup via variables
set fpga [dev]
set fpgadata [address]
fpga loadmk

Before this patch only cases 1 and 3 are working but the part of code
was trying to support also cases 2 and 4.
This patch is adding support for cases 2 and 4 to have all of
combinations supported.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v2:
- Extend non complete commit message

Changes in v1:
- New patch from RFC

 cmd/fpga.c | 55 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 20 deletions(-)

Comments

Simon Glass Aug. 9, 2018, 11:20 a.m. UTC | #1
On 8 August 2018 at 05:37, Michal Simek <michal.simek@xilinx.com> wrote:
> There are ways how to call fpga loadmk
>
> 1. Full command
> fpga loadmk [dev] [address]
>
> 2. Dev setup via variable
> set fpga [dev]
> fpga loadmk [address]
>
> 3. Address setup via variable
> set fpgadata [address]
> fpga loadmk [dev]
>
> 4. Dev and address setup via variables
> set fpga [dev]
> set fpgadata [address]
> fpga loadmk
>
> Before this patch only cases 1 and 3 are working but the part of code
> was trying to support also cases 2 and 4.
> This patch is adding support for cases 2 and 4 to have all of
> combinations supported.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v2:
> - Extend non complete commit message
>
> Changes in v1:
> - New patch from RFC
>
>  cmd/fpga.c | 55 +++++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 35 insertions(+), 20 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/cmd/fpga.c b/cmd/fpga.c
index 9cb0116af734..de9d19dd8e91 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -22,7 +22,7 @@  static long do_fpga_get_device(char *arg)
 		/* Should be strtol to handle -1 cases */
 		dev = simple_strtol(devstr, NULL, 16);
 
-	if (arg)
+	if (dev == FPGA_INVALID_DEVICE && arg)
 		dev = simple_strtol(arg, NULL, 16);
 
 	debug("%s: device = %ld\n", __func__, dev);
@@ -312,29 +312,44 @@  static int do_fpga_loadmk(cmd_tbl_t *cmdtp, int flag, int argc,
 	ulong dev = do_fpga_get_device(argv[0]);
 	char *datastr = env_get("fpgadata");
 
-	if (datastr)
-		fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
+	debug("fpga: argc %x, dev %lx, datastr %s\n", argc, dev, datastr);
+
+	if (dev == FPGA_INVALID_DEVICE) {
+		debug("fpga: Invalid fpga device\n");
+		return CMD_RET_USAGE;
+	}
+
+	if (argc == 0 && !datastr) {
+		debug("fpga: No datastr passed\n");
+		return CMD_RET_USAGE;
+	}
 
 	if (argc == 2) {
+		datastr = argv[1];
+		debug("fpga: Full command with two args\n");
+	} else if (argc == 1 && !datastr) {
+		debug("fpga: Dev is setup - fpgadata passed\n");
+		datastr = argv[0];
+	}
+
 #if defined(CONFIG_FIT)
-		if (fit_parse_subimage(argv[1], (ulong)fpga_data,
-				       &fit_addr, &fit_uname)) {
-			fpga_data = (void *)fit_addr;
-			debug("*  fpga: subimage '%s' from FIT image ",
-			      fit_uname);
-			debug("at 0x%08lx\n", fit_addr);
-		} else
+	if (fit_parse_subimage(datastr, (ulong)fpga_data,
+			       &fit_addr, &fit_uname)) {
+		fpga_data = (void *)fit_addr;
+		debug("*  fpga: subimage '%s' from FIT image ",
+		      fit_uname);
+		debug("at 0x%08lx\n", fit_addr);
+	} else
 #endif
-		{
-			fpga_data = (void *)simple_strtoul(argv[1], NULL, 16);
-			debug("*  fpga: cmdline image address = 0x%08lx\n",
-			      (ulong)fpga_data);
-		}
-		debug("%s: fpga_data = 0x%lx\n", __func__, (ulong)fpga_data);
-		if (!fpga_data) {
-			puts("Zero fpga_data address\n");
-			return CMD_RET_USAGE;
-		}
+	{
+		fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
+		debug("*  fpga: cmdline image address = 0x%08lx\n",
+		      (ulong)fpga_data);
+	}
+	debug("%s: fpga_data = 0x%lx\n", __func__, (ulong)fpga_data);
+	if (!fpga_data) {
+		puts("Zero fpga_data address\n");
+		return CMD_RET_USAGE;
 	}
 
 	switch (genimg_get_format(fpga_data)) {