#include <grub/types.h>
#include <grub/uboot/disk.h>
#include <grub/uboot/uboot.h>
+#include <grub/uboot/api_public.h>
-static struct ubootdisk_data *fd_devices;
static struct ubootdisk_data *hd_devices;
-static struct ubootdisk_data *cd_devices;
+static int hd_num;
+static int hd_max;
/*
* grub_ubootdisk_register():
* code.
*/
grub_err_t
-grub_ubootdisk_register (struct device_info *newdev, int handle)
+grub_ubootdisk_register (struct device_info *newdev)
{
struct ubootdisk_data *d;
- enum disktype type;
#define STOR_TYPE(x) ((x) & 0x0ff0)
switch (STOR_TYPE (newdev->type))
{
case DT_STOR_IDE:
case DT_STOR_SATA:
- /* hd */
- type = hd;
- break;
case DT_STOR_MMC:
case DT_STOR_USB:
- /* fd */
- type = fd;
+ /* hd */
+ if (hd_num == hd_max)
+ {
+ int new_num;
+ new_num = (hd_max ? hd_max * 2 : 1);
+ d = grub_realloc(hd_devices,
+ sizeof (struct ubootdisk_data) * new_num);
+ if (!d)
+ return grub_errno;
+ hd_devices = d;
+ hd_max = new_num;
+ }
+
+ d = &hd_devices[hd_num];
+ hd_num++;
break;
default:
return GRUB_ERR_BAD_DEVICE;
break;
}
- d = (struct ubootdisk_data *) grub_malloc (sizeof (struct ubootdisk_data));
- if (!d)
- return GRUB_ERR_OUT_OF_MEMORY;
- d->handle = handle;
+ d->dev = newdev;
d->cookie = newdev->cookie;
d->opencount = 0;
- switch (type)
- {
- case cd:
- grub_dprintf ("ubootdisk", "registering cd device\n");
- d->next = cd_devices;
- cd_devices = d;
-
- break;
- case fd:
- grub_dprintf ("ubootdisk", "registering fd device\n");
- d->next = fd_devices;
- fd_devices = d;
-
- break;
- case hd:
- grub_dprintf ("ubootdisk", "registering hd device\n");
- d->next = hd_devices;
- hd_devices = d;
-
- break;
- default:
- grub_free (d);
- return GRUB_ERR_BAD_DEVICE;
- }
-
return 0;
}
/*
* uboot_disk_iterate():
- * Itarator over enumerated disk devices.
+ * Iterator over enumerated disk devices.
*/
static int
uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
grub_disk_pull_t pull)
{
- struct ubootdisk_data *d;
char buf[16];
int count;
{
case GRUB_DISK_PULL_NONE:
/* "hd" - built-in mass-storage */
- for (d = hd_devices, count = 0; d; d = d->next, count++)
+ for (count = 0 ; count < hd_num; count++)
{
grub_snprintf (buf, sizeof (buf) - 1, "hd%d", count);
grub_dprintf ("ubootdisk", "iterating %s\n", buf);
return 1;
}
break;
- case GRUB_DISK_PULL_REMOVABLE:
- /* "floppy" - removable mass storage */
- for (d = fd_devices, count = 0; d; d = d->next, count++)
- {
- grub_snprintf (buf, sizeof (buf) - 1, "fd%d", count);
- grub_dprintf ("ubootdisk", "iterating %s\n", buf);
- if (hook (buf, hook_data))
- return 1;
- }
-
- /* "cdrom" - removeable read-only storage */
- for (d = cd_devices, count = 0; d; d = d->next, count++)
- {
- grub_snprintf (buf, sizeof (buf) - 1, "cd%d", count);
- grub_dprintf ("ubootdisk", "iterating %s\n", buf);
- if (hook (buf, hook_data))
- return 1;
- }
- break;
default:
return 0;
}
/* Helper function for uboot_disk_open. */
static struct ubootdisk_data *
-get_device (struct ubootdisk_data *devices, int num)
+get_hd_device (int num)
{
- struct ubootdisk_data *d;
-
- for (d = devices; d && num; d = d->next, num--)
- ;
-
- if (num == 0)
- return d;
+ if (num < hd_num)
+ return &hd_devices[num];
return NULL;
}
switch (name[0])
{
- case 'f':
- d = get_device (fd_devices, num);
- break;
- case 'c':
- d = get_device (cd_devices, num);
- break;
case 'h':
- d = get_device (hd_devices, num);
+ d = get_hd_device (num);
break;
default:
goto fail;
}
else
{
- retval = uboot_dev_open (d->handle);
+ retval = grub_uboot_dev_open (d->dev);
if (retval != 0)
goto fail;
d->opencount = 1;
grub_dprintf ("ubootdisk", "cookie: 0x%08x\n", (grub_addr_t) d->cookie);
disk->id = (grub_addr_t) d->cookie;
- /* Device has previously been enumerated, so this should never fail */
- if ((devinfo = uboot_dev_get (d->handle)) == NULL)
- goto fail;
+ devinfo = d->dev;
d->block_size = devinfo->di_stor.block_size;
if (d->block_size == 0)
grub_dprintf ("ubootdisk", "(%s) blocksize=%d, log_sector_size=%d\n",
disk->name, d->block_size, disk->log_sector_size);
- disk->total_sectors = devinfo->di_stor.block_count ? : GRUB_DISK_SIZE_UNKNOWN;
+ if (devinfo->di_stor.block_count)
+ disk->total_sectors = devinfo->di_stor.block_count;
+ else
+ disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
+
disk->data = d;
return GRUB_ERR_NONE;
}
else if (d->opencount == 1)
{
- retval = uboot_dev_close (d->handle);
+ retval = grub_uboot_dev_close (d->dev);
d->opencount--;
grub_dprintf ("ubootdisk", "closed %s (%d)\n", disk->name, retval);
}
grub_disk_addr_t offset, grub_size_t numblocks, char *buf)
{
struct ubootdisk_data *d;
- lbasize_t real_size;
+ grub_size_t real_size;
int retval;
d = disk->data;
- retval = uboot_dev_read (d->handle, buf, numblocks, offset, &real_size);
+ retval = grub_uboot_dev_read (d->dev, buf, numblocks, offset, &real_size);
grub_dprintf ("ubootdisk",
"retval=%d, numblocks=%d, real_size=%llu, sector=%llu\n",
retval, numblocks, (grub_uint64_t) real_size,
grub_size_t size __attribute__ ((unused)),
const char *buf __attribute__ ((unused)))
{
- grub_dprintf ("ubootdisk", "attempt to write\n");
- return GRUB_ERR_NOT_IMPLEMENTED_YET;
+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+ "attempt to write (not supported)");
}
static struct grub_disk_dev grub_ubootdisk_dev = {
ldr sp, =entry_state
push {r4-r12,lr} @ store U-Boot context (sp in r12)
- ldr r12, =EXT_C(uboot_machine_type)
+ ldr r12, =EXT_C(grub_uboot_machine_type)
str r1, [r12]
- ldr r12, =EXT_C(uboot_boot_data)
+ ldr r12, =EXT_C(grub_uboot_boot_data)
str r2, [r12]
@ Modules have been stored as a blob in BSS,
* r12 (ip). Furthermore it needs to restore r8 for
* U-Boot (Global Data Pointer) and preserve it for Grub.
*/
-FUNCTION(uboot_syscall)
+FUNCTION(grub_uboot_syscall)
ldr ip, =transition_space
stm ip, {r8, lr}
ldr ip, =gd_backup
ldr r8, [ip]
- ldr ip, =uboot_syscall_ptr
+ ldr ip, =grub_uboot_syscall_ptr
mov lr, pc
ldr pc, [ip]
ldr ip, =gd_backup
ldm ip, {r8, lr}
bx lr
-FUNCTION(uboot_return)
+FUNCTION(grub_uboot_return)
ldr sp, =entry_state_end
pop {r4-r12, lr}
mov sp, r12
.long 0 @ r9
.long 0 @ r10
.long 0 @ r11
-VARIABLE(uboot_search_hint)@ U-Boot stack pointer -
+VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer -
.long 0 @ also API signature address hint.
.long 0 @ lr
entry_state: @ backup for U-Boot context
.long 0 @ r8
.long 0 @ lr
-VARIABLE(uboot_syscall_ptr)
+VARIABLE(grub_uboot_syscall_ptr)
.long 0 @
.end
#include <grub/machine/kernel.h>
#include <grub/uboot/disk.h>
#include <grub/uboot/uboot.h>
+#include <grub/uboot/api_public.h>
grub_addr_t start_of_ram;
void
grub_uboot_mm_init (void)
{
- struct sys_info *si = uboot_get_sys_info ();
+ struct sys_info *si = grub_uboot_get_sys_info ();
grub_mm_init_region ((void *) (grub_modules_get_end ()
+ GRUB_KERNEL_MACHINE_STACK_SIZE),
/*
* grub_uboot_probe_hardware():
- *
*/
grub_err_t
grub_uboot_probe_hardware (void)
{
int devcount, i;
- devcount = uboot_dev_enum ();
+ devcount = grub_uboot_dev_enum ();
grub_dprintf ("init", "%d devices found\n", devcount);
for (i = 0; i < devcount; i++)
{
- struct device_info *devinfo = uboot_dev_get (i);
+ struct device_info *devinfo = grub_uboot_dev_get (i);
grub_dprintf ("init", "device handle: %d\n", i);
grub_dprintf ("init", " cookie\t= 0x%08x\n",
if (devinfo->type & DEV_TYP_STOR)
{
grub_dprintf ("init", " type\t\t= DISK\n");
- grub_ubootdisk_register (devinfo, i);
+ grub_ubootdisk_register (devinfo);
}
else if (devinfo->type & DEV_TYP_NET)
{
- grub_dprintf ("init", " type\t\t= NET\n");
+ /* Dealt with in ubootnet module. */
+ grub_dprintf ("init", " type\t\t= NET (not supported yet)\n");
}
else
{
grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
{
int i;
- struct sys_info *si = uboot_get_sys_info ();
+ struct sys_info *si = grub_uboot_get_sys_info ();
if (!si || (si->mr_no < 1))
return GRUB_ERR_BUG;
#include <grub/uboot/console.h>
#include <grub/uboot/disk.h>
#include <grub/uboot/uboot.h>
+#include <grub/uboot/api_public.h>
extern char __bss_start[];
extern char _end[];
extern grub_size_t grub_total_module_size;
-extern int (*uboot_syscall_ptr) (int, int *, ...);
+extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
/* Set to anything other than zero so it lands in .data and not .bss. */
grub_addr_t grub_modbase = 0x55aa55aa;
-grub_uint32_t uboot_machine_type = 0x55aa55aa;
-grub_addr_t uboot_boot_data = 0x55aa55aa;
+grub_uint32_t grub_uboot_machine_type = 0x55aa55aa;
+grub_addr_t grub_uboot_boot_data = 0x55aa55aa;
static unsigned long timer_start;
void
grub_exit (void)
{
- uboot_return (0);
+ grub_uboot_return (0);
}
grub_uint32_t
-uboot_get_machine_type (void)
+grub_uboot_get_machine_type (void)
{
- return uboot_machine_type;
+ return grub_uboot_machine_type;
}
grub_addr_t
-uboot_get_boot_data (void)
+grub_uboot_get_boot_data (void)
{
- return uboot_boot_data;
+ return grub_uboot_boot_data;
}
static grub_uint64_t
uboot_timer_ms (void)
{
- return (grub_uint64_t) uboot_get_timer (timer_start) / 1000;
+ return (grub_uint64_t) grub_uboot_get_timer (timer_start) / 1000;
}
void
int ver;
/* First of all - establish connection with U-Boot */
- ver = uboot_api_init ();
+ ver = grub_uboot_api_init ();
if (!ver)
{
/* Don't even have a console to log errors to... */
else if (ver > API_SIG_VERSION)
{
/* Try to print an error message */
- uboot_puts ("invalid U-Boot API version\n");
+ grub_uboot_puts ("invalid U-Boot API version\n");
}
/* Initialize the console so that GRUB can display messages. */
grub_uboot_probe_hardware ();
/* Initialise timer */
- timer_start = uboot_get_timer (0);
+ timer_start = grub_uboot_get_timer (0);
grub_install_get_time_ms (uboot_timer_ms);
/* Initialize */
{
char *tmp;
- tmp = uboot_env_get ("grub_bootdev");
+ tmp = grub_uboot_env_get ("grub_bootdev");
if (tmp)
{
*device = grub_strdup (tmp);
else
*device = NULL;
- tmp = uboot_env_get ("grub_bootpath");
+ tmp = grub_uboot_env_get ("grub_bootpath");
if (tmp)
{
*path = grub_strdup (tmp);
#include <grub/misc.h>
#include <grub/mm.h>
+#include <grub/uboot/api_public.h>
#include <grub/uboot/uboot.h>
/*
* returns: 0 if the call not found, 1 if serviced
*/
-extern int (*uboot_syscall_ptr) (int, int *, ...);
-extern int uboot_syscall (int, int *, ...);
-extern grub_addr_t uboot_search_hint;
+extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
+extern int grub_uboot_syscall (int, int *, ...);
+extern grub_addr_t grub_uboot_search_hint;
static struct sys_info uboot_sys_info;
static struct mem_region uboot_mem_info[5];
-static struct device_info uboot_devices[6];
+static struct device_info * devices;
static int num_devices;
int
-uboot_api_init (void)
+grub_uboot_api_init (void)
{
struct api_signature *start, *end;
struct api_signature *p;
- if (uboot_search_hint)
+ if (grub_uboot_search_hint)
{
/* Extended search range to work around Trim Slice U-Boot issue */
- start = (struct api_signature *) ((uboot_search_hint & ~0x000fffff)
+ start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff)
- 0x00500000);
end =
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
{
if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0)
{
- uboot_syscall_ptr = p->syscall;
+ grub_uboot_syscall_ptr = p->syscall;
return p->version;
}
}
return 0;
}
-/* All functions below are wrappers around the uboot_syscall() function */
-
/*
- * int API_getc(int *c)
+ * All functions below are wrappers around the grub_uboot_syscall() function
*/
+
int
-uboot_getc (void)
+grub_uboot_getc (void)
{
int c;
- if (!uboot_syscall (API_GETC, NULL, &c))
+ if (!grub_uboot_syscall (API_GETC, NULL, &c))
return -1;
return c;
}
-/*
- * int API_tstc(int *c)
- */
int
-uboot_tstc (void)
+grub_uboot_tstc (void)
{
int c;
- if (!uboot_syscall (API_TSTC, NULL, &c))
+ if (!grub_uboot_syscall (API_TSTC, NULL, &c))
return -1;
return c;
}
-/*
- * int API_putc(char *ch)
- */
void
-uboot_putc (int c)
+grub_uboot_putc (int c)
{
- uboot_syscall (API_PUTC, NULL, &c);
+ grub_uboot_syscall (API_PUTC, NULL, &c);
}
-/*
- * int API_puts(const char *s)
- */
void
-uboot_puts (const char *s)
+grub_uboot_puts (const char *s)
{
- uboot_syscall (API_PUTS, NULL, s);
+ grub_uboot_syscall (API_PUTS, NULL, s);
}
-/*
- * int API_reset(void)
- */
void
-uboot_reset (void)
+grub_uboot_reset (void)
{
- uboot_syscall (API_RESET, NULL, 0);
+ grub_uboot_syscall (API_RESET, NULL, 0);
}
-/*
- * int API_get_sys_info(struct sys_info *si)
- *
- * fill out the sys_info struct containing selected parameters about the
- * machine
- */
struct sys_info *
-uboot_get_sys_info (void)
+grub_uboot_get_sys_info (void)
{
int retval;
uboot_sys_info.mr = uboot_mem_info;
uboot_sys_info.mr_no = sizeof (uboot_mem_info) / sizeof (struct mem_region);
- if (uboot_syscall (API_GET_SYS_INFO, &retval, &uboot_sys_info))
+ if (grub_uboot_syscall (API_GET_SYS_INFO, &retval, &uboot_sys_info))
if (retval == 0)
return &uboot_sys_info;
return NULL;
}
-/*
- * int API_udelay(unsigned long *udelay)
- */
void
-uboot_udelay (grub_uint32_t usec)
+grub_uboot_udelay (grub_uint32_t usec)
{
- uboot_syscall (API_UDELAY, NULL, &usec);
+ grub_uboot_syscall (API_UDELAY, NULL, &usec);
}
-/*
- * int API_get_timer(unsigned long *current, unsigned long *base)
- */
grub_uint32_t
-uboot_get_timer (grub_uint32_t base)
+grub_uboot_get_timer (grub_uint32_t base)
{
grub_uint32_t current;
- if (!uboot_syscall (API_GET_TIMER, NULL, ¤t, &base))
+ if (!grub_uboot_syscall (API_GET_TIMER, NULL, ¤t, &base))
return 0;
return current;
}
-/*
- * int API_dev_enum(struct device_info *)
- *
- */
int
-uboot_dev_enum (void)
+grub_uboot_dev_enum (void)
{
- int max;
+ struct device_info * enum_devices;
+ int num_enum_devices, max_devices;
- grub_memset (&uboot_devices, 0, sizeof (uboot_devices));
- max = sizeof (uboot_devices) / sizeof (struct device_info);
+ if (num_devices)
+ return num_devices;
+
+ max_devices = 2;
+ enum_devices = grub_malloc (sizeof(struct device_info) * max_devices);
+ if (!enum_devices)
+ return 0;
/*
* The API_DEV_ENUM call starts a fresh enumeration when passed a
* struct device_info with a NULL cookie, and then depends on having
- * the prevoiusly enumerated device cookie "seeded" into the target
+ * the previously enumerated device cookie "seeded" into the target
* structure.
*/
- if (!uboot_syscall (API_DEV_ENUM, NULL, &uboot_devices)
- || uboot_devices[0].cookie == NULL)
- return 0;
- for (num_devices = 1; num_devices < max; num_devices++)
+ enum_devices[0].cookie = NULL;
+ num_enum_devices = 0;
+
+ if (grub_uboot_syscall (API_DEV_ENUM, NULL,
+ &enum_devices[num_enum_devices]) == 0)
+ goto error;
+
+ num_enum_devices++;
+
+ while (enum_devices[num_enum_devices - 1].cookie != NULL)
{
- uboot_devices[num_devices].cookie =
- uboot_devices[num_devices - 1].cookie;
- if (!uboot_syscall (API_DEV_ENUM, NULL, &uboot_devices[num_devices]))
- return 0;
+ if (num_enum_devices == max_devices)
+ {
+ struct device_info *tmp;
+ int new_max;
+ new_max = max_devices * 2;
+ tmp = grub_realloc (enum_devices,
+ sizeof (struct device_info) * new_max);
+ if (!tmp)
+ {
+ /* Failed to realloc, so return what we have */
+ break;
+ }
+ enum_devices = tmp;
+ max_devices = new_max;
+ }
+
+ enum_devices[num_enum_devices].cookie =
+ enum_devices[num_enum_devices - 1].cookie;
+ if (grub_uboot_syscall (API_DEV_ENUM, NULL,
+ &enum_devices[num_enum_devices]) == 0)
+ goto error;
- /* When no more devices to enumerate, target cookie set to NULL */
- if (uboot_devices[num_devices].cookie == NULL)
+ if (enum_devices[num_enum_devices].cookie == NULL)
break;
+
+ num_enum_devices++;
}
- return num_devices;
+ devices = enum_devices;
+ return num_devices = num_enum_devices;
+
+ error:
+ grub_free (enum_devices);
+ return 0;
}
#define VALID_DEV(x) (((x) < num_devices) && ((x) >= 0))
-#define OPEN_DEV(x) (VALID_DEV(x) && (uboot_devices[(x)].state == DEV_STA_OPEN))
+#define OPEN_DEV(x) ((x->state == DEV_STA_OPEN))
struct device_info *
-uboot_dev_get (int handle)
+grub_uboot_dev_get (int index)
{
- if (VALID_DEV (handle))
- return &uboot_devices[handle];
+ if (VALID_DEV (index))
+ return &devices[index];
return NULL;
}
-/*
- * int API_dev_open(struct device_info *)
- */
int
-uboot_dev_open (int handle)
+grub_uboot_dev_open (struct device_info *dev)
{
- struct device_info *dev;
int retval;
- if (!VALID_DEV (handle))
- return -1;
-
- dev = &uboot_devices[handle];
-
- if (!uboot_syscall (API_DEV_OPEN, &retval, dev))
+ if (!grub_uboot_syscall (API_DEV_OPEN, &retval, dev))
return -1;
return retval;
}
-/*
- * int API_dev_close(struct device_info *)
- */
int
-uboot_dev_close (int handle)
+grub_uboot_dev_close (struct device_info *dev)
{
- struct device_info *dev;
int retval;
- if (!VALID_DEV (handle))
- return -1;
-
- dev = &uboot_devices[handle];
-
- if (!uboot_syscall (API_DEV_CLOSE, &retval, dev))
+ if (!grub_uboot_syscall (API_DEV_CLOSE, &retval, dev))
return -1;
return retval;
}
-/*
- * int API_dev_read(struct device_info *di, void *buf, size_t *len,
- * unsigned long *start, size_t *act_len)
- */
int
-uboot_dev_read (int handle, void *buf, lbasize_t blocks,
- lbastart_t start, lbasize_t * real_blocks)
+grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks,
+ grub_uint32_t start, grub_size_t * real_blocks)
{
- struct device_info *dev;
int retval;
- if (!OPEN_DEV (handle))
+ if (!OPEN_DEV (dev))
return -1;
- dev = &uboot_devices[handle];
-
- if (!uboot_syscall (API_DEV_READ, &retval, dev, buf,
- &blocks, &start, real_blocks))
+ if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf,
+ &blocks, &start, real_blocks))
return -1;
return retval;
}
-/*
- * int API_dev_read(struct device_info *di, void *buf,
- * size_t *len, size_t *act_len)
- */
int
-uboot_dev_recv (int handle, void *buf, int size, int *real_size)
+grub_uboot_dev_recv (struct device_info *dev, void *buf,
+ int size, int *real_size)
{
- struct device_info *dev;
int retval;
- if (!OPEN_DEV (handle))
+ if (!OPEN_DEV (dev))
return -1;
- dev = &uboot_devices[handle];
- if (!uboot_syscall (API_DEV_READ, &retval, dev, buf, &size, real_size))
+ if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf, &size, real_size))
return -1;
return retval;
}
-/*
- * Notice: this is for sending network packets only, as U-Boot does not
- * support writing to storage at the moment (12.2007)
- *
- * int API_dev_write(struct device_info *di, void *buf, int *len)
- */
int
-uboot_dev_send (int handle, void *buf, int size)
+grub_uboot_dev_send (struct device_info *dev, void *buf, int size)
{
- struct device_info *dev;
int retval;
- if (!OPEN_DEV (handle))
+ if (!OPEN_DEV (dev))
return -1;
- dev = &uboot_devices[handle];
- if (!uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size))
+ if (!grub_uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size))
return -1;
return retval;
}
-/*
- * int API_env_get(const char *name, char **value)
- */
char *
-uboot_env_get (const char *name)
+grub_uboot_env_get (const char *name)
{
char *value;
- if (!uboot_syscall (API_ENV_GET, NULL, name, &value))
+ if (!grub_uboot_syscall (API_ENV_GET, NULL, name, &value))
return NULL;
return value;
}
-/*
- * int API_env_set(const char *name, const char *value)
- */
void
-uboot_env_set (const char *name, const char *value)
+grub_uboot_env_set (const char *name, const char *value)
{
- uboot_syscall (API_ENV_SET, NULL, name, value);
+ grub_uboot_syscall (API_ENV_SET, NULL, name, value);
}
{
grub_machine_fini ();
- uboot_reset ();
+ grub_uboot_reset ();
while (1);
}
#include <grub/net/netbuff.h>
#include <grub/uboot/disk.h>
#include <grub/uboot/uboot.h>
+#include <grub/uboot/api_public.h>
#include <grub/dl.h>
#include <grub/net.h>
#include <grub/time.h>
GRUB_MOD_LICENSE ("GPLv3+");
-struct ubootnet_data
-{
- void *cookie;
- int handle;
-};
-
static grub_err_t
card_open (struct grub_net_card *dev)
{
int status;
- struct ubootnet_data *data = dev->data;
- status = uboot_dev_open (data->handle);
+ status = grub_uboot_dev_open (dev->data);
if (status)
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
static void
card_close (struct grub_net_card *dev)
{
- struct ubootnet_data *data = dev->data;
-
- uboot_dev_close (data->handle);
+ grub_uboot_dev_close (dev->data);
}
static grub_err_t
send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
{
int status;
- struct ubootnet_data *data = dev->data;
grub_size_t len;
len = (pack->tail - pack->data);
len = dev->mtu;
grub_memcpy (dev->txbuf, pack->data, len);
- status = uboot_dev_send (data->handle, dev->txbuf,
- len);
+ status = grub_uboot_dev_send (dev->data, dev->txbuf, len);
if (status)
return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
get_card_packet (struct grub_net_card *dev)
{
int rc;
- struct ubootnet_data *data = dev->data;
grub_uint64_t start_time;
struct grub_net_buff *nb;
int actual;
start_time = grub_get_time_ms ();
do
{
- rc = uboot_dev_recv (data->handle, nb->data, dev->mtu + 64, &actual);
+ rc = grub_uboot_dev_recv (dev->data, nb->data, dev->mtu + 64, &actual);
grub_dprintf ("net", "rc=%d, actual=%d, time=%lld\n", rc, actual,
grub_get_time_ms () - start_time);
}
int devcount, i;
int nfound = 0;
- devcount = uboot_dev_enum ();
+ devcount = grub_uboot_dev_enum ();
for (i = 0; i < devcount; i++)
{
- struct device_info *devinfo = uboot_dev_get (i);
- struct ubootnet_data *ubdata;
+ struct device_info *devinfo = grub_uboot_dev_get (i);
struct grub_net_card *card;
if (!(devinfo->type & DEV_TYP_NET))
continue;
-
- ubdata = grub_malloc (sizeof (struct ubootnet_data));
- if (!ubdata)
- {
- grub_print_error ();
- return;
- }
+
card = grub_zalloc (sizeof (struct grub_net_card));
if (!card)
{
- grub_free (ubdata);
grub_print_error ();
return;
}
- ubdata->handle = i;
- ubdata->cookie = devinfo->cookie;
-
/* FIXME: Any way to check this? */
card->mtu = 1500;
card->txbuf = grub_zalloc (card->txbufsize);
if (!card->txbuf)
{
- grub_free (ubdata);
grub_free (card);
grub_print_error ();
continue;
}
- card->data = ubdata;
+ card->data = devinfo;
card->flags = 0;
card->name = grub_xasprintf ("ubnet_%d", ++nfound);
card->idle_poll_delay_ms = 10;
static void
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
{
- uboot_putc (c);
+ grub_uboot_putc (c);
}
static int
readkey (struct grub_term_input *term __attribute__ ((unused)))
{
- if (uboot_tstc () > 0)
- return uboot_getc ();
+ if (grub_uboot_tstc () > 0)
+ return grub_uboot_getc ();
return -1;
}
const char *type;
/* See if explicitly set by U-Boot environment */
- type = uboot_env_get ("grub_term");
+ type = grub_uboot_env_get ("grub_term");
if (!type)
type = "vt100";
# define LINUX_ADDRESS (start_of_ram + 0x8000)
# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
-# define firmware_get_boot_data uboot_get_boot_data
-# define firmware_get_machine_type uboot_get_machine_type
+# define firmware_get_boot_data grub_uboot_get_boot_data
+# define firmware_get_machine_type grub_uboot_get_machine_type
#elif defined GRUB_MACHINE_EFI
# include <grub/efi/efi.h>
# include <grub/machine/loader.h>
struct ubootdisk_data
{
- struct ubootdisk_data *next;
void *cookie;
- int handle;
+ struct device_info *dev;
int opencount;
enum disktype type;
grub_uint32_t block_size;
};
-grub_err_t grub_ubootdisk_register (struct device_info *newdev, int handle);
+grub_err_t grub_ubootdisk_register (struct device_info *newdev);
#endif /* ! GRUB_UBOOT_DISK_HEADER */
void grub_uboot_init (void);
void grub_uboot_fini (void);
-void uboot_return (int) __attribute__ ((noreturn));
+void grub_uboot_return (int) __attribute__ ((noreturn));
-grub_addr_t uboot_get_real_bss_start (void);
+grub_addr_t grub_uboot_get_real_bss_start (void);
grub_err_t grub_uboot_probe_hardware (void);
extern grub_addr_t EXPORT_VAR (start_of_ram);
-grub_uint32_t EXPORT_FUNC (uboot_get_machine_type) (void);
-grub_addr_t EXPORT_FUNC (uboot_get_boot_data) (void);
+grub_uint32_t EXPORT_FUNC (grub_uboot_get_machine_type) (void);
+grub_addr_t EXPORT_FUNC (grub_uboot_get_boot_data) (void);
/*
* We scan through a defined region around the hint address passed to us
* from U-Boot.
*/
-#include <grub/uboot/api_public.h>
#define UBOOT_API_SEARCH_LEN (3 * 1024 * 1024)
-int uboot_api_init (void);
-
-/* All functions below are wrappers around the uboot_syscall() function */
-
-/*
- * int API_getc(int *c)
- */
-int uboot_getc (void);
-
-/*
- * int API_tstc(int *c)
- */
-int uboot_tstc (void);
-
-/*
- * int API_putc(char *ch)
- */
-void uboot_putc (int c);
-
-/*
- * int API_puts(const char *s)
- */
-void uboot_puts (const char *s);
-
-/*
- * int API_reset(void)
- */
-void EXPORT_FUNC (uboot_reset) (void);
-
-/*
- * int API_get_sys_info(struct sys_info *si)
- *
- * fill out the sys_info struct containing selected parameters about the
- * machine
- */
-struct sys_info *uboot_get_sys_info (void);
-
-/*
- * int API_udelay(unsigned long *udelay)
- */
-void uboot_udelay (grub_uint32_t usec);
+int grub_uboot_api_init (void);
/*
- * int API_get_timer(unsigned long *current, unsigned long *base)
- */
-grub_uint32_t uboot_get_timer (grub_uint32_t base);
+ * All functions below are wrappers around the uboot_syscall() function,
+ * implemented in grub-core/kern/uboot/uboot.c
+*/
-/*
- * int API_dev_enum(struct device_info *)
- */
-int EXPORT_FUNC(uboot_dev_enum) (void);
+int grub_uboot_getc (void);
+int grub_uboot_tstc (void);
+void grub_uboot_putc (int c);
+void grub_uboot_puts (const char *s);
-struct device_info *EXPORT_FUNC(uboot_dev_get) (int handle);
+void EXPORT_FUNC (grub_uboot_reset) (void);
-/*
- * int API_dev_open(struct device_info *)
- */
-int EXPORT_FUNC(uboot_dev_open) (int handle);
+struct sys_info *grub_uboot_get_sys_info (void);
-/*
- * int API_dev_close(struct device_info *)
- */
-int EXPORT_FUNC(uboot_dev_close) (int handle);
+void grub_uboot_udelay (grub_uint32_t usec);
+grub_uint32_t grub_uboot_get_timer (grub_uint32_t base);
-/*
- * Notice: this is for sending network packets only, as U-Boot does not
- * support writing to storage at the moment (12.2007)
- *
- * int API_dev_write(struct device_info *di, void *buf, int *len)
- */
-int uboot_dev_write (int handle, void *buf, int *len);
-
-/*
- * int API_dev_read(
- * struct device_info *di,
- * void *buf,
- * size_t *len,
- * unsigned long *start
- * size_t *act_len
- * )
- */
-int uboot_dev_read (int handle, void *buf, lbasize_t blocks,
- lbastart_t start, lbasize_t * real_blocks);
-
-int EXPORT_FUNC(uboot_dev_recv) (int handle, void *buf, int size, int *real_size);
-int EXPORT_FUNC(uboot_dev_send) (int handle, void *buf, int size);
+int EXPORT_FUNC (grub_uboot_dev_enum) (void);
+struct device_info * EXPORT_FUNC (grub_uboot_dev_get) (int index);
+int EXPORT_FUNC (grub_uboot_dev_open) (struct device_info *dev);
+int EXPORT_FUNC (grub_uboot_dev_close) (struct device_info *dev);
+int grub_uboot_dev_write (struct device_info *dev, void *buf, int *len);
+int grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks,
+ grub_uint32_t start, grub_size_t * real_blocks);
+int EXPORT_FUNC (grub_uboot_dev_recv) (struct device_info *dev, void *buf,
+ int size, int *real_size);
+int EXPORT_FUNC (grub_uboot_dev_send) (struct device_info *dev, void *buf,
+ int size);
-/*
- * int API_env_get(const char *name, char **value)
- */
-char *uboot_env_get (const char *name);
-
-/*
- * int API_env_set(const char *name, const char *value)
- */
-void uboot_env_set (const char *name, const char *value);
+char *grub_uboot_env_get (const char *name);
+void grub_uboot_env_set (const char *name, const char *value);
#endif /* ! GRUB_UBOOT_UBOOT_HEADER */