Author: stepan Date: 2008-09-11 19:51:27 +0200 (Thu, 11 Sep 2008) New Revision: 60
Added: trunk/filo/main/grub/grub.c Removed: trunk/filo/fs/shared.h trunk/filo/include/grub/config.h trunk/filo/main/grub.c trunk/filo/main/grub/asmstub.c Modified: trunk/filo/Config.in trunk/filo/Makefile trunk/filo/configs/defconfig trunk/filo/drivers/newusb/usb.c trunk/filo/fs/blockdev.c trunk/filo/fs/filesys.h trunk/filo/fs/fsys_aboot.c trunk/filo/fs/fsys_cramfs.c trunk/filo/fs/fsys_ext2fs.c trunk/filo/fs/fsys_fat.c trunk/filo/fs/fsys_iso9660.c trunk/filo/fs/fsys_jfs.c trunk/filo/fs/fsys_minix.c trunk/filo/fs/fsys_reiserfs.c trunk/filo/fs/fsys_squashfs.c trunk/filo/fs/fsys_xfs.c trunk/filo/fs/vfs.c trunk/filo/include/fs.h trunk/filo/include/grub/serial.h trunk/filo/include/grub/shared.h trunk/filo/main/Makefile.inc trunk/filo/main/filo.c trunk/filo/main/grub/Makefile.inc trunk/filo/main/grub/builtins.c trunk/filo/main/grub/char_io.c trunk/filo/main/grub/serial.c trunk/filo/main/grub/stage2.c Log: mostly cleanups to filo. -?\195?\130?\194?\160drop a couple of obsolete files, macros, prototypes, etc - add an experimental configfile command to the grub interface - adapt usb driver to libpayload changes - use LIBPAYLOAD_PREFIX
Modified: trunk/filo/Config.in =================================================================== --- trunk/filo/Config.in 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/Config.in 2008-09-11 17:51:27 UTC (rev 60) @@ -281,6 +281,7 @@ select DEBUG_SEGMENT select DEBUG_SYS_INFO select DEBUG_BLOCKDEV + select DEBUG_VFS select DEBUG_FSYS_EXT2FS select DEBUG_PCI select DEBUG_VIA_SOUND @@ -312,6 +313,10 @@ bool "DEBUG_BLOCKDEV" default n
+config DEBUG_VFS + bool "DEBUG_VFS" + default n + config DEBUG_FSYS_EXT2FS bool "DEBUG_FSYS_EXT2FS" depends on FSYS_EXT2FS
Modified: trunk/filo/Makefile =================================================================== --- trunk/filo/Makefile 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/Makefile 2008-09-11 17:51:27 UTC (rev 60) @@ -69,13 +69,13 @@
include $(PLATFORM-y) $(BUILD-y)
-LIBPAYLOAD = libpayload/lib/libpayload.a -INCPAYLOAD = libpayload/include -INCPAYLOADDRIVERS = libpayload/drivers +LIBPAYLOAD_PREFIX ?= libpayload +LIBPAYLOAD = $(LIBPAYLOAD_PREFIX)/lib/libpayload.a +INCPAYLOAD = $(LIBPAYLOAD_PREFIX)/include LIBGCC = $(shell $(CC) -print-libgcc-file-name)
OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y)) -INCLUDES := -I$(INCPAYLOAD) -I$(INCPAYLOADDRIVERS) -Iinclude -I$(ARCHDIR-y)/include -Ibuild +INCLUDES := -I$(INCPAYLOAD) -Iinclude -I$(ARCHDIR-y)/include -Ibuild INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
try-run= $(shell set -e; \
Modified: trunk/filo/configs/defconfig =================================================================== --- trunk/filo/configs/defconfig 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/configs/defconfig 2008-09-11 17:51:27 UTC (rev 60) @@ -22,7 +22,7 @@ CONFIG_IDE_DISK_POLL_DELAY=0 # CONFIG_SLOW_SATA is not set # CONFIG_PCMCIA_CF is not set -# CONFIG_USB_NEW_DISK is not set +CONFIG_USB_NEW_DISK=y # CONFIG_USB_DISK is not set # CONFIG_FLASH_DISK is not set CONFIG_SUPPORT_PCI=y
Modified: trunk/filo/drivers/newusb/usb.c =================================================================== --- trunk/filo/drivers/newusb/usb.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/drivers/newusb/usb.c 2008-09-11 17:51:27 UTC (rev 60) @@ -16,8 +16,8 @@ */
#include <fs.h> -#include "usb/usb.h" -#include "usb/usbmsc.h" +#include <usb/usb.h> +#include <usb/usbmsc.h>
static usbdev_t* devs[4]; // FIXME: only 4 devices @@ -43,17 +43,14 @@ this would be a nice place, but the usb disk handling must be more clever for that. */ + usb_poll(); if (count >= drive) return drive; return -1; }
-int usb_new_read(int drive, sector_t sector, void *buffer) +int usb_new_read(const int drive, const sector_t sector, const int size, void *buffer) { if (count < drive) return -1; - /* FIXME: only one sector at a time :-( - This must happen some layers further up - */ - const int size = 1; int result = -readwrite_blocks(devs[drive], sector, size, cbw_direction_data_in, buffer); return result; }
Modified: trunk/filo/fs/blockdev.c =================================================================== --- trunk/filo/fs/blockdev.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/blockdev.c 2008-09-11 17:51:27 UTC (rev 60) @@ -1,6 +1,9 @@ /* * This file is part of FILO. * + * Copyright (C) 2003 SONE Takeshi ts1@tsn.or.jp + * Copyright (C) 2005-2008 coresystems GmbH + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. @@ -37,312 +40,317 @@
static inline int has_pc_part_magic(unsigned char *sect) { - return sect[510]==0x55 && sect[511]==0xAA; + return sect[510] == 0x55 && sect[511] == 0xAA; }
static inline int is_pc_extended_part(unsigned char type) { - return type==5 || type==0xf || type==0x85; + return type == 5 || type == 0xf || type == 0x85; }
/* IBM-PC/MS-DOS style partitioning scheme */ static int open_pc_partition(int part, unsigned long *start_p, - unsigned long *length_p) + unsigned long *length_p) { - /* Layout of PC partition table */ - struct pc_partition { - unsigned char boot; - unsigned char head; - unsigned char sector; - unsigned char cyl; - unsigned char type; - unsigned char e_head; - unsigned char e_sector; - unsigned char e_cyl; - unsigned char start_sect[4]; /* unaligned little endian */ - unsigned char nr_sects[4]; /* ditto */ - } *p; - unsigned char buf[DEV_SECTOR_SIZE]; + /* Layout of PC partition table */ + struct pc_partition { + unsigned char boot; + unsigned char head; + unsigned char sector; + unsigned char cyl; + unsigned char type; + unsigned char e_head; + unsigned char e_sector; + unsigned char e_cyl; + unsigned char start_sect[4]; /* unaligned little endian */ + unsigned char nr_sects[4]; /* ditto */ + } *p; + unsigned char buf[DEV_SECTOR_SIZE];
- /* PC partition probe */ - if (!devread(0, 0, sizeof(buf), buf)) { - debug("device read failed\n"); - return 0; - } - if (!has_pc_part_magic(buf)) { - debug("pc partition magic number not found\n"); - //debug_hexdump(buf, DEV_SECTOR_SIZE); - return PARTITION_UNKNOWN; - } - p = (struct pc_partition *) (buf + 0x1be); - if (part < 4) { - /* Primary partition */ - p += part; - if (p->type==0 || is_pc_extended_part(p->type)) { - printf("Partition %d does not exist\n", part+1); - return 0; + /* PC partition probe */ + if (!devread(0, 0, sizeof(buf), buf)) { + debug("device read failed.\n"); + return 0; } - *start_p = cpu_to_le32(*(u32 *)(p->start_sect)); - *length_p = cpu_to_le32(*(u32 *)(p->nr_sects)); - return 1; - } else { - /* Extended partition */ - int i; - int cur_part; - unsigned long ext_start, cur_table; - /* Search for the extended partition - * which contains logical partitions */ - for (i = 0; i < 4; i++) { - if (is_pc_extended_part(p[i].type)) - break; + if (!has_pc_part_magic(buf)) { + debug("PC partition table magic number not found.\n"); + //debug_hexdump(buf, DEV_SECTOR_SIZE); + return PARTITION_UNKNOWN; } - if (i >= 4) { - printf("Extended partition not found\n"); - return 0; - } - debug("Extended partition at %d\n", i+1); - /* Visit each logical partition labels */ - ext_start = cpu_to_le32(*(u32*)(p[i].start_sect)); - cur_table = ext_start; - cur_part = 4; - for (;;) { - debug("cur_part=%d at %lu\n", cur_part, cur_table); - if (!devread(cur_table, 0, sizeof(buf), buf)) - return 0; - if (!has_pc_part_magic(buf)) { - debug("no magic\n"); - break; - } - - p = (struct pc_partition *) (buf + 0x1be); - /* First entry is the logical partition */ - if (cur_part == part) { - if (p->type==0) { - printf("Partition %d is empty\n", part+1); - return 0; + p = (struct pc_partition *) (buf + 0x1be); + if (part < 4) { + /* Primary partition */ + p += part; + if (p->type == 0 || is_pc_extended_part(p->type)) { + printf("Partition %d does not exist.\n", part + 1); + return 0; } - *start_p = cur_table + cpu_to_le32(*(u32*)(p->start_sect)); - *length_p = cpu_to_le32(*(u32*)(p->nr_sects)); + *start_p = cpu_to_le32(*(u32 *) (p->start_sect)); + *length_p = cpu_to_le32(*(u32 *) (p->nr_sects)); return 1; - } - /* Second entry is link to next partition */ - if (!is_pc_extended_part(p[1].type)) { - debug("no link\n"); - break; - } - cur_table = ext_start + cpu_to_le32(*(u32*)(p[1].start_sect)); + } else { + /* Extended partition */ + int i; + int cur_part; + unsigned long ext_start, cur_table; + /* Search for the extended partition + * which contains logical partitions */ + for (i = 0; i < 4; i++) { + if (is_pc_extended_part(p[i].type)) + break; + } + if (i >= 4) { + printf("No extended partition found.\n"); + return 0; + } + debug("Extended partition at %d.\n", i + 1); + /* Visit each logical partition labels */ + ext_start = cpu_to_le32(*(u32 *) (p[i].start_sect)); + cur_table = ext_start; + cur_part = 4; + for (;;) { + debug("cur_part=%d at %lu\n", cur_part, cur_table); + if (!devread(cur_table, 0, sizeof(buf), buf)) + return 0; + if (!has_pc_part_magic(buf)) { + debug("PC partition table magic number not found.\n"); + break; + }
- cur_part++; + p = (struct pc_partition *) (buf + 0x1be); + /* First entry is the logical partition */ + if (cur_part == part) { + if (p->type == 0) { + printf("Partition %d is empty.\n", part + 1); + return 0; + } + *start_p = cur_table + cpu_to_le32(*(u32 *) (p->start_sect)); + *length_p = cpu_to_le32(*(u32 *) (p->nr_sects)); + return 1; + } + /* Second entry is link to next partition */ + if (!is_pc_extended_part(p[1].type)) { + debug("no link\n"); + break; + } + cur_table = ext_start + cpu_to_le32(*(u32 *) (p[1].start_sect)); + + cur_part++; + } + printf("Logical partition %d does not exist.\n", part + 1); + return 0; } - printf("Logical partition %d not exist\n", part+1); - return 0; - } }
static void flush_cache(void) { - int i; - for (i = 0; i < NUM_CACHE; i++) - cache_sect[i] = (unsigned long) -1; + int i; + for (i = 0; i < NUM_CACHE; i++) + cache_sect[i] = (unsigned long) -1; }
static int parse_device_name(const char *name, int *type, int *drive, - int *part, uint64_t *offset, uint64_t *length) + int *part, uint64_t * offset, + uint64_t * length) { - *offset = *length = 0; + *offset = *length = 0;
- if (memcmp(name, "hd", 2) == 0) { - *type = DISK_IDE; - name += 2; - if (*name < 'a' || *name > 'z') { - printf("Invalid drive\n"); - return 0; + if (memcmp(name, "hd", 2) == 0) { + *type = DISK_IDE; + name += 2; + if (*name < 'a' || *name > 'z') { + printf("Invalid drive\n"); + return 0; + } + *drive = *name - 'a'; + name++; + } else if (memcmp(name, "ud", 2) == 0) { + *type = DISK_NEW_USB; + name += 2; + if (*name < 'a' || *name > 'z') { + printf("Invalid drive\n"); + return 0; + } + *drive = *name - 'a'; + name++; + } else if (memcmp(name, "flash", 5) == 0) { + *type = DISK_FLASH; + name += 5; + if (*name < 'a' || *name > 'z') { + printf("Invalid flash chip\n"); + return 0; + } + *drive = *name - 'a'; + name++; + } else if (memcmp(name, "mem", 3) == 0) { + *type = DISK_MEM; + name += 3; + *drive = 0; + } else { + printf("Unknown device type\n"); + return 0; } - *drive = *name - 'a'; - name++; - } else if (memcmp(name, "ud", 2) == 0) { - *type = DISK_NEW_USB; - name += 2; - if (*name < 'a' || *name > 'z') { - printf("Invalid drive\n"); - return 0; - } - *drive = *name - 'a'; - name++; - } - else if (memcmp(name, "flash", 5) == 0) { - *type = DISK_FLASH; - name += 5; - if (*name < 'a' || *name > 'z') { - printf("Invalid flash chip\n"); - return 0; - } - *drive = *name - 'a'; - name++; - } else if (memcmp(name, "mem", 3) == 0) { - *type = DISK_MEM; - name += 3; - *drive = 0; - } else { - printf("Unknown device type\n"); - return 0; - }
- *part = (int) simple_strtoull(name, (char **)&name, 0); + *part = (int) simple_strtoull(name, (char **) &name, 0);
- if (*name == '@') { - name++; - *offset = strtoull_with_suffix(name, (char **)&name, 0); - if (*name == ',') - *length = strtoull_with_suffix(name+1, (char **)&name, 0); - debug("offset=%#Lx length=%#Lx\n", *offset, *length); - } + if (*name == '@') { + name++; + *offset = strtoull_with_suffix(name, (char **) &name, 0); + if (*name == ',') + *length = + strtoull_with_suffix(name + 1, (char **) &name, + 0); + debug("offset=%#Lx length=%#Lx\n", *offset, *length); + }
- if (*name != '\0') { - printf("Can't parse device name\n"); - return 0; - } + if (*name != '\0') { + printf("Can't parse device name\n"); + return 0; + }
- return 1; + return 1; }
int devopen(const char *name, int *reopen) { - int type, drive, part; - uint64_t offset, length; - uint32_t disk_size = 0; + int type, drive, part; + uint64_t offset, length; + uint32_t disk_size = 0;
- /* Don't re-open the device that's already open */ - if (strcmp(name, dev_name) == 0 && dev_type != -1 ) { - debug("already open\n"); - *reopen = 1; - return 1; - } - *reopen = 0; + /* Don't re-open the device that's already open */ + if (strcmp(name, dev_name) == 0 && dev_type != -1) { + debug("already open\n"); + *reopen = 1; + return 1; + } + *reopen = 0;
- if (!parse_device_name(name, &type, &drive, &part, &offset, &length)) { - debug("failed to parse device name: %s\n", name); - return 0; - } - - /* If we have another dev open, close it first! */ - if (dev_type != type && dev_type != -1) - devclose(); + if (!parse_device_name + (name, &type, &drive, &part, &offset, &length)) { + debug("failed to parse device name: %s\n", name); + return 0; + }
- /* Do simple sanity check first */ - if (offset & DEV_SECTOR_MASK) { - printf("Device offset must be multiple of %d\n", DEV_SECTOR_SIZE); - return 0; - } - if (length & DEV_SECTOR_MASK) { - printf("WARNING: length is rounded up to multiple of %d\n", DEV_SECTOR_SIZE); - length = (length + DEV_SECTOR_MASK) & ~DEV_SECTOR_MASK; - } + /* If we have another dev open, close it first! */ + if (dev_type != type && dev_type != -1) + devclose();
- switch (type) { + /* Do simple sanity check first */ + if (offset & DEV_SECTOR_MASK) { + printf("Device offset must be a multiple of %d.\n", DEV_SECTOR_SIZE); + return 0; + } + if (length & DEV_SECTOR_MASK) { + printf("WARNING: length is rounded up to multiple of %d.\n", DEV_SECTOR_SIZE); + length = (length + DEV_SECTOR_MASK) & ~DEV_SECTOR_MASK; + } + + switch (type) { #ifdef CONFIG_IDE_DISK - case DISK_IDE: - if (ide_probe(drive) != 0) { - debug("failed to open ide\n"); - return 0; - } - disk_size = (uint32_t) -1; /* FIXME */ - break; + case DISK_IDE: + if (ide_probe(drive) != 0) { + debug("Failed to open IDE.\n"); + return 0; + } + disk_size = (uint32_t) - 1; /* FIXME */ + break; #endif - #ifdef CONFIG_USB_NEW_DISK - case DISK_NEW_USB: - if (usb_new_probe(drive) != 0) { - debug("failed to open usb\n"); - return 0; - } - disk_size = (uint32_t) -1; /* FIXME */ - break; + case DISK_NEW_USB: + if (usb_new_probe(drive) != 0) { + debug("Failed to open USB.\n"); + return 0; + } + disk_size = (uint32_t) - 1; /* FIXME */ + break; #endif
#ifdef CONFIG_USB_DISK - case DISK_USB: - if (usb_probe(drive) != 0) { - debug("failed to open usb\n"); - return 0; - } - disk_size = (uint32_t) -1; /* FIXME */ - break; + case DISK_USB: + if (usb_probe(drive) != 0) { + debug("Failed to open USB.\n"); + return 0; + } + disk_size = (uint32_t) - 1; /* FIXME */ + break; #endif
#ifdef CONFIG_FLASH_DISK case DISK_FLASH: - if(flash_probe(drive) != 0) - { - debug("failed to open flash\n"); + if (flash_probe(drive) != 0) { + debug("Failed to open FLASH.\n"); return 0; } - disk_size = (uint32_t) -1; /* FIXME */ + disk_size = (uint32_t) - 1; /* FIXME */ break; #endif
case DISK_MEM: - disk_size = 1 << (32 - DEV_SECTOR_BITS); /* 4GB/512-byte */ - break; + disk_size = 1 << (32 - DEV_SECTOR_BITS); /* 4GB/512-byte */ + break;
default: - printf("Unknown device type %d\n", type); - return 0; - } + printf("Unknown device type %d.\n", type); + return 0; + }
- if (dev_type != type || dev_drive != drive) - flush_cache(); + if (dev_type != type || dev_drive != drive) + flush_cache();
- /* start with whole disk */ - dev_type = type; - dev_drive = drive; - part_start = 0; - part_length = disk_size; - using_devsize = 1; + /* start with whole disk */ + dev_type = type; + dev_drive = drive; + part_start = 0; + part_length = disk_size; + using_devsize = 1;
- if (part != 0) { - /* partition is specified */ - int ret; - ret = open_pc_partition(part - 1, &part_start, &part_length); - if (ret == PARTITION_UNKNOWN) { - ret = open_eltorito_image(part - 1, &part_start, &part_length); - if (ret == PARTITION_UNKNOWN) { - printf("Unrecognized partitioning scheme\n"); - return 0; - } + if (part != 0) { + /* partition is specified */ + int ret; + ret = + open_pc_partition(part - 1, &part_start, &part_length); + if (ret == PARTITION_UNKNOWN) { + ret = + open_eltorito_image(part - 1, &part_start, + &part_length); + if (ret == PARTITION_UNKNOWN) { + printf("Unrecognized partitioning scheme.\n"); + return 0; + } + } + if (ret == 0) { + debug("Can't open partition %d.\n", part); + return 0; + } + + debug("Partition %d start %lu length %lu\n", part, + part_start, part_length); } - if (ret == 0) { - debug("can't open partition %d\n", part); - return 0; - }
- debug("Partition %d start %lu length %lu\n", part, - part_start, part_length); - } - - if (offset) { - if (offset >= (uint64_t) part_length << DEV_SECTOR_BITS) { - printf("Device offset is too high\n"); - return 0; + if (offset) { + if (offset >= (uint64_t) part_length << DEV_SECTOR_BITS) { + printf("Device offset is too high.\n"); + return 0; + } + part_start += offset >> DEV_SECTOR_BITS; + part_length -= offset >> DEV_SECTOR_BITS; + debug("after offset: start %lu, length %lu\n", part_start, + part_length); } - part_start += offset >> DEV_SECTOR_BITS; - part_length -= offset >> DEV_SECTOR_BITS; - debug("after offset: start %lu, length %lu\n", part_start, part_length); - }
- if (length) { - if (length > (uint64_t) part_length << DEV_SECTOR_BITS) { - printf("Specified length exceeds the size of device\n"); - return 0; + if (length) { + if (length > (uint64_t) part_length << DEV_SECTOR_BITS) { + printf ("Specified length exceeds the size of device.\n"); + return 0; + } + part_length = length >> DEV_SECTOR_BITS; + debug("after length: length %lu\n", part_length); + using_devsize = 0; } - part_length = length >> DEV_SECTOR_BITS; - debug("after length: length %lu\n", part_length); - using_devsize = 0; - }
- strncpy(dev_name, name, sizeof(dev_name)-1); + strncpy(dev_name, name, sizeof(dev_name) - 1);
- return 1; + return 1; }
void devclose(void) @@ -352,102 +360,107 @@ if (dev_type == DISK_FLASH) NAND_close(); #endif - + dev_type = -1; }
/* Read a sector from opened device with simple/stupid buffer cache */ static void *read_sector(unsigned long sector) { - unsigned int hash; - void *buf; + unsigned int hash; + void *buf;
- /* If reading memory, just return the memory as the buffer */ - if (dev_type == DISK_MEM) { - unsigned long phys = sector << DEV_SECTOR_BITS; - //debug("mem: %#lx\n", phys); - return phys_to_virt(phys); - } + /* If reading memory, just return the memory as the buffer */ + if (dev_type == DISK_MEM) { + unsigned long phys = sector << DEV_SECTOR_BITS; + //debug("mem: %#lx\n", phys); + return phys_to_virt(phys); + }
- /* Search in the cache */ - hash = sector % NUM_CACHE; - buf = buf_cache[hash]; - if (cache_sect[hash] != sector) { - cache_sect[hash] = (unsigned long) -1; - switch (dev_type) { + /* Search in the cache */ + hash = sector % NUM_CACHE; + buf = buf_cache[hash]; + if (cache_sect[hash] != sector) { + cache_sect[hash] = (unsigned long) -1; + switch (dev_type) { #ifdef CONFIG_IDE_DISK - case DISK_IDE: - if (ide_read(dev_drive, sector, buf) != 0) - goto readerr; - break; + case DISK_IDE: + if (ide_read(dev_drive, sector, buf) != 0) + goto readerr; + break; #endif #ifdef CONFIG_USB_NEW_DISK - case DISK_NEW_USB: - if (usb_new_read(dev_drive, sector, buf) != 0) - goto readerr; - break; + case DISK_NEW_USB: + { + int count = (NUM_CACHE-hash>8)?8:(NUM_CACHE-hash); + if (usb_new_read(dev_drive, sector, count, buf) != 0) + goto readerr; + while (--count>0) { + cache_sect[hash+count] = sector + count; + } + break; + } #endif #ifdef CONFIG_USB_DISK - case DISK_USB: - if (usb_read(dev_drive, sector, buf) != 0) - goto readerr; - break; + case DISK_USB: + if (usb_read(dev_drive, sector, buf) != 0) + goto readerr; + break; #endif
#ifdef CONFIG_FLASH_DISK - case DISK_FLASH: - if (flash_read(dev_drive, sector, buf) != 0) - return 0; - break; + case DISK_FLASH: + if (flash_read(dev_drive, sector, buf) != 0) + return 0; + break; #endif
- default: - printf("read_sector: device not open\n"); - return 0; + default: + printf("read_sector: device not open\n"); + return 0; + } + cache_sect[hash] = sector; } - cache_sect[hash] = sector; - } - return buf; + return buf;
-readerr: - printf("Disk read error dev=%d drive=%d sector=%lu\n", - dev_type, dev_drive, sector); - dev_name[0] = '\0'; /* force re-open the device next time */ - return 0; + readerr: + printf("Disk read error dev=%d drive=%d sector=%lu\n", + dev_type, dev_drive, sector); + dev_name[0] = '\0'; /* force re-open the device next time */ + return 0; }
int devread(unsigned long sector, unsigned long byte_offset, - unsigned long byte_len, void *buf) + unsigned long byte_len, void *buf) { - char *sector_buffer; - char *dest = buf; - unsigned long len; + char *sector_buffer; + char *dest = buf; + unsigned long len;
- sector += byte_offset >> 9; - byte_offset &= 0x1ff; + sector += byte_offset >> 9; + byte_offset &= 0x1ff;
- if (sector + ((byte_len + 0x1ff) >> 9) > part_length) { - printf("Attempt to read out of device/partition\n"); - debug("sector=%lu part_length=%lu byte_len=%lu\n", - sector, part_length, byte_len); - return 0; - } + if (sector + ((byte_len + 0x1ff) >> 9) > part_length) { + printf("Attempt to read beyond device/partition.\n"); + debug("sector=%lu part_length=%lu byte_len=%lu\n", + sector, part_length, byte_len); + return 0; + }
- while (byte_len > 0) { - sector_buffer = read_sector(part_start + sector); - if (!sector_buffer) { - debug("read sector failed\n"); - return 0; + while (byte_len > 0) { + sector_buffer = read_sector(part_start + sector); + if (!sector_buffer) { + debug("Couldn't read sector.\n"); + return 0; + } + len = 512 - byte_offset; + if (len > byte_len) + len = byte_len; + memcpy(dest, sector_buffer + byte_offset, len); + sector++; + byte_offset = 0; + byte_len -= len; + dest += len; } - len = 512 - byte_offset; - if (len > byte_len) - len = byte_len; - memcpy(dest, sector_buffer + byte_offset, len); - sector++; - byte_offset = 0; - byte_len -= len; - dest += len; - } - return 1; + return 1; } -
Modified: trunk/filo/fs/filesys.h =================================================================== --- trunk/filo/fs/filesys.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/filesys.h 2008-09-11 17:51:27 UTC (rev 60) @@ -23,9 +23,6 @@ #include <config.h> #include <fs.h>
-/* This disables some portion of code */ -#define STAGE1_5 1 - #if defined(__i386__) /* * ffz = Find First Zero in word. Undefined if no zero exists, @@ -153,7 +150,8 @@ #define FSYS_BUFLEN 0x8000 extern char FSYS_BUF[FSYS_BUFLEN];
-#define print_possibilities 0 +extern int print_possibilities; +void print_a_completion (char *filename);
#define SECTOR_SIZE 512 #define SECTOR_BITS 9
Modified: trunk/filo/fs/fsys_aboot.c =================================================================== --- trunk/filo/fs/fsys_aboot.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_aboot.c 2008-09-11 17:51:27 UTC (rev 60) @@ -26,7 +26,6 @@ #include <fs.h>
#include "artecboot.h" -#include "shared.h" #include "filesys.h"
#define DEBUG_THIS CONFIG_DEBUG_ARTECBOOT
Modified: trunk/filo/fs/fsys_cramfs.c =================================================================== --- trunk/filo/fs/fsys_cramfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_cramfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -20,7 +20,6 @@ /* fsys_minix.c used as a skeleton, cramfs code in kernel used as * documentation and some code */
-#include "shared.h" #include "filesys.h" #include "mini_inflate.h"
@@ -30,16 +29,6 @@ # define debug_cramfs(str, args...) do {;} while(0) #endif
-#if 0 -/* include/asm-i386/type.h */ -typedef __signed__ char s8; -typedef unsigned char u8; -typedef __signed__ short s16; -typedef unsigned short u16; -typedef __signed__ int s32; -typedef unsigned int u32; -#endif - #define BLOCK_SIZE SECTOR_SIZE
#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
Modified: trunk/filo/fs/fsys_ext2fs.c =================================================================== --- trunk/filo/fs/fsys_ext2fs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_ext2fs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -17,7 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h"
static int mapblock1, mapblock2;
Modified: trunk/filo/fs/fsys_fat.c =================================================================== --- trunk/filo/fs/fsys_fat.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_fat.c 2008-09-11 17:51:27 UTC (rev 60) @@ -17,7 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h" #include "fat.h"
Modified: trunk/filo/fs/fsys_iso9660.c =================================================================== --- trunk/filo/fs/fsys_iso9660.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_iso9660.c 2008-09-11 17:51:27 UTC (rev 60) @@ -34,7 +34,6 @@ * 2003-10 by SONE Takeshi */
-#include "shared.h" #include "filesys.h" #include "iso9660.h" #define DEBUG_THIS CONFIG_DEBUG_ISO9660 @@ -175,8 +174,7 @@ if (rr_ptr.rr->version != 1) { #ifndef STAGE1_5 - if (debug) - printf( + debug( "Non-supported version (%d) RockRidge chunk " "`%c%c'\n", rr_ptr.rr->version, rr_ptr.rr->signature & 0xFF, @@ -272,7 +270,7 @@ print_possibilities = -print_possibilities; memcpy(NAME_BUF, name, name_len); NAME_BUF[name_len] = '\0'; - print_a_completion (NAME_BUF); + print_a_completion ((char *)NAME_BUF); #endif } }
Modified: trunk/filo/fs/fsys_jfs.c =================================================================== --- trunk/filo/fs/fsys_jfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_jfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -18,7 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h" #include "jfs.h"
Modified: trunk/filo/fs/fsys_minix.c =================================================================== --- trunk/filo/fs/fsys_minix.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_minix.c 2008-09-11 17:51:27 UTC (rev 60) @@ -23,7 +23,6 @@ mkfs.minix -c DEVICE */
-#include "shared.h" #include "filesys.h"
#define DEBUG_MINIX CONFIG_DEBUG_MINIX
Modified: trunk/filo/fs/fsys_reiserfs.c =================================================================== --- trunk/filo/fs/fsys_reiserfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_reiserfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -18,7 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h"
#undef REISERDEBUG
Modified: trunk/filo/fs/fsys_squashfs.c =================================================================== --- trunk/filo/fs/fsys_squashfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_squashfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -18,7 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h" #include "squashfs_fs.h" #include "squashfs_zlib.h"
Modified: trunk/filo/fs/fsys_xfs.c =================================================================== --- trunk/filo/fs/fsys_xfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/fsys_xfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -18,7 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "shared.h" #include "filesys.h" #include "xfs.h"
Deleted: trunk/filo/fs/shared.h =================================================================== --- trunk/filo/fs/shared.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/shared.h 2008-09-11 17:51:27 UTC (rev 60) @@ -1 +0,0 @@ -/* Sorry, nothing is shared here ;) Just for GRUB compatibility. */
Modified: trunk/filo/fs/vfs.c =================================================================== --- trunk/filo/fs/vfs.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/fs/vfs.c 2008-09-11 17:51:27 UTC (rev 60) @@ -1,6 +1,9 @@ /* * This file is part of FILO. * + * Copyright (C) 2003 SONE Takeshi ts1@tsn.or.jp + * Copyright (C) 2005-2008 coresystems GmbH + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. @@ -32,190 +35,201 @@ void (*disk_read_func) (int, int, int); char FSYS_BUF[FSYS_BUFLEN]; int fsmax; +int print_possibilities = 0;
struct fsys_entry { - char *name; - int (*mount_func) (void); - int (*read_func) (char *buf, int len); - int (*dir_func) (char *dirname); - void (*close_func) (void); - int (*embed_func) (int *start_sector, int needed_sectors); + char *name; + int (*mount_func) (void); + int (*read_func) (char *buf, int len); + int (*dir_func) (char *dirname); + void (*close_func) (void); + int (*embed_func) (int *start_sector, int needed_sectors); };
struct fsys_entry fsys_table[] = { # ifdef CONFIG_FSYS_FAT - {"FAT filesystem", fat_mount, fat_read, fat_dir, 0, 0}, + {"FAT filesystem", fat_mount, fat_read, fat_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_EXT2FS - {"EXT2 filesystem", ext2fs_mount, ext2fs_read, ext2fs_dir, 0, 0}, + {"EXT2 filesystem", ext2fs_mount, ext2fs_read, ext2fs_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_MINIX - {"MINIX filesystem", minix_mount, minix_read, minix_dir, 0, 0}, + {"MINIX filesystem", minix_mount, minix_read, minix_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_REISERFS - {"REISERFS filesystem", reiserfs_mount, reiserfs_read, reiserfs_dir, 0, - reiserfs_embed}, + {"REISERFS filesystem", reiserfs_mount, reiserfs_read, reiserfs_dir, 0, reiserfs_embed}, # endif # ifdef CONFIG_FSYS_JFS - {"JFS filesystem", jfs_mount, jfs_read, jfs_dir, 0, jfs_embed}, + {"JFS filesystem", jfs_mount, jfs_read, jfs_dir, 0, jfs_embed}, # endif # ifdef CONFIG_FSYS_XFS - {"XFS filesystem", xfs_mount, xfs_read, xfs_dir, 0, 0}, + {"XFS filesystem", xfs_mount, xfs_read, xfs_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_ISO9660 - {"ISO9660 filesystem", iso9660_mount, iso9660_read, iso9660_dir, 0, 0}, + {"ISO9660 filesystem", iso9660_mount, iso9660_read, iso9660_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_CRAMFS - {"CRAM filesystem", cramfs_mount, cramfs_read, cramfs_dir, 0, 0}, + {"CRAM filesystem", cramfs_mount, cramfs_read, cramfs_dir, 0, 0}, # endif # ifdef CONFIG_FSYS_SQUASHFS - {"SQUASH filesystem", squashfs_mount, squashfs_read, squashfs_dir, 0, 0}, + {"SQUASH filesystem", squashfs_mount, squashfs_read, squashfs_dir, 0, 0}, # endif # ifdef CONFIG_ARTEC_BOOT - {"Artecboot Virtual Filesystem", aboot_mount, aboot_read, aboot_dir, 0, 0}, + {"Artecboot Virtual Filesystem", aboot_mount, aboot_read, aboot_dir, 0, 0}, # endif - };
/* NULLFS is used to read images from raw device */ static int nullfs_dir(char *name) { - uint64_t dev_size; + uint64_t dev_size;
- if (name) { - debug("can't have a named file\n"); - return 0; - } + if (name) { + debug("Can't have a named file.\n"); + return 0; + }
- dev_size = (uint64_t) part_length << 9; - /* GRUB code doesn't like 2GB or bigger files */ - if (dev_size > 0x7fffffff) - dev_size = 0x7fffffff; - filemax = dev_size; - return 1; + dev_size = (uint64_t) part_length << 9; + + /* GRUB code doesn't like 2GB or bigger files */ + if (dev_size > 0x7fffffff) { + dev_size = 0x7fffffff; + } + + filemax = dev_size; + + return 1; }
static int nullfs_read(char *buf, int len) { - if (devread(filepos>>9, filepos&0x1ff, len, buf)) { - filepos += len; - return len; - } else - return 0; + if (devread(filepos >> 9, filepos & 0x1ff, len, buf)) { + filepos += len; + return len; + } else { + return 0; + } }
-static struct fsys_entry nullfs = - {"nullfs", 0, nullfs_read, nullfs_dir, 0, 0}; +static struct fsys_entry nullfs = { "nullfs", 0, nullfs_read, nullfs_dir, 0, 0 };
static struct fsys_entry *fsys;
int mount_fs(void) { - int i; + int i;
- for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) { - if (fsys_table[i].mount_func()) { - fsys = &fsys_table[i]; - printf("Mounted %s\n", fsys->name); - return 1; + for (i = 0; i < sizeof(fsys_table) / sizeof(fsys_table[0]); i++) { + if (!fsys_table[i].mount_func()) + continue; + + fsys = &fsys_table[i]; + printf("Mounted %s\n", fsys->name); + return 1; } - } - fsys = 0; - printf("Unknown filesystem type\n"); - return 0; + fsys = 0; + + printf("Unknown filesystem type.\n"); + return 0; }
int file_open(const char *filename) { - char *dev = 0; - const char *path; - int len; - int retval = 0; - int reopen; + char *dev = 0; + const char *path; + int len; + int retval = 0; + int reopen;
- path = strchr(filename, ':'); - if (path) { - len = path - filename; - path++; - dev = malloc(len + 1); - memcpy(dev, filename, len); - dev[len] = '\0'; - } else { - /* No colon is given. Is this device or filename? */ - if (filename[0] == '/') { - /* Anything starts with '/' must be a filename */ - dev = 0; - path = filename; + path = strchr(filename, ':'); + if (path) { + len = path - filename; + path++; + dev = malloc(len + 1); + memcpy(dev, filename, len); + dev[len] = '\0'; } else { - dev = strdup(filename); - path = 0; + /* No colon is given. Is this device or filename? */ + if (filename[0] == '/') { + /* Anything starts with '/' must be a filename */ + dev = 0; + path = filename; + } else { + dev = strdup(filename); + path = 0; + } } - } - debug("dev=%s, path=%s\n", dev, path); + debug("dev=%s, path=%s\n", dev, path);
- if (dev && dev[0]) { - if (!devopen(dev, &reopen)) { - fsys = 0; - goto out; + if (dev && dev[0]) { + if (!devopen(dev, &reopen)) { + fsys = 0; + goto out; + } + if (!reopen) + fsys = 0; } - if (!reopen) - fsys = 0; - }
- if (path) { - if (!fsys || fsys==&nullfs) { - if (!mount_fs()) + if (path) { + if (!fsys || fsys == &nullfs) { + if (!mount_fs()) + goto out; + } + using_devsize = 0; + if (!path[0]) { + printf("No filename is given.\n"); + goto out; + } + } else { + fsys = &nullfs; + } + + filepos = 0; + errnum = 0; + if (!fsys->dir_func((char *) path)) { + printf("File not found.\n"); goto out; } - using_devsize = 0; - if (!path[0]) { - printf("No filename is given\n"); - goto out; - } - } else - fsys = &nullfs; + retval = 1;
- filepos = 0; - errnum = 0; - if (!fsys->dir_func((char *) path)) { - printf("File not found\n"); - goto out; - } - retval = 1; out: - if (dev) - free(dev); - return retval; + if (dev) + free(dev); + + return retval; }
int file_read(void *buf, unsigned long len) { - if (filepos < 0 || filepos > filemax) - filepos = filemax; - if (len < 0 || len > filemax-filepos) - len = filemax - filepos; - errnum = 0; + if (filepos < 0 || filepos > filemax) + filepos = filemax;
+ if (len < 0 || len > filemax - filepos) + len = filemax - filepos; + + errnum = 0; + debug("reading %d bytes, offset 0x%x\n", len, filepos); return fsys->read_func(buf, len); }
-int file_seek(unsigned long offset) +unsigned long file_seek(unsigned long offset) { debug("seeking to 0x%x\n", offset); - filepos = offset; - return filepos; + filepos = offset; + return filepos; }
unsigned long file_size(void) { - return filemax; + return filemax; }
void file_set_size(unsigned long size) { debug("updating file size to %d bytes\n", size); - filemax = size; + + filemax = size; using_devsize = 0; }
@@ -223,4 +237,3 @@ { devclose(); } -
Modified: trunk/filo/include/fs.h =================================================================== --- trunk/filo/include/fs.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/include/fs.h 2008-09-11 17:51:27 UTC (rev 60) @@ -39,7 +39,7 @@
#ifdef CONFIG_USB_NEW_DISK int usb_new_probe(int drive); -int usb_new_read(int drive, sector_t sector, void *buffer); +int usb_new_read(const int drive, const sector_t sector, const int size, void *buffer); #endif
#ifdef CONFIG_FLASH_DISK @@ -63,7 +63,7 @@
int file_open(const char *filename); int file_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); +unsigned long file_seek(unsigned long offset); unsigned long file_size(void); void file_set_size(unsigned long size); void file_close(void);
Deleted: trunk/filo/include/grub/config.h =================================================================== --- trunk/filo/include/grub/config.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/include/grub/config.h 2008-09-11 17:51:27 UTC (rev 60) @@ -1,107 +0,0 @@ -/* config.h. Generated by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if an absolute indirect call/jump must NOT be prefixed with `*' */ -/* #undef ABSOLUTE_WITHOUT_ASTERISK */ - -/* Define it to "addr32" or "addr32;" to make GAS happy */ -#define ADDR32 addr32 - -/* Define if you don't want to pass the mem= option to Linux */ -#define AUTO_LINUX_MEM_OPT 1 - -/* Define it to "data32" or "data32;" to make GAS happy */ -#define DATA32 data32 - -/* Define if C symbols get an underscore after compilation */ -/* #undef HAVE_ASM_USCORE */ - -/* Define to 1 if you have the <curses.h> header file. */ -#define HAVE_CURSES_H 1 - -/* Define if edata is defined */ -#define HAVE_EDATA_SYMBOL 1 - -/* Define if end is defined */ -#define HAVE_END_SYMBOL 1 - -/* Define to 1 if you have the <inttypes.h> header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define if you have a curses library */ -#define HAVE_LIBCURSES 1 - -/* Define to 1 if you have the <memory.h> header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the <ncurses/curses.h> header file. */ -/* #undef HAVE_NCURSES_CURSES_H */ - -/* Define to 1 if you have the <ncurses.h> header file. */ -#define HAVE_NCURSES_H 1 - -/* Define if opendisk() in -lutil can be used */ -/* #undef HAVE_OPENDISK */ - -/* Define if start is defined */ -/* #undef HAVE_START_SYMBOL */ - -/* Define to 1 if you have the <stdint.h> header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the <stdlib.h> header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the <strings.h> header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the <sys/stat.h> header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the <sys/types.h> header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the <unistd.h> header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if _edata is defined */ -#define HAVE_USCORE_EDATA_SYMBOL 1 - -/* Define if end is defined */ -#define HAVE_USCORE_END_SYMBOL 1 - -/* Define if _start is defined */ -#define HAVE_USCORE_START_SYMBOL 1 - -/* Define if __bss_start is defined */ -#define HAVE_USCORE_USCORE_BSS_START_SYMBOL 1 - -/* Name of package */ -#define PACKAGE "grub" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "bug-grub@gnu.org" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "GRUB" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GRUB 0.97" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "grub" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.97" - -/* Define if there is user specified preset menu string */ -/* #undef PRESET_MENU_STRING */ - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "0.97"
Modified: trunk/filo/include/grub/serial.h =================================================================== --- trunk/filo/include/grub/serial.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/include/grub/serial.h 2008-09-11 17:51:27 UTC (rev 60) @@ -84,10 +84,4 @@ int serial_hw_init (unsigned short port, unsigned int speed, int word_len, int parity, int stop_bit_len);
-#ifdef GRUB_UTIL -/* Set the file name of a serial device (or a pty device). This is a - function specific to the grub shell. */ -void serial_set_device (const char *device); -#endif /* GRUB_UTIL */ - #endif /* ! GRUB_SERIAL_HEADER */
Modified: trunk/filo/include/grub/shared.h =================================================================== --- trunk/filo/include/grub/shared.h 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/include/grub/shared.h 2008-09-11 17:51:27 UTC (rev 60) @@ -25,24 +25,11 @@ #ifndef GRUB_SHARED_HEADER #define GRUB_SHARED_HEADER 1
-#include <grub/config.h> +void grub_main(void);
-/* Add an underscore to a C symbol in assembler code if needed. */ -#ifdef HAVE_ASM_USCORE -# define EXT_C(sym) _ ## sym -#else -# define EXT_C(sym) sym -#endif - /* Maybe redirect memory requests through grub_scratch_mem. */ -#ifdef GRUB_UTIL -extern char *grub_scratch_mem; -# define RAW_ADDR(x) ((x) + (int) grub_scratch_mem) -# define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4) -#else # define RAW_ADDR(x) (x) # define RAW_SEG(x) (x) -#endif
/* * Integer sizes @@ -215,33 +202,7 @@ #define STAGE2_ID_ISO9660_STAGE1_5 9 #define STAGE2_ID_UFS2_STAGE1_5 10
-#ifndef STAGE1_5 # define STAGE2_ID STAGE2_ID_STAGE2 -#else -# if defined(FSYS_FFS) -# define STAGE2_ID STAGE2_ID_FFS_STAGE1_5 -# elif defined(FSYS_EXT2FS) -# define STAGE2_ID STAGE2_ID_E2FS_STAGE1_5 -# elif defined(FSYS_FAT) -# define STAGE2_ID STAGE2_ID_FAT_STAGE1_5 -# elif defined(FSYS_MINIX) -# define STAGE2_ID STAGE2_ID_MINIX_STAGE1_5 -# elif defined(FSYS_REISERFS) -# define STAGE2_ID STAGE2_ID_REISERFS_STAGE1_5 -# elif defined(FSYS_VSTAFS) -# define STAGE2_ID STAGE2_ID_VSTAFS_STAGE1_5 -# elif defined(FSYS_JFS) -# define STAGE2_ID STAGE2_ID_JFS_STAGE1_5 -# elif defined(FSYS_XFS) -# define STAGE2_ID STAGE2_ID_XFS_STAGE1_5 -# elif defined(FSYS_ISO9660) -# define STAGE2_ID STAGE2_ID_ISO9660_STAGE1_5 -# elif defined(FSYS_UFS2) -# define STAGE2_ID STAGE2_ID_UFS2_STAGE1_5 -# else -# error "unknown Stage 2" -# endif -#endif
/* * defines for use when switching between real and protected mode @@ -257,17 +218,6 @@ #define PROTSTACKINIT (FSYS_BUF - 0x10)
-/* - * Assembly code defines - * - * "EXT_C" is assumed to be defined in the Makefile by the configure - * command. - */ - -#define ENTRY(x) .globl EXT_C(x) ; EXT_C(x): -#define VARIABLE(x) ENTRY(x) - - #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */ #define K_STATUS 0x64 /* keyboard status */ #define K_CMD 0x64 /* keybd ctlr command (write-only) */ @@ -284,7 +234,10 @@
/* Codes for getchar. */ #define ASCII_CHAR(x) ((x) & 0xFF) -#if !defined(GRUB_UTIL) || !defined(HAVE_LIBCURSES) + +#warning "CURSES keys fundamentally different from libpayload's" +// And that's why we can't just do +// # include <curses.h> # define KEY_LEFT 0x4B00 # define KEY_RIGHT 0x4D00 # define KEY_UP 0x4800 @@ -298,13 +251,6 @@ # define KEY_PPAGE 0x4900 # define A_NORMAL 0x7 # define A_REVERSE 0x70 -#elif defined(HAVE_NCURSES_CURSES_H) -# include <ncurses/curses.h> -#elif defined(HAVE_NCURSES_H) -# include <ncurses.h> -#elif defined(HAVE_CURSES_H) -# include <curses.h> -#endif
/* In old BSD curses, A_NORMAL and A_REVERSE are not defined, so we define them here if they are undefined. */ @@ -358,21 +304,8 @@ /* Remap some libc-API-compatible function names so that we prevent circularararity. */ #ifndef WITHOUT_LIBC_STUBS -//#define memmove grub_memmove -//#define memcpy grub_memmove /* we don't need a separate memcpy */ -//#define memset grub_memset -//#define isspace grub_isspace -// #define printf grub_printf -//#define sprintf grub_sprintf #undef putchar #define putchar grub_putchar -//#define strncat grub_strncat -//#define strstr grub_strstr -//#define memcmp grub_memcmp -//#define strcmp grub_strcmp -//#define tolower grub_tolower -//#define strlen grub_strlen -//#define strcpy grub_strcpy
/* Instead, for FILO we map the grub_ functions to * "normal" functions: @@ -583,32 +516,6 @@ extern char *linux_data_tmp_addr; extern char *linux_data_real_addr;
-#ifdef GRUB_UTIL -/* If not using config file, this variable is set to zero, - otherwise non-zero. */ -extern int use_config_file; -/* If using the preset menu, this variable is set to non-zero, - otherwise zero. */ -extern int use_preset_menu; -/* If not using curses, this variable is set to zero, otherwise non-zero. */ -extern int use_curses; -/* The flag for verbose messages. */ -extern int verbose; -/* The flag for read-only. */ -extern int read_only; -/* The number of floppies to be probed. */ -extern int floppy_disks; -/* The map between BIOS drives and UNIX device file names. */ -extern char **device_map; -/* The filename which stores the information about a device map. */ -extern char *device_map_file; -/* The array of geometries. */ -extern struct geometry *disks; -/* Assign DRIVE to a device name DEVICE. */ -extern void assign_device_name (int drive, const char *device); -#endif - -#ifndef STAGE1_5 /* GUI interface variables. */ # define MAX_FALLBACK_ENTRIES 8 extern int fallback_entries[MAX_FALLBACK_ENTRIES]; @@ -634,7 +541,6 @@ extern int max_lines; extern int count_lines; extern int use_pager; -#endif
#ifndef NO_DECOMPRESSION extern int no_decompression; @@ -645,11 +551,6 @@ extern void (*disk_read_hook) (int, int, int); extern void (*disk_read_func) (int, int, int);
-#ifndef STAGE1_5 -/* The flag for debug mode. */ -extern int debug; -#endif /* STAGE1_5 */ - extern unsigned long current_drive; extern unsigned long current_partition;
@@ -695,10 +596,8 @@ extern unsigned long saved_drive; extern unsigned long saved_partition; extern unsigned long cdrom_drive; -#ifndef STAGE1_5 extern unsigned long saved_mem_upper; extern unsigned long extended_memory; -#endif
/* * Error variables. @@ -833,7 +732,6 @@ void stop_floppy (void);
/* Command-line interface functions. */ -#ifndef STAGE1_5
/* The flags for the builtins. */ #define BUILTIN_CMDLINE 0x1 /* Run in the command-line. */ @@ -891,44 +789,10 @@ #define CMDLINE_EDIT_MODE 0x2
void print_cmdline_message (int type); -#endif
/* C library replacement functions with identical semantics. */ void grub_printf (const char *format,...); -//int grub_sprintf (char *buffer, const char *format, ...); -//int grub_tolower (int c); -//int grub_isspace (int c); -//int grub_strncat (char *s1, const char *s2, int n); -//void *grub_memmove (void *to, const void *from, int len); -//void *grub_memset (void *start, int c, int len); -//int grub_strncat (char *s1, const char *s2, int n); -//char *grub_strstr (const char *s1, const char *s2); -//int grub_memcmp (const char *s1, const char *s2, int n); -//int grub_strcmp (const char *s1, const char *s2); -//int grub_strlen (const char *str); -//char *grub_strcpy (char *dest, const char *src);
-#ifndef GRUB_UTIL -typedef unsigned long grub_jmp_buf[6]; -#else -/* In the grub shell, use the libc jmp_buf instead. */ -# include <setjmp.h> -# define grub_jmp_buf jmp_buf -#endif - -#ifdef GRUB_UTIL -# define grub_setjmp setjmp -# define grub_longjmp longjmp -#else /* ! GRUB_UTIL */ -int grub_setjmp (grub_jmp_buf env); -void grub_longjmp (grub_jmp_buf env, int val); -#endif /* ! GRUB_UTIL */ - -/* The environment for restarting Stage 2. */ -extern grub_jmp_buf restart_env; -/* The environment for restarting the command-line interface. */ -extern grub_jmp_buf restart_cmdline_env; - /* misc */ void init_page (void); void print_error (void); @@ -948,11 +812,6 @@ int gunzip_read (char *buf, int len); #endif /* NO_DECOMPRESSION */
-int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf); -int devread (int sector, int byte_offset, int byte_len, char *buf); -int rawwrite (int drive, int sector, char *buf); -int devwrite (int sector, int sector_len, char *buf); - /* Parse a device string and initialize the global parameters. */ char *set_device (char *device); int open_device (void); @@ -970,22 +829,6 @@ /* Set or clear the current root partition's hidden flag. */ int set_partition_hidden_flag (int hidden);
-#if 0 -/* Open a file or directory on the active device, using GRUB's - internal filesystem support. */ -int grub_open (char *filename); - -/* Read LEN bytes into BUF from the file that was opened with - GRUB_OPEN. If LEN is -1, read all the remaining data in the file. */ -int grub_read (char *buf, int len); - -/* Reposition a file offset. */ -int grub_seek (int offset); - -/* Close a file. */ -void grub_close (void); -#endif - /* List the contents of the directory that was opened with GRUB_OPEN, printing all completions. */ int dir (char *dirname); @@ -1002,7 +845,6 @@ /* Copies the current partition data to the desired address. */ void copy_current_part_entry (char *buf);
-#ifndef STAGE1_5 void bsd_boot (kernel_t type, int bootdev, char *arg) __attribute__ ((noreturn));
@@ -1017,7 +859,6 @@ int load_initrd (char *initrd);
int check_password(char *entered, char* expected, password_t type); -#endif
void init_bios_info (void);
Modified: trunk/filo/main/Makefile.inc =================================================================== --- trunk/filo/main/Makefile.inc 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/Makefile.inc 2008-09-11 17:51:27 UTC (rev 60) @@ -18,5 +18,4 @@
TARGETS-y += main/filo.o main/elfload.o main/elfnote.o main/ipchecksum.o main/strtox.o TARGETS-$(CONFIG_SUPPORT_SOUND) += main/sound.o -TARGETS-$(CONFIG_USE_GRUB) += main/grub.o
Modified: trunk/filo/main/filo.c =================================================================== --- trunk/filo/main/filo.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/filo.c 2008-09-11 17:51:27 UTC (rev 60) @@ -187,4 +187,9 @@ return 0; }
+void print_a_completion (char *name) +{ + // Nothing yet. +} + #endif /* CONFIG_USE_GRUB */
Modified: trunk/filo/main/grub/Makefile.inc =================================================================== --- trunk/filo/main/grub/Makefile.inc 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/Makefile.inc 2008-09-11 17:51:27 UTC (rev 60) @@ -21,6 +21,7 @@ TARGETS-$(CONFIG_USE_GRUB) += main/grub/cmdline.o main/grub/char_io.o TARGETS-$(CONFIG_USE_GRUB) += main/grub/grubcons.o main/grub/serial.o TARGETS-$(CONFIG_USE_GRUB) += main/grub/terminfo.o main/grub/tparm.o -TARGETS-$(CONFIG_USE_GRUB) += main/grub/asmstub.o main/grub/completions.o +TARGETS-$(CONFIG_USE_GRUB) += main/grub/completions.o +TARGETS-$(CONFIG_USE_GRUB) += main/grub/grub.o TARGETS-$(CONFIG_USE_MD5_PASSWORDS) += main/grub/md5.o
Deleted: trunk/filo/main/grub/asmstub.c =================================================================== --- trunk/filo/main/grub/asmstub.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/asmstub.c 2008-09-11 17:51:27 UTC (rev 60) @@ -1,24 +0,0 @@ -/* - * This file is part of FILO. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -unsigned long install_partition = 0x20000; -unsigned long boot_drive = 0; -int saved_entryno = 0; -char version_string[] = "1.0"; -char config_file[128] = "\0"; -
Modified: trunk/filo/main/grub/builtins.c =================================================================== --- trunk/filo/main/grub/builtins.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/builtins.c 2008-09-11 17:51:27 UTC (rev 60) @@ -21,6 +21,7 @@
#include <libpayload.h> #include <config.h> +#include <fs.h> #include <grub/shared.h> #include <grub/term.h> #include <grub/terminfo.h> @@ -41,8 +42,12 @@ unsigned long saved_drive; unsigned long saved_partition; unsigned long saved_mem_upper; +// other.. +unsigned long install_partition = 0x20000; +unsigned long boot_drive = 0; +int saved_entryno = 0; +char config_file[128] = "\0";
- kernel_t kernel_type;
/* The fallback entry. */ @@ -257,6 +262,44 @@ " "blink-" to FG if you want a blinking foreground color." };
+/* configfile */ +static int +configfile_func (char *arg, int flags) +{ + char *new_config = config_file; + + /* Check if the file ARG is present. */ + if (! grub_open (arg)) + return 1; + + grub_close (); + + /* Copy ARG to CONFIG_FILE. */ + while ((*new_config++ = *arg++) != 0) + ; + + /* Force to load the configuration file. */ + // use_config_file = 1; + + /* Make sure that the user will not be authoritative. */ + auth = 0; + + /* Restart cmain. */ + grub_main(); + + /* Never reach here. */ + return 0; +} + +static struct builtin builtin_configfile = +{ + "configfile", + configfile_func, + BUILTIN_CMDLINE | BUILTIN_HELP_LIST, + "configfile FILE", + "Load FILE as the configuration file." +}; + /* default */ static int default_func (char *arg, int flags) @@ -952,22 +995,6 @@ return 1; } } -# ifdef GRUB_UTIL - /* In the grub shell, don't use any port number but open a tty - device instead. */ - else if (grub_memcmp (arg, "--device=", sizeof ("--device=") - 1) == 0) - { - char *p = arg + sizeof ("--device=") - 1; - char dev[256]; /* XXX */ - char *q = dev; - - while (*p && ! grub_isspace (*p)) - *q++ = *p++; - - *q = 0; - serial_set_device (dev); - } -# endif /* GRUB_UTIL */ else break;
@@ -1337,6 +1364,7 @@ { &builtin_boot, &builtin_color, + &builtin_configfile, &builtin_default, #ifdef CONFIG_EXPERIMENTAL &builtin_find,
Modified: trunk/filo/main/grub/char_io.c =================================================================== --- trunk/filo/main/grub/char_io.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/char_io.c 2008-09-11 17:51:27 UTC (rev 60) @@ -67,7 +67,6 @@
-#ifndef STAGE1_5 struct term_entry term_table[] = { #if CONFIG_VGA_CONSOLE == 1 && CONFIG_PC_KEYBOARD ==1 @@ -115,18 +114,12 @@ int max_lines = 24; int count_lines = -1; int use_pager = 1; -#endif
void print_error (void) { if (errnum > ERR_NONE && errnum < MAX_ERR_NUM) -#ifndef STAGE1_5 - /* grub_printf("\7\n %s\n", err_list[errnum]); */ grub_printf ("\nError %u: %s\n", errnum, err_list[errnum]); -#else /* STAGE1_5 */ - grub_printf ("Error %u\n", errnum); -#endif /* STAGE1_5 */ }
char * @@ -135,7 +128,6 @@ unsigned long num = *((&c) + 1), mult = 10; char *ptr = buf;
-#ifndef STAGE1_5 if (c == 'x' || c == 'X') mult = 16;
@@ -145,7 +137,6 @@ *(ptr++) = '-'; buf++; } -#endif
do { @@ -193,17 +184,14 @@ else switch (c = *(format++)) { -#ifndef STAGE1_5 case 'd': case 'x': case 'X': -#endif case 'u': *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0; grub_putstr (str); break;
-#ifndef STAGE1_5 case 'c': grub_putchar ((*(dataptr++)) & 0xff); break; @@ -211,12 +199,10 @@ case 's': grub_putstr ((char *) *(dataptr++)); break; -#endif } } }
-#ifndef STAGE1_5 void init_page (void) { @@ -882,7 +868,6 @@
return 1; } -#endif /* STAGE1_5 */
/* Wait for a keypress and return its code. */ int
Added: trunk/filo/main/grub/grub.c =================================================================== --- trunk/filo/main/grub/grub.c (rev 0) +++ trunk/filo/main/grub/grub.c 2008-09-11 17:51:27 UTC (rev 60) @@ -0,0 +1,116 @@ +/* + * This file is part of FILO. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <libpayload.h> +#include <config.h> +#include <lib.h> +#include <fs.h> +#include <arch/timer.h> + +extern char config_file[]; + +#define ENTER '\r' +#define ESCAPE '\x1b' + +#ifndef CONFIG_MENULST_TIMEOUT +#define CONFIG_MENULST_TIMEOUT 0 +#endif +#if !CONFIG_MENULST_TIMEOUT +#define menulst_delay() 0 /* success */ +#endif + +#if CONFIG_MENULST_TIMEOUT +static inline int menulst_delay(void) +{ + u64 timeout; + int sec, tmp; + char key; + + key = 0; + +#ifdef CONFIG_MENULST_FILE + printf("Press <Enter> for default menu.lst (%s), or <Esc> for prompt... ", + CONFIG_MENULST_FILE); +#else + printf("Press <Enter> for the FILO shell or <ESC> to enter a menu.lst path..."); +#endif + for (sec = CONFIG_MENULST_TIMEOUT; sec>0 && key==0; sec--) { + printf("%d", sec); + timeout = currticks() + TICKS_PER_SEC; + while (currticks() < timeout) { + if (havechar()) { + key = getchar(); + if (key==ENTER || key==ESCAPE) + break; + } + } + for (tmp = sec; tmp; tmp /= 10) + printf("\b \b"); + } + if (key == 0) { + printf("timed out\n"); + return 0; /* success */ + } else { + putchar('\n'); + if (key == ESCAPE) + return -1; /* canceled */ + else + return 0; /* default accepted */ + } +} +#endif /* CONFIG_MENULST_TIMEOUT */ + +void grub_menulst(void) +{ + char line[256]; + + /* If Escape key is pressed already, skip autoboot */ + if (havechar() && getchar()==ESCAPE) + return; + + if (menulst_delay()==0) { +#ifdef CONFIG_MENULST_FILE + printf("menu: %s\n", CONFIG_MENULST_FILE); + strcpy(config_file, CONFIG_MENULST_FILE); +#endif + } else { + /* The above didn't work, ask user */ + while (havechar()) + getchar(); + +#ifdef CONFIG_MENULST_FILE + strncpy(line, CONFIG_MENULST_FILE, sizeof(line)-1); + line[sizeof(line)-1] = '\0'; +#else + line[0] = '\0'; +#endif + for (;;) { + printf("menu: "); + getline(line, sizeof line); + + if (strcmp(line,"quit")==0) break; + + if (line[0]) { + strcpy(config_file, line); + break; + } + } + } + + +} +
Modified: trunk/filo/main/grub/serial.c =================================================================== --- trunk/filo/main/grub/serial.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/serial.c 2008-09-11 17:51:27 UTC (rev 60) @@ -33,8 +33,6 @@
static int keep_track = 1;
-#ifndef GRUB_UTIL - /* Fetch a key. */ int serial_hw_fetch (void) @@ -94,9 +92,7 @@ #endif return 1; } -#endif /* ! GRUB_UTIL */
- /* Generic definitions. */
#if CONFIG_SERIAL_CONSOLE
Modified: trunk/filo/main/grub/stage2.c =================================================================== --- trunk/filo/main/grub/stage2.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub/stage2.c 2008-09-11 17:51:27 UTC (rev 60) @@ -1,6 +1,7 @@ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2000,2001,2002,2004,2005 Free Software Foundation, Inc. + * Copyright (C) 2005-2008 coresystems GmbH * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,36 +22,24 @@ #include <config.h> #include <grub/shared.h> #include <grub/term.h> +#include <fs.h>
-int file_open(const char *filename); -int file_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); -void file_close(void); +/* Define if there is user specified preset menu string */ +/* #undef PRESET_MENU_STRING */ + void grub_menulst(void);
struct multiboot_info mbi;
-#if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS) +#if defined(PRESET_MENU_STRING)
-# if defined(PRESET_MENU_STRING) static const char *preset_menu = PRESET_MENU_STRING; -# elif defined(SUPPORT_DISKLESS) -/* Execute the command "bootp" automatically. */ -static const char *preset_menu = "bootp\n"; -# endif /* SUPPORT_DISKLESS */
static int preset_menu_offset;
static int open_preset_menu (void) { -#ifdef GRUB_UTIL - /* Unless the user explicitly requests to use the preset menu, - always opening the preset menu fails in the grub shell. */ - if (! use_preset_menu) - return 0; -#endif /* GRUB_UTIL */ - preset_menu_offset = 0; return preset_menu != 0; } @@ -76,13 +65,13 @@ preset_menu = 0; }
-#else /* ! PRESET_MENU_STRING && ! SUPPORT_DISKLESS */ +#else /* ! PRESET_MENU_STRING */
#define open_preset_menu() 0 #define read_from_preset_menu(buf, maxlen) 0 #define close_preset_menu()
-#endif /* ! PRESET_MENU_STRING && ! SUPPORT_DISKLESS */ +#endif /* ! PRESET_MENU_STRING */
static char * get_entry (char *list, int num, int nested) @@ -798,13 +787,6 @@
break; } -#ifdef GRUB_UTIL - if (c == 'q') - { - /* The same as ``quit''. */ - stop (); - } -#endif } } } @@ -951,19 +933,16 @@ init_config (); }
- // /* Initialize the environment for restarting Stage 2. */ - // grub_setjmp (restart_env); - /* Initialize the kill buffer. */ *kill_buf = 0;
-#if (defined(CONFIG_SERIAL_CONSOLE) && CONFIG_SERIAL_CONSOLE == 1) +#ifdef CONFIG_SERIAL_CONSOLE { errnum=0; memset(myheap, 0, 256); run_script("serial --unit=0 --speed=9600\n\0", myheap); // dummy call memset(myheap, 0, 256); -#if !(defined(CONFIG_VGA_CONSOLE) && CONFIG_VGA_CONSOLE == 1 ) +#ifndef CONFIG_VGA_CONSOLE run_script("terminal serial\n\0", myheap); #endif } @@ -979,9 +958,6 @@
/* Here load the configuration file. */
-#ifdef GRUB_UTIL - if (use_config_file) -#endif /* GRUB_UTIL */ { char *default_file = (char *) DEFAULT_FILE_BUF; int i;
Deleted: trunk/filo/main/grub.c =================================================================== --- trunk/filo/main/grub.c 2008-09-04 06:22:39 UTC (rev 59) +++ trunk/filo/main/grub.c 2008-09-11 17:51:27 UTC (rev 60) @@ -1,119 +0,0 @@ -/* - * This file is part of FILO. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <libpayload.h> -#include <config.h> -#include <lib.h> -#include <fs.h> -#include <arch/timer.h> - -extern char config_file[]; -// #include <grub/shared.h> - -#define ENTER '\r' -#define ESCAPE '\x1b' - -#ifndef CONFIG_MENULST_TIMEOUT -#define CONFIG_MENULST_TIMEOUT 0 -#endif -#if !CONFIG_MENULST_TIMEOUT -#define menulst_delay() 0 /* success */ -#endif - -#ifdef CONFIG_USE_GRUB -#if CONFIG_MENULST_TIMEOUT -static inline int menulst_delay(void) -{ - u64 timeout; - int sec, tmp; - char key; - - key = 0; - -#ifdef CONFIG_MENULST_FILE - printf("Press <Enter> for default menu.lst (%s), or <Esc> for prompt... ", - CONFIG_MENULST_FILE); -#else - printf("Press <Enter> for the FILO shell or <ESC> to enter a menu.lst path..."); -#endif - for (sec = CONFIG_MENULST_TIMEOUT; sec>0 && key==0; sec--) { - printf("%d", sec); - timeout = currticks() + TICKS_PER_SEC; - while (currticks() < timeout) { - if (havechar()) { - key = getchar(); - if (key==ENTER || key==ESCAPE) - break; - } - } - for (tmp = sec; tmp; tmp /= 10) - printf("\b \b"); - } - if (key == 0) { - printf("timed out\n"); - return 0; /* success */ - } else { - putchar('\n'); - if (key == ESCAPE) - return -1; /* canceled */ - else - return 0; /* default accepted */ - } -} -#endif /* CONFIG_MENULST_TIMEOUT */ - -void grub_menulst(void) -{ - char line[256]; - - /* If Escape key is pressed already, skip autoboot */ - if (havechar() && getchar()==ESCAPE) - return; - - if (menulst_delay()==0) { -#ifdef CONFIG_MENULST_FILE - printf("menu: %s\n", CONFIG_MENULST_FILE); - strcpy(config_file, CONFIG_MENULST_FILE); -#endif - } else { - /* The above didn't work, ask user */ - while (havechar()) - getchar(); - -#ifdef CONFIG_MENULST_FILE - strncpy(line, CONFIG_MENULST_FILE, sizeof(line)-1); - line[sizeof(line)-1] = '\0'; -#else - line[0] = '\0'; -#endif - for (;;) { - printf("menu: "); - getline(line, sizeof line); - - if (strcmp(line,"quit")==0) break; - - if (line[0]) { - strcpy(config_file, line); - break; - } - } - } - - -} -#endif /* CONFIG_USE_GRUB */ -