aboutsummaryrefslogtreecommitdiffstats
path: root/package/system
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-01-19 17:05:03 +0000
committerGabor Juhos <juhosg@openwrt.org>2013-01-19 17:05:03 +0000
commit7eff5d2df0d21f3a54db650e7883548a59183841 (patch)
tree9bedd750488a7a768cefe945e51492b67d99ab0a /package/system
parentf7a943694ff5e370303b27f7093abcc5079385b4 (diff)
downloadupstream-7eff5d2df0d21f3a54db650e7883548a59183841.tar.gz
upstream-7eff5d2df0d21f3a54db650e7883548a59183841.tar.bz2
upstream-7eff5d2df0d21f3a54db650e7883548a59183841.zip
ramips: add kernel support for the Tenda 3G300M
Ralink RT3052F, 4MB flash, 32MB ram, one USB 2.0, two buttons and seven leds. Factory image should be used to flash from original firmware. Signed-off-by: Cezary Jackiewicz <cezary.jackiewicz@gmail.com> Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 35244
Diffstat (limited to 'package/system')
0 files changed, 0 insertions, 0 deletions
>123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
/* 
    Xen Store Daemon Test tool
    Copyright (C) 2005 Rusty Russell IBM Corporation

    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
*/

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fnmatch.h>
#include <stdarg.h>
#include <string.h>
#include <getopt.h>
#include <ctype.h>
#include <sys/time.h>
#include "utils.h"
#include "xs_lib.h"
#include "list.h"

#define XSTEST

static struct xs_handle *handles[10] = { NULL };

static unsigned int timeout_ms = 200;
static bool timeout_suppressed = true;
static bool readonly = false;
static bool print_input = false;
static unsigned int linenum = 0;

struct ringbuf_head
{
	uint32_t write; /* Next place to write to */
	uint32_t read; /* Next place to read from */
	uint8_t flags;
	char buf[0];
} __attribute__((packed));

static struct ringbuf_head *out, *in;
static unsigned int ringbuf_datasize;
static int daemon_pid;

/* FIXME: Mark connection as broken (close it?) when this happens. */
static bool check_buffer(const struct ringbuf_head *h)
{
	return (h->write < ringbuf_datasize && h->read < ringbuf_datasize);
}

/* We can't fill last byte: would look like empty buffer. */
static void *get_output_chunk(const struct ringbuf_head *h,
			      void *buf, uint32_t *len)
{
	uint32_t read_mark;

	if (h->read == 0)
		read_mark = ringbuf_datasize - 1;
	else
		read_mark = h->read - 1;

	/* Here to the end of buffer, unless they haven't read some out. */
	*len = ringbuf_datasize - h->write;
	if (read_mark >= h->write)
		*len = read_mark - h->write;
	return buf + h->write;
}

static const void *get_input_chunk(const struct ringbuf_head *h,
				   const void *buf, uint32_t *len)
{
	/* Here to the end of buffer, unless they haven't written some. */
	*len = ringbuf_datasize - h->read;
	if (h->write >= h->read)
		*len = h->write - h->read;
	return buf + h->read;
}

static int output_avail(struct ringbuf_head *out)
{
	unsigned int avail;

	get_output_chunk(out, out->buf, &avail);
	return avail != 0;
}

static void update_output_chunk(struct ringbuf_head *h, uint32_t len)
{
	h->write += len;
	if (h->write == ringbuf_datasize)
		h->write = 0;
}

static void update_input_chunk(struct ringbuf_head *h, uint32_t len)
{
	h->read += len;
	if (h->read == ringbuf_datasize)
		h->read = 0;
}

/* FIXME: We spin, and we're sloppy. */
static bool read_all_shmem(int fd __attribute__((unused)),
			   void *data, unsigned int len)
{
	unsigned int avail;
	int was_full;

	if (!check_buffer(in))
		barf("Corrupt buffer");

	was_full = !output_avail(in);
	while (len) {
		const void *src = get_input_chunk(in, in->buf, &avail);
		if (avail > len)
			avail = len;
		memcpy(data, src, avail);
		data += avail;
		len -= avail;
		update_input_chunk(in, avail);
	}

	/* Tell other end we read something. */
	if (was_full)
		kill(daemon_pid, SIGUSR2);
	return true;
}

static bool write_all_shmem(int fd __attribute__((unused)),
			    const void *data, unsigned int len)
{
	uint32_t avail;

	if (!check_buffer(out))
		barf("Corrupt buffer");

	while (len) {
		void *dst = get_output_chunk(out, out->buf, &avail);
		if (avail > len)
			avail = len;
		memcpy(dst, data, avail);
		data += avail;
		len -= avail;
		update_output_chunk(out, avail);
	}

	/* Tell other end we wrote something. */
	kill(daemon_pid, SIGUSR2);
	return true;
}

static bool read_all(int fd, void *data, unsigned int len);
static bool read_all_choice(int fd, void *data, unsigned int len)
{
	if (fd == -2)
		return read_all_shmem(fd, data, len);
	return read_all(fd, data, len);
}

static bool write_all_choice(int fd, const void *data, unsigned int len)
{
	if (fd == -2)
		return write_all_shmem(fd, data, len);
	return xs_write_all(fd, data, len);
}

/* We want access to internal functions. */
#include "xs.c"

static void __attribute__((noreturn)) usage(void)
{
	barf("Usage:\n"
	     "       xs_test [--readonly] [--no-timeout] [-x]\n"
	     "Reads commands from stdin, one per line:"
	     "  dir <path>\n"
	     "  read <path>\n"
	     "  write <path> <flags> <value>...\n"
	     "  setid <id>\n"
	     "  mkdir <path>\n"
	     "  rm <path>\n"
	     "  getperm <path>\n"
	     "  setperm <path> <id> <flags> ...\n"
	     "  shutdown\n"
	     "  watch <path> <token>\n"
	     "  waitwatch\n"
	     "  ackwatch <token>\n"
	     "  unwatch <path> <token>\n"
	     "  close\n"
	     "  start <node>\n"
	     "  abort\n"
	     "  introduce <domid> <mfn> <eventchn> <path>\n"
	     "  commit\n"
	     "  sleep <milliseconds>\n"
	     "  expect <pattern>\n"
	     "  notimeout\n"
	     "  readonly\n"
	     "  readwrite\n"
	     "  noackwrite <path> <flags> <value>...\n"
	     "  readack\n"
	     "  dump\n");
}

static int argpos(const char *line, unsigned int num)
{
	unsigned int i, len = 0, off = 0;

	for (i = 0; i <= num; i++) {
		off += len;
		off += strspn(line + off, " \t\n");
		len = strcspn(line + off, " \t\n");
		if (!len)
			return off;
	}
	return off;
}

static char *arg(const char *line, unsigned int num)
{
	static char *args[10];
	unsigned int off, len;

	off = argpos(line, num);
	len = strcspn(line + off, " \t\n");

	if (!len)
		barf("Can't get arg %u", num);

	free(args[num]);
	args[num] = malloc(len + 1);
	memcpy(args[num], line+off, len);
	args[num][len] = '\0';
	return args[num];
}

struct expect
{
	struct list_head list;
	char *pattern;
};
static LIST_HEAD(expects);

static char *command;

/* Trim leading and trailing whitespace */
static void trim(char *str)
{
	while (isspace(str[0]))
		memmove(str, str+1, strlen(str));

	while (strlen(str) && isspace(str[strlen(str)-1]))
		str[strlen(str)-1] = '\0';
}

static void output(const char *fmt, ...)
{
	char *str;
	struct expect *i;
	va_list arglist;

	va_start(arglist, fmt);
	vasprintf(&str, fmt, arglist);
	va_end(arglist);

	printf("%s", str);
	fflush(stdout);
	trim(str);
	list_for_each_entry(i, &expects, list) {
		if (fnmatch(i->pattern, str, 0) == 0) {
			list_del(&i->list);
			free(i);
			return;
		}
	}
	barf("Unexpected output %s\n", str);
}

static void failed(int handle)
{
	if (handle)
		output("%i: %s failed: %s\n",
		       handle, command, strerror(errno));
	else
		output("%s failed: %s\n", command, strerror(errno));
}

static void expect(const char *line)
{
	struct expect *e = malloc(sizeof(*e));

	e->pattern = strdup(line + argpos(line, 1));
	trim(e->pattern);
	list_add(&e->list, &expects);
}

static void do_dir(unsigned int handle, char *path)
{
	char **entries;
	unsigned int i, num;

	entries = xs_directory(handles[handle], path, &num);
	if (!entries) {
		failed(handle);
		return;
	}

	for (i = 0; i < num; i++)
		if (handle)
			output("%i:%s\n", handle, entries[i]);
		else
			output("%s\n", entries[i]);
	free(entries);
}

