Simplify nand indentation.

Removes check covered by new nand_command_get_device_by_num helper.
Reverses logic of probe check to further reduce indentation.
__archive__
Zachary T Welch 2009-11-05 18:40:52 -08:00
parent ff61e6a37c
commit ca00483a95
1 changed files with 320 additions and 347 deletions

View File

@ -1135,10 +1135,12 @@ static int handle_nand_info_command(struct command_context_s *cmd_ctx, char *cmd
break; break;
} }
if (p) if (NULL == p->device)
{
if (p->device)
{ {
command_print(cmd_ctx, "#%s: not probed", args[0]);
return ERROR_OK;
}
if (first >= p->num_blocks) if (first >= p->num_blocks)
first = p->num_blocks - 1; first = p->num_blocks - 1;
@ -1174,12 +1176,6 @@ static int handle_nand_info_command(struct command_context_s *cmd_ctx, char *cmd
erase_state, erase_state,
bad_state); bad_state);
} }
}
else
{
command_print(cmd_ctx, "#%s: not probed", args[0]);
}
}
return ERROR_OK; return ERROR_OK;
} }
@ -1196,8 +1192,6 @@ static int handle_nand_probe_command(struct command_context_s *cmd_ctx, char *cm
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (p)
{
if ((retval = nand_probe(p)) == ERROR_OK) if ((retval = nand_probe(p)) == ERROR_OK)
{ {
command_print(cmd_ctx, "NAND flash device '%s' found", p->device->name); command_print(cmd_ctx, "NAND flash device '%s' found", p->device->name);
@ -1210,7 +1204,6 @@ static int handle_nand_probe_command(struct command_context_s *cmd_ctx, char *cm
{ {
command_print(cmd_ctx, "unknown error when probing NAND flash device"); command_print(cmd_ctx, "unknown error when probing NAND flash device");
} }
}
return ERROR_OK; return ERROR_OK;
} }
@ -1228,8 +1221,6 @@ static int handle_nand_erase_command(struct command_context_s *cmd_ctx, char *cm
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (p)
{
unsigned long offset; unsigned long offset;
unsigned long length; unsigned long length;
@ -1269,7 +1260,6 @@ static int handle_nand_erase_command(struct command_context_s *cmd_ctx, char *cm
{ {
command_print(cmd_ctx, "unknown error when erasing NAND flash device"); command_print(cmd_ctx, "unknown error when erasing NAND flash device");
} }
}
return ERROR_OK; return ERROR_OK;
} }
@ -1353,8 +1343,6 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (p)
{
uint8_t *page = NULL; uint8_t *page = NULL;
uint32_t page_size = 0; uint32_t page_size = 0;
uint8_t *oob = NULL; uint8_t *oob = NULL;
@ -1495,7 +1483,6 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
args[1], args[0], offset, duration_text); args[1], args[0], offset, duration_text);
free(duration_text); free(duration_text);
duration_text = NULL; duration_text = NULL;
}
return ERROR_OK; return ERROR_OK;
} }
@ -1512,14 +1499,15 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (p) if (NULL == p->device)
{
if (p->device)
{ {
command_print(cmd_ctx, "#%s: not probed", args[0]);
return ERROR_OK;
}
fileio_t fileio; fileio_t fileio;
duration_t duration; duration_t duration;
char *duration_text; char *duration_text;
int retval;
uint8_t *page = NULL; uint8_t *page = NULL;
uint32_t page_size = 0; uint32_t page_size = 0;
@ -1612,12 +1600,6 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd
command_print(cmd_ctx, "dumped %lld byte in %s", fileio.size, duration_text); command_print(cmd_ctx, "dumped %lld byte in %s", fileio.size, duration_text);
free(duration_text); free(duration_text);
duration_text = NULL; duration_text = NULL;
}
else
{
command_print(cmd_ctx, "#%s: not probed", args[0]);
}
}
return ERROR_OK; return ERROR_OK;
} }
@ -1634,33 +1616,24 @@ static int handle_nand_raw_access_command(struct command_context_s *cmd_ctx, cha
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (p) if (NULL == p->device)
{
if (p->device)
{ {
command_print(cmd_ctx, "#%s: not probed", args[0]);
return ERROR_OK;
}
if (argc == 2) if (argc == 2)
{ {
if (strcmp("enable", args[1]) == 0) if (strcmp("enable", args[1]) == 0)
{
p->use_raw = 1; p->use_raw = 1;
}
else if (strcmp("disable", args[1]) == 0) else if (strcmp("disable", args[1]) == 0)
{
p->use_raw = 0; p->use_raw = 0;
}
else else
{
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
}
command_print(cmd_ctx, "raw access is %s", (p->use_raw) ? "enabled" : "disabled"); const char *msg = p->use_raw ? "enabled" : "disabled";
} command_print(cmd_ctx, "raw access is %s", msg);
else
{
command_print(cmd_ctx, "#%s: not probed", args[0]);
}
}
return ERROR_OK; return ERROR_OK;
} }