Exemplo n.º 1
0
Arquivo: map.c Projeto: anyc/numatop
int
map_load(track_proc_t *proc)
{
	map_t *map = &proc->map;
	map_t new_map;
	map_entry_t *old_entry;
	int i;

	if (!map->loaded) {
		if (map_read(proc->pid, map) != 0) {
			return (-1);
		}

		return (0);		
	}

	if (map_read(proc->pid, &new_map) != 0) {
		return (-1);
	}

	for (i = 0; i < new_map.nentry_cur; i++) {
		if ((old_entry = map_entry_find(proc, new_map.arr[i].start_addr, 
			new_map.arr[i].end_addr - new_map.arr[i].start_addr)) == NULL) {
			new_map.arr[i].need_resolve = B_TRUE;
		} else {
			new_map.arr[i].need_resolve = old_entry->need_resolve;
		}
	}
	
	map_fini(&proc->map);
	memcpy(&proc->map, &new_map, sizeof (map_t));
	return (0);	
}
Exemplo n.º 2
0
int __xipram cfi_qry_present(struct map_info *map, __u32 base,
			     struct cfi_private *cfi)
{
	int osf = cfi->interleave * cfi->device_type;	/* scale factor */
	map_word val[3];
	map_word qry[3];

	qry[0] = cfi_build_cmd('Q', map, cfi);
	qry[1] = cfi_build_cmd('R', map, cfi);
	qry[2] = cfi_build_cmd('Y', map, cfi);

	val[0] = map_read(map, base + osf*0x10);
	val[1] = map_read(map, base + osf*0x11);
	val[2] = map_read(map, base + osf*0x12);

	if (!map_word_equal(map, qry[0], val[0]))
		return 0;

	if (!map_word_equal(map, qry[1], val[1]))
		return 0;

	if (!map_word_equal(map, qry[2], val[2]))
		return 0;

