Browse Source

- convert all files to unix line-ending

git-svn-id: svn://svn.berlios.de/openocd/trunk@347 b42882b7-edfa-0310-969c-e2dbd0fdcd60
tags/v0.1.0
drath 16 years ago
parent
commit
3d6bcf0792
42 changed files with 32837 additions and 32837 deletions
  1. +100
    -100
      src/flash/at91sam7.h
  2. +2355
    -2355
      src/flash/cfi.c
  3. +179
    -179
      src/flash/s3c2440_nand.c
  4. +1348
    -1348
      src/flash/str9xpec.c
  5. +607
    -607
      src/helper/command.c
  6. +104
    -104
      src/helper/configuration.c
  7. +248
    -248
      src/helper/log.c
  8. +113
    -113
      src/helper/log.h
  9. +153
    -153
      src/helper/options.c
  10. +29
    -29
      src/helper/replacements.h
  11. +366
    -366
      src/jtag/bitq.c
  12. +237
    -237
      src/jtag/ep93xx.c
  13. +2139
    -2139
      src/jtag/ft2232.c
  14. +1841
    -1841
      src/jtag/jtag.c
  15. +681
    -681
      src/jtag/usbprog.c
  16. +157
    -157
      src/openocd.c
  17. +264
    -264
      src/pld/virtex2.c
  18. +2107
    -2107
      src/server/gdb_server.c
  19. +450
    -450
      src/server/server.c
  20. +631
    -631
      src/server/telnet_server.c
  21. +1358
    -1358
      src/target/arm11.c
  22. +250
    -250
      src/target/arm11.h
  23. +611
    -611
      src/target/arm11_dbgtap.c
  24. +626
    -626
      src/target/arm720t.c
  25. +9
    -9
      src/target/arm7_9_common.c
  26. +874
    -874
      src/target/arm7tdmi.c
  27. +1485
    -1485
      src/target/arm920t.c
  28. +944
    -944
      src/target/arm926ejs.c
  29. +364
    -364
      src/target/arm966e.c
  30. +1105
    -1105
      src/target/arm9tdmi.c
  31. +207
    -207
      src/target/arm_jtag.c
  32. +708
    -708
      src/target/cortex_swjdp.c
  33. +565
    -565
      src/target/embeddedice.c
  34. +741
    -741
      src/target/etb.c
  35. +75
    -75
      src/target/etb.h
  36. +1863
    -1863
      src/target/etm.c
  37. +214
    -214
      src/target/etm.h
  38. +33
    -33
      src/target/etm_dummy.h
  39. +64
    -64
      src/target/oocd_trace.h
  40. +2332
    -2332
      src/target/target.c
  41. +3799
    -3799
      src/target/xscale.c
  42. +501
    -501
      src/xsvf/xsvf.c

+ 100
- 100
src/flash/at91sam7.h View File

@@ -1,100 +1,100 @@
/***************************************************************************
* Copyright (C) 2006 by Magnus Lundin *
* lundin@mlu.mine.nu *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef AT91SAM7_H
#define AT91SAM7_H
#include "flash.h"
#include "target.h"
typedef struct at91sam7_flash_bank_s
{
u32 working_area;
u32 working_area_size;
/* chip id register */
u32 cidr;
u16 cidr_ext;
u16 cidr_nvptyp;
u16 cidr_arch;
u16 cidr_sramsiz;
u16 cidr_nvpsiz;
u16 cidr_nvpsiz2;
u16 cidr_eproc;
u16 cidr_version;
char * target_name;
/* flash geometry */
u16 num_pages;
u16 pagesize;
u16 pages_in_lockregion;
u8 num_erase_regions;
u8 num_planes;
u32 *erase_region_info;
/* nv memory bits */
u16 num_lockbits;
u16 lockbits[4];
u16 num_nvmbits;
u16 nvmbits;
u8 securitybit;
u8 flashmode[4]; /* 0: not init, 1: fmcn for nvbits (1uS), 2: fmcn for flash (1.5uS) */
/* main clock status */
u8 mck_valid;
u32 mck_freq;
int probed;
} at91sam7_flash_bank_t;
/* AT91SAM7 control registers */
#define DBGU_CIDR 0xFFFFF240
#define CKGR_MCFR 0xFFFFFC24
#define CKGR_MCFR_MAINRDY 0x10000
#define CKGR_PLLR 0xFFFFFC2c
#define CKGR_PLLR_DIV 0xff
#define CKGR_PLLR_MUL 0x07ff0000
#define PMC_MCKR 0xFFFFFC30
#define PMC_MCKR_CSS 0x03
#define PMC_MCKR_PRES 0x1c
/* Flash Controller Commands */
#define WP 0x01
#define SLB 0x02
#define WPL 0x03
#define CLB 0x04
#define EA 0x08
#define SGPB 0x0B
#define CGPB 0x0D
#define SSB 0x0F
/* MC_FSR bit definitions */
#define MC_FSR_FRDY 1
#define MC_FSR_EOL 2
/* AT91SAM7 constants */
#define RC_FREQ 32000
/* FLASH_TIMING_MODES */
#define FMR_TIMING_NONE 0
#define FMR_TIMING_NVBITS 1
#define FMR_TIMING_FLASH 2
#endif /* AT91SAM7_H */
/***************************************************************************
* Copyright (C) 2006 by Magnus Lundin *
* lundin@mlu.mine.nu *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef AT91SAM7_H
#define AT91SAM7_H
#include "flash.h"
#include "target.h"
typedef struct at91sam7_flash_bank_s
{
u32 working_area;
u32 working_area_size;
/* chip id register */
u32 cidr;
u16 cidr_ext;
u16 cidr_nvptyp;
u16 cidr_arch;
u16 cidr_sramsiz;
u16 cidr_nvpsiz;
u16 cidr_nvpsiz2;
u16 cidr_eproc;
u16 cidr_version;
char * target_name;
/* flash geometry */
u16 num_pages;
u16 pagesize;
u16 pages_in_lockregion;
u8 num_erase_regions;
u8 num_planes;
u32 *erase_region_info;
/* nv memory bits */
u16 num_lockbits;
u16 lockbits[4];
u16 num_nvmbits;
u16 nvmbits;
u8 securitybit;
u8 flashmode[4]; /* 0: not init, 1: fmcn for nvbits (1uS), 2: fmcn for flash (1.5uS) */
/* main clock status */
u8 mck_valid;
u32 mck_freq;
int probed;
} at91sam7_flash_bank_t;
/* AT91SAM7 control registers */
#define DBGU_CIDR 0xFFFFF240
#define CKGR_MCFR 0xFFFFFC24
#define CKGR_MCFR_MAINRDY 0x10000
#define CKGR_PLLR 0xFFFFFC2c
#define CKGR_PLLR_DIV 0xff
#define CKGR_PLLR_MUL 0x07ff0000
#define PMC_MCKR 0xFFFFFC30
#define PMC_MCKR_CSS 0x03
#define PMC_MCKR_PRES 0x1c
/* Flash Controller Commands */
#define WP 0x01
#define SLB 0x02
#define WPL 0x03
#define CLB 0x04
#define EA 0x08
#define SGPB 0x0B
#define CGPB 0x0D
#define SSB 0x0F
/* MC_FSR bit definitions */
#define MC_FSR_FRDY 1
#define MC_FSR_EOL 2
/* AT91SAM7 constants */
#define RC_FREQ 32000
/* FLASH_TIMING_MODES */
#define FMR_TIMING_NONE 0
#define FMR_TIMING_NVBITS 1
#define FMR_TIMING_FLASH 2
#endif /* AT91SAM7_H */

