#include "config.h"
#endif
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <inttypes.h>
-
-#include "command.h"
-#include "log.h"
-#include "target.h"
+#include "mflash.h"
#include "time_support.h"
#include "fileio.h"
-#include "mflash.h"
+#include "log.h"
+
static int s3c2440_set_gpio_to_output (mflash_gpio_num_t gpio);
static int s3c2440_set_gpio_output_val (mflash_gpio_num_t gpio, u8 val);
return ret;
}
-static int mflash_rst(u8 level)
+static int mg_hdrst(u8 level)
{
return mflash_bank->gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, level);
}
-static int mflash_init_gpio (void)
+static int mg_init_gpio (void)
{
mflash_gpio_drv_t *gpio_drv = mflash_bank->gpio_drv;
gpio_drv->set_gpio_to_output(mflash_bank->rst_pin);
gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, 1);
- if (mflash_bank->wp_pin.num != -1) {
- gpio_drv->set_gpio_to_output(mflash_bank->wp_pin);
- gpio_drv->set_gpio_output_val(mflash_bank->wp_pin, 1);
- }
-
- if (mflash_bank->dpd_pin.num != -1) {
- gpio_drv->set_gpio_to_output(mflash_bank->dpd_pin);
- gpio_drv->set_gpio_output_val(mflash_bank->dpd_pin, 1);
- }
-
return ERROR_OK;
}
{
mflash_bank->proved = 0;
- mflash_init_gpio();
+ mg_init_gpio();
LOG_INFO("reset mflash");
- mflash_rst(0);
+ mg_hdrst(0);
if (mg_dsk_wait(mg_io_wait_bsy, MG_OEM_DISK_WAIT_TIME_LONG) != ERROR_OK)
return ERROR_FAIL;
- mflash_rst(1);
+ mg_hdrst(1);
if (mg_dsk_wait(mg_io_wait_not_bsy, MG_OEM_DISK_WAIT_TIME_LONG) != ERROR_OK)
return ERROR_FAIL;
return ERROR_OK;
}
-static int mflash_probe_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int mg_probe_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
int ret;
return ERROR_OK;
}
-static int mflash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
u32 address, buf_cnt;
u8 *buffer;
return ERROR_OK;
}
-static int mflash_dump_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
u32 address, size_written, size;
u8 *buffer;
int mflash_init_drivers(struct command_context_s *cmd_ctx)
{
if (mflash_bank) {
- register_command(cmd_ctx, mflash_cmd, "probe", mflash_probe_command, COMMAND_EXEC, NULL);
- register_command(cmd_ctx, mflash_cmd, "write", mflash_write_command, COMMAND_EXEC,
+ register_command(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL);
+ register_command(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC,
"mflash write <num> <file> <address>");
- register_command(cmd_ctx, mflash_cmd, "dump", mflash_dump_command, COMMAND_EXEC,
+ register_command(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC,
"mflash dump <num> <file> <address> <size>");
}
return ERROR_OK;
}
-static int mflash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
target_t *target;
char *str;
int i;
- if (argc < 8)
+ if (argc < 4)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
- if ((target = get_target_by_num(strtoul(args[7], NULL, 0))) == NULL)
+ if ((target = get_target(args[3])) == NULL)
{
- LOG_ERROR("target %lu not defined", strtoul(args[7], NULL, 0));
+ LOG_ERROR("target '%s' not defined", args[3]);
return ERROR_FAIL;
}
mflash_bank = calloc(sizeof(mflash_bank_t), 1);
mflash_bank->base = strtoul(args[1], NULL, 0);
- mflash_bank->chip_width = strtoul(args[2], NULL, 0);
- mflash_bank->bus_width = strtoul(args[3], NULL, 0);
- mflash_bank->rst_pin.num = strtoul(args[4], &str, 0);
+ mflash_bank->rst_pin.num = strtoul(args[2], &str, 0);
if (*str)
mflash_bank->rst_pin.port[0] = (u16)tolower(str[0]);
- mflash_bank->wp_pin.num = strtol(args[5], &str, 0);
- if (*str)
- mflash_bank->wp_pin.port[0] = (u16)tolower(str[0]);
- mflash_bank->dpd_pin.num = strtol(args[6], &str, 0);
- if (*str)
- mflash_bank->dpd_pin.port[0] = (u16)tolower(str[0]);
mflash_bank->target = target;
int mflash_register_commands(struct command_context_s *cmd_ctx)
{
mflash_cmd = register_command(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL);
- register_command(cmd_ctx, mflash_cmd, "bank", mflash_bank_command, COMMAND_CONFIG,
- "mflash bank <soc> <base> <chip_width> <bus_width> <RST pin> <WP pin> <DPD pin> <target #>");
+ register_command(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG,
+ "mflash bank <soc> <base> <RST pin> <target #>");
return ERROR_OK;
}