Skip to contentSkip to conversation

cmd_fpga: cleanup help and check parameters

PATCH New Stefano Babic 2 participants 2 messages Oct 19, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd_fpga: cleanup help and check parameters

The usage and help for the fpga command is wrong and incomplete, and the parameters are not checked before to be passed to the underlying subfunction.

---
 common/cmd_fpga.c |   50 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 39 insertions(+), 11 deletions(-)
common/cmd_fpga.c +39 -11
index e50c9de..0ad310f 100644
@@ -163,6 +163,7 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 	char *devstr = getenv ("fpga");
 	char *datastr = getenv ("fpgadata");
 	int rc = FPGA_FAIL;
+	int wrong_parms = 0;
 #if defined (CONFIG_FIT)
 	const char *fit_uname = NULL;
 	ulong fit_addr;
@@ -229,6 +230,32 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 		break;
 	}
 
+	if (dev == FPGA_INVALID_DEVICE) {
+		puts("FPGA device not specified\n");
+		op = FPGA_NONE;
+	}
+
+	switch (op) {
+	case FPGA_NONE:
+	case FPGA_INFO:
+		break;
+	case FPGA_LOAD:
+	case FPGA_LOADB:
+	case FPGA_DUMP:
+		if (!fpga_data || !data_size)
+			wrong_parms = 1;
+		break;
+	case FPGA_LOADMK:
+		if (!fpga_data)
+			wrong_parms = 1;
+		break;
+	}
+
+	if (wrong_parms) {
+		puts("Wrong parameters for FPGA request\n");
+		op = FPGA_NONE;
+	}
+
 	switch (op) {
 	case FPGA_NONE:
 		return cmd_usage(cmdtp);
@@ -342,17 +369,18 @@ static int fpga_get_op (char *opstr)
 }
 
 U_BOOT_CMD (fpga, 6, 1, do_fpga,
-	    "loadable FPGA image support",
-	    "fpga [operation type] [device number] [image address] [image size]\n"
-	    "fpga operations:\n"
-	    "\tinfo\tlist known device information\n"
-	    "\tload\tLoad device from memory buffer\n"
-	    "\tloadb\tLoad device from bitstream buffer (Xilinx devices only)\n"
-	    "\tloadmk\tLoad device generated with mkimage\n"
-	    "\tdump\tLoad device to memory buffer"
+	"loadable FPGA image support",
+	"[operation type] [device number] [image address] [image size]\n"
+	"fpga operations:\n"
+	"  dump\t[dev]\t\t\tLoad device to memory buffer\n"
+	"  info\t[dev]\t\t\tlist known device information\n"
+	"  load\t[dev] [address] [size]\tLoad device from memory buffer\n"
+	"  loadb\t[dev] [address] [size]\t"
+	"Load device from bitstream buffer (Xilinx only)\n"
+	"  loadmk [dev] [address]\tLoad device generated with mkimage"
 #if defined(CONFIG_FIT)
-	    "\n"
-	    "\tFor loadmk operating on FIT format uImage address must include\n"
-	    "\tsubimage unit name in the form of addr:<subimg_uname>"
+	"\n"
+	"\tFor loadmk operating on FIT format uImage address must include\n"
+	"\tsubimage unit name in the form of addr:<subimg_uname>"
 #endif
 );
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 cmd_fpga: cleanup help and check parameters

Dear Stefano Babic,

Quoted 8 lines · In message <[email protected]> you wrote:

The usage and help for the fpga command is wrong and incomplete, and the parameters are not checked before to be passed to the underlying subfunction.

---
 common/cmd_fpga.c |   50 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 39 insertions(+), 11 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Everything should be made as simple as possible, but not simpler."
                                                    - Albert Einstein