+ 2355
- 2355
src/flash/cfi.c
File diff suppressed because it is too large
View File


+ 179
- 179
src/flash/s3c2440_nand.c View File

@@ -1,179 +1,179 @@
/* src/flash/s3c2440_nand.c
*
* S3C2440 OpenOCD NAND Flash controller support.
*
* Copyright 2007,2008 Ben Dooks <ben@fluff.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Many thanks to Simtec Electronics for sponsoring this work.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "replacements.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
#include "nand.h"
#include "s3c24xx_nand.h"
#include "target.h"
int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device);
int s3c2440_init(struct nand_device_s *device);
int s3c2440_nand_ready(struct nand_device_s *device, int timeout);
nand_flash_controller_t s3c2440_nand_controller =
{
.name = "s3c2440",
.nand_device_command = s3c2440_nand_device_command,
.register_commands = s3c24xx_register_commands,
.init = s3c2440_init,
.reset = s3c24xx_reset,
.command = s3c24xx_command,
.address = s3c24xx_address,
.write_data = s3c24xx_write_data,
.read_data = s3c24xx_read_data,
.write_page = s3c24xx_write_page,
.read_page = s3c24xx_read_page,
.write_block_data = s3c2440_write_block_data,
.read_block_data = s3c2440_read_block_data,
.controller_ready = s3c24xx_controller_ready,
.nand_ready = s3c2440_nand_ready,
};
int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc,
struct nand_device_s *device)
{
s3c24xx_nand_controller_t *info;
info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, device);
if (info == NULL) {
return ERROR_NAND_DEVICE_INVALID;
}
/* fill in the address fields for the core device */
info->cmd = S3C2440_NFCMD;
info->addr = S3C2440_NFADDR;
info->data = S3C2440_NFDATA;
info->nfstat = S3C2440_NFSTAT;
return ERROR_OK;
}
int s3c2440_init(struct nand_device_s *device)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 version;
target_write_u32(target, S3C2410_NFCONF,
S3C2440_NFCONF_TACLS(3) |
S3C2440_NFCONF_TWRPH0(7) |
S3C2440_NFCONF_TWRPH1(7));
target_write_u32(target, S3C2440_NFCONT,
S3C2440_NFCONT_INITECC | S3C2440_NFCONT_ENABLE);
return ERROR_OK;
}
int s3c2440_nand_ready(struct nand_device_s *device, int timeout)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u8 status;
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
do {
target_read_u8(target, s3c24xx_info->nfstat, &status);
if (status & S3C2440_NFSTAT_READY)
return 1;
usleep(1000);
} while (timeout-- > 0);
return 0;
}
/* use the fact we can read/write 4 bytes in one go via a single 32bit op */
int s3c2440_read_block_data(struct nand_device_s *device, u8 *data, int data_size)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 nfdata = s3c24xx_info->data;
u32 tmp;
INFO("%s: reading data: %p, %p, %d\n", __func__, device, data, data_size);
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
while (data_size >= 4) {
target_read_u32(target, nfdata, &tmp);
data[0] = tmp;
data[1] = tmp >> 8;
data[2] = tmp >> 16;
data[3] = tmp >> 24;
data_size -= 4;
data += 4;
}
while (data_size > 0) {
target_read_u8(target, nfdata, data);
data_size -= 1;
data += 1;
}
return ERROR_OK;
}
int s3c2440_write_block_data(struct nand_device_s *device, u8 *data, int data_size)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 nfdata = s3c24xx_info->data;
u32 tmp;
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
while (data_size >= 4) {
tmp = le_to_h_u32(data);
target_write_u32(target, nfdata, tmp);
data_size -= 4;
data += 4;
}
while (data_size > 0) {
target_write_u8(target, nfdata, *data);
data_size -= 1;
data += 1;
}
return ERROR_OK;
}
/* src/flash/s3c2440_nand.c
*
* S3C2440 OpenOCD NAND Flash controller support.
*
* Copyright 2007,2008 Ben Dooks <ben@fluff.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Many thanks to Simtec Electronics for sponsoring this work.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "replacements.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
#include "nand.h"
#include "s3c24xx_nand.h"
#include "target.h"
int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device);
int s3c2440_init(struct nand_device_s *device);
int s3c2440_nand_ready(struct nand_device_s *device, int timeout);
nand_flash_controller_t s3c2440_nand_controller =
{
.name = "s3c2440",
.nand_device_command = s3c2440_nand_device_command,
.register_commands = s3c24xx_register_commands,
.init = s3c2440_init,
.reset = s3c24xx_reset,
.command = s3c24xx_command,
.address = s3c24xx_address,
.write_data = s3c24xx_write_data,
.read_data = s3c24xx_read_data,
.write_page = s3c24xx_write_page,
.read_page = s3c24xx_read_page,
.write_block_data = s3c2440_write_block_data,
.read_block_data = s3c2440_read_block_data,
.controller_ready = s3c24xx_controller_ready,
.nand_ready = s3c2440_nand_ready,
};
int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc,
struct nand_device_s *device)
{
s3c24xx_nand_controller_t *info;
info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, device);
if (info == NULL) {
return ERROR_NAND_DEVICE_INVALID;
}
/* fill in the address fields for the core device */
info->cmd = S3C2440_NFCMD;
info->addr = S3C2440_NFADDR;
info->data = S3C2440_NFDATA;
info->nfstat = S3C2440_NFSTAT;
return ERROR_OK;
}
int s3c2440_init(struct nand_device_s *device)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 version;
target_write_u32(target, S3C2410_NFCONF,
S3C2440_NFCONF_TACLS(3) |
S3C2440_NFCONF_TWRPH0(7) |
S3C2440_NFCONF_TWRPH1(7));
target_write_u32(target, S3C2440_NFCONT,
S3C2440_NFCONT_INITECC | S3C2440_NFCONT_ENABLE);
return ERROR_OK;
}
int s3c2440_nand_ready(struct nand_device_s *device, int timeout)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u8 status;
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
do {
target_read_u8(target, s3c24xx_info->nfstat, &status);
if (status & S3C2440_NFSTAT_READY)
return 1;
usleep(1000);
} while (timeout-- > 0);
return 0;
}
/* use the fact we can read/write 4 bytes in one go via a single 32bit op */
int s3c2440_read_block_data(struct nand_device_s *device, u8 *data, int data_size)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 nfdata = s3c24xx_info->data;
u32 tmp;
INFO("%s: reading data: %p, %p, %d\n", __func__, device, data, data_size);
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
while (data_size >= 4) {
target_read_u32(target, nfdata, &tmp);
data[0] = tmp;
data[1] = tmp >> 8;
data[2] = tmp >> 16;
data[3] = tmp >> 24;
data_size -= 4;
data += 4;
}
while (data_size > 0) {
target_read_u8(target, nfdata, data);
data_size -= 1;
data += 1;
}
return ERROR_OK;
}
int s3c2440_write_block_data(struct nand_device_s *device, u8 *data, int data_size)
{
s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
target_t *target = s3c24xx_info->target;
u32 nfdata = s3c24xx_info->data;
u32 tmp;
if (target->state != TARGET_HALTED) {
ERROR("target must be halted to use S3C24XX NAND flash controller");
return ERROR_NAND_OPERATION_FAILED;
}
while (data_size >= 4) {
tmp = le_to_h_u32(data);
target_write_u32(target, nfdata, tmp);
data_size -= 4;
data += 4;
}
while (data_size > 0) {
target_write_u8(target, nfdata, *data);
data_size -= 1;
data += 1;
}
return ERROR_OK;
}

