Leif's API fixes
This commit is contained in:
parent
bb9f92b9b1
commit
b385e0723b
11 changed files with 217 additions and 387 deletions
|
@ -26,10 +26,11 @@
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
#include <grub/uboot/disk.h>
|
#include <grub/uboot/disk.h>
|
||||||
#include <grub/uboot/uboot.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 *hd_devices;
|
||||||
static struct ubootdisk_data *cd_devices;
|
static int hd_num;
|
||||||
|
static int hd_max;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* grub_ubootdisk_register():
|
* grub_ubootdisk_register():
|
||||||
|
@ -37,73 +38,53 @@ static struct ubootdisk_data *cd_devices;
|
||||||
* code.
|
* code.
|
||||||
*/
|
*/
|
||||||
grub_err_t
|
grub_err_t
|
||||||
grub_ubootdisk_register (struct device_info *newdev, int handle)
|
grub_ubootdisk_register (struct device_info *newdev)
|
||||||
{
|
{
|
||||||
struct ubootdisk_data *d;
|
struct ubootdisk_data *d;
|
||||||
enum disktype type;
|
|
||||||
|
|
||||||
#define STOR_TYPE(x) ((x) & 0x0ff0)
|
#define STOR_TYPE(x) ((x) & 0x0ff0)
|
||||||
switch (STOR_TYPE (newdev->type))
|
switch (STOR_TYPE (newdev->type))
|
||||||
{
|
{
|
||||||
case DT_STOR_IDE:
|
case DT_STOR_IDE:
|
||||||
case DT_STOR_SATA:
|
case DT_STOR_SATA:
|
||||||
/* hd */
|
|
||||||
type = hd;
|
|
||||||
break;
|
|
||||||
case DT_STOR_MMC:
|
case DT_STOR_MMC:
|
||||||
case DT_STOR_USB:
|
case DT_STOR_USB:
|
||||||
/* fd */
|
/* hd */
|
||||||
type = fd;
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
return GRUB_ERR_BAD_DEVICE;
|
return GRUB_ERR_BAD_DEVICE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = (struct ubootdisk_data *) grub_malloc (sizeof (struct ubootdisk_data));
|
d->dev = newdev;
|
||||||
if (!d)
|
|
||||||
return GRUB_ERR_OUT_OF_MEMORY;
|
|
||||||
d->handle = handle;
|
|
||||||
d->cookie = newdev->cookie;
|
d->cookie = newdev->cookie;
|
||||||
d->opencount = 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* uboot_disk_iterate():
|
* uboot_disk_iterate():
|
||||||
* Itarator over enumerated disk devices.
|
* Iterator over enumerated disk devices.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
||||||
grub_disk_pull_t pull)
|
grub_disk_pull_t pull)
|
||||||
{
|
{
|
||||||
struct ubootdisk_data *d;
|
|
||||||
char buf[16];
|
char buf[16];
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
|
@ -111,7 +92,7 @@ uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
||||||
{
|
{
|
||||||
case GRUB_DISK_PULL_NONE:
|
case GRUB_DISK_PULL_NONE:
|
||||||
/* "hd" - built-in mass-storage */
|
/* "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_snprintf (buf, sizeof (buf) - 1, "hd%d", count);
|
||||||
grub_dprintf ("ubootdisk", "iterating %s\n", buf);
|
grub_dprintf ("ubootdisk", "iterating %s\n", buf);
|
||||||
|
@ -119,25 +100,6 @@ uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -147,15 +109,10 @@ uboot_disk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
||||||
|
|
||||||
/* Helper function for uboot_disk_open. */
|
/* Helper function for uboot_disk_open. */
|
||||||
static struct ubootdisk_data *
|
static struct ubootdisk_data *
|
||||||
get_device (struct ubootdisk_data *devices, int num)
|
get_hd_device (int num)
|
||||||
{
|
{
|
||||||
struct ubootdisk_data *d;
|
if (num < hd_num)
|
||||||
|
return &hd_devices[num];
|
||||||
for (d = devices; d && num; d = d->next, num--)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (num == 0)
|
|
||||||
return d;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -190,14 +147,8 @@ uboot_disk_open (const char *name, struct grub_disk *disk)
|
||||||
|
|
||||||
switch (name[0])
|
switch (name[0])
|
||||||
{
|
{
|
||||||
case 'f':
|
|
||||||
d = get_device (fd_devices, num);
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
d = get_device (cd_devices, num);
|
|
||||||
break;
|
|
||||||
case 'h':
|
case 'h':
|
||||||
d = get_device (hd_devices, num);
|
d = get_hd_device (num);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -219,7 +170,7 @@ uboot_disk_open (const char *name, struct grub_disk *disk)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retval = uboot_dev_open (d->handle);
|
retval = grub_uboot_dev_open (d->dev);
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
d->opencount = 1;
|
d->opencount = 1;
|
||||||
|
@ -228,9 +179,7 @@ uboot_disk_open (const char *name, struct grub_disk *disk)
|
||||||
grub_dprintf ("ubootdisk", "cookie: 0x%08x\n", (grub_addr_t) d->cookie);
|
grub_dprintf ("ubootdisk", "cookie: 0x%08x\n", (grub_addr_t) d->cookie);
|
||||||
disk->id = (grub_addr_t) d->cookie;
|
disk->id = (grub_addr_t) d->cookie;
|
||||||
|
|
||||||
/* Device has previously been enumerated, so this should never fail */
|
devinfo = d->dev;
|
||||||
if ((devinfo = uboot_dev_get (d->handle)) == NULL)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
d->block_size = devinfo->di_stor.block_size;
|
d->block_size = devinfo->di_stor.block_size;
|
||||||
if (d->block_size == 0)
|
if (d->block_size == 0)
|
||||||
|
@ -246,7 +195,11 @@ uboot_disk_open (const char *name, struct grub_disk *disk)
|
||||||
grub_dprintf ("ubootdisk", "(%s) blocksize=%d, log_sector_size=%d\n",
|
grub_dprintf ("ubootdisk", "(%s) blocksize=%d, log_sector_size=%d\n",
|
||||||
disk->name, d->block_size, disk->log_sector_size);
|
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;
|
disk->data = d;
|
||||||
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
|
@ -275,7 +228,7 @@ uboot_disk_close (struct grub_disk *disk)
|
||||||
}
|
}
|
||||||
else if (d->opencount == 1)
|
else if (d->opencount == 1)
|
||||||
{
|
{
|
||||||
retval = uboot_dev_close (d->handle);
|
retval = grub_uboot_dev_close (d->dev);
|
||||||
d->opencount--;
|
d->opencount--;
|
||||||
grub_dprintf ("ubootdisk", "closed %s (%d)\n", disk->name, retval);
|
grub_dprintf ("ubootdisk", "closed %s (%d)\n", disk->name, retval);
|
||||||
}
|
}
|
||||||
|
@ -296,12 +249,12 @@ uboot_disk_read (struct grub_disk *disk,
|
||||||
grub_disk_addr_t offset, grub_size_t numblocks, char *buf)
|
grub_disk_addr_t offset, grub_size_t numblocks, char *buf)
|
||||||
{
|
{
|
||||||
struct ubootdisk_data *d;
|
struct ubootdisk_data *d;
|
||||||
lbasize_t real_size;
|
grub_size_t real_size;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
d = disk->data;
|
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",
|
grub_dprintf ("ubootdisk",
|
||||||
"retval=%d, numblocks=%d, real_size=%llu, sector=%llu\n",
|
"retval=%d, numblocks=%d, real_size=%llu, sector=%llu\n",
|
||||||
retval, numblocks, (grub_uint64_t) real_size,
|
retval, numblocks, (grub_uint64_t) real_size,
|
||||||
|
@ -318,8 +271,8 @@ uboot_disk_write (struct grub_disk *disk __attribute__ ((unused)),
|
||||||
grub_size_t size __attribute__ ((unused)),
|
grub_size_t size __attribute__ ((unused)),
|
||||||
const char *buf __attribute__ ((unused)))
|
const char *buf __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
grub_dprintf ("ubootdisk", "attempt to write\n");
|
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||||
return GRUB_ERR_NOT_IMPLEMENTED_YET;
|
"attempt to write (not supported)");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct grub_disk_dev grub_ubootdisk_dev = {
|
static struct grub_disk_dev grub_ubootdisk_dev = {
|
||||||
|
|
|
@ -65,9 +65,9 @@ FUNCTION(codestart)
|
||||||
ldr sp, =entry_state
|
ldr sp, =entry_state
|
||||||
push {r4-r12,lr} @ store U-Boot context (sp in r12)
|
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]
|
str r1, [r12]
|
||||||
ldr r12, =EXT_C(uboot_boot_data)
|
ldr r12, =EXT_C(grub_uboot_boot_data)
|
||||||
str r2, [r12]
|
str r2, [r12]
|
||||||
|
|
||||||
@ Modules have been stored as a blob in BSS,
|
@ Modules have been stored as a blob in BSS,
|
||||||
|
@ -115,12 +115,12 @@ FUNCTION(codestart)
|
||||||
* r12 (ip). Furthermore it needs to restore r8 for
|
* r12 (ip). Furthermore it needs to restore r8 for
|
||||||
* U-Boot (Global Data Pointer) and preserve it for Grub.
|
* U-Boot (Global Data Pointer) and preserve it for Grub.
|
||||||
*/
|
*/
|
||||||
FUNCTION(uboot_syscall)
|
FUNCTION(grub_uboot_syscall)
|
||||||
ldr ip, =transition_space
|
ldr ip, =transition_space
|
||||||
stm ip, {r8, lr}
|
stm ip, {r8, lr}
|
||||||
ldr ip, =gd_backup
|
ldr ip, =gd_backup
|
||||||
ldr r8, [ip]
|
ldr r8, [ip]
|
||||||
ldr ip, =uboot_syscall_ptr
|
ldr ip, =grub_uboot_syscall_ptr
|
||||||
mov lr, pc
|
mov lr, pc
|
||||||
ldr pc, [ip]
|
ldr pc, [ip]
|
||||||
ldr ip, =gd_backup
|
ldr ip, =gd_backup
|
||||||
|
@ -129,7 +129,7 @@ FUNCTION(uboot_syscall)
|
||||||
ldm ip, {r8, lr}
|
ldm ip, {r8, lr}
|
||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
FUNCTION(uboot_return)
|
FUNCTION(grub_uboot_return)
|
||||||
ldr sp, =entry_state_end
|
ldr sp, =entry_state_end
|
||||||
pop {r4-r12, lr}
|
pop {r4-r12, lr}
|
||||||
mov sp, r12
|
mov sp, r12
|
||||||
|
@ -149,7 +149,7 @@ gd_backup:
|
||||||
.long 0 @ r9
|
.long 0 @ r9
|
||||||
.long 0 @ r10
|
.long 0 @ r10
|
||||||
.long 0 @ r11
|
.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 @ also API signature address hint.
|
||||||
.long 0 @ lr
|
.long 0 @ lr
|
||||||
entry_state: @ backup for U-Boot context
|
entry_state: @ backup for U-Boot context
|
||||||
|
@ -159,7 +159,7 @@ transition_space:
|
||||||
.long 0 @ r8
|
.long 0 @ r8
|
||||||
.long 0 @ lr
|
.long 0 @ lr
|
||||||
|
|
||||||
VARIABLE(uboot_syscall_ptr)
|
VARIABLE(grub_uboot_syscall_ptr)
|
||||||
.long 0 @
|
.long 0 @
|
||||||
|
|
||||||
.end
|
.end
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <grub/machine/kernel.h>
|
#include <grub/machine/kernel.h>
|
||||||
#include <grub/uboot/disk.h>
|
#include <grub/uboot/disk.h>
|
||||||
#include <grub/uboot/uboot.h>
|
#include <grub/uboot/uboot.h>
|
||||||
|
#include <grub/uboot/api_public.h>
|
||||||
|
|
||||||
grub_addr_t start_of_ram;
|
grub_addr_t start_of_ram;
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ grub_addr_t start_of_ram;
|
||||||
void
|
void
|
||||||
grub_uboot_mm_init (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_mm_init_region ((void *) (grub_modules_get_end ()
|
||||||
+ GRUB_KERNEL_MACHINE_STACK_SIZE),
|
+ GRUB_KERNEL_MACHINE_STACK_SIZE),
|
||||||
|
@ -57,19 +58,18 @@ grub_uboot_mm_init (void)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* grub_uboot_probe_hardware():
|
* grub_uboot_probe_hardware():
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
grub_err_t
|
grub_err_t
|
||||||
grub_uboot_probe_hardware (void)
|
grub_uboot_probe_hardware (void)
|
||||||
{
|
{
|
||||||
int devcount, i;
|
int devcount, i;
|
||||||
|
|
||||||
devcount = uboot_dev_enum ();
|
devcount = grub_uboot_dev_enum ();
|
||||||
grub_dprintf ("init", "%d devices found\n", devcount);
|
grub_dprintf ("init", "%d devices found\n", devcount);
|
||||||
|
|
||||||
for (i = 0; i < devcount; i++)
|
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", "device handle: %d\n", i);
|
||||||
grub_dprintf ("init", " cookie\t= 0x%08x\n",
|
grub_dprintf ("init", " cookie\t= 0x%08x\n",
|
||||||
|
@ -78,11 +78,12 @@ grub_uboot_probe_hardware (void)
|
||||||
if (devinfo->type & DEV_TYP_STOR)
|
if (devinfo->type & DEV_TYP_STOR)
|
||||||
{
|
{
|
||||||
grub_dprintf ("init", " type\t\t= DISK\n");
|
grub_dprintf ("init", " type\t\t= DISK\n");
|
||||||
grub_ubootdisk_register (devinfo, i);
|
grub_ubootdisk_register (devinfo);
|
||||||
}
|
}
|
||||||
else if (devinfo->type & DEV_TYP_NET)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -97,7 +98,7 @@ grub_err_t
|
||||||
grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
|
grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
|
||||||
{
|
{
|
||||||
int i;
|
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))
|
if (!si || (si->mr_no < 1))
|
||||||
return GRUB_ERR_BUG;
|
return GRUB_ERR_BUG;
|
||||||
|
|
|
@ -29,41 +29,42 @@
|
||||||
#include <grub/uboot/console.h>
|
#include <grub/uboot/console.h>
|
||||||
#include <grub/uboot/disk.h>
|
#include <grub/uboot/disk.h>
|
||||||
#include <grub/uboot/uboot.h>
|
#include <grub/uboot/uboot.h>
|
||||||
|
#include <grub/uboot/api_public.h>
|
||||||
|
|
||||||
extern char __bss_start[];
|
extern char __bss_start[];
|
||||||
extern char _end[];
|
extern char _end[];
|
||||||
extern grub_size_t grub_total_module_size;
|
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. */
|
/* Set to anything other than zero so it lands in .data and not .bss. */
|
||||||
grub_addr_t grub_modbase = 0x55aa55aa;
|
grub_addr_t grub_modbase = 0x55aa55aa;
|
||||||
grub_uint32_t uboot_machine_type = 0x55aa55aa;
|
grub_uint32_t grub_uboot_machine_type = 0x55aa55aa;
|
||||||
grub_addr_t uboot_boot_data = 0x55aa55aa;
|
grub_addr_t grub_uboot_boot_data = 0x55aa55aa;
|
||||||
|
|
||||||
static unsigned long timer_start;
|
static unsigned long timer_start;
|
||||||
|
|
||||||
void
|
void
|
||||||
grub_exit (void)
|
grub_exit (void)
|
||||||
{
|
{
|
||||||
uboot_return (0);
|
grub_uboot_return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_uint32_t
|
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
|
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
|
static grub_uint64_t
|
||||||
uboot_timer_ms (void)
|
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
|
void
|
||||||
|
@ -72,7 +73,7 @@ grub_machine_init (void)
|
||||||
int ver;
|
int ver;
|
||||||
|
|
||||||
/* First of all - establish connection with U-Boot */
|
/* First of all - establish connection with U-Boot */
|
||||||
ver = uboot_api_init ();
|
ver = grub_uboot_api_init ();
|
||||||
if (!ver)
|
if (!ver)
|
||||||
{
|
{
|
||||||
/* Don't even have a console to log errors to... */
|
/* Don't even have a console to log errors to... */
|
||||||
|
@ -81,7 +82,7 @@ grub_machine_init (void)
|
||||||
else if (ver > API_SIG_VERSION)
|
else if (ver > API_SIG_VERSION)
|
||||||
{
|
{
|
||||||
/* Try to print an error message */
|
/* 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. */
|
/* Initialize the console so that GRUB can display messages. */
|
||||||
|
@ -103,7 +104,7 @@ grub_machine_init (void)
|
||||||
grub_uboot_probe_hardware ();
|
grub_uboot_probe_hardware ();
|
||||||
|
|
||||||
/* Initialise timer */
|
/* Initialise timer */
|
||||||
timer_start = uboot_get_timer (0);
|
timer_start = grub_uboot_get_timer (0);
|
||||||
grub_install_get_time_ms (uboot_timer_ms);
|
grub_install_get_time_ms (uboot_timer_ms);
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
|
@ -127,7 +128,7 @@ grub_machine_get_bootlocation (char **device, char **path)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = uboot_env_get ("grub_bootdev");
|
tmp = grub_uboot_env_get ("grub_bootdev");
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
*device = grub_strdup (tmp);
|
*device = grub_strdup (tmp);
|
||||||
|
@ -137,7 +138,7 @@ grub_machine_get_bootlocation (char **device, char **path)
|
||||||
else
|
else
|
||||||
*device = NULL;
|
*device = NULL;
|
||||||
|
|
||||||
tmp = uboot_env_get ("grub_bootpath");
|
tmp = grub_uboot_env_get ("grub_bootpath");
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
*path = grub_strdup (tmp);
|
*path = grub_strdup (tmp);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <grub/misc.h>
|
#include <grub/misc.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
|
#include <grub/uboot/api_public.h>
|
||||||
#include <grub/uboot/uboot.h>
|
#include <grub/uboot/uboot.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -38,25 +39,25 @@
|
||||||
* returns: 0 if the call not found, 1 if serviced
|
* returns: 0 if the call not found, 1 if serviced
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int (*uboot_syscall_ptr) (int, int *, ...);
|
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
|
||||||
extern int uboot_syscall (int, int *, ...);
|
extern int grub_uboot_syscall (int, int *, ...);
|
||||||
extern grub_addr_t uboot_search_hint;
|
extern grub_addr_t grub_uboot_search_hint;
|
||||||
|
|
||||||
static struct sys_info uboot_sys_info;
|
static struct sys_info uboot_sys_info;
|
||||||
static struct mem_region uboot_mem_info[5];
|
static struct mem_region uboot_mem_info[5];
|
||||||
static struct device_info uboot_devices[6];
|
static struct device_info * devices;
|
||||||
static int num_devices;
|
static int num_devices;
|
||||||
|
|
||||||
int
|
int
|
||||||
uboot_api_init (void)
|
grub_uboot_api_init (void)
|
||||||
{
|
{
|
||||||
struct api_signature *start, *end;
|
struct api_signature *start, *end;
|
||||||
struct api_signature *p;
|
struct api_signature *p;
|
||||||
|
|
||||||
if (uboot_search_hint)
|
if (grub_uboot_search_hint)
|
||||||
{
|
{
|
||||||
/* Extended search range to work around Trim Slice U-Boot issue */
|
/* 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);
|
- 0x00500000);
|
||||||
end =
|
end =
|
||||||
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
|
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
|
||||||
|
@ -73,7 +74,7 @@ uboot_api_init (void)
|
||||||
{
|
{
|
||||||
if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0)
|
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 p->version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,69 +82,50 @@ uboot_api_init (void)
|
||||||
return 0;
|
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
|
int
|
||||||
uboot_getc (void)
|
grub_uboot_getc (void)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
if (!uboot_syscall (API_GETC, NULL, &c))
|
if (!grub_uboot_syscall (API_GETC, NULL, &c))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_tstc(int *c)
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
uboot_tstc (void)
|
grub_uboot_tstc (void)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
if (!uboot_syscall (API_TSTC, NULL, &c))
|
if (!grub_uboot_syscall (API_TSTC, NULL, &c))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_putc(char *ch)
|
|
||||||
*/
|
|
||||||
void
|
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
|
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
|
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 *
|
struct sys_info *
|
||||||
uboot_get_sys_info (void)
|
grub_uboot_get_sys_info (void)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -152,212 +134,193 @@ uboot_get_sys_info (void)
|
||||||
uboot_sys_info.mr = uboot_mem_info;
|
uboot_sys_info.mr = uboot_mem_info;
|
||||||
uboot_sys_info.mr_no = sizeof (uboot_mem_info) / sizeof (struct mem_region);
|
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)
|
if (retval == 0)
|
||||||
return &uboot_sys_info;
|
return &uboot_sys_info;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_udelay(unsigned long *udelay)
|
|
||||||
*/
|
|
||||||
void
|
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
|
grub_uint32_t
|
||||||
uboot_get_timer (grub_uint32_t base)
|
grub_uboot_get_timer (grub_uint32_t base)
|
||||||
{
|
{
|
||||||
grub_uint32_t current;
|
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 0;
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_enum(struct device_info *)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int
|
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));
|
if (num_devices)
|
||||||
max = sizeof (uboot_devices) / sizeof (struct device_info);
|
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
|
* The API_DEV_ENUM call starts a fresh enumeration when passed a
|
||||||
* struct device_info with a NULL cookie, and then depends on having
|
* 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.
|
* 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 =
|
if (num_enum_devices == max_devices)
|
||||||
uboot_devices[num_devices - 1].cookie;
|
{
|
||||||
if (!uboot_syscall (API_DEV_ENUM, NULL, &uboot_devices[num_devices]))
|
struct device_info *tmp;
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* When no more devices to enumerate, target cookie set to NULL */
|
enum_devices[num_enum_devices].cookie =
|
||||||
if (uboot_devices[num_devices].cookie == NULL)
|
enum_devices[num_enum_devices - 1].cookie;
|
||||||
|
if (grub_uboot_syscall (API_DEV_ENUM, NULL,
|
||||||
|
&enum_devices[num_enum_devices]) == 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (enum_devices[num_enum_devices].cookie == NULL)
|
||||||
break;
|
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 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 *
|
struct device_info *
|
||||||
uboot_dev_get (int handle)
|
grub_uboot_dev_get (int index)
|
||||||
{
|
{
|
||||||
if (VALID_DEV (handle))
|
if (VALID_DEV (index))
|
||||||
return &uboot_devices[handle];
|
return &devices[index];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_open(struct device_info *)
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
uboot_dev_open (int handle)
|
grub_uboot_dev_open (struct device_info *dev)
|
||||||
{
|
{
|
||||||
struct device_info *dev;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (!VALID_DEV (handle))
|
if (!grub_uboot_syscall (API_DEV_OPEN, &retval, dev))
|
||||||
return -1;
|
|
||||||
|
|
||||||
dev = &uboot_devices[handle];
|
|
||||||
|
|
||||||
if (!uboot_syscall (API_DEV_OPEN, &retval, dev))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_close(struct device_info *)
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
uboot_dev_close (int handle)
|
grub_uboot_dev_close (struct device_info *dev)
|
||||||
{
|
{
|
||||||
struct device_info *dev;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (!VALID_DEV (handle))
|
if (!grub_uboot_syscall (API_DEV_CLOSE, &retval, dev))
|
||||||
return -1;
|
|
||||||
|
|
||||||
dev = &uboot_devices[handle];
|
|
||||||
|
|
||||||
if (!uboot_syscall (API_DEV_CLOSE, &retval, dev))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_read(struct device_info *di, void *buf, size_t *len,
|
|
||||||
* unsigned long *start, size_t *act_len)
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
uboot_dev_read (int handle, void *buf, lbasize_t blocks,
|
grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks,
|
||||||
lbastart_t start, lbasize_t * real_blocks)
|
grub_uint32_t start, grub_size_t * real_blocks)
|
||||||
{
|
{
|
||||||
struct device_info *dev;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (!OPEN_DEV (handle))
|
if (!OPEN_DEV (dev))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dev = &uboot_devices[handle];
|
if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf,
|
||||||
|
&blocks, &start, real_blocks))
|
||||||
if (!uboot_syscall (API_DEV_READ, &retval, dev, buf,
|
|
||||||
&blocks, &start, real_blocks))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_read(struct device_info *di, void *buf,
|
|
||||||
* size_t *len, size_t *act_len)
|
|
||||||
*/
|
|
||||||
int
|
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;
|
int retval;
|
||||||
|
|
||||||
if (!OPEN_DEV (handle))
|
if (!OPEN_DEV (dev))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dev = &uboot_devices[handle];
|
if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf, &size, real_size))
|
||||||
if (!uboot_syscall (API_DEV_READ, &retval, dev, buf, &size, real_size))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return retval;
|
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
|
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;
|
int retval;
|
||||||
|
|
||||||
if (!OPEN_DEV (handle))
|
if (!OPEN_DEV (dev))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dev = &uboot_devices[handle];
|
if (!grub_uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size))
|
||||||
if (!uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_env_get(const char *name, char **value)
|
|
||||||
*/
|
|
||||||
char *
|
char *
|
||||||
uboot_env_get (const char *name)
|
grub_uboot_env_get (const char *name)
|
||||||
{
|
{
|
||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
if (!uboot_syscall (API_ENV_GET, NULL, name, &value))
|
if (!grub_uboot_syscall (API_ENV_GET, NULL, name, &value))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_env_set(const char *name, const char *value)
|
|
||||||
*/
|
|
||||||
void
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,6 @@ grub_reboot (void)
|
||||||
{
|
{
|
||||||
grub_machine_fini ();
|
grub_machine_fini ();
|
||||||
|
|
||||||
uboot_reset ();
|
grub_uboot_reset ();
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <grub/net/netbuff.h>
|
#include <grub/net/netbuff.h>
|
||||||
#include <grub/uboot/disk.h>
|
#include <grub/uboot/disk.h>
|
||||||
#include <grub/uboot/uboot.h>
|
#include <grub/uboot/uboot.h>
|
||||||
|
#include <grub/uboot/api_public.h>
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
#include <grub/net.h>
|
#include <grub/net.h>
|
||||||
#include <grub/time.h>
|
#include <grub/time.h>
|
||||||
|
@ -26,19 +27,12 @@
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
struct ubootnet_data
|
|
||||||
{
|
|
||||||
void *cookie;
|
|
||||||
int handle;
|
|
||||||
};
|
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
card_open (struct grub_net_card *dev)
|
card_open (struct grub_net_card *dev)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
struct ubootnet_data *data = dev->data;
|
|
||||||
|
|
||||||
status = uboot_dev_open (data->handle);
|
status = grub_uboot_dev_open (dev->data);
|
||||||
if (status)
|
if (status)
|
||||||
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
|
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
|
||||||
|
|
||||||
|
@ -48,16 +42,13 @@ card_open (struct grub_net_card *dev)
|
||||||
static void
|
static void
|
||||||
card_close (struct grub_net_card *dev)
|
card_close (struct grub_net_card *dev)
|
||||||
{
|
{
|
||||||
struct ubootnet_data *data = dev->data;
|
grub_uboot_dev_close (dev->data);
|
||||||
|
|
||||||
uboot_dev_close (data->handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
|
send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
struct ubootnet_data *data = dev->data;
|
|
||||||
grub_size_t len;
|
grub_size_t len;
|
||||||
|
|
||||||
len = (pack->tail - pack->data);
|
len = (pack->tail - pack->data);
|
||||||
|
@ -65,8 +56,7 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
|
||||||
len = dev->mtu;
|
len = dev->mtu;
|
||||||
|
|
||||||
grub_memcpy (dev->txbuf, pack->data, len);
|
grub_memcpy (dev->txbuf, pack->data, len);
|
||||||
status = uboot_dev_send (data->handle, dev->txbuf,
|
status = grub_uboot_dev_send (dev->data, dev->txbuf, len);
|
||||||
len);
|
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
|
return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
|
||||||
|
@ -77,7 +67,6 @@ static struct grub_net_buff *
|
||||||
get_card_packet (struct grub_net_card *dev)
|
get_card_packet (struct grub_net_card *dev)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct ubootnet_data *data = dev->data;
|
|
||||||
grub_uint64_t start_time;
|
grub_uint64_t start_time;
|
||||||
struct grub_net_buff *nb;
|
struct grub_net_buff *nb;
|
||||||
int actual;
|
int actual;
|
||||||
|
@ -92,7 +81,7 @@ get_card_packet (struct grub_net_card *dev)
|
||||||
start_time = grub_get_time_ms ();
|
start_time = grub_get_time_ms ();
|
||||||
do
|
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_dprintf ("net", "rc=%d, actual=%d, time=%lld\n", rc, actual,
|
||||||
grub_get_time_ms () - start_time);
|
grub_get_time_ms () - start_time);
|
||||||
}
|
}
|
||||||
|
@ -120,34 +109,23 @@ GRUB_MOD_INIT (ubootnet)
|
||||||
int devcount, i;
|
int devcount, i;
|
||||||
int nfound = 0;
|
int nfound = 0;
|
||||||
|
|
||||||
devcount = uboot_dev_enum ();
|
devcount = grub_uboot_dev_enum ();
|
||||||
|
|
||||||
for (i = 0; i < devcount; i++)
|
for (i = 0; i < devcount; i++)
|
||||||
{
|
{
|
||||||
struct device_info *devinfo = uboot_dev_get (i);
|
struct device_info *devinfo = grub_uboot_dev_get (i);
|
||||||
struct ubootnet_data *ubdata;
|
|
||||||
struct grub_net_card *card;
|
struct grub_net_card *card;
|
||||||
|
|
||||||
if (!(devinfo->type & DEV_TYP_NET))
|
if (!(devinfo->type & DEV_TYP_NET))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ubdata = grub_malloc (sizeof (struct ubootnet_data));
|
|
||||||
if (!ubdata)
|
|
||||||
{
|
|
||||||
grub_print_error ();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
card = grub_zalloc (sizeof (struct grub_net_card));
|
card = grub_zalloc (sizeof (struct grub_net_card));
|
||||||
if (!card)
|
if (!card)
|
||||||
{
|
{
|
||||||
grub_free (ubdata);
|
|
||||||
grub_print_error ();
|
grub_print_error ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ubdata->handle = i;
|
|
||||||
ubdata->cookie = devinfo->cookie;
|
|
||||||
|
|
||||||
/* FIXME: Any way to check this? */
|
/* FIXME: Any way to check this? */
|
||||||
card->mtu = 1500;
|
card->mtu = 1500;
|
||||||
|
|
||||||
|
@ -158,13 +136,12 @@ GRUB_MOD_INIT (ubootnet)
|
||||||
card->txbuf = grub_zalloc (card->txbufsize);
|
card->txbuf = grub_zalloc (card->txbufsize);
|
||||||
if (!card->txbuf)
|
if (!card->txbuf)
|
||||||
{
|
{
|
||||||
grub_free (ubdata);
|
|
||||||
grub_free (card);
|
grub_free (card);
|
||||||
grub_print_error ();
|
grub_print_error ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
card->data = ubdata;
|
card->data = devinfo;
|
||||||
card->flags = 0;
|
card->flags = 0;
|
||||||
card->name = grub_xasprintf ("ubnet_%d", ++nfound);
|
card->name = grub_xasprintf ("ubnet_%d", ++nfound);
|
||||||
card->idle_poll_delay_ms = 10;
|
card->idle_poll_delay_ms = 10;
|
||||||
|
|
|
@ -28,14 +28,14 @@
|
||||||
static void
|
static void
|
||||||
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
|
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
|
||||||
{
|
{
|
||||||
uboot_putc (c);
|
grub_uboot_putc (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
readkey (struct grub_term_input *term __attribute__ ((unused)))
|
readkey (struct grub_term_input *term __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
if (uboot_tstc () > 0)
|
if (grub_uboot_tstc () > 0)
|
||||||
return uboot_getc ();
|
return grub_uboot_getc ();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ grub_console_init_lately (void)
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
||||||
/* See if explicitly set by U-Boot environment */
|
/* See if explicitly set by U-Boot environment */
|
||||||
type = uboot_env_get ("grub_term");
|
type = grub_uboot_env_get ("grub_term");
|
||||||
if (!type)
|
if (!type)
|
||||||
type = "vt100";
|
type = "vt100";
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
# define LINUX_ADDRESS (start_of_ram + 0x8000)
|
# define LINUX_ADDRESS (start_of_ram + 0x8000)
|
||||||
# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
|
# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
|
||||||
# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
|
# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
|
||||||
# define firmware_get_boot_data uboot_get_boot_data
|
# define firmware_get_boot_data grub_uboot_get_boot_data
|
||||||
# define firmware_get_machine_type uboot_get_machine_type
|
# define firmware_get_machine_type grub_uboot_get_machine_type
|
||||||
#elif defined GRUB_MACHINE_EFI
|
#elif defined GRUB_MACHINE_EFI
|
||||||
# include <grub/efi/efi.h>
|
# include <grub/efi/efi.h>
|
||||||
# include <grub/machine/loader.h>
|
# include <grub/machine/loader.h>
|
||||||
|
|
|
@ -31,14 +31,13 @@ enum disktype
|
||||||
|
|
||||||
struct ubootdisk_data
|
struct ubootdisk_data
|
||||||
{
|
{
|
||||||
struct ubootdisk_data *next;
|
|
||||||
void *cookie;
|
void *cookie;
|
||||||
int handle;
|
struct device_info *dev;
|
||||||
int opencount;
|
int opencount;
|
||||||
enum disktype type;
|
enum disktype type;
|
||||||
grub_uint32_t block_size;
|
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 */
|
#endif /* ! GRUB_UBOOT_DISK_HEADER */
|
||||||
|
|
|
@ -28,16 +28,16 @@ void grub_uboot_mm_init (void);
|
||||||
void grub_uboot_init (void);
|
void grub_uboot_init (void);
|
||||||
void grub_uboot_fini (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);
|
grub_err_t grub_uboot_probe_hardware (void);
|
||||||
|
|
||||||
extern grub_addr_t EXPORT_VAR (start_of_ram);
|
extern grub_addr_t EXPORT_VAR (start_of_ram);
|
||||||
|
|
||||||
grub_uint32_t EXPORT_FUNC (uboot_get_machine_type) (void);
|
grub_uint32_t EXPORT_FUNC (grub_uboot_get_machine_type) (void);
|
||||||
grub_addr_t EXPORT_FUNC (uboot_get_boot_data) (void);
|
grub_addr_t EXPORT_FUNC (grub_uboot_get_boot_data) (void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -47,104 +47,40 @@ grub_addr_t EXPORT_FUNC (uboot_get_boot_data) (void);
|
||||||
* We scan through a defined region around the hint address passed to us
|
* We scan through a defined region around the hint address passed to us
|
||||||
* from U-Boot.
|
* from U-Boot.
|
||||||
*/
|
*/
|
||||||
#include <grub/uboot/api_public.h>
|
|
||||||
|
|
||||||
#define UBOOT_API_SEARCH_LEN (3 * 1024 * 1024)
|
#define UBOOT_API_SEARCH_LEN (3 * 1024 * 1024)
|
||||||
int uboot_api_init (void);
|
int grub_uboot_api_init (void);
|
||||||
|
|
||||||
/* All functions below are wrappers around the uboot_syscall() function */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int API_getc(int *c)
|
* All functions below are wrappers around the uboot_syscall() function,
|
||||||
*/
|
* implemented in grub-core/kern/uboot/uboot.c
|
||||||
int uboot_getc (void);
|
*/
|
||||||
|
|
||||||
/*
|
int grub_uboot_getc (void);
|
||||||
* int API_tstc(int *c)
|
int grub_uboot_tstc (void);
|
||||||
*/
|
void grub_uboot_putc (int c);
|
||||||
int uboot_tstc (void);
|
void grub_uboot_puts (const char *s);
|
||||||
|
|
||||||
/*
|
void EXPORT_FUNC (grub_uboot_reset) (void);
|
||||||
* int API_putc(char *ch)
|
|
||||||
*/
|
|
||||||
void uboot_putc (int c);
|
|
||||||
|
|
||||||
/*
|
struct sys_info *grub_uboot_get_sys_info (void);
|
||||||
* int API_puts(const char *s)
|
|
||||||
*/
|
|
||||||
void uboot_puts (const char *s);
|
|
||||||
|
|
||||||
/*
|
void grub_uboot_udelay (grub_uint32_t usec);
|
||||||
* int API_reset(void)
|
grub_uint32_t grub_uboot_get_timer (grub_uint32_t base);
|
||||||
*/
|
|
||||||
void EXPORT_FUNC (uboot_reset) (void);
|
|
||||||
|
|
||||||
/*
|
int EXPORT_FUNC (grub_uboot_dev_enum) (void);
|
||||||
* int API_get_sys_info(struct sys_info *si)
|
struct device_info * EXPORT_FUNC (grub_uboot_dev_get) (int index);
|
||||||
*
|
int EXPORT_FUNC (grub_uboot_dev_open) (struct device_info *dev);
|
||||||
* fill out the sys_info struct containing selected parameters about the
|
int EXPORT_FUNC (grub_uboot_dev_close) (struct device_info *dev);
|
||||||
* machine
|
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,
|
||||||
struct sys_info *uboot_get_sys_info (void);
|
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);
|
||||||
|
|
||||||
/*
|
char *grub_uboot_env_get (const char *name);
|
||||||
* int API_udelay(unsigned long *udelay)
|
void grub_uboot_env_set (const char *name, const char *value);
|
||||||
*/
|
|
||||||
void uboot_udelay (grub_uint32_t usec);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_get_timer(unsigned long *current, unsigned long *base)
|
|
||||||
*/
|
|
||||||
grub_uint32_t uboot_get_timer (grub_uint32_t base);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_enum(struct device_info *)
|
|
||||||
*/
|
|
||||||
int EXPORT_FUNC(uboot_dev_enum) (void);
|
|
||||||
|
|
||||||
struct device_info *EXPORT_FUNC(uboot_dev_get) (int handle);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_open(struct device_info *)
|
|
||||||
*/
|
|
||||||
int EXPORT_FUNC(uboot_dev_open) (int handle);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* int API_dev_close(struct device_info *)
|
|
||||||
*/
|
|
||||||
int EXPORT_FUNC(uboot_dev_close) (int handle);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 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);
|
|
||||||
|
|
||||||
#endif /* ! GRUB_UBOOT_UBOOT_HEADER */
|
#endif /* ! GRUB_UBOOT_UBOOT_HEADER */
|
||||||
|
|
Loading…
Reference in a new issue