Author: stepan
Date: 2009-07-30 19:10:26 +0200 (Thu, 30 Jul 2009)
New Revision: 103
Modified:
trunk/filo/Config.in
trunk/filo/Documentation/CHANGES
trunk/filo/Documentation/FAQ
trunk/filo/Makefile
trunk/filo/README
trunk/filo/build.sh
trunk/filo/drivers/ide_new.c
trunk/filo/drivers/ide_new.h
trunk/filo/fs/blockdev.c
trunk/filo/fs/filesys.h
trunk/filo/include/debug.h
trunk/filo/include/lib.h
trunk/filo/main/filo.c
trunk/filo/main/grub/builtins.c
trunk/filo/main/grub/char_io.c
trunk/filo/main/grub/cmdline.c
trunk/filo/main/grub/completions.c
Log:
* preprocessor fixups
* drop some prototypes that are already in libpayload.h
* fix some shadowed variables
* fix error reporting in the boot command
* fix keyboard issues in grub interface
* don't require "head" for building filo
* fix CD booting
Modified: trunk/filo/Config.in
===================================================================
--- trunk/filo/Config.in 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/Config.in 2009-07-30 17:10:26 UTC (rev 103)
@@ -1,5 +1,5 @@
##
-## Copyright (C) 2008 coresystems GmbH
+## Copyright (C) 2008-2009 coresystems GmbH
##
mainmenu "FILO Configuration"
Modified: trunk/filo/Documentation/CHANGES
===================================================================
--- trunk/filo/Documentation/CHANGES 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/Documentation/CHANGES 2009-07-30 17:10:26 UTC (rev 103)
@@ -1,3 +1,5 @@
+As of 0.6 this file is neglected in favor of svn commit messages.
+
Version 0.6.0b1 stepan 2008-08-11
* Use Kconfig for configuration
* Drop recursive Makefiles
Modified: trunk/filo/Documentation/FAQ
===================================================================
--- trunk/filo/Documentation/FAQ 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/Documentation/FAQ 2009-07-30 17:10:26 UTC (rev 103)
@@ -1,5 +1,6 @@
Q. My GRUB menu.lst does not work.
-A. The disks are numbered differently in FILO, following the linux scheme.
+A. The disks are numbered differently in FILO. They might or might not follow
+ the Linux scheme, depending on the order of driver modules in Linux, etc.
hd2,0 is hdc1, not necessarily the third disk (there might be no hdb)
Q. FILO loads my ELF kernel fine, but complains "Verify FAILED".
Modified: trunk/filo/Makefile
===================================================================
--- trunk/filo/Makefile 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/Makefile 2009-07-30 17:10:26 UTC (rev 103)
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2008 by coresystems GmbH
+# Copyright (C) 2008-2009 by 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
@@ -93,7 +93,7 @@
GCCINCDIR = $(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
CPPFLAGS = -nostdinc -imacros $(obj)/config.h -Iinclude -I$(GCCINCDIR) -MD
-CFLAGS += -Wall $(STACKPROTECT) $(INCLUDES) -Os -fomit-frame-pointer -fno-common -ffreestanding -fno-strict-aliasing
+CFLAGS += $(STACKPROTECT) $(INCLUDES) -Wall -Os -fomit-frame-pointer -fno-common -ffreestanding -fno-strict-aliasing -Wshadow
TARGET = $(obj)/filo.elf
Modified: trunk/filo/README
===================================================================
--- trunk/filo/README 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/README 2009-07-30 17:10:26 UTC (rev 103)
@@ -177,7 +177,8 @@
LICENSE
Copyright (C) 2003 by SONE Takeshi <ts1(a)tsn.or.jp> and others.
- Copyright (C) 2005-2008 by coresystems GmbH <info(a)coresystems.de>.
+ Copyright (C) 2005-2009 by coresystems GmbH <info(a)coresystems.de>.
This program is licensed under the terms of GNU General Public License.
See the COPYING file for details.
+
Modified: trunk/filo/build.sh
===================================================================
--- trunk/filo/build.sh 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/build.sh 2009-07-30 17:10:26 UTC (rev 103)
@@ -20,7 +20,7 @@
continue
fi
if ${gccprefixes}as --32 -o ${TMP}.o ${TMP}.s; then
- head -c 4 ${TMP}.o > ${TMP}.test
+ dd bs=4 count=1 if=${TMP}.o > ${TMP}.test 2>/dev/null
if cmp ${TMP}.test ${TMP}.compare; then
GCCPREFIX=$gccprefixes
rm -f $TMP ${TMP}.s ${TMP}.o ${TMP}.compare ${TMP}.test
Modified: trunk/filo/drivers/ide_new.c
===================================================================
--- trunk/filo/drivers/ide_new.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/drivers/ide_new.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -819,11 +819,11 @@
{
if (!sectors)
return 1;
- if (block + sectors > drive->sectors)
+ if (block + sectors > (drive->sectors * (drive->bs / 512)))
return 1;
#ifdef CONFIG_DEBUG_IDE
- printf("ob_ide_read_sectors: block=%Ld sectors=%u\n", (unsigned long) block, sectors);
+ printf("ob_ide_read_sectors: block=%ld sectors=%u\n", (unsigned long) block, sectors);
#endif
if (drive->type == ide_type_ata)
@@ -1306,21 +1306,20 @@
#else /* !CONFIG_SUPPORT_PCI */
# define find_ide_controller find_ide_controller_compat
#endif
-//int ob_ide_init(int (*func)(struct ide_drive*))
-int ob_ide_init(int drive)
+int ob_ide_init(int driveno)
{
int j;
struct ide_channel *chan;
int chan_index;
- if (drive >= IDE_MAX_DRIVES) {
+ if (driveno >= IDE_MAX_DRIVES) {
printf("Unsupported drive number\n");
return -1;
}
/* A controller has two drives (master, slave) */
- chan_index = drive >> 1;
+ chan_index = driveno >> 1;
chan = &ob_ide_channels[chan_index];
if (chan->present == 0) {
Modified: trunk/filo/drivers/ide_new.h
===================================================================
--- trunk/filo/drivers/ide_new.h 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/drivers/ide_new.h 2009-07-30 17:10:26 UTC (rev 103)
@@ -217,8 +217,7 @@
ob_ide_read_blocks(struct ide_drive *drive, int n, u32 blk, unsigned char* dest);
static int
ob_ide_atapi_request_sense(struct ide_drive *drive);
-//int ob_ide_init(int (*func)(struct ide_drive*));
-int ob_ide_init(int drive);
+int ob_ide_init(int driveno);
/* FILO compat */
Modified: trunk/filo/fs/blockdev.c
===================================================================
--- trunk/filo/fs/blockdev.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/fs/blockdev.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -188,7 +188,7 @@
name += 3;
*drive = 0;
} else {
- printf("Unknown device type\n");
+ printf("Unknown device type: %s\n", name);
return 0;
}
@@ -450,8 +450,11 @@
char *dest = buf;
unsigned long len;
- sector += byte_offset >> 9;
- byte_offset &= 0x1ff;
+ /* while sectors are technically 512b in filo, iso9660 requires
+ some special handling. This wastes up to three sectors worth
+ of RAM on a 512b filesystem, but enables iso9660 to work. */
+ sector += (byte_offset >> 11) * 4;
+ byte_offset &= 0x7ff;
if (sector + ((byte_len + 0x1ff) >> 9) > part_length) {
printf("Attempt to read beyond device/partition.\n");
@@ -466,6 +469,15 @@
debug("Couldn't read sector.\n");
return 0;
}
+ /* now, we always only request one sector at a time,
+ but rely on the cache system to iron out the
+ issues with 2048b sectors. Yet, we have to skip
+ the first fake sectors in processing. */
+ if (byte_offset >= 512) {
+ byte_offset -= 512;
+ sector++;
+ continue;
+ }
len = 512 - byte_offset;
if (len > byte_len)
len = byte_len;
Modified: trunk/filo/fs/filesys.h
===================================================================
--- trunk/filo/fs/filesys.h 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/fs/filesys.h 2009-07-30 17:10:26 UTC (rev 103)
@@ -278,6 +278,6 @@
#define FS_FILECORE 16 /* Acorn Filecore Filing System */
#define FS_EXT2FS 17 /* Linux Extended 2 file system */
-#if CONFIG_DEBUG_FSYS_EXT2FS
+#ifdef CONFIG_DEBUG_FSYS_EXT2FS
#define E2DEBUG
#endif
Modified: trunk/filo/include/debug.h
===================================================================
--- trunk/filo/include/debug.h 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/include/debug.h 2009-07-30 17:10:26 UTC (rev 103)
@@ -22,15 +22,15 @@
#include <lib.h>
/* Defining DEBUG_THIS before including this file enables debug() macro
- * for the file. DEBUG_ALL is for global control. */
+ * for the file. CONFIG_DEBUG_ALL is for global control. */
-#if DEBUG_THIS || DEBUG_ALL
+#if ( defined(DEBUG_THIS) && (DEBUG_THIS == 1)) || (defined(CONFIG_DEBUG_ALL) && (CONFIG_DEBUG_ALL == 1))
#define DEBUG 1
#else
#undef DEBUG
#endif
-#if DEBUG
+#ifdef DEBUG
# define debug(...) \
printf(__VA_ARGS__)
# define debug_hexdump hexdump
@@ -39,7 +39,7 @@
# define debug_hexdump(...) /* nothing */
#endif
-#if CONFIG_USE_GRUB
+#ifdef CONFIG_USE_GRUB
extern int using_grub_interface;
void grub_printf (const char *format,...);
#define printf(x...) do { if (using_grub_interface) { grub_printf(x); } else { printf(x); } } while (0)
Modified: trunk/filo/include/lib.h
===================================================================
--- trunk/filo/include/lib.h 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/include/lib.h 2009-07-30 17:10:26 UTC (rev 103)
@@ -22,9 +22,6 @@
#include <libpayload.h>
#include <config.h>
-// from libpayload.
-int getline(char *buf, int max);
-
unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
unsigned long long strtoull_with_suffix(const char *cp,char **endp,unsigned int base);
@@ -32,8 +29,6 @@
long long simple_strtoll(const char *cp,char **endp,unsigned int base);
-void halt(void) __attribute__((noreturn));
-
#define abort() halt()
#define LOADER_NOT_SUPPORT 0xbadf11e
@@ -41,19 +36,19 @@
struct sys_info;
int elf_load(const char *filename, const char *cmdline);
-#if CONFIG_LINUX_LOADER
+#ifdef CONFIG_LINUX_LOADER
int linux_load(const char *filename, const char *cmdline);
#else
#define linux_load(x,y) LOADER_NOT_SUPPORT /* nop */
#endif
-#if CONFIG_WINCE_LOADER
+#ifdef CONFIG_WINCE_LOADER
int wince_load(const char *filename, const char *cmdline);
#else
#define wince_load(x,y) LOADER_NOT_SUPPORT /* nop */
#endif
-#if CONFIG_ARTEC_BOOT
+#ifdef CONFIG_ARTEC_BOOT
int artecboot_load(const char *filename, const char *cmdline);
#else
#define artecboot_load(x,y) LOADER_NOT_SUPPORT /* nop */
Modified: trunk/filo/main/filo.c
===================================================================
--- trunk/filo/main/filo.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/main/filo.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -37,7 +37,7 @@
#define autoboot() ((void) 0) /* nop */
#endif
-#if CONFIG_AUTOBOOT_DELAY == 0
+#ifndef CONFIG_AUTOBOOT_DELAY
#define autoboot_delay() 0 /* success */
#endif
@@ -78,9 +78,10 @@
#endif
}
-void boot(const char *line)
+int boot(const char *line)
{
char *file, *param;
+ int ret;
/* Split filename and parameter */
file = strdup(line);
@@ -90,12 +91,38 @@
param++;
}
- if (artecboot_load(file, param) == LOADER_NOT_SUPPORT)
- if (elf_load(file, param) == LOADER_NOT_SUPPORT)
- if (linux_load(file, param) == LOADER_NOT_SUPPORT)
- if (wince_load(file, param) == LOADER_NOT_SUPPORT)
- printf("Unsupported image format\n");
+ /* If the boot command is successful, the loader
+ * function will not return.
+ *
+ * If the loader is not supported, or it recognized
+ * that it does not match for the given file type, it
+ * will return LOADER_NOT_SUPPORT.
+ *
+ * All other cases are an unknown error for now.
+ */
+
+ ret = artecboot_load(file, param);
+ if (ret != LOADER_NOT_SUPPORT)
+ goto out;
+
+ ret = elf_load(file, param);
+ if (ret != LOADER_NOT_SUPPORT)
+ goto out;
+
+ ret = linux_load(file, param);
+ if (ret != LOADER_NOT_SUPPORT)
+ goto out;
+
+ ret = wince_load(file, param);
+ if (ret != LOADER_NOT_SUPPORT)
+ goto out;
+
+ printf("Unsupported image format\n");
+
+out:
free(file);
+
+ return ret;
}
void reset_handler(void)
Modified: trunk/filo/main/grub/builtins.c
===================================================================
--- trunk/filo/main/grub/builtins.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/main/grub/builtins.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -22,6 +22,7 @@
#include <libpayload.h>
#include <config.h>
#include <fs.h>
+#include <lib.h>
#include <grub/shared.h>
#include <arch/timer.h>
#ifdef CONFIG_USE_MD5_PASSWORDS
@@ -74,6 +75,8 @@
int show_menu = 1;
+static int last_normal_color = -1, last_highlight_color = -1;
+
/* Initialize the data for builtins. */
void init_builtins(void)
{
@@ -108,13 +111,20 @@
/* boot */
static int boot_func(char *arg, int flags)
{
- void boot(const char *line);
+ int boot(const char *line);
+ int ret;
if(!boot_line[0]) {
- grub_printf("No kernel.\n");
+ errnum = ERR_BOOT_COMMAND;
return 1;
}
+ /* Set color back to black and white, or Linux booting will look
+ * very funny.
+ */
+ console_setcolor((COLOR_BLACK << 4) | COLOR_WHITE,
+ (COLOR_WHITE << 4) | COLOR_BLACK);
+
cls();
if (initrd_space[0]) {
@@ -123,7 +133,27 @@
}
grub_printf("\nBooting '%s'\n", boot_line);
- boot(boot_line);
+
+ ret = boot(boot_line);
+
+ /* If we regain control, something went wrong. */
+
+ /* The menu color was changed and we failed to boot, so we
+ * need to restore the colors in order to make the menu look as
+ * it did before.
+ */
+ if (last_normal_color != -1) {
+ console_setcolor(last_normal_color, last_highlight_color);
+ }
+
+ /* If no loader felt responsible for this image format, it's
+ * a bad file format, otherwise we don't really know.
+ */
+ if (ret == LOADER_NOT_SUPPORT)
+ errnum = ERR_EXEC_FORMAT;
+ else
+ errnum = ERR_BOOT_FAILURE;
+
return 1;
}
@@ -238,6 +268,10 @@
console_setcolor(new_normal_color, new_highlight_color);
+ // keep the state so we can restore after a failed boot
+ last_normal_color = new_normal_color;
+ last_highlight_color = new_highlight_color;
+
return 0;
}
Modified: trunk/filo/main/grub/char_io.c
===================================================================
--- trunk/filo/main/grub/char_io.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/main/grub/char_io.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -125,7 +125,7 @@
num_history++;
}
-static int real_get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline)
+static int real_get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline_like)
{
/* This is a rather complicated function. So explain the concept.
@@ -369,7 +369,7 @@
while ((c = ASCII_CHAR(getkey())) != '\n' && c != '\r') {
/* If READLINE is non-zero, handle readline-like key bindings. */
- if (readline) {
+ if (readline_like) {
switch (c) {
case 9: /* TAB lists completions */
{
@@ -560,7 +560,7 @@
/* If the readline-like feature is turned on and CMDLINE is not
empty, add it into the history list. */
- if (readline && lpos < llen)
+ if (readline_like && lpos < llen)
add_history(cmdline, 0);
refresh();
@@ -576,7 +576,7 @@
or zero-length).
If ECHO_CHAR is nonzero, echo it instead of the typed character. */
-int get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline)
+int get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline_like)
{
int old_cursor;
int ret;
@@ -628,7 +628,7 @@
}
/* Complicated features are left to real_get_cmdline. */
- ret = real_get_cmdline(prompt, cmdline, maxlen, echo_char, readline);
+ ret = real_get_cmdline(prompt, cmdline, maxlen, echo_char, readline_like);
setcursor(old_cursor);
refresh();
return ret;
Modified: trunk/filo/main/grub/cmdline.c
===================================================================
--- trunk/filo/main/grub/cmdline.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/main/grub/cmdline.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -204,7 +204,7 @@
intervention. */
if (fallback_entryno < 0) {
grub_printf("\nPress any key to continue...");
- (void) getchar();
+ (void)getkey();
}
return 1;
Modified: trunk/filo/main/grub/completions.c
===================================================================
--- trunk/filo/main/grub/completions.c 2009-07-18 14:44:04 UTC (rev 102)
+++ trunk/filo/main/grub/completions.c 2009-07-30 17:10:26 UTC (rev 103)
@@ -62,7 +62,7 @@
int print_completions(int is_filename, int is_completion)
{
-#if CONFIG_EXPERIMENTAL
+#ifdef CONFIG_EXPERIMENTAL
char *buf = (char *) COMPLETION_BUF;
char *ptr = buf;