+ 1348
- 1348
src/flash/str9xpec.c
File diff suppressed because it is too large
View File


+ 607
- 607
src/helper/command.c
File diff suppressed because it is too large
View File


+ 104
- 104
src/helper/configuration.c View File

@@ -1,104 +1,104 @@
/***************************************************************************
* Copyright (C) 2004, 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "types.h"
#include "command.h"
#include "configuration.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static size_t num_config_files;
static char** config_file_names;
static size_t num_script_dirs;
static char** script_search_dirs;
void add_script_search_dir (const char *dir)
{
num_script_dirs++;
script_search_dirs = (char **)realloc(script_search_dirs, (num_script_dirs+1) * sizeof (char *));
script_search_dirs[num_script_dirs-1] = strdup(dir);
script_search_dirs[num_script_dirs] = NULL;
}
void add_config_file_name (const char *cfg)
{
num_config_files++;
config_file_names = (char **)realloc(config_file_names, (num_config_files+1) * sizeof (char *));
config_file_names[num_config_files-1] = strdup(cfg);
config_file_names[num_config_files] = NULL;
}
FILE *open_file_from_path (command_context_t *cmd_ctx, char *file, char *mode)
{
FILE *fp = NULL;
char **search_dirs = script_search_dirs;
char *dir;
char full_path[1024];
/* Check absolute and relative to current working dir first.
* This keeps full_path reporting belowing working. */
snprintf(full_path, 1024, "%s", file);
fp = fopen(full_path, mode);
while (!fp)
{
dir = *search_dirs++;
if (!dir)
break;
snprintf(full_path, 1024, "%s/%s", dir, file);
fp = fopen(full_path, mode);
}
if (fp)
command_print(cmd_ctx, "opened %s", full_path);
return fp;
}
int parse_config_file(struct command_context_s *cmd_ctx)
{
char **cfg;
FILE *config_file;
if (!config_file_names)
add_config_file_name ("script openocd.cfg");
cfg = config_file_names;
while (*cfg)
{
command_run_line(cmd_ctx, *cfg);
cfg++;
}
return ERROR_OK;
}
/***************************************************************************
* Copyright (C) 2004, 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "types.h"
#include "command.h"
#include "configuration.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static size_t num_config_files;
static char** config_file_names;
static size_t num_script_dirs;
static char** script_search_dirs;
void add_script_search_dir (const char *dir)
{
num_script_dirs++;
script_search_dirs = (char **)realloc(script_search_dirs, (num_script_dirs+1) * sizeof (char *));
script_search_dirs[num_script_dirs-1] = strdup(dir);
script_search_dirs[num_script_dirs] = NULL;
}
void add_config_file_name (const char *cfg)
{
num_config_files++;
config_file_names = (char **)realloc(config_file_names, (num_config_files+1) * sizeof (char *));
config_file_names[num_config_files-1] = strdup(cfg);
config_file_names[num_config_files] = NULL;
}
FILE *open_file_from_path (command_context_t *cmd_ctx, char *file, char *mode)
{
FILE *fp = NULL;
char **search_dirs = script_search_dirs;
char *dir;
char full_path[1024];
/* Check absolute and relative to current working dir first.
* This keeps full_path reporting belowing working. */
snprintf(full_path, 1024, "%s", file);
fp = fopen(full_path, mode);
while (!fp)
{
dir = *search_dirs++;
if (!dir)
break;
snprintf(full_path, 1024, "%s/%s", dir, file);
fp = fopen(full_path, mode);
}
if (fp)
command_print(cmd_ctx, "opened %s", full_path);
return fp;
}
int parse_config_file(struct command_context_s *cmd_ctx)
{
char **cfg;
FILE *config_file;
if (!config_file_names)
add_config_file_name ("script openocd.cfg");
cfg = config_file_names;
while (*cfg)
{
command_run_line(cmd_ctx, *cfg);
cfg++;
}
return ERROR_OK;
}

