/*-
* Copyright (c) 2008 Semihalf, Rafal Jaworowski
* Copyright (c) 2009 Semihalf, Piotr Ziecik
* Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/*
* Block storage I/O routines for U-Boot
*/
__FBSDID("$FreeBSD$");
#include <stand.h>
#include "api_public.h"
#include "bootstrap.h"
#include "disk.h"
#include "glue.h"
#include "libuboot.h"
} while (0)
#ifdef DEBUG
#else
#endif
static struct {
static int stor_info_no = 0;
static int stor_opendev(struct disk_devdesc *);
/* devsw I/F */
static int stor_init(void);
static int stor_close(struct open_file *);
static void stor_print(int);
static void stor_cleanup(void);
"disk",
};
static int
stor_init(void)
{
int i;
if (devs_no == 0) {
printf("No U-Boot devices! Really enumerated?\n");
return (-1);
}
for (i = 0; i < devs_no; i++) {
di = ub_dev_get(i);
if (stor_info_no >= UB_MAX_DEV) {
printf("Too many storage devices: %d\n",
return (-1);
}
stor_info_no++;
}
}
if (!stor_info_no) {
debugf("No storage devices\n");
return (-1);
}
return (0);
}
static void
stor_cleanup(void)
{
int i;
for (i = 0; i < stor_info_no; i++)
}
static int
{
int err;
stor_printf("write attempt, operation not supported!\n");
return (EROFS);
}
stor_printf("size=%zu not multiple of device "
"block size=%d\n",
return (EIO);
}
if (rsize)
*rsize = 0;
return (err);
}
static int
{
return (stor_opendev(dev));
}
static int
{
int err;
return (EIO);
if (err != 0) {
stor_printf("device open failed with error=%d, "
return (ENXIO);
}
}
}
static int
{
return (disk_close(dev));
}
static int
{
int err;
if (err != 0) {
return (EIO);
}
stor_printf("real size != size\n");
}
return (err);
}
static void
{
int i;
for (i = 0; i < stor_info_no; i++) {
if (stor_opendev(&dev) == 0) {
disk_close(&dev);
}
}
}
static int
{
switch (cmd) {
case DIOCGSECTORSIZE:
break;
case DIOCGMEDIASIZE:
break;
default:
return (ENOTTY);
}
return (0);
}
/*
* Return the device unit number for the given type and type-relative unit
* number.
*/
int
{
int local_type_unit;
int i;
local_type_unit = 0;
for (i = 0; i < stor_info_no; i++) {
if (local_type_unit == type_unit) {
return (i);
}
}
}
return (-1);
}