static void do_read(unsigned int handle, char *path)
{
	char *value;
	unsigned int len;

	value = xs_read(handles[handle], path, &len);
	if (!value) {
		failed(handle);
		return;
	}

	/* It's supposed to nul terminate for us. */
	assert(value[len] == '\0');
	if (handle)
		output("%i:%.*s\n", handle, len, value);
	else
		output("%.*s\n", len, value);
}

static void do_write(unsigned int handle, char *path, char *flags, char *data)
{
	int f;

	if (streq(flags, "none"))
		f = 0;
	else if (streq(flags, "create"))
		f = O_CREAT;
	else if (streq(flags, "excl"))
		f = O_CREAT | O_EXCL;
	else if (streq(flags, "crap"))
		f = 100;
	else
		barf("write flags 'none', 'create' or 'excl' only");

	if (!xs_write(handles[handle], path, data, strlen(data), f))
		failed(handle);
}

static void do_noackwrite(unsigned int handle,
			  char *path, const char *flags, char *data)
{
	struct xsd_sockmsg msg;

	/* Format: Flags (as string), path, data. */
	if (streq(flags, "none"))
		flags = XS_WRITE_NONE;
	else if (streq(flags, "create"))
		flags = XS_WRITE_CREATE;
	else if (streq(flags, "excl"))
		flags = XS_WRITE_CREATE_EXCL;
	else
		barf("noackwrite flags 'none', 'create' or 'excl' only");

	msg.len = strlen(path) + 1 + strlen(flags) + 1 + strlen(data);
	msg.type = XS_WRITE;
	if (!write_all_choice(handles[handle]->fd, &msg, sizeof(msg)))
		failed(handle);
	if (!write_all_choice(handles[handle]->fd, path, strlen(path) + 1))
		failed(handle);
	if (!write_all_choice(handles[handle]->fd, flags, strlen(flags) + 1))
		failed(handle);
	if (!write_all_choice(handles[handle]->fd, data, strlen(data)))
		failed(handle);
	/* Do not wait for ack. */
}

static void do_readack(unsigned int handle)
{
	enum xsd_sockmsg_type type;
	char *ret;

	ret = read_reply(handles[handle]->fd, &type, NULL);
	if (!ret)
		failed(handle);
	free(ret);
}

static void do_setid(unsigned int handle, char *id)
{
	if (!xs_bool(xs_debug_command(handles[handle], "setid", id,
				      strlen(id)+1)))
		failed(handle);
}

static void do_mkdir(unsigned int handle, char *path)
{
	if (!xs_mkdir(handles[handle], path))
		failed(handle);
}

static void do_rm(unsigned int handle, char *path)
{
	if (!xs_rm(handles[handle], path))
		failed(handle);
}

static void do_getperm(unsigned int handle, char *path)
{
	unsigned int i, num;
	struct xs_permissions *perms;

	perms = xs_get_permissions(handles[handle], path, &num);
	if (!perms) {
		failed(handle);
		return;
	}

	for (i = 0; i < num; i++) {
		char *permstring;

		switch (perms[i].perms) {
		case XS_PERM_NONE:
			permstring = "NONE";
			break;
		case XS_PERM_WRITE:
			permstring = "WRITE";
			break;
		case XS_PERM_READ:
			permstring = "READ";
			break;
		case XS_PERM_READ|XS_PERM_WRITE:
			permstring = "READ/WRITE";
			break;
		default:
			barf("bad perm value %i", perms[i].perms);
		}

		if (handle)
			output("%i:%i %s\n", handle, perms[i].id, permstring);
		else
			output("%i %s\n", perms[i].id, permstring);
	}
	free(perms);
}

static void do_setperm(unsigned int handle, char *path, char *line)
{
	unsigned int i;
	struct xs_permissions perms[100];

	strtok(line, " \t\n");
	strtok(NULL, " \t\n");
	for (i = 0; ; i++) {
		char *arg = strtok(NULL, " \t\n");
		if (!arg)
			break;
		perms[i].id = atoi(arg);
		arg = strtok(NULL, " \t\n");
		if (!arg)
			break;
		if (streq(arg, "WRITE"))
			perms[i].perms = XS_PERM_WRITE;
		else if (streq(arg, "READ"))
			perms[i].perms = XS_PERM_READ;
		else if (streq(arg, "READ/WRITE"))
			perms[i].perms = XS_PERM_READ|XS_PERM_WRITE;
		else if (streq(arg, "NONE"))
			perms[i].perms = XS_PERM_NONE;
		else
			barf("bad flags %s\n", arg);
	}

	if (!xs_set_permissions(handles[handle], path, perms, i))
		failed(handle);
}

static void do_shutdown(unsigned int handle)
{
	if (!xs_shutdown(handles[handle]))
		failed(handle);
}

static void do_watch(unsigned int handle, const char *node, const char *token)
{
	if (!xs_watch(handles[handle], node, token))
		failed(handle);
}

static void set_timeout(void)
{
	struct itimerval timeout;

	timeout.it_value.tv_sec = timeout_ms / 1000;
	timeout.it_value.tv_usec = (timeout_ms * 1000) % 1000000;
	timeout.it_interval.tv_sec = timeout.it_interval.tv_usec = 0;
	setitimer(ITIMER_REAL, &timeout, NULL);
}

static void disarm_timeout(void)
{
	struct itimerval timeout;

	timeout.it_value.tv_sec = 0;
	timeout.it_value.tv_usec = 0;
	setitimer(ITIMER_REAL, &timeout, NULL);
}

static void do_waitwatch(unsigned int handle)
{
	char **vec;
	struct timeval tv = {.tv_sec = timeout_ms/1000,
			     .tv_usec = (timeout_ms*1000)%1000000 };
	fd_set set;

	if (xs_fileno(handles[handle]) != -2) {
		/* Manually select here so we can time out gracefully. */
		FD_ZERO(&set);
		FD_SET(xs_fileno(handles[handle]), &set);
		disarm_timeout();
		if (select(xs_fileno(handles[handle])+1, &set,
			   NULL, NULL, &tv) == 0) {
			errno = ETIMEDOUT;
			failed(handle);
			return;
		}
		set_timeout();
	}

	vec = xs_read_watch(handles[handle]);
	if (!vec) {
		failed(handle);
		return;
	}

	if (handle)
		output("%i:%s:%s\n", handle, vec[0], vec[1]);
	else
		output("%s:%s\n", vec[0], vec[1]);
	free(vec);
}

static void do_ackwatch(unsigned int handle, const char *token)
{
	if (!xs_acknowledge_watch(handles[handle], token))
		failed(handle);
}

static void do_unwatch(unsigned int handle, const char *node, const char *token)
{
	if (!xs_unwatch(handles[handle], node, token))
		failed(handle);
}

static void do_start(unsigned int handle, const char *node)
{
	if (!xs_transaction_start(handles[handle], node))
		failed(handle);
}

static void do_end(unsigned int handle, bool abort)
{
	if (!xs_transaction_end(handles[handle], abort))
		failed(handle);
}

static void do_introduce(unsigned int handle,
			 const char *domid,
			 const char *mfn,
			 const char *eventchn,
			 const char *path)
{
	unsigned int i;
	int fd;

	/* This mechanism is v. slow w. valgrind running. */
	timeout_ms = 5000;

	/* We poll, so ignore signal */
	signal(SIGUSR2, SIG_IGN);
	for (i = 0; i < ARRAY_SIZE(handles); i++)
		if (!handles[i])
			break;

	fd = open("/tmp/xcmap", O_RDWR);
	/* Set in and out pointers. */
	out = mmap(NULL, getpagesize(), PROT_WRITE|PROT_READ, MAP_SHARED,fd,0);
	if (out == MAP_FAILED)
		barf_perror("Failed to map /tmp/xcmap page");
	in = (void *)out + getpagesize() / 2;
	close(fd);

	/* Tell them the event channel and our PID. */
	*(int *)((void *)out + 32) = getpid();
	*(u16 *)((void *)out + 36) = atoi(eventchn);

	if (!xs_introduce_domain(handles[handle], atoi(domid),
				 atol(mfn), atoi(eventchn), path)) {
		failed(handle);
		munmap(out, getpagesize());
		return;
	}
	output("handle is %i\n", i);

	/* Create new handle. */
	handles[i] = new(struct xs_handle);
	handles[i]->fd = -2;

	/* Read in daemon pid. */
	daemon_pid = *(int *)((void *)out + 32);
}

static void do_release(unsigned int handle, const char *domid)
{
	if (!xs_release_domain(handles[handle], atoi(domid)))