+ 248
- 248
src/helper/log.c View File

@@ -1,248 +1,248 @@
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "log.h"
#include "configuration.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
int debug_level = -1;
static FILE* log_output;
static log_callback_t *log_callbacks = NULL;
static time_t start;
static char *log_strings[5] =
{
"User: ",
"Error: ",
"Warning:",
"Info: ",
"Debug: "
};
void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
{
static int count = 0;
count++;
va_list args;
char buffer[512];
log_callback_t *cb;
if (level > debug_level)
return;
va_start(args, format);
vsnprintf(buffer, 512, format, args);
va_end(args);
if (level == LOG_OUTPUT)
{
/* do not prepend any headers, just print out what we were given and return */
fputs(buffer, log_output);
fflush(log_output);
return;
}
char *f = strrchr(file, '/');
if (f != NULL)
file = f + 1;
if (debug_level >= LOG_DEBUG)
{
/* print with count and time information */
time_t t=time(NULL)-start;
fprintf(log_output, "%s %d %ld %s:%d %s(): %s\n", log_strings[level+1], count, t, file, line, function, buffer);
}
else
{
/* do not print count and time */
fprintf(log_output, "%s %s:%d %s(): %s\n", log_strings[level+1], file, line, function, buffer);
}
fflush(log_output);
/* Never forward LOG_DEBUG, too verbose and they can be found in the log if need be */
if (level <= LOG_INFO)
{
for (cb = log_callbacks; cb; cb = cb->next)
{
va_start(args, format);
cb->fn(cb->priv, file, line, function, format, args);
va_end(args);
}
}
}
/* change the current debug level on the fly
* 0: only ERRORS
* 1: + WARNINGS
* 2: + INFORMATIONAL MSGS
* 3: + DEBUG MSGS
*/
int handle_debug_level_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc == 0)
command_print(cmd_ctx, "debug_level: %i", debug_level);
if (argc > 0)
debug_level = strtoul(args[0], NULL, 0);
if (debug_level < 0)
debug_level = 0;
if (debug_level > 3)
debug_level = 3;
return ERROR_OK;
}
int handle_log_output_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc == 1)
{
FILE* file = fopen(args[0], "w");
if (file)
{
log_output = file;
}
}
return ERROR_OK;
}
int log_register_commands(struct command_context_s *cmd_ctx)
{
start = time(NULL);
register_command(cmd_ctx, NULL, "log_output", handle_log_output_command,
COMMAND_ANY, "redirect logging to <file> (default: stderr)");
register_command(cmd_ctx, NULL, "debug_level", handle_debug_level_command,
COMMAND_ANY, "adjust debug level <0-3>");
return ERROR_OK;
}
int log_init(struct command_context_s *cmd_ctx)
{
/* set defaults for daemon configuration, if not set by cmdline or cfgfile */
if (debug_level == -1)
debug_level = LOG_INFO;
if (log_output == NULL)
{
log_output = stderr;
}
return ERROR_OK;
}
int set_log_output(struct command_context_s *cmd_ctx, FILE *output)
{
log_output = output;
return ERROR_OK;
}
/* add/remove log callback handler */
int log_add_callback(log_callback_fn fn, void *priv)
{
log_callback_t *cb;
/* prevent the same callback to be registered more than once, just for sure */
for (cb = log_callbacks; cb; cb = cb->next)
{
if (cb->fn == fn && cb->priv == priv)
return ERROR_INVALID_ARGUMENTS;
}
/* alloc memory, it is safe just to return in case of an error, no need for the caller to check this */
if ((cb = malloc(sizeof(log_callback_t))) == NULL)
return ERROR_BUF_TOO_SMALL;
/* add item to the beginning of the linked list */
cb->fn = fn;
cb->priv = priv;
cb->next = log_callbacks;
log_callbacks = cb;
return ERROR_OK;
}
int log_remove_callback(log_callback_fn fn, void *priv)
{
log_callback_t *cb, **p;
for (p = &log_callbacks; cb = *p; p = &(*p)->next)
{
if (cb->fn == fn && cb->priv == priv)
{
*p = cb->next;
free(cb);
return ERROR_OK;
}
}
/* no such item */
return ERROR_INVALID_ARGUMENTS;
}
/* return allocated string w/printf() result */
char *alloc_printf(const char *fmt, va_list ap)
{
char *string = NULL;
/* start by 0 to exercise all the code paths. Need minimum 2 bytes to
* fit 1 char and 0 terminator. */
int size = 0;
int first = 1;
for (;;)
{
if ((string == NULL) || (!first))
{
size = size * 2 + 2;
char *t = string;
string = realloc(string, size);
if (string == NULL)
{
if (t != NULL)
free(t);
return NULL;
}
}
int ret;
ret = vsnprintf(string, size, fmt, ap);
/* NB! The result of the vsnprintf() might be an *EMPTY* string! */
if ((ret >= 0) && ((ret + 1) < size))
{
return string;
}
/* there was just enough or not enough space, allocate more. */
first = 0;
}
}
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "log.h"
#include "configuration.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
int debug_level = -1;
static FILE* log_output;
static log_callback_t *log_callbacks = NULL;
static time_t start;
static char *log_strings[5] =
{
"User: ",
"Error: ",
"Warning:",
"Info: ",
"Debug: "
};
void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
{
static int count = 0;
count++;
va_list args;
char buffer[512];
log_callback_t *cb;
if (level > debug_level)
return;
va_start(args, format);
vsnprintf(buffer, 512, format, args);
va_end(args);
if (level == LOG_OUTPUT)
{
/* do not prepend any headers, just print out what we were given and return */
fputs(buffer, log_output);
fflush(log_output);
return;
}
char *f = strrchr(file, '/');
if (f != NULL)
file = f + 1;
if (debug_level >= LOG_DEBUG)
{
/* print with count and time information */
time_t t=time(NULL)-start;
fprintf(log_output, "%s %d %ld %s:%d %s(): %s\n", log_strings[level+1], count, t, file, line, function, buffer);
}
else
{
/* do not print count and time */
fprintf(log_output, "%s %s:%d %s(): %s\n", log_strings[level+1], file, line, function, buffer);
}
fflush(log_output);
/* Never forward LOG_DEBUG, too verbose and they can be found in the log if need be */
if (level <= LOG_INFO)
{
for (cb = log_callbacks; cb; cb = cb->next)
{
va_start(args, format);
cb->fn(cb->priv, file, line, function, format, args);
va_end(args);
}
}
}
/* change the current debug level on the fly
* 0: only ERRORS
* 1: + WARNINGS
* 2: + INFORMATIONAL MSGS
* 3: + DEBUG MSGS
*/
int handle_debug_level_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc == 0)
command_print(cmd_ctx, "debug_level: %i", debug_level);
if (argc > 0)
debug_level = strtoul(args[0], NULL, 0);
if (debug_level < 0)
debug_level = 0;
if (debug_level > 3)
debug_level = 3;
return ERROR_OK;
}
int handle_log_output_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc == 1)
{
FILE* file = fopen(args[0], "w");
if (file)
{
log_output = file;
}
}
return ERROR_OK;
}
int log_register_commands(struct command_context_s *cmd_ctx)
{
start = time(NULL);
register_command(cmd_ctx, NULL, "log_output", handle_log_output_command,
COMMAND_ANY, "redirect logging to <file> (default: stderr)");
register_command(cmd_ctx, NULL, "debug_level", handle_debug_level_command,
COMMAND_ANY, "adjust debug level <0-3>");
return ERROR_OK;
}
int log_init(struct command_context_s *cmd_ctx)
{
/* set defaults for daemon configuration, if not set by cmdline or cfgfile */
if (debug_level == -1)
debug_level = LOG_INFO;
if (log_output == NULL)
{
log_output = stderr;
}
return ERROR_OK;
}
int set_log_output(struct command_context_s *cmd_ctx, FILE *output)
{
log_output = output;
return ERROR_OK;
}
/* add/remove log callback handler */
int log_add_callback(log_callback_fn fn, void *priv)
{
log_callback_t *cb;
/* prevent the same callback to be registered more than once, just for sure */
for (cb = log_callbacks; cb; cb = cb->next)
{
if (cb->fn == fn && cb->priv == priv)
return ERROR_INVALID_ARGUMENTS;
}
/* alloc memory, it is safe just to return in case of an error, no need for the caller to check this */
if ((cb = malloc(sizeof(log_callback_t))) == NULL)
return ERROR_BUF_TOO_SMALL;
/* add item to the beginning of the linked list */
cb->fn = fn;
cb->priv = priv;
cb->next = log_callbacks;
log_callbacks = cb;
return ERROR_OK;
}
int log_remove_callback(log_callback_fn fn, void *priv)
{
log_callback_t *cb, **p;
for (p = &log_callbacks; cb = *p; p = &(*p)->next)
{
if (cb->fn == fn && cb->priv == priv)
{
*p = cb->next;
free(cb);
return ERROR_OK;
}
}
/* no such item */
return ERROR_INVALID_ARGUMENTS;
}
/* return allocated string w/printf() result */
char *alloc_printf(const char *fmt, va_list ap)
{
char *string = NULL;
/* start by 0 to exercise all the code paths. Need minimum 2 bytes to
* fit 1 char and 0 terminator. */
int size = 0;
int first = 1;
for (;;)
{
if ((string == NULL) || (!first))
{
size = size * 2 + 2;
char *t = string;
string = realloc(string, size);
if (string == NULL)
{
if (t != NULL)
free(t);
return NULL;
}
}
int ret;
ret = vsnprintf(string, size, fmt, ap);
/* NB! The result of the vsnprintf() might be an *EMPTY* string! */
if ((ret >= 0) && ((ret + 1) < size))
{
return string;
}
/* there was just enough or not enough space, allocate more. */
first = 0;
}
}

