Exemplo n.º 1
0
static void find_dev(char *path)
{
	DIR *dir;
	int len=strlen(path);

	if (!(dir = opendir(path)))
		bb_perror_msg_and_die("No %s",path);

	for (;;) {
		struct dirent *entry = readdir(dir);
		
		if (!entry) break;

		/* Skip "." and ".." (also skips hidden files, which is ok) */

		if (entry->d_name[0]=='.') continue;

		if (entry->d_type == DT_DIR) {
			snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
			find_dev(path);
			path[len] = 0;
		}
		
		/* If there's a dev entry, mknod it */
		
		if (strcmp(entry->d_name, "dev")) make_device(path);
	}
	
	closedir(dir);
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: 3a9LL/panda
static void
encode_bootpath( const char *spec, const char *args )
{
	phandle_t chosen_ph = find_dev("/chosen");
	set_property( chosen_ph, "bootpath", spec, strlen(spec)+1 );
	set_property( chosen_ph, "bootargs", args, strlen(args)+1 );
}
Exemplo n.º 3
0
/* ( -- success? ) */
static void
scsi_open( instance_data_t *sd )
{
    static int once = 0;
    phandle_t ph;

    fword("my-unit");
    sd->target = POP();

    if( !once ) {
        once++;
        OSI_SCSIControl( SCSI_CTRL_INIT, 0 );
    }

    /* obtiain device information */
    if( inquiry(sd) )
        RET(0);

    selfword("open-deblocker");

    /* interpose disk-label */
    ph = find_dev("/packages/disk-label");
    fword("my-args");
    PUSH_ph( ph );
    fword("interpose");

    PUSH( -1 );
}
Exemplo n.º 4
0
// Is the address within one of the flash drivers?
__externC int
cyg_flash_verify_addr(const cyg_flashaddr_t address)
{
  int stat = CYG_FLASH_ERR_OK;
  (void) find_dev(address, &stat);
  return stat;
}
Exemplo n.º 5
0
static void check_preloaded_kernel(void)
{
    unsigned long kernel_image, kernel_size;
    unsigned long initrd_image, initrd_size;
    const char * kernel_cmdline;
    volatile struct context *ctx = __context;

    kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE);
    if (kernel_size) {
        kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR);
        kernel_cmdline = (const char *)(uintptr_t) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE);
        initrd_image = fw_cfg_read_i32(FW_CFG_INITRD_ADDR);
        initrd_size = fw_cfg_read_i32(FW_CFG_INITRD_SIZE);
        printk("[ppc] Kernel already loaded (0x%8.8lx + 0x%8.8lx) "
               "(initrd 0x%8.8lx + 0x%8.8lx)\n",
               kernel_image, kernel_size, initrd_image, initrd_size);
        if (kernel_cmdline) {
               phandle_t ph;
	       printk("[ppc] Kernel command line: %s\n", kernel_cmdline);
	       ph = find_dev("/chosen");
               set_property(ph, "bootargs", strdup(kernel_cmdline), strlen(kernel_cmdline) + 1);
        }

        arch_init_program();
        ctx->regs[REG_R3] = initrd_image;
        ctx->regs[REG_R4] = initrd_size;
        ctx->pc = kernel_image;

        start_elf();
    }
}
Exemplo n.º 6
0
static void
ob_sd_open(ATTRIBUTE_UNUSEDsd_private_t **sd)
{
    int ret = 1, id;
    phandle_t ph;

    fword("my-unit");
    id = POP();
    POP(); // unit id is 2 ints but we only need one.
    *sd = &global_esp->sd[id];

#ifdef CONFIG_DEBUG_ESP
    {
        char *args;

        fword("my-args");
        args = pop_fstr_copy();
        DPRINTF("opening drive %d args %s\n", id, args);
        free(args);
    }
#endif

    selfword("open-deblocker");

    /* interpose disk-label */
    ph = find_dev("/packages/disk-label");
    fword("my-args");
    PUSH_ph( ph );
    fword("interpose");

    RET ( -ret );
}
Exemplo n.º 7
0
Arquivo: src.c Projeto: QXIP/baresip
int winwave_src_alloc(struct ausrc_st **stp, struct ausrc *as,
		      struct media_ctx **ctx,
		      struct ausrc_prm *prm, const char *device,
		      ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
{
	struct ausrc_st *st;
	int err;

	(void)ctx;
	(void)errh;

	if (!stp || !as || !prm)
		return EINVAL;

	st = mem_zalloc(sizeof(*st), ausrc_destructor);
	if (!st)
		return ENOMEM;

	st->as  = mem_ref(as);
	st->rh  = rh;
	st->arg = arg;

	err = read_stream_open(st, prm, find_dev(device));

	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
Exemplo n.º 8
0
static void
rtc_init(char *path)
{
	phandle_t ph, aliases;
	char buf[64];

        snprintf(buf, sizeof(buf), "%s/rtc", path);
	REGISTER_NAMED_NODE(rtc, buf);

	ph = find_dev(buf);
	set_property(ph, "device_type", "rtc", 4);
	set_property(ph, "compatible", "rtc", 4);

	aliases = find_dev("/aliases");
	set_property(aliases, "rtc", buf, strlen(buf) + 1);

}
Exemplo n.º 9
0
int main(void)
{
	struct usb_device *dev;
	usb_dev_handle *handle;
	uint16_t iface;
	int state;
	uint32_t offset;

	banner();
	usb_init();

retry:
	if(!(dev = find_dev()) || !(handle = get_dfu_interface(dev, &iface))) {
		puts("FATAL: No compatible device found!\n");
#ifdef WIN32
		system("pause");
#endif
		return -1;
	}

	state = dfu_getstate(handle, iface);
	if((state < 0) || (state == STATE_APP_IDLE)) {
		puts("Resetting device in firmware upgrade mode...");
		dfu_detach(handle, iface, 1000);
		usb_release_interface(handle, iface);
		usb_close(handle);
#ifdef WIN32
		Sleep(5000);
#else
		sleep(5);
#endif
		goto retry;
	}
	printf("Found device at %s:%s\n", dev->bus->dirname, dev->filename);

	dfu_makeidle(handle, iface);

	for(offset = 0; offset < bindatalen; offset += 1024) {
		printf("Progress: %d%%\r", (offset*100)/bindatalen);
		fflush(stdout);
		assert(stm32_mem_erase(handle, iface, LOAD_ADDRESS + offset) == 0);
		stm32_mem_write(handle, iface, (void*)&bindata[offset], 1024);
	}
	stm32_mem_manifest(handle, iface);

	usb_release_interface(handle, iface);
	usb_close(handle);

	puts("All operations complete!\n");

#ifdef WIN32
		system("pause");
#endif

	return 0;
}
Exemplo n.º 10
0
int mdev_main(int argc, char *argv[])
{
	if (argc > 1) {
		if (argc == 2 && !strcmp(argv[1],"-s")) {
			RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
			strcpy(temp,"/sys/block");
			find_dev(temp);
			strcpy(temp,"/sys/class");
			find_dev(temp);
			if(ENABLE_FEATURE_CLEAN_UP)
				RELEASE_CONFIG_BUFFER(temp);
			return 0;
		} else bb_show_usage();
	} 
	
/* hotplug support goes here */
	
	return 0;
}
Exemplo n.º 11
0
// Return the size of the block which is at the given address
__externC size_t
cyg_flash_block_size(const cyg_flashaddr_t flash_base)
{
  struct cyg_flash_dev *    dev;
  int                       stat;

  dev = find_dev(flash_base, &stat);
  if (!dev) return stat;
  return flash_block_size(dev, flash_base);
}
Exemplo n.º 12
0
t_stat
ng_reset(DEVICE *dptr)
{
  DEVICE *dptr2;
  t_stat r;

  if (dptr->flags & DEV_DIS) {
    sim_cancel (dptr->units);
    return auto_config ("NG", (dptr->flags & DEV_DIS) ? 0 : 1);;
  }

  dptr2 = find_dev ("VT");
  if ((dptr2 != NULL) && !(dptr2->flags & DEV_DIS)) {
    dptr->flags |= DEV_DIS;
    return sim_messagef (SCPE_NOFNC, "NG and VT device can't both be enabled\n");
    }
  dptr2 = find_dev ("CH");
  if ((dptr2 != NULL) && !(dptr2->flags & DEV_DIS)) {
    dptr->flags |= DEV_DIS;
    return sim_messagef (SCPE_ALATT, "NG device in conflict with CH.\n");
    }

  r = auto_config ("NG", (dptr->flags & DEV_DIS) ? 0 : 1);;
  if (r != SCPE_OK) {
    dptr->flags |= DEV_DIS;
    return r;
    }

  if (!ng_inited && !ng_init(dptr, DEB_TRC))
      return sim_messagef (SCPE_ALATT, "Display already in use.\n");
  ng_inited = TRUE;

  CLR_INT (NG);
  ng_unit.wait = 100;
  sim_activate (dptr->units, 1);

  set_cmd (0, "DZ DISABLED"); /* Conflict with NG. */
  set_cmd (0, "HK DISABLED"); /* Conflict with RF. */

  vid_register_quit_callback (&ng_quit_callback);

  return SCPE_OK;
}
Exemplo n.º 13
0
static void
powermgt_init(char *path)
{
	phandle_t ph;
	char buf[64];

        snprintf(buf, sizeof(buf), "%s/power-mgt", path);
	REGISTER_NAMED_NODE(rtc, buf);

	ph = find_dev(buf);
	set_property(ph, "device_type", "power-mgt", 10);
	set_property(ph, "mgt-kind", "min-consumption-pwm-led", strlen("min-consumption-pwm-led") + 1);
	set_property(ph, "compatible", "cuda", strlen("cuda") + 1);
}
Exemplo n.º 14
0
// Return information about the flash at the given address
__externC int
cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base, cyg_flash_info_t * info)
{
  struct cyg_flash_dev *dev;
  int                   stat = CYG_FLASH_ERR_OK;

  dev = find_dev(flash_base, &stat);
  if (dev) {
    info->start = dev->start;
    info->end = dev->end;
    info->num_block_infos = dev->num_block_infos;
    info->block_info = dev->block_info;
  }
  return stat;
}
Exemplo n.º 15
0
void
arch_of_init( void )
{
#if USE_RTAS
	phandle_t ph;
#endif
	int autoboot;

	devtree_init();
	node_methods_init();
	modules_init();
        setup_timers();
#ifdef CONFIG_DRIVER_PCI
	ob_pci_init();
#endif

#if USE_RTAS
	if( !(ph=find_dev("/rtas")) )
		printk("Warning: No /rtas node\n");
	else {
		ulong size = 0x1000;
		while( size < (ulong)of_rtas_end - (ulong)of_rtas_start )
			size *= 2;
		set_property( ph, "rtas-size", (char*)&size, sizeof(size) );
	}
#endif

#if 0
	/* tweak boot settings */
	autoboot = !!get_bool_res("autoboot");
#endif
	autoboot = 0;
	if( !autoboot )
		printk("Autobooting disabled - dropping into OpenFirmware\n");
	setenv("auto-boot?", autoboot ? "true" : "false" );
	setenv("boot-command", "briqboot");

#if 0
	if( get_bool_res("tty-interface") == 1 )
#endif
		fword("activate-tty-interface");

	/* hack */
	device_end();
	bind_func("briqboot", boot );
}
Exemplo n.º 16
0
recvjob()
{
	struct stat stb;
	char *bp = pbuf;
	int status, rcleanup();

	/*
	 * Perform lookup for printer name or abbreviation
	 */
	if ((status = pgetent(line, printer)) < 0)
		frecverr("cannot open printer description file");
	else if (status == 0)
		frecverr("unknown printer %s", printer);
	if ((LF = pgetstr("lf", &bp)) == NULL)
		LF = DEFLOGF;
	if ((SD = pgetstr("sd", &bp)) == NULL)
		SD = DEFSPOOL;
	if ((LO = pgetstr("lo", &bp)) == NULL)
		LO = DEFLOCK;

	(void) close(2);			/* set up log file */
	if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
		syslog(LOG_ERR, "%s: %m", LF);
		(void) open("/dev/null", O_WRONLY);
	}

	if (chdir(SD) < 0)
		frecverr("%s: %s: %m", printer, SD);
	if (stat(LO, &stb) == 0) {
		if (stb.st_mode & 010) {
			/* queue is disabled */
			putchar('\1');		/* return error code */
			exit(1);
		}
	} else if (stat(SD, &stb) < 0)
		frecverr("%s: %s: %m", printer, SD);
	minfree = read_number("minfree");
	ddev = find_dev(stb.st_dev, S_IFBLK);
	if ((dfd = open(ddev, O_RDONLY)) < 0)
		syslog(LOG_WARNING, "%s: %s: %m", printer, ddev);
	signal(SIGTERM, rcleanup);
	signal(SIGPIPE, rcleanup);

	if (readjob())
		printjob();
}
Exemplo n.º 17
0
void *
sfx_find_device(int type, char *name)
{
	struct _midi_device *dev = find_dev(type, name);

	if (dev) {
		if (dev->init(dev)) {
			fprintf(stderr, "[SFX] Opening device '%s' failed\n",
				dev->name);
			return NULL;
		}

		return dev;
	};
	
	return NULL;
}
Exemplo n.º 18
0
void
ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base,
                  uint64_t offset, int intr)
{
    phandle_t aliases;
    char nodebuff[128];

    snprintf(nodebuff, sizeof(nodebuff), "%s/%s", path, dev_name);
    REGISTER_NAMED_NODE(pc_serial, nodebuff);

    push_str(nodebuff);
    fword("find-device");

    PUSH(offset);
    PUSH(find_package_method("init", get_cur_dev()));
    fword("execute");

    push_str("serial");
    fword("device-type");

    PUSH((base + offset) >> 32);
    fword("encode-int");
    PUSH((base + offset) & 0xffffffff);
    fword("encode-int");
    fword("encode+");
    PUSH(SER_SIZE);
    fword("encode-int");
    fword("encode+");
    push_str("reg");
    fword("property");
    
#if !defined(CONFIG_SPARC64)
    PUSH(offset);
    fword("encode-int");
    push_str("address");
    fword("property");
#endif
    
#if defined(CONFIG_SPARC64)
    set_int_property(get_cur_dev(), "interrupts", 1);
#endif

    aliases = find_dev("/aliases");
    set_property(aliases, "ttya", nodebuff, strlen(nodebuff) + 1);
}
Exemplo n.º 19
0
// Lock the mutex's for a range of addresses
__externC int
cyg_flash_mutex_lock(const cyg_flashaddr_t from, size_t len)
{
  struct cyg_flash_dev *    dev;
  int                       stat    = CYG_FLASH_ERR_OK;

  dev = find_dev(from, &stat);
  if (dev) {
    LOCK(dev);
    if (len > (dev->end + 1 - from)) {
      stat = cyg_flash_mutex_lock(dev->end + 1, len - (dev->end + 1 - from));
      if (CYG_FLASH_ERR_OK != stat) {
        // Something went wrong, unlock what we just locked
        UNLOCK(dev);
      }
    }
  }
  return stat;
}
Exemplo n.º 20
0
int sinwave_src_alloc(struct ausrc_st **stp, const struct ausrc *as,
		      struct media_ctx **ctx,
		      struct ausrc_prm *prm, const char *device,
		      ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
{
	struct ausrc_st *st;
	int err;

	(void)ctx;
	(void)errh;

	if (!stp || !as || !prm)
		return EINVAL;

	st = mem_zalloc(sizeof(*st), ausrc_destructor);
	if (!st)
		return ENOMEM;

	st->as  = as;
	st->rh  = rh;
	st->arg = arg;

	st->srate = prm->srate;
	st->ptime = prm->ptime;
	st->sampc = prm->srate * prm->ch * prm->ptime / 1000;
	
	// Initialize Wave Generator
	st->gen.amplitude   = 0.2f;
	st->gen.Hz          = 440.0f;
	st->gen.sample_rate = (float) prm->srate; //(float)(prm->srate * prm->ch * prm->ptime / 1000);

	err = read_stream_open(st, prm, find_dev(device));
//	st->hThread = CreateThread(NULL, 4096, sin_thread, st, 0, NULL);
//	err = (st->hThread == NULL);

	if (err) {
		mem_deref(st);
		st->rh = false;
	} else
		*stp = st;

	return err;
}
Exemplo n.º 21
0
cuda_t *cuda_init (const char *path, phys_addr_t base)
{
	cuda_t *cuda;
	char buf[64];
	phandle_t aliases;

	base += IO_CUDA_OFFSET;
	CUDA_DPRINTF(" base=" FMT_plx "\n", base);
	cuda = malloc(sizeof(cuda_t));
	if (cuda == NULL)
	    return NULL;

	snprintf(buf, sizeof(buf), "%s/via-cuda", path);
	REGISTER_NAMED_NODE(ob_cuda, buf);

	aliases = find_dev("/aliases");
	set_property(aliases, "via-cuda", buf, strlen(buf) + 1);

	cuda->base = base;
	cuda_writeb(cuda, B, cuda_readb(cuda, B) | TREQ | TIP);
#ifdef CONFIG_DRIVER_ADB
	cuda->adb_bus = adb_bus_new(cuda, &cuda_adb_req);
	if (cuda->adb_bus == NULL) {
	    free(cuda);
	    return NULL;
	}
	adb_bus_init(buf, cuda->adb_bus);
#endif

	rtc_init(buf);
	powermgt_init(buf);

        main_cuda = cuda;

	device_end();
	bind_func("poweroff", ppc32_poweroff);

	return cuda;
}
Exemplo n.º 22
0
// Set a printf function to use for a particular device,
// which is associated with the supplied base address
__externC int
cyg_flash_set_printf(const cyg_flashaddr_t flash_base,
                     cyg_flash_printf *pf)
{
  struct cyg_flash_dev *dev;
  int                   stat = CYG_FLASH_ERR_OK;

  dev = find_dev(flash_base, &stat);
  if (dev) {
    // Locking may seem like overkill, but if there's any chance of CHATTER
    // mid-change then bad things are theoretically possible. But we only
    // lock if this device is usable, i.e. it's been initialised.
    if (dev->init) {
      LOCK(dev);
    }
    dev->pf = pf;
    if (dev->init) {
      UNLOCK(dev);
    }
  }
  return stat;
}
Exemplo n.º 23
0
// Unlock the mutex's for a range of addresses
__externC int
cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len)
{
  struct cyg_flash_dev *    dev;
  int                       stat = CYG_FLASH_ERR_OK;

  dev = find_dev(from, &stat);
  if (dev) {
    UNLOCK(dev);
    if (len > (dev->end + 1 - from)) {
      stat = cyg_flash_mutex_lock(dev->end + 1, len - (dev->end + 1 - from));
      if (CYG_FLASH_ERR_OK != stat) {
        // Something went wrong, relock what we just unlocked. This may not
        // be worth it since things must be pretty messed up, and could
        // conceivably end in deadlock if there is a concurrent call to
        // cyg_flash_mutex_lock();
        LOCK(dev);
      }
    }
  }
  return stat;
}
Exemplo n.º 24
0
usb_dev_handle *dpf_usb_open(void)
{
    struct usb_device *d;
	usb_dev_handle *usb_dev;

    usb_init();
    usb_find_busses();
    usb_find_devices();

    d = find_dev();
    if (!d) {
		handle_error("No matching USB device found!");
		return NULL;
	}

	usb_dev = usb_open(d);
	if (usb_dev == NULL) {
		handle_error("Failed to open usb device!");
		return NULL;
	}
	return usb_dev;
}
Exemplo n.º 25
0
int winwave_play_alloc(struct auplay_st **stp, const struct auplay *ap,
		       struct auplay_prm *prm, const char *device,
		       auplay_write_h *wh, void *arg)
{
	struct auplay_st *st;
	int i, err;

	if (!stp || !ap || !prm)
		return EINVAL;

	st = mem_zalloc(sizeof(*st), auplay_destructor);
	if (!st)
		return ENOMEM;

	st->ap  = ap;
	st->wh  = wh;
	st->arg = arg;

	err = write_stream_open(st, prm, find_dev(device));
	if (err)
		goto out;

	/* The write runs at 100ms intervals
	 * prepare enough buffers to suite its needs
	 */
	for (i = 0; i < 5; i++)
		dsp_write(st);

 out:
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
Exemplo n.º 26
0
unsigned
bus_config(const char *configfile,
	   const char *configextra[], unsigned numconfigextra)
{
	char *s;
	const struct bus_device *dev;
	char buf[1024], *argv[MAXARGS];
	int argc, slot, line=0;
	unsigned i;
	FILE *f;

	for (i=0; i<numconfigextra; i++) {
		s = strchr(configextra[i], ':');
		Assert(s);
		*s = 0;
		slot = atoi(configextra[i]);
		if (slot < 0 || slot >= LAMEBUS_NSLOTS) {
			*s = ':';
			msg("-C %s: Invalid slot number (0-31 allowed)",
			    configextra[i]);
			die();
		}
		*s = ':';
	}

	f = fopen(configfile, "r");
	if (!f) {
		msg("Cannot open config file %s", configfile);
		die();
	}

	while (fgets(buf, sizeof(buf),f)) {
		line++;
		s = strchr(buf, '#');
		if (s) *s = 0;
		argc=0;
		for (s=strtok(buf, " \t\r\n"); s; s=strtok(NULL, " \t\r\n")) {
			if (argc<MAXARGS) argv[argc++] = s;
		}
		if (argc>=MAXARGS) {
			msg("config %s: line %d: Too many args", 
			    configfile, line);
			die();
		}
		argv[argc] = NULL;
		if (argc==0) continue;

		slot = strtol(argv[0], &s, 0);
		if (strlen(s)>0 || slot<0 || slot>=LAMEBUS_NSLOTS) {
			msg("config %s: line %d: Invalid slot `%s' (should "
			    "be 0-%d)", 
			    configfile, line, argv[0], LAMEBUS_NSLOTS-1);
			die();
		}
      
		if (argc==1) {
			msg("config %s: line %d: slot %d: No device", 
			    configfile, line, slot);
			die();
		}

		if (devices[slot].ls_info!=NULL) {
			msg("config %s: line %d: slot %d: Already in use",
			    configfile, line, slot);
			die();
		}
		
		dev = find_dev(argv[1]);
		if (!dev) {
			msg("config %s: line %d: slot %d: No such "
			    "hardware `%s'", 
			    configfile, line, slot, argv[1]);
			die();
		}

		for (i=0; i<numconfigextra; i++) {
			if (configextra[i] == NULL) {
				continue;
			}
			s = strchr(configextra[i], ':');
			Assert(s != NULL);
			*s = 0;
			if (atoi(configextra[i]) == slot) {
				if (argc >= MAXARGS) {
					*s = ':';
					msg("-S %s: too many args for "
					    "this slot", configextra[i]);
					die();
				}
				argv[argc++] = s+1;
				configextra[i] = NULL;
			}
			else {
				*s = ':';
			}
		}
		
		{
			int isbus = dev->dev_iscontroller;
			int isbusslot = slot==LAMEBUS_CONTROLLER_SLOT;

			if ((isbus && !isbusslot) || (!isbus && isbusslot)) {
				msg("config %s: line %d: slot %d: "
				    "%s: Bus controller must "
				    "go in slot %d", 
				    configfile, line, slot, argv[1], 
				    LAMEBUS_CONTROLLER_SLOT);
				die();
			}
		}
		
		devices[slot].ls_info = dev->dev_info;
		devices[slot].ls_devdata = 
			dev->dev_info->ldi_init(slot, argc-1, argv+1);
	}
	
	fclose(f);

	for (i=0; i<numconfigextra; i++) {
		if (configextra[i] == NULL) {
			continue;
		}
		msg("-C %s: No device in that slot", configextra[i]);
		die();
	}
	
	if (bus_ramsize == 0) {
		msg("config %s: No system memory", configfile);
		die();
	}
	if (bus_ramsize & 0xfff) {
		msg("config %s: System memory size not page-aligned", 
		    configfile);
		die();
	}
	if (bus_ramsize > MAXMEM) {
		msg("config %s: System memory too large", configfile);
		die();
	}
	
	ram = calloc(bus_ramsize, 1);
	if (!ram) {
		msg("config %s: Cannot allocate system memory", configfile);
		die();
	}

	return ncpus;
}
Exemplo n.º 27
0
static int host_size_cells(void)
{
    return get_int_property(find_dev("/"), "#size-cells", NULL);
}
Exemplo n.º 28
0
static int host_address_cells(void)
{
    return get_int_property(find_dev("/"), "#address-cells", NULL);
}
Exemplo n.º 29
0
void setup_romvec(void)
{
	/* SPARC32 is slightly unusual in that before invoking any loaders, a romvec array
	   needs to be set up to pass certain parameters using a C struct. Hence this function
	   extracts the relevant boot information and places it in obp_arg. */

	int intprop, proplen, target, device, i;
	unsigned int *intprop_ptr;
	phandle_t chosen;
	char *prop, *id, *name;
	static char bootpathbuf[128], bootargsbuf[128], buf[128];
	struct linux_mlist_v0 **pp;

	/* Get the stdin and stdout paths */
	chosen = find_dev("/chosen");
	intprop = get_int_property(chosen, "stdin", &proplen);
	PUSH(intprop);
	fword("get-instance-path");
	((struct linux_romvec *)romvec)->pv_stdin = pop_fstr_copy();

	intprop = get_int_property(chosen, "stdout", &proplen);
	PUSH(intprop);
	fword("get-instance-path");
	((struct linux_romvec *)romvec)->pv_stdout = pop_fstr_copy();

	/* Get the name of the selected boot device, along with the device and unit number */
	prop = get_property(chosen, "bootpath", &proplen);
	strncpy(bootpathbuf, prop, proplen);
	prop = get_property(chosen, "bootargs", &proplen);
	strncpy(bootargsbuf, prop, proplen);	

	/* Set bootpath pointer used in romvec table to the bootpath */
        push_str(bootpathbuf);
        fword("pathres-resolve-aliases");
        bootpath = pop_fstr_copy();
        printk("bootpath: %s\n", bootpath);

	/* Now do some work to get hold of the target, partition etc. */
	push_str(bootpathbuf);
	feval("open-dev");
	feval("ihandle>boot-device-handle drop to my-self");
	push_str("name");
	fword("get-my-property");
	POP();
	name = pop_fstr_copy();

        if (!strncmp(name, "sd", 2)) {

		/*
		  Old-style SunOS disk paths are given in the form:

			sd(c,t,d):s

		  where:
		    c = controller (Nth controller in system, usually 0)
		    t = target (my-unit phys.hi)
		    d = device/LUN (my-unit phys.lo)
		    s = slice/partition (my-args)
		*/

		/* Controller currently always 0 */
		obp_arg.boot_dev_ctrl = 0;

		/* Get the target, device and slice */
		fword("my-unit");
		target = POP();
		device = POP();

		fword("my-args");
		id = pop_fstr_copy();

		if (id != NULL) {
			snprintf(buf, sizeof(buf), "sd(0,%d,%d):%c", target, device, id[0]);
			obp_arg.dev_partition = id[0] - 'a';
		} else {
			snprintf(buf, sizeof(buf), "sd(0,%d,%d)", target, device);
			obp_arg.dev_partition = 0;
		}

		obp_arg.boot_dev_unit = target;

		obp_arg.boot_dev[0] = buf[0];
		obp_arg.boot_dev[1] = buf[1];
		obp_arg.argv[0] = buf;
        	obp_arg.argv[1] = bootargsbuf;

        } else if (!strncmp(name, "SUNW,fdtwo", 10)) {
		
		obp_arg.boot_dev_ctrl = 0;
		obp_arg.boot_dev_unit = 0;
		obp_arg.dev_partition = 0;

		strcpy(buf, "fd()");

		obp_arg.boot_dev[0] = buf[0];
		obp_arg.boot_dev[1] = buf[1];
		obp_arg.argv[0] = buf;
        	obp_arg.argv[1] = bootargsbuf;

        } else if (!strncmp(name, "le", 2)) {

		obp_arg.boot_dev_ctrl = 0;
		obp_arg.boot_dev_unit = 0;
		obp_arg.dev_partition = 0;

		strcpy(buf, "le()");

		obp_arg.boot_dev[0] = buf[0];
		obp_arg.boot_dev[1] = buf[1];
		obp_arg.argv[0] = buf;
        	obp_arg.argv[1] = bootargsbuf;

	}

	/* Generate the totphys (total memory available) list */
	prop = get_property(s_phandle_memory, "reg", &proplen);
	intprop_ptr = (unsigned int *)prop;

	for (pp = &totphyslist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) {
		*pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0));
		(**pp).theres_more = NULL;
		(**pp).start_adr = (char *)intprop_ptr[1];
		(**pp).num_bytes = intprop_ptr[2];

		intprop_ptr += 3;
	}

	/* Generate the avail (physical memory available) list */
	prop = get_property(s_phandle_memory, "available", &proplen);
	intprop_ptr = (unsigned int *)prop;

	for (pp = &availlist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) {
		*pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0));
		(**pp).theres_more = NULL;
		(**pp).start_adr = (char *)intprop_ptr[1];
		(**pp).num_bytes = intprop_ptr[2];

		intprop_ptr += 3;
	}

	/* Generate the prommap (taken virtual memory) list from inverse of available */
	prop = get_property(s_phandle_mmu, "available", &proplen);
	intprop_ptr = (unsigned int *)prop;

	for (pp = &prommaplist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) {
		*pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0));
		(**pp).theres_more = NULL;
		(**pp).start_adr = (char *)(intprop_ptr[1] + intprop_ptr[2]);

		if (i + 3 < (proplen / sizeof(int))) {
			/* Size from next entry */
			(**pp).num_bytes = (intprop_ptr[4] + intprop_ptr[5]) - (intprop_ptr[1] + intprop_ptr[2]);
		} else {
			/* Tail (size from top of virtual memory) */
			(**pp).num_bytes = ofmem_arch_get_virt_top() - 1 - (intprop_ptr[1] + intprop_ptr[2]) + 1;
		}

		intprop_ptr += 3;
	}

	/* Finally set the memory properties */
	((struct linux_romvec *)romvec)->pv_v0mem.v0_totphys = &totphyslist;
	((struct linux_romvec *)romvec)->pv_v0mem.v0_available = &availlist;
	((struct linux_romvec *)romvec)->pv_v0mem.v0_prommap = &prommaplist;
}
Exemplo n.º 30
0
int raw_init(struct k_capture *p_capture, char *device)
{
    struct ifreq ifr;
    struct packet_mreq mr;
    struct sockaddr_ll sll;
    int raw_socket;
    int ifindex;

    if (p_capture->name) {
	    free(p_capture->name);
	    p_capture->name = NULL;
    }

/*  
  if(p_capture->file_status){
    free(p_capture->file_status);
    p_capture = NULL;
  }
*/

    if (strcmp(device, "auto")) {
	    p_capture->interface_auto = 0;
	    /*
	       p_capture->file_status = NULL;
	     */
	    if ((p_capture->name = (char *) malloc(strlen(device) * sizeof(char) + 1)) == NULL) {
	        fprintf(stderr,"Raw_init(): Error malloc p_capture->name: %s\n",strerror(errno));
	        return 1;
	    }
	    strcpy(p_capture->name, device);
    } else {
	    char *file = NULL;
	    if ((file = find_dev(file)) == NULL) return 1;
	    if ((p_capture->name = (char *) malloc(strlen(file) * sizeof(char) + 1)) == NULL) {
	        fprintf(stderr, "Raw_init(): Error malloc: %s\n",strerror(errno));
	        return 1;
	    }
	    strcpy(p_capture->name, file);
	    p_capture->interface_auto = 1;

/*    
    if((p_capture->file_status=(char*) malloc(strlen(DEVDIR)*strlen(file)*strlen(FILEOPERSTATE)*sizeof(char) + 1)) == NULL){
      fprintf(stderr,"Raw_init(): Error malloc p_capture->filestatus: %s\n", strerror(errno));
      return 1;
    }
    if(sprintf(p_capture->file_status,"%s%s/%s",DEVDIR, file, FILEOPERSTATE) < 0){
      fprintf(stderr,"raw_init(): Error sprintf: %s\n", strerror(errno));
      return 0;
    }
*/
	    if (!file) {
	        free(file);
	        file = NULL;
	    }
    }

    memset(&ifr, 0, sizeof(struct ifreq));
    memset(&mr, 0, sizeof(struct packet_mreq));

    if ((raw_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 1) {
	    fprintf(stderr, "ERROR: Could not open socket, Got ?\n");
	    return 1;
    }

    strcpy(ifr.ifr_name, p_capture->name);

    fprintf(stderr, "Interface: %s\n", ifr.ifr_name);


    if (ioctl(raw_socket, SIOCGIFFLAGS, &ifr) == -1) {
	    fprintf(stderr,"ERROR: Could not retrieve the flags from the device. %s\n",strerror(errno));
	    return 1;
    }
// save old interface state  
    p_capture->old_status = ifr;

    ifr.ifr_flags |= IFF_PROMISC;

    if (ioctl(raw_socket, SIOCSIFFLAGS, &ifr) == -1) {
	    fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n",strerror(errno));
	    return 1;
    }

    fprintf(stderr, "Flag: %d\n", ifr.ifr_flags);

    if (ioctl(raw_socket, SIOCGIFINDEX, &ifr) < 0) {
	    fprintf(stderr, "ERROR: Error getting the device index.\n");
	    return 1;
    }

    sll.sll_family = AF_PACKET;
    sll.sll_ifindex = ifr.ifr_ifindex;
    sll.sll_protocol = htons(ETH_P_ALL);
    bind(raw_socket, (struct sockaddr_ll *) &sll, sizeof(sll));

    ifindex = ifr.ifr_ifindex;
    mr.mr_ifindex = ifindex;
    mr.mr_type = PACKET_MR_PROMISC;

    if (setsockopt(raw_socket, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,sizeof(mr)) < 0) {
    	fprintf(stderr, "ERROR: Error setsockopt. %s\n", strerror(errno));
	    return 1;
    }

/*  Set timeout
 * We set how long, we will wait for data
*/
    struct timeval tv;

    tv.tv_sec = 10;		/* 10 Secs Timeout */
    tv.tv_usec = 0;		// Not init'ing this can cause strange errors

    if (setsockopt(raw_socket, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv,sizeof(struct timeval))) {
    	fprintf(stderr, "ERROR: Error setsockopt for time: %s\n", strerror(errno));
	    return 1;
    };

    p_capture->socket = raw_socket;
    p_capture->sll = sll;

    return 0;

}