	return 1; 	/* "QRY" found */
}
Exemplo n.º 3
0
void sighup()
{
	map_destroy();
	map_read();

	signal(SIGHUP, sighup);
}
Exemplo n.º 4
0
int
main(int argc, char** argv)
{
  if(argc != 2) {
    fprintf(stderr, "usage: simulator <n-threads>\n");
    return EXIT_FAILURE;
  }
  
  NTHREADS = atoi(argv[1]);
  
  map = map_read(stdin);
  
  if(!map) {
    fprintf(stderr, "Failed to read map\n");
    exit(EXIT_FAILURE);
  }
  
  //map_print(map, stdout);
  
  simulate();
  
  //map_print(map, stdout);
  map_output(map, stdout);
  
  map_free(map);
  
  return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int map_lock(struct map_ent **melp)
{
	while (lf == NULL) {
		struct stat buf;
		lf = open_map(MAP_LOCK);
		if (lf == NULL)
			return -1;
		if (flock(fileno(lf), LOCK_EX) != 0) {
			fclose(lf);
			lf = NULL;
			return -1;
		}
		if (fstat(fileno(lf), &buf) != 0 ||
		    buf.st_nlink == 0) {
			/* The owner of the lock unlinked it,
			 * so we have a lock on a stale file,
			 * try again
			 */
			fclose(lf);
			lf = NULL;
		}
	}
	if (*melp)
		map_free(*melp);
	map_read(melp);
	return 0;
}
Exemplo n.º 6
0
int map_update(struct map_ent **mpp, char *devnm, char *metadata,
	       int *uuid, char *path)
{
	struct map_ent *map, *mp;
	int rv;

	if (mpp && *mpp)
		map = *mpp;
	else
		map_read(&map);

	for (mp = map ; mp ; mp=mp->next)
		if (strcmp(mp->devnm, devnm) == 0) {
			strcpy(mp->metadata, metadata);
			memcpy(mp->uuid, uuid, 16);
			free(mp->path);
			mp->path = path ? xstrdup(path) : NULL;
			mp->bad = 0;
			break;
		}
	if (!mp)
		map_add(&map, devnm, metadata, uuid, path);
	if (mpp)
		*mpp = NULL;
	rv = map_write(map);
	map_free(map);
	return rv;
}
Exemplo n.º 7
0
void copyumap(int y, int x, int fullvis)
{
    char c;

    c = at(y, x);
    if (!fullvis && c == SPACE && map_read(umap, y, x) != SPACE)
        c = OBSPACE;
    map_write(umap, y, x, c);
}
Exemplo n.º 8
0
Arquivo: igmp.c Projeto: hchunhui/pop
struct igmp_addrs *igmp_get_maddrs(struct map *group_table, uint32_t groupid)
{
	struct igmp_addrs *l;

	l = map_read(group_table, INT(groupid)).p;
	if(l == NULL) {
		l = malloc(sizeof(struct igmp_addrs));
		l->addrs = NULL;
		l->n = 0;
		map_add_key(group_table, INT(groupid), PTR(l), mgt_eq_val, mgt_free_val);
	}
	return l;
}
Exemplo n.º 9
0
int		map_open(char *filepath, char *buffer, int size)
{
  int		fd;

  fd = open(filepath, O_RDONLY);
  if (fd == -1)
    {
      my_putstr_error("Can't open the file\n");
      exit(1);
    }
  map_read(fd, buffer, size);
  close(fd);
  return (fd);
}
Exemplo n.º 10
0
/* Look at position (y,x) in the maze map */
char at(int y, int x)
{
    int maxy, maxx;

    getmaxyx(&maxy, &maxx);    

    if (y == py && x == px)
        return punder; 

    if (y < 0 || y >= maxy || x < 0 || x >= maxx)
        return SPACE;
    else {
        return map_read(map, y, x);
    }
}
Exemplo n.º 11
0
/*
 * this function should be changed--the mask map stack is misused as
 * to define the topology of variogram maps.
 *
 * use min/max coordinates for block diagonal as maximum cutoff
 * Returns: about 1/3 the max. dist between any two points in data. 
 */
void fill_cutoff_width(DATA *data /* pointer to DATA structure to derive
		the values from */,
		VARIOGRAM *v /* pointer to VARIOGRAM structure */)
{
	double d = 0.0;
	int i;
	GRIDMAP *m;
	SAMPLE_VGM *ev;

	assert(data);
	assert(v);

	ev = v->ev;
	if (get_n_masks() > 0) {
		m = new_map();
		m->is_write = 0;
		m->filename = get_mask_name(0);
		if ((m = map_read(m)) == NULL)
			ErrMsg(ER_READ, "cannot open map");
		ev->iwidth = 1.0;
		ev->cutoff = m->rows * m->cols; 
			/* not a real cutoff, but rather the size of the container array */
		ev->map = m;
	} else if (gl_bounds != NULL) {
		i = 0;
		while (gl_bounds[i] >= 0.0) /* count length */
			i++;
		ev->cutoff = gl_bounds[i-1];
		ev->iwidth = ev->cutoff / i;
	} else {
		if (is_mv_double(&(ev->cutoff))) {
			if (gl_cutoff < 0.0) {
				d = data_block_diagonal(data);
				if (d == 0.0)
					ev->cutoff = 1.0; /* ha ha ha */
				else
					ev->cutoff = d * gl_fraction;
			} else
				ev->cutoff = gl_cutoff;
		}
		if (is_mv_double(&(ev->iwidth))) {
			if (gl_iwidth < 0.0)
				ev->iwidth = ev->cutoff / gl_n_intervals;
			else
				ev->iwidth = gl_iwidth;
		}
	}
}
Exemplo n.º 12
0
void map_delete(struct map_ent **mapp, char *devnm)
{
	struct map_ent *mp;

	if (*mapp == NULL)
		map_read(mapp);

	for (mp = *mapp; mp; mp = *mapp) {
		if (strcmp(mp->devnm, devnm) == 0) {
			*mapp = mp->next;
			free(mp->path);
			free(mp);
		} else
			mapp = & mp->next;
	}
}
Exemplo n.º 13
0
struct map_ent *map_by_devnm(struct map_ent **map, char *devnm)
{
	struct map_ent *mp;
	if (!*map)
		map_read(map);

	for (mp = *map ; mp ; mp = mp->next) {
		if (strcmp(mp->devnm, devnm) != 0)
			continue;
		if (!mddev_busy(mp->devnm)) {
			mp->bad = 1;
			continue;
		}
		return mp;
	}
	return NULL;
}
Exemplo n.º 14
0
struct map_ent *map_by_uuid(struct map_ent **map, int uuid[4])
{
	struct map_ent *mp;
	if (!*map)
		map_read(map);

	for (mp = *map ; mp ; mp = mp->next) {
		if (memcmp(uuid, mp->uuid, 16) != 0)
			continue;
		if (!mddev_busy(mp->devnm)) {
			mp->bad = 1;
			continue;
		}
		return mp;
	}
	return NULL;
}
Exemplo n.º 15
0
static GRIDMAP *check_open(const char *name, int i) {
	GRIDMAP *mask;
	unsigned int r, c;

	mask = new_map(READ_ONLY);
	mask->filename = name;
	if ((mask = map_read(mask)) == NULL)
		ErrMsg(ER_READ, name);
	if (i == 0) {
		for (r = n_pred_locs = 0; r < mask->rows; r++)
			for (c = 0; c < mask->cols; c++)
				if (! map_cell_is_mv(mask, r, c))
					n_pred_locs++;
	} else if (! map_equal(mask, masks[0]))
		ErrMsg(ER_NULL, "mask map location is different from first mask map");
	return mask;
}
Exemplo n.º 16
0
int is_valid_strata_map(const char *name, int n_vars) {
	GRIDMAP *mp;
	int check_failed = 1;

	mp = new_map(READ_ONLY);
	mp->filename = name;
	if ((mp = map_read(mp)) == NULL)
		ErrMsg(ER_READ, name);
	/* 
	 * check min/max: enough strata? this check was:
	 * check_failed = (mp->cellmax - mp->cellmin < n_vars - 1);
	 */
	check_failed = (mp->cellmax - mp->cellmin < 1.0);
	if (! check_failed && mp->cellmax - mp->cellmin < n_vars - 1)
		pr_warning("fewer mask map categories than data variables present");
	map_free(mp);
	return (check_failed == 0);
}
Exemplo n.º 17
0
__xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* name)
{
	struct cfi_private *cfi = map->fldrv_priv;
	__u32 base = 0; // cfi->chips[0].start;
	int ofs_factor = cfi->interleave * cfi->device_type;
	int i;
	struct cfi_extquery *extp = NULL;

	if (!adr)
		goto out;

	printk(KERN_INFO "%s Extended Query Table at 0x%4.4X\n", name, adr);

	extp = kmalloc(size, GFP_KERNEL);
	if (!extp) {
		printk(KERN_ERR "Failed to allocate memory\n");
		goto out;
	}

#ifdef CONFIG_MTD_XIP
	local_irq_disable();
#endif

	/* Switch it into Query Mode */
	cfi_qry_mode_on(base, map, cfi);
	/* Read in the Extended Query Table */
	for (i=0; i<size; i++) {
		((unsigned char *)extp)[i] =
			cfi_read_query(map, base+((adr+i)*ofs_factor));
	}

	/* Make sure it returns to read mode */
	cfi_qry_mode_off(base, map, cfi);

#ifdef CONFIG_MTD_XIP
	(void) map_read(map, base);
	xip_iprefetch();
	local_irq_enable();
#endif

 out:	return extp;
}
Exemplo n.º 18
0
struct map_ent *map_by_name(struct map_ent **map, char *name)
{
	struct map_ent *mp;
	if (!*map)
		map_read(map);

