Esempio n. 1
0
static int raw_fileop_read(void *ref,uint8_t *buf,int len)
{
    raw_file_t *file = (raw_file_t *) ref;
    int res;

    /*
     * Bound the length based on our "file length" if one
     * was specified.
     */

    if (file->raw_length >= 0) {
	if ((file->raw_length - file->raw_fileoffset) < len) {
	    len = file->raw_length - file->raw_fileoffset;
	    }
	}

    if (len == 0) return 0;

    /*
     * Read the data, adding in the base address.
     */

    res = cfe_readblk(file->raw_fsctx->raw_dev,
		      file->raw_baseoffset + file->raw_fileoffset,
		      buf,len);

    if (res > 0) {
	file->raw_fileoffset += res;
	}

    return res;
}
Esempio n. 2
0
static int ui_cmd_readnvram(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *dev;
    char *tok;
    int fd;
    int offset = 0;
    int res;
    uint8_t buf[512];
    int idx;

    dev = cmd_getarg(cmd,0);
    if (!dev) return ui_showusage(cmd);

    tok = cmd_getarg(cmd,1);
    if (tok) offset = xtoi(tok);
    else offset = 0;

    fd = cfe_open(dev);
    if (fd < 0) {
	ui_showerror(fd,"could not open NVRAM");
	return fd;
	}

    res = cfe_readblk(fd,offset,buf,512);
    printf("Offset %d Result %d\n",offset,res);
    for (idx = 0; idx < 512; idx++) {
	if ((idx % 16) == 0) printf("\n");
	printf("%02X ",buf[idx]);
	}
    printf("\n");	

    cfe_close(fd);
    return 0;
	
}
Esempio n. 3
0
int
blkdevstrategy(void *devdata, int rw, daddr_t bn, size_t reqcnt, void *addrvoid, size_t *cnt)
	/* cnt:	 out: number of bytes transfered */
{
	unsigned char *addr = addrvoid;
	int res;

#if !defined(LIBSA_NO_TWIDDLE)
	twiddle();
#endif

	/* Partial-block transfers not handled. */
	if (reqcnt & (DEV_BSIZE - 1)) {
		*cnt = 0;
		return (EINVAL);
	}
	res = cfe_readblk(booted_dev_fd,(bn+blkdev_part_offset)*DEV_BSIZE,addr,reqcnt);
	if (res < 0) return EIO;

	*cnt = res;
	return (0);
}
Esempio n. 4
0
static int
bhnd_nvram_iocfe_read(struct bhnd_nvram_io *io, size_t offset, void *buffer,
    size_t nbytes)
{
	struct bcm_nvram_iocfe	*iocfe;
	size_t			 remain;
	int64_t			 cfe_offset;
	int			 nr, nreq;

	iocfe = (struct bcm_nvram_iocfe *)io;

	/* Determine (and validate) the base CFE offset */
#if (SIZE_MAX > INT64_MAX)
	if (iocfe->offset > INT64_MAX || offset > INT64_MAX)
		return (ENXIO);
#endif

	if (INT64_MAX - offset < iocfe->offset)
		return (ENXIO);

	cfe_offset = iocfe->offset + offset;

	/* Verify that cfe_offset + nbytes is representable */
	if (INT64_MAX - cfe_offset < nbytes)
		return (ENXIO);

	/* Perform the read */
	for (remain = nbytes; remain > 0;) {
		void	*p;
		size_t	 nread;
		int64_t	 cfe_noff;

		nread = (nbytes - remain);
		cfe_noff = cfe_offset + nread;
		p = ((uint8_t *)buffer + nread);
		nreq = ummin(INT_MAX, remain);
	
		nr = cfe_readblk(iocfe->fd, cfe_noff, p, nreq);
		if (nr < 0) {
			IOCFE_LOG(iocfe, "cfe_readblk() failed: %d\n", nr);
			return (ENXIO);
		}

		/* Check for unexpected short read */
		if (nr == 0 && remain > 0) {
			/* If the request fits entirely within the CFE
			 * device range, we shouldn't hit EOF */
			if (remain < iocfe->size &&
			    iocfe->size - remain > offset)
			{
				IOCFE_LOG(iocfe, "cfe_readblk() returned "
				    "unexpected short read (%d/%d)\n", nr,
				    nreq);
				return (ENXIO);
			}
		}

		if (nr == 0)
			break;

		remain -= nr;
	}

	/* Check for short read */
	if (remain > 0)
		return (ENXIO);

	return (0);
}
Esempio n. 5
0
int
cfe_read(int handle, unsigned char *buffer, int length)
{
    return cfe_readblk(handle, 0, buffer, length);
}