Commit 32b5eff5 authored by Marek Vasut's avatar Marek Vasut

mxssb: Improve command error reporting

Report proper error messages when the command parsing function
fails. Also report line number at which the error happened.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 72b9bd61
......@@ -492,7 +492,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
tok = strtok(line, " ");
if (!tok) { /* No command on this line. */
fprintf(stderr, "WARN: No command on this line, ignoring!\n");
fprintf(stderr,
"#%i WARN: No command on this line, ignoring!\n",
lst->lineno);
ret = 0;
goto err;
}
......@@ -505,14 +507,16 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
}
if ((len != 3) && (len != 4)) {
fprintf(stderr, "WARN: Unknown command!\n");
fprintf(stderr, "#%i ERR: Unknown command '%s'!\n",
lst->lineno, tok);
ret = -EINVAL;
goto err;
}
if ((len == 3) &&
(strncmp(tok, "TAG", 3) && strncmp(tok, "NOP", 3))) {
fprintf(stderr, "ERR: Unknown command!\n");
fprintf(stderr, "#%i ERR: Unknown command '%s'!\n",
lst->lineno, tok);
ret = -EINVAL;
goto err;
}
......@@ -521,7 +525,8 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
(strncmp(tok, "LOAD", 4) && strncmp(tok, "FILL", 4) &&
strncmp(tok, "JUMP", 4) && strncmp(tok, "CALL", 4) &&
strncmp(tok, "MODE", 4))) {
fprintf(stderr, "ERR: Unknown command!\n");
fprintf(stderr, "#%i ERR: Unknown command '%s'!\n",
lst->lineno, tok);
ret = -EINVAL;
goto err;
}
......@@ -547,6 +552,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
case 'L': /* ROM_LOAD_CMD */
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr,
"#%i ERR: Missing LOAD address or 'IVT'!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -555,6 +563,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
cctx->ivt = 1;
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr,
"#%i ERR: Missing LOAD address!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -562,12 +573,17 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
/* Read load destination address. */
dest = sb_token_to_long(tok);
if (dest < 0) {
fprintf(stderr, "#%i ERR: Incorrect LOAD address!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
/* Read filename or IVT entrypoint. */
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr,
"#%i ERR: Missing LOAD filename or IVT ep!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -576,6 +592,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
long ivtep = sb_token_to_long(tok);
if (ivtep < 0) {
fprintf(stderr,
"#%i ERR: Incorrect IVT entry point!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -595,13 +614,17 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
} else {
ret = sb_load_file(cctx, tok);
if (ret) {
fprintf(stderr, "#%i ERR: Cannot load '%s'!\n",
lst->lineno, tok);
ret = ret;
goto err;
}
}
if (cctx->length & (SB_BLOCK_SIZE - 1))
fprintf(stderr, "WARN: Unaligned payload!\n");
if (cctx->length & (SB_BLOCK_SIZE - 1)) {
fprintf(stderr, "#%i ERR: Unaligned payload!\n",
lst->lineno);
}
/* Fill LOAD instruction. */
cmd->header.tag = ROM_LOAD_CMD;
......@@ -612,15 +635,22 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
break;
case 'F': /* ROM_FILL_CMD ; UNSUPPORTED */
cmd->header.tag = ROM_FILL_CMD;
fprintf(stderr, "#%i ERR: Unsupported instruction '%s'!\n",
lst->lineno, tok);
ret = -ENOTSUP;
goto err;
case 'J': /* ROM_JUMP_CMD ; UNSUPPORTED */
cmd->header.tag = ROM_JUMP_CMD;
fprintf(stderr, "#%i ERR: Unsupported instruction '%s'!\n",
lst->lineno, tok);
ret = -ENOTSUP;
goto err;
case 'C': /* ROM_CALL_CMD */
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr,
"#%i ERR: Missing CALL address or 'HAB'!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -629,6 +659,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
cmd->header.flags = ROM_CALL_CMD_FLAG_HAB;
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr,
"#%i ERR: Missing CALL address!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -636,6 +669,8 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
/* Read load destination address. */
dest = sb_token_to_long(tok);
if (dest < 0) {
fprintf(stderr, "#%i ERR: Incorrect CALL address!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -645,6 +680,9 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
if (tok) {
arg = sb_token_to_long(tok);
if (arg < 0) {
fprintf(stderr,
"#%i ERR: Incorrect CALL argument!\n",
lst->lineno);
ret = -EINVAL;
goto err;
}
......@@ -656,7 +694,8 @@ static int sb_tag_to_command(struct sb_cmd_ctx *cctx, struct sb_cmd_list *lst)
break;
case 'M': /* ROM_MODE_CMD ; UNSUPPORTED */
cmd->header.tag = ROM_MODE_CMD;
ret = -ENOTSUP;
fprintf(stderr, "#%i ERR: Unsupported instruction '%s'!\n",
lst->lineno, tok);
goto err;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment