199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2008 Semihalf, Rafal Jaworowski
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2009 Semihalf, Piotr Ziecik
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Block storage I/O routines for U-Boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s%d: ", dev->d_dev->dv_name, dev->d_unit); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define debugf(fmt, args...) do { printf("%s(): ", __func__); \
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int stor_readdev(struct disk_devdesc *, daddr_t, size_t, char *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* devsw I/F */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int stor_init(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int stor_strategy(void *, int, daddr_t, size_t, char *, size_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int stor_ioctl(struct open_file *f, u_long cmd, void *data);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void stor_print(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void stor_cleanup(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("No U-Boot devices! Really enumerated?\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < devs_no; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((di != NULL) && (di->type & DEV_TYP_STOR)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome debugf("storage devices found: %d\n", stor_info_no);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < stor_info_no; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soomestor_strategy(void *devdata, int rw, daddr_t blk, size_t size, char *buf,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct disk_devdesc *dev = (struct disk_devdesc *)devdata;
199767f8919635c4928607450d9e0abb932109ceToomas Soome stor_printf("write attempt, operation not supported!\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome "block size=%d\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = stor_readdev(dev, blk + dev->d_offset, bcount, buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dev->d_unit < 0 || dev->d_unit >= stor_info_no)
199767f8919635c4928607450d9e0abb932109ceToomas Soome stor_printf("device open failed with error=%d, "
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (disk_open(dev, SI(dev).blocks * SI(dev).bsize,
199767f8919635c4928607450d9e0abb932109ceToomas Soomestor_readdev(struct disk_devdesc *dev, daddr_t blk, size_t size, char *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome debugf("reading blk=%d size=%d @ 0x%08x\n", (int)blk, size, (uint32_t)buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = ub_dev_read(SI(dev).handle, buf, size, blk, &real_size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < stor_info_no; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomestor_ioctl(struct open_file *f, u_long cmd, void *data)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *(off_t *)data = SI(dev).bsize * SI(dev).blocks;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Return the device unit number for the given type and type-relative unit
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < stor_info_no; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);