Commit d1289c1d authored by Marek Vasut's avatar Marek Vasut

mxssb: Implement the FILL command

With the current parser, it is very easy to implement the commands.
Implement the FILL command, which fills the memory with pattern.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 929ca711
......@@ -97,6 +97,7 @@ struct sb_image_ctx {
* TAG [LAST]
* LOAD address file
* LOAD IVT address IVT_entry_point
* FILL address pattern length
* JUMP [HAB] address [r0_arg]
* CALL [HAB] address [r0_arg]
*/
......@@ -757,6 +758,105 @@ err:
return ret;
}
static int sb_build_command_fill(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
{
struct sb_section_ctx *sctx = ictx->sect_tail;
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
char *tok;
long address, pattern, length;
int ret;
cctx = calloc(1, sizeof(*cctx));
if (!cctx)
return -ENOMEM;
ccmd = &cctx->payload;
/*
* Prepare the command.
*/
tok = strtok(cmd->cmd, " ");
if (!tok) {
fprintf(stderr, "#%i ERR: Missing FILL address!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
/* Read fill destination address. */
address = sb_token_to_long(tok);
if (address < 0) {
fprintf(stderr, "#%i ERR: Incorrect FILL address!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr, "#%i ERR: Missing FILL pattern!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
/* Read fill pattern address. */
pattern = sb_token_to_long(tok);
if (pattern < 0) {
fprintf(stderr, "#%i ERR: Incorrect FILL pattern!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
tok = strtok(NULL, " ");
if (!tok) {
fprintf(stderr, "#%i ERR: Missing FILL length!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
/* Read fill pattern address. */
length = sb_token_to_long(tok);
if (length < 0) {
fprintf(stderr, "#%i ERR: Incorrect FILL length!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
/*
* Construct the command.
*/
ccmd->header.checksum = 0x5a;
ccmd->header.tag = ROM_FILL_CMD;
ccmd->fill.address = address;
ccmd->fill.count = length;
ccmd->fill.pattern = pattern;
cctx->size = sizeof(*ccmd);
/*
* Append the command to the last section.
*/
if (!sctx->cmd_head) {
sctx->cmd_head = cctx;
sctx->cmd_tail = cctx;
} else {
sctx->cmd_tail->cmd = cctx;
sctx->cmd_tail = cctx;
}
return 0;
err:
free(cctx);
return ret;
}
static int sb_build_command_jump_call(struct sb_image_ctx *ictx,
struct sb_cmd_list *cmd,
unsigned int is_call)
......@@ -1027,6 +1127,8 @@ static int sb_parse_line(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
ret = sb_build_command_tag(ictx, cmd);
else if (!strcmp(tok, "LOAD"))
ret = sb_build_command_load(ictx, cmd);
else if (!strcmp(tok, "FILL"))
ret = sb_build_command_fill(ictx, cmd);
else if (!strcmp(tok, "JUMP"))
ret = sb_build_command_jump(ictx, cmd);
else if (!strcmp(tok, "CALL"))
......
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