+ 113
- 113
src/helper/log.h View File

@@ -1,113 +1,113 @@
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef ERROR_H
#define ERROR_H
#include "replacements.h"
#include "command.h"
#include <stdarg.h>
/* logging priorities
* LOG_USER - user messages. Could be anything from information
* to progress messags. These messages do not represent
* incorrect or unexpected behaviour, just normal execution.
* LOG_ERROR - fatal errors, that are likely to cause program abort
* LOG_WARNING - non-fatal errors, that may be resolved later
* LOG_INFO - state information, etc.
* LOG_DEBUG - debug statements, execution trace
*/
enum log_levels
{
LOG_OUTPUT = -2,
LOG_USER = -1,
LOG_ERROR = 0,
LOG_WARNING = 1,
LOG_INFO = 2,
LOG_DEBUG = 3
};
extern void log_printf(enum log_levels level, const char *file, int line,
const char *function, const char *format, ...)
__attribute__ ((format (printf, 5, 6)));
extern int log_register_commands(struct command_context_s *cmd_ctx);
extern int log_init(struct command_context_s *cmd_ctx);
extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
typedef void (*log_callback_fn)(void *priv, const char *file, int line,
const char *function, const char *format, va_list args);
typedef struct log_callback_s
{
log_callback_fn fn;
void *priv;
struct log_callback_s *next;
} log_callback_t;
extern int log_add_callback(log_callback_fn fn, void *priv);
extern int log_remove_callback(log_callback_fn fn, void *priv);
char *alloc_printf(const char *fmt, va_list ap);
extern int debug_level;
/* Avoid fn call and building parameter list if we're not outputting the information.
* Matters on feeble CPUs for DEBUG/INFO statements that are involved frequently */
#define DEBUG(expr ...) \
do { if (debug_level >= LOG_DEBUG) \
log_printf (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define INFO(expr ...) \
do { if (debug_level >= LOG_INFO) \
log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define WARNING(expr ...) \
do { \
log_printf (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define ERROR(expr ...) \
do { \
log_printf (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define USER(expr ...) \
do { \
log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define OUTPUT(expr ...) \
do { \
log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
/* general failures
* error codes < 100
*/
#define ERROR_OK (0)
#define ERROR_INVALID_ARGUMENTS (-1)
#define ERROR_NO_CONFIG_FILE (-2)
#define ERROR_BUF_TOO_SMALL (-3)
#endif /* LOG_H */
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef ERROR_H
#define ERROR_H
#include "replacements.h"
#include "command.h"
#include <stdarg.h>
/* logging priorities
* LOG_USER - user messages. Could be anything from information
* to progress messags. These messages do not represent
* incorrect or unexpected behaviour, just normal execution.
* LOG_ERROR - fatal errors, that are likely to cause program abort
* LOG_WARNING - non-fatal errors, that may be resolved later
* LOG_INFO - state information, etc.
* LOG_DEBUG - debug statements, execution trace
*/
enum log_levels
{
LOG_OUTPUT = -2,
LOG_USER = -1,
LOG_ERROR = 0,
LOG_WARNING = 1,
LOG_INFO = 2,
LOG_DEBUG = 3
};
extern void log_printf(enum log_levels level, const char *file, int line,
const char *function, const char *format, ...)
__attribute__ ((format (printf, 5, 6)));
extern int log_register_commands(struct command_context_s *cmd_ctx);
extern int log_init(struct command_context_s *cmd_ctx);
extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
typedef void (*log_callback_fn)(void *priv, const char *file, int line,
const char *function, const char *format, va_list args);
typedef struct log_callback_s
{
log_callback_fn fn;
void *priv;
struct log_callback_s *next;
} log_callback_t;
extern int log_add_callback(log_callback_fn fn, void *priv);
extern int log_remove_callback(log_callback_fn fn, void *priv);
char *alloc_printf(const char *fmt, va_list ap);
extern int debug_level;
/* Avoid fn call and building parameter list if we're not outputting the information.
* Matters on feeble CPUs for DEBUG/INFO statements that are involved frequently */
#define DEBUG(expr ...) \
do { if (debug_level >= LOG_DEBUG) \
log_printf (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define INFO(expr ...) \
do { if (debug_level >= LOG_INFO) \
log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define WARNING(expr ...) \
do { \
log_printf (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define ERROR(expr ...) \
do { \
log_printf (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define USER(expr ...) \
do { \
log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define OUTPUT(expr ...) \
do { \
log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
/* general failures
* error codes < 100
*/
#define ERROR_OK (0)
#define ERROR_INVALID_ARGUMENTS (-1)
#define ERROR_NO_CONFIG_FILE (-2)
#define ERROR_BUF_TOO_SMALL (-3)
#endif /* LOG_H */

+ 153
- 153
src/helper/options.c View File

@@ -1,153 +1,153 @@
/***************************************************************************
* Copyright (C) 2004, 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "types.h"
#include "command.h"
#include "configuration.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
static int help_flag;
static struct option long_options[] =
{
{"help", no_argument, &help_flag, 1},
{"debug", optional_argument, 0, 'd'},
{"file", required_argument, 0, 'f'},
{"search", required_argument, 0, 's'},
{"log_output", required_argument, 0, 'l'},
{"command", required_argument, 0, 'c'},
{0, 0, 0, 0}
};
int configuration_output_handler(struct command_context_s *context, char* line)
{
INFO(line);
return ERROR_OK;
}
int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
{
int c;
char command_buffer[128];
while (1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long(argc, argv, "hd::l:f:s:c:", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 0:
break;
case 'h': /* --help | -h */
help_flag = 1;
break;
case 'f': /* --file | -f */
snprintf(command_buffer, 128, "script %s", optarg);
add_config_file_name(command_buffer);
break;
case 's': /* --search | -s */
add_script_search_dir(optarg);
break;
case 'd': /* --debug | -d */
if (optarg)
snprintf(command_buffer, 128, "debug_level %s", optarg);
else
snprintf(command_buffer, 128, "debug_level 3");
command_run_line(cmd_ctx, command_buffer);
break;
case 'l': /* --log_output | -l */
if (optarg)
{
snprintf(command_buffer, 128, "log_output %s", optarg);
command_run_line(cmd_ctx, command_buffer);
}
break;
case 'c': /* --command | -c */
if (optarg)
{
add_config_file_name(optarg);
}
break;
}
}
if (help_flag)
{
OUTPUT("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
OUTPUT("--help | -h\tdisplay this help\n");
OUTPUT("--file | -f\tuse configuration file <name>\n");
OUTPUT("--search | -s\tdir to search for config files and scripts.\n");
OUTPUT("--debug | -d\tset debug level <0-3>\n");
OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
OUTPUT("--command | -c\trun <command>\n");
exit(-1);
}
#ifdef _WIN32
/* Add the parent of the directory where openocd.exe resides to the
* config script search path.
* Directory layout:
* bin\openocd.exe
* lib\openocd
* event\at91eb40a_reset.cfg
* target\at91eb40a.cfg
*/
{
char strExePath [MAX_PATH];
GetModuleFileName (NULL, strExePath, MAX_PATH);
/* Either this code will *always* work or it will SEGFAULT giving
* excellent information on the culprit.
*/
*strrchr(strExePath, '\\')=0;
strcat(strExePath, "\\..");
add_script_search_dir(strExePath);
}
#else
/* Add dir for openocd supplied scripts last so that user can over
ride those scripts if desired. */
add_script_search_dir(PKGDATADIR);
add_script_search_dir(PKGLIBDIR);
#endif
return ERROR_OK;
}
/***************************************************************************
* Copyright (C) 2004, 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "types.h"
#include "command.h"
#include "configuration.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
static int help_flag;
static struct option long_options[] =
{
{"help", no_argument, &help_flag, 1},
{"debug", optional_argument, 0, 'd'},
{"file", required_argument, 0, 'f'},
{"search", required_argument, 0, 's'},
{"log_output", required_argument, 0, 'l'},
{"command", required_argument, 0, 'c'},
{0, 0, 0, 0}
};
int configuration_output_handler(struct command_context_s *context, char* line)
{
INFO(line);
return ERROR_OK;
}
int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
{
int c;
char command_buffer[128];
while (1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long(argc, argv, "hd::l:f:s:c:", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 0:
break;
case 'h': /* --help | -h */
help_flag = 1;
break;
case 'f': /* --file | -f */
snprintf(command_buffer, 128, "script %s", optarg);
add_config_file_name(command_buffer);
break;
case 's': /* --search | -s */
add_script_search_dir(optarg);
break;
case 'd': /* --debug | -d */
if (optarg)
snprintf(command_buffer, 128, "debug_level %s", optarg);
else
snprintf(command_buffer, 128, "debug_level 3");
command_run_line(cmd_ctx, command_buffer);
break;
case 'l': /* --log_output | -l */
if (optarg)
{
snprintf(command_buffer, 128, "log_output %s", optarg);
command_run_line(cmd_ctx, command_buffer);
}
break;
case 'c': /* --command | -c */
if (optarg)
{
add_config_file_name(optarg);
}
break;
}
}
if (help_flag)
{
OUTPUT("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
OUTPUT("--help | -h\tdisplay this help\n");
OUTPUT("--file | -f\tuse configuration file <name>\n");
OUTPUT("--search | -s\tdir to search for config files and scripts.\n");
OUTPUT("--debug | -d\tset debug level <0-3>\n");
OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
OUTPUT("--command | -c\trun <command>\n");
exit(-1);
}
#ifdef _WIN32
/* Add the parent of the directory where openocd.exe resides to the
* config script search path.
* Directory layout:
* bin\openocd.exe
* lib\openocd
* event\at91eb40a_reset.cfg
* target\at91eb40a.cfg
*/
{
char strExePath [MAX_PATH];
GetModuleFileName (NULL, strExePath, MAX_PATH);
/* Either this code will *always* work or it will SEGFAULT giving
* excellent information on the culprit.
*/
*strrchr(strExePath, '\\')=0;
strcat(strExePath, "\\..");
add_script_search_dir(strExePath);
}
#else
/* Add dir for openocd supplied scripts last so that user can over
ride those scripts if desired. */
add_script_search_dir(PKGDATADIR);
add_script_search_dir(PKGLIBDIR);
#endif
return ERROR_OK;
}

+ 29
- 29
src/helper/replacements.h View File

@@ -67,38 +67,38 @@ struct timezone {
};

extern int gettimeofday(struct timeval *tv, struct timezone *tz);
#endif
#endif
/**** clear_malloc & fill_malloc ****/
void *clear_malloc(size_t size);
void *fill_malloc(size_t size);
/*
* Now you have 3 ways for the malloc function:
*
* 1. Do not change anything, use the original malloc
*
* 2. Use the clear_malloc function instead of the original malloc.
* In this case you must use the following define:
* #define malloc((_a)) clear_malloc((_a))
*
* 3. Use the fill_malloc function instead of the original malloc.
* In this case you must use the following define:
* #define malloc((_a)) fill_malloc((_a))
*
* We have figured out that there could exist some malloc problems
* where variables are using without to be initialise. To find this
* places, use the fill_malloc function. With this function we want
* to initialize memory to some known bad state. This is quite easily
* spotted in the debugger and will trap to an invalid address.
*
* clear_malloc can be used if you want to set not initialise
* variable to 0.
*
* If you do not want to change the malloc function, to not use one of
* the following macros. Which is the default way.
*/
/*
* Now you have 3 ways for the malloc function:
*
* 1. Do not change anything, use the original malloc
*
* 2. Use the clear_malloc function instead of the original malloc.
* In this case you must use the following define:
* #define malloc((_a)) clear_malloc((_a))
*
* 3. Use the fill_malloc function instead of the original malloc.
* In this case you must use the following define:
* #define malloc((_a)) fill_malloc((_a))
*
* We have figured out that there could exist some malloc problems
* where variables are using without to be initialise. To find this
* places, use the fill_malloc function. With this function we want
* to initialize memory to some known bad state. This is quite easily
* spotted in the debugger and will trap to an invalid address.
*
* clear_malloc can be used if you want to set not initialise
* variable to 0.
*
* If you do not want to change the malloc function, to not use one of
* the following macros. Which is the default way.
*/
//#define malloc(_a) clear_malloc(_a)
//#define malloc(_a) fill_malloc(_a)



+ 366
- 366
src/jtag/bitq.c View File

@@ -1,366 +1,366 @@
/***************************************************************************
* Copyright (C) 2007 by Pavel Chromy *
* chromy@asix.cz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "bitq.h"
/* project specific includes */
#include "log.h"
#include "types.h"
#include "jtag.h"
#include "configuration.h"
/* system includes */
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
bitq_interface_t *bitq_interface; /* low level bit queue interface */
bitq_state_t bitq_in_state; /* state of input queue */
u8 *bitq_in_buffer; /* buffer dynamically reallocated as needed */
unsigned long bitq_in_bufsize=32; /* min. buffer size */
/*
* input queue processing does not use jtag_read_buffer() to avoid unnecessary overhead
* also the buffer for incomming data is reallocated only if necessary
* no parameters, makes use of stored state information
*/
void bitq_in_proc(void)
{
/* static information preserved between calls to increase performance */
static u8 *in_buff; /* pointer to buffer for scanned data */
static int in_idx; /* index of byte being scanned */
static u8 in_mask; /* mask of next bit to be scanned */
scan_field_t *field;
int tdo;
/* loop through the queue */
while (bitq_in_state.cmd) {
/* only JTAG_SCAN command may return data */
if (bitq_in_state.cmd->type==JTAG_SCAN) {
/* loop through the fields */
while (bitq_in_state.field_idx<bitq_in_state.cmd->cmd.scan->num_fields) {
field=&bitq_in_state.cmd->cmd.scan->fields[bitq_in_state.field_idx];
if ( field->in_value || field->in_handler) {
if (bitq_in_state.bit_pos==0) {
/* initialize field scanning */
in_mask=0x01;
in_idx=0;
if (field->in_value) in_buff=field->in_value;
else {
/* buffer reallocation needed? */
if (field->num_bits>bitq_in_bufsize*8) {
/* buffer previously allocated? */
if (bitq_in_buffer!=NULL) {
/* free it */
free(bitq_in_buffer);
bitq_in_buffer=NULL;
}
/* double the buffer size until it fits */
while (field->num_bits>bitq_in_bufsize*8) bitq_in_bufsize*=2;
}
/* if necessary, allocate buffer and check for malloc error */
if (bitq_in_buffer==NULL && (bitq_in_buffer=malloc(bitq_in_bufsize))==NULL) {
ERROR("malloc error");
exit(-1);
}
in_buff=(void *)bitq_in_buffer;
}
}
/* field scanning */
while (bitq_in_state.bit_pos<field->num_bits) {
if ((tdo=bitq_interface->in())<0) {
#ifdef _DEBUG_JTAG_IO_
DEBUG("bitq in EOF");
#endif
return;
}
if (in_mask==0x01) in_buff[in_idx]=0;
if (tdo) in_buff[in_idx]|=in_mask;
if (in_mask==0x80) {
in_mask=0x01;
in_idx++;
}
else in_mask<<=1;
bitq_in_state.bit_pos++;
}
if (field->in_handler && bitq_in_state.status==ERROR_OK) {
bitq_in_state.status=(*field->in_handler)(in_buff, field->in_handler_priv, field);
}
}
bitq_in_state.field_idx++; /* advance to next field */
bitq_in_state.bit_pos=0; /* start next field from the first bit */
}
}
bitq_in_state.cmd=bitq_in_state.cmd->next; /* advance to next command */
bitq_in_state.field_idx=0; /* preselect first field */
}
}
void bitq_io(int tms, int tdi, int tdo_req)
{
bitq_interface->out(tms, tdi, tdo_req);
/* check and process the input queue */
if (bitq_interface->in_rdy()) bitq_in_proc();
}
void bitq_end_state(enum tap_state state)
{
if (state==-1) return;
if (tap_move_map[state]==-1) {
ERROR("BUG: %i is not a valid end state", state);
exit(-1);
}
end_state = state;
}
void bitq_state_move(enum tap_state new_state)
{
int i=0;
u8 tms_scan;
if (tap_move_map[cur_state]==-1 || tap_move_map[new_state]==-1) {
ERROR("TAP move from or to unstable state");
exit(-1);
}
tms_scan=TAP_MOVE(cur_state, new_state);
for (i=0; i<7; i++) {
bitq_io(tms_scan&1, 0, 0);
tms_scan>>=1;
}
cur_state = new_state;
}