=== modified file 'grub-core/disk/uboot/ubootdisk.c' --- grub-core/disk/uboot/ubootdisk.c 2013-04-12 14:50:21 +0000 +++ grub-core/disk/uboot/ubootdisk.c 2013-04-28 21:49:25 +0000 @@ -26,10 +26,11 @@ #include #include #include +#include -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(): @@ -37,73 +38,53 @@ * 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; @@ -111,7 +92,7 @@ { 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); @@ -119,25 +100,6 @@ 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; } @@ -147,15 +109,10 @@ /* 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; } @@ -190,14 +147,8 @@ 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; @@ -219,7 +170,7 @@ } else { - retval = uboot_dev_open (d->handle); + retval = grub_uboot_dev_open (d->dev); if (retval != 0) goto fail; d->opencount = 1; @@ -228,9 +179,7 @@ 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) @@ -246,7 +195,11 @@ 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; @@ -275,7 +228,7 @@ } 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); } @@ -296,12 +249,12 @@ 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, @@ -318,8 +271,8 @@ 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 = { === modified file 'grub-core/kern/arm/uboot/startup.S' --- grub-core/kern/arm/uboot/startup.S 2013-04-28 20:47:19 +0000 +++ grub-core/kern/arm/uboot/startup.S 2013-04-28 21:05:29 +0000 @@ -65,15 +65,15 @@ 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, @ they need to be manually relocated to _end or @ (__bss_start + grub_total_module_size), whichever greater. - bl uboot_get_real_bss_start @ r0 = src + bl grub_uboot_get_real_bss_start @ r0 = src ldr r1, =EXT_C(_end) @ dst = End of BSS ldr r2, grub_total_module_size @ blob size add r3, r0, r2 @ blob end @@ -92,7 +92,7 @@ @ Since we _are_ the C run-time, we need to manually zero the BSS @ region before continuing - bl uboot_get_real_bss_start @ zero from here + bl grub_uboot_get_real_bss_start @ zero from here ldr r1, =EXT_C(_end) @ to here mov r2, #0 1: str r2, [r0], #4 @@ -105,7 +105,7 @@ * __bss_start does not actually point to the start of the runtime * BSS, but rather to the next byte following the preceding data. */ -FUNCTION (uboot_get_real_bss_start) +FUNCTION (grub_uboot_get_real_bss_start) ldr r0, =EXT_C(__bss_start) @ src tst r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) beq 1f @@ -121,12 +121,12 @@ * 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 @@ -135,7 +135,7 @@ 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 @@ -155,7 +155,7 @@ .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 @@ -165,7 +165,7 @@ .long 0 @ r8 .long 0 @ lr -VARIABLE(uboot_syscall_ptr) +VARIABLE(grub_uboot_syscall_ptr) .long 0 @ .end === modified file 'grub-core/kern/uboot/hw.c' --- grub-core/kern/uboot/hw.c 2013-04-12 14:55:38 +0000 +++ grub-core/kern/uboot/hw.c 2013-04-28 20:58:24 +0000 @@ -25,6 +25,7 @@ #include #include #include +#include grub_addr_t start_of_ram; @@ -37,7 +38,7 @@ 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), @@ -57,19 +58,18 @@ /* * 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", @@ -78,11 +78,12 @@ 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 { @@ -97,7 +98,7 @@ 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; === modified file 'grub-core/kern/uboot/init.c' --- grub-core/kern/uboot/init.c 2013-04-28 20:47:19 +0000 +++ grub-core/kern/uboot/init.c 2013-04-28 22:11:31 +0000 @@ -29,41 +29,42 @@ #include #include #include +#include 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 @@ -73,7 +74,7 @@ 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... */ @@ -82,14 +83,14 @@ 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"); } /* * Modules were relocated to _end, or __bss_start + grub_total_module_size, * whichever greater. (And __bss_start may not point to actual BSS start...) */ - real_bss_start = uboot_get_real_bss_start (); + real_bss_start = grub_uboot_get_real_bss_start (); end = real_bss_start + grub_total_module_size; if (end < (grub_addr_t) _end) end = (grub_addr_t) _end; @@ -116,7 +117,7 @@ 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 */ @@ -140,7 +141,7 @@ { char *tmp; - tmp = uboot_env_get ("grub_bootdev"); + tmp = grub_uboot_env_get ("grub_bootdev"); if (tmp) { *device = grub_strdup (tmp); @@ -150,7 +151,7 @@ else *device = NULL; - tmp = uboot_env_get ("grub_bootpath"); + tmp = grub_uboot_env_get ("grub_bootpath"); if (tmp) { *path = grub_strdup (tmp); === modified file 'grub-core/kern/uboot/uboot.c' --- grub-core/kern/uboot/uboot.c 2013-04-07 00:41:07 +0000 +++ grub-core/kern/uboot/uboot.c 2013-04-28 22:08:15 +0000 @@ -18,6 +18,7 @@ #include #include +#include #include /* @@ -38,25 +39,25 @@ * 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 - @@ -73,7 +74,7 @@ { 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; } } @@ -81,69 +82,50 @@ return 0; } -/* All functions below are wrappers around the uboot_syscall() function */ - -/* - * int API_getc(int *c) - */ -int -uboot_getc (void) -{ - int c; - if (!uboot_syscall (API_GETC, NULL, &c)) - return -1; - - return c; -} - -/* - * int API_tstc(int *c) - */ -int -uboot_tstc (void) -{ - int c; - if (!uboot_syscall (API_TSTC, NULL, &c)) - return -1; - - return c; -} - -/* - * int API_putc(char *ch) - */ -void -uboot_putc (int c) -{ - uboot_syscall (API_PUTC, NULL, &c); -} - -/* - * int API_puts(const char *s) - */ -void -uboot_puts (const char *s) -{ - uboot_syscall (API_PUTS, NULL, s); -} - -/* - * int API_reset(void) - */ -void -uboot_reset (void) -{ - 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 - */ +/* + * All functions below are wrappers around the grub_uboot_syscall() function + */ + +int +grub_uboot_getc (void) +{ + int c; + if (!grub_uboot_syscall (API_GETC, NULL, &c)) + return -1; + + return c; +} + +int +grub_uboot_tstc (void) +{ + int c; + if (!grub_uboot_syscall (API_TSTC, NULL, &c)) + return -1; + + return c; +} + +void +grub_uboot_putc (int c) +{ + grub_uboot_syscall (API_PUTC, NULL, &c); +} + +void +grub_uboot_puts (const char *s) +{ + grub_uboot_syscall (API_PUTS, NULL, s); +} + +void +grub_uboot_reset (void) +{ + grub_uboot_syscall (API_RESET, NULL, 0); +} + struct sys_info * -uboot_get_sys_info (void) +grub_uboot_get_sys_info (void) { int retval; @@ -152,212 +134,193 @@ 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; - - grub_memset (&uboot_devices, 0, sizeof (uboot_devices)); - max = sizeof (uboot_devices) / sizeof (struct device_info); + struct device_info * enum_devices; + int num_enum_devices, max_devices; + + 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; - - /* When no more devices to enumerate, target cookie set to NULL */ - if (uboot_devices[num_devices].cookie == NULL) + 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; + + 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) -{ - struct device_info *dev; - int retval; - - if (!VALID_DEV (handle)) - return -1; - - dev = &uboot_devices[handle]; - - if (!uboot_syscall (API_DEV_OPEN, &retval, dev)) - return -1; - - return retval; -} - -/* - * int API_dev_close(struct device_info *) - */ -int -uboot_dev_close (int handle) -{ - struct device_info *dev; - int retval; - - if (!VALID_DEV (handle)) - return -1; - - dev = &uboot_devices[handle]; - - if (!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) -{ - struct device_info *dev; - int retval; - - if (!OPEN_DEV (handle)) - return -1; - - dev = &uboot_devices[handle]; - - if (!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) -{ - struct device_info *dev; - int retval; - - if (!OPEN_DEV (handle)) - return -1; - - dev = &uboot_devices[handle]; - if (!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) -{ - struct device_info *dev; - int retval; - - if (!OPEN_DEV (handle)) - return -1; - - dev = &uboot_devices[handle]; - if (!uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size)) - return -1; - - return retval; -} - -/* - * int API_env_get(const char *name, char **value) - */ +int +grub_uboot_dev_open (struct device_info *dev) +{ + int retval; + + if (!grub_uboot_syscall (API_DEV_OPEN, &retval, dev)) + return -1; + + return retval; +} + +int +grub_uboot_dev_close (struct device_info *dev) +{ + int retval; + + if (!grub_uboot_syscall (API_DEV_CLOSE, &retval, dev)) + return -1; + + return retval; +} + + +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 retval; + + if (!OPEN_DEV (dev)) + return -1; + + if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf, + &blocks, &start, real_blocks)) + return -1; + + return retval; +} + +int +grub_uboot_dev_recv (struct device_info *dev, void *buf, + int size, int *real_size) +{ + int retval; + + if (!OPEN_DEV (dev)) + return -1; + + if (!grub_uboot_syscall (API_DEV_READ, &retval, dev, buf, &size, real_size)) + return -1; + + return retval; + +} + +int +grub_uboot_dev_send (struct device_info *dev, void *buf, int size) +{ + int retval; + + if (!OPEN_DEV (dev)) + return -1; + + if (!grub_uboot_syscall (API_DEV_WRITE, &retval, dev, buf, &size)) + return -1; + + return retval; +} + 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); } === modified file 'grub-core/lib/uboot/reboot.c' --- grub-core/lib/uboot/reboot.c 2013-04-07 00:41:07 +0000 +++ grub-core/lib/uboot/reboot.c 2013-04-28 20:52:15 +0000 @@ -25,6 +25,6 @@ { grub_machine_fini (); - uboot_reset (); + grub_uboot_reset (); while (1); } === modified file 'grub-core/net/drivers/uboot/ubootnet.c' --- grub-core/net/drivers/uboot/ubootnet.c 2013-04-13 18:07:37 +0000 +++ grub-core/net/drivers/uboot/ubootnet.c 2013-04-28 22:06:49 +0000 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,19 +27,12 @@ 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."); @@ -48,16 +42,13 @@ 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); @@ -65,8 +56,7 @@ 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")); @@ -77,7 +67,6 @@ 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; @@ -92,7 +81,7 @@ 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); } @@ -120,34 +109,23 @@ 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; @@ -158,13 +136,12 @@ 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; === modified file 'grub-core/term/uboot/console.c' --- grub-core/term/uboot/console.c 2013-04-07 00:41:07 +0000 +++ grub-core/term/uboot/console.c 2013-04-28 21:41:47 +0000 @@ -28,14 +28,14 @@ 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; } @@ -127,7 +127,7 @@ 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"; === modified file 'include/grub/arm/linux.h' --- include/grub/arm/linux.h 2013-04-07 00:41:07 +0000 +++ include/grub/arm/linux.h 2013-04-28 20:52:42 +0000 @@ -30,8 +30,8 @@ # 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 # include === modified file 'include/grub/uboot/disk.h' --- include/grub/uboot/disk.h 2013-04-07 00:41:07 +0000 +++ include/grub/uboot/disk.h 2013-04-28 21:03:15 +0000 @@ -31,14 +31,13 @@ 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 */ === modified file 'include/grub/uboot/uboot.h' --- include/grub/uboot/uboot.h 2013-04-12 14:55:38 +0000 +++ include/grub/uboot/uboot.h 2013-04-28 21:30:56 +0000 @@ -28,16 +28,16 @@ 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); /* @@ -47,104 +47,40 @@ * We scan through a defined region around the hint address passed to us * from U-Boot. */ -#include #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 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); +int grub_uboot_api_init (void); + +/* + * All functions below are wrappers around the uboot_syscall() function, + * implemented in grub-core/kern/uboot/uboot.c +*/ + +int grub_uboot_getc (void); +int grub_uboot_tstc (void); +void grub_uboot_putc (int c); +void grub_uboot_puts (const char *s); + +void EXPORT_FUNC (grub_uboot_reset) (void); + +struct sys_info *grub_uboot_get_sys_info (void); + +void grub_uboot_udelay (grub_uint32_t usec); +grub_uint32_t grub_uboot_get_timer (grub_uint32_t base); + +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); + +char *grub_uboot_env_get (const char *name); +void grub_uboot_env_set (const char *name, const char *value); #endif /* ! GRUB_UBOOT_UBOOT_HEADER */