#include "target.h" less wildly
[fw/openocd] / src / flash / mflash.c
index 5a392a4d64f90217f679ef26983cf0b9b8c0aedb..49dc432f36eb002c7a41c5b384264a1a5c15f23b 100644 (file)
 #endif
 
 #include "mflash.h"
+#include "target.h"
 #include "time_support.h"
 #include "fileio.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, uint8_t val);
-static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio);
-static int pxa270_set_gpio_output_val (mflash_gpio_num_t gpio, uint8_t val);
+static int s3c2440_set_gpio_to_output (struct mflash_gpio_num gpio);
+static int s3c2440_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val);
+static int pxa270_set_gpio_to_output (struct mflash_gpio_num gpio);
+static int pxa270_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val);
 
-static command_t *mflash_cmd;
+static struct command *mflash_cmd;
 
-static mflash_bank_t *mflash_bank;
+static struct mflash_bank *mflash_bank;
 
-static mflash_gpio_drv_t pxa270_gpio = {
+static struct mflash_gpio_drv pxa270_gpio = {
        .name = "pxa270",
        .set_gpio_to_output = pxa270_set_gpio_to_output,
        .set_gpio_output_val = pxa270_set_gpio_output_val
 };
 
-static mflash_gpio_drv_t s3c2440_gpio = {
+static struct mflash_gpio_drv s3c2440_gpio = {
        .name = "s3c2440",
        .set_gpio_to_output = s3c2440_set_gpio_to_output,
        .set_gpio_output_val = s3c2440_set_gpio_output_val
 };
 
-static mflash_gpio_drv_t *mflash_gpio[] =
+static struct mflash_gpio_drv *mflash_gpio[] =
 {
                &pxa270_gpio,
                &s3c2440_gpio,
@@ -64,10 +65,10 @@ static mflash_gpio_drv_t *mflash_gpio[] =
 #define PXA270_GPSR0 0x40E00018
 #define PXA270_GPCR0 0x40E00024
 
-static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
+static int pxa270_set_gpio_to_output (struct mflash_gpio_num gpio)
 {
        uint32_t addr, value, mask;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        int ret;
 
        /* remove alternate function. */
@@ -101,10 +102,10 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
        return ret;
 }
 
-static int pxa270_set_gpio_output_val (mflash_gpio_num_t gpio, uint8_t val)
+static int pxa270_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val)
 {
        uint32_t addr, value, mask;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        int ret;
 
        mask = 0x1u << (gpio.num & 0x1F);
@@ -130,10 +131,10 @@ static int pxa270_set_gpio_output_val (mflash_gpio_num_t gpio, uint8_t val)
 #define S3C2440_GPJCON 0x560000d0
 #define S3C2440_GPJDAT 0x560000d4
 
-static int s3c2440_set_gpio_to_output (mflash_gpio_num_t gpio)
+static int s3c2440_set_gpio_to_output (struct mflash_gpio_num gpio)
 {
        uint32_t data, mask, gpio_con;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        int ret;
 
        if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') {
@@ -162,10 +163,10 @@ static int s3c2440_set_gpio_to_output (mflash_gpio_num_t gpio)
        return ret;
 }
 
-static int s3c2440_set_gpio_output_val (mflash_gpio_num_t gpio, uint8_t val)
+static int s3c2440_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val)
 {
        uint32_t data, mask, gpio_dat;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        int ret;
 
        if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') {
@@ -199,7 +200,7 @@ static int mg_hdrst(uint8_t level)
 static int mg_init_gpio (void)
 {
        int ret;
-       mflash_gpio_drv_t *gpio_drv = mflash_bank->gpio_drv;
+       struct mflash_gpio_drv *gpio_drv = mflash_bank->gpio_drv;
 
        ret = gpio_drv->set_gpio_to_output(mflash_bank->rst_pin);
        if (ret != ERROR_OK)
@@ -213,7 +214,7 @@ static int mg_init_gpio (void)
 static int mg_dsk_wait(mg_io_type_wait wait, uint32_t time)
 {
        uint8_t status, error;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
        int ret;
        long long t = 0;
@@ -291,7 +292,7 @@ static int mg_dsk_wait(mg_io_type_wait wait, uint32_t time)
 
 static int mg_dsk_srst(uint8_t on)
 {
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
        uint8_t value;
        int ret;
@@ -311,7 +312,7 @@ static int mg_dsk_srst(uint8_t on)
 
 static int mg_dsk_io_cmd(uint32_t sect_num, uint32_t cnt, uint8_t cmd)
 {
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
        uint8_t value;
        int ret;
@@ -336,7 +337,7 @@ static int mg_dsk_io_cmd(uint32_t sect_num, uint32_t cnt, uint8_t cmd)
 
 static int mg_dsk_drv_info(void)
 {
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint32_t mg_buff = mflash_bank->base + MG_BUFFER_OFFSET;
        int ret;
 
@@ -349,7 +350,7 @@ static int mg_dsk_drv_info(void)
        LOG_INFO("mflash: read drive info");
 
        if (! mflash_bank->drv_info)
-               mflash_bank->drv_info = malloc(sizeof(mg_drv_info_t));
+               mflash_bank->drv_info = malloc(sizeof(struct mg_drv_info));
 
        target_read_memory(target, mg_buff, 2, sizeof(mg_io_type_drv_info) >> 1,
                        (uint8_t *)&mflash_bank->drv_info->drv_id);
@@ -408,7 +409,7 @@ static int mg_mflash_probe(void)
        return mg_dsk_drv_info();
 }
 
-static int mg_probe_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(mg_probe_cmd)
 {
        int ret;
 
@@ -426,7 +427,7 @@ static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_
 {
        uint32_t i, address;
        int ret;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint8_t *buff_ptr = buff;
 
        if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, mg_io_cmd_read)) != ERROR_OK)
@@ -498,7 +499,7 @@ static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect
 {
        uint32_t i, address;
        int ret;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint8_t *buff_ptr = buff;
 
        if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, cmd)) != ERROR_OK)
@@ -702,11 +703,11 @@ static int mg_mflash_write(uint32_t addr, uint8_t *buff, uint32_t len)
        return ret;
 }
 
-static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(mg_write_cmd)
 {
        uint32_t address, buf_cnt, cnt, res, i;
        uint8_t *buffer;
-       fileio_t fileio;
+       struct fileio fileio;
        int ret;
 
        if (argc != 3) {
@@ -766,11 +767,11 @@ mg_write_cmd_err:
        return ret;
 }
 
-static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(mg_dump_cmd)
 {
        uint32_t address, size_written, size, cnt, res, i;
        uint8_t *buffer;
-       fileio_t fileio;
+       struct fileio fileio;
        int ret;
 
        if (argc != 4) {
@@ -834,7 +835,7 @@ mg_dump_cmd_err:
 
 static int mg_set_feature(mg_feature_id feature, mg_feature_val config)
 {
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
        int ret;
 
@@ -953,7 +954,7 @@ static int mg_verify_interface(void)
        uint16_t buff[MG_MFLASH_SECTOR_SIZE >> 1];
        uint16_t i, j;
        uint32_t address = mflash_bank->base + MG_BUFFER_OFFSET;
-       target_t *target = mflash_bank->target;
+       struct target *target = mflash_bank->target;
        int ret;
 
        for (j = 0; j < 10; j++) {
@@ -1208,8 +1209,7 @@ static int mg_erase_nand(void)
        return ret;
 }
 
-int mg_config_cmd(struct command_context_s *cmd_ctx, char *cmd,
-               char **args, int argc)
+COMMAND_HANDLER(mg_config_cmd)
 {
        double fin, fout;
        mg_pll_t pll;
@@ -1266,7 +1266,7 @@ int mg_config_cmd(struct command_context_s *cmd_ctx, char *cmd,
        }
 }
 
-int mflash_init_drivers(struct command_context_s *cmd_ctx)
+int mflash_init_drivers(struct command_context *cmd_ctx)
 {
        if (mflash_bank) {
                register_command(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL);
@@ -1281,9 +1281,9 @@ int mflash_init_drivers(struct command_context_s *cmd_ctx)
        return ERROR_OK;
 }
 
-static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(mg_bank_cmd)
 {
-       target_t *target;
+       struct target *target;
        int i;
 
        if (argc < 4)
@@ -1297,7 +1297,7 @@ static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
                return ERROR_FAIL;
        }
 
-       mflash_bank = calloc(sizeof(mflash_bank_t), 1);
+       mflash_bank = calloc(sizeof(struct mflash_bank), 1);
        COMMAND_PARSE_NUMBER(u32, args[1], mflash_bank->base);
        /// @todo Verify how this parsing should work, then document it.
        char *str;
@@ -1321,7 +1321,7 @@ static int mg_bank_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
        return ERROR_OK;
 }
 
-int mflash_register_commands(struct command_context_s *cmd_ctx)
+int mflash_register_commands(struct command_context *cmd_ctx)
 {
        mflash_cmd = register_command(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL);
        register_command(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG,