target_t -> struct target
[fw/openocd] / src / flash / lpc2900.c
index 379b4e8731c0f269507fdb5a9fdc9b8004e67d4c..49d02598920221230958443cb6c64bc11617e572 100644 (file)
 /**
  * Private data for \c lpc2900 flash driver.
  */
-typedef struct lpc2900_flash_bank_s
+struct lpc2900_flash_bank
 {
        /**
         * Holds the value read from CHIPID register.
@@ -168,7 +168,7 @@ typedef struct lpc2900_flash_bank_s
         */
        uint32_t max_ram_block;
 
-} lpc2900_flash_bank_t;
+};
 
 
 static uint32_t lpc2900_wait_status(flash_bank_t *bank, uint32_t mask, int timeout);
@@ -199,7 +199,7 @@ static uint32_t lpc2900_wait_status( flash_bank_t *bank,
                                      int timeout )
 {
        uint32_t int_status;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
 
        do
@@ -231,7 +231,7 @@ static uint32_t lpc2900_wait_status( flash_bank_t *bank,
 static void lpc2900_setup( struct flash_bank_s *bank )
 {
        uint32_t fcra;
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
 
        /* Power up the flash block */
@@ -253,7 +253,7 @@ static void lpc2900_setup( struct flash_bank_s *bank )
  */
 static uint32_t lpc2900_is_ready( struct flash_bank_s *bank )
 {
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
        if( lpc2900_info->chipid != EXPECTED_CHIPID )
        {
@@ -283,7 +283,7 @@ static uint32_t lpc2900_read_security_status( struct flash_bank_s *bank )
                return status;
        }
 
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        /* Enable ISS access */
        target_write_u32(target, FCTR, FCTR_FS_CS | FCTR_FS_WEB | FCTR_FS_ISS);
@@ -361,7 +361,7 @@ static uint32_t lpc2900_run_bist128(struct flash_bank_s *bank,
                                     uint32_t addr_to,
                                     uint32_t (*signature)[4] )
 {
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        /* Clear END_OF_MISR interrupt status */
        target_write_u32( target, INT_CLR_STATUS, INTSRC_END_OF_MISR );
@@ -436,7 +436,7 @@ static int lpc2900_write_index_page( struct flash_bank_s *bank,
        }
 
        /* Get target, and check if it's halted */
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        if( target->state != TARGET_HALTED )
        {
                LOG_ERROR( "Target not halted" );
@@ -444,7 +444,7 @@ static int lpc2900_write_index_page( struct flash_bank_s *bank,
        }
 
        /* Private info */
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
        /* Enable flash block and set the correct CRA clock of 66 kHz */
        lpc2900_setup( bank );
@@ -531,8 +531,7 @@ static uint32_t lpc2900_calc_tr( uint32_t clock, uint32_t time )
  * Uses the Built-In-Self-Test (BIST) to generate a 128-bit hash value
  * of the flash content.
  */
-static int lpc2900_handle_signature_command( struct command_context_s *cmd_ctx,
-                                             char *cmd, char **args, int argc )
+COMMAND_HANDLER(lpc2900_handle_signature_command)
 {
        uint32_t status;
        uint32_t signature[4];
@@ -582,8 +581,7 @@ static int lpc2900_handle_signature_command( struct command_context_s *cmd_ctx,
  * Read customer info from index sector, and store that block of data into
  * a disk file. The format is binary.
  */
-static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx,
-                                               char *cmd, char **args, int argc )
+COMMAND_HANDLER(lpc2900_handle_read_custom_command)
 {
        if( argc < 2 )
        {
@@ -595,11 +593,11 @@ static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx
        if (ERROR_OK != retval)
                return retval;
 
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
        lpc2900_info->risky = 0;
 
        /* Get target, and check if it's halted */
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        if( target->state != TARGET_HALTED )
        {
                LOG_ERROR( "Target not halted" );
@@ -624,7 +622,7 @@ static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx
        target_write_u32( target, FCTR, FCTR_FS_CS | FCTR_FS_WEB );
 
        /* Try and open the file */
-       fileio_t fileio;
+       struct fileio fileio;
        const char *filename = args[1];
        int ret = fileio_open( &fileio, filename, FILEIO_WRITE, FILEIO_BINARY );
        if( ret != ERROR_OK )
@@ -654,8 +652,7 @@ static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx
 /**
  * Enter password to enable potentially dangerous options.
  */
-static int lpc2900_handle_password_command(struct command_context_s *cmd_ctx,
-                                           char *cmd, char **args, int argc)
+COMMAND_HANDLER(lpc2900_handle_password_command)
 {
        if (argc < 2)
        {
@@ -667,7 +664,7 @@ static int lpc2900_handle_password_command(struct command_context_s *cmd_ctx,
        if (ERROR_OK != retval)
                return retval;
 
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
 #define ISS_PASSWORD "I_know_what_I_am_doing"
 
@@ -690,8 +687,7 @@ static int lpc2900_handle_password_command(struct command_context_s *cmd_ctx,
 /**
  * Write customer info from file to the index sector.
  */
-static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ctx,
-                                                char *cmd, char **args, int argc )
+COMMAND_HANDLER(lpc2900_handle_write_custom_command)
 {
        if (argc < 2)
        {
@@ -703,7 +699,7 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
        if (ERROR_OK != retval)
                return retval;
 
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
        if( !lpc2900_info->risky )
@@ -714,7 +710,7 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
        lpc2900_info->risky = 0;
 
        /* Get target, and check if it's halted */
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        if (target->state != TARGET_HALTED)
        {
                LOG_ERROR("Target not halted");
@@ -722,7 +718,7 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
        }
 
        /* The image will always start at offset 0 */
-       image_t image;
+       struct image image;
        image.base_address_set = 1;
        image.base_address = 0;
        image.start_address_set = 0;
@@ -801,8 +797,7 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
 /**
  * Activate 'sector security' for a range of sectors.
  */
-static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ctx,
-                                                char *cmd, char **args, int argc)
+COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
 {
        if (argc < 3)
        {
@@ -815,7 +810,7 @@ static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ct
        if (ERROR_OK != retval)
                return retval;
 
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
        if( !lpc2900_info->risky )
@@ -901,8 +896,7 @@ static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ct
 /**
  * Activate JTAG protection.
  */
-static int lpc2900_handle_secure_jtag_command(struct command_context_s *cmd_ctx,
-                                              char *cmd, char **args, int argc)
+COMMAND_HANDLER(lpc2900_handle_secure_jtag_command)
 {
        if (argc < 1)
        {
@@ -915,7 +909,7 @@ static int lpc2900_handle_secure_jtag_command(struct command_context_s *cmd_ctx,
        if (ERROR_OK != retval)
                return retval;
 
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
        if( !lpc2900_info->risky )
@@ -1022,11 +1016,9 @@ static int lpc2900_register_commands(struct command_context_s *cmd_ctx)
 
 
 /// Evaluate flash bank command.
-static int lpc2900_flash_bank_command(struct command_context_s *cmd_ctx,
-                                      char *cmd, char **args, int argc,
-                                      struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command)
 {
-       lpc2900_flash_bank_t *lpc2900_info;
+       struct lpc2900_flash_bank *lpc2900_info;
 
        if (argc < 6)
        {
@@ -1034,7 +1026,7 @@ static int lpc2900_flash_bank_command(struct command_context_s *cmd_ctx,
                return ERROR_FLASH_BANK_INVALID;
        }
 
-       lpc2900_info = malloc(sizeof(lpc2900_flash_bank_t));
+       lpc2900_info = malloc(sizeof(struct lpc2900_flash_bank));
        bank->driver_priv = lpc2900_info;
 
        /* Get flash clock.
@@ -1083,8 +1075,8 @@ static int lpc2900_erase(struct flash_bank_s *bank, int first, int last)
        uint32_t status;
        int sector;
        int last_unsecured_sector;
-       target_t *target = bank->target;
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct target *target = bank->target;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
 
        status = lpc2900_is_ready(bank);
@@ -1213,8 +1205,8 @@ static int lpc2900_write(struct flash_bank_s *bank, uint8_t *buffer,
        uint8_t page[FLASH_PAGE_SIZE];
        uint32_t status;
        uint32_t num_bytes;
-       target_t *target = bank->target;
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
+       struct target *target = bank->target;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
        int sector;
        int retval;
 
@@ -1302,7 +1294,7 @@ static int lpc2900_write(struct flash_bank_s *bank, uint8_t *buffer,
 
        /* Try working area allocation. Start with a large buffer, and try with
           reduced size if that fails. */
-       working_area_t *warea;
+       struct working_area *warea;
        uint32_t buffer_size = lpc2900_info->max_ram_block - 1 * KiB;
        while( (retval = target_alloc_working_area(target,
                                                   buffer_size + target_code_size,
@@ -1321,8 +1313,8 @@ static int lpc2900_write(struct flash_bank_s *bank, uint8_t *buffer,
 
        if( warea )
        {
-               reg_param_t reg_params[5];
-               armv4_5_algorithm_t armv4_5_info;
+               struct reg_param reg_params[5];
+               struct armv4_5_algorithm armv4_5_info;
 
                /* We can use target mode. Download the algorithm. */
                retval = target_write_buffer( target,
@@ -1558,8 +1550,8 @@ static int lpc2900_write(struct flash_bank_s *bank, uint8_t *buffer,
  */
 static int lpc2900_probe(struct flash_bank_s *bank)
 {
-       lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
+       struct target *target = bank->target;
        int i = 0;
        uint32_t offset;
 
@@ -1710,7 +1702,7 @@ static int lpc2900_probe(struct flash_bank_s *bank)
         * the logical flash number are translated into the physical flash numbers
         * of the device.
         */
-       bank->sectors = malloc(sizeof(flash_sector_t) * bank->num_sectors);
+       bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
 
        offset = 0;
        for (i = 0; i < bank->num_sectors; i++)
@@ -1838,7 +1830,7 @@ static int lpc2900_info(struct flash_bank_s *bank, char *buf, int buf_size)
 }
 
 
-flash_driver_t lpc2900_flash =
+struct flash_driver lpc2900_flash =
 {
        .name               = "lpc2900",
        .register_commands  = lpc2900_register_commands,