	for (mp = *map ; mp ; mp = mp->next) {
		if (!mp->path)
			continue;
		if (strncmp(mp->path, "/dev/md/", 8) != 0)
			continue;
		if (strcmp(mp->path+8, name) != 0)
			continue;
		if (!mddev_busy(mp->devnm)) {
			mp->bad = 1;
			continue;
		}
		return mp;
	}
	return NULL;
}
Exemplo n.º 19
0
int main(int argc, char ** argv){
	// Declerations
	Map M;
	Char C;
	FILE *fin;
	char input;	

	// File pointer init
	fin = fopen("./resources/maps/test.map","r");
	map_read(fin,&M);
	read_chars(&C);
//	printf("%d\n",ret);
	place_on_map(C,&M);

//	print_deb(M);	
	initscr();
	curs_set(0);
	header();
	keypad(stdscr,TRUE);
	cbreak();
	getch();
	clear();
	print_map(M);
	// Main game loop
	do{
		input = getch();	
		clear();
		int ret = action(&C,&M,input);
		if(ret){
			mvprintw(GRID_Y,0,"Can't do that!");
		}
		print_map(M);
		refresh();
		fflush(stdin);
	}while(input != 'q');
	endwin();
	
	fclose(fin);
	return 0;
}
Exemplo n.º 20
0
/**
 * Behandelt die Kommandozeilen-Argumente
 * \param argc	Anzahl der Argumente
 * \param *argv	Zeiger auf String-Array der Argumente
 */
void hand_cmd_args(int argc, char * argv[]) {
	/* Der Zielhost wird per default durch das Macro IP definiert und
	 * tcp_hostname mit einer Kopie des Strings initialisiert. */
	tcp_hostname = malloc(strlen(IP) + 1);
	if (NULL == tcp_hostname) {
		exit(1);
	}
	strcpy(tcp_hostname, IP);

	int ch;
	/* Die Kommandozeilenargumente komplett verarbeiten */
	while ((ch = getopt(argc, argv, "hsTu:Et:Mm:c:l:e:d:a:i:fk:o:F:")) != -1) {
		argc -= optind;
		argv += optind;
		switch (ch) {

		case 's': {
#ifdef BOT_2_SIM_AVAILABLE
			/* Servermodus [-s] wird verlangt */
			printf("ARGV[0]= %s\n", argv[0]);
			tcp_server_init();
			tcp_server_run(1000); // beendet per exit()
#else
			puts("Fehler, Binary wurde ohne BOT_2_SIM_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_2_SIM_AVAILABLE
			break;
		}

		case 'T': {
#ifdef BOT_2_SIM_AVAILABLE
			/* Testclient starten */
			tcp_test_client_init();
			tcp_test_client_run(1000); // beendet per exit()
#else
			puts("Fehler, Binary wurde ohne BOT_2_SIM_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_2_SIM_AVAILABLE
			break;
		}

		case 'u': {
#ifdef ARM_LINUX_BOARD
			long long int n = atoll(optarg);
			uart_test((uint32_t) n);
#endif
			break;
		}

		case 't': {
			/* Hostname, auf dem ct-Sim laeuft, wurde uebergeben. Der String wird in hostname gesichert. */
			const size_t len = strlen(optarg) + 1;
			if (len > 255) {
				puts("hostname ungueltig");
				exit(1);
			}
			tcp_hostname = realloc(tcp_hostname, len);
			if (tcp_hostname == NULL) {
				exit(1);
			}
			strcpy(tcp_hostname, optarg);
			break;
		}

		case 'a': {
			/* Bot-Adresse wurde uebergeben */
			int addr = atoi(optarg);
			if ((addr >= CMD_SIM_ADDR) && (addr != CMD_BROADCAST)) {
				puts("Unzulaessige Bot-Adresse!");
				exit(1);
			}
			set_bot_address(addr);
			break;
		}

		case 'i': {
			/* angegebenes BotFS Image verwenden */
#ifdef BOT_FS_AVAILABLE
			const size_t len = strlen(optarg) + 1;
			if (len > 1024) {
				puts("Image-Pfad ungueltig");
				exit(1);
			}
			botfs_volume_image_file = malloc(len);
			if (NULL == botfs_volume_image_file) {
				exit(1);
			}
			strcpy(botfs_volume_image_file, optarg);
			printf("Verwende \"%s\" als BotFS-Volume-Image\n", botfs_volume_image_file);
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
			break;
		}

		case 'M': {
			/* Dateiname fuer die Map wurde uebergeben. Der String wird in from gesichert. */
#ifndef MAP_AVAILABLE
			puts("ACHTUNG, das Programm wurde ohne MAP_AVAILABLE uebersetzt, die Option -M steht derzeit also NICHT zur Verfuegung.");
			puts("um dennoch Karten zu konvertieren, bitte im Quelltext in der Datei ct-Bot.h die Kommentarzeichen vor MAP_AVAILABLE entfernen");
			puts("und neu compilieren.");
			exit(1);
#endif
#ifdef MMC_VM_AVAILABLE
			puts("Executable wurde mit MMC_VM_AVAILABLE compiliert.");
			puts("Um Karten des echten Bots einlesen zu koennen, bitte den Code bitte ohne MMC_VM_AVAILABLE neu uebersetzen.");
			exit(1);
#endif
#ifdef MAP_AVAILABLE
			/* Karte in pgm konvertieren */
#ifndef BOT_FS_AVAILABLE
			if (argc != 1) {
				usage();
				exit(1);
			}
			const size_t len = strlen(argv[0]) + 1;
			if (len > 1024) {
				puts("Dateiname ungueltig");
				exit(1);
			}
			printf("Konvertiere Karte %s in PGM %s\n", argv[0], "map.pgm");
			map_read(argv[0]);
#else
			uint8_t buffer[BOTFS_BLOCK_SIZE];
			if (botfs_init(botfs_volume_image_file, buffer, False) != 0) {
				puts("BotFS konnte nicht initialisiert werden");
				exit(1);
			}
			if (map_init() != 0) {
				puts("Map-Subsystem konnte nicht initialisiert werde");
				exit(1);
			}
#endif // BOT_FS_AVAILABLE
			map_to_pgm("map.pgm");
			exit(0);
#endif // MAP_AVAILABLE
		}

		case 'm': {
#ifndef MAP_AVAILABLE
			puts("ACHTUNG, das Programm wurde ohne MAP_AVAILABLE uebersetzt, die Option -m steht derzeit also NICHT zur Verfuegung.");
			puts("um dennoch Karten zu konvertieren, bitte im Quelltext in der Datei ct-Bot.h die Kommentarzeichen vor MAP_AVAILABLE entfernen");
			puts("und neu compilieren.");
			exit(1);
#else
			/* Karte einlesen */
			const size_t len = strlen(optarg) + 1;
			if (len > 1024) {
				puts("Dateiname ungueltig");
				exit(1);
			}
			printf("Lese Karte von \"%s\" ein\n", optarg);
#ifdef BOT_FS_AVAILABLE
			uint8_t buffer[BOTFS_BLOCK_SIZE];
			if (botfs_init(botfs_volume_image_file, buffer, False) != 0) {
				puts("BotFS konnte nicht initialisiert werden");
				exit(1);
			}
#endif // BOT_FS_AVAILABLE
			map_read(optarg);
#endif // MAP_AVAILABLE
			break;
		}

		case 'f': {
			/* BotFS Tool */
#ifdef BOT_FS_AVAILABLE
			char * image = argv[0];
			botfs_management(image);
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
			break;
		}

		case 'k' : {
			/* BotFS file copy */
#ifdef BOT_FS_AVAILABLE
			char * image = optarg;
			char buffer[BOTFS_BLOCK_SIZE];
			if (botfs_init(image, buffer, False) != 0) {
				printf("Konnte BotFS mit Image \"%s\" nicht initialisieren\n", image);
				exit(1);
			}
			if (argc != 2) {
				usage();
				exit(1);
			}
			const char * source_file = argv[0];
			const char * dest_file = argv[1];
			if (botfs_copy_file(dest_file, source_file, buffer) == 0) {
				puts("Datei erfolgreich kopiert");
				exit(0);
			} else {
				puts("Fehler beim Kopieren");
				exit(1);
			}
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
		}

		case 'o' : {
			/* BotFS file extract */
#ifdef BOT_FS_AVAILABLE
			char * image = optarg;
			char buffer[BOTFS_BLOCK_SIZE];
			if (botfs_init(image, buffer, False) != 0) {
				printf("Konnte BotFS mit Image \"%s\" nicht initialisieren\n", image);
				exit(1);
			}
			if (argc != 2) {
				usage();
				exit(1);
			}
			const char * source_file = argv[0];
			const char * dest_file = argv[1];
			if (botfs_extract_file(dest_file, source_file, 0, 0, buffer) == 0) {
				puts("Datei erfolgreich kopiert");
				exit(0);
			} else {
				puts("Fehler beim Kopieren");
				exit(1);
			}
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
		}

		case 'F': {
			/* Fat16-Tool */
#ifdef BOT_FS_AVAILABLE
			botfs_read_fat16(optarg);
			exit(0);
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
		}

		case 'c': {
			/* Datei fuer den Bot (mini-fat) soll erzeugt werden. */
			const int len = strlen(optarg) + 1;
			if (len > 1024) {
				puts("Dateiname ungueltig");
				exit(1);
			}
			if (argc != 2) {
				usage();
				exit(1);
			}
			const size_t id_len = strlen(argv[0]);
			if (id_len >= MMC_FILENAME_MAX) {
				puts("ID zu lang");
				exit(1);
			}
			const int size = atoi(argv[1]);
			printf("Mini-Fat-Datei (%s) mit %d kByte und ID=%s fuer den Bot soll erstellt werden.\n",
				optarg, size, argv[0]);
			create_mini_fat_file(optarg, argv[0], size);
			exit(0);
		}

		case 'e': {
			/* Datei fuer den Sim (mini-fat) soll erzeugt werden. */
			if (argc != 2) {
				usage();
				exit(1);
			}

			const int size = atoi(argv[1]);
			uint32_t addr = atoi(optarg);
			printf("Mini-Fat-Datei mit ID=%s an Adresse 0x%x mit %d kByte auf der emulierten MMC soll erstellt werden.\n",
				argv[0], addr, size);
			create_emu_mini_fat_file(addr, argv[0], size);
			exit(0);
		}

		case 'd': {
			/* Datei fuer den Sim (mini-fat) soll geloescht werden. */
			if (argc != 0) {
				usage();
				exit(1);
			}

			printf("Mini-Fat-Datei mit ID %s auf der emulierten MMC soll geloescht werden.\n", optarg);
			delete_emu_mini_fat_file(optarg);
			exit(0);
		}

		case 'l': {
#ifdef BOT_FS_AVAILABLE
			/* Speedlog-Datei soll in txt konvertiert werden */
			const size_t len = strlen(optarg) + 1;
			if (len > 1024) {
				puts("Dateiname ungueltig");
				exit(1);
			}
			convert_slog_file(optarg);
			exit(0);
#else
			puts("Fehler, Binary wurde ohne BOT_FS_AVAILABLE compiliert!");
			exit(1);
#endif // BOT_FS_AVAILABLE
		}

		case 'E': {
			/* EEPROM-Init */
			printf("EEPROM soll mit den Daten einer eep-Datei initialisiert werden.\n");
			if (init_eeprom_man(1) != 0) {
				puts("Fehler bei EEPROM-Initialisierung!");
			} else {
				puts("done.");
			}
			exit(0);
		}

		case 'h':
		default:
			/* -h oder falscher Parameter, Usage anzeigen */
			usage();
			exit(0);
		}
	}
}
Exemplo n.º 21
0
static int __init init_autcpu12_sram (void)
{
	map_word tmp, save0, save1;
	int err;

	autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K);
	if (!autcpu12_sram_map.virt) {
		printk("Failed to ioremap autcpu12 NV-RAM space\n");
		err = -EIO;
		goto out;
	}
	simple_map_init(&autcpu12_sram_map);

	/*
	 * Check for 32K/128K
	 * read ofs 0
	 * read ofs 0x10000
	 * Write complement to ofs 0x100000
	 * Read	and check result on ofs 0x0
	 * Restore contents
	 */
	save0 = map_read(&autcpu12_sram_map, 0);
	save1 = map_read(&autcpu12_sram_map, 0x10000);
	tmp.x[0] = ~save0.x[0];
	map_write(&autcpu12_sram_map, tmp, 0x10000);
	/* if we find this pattern on 0x0, we have 32K size
	 * restore contents and exit
	 */
	tmp = map_read(&autcpu12_sram_map, 0);
	if (!map_word_equal(&autcpu12_sram_map, tmp, save0)) {
		map_write(&autcpu12_sram_map, save0, 0x0);
		goto map;
	}
	/* We have a 128K found, restore 0x10000 and set size
	 * to 128K
	 */
	map_write(&autcpu12_sram_map, save1, 0x10000);
	autcpu12_sram_map.size = SZ_128K;

map:
	sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map);
	if (!sram_mtd) {
		printk("NV-RAM probe failed\n");
		err = -ENXIO;
		goto out_ioremap;
	}

	sram_mtd->owner = THIS_MODULE;
	sram_mtd->erasesize = 16;

	if (mtd_device_register(sram_mtd, NULL, 0)) {
		printk("NV-RAM device addition failed\n");
		err = -ENOMEM;
		goto out_probe;
	}

	printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);

	return 0;

out_probe:
	map_destroy(sram_mtd);
	sram_mtd = 0;

out_ioremap:
	iounmap((void *)autcpu12_sram_map.virt);
out:
	return err;
}
Exemplo n.º 22
0
int main(int argc, char **argv)
{
	int force = 0, lsock, csock, one = 0, jeden = 1, local_port;
	int detach = 1, sa_len, conn_limit = 0, optc;
	char *username = NULL, *bind_host = NULL;
	struct sockaddr *sa;
	struct sockaddr_in laddr, caddr;
	struct sockaddr_in6 laddr6;
	unsigned int caddrlen = sizeof(caddr);
	struct passwd *pw = NULL;
	
	while ((optc = getopt(argc, argv, "1dv46fHs:l:I:i:hu:m:L:A:p:")) != -1) {
		switch (optc) {
			case '1':
				one = 1;
				break;
			case 'd':
				detach = 0;
				break;
			case 'v':
				verbose = 1;
				break;
			case '4':
				break;
			case '6':
				remote_hint = AF_INET;
				local_hint = AF_INET6;
				break;
			case 's':
				source_host = xstrdup(optarg);
				break;
			case 'l':
				bind_host = xstrdup(optarg);
				break;
			case 'f':
				force = 1;
				break;
			case 'i':
				ircpass = xstrdup(optarg);
				clear_argv(argv[optind - 1]);
				break;
			case 'I':
				ircsendpass = xstrdup(optarg);
				clear_argv(argv[optind - 1]);
				break;
			case 'h':
				hexdump = 1;
				break;
			case 'u':
				username = xstrdup(optarg);
				break;
			case 'm':
				map_file = xstrdup(optarg);
				break;
			case 'L':
				conn_limit = atoi(optarg);
				break;
			case 'p':
				pid_file = xstrdup(optarg);
				break;
			case 'H':
				hint_optional = 1;
				break;
			default:
				return 1;
		}
	}

	if (hexdump)
		verbose = 1;

	if (verbose)
		detach = 0;
	
	if (detach)
		verbose = 0;

	if (argc - optind < 2) {
		usage(argv[0]);
		exit(1);
	}

	if (username && !(pw = getpwnam(username))) {
		fprintf(stderr, "%s: unknown user %s\n", argv[0], username);
		exit(1);
	}
  
	if (map_file)
		map_read();
  
	local_port = atoi(argv[optind++]);
	remote_host = argv[optind++];
	remote_port = (argc == optind) ? local_port : atoi(argv[optind]);

	debug("resolving %s\n", remote_host);

	if (!(sa = resolve_host(remote_host, remote_hint)) && !force) {
		fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host);
		exit(1);
	}

	free(sa);
	sa = NULL;

	if (bind_host) {
		debug("resolving %s\n", bind_host);

		if (!(sa = resolve_host(bind_host, local_hint))) {
			fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host);
			exit(1);
		}
	}
 
	debug("local: %s,%d; ", (bind_host) ? bind_host : "default", local_port);
	debug("remote: %s,%d; ", remote_host, remote_port);

	if (map_file)
		debug("source: mapped\n");
	else
		debug("source: %s\n", (source_host) ? source_host : "default");

	if (local_hint == AF_INET) {
		lsock = socket(PF_INET, SOCK_STREAM, 0);

		memset(&laddr, 0, (sa_len = sizeof(laddr)));
		laddr.sin_family = AF_INET;
		laddr.sin_port = htons(local_port);
		
		if (sa) {
			memcpy(&laddr.sin_addr, &((struct sockaddr_in*) sa)->sin_addr, sizeof(struct in_addr));
			free(sa);
		}
		
		sa = (struct sockaddr*) &laddr;
	} else {
		lsock = socket(PF_INET6, SOCK_STREAM, 0);
		
		memset(&laddr6, 0, (sa_len = sizeof(laddr6)));
		laddr6.sin6_family = AF_INET6;
		laddr6.sin6_port = htons(local_port);
		
		if (sa) {
			memcpy(&laddr6.sin6_addr, &((struct sockaddr_in6*) sa)->sin6_addr, sizeof(struct in6_addr));
			free(sa);
		}

		sa = (struct sockaddr*) &laddr6;
	}

	if (setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &jeden, sizeof(jeden)) == -1) {
		perror("setsockopt");
		exit(1);
	}
  
	if (bind(lsock, sa, sa_len)) {
		perror("bind");
		exit(1);
	}    
  
	if (listen(lsock, 100)) {
		perror("listen");
		exit(1);
	}

	if (detach) {
		int i, ret;

		signal(SIGHUP, sighup);
		
		for (i = 0; i < 3; i++)
			close(i);

		ret = fork();
		
		if (ret == -1) {
			perror("fork");
			exit(1);
		}

		if (ret)
			exit(0);
	}

	if (pid_file) {
		FILE *f = fopen(pid_file, "w");

		if (!f)
			debug("warning: cannot write to pidfile (%s)\n", strerror(errno));
		else {
			fprintf(f, "%d", getpid());
			fclose(f);
		}
	}

	if (username && ((setgid(pw->pw_gid) == -1) || (setuid(pw->pw_uid) == -1))) {
		perror("setuid/setgid");
		exit(1);
	}

	setsid();
	signal(SIGCHLD, sigchld);
	signal(SIGTERM, sigterm);
	signal(SIGINT, sigterm);
	signal(SIGHUP, sighup);
    
	for (;;) {  
		int ret;
		fd_set rds;

		FD_ZERO(&rds);
		FD_SET(lsock, &rds);

		if (select(lsock + 1, &rds, NULL, NULL, NULL) == -1) {
			if (errno == EINTR)
				continue;

			perror("select");
			break;
		}

		if ((csock = accept(lsock, (struct sockaddr*) &caddr, &caddrlen)) == -1) {
			perror("accept");
			break;
		}

		inet_ntop(caddr.sin_family, (caddr.sin_family == AF_INET) ?
			&caddr.sin_addr :
			(void*) &(((struct sockaddr_in6*)&caddr)->sin6_addr),
			remote, sizeof(remote));

		debug("<%d> connection from %s,%d", csock, remote, ntohs(caddr.sin_port));

		if (conn_limit && (conn_count >= conn_limit)) {
			debug(" -- rejected due to limit.\n");
			shutdown(csock, 2);
			close(csock);
			continue;
		}
		
		if (conn_limit) {
			conn_count++;
			debug(" (no. %d)", conn_count);
		}
		
		fflush(stdout);
    
		if ((ret = fork()) == -1) {
			debug(" -- fork() failed.\n");
			shutdown(csock, 2);
			close(csock);
			continue;
		}
    
		if (!ret) {
			signal(SIGHUP, SIG_IGN);
			close(lsock);
			debug("\n");
			make_tunnel(csock, remote);
			debug("<%d> connection closed\n", csock);
			exit(0);
		} 

		close(csock);
    
		if (one) {
			shutdown(lsock, 2);
			close(lsock);
			exit(0);
		}

	}

	close(lsock);
  
	exit(1);
}
int main(int argc, char* argv[]) {
/*    int write_buf;
    char read_buf;*/

	// Initialization
    initDevices();
    #ifndef WITHOUT_NETWORK
	initPeerSocket();
	#endif

	usleep(1000000); // delay 3sec
/*
	#ifdef SERVERMODE
	#ifndef WITHOUT_NETWORK
	// Wait for arrival
	waitThreeAxisChange();
	sendStopSignal();
	#endif
	#endif
*/


	// Strart linetracing
	int thr_id[5];
    pthread_t p_threads[5];
/*
	thr_id[0] = pthread_create(&p_threads[0], NULL, detectDistance, (void *)NULL);     
	if (thr_id[0] < 0)     
	{    
		perror("thread1 create error : ");  
		exit(0);    
	}
*/
	thr_id[1] = pthread_create(&p_threads[1], NULL, writeCommand, (void *)NULL);     
	if (thr_id[1] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
/*
	thr_id[2] = pthread_create(&p_threads[2], NULL, findObj, (void *)NULL);     
	if (thr_id[2] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}

	thr_id[3] = pthread_create(&p_threads[3], NULL, backboard, (void *)NULL);     
	if (thr_id[3] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
  	
	thr_id[4] = pthread_create(&p_threads[4], NULL, map_read, (void *)NULL);     
	if (thr_id[4] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
	thr_id[5] = pthread_create(&p_threads[5], NULL, traceLine, (void *)NULL);     
	if (thr_id[5] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
*/
	int status;

	/*
	pthread_join(p_threads[4], (void **)&status);
	pthread_join(p_threads[3], (void **)&status);
	pthread_join(p_threads[0], (void **)&status);
	pthread_join(p_threads[2], (void **)&status);
	pthread_join(p_threads[5], (void **)&status);
	*/
	map_read();
	//pthread_join(p_threads[0], (void **)&status);
	pthread_join(p_threads[1], (void **)&status);
	
	endProgram();

	return 0;
}  
static int autcpu12_nvram_probe(struct platform_device *pdev)
{
	map_word tmp, save0, save1;
	struct resource *res;
	struct autcpu12_nvram_priv *priv;

	priv = devm_kzalloc(&pdev->dev,
			    sizeof(struct autcpu12_nvram_priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	platform_set_drvdata(pdev, priv);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
		dev_err(&pdev->dev, "failed to get memory resource\n");
		return -ENOENT;
	}

	priv->map.bankwidth	= 4;
	priv->map.phys		= res->start;
	priv->map.size		= resource_size(res);
	priv->map.virt = devm_ioremap_resource(&pdev->dev, res);
	strcpy((char *)priv->map.name, res->name);
	if (IS_ERR(priv->map.virt))
		return PTR_ERR(priv->map.virt);

	simple_map_init(&priv->map);

	/*
	 * Check for 32K/128K
	 * read ofs 0
	 * read ofs 0x10000
	 * Write complement to ofs 0x100000
	 * Read	and check result on ofs 0x0
	 * Restore contents
	 */
	save0 = map_read(&priv->map, 0);
	save1 = map_read(&priv->map, 0x10000);
	tmp.x[0] = ~save0.x[0];
	map_write(&priv->map, tmp, 0x10000);
	tmp = map_read(&priv->map, 0);
	/* if we find this pattern on 0x0, we have 32K size */
	if (!map_word_equal(&priv->map, tmp, save0)) {
		map_write(&priv->map, save0, 0x0);
		priv->map.size = SZ_32K;
	} else
		map_write(&priv->map, save1, 0x10000);

	priv->mtd = do_map_probe("map_ram", &priv->map);
	if (!priv->mtd) {
		dev_err(&pdev->dev, "probing failed\n");
		return -ENXIO;
	}

	priv->mtd->owner	= THIS_MODULE;
	priv->mtd->erasesize	= 16;
	priv->mtd->dev.parent	= &pdev->dev;
	if (!mtd_device_register(priv->mtd, NULL, 0)) {
		dev_info(&pdev->dev,
			 "NV-RAM device size %ldKiB registered on AUTCPU12\n",
			 priv->map.size / SZ_1K);
		return 0;
	}

	map_destroy(priv->mtd);
	dev_err(&pdev->dev, "NV-RAM device addition failed\n");
	return -ENOMEM;
}