From e880248e79587a962f9b21189d2202060d39e54a Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 9 Nov 2009 14:55:27 +0000 Subject: [PATCH 001/164] Fix *.lst handling after ${prefix} redefinition. --- normal/autofs.c | 15 +++++++++------ normal/dyncmd.c | 16 ++++++++++------ normal/handler.c | 16 ++++++++++------ normal/main.c | 15 ++++++++++++--- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/normal/autofs.c b/normal/autofs.c index ce354a22c..cf552052a 100644 --- a/normal/autofs.c +++ b/normal/autofs.c @@ -51,12 +51,6 @@ void read_fs_list (void) { const char *prefix; - static int first_time = 1; - - /* Make sure that this function does not get executed twice. */ - if (! first_time) - return; - first_time = 0; prefix = grub_env_get ("prefix"); if (prefix) @@ -72,6 +66,15 @@ read_fs_list (void) file = grub_file_open (filename); if (file) { + /* Override previous fs.lst. */ + while (fs_module_list) + { + grub_named_list_t tmp; + tmp = fs_module_list->next; + grub_free (fs_module_list); + fs_module_list = tmp; + } + while (1) { char *buf; diff --git a/normal/dyncmd.c b/normal/dyncmd.c index dc530b07b..6e5028906 100644 --- a/normal/dyncmd.c +++ b/normal/dyncmd.c @@ -62,12 +62,6 @@ void read_command_list (void) { const char *prefix; - static int first_time = 1; - - /* Make sure that this function does not get executed twice. */ - if (! first_time) - return; - first_time = 0; prefix = grub_env_get ("prefix"); if (prefix) @@ -84,6 +78,16 @@ read_command_list (void) if (file) { char *buf = NULL; + + /* Override previous commands.lst. */ + while (grub_command_list) + { + grub_command_t tmp; + tmp = grub_command_list->next; + grub_free (grub_command_list); + grub_command_list = tmp; + } + for (;; grub_free (buf)) { char *p, *name, *modname; diff --git a/normal/handler.c b/normal/handler.c index eb19f912f..b32209a44 100644 --- a/normal/handler.c +++ b/normal/handler.c @@ -135,7 +135,6 @@ void read_handler_list (void) { const char *prefix; - static int first_time = 1; const char *class_name; auto int iterate_handler (grub_handler_t handler); @@ -162,11 +161,6 @@ read_handler_list (void) return 0; } - /* Make sure that this function does not get executed twice. */ - if (! first_time) - return; - first_time = 0; - prefix = grub_env_get ("prefix"); if (prefix) { @@ -182,6 +176,16 @@ read_handler_list (void) if (file) { char *buf = NULL; + + /* Override previous handler.lst. */ + while (grub_handler_class_list) + { + grub_handler_class_t tmp; + tmp = grub_handler_class_list->next; + grub_free (grub_handler_class_list); + grub_handler_class_list = tmp; + } + for (;; grub_free (buf)) { char *p; diff --git a/normal/main.c b/normal/main.c index 748eef805..499eb59f6 100644 --- a/normal/main.c +++ b/normal/main.c @@ -404,6 +404,16 @@ grub_normal_init_page (void) static int reader_nested; +static char * +read_lists (struct grub_env_var *var __attribute__ ((unused)), + const char *val) +{ + read_command_list (); + read_fs_list (); + read_handler_list (); + return val ? grub_strdup (val) : NULL; +} + /* Read the config file CONFIG and execute the menu interface or the command line interface if BATCH is false. */ void @@ -411,9 +421,8 @@ grub_normal_execute (const char *config, int nested, int batch) { grub_menu_t menu = 0; - read_command_list (); - read_fs_list (); - read_handler_list (); + read_lists (NULL, NULL); + grub_register_variable_hook ("prefix", NULL, read_lists); grub_command_execute ("parser.sh", 0, 0); reader_nested = nested; From c9b1ebc10bea80b7be294d75cada90c668b14ed6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 Nov 2009 17:13:17 +0100 Subject: [PATCH 002/164] First try to gcry glue --- conf/common.rmk | 2 + conf/gcry.rmk | 52 +++++++++++++++ conf/i386-pc.rmk | 4 +- import_gcry.py | 136 ++++++++++++++++++++++++++++++++++++++ include/grub/crypto.h | 138 +++++++++++++++++++++++++++++++++++++++ include/grub/gcry_wrap.h | 36 ++++++++++ kern/crypto.c | 34 ++++++++++ 7 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 conf/gcry.rmk create mode 100644 import_gcry.py create mode 100644 include/grub/crypto.h create mode 100644 include/grub/gcry_wrap.h create mode 100644 kern/crypto.c diff --git a/conf/common.rmk b/conf/common.rmk index e1ac5274c..0d19344a7 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -618,3 +618,5 @@ pkglib_MODULES += setjmp.mod setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS) + +include $(srcdir)/conf/gcry.mk diff --git a/conf/gcry.rmk b/conf/gcry.rmk new file mode 100644 index 000000000..0eb3c79bc --- /dev/null +++ b/conf/gcry.rmk @@ -0,0 +1,52 @@ +# -*- makefile -*- + +pkglib_MODULES += seed.mod +seed_mod_SOURCES = gcry/cipher/seed.c +seed_mod_ASFLAGS = $(COMMON_ASFLAGS) +seed_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += twofish.mod +twofish_mod_SOURCES = gcry/cipher/twofish.c +twofish_mod_ASFLAGS = $(COMMON_ASFLAGS) +twofish_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += des.mod +des_mod_SOURCES = gcry/cipher/des.c +des_mod_ASFLAGS = $(COMMON_ASFLAGS) +des_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += arcfour.mod +arcfour_mod_SOURCES = gcry/cipher/arcfour.c +arcfour_mod_ASFLAGS = $(COMMON_ASFLAGS) +arcfour_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += rfc2268.mod +rfc2268_mod_SOURCES = gcry/cipher/rfc2268.c +rfc2268_mod_ASFLAGS = $(COMMON_ASFLAGS) +rfc2268_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += cast5.mod +cast5_mod_SOURCES = gcry/cipher/cast5.c +cast5_mod_ASFLAGS = $(COMMON_ASFLAGS) +cast5_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += camellia-glue.mod +camellia-glue_mod_SOURCES = gcry/cipher/camellia-glue.c +camellia-glue_mod_ASFLAGS = $(COMMON_ASFLAGS) +camellia-glue_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += rijndael.mod +rijndael_mod_SOURCES = gcry/cipher/rijndael.c +rijndael_mod_ASFLAGS = $(COMMON_ASFLAGS) +rijndael_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += serpent.mod +serpent_mod_SOURCES = gcry/cipher/serpent.c +serpent_mod_ASFLAGS = $(COMMON_ASFLAGS) +serpent_mod_LDFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += blowfish.mod +blowfish_mod_SOURCES = gcry/cipher/blowfish.c +blowfish_mod_ASFLAGS = $(COMMON_ASFLAGS) +blowfish_mod_LDFLAGS = $(COMMON_ASFLAGS) + diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 373b942cc..0e3291782 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -58,13 +58,15 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/generic/millisleep.c \ kern/env.c \ term/i386/pc/console.c term/i386/vga_common.c \ + kern/crypto.c \ symlist.c kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h + machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h \ + crypto.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/import_gcry.py b/import_gcry.py new file mode 100644 index 000000000..c751f5e6f --- /dev/null +++ b/import_gcry.py @@ -0,0 +1,136 @@ +import re +import sys +import os +import datetime + +if len (sys.argv) < 3: + print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) + exit (0) +indir = sys.argv[1] +outdir = sys.argv[2] + +basedir = os.path.join (outdir, "gcry") +os.makedirs (basedir) +cipher_dir_in = os.path.join (indir, "cipher") +cipher_dir_out = os.path.join (basedir, "cipher") +os.makedirs (cipher_dir_out) +cipher_files = os.listdir (cipher_dir_in) +conf = open (os.path.join (outdir, "conf", "gcry.rmk"), "w") +conf.write ("# -*- makefile -*-\n\n") +chlog = "" + +for cipher_file in cipher_files: + infile = os.path.join (cipher_dir_in, cipher_file) + outfile = os.path.join (cipher_dir_out, cipher_file) + if cipher_file == "ChangeLog": + continue + chlognew = " * %s" % cipher_file + nch = False + if re.match (".*\.[ch]$", cipher_file): + isc = re.match (".*\.c$", cipher_file) + f = open (infile, "r") + fw = open (outfile, "w") + fw.write ("/* This file was automatically imported with \n") + fw.write (" import_gcry.py. Please don't modify it */\n"); + ciphernames = [] + for line in f: + m = re.match ("#include <.*>", line) + if not m is None: + chmsg = "Removed including of %s" % \ + m.group () [len ("#include <"):len (m.group ()) - 1] + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s: %s" % (chlognew, chmsg) + nch = True + continue + m = re.match ("gcry_cipher_spec_t", line) + if isc and not m is None: + ciphername = line [len ("gcry_cipher_spec_t"):].strip () + ciphername = re.match("[a-zA-Z0-9_]*",ciphername).group () + ciphernames.append (ciphername) + fw.write (line) + if len (ciphernames) > 0: + modname = cipher_file [0:len(cipher_file) - 2] + chmsg = "(GRUB_MOD_INIT(%s)): New function\n" % modname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s%s" % (chlognew, chmsg) + nch = True + fw.write ("\n\nGRUB_MOD_INIT(%s)\n" % modname) + fw.write ("{\n") + for ciphername in ciphernames: + chmsg = "Register cipher %s" % ciphername + chlognew = "%s\n %s" % (chlognew, chmsg) + fw.write (" grub_cipher_register (&%s);\n" % ciphername) + fw.write ("}") + chmsg = "(GRUB_MOD_FINI(%s)): New function\n" % modname + chlognew = "%s\n %s" % (chlognew, chmsg) + fw.write ("\n\nGRUB_MOD_FINI(%s)\n" % modname) + fw.write ("{\n") + for ciphername in ciphernames: + chmsg = "Unregister cipher %s" % ciphername + chlognew = "%s\n %s" % (chlognew, chmsg) + fw.write (" grub_cipher_unregister (&%s);\n" % ciphername) + fw.write ("}\n") + conf.write ("pkglib_MODULES += %s.mod\n" % modname) + conf.write ("%s_mod_SOURCES = gcry/cipher/%s\n" %\ + (modname, cipher_file)) + conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-error\n" % modname) + conf.write ("%s_mod_LDFLAGS = $(COMMON_ASFLAGS)\n\n" % modname) + elif isc: + print ("WARNING: c file isn't a module: %s" % cipher_file) + f.close () + fw.close () + if nch: + chlog = "%s%s\n" % (chlog, chlognew) + continue + if re.match ("(Manifest|Makefile\.am)$", cipher_file): + chlog = "%s%sRemoved\n" % (chlog, chlognew) + continue + # Autogenerated files. Not even worth mentionning in ChangeLog + if re.match ("Makefile\.in$", cipher_file): + chlog = "%s%sRemoved\n" % (chlog, chlognew) + continue + chlog = "%s%sSkipped unknown file\n" % (chlog, chlognew) + print ("WARNING: unknown file %s" % cipher_file) + +outfile = os.path.join (cipher_dir_out, "types.h") +fw=open (outfile, "w") +fw.write ("#include \n") +fw.write ("#include \n") +chlog = "%s * types.h: New file.\n" % chlog +fw.close () + +outfile = os.path.join (cipher_dir_out, "cipher.h") +fw=open (outfile, "w") +fw.write ("#include \n") +fw.write ("#include \n") +chlog = "%s * cipher.h: Likewise.\n" % chlog +fw.close () + +outfile = os.path.join (cipher_dir_out, "g10lib.h") +fw=open (outfile, "w") +fw.write ("#include \n") +chlog = "%s * g10lib.h: Likewise.\n" % chlog +fw.close () + +infile = os.path.join (cipher_dir_in, "ChangeLog") +outfile = os.path.join (cipher_dir_out, "ChangeLog") + + +f=open (infile, "r") +fw=open (outfile, "w") +dt = datetime.date.today () +fw.write ("%04d-%02d-%02d Automatic import tool\n" % \ + (dt.year,dt.month, dt.day)) +fw.write ("\n") +fw.write (" Imported ciphers to GRUB\n") +fw.write ("\n") +fw.write (chlog) +fw.write ("\n") +for line in f: + fw.write (line) +f.close () +fw.close () diff --git a/include/grub/crypto.h b/include/grub/crypto.h new file mode 100644 index 000000000..36503c1a1 --- /dev/null +++ b/include/grub/crypto.h @@ -0,0 +1,138 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 + * 2007, 2008, 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +/* Contains elements based on gcrypt-module.h and gcrypt.h.in. + If it's changed please update this file. */ + +#ifndef GRUB_CIPHER_HEADER +#define GRUB_CIPHER_HEADER 1 + +#include +#include + +typedef enum + { + GPG_ERR_NO_ERROR, + GPG_ERR_BAD_MPI, + GPG_ERR_BAD_SECKEY, + GPG_ERR_BAD_SIGNATURE, + GPG_ERR_CIPHER_ALGO, + GPG_ERR_CONFLICT, + GPG_ERR_DECRYPT_FAILED, + GPG_ERR_DIGEST_ALGO, + GPG_ERR_GENERAL, + GPG_ERR_INTERNAL, + GPG_ERR_INV_ARG, + GPG_ERR_INV_CIPHER_MODE, + GPG_ERR_INV_FLAG, + GPG_ERR_INV_KEYLEN, + GPG_ERR_INV_OBJ, + GPG_ERR_INV_OP, + GPG_ERR_INV_SEXP, + GPG_ERR_INV_VALUE, + GPG_ERR_MISSING_VALUE, + GPG_ERR_NO_ENCRYPTION_SCHEME, + GPG_ERR_NO_OBJ, + GPG_ERR_NO_PRIME, + GPG_ERR_NO_SIGNATURE_SCHEME, + GPG_ERR_NOT_FOUND, + GPG_ERR_NOT_IMPLEMENTED, + GPG_ERR_NOT_SUPPORTED, + GPG_ERROR_CFLAGS, + GPG_ERR_PUBKEY_ALGO, + GPG_ERR_SELFTEST_FAILED, + GPG_ERR_TOO_SHORT, + GPG_ERR_UNSUPPORTED, + GPG_ERR_WEAK_KEY, + GPG_ERR_WRONG_KEY_USAGE, + GPG_ERR_WRONG_PUBKEY_ALGO, + } gcry_err_code_t; + +enum gcry_cipher_modes + { + GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */ + GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */ + GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */ + GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */ + GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */ + GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */ + GCRY_CIPHER_MODE_CTR = 6 /* Counter. */ + }; + +/* Type for the cipher_setkey function. */ +typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c, + const unsigned char *key, + unsigned keylen); + +/* Type for the cipher_encrypt function. */ +typedef void (*gcry_cipher_encrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf); + +/* Type for the cipher_decrypt function. */ +typedef void (*gcry_cipher_decrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf); + +/* Type for the cipher_stencrypt function. */ +typedef void (*gcry_cipher_stencrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf, + unsigned int n); + +/* Type for the cipher_stdecrypt function. */ +typedef void (*gcry_cipher_stdecrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf, + unsigned int n); + +typedef struct gcry_cipher_oid_spec +{ + const char *oid; + int mode; +} gcry_cipher_oid_spec_t; + +/* Module specification structure for ciphers. */ +typedef struct gcry_cipher_spec +{ + const char *name; + const char **aliases; + gcry_cipher_oid_spec_t *oids; + grub_size_t blocksize; + grub_size_t keylen; + grub_size_t contextsize; + gcry_cipher_setkey_t setkey; + gcry_cipher_encrypt_t encrypt; + gcry_cipher_decrypt_t decrypt; + gcry_cipher_stencrypt_t stencrypt; + gcry_cipher_stdecrypt_t stdecrypt; +} gcry_cipher_spec_t; + +struct grub_cipher +{ + struct grub_cipher *next; + const char *name; +}; +typedef struct grub_cipher *grub_cipher_t; + +extern grub_cipher_t EXPORT_VAR (grub_ciphers); +void EXPORT_FUNC(grub_burn_stack) (grub_size_t size); + + +#endif diff --git a/include/grub/gcry_wrap.h b/include/grub/gcry_wrap.h new file mode 100644 index 000000000..364946d1b --- /dev/null +++ b/include/grub/gcry_wrap.h @@ -0,0 +1,36 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#ifndef GRUB_GCRY_WRAP_HEADER +#define GRUB_GCRY_WRAP_HEADER 1 + +#include +#include +#include +#include +#include + +typedef grub_uint32_t u32; +typedef grub_uint16_t u16; +typedef grub_uint8_t byte; +typedef grub_size_t size_t; + +#define _gcry_burn_stack grub_burn_stack +#define log_error(fmt, args...) grub_dprintf ("crypto", fmt, ## args) + +#endif diff --git a/kern/crypto.c b/kern/crypto.c new file mode 100644 index 000000000..7dd00c84d --- /dev/null +++ b/kern/crypto.c @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1999, 2001, 2002, 2003, 2007, + * 2008, 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ +#include +#include + +grub_cipher_t grub_ciphers; + +/* Based on libgcrypt-1.4.4/src/misc.c. */ +void +grub_burn_stack (grub_size_t size) +{ + char buf[64]; + + grub_memset (buf, 0, sizeof (buf)); + size -= sizeof (buf); + if (size > 0) + grub_burn_stack (size); +} From 58806db8473505662ce9809a4ac996067808e7bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 Nov 2009 20:30:40 +0100 Subject: [PATCH 003/164] Improvements in headers --- conf/gcry.rmk | 52 ---------------------------------------- import_gcry.py | 4 ++-- include/grub/crypto.h | 48 +++++++++++++++++++++++++++++++++++++ include/grub/gcry_wrap.h | 2 ++ 4 files changed, 52 insertions(+), 54 deletions(-) delete mode 100644 conf/gcry.rmk diff --git a/conf/gcry.rmk b/conf/gcry.rmk deleted file mode 100644 index 0eb3c79bc..000000000 --- a/conf/gcry.rmk +++ /dev/null @@ -1,52 +0,0 @@ -# -*- makefile -*- - -pkglib_MODULES += seed.mod -seed_mod_SOURCES = gcry/cipher/seed.c -seed_mod_ASFLAGS = $(COMMON_ASFLAGS) -seed_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += twofish.mod -twofish_mod_SOURCES = gcry/cipher/twofish.c -twofish_mod_ASFLAGS = $(COMMON_ASFLAGS) -twofish_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += des.mod -des_mod_SOURCES = gcry/cipher/des.c -des_mod_ASFLAGS = $(COMMON_ASFLAGS) -des_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += arcfour.mod -arcfour_mod_SOURCES = gcry/cipher/arcfour.c -arcfour_mod_ASFLAGS = $(COMMON_ASFLAGS) -arcfour_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += rfc2268.mod -rfc2268_mod_SOURCES = gcry/cipher/rfc2268.c -rfc2268_mod_ASFLAGS = $(COMMON_ASFLAGS) -rfc2268_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += cast5.mod -cast5_mod_SOURCES = gcry/cipher/cast5.c -cast5_mod_ASFLAGS = $(COMMON_ASFLAGS) -cast5_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += camellia-glue.mod -camellia-glue_mod_SOURCES = gcry/cipher/camellia-glue.c -camellia-glue_mod_ASFLAGS = $(COMMON_ASFLAGS) -camellia-glue_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += rijndael.mod -rijndael_mod_SOURCES = gcry/cipher/rijndael.c -rijndael_mod_ASFLAGS = $(COMMON_ASFLAGS) -rijndael_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += serpent.mod -serpent_mod_SOURCES = gcry/cipher/serpent.c -serpent_mod_ASFLAGS = $(COMMON_ASFLAGS) -serpent_mod_LDFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += blowfish.mod -blowfish_mod_SOURCES = gcry/cipher/blowfish.c -blowfish_mod_ASFLAGS = $(COMMON_ASFLAGS) -blowfish_mod_LDFLAGS = $(COMMON_ASFLAGS) - diff --git a/import_gcry.py b/import_gcry.py index c751f5e6f..738c2c479 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -77,8 +77,8 @@ for cipher_file in cipher_files: conf.write ("pkglib_MODULES += %s.mod\n" % modname) conf.write ("%s_mod_SOURCES = gcry/cipher/%s\n" %\ (modname, cipher_file)) - conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-error\n" % modname) - conf.write ("%s_mod_LDFLAGS = $(COMMON_ASFLAGS)\n\n" % modname) + conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error\n" % modname) + conf.write ("%s_mod_LDFLAGS = $(COMMON_LDFLAGS)\n\n" % modname) elif isc: print ("WARNING: c file isn't a module: %s" % cipher_file) f.close () diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 36503c1a1..ab482f467 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -63,6 +63,7 @@ typedef enum GPG_ERR_WRONG_KEY_USAGE, GPG_ERR_WRONG_PUBKEY_ALGO, } gcry_err_code_t; +#define gpg_err_code_t gcry_err_code_t enum gcry_cipher_modes { @@ -124,6 +125,53 @@ typedef struct gcry_cipher_spec gcry_cipher_stdecrypt_t stdecrypt; } gcry_cipher_spec_t; +/* Definition of a function used to report selftest failures. + DOMAIN is a string describing the function block: + "cipher", "digest", "pubkey or "random", + ALGO is the algorithm under test, + WHAT is a string describing what has been tested, + DESC is a string describing the error. */ +typedef void (*selftest_report_func_t)(const char *domain, + int algo, + const char *what, + const char *errdesc); + +/* Definition of the selftest functions. */ +typedef gpg_err_code_t (*selftest_func_t) + (int algo, int extended, selftest_report_func_t report); + +/* The type used to convey additional information to a cipher. */ +typedef gpg_err_code_t (*cipher_set_extra_info_t) + (void *c, int what, const void *buffer, grub_size_t buflen); + + +/* Extra module specification structures. These are used for internal + modules which provide more functions than available through the + public algorithm register APIs. */ +typedef struct cipher_extra_spec +{ + selftest_func_t selftest; + cipher_set_extra_info_t set_extra_info; +} cipher_extra_spec_t; + +/* (Forward declaration.) */ +struct gcry_md_context; + +/* This object is used to hold a handle to a message digest object. + This structure is private - only to be used by the public gcry_md_* + macros. */ +typedef struct gcry_md_handle +{ + /* Actual context. */ + struct gcry_md_context *ctx; + + /* Buffer management. */ + int bufpos; + int bufsize; + unsigned char buf[1]; +} *gcry_md_hd_t; + + struct grub_cipher { struct grub_cipher *next; diff --git a/include/grub/gcry_wrap.h b/include/grub/gcry_wrap.h index 364946d1b..6f415a2e5 100644 --- a/include/grub/gcry_wrap.h +++ b/include/grub/gcry_wrap.h @@ -25,6 +25,8 @@ #include #include +#define __GNU_LIBRARY__ + typedef grub_uint32_t u32; typedef grub_uint16_t u16; typedef grub_uint8_t byte; From 47972a242007a3739afdda393adc88d0b6db5265 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 9 Nov 2009 21:33:15 +0000 Subject: [PATCH 004/164] Save & restore grub_fs_autoload_hook while we're in read_fs_list() --- normal/autofs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/normal/autofs.c b/normal/autofs.c index cf552052a..d1ef761fb 100644 --- a/normal/autofs.c +++ b/normal/autofs.c @@ -61,8 +61,15 @@ read_fs_list (void) if (filename) { grub_file_t file; + grub_fs_autoload_hook_t tmp_autoload_hook; grub_sprintf (filename, "%s/fs.lst", prefix); + + /* This rules out the possibility that read_fs_list() is invoked + recursively when we call grub_file_open() below. */ + tmp_autoload_hook = grub_fs_autoload_hook; + grub_fs_autoload_hook = NULL; + file = grub_file_open (filename); if (file) { @@ -116,6 +123,7 @@ read_fs_list (void) } grub_file_close (file); + grub_fs_autoload_hook = tmp_autoload_hook; } grub_free (filename); From 8fbfe0d68b777b199ae6f9521669399e443cb9d4 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 9 Nov 2009 21:44:48 +0000 Subject: [PATCH 005/164] Write ChangeLog entry. --- ChangeLog.prefix-redefinition-fix | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ChangeLog.prefix-redefinition-fix diff --git a/ChangeLog.prefix-redefinition-fix b/ChangeLog.prefix-redefinition-fix new file mode 100644 index 000000000..0d47db753 --- /dev/null +++ b/ChangeLog.prefix-redefinition-fix @@ -0,0 +1,12 @@ +2009-11-09 Robert Millan + + * normal/autofs.c (read_fs_list): Make function capable of being + run multiple times, gracefuly replacing the previous data + structures. + * normal/dyncmd.c (read_command_list): Likewise. + * normal/handler.c (read_handler_list): Likewise. + * normal/main.c (read_lists): New function. Calls all the + list reading functions. + (grub_normal_execute): Use read_lists() instead of calling all + list reading functions explicitly. Register read_lists() as a + variable hook attached to ${prefix}. From 39f7c91b5088152adfd8a4e851a9d425125681b3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 01:01:11 +0100 Subject: [PATCH 006/164] base for ciphers and digests --- import_gcry.py | 31 ++++++++++++--- include/grub/crypto.h | 85 ++++++++++++++++++++++++++++++---------- include/grub/gcry_wrap.h | 33 ++++++++++++++++ kern/crypto.c | 4 +- 4 files changed, 126 insertions(+), 27 deletions(-) diff --git a/import_gcry.py b/import_gcry.py index 738c2c479..cc06142e6 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -33,6 +33,7 @@ for cipher_file in cipher_files: fw.write ("/* This file was automatically imported with \n") fw.write (" import_gcry.py. Please don't modify it */\n"); ciphernames = [] + mdnames = [] for line in f: m = re.match ("#include <.*>", line) if not m is None: @@ -49,9 +50,21 @@ for cipher_file in cipher_files: ciphername = line [len ("gcry_cipher_spec_t"):].strip () ciphername = re.match("[a-zA-Z0-9_]*",ciphername).group () ciphernames.append (ciphername) + m = re.match ("gcry_md_spec_t", line) + if isc and not m is None: + mdname = line [len ("gcry_md_spec_t"):].strip () + mdname = re.match("[a-zA-Z0-9_]*",mdname).group () + mdnames.append (mdname) fw.write (line) - if len (ciphernames) > 0: + if len (ciphernames) > 0 or len (mdnames) > 0: modname = cipher_file [0:len(cipher_file) - 2] + if re.match (".*-glue$", modname): + modfiles = "gcry/cipher/%s gcry/cipher/%s" \ + % (cipher_file, cipher_file.replace ("-glue.c", ".c")) + modname = modname.replace ("-glue", "") + else: + modfiles = "gcry/cipher/%s" % cipher_file + modname = "gcry_%s" % modname chmsg = "(GRUB_MOD_INIT(%s)): New function\n" % modname if nch: chlognew = "%s\n %s" % (chlognew, chmsg) @@ -64,6 +77,10 @@ for cipher_file in cipher_files: chmsg = "Register cipher %s" % ciphername chlognew = "%s\n %s" % (chlognew, chmsg) fw.write (" grub_cipher_register (&%s);\n" % ciphername) + for mdname in mdnames: + chmsg = "Register digest %s" % mdname + chlognew = "%s\n %s" % (chlognew, chmsg) + fw.write (" grub_md_register (&%s);\n" % mdname) fw.write ("}") chmsg = "(GRUB_MOD_FINI(%s)): New function\n" % modname chlognew = "%s\n %s" % (chlognew, chmsg) @@ -73,14 +90,18 @@ for cipher_file in cipher_files: chmsg = "Unregister cipher %s" % ciphername chlognew = "%s\n %s" % (chlognew, chmsg) fw.write (" grub_cipher_unregister (&%s);\n" % ciphername) + for mdname in mdnames: + chmsg = "Unregister MD %s" % mdname + chlognew = "%s\n %s" % (chlognew, chmsg) + fw.write (" grub_md_unregister (&%s);\n" % mdname) fw.write ("}\n") conf.write ("pkglib_MODULES += %s.mod\n" % modname) - conf.write ("%s_mod_SOURCES = gcry/cipher/%s\n" %\ - (modname, cipher_file)) + conf.write ("%s_mod_SOURCES = %s\n" %\ + (modname, modfiles)) conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error\n" % modname) conf.write ("%s_mod_LDFLAGS = $(COMMON_LDFLAGS)\n\n" % modname) - elif isc: - print ("WARNING: c file isn't a module: %s" % cipher_file) + elif isc and cipher_file != "camellia.c": + print ("WARNING: C file isn't a module: %s" % cipher_file) f.close () fw.close () if nch: diff --git a/include/grub/crypto.h b/include/grub/crypto.h index ab482f467..bd236116d 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -123,6 +123,7 @@ typedef struct gcry_cipher_spec gcry_cipher_decrypt_t decrypt; gcry_cipher_stencrypt_t stencrypt; gcry_cipher_stdecrypt_t stdecrypt; + struct gcry_cipher_spec *next; } gcry_cipher_spec_t; /* Definition of a function used to report selftest failures. @@ -154,33 +155,75 @@ typedef struct cipher_extra_spec cipher_set_extra_info_t set_extra_info; } cipher_extra_spec_t; -/* (Forward declaration.) */ -struct gcry_md_context; +/* Type for the md_init function. */ +typedef void (*gcry_md_init_t) (void *c); -/* This object is used to hold a handle to a message digest object. - This structure is private - only to be used by the public gcry_md_* - macros. */ -typedef struct gcry_md_handle +/* Type for the md_write function. */ +typedef void (*gcry_md_write_t) (void *c, const void *buf, grub_size_t nbytes); + +/* Type for the md_final function. */ +typedef void (*gcry_md_final_t) (void *c); + +/* Type for the md_read function. */ +typedef unsigned char *(*gcry_md_read_t) (void *c); + +typedef struct gcry_md_oid_spec { - /* Actual context. */ - struct gcry_md_context *ctx; - - /* Buffer management. */ - int bufpos; - int bufsize; - unsigned char buf[1]; -} *gcry_md_hd_t; + const char *oidstring; +} gcry_md_oid_spec_t; - -struct grub_cipher +/* Module specification structure for message digests. */ +typedef struct gcry_md_spec { - struct grub_cipher *next; const char *name; -}; -typedef struct grub_cipher *grub_cipher_t; + unsigned char *asnoid; + int asnlen; + gcry_md_oid_spec_t *oids; + int mdlen; + gcry_md_init_t init; + gcry_md_write_t write; + gcry_md_final_t final; + gcry_md_read_t read; + grub_size_t contextsize; /* allocate this amount of context */ + struct gcry_md_spec *next; +} gcry_md_spec_t; + +extern gcry_cipher_spec_t *EXPORT_VAR (grub_ciphers); +extern gcry_md_spec_t *EXPORT_VAR (grub_digests); + +static inline void +grub_cipher_register (gcry_cipher_spec_t *cipher) +{ + cipher->next = grub_ciphers; + grub_ciphers = cipher; +} + +static inline void +grub_cipher_unregister (gcry_cipher_spec_t *cipher) +{ + gcry_cipher_spec_t **ciph; + for (ciph = &grub_ciphers; *ciph; ciph = &((*ciph)->next)) + if (*ciph == cipher) + *ciph = (*ciph)->next; +} + +static inline void +grub_md_register (gcry_md_spec_t *digest) +{ + digest->next = grub_digests; + grub_digests = digest; +} + +static inline void +grub_md_unregister (gcry_md_spec_t *cipher) +{ + gcry_md_spec_t **ciph; + for (ciph = &grub_digests; *ciph; ciph = &((*ciph)->next)) + if (*ciph == cipher) + *ciph = (*ciph)->next; +} + -extern grub_cipher_t EXPORT_VAR (grub_ciphers); void EXPORT_FUNC(grub_burn_stack) (grub_size_t size); - #endif diff --git a/include/grub/gcry_wrap.h b/include/grub/gcry_wrap.h index 6f415a2e5..37a1ee4d7 100644 --- a/include/grub/gcry_wrap.h +++ b/include/grub/gcry_wrap.h @@ -27,12 +27,45 @@ #define __GNU_LIBRARY__ +#define DIM ARRAY_SIZE + +typedef grub_uint64_t u64; typedef grub_uint32_t u32; typedef grub_uint16_t u16; typedef grub_uint8_t byte; typedef grub_size_t size_t; +#define U64_C(c) (c ## ULL) + #define _gcry_burn_stack grub_burn_stack #define log_error(fmt, args...) grub_dprintf ("crypto", fmt, ## args) + +#define PUBKEY_FLAG_NO_BLINDING (1 << 0) + +#define CIPHER_INFO_NO_WEAK_KEY 1 + +#define HAVE_U64_TYPEDEF 1 + +typedef union { + int a; + short b; + char c[1]; + long d; +#ifdef HAVE_U64_TYPEDEF + u64 e; +#endif + float f; + double g; +} PROPERLY_ALIGNED_TYPE; + +#define gcry_assert(x) grub_assert_real(__FILE__, __LINE__, x) + +static inline void +grub_assert_real (const char *file, int line, int cond) +{ + if (cond) + grub_fatal ("Assertion failed at %s:%d\n", file, line); +} + #endif diff --git a/kern/crypto.c b/kern/crypto.c index 7dd00c84d..83e2d96df 100644 --- a/kern/crypto.c +++ b/kern/crypto.c @@ -18,8 +18,10 @@ */ #include #include +#include -grub_cipher_t grub_ciphers; +gcry_cipher_spec_t *grub_ciphers = NULL; +gcry_md_spec_t *grub_digests = NULL; /* Based on libgcrypt-1.4.4/src/misc.c. */ void From 9f08f2a1fd8104b9038c14c8f3d487d4fa192837 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 20:46:05 +0100 Subject: [PATCH 007/164] bugfix burn_stack --- kern/crypto.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kern/crypto.c b/kern/crypto.c index 83e2d96df..d097e1668 100644 --- a/kern/crypto.c +++ b/kern/crypto.c @@ -30,7 +30,6 @@ grub_burn_stack (grub_size_t size) char buf[64]; grub_memset (buf, 0, sizeof (buf)); - size -= sizeof (buf); - if (size > 0) - grub_burn_stack (size); + if (size > sizeof (buf)) + grub_burn_stack (size - sizeof (buf)); } From 20de16bb918776f0183069c82d5afa3356e0f809 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 20:47:06 +0100 Subject: [PATCH 008/164] bugfix burn_stack --- commands/xnu_uuid.c | 311 ++------------------------------------------ conf/i386-pc.rmk | 2 +- 2 files changed, 13 insertions(+), 300 deletions(-) diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index 06e88e560..d7f86276b 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -31,12 +31,9 @@ #include #include #include +#include -struct tohash -{ - grub_uint8_t prefix[16]; - grub_uint64_t serial; -} __attribute__ ((packed)); +extern gcry_md_spec_t _gcry_digest_spec_md5; /* This prefix is used by xnu and boot-132 to hash together with volume serial. */ @@ -44,311 +41,27 @@ static grub_uint8_t hash_prefix[16] = {0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6, 0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC}; -#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) -#define ror(x,n) ( ((x) >> (n)) | ((x) << (32-(n))) ) - -typedef struct { - grub_uint32_t A,B,C,D; /* chaining variables */ - grub_uint32_t nblocks; - grub_uint8_t buf[64]; - int count; -} MD5_CONTEXT; - -static void -md5_init( void *context ) -{ - MD5_CONTEXT *ctx = context; - - ctx->A = 0x67452301; - ctx->B = 0xefcdab89; - ctx->C = 0x98badcfe; - ctx->D = 0x10325476; - - ctx->nblocks = 0; - ctx->count = 0; -} - -/* These are the four functions used in the four steps of the MD5 algorithm - and defined in the RFC 1321. The first function is a little bit optimized - (as found in Colin Plumbs public domain implementation). */ -/* #define FF(b, c, d) ((b & c) | (~b & d)) */ -#define FF(b, c, d) (d ^ (b & (c ^ d))) -#define FG(b, c, d) FF (d, b, c) -#define FH(b, c, d) (b ^ c ^ d) -#define FI(b, c, d) (c ^ (b | ~d)) - - -/**************** - * transform n*64 grub_uint8_ts - */ -static void -transform ( MD5_CONTEXT *ctx, const unsigned char *data ) -{ - grub_uint32_t correct_words[16]; - register grub_uint32_t A = ctx->A; - register grub_uint32_t B = ctx->B; - register grub_uint32_t C = ctx->C; - register grub_uint32_t D = ctx->D; - grub_uint32_t *cwp = correct_words; - -#ifdef GRUB_CPU_WORDS_BIGENDIAN - { - int i; - const grub_uint32_t *p = (const grub_uint32_t *) data; - - for (i = 0; i < 16; i++) - correct_words[i] = grub_le_to_cpu32 (p[i]); - } -#else - grub_memcpy (correct_words, data, 64); -#endif - -#define OP(a, b, c, d, s, T) \ - do \ - { \ - a += FF (b, c, d) + (*cwp++) + T; \ - a = rol(a, s); \ - a += b; \ - } \ - while (0) - - /* Before we start, one word about the strange constants. - They are defined in RFC 1321 as - - T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 - */ - - /* Round 1. */ - OP (A, B, C, D, 7, 0xd76aa478); - OP (D, A, B, C, 12, 0xe8c7b756); - OP (C, D, A, B, 17, 0x242070db); - OP (B, C, D, A, 22, 0xc1bdceee); - OP (A, B, C, D, 7, 0xf57c0faf); - OP (D, A, B, C, 12, 0x4787c62a); - OP (C, D, A, B, 17, 0xa8304613); - OP (B, C, D, A, 22, 0xfd469501); - OP (A, B, C, D, 7, 0x698098d8); - OP (D, A, B, C, 12, 0x8b44f7af); - OP (C, D, A, B, 17, 0xffff5bb1); - OP (B, C, D, A, 22, 0x895cd7be); - OP (A, B, C, D, 7, 0x6b901122); - OP (D, A, B, C, 12, 0xfd987193); - OP (C, D, A, B, 17, 0xa679438e); - OP (B, C, D, A, 22, 0x49b40821); - -#undef OP -#define OP(f, a, b, c, d, k, s, T) \ - do \ - { \ - a += f (b, c, d) + correct_words[k] + T; \ - a = rol(a, s); \ - a += b; \ - } \ - while (0) - - /* Round 2. */ - OP (FG, A, B, C, D, 1, 5, 0xf61e2562); - OP (FG, D, A, B, C, 6, 9, 0xc040b340); - OP (FG, C, D, A, B, 11, 14, 0x265e5a51); - OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa); - OP (FG, A, B, C, D, 5, 5, 0xd62f105d); - OP (FG, D, A, B, C, 10, 9, 0x02441453); - OP (FG, C, D, A, B, 15, 14, 0xd8a1e681); - OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8); - OP (FG, A, B, C, D, 9, 5, 0x21e1cde6); - OP (FG, D, A, B, C, 14, 9, 0xc33707d6); - OP (FG, C, D, A, B, 3, 14, 0xf4d50d87); - OP (FG, B, C, D, A, 8, 20, 0x455a14ed); - OP (FG, A, B, C, D, 13, 5, 0xa9e3e905); - OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8); - OP (FG, C, D, A, B, 7, 14, 0x676f02d9); - OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a); - - /* Round 3. */ - OP (FH, A, B, C, D, 5, 4, 0xfffa3942); - OP (FH, D, A, B, C, 8, 11, 0x8771f681); - OP (FH, C, D, A, B, 11, 16, 0x6d9d6122); - OP (FH, B, C, D, A, 14, 23, 0xfde5380c); - OP (FH, A, B, C, D, 1, 4, 0xa4beea44); - OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9); - OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60); - OP (FH, B, C, D, A, 10, 23, 0xbebfbc70); - OP (FH, A, B, C, D, 13, 4, 0x289b7ec6); - OP (FH, D, A, B, C, 0, 11, 0xeaa127fa); - OP (FH, C, D, A, B, 3, 16, 0xd4ef3085); - OP (FH, B, C, D, A, 6, 23, 0x04881d05); - OP (FH, A, B, C, D, 9, 4, 0xd9d4d039); - OP (FH, D, A, B, C, 12, 11, 0xe6db99e5); - OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8); - OP (FH, B, C, D, A, 2, 23, 0xc4ac5665); - - /* Round 4. */ - OP (FI, A, B, C, D, 0, 6, 0xf4292244); - OP (FI, D, A, B, C, 7, 10, 0x432aff97); - OP (FI, C, D, A, B, 14, 15, 0xab9423a7); - OP (FI, B, C, D, A, 5, 21, 0xfc93a039); - OP (FI, A, B, C, D, 12, 6, 0x655b59c3); - OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92); - OP (FI, C, D, A, B, 10, 15, 0xffeff47d); - OP (FI, B, C, D, A, 1, 21, 0x85845dd1); - OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f); - OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0); - OP (FI, C, D, A, B, 6, 15, 0xa3014314); - OP (FI, B, C, D, A, 13, 21, 0x4e0811a1); - OP (FI, A, B, C, D, 4, 6, 0xf7537e82); - OP (FI, D, A, B, C, 11, 10, 0xbd3af235); - OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb); - OP (FI, B, C, D, A, 9, 21, 0xeb86d391); - - /* Put checksum in context given as argument. */ - ctx->A += A; - ctx->B += B; - ctx->C += C; - ctx->D += D; -} - -/* The routine updates the message-digest context to - * account for the presence of each of the characters inBuf[0..inLen-1] - * in the message whose digest is being computed. - */ -static void -md5_write( void *context, const void *inbuf_arg , grub_size_t inlen) -{ - const unsigned char *inbuf = inbuf_arg; - MD5_CONTEXT *hd = context; - - if( hd->count == 64 ) /* flush the buffer */ - { - transform( hd, hd->buf ); - // _gcry_burn_stack (80+6*sizeof(void*)); - hd->count = 0; - hd->nblocks++; - } - if( !inbuf ) - return; - - if( hd->count ) - { - for( ; inlen && hd->count < 64; inlen-- ) - hd->buf[hd->count++] = *inbuf++; - md5_write( hd, NULL, 0 ); - if( !inlen ) - return; - } - // _gcry_burn_stack (80+6*sizeof(void*)); - - while( inlen >= 64 ) - { - transform( hd, inbuf ); - hd->count = 0; - hd->nblocks++; - inlen -= 64; - inbuf += 64; - } - for( ; inlen && hd->count < 64; inlen-- ) - hd->buf[hd->count++] = *inbuf++; - -} - - - -/* The routine final terminates the message-digest computation and - * ends with the desired message digest in mdContext->digest[0...15]. - * The handle is prepared for a new MD5 cycle. - * Returns 16 grub_uint8_ts representing the digest. - */ -static void -md5_final( void *context) -{ - MD5_CONTEXT *hd = context; - grub_uint32_t t, msb, lsb; - grub_uint32_t *p; - - md5_write(hd, NULL, 0); /* flush */; - - t = hd->nblocks; - /* multiply by 64 to make a grub_uint8_t count */ - lsb = t << 6; - msb = t >> 26; - /* add the count */ - t = lsb; - if( (lsb += hd->count) < t ) - msb++; - /* multiply by 8 to make a bit count */ - t = lsb; - lsb <<= 3; - msb <<= 3; - msb |= t >> 29; - - if( hd->count < 56 ) /* enough room */ - { - hd->buf[hd->count++] = 0x80; /* pad */ - while( hd->count < 56 ) - hd->buf[hd->count++] = 0; /* pad */ - } - else /* need one extra block */ - { - hd->buf[hd->count++] = 0x80; /* pad character */ - while( hd->count < 64 ) - hd->buf[hd->count++] = 0; - md5_write(hd, NULL, 0); /* flush */; - grub_memset(hd->buf, 0, 56 ); /* fill next block with zeroes */ - } - /* append the 64 bit count */ - hd->buf[56] = lsb ; - hd->buf[57] = lsb >> 8; - hd->buf[58] = lsb >> 16; - hd->buf[59] = lsb >> 24; - hd->buf[60] = msb ; - hd->buf[61] = msb >> 8; - hd->buf[62] = msb >> 16; - hd->buf[63] = msb >> 24; - transform( hd, hd->buf ); - // _gcry_burn_stack (80+6*sizeof(void*)); - - p = (grub_uint32_t *) hd->buf; -#define X(a) do { *p = grub_le_to_cpu32 (hd->a); p++; } while (0) - X(A); - X(B); - X(C); - X(D); -#undef X - -} - -/** - * GRUB2 Crypto Interface - * Written by Michael Gorven - */ -static grub_err_t -md5 (const char *in, grub_size_t insize, char *out) -{ - MD5_CONTEXT hd; - - md5_init (&hd); - md5_write (&hd, in, insize); - md5_final (&hd); - grub_memcpy (out, hd.buf, 16); - - return GRUB_ERR_NONE; -} - static grub_err_t grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { - struct tohash hashme; - grub_uint8_t xnu_uuid[16]; + grub_uint64_t serial; + grub_uint8_t *xnu_uuid; char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; char *ptr; + grub_uint8_t ctx[_gcry_digest_spec_md5.contextsize]; if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required"); - hashme.serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16)); - grub_memcpy (hashme.prefix, hash_prefix, sizeof (hashme.prefix)); + serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16)); + + _gcry_digest_spec_md5.init (&ctx); + _gcry_digest_spec_md5.write (&ctx, hash_prefix, sizeof (hash_prefix)); + _gcry_digest_spec_md5.write (&ctx, &serial, sizeof (serial)); + _gcry_digest_spec_md5.final (&ctx); + xnu_uuid = _gcry_digest_spec_md5.read (&ctx); - md5 ((char *) &hashme, sizeof (hashme), (char *) xnu_uuid); grub_sprintf (uuid_string, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", (unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1], diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 0e3291782..45e1ccf91 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -125,7 +125,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ - commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ + commands/gptsync.c commands/probe.c \ commands/i386/cpuid.c \ commands/password.c commands/keystatus.c \ disk/host.c disk/loopback.c disk/scsi.c \ From a4bafc47107165a839d6aec22e4cef1724785914 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 20:51:22 +0100 Subject: [PATCH 009/164] First working cipher import --- import_gcry.py | 90 +++++++++++++++++++-- include/grub/{gcry_wrap.h => cipher_wrap.h} | 13 +++ include/grub/crypto.h | 1 + 3 files changed, 99 insertions(+), 5 deletions(-) rename include/grub/{gcry_wrap.h => cipher_wrap.h} (92%) diff --git a/import_gcry.py b/import_gcry.py index cc06142e6..9a53a356a 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -10,10 +10,17 @@ indir = sys.argv[1] outdir = sys.argv[2] basedir = os.path.join (outdir, "gcry") -os.makedirs (basedir) +try: + os.makedirs (basedir) +except: + print ("WARNING: %s already exists" % basedir) cipher_dir_in = os.path.join (indir, "cipher") cipher_dir_out = os.path.join (basedir, "cipher") -os.makedirs (cipher_dir_out) +try: + os.makedirs (cipher_dir_out) +except: + print ("WARNING: %s already exists" % cipher_dir_out) + cipher_files = os.listdir (cipher_dir_in) conf = open (os.path.join (outdir, "conf", "gcry.rmk"), "w") conf.write ("# -*- makefile -*-\n\n") @@ -34,7 +41,33 @@ for cipher_file in cipher_files: fw.write (" import_gcry.py. Please don't modify it */\n"); ciphernames = [] mdnames = [] + hold = False + skip = False + skip2 = False for line in f: + if skip: + if line[0] == "}": + skip = False + continue + if skip2: + if not re.search (" *};", line) is None: + skip2 = False + continue + if hold: + hold = False + # We're optimising for size. + elif not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None: + skip = True + fname = re.match ("[a-zA-Z0-9_]*", line).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + else: + fw.write (holdline) m = re.match ("#include <.*>", line) if not m is None: chmsg = "Removed including of %s" % \ @@ -55,6 +88,46 @@ for cipher_file in cipher_files: mdname = line [len ("gcry_md_spec_t"):].strip () mdname = re.match("[a-zA-Z0-9_]*",mdname).group () mdnames.append (mdname) + m = re.match ("static const char \*selftest.*;$", line) + if not m is None: + fname = line[len ("static const char \*"):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed declaration." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + m = re.match ("(static const char( |)\*|static gpg_err_code_t|void)$", line) + if not m is None: + hold = True + holdline = line + continue + m = re.match ("cipher_extra_spec_t", line) + if isc and not m is None: + skip2 = True + fname = line[len ("cipher_extra_spec_t "):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + m = re.match ("md_extra_spec_t", line) + if isc and not m is None: + skip2 = True + fname = line[len ("md_extra_spec_t "):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue fw.write (line) if len (ciphernames) > 0 or len (mdnames) > 0: modname = cipher_file [0:len(cipher_file) - 2] @@ -120,20 +193,27 @@ for cipher_file in cipher_files: outfile = os.path.join (cipher_dir_out, "types.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * types.h: New file.\n" % chlog fw.close () +outfile = os.path.join (cipher_dir_out, "memory.h") +fw=open (outfile, "w") +fw.write ("#include \n") +chlog = "%s * memory.h: New file.\n" % chlog +fw.close () + + outfile = os.path.join (cipher_dir_out, "cipher.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * cipher.h: Likewise.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "g10lib.h") fw=open (outfile, "w") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * g10lib.h: Likewise.\n" % chlog fw.close () diff --git a/include/grub/gcry_wrap.h b/include/grub/cipher_wrap.h similarity index 92% rename from include/grub/gcry_wrap.h rename to include/grub/cipher_wrap.h index 37a1ee4d7..9e6242b7f 100644 --- a/include/grub/gcry_wrap.h +++ b/include/grub/cipher_wrap.h @@ -68,4 +68,17 @@ grub_assert_real (const char *file, int line, int cond) grub_fatal ("Assertion failed at %s:%d\n", file, line); } +/* Selftests are in separate modules. */ +static inline char * +selftest (void) +{ + return NULL; +} + +static inline int +fips_mode (void) +{ + return 0; +} + #endif diff --git a/include/grub/crypto.h b/include/grub/crypto.h index bd236116d..17f14de86 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -64,6 +64,7 @@ typedef enum GPG_ERR_WRONG_PUBKEY_ALGO, } gcry_err_code_t; #define gpg_err_code_t gcry_err_code_t +#define gpg_error_t gcry_err_code_t enum gcry_cipher_modes { From 63d7ad01ebf629007f8f42a9d3ae32a81d8fa805 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 20:59:09 +0100 Subject: [PATCH 010/164] Fixed splitting error --- import_gcry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_gcry.py b/import_gcry.py index 9a53a356a..ca03729af 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -56,7 +56,7 @@ for cipher_file in cipher_files: if hold: hold = False # We're optimising for size. - elif not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None: + if not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None: skip = True fname = re.match ("[a-zA-Z0-9_]*", line).group () chmsg = "(%s): Removed." % fname From 414f919237bd02e53a11066fcdc0c08e9adc8e2e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 12 Nov 2009 18:08:44 +0100 Subject: [PATCH 011/164] Various cleanups and wrapper functions. Allocate disk id for LUKS. --- commands/xnu_uuid.c | 14 ++- import_gcry.py | 28 ++++++ include/grub/crypto.h | 202 +++++++++++++++++++++++++++++++++++------- include/grub/disk.h | 1 + 4 files changed, 206 insertions(+), 39 deletions(-) diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index d7f86276b..48c67d18e 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -33,8 +33,6 @@ #include #include -extern gcry_md_spec_t _gcry_digest_spec_md5; - /* This prefix is used by xnu and boot-132 to hash together with volume serial. */ static grub_uint8_t hash_prefix[16] @@ -49,18 +47,18 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)), grub_uint8_t *xnu_uuid; char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; char *ptr; - grub_uint8_t ctx[_gcry_digest_spec_md5.contextsize]; + grub_uint8_t ctx[GRUB_MD_MD5->contextsize]; if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required"); serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16)); - _gcry_digest_spec_md5.init (&ctx); - _gcry_digest_spec_md5.write (&ctx, hash_prefix, sizeof (hash_prefix)); - _gcry_digest_spec_md5.write (&ctx, &serial, sizeof (serial)); - _gcry_digest_spec_md5.final (&ctx); - xnu_uuid = _gcry_digest_spec_md5.read (&ctx); + GRUB_MD_MD5->init (&ctx); + GRUB_MD_MD5->write (&ctx, hash_prefix, sizeof (hash_prefix)); + GRUB_MD_MD5->write (&ctx, &serial, sizeof (serial)); + GRUB_MD_MD5->final (&ctx); + xnu_uuid = GRUB_MD_MD5->read (&ctx); grub_sprintf (uuid_string, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", diff --git a/import_gcry.py b/import_gcry.py index ca03729af..39542d8c4 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -26,6 +26,20 @@ conf = open (os.path.join (outdir, "conf", "gcry.rmk"), "w") conf.write ("# -*- makefile -*-\n\n") chlog = "" +mdblocksizes = {"_gcry_digest_spec_crc32" : 1, + "_gcry_digest_spec_crc32_rfc1510" : 1, + "_gcry_digest_spec_crc24_rfc2440" : 1, + "_gcry_digest_spec_md4" : 64, + "_gcry_digest_spec_md5" : 64, + "_gcry_digest_spec_rmd160" : 64, + "_gcry_digest_spec_sha1" : 64, + "_gcry_digest_spec_sha224" : 64, + "_gcry_digest_spec_sha256" : 64, + "_gcry_digest_spec_sha384" : 128, + "_gcry_digest_spec_sha512" : 128, + "_gcry_digest_spec_tiger" : 64, + "_gcry_digest_spec_whirlpool" : 64} + for cipher_file in cipher_files: infile = os.path.join (cipher_dir_in, cipher_file) outfile = os.path.join (cipher_dir_out, cipher_file) @@ -44,6 +58,8 @@ for cipher_file in cipher_files: hold = False skip = False skip2 = False + ismd = False + iscomma = False for line in f: if skip: if line[0] == "}": @@ -53,6 +69,16 @@ for cipher_file in cipher_files: if not re.search (" *};", line) is None: skip2 = False continue + if ismd: + if not re.search (" *};", line) is None: + if not mdblocksizes.has_key (mdname): + print ("ERROR: Unknown digest blocksize: %s\n" % mdname) + exit (1) + if not iscomma: + fw.write (" ,\n") + fw.write (" .blocksize = %s\n" % mdblocksizes [mdname]) + ismd = False + iscomma = not re.search (",$", line) is None if hold: hold = False # We're optimising for size. @@ -85,9 +111,11 @@ for cipher_file in cipher_files: ciphernames.append (ciphername) m = re.match ("gcry_md_spec_t", line) if isc and not m is None: + assert (not ismd) mdname = line [len ("gcry_md_spec_t"):].strip () mdname = re.match("[a-zA-Z0-9_]*",mdname).group () mdnames.append (mdname) + ismd = True m = re.match ("static const char \*selftest.*;$", line) if not m is None: fname = line[len ("static const char \*"):] diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 17f14de86..239b46666 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -25,6 +25,8 @@ #include #include +#include +#include typedef enum { @@ -127,35 +129,6 @@ typedef struct gcry_cipher_spec struct gcry_cipher_spec *next; } gcry_cipher_spec_t; -/* Definition of a function used to report selftest failures. - DOMAIN is a string describing the function block: - "cipher", "digest", "pubkey or "random", - ALGO is the algorithm under test, - WHAT is a string describing what has been tested, - DESC is a string describing the error. */ -typedef void (*selftest_report_func_t)(const char *domain, - int algo, - const char *what, - const char *errdesc); - -/* Definition of the selftest functions. */ -typedef gpg_err_code_t (*selftest_func_t) - (int algo, int extended, selftest_report_func_t report); - -/* The type used to convey additional information to a cipher. */ -typedef gpg_err_code_t (*cipher_set_extra_info_t) - (void *c, int what, const void *buffer, grub_size_t buflen); - - -/* Extra module specification structures. These are used for internal - modules which provide more functions than available through the - public algorithm register APIs. */ -typedef struct cipher_extra_spec -{ - selftest_func_t selftest; - cipher_set_extra_info_t set_extra_info; -} cipher_extra_spec_t; - /* Type for the md_init function. */ typedef void (*gcry_md_init_t) (void *c); @@ -180,12 +153,14 @@ typedef struct gcry_md_spec unsigned char *asnoid; int asnlen; gcry_md_oid_spec_t *oids; - int mdlen; + grub_size_t mdlen; gcry_md_init_t init; gcry_md_write_t write; gcry_md_final_t final; gcry_md_read_t read; grub_size_t contextsize; /* allocate this amount of context */ + /* Block size, needed for HMAC. */ + grub_size_t blocksize; struct gcry_md_spec *next; } gcry_md_spec_t; @@ -199,7 +174,7 @@ grub_cipher_register (gcry_cipher_spec_t *cipher) grub_ciphers = cipher; } -static inline void +static inline void grub_cipher_unregister (gcry_cipher_spec_t *cipher) { gcry_cipher_spec_t **ciph; @@ -224,7 +199,172 @@ grub_md_unregister (gcry_md_spec_t *cipher) *ciph = (*ciph)->next; } +static inline void +grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, + grub_size_t inlen) +{ + grub_uint8_t ctx[hash->contextsize]; + hash->init (&ctx); + hash->write (&ctx, in, inlen); + hash->final (&ctx); + grub_memcpy (out, hash->read (&ctx), hash->mdlen); +} + +static inline const gcry_md_spec_t * +grub_crypto_lookup_md_by_name (const char *name) +{ + const gcry_md_spec_t *md; + for (md = grub_digests; md; md = md->next) + if (grub_strcasecmp (name, md->name) == 0) + return md; + return NULL; +} + +typedef struct grub_crypto_cipher_handle +{ + const struct gcry_cipher_spec *cipher; + char ctx[0]; +} *grub_crypto_cipher_handle_t; + +static inline const gcry_cipher_spec_t * +grub_crypto_lookup_cipher_by_name (const char *name) +{ + const gcry_cipher_spec_t *ciph; + for (ciph = grub_ciphers; ciph; ciph = ciph->next) + { + const char **alias; + if (grub_strcasecmp (name, ciph->name) == 0) + return ciph; + if (!ciph->aliases) + continue; + for (alias = ciph->aliases; *alias; alias++) + if (grub_strcasecmp (name, *alias) == 0) + return ciph; + } + return NULL; +} + + +static inline grub_crypto_cipher_handle_t +grub_crypto_cipher_open (const struct gcry_cipher_spec *cipher) +{ + grub_crypto_cipher_handle_t ret; + ret = grub_malloc (sizeof (*ret) + cipher->contextsize); + if (!ret) + return NULL; + ret->cipher = cipher; + return ret; +} + +static inline gcry_err_code_t +grub_crypto_cipher_set_key (grub_crypto_cipher_handle_t cipher, + const unsigned char *key, + unsigned keylen) +{ + return cipher->cipher->setkey (cipher->ctx, key, keylen); +} + + +static inline void +grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher) +{ + grub_free (cipher); +} + + +static inline void +grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size) +{ + const grub_uint8_t *in1ptr = in1, *in2ptr = in2; + grub_uint8_t *outptr = out; + while (size--) + { + *outptr = *in1ptr ^ *in2ptr; + in1ptr++; + in2ptr++; + outptr++; + } +} + +static inline grub_err_t +grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size) +{ + grub_uint8_t *inptr, *outptr, *end; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + return GRUB_ERR_NONE; +} + +static inline grub_err_t +grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size) +{ + grub_uint8_t *inptr, *outptr, *end; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + cipher->cipher->encrypt (cipher->ctx, outptr, inptr); + return GRUB_ERR_NONE; +} + +static inline grub_err_t +grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv_in) +{ + grub_uint8_t *inptr, *outptr, *end; + void *iv; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + iv = iv_in; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_crypto_xor (outptr, inptr, iv, cipher->cipher->blocksize); + cipher->cipher->encrypt (cipher->ctx, outptr, outptr); + iv = outptr; + } + grub_memcpy (iv_in, iv, cipher->cipher->blocksize); + return GRUB_ERR_NONE; +} + +static inline grub_err_t +grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv) +{ + grub_uint8_t *inptr, *outptr, *end; + grub_uint8_t ivt[cipher->cipher->blocksize]; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_memcpy (iv, ivt, cipher->cipher->blocksize); + } + return GRUB_ERR_NONE; +} + void EXPORT_FUNC(grub_burn_stack) (grub_size_t size); +extern gcry_md_spec_t _gcry_digest_spec_md5; +#define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5) + #endif diff --git a/include/grub/disk.h b/include/grub/disk.h index de71bb588..cc801bc67 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -42,6 +42,7 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_PXE_ID, GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_FILE_ID, + GRUB_DISK_DEVICE_LUKS_ID }; struct grub_disk; From d944246c6aa076458bc3ee4dbd8026e39015e8e8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 12 Nov 2009 22:40:14 +0100 Subject: [PATCH 012/164] Created crypto module. Moved some functions to it. --- conf/common.rmk | 5 + conf/i386-pc.rmk | 4 +- include/grub/crypto.h | 211 ++++++--------------------------------- lib/crypto.c | 225 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 263 insertions(+), 182 deletions(-) create mode 100644 lib/crypto.c diff --git a/conf/common.rmk b/conf/common.rmk index 0d19344a7..35b4620f4 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -619,4 +619,9 @@ setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += crypto.mod +crypto_mod_SOURCES = lib/crypto.c +crypto_mod_CFLAGS = $(COMMON_CFLAGS) +crypto_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/gcry.mk diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 45e1ccf91..ac9337e41 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -58,15 +58,13 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/generic/millisleep.c \ kern/env.c \ term/i386/pc/console.c term/i386/vga_common.c \ - kern/crypto.c \ symlist.c kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h \ - crypto.h + machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 239b46666..5cd7f02b4 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -164,205 +164,58 @@ typedef struct gcry_md_spec struct gcry_md_spec *next; } gcry_md_spec_t; -extern gcry_cipher_spec_t *EXPORT_VAR (grub_ciphers); -extern gcry_md_spec_t *EXPORT_VAR (grub_digests); - -static inline void -grub_cipher_register (gcry_cipher_spec_t *cipher) -{ - cipher->next = grub_ciphers; - grub_ciphers = cipher; -} - -static inline void -grub_cipher_unregister (gcry_cipher_spec_t *cipher) -{ - gcry_cipher_spec_t **ciph; - for (ciph = &grub_ciphers; *ciph; ciph = &((*ciph)->next)) - if (*ciph == cipher) - *ciph = (*ciph)->next; -} - -static inline void -grub_md_register (gcry_md_spec_t *digest) -{ - digest->next = grub_digests; - grub_digests = digest; -} - -static inline void -grub_md_unregister (gcry_md_spec_t *cipher) -{ - gcry_md_spec_t **ciph; - for (ciph = &grub_digests; *ciph; ciph = &((*ciph)->next)) - if (*ciph == cipher) - *ciph = (*ciph)->next; -} - -static inline void -grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, - grub_size_t inlen) -{ - grub_uint8_t ctx[hash->contextsize]; - hash->init (&ctx); - hash->write (&ctx, in, inlen); - hash->final (&ctx); - grub_memcpy (out, hash->read (&ctx), hash->mdlen); -} - -static inline const gcry_md_spec_t * -grub_crypto_lookup_md_by_name (const char *name) -{ - const gcry_md_spec_t *md; - for (md = grub_digests; md; md = md->next) - if (grub_strcasecmp (name, md->name) == 0) - return md; - return NULL; -} - typedef struct grub_crypto_cipher_handle { const struct gcry_cipher_spec *cipher; char ctx[0]; } *grub_crypto_cipher_handle_t; -static inline const gcry_cipher_spec_t * -grub_crypto_lookup_cipher_by_name (const char *name) -{ - const gcry_cipher_spec_t *ciph; - for (ciph = grub_ciphers; ciph; ciph = ciph->next) - { - const char **alias; - if (grub_strcasecmp (name, ciph->name) == 0) - return ciph; - if (!ciph->aliases) - continue; - for (alias = ciph->aliases; *alias; alias++) - if (grub_strcasecmp (name, *alias) == 0) - return ciph; - } - return NULL; -} +const gcry_cipher_spec_t * +grub_crypto_lookup_cipher_by_name (const char *name); +grub_crypto_cipher_handle_t +grub_crypto_cipher_open (const struct gcry_cipher_spec *cipher); -static inline grub_crypto_cipher_handle_t -grub_crypto_cipher_open (const struct gcry_cipher_spec *cipher) -{ - grub_crypto_cipher_handle_t ret; - ret = grub_malloc (sizeof (*ret) + cipher->contextsize); - if (!ret) - return NULL; - ret->cipher = cipher; - return ret; -} - -static inline gcry_err_code_t +gcry_err_code_t grub_crypto_cipher_set_key (grub_crypto_cipher_handle_t cipher, const unsigned char *key, - unsigned keylen) -{ - return cipher->cipher->setkey (cipher->ctx, key, keylen); -} + unsigned keylen); +void +grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher); -static inline void -grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher) -{ - grub_free (cipher); -} - - -static inline void -grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size) -{ - const grub_uint8_t *in1ptr = in1, *in2ptr = in2; - grub_uint8_t *outptr = out; - while (size--) - { - *outptr = *in1ptr ^ *in2ptr; - in1ptr++; - in2ptr++; - outptr++; - } -} - -static inline grub_err_t +void +grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size); +grub_err_t grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size) -{ - grub_uint8_t *inptr, *outptr, *end; - if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); - end = (grub_uint8_t *) in + size; - for (inptr = in, outptr = out; inptr < end; - inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) - cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - return GRUB_ERR_NONE; -} + void *out, void *in, grub_size_t size); -static inline grub_err_t +grub_err_t grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size) -{ - grub_uint8_t *inptr, *outptr, *end; - if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); - end = (grub_uint8_t *) in + size; - for (inptr = in, outptr = out; inptr < end; - inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) - cipher->cipher->encrypt (cipher->ctx, outptr, inptr); - return GRUB_ERR_NONE; -} - -static inline grub_err_t + void *out, void *in, grub_size_t size); +grub_err_t grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, - void *iv_in) -{ - grub_uint8_t *inptr, *outptr, *end; - void *iv; - if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); - end = (grub_uint8_t *) in + size; - iv = iv_in; - for (inptr = in, outptr = out; inptr < end; - inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) - { - grub_crypto_xor (outptr, inptr, iv, cipher->cipher->blocksize); - cipher->cipher->encrypt (cipher->ctx, outptr, outptr); - iv = outptr; - } - grub_memcpy (iv_in, iv, cipher->cipher->blocksize); - return GRUB_ERR_NONE; -} - -static inline grub_err_t + void *iv_in); +grub_err_t grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, - void *iv) -{ - grub_uint8_t *inptr, *outptr, *end; - grub_uint8_t ivt[cipher->cipher->blocksize]; - if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); - end = (grub_uint8_t *) in + size; - for (inptr = in, outptr = out; inptr < end; - inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) - { - grub_memcpy (ivt, inptr, cipher->cipher->blocksize); - cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); - grub_memcpy (iv, ivt, cipher->cipher->blocksize); - } - return GRUB_ERR_NONE; -} + void *iv); +void +grub_cipher_register (gcry_cipher_spec_t *cipher); +void +grub_cipher_unregister (gcry_cipher_spec_t *cipher); +void +grub_md_register (gcry_md_spec_t *digest); +void +grub_md_unregister (gcry_md_spec_t *cipher); +void +grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, + grub_size_t inlen); +const gcry_md_spec_t * +grub_crypto_lookup_md_by_name (const char *name); - -void EXPORT_FUNC(grub_burn_stack) (grub_size_t size); +void grub_burn_stack (grub_size_t size); extern gcry_md_spec_t _gcry_digest_spec_md5; #define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5) diff --git a/lib/crypto.c b/lib/crypto.c new file mode 100644 index 000000000..64c386dae --- /dev/null +++ b/lib/crypto.c @@ -0,0 +1,225 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 + * 2007, 2008, 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include + +static gcry_cipher_spec_t *grub_ciphers = NULL; +static gcry_md_spec_t *grub_digests = NULL; + +/* Based on libgcrypt-1.4.4/src/misc.c. */ +void +grub_burn_stack (grub_size_t size) +{ + char buf[64]; + + grub_memset (buf, 0, sizeof (buf)); + if (size > sizeof (buf)) + grub_burn_stack (size - sizeof (buf)); +} + + +void +grub_cipher_register (gcry_cipher_spec_t *cipher) +{ + cipher->next = grub_ciphers; + grub_ciphers = cipher; +} + +void +grub_cipher_unregister (gcry_cipher_spec_t *cipher) +{ + gcry_cipher_spec_t **ciph; + for (ciph = &grub_ciphers; *ciph; ciph = &((*ciph)->next)) + if (*ciph == cipher) + *ciph = (*ciph)->next; +} + +void +grub_md_register (gcry_md_spec_t *digest) +{ + digest->next = grub_digests; + grub_digests = digest; +} + +void +grub_md_unregister (gcry_md_spec_t *cipher) +{ + gcry_md_spec_t **ciph; + for (ciph = &grub_digests; *ciph; ciph = &((*ciph)->next)) + if (*ciph == cipher) + *ciph = (*ciph)->next; +} + +void +grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, + grub_size_t inlen) +{ + grub_uint8_t ctx[hash->contextsize]; + hash->init (&ctx); + hash->write (&ctx, in, inlen); + hash->final (&ctx); + grub_memcpy (out, hash->read (&ctx), hash->mdlen); +} + +const gcry_md_spec_t * +grub_crypto_lookup_md_by_name (const char *name) +{ + const gcry_md_spec_t *md; + for (md = grub_digests; md; md = md->next) + if (grub_strcasecmp (name, md->name) == 0) + return md; + return NULL; +} + +const gcry_cipher_spec_t * +grub_crypto_lookup_cipher_by_name (const char *name) +{ + const gcry_cipher_spec_t *ciph; + for (ciph = grub_ciphers; ciph; ciph = ciph->next) + { + const char **alias; + if (grub_strcasecmp (name, ciph->name) == 0) + return ciph; + if (!ciph->aliases) + continue; + for (alias = ciph->aliases; *alias; alias++) + if (grub_strcasecmp (name, *alias) == 0) + return ciph; + } + return NULL; +} + + +grub_crypto_cipher_handle_t +grub_crypto_cipher_open (const struct gcry_cipher_spec *cipher) +{ + grub_crypto_cipher_handle_t ret; + ret = grub_malloc (sizeof (*ret) + cipher->contextsize); + if (!ret) + return NULL; + ret->cipher = cipher; + return ret; +} + +gcry_err_code_t +grub_crypto_cipher_set_key (grub_crypto_cipher_handle_t cipher, + const unsigned char *key, + unsigned keylen) +{ + return cipher->cipher->setkey (cipher->ctx, key, keylen); +} + + +void +grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher) +{ + grub_free (cipher); +} + + +void +grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size) +{ + const grub_uint8_t *in1ptr = in1, *in2ptr = in2; + grub_uint8_t *outptr = out; + while (size--) + { + *outptr = *in1ptr ^ *in2ptr; + in1ptr++; + in2ptr++; + outptr++; + } +} + +grub_err_t +grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size) +{ + grub_uint8_t *inptr, *outptr, *end; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + return GRUB_ERR_NONE; +} + +grub_err_t +grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size) +{ + grub_uint8_t *inptr, *outptr, *end; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + cipher->cipher->encrypt (cipher->ctx, outptr, inptr); + return GRUB_ERR_NONE; +} + +grub_err_t +grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv_in) +{ + grub_uint8_t *inptr, *outptr, *end; + void *iv; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + iv = iv_in; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_crypto_xor (outptr, inptr, iv, cipher->cipher->blocksize); + cipher->cipher->encrypt (cipher->ctx, outptr, outptr); + iv = outptr; + } + grub_memcpy (iv_in, iv, cipher->cipher->blocksize); + return GRUB_ERR_NONE; +} + +grub_err_t +grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv) +{ + grub_uint8_t *inptr, *outptr, *end; + grub_uint8_t ivt[cipher->cipher->blocksize]; + if (size % cipher->cipher->blocksize != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "This encryption can't decrypt partial blocks"); + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_memcpy (iv, ivt, cipher->cipher->blocksize); + } + return GRUB_ERR_NONE; +} From fbf62978dcd4d42facffdcf99831e82a1979cdc3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 Nov 2009 00:27:04 +0100 Subject: [PATCH 013/164] Improved error handling --- include/grub/crypto.h | 26 +++++++++++++------------ lib/crypto.c | 44 +++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 5cd7f02b4..7a3461e3b 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -20,13 +20,14 @@ /* Contains elements based on gcrypt-module.h and gcrypt.h.in. If it's changed please update this file. */ -#ifndef GRUB_CIPHER_HEADER -#define GRUB_CIPHER_HEADER 1 +#ifndef GRUB_CRYPTO_HEADER +#define GRUB_CRYPTO_HEADER 1 #include #include -#include -#include +#include +/* For GRUB_ACCESS_DENIED. */ +#include typedef enum { @@ -64,6 +65,7 @@ typedef enum GPG_ERR_WEAK_KEY, GPG_ERR_WRONG_KEY_USAGE, GPG_ERR_WRONG_PUBKEY_ALGO, + GPG_ERR_OUT_OF_MEMORY } gcry_err_code_t; #define gpg_err_code_t gcry_err_code_t #define gpg_error_t gcry_err_code_t @@ -186,26 +188,23 @@ grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher); void grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size); -grub_err_t + +gcry_err_code_t grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size); -grub_err_t +gcry_err_code_t grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size); -grub_err_t +gcry_err_code_t grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, void *iv_in); -grub_err_t +gcry_err_code_t grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, void *iv); void -grub_cipher_register (gcry_cipher_spec_t *cipher); -void -grub_cipher_unregister (gcry_cipher_spec_t *cipher); -void grub_md_register (gcry_md_spec_t *digest); void grub_md_unregister (gcry_md_spec_t *cipher); @@ -215,6 +214,9 @@ grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, const gcry_md_spec_t * grub_crypto_lookup_md_by_name (const char *name); +grub_err_t +grub_crypto_gcry_error (gcry_err_code_t in); + void grub_burn_stack (grub_size_t size); extern gcry_md_spec_t _gcry_digest_spec_md5; diff --git a/lib/crypto.c b/lib/crypto.c index 64c386dae..718d6e278 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -149,46 +149,49 @@ grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size) } } -grub_err_t +gcry_err_code_t grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size) { grub_uint8_t *inptr, *outptr, *end; + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); + return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; } -grub_err_t +gcry_err_code_t grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size) { grub_uint8_t *inptr, *outptr, *end; + if (!cipher->cipher->encrypt) + return GPG_ERR_NOT_SUPPORTED; if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); + return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) cipher->cipher->encrypt (cipher->ctx, outptr, inptr); - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; } -grub_err_t +gcry_err_code_t grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, void *iv_in) { grub_uint8_t *inptr, *outptr, *end; void *iv; + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); + return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; iv = iv_in; for (inptr = in, outptr = out; inptr < end; @@ -199,19 +202,20 @@ grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, iv = outptr; } grub_memcpy (iv_in, iv, cipher->cipher->blocksize); - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; } -grub_err_t +gcry_err_code_t grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, void *iv) { grub_uint8_t *inptr, *outptr, *end; grub_uint8_t ivt[cipher->cipher->blocksize]; + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; if (size % cipher->cipher->blocksize != 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "This encryption can't decrypt partial blocks"); + return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) @@ -221,5 +225,13 @@ grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); grub_memcpy (iv, ivt, cipher->cipher->blocksize); } - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; +} + +grub_err_t +grub_crypto_gcry_error (gcry_err_code_t in) +{ + if (in == GPG_ERR_NO_ERROR) + return GRUB_ERR_NONE; + return GRUB_ACCESS_DENIED; } From 37f7911f01628181288aaf7fe9e3b871137d7972 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 Nov 2009 01:27:38 +0100 Subject: [PATCH 014/164] Fix compilation error --- include/grub/crypto.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 7a3461e3b..34b1cb078 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -205,6 +205,10 @@ grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size, void *iv); void +grub_cipher_register (gcry_cipher_spec_t *cipher); +void +grub_cipher_unregister (gcry_cipher_spec_t *cipher); +void grub_md_register (gcry_md_spec_t *digest); void grub_md_unregister (gcry_md_spec_t *cipher); From df48e9e18d649f5305b701eb7c77c5a0bef9515d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 Nov 2009 16:25:50 +0100 Subject: [PATCH 015/164] REimport of videomask patch --- commands/videotest.c | 11 +- include/grub/video.h | 13 ++- loader/i386/linux.c | 4 +- loader/i386/pc/xnu.c | 22 ++-- term/gfxterm.c | 14 +-- video/i386/pc/vbe.c | 36 ++++--- video/video.c | 244 +++++++++++++++++++------------------------ 7 files changed, 166 insertions(+), 178 deletions(-) diff --git a/commands/videotest.c b/commands/videotest.c index 6fe4b9bd1..fe504ee7b 100644 --- a/commands/videotest.c +++ b/commands/videotest.c @@ -30,9 +30,7 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { - if (grub_video_set_mode ("1024x768;800x600;640x480", 0) != GRUB_ERR_NONE) - return grub_errno; - + grub_err_t err; grub_video_color_t color; unsigned int x; unsigned int y; @@ -49,6 +47,10 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), const char *str; int texty; + err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); + if (err) + return err; + grub_video_get_viewport (&x, &y, &width, &height); grub_video_create_render_target (&text_layer, width, height, @@ -152,12 +154,13 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); - for (i = 0; i < 255; i++) + for (i = 0; i < 5; i++) { color = grub_video_map_rgb (i, 33, 77); grub_video_fill_rect (color, 0, 0, width, height); grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0, 0, 0, width, height); + grub_video_swap_buffers (); } grub_getkey (); diff --git a/include/grub/video.h b/include/grub/video.h index 4145db465..53fe67c4e 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -171,7 +171,7 @@ struct grub_video_adapter grub_err_t (*fini) (void); grub_err_t (*setup) (unsigned int width, unsigned int height, - unsigned int mode_type); + unsigned int mode_type, unsigned int mode_mask); grub_err_t (*get_info) (struct grub_video_mode_info *mode_info); @@ -307,7 +307,14 @@ grub_err_t grub_video_set_active_render_target (struct grub_video_render_target grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); grub_err_t grub_video_set_mode (const char *modestring, - int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, - struct grub_video_mode_info *mode_info)); + unsigned int modemask, + unsigned int modevalue); + +static inline int +grub_video_check_mode_flag (unsigned int flags, unsigned int mask, + unsigned int flag, int def) +{ + return (flag & mask) ? !! (flags & flag) : def; +} #endif /* ! GRUB_VIDEO_HEADER */ diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 4bdb09b24..8659e8245 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -523,11 +523,11 @@ grub_linux_boot (void) if (! tmp) return grub_errno; grub_sprintf (tmp, "%s;text", modevar); - err = grub_video_set_mode (tmp, 0); + err = grub_video_set_mode (tmp, 0, 0); grub_free (tmp); } else - err = grub_video_set_mode ("text", 0); + err = grub_video_set_mode ("text", 0, 0); if (err) { diff --git a/loader/i386/pc/xnu.c b/loader/i386/pc/xnu.c index ebb176bb4..839d0ad44 100644 --- a/loader/i386/pc/xnu.c +++ b/loader/i386/pc/xnu.c @@ -26,16 +26,7 @@ #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) -#define DEFAULT_VIDEO_MODE "1024x768x32,800x600x32,640x480x32" - -static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)), - struct grub_video_mode_info *info) -{ - if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) - return 0; - - return 1; -} +#define DEFAULT_VIDEO_MODE "auto" /* Setup video for xnu. */ grub_err_t @@ -48,8 +39,12 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) grub_err_t err; modevar = grub_env_get ("gfxpayload"); + /* Consider only graphical 32-bit deep modes. */ if (! modevar || *modevar == 0) - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook); + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); else { tmp = grub_malloc (grub_strlen (modevar) @@ -58,7 +53,10 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate temporary storag"); grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); - err = grub_video_set_mode (tmp, video_hook); + err = grub_video_set_mode (tmp, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); grub_free (tmp); } diff --git a/term/gfxterm.c b/term/gfxterm.c index f161499e6..57c51cffa 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -27,7 +27,7 @@ #include #include -#define DEFAULT_VIDEO_MODE "1024x768,800x600,640x480" +#define DEFAULT_VIDEO_MODE "auto" #define DEFAULT_BORDER_WIDTH 10 #define DEFAULT_STANDARD_COLOR 0x07 @@ -244,12 +244,6 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, return grub_errno; } -static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)), - struct grub_video_mode_info *info) -{ - return ! (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT); -} - static grub_err_t grub_gfxterm_init (void) { @@ -269,13 +263,15 @@ grub_gfxterm_init (void) /* Parse gfxmode environment variable if set. */ modevar = grub_env_get ("gfxmode"); if (! modevar || *modevar == 0) - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook); + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); else { tmp = grub_malloc (grub_strlen (modevar) + sizeof (DEFAULT_VIDEO_MODE) + 1); grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); - err = grub_video_set_mode (tmp, video_hook); + err = grub_video_set_mode (tmp, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); grub_free (tmp); } diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index a285b26ba..8759ba652 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -362,7 +362,7 @@ grub_video_vbe_fini (void) static grub_err_t grub_video_vbe_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask) { grub_uint16_t *p; struct grub_vbe_mode_info_block vbe_mode_info; @@ -412,32 +412,40 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, /* Not compatible memory model. */ continue; - if ((vbe_mode_info.x_resolution != width) - || (vbe_mode_info.y_resolution != height)) + if (((vbe_mode_info.x_resolution != width) + || (vbe_mode_info.y_resolution != height)) && width != 0 && height != 0) /* Non matching resolution. */ continue; /* Check if user requested RGB or index color mode. */ - if ((mode_type & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) + if ((mode_mask & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) { - if (((mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != 0) - && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)) - /* Requested only index color modes. */ - continue; + unsigned my_mode_type = 0; - if (((mode_type & GRUB_VIDEO_MODE_TYPE_RGB) != 0) - && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)) - /* Requested only RGB modes. */ - continue; + if (vbe_mode_info.memory_model == GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL) + my_mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + + if (vbe_mode_info.memory_model == GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR) + my_mode_type |= GRUB_VIDEO_MODE_TYPE_RGB; + + if ((my_mode_type & mode_mask + & (GRUB_VIDEO_MODE_TYPE_RGB | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)) + != (mode_type & mode_mask + & (GRUB_VIDEO_MODE_TYPE_RGB + | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR))) + continue; } /* If there is a request for specific depth, ignore others. */ if ((depth != 0) && (vbe_mode_info.bits_per_pixel != depth)) continue; - /* Select mode with most number of bits per pixel. */ + /* Select mode with most of "volume" (size of framebuffer in bits). */ if (best_vbe_mode != 0) - if (vbe_mode_info.bits_per_pixel < best_vbe_mode_info.bits_per_pixel) + if ((grub_uint64_t) vbe_mode_info.bits_per_pixel + * vbe_mode_info.x_resolution * vbe_mode_info.y_resolution + < (grub_uint64_t) best_vbe_mode_info.bits_per_pixel + * best_vbe_mode_info.x_resolution * best_vbe_mode_info.y_resolution) continue; /* Save so far best mode information for later use. */ diff --git a/video/video.c b/video/video.c index c1d66bdd0..eff257122 100644 --- a/video/video.c +++ b/video/video.c @@ -399,21 +399,81 @@ grub_video_get_active_render_target (struct grub_video_render_target **target) return grub_video_adapter_active->get_active_render_target (target); } +/* Parse x[x]*/ +static grub_err_t +parse_modespec (const char *current_mode, int *width, int *height, int *depth) +{ + const char *value; + const char *param = current_mode; + + *width = *height = *depth = -1; + + if (grub_strcmp (param, "auto") == 0) + { + *width = *height = 0; + return GRUB_ERR_NONE; + } + + /* Find width value. */ + value = param; + param = grub_strchr(param, 'x'); + if (param == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + param++; + + *width = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + /* Find height value. */ + value = param; + param = grub_strchr(param, 'x'); + if (param == NULL) + { + *height = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + } + else + { + /* We have optional color depth value. */ + param++; + + *height = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + + /* Convert color depth value. */ + value = param; + *depth = grub_strtoul (value, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Invalid mode: %s\n", + current_mode); + } + return GRUB_ERR_NONE; +} + grub_err_t grub_video_set_mode (const char *modestring, - int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, - struct grub_video_mode_info *mode_info)) + unsigned int modemask, + unsigned int modevalue) { char *tmp; char *next_mode; char *current_mode; - char *param; - char *value; char *modevar; - int width = -1; - int height = -1; - int depth = -1; - int flags = 0; + + modevalue &= modemask; /* Take copy of env.var. as we don't want to modify that. */ modevar = grub_strdup (modestring); @@ -429,26 +489,26 @@ grub_video_set_mode (const char *modestring, || grub_memcmp (next_mode, "keep,", sizeof ("keep,") - 1) == 0 || grub_memcmp (next_mode, "keep;", sizeof ("keep;") - 1) == 0) { - struct grub_video_mode_info mode_info; int suitable = 1; grub_err_t err; - grub_memset (&mode_info, 0, sizeof (mode_info)); - if (grub_video_adapter_active) { + struct grub_video_mode_info mode_info; + grub_memset (&mode_info, 0, sizeof (mode_info)); err = grub_video_get_info (&mode_info); if (err) { suitable = 0; grub_errno = GRUB_ERR_NONE; } + if ((mode_info.mode_type & modemask) != modevalue) + suitable = 0; } - else - mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_PURE_TEXT; + else if (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) != 0) + && ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) == 0)) + suitable = 0; - if (suitable && hook) - suitable = hook (grub_video_adapter_active, &mode_info); if (suitable) { grub_free (modevar); @@ -482,15 +542,16 @@ grub_video_set_mode (const char *modestring, /* Loop until all modes has been tested out. */ while (next_mode != NULL) { + int width = -1; + int height = -1; + int depth = -1; + grub_err_t err; + unsigned int flags = modevalue; + unsigned int flagmask = modemask; + /* Use last next_mode as current mode. */ tmp = next_mode; - /* Reset video mode settings. */ - width = -1; - height = -1; - depth = -1; - flags = 0; - /* Save position of next mode and separate modes. */ for (; *next_mode; next_mode++) if (*next_mode == ',' || *next_mode == ';') @@ -509,19 +570,16 @@ grub_video_set_mode (const char *modestring, /* Initialize token holders. */ current_mode = tmp; - param = tmp; - value = NULL; /* XXX: we assume that we're in pure text mode if no video mode is initialized. Is it always true? */ - if (grub_strcmp (param, "text") == 0) + if (grub_strcmp (current_mode, "text") == 0) { struct grub_video_mode_info mode_info; grub_memset (&mode_info, 0, sizeof (mode_info)); - mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_PURE_TEXT; - - if (! hook || hook (0, &mode_info)) + if (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) == 0) + || ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) != 0)) { /* Valid mode found from adapter, and it has been activated. Specify it as active adapter. */ @@ -534,121 +592,31 @@ grub_video_set_mode (const char *modestring, } } - /* Parse x[x]*/ - - /* Find width value. */ - value = param; - param = grub_strchr(param, 'x'); - if (param == NULL) + err = parse_modespec (current_mode, &width, &height, &depth); + if (err) { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - /* Free memory before returning. */ grub_free (modevar); - return rc; - } - - *param = 0; - param++; - - width = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - - /* Find height value. */ - value = param; - param = grub_strchr(param, 'x'); - if (param == NULL) - { - height = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - } - else - { - /* We have optional color depth value. */ - *param = 0; - param++; - - height = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } - - /* Convert color depth value. */ - value = param; - depth = grub_strtoul (value, 0, 0); - if (grub_errno != GRUB_ERR_NONE) - { - grub_err_t rc; - - /* First setup error message. */ - rc = grub_error (GRUB_ERR_BAD_ARGUMENT, - "Invalid mode: %s\n", - current_mode); - - /* Free memory before returning. */ - grub_free (modevar); - - return rc; - } + return err; } /* Try out video mode. */ - /* If we have 8 or less bits, then assume that it is indexed color mode. */ - if ((depth <= 8) && (depth != -1)) - flags |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + /* If user requested specific depth check if this depth is supported. */ + if (depth != -1 && (flagmask & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + && + (((flags & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + != ((depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)))) + continue; - /* We have more than 8 bits, then assume that it is RGB color mode. */ - if (depth > 8) - flags |= GRUB_VIDEO_MODE_TYPE_RGB; - - /* If user requested specific depth, forward that information to driver. */ if (depth != -1) - flags |= (depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) - & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + { + flags |= (depth << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + flagmask |= GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + } /* Try to initialize requested mode. Ignore any errors. */ grub_video_adapter_t p; @@ -670,7 +638,7 @@ grub_video_set_mode (const char *modestring, } /* Try to initialize video mode. */ - err = p->setup (width, height, flags); + err = p->setup (width, height, flags, flagmask); if (err != GRUB_ERR_NONE) { p->fini (); @@ -686,7 +654,15 @@ grub_video_set_mode (const char *modestring, continue; } - if (hook && ! hook (p, &mode_info)) + flags = mode_info.mode_type & ~GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + flags |= (mode_info.bpp << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) + & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK; + + /* Check that mode is suitable for upper layer. */ + if ((flags & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) + ? (((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modemask) != 0) + && ((GRUB_VIDEO_MODE_TYPE_PURE_TEXT & modevalue) == 0)) + : ((flags & modemask) != modevalue)) { p->fini (); grub_errno = GRUB_ERR_NONE; From 6e7d9194d1e8d605d0462260836f723ac7d6ef1a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 02:32:29 +0100 Subject: [PATCH 016/164] Add HMAC and PBKDF2 --- conf/common.rmk | 5 ++ import_gcry.py | 27 +++++++- include/grub/cipher_wrap.h | 2 +- include/grub/crypto.h | 38 +++++++++- lib/crypto.c | 137 ++++++++++++++++++++++++++++++++++++- lib/pbkdf2.c | 101 +++++++++++++++++++++++++++ 6 files changed, 302 insertions(+), 8 deletions(-) create mode 100644 lib/pbkdf2.c diff --git a/conf/common.rmk b/conf/common.rmk index 35b4620f4..3356c556b 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -624,4 +624,9 @@ crypto_mod_SOURCES = lib/crypto.c crypto_mod_CFLAGS = $(COMMON_CFLAGS) crypto_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += pbkdf2.mod +pbkdf2_mod_SOURCES = lib/pbkdf2.c +pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) +pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/gcry.mk diff --git a/import_gcry.py b/import_gcry.py index 39542d8c4..ae5b76778 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -1,3 +1,21 @@ +#* +#* GRUB -- GRand Unified Bootloader +#* Copyright (C) 2009 Free Software Foundation, Inc. +#* +#* GRUB 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, either version 3 of the License, or +#* (at your option) any later version. +#* +#* GRUB 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 GRUB. If not, see . +#* + import re import sys import os @@ -26,9 +44,12 @@ conf = open (os.path.join (outdir, "conf", "gcry.rmk"), "w") conf.write ("# -*- makefile -*-\n\n") chlog = "" -mdblocksizes = {"_gcry_digest_spec_crc32" : 1, - "_gcry_digest_spec_crc32_rfc1510" : 1, - "_gcry_digest_spec_crc24_rfc2440" : 1, +# Strictly speaking CRC32/CRC24 work on bytes so this value should be 1 +# But libgcrypt uses 64. Let's keep the value for compatibility. Since +# noone uses CRC24/CRC32 for HMAC this is no problem +mdblocksizes = {"_gcry_digest_spec_crc32" : 64, + "_gcry_digest_spec_crc32_rfc1510" : 64, + "_gcry_digest_spec_crc24_rfc2440" : 64, "_gcry_digest_spec_md4" : 64, "_gcry_digest_spec_md5" : 64, "_gcry_digest_spec_rmd160" : 64, diff --git a/include/grub/cipher_wrap.h b/include/grub/cipher_wrap.h index 9e6242b7f..60ab369f0 100644 --- a/include/grub/cipher_wrap.h +++ b/include/grub/cipher_wrap.h @@ -64,7 +64,7 @@ typedef union { static inline void grub_assert_real (const char *file, int line, int cond) { - if (cond) + if (!cond) grub_fatal ("Assertion failed at %s:%d\n", file, line); } diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 34b1cb078..df15f9bb9 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -166,11 +166,15 @@ typedef struct gcry_md_spec struct gcry_md_spec *next; } gcry_md_spec_t; -typedef struct grub_crypto_cipher_handle +struct grub_crypto_cipher_handle { const struct gcry_cipher_spec *cipher; char ctx[0]; -} *grub_crypto_cipher_handle_t; +}; + +typedef struct grub_crypto_cipher_handle *grub_crypto_cipher_handle_t; + +struct grub_crypto_hmac_handle; const gcry_cipher_spec_t * grub_crypto_lookup_cipher_by_name (const char *name); @@ -213,7 +217,7 @@ grub_md_register (gcry_md_spec_t *digest); void grub_md_unregister (gcry_md_spec_t *cipher); void -grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, +grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in, grub_size_t inlen); const gcry_md_spec_t * grub_crypto_lookup_md_by_name (const char *name); @@ -223,7 +227,35 @@ grub_crypto_gcry_error (gcry_err_code_t in); void grub_burn_stack (grub_size_t size); +struct grub_crypto_hmac_handle * +grub_crypto_hmac_init (const struct gcry_md_spec *md, + const void *key, grub_size_t keylen); +void +grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, void *data, + grub_size_t datalen); +gcry_err_code_t +grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out); + +gcry_err_code_t +grub_crypto_hmac_buffer (const struct gcry_md_spec *md, + const void *key, grub_size_t keylen, + void *data, grub_size_t datalen, void *out); + extern gcry_md_spec_t _gcry_digest_spec_md5; #define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5) +#define GRUB_MD_SHA1 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha1) + +/* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant + of digest supplied by MD. Inputs are the password P of length PLEN, + the salt S of length SLEN, the iteration counter C (> 0), and the + desired derived output length DKLEN. Output buffer is DK which + must have room for at least DKLEN octets. The output buffer will + be filled with the derived data. */ +gcry_err_code_t +grub_crypto_pbkdf2 (const struct gcry_md_spec *md, + const grub_uint8_t *P, grub_size_t Plen, + const grub_uint8_t *S, grub_size_t Slen, + unsigned int c, + grub_uint8_t *DK, grub_size_t dkLen); #endif diff --git a/lib/crypto.c b/lib/crypto.c index 718d6e278..3cb66f942 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -21,6 +21,13 @@ #include #include +struct grub_crypto_hmac_handle +{ + const struct gcry_md_spec *md; + void *ctx; + void *opad; +}; + static gcry_cipher_spec_t *grub_ciphers = NULL; static gcry_md_spec_t *grub_digests = NULL; @@ -69,7 +76,7 @@ grub_md_unregister (gcry_md_spec_t *cipher) } void -grub_crypto_hash (const gcry_md_spec_t *hash, void *out, void *in, +grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in, grub_size_t inlen) { grub_uint8_t ctx[hash->contextsize]; @@ -228,6 +235,134 @@ grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, return GPG_ERR_NO_ERROR; } +/* Based on gcry/cipher/md.c. */ +struct grub_crypto_hmac_handle * +grub_crypto_hmac_init (const struct gcry_md_spec *md, + const void *key, grub_size_t keylen) +{ + grub_uint8_t *helpkey = NULL; + grub_uint8_t *ipad = NULL, *opad = NULL; + void *ctx = NULL; + struct grub_crypto_hmac_handle *ret = NULL; + unsigned i; + + if (md->mdlen > md->blocksize) + return NULL; + + ctx = grub_malloc (md->contextsize); + if (!ctx) + goto err; + + if ( keylen > md->blocksize ) + { + helpkey = grub_malloc (md->mdlen); + if (!helpkey) + goto err; + grub_crypto_hash (md, helpkey, key, keylen); + + key = helpkey; + keylen = md->mdlen; + } + + ipad = grub_zalloc (md->blocksize); + if (!ipad) + goto err; + + opad = grub_zalloc (md->blocksize); + if (!opad) + goto err; + + grub_memcpy ( ipad, key, keylen ); + grub_memcpy ( opad, key, keylen ); + for (i=0; i < md->blocksize; i++ ) + { + ipad[i] ^= 0x36; + opad[i] ^= 0x5c; + } + grub_free (helpkey); + helpkey = NULL; + + md->init (ctx); + + md->write (ctx, ipad, md->blocksize); /* inner pad */ + grub_memset (ipad, 0, md->blocksize); + grub_free (ipad); + ipad = NULL; + + ret = grub_malloc (sizeof (*ret)); + if (!ret) + goto err; + + ret->md = md; + ret->ctx = ctx; + ret->opad = opad; + + return ret; + + err: + grub_free (helpkey); + grub_free (ctx); + grub_free (ipad); + grub_free (opad); + return NULL; +} + +void +grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, void *data, + grub_size_t datalen) +{ + hnd->md->write (hnd->ctx, data, datalen); +} + +gcry_err_code_t +grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out) +{ + grub_uint8_t *p; + grub_uint8_t *ctx2; + + ctx2 = grub_malloc (hnd->md->contextsize); + if (!ctx2) + return GPG_ERR_OUT_OF_MEMORY; + + hnd->md->final (hnd->ctx); + hnd->md->read (hnd->ctx); + p = hnd->md->read (hnd->ctx); + + hnd->md->init (ctx2); + hnd->md->write (ctx2, hnd->opad, hnd->md->blocksize); + hnd->md->write (ctx2, p, hnd->md->mdlen); + hnd->md->final (ctx2); + grub_memset (hnd->opad, 0, hnd->md->blocksize); + grub_free (hnd->opad); + grub_memset (hnd->ctx, 0, hnd->md->contextsize); + grub_free (hnd->ctx); + + grub_memcpy (out, hnd->md->read (ctx2), hnd->md->mdlen); + grub_memset (ctx2, 0, hnd->md->contextsize); + grub_free (ctx2); + + grub_memset (hnd, 0, sizeof (*hnd)); + grub_free (hnd); + + return GPG_ERR_NO_ERROR; +} + +gcry_err_code_t +grub_crypto_hmac_buffer (const struct gcry_md_spec *md, + const void *key, grub_size_t keylen, + void *data, grub_size_t datalen, void *out) +{ + struct grub_crypto_hmac_handle *hnd; + + hnd = grub_crypto_hmac_init (md, key, keylen); + if (!hnd) + return GPG_ERR_OUT_OF_MEMORY; + + grub_crypto_hmac_write (hnd, data, datalen); + return grub_crypto_hmac_fini (hnd, out); +} + + grub_err_t grub_crypto_gcry_error (gcry_err_code_t in) { diff --git a/lib/pbkdf2.c b/lib/pbkdf2.c new file mode 100644 index 000000000..f2d3ca97f --- /dev/null +++ b/lib/pbkdf2.c @@ -0,0 +1,101 @@ +/* gc-pbkdf2-sha1.c --- Password-Based Key Derivation Function a'la PKCS#5 + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. + + 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; either version 2, or (at your option) + any later version. + + 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Simon Josefsson. */ + +#include +#include +#include + +/* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant + of digest supplied by MD. Inputs are the password P of length PLEN, + the salt S of length SLEN, the iteration counter C (> 0), and the + desired derived output length DKLEN. Output buffer is DK which + must have room for at least DKLEN octets. The output buffer will + be filled with the derived data. */ +gcry_err_code_t +grub_crypto_pbkdf2 (const struct gcry_md_spec *md, + const grub_uint8_t *P, grub_size_t Plen, + const grub_uint8_t *S, grub_size_t Slen, + unsigned int c, + grub_uint8_t *DK, grub_size_t dkLen) +{ + unsigned int hLen = md->mdlen; + grub_uint8_t U[md->mdlen]; + grub_uint8_t T[md->mdlen]; + unsigned int u; + unsigned int l; + unsigned int r; + unsigned int i; + unsigned int k; + gcry_err_code_t rc; + grub_uint8_t *tmp; + grub_size_t tmplen = Slen + 4; + + if (c == 0) + return GPG_ERR_INV_ARG; + + if (dkLen == 0) + return GPG_ERR_INV_ARG; + + if (dkLen > 4294967295U) + return GPG_ERR_INV_ARG; + + l = ((dkLen - 1) / hLen) + 1; + r = dkLen - (l - 1) * hLen; + + tmp = grub_malloc (tmplen); + if (tmp == NULL) + return GPG_ERR_OUT_OF_MEMORY; + + grub_memcpy (tmp, S, Slen); + + for (i = 1; i <= l; i++) + { + grub_memset (T, 0, hLen); + + for (u = 1; u <= c; u++) + { + if (u == 1) + { + tmp[Slen + 0] = (i & 0xff000000) >> 24; + tmp[Slen + 1] = (i & 0x00ff0000) >> 16; + tmp[Slen + 2] = (i & 0x0000ff00) >> 8; + tmp[Slen + 3] = (i & 0x000000ff) >> 0; + + rc = grub_crypto_hmac_buffer (md, P, Plen, tmp, tmplen, U); + } + else + rc = grub_crypto_hmac_buffer (md, P, Plen, U, hLen, U); + + if (rc != GPG_ERR_NO_ERROR) + { + grub_free (tmp); + return rc; + } + + for (k = 0; k < hLen; k++) + T[k] ^= U[k]; + } + + grub_memcpy (DK + (i - 1) * hLen, T, i == l ? r : hLen); + } + + grub_free (tmp); + + return GPG_ERR_NO_ERROR; +} From 10e53efaee09c05c91f3f8b79230d45e3db6c496 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 Nov 2009 23:31:27 +0100 Subject: [PATCH 017/164] crypto_memcmp --- include/grub/crypto.h | 6 ++++++ lib/crypto.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/grub/crypto.h b/include/grub/crypto.h index df15f9bb9..4d8ce88b8 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -242,8 +242,11 @@ grub_crypto_hmac_buffer (const struct gcry_md_spec *md, void *data, grub_size_t datalen, void *out); extern gcry_md_spec_t _gcry_digest_spec_md5; +extern gcry_md_spec_t _gcry_digest_spec_sha1; +extern gcry_md_spec_t _gcry_digest_spec_sha256; #define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5) #define GRUB_MD_SHA1 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha1) +#define GRUB_MD_SHA256 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha256) /* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant of digest supplied by MD. Inputs are the password P of length PLEN, @@ -258,4 +261,7 @@ grub_crypto_pbkdf2 (const struct gcry_md_spec *md, unsigned int c, grub_uint8_t *DK, grub_size_t dkLen); +int +grub_crypto_memcmp (void *a, void *b, grub_size_t n); + #endif diff --git a/lib/crypto.c b/lib/crypto.c index 3cb66f942..4b36dde6f 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -370,3 +370,18 @@ grub_crypto_gcry_error (gcry_err_code_t in) return GRUB_ERR_NONE; return GRUB_ACCESS_DENIED; } + +int +grub_crypto_memcmp (void *a, void *b, grub_size_t n) +{ + register grub_size_t counter = 0; + grub_uint8_t *pa, *pb; + + for (pa = a, pb = b; n; pa++, pb++, n--) + { + if (*pa != *pb) + counter++; + } + + return !!counter; +} From 228734ab023191ff8df42e83c615d7ab610a3aea Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 Nov 2009 23:36:42 +0100 Subject: [PATCH 018/164] MAX_PASSLEN based authentication --- commands/password.c | 13 ++++++++--- include/grub/auth.h | 7 +----- normal/auth.c | 56 ++------------------------------------------- 3 files changed, 13 insertions(+), 63 deletions(-) diff --git a/commands/password.c b/commands/password.c index 0e048797e..247e0bffd 100644 --- a/commands/password.c +++ b/commands/password.c @@ -26,18 +26,20 @@ static grub_dl_t my_mod; +#define MAX_PASSLEN 1024 + static grub_err_t check_password (const char *user, void *password) { - char entered[1024]; + char entered[MAX_PASSLEN]; grub_memset (entered, 0, sizeof (entered)); if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1)) return GRUB_ACCESS_DENIED; - if (grub_auth_strcmp (entered, password) != 0) + if (grub_crypto_memcmp (entered, password, MAX_PASSLEN) != 0) return GRUB_ACCESS_DENIED; grub_auth_authenticate (user); @@ -51,13 +53,18 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), { grub_err_t err; char *pass; + int copylen; if (argc != 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two arguments expected."); - pass = grub_strdup (args[1]); + pass = grub_zalloc (MAX_PASSLEN); if (!pass) return grub_errno; + copylen = grub_strlen (argv[1]); + if (copylen >= MAX_PASSLEN) + copylen = MAX_PASSLEN - 1; + grub_memcpy (pass, argv[1], copylen); err = grub_auth_register_authentication (args[0], check_password, pass); if (err) diff --git a/include/grub/auth.h b/include/grub/auth.h index da930eeda..e72d984ae 100644 --- a/include/grub/auth.h +++ b/include/grub/auth.h @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with GRUB. If not, see . */ -#ifndef GRUB_AURH_HEADER +#ifndef GRUB_AUTH_HEADER #define GRUB_AUTH_HEADER 1 #include @@ -26,11 +26,6 @@ string, len, \ '*', 0, 0) -/* Like strcmp but untimeable. Accepts NULL as second argument. */ -int grub_auth_strcmp (const char *user_input, const char *template); -/* Like strcmp but untimeable and ignores commas in needle. */ -int grub_auth_strword (const char *haystack, const char *needle); - typedef grub_err_t (*grub_auth_callback_t) (const char*, void *); grub_err_t grub_auth_register_authentication (const char *user, diff --git a/normal/auth.c b/normal/auth.c index c71262584..7d5a07d26 100644 --- a/normal/auth.c +++ b/normal/auth.c @@ -35,58 +35,6 @@ struct grub_auth_user struct grub_auth_user *users = NULL; -int -grub_auth_strcmp (const char *s1, const char *s2) -{ - int ret; - grub_uint64_t end; - - end = grub_get_time_ms () + 100; - ret = grub_strcmp (s1, s2); - - /* This prevents an attacker from deriving information about the - password from the time it took to execute this function. */ - while (grub_get_time_ms () < end); - - return ret; -} - -static int -grub_iswordseparator (int c) -{ - return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&'); -} - -int -grub_auth_strword (const char *haystack, const char *needle) -{ - const char *n_pos = needle; - int found = 0; - - while (grub_iswordseparator (*haystack)) - haystack++; - - while (*haystack) - { - int ok = 1; - /* Crawl both the needle and the haystack word we're on. */ - while(*haystack && !grub_iswordseparator (*haystack)) - { - if (*haystack == *n_pos && ok) - n_pos++; - else - ok = 0; - - haystack++; - } - - if (ok) - found = 1; - } - - return found; -} - grub_err_t grub_auth_register_authentication (const char *user, grub_auth_callback_t callback, @@ -193,8 +141,8 @@ is_authenticated (const char *userlist) return 0; name = ((struct grub_auth_user *) item)->name; - return (userlist && grub_auth_strword (userlist, name)) - || grub_auth_strword (superusers, name); + return (userlist && grub_strword (userlist, name)) + || grub_strword (superusers, name); } superusers = grub_env_get ("superusers"); From 53eb42a6fac7fa4dc13f485b2dff6127a484b036 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 Nov 2009 23:42:11 +0100 Subject: [PATCH 019/164] Compilation error fixed --- commands/password.c | 5 +++-- normal/auth.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/password.c b/commands/password.c index 247e0bffd..99b993839 100644 --- a/commands/password.c +++ b/commands/password.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -61,10 +62,10 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), pass = grub_zalloc (MAX_PASSLEN); if (!pass) return grub_errno; - copylen = grub_strlen (argv[1]); + copylen = grub_strlen (args[1]); if (copylen >= MAX_PASSLEN) copylen = MAX_PASSLEN - 1; - grub_memcpy (pass, argv[1], copylen); + grub_memcpy (pass, args[1], copylen); err = grub_auth_register_authentication (args[0], check_password, pass); if (err) diff --git a/normal/auth.c b/normal/auth.c index 7d5a07d26..0a8b5bc82 100644 --- a/normal/auth.c +++ b/normal/auth.c @@ -164,7 +164,7 @@ grub_auth_check_authentication (const char *userlist) auto int hook (grub_list_t item); int hook (grub_list_t item) { - if (grub_auth_strcmp (login, ((struct grub_auth_user *) item)->name) == 0) + if (grub_strcmp (login, ((struct grub_auth_user *) item)->name) == 0) cur = (struct grub_auth_user *) item; return 0; } From 0e3c54a5c515e4d3b956b46e800396c55b244804 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Nov 2009 02:36:21 +0100 Subject: [PATCH 020/164] PBKDF2 passwords available --- .bzrignore | 56 ++++++ commands/password_pbkdf2.c | 202 ++++++++++++++++++++++ conf/common.rmk | 9 + conf/i386-coreboot.rmk | 2 +- conf/i386-efi.rmk | 2 +- conf/i386-ieee1275.rmk | 2 +- conf/i386-pc.rmk | 2 +- conf/powerpc-ieee1275.rmk | 2 +- conf/sparc64-ieee1275.rmk | 2 +- conf/x86_64-efi.rmk | 2 +- include/grub/crypto.h | 2 + util/grub-pbkdf2.c | 337 +++++++++++++++++++++++++++++++++++++ 12 files changed, 613 insertions(+), 7 deletions(-) create mode 100644 .bzrignore create mode 100644 commands/password_pbkdf2.c create mode 100644 util/grub-pbkdf2.c diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 000000000..e5d7be2d4 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,56 @@ +00_header +10_* +30_os-prober +40_custom +autom4te.cache +build_env.mk +.bzrignore +config.cache +config.h +config.h.in +config.log +config.status +configure +conf/*.mk +*.d +DISTLIST +docs/*.info +docs/stamp-vti +docs/version.texi +*.elf +*.exec +genkernsyms.sh +gensymlist.sh +grub-dumpbios +grub-editenv +grub-emu +grub_emu_init.c +grub_emu_init.h +grub-fstest +grub_fstest_init.c +grub_fstest_init.h +grub-install +grub-mk* +grub-pbkdf2 +grub-pe2elf +grub-probe +grub_probe_init.c +grub_probe_init.h +grub_script.tab.c +grub_script.tab.h +grub-setup +grub_setup_init.c +grub_setup_init.h +*.img +include/grub/cpu +include/grub/machine +*.lst +Makefile +*.mod +mod-*.c +*.pf2 +stamp-h +stamp-h1 +stamp-h.in +symlist.c +update-grub_lib diff --git a/commands/password_pbkdf2.c b/commands/password_pbkdf2.c new file mode 100644 index 000000000..44da0101e --- /dev/null +++ b/commands/password_pbkdf2.c @@ -0,0 +1,202 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009 Vladimir 'phcoder' Serbineko + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +static grub_dl_t my_mod; + +struct pbkdf2_password +{ + grub_uint8_t *salt; + grub_size_t saltlen; + unsigned int c; + grub_uint8_t *expected; + grub_size_t buflen; +}; + +static grub_err_t +check_password (const char *user, void *pin) +{ + char entered[1024]; + grub_uint8_t *buf; + struct pbkdf2_password *pass = pin; + gcry_err_code_t err; + + grub_memset (entered, 0, sizeof (entered)); + + if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1)) + return GRUB_ACCESS_DENIED; + + buf = grub_malloc (pass->buflen); + if (!buf) + return grub_crypto_gcry_error (GPG_ERR_OUT_OF_MEMORY); + + err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, (grub_uint8_t *) &entered, + grub_strlen (entered), + pass->salt, pass->saltlen, pass->c, + buf, pass->buflen); + if (err) + { + grub_free (buf); + return grub_crypto_gcry_error (err); + } + + if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0) + return GRUB_ACCESS_DENIED; + + grub_auth_authenticate (user); + + return GRUB_ERR_NONE; +} + +static inline int +hex2val (char hex) +{ + if ('0' <= hex && hex <= '9') + return hex - '0'; + if ('a' <= hex && hex <= 'f') + return hex - 'a' + 10; + if ('A' <= hex && hex <= 'F') + return hex - 'A' + 10; + return -1; +} + +static grub_err_t +grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + grub_err_t err; + char *ptr, *ptr2; + grub_uint8_t *ptro; + struct pbkdf2_password *pass; + + if (argc != 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two arguments expected."); + + if (grub_memcmp (args[1], "grub.pbkdf2.sha512.", + sizeof ("grub.pbkdf2.sha512.") - 1) != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password."); + + ptr = args[1] + sizeof ("grub.pbkdf2.sha512.") - 1; + + pass = grub_malloc (sizeof (*pass)); + if (!pass) + return grub_errno; + + pass->c = grub_strtoul (ptr, &ptr, 0); + if (*ptr != '.') + { + grub_free (pass); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password."); + } + ptr++; + + ptr2 = grub_strchr (ptr, '.'); + if (!ptr2 || ((ptr2 - ptr) & 1) || grub_strlen (ptr2 + 1) & 1) + { + grub_free (pass); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password."); + } + + pass->saltlen = (ptr2 - ptr) >> 1; + pass->buflen = grub_strlen (ptr2 + 1) >> 1; + ptro = pass->salt = grub_malloc (pass->saltlen); + if (!ptro) + { + grub_free (pass); + return grub_errno; + } + while (ptr < ptr2) + { + int hex1, hex2; + hex1 = hex2val (*ptr); + ptr++; + hex2 = hex2val (*ptr); + ptr++; + if (hex1 < 0 || hex2 < 0) + { + grub_free (pass->salt); + grub_free (pass); + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Incorrect PBKDF2 password."); + } + + *ptro = (hex1 << 4) | hex2; + ptro++; + } + + ptro = pass->expected = grub_malloc (pass->buflen); + if (!ptro) + { + grub_free (pass->salt); + grub_free (pass); + return grub_errno; + } + ptr = ptr2 + 1; + ptr2 += grub_strlen (ptr2); + while (ptr < ptr2) + { + int hex1, hex2; + hex1 = hex2val (*ptr); + ptr++; + hex2 = hex2val (*ptr); + ptr++; + if (hex1 < 0 || hex2 < 0) + { + grub_free (pass->expected); + grub_free (pass->salt); + grub_free (pass); + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Incorrect PBKDF2 password."); + } + + *ptro = (hex1 << 4) | hex2; + ptro++; + } + + err = grub_auth_register_authentication (args[0], check_password, pass); + if (err) + { + grub_free (pass); + return err; + } + grub_dl_ref (my_mod); + return GRUB_ERR_NONE; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(password_pbkdf2) +{ + my_mod = mod; + cmd = grub_register_command ("password_pbkdf2", grub_cmd_password, + "password_pbkdf2 USER PBKDF2_PASSWORD", + "Set user password (PBKDF2). "); +} + +GRUB_MOD_FINI(password_pbkdf2) +{ + grub_unregister_command (cmd); +} diff --git a/conf/common.rmk b/conf/common.rmk index 3356c556b..eae37acde 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -629,4 +629,13 @@ pbkdf2_mod_SOURCES = lib/pbkdf2.c pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For password_pbkdf2.mod. +pkglib_MODULES += password_pbkdf2.mod +password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c +password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) +password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) + +bin_UTILITIES += grub-pbkdf2 +grub_pbkdf2_SOURCES = util/grub-pbkdf2.c lib/crypto.c gcry/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c + include $(srcdir)/conf/gcry.mk diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 5645395b8..83a49d398 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -130,7 +130,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/datetime.c normal/main.c \ normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 99ab06f64..6c9e8862f 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -57,7 +57,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/command.c normal/datetime.c \ - normal/auth.c normal/autofs.c \ + normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/context.c normal/main.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/menu_text.c \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 4b640de49..6042676ea 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -85,7 +85,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/color.c \ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index ac9337e41..0372b529d 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -137,7 +137,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/menu_text.c \ diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index ee7f9ec27..344aa17ac 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -65,7 +65,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/command.c kern/corecmd.c commands/extcmd.c \ lib/arg.c normal/cmdline.c normal/datetime.c \ normal/completion.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c normal/main.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c normal/main.c \ normal/menu.c \ normal/menu_text.c \ normal/menu_entry.c normal/menu_viewer.c \ diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 62e951a5e..de67a131a 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -123,7 +123,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/command.c kern/corecmd.c commands/extcmd.c \ lib/arg.c normal/cmdline.c normal/datetime.c \ normal/completion.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c normal/main.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c normal/main.c \ normal/menu.c \ normal/menu_text.c \ normal/menu_entry.c normal/menu_viewer.c \ diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 5be1b404f..d671f152b 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -53,7 +53,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \ kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ kern/partition.c kern/readerescue.c kern/term.c \ - lib/arg.c normal/cmdline.c normal/misc.c normal/auth.c \ + lib/arg.c normal/cmdline.c normal/misc.c normal/auth.c lib/crypto.c \ normal/autofs.c \ normal/completion.c normal/datetime.c normal/context.c \ normal/main.c \ diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 4d8ce88b8..eb1898fe4 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -244,9 +244,11 @@ grub_crypto_hmac_buffer (const struct gcry_md_spec *md, extern gcry_md_spec_t _gcry_digest_spec_md5; extern gcry_md_spec_t _gcry_digest_spec_sha1; extern gcry_md_spec_t _gcry_digest_spec_sha256; +extern gcry_md_spec_t _gcry_digest_spec_sha512; #define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5) #define GRUB_MD_SHA1 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha1) #define GRUB_MD_SHA256 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha256) +#define GRUB_MD_SHA512 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha512) /* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant of digest supplied by MD. Inputs are the password P of length PLEN, diff --git a/util/grub-pbkdf2.c b/util/grub-pbkdf2.c new file mode 100644 index 000000000..a05fa62b1 --- /dev/null +++ b/util/grub-pbkdf2.c @@ -0,0 +1,337 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1992-1999,2001,2003,2004,2005,2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +/* Few functions to make crypto happy. */ +void * +grub_memmove (void *dest, const void *src, grub_size_t n) +{ + return memmove (dest, src, n); +} + +void * +grub_memset (void *s, int c, grub_size_t n) +{ + return memset (s, c, n); +} + +int +grub_vprintf (const char *fmt, va_list args) +{ + return vprintf (fmt, args); +} + +int +grub_vsprintf (char *str, const char *fmt, va_list args) +{ + return vsprintf (str, fmt, args); +} + +void +grub_abort (void) +{ + abort (); +} + +static struct option options[] = + { + {"iteration_count", required_argument, 0, 'c'}, + {"buflen", required_argument, 0, 'l'}, + {"saltlen", required_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + }; + +static void +usage (int status) +{ + if (status) + fprintf (stderr, "Try ``grub-scrypt --help'' for more information.\n"); + else + printf ("\ +Usage: grub-scrypt [OPTIONS]\n\ +\nOptions:\n\ + -c number, --iteration-count=number Number of PBKDF2 iterations\n\ + -l number, --buflen=number Length of generated hash\n\ + -s number, --salt=number Length of salt\n\ +\n\ +Report bugs to <%s>.\n", PACKAGE_BUGREPORT); + + exit (status); +} + +static void +hexify (char *hex, grub_uint8_t *bin, grub_size_t n) +{ + while (n--) + { + if (((*bin & 0xf0) >> 4) < 10) + *hex = ((*bin & 0xf0) >> 4) + '0'; + else + *hex = ((*bin & 0xf0) >> 4) + 'A' - 10; + hex++; + + if ((*bin & 0xf) < 10) + *hex = (*bin & 0xf) + '0'; + else + *hex = (*bin & 0xf) + 'A' - 10; + hex++; + bin++; + } + *hex = 0; +} + +int +main (int argc, char *argv[]) +{ + unsigned int c = 10000, buflen = 64, saltlen = 64; + char *pass1, *pass2; + char *bufhex, *salthex; + gcry_err_code_t gcry_err; + grub_uint8_t *buf, *salt; + ssize_t nr; + FILE *in, *out; + struct termios s, t; + int tty_changed; + + progname = "grub-pbkdf2"; + + /* Check for options. */ + while (1) + { + int c = getopt_long (argc, argv, "c:l:s:hvV", options, 0); + + if (c == -1) + break; + + switch (c) + { + case 'c': + c = strtoul (optarg, NULL, 0); + break; + + case 'l': + buflen = strtoul (optarg, NULL, 0); + break; + + case 's': + saltlen = strtoul (optarg, NULL, 0); + break; + + case 'h': + usage (0); + return 0; + + case 'V': + printf ("%s (%s) %s\n", progname, + PACKAGE_NAME, PACKAGE_VERSION); + return 0; + + default: + usage (1); + return 1; + } + } + + bufhex = malloc (buflen * 2 + 1); + if (!bufhex) + grub_util_error ("Out of memory"); + buf = malloc (buflen); + if (!buf) + { + free (bufhex); + grub_util_error ("Out of memory"); + } + + salt = malloc (saltlen); + if (!salt) + { + free (bufhex); + free (buf); + grub_util_error ("Out of memory"); + } + salthex = malloc (saltlen * 2 + 1); + if (!salthex) + { + free (salt); + free (bufhex); + free (buf); + grub_util_error ("Out of memory"); + } + + /* Disable echoing. Based on glibc. */ + in = fopen ("/dev/tty", "w+c"); + if (in == NULL) + { + in = stdin; + out = stderr; + } + else + out = in; + + if (tcgetattr (fileno (in), &t) == 0) + { + /* Save the old one. */ + s = t; + /* Tricky, tricky. */ + t.c_lflag &= ~(ECHO|ISIG); + tty_changed = (tcsetattr (fileno (in), TCSAFLUSH, &t) == 0); + } + else + tty_changed = 0; + + printf ("Enter password: "); + pass1 = NULL; + { + grub_size_t n; + nr = getline (&pass1, &n, stdin); + } + if (nr < 0 || !pass1) + { + free (buf); + free (bufhex); + free (salthex); + free (salt); + /* Restore the original setting. */ + if (tty_changed) + (void) tcsetattr (fileno (in), TCSAFLUSH, &s); + grub_util_error ("Failure to read password"); + } + if (nr >= 1 && pass1[nr-1] == '\n') + pass1[nr-1] = 0; + + printf ("\nReenter password: "); + pass2 = NULL; + { + grub_size_t n; + nr = getline (&pass2, &n, stdin); + } + /* Restore the original setting. */ + if (tty_changed) + (void) tcsetattr (fileno (in), TCSAFLUSH, &s); + printf ("\n"); + + if (nr < 0 || !pass2) + { + memset (pass1, 0, strlen (pass1)); + free (pass1); + free (buf); + free (bufhex); + free (salthex); + free (salt); + grub_util_error ("Failure to read password"); + } + if (nr >= 1 && pass2[nr-1] == '\n') + pass2[nr-1] = 0; + + if (strcmp (pass1, pass2) != 0) + { + memset (pass1, 0, strlen (pass1)); + memset (pass2, 0, strlen (pass2)); + free (pass1); + free (pass2); + free (buf); + free (bufhex); + free (salthex); + free (salt); + grub_util_error ("Passwords don't match"); + } + memset (pass2, 0, strlen (pass2)); + free (pass2); + +#if ! defined (__linux__) && ! defined (__FreeBSD__) + printf ("WARNING: your random generator isn't known to be secure\n"); +#endif + + { + FILE *f; + size_t rd; + f = fopen ("/dev/random", "rb"); + if (!f) + { + memset (pass1, 0, strlen (pass1)); + free (pass1); + free (buf); + free (bufhex); + free (salthex); + free (salt); + fclose (f); + grub_util_error ("Couldn't retrieve random data for salt"); + } + rd = fread (salt, 1, saltlen, f); + if (rd != saltlen) + { + fclose (f); + memset (pass1, 0, strlen (pass1)); + free (pass1); + free (buf); + free (bufhex); + free (salthex); + free (salt); + fclose (f); + grub_util_error ("Couldn't retrieve random data for salt"); + } + fclose (f); + } + + gcry_err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, + (grub_uint8_t *) pass1, strlen (pass1), + salt, saltlen, + c, buf, buflen); + memset (pass1, 0, strlen (pass1)); + free (pass1); + + if (gcry_err) + { + memset (buf, 0, buflen); + memset (bufhex, 0, 2 * buflen); + free (buf); + free (bufhex); + memset (salt, 0, saltlen); + memset (salthex, 0, 2 * saltlen); + free (salt); + free (salthex); + grub_util_error ("Cryptographic error number %d", gcry_err); + } + + hexify (bufhex, buf, buflen); + hexify (salthex, salt, saltlen); + + printf ("Your PBKDF2 is grub.pbkdf2.sha512.%d.%s.%s\n", c, salthex, bufhex); + memset (buf, 0, buflen); + memset (bufhex, 0, 2 * buflen); + free (buf); + free (bufhex); + memset (salt, 0, saltlen); + memset (salthex, 0, 2 * saltlen); + free (salt); + free (salthex); + + return 0; +} From 5edd456216b1d6f648f405ba8a065235f015997a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 Nov 2009 14:33:44 +0100 Subject: [PATCH 021/164] Remove leftover kern/crypto.c --- kern/crypto.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 kern/crypto.c diff --git a/kern/crypto.c b/kern/crypto.c deleted file mode 100644 index d097e1668..000000000 --- a/kern/crypto.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999, 2001, 2002, 2003, 2007, - * 2008, 2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ -#include -#include -#include - -gcry_cipher_spec_t *grub_ciphers = NULL; -gcry_md_spec_t *grub_digests = NULL; - -/* Based on libgcrypt-1.4.4/src/misc.c. */ -void -grub_burn_stack (grub_size_t size) -{ - char buf[64]; - - grub_memset (buf, 0, sizeof (buf)); - if (size > sizeof (buf)) - grub_burn_stack (size - sizeof (buf)); -} From 024478a2d8fba8fc6d26f61480058fc64de353fc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 Nov 2009 18:54:23 +0100 Subject: [PATCH 022/164] Fixed bug which causes some commands to be masked --- normal/dyncmd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/normal/dyncmd.c b/normal/dyncmd.c index 6e5028906..edaf614b8 100644 --- a/normal/dyncmd.c +++ b/normal/dyncmd.c @@ -78,14 +78,22 @@ read_command_list (void) if (file) { char *buf = NULL; + grub_command_t ptr, last = 0, next; /* Override previous commands.lst. */ - while (grub_command_list) + for (ptr = grub_command_list; ptr; ptr = next) { - grub_command_t tmp; - tmp = grub_command_list->next; - grub_free (grub_command_list); - grub_command_list = tmp; + next = ptr->next; + if (ptr->func == grub_dyncmd_dispatcher) + { + if (last) + last->next = ptr->next; + else + grub_command_list = ptr->next; + grub_free (ptr); + } + else + last = ptr; } for (;; grub_free (buf)) From f78821e5bc473ce99b2bba9b9ce38e17f9149e3d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 19 Nov 2009 23:10:40 +0100 Subject: [PATCH 023/164] Removed extraneous copyright line --- commands/password_pbkdf2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/commands/password_pbkdf2.c b/commands/password_pbkdf2.c index 44da0101e..38481f362 100644 --- a/commands/password_pbkdf2.c +++ b/commands/password_pbkdf2.c @@ -1,7 +1,6 @@ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. - * Copyright (C) 2009 Vladimir 'phcoder' Serbineko * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 242f0731c7805a94d79eade8cb0cf928a526839c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 20 Nov 2009 09:41:20 +0100 Subject: [PATCH 024/164] reimported savedefault by cjwatson and myself Also-By: Vladimir 'phcoder' Serbinenko --- ChangeLog.savedefault | 29 +++++++ conf/common.rmk | 14 ++++ normal/menu.c | 2 + normal/menu_text.c | 26 ++++++- util/grub-install.in | 5 ++ util/grub-mkconfig_lib.in | 8 ++ util/grub-reboot.in | 104 ++++++++++++++++++++++++++ util/grub-set-default.in | 99 ++++++++++++++++++++++++ util/grub.d/00_header.in | 8 ++ util/grub.d/10_hurd.in | 1 + util/grub.d/10_kfreebsd.in | 1 + util/grub.d/10_linux.in | 1 + util/grub.d/10_windows.in | 1 + util/grub.d/30_os-prober.in | 3 + util/i386/efi/grub-install.in | 5 ++ util/ieee1275/grub-install.in | 5 ++ util/sparc64/ieee1275/grub-install.in | 5 ++ 17 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 ChangeLog.savedefault create mode 100644 util/grub-reboot.in create mode 100644 util/grub-set-default.in diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault new file mode 100644 index 000000000..c18106bd5 --- /dev/null +++ b/ChangeLog.savedefault @@ -0,0 +1,29 @@ +2009-10-25 Vladimir Serbinenko +2009-10-25 Colin Watson + + * normal/menu.c (grub_menu_execute_entry): Save selected entry title + in `chosen' environment variable. + * normal/menu_text.c (get_entry_number): Check if the variable + matches the title of a menu entry. + (run_menu): Pass menu to get_entry_number. + + * util/grub-reboot.in: New file. + * util/grub-set-default.in: New file. + * conf/common.rmk (grub-reboot): New utility. + (grub-set-default): New utility. + + * util/grub-mkconfig_lib.in (save_default_entry): New function. + * util/grub.d/00_header.in: If GRUB_DEFAULT is `saved', set + default to `${saved_entry}'. If `${prev_saved_entry}' is non-empty, + move it to `saved_entry' for the next boot. Load environment on + initialisation. + * util/grub.d/10_kfreebsd.in: Call save_default_entry. + * util/grub.d/10_hurd.in: Likewise. + * util/grub.d/10_linux.in (linux_entry): Likewise. + * util/grub.d/10_windows.in: Likewise. + * util/grub.d/30_os-prober.in: Likewise. + + * util/grub-install.in: Create environment block. + * util/i386/efi/grub-install.in: Likewise. + * util/ieee1275/grub-install.in: Likewise. + * util/sparc64/ieee1275/grub-install.in: Likewise. diff --git a/conf/common.rmk b/conf/common.rmk index 173f24b62..881c72795 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -175,6 +175,20 @@ CLEANFILES += $(grub-mkconfig_SCRIPTS) grub-mkconfig_DATA += util/grub.d/README +# For grub-set-default. +grub-set-default: util/grub-set-default.in config.status + ./config.status --file=$@:$< + chmod +x $@ +sbin_SCRIPTS += grub-set-default +CLEANFILES += grub-set-default + +# For grub-reboot. +grub-reboot: util/grub-reboot.in config.status + ./config.status --file=$@:$< + chmod +x $@ +sbin_SCRIPTS += grub-reboot +CLEANFILES += grub-reboot + # Filing systems. pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ diff --git a/normal/menu.c b/normal/menu.c index 8ee7d1c22..b9f74b7d7 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -137,6 +137,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry) return; } + grub_env_set ("chosen", entry->title); + grub_parser_execute ((char *) entry->sourcecode); if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) diff --git a/normal/menu_text.c b/normal/menu_text.c index e0d96c47f..19f9cf756 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -237,7 +237,7 @@ grub_menu_init_page (int nested, int edit) /* Get the entry number from the variable NAME. */ static int -get_entry_number (const char *name) +get_entry_number (grub_menu_t menu, const char *name) { char *val; int entry; @@ -250,6 +250,28 @@ get_entry_number (const char *name) entry = (int) grub_strtoul (val, 0, 0); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + /* See if the variable matches the title of a menu entry. */ + grub_menu_entry_t e = menu->entry_list; + int i; + + grub_errno = GRUB_ERR_NONE; + + for (i = 0; e; i++) + { + if (grub_strcmp (e->title, val) == 0) + { + entry = i; + break; + } + e = e->next; + } + + if (! e) + entry = -1; + } + if (grub_errno != GRUB_ERR_NONE) { grub_errno = GRUB_ERR_NONE; @@ -291,7 +313,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) first = 0; - default_entry = get_entry_number ("default"); + default_entry = get_entry_number (menu, "default"); /* If DEFAULT_ENTRY is not within the menu entries, fall back to the first entry. */ diff --git a/util/grub-install.in b/util/grub-install.in index 356e161e7..1cf7135fd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -39,6 +39,7 @@ else fi grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -250,6 +251,10 @@ fi # Write device to a variable so we don't have to traverse /dev every time. grub_device=`$grub_probe --target=device ${grubdir}` +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device ${grub_device}` if test "x$fs_module" = x -a "x$modules" = x; then diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index bb30cc475..8cdd1d470 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -130,6 +130,14 @@ convert_system_path_to_grub_path () echo ${drive}${relative_path} } +save_default_entry () +{ + if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then + echo 'saved_entry=${chosen}' + echo 'save_env saved_entry' + fi +} + prepare_grub_to_access_device () { device=$1 diff --git a/util/grub-reboot.in b/util/grub-reboot.in new file mode 100644 index 000000000..886d61770 --- /dev/null +++ b/util/grub-reboot.in @@ -0,0 +1,104 @@ +#! /bin/sh +# +# Set a default boot entry for GRUB, for the next boot only. +# Copyright (C) 2004,2009 Free Software Foundation, Inc. +# +# GRUB 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, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB 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 GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ + +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` +rootdir= + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --root-directory=*) + rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if test "x$entry" != x; then + echo "More than one entry?" 1>&2 + usage + exit 1 + fi + entry="${option}" ;; + esac +done + +if test "x$entry" = x; then + echo "entry not specified." 1>&2 + usage + exit 1 +fi + +# Initialize these directories here, since ROOTDIR was initialized. +case "$host_os" in +netbsd* | openbsd*) + # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub + # instead of /boot/grub. + grub_prefix=`echo /grub | sed ${transform}` + bootdir=${rootdir} + ;; +*) + # Use /boot/grub by default. + bootdir=${rootdir}/boot + ;; +esac + +grubdir=${bootdir}/`echo grub | sed ${transform}` + +prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'` +if [ "$prev_saved_entry" ]; then + $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry" +else + $grub_editenv ${grubdir}/grubenv unset prev_saved_entry +fi +$grub_editenv ${grubdir}/grubenv set saved_entry="$entry" + +# Bye. +exit 0 diff --git a/util/grub-set-default.in b/util/grub-set-default.in new file mode 100644 index 000000000..6663d3fbd --- /dev/null +++ b/util/grub-set-default.in @@ -0,0 +1,99 @@ +#! /bin/sh +# +# Set a default boot entry for GRUB. +# Copyright (C) 2004,2009 Free Software Foundation, Inc. +# +# GRUB 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, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB 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 GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ + +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` +rootdir= + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --root-directory=*) + rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if test "x$entry" != x; then + echo "More than one entry?" 1>&2 + usage + exit 1 + fi + entry="${option}" ;; + esac +done + +if test "x$entry" = x; then + echo "entry not specified." 1>&2 + usage + exit 1 +fi + +# Initialize these directories here, since ROOTDIR was initialized. +case "$host_os" in +netbsd* | openbsd*) + # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub + # instead of /boot/grub. + grub_prefix=`echo /grub | sed ${transform}` + bootdir=${rootdir} + ;; +*) + # Use /boot/grub by default. + bootdir=${rootdir}/boot + ;; +esac + +grubdir=${bootdir}/`echo grub | sed ${transform}` + +$grub_editenv ${grubdir}/grubenv unset prev_saved_entry +$grub_editenv ${grubdir}/grubenv set saved_entry="$entry" + +# Bye. +exit 0 diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 9f421dc1c..7279469b7 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -32,11 +32,19 @@ for i in ${GRUB_PRELOAD_MODULES} ; do done if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi +if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF +load_env set default=${GRUB_DEFAULT} +if [ \${prev_saved_entry} ]; then + saved_entry=\${prev_saved_entry} + save_env saved_entry + prev_saved_entry= + save_env prev_saved_entry +fi EOF case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index e693c7dfa..c1871e07a 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -75,6 +75,7 @@ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} EOF +save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" cat << EOF module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index c6712e32f..026f1d7ac 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -39,6 +39,7 @@ kfreebsd_entry () args="$4" # not used yet title="$(gettext "%s, with kFreeBSD %s")" printf "menuentry \"${title}\" {" ${os} ${version} + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 8803055cf..dc9696ec8 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -59,6 +59,7 @@ linux_entry () title="$(gettext "%s, with Linux %s")" fi printf "menuentry \"${title}\" {" ${os} ${version} + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in index 055258e29..35dd4a4cc 100644 --- a/util/grub.d/10_windows.in +++ b/util/grub.d/10_windows.in @@ -73,6 +73,7 @@ for dir in $dirlist ; do menuentry "$OS" { EOF + save_default_entry | sed -e 's,^,\t,' prepare_grub_to_access_device "$dev" | sed 's,^,\t,' cat << EOF diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index c5728866c..103785ed9 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -55,6 +55,7 @@ for OS in ${OSPROBED} ; do cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" case ${LONGNAME} in @@ -113,6 +114,8 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF insmod vbe diff --git a/util/i386/efi/grub-install.in b/util/i386/efi/grub-install.in index a5f97e346..e597c4eee 100644 --- a/util/i386/efi/grub-install.in +++ b/util/i386/efi/grub-install.in @@ -34,6 +34,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -178,6 +179,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}` if test "x$fs_module" = xfat; then :; else diff --git a/util/ieee1275/grub-install.in b/util/ieee1275/grub-install.in index 710ed125b..9a26b0dca 100644 --- a/util/ieee1275/grub-install.in +++ b/util/ieee1275/grub-install.in @@ -37,6 +37,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -163,6 +164,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Create the core image. First, auto-detect the filesystem module. fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}` if test "x$fs_module" = x -a "x$modules" = x; then diff --git a/util/sparc64/ieee1275/grub-install.in b/util/sparc64/ieee1275/grub-install.in index a03869cb3..f49157acd 100644 --- a/util/sparc64/ieee1275/grub-install.in +++ b/util/sparc64/ieee1275/grub-install.in @@ -38,6 +38,7 @@ grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules= @@ -206,6 +207,10 @@ for file in ${pkglibdir}/*.img; do cp -f $file ${grubdir} || exit 1 done +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Write device to a variable so we don't have to traverse /dev every time. grub_device=`$grub_probe --target=device ${grubdir}` From 6e3ac954910d28d291b94c0fafb78337ba680bd1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:23:43 +0100 Subject: [PATCH 025/164] Fixed warning --- video/video.c | 1 - 1 file changed, 1 deletion(-) diff --git a/video/video.c b/video/video.c index eff257122..2e17ee7dc 100644 --- a/video/video.c +++ b/video/video.c @@ -624,7 +624,6 @@ grub_video_set_mode (const char *modestring, /* Loop thru all possible video adapter trying to find requested mode. */ for (p = grub_video_adapter_list; p; p = p->next) { - grub_err_t err; struct grub_video_mode_info mode_info; grub_memset (&mode_info, 0, sizeof (mode_info)); From d3d0094e17c628523fa51e7a4dcaa3fb0b596298 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 20 Nov 2009 13:29:17 +0100 Subject: [PATCH 026/164] ChangeLog --- ChangeLog.videomask | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ChangeLog.videomask diff --git a/ChangeLog.videomask b/ChangeLog.videomask new file mode 100644 index 000000000..7c58d0b57 --- /dev/null +++ b/ChangeLog.videomask @@ -0,0 +1,10 @@ +2009-11-20 Vladimir Serbinenko + + Use flag-based instead of hook-based video mode selection and "auto" + keyword. + + * include/grub/video.h (grub_video_adapter): Changed 'setup' member. + (grub_video_set_mode): Changed prototype. All users updated. + (grub_video_check_mode_flag): New inline function. + * video/video.c (parse_modespec): New function. + (grub_video_set_mode): Parse flags and keywords. From a261f807286581cbc86b08fa8141cc617bc6b842 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 26 Nov 2009 17:14:39 +0100 Subject: [PATCH 027/164] Added origin notice to lib/pbkdf2.c --- lib/pbkdf2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pbkdf2.c b/lib/pbkdf2.c index f2d3ca97f..083446ab9 100644 --- a/lib/pbkdf2.c +++ b/lib/pbkdf2.c @@ -16,6 +16,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Simon Josefsson. */ +/* Imported from gnulib. */ #include #include From 84c6b0863ff40de102f9f0845136d1964ad94f43 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 26 Nov 2009 17:34:22 +0100 Subject: [PATCH 028/164] renamed grub-pbkdf2 into grub-mkpasswd-pbkdf2 --- conf/common.rmk | 4 ++-- util/{grub-pbkdf2.c => grub-mkpasswd-pbkdf2.c} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename util/{grub-pbkdf2.c => grub-mkpasswd-pbkdf2.c} (99%) diff --git a/conf/common.rmk b/conf/common.rmk index 58b1d8a31..f680655ed 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -638,7 +638,7 @@ password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) -bin_UTILITIES += grub-pbkdf2 -grub_pbkdf2_SOURCES = util/grub-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c +bin_UTILITIES += grub-mkpasswd-pbkdf2 +grub_mkpasswd_pbkdf2_SOURCES = util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c include $(srcdir)/conf/gcry.mk diff --git a/util/grub-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c similarity index 99% rename from util/grub-pbkdf2.c rename to util/grub-mkpasswd-pbkdf2.c index a05fa62b1..ad52aae91 100644 --- a/util/grub-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -120,7 +120,7 @@ main (int argc, char *argv[]) struct termios s, t; int tty_changed; - progname = "grub-pbkdf2"; + progname = "grub-mkpasswd-pbkdf2"; /* Check for options. */ while (1) From 9d1fafb96e554d6246ae14b42887f3d9774458b5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 5 Dec 2009 16:33:39 +0100 Subject: [PATCH 029/164] Move include/grub/cipher_wrap.h to lib/libgcrypt_wrap/cipher_wrap.h --- conf/common.rmk | 1 + .../grub => lib/libgcrypt_wrap}/cipher_wrap.h | 0 util/import_gcry.py | 23 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) rename {include/grub => lib/libgcrypt_wrap}/cipher_wrap.h (100%) diff --git a/conf/common.rmk b/conf/common.rmk index f680655ed..376700be2 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -640,5 +640,6 @@ password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) bin_UTILITIES += grub-mkpasswd-pbkdf2 grub_mkpasswd_pbkdf2_SOURCES = util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c +grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap include $(srcdir)/conf/gcry.mk diff --git a/include/grub/cipher_wrap.h b/lib/libgcrypt_wrap/cipher_wrap.h similarity index 100% rename from include/grub/cipher_wrap.h rename to lib/libgcrypt_wrap/cipher_wrap.h diff --git a/util/import_gcry.py b/util/import_gcry.py index b66de90cc..fe68c85a4 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -67,6 +67,12 @@ for cipher_file in cipher_files: if cipher_file == "ChangeLog": continue chlognew = " * %s" % cipher_file + if re.match ("(Manifest|Makefile\.am|ac\.c|cipher\.c|hash-common\.c|hmac-tests\.c|md\.c|pubkey\.c)$", cipher_file): + chlog = "%s%s: Removed\n" % (chlog, chlognew) + continue + # Autogenerated files. Not even worth mentionning in ChangeLog + if re.match ("Makefile\.in$", cipher_file): + continue nch = False if re.match (".*\.[ch]$", cipher_file): isc = re.match (".*\.c$", cipher_file) @@ -220,7 +226,7 @@ for cipher_file in cipher_files: conf.write ("pkglib_MODULES += %s.mod\n" % modname) conf.write ("%s_mod_SOURCES = %s\n" %\ (modname, modfiles)) - conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error\n" % modname) + conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap\n" % modname) conf.write ("%s_mod_LDFLAGS = $(COMMON_LDFLAGS)\n\n" % modname) elif isc and cipher_file != "camellia.c": print ("WARNING: C file isn't a module: %s" % cipher_file) @@ -229,26 +235,19 @@ for cipher_file in cipher_files: if nch: chlog = "%s%s\n" % (chlog, chlognew) continue - if re.match ("(Manifest|Makefile\.am)$", cipher_file): - chlog = "%s%sRemoved\n" % (chlog, chlognew) - continue - # Autogenerated files. Not even worth mentionning in ChangeLog - if re.match ("Makefile\.in$", cipher_file): - chlog = "%s%sRemoved\n" % (chlog, chlognew) - continue chlog = "%s%sSkipped unknown file\n" % (chlog, chlognew) print ("WARNING: unknown file %s" % cipher_file) outfile = os.path.join (cipher_dir_out, "types.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * types.h: New file.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "memory.h") fw=open (outfile, "w") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * memory.h: New file.\n" % chlog fw.close () @@ -256,13 +255,13 @@ fw.close () outfile = os.path.join (cipher_dir_out, "cipher.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * cipher.h: Likewise.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "g10lib.h") fw=open (outfile, "w") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * g10lib.h: Likewise.\n" % chlog fw.close () From fd39f820fdbd4fdb9d82cdc6befecdd25904709a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 5 Dec 2009 18:59:36 +0100 Subject: [PATCH 030/164] fix mismerge with trunk (progname) --- conf/common.rmk | 2 +- util/grub-mkpasswd-pbkdf2.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/conf/common.rmk b/conf/common.rmk index 395d6b17b..0c6fb0cae 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -650,7 +650,7 @@ password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) bin_UTILITIES += grub-mkpasswd-pbkdf2 -grub_mkpasswd_pbkdf2_SOURCES = util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c +grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap include $(srcdir)/conf/gcry.mk diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index ad52aae91..2f7c5efaa 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,7 @@ #include #include +#include "progname.h" /* Few functions to make crypto happy. */ void * @@ -120,7 +122,10 @@ main (int argc, char *argv[]) struct termios s, t; int tty_changed; - progname = "grub-mkpasswd-pbkdf2"; + set_program_name (argv[0]); + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); /* Check for options. */ while (1) @@ -149,7 +154,7 @@ main (int argc, char *argv[]) return 0; case 'V': - printf ("%s (%s) %s\n", progname, + printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); return 0; From c0a6bd447e6d551df5dc27128ad539f00abf7e39 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 5 Dec 2009 20:45:32 +0100 Subject: [PATCH 031/164] fix *-emu build --- conf/any-emu.rmk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 9038b07df..cf13d2b67 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -45,7 +45,10 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ disk/raid.c disk/raid5_recover.c disk/raid6_recover.c \ disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \ commands/parttool.c parttool/msdospart.c \ + lib/libgcrypt-grub/cipher/md5.c \ grub_emu_init.c gnulib/progname.c +grub_emu_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap + ifeq ($(target_cpu), i386) grub_emu_SOURCES += commands/i386/cpuid.c From b391bdb2f2c5ccf29da66cecdbfb7566656a704d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 6 Dec 2009 20:11:50 +0100 Subject: [PATCH 032/164] Use dedicated simple password retriever for size of future crypto disks modules and simplify entering passwords routines --- commands/password.c | 19 +++++----------- commands/password_pbkdf2.c | 11 +++------ conf/common.rmk | 2 +- include/grub/auth.h | 9 +++----- include/grub/crypto.h | 10 ++++++--- lib/crypto.c | 46 ++++++++++++++++++++++++++++++++++++-- normal/auth.c | 20 +++++++---------- 7 files changed, 71 insertions(+), 46 deletions(-) diff --git a/commands/password.c b/commands/password.c index 99b993839..7bb2f0ae5 100644 --- a/commands/password.c +++ b/commands/password.c @@ -27,20 +27,11 @@ static grub_dl_t my_mod; -#define MAX_PASSLEN 1024 - static grub_err_t -check_password (const char *user, +check_password (const char *user, const char *entered, void *password) { - char entered[MAX_PASSLEN]; - - grub_memset (entered, 0, sizeof (entered)); - - if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1)) - return GRUB_ACCESS_DENIED; - - if (grub_crypto_memcmp (entered, password, MAX_PASSLEN) != 0) + if (grub_crypto_memcmp (entered, password, GRUB_AUTH_MAX_PASSLEN) != 0) return GRUB_ACCESS_DENIED; grub_auth_authenticate (user); @@ -59,12 +50,12 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), if (argc != 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two arguments expected."); - pass = grub_zalloc (MAX_PASSLEN); + pass = grub_zalloc (GRUB_AUTH_MAX_PASSLEN); if (!pass) return grub_errno; copylen = grub_strlen (args[1]); - if (copylen >= MAX_PASSLEN) - copylen = MAX_PASSLEN - 1; + if (copylen >= GRUB_AUTH_MAX_PASSLEN) + copylen = GRUB_AUTH_MAX_PASSLEN - 1; grub_memcpy (pass, args[1], copylen); err = grub_auth_register_authentication (args[0], check_password, pass); diff --git a/commands/password_pbkdf2.c b/commands/password_pbkdf2.c index 38481f362..51c8ea794 100644 --- a/commands/password_pbkdf2.c +++ b/commands/password_pbkdf2.c @@ -16,6 +16,7 @@ * along with GRUB. If not, see . */ +#include #include #include #include @@ -36,23 +37,17 @@ struct pbkdf2_password }; static grub_err_t -check_password (const char *user, void *pin) +check_password (const char *user, const char *entered, void *pin) { - char entered[1024]; grub_uint8_t *buf; struct pbkdf2_password *pass = pin; gcry_err_code_t err; - grub_memset (entered, 0, sizeof (entered)); - - if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1)) - return GRUB_ACCESS_DENIED; - buf = grub_malloc (pass->buflen); if (!buf) return grub_crypto_gcry_error (GPG_ERR_OUT_OF_MEMORY); - err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, (grub_uint8_t *) &entered, + err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, (grub_uint8_t *) entered, grub_strlen (entered), pass->salt, pass->saltlen, pass->c, buf, pass->buflen); diff --git a/conf/common.rmk b/conf/common.rmk index 0c6fb0cae..ad0e4942c 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -651,6 +651,6 @@ password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) bin_UTILITIES += grub-mkpasswd-pbkdf2 grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c -grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap +grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 include $(srcdir)/conf/gcry.mk diff --git a/include/grub/auth.h b/include/grub/auth.h index e72d984ae..747334451 100644 --- a/include/grub/auth.h +++ b/include/grub/auth.h @@ -19,14 +19,11 @@ #define GRUB_AUTH_HEADER 1 #include +#include -/* Macros for indistinguishibility. */ -#define GRUB_ACCESS_DENIED grub_error (GRUB_ERR_ACCESS_DENIED, "Access denied.") -#define GRUB_GET_PASSWORD(string, len) grub_cmdline_get ("Enter password: ", \ - string, len, \ - '*', 0, 0) +#define GRUB_AUTH_MAX_PASSLEN 1024 -typedef grub_err_t (*grub_auth_callback_t) (const char*, void *); +typedef grub_err_t (*grub_auth_callback_t) (const char *, const char *, void *); grub_err_t grub_auth_register_authentication (const char *user, grub_auth_callback_t callback, diff --git a/include/grub/crypto.h b/include/grub/crypto.h index eb1898fe4..3129131cb 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -26,8 +26,6 @@ #include #include #include -/* For GRUB_ACCESS_DENIED. */ -#include typedef enum { @@ -264,6 +262,12 @@ grub_crypto_pbkdf2 (const struct gcry_md_spec *md, grub_uint8_t *DK, grub_size_t dkLen); int -grub_crypto_memcmp (void *a, void *b, grub_size_t n); +grub_crypto_memcmp (const void *a, const void *b, grub_size_t n); + +int +grub_password_get (char buf[], unsigned buf_size); + +/* For indistinguishibility. */ +#define GRUB_ACCESS_DENIED grub_error (GRUB_ERR_ACCESS_DENIED, "Access denied.") #endif diff --git a/lib/crypto.c b/lib/crypto.c index 4b36dde6f..06104bd4d 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -20,6 +20,7 @@ #include #include #include +#include struct grub_crypto_hmac_handle { @@ -372,10 +373,10 @@ grub_crypto_gcry_error (gcry_err_code_t in) } int -grub_crypto_memcmp (void *a, void *b, grub_size_t n) +grub_crypto_memcmp (const void *a, const void *b, grub_size_t n) { register grub_size_t counter = 0; - grub_uint8_t *pa, *pb; + const grub_uint8_t *pa, *pb; for (pa = a, pb = b; n; pa++, pb++, n--) { @@ -385,3 +386,44 @@ grub_crypto_memcmp (void *a, void *b, grub_size_t n) return !!counter; } + +#ifndef GRUB_MKPASSWD +int +grub_password_get (char buf[], unsigned buf_size) +{ + unsigned cur_len = 0; + int key; + + while (1) + { + key = GRUB_TERM_ASCII_CHAR (grub_getkey ()); + if (key == '\n' || key == '\r') + break; + + if (key == '\e') + { + cur_len = 0; + break; + } + + if (key == '\b') + { + cur_len--; + continue; + } + + if (!grub_isprint (key)) + continue; + + if (cur_len + 2 < buf_size) + buf[cur_len++] = key; + } + + grub_memset (buf + cur_len, 0, buf_size - cur_len); + + grub_putchar ('\n'); + grub_refresh (); + + return (key != '\e'); +} +#endif diff --git a/normal/auth.c b/normal/auth.c index 0a8b5bc82..d679fcc35 100644 --- a/normal/auth.c +++ b/normal/auth.c @@ -160,6 +160,7 @@ grub_auth_check_authentication (const char *userlist) struct grub_auth_user *cur = NULL; grub_err_t err; static unsigned long punishment_delay = 1; + char entered[GRUB_AUTH_MAX_PASSLEN]; auto int hook (grub_list_t item); int hook (grub_list_t item) @@ -189,22 +190,17 @@ grub_auth_check_authentication (const char *userlist) 0, 0, 0)) goto access_denied; + grub_printf ("Enter password: "); + + if (!grub_password_get (entered, GRUB_AUTH_MAX_PASSLEN)) + goto access_denied; + grub_list_iterate (GRUB_AS_LIST (users), hook); if (!cur || ! cur->callback) - { - grub_list_iterate (GRUB_AS_LIST (users), hook_any); + goto access_denied; - /* No users present at all. */ - if (!cur) - goto access_denied; - - /* Display any of available authentication schemes. */ - err = cur->callback (login, 0); - - goto access_denied; - } - err = cur->callback (login, cur->arg); + err = cur->callback (login, entered, cur->arg); if (is_authenticated (userlist)) { punishment_delay = 1; From b824145a8f2f6435a62b6d127536078f6d3e136c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:56:39 +0000 Subject: [PATCH 033/164] 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Fix merge error that moved a `save_default_entry' call from the macosx case to the linux case. --- ChangeLog.savedefault | 5 +++++ util/grub.d/30_os-prober.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index c18106bd5..0810274a3 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/30_os-prober.in: Fix merge error that moved a + `save_default_entry' call from the macosx case to the linux case. + 2009-10-25 Vladimir Serbinenko 2009-10-25 Colin Watson diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index 0e71096d1..f4a37d5f5 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -97,6 +97,7 @@ EOF cat << EOF menuentry "${LLABEL} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")" fi @@ -119,7 +120,6 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF - save_default_entry | sed -e "s/^/\t/" save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF From 36cd6dd151db7b033fb3d0fd055f8c7d83feb928 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:57:46 +0000 Subject: [PATCH 034/164] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Quote the value assigned to `default', in case it contains spaces. --- ChangeLog.savedefault | 5 +++++ util/grub.d/00_header.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 0810274a3..6f885a73f 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Quote the value assigned to `default', + in case it contains spaces. + 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Fix merge error that moved a diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 577a12722..e8c3a14c4 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -40,7 +40,7 @@ if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF load_env -set default=${GRUB_DEFAULT} +set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then saved_entry=\${prev_saved_entry} save_env saved_entry From 42356b4d5e1ee06d9189b4b4001215585c62dc8a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 00:59:26 +0000 Subject: [PATCH 035/164] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Silently ignore zero-sized environment blocks. --- ChangeLog.savedefault | 5 +++++ util/grub.d/00_header.in | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 6f885a73f..cdeb05a87 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Silently ignore zero-sized environment + blocks. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Quote the value assigned to `default', diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index e8c3a14c4..2bcfe1d25 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -39,7 +39,9 @@ if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF -load_env +if [ -s \$prefix/grubenv ]; then + load_env +fi set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then saved_entry=\${prev_saved_entry} From 47075ea3c749f0d4ed082f7748387abc7f8a0717 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:00:26 +0000 Subject: [PATCH 036/164] 2009-12-08 Colin Watson * util/grub-reboot.in: Fix --version output. * util/grub-set-default.in: Likewise. --- ChangeLog.savedefault | 5 +++++ util/grub-reboot.in | 2 +- util/grub-set-default.in | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index cdeb05a87..55500a67c 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,8 @@ +2009-12-08 Colin Watson + + * util/grub-reboot.in: Fix --version output. + * util/grub-set-default.in: Likewise. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Silently ignore zero-sized environment diff --git a/util/grub-reboot.in b/util/grub-reboot.in index 886d61770..16abdf6f4 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -51,7 +51,7 @@ for option in "$@"; do usage exit 0 ;; -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + echo "grub-reboot (GNU GRUB ${PACKAGE_VERSION})" exit 0 ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; diff --git a/util/grub-set-default.in b/util/grub-set-default.in index 6663d3fbd..4d7c10e8e 100644 --- a/util/grub-set-default.in +++ b/util/grub-set-default.in @@ -51,7 +51,7 @@ for option in "$@"; do usage exit 0 ;; -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + echo "grub-set-default (GNU GRUB ${PACKAGE_VERSION})" exit 0 ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; From b967a04d5b398fcbe5e3a157432f8559ca41b087 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:01:21 +0000 Subject: [PATCH 037/164] 2009-12-08 Colin Watson * util/grub.d/00_header.in: Use `set var=val' rather than plain `var=val'. * util/grub-mkconfig_lib.in (save_default_entry): Likewise. --- ChangeLog.savedefault | 6 ++++++ util/grub-mkconfig_lib.in | 2 +- util/grub.d/00_header.in | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 55500a67c..25811c79b 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,9 @@ +2009-12-08 Colin Watson + + * util/grub.d/00_header.in: Use `set var=val' rather than plain + `var=val'. + * util/grub-mkconfig_lib.in (save_default_entry): Likewise. + 2009-12-08 Colin Watson * util/grub-reboot.in: Fix --version output. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index d18002ce4..95fd02ad9 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -93,7 +93,7 @@ convert_system_path_to_grub_path () save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then - echo 'saved_entry=${chosen}' + echo 'set saved_entry=${chosen}' echo 'save_env saved_entry' fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 2bcfe1d25..4cd8fd30c 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -44,9 +44,9 @@ if [ -s \$prefix/grubenv ]; then fi set default="${GRUB_DEFAULT}" if [ \${prev_saved_entry} ]; then - saved_entry=\${prev_saved_entry} + set saved_entry=\${prev_saved_entry} save_env saved_entry - prev_saved_entry= + set prev_saved_entry= save_env prev_saved_entry fi EOF From 6c1f8c1215b57cf404d103003d0becc74dbeed10 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Dec 2009 01:02:08 +0000 Subject: [PATCH 038/164] 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. --- ChangeLog.savedefault | 4 ++++ util/grub.d/30_os-prober.in | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 25811c79b..7457c3f71 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,7 @@ +2009-12-08 Colin Watson + + * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. + 2009-12-08 Colin Watson * util/grub.d/00_header.in: Use `set var=val' rather than plain diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index f4a37d5f5..b91838782 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -170,6 +170,7 @@ EOF cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF + save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" grub_device="`${grub_probe} --device ${DEVICE} --target=drive`" mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`" From e6d8d32a946e7d8fefda8b3e55a8810b5b1039ae Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 16 Dec 2009 19:03:56 +0100 Subject: [PATCH 039/164] fix efi video drivers for video API change --- video/efi_gop.c | 2 +- video/efi_uga.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/video/efi_gop.c b/video/efi_gop.c index e2eb2f7ae..3143135d6 100644 --- a/video/efi_gop.c +++ b/video/efi_gop.c @@ -185,7 +185,7 @@ grub_video_gop_fill_mode_info (struct grub_efi_gop_mode_info *in, static grub_err_t grub_video_gop_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) { unsigned int depth; struct grub_efi_gop_mode_info *info = NULL; diff --git a/video/efi_uga.c b/video/efi_uga.c index 9bca64306..1fe0aa500 100644 --- a/video/efi_uga.c +++ b/video/efi_uga.c @@ -198,7 +198,7 @@ grub_video_uga_fini (void) static grub_err_t grub_video_uga_setup (unsigned int width, unsigned int height, - unsigned int mode_type) + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) { unsigned int depth; int found = 0; From 7316783f35a1c210007951d74f959e003088da8e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Dec 2009 17:33:35 +0100 Subject: [PATCH 040/164] Crypto module autoloading --- Makefile.in | 5 +- conf/any-emu.rmk | 2 +- conf/common.rmk | 2 +- include/grub/crypto.h | 2 + include/grub/normal.h | 2 + lib/crypto.c | 46 +++++++++---- normal/crypto.c | 153 ++++++++++++++++++++++++++++++++++++++++++ normal/main.c | 1 + util/import_gcry.py | 38 +++++++++-- 9 files changed, 230 insertions(+), 21 deletions(-) create mode 100644 normal/crypto.c diff --git a/Makefile.in b/Makefile.in index 46b380cd5..b28b660da 100644 --- a/Makefile.in +++ b/Makefile.in @@ -169,7 +169,7 @@ endif ### General targets. CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo -pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst +pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk cat $(DEFSYMFILES) /dev/null \ | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \ @@ -193,6 +193,9 @@ parttool.lst: $(PARTTOOLFILES) video.lst: $(VIDEOFILES) cat $^ /dev/null | sort | uniq > $@ +crypto.lst: lib/libgcrypt-grub/cipher/crypto.lst + cp $^ $@ + ifneq (true, $(MAKEINFO)) info_INFOS += docs/grub.info endif diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 451ab3393..a3b3c84d9 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -27,7 +27,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ - normal/menu_text.c \ + normal/menu_text.c normal/crypto.c \ script/main.c script/execute.c script/function.c \ script/lexer.c script/script.c grub_script.tab.c \ partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \ diff --git a/conf/common.rmk b/conf/common.rmk index 81372d20c..64be988b9 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -543,7 +543,7 @@ normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \ normal/auth.c normal/autofs.c normal/handler.c \ normal/color.c normal/completion.c normal/datetime.c normal/menu.c \ normal/menu_entry.c normal/menu_text.c normal/menu_viewer.c \ - normal/misc.c + normal/misc.c normal/crypto.c normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 3129131cb..48b52ee65 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -270,4 +270,6 @@ grub_password_get (char buf[], unsigned buf_size); /* For indistinguishibility. */ #define GRUB_ACCESS_DENIED grub_error (GRUB_ERR_ACCESS_DENIED, "Access denied.") +extern void (*grub_crypto_autoload_hook) (const char *name); + #endif diff --git a/include/grub/normal.h b/include/grub/normal.h index e55553de5..66b427bcb 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -95,6 +95,8 @@ void read_command_list (void); /* Defined in `autofs.c'. */ void read_fs_list (void); +void read_crypto_list (void); + #ifdef GRUB_UTIL void grub_normal_init (void); diff --git a/lib/crypto.c b/lib/crypto.c index 06104bd4d..021560d6c 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -32,6 +32,8 @@ struct grub_crypto_hmac_handle static gcry_cipher_spec_t *grub_ciphers = NULL; static gcry_md_spec_t *grub_digests = NULL; +void (*grub_crypto_autoload_hook) (const char *name) = NULL; + /* Based on libgcrypt-1.4.4/src/misc.c. */ void grub_burn_stack (grub_size_t size) @@ -91,28 +93,44 @@ const gcry_md_spec_t * grub_crypto_lookup_md_by_name (const char *name) { const gcry_md_spec_t *md; - for (md = grub_digests; md; md = md->next) - if (grub_strcasecmp (name, md->name) == 0) - return md; - return NULL; + int first = 1; + while (1) + { + for (md = grub_digests; md; md = md->next) + if (grub_strcasecmp (name, md->name) == 0) + return md; + if (grub_crypto_autoload_hook && first) + grub_crypto_autoload_hook (name); + else + return NULL; + first = 0; + } } const gcry_cipher_spec_t * grub_crypto_lookup_cipher_by_name (const char *name) { const gcry_cipher_spec_t *ciph; - for (ciph = grub_ciphers; ciph; ciph = ciph->next) + int first = 1; + while (1) { - const char **alias; - if (grub_strcasecmp (name, ciph->name) == 0) - return ciph; - if (!ciph->aliases) - continue; - for (alias = ciph->aliases; *alias; alias++) - if (grub_strcasecmp (name, *alias) == 0) - return ciph; + for (ciph = grub_ciphers; ciph; ciph = ciph->next) + { + const char **alias; + if (grub_strcasecmp (name, ciph->name) == 0) + return ciph; + if (!ciph->aliases) + continue; + for (alias = ciph->aliases; *alias; alias++) + if (grub_strcasecmp (name, *alias) == 0) + return ciph; + } + if (grub_crypto_autoload_hook && first) + grub_crypto_autoload_hook (name); + else + return NULL; + first = 0; } - return NULL; } diff --git a/normal/crypto.c b/normal/crypto.c new file mode 100644 index 000000000..67330272a --- /dev/null +++ b/normal/crypto.c @@ -0,0 +1,153 @@ +/* crypto.c - support crypto autoload */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +struct load_spec +{ + struct load_spec *next; + char *name; + char *modname; +}; + +struct load_spec *crypto_specs = NULL; + +static void +grub_crypto_autoload (const char *name) +{ + struct load_spec *cur; + grub_dl_t mod; + + for (cur = crypto_specs; cur; cur = cur->next) + if (grub_strcasecmp (name, cur->name) == 0) + { + mod = grub_dl_load (cur->modname); + if (mod) + grub_dl_ref (mod); + grub_errno = GRUB_ERR_NONE; + } +} + +static void +grub_crypto_spec_free (void) +{ + struct load_spec *cur, *next; + for (cur = crypto_specs; cur; cur = next) + { + next = cur->next; + grub_free (cur->name); + grub_free (cur->modname); + grub_free (cur); + } + crypto_specs = NULL; +} + + +/* Read the file crypto.lst for auto-loading. */ +void +read_crypto_list (void) +{ + const char *prefix; + char *filename; + grub_file_t file; + char *buf = NULL; + + prefix = grub_env_get ("prefix"); + if (!prefix) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + filename = grub_malloc (grub_strlen (prefix) + sizeof ("/crypto.lst")); + if (!filename) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + grub_sprintf (filename, "%s/crypto.lst", prefix); + file = grub_file_open (filename); + if (!file) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + /* Override previous commands.lst. */ + grub_crypto_spec_free (); + + for (;; grub_free (buf)) + { + char *p, *name; + struct load_spec *cur; + + buf = grub_file_getline (file); + + if (! buf) + break; + + name = buf; + + p = grub_strchr (name, ':'); + if (! p) + continue; + + *p = '\0'; + while (*++p == ' ') + ; + + cur = grub_malloc (sizeof (*cur)); + if (!cur) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + + cur->name = grub_strdup (name); + if (! name) + { + grub_errno = GRUB_ERR_NONE; + grub_free (cur); + continue; + } + + cur->modname = grub_strdup (p); + if (! cur->modname) + { + grub_errno = GRUB_ERR_NONE; + grub_free (cur); + grub_free (cur->name); + continue; + } + cur->next = crypto_specs; + crypto_specs = cur; + } + + grub_file_close (file); + + grub_errno = GRUB_ERR_NONE; + + grub_crypto_autoload_hook = grub_crypto_autoload; +} diff --git a/normal/main.c b/normal/main.c index 3166ea146..189244aa0 100644 --- a/normal/main.c +++ b/normal/main.c @@ -428,6 +428,7 @@ grub_normal_execute (const char *config, int nested, int batch) read_command_list (); read_fs_list (); read_handler_list (); + read_crypto_list (); grub_command_execute ("parser.grub", 0, 0); reader_nested = nested; diff --git a/util/import_gcry.py b/util/import_gcry.py index fe68c85a4..93bf5982f 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -61,6 +61,18 @@ mdblocksizes = {"_gcry_digest_spec_crc32" : 64, "_gcry_digest_spec_tiger" : 64, "_gcry_digest_spec_whirlpool" : 64} +cryptolist = open (os.path.join (cipher_dir_out, "crypto.lst"), "w") + +# rijndael is the only cipher using aliases. So no need for mangling, just +# hardcode it +cryptolist.write ("RIJNDAEL: gcry_rijndael\n"); +cryptolist.write ("RIJNDAEL192: gcry_rijndael\n"); +cryptolist.write ("RIJNDAEL256: gcry_rijndael\n"); +cryptolist.write ("AES128: gcry_rijndael\n"); +cryptolist.write ("AES-128: gcry_rijndael\n"); +cryptolist.write ("AES-192: gcry_rijndael\n"); +cryptolist.write ("AES-256: gcry_rijndael\n"); + for cipher_file in cipher_files: infile = os.path.join (cipher_dir_in, cipher_file) outfile = os.path.join (cipher_dir_out, cipher_file) @@ -86,7 +98,15 @@ for cipher_file in cipher_files: skip = False skip2 = False ismd = False + iscryptostart = False iscomma = False + isglue = False + if isc: + modname = cipher_file [0:len(cipher_file) - 2] + if re.match (".*-glue$", modname): + modname = modname.replace ("-glue", "") + isglue = True + modname = "gcry_%s" % modname for line in f: if skip: if line[0] == "}": @@ -96,6 +116,12 @@ for cipher_file in cipher_files: if not re.search (" *};", line) is None: skip2 = False continue + if iscryptostart: + s = re.search (" *\"([A-Z0-9_a-z]*)\"", line) + if not s is None: + sg = s.groups()[0] + cryptolist.write (("%s: %s\n") % (sg, modname)) + iscryptostart = False if ismd: if not re.search (" *};", line) is None: if not mdblocksizes.has_key (mdname): @@ -133,16 +159,20 @@ for cipher_file in cipher_files: continue m = re.match ("gcry_cipher_spec_t", line) if isc and not m is None: + assert (not iscryptostart) ciphername = line [len ("gcry_cipher_spec_t"):].strip () ciphername = re.match("[a-zA-Z0-9_]*",ciphername).group () ciphernames.append (ciphername) + iscryptostart = True m = re.match ("gcry_md_spec_t", line) if isc and not m is None: assert (not ismd) + assert (not iscryptostart) mdname = line [len ("gcry_md_spec_t"):].strip () mdname = re.match("[a-zA-Z0-9_]*",mdname).group () mdnames.append (mdname) ismd = True + iscryptostart = True m = re.match ("static const char \*selftest.*;$", line) if not m is None: fname = line[len ("static const char \*"):] @@ -185,14 +215,11 @@ for cipher_file in cipher_files: continue fw.write (line) if len (ciphernames) > 0 or len (mdnames) > 0: - modname = cipher_file [0:len(cipher_file) - 2] - if re.match (".*-glue$", modname): + if isglue: modfiles = "lib/libgcrypt-grub/cipher/%s lib/libgcrypt-grub/cipher/%s" \ % (cipher_file, cipher_file.replace ("-glue.c", ".c")) - modname = modname.replace ("-glue", "") else: modfiles = "lib/libgcrypt-grub/cipher/%s" % cipher_file - modname = "gcry_%s" % modname chmsg = "(GRUB_MOD_INIT(%s)): New function\n" % modname if nch: chlognew = "%s\n %s" % (chlognew, chmsg) @@ -238,6 +265,9 @@ for cipher_file in cipher_files: chlog = "%s%sSkipped unknown file\n" % (chlog, chlognew) print ("WARNING: unknown file %s" % cipher_file) +cryptolist.close () +chlog = "%s * crypto.lst: New file.\n" % chlog + outfile = os.path.join (cipher_dir_out, "types.h") fw=open (outfile, "w") fw.write ("#include \n") From 0eb11149c98134432021ef067c0b4e64dcb91984 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Dec 2009 19:58:33 +0100 Subject: [PATCH 041/164] eliminate dead code and data in des.c --- util/import_gcry.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/util/import_gcry.py b/util/import_gcry.py index 93bf5982f..d71924d53 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -101,6 +101,7 @@ for cipher_file in cipher_files: iscryptostart = False iscomma = False isglue = False + skip_statement = False if isc: modname = cipher_file [0:len(cipher_file) - 2] if re.match (".*-glue$", modname): @@ -108,6 +109,10 @@ for cipher_file in cipher_files: isglue = True modname = "gcry_%s" % modname for line in f: + if skip_statement: + if not re.search (";", line) is None: + skip_statement = False + continue if skip: if line[0] == "}": skip = False @@ -132,10 +137,22 @@ for cipher_file in cipher_files: fw.write (" .blocksize = %s\n" % mdblocksizes [mdname]) ismd = False iscomma = not re.search (",$", line) is None + # Used only for selftests. + m = re.match ("(static byte|static unsigned char) (weak_keys_chksum)\[[0-9]*\] =", line) + if not m is None: + skip = True + fname = m.groups ()[1] + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue if hold: hold = False # We're optimising for size. - if not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None: + if not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer|tripledes_set2keys|do_tripledes_set_extra_info)", line) is None: skip = True fname = re.match ("[a-zA-Z0-9_]*", line).group () chmsg = "(%s): Removed." % fname @@ -184,11 +201,18 @@ for cipher_file in cipher_files: chlognew = "%s %s" % (chlognew, chmsg) nch = True continue - m = re.match ("(static const char( |)\*|static gpg_err_code_t|void)$", line) + m = re.match ("(static const char( |)\*|static gpg_err_code_t|void|static int|static gcry_err_code_t)$", line) if not m is None: hold = True holdline = line continue + m = re.match ("static int tripledes_set2keys \(.*\);", line) + if not m is None: + continue + m = re.match ("static int tripledes_set2keys \(", line) + if not m is None: + skip_statement = True + continue m = re.match ("cipher_extra_spec_t", line) if isc and not m is None: skip2 = True From a7a095c71ae9362e13bb0f38998fabd1398bba4d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Dec 2009 20:31:12 +0100 Subject: [PATCH 042/164] hashsum support --- commands/hashsum.c | 278 +++++++++++++++++++++++++++++++++++++++++++++ conf/common.rmk | 5 + 2 files changed, 283 insertions(+) create mode 100644 commands/hashsum.c diff --git a/commands/hashsum.c b/commands/hashsum.c new file mode 100644 index 000000000..60e17447b --- /dev/null +++ b/commands/hashsum.c @@ -0,0 +1,278 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct grub_arg_option options[] = { + {"hash", 'h', 0, "Specify hash to use.", "HASH", ARG_TYPE_STRING}, + {"check", 'c', 0, "Check hash list file.", "FILE", ARG_TYPE_STRING}, + {"prefix", 'p', 0, "Base directory for hash list.", "DIRECTORY", + ARG_TYPE_STRING}, + {"keep-going", 'k', 0, "Don't stop after first error.", 0, 0}, + {0, 0, 0, 0, 0, 0} +}; + +struct { const char *name; const char *hashname; } aliases[] = + { + {"sha256sum", "sha256"}, + {"sha512sum", "sha512"}, + {"md5sum", "md5"}, + }; + +static inline int +hextoval (char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + return -1; +} + +static grub_err_t +hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result) +{ + grub_uint8_t context[hash->contextsize]; + char *readbuf[4096]; + + grub_memset (context, 0, sizeof (context)); + hash->init (context); + while (1) + { + grub_ssize_t r; + r = grub_file_read (file, readbuf, sizeof (readbuf)); + if (r < 0) + return grub_errno; + if (r == 0) + break; + hash->write (context, readbuf, r); + } + hash->final (context); + grub_memcpy (result, hash->read (context), hash->mdlen); + + return GRUB_ERR_NONE; +} + +static grub_err_t +check_list (const gcry_md_spec_t *hash, const char *hashfilename, + const char *prefix, int keep) +{ + grub_file_t hashlist, file; + char *buf = NULL; + grub_uint8_t expected[hash->mdlen]; + grub_uint8_t actual[hash->mdlen]; + grub_err_t err; + unsigned i; + unsigned unread = 0, mismatch = 0; + + hashlist = grub_file_open (hashfilename); + if (!hashlist) + return grub_errno; + + while (grub_free (buf), (buf = grub_file_getline (hashlist))) + { + const char *p = buf; + for (i = 0; i < hash->mdlen; i++) + { + int high, low; + high = hextoval (*p++); + low = hextoval (*p++); + if (high < 0 || low < 0) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); + expected[i] = (high << 4) | low; + } + if (*p++ != ' ' || *p++ != ' ') + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list"); + if (prefix) + { + char *filename; + + filename = grub_malloc (grub_strlen (prefix) + + grub_strlen (p) + 2); + if (!filename) + return grub_errno; + grub_sprintf (filename, "%s/%s", prefix, p); + file = grub_file_open (filename); + grub_free (filename); + } + else + file = grub_file_open (p); + if (!file) + { + grub_file_close (hashlist); + grub_free (buf); + return grub_errno; + } + err = hash_file (file, hash, actual); + grub_file_close (file); + if (err) + { + grub_printf ("%s: READ ERROR\n", p); + if (!keep) + { + grub_file_close (hashlist); + grub_free (buf); + return err; + } + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + unread++; + continue; + } + if (grub_crypto_memcmp (expected, actual, hash->mdlen) != 0) + { + grub_printf ("%s: HASH MISMATCH\n", p); + if (!keep) + { + grub_file_close (hashlist); + grub_free (buf); + return grub_error (GRUB_ERR_TEST_FAILURE, + "hash of '%s' mismatches", p); + } + mismatch++; + continue; + } + grub_printf ("%s: OK\n", p); + } + if (mismatch || unread) + return grub_error (GRUB_ERR_TEST_FAILURE, + "%d files couldn't be read and hash " + "of %d files mismatches", unread, mismatch); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_hashsum (struct grub_extcmd *cmd, + int argc, char **args) +{ + struct grub_arg_list *state = cmd->state; + const char *hashname = NULL; + const char *prefix = NULL; + const gcry_md_spec_t *hash; + unsigned i; + int keep = state[3].set; + unsigned unread = 0; + + for (i = 0; i < ARRAY_SIZE (aliases); i++) + if (grub_strcmp (cmd->cmd->name, aliases[i].name) == 0) + hashname = aliases[i].hashname; + if (state[0].set) + hashname = state[0].arg; + + if (!hashname) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no hash specified"); + + hash = grub_crypto_lookup_md_by_name (hashname); + if (!hash) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown hash"); + + if (state[2].set) + prefix = state[2].arg; + + if (state[1].set) + { + if (argc != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "--check is incompatible with file list"); + return check_list (hash, state[1].arg, prefix, keep); + } + + for (i = 0; i < (unsigned) argc; i++) + { + grub_uint8_t result[hash->mdlen]; + grub_file_t file; + grub_err_t err; + unsigned j; + file = grub_file_open (args[i]); + if (!file) + { + if (!keep) + return grub_errno; + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + unread++; + continue; + } + err = hash_file (file, hash, result); + grub_file_close (file); + if (err) + { + if (!keep) + return err; + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + unread++; + continue; + } + for (j = 0; j < hash->mdlen; j++) + grub_printf ("%02x", result[j]); + grub_printf (" %s\n", args[i]); + } + + if (unread) + return grub_error (GRUB_ERR_TEST_FAILURE, "%d files couldn't be read.", + unread); + return GRUB_ERR_NONE; +} + +static grub_extcmd_t cmd, cmd_md5, cmd_sha256, cmd_sha512; + +GRUB_MOD_INIT(hashsum) +{ + cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum, + GRUB_COMMAND_FLAG_BOTH, + "hashsum -h HASH [-c FILE [-p PREFIX]] " + "[FILE1 [FILE2 ...]]", + "Compute or check hash checksum.", + options); + cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum, + GRUB_COMMAND_FLAG_BOTH, + "md5sum [-c FILE [-p PREFIX]] " + "[FILE1 [FILE2 ...]]", + "Compute or check hash checksum.", + options); + cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum, + GRUB_COMMAND_FLAG_BOTH, + "sha256sum [-c FILE [-p PREFIX]] " + "[FILE1 [FILE2 ...]]", + "Compute or check hash checksum.", + options); + cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum, + GRUB_COMMAND_FLAG_BOTH, + "sha512sum [-c FILE [-p PREFIX]] " + "[FILE1 [FILE2 ...]]", + "Compute or check hash checksum.", + options); +} + +GRUB_MOD_FINI(hashsum) +{ + grub_unregister_extcmd (cmd); + grub_unregister_extcmd (cmd_md5); + grub_unregister_extcmd (cmd_sha256); + grub_unregister_extcmd (cmd_sha512); +} diff --git a/conf/common.rmk b/conf/common.rmk index 64be988b9..271384d53 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -649,6 +649,11 @@ crypto_mod_SOURCES = lib/crypto.c crypto_mod_CFLAGS = $(COMMON_CFLAGS) crypto_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += hashsum.mod +hashsum_mod_SOURCES = commands/hashsum.c +hashsum_mod_CFLAGS = $(COMMON_CFLAGS) +hashsum_mod_LDFLAGS = $(COMMON_LDFLAGS) + pkglib_MODULES += pbkdf2.mod pbkdf2_mod_SOURCES = lib/pbkdf2.c pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) From f4c623e170d42b4f55172d52426251ef55c1ee66 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 00:37:11 +0100 Subject: [PATCH 043/164] Work on multi-out terminal --- commands/help.c | 26 ++- commands/sleep.c | 9 +- conf/any-emu.rmk | 2 +- conf/common.rmk | 2 +- include/grub/charset.h | 3 + include/grub/normal.h | 7 +- include/grub/parser.h | 1 + include/grub/reader.h | 52 +---- include/grub/term.h | 52 ++--- kern/main.c | 3 +- kern/misc.c | 13 +- kern/reader.c | 25 --- kern/rescue_reader.c | 36 ++-- kern/term.c | 209 +++++++----------- lib/charset.c | 64 ++++++ loader/i386/linux.c | 5 +- normal/cmdline.c | 477 +++++++++++++++++++++++------------------ normal/color.c | 47 ++-- normal/main.c | 112 ++++++---- normal/term.c | 128 +++++++++++ term/i386/pc/console.c | 4 - 21 files changed, 707 insertions(+), 570 deletions(-) create mode 100644 normal/term.c diff --git a/commands/help.c b/commands/help.c index c18ec6b83..4d16945af 100644 --- a/commands/help.c +++ b/commands/help.c @@ -37,18 +37,28 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)) { - char description[GRUB_TERM_WIDTH / 2]; + struct grub_term_output *cur; int desclen = grub_strlen (cmd->summary); + for (cur = grub_term_outputs; cur; cur = cur->next) + { + if (!(cur->flags & GRUB_TERM_ACTIVE)) + continue; + int width = grub_term_width(cur); + char description[width / 2]; /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled with the description followed by spaces. */ - grub_memset (description, ' ', GRUB_TERM_WIDTH / 2 - 1); - description[GRUB_TERM_WIDTH / 2 - 1] = '\0'; - grub_memcpy (description, cmd->summary, - (desclen < GRUB_TERM_WIDTH / 2 - 1 - ? desclen : GRUB_TERM_WIDTH / 2 - 1)); - - grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " "); + grub_memset (description, ' ', width / 2 - 1); + description[width / 2 - 1] = '\0'; + grub_memcpy (description, cmd->summary, + (desclen < width / 2 - 1 + ? desclen : width / 2 - 1)); + grub_puts_terminal (description, cur); + } + if ((cnt++) % 2) + grub_printf ("\n"); + else + grub_printf (" "); } return 0; } diff --git a/commands/sleep.c b/commands/sleep.c index 9207b60a7..aea7f2690 100644 --- a/commands/sleep.c +++ b/commands/sleep.c @@ -32,12 +32,12 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; -static grub_uint8_t x, y; +static grub_uint16_t *pos; static void do_print (int n) { - grub_gotoxy (x, y); + grub_term_restore_pos (pos); /* NOTE: Do not remove the trailing space characters. They are required to clear the line. */ grub_printf ("%d ", n); @@ -63,7 +63,6 @@ static grub_err_t grub_cmd_sleep (grub_extcmd_t cmd, int argc, char **args) { struct grub_arg_list *state = cmd->state; - grub_uint16_t xy; int n; if (argc != 1) @@ -77,9 +76,7 @@ grub_cmd_sleep (grub_extcmd_t cmd, int argc, char **args) return 0; } - xy = grub_getxy (); - x = xy >> 8; - y = xy & 0xff; + pos = grub_term_save_pos (); for (; n; n--) { diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index fb97de0a0..2c383f387 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -27,7 +27,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ normal/handler.c normal/auth.c normal/autofs.c \ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ - normal/menu_text.c \ + normal/menu_text.c normal/term.c \ script/main.c script/execute.c script/function.c \ script/lexer.c script/script.c grub_script.tab.c \ partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \ diff --git a/conf/common.rmk b/conf/common.rmk index 1ed30a404..02d57f0a3 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -543,7 +543,7 @@ normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \ normal/auth.c normal/autofs.c normal/handler.c \ normal/color.c normal/completion.c normal/datetime.c normal/menu.c \ normal/menu_entry.c normal/menu_text.c normal/menu_viewer.c \ - normal/misc.c + normal/misc.c normal/term.c normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/include/grub/charset.h b/include/grub/charset.h index f85862f8b..daaa5c99f 100644 --- a/include/grub/charset.h +++ b/include/grub/charset.h @@ -109,4 +109,7 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src, return dest; } +/* Convert UCS-4 to UTF-8. */ +char *grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size); + #endif diff --git a/include/grub/normal.h b/include/grub/normal.h index e55553de5..d629338e6 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -20,6 +20,7 @@ #ifndef GRUB_NORMAL_HEADER #define GRUB_NORMAL_HEADER 1 +#include #include #include #include @@ -50,7 +51,7 @@ extern struct grub_menu_viewer grub_normal_text_menu_viewer; /* Defined in `main.c'. */ void grub_enter_normal_mode (const char *config); void grub_normal_execute (const char *config, int nested, int batch); -void grub_normal_init_page (void); +void grub_normal_init_page (struct grub_term_output *term); void grub_menu_init_page (int nested, int edit); grub_err_t grub_normal_add_menu_entry (int argc, const char **args, const char *sourcecode); @@ -58,8 +59,7 @@ char *grub_file_getline (grub_file_t file); void grub_cmdline_run (int nested); /* Defined in `cmdline.c'. */ -int grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, - int echo_char, int readline, int history); +char *grub_cmdline_get (const char *prompt, unsigned max_len); grub_err_t grub_set_history (int newsize); /* Defined in `completion.c'. */ @@ -95,6 +95,7 @@ void read_command_list (void); /* Defined in `autofs.c'. */ void read_fs_list (void); +void grub_set_more (int onoff); #ifdef GRUB_UTIL void grub_normal_init (void); diff --git a/include/grub/parser.h b/include/grub/parser.h index 41f768bba..17f0c4303 100644 --- a/include/grub/parser.h +++ b/include/grub/parser.h @@ -22,6 +22,7 @@ #include #include +#include #include /* All the states for the command line. */ diff --git a/include/grub/reader.h b/include/grub/reader.h index c7e67bf5e..fd72a3252 100644 --- a/include/grub/reader.h +++ b/include/grub/reader.h @@ -20,60 +20,10 @@ #ifndef GRUB_READER_HEADER #define GRUB_READER_HEADER 1 -#include #include -#include typedef grub_err_t (*grub_reader_getline_t) (char **, int); -struct grub_reader -{ - /* The next reader. */ - struct grub_parser *next; - - /* The reader name. */ - const char *name; - - /* Initialize the reader. */ - grub_err_t (*init) (void); - - /* Clean up the reader. */ - grub_err_t (*fini) (void); - - grub_reader_getline_t read_line; -}; -typedef struct grub_reader *grub_reader_t; - -extern struct grub_handler_class EXPORT_VAR(grub_reader_class); - -grub_err_t EXPORT_FUNC(grub_reader_loop) (grub_reader_getline_t getline); - -static inline void -grub_reader_register (const char *name __attribute__ ((unused)), - grub_reader_t reader) -{ - grub_handler_register (&grub_reader_class, GRUB_AS_HANDLER (reader)); -} - -static inline void -grub_reader_unregister (grub_reader_t reader) -{ - grub_handler_unregister (&grub_reader_class, GRUB_AS_HANDLER (reader)); -} - -static inline grub_reader_t -grub_reader_get_current (void) -{ - return (grub_reader_t) grub_reader_class.cur_handler; -} - -static inline grub_err_t -grub_reader_set_current (grub_reader_t reader) -{ - return grub_handler_set_current (&grub_reader_class, - GRUB_AS_HANDLER (reader)); -} - -void grub_register_rescue_reader (void); +void grub_rescue_run (void); #endif /* ! GRUB_READER_HEADER */ diff --git a/include/grub/term.h b/include/grub/term.h index 316d75390..39a10ed71 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -68,6 +68,8 @@ grub_term_color_state; #define GRUB_TERM_NO_EDIT (1 << 1) /* Set when the terminal cannot do fancy things. */ #define GRUB_TERM_DUMB (1 << 2) +/* Terminal is used as general output. */ +#define GRUB_TERM_ACTIVE (1 << 3) /* Set when the terminal needs to be initialized. */ #define GRUB_TERM_NEED_INIT (1 << 16) @@ -93,10 +95,6 @@ grub_term_color_state; /* Menu-related geometrical constants. */ -/* FIXME: Ugly way to get them form terminal. */ -#define GRUB_TERM_WIDTH ((grub_getwh()&0xFF00)>>8) -#define GRUB_TERM_HEIGHT (grub_getwh()&0xFF) - /* The number of lines of "GRUB version..." at the top. */ #define GRUB_TERM_INFO_HEIGHT 1 @@ -225,7 +223,7 @@ struct grub_term_output typedef struct grub_term_output *grub_term_output_t; extern struct grub_handler_class EXPORT_VAR(grub_term_input_class); -extern struct grub_handler_class EXPORT_VAR(grub_term_output_class); +extern struct grub_term_output *EXPORT_VAR(grub_term_outputs); static inline void grub_term_register_input (const char *name __attribute__ ((unused)), @@ -238,7 +236,7 @@ static inline void grub_term_register_output (const char *name __attribute__ ((unused)), grub_term_output_t term) { - grub_handler_register (&grub_term_output_class, GRUB_AS_HANDLER (term)); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } static inline void @@ -250,7 +248,7 @@ grub_term_unregister_input (grub_term_input_t term) static inline void grub_term_unregister_output (grub_term_output_t term) { - grub_handler_unregister (&grub_term_output_class, GRUB_AS_HANDLER (term)); + grub_list_remove (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } static inline grub_err_t @@ -260,44 +258,34 @@ grub_term_set_current_input (grub_term_input_t term) GRUB_AS_HANDLER (term)); } -static inline grub_err_t -grub_term_set_current_output (grub_term_output_t term) -{ - return grub_handler_set_current (&grub_term_output_class, - GRUB_AS_HANDLER (term)); -} - static inline grub_term_input_t grub_term_get_current_input (void) { return (grub_term_input_t) grub_term_input_class.cur_handler; } -static inline grub_term_output_t -grub_term_get_current_output (void) -{ - return (grub_term_output_t) grub_term_output_class.cur_handler; -} - void EXPORT_FUNC(grub_putchar) (int c); -void EXPORT_FUNC(grub_putcode) (grub_uint32_t code); -grub_ssize_t EXPORT_FUNC(grub_getcharwidth) (grub_uint32_t code); +void EXPORT_FUNC(grub_putcode) (grub_uint32_t code, + struct grub_term_output *term); int EXPORT_FUNC(grub_getkey) (void); int EXPORT_FUNC(grub_checkkey) (void); int EXPORT_FUNC(grub_getkeystatus) (void); -grub_uint16_t EXPORT_FUNC(grub_getwh) (void); -grub_uint16_t EXPORT_FUNC(grub_getxy) (void); -void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y); void EXPORT_FUNC(grub_cls) (void); void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state); -void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color, - grub_uint8_t highlight_color); -void EXPORT_FUNC(grub_getcolor) (grub_uint8_t *normal_color, - grub_uint8_t *highlight_color); -int EXPORT_FUNC(grub_setcursor) (int on); -int EXPORT_FUNC(grub_getcursor) (void); void EXPORT_FUNC(grub_refresh) (void); -void EXPORT_FUNC(grub_set_more) (int onoff); +void grub_puts_terminal (const char *str, struct grub_term_output *term); +grub_uint16_t *grub_term_save_pos (void); +void grub_term_restore_pos (grub_uint16_t *pos); + +static inline int grub_term_width (struct grub_term_output *term) +{ + return ((term->getwh()&0xFF00)>>8); +} + +static inline int grub_term_height (struct grub_term_output *term) +{ + return (term->getwh()&0xFF); +} /* For convenience. */ #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff) diff --git a/kern/main.c b/kern/main.c index 9215d55e7..040f89e6d 100644 --- a/kern/main.c +++ b/kern/main.c @@ -169,9 +169,8 @@ grub_main (void) grub_register_core_commands (); grub_register_rescue_parser (); - grub_register_rescue_reader (); grub_load_config (); grub_load_normal_mode (); - grub_reader_loop (0); + grub_rescue_run (); } diff --git a/kern/misc.c b/kern/misc.c index f6d189e94..7dd9bd18a 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -968,15 +968,12 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, void grub_abort (void) { - if (grub_term_get_current_output ()) + grub_printf ("\nAborted."); + + if (grub_term_get_current_input ()) { - grub_printf ("\nAborted."); - - if (grub_term_get_current_input ()) - { - grub_printf (" Press any key to exit."); - grub_getkey (); - } + grub_printf (" Press any key to exit."); + grub_getkey (); } grub_exit (); diff --git a/kern/reader.c b/kern/reader.c index 271a90f5a..74698d34b 100644 --- a/kern/reader.c +++ b/kern/reader.c @@ -22,28 +22,3 @@ #include #include -struct grub_handler_class grub_reader_class = - { - .name = "reader" - }; - -grub_err_t -grub_reader_loop (grub_reader_getline_t getline) -{ - while (1) - { - char *line; - grub_reader_getline_t func; - - /* Print an error, if any. */ - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - - func = (getline) ? : grub_reader_get_current ()->read_line; - if ((func (&line, 0)) || (! line)) - return grub_errno; - - grub_parser_get_current ()->parse_line (line, func); - grub_free (line); - } -} diff --git a/kern/rescue_reader.c b/kern/rescue_reader.c index 2a06f3fc2..732124b1a 100644 --- a/kern/rescue_reader.c +++ b/kern/rescue_reader.c @@ -19,20 +19,15 @@ #include #include +#include #include #include +#include #define GRUB_RESCUE_BUF_SIZE 256 static char linebuf[GRUB_RESCUE_BUF_SIZE]; -static grub_err_t -grub_rescue_init (void) -{ - grub_printf ("Entering rescue mode...\n"); - return 0; -} - /* Prompt to input a command and read the line. */ static grub_err_t grub_rescue_read_line (char **line, int cont) @@ -74,15 +69,24 @@ grub_rescue_read_line (char **line, int cont) return 0; } -static struct grub_reader grub_rescue_reader = - { - .name = "rescue", - .init = grub_rescue_init, - .read_line = grub_rescue_read_line - }; - void -grub_register_rescue_reader (void) +grub_rescue_run (void) { - grub_reader_register ("rescue", &grub_rescue_reader); + grub_printf ("Entering rescue mode...\n"); + + while (1) + { + char *line; + + /* Print an error, if any. */ + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + + grub_rescue_read_line (&line, 0); + if (! line) + continue; + + grub_parser_get_current ()->parse_line (line, grub_rescue_read_line); + grub_free (line); + } } diff --git a/kern/term.c b/kern/term.c index 94d5a9e1d..35660273e 100644 --- a/kern/term.c +++ b/kern/term.c @@ -22,78 +22,35 @@ #include #include -/* The amount of lines counted by the pager. */ -static int grub_more_lines; - -/* If the more pager is active. */ -static int grub_more; - -/* The current cursor state. */ -static int cursor_state = 1; - struct grub_handler_class grub_term_input_class = { .name = "terminal_input" }; -struct grub_handler_class grub_term_output_class = - { - .name = "terminal_output" - }; - #define grub_cur_term_input grub_term_get_current_input () -#define grub_cur_term_output grub_term_get_current_output () + +struct grub_term_output *grub_term_outputs; /* Put a Unicode character. */ void -grub_putcode (grub_uint32_t code) +grub_putcode (grub_uint32_t code, struct grub_term_output *term) { - int height = grub_getwh () & 255; + int height; - if (code == '\t' && grub_cur_term_output->getxy) + height = term->getwh () & 255; + + if (code == '\t' && term->getxy) { int n; - n = 8 - ((grub_getxy () >> 8) & 7); + n = 8 - ((term->getxy () >> 8) & 7); while (n--) - grub_putcode (' '); + grub_putcode (' ', term); return; } - (grub_cur_term_output->putchar) (code); - - if (code == '\n') - { - grub_putcode ('\r'); - - grub_more_lines++; - - if (grub_more && grub_more_lines == height - 1) - { - char key; - int pos = grub_getxy (); - - /* Show --MORE-- on the lower left side of the screen. */ - grub_gotoxy (1, height - 1); - grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); - grub_printf ("--MORE--"); - grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); - - key = grub_getkey (); - - /* Remove the message. */ - grub_gotoxy (1, height - 1); - grub_printf (" "); - grub_gotoxy (pos >> 8, pos & 0xFF); - - /* Scroll one lines or an entire page, depending on the key. */ - if (key == '\r' || key =='\n') - grub_more_lines--; - else - grub_more_lines = 0; - } - } + (term->putchar) (code); } /* Put a character. C is one byte of a UTF-8 stream. @@ -106,26 +63,28 @@ grub_putchar (int c) grub_uint32_t code; grub_ssize_t ret; + auto int do_putcode (grub_list_t item); + int do_putcode (grub_list_t item) + { + struct grub_term_output *term = (struct grub_term_output *) item; + + if (term->flags & GRUB_TERM_ACTIVE) + grub_putcode (code, term); + + return 0; + } + buf[size++] = c; ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0); - if (ret > 0) - { - size = 0; - grub_putcode (code); - } - else if (ret < 0) - { - size = 0; - grub_putcode ('?'); - } -} + if (ret < 0) + code = '?'; -/* Return the number of columns occupied by the character code CODE. */ -grub_ssize_t -grub_getcharwidth (grub_uint32_t code) -{ - return (grub_cur_term_output->getcharwidth) (code); + if (ret != 0) + { + size = 0; + grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), do_putcode); + } } int @@ -149,91 +108,67 @@ grub_getkeystatus (void) return 0; } -grub_uint16_t -grub_getxy (void) -{ - return (grub_cur_term_output->getxy) (); -} - -grub_uint16_t -grub_getwh (void) -{ - return (grub_cur_term_output->getwh) (); -} - -void -grub_gotoxy (grub_uint8_t x, grub_uint8_t y) -{ - (grub_cur_term_output->gotoxy) (x, y); -} - void grub_cls (void) { - if ((grub_cur_term_output->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) - { - grub_putchar ('\n'); - grub_refresh (); - } - else - (grub_cur_term_output->cls) (); + auto int hook (grub_list_t item); + int hook (grub_list_t item) + { + struct grub_term_output *term = (struct grub_term_output *) item; + + if (!(term->flags & GRUB_TERM_ACTIVE)) + return 0; + + if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) + { + grub_putcode ('\n', term); + grub_refresh (); + } + else + (term->cls) (); + + return 0; + } + + grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); } void grub_setcolorstate (grub_term_color_state state) { - if (grub_cur_term_output->setcolorstate) - (grub_cur_term_output->setcolorstate) (state); -} + auto int hook (grub_list_t item); + int hook (grub_list_t item) + { + struct grub_term_output *term = (struct grub_term_output *) item; -void -grub_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color) -{ - if (grub_cur_term_output->setcolor) - (grub_cur_term_output->setcolor) (normal_color, highlight_color); -} + if (!(term->flags & GRUB_TERM_ACTIVE)) + return 0; -void -grub_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color) -{ - if (grub_cur_term_output->getcolor) - (grub_cur_term_output->getcolor) (normal_color, highlight_color); -} + if (term->setcolorstate) + (term->setcolorstate) (state); -int -grub_setcursor (int on) -{ - int ret = cursor_state; + return 0; + } - if (grub_cur_term_output->setcursor) - { - (grub_cur_term_output->setcursor) (on); - cursor_state = on; - } - - return ret; -} - -int -grub_getcursor (void) -{ - return cursor_state; + grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); } void grub_refresh (void) { - if (grub_cur_term_output->refresh) - (grub_cur_term_output->refresh) (); -} + auto int hook (grub_list_t item); + int hook (grub_list_t item) + { + struct grub_term_output *term = (struct grub_term_output *) item; -void -grub_set_more (int onoff) -{ - if (onoff == 1) - grub_more++; - else - grub_more--; + if (!(term->flags & GRUB_TERM_ACTIVE)) + return 0; - grub_more_lines = 0; + if (term->refresh) + (term->refresh) (); + + return 0; + } + + grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); } diff --git a/lib/charset.c b/lib/charset.c index 8bc5b9149..0f2c2c8ee 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -114,3 +114,67 @@ grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize, *srcend = src; return p - dest; } + +/* Convert UCS-4 to UTF-8. */ +char * +grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size) +{ + grub_size_t remaining; + grub_uint32_t *ptr; + grub_size_t cnt = 0; + grub_uint8_t *ret, *dest; + + remaining = size; + ptr = src; + while (remaining--) + { + grub_uint32_t code = *ptr++; + + if (code <= 0x007F) + cnt++; + else if (code <= 0x07FF) + cnt += 2; + else if ((code >= 0xDC00 && code <= 0xDFFF) + || (code >= 0xD800 && code <= 0xDBFF)) + /* No surrogates in UCS-4... */ + cnt++; + else + cnt += 3; + } + cnt++; + + ret = grub_malloc (cnt); + if (!ret) + return 0; + + dest = ret; + remaining = size; + ptr = src; + while (remaining--) + { + grub_uint32_t code = *ptr++; + + if (code <= 0x007F) + *dest++ = code; + else if (code <= 0x07FF) + { + *dest++ = (code >> 6) | 0xC0; + *dest++ = (code & 0x3F) | 0x80; + } + else if ((code >= 0xDC00 && code <= 0xDFFF) + || (code >= 0xD800 && code <= 0xDBFF)) + { + /* No surrogates in UCS-4... */ + *dest++ = '?'; + } + else + { + *dest++ = (code >> 12) | 0xE0; + *dest++ = ((code >> 6) & 0x3F) | 0x80; + *dest++ = (code & 0x3F) | 0x80; + } + } + *dest = 0; + + return ret; +} diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 82bfd6b95..140ed1957 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -33,6 +33,7 @@ #include #include #include +#include #define GRUB_LINUX_CL_OFFSET 0x1000 #define GRUB_LINUX_CL_END_OFFSET 0x2000 @@ -547,8 +548,8 @@ grub_linux_boot (void) /* Initialize these last, because terminal position could be affected by printfs above. */ if (params->have_vga == GRUB_VIDEO_TYPE_TEXT) { - params->video_cursor_x = grub_getxy () >> 8; - params->video_cursor_y = grub_getxy () & 0xff; + params->video_cursor_x = grub_console_getxy () >> 8; + params->video_cursor_y = grub_console_getxy () & 0xff; } #ifdef __x86_64__ diff --git a/normal/cmdline.c b/normal/cmdline.c index 6d74e6e69..c104709c5 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -28,10 +28,10 @@ #include #include -static char *kill_buf; +static grub_uint32_t *kill_buf; static int hist_size; -static char **hist_lines = 0; +static grub_uint32_t **hist_lines = 0; static int hist_pos = 0; static int hist_end = 0; static int hist_used = 0; @@ -39,7 +39,7 @@ static int hist_used = 0; grub_err_t grub_set_history (int newsize) { - char **old_hist_lines = hist_lines; + grub_uint32_t **old_hist_lines = hist_lines; hist_lines = grub_malloc (sizeof (char *) * newsize); /* Copy the old lines into the new buffer. */ @@ -90,17 +90,42 @@ grub_set_history (int newsize) /* Get the entry POS from the history where `0' is the newest entry. */ -static char * +static grub_uint32_t * grub_history_get (int pos) { pos = (hist_pos + pos) % hist_size; return hist_lines[pos]; } +static grub_size_t +strlen_ucs4 (const grub_uint32_t *s) +{ + const grub_uint32_t *p = s; + + while (*p) + p++; + + return p - s; +} + +static grub_uint32_t * +strdup_ucs4 (const grub_uint32_t *s) +{ + grub_size_t len; + char *p; + + len = strlen_ucs4 (s) + 1; + p = (char *) grub_malloc (len * sizeof (grub_uint32_t)); + if (! p) + return 0; + + return grub_memcpy (p, s, len * sizeof (grub_uint32_t)); +} + /* Insert a new history line S on the top of the history. */ static void -grub_history_add (char *s) +grub_history_add (grub_uint32_t *s) { /* Remove the oldest entry in the history to make room for a new entry. */ @@ -121,16 +146,16 @@ grub_history_add (char *s) hist_pos = hist_size + hist_pos; /* Insert into history. */ - hist_lines[hist_pos] = grub_strdup (s); + hist_lines[hist_pos] = strdup_ucs4 (s); } /* Replace the history entry on position POS with the string S. */ static void -grub_history_replace (int pos, char *s) +grub_history_replace (int pos, grub_uint32_t *s) { pos = (hist_pos + pos) % hist_size; grub_free (hist_lines[pos]); - hist_lines[pos] = grub_strdup (s); + hist_lines[pos] = strdup_ucs4 (s); } /* A completion hook to print items. */ @@ -176,62 +201,81 @@ print_completion (const char *item, grub_completion_type_t type, int count) grub_printf (" %s", item); } -/* Get a command-line. If ECHO_CHAR is not zero, echo it instead of input - characters. If READLINE is non-zero, readline-like key bindings are - available. If ESC is pushed, return zero, otherwise return non-zero. */ -/* FIXME: The dumb interface is not supported yet. */ -int -grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, - int echo_char, int readline, int history) +struct cmdline_term +{ + unsigned xpos, ypos, ystart, width, height; + struct grub_term_output *term; +}; + +/* Get a command-line. If ESC is pushed, return zero, + otherwise return command line. */ +/* FIXME: The dumb interface is not supported yet. */ +char * +grub_cmdline_get (const char *prompt, unsigned max_len) { - unsigned xpos, ypos, ystart; grub_size_t lpos, llen; grub_size_t plen; - char buf[max_len]; + grub_uint32_t buf[max_len]; int key; int histpos = 0; - auto void cl_insert (const char *str); + auto void cl_insert (const grub_uint32_t *str); auto void cl_delete (unsigned len); - auto void cl_print (int pos, int c); - auto void cl_set_pos (void); + auto void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c); + auto void cl_set_pos (struct cmdline_term *cl_term); + auto void cl_print_all (int pos, grub_uint32_t c); + auto void cl_set_pos_all (void); const char *prompt_translated = _(prompt); + struct cmdline_term *cl_terms; + unsigned nterms; - void cl_set_pos (void) + void cl_set_pos (struct cmdline_term *cl_term) + { + cl_term->xpos = (plen + lpos) % (cl_term->width - 1); + cl_term->ypos = cl_term->ystart + (plen + lpos) / (cl_term->width - 1); + cl_term->term->gotoxy (cl_term->xpos, cl_term->ypos); + } + + void cl_set_pos_all () + { + unsigned i; + for (i = 0; i < nterms; i++) + cl_set_pos (&cl_terms[i]); + } + + void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c) { - xpos = (plen + lpos) % 79; - ypos = ystart + (plen + lpos) / 79; - grub_gotoxy (xpos, ypos); - - grub_refresh (); - } - - void cl_print (int pos, int c) - { - char *p; + grub_uint32_t *p; for (p = buf + pos; *p; p++) { - if (xpos++ > 78) + if (cl_term->xpos++ > cl_term->width - 2) { - grub_putchar ('\n'); + grub_putcode ('\n', cl_term->term); - xpos = 1; - if (ypos == (unsigned) (grub_getxy () & 0xFF)) - ystart--; + cl_term->xpos = 1; + if (cl_term->ypos == (unsigned) (cl_term->height)) + cl_term->ystart--; else - ypos++; + cl_term->ypos++; } if (c) - grub_putchar (c); + grub_putcode (c, cl_term->term); else - grub_putchar (*p); + grub_putcode (*p, cl_term->term); } } - void cl_insert (const char *str) + void cl_print_all (int pos, grub_uint32_t c) + { + unsigned i; + for (i = 0; i < nterms; i++) + cl_print (&cl_terms[i], pos, c); + } + + void cl_insert (const grub_uint32_t *str) { - grub_size_t len = grub_strlen (str); + grub_size_t len = strlen_ucs4 (str); if (len + llen < max_len) { @@ -240,8 +284,8 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, llen += len; lpos += len; - cl_print (lpos - len, echo_char); - cl_set_pos (); + cl_print_all (lpos - len, echo_char); + cl_set_pos_all (); } grub_refresh (); @@ -254,182 +298,207 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, grub_size_t saved_lpos = lpos; lpos = llen - len; - cl_set_pos (); - cl_print (lpos, ' '); + cl_set_pos_all (); + cl_print_all (lpos, ' '); lpos = saved_lpos; - cl_set_pos (); + cl_set_pos_all (); grub_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1); llen -= len; - cl_print (lpos, echo_char); - cl_set_pos (); + cl_print_all (lpos, echo_char); + cl_set_pos_all (); } grub_refresh (); } + void init_clterm (struct cmdline_term *cl_term_cur) + { + cl_term_cur->xpos = plen; + cl_term_cur->ypos = (cl_term_cur->term->getxy () & 0xFF); + cl_term_cur->ystart = cl_term_cur->ypos; + cl_term_cur->width = grub_term_width (cl_term_cur->term); + cl_term_cur->height = grub_term_height (cl_term_cur->term); + } + + void init_clterm_all (void) + { + unsigned i; + for (i = 0; i < nterms; i++) + init_clterm (&cl_terms[i]); + } + plen = grub_strlen (prompt_translated); lpos = llen = 0; buf[0] = '\0'; - if ((grub_getxy () >> 8) != 0) - grub_putchar ('\n'); + grub_putchar ('\n'); grub_printf ("%s", prompt_translated); - xpos = plen; - ystart = ypos = (grub_getxy () & 0xFF); + { + struct cmdline_term *cl_term_cur; + struct grub_term_output *cur; + nterms = 0; + for (cur = grub_term_outputs; cur; cur = cur->next) + if (cur->flags & GRUB_TERM_ACTIVE) + nterms++; - cl_insert (cmdline); + cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); + if (!cl_terms) + return grub_errno; + cl_term_cur = cl_terms; + for (cur = grub_term_outputs; cur; cur = cur->next) + if (cur->flags & GRUB_TERM_ACTIVE) + { + cl_term_cur->term = cur; + init_clterm (cl_term_cur); + cl_term_cur++; + } + } if (history && hist_used == 0) grub_history_add (buf); while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r') { - if (readline) - { - switch (key) - { - case 1: /* Ctrl-a */ - lpos = 0; - cl_set_pos (); - break; - - case 2: /* Ctrl-b */ - if (lpos > 0) - { - lpos--; - cl_set_pos (); - } - break; - - case 5: /* Ctrl-e */ - lpos = llen; - cl_set_pos (); - break; - - case 6: /* Ctrl-f */ - if (lpos < llen) - { - lpos++; - cl_set_pos (); - } - break; - - case 9: /* Ctrl-i or TAB */ - { - char *insert; - int restore; - - /* Backup the next character and make it 0 so it will - be easy to use string functions. */ - char backup = buf[lpos]; - buf[lpos] = '\0'; - - - insert = grub_normal_do_completion (buf, &restore, - print_completion); - /* Restore the original string. */ - buf[lpos] = backup; - - if (restore) - { - /* Restore the prompt. */ - grub_printf ("\n%s %s", prompt_translated, buf); - xpos = plen; - ystart = ypos = (grub_getxy () & 0xFF); - } - - if (insert) - { - cl_insert (insert); - grub_free (insert); - } - } - break; - - case 11: /* Ctrl-k */ - if (lpos < llen) - { - if (kill_buf) - grub_free (kill_buf); - - kill_buf = grub_strdup (buf + lpos); - grub_errno = GRUB_ERR_NONE; - - cl_delete (llen - lpos); - } - break; - - case 14: /* Ctrl-n */ - { - char *hist; - - lpos = 0; - - if (histpos > 0) - { - grub_history_replace (histpos, buf); - histpos--; - } - - cl_delete (llen); - hist = grub_history_get (histpos); - cl_insert (hist); - - break; - } - case 16: /* Ctrl-p */ - { - char *hist; - - lpos = 0; - - if (histpos < hist_used - 1) - { - grub_history_replace (histpos, buf); - histpos++; - } - - cl_delete (llen); - hist = grub_history_get (histpos); - - cl_insert (hist); - } - break; - - case 21: /* Ctrl-u */ - if (lpos > 0) - { - grub_size_t n = lpos; - - if (kill_buf) - grub_free (kill_buf); - - kill_buf = grub_malloc (n + 1); - grub_errno = GRUB_ERR_NONE; - if (kill_buf) - { - grub_memcpy (kill_buf, buf, n); - kill_buf[n] = '\0'; - } - - lpos = 0; - cl_set_pos (); - cl_delete (n); - } - break; - - case 25: /* Ctrl-y */ - if (kill_buf) - cl_insert (kill_buf); - break; - } - } - switch (key) { + case 1: /* Ctrl-a */ + lpos = 0; + cl_set_pos_all (); + break; + + case 2: /* Ctrl-b */ + if (lpos > 0) + { + lpos--; + cl_set_pos_all (); + } + break; + + case 5: /* Ctrl-e */ + lpos = llen; + cl_set_pos_all (); + break; + + case 6: /* Ctrl-f */ + if (lpos < llen) + { + lpos++; + cl_set_pos_all (); + } + break; + + case 9: /* Ctrl-i or TAB */ + { + grub_uint32_t *insert; + int restore; + + /* Backup the next character and make it 0 so it will + be easy to use string functions. */ + char backup = buf[lpos]; + buf[lpos] = '\0'; + + + insert = grub_normal_do_completion (buf, &restore, + print_completion); + /* Restore the original string. */ + buf[lpos] = backup; + + if (restore) + { + /* Restore the prompt. */ + grub_printf ("\n%s", prompt_translated); + init_clterm_all (); + cl_print_all (0, 0); + } + + if (insert) + { + cl_insert (insert); + grub_free (insert); + } + } + break; + + case 11: /* Ctrl-k */ + if (lpos < llen) + { + if (kill_buf) + grub_free (kill_buf); + + kill_buf = strdup_ucs4 (buf + lpos); + grub_errno = GRUB_ERR_NONE; + + cl_delete (llen - lpos); + } + break; + + case 14: /* Ctrl-n */ + { + grub_uint32_t *hist; + + lpos = 0; + + if (histpos > 0) + { + grub_history_replace (histpos, buf); + histpos--; + } + + cl_delete (llen); + hist = grub_history_get (histpos); + cl_insert (hist); + + break; + } + case 16: /* Ctrl-p */ + { + grub_uint32_t *hist; + + lpos = 0; + + if (histpos < hist_used - 1) + { + grub_history_replace (histpos, buf); + histpos++; + } + + cl_delete (llen); + hist = grub_history_get (histpos); + + cl_insert (hist); + } + break; + + case 21: /* Ctrl-u */ + if (lpos > 0) + { + grub_size_t n = lpos; + + if (kill_buf) + grub_free (kill_buf); + + kill_buf = grub_malloc (n + 1); + grub_errno = GRUB_ERR_NONE; + if (kill_buf) + { + grub_memcpy (kill_buf, buf, n); + kill_buf[n] = '\0'; + } + + lpos = 0; + cl_set_pos_all (); + cl_delete (n); + } + break; + + case 25: /* Ctrl-y */ + if (kill_buf) + cl_insert (kill_buf); + break; + case '\e': return 0; @@ -437,7 +506,7 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, if (lpos > 0) { lpos--; - cl_set_pos (); + cl_set_pos_all (); } else break; @@ -451,7 +520,7 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, default: if (grub_isprint (key)) { - char str[2]; + grub_uint32_t str[2]; str[0] = key; str[1] = '\0'; @@ -464,23 +533,21 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, grub_putchar ('\n'); grub_refresh (); - /* If ECHO_CHAR is NUL, remove leading spaces. */ + /* Remove leading spaces. */ lpos = 0; - if (! echo_char) - while (buf[lpos] == ' ') - lpos++; + while (buf[lpos] == ' ') + lpos++; if (history) { histpos = 0; - if (grub_strlen (buf) > 0) + if (strlen_ucs4 (buf) > 0) { + grub_uint32_t empty[] = { 0 }; grub_history_replace (histpos, buf); - grub_history_add (""); + grub_history_add (empty); } } - grub_memcpy (cmdline, buf + lpos, llen - lpos + 1); - - return 1; + return grub_ucs4_to_utf8_alloc (buf + lpos, llen - lpos + 1); } diff --git a/normal/color.c b/normal/color.c index 0b9868d3b..63bd889a5 100644 --- a/normal/color.c +++ b/normal/color.c @@ -103,23 +103,36 @@ free_and_return: grub_free (fg_name); } +static grub_uint8_t color_normal, color_highlight; + +static void +set_colors (void) +{ + struct grub_term_output *term; + + for (term = grub_term_outputs; term; term = term->next) + { + if (! (term->flags & GRUB_TERM_ACTIVE)) + continue; + + /* Reloads terminal `normal' and `highlight' colors. */ + if (term->setcolor) + term->setcolor (color_normal, color_highlight); + + /* Propagates `normal' color to terminal current color. */ + if (term->setcolorstate) + term->setcolorstate (GRUB_TERM_COLOR_NORMAL); + } +} + /* Replace default `normal' colors with the ones specified by user (if any). */ char * grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)), const char *val) { - grub_uint8_t color_normal, color_highlight; - - /* Use old settings in case grub_parse_color_name_pair() has no effect. */ - grub_getcolor (&color_normal, &color_highlight); - grub_parse_color_name_pair (&color_normal, val); - /* Reloads terminal `normal' and `highlight' colors. */ - grub_setcolor (color_normal, color_highlight); - - /* Propagates `normal' color to terminal current color. */ - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + set_colors (); return grub_strdup (val); } @@ -129,21 +142,9 @@ char * grub_env_write_color_highlight (struct grub_env_var *var __attribute__ ((unused)), const char *val) { - grub_uint8_t color_normal, color_highlight; - - /* Use old settings in case grub_parse_color_name_pair() has no effect. */ - grub_getcolor (&color_normal, &color_highlight); - grub_parse_color_name_pair (&color_highlight, val); - /* Reloads terminal `normal' and `highlight' colors. */ - grub_setcolor (color_normal, color_highlight); - - /* Propagates `normal' color to terminal current color. - Note: Using GRUB_TERM_COLOR_NORMAL here rather than - GRUB_TERM_COLOR_HIGHLIGHT is intentional. We don't want to switch - to highlight state just because color was reloaded. */ - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + set_colors (); return grub_strdup (val); } diff --git a/normal/main.c b/normal/main.c index e8dfb182b..42098e682 100644 --- a/normal/main.c +++ b/normal/main.c @@ -372,7 +372,21 @@ read_config_file (const char *config) if (! file) return 0; - grub_reader_loop (getline); + while (1) + { + char *line; + + /* Print an error, if any. */ + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + + if ((getline (&line, 0)) || (! line)) + break; + + grub_parser_get_current ()->parse_line (line, getline); + grub_free (line); + } + grub_file_close (file); if (old_parser) @@ -383,7 +397,7 @@ read_config_file (const char *config) /* Initialize the screen. */ void -grub_normal_init_page (void) +grub_normal_init_page (struct grub_term_output *term) { int msg_len; int posx; @@ -391,13 +405,12 @@ grub_normal_init_page (void) char *msg_formatted = grub_malloc (grub_strlen(msg) + grub_strlen(PACKAGE_VERSION)); + grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; grub_cls (); grub_sprintf (msg_formatted, msg, PACKAGE_VERSION); - - grub_uint32_t *unicode_msg; - grub_uint32_t *last_position; msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, &unicode_msg, &last_position); @@ -408,8 +421,8 @@ grub_normal_init_page (void) } posx = grub_getstringwidth (unicode_msg, last_position); - posx = (GRUB_TERM_WIDTH - posx) / 2; - grub_gotoxy (posx, 1); + posx = (grub_term_width (term) - posx) / 2; + term->gotoxy (posx, 1); grub_print_ucs4 (unicode_msg, last_position); grub_printf("\n\n"); @@ -493,48 +506,30 @@ quit: return 0; } -void -grub_cmdline_run (int nested) -{ - grub_reader_t reader; - grub_err_t err = GRUB_ERR_NONE; - - err = grub_auth_check_authentication (NULL); - - if (err) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - return; - } - - reader = grub_reader_get_current (); - - reader_nested = nested; - if (reader->init) - reader->init (); - grub_reader_loop (0); -} - static grub_err_t grub_normal_reader_init (void) { - grub_normal_init_page (); - grub_setcursor (1); - + struct grub_term_output *term; const char *msg = _("Minimal BASH-like line editing is supported. For " "the first word, TAB lists possible command completions. Anywhere " "else TAB lists possible device or file completions. %s"); - const char *msg_esc = _("ESC at any time exits."); - char *msg_formatted = grub_malloc (sizeof (char) * (grub_strlen (msg) + grub_strlen(msg_esc) + 1)); grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : ""); - grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN); - grub_puts ("\n"); + for (term = grub_term_outputs; term; term = term->next) + { + if (! (term->flags & GRUB_TERM_ACTIVE)) + continue; + grub_normal_init_page (term); + if (term->setcursor) + term->setcursor (1); + + grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN); + grub_puts ("\n"); + } grub_free (msg_formatted); return 0; @@ -567,12 +562,40 @@ grub_normal_read_line (char **line, int cont) return 0; } -static struct grub_reader grub_normal_reader = - { - .name = "normal", - .init = grub_normal_reader_init, - .read_line = grub_normal_read_line - }; +void +grub_cmdline_run (int nested) +{ + grub_err_t err = GRUB_ERR_NONE; + + err = grub_auth_check_authentication (NULL); + + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + return; + } + + reader_nested = nested; + + grub_normal_reader_init (); + + while (1) + { + char *line; + + /* Print an error, if any. */ + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + + grub_normal_read_line (&line, 0); + if (! line) + continue; + + grub_parser_get_current ()->parse_line (line, grub_normal_read_line); + grub_free (line); + } +} static char * grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)), @@ -592,8 +615,6 @@ GRUB_MOD_INIT(normal) grub_set_history (GRUB_DEFAULT_HISTORY_SIZE); - grub_reader_register ("normal", &grub_normal_reader); - grub_reader_set_current (&grub_normal_reader); grub_register_variable_hook ("pager", 0, grub_env_write_pager); /* Register a command "normal" for the rescue mode. */ @@ -612,7 +633,6 @@ GRUB_MOD_INIT(normal) GRUB_MOD_FINI(normal) { grub_set_history (0); - grub_reader_unregister (&grub_normal_reader); grub_register_variable_hook ("pager", 0, 0); grub_fs_autoload_hook = 0; free_handler_list (); diff --git a/normal/term.c b/normal/term.c new file mode 100644 index 000000000..73eab548a --- /dev/null +++ b/normal/term.c @@ -0,0 +1,128 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +/* The amount of lines counted by the pager. */ +static int grub_more_lines; + +/* If the more pager is active. */ +static int grub_more; + +static void +process_newline (void) +{ + if (code == '\n') + { + grub_putcode ('\r'); + + grub_more_lines++; + + if (grub_more && grub_more_lines == height - 1) + { + char key; + int pos = term->getxy (); + + /* Show --MORE-- on the lower left side of the screen. */ + term->gotoxy (1, height - 1); + grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); + grub_printf ("--MORE--"); + grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); + + key = grub_getkey (); + + /* Remove the message. */ + term->gotoxy (1, height - 1); + grub_printf (" "); + term->gotoxy (pos >> 8, pos & 0xFF); + + /* Scroll one lines or an entire page, depending on the key. */ + if (key == '\r' || key =='\n') + grub_more_lines--; + else + grub_more_lines = 0; + } + } +} + +void +grub_set_more (int onoff) +{ + if (onoff == 1) + grub_more++; + else + grub_more--; + + grub_more_lines = 0; +} + +void +grub_puts_terminal (const char *str, struct grub_term_output *term) +{ + grub_uint32_t code; + grub_ssize_t ret; + const char *ptr = str; + unsigned i; + + while (*ptr) + { + ret = grub_utf8_to_ucs4 (&code, 1, ptr, + grub_strlen (ptr), &ptr); + if (ret < 0) + { + grub_putcode ('?', term); + ptr++; + continue; + } + else + grub_putcode (code, term); + } +} + +grub_uint16_t * +grub_term_save_pos (void) +{ + struct grub_term_output *cur; + unsigned cnt = 0; + grub_uint16_t *ret, *ptr; + + for (cur = grub_term_outputs; cur; cur = cur->next) + if (cur->flags & GRUB_TERM_ACTIVE) + cnt++; + + ret = grub_malloc (cnt * sizeof (ret[0])); + if (!ret) + return NULL; + + for (cur = grub_term_outputs; cur; cur = cur->next) + if (cur->flags & GRUB_TERM_ACTIVE) + *ptr++ = cur->getxy (); + + return ret; +} + +void +grub_term_restore_pos (grub_uint16_t *pos) +{ + struct grub_term_output *cur; + + if (!pos) + return; + + for (cur = grub_term_outputs; cur; cur = cur->next) + if (cur->flags & GRUB_TERM_ACTIVE) + cur->gotoxy ((*ptr & 0xff00) >> 8, *ptr & 0xff); +} diff --git a/term/i386/pc/console.c b/term/i386/pc/console.c index 66475d456..b54e2f6f1 100644 --- a/term/i386/pc/console.c +++ b/term/i386/pc/console.c @@ -79,10 +79,6 @@ grub_console_init (void) void grub_console_fini (void) { - /* This is to make sure the console is restored to text mode before - we boot. */ - grub_term_set_current_output (&grub_console_term_output); - grub_term_unregister_input (&grub_console_term_input); grub_term_unregister_output (&grub_console_term_output); } From 2e7138317249dfe3fe61c1b23beca1cbc75a003d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 15:34:33 +0100 Subject: [PATCH 044/164] Core changes hopefully finished --- commands/help.c | 2 +- include/grub/charset.h | 6 + include/grub/menu_viewer.h | 17 +- include/grub/misc.h | 10 +- include/grub/normal.h | 20 +- include/grub/term.h | 136 +++++-- kern/misc.c | 13 +- kern/term.c | 25 +- lib/charset.c | 91 ++++- normal/auth.c | 50 ++- normal/cmdline.c | 113 ++++-- normal/color.c | 8 +- normal/main.c | 43 +-- normal/menu.c | 385 ++++++++++++++++++++ normal/menu_entry.c | 659 +++++++++++++++++++++------------- normal/menu_text.c | 704 ++++++++++++------------------------- normal/menu_viewer.c | 55 --- normal/term.c | 88 ++--- term/efi/console.c | 2 +- term/i386/pc/console.c | 2 +- term/i386/pc/vga_text.c | 7 + term/ieee1275/ofconsole.c | 2 +- util/console.c | 2 +- 23 files changed, 1493 insertions(+), 947 deletions(-) diff --git a/commands/help.c b/commands/help.c index 4d16945af..5e8f0b27a 100644 --- a/commands/help.c +++ b/commands/help.c @@ -41,7 +41,7 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, int desclen = grub_strlen (cmd->summary); for (cur = grub_term_outputs; cur; cur = cur->next) { - if (!(cur->flags & GRUB_TERM_ACTIVE)) + if (!grub_term_is_active (cur)) continue; int width = grub_term_width(cur); char description[width / 2]; diff --git a/include/grub/charset.h b/include/grub/charset.h index daaa5c99f..fc050da24 100644 --- a/include/grub/charset.h +++ b/include/grub/charset.h @@ -112,4 +112,10 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src, /* Convert UCS-4 to UTF-8. */ char *grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size); +int +grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize); + +int grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, + grub_uint32_t **last_position); + #endif diff --git a/include/grub/menu_viewer.h b/include/grub/menu_viewer.h index 725c97548..3821219a3 100644 --- a/include/grub/menu_viewer.h +++ b/include/grub/menu_viewer.h @@ -27,17 +27,18 @@ struct grub_menu_viewer { - /* The menu viewer name. */ - const char *name; - - grub_err_t (*show_menu) (grub_menu_t menu, int nested); - struct grub_menu_viewer *next; + void *data; + void (*set_chosen_entry) (int entry, void *data); + void (*print_timeout) (int timeout, void *data); + void (*clear_timeout) (void *data); + void (*fini) (void *fini); }; -typedef struct grub_menu_viewer *grub_menu_viewer_t; -void grub_menu_viewer_register (grub_menu_viewer_t viewer); +void grub_menu_register_viewer (struct grub_menu_viewer *viewer); -grub_err_t grub_menu_viewer_show_menu (grub_menu_t menu, int nested); +grub_err_t grub_menu_register_viewer_init (void (*callback) (int entry, + grub_menu_t menu, + int nested)); #endif /* GRUB_MENU_VIEWER_HEADER */ diff --git a/include/grub/misc.h b/include/grub/misc.h index 92fb460cf..9c3193f88 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -183,11 +183,11 @@ int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ (( int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args); void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); -grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest, - grub_size_t destsize, - const grub_uint8_t *src, - grub_size_t srcsize, - const grub_uint8_t **srcend); +grub_size_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest, + grub_size_t destsize, + const grub_uint8_t *src, + grub_size_t srcsize, + const grub_uint8_t **srcend); grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r); diff --git a/include/grub/normal.h b/include/grub/normal.h index 33c30b22a..91457fc09 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -51,15 +51,16 @@ extern struct grub_menu_viewer grub_normal_text_menu_viewer; /* Defined in `main.c'. */ void grub_enter_normal_mode (const char *config); void grub_normal_execute (const char *config, int nested, int batch); +void grub_menu_init_page (int nested, int edit, + struct grub_term_output *term); void grub_normal_init_page (struct grub_term_output *term); -void grub_menu_init_page (int nested, int edit); grub_err_t grub_normal_add_menu_entry (int argc, const char **args, const char *sourcecode); char *grub_file_getline (grub_file_t file); void grub_cmdline_run (int nested); /* Defined in `cmdline.c'. */ -char *grub_cmdline_get (const char *prompt, unsigned max_len); +char *grub_cmdline_get (const char *prompt); grub_err_t grub_set_history (int newsize); /* Defined in `completion.c'. */ @@ -76,14 +77,19 @@ void grub_parse_color_name_pair (grub_uint8_t *ret, const char *name); /* Defined in `menu_text.c'. */ void grub_wait_after_message (void); -int grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, - grub_uint32_t **last_position); void grub_print_ucs4 (const grub_uint32_t * str, - const grub_uint32_t * last_position); + const grub_uint32_t * last_position, + struct grub_term_output *term); grub_ssize_t grub_getstringwidth (grub_uint32_t * str, - const grub_uint32_t * last_position); + const grub_uint32_t * last_position, + struct grub_term_output *term); void grub_print_message_indented (const char *msg, int margin_left, - int margin_right); + int margin_right, + struct grub_term_output *term); +void +grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested); +grub_err_t +grub_show_menu (grub_menu_t menu, int nested); /* Defined in `handler.c'. */ void read_handler_list (void); diff --git a/include/grub/term.h b/include/grub/term.h index 39a10ed71..a0b96b497 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -111,37 +111,12 @@ grub_term_color_state; /* The X position of the left border. */ #define GRUB_TERM_LEFT_BORDER_X GRUB_TERM_MARGIN -/* The width of the border. */ -#define GRUB_TERM_BORDER_WIDTH (GRUB_TERM_WIDTH \ - - GRUB_TERM_MARGIN * 3 \ - - GRUB_TERM_SCROLL_WIDTH) - /* The number of lines of messages at the bottom. */ #define GRUB_TERM_MESSAGE_HEIGHT 8 -/* The height of the border. */ -#define GRUB_TERM_BORDER_HEIGHT (GRUB_TERM_HEIGHT \ - - GRUB_TERM_TOP_BORDER_Y \ - - GRUB_TERM_MESSAGE_HEIGHT) - -/* The number of entries shown at a time. */ -#define GRUB_TERM_NUM_ENTRIES (GRUB_TERM_BORDER_HEIGHT - 2) - /* The Y position of the first entry. */ #define GRUB_TERM_FIRST_ENTRY_Y (GRUB_TERM_TOP_BORDER_Y + 1) -/* The max column number of an entry. The last "-1" is for a - continuation marker. */ -#define GRUB_TERM_ENTRY_WIDTH (GRUB_TERM_BORDER_WIDTH - 2 \ - - GRUB_TERM_MARGIN * 2 - 1) - -/* The standard X position of the cursor. */ -#define GRUB_TERM_CURSOR_X (GRUB_TERM_LEFT_BORDER_X \ - + GRUB_TERM_BORDER_WIDTH \ - - GRUB_TERM_MARGIN \ - - 1) - - struct grub_term_input { /* The next terminal. */ @@ -277,16 +252,123 @@ void grub_puts_terminal (const char *str, struct grub_term_output *term); grub_uint16_t *grub_term_save_pos (void); void grub_term_restore_pos (grub_uint16_t *pos); -static inline int grub_term_width (struct grub_term_output *term) +static inline unsigned grub_term_width (struct grub_term_output *term) { return ((term->getwh()&0xFF00)>>8); } -static inline int grub_term_height (struct grub_term_output *term) +static inline unsigned grub_term_height (struct grub_term_output *term) { return (term->getwh()&0xFF); } +/* The width of the border. */ +static inline unsigned +grub_term_border_width (struct grub_term_output *term) +{ + return grub_term_width (term) - GRUB_TERM_MARGIN * 3 - GRUB_TERM_SCROLL_WIDTH; +} + +/* The max column number of an entry. The last "-1" is for a + continuation marker. */ +static inline int +grub_term_entry_width (struct grub_term_output *term) +{ + return grub_term_border_width (term) - 2 - GRUB_TERM_MARGIN * 2 - 1; +} + +/* The height of the border. */ + +static inline unsigned +grub_term_border_height (struct grub_term_output *term) +{ + return grub_term_height (term) - GRUB_TERM_TOP_BORDER_Y + - GRUB_TERM_MESSAGE_HEIGHT; +} + +/* The number of entries shown at a time. */ +static inline int +grub_term_num_entries (struct grub_term_output *term) +{ + return grub_term_border_height (term) - 2; +} + +static inline int +grub_term_cursor_x (struct grub_term_output *term) +{ + return (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term) + - GRUB_TERM_MARGIN - 1); +} + +static inline grub_uint16_t +grub_term_getxy (struct grub_term_output *term) +{ + return term->getxy (); +} + +static inline void +grub_term_refresh (struct grub_term_output *term) +{ + if (term->refresh) + term->refresh (); +} + +static inline void +grub_term_gotoxy (struct grub_term_output *term, grub_uint8_t x, grub_uint8_t y) +{ + term->gotoxy (x, y); +} + +static inline void +grub_term_setcolorstate (struct grub_term_output *term, + grub_term_color_state state) +{ + if (term->setcolorstate) + term->setcolorstate (state); +} + + /* Set the normal color and the highlight color. The format of each + color is VGA's. */ +static inline void +grub_term_setcolor (struct grub_term_output *term, + grub_uint8_t normal_color, grub_uint8_t highlight_color) +{ + if (term->setcolor) + term->setcolor (normal_color, highlight_color); +} + +/* Turn on/off the cursor. */ +static inline void +grub_term_setcursor (struct grub_term_output *term, int on) +{ + if (term->setcursor) + term->setcursor (on); +} + +static inline int +grub_term_is_active (struct grub_term_output *term) +{ + return !!(term->flags & GRUB_TERM_ACTIVE); +} + +static inline grub_ssize_t +grub_term_getcharwidth (struct grub_term_output *term, grub_uint32_t c) +{ + if (term->getcharwidth) + return term->getcharwidth (c); + else + return 1; +} + +static inline void +grub_term_getcolor (struct grub_term_output *term, + grub_uint8_t *normal_color, grub_uint8_t *highlight_color) +{ + term->getcolor (normal_color, highlight_color); +} + +extern void (*EXPORT_VAR (grub_newline_hook)) (void); + /* For convenience. */ #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff) diff --git a/kern/misc.c b/kern/misc.c index 7dd9bd18a..ef782f5dd 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -882,10 +882,10 @@ grub_sprintf (char *str, const char *fmt, ...) /* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string. Return the number of characters converted. DEST must be able to hold - at least DESTSIZE characters. If an invalid sequence is found, return -1. + at least DESTSIZE characters. If SRCEND is not NULL, then *SRCEND is set to the next byte after the last byte used in SRC. */ -grub_ssize_t +grub_size_t grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, const grub_uint8_t *src, grub_size_t srcsize, const grub_uint8_t **srcend) @@ -907,7 +907,8 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, if ((c & 0xc0) != 0x80) { /* invalid */ - return -1; + code = '?'; + count = 0; } else { @@ -949,7 +950,11 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize, code = c & 0x01; } else - return -1; + { + /* invalid */ + code = '?'; + count = 0; + } } if (count == 0) diff --git a/kern/term.c b/kern/term.c index 35660273e..b71c12334 100644 --- a/kern/term.c +++ b/kern/term.c @@ -31,13 +31,15 @@ struct grub_handler_class grub_term_input_class = struct grub_term_output *grub_term_outputs; +void (*grub_newline_hook) (void) = NULL; + /* Put a Unicode character. */ void grub_putcode (grub_uint32_t code, struct grub_term_output *term) { int height; - height = term->getwh () & 255; + height = grub_term_height (term); if (code == '\t' && term->getxy) { @@ -50,6 +52,8 @@ grub_putcode (grub_uint32_t code, struct grub_term_output *term) return; } + if (code == '\n') + (term->putchar) ('\r'); (term->putchar) (code); } @@ -68,7 +72,7 @@ grub_putchar (int c) { struct grub_term_output *term = (struct grub_term_output *) item; - if (term->flags & GRUB_TERM_ACTIVE) + if (grub_term_is_active (term)) grub_putcode (code, term); return 0; @@ -77,14 +81,13 @@ grub_putchar (int c) buf[size++] = c; ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0); - if (ret < 0) - code = '?'; - if (ret != 0) { size = 0; grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), do_putcode); } + if (ret == '\n' && grub_newline_hook) + grub_newline_hook (); } int @@ -116,7 +119,7 @@ grub_cls (void) { struct grub_term_output *term = (struct grub_term_output *) item; - if (!(term->flags & GRUB_TERM_ACTIVE)) + if (! grub_term_is_active (term)) return 0; if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) @@ -141,11 +144,10 @@ grub_setcolorstate (grub_term_color_state state) { struct grub_term_output *term = (struct grub_term_output *) item; - if (!(term->flags & GRUB_TERM_ACTIVE)) + if (! grub_term_is_active (term)) return 0; - if (term->setcolorstate) - (term->setcolorstate) (state); + grub_term_setcolorstate (term, state); return 0; } @@ -161,11 +163,10 @@ grub_refresh (void) { struct grub_term_output *term = (struct grub_term_output *) item; - if (!(term->flags & GRUB_TERM_ACTIVE)) + if (!grub_term_is_active (term)) return 0; - if (term->refresh) - (term->refresh) (); + grub_term_refresh (term); return 0; } diff --git a/lib/charset.c b/lib/charset.c index 0f2c2c8ee..f2e1b036d 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -24,6 +24,8 @@ last byte used in SRC. */ #include +#include +#include grub_ssize_t grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize, @@ -176,5 +178,92 @@ grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size) } *dest = 0; - return ret; + return (char *) ret; +} + +int +grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize) +{ + grub_uint32_t code = 0; + int count = 0; + + while (srcsize) + { + grub_uint32_t c = *src++; + if (srcsize != (grub_size_t)-1) + srcsize--; + if (count) + { + if ((c & 0xc0) != 0x80) + { + /* invalid */ + return 0; + } + else + { + code <<= 6; + code |= (c & 0x3f); + count--; + } + } + else + { + if (c == 0) + break; + + if ((c & 0x80) == 0x00) + code = c; + else if ((c & 0xe0) == 0xc0) + { + count = 1; + code = c & 0x1f; + } + else if ((c & 0xf0) == 0xe0) + { + count = 2; + code = c & 0x0f; + } + else if ((c & 0xf8) == 0xf0) + { + count = 3; + code = c & 0x07; + } + else if ((c & 0xfc) == 0xf8) + { + count = 4; + code = c & 0x03; + } + else if ((c & 0xfe) == 0xfc) + { + count = 5; + code = c & 0x01; + } + else + return 0; + } + } + + return 1; +} + +int +grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, + grub_uint32_t **last_position) +{ + grub_size_t msg_len = grub_strlen (msg); + + *unicode_msg = grub_malloc (grub_strlen (msg) * sizeof (grub_uint32_t)); + + if (!*unicode_msg) + { + grub_printf ("utf8_to_ucs4 ERROR1: %s", msg); + return -1; + } + + msg_len = grub_utf8_to_ucs4 (*unicode_msg, msg_len, + (grub_uint8_t *) msg, -1, 0); + + *last_position = *unicode_msg + msg_len; + + return msg_len; } diff --git a/normal/auth.c b/normal/auth.c index 240a77aee..156b84c37 100644 --- a/normal/auth.c +++ b/normal/auth.c @@ -154,6 +154,49 @@ is_authenticated (const char *userlist) return grub_list_iterate (GRUB_AS_LIST (users), hook); } +static int +grub_username_get (char buf[], unsigned buf_size) +{ + unsigned cur_len = 0; + int key; + + while (1) + { + key = GRUB_TERM_ASCII_CHAR (grub_getkey ()); + if (key == '\n' || key == '\r') + break; + + if (key == '\e') + { + cur_len = 0; + break; + } + + if (key == '\b') + { + cur_len--; + grub_printf ("\b"); + continue; + } + + if (!grub_isprint (key)) + continue; + + if (cur_len + 2 < buf_size) + { + buf[cur_len++] = key; + grub_putchar (key); + } + } + + grub_memset (buf + cur_len, 0, buf_size - cur_len); + + grub_putchar ('\n'); + grub_refresh (); + + return (key != '\e'); +} + grub_err_t grub_auth_check_authentication (const char *userlist) { @@ -187,11 +230,12 @@ grub_auth_check_authentication (const char *userlist) return GRUB_ERR_NONE; } - if (!grub_cmdline_get (N_("Enter username:"), login, sizeof (login) - 1, - 0, 0, 0)) + grub_puts_ (N_("Enter username: ")); + + if (!grub_username_get (login, sizeof (login) - 1)) goto access_denied; - grub_printf ("Enter password: "); + grub_puts_ (N_("Enter password: ")); if (!grub_password_get (entered, GRUB_AUTH_MAX_PASSLEN)) goto access_denied; diff --git a/normal/cmdline.c b/normal/cmdline.c index c104709c5..1412a6d6a 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -27,6 +27,7 @@ #include #include #include +#include static grub_uint32_t *kill_buf; @@ -211,11 +212,12 @@ struct cmdline_term otherwise return command line. */ /* FIXME: The dumb interface is not supported yet. */ char * -grub_cmdline_get (const char *prompt, unsigned max_len) +grub_cmdline_get (const char *prompt) { grub_size_t lpos, llen; grub_size_t plen; - grub_uint32_t buf[max_len]; + grub_uint32_t *buf; + grub_size_t max_len = 256; int key; int histpos = 0; auto void cl_insert (const grub_uint32_t *str); @@ -226,13 +228,14 @@ grub_cmdline_get (const char *prompt, unsigned max_len) auto void cl_set_pos_all (void); const char *prompt_translated = _(prompt); struct cmdline_term *cl_terms; + char *ret; unsigned nterms; void cl_set_pos (struct cmdline_term *cl_term) { cl_term->xpos = (plen + lpos) % (cl_term->width - 1); cl_term->ypos = cl_term->ystart + (plen + lpos) / (cl_term->width - 1); - cl_term->term->gotoxy (cl_term->xpos, cl_term->ypos); + grub_term_gotoxy (cl_term->term, cl_term->xpos, cl_term->ypos); } void cl_set_pos_all () @@ -246,7 +249,7 @@ grub_cmdline_get (const char *prompt, unsigned max_len) { grub_uint32_t *p; - for (p = buf + pos; *p; p++) + for (p = buf + pos; p < buf + llen; p++) { if (cl_term->xpos++ > cl_term->width - 2) { @@ -277,14 +280,30 @@ grub_cmdline_get (const char *prompt, unsigned max_len) { grub_size_t len = strlen_ucs4 (str); + if (len + llen >= max_len) + { + grub_uint32_t *nbuf; + max_len *= 2; + nbuf = grub_realloc (buf, sizeof (grub_uint32_t) * max_len); + if (nbuf) + buf = nbuf; + else + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + max_len /= 2; + } + } + if (len + llen < max_len) { - grub_memmove (buf + lpos + len, buf + lpos, llen - lpos + 1); - grub_memmove (buf + lpos, str, len); + grub_memmove (buf + lpos + len, buf + lpos, + (llen - lpos + 1) * sizeof (grub_uint32_t)); + grub_memmove (buf + lpos, str, len * sizeof (grub_uint32_t)); llen += len; lpos += len; - cl_print_all (lpos - len, echo_char); + cl_print_all (lpos - len, 0); cl_set_pos_all (); } @@ -305,7 +324,7 @@ grub_cmdline_get (const char *prompt, unsigned max_len) grub_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1); llen -= len; - cl_print_all (lpos, echo_char); + cl_print_all (lpos, 0); cl_set_pos_all (); } @@ -315,7 +334,7 @@ grub_cmdline_get (const char *prompt, unsigned max_len) void init_clterm (struct cmdline_term *cl_term_cur) { cl_term_cur->xpos = plen; - cl_term_cur->ypos = (cl_term_cur->term->getxy () & 0xFF); + cl_term_cur->ypos = (grub_term_getxy (cl_term_cur->term) & 0xFF); cl_term_cur->ystart = cl_term_cur->ypos; cl_term_cur->width = grub_term_width (cl_term_cur->term); cl_term_cur->height = grub_term_height (cl_term_cur->term); @@ -328,6 +347,10 @@ grub_cmdline_get (const char *prompt, unsigned max_len) init_clterm (&cl_terms[i]); } + buf = grub_malloc (max_len * sizeof (grub_uint32_t)); + if (!buf) + return 0; + plen = grub_strlen (prompt_translated); lpos = llen = 0; buf[0] = '\0'; @@ -341,15 +364,15 @@ grub_cmdline_get (const char *prompt, unsigned max_len) struct grub_term_output *cur; nterms = 0; for (cur = grub_term_outputs; cur; cur = cur->next) - if (cur->flags & GRUB_TERM_ACTIVE) + if (grub_term_is_active (cur)) nterms++; cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); if (!cl_terms) - return grub_errno; + return 0; cl_term_cur = cl_terms; for (cur = grub_term_outputs; cur; cur = cur->next) - if (cur->flags & GRUB_TERM_ACTIVE) + if (grub_term_is_active (cur)) { cl_term_cur->term = cur; init_clterm (cl_term_cur); @@ -357,7 +380,7 @@ grub_cmdline_get (const char *prompt, unsigned max_len) } } - if (history && hist_used == 0) + if (hist_used == 0) grub_history_add (buf); while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r') @@ -394,17 +417,38 @@ grub_cmdline_get (const char *prompt, unsigned max_len) { grub_uint32_t *insert; int restore; + char *bufu8, *insertu8; + grub_size_t insertlen; + grub_size_t t; - /* Backup the next character and make it 0 so it will - be easy to use string functions. */ - char backup = buf[lpos]; buf[lpos] = '\0'; + bufu8 = grub_ucs4_to_utf8_alloc (buf, lpos); + if (!bufu8) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + break; + } - insert = grub_normal_do_completion (buf, &restore, - print_completion); - /* Restore the original string. */ - buf[lpos] = backup; + insertu8 = grub_normal_do_completion (bufu8, &restore, + print_completion); + grub_free (bufu8); + insertlen = grub_strlen (bufu8); + insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); + if (!insert) + { + grub_free (insertu8); + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + break; + } + t = grub_utf8_to_ucs4 (insert, insertlen, + (grub_uint8_t *) insertu8, + insertlen, 0); + insert[t] = 0; + + grub_free (insertu8); if (restore) { @@ -429,7 +473,11 @@ grub_cmdline_get (const char *prompt, unsigned max_len) grub_free (kill_buf); kill_buf = strdup_ucs4 (buf + lpos); - grub_errno = GRUB_ERR_NONE; + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } cl_delete (llen - lpos); } @@ -481,7 +529,11 @@ grub_cmdline_get (const char *prompt, unsigned max_len) grub_free (kill_buf); kill_buf = grub_malloc (n + 1); - grub_errno = GRUB_ERR_NONE; + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } if (kill_buf) { grub_memcpy (kill_buf, buf, n); @@ -538,16 +590,15 @@ grub_cmdline_get (const char *prompt, unsigned max_len) while (buf[lpos] == ' ') lpos++; - if (history) + histpos = 0; + if (strlen_ucs4 (buf) > 0) { - histpos = 0; - if (strlen_ucs4 (buf) > 0) - { - grub_uint32_t empty[] = { 0 }; - grub_history_replace (histpos, buf); - grub_history_add (empty); - } + grub_uint32_t empty[] = { 0 }; + grub_history_replace (histpos, buf); + grub_history_add (empty); } - return grub_ucs4_to_utf8_alloc (buf + lpos, llen - lpos + 1); + ret = grub_ucs4_to_utf8_alloc (buf + lpos, llen - lpos + 1); + grub_free (buf); + return ret; } diff --git a/normal/color.c b/normal/color.c index 63bd889a5..80a285787 100644 --- a/normal/color.c +++ b/normal/color.c @@ -112,16 +112,14 @@ set_colors (void) for (term = grub_term_outputs; term; term = term->next) { - if (! (term->flags & GRUB_TERM_ACTIVE)) + if (! grub_term_is_active (term)) continue; /* Reloads terminal `normal' and `highlight' colors. */ - if (term->setcolor) - term->setcolor (color_normal, color_highlight); + grub_term_setcolor (term, color_normal, color_highlight); /* Propagates `normal' color to terminal current color. */ - if (term->setcolorstate) - term->setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); } } diff --git a/normal/main.c b/normal/main.c index 0dab9e09e..b490f49e5 100644 --- a/normal/main.c +++ b/normal/main.c @@ -30,6 +30,7 @@ #include #include #include +#include #define GRUB_DEFAULT_HISTORY_SIZE 50 @@ -420,11 +421,11 @@ grub_normal_init_page (struct grub_term_output *term) return; } - posx = grub_getstringwidth (unicode_msg, last_position); + posx = grub_getstringwidth (unicode_msg, last_position, term); posx = (grub_term_width (term) - posx) / 2; - term->gotoxy (posx, 1); + grub_term_gotoxy (term, posx, 1); - grub_print_ucs4 (unicode_msg, last_position); + grub_print_ucs4 (unicode_msg, last_position, term); grub_printf("\n\n"); grub_free (unicode_msg); } @@ -458,7 +459,7 @@ grub_normal_execute (const char *config, int nested, int batch) { if (menu && menu->size) { - grub_menu_viewer_show_menu (menu, nested); + grub_show_menu (menu, nested); if (nested) free_menu (menu); } @@ -470,20 +471,19 @@ void grub_enter_normal_mode (const char *config) { grub_normal_execute (config, 0, 0); + grub_cmdline_run (1); } /* Enter normal mode from rescue mode. */ static grub_err_t -grub_cmd_normal (struct grub_command *cmd, +grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { - grub_unregister_command (cmd); - if (argc == 0) { /* Guess the config filename. It is necessary to make CONFIG static, so that it won't get broken by longjmp. */ - static char *config; + char *config; const char *prefix; prefix = grub_env_get ("prefix"); @@ -525,10 +525,9 @@ grub_normal_reader_init (void) if (! (term->flags & GRUB_TERM_ACTIVE)) continue; grub_normal_init_page (term); - if (term->setcursor) - term->setcursor (1); + grub_term_setcursor (term, 1); - grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN); + grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); grub_puts ("\n"); } grub_free (msg_formatted); @@ -536,7 +535,6 @@ grub_normal_reader_init (void) return 0; } -static char cmdline[GRUB_MAX_CMDLINE]; static grub_err_t grub_normal_read_line (char **line, int cont) @@ -548,18 +546,18 @@ grub_normal_read_line (char **line, int cont) while (1) { - cmdline[0] = 0; - if (grub_cmdline_get (prompt, cmdline, sizeof (cmdline), 0, 1, 1)) + *line = grub_cmdline_get (prompt); + if (*line) break; if ((reader_nested) || (cont)) { + grub_free (*line); *line = 0; return grub_errno; } } - *line = grub_strdup (cmdline); return 0; } @@ -591,7 +589,7 @@ grub_cmdline_run (int nested) grub_normal_read_line (&line, 0); if (! line) - continue; + break; grub_parser_get_current ()->parse_line (line, grub_normal_read_line); grub_free (line); @@ -612,15 +610,20 @@ GRUB_MOD_INIT(normal) if (mod) grub_dl_ref (mod); - grub_menu_viewer_register (&grub_normal_text_menu_viewer); - grub_set_history (GRUB_DEFAULT_HISTORY_SIZE); + grub_menu_register_viewer_init (grub_menu_text_register_instances); + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + grub_register_variable_hook ("pager", 0, grub_env_write_pager); /* Register a command "normal" for the rescue mode. */ - grub_register_command_prio ("normal", grub_cmd_normal, - 0, "Enter normal mode", 0); + grub_register_command ("normal", grub_cmd_normal, + 0, "Enter normal mode"); /* Reload terminal colors when these variables are written to. */ grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal); diff --git a/normal/menu.c b/normal/menu.c index 8ee7d1c22..824779db6 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -27,6 +27,30 @@ #include #include #include +#include + +/* Time to delay after displaying an error message about a default/fallback + entry failing to boot. */ +#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500 + +struct menu_run_callback +{ + struct menu_run_callback *next; + void (*hook) (int entry, grub_menu_t menu, int nested); +}; + +struct menu_run_callback *callbacks = NULL; + +/* Wait until the user pushes any key so that the user + can see what happened. */ +void +grub_wait_after_message (void) +{ + grub_putchar ('\n'); + grub_printf_ (N_("Press any key to continue...")); + (void) grub_getkey (); + grub_putchar ('\n'); +} /* Get a menu entry by its index in the entry list. */ grub_menu_entry_t @@ -178,3 +202,364 @@ grub_menu_execute_with_fallback (grub_menu_t menu, callback->notify_failure (callback_data); } + +static struct grub_menu_viewer *viewers; + +static void +menu_set_chosen_entry (int entry) +{ + struct grub_menu_viewer *cur; + for (cur = viewers; cur; cur = cur->next) + cur->set_chosen_entry (entry, cur->data); +} + +static void +menu_print_timeout (int timeout) +{ + struct grub_menu_viewer *cur; + for (cur = viewers; cur; cur = cur->next) + cur->print_timeout (timeout, cur->data); +} + +static void +menu_fini (void) +{ + struct grub_menu_viewer *cur, *next; + for (cur = viewers; cur; cur = next) + { + next = cur->next; + cur->fini (cur->data); + grub_free (cur); + } + viewers = NULL; +} + +static void +menu_init (int entry, grub_menu_t menu, int nested) +{ + struct menu_run_callback *cb; + for (cb = callbacks; cb; cb = cb->next) + cb->hook (entry, menu, nested); +} + +static void +clear_timeout (void) +{ + struct grub_menu_viewer *cur; + for (cur = viewers; cur; cur = cur->next) + cur->clear_timeout (cur->data); +} + +void +grub_menu_register_viewer (struct grub_menu_viewer *viewer) +{ + viewer->next = viewers; + viewers = viewer; +} + +grub_err_t +grub_menu_register_viewer_init (void (*callback) (int entry, grub_menu_t menu, + int nested)) +{ + struct menu_run_callback *cb; + cb = grub_malloc (sizeof (*cb)); + if (!cb) + return grub_errno; + cb->hook = callback; + cb->next = callbacks; + callbacks = cb; + return GRUB_ERR_NONE; +} + +/* Get the entry number from the variable NAME. */ +static int +get_entry_number (const char *name) +{ + char *val; + int entry; + + val = grub_env_get (name); + if (! val) + return -1; + + grub_error_push (); + + entry = (int) grub_strtoul (val, 0, 0); + + if (grub_errno != GRUB_ERR_NONE) + { + grub_errno = GRUB_ERR_NONE; + entry = -1; + } + + grub_error_pop (); + + return entry; +} + +#define GRUB_MENU_PAGE_SIZE 10 + +/* Show the menu and handle menu entry selection. Returns the menu entry + index that should be executed or -1 if no entry should be executed (e.g., + Esc pressed to exit a sub-menu or switching menu viewers). + If the return value is not -1, then *AUTO_BOOT is nonzero iff the menu + entry to be executed is a result of an automatic default selection because + of the timeout. */ +static int +run_menu (grub_menu_t menu, int nested, int *auto_boot) +{ + grub_uint64_t saved_time; + int default_entry, current_entry; + int timeout; + + default_entry = get_entry_number ("default"); + + /* If DEFAULT_ENTRY is not within the menu entries, fall back to + the first entry. */ + if (default_entry < 0 || default_entry >= menu->size) + default_entry = 0; + + /* If timeout is 0, drawing is pointless (and ugly). */ + if (grub_menu_get_timeout () == 0) + { + *auto_boot = 1; + return default_entry; + } + + current_entry = default_entry; + + /* Initialize the time. */ + saved_time = grub_get_time_ms (); + + refresh: + menu_init (current_entry, menu, nested); + + timeout = grub_menu_get_timeout (); + + if (timeout > 0) + menu_print_timeout (timeout); + + while (1) + { + int c; + timeout = grub_menu_get_timeout (); + + if (timeout > 0) + { + grub_uint64_t current_time; + + current_time = grub_get_time_ms (); + if (current_time - saved_time >= 1000) + { + timeout--; + grub_menu_set_timeout (timeout); + saved_time = current_time; + menu_print_timeout (timeout); + } + } + + if (timeout == 0) + { + grub_env_unset ("timeout"); + *auto_boot = 1; + menu_fini (); + return default_entry; + } + + if (grub_checkkey () >= 0 || timeout < 0) + { + c = GRUB_TERM_ASCII_CHAR (grub_getkey ()); + + if (timeout >= 0) + { + grub_env_unset ("timeout"); + grub_env_unset ("fallback"); + clear_timeout (); + } + + switch (c) + { + case GRUB_TERM_HOME: + current_entry = 0; + menu_set_chosen_entry (current_entry); + break; + + case GRUB_TERM_END: + current_entry = menu->size - 1; + menu_set_chosen_entry (current_entry); + break; + + case GRUB_TERM_UP: + case '^': + current_entry--; + menu_set_chosen_entry (current_entry); + break; + + case GRUB_TERM_DOWN: + case 'v': + current_entry++; + menu_set_chosen_entry (current_entry); + break; + + case GRUB_TERM_PPAGE: + if (current_entry < GRUB_MENU_PAGE_SIZE) + current_entry = 0; + else + current_entry -= GRUB_MENU_PAGE_SIZE; + menu_set_chosen_entry (current_entry); + break; + + case GRUB_TERM_NPAGE: + if (current_entry + GRUB_MENU_PAGE_SIZE < menu->size) + current_entry = 0; + else + current_entry += GRUB_MENU_PAGE_SIZE; + menu_set_chosen_entry (current_entry); + break; + + case '\n': + case '\r': + case 6: + menu_fini (); + *auto_boot = 0; + return current_entry; + + case '\e': + if (nested) + { + menu_fini (); + return -1; + } + break; + + case 'c': + grub_cmdline_run (1); + goto refresh; + + case 'e': + { + grub_menu_entry_t e = grub_menu_get_entry (menu, current_entry); + if (e) + grub_menu_entry_run (e); + } + goto refresh; + + default: + break; + } + } + } + + /* Never reach here. */ + return -1; +} + +/* Callback invoked immediately before a menu entry is executed. */ +static void +notify_booting (grub_menu_entry_t entry, + void *userdata __attribute__((unused))) +{ + grub_printf (" "); + grub_printf_ (N_("Booting \'%s\'"), entry->title); + grub_printf ("\n\n"); +} + +/* Callback invoked when a default menu entry executed because of a timeout + has failed and an attempt will be made to execute the next fallback + entry, ENTRY. */ +static void +notify_fallback (grub_menu_entry_t entry, + void *userdata __attribute__((unused))) +{ + grub_printf ("\n "); + grub_printf_ (N_("Falling back to \'%s\'"), entry->title); + grub_printf ("\n\n"); + grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); +} + +/* Callback invoked when a menu entry has failed and there is no remaining + fallback entry to attempt. */ +static void +notify_execution_failure (void *userdata __attribute__((unused))) +{ + if (grub_errno != GRUB_ERR_NONE) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + grub_printf ("\n "); + grub_printf_ (N_("Failed to boot default entries.\n")); + grub_wait_after_message (); +} + +/* Callbacks used by the text menu to provide user feedback when menu entries + are executed. */ +static struct grub_menu_execute_callback execution_callback = +{ + .notify_booting = notify_booting, + .notify_fallback = notify_fallback, + .notify_failure = notify_execution_failure +}; + +static grub_err_t +show_menu (grub_menu_t menu, int nested) +{ + while (1) + { + int boot_entry; + grub_menu_entry_t e; + int auto_boot; + + boot_entry = run_menu (menu, nested, &auto_boot); + if (boot_entry < 0) + break; + + e = grub_menu_get_entry (menu, boot_entry); + if (! e) + continue; /* Menu is empty. */ + + grub_cls (); + + if (auto_boot) + { + grub_menu_execute_with_fallback (menu, e, &execution_callback, 0); + } + else + { + grub_errno = GRUB_ERR_NONE; + grub_menu_execute_entry (e); + if (grub_errno != GRUB_ERR_NONE) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + grub_wait_after_message (); + } + } + } + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_show_menu (grub_menu_t menu, int nested) +{ + grub_err_t err1, err2; + + while (1) + { + err1 = show_menu (menu, nested); + grub_print_error (); + + err2 = grub_auth_check_authentication (NULL); + if (err2) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + continue; + } + + break; + } + + return err1; +} diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 7a31c27af..da4eff496 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -43,6 +43,15 @@ struct line int max_len; }; +struct per_term_screen +{ + struct grub_term_output *term; + /* The X coordinate. */ + int x; + /* The Y coordinate. */ + int y; +}; + struct screen { /* The array of lines. */ @@ -55,18 +64,18 @@ struct screen int real_column; /* The current line. */ int line; - /* The X coordinate. */ - int x; - /* The Y coordinate. */ - int y; /* The kill buffer. */ char *killed_text; /* The flag of a completion window. */ int completion_shown; + + struct per_term_screen *terms; + unsigned nterms; }; /* Used for storing completion items temporarily. */ static struct line completion_buffer; +static int completion_type; /* Initialize a line. */ static int @@ -98,77 +107,88 @@ ensure_space (struct line *linep, int extra) /* Return the number of lines occupied by this line on the screen. */ static int -get_logical_num_lines (struct line *linep) +get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) { - return (linep->len / GRUB_TERM_ENTRY_WIDTH) + 1; + return (linep->len / grub_term_entry_width (term_screen->term)) + 1; } /* Print a line. */ static void -print_line (struct line *linep, int offset, int start, int y) +print_line (struct line *linep, int offset, int start, int y, + struct per_term_screen *term_screen) { - int i; - char *p; + grub_term_gotoxy (term_screen->term, + GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + start + 1, + y + GRUB_TERM_FIRST_ENTRY_Y); - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + start + 1, - y + GRUB_TERM_FIRST_ENTRY_Y); - - for (p = linep->buf + offset + start, i = start; - i < GRUB_TERM_ENTRY_WIDTH && offset + i < linep->len; - p++, i++) - grub_putchar (*p); - - for (; i < GRUB_TERM_ENTRY_WIDTH; i++) - grub_putchar (' '); - - if (linep->len >= offset + GRUB_TERM_ENTRY_WIDTH) - grub_putchar ('\\'); + if (linep->len >= offset + grub_term_entry_width (term_screen->term)) + { + char *p, c; + p = linep->buf + offset + start + + grub_term_entry_width (term_screen->term); + c = *p; + *p = 0; + grub_puts_terminal (linep->buf + offset + start, term_screen->term); + *p = c; + grub_putcode ('\\', term_screen->term); + } else - grub_putchar (' '); + { + int i; + for (i = 0; + i <= grub_term_entry_width (term_screen->term) - linep->len + offset; + i++) + grub_putcode (' ', term_screen->term); + } } /* Print an empty line. */ static void -print_empty_line (int y) +print_empty_line (int y, struct per_term_screen *term_screen) { int i; - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, - y + GRUB_TERM_FIRST_ENTRY_Y); + grub_term_gotoxy (term_screen->term, + GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, + y + GRUB_TERM_FIRST_ENTRY_Y); - for (i = 0; i < GRUB_TERM_ENTRY_WIDTH + 1; i++) - grub_putchar (' '); + for (i = 0; i < grub_term_entry_width (term_screen->term) + 1; i++) + grub_putcode (' ', term_screen->term); } /* Print an up arrow. */ static void -print_up (int flag) +print_up (int flag, struct per_term_screen *term_screen) { - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH, - GRUB_TERM_FIRST_ENTRY_Y); + grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X + + grub_term_entry_width (term_screen->term), + GRUB_TERM_FIRST_ENTRY_Y); if (flag) - grub_putcode (GRUB_TERM_DISP_UP); + grub_putcode (GRUB_TERM_DISP_UP, term_screen->term); else - grub_putchar (' '); + grub_putcode (' ', term_screen->term); } /* Print a down arrow. */ static void -print_down (int flag) +print_down (int flag, struct per_term_screen *term_screen) { - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH, - GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES); + grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X + + grub_term_border_width (term_screen->term), + GRUB_TERM_TOP_BORDER_Y + + grub_term_num_entries (term_screen->term)); if (flag) - grub_putcode (GRUB_TERM_DISP_DOWN); + grub_putcode (GRUB_TERM_DISP_DOWN, term_screen->term); else - grub_putchar (' '); + grub_putcode (' ', term_screen->term); } /* Draw the lines of the screen SCREEN. */ static void -update_screen (struct screen *screen, int region_start, int region_column, +update_screen (struct screen *screen, struct per_term_screen *term_screen, + int region_start, int region_column, int up, int down, enum update_mode mode) { int up_flag = 0; @@ -178,12 +198,13 @@ update_screen (struct screen *screen, int region_start, int region_column, struct line *linep; /* Check if scrolling is necessary. */ - if (screen->y < 0 || screen->y >= GRUB_TERM_NUM_ENTRIES) + if (term_screen->y < 0 || term_screen->y + >= grub_term_num_entries (term_screen->term)) { - if (screen->y < 0) - screen->y = 0; + if (term_screen->y < 0) + term_screen->y = 0; else - screen->y = GRUB_TERM_NUM_ENTRIES - 1; + term_screen->y = grub_term_num_entries (term_screen->term) - 1; region_start = 0; region_column = 0; @@ -196,14 +217,15 @@ update_screen (struct screen *screen, int region_start, int region_column, { /* Draw lines. This code is tricky, because this must calculate logical positions. */ - y = screen->y - screen->column / GRUB_TERM_ENTRY_WIDTH; + y = term_screen->y - screen->column + / grub_term_entry_width (term_screen->term); i = screen->line; linep = screen->lines + i; while (y > 0) { i--; linep--; - y -= get_logical_num_lines (linep); + y -= get_logical_num_lines (linep, term_screen); } if (y < 0 || i > 0) @@ -214,8 +236,9 @@ update_screen (struct screen *screen, int region_start, int region_column, int column; for (column = 0; - column <= linep->len && y < GRUB_TERM_NUM_ENTRIES; - column += GRUB_TERM_ENTRY_WIDTH, y++) + column <= linep->len + && y < grub_term_num_entries (term_screen->term); + column += grub_term_entry_width (term_screen->term), y++) { if (y < 0) continue; @@ -223,16 +246,19 @@ update_screen (struct screen *screen, int region_start, int region_column, if (i == region_start) { if (region_column >= column - && region_column < column + GRUB_TERM_ENTRY_WIDTH) - print_line (linep, column, region_column - column, y); + && region_column + < (column + + grub_term_entry_width (term_screen->term))) + print_line (linep, column, region_column - column, y, + term_screen); else if (region_column < column) - print_line (linep, column, 0, y); + print_line (linep, column, 0, y, term_screen); } else if (i > region_start && mode == ALL_LINES) - print_line (linep, column, 0, y); + print_line (linep, column, 0, y, term_screen); } - if (y == GRUB_TERM_NUM_ENTRIES) + if (y == grub_term_num_entries (term_screen->term)) { if (column <= linep->len || i + 1 < screen->num_lines) down_flag = 1; @@ -242,35 +268,53 @@ update_screen (struct screen *screen, int region_start, int region_column, i++; if (mode == ALL_LINES && i == screen->num_lines) - for (; y < GRUB_TERM_NUM_ENTRIES; y++) - print_empty_line (y); + for (; y < grub_term_num_entries (term_screen->term); y++) + print_empty_line (y, term_screen); } - while (y < GRUB_TERM_NUM_ENTRIES); + while (y < grub_term_num_entries (term_screen->term)); /* Draw up and down arrows. */ if (up) - print_up (up_flag); + print_up (up_flag, term_screen); if (down) - print_down (down_flag); + print_down (down_flag, term_screen); } /* Place the cursor. */ - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1 + screen->x, - GRUB_TERM_FIRST_ENTRY_Y + screen->y); + grub_term_gotoxy (term_screen->term, + GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1 + + term_screen->x, + GRUB_TERM_FIRST_ENTRY_Y + term_screen->y); - grub_refresh (); + grub_term_refresh (term_screen->term); +} + +static void +update_screen_all (struct screen *screen, + int region_start, int region_column, + int up, int down, enum update_mode mode) +{ + unsigned i; + for (i = 0; i < screen->nterms; i++) + update_screen (screen, &screen->terms[i], region_start, region_column, + up, down, mode); } -/* Insert the string S into the screen SCREEN. This updates the cursor - position and redraw the screen. Return zero if fails. */ static int insert_string (struct screen *screen, char *s, int update) { int region_start = screen->num_lines; int region_column = 0; - int down = 0; - enum update_mode mode = NO_LINE; + int down[screen->nterms]; + enum update_mode mode[screen->nterms]; + unsigned i; + + for (i = 0; i < screen->nterms; i++) + { + down[i] = 0; + mode[i] = NO_LINE; + } while (*s) { @@ -319,15 +363,20 @@ insert_string (struct screen *screen, char *s, int update) region_column = screen->column; } - mode = ALL_LINES; - down = 1; /* XXX not optimal. */ + for (i = 0; i < screen->nterms; i++) + { + mode[i] = ALL_LINES; + down[i] = 1; /* XXX not optimal. */ + } /* Move the cursor. */ screen->column = screen->real_column = 0; screen->line++; - screen->x = 0; - screen->y++; - + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x = 0; + screen->terms[i].y++; + } s++; } else @@ -336,7 +385,7 @@ insert_string (struct screen *screen, char *s, int update) char *p; struct line *current_linep; int size; - int orig_num, new_num; + int orig_num[screen->nterms], new_num[screen->nterms]; /* Find a string delimited by LF. */ p = grub_strchr (s, '\n'); @@ -355,9 +404,13 @@ insert_string (struct screen *screen, char *s, int update) grub_memmove (current_linep->buf + screen->column, s, size); - orig_num = get_logical_num_lines (current_linep); + for (i = 0; i < screen->nterms; i++) + orig_num[i] = get_logical_num_lines (current_linep, + &screen->terms[i]); current_linep->len += size; - new_num = get_logical_num_lines (current_linep); + for (i = 0; i < screen->nterms; i++) + new_num[i] = get_logical_num_lines (current_linep, + &screen->terms[i]); /* Update the dirty region. */ if (region_start > screen->line) @@ -366,27 +419,34 @@ insert_string (struct screen *screen, char *s, int update) region_column = screen->column; } - if (orig_num != new_num) - { - mode = ALL_LINES; - down = 1; /* XXX not optimal. */ - } - else if (mode != ALL_LINES) - mode = SINGLE_LINE; + for (i = 0; i < screen->nterms; i++) + if (orig_num[i] != new_num[i]) + { + mode[i] = ALL_LINES; + down[i] = 1; /* XXX not optimal. */ + } + else if (mode[i] != ALL_LINES) + mode[i] = SINGLE_LINE; /* Move the cursor. */ screen->column += size; screen->real_column = screen->column; - screen->x += size; - screen->y += screen->x / GRUB_TERM_ENTRY_WIDTH; - screen->x %= GRUB_TERM_ENTRY_WIDTH; - + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x += size; + screen->terms[i].y += screen->terms[i].x + / grub_term_entry_width (screen->terms[i].term); + screen->terms[i].x + %= grub_term_entry_width (screen->terms[i].term); + } s = p; } } if (update) - update_screen (screen, region_start, region_column, 0, down, mode); + for (i = 0; i < screen->nterms; i++) + update_screen (screen, &screen->terms[i], + region_start, region_column, 0, down[i], mode[i]); return 1; } @@ -408,6 +468,7 @@ destroy_screen (struct screen *screen) grub_free (screen->killed_text); grub_free (screen->lines); + grub_free (screen->terms); grub_free (screen); } @@ -416,6 +477,7 @@ static struct screen * make_screen (grub_menu_entry_t entry) { struct screen *screen; + unsigned i; /* Initialize the screen. */ screen = grub_zalloc (sizeof (*screen)); @@ -437,8 +499,11 @@ make_screen (grub_menu_entry_t entry) screen->column = 0; screen->real_column = 0; screen->line = 0; - screen->x = 0; - screen->y = 0; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x = 0; + screen->terms[i].y = 0; + } return screen; @@ -451,44 +516,58 @@ static int forward_char (struct screen *screen, int update) { struct line *linep; + unsigned i; linep = screen->lines + screen->line; if (screen->column < linep->len) { screen->column++; - screen->x++; - if (screen->x == GRUB_TERM_ENTRY_WIDTH) + for (i = 0; i < screen->nterms; i++) { - screen->x = 0; - screen->y++; + screen->terms[i].x++; + if (screen->terms[i].x + == grub_term_entry_width (screen->terms[i].term)) + { + screen->terms[i].x = 0; + screen->terms[i].y++; + } } } else if (screen->num_lines > screen->line + 1) { screen->column = 0; screen->line++; - screen->x = 0; - screen->y++; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x = 0; + screen->terms[i].y++; + } } screen->real_column = screen->column; if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } static int backward_char (struct screen *screen, int update) { + unsigned i; + if (screen->column > 0) { screen->column--; - screen->x--; - if (screen->x == -1) + for (i = 0; i < screen->nterms; i++) { - screen->x = GRUB_TERM_ENTRY_WIDTH - 1; - screen->y--; + screen->terms[i].x--; + if (screen->terms[i].x == -1) + { + screen->terms[i].x + = grub_term_entry_width (screen->terms[i].term) - 1; + screen->terms[i].y--; + } } } else if (screen->line > 0) @@ -498,14 +577,18 @@ backward_char (struct screen *screen, int update) screen->line--; linep = screen->lines + screen->line; screen->column = linep->len; - screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH; - screen->y--; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x = screen->column + % grub_term_entry_width (screen->terms[i].term); + screen->terms[i].y--; + } } screen->real_column = screen->column; if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } @@ -513,14 +596,16 @@ backward_char (struct screen *screen, int update) static int previous_line (struct screen *screen, int update) { + unsigned i; + if (screen->line > 0) { struct line *linep; - int dy; + int col; /* How many physical lines from the current position to the first physical line? */ - dy = screen->column / GRUB_TERM_ENTRY_WIDTH; + col = screen->column; screen->line--; @@ -530,23 +615,35 @@ previous_line (struct screen *screen, int update) else screen->column = screen->real_column; - /* How many physical lines from the current position - to the last physical line? */ - dy += (linep->len / GRUB_TERM_ENTRY_WIDTH - - screen->column / GRUB_TERM_ENTRY_WIDTH); + for (i = 0; i < screen->nterms; i++) + { + int dy; + dy = col / grub_term_entry_width (screen->terms[i].term); - screen->y -= dy + 1; - screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH; + /* How many physical lines from the current position + to the last physical line? */ + dy += (linep->len / grub_term_entry_width (screen->terms[i].term) + - screen->column + / grub_term_entry_width (screen->terms[i].term)); + + screen->terms[i].y -= dy + 1; + screen->terms[i].x + = screen->column % grub_term_entry_width (screen->terms[i].term); + } } else { - screen->y -= screen->column / GRUB_TERM_ENTRY_WIDTH; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].y + -= screen->column / grub_term_entry_width (screen->terms[i].term); + screen->terms[i].x = 0; + } screen->column = 0; - screen->x = 0; } if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } @@ -554,16 +651,18 @@ previous_line (struct screen *screen, int update) static int next_line (struct screen *screen, int update) { + unsigned i; + if (screen->line < screen->num_lines - 1) { struct line *linep; - int dy; + int l1, c1; /* How many physical lines from the current position to the last physical line? */ linep = screen->lines + screen->line; - dy = (linep->len / GRUB_TERM_ENTRY_WIDTH - - screen->column / GRUB_TERM_ENTRY_WIDTH); + l1 = linep->len; + c1 = screen->column; screen->line++; @@ -573,26 +672,40 @@ next_line (struct screen *screen, int update) else screen->column = screen->real_column; - /* How many physical lines from the current position - to the first physical line? */ - dy += screen->column / GRUB_TERM_ENTRY_WIDTH; - - screen->y += dy + 1; - screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH; + for (i = 0; i < screen->nterms; i++) + { + int dy; + dy = l1 / grub_term_entry_width (screen->terms[i].term) + - c1 / grub_term_entry_width (screen->terms[i].term); + /* How many physical lines from the current position + to the first physical line? */ + dy += screen->column / grub_term_entry_width (screen->terms[i].term); + screen->terms[i].y += dy + 1; + screen->terms[i].x = screen->column + % grub_term_entry_width (screen->terms[i].term); + } } else { struct line *linep; - + int l, s; + linep = screen->lines + screen->line; - screen->y += (linep->len / GRUB_TERM_ENTRY_WIDTH - - screen->column / GRUB_TERM_ENTRY_WIDTH); + l = linep->len; + s = screen->column; screen->column = linep->len; - screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].y + += (l / grub_term_entry_width (screen->terms[i].term) + - s / grub_term_entry_width (screen->terms[i].term)); + screen->terms[i].x + = screen->column % grub_term_entry_width (screen->terms[i].term); + } } if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } @@ -600,12 +713,19 @@ next_line (struct screen *screen, int update) static int beginning_of_line (struct screen *screen, int update) { - screen->y -= screen->column / GRUB_TERM_ENTRY_WIDTH; + unsigned i; + int col; + + col = screen->column; screen->column = screen->real_column = 0; - screen->x = 0; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].x = 0; + screen->terms[i].y -= col / grub_term_entry_width (screen->terms[i].term); + } if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } @@ -614,15 +734,23 @@ static int end_of_line (struct screen *screen, int update) { struct line *linep; + unsigned i; + int col; linep = screen->lines + screen->line; - screen->y += (linep->len / GRUB_TERM_ENTRY_WIDTH - - screen->column / GRUB_TERM_ENTRY_WIDTH); + col = screen->column; screen->column = screen->real_column = linep->len; - screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH; + for (i = 0; i < screen->nterms; i++) + { + screen->terms[i].y + += (linep->len / grub_term_entry_width (screen->terms->term) + - col / grub_term_entry_width (screen->terms->term)); + screen->terms[i].x + = screen->column % grub_term_entry_width (screen->terms->term); + } if (update) - update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE); + update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE); return 1; } @@ -631,32 +759,41 @@ static int delete_char (struct screen *screen, int update) { struct line *linep; - enum update_mode mode = NO_LINE; int start = screen->num_lines; int column = 0; - int down = 0; linep = screen->lines + screen->line; if (linep->len > screen->column) { - int orig_num, new_num; + int orig_num[screen->nterms], new_num; + unsigned i; - orig_num = get_logical_num_lines (linep); + for (i = 0; i < screen->nterms; i++) + orig_num[i] = get_logical_num_lines (linep, &screen->terms[i]); grub_memmove (linep->buf + screen->column, linep->buf + screen->column + 1, linep->len - screen->column - 1); linep->len--; - new_num = get_logical_num_lines (linep); - - if (orig_num != new_num) - mode = ALL_LINES; - else - mode = SINGLE_LINE; - start = screen->line; column = screen->column; + + screen->real_column = screen->column; + + if (update) + { + for (i = 0; i < screen->nterms; i++) + { + new_num = get_logical_num_lines (linep, &screen->terms[i]); + if (orig_num[i] != new_num) + update_screen (screen, &screen->terms[i], + start, column, 0, 0, ALL_LINES); + else + update_screen (screen, &screen->terms[i], + start, column, 0, 0, SINGLE_LINE); + } + } } else if (screen->num_lines > screen->line + 1) { @@ -676,17 +813,14 @@ delete_char (struct screen *screen, int update) * sizeof (struct line)); screen->num_lines--; - mode = ALL_LINES; start = screen->line; column = screen->column; - down = 1; + + screen->real_column = screen->column; + if (update) + update_screen_all (screen, start, column, 0, 1, ALL_LINES); } - screen->real_column = screen->column; - - if (update) - update_screen (screen, start, column, 0, down, mode); - return 1; } @@ -731,9 +865,8 @@ kill_line (struct screen *screen, int continuous, int update) if (size > 0) { - enum update_mode mode = SINGLE_LINE; - int down = 0; - int orig_num, new_num; + int orig_num[screen->nterms], new_num; + unsigned i; p = grub_realloc (p, offset + size + 1); if (! p) @@ -744,18 +877,23 @@ kill_line (struct screen *screen, int continuous, int update) screen->killed_text = p; - orig_num = get_logical_num_lines (linep); + for (i = 0; i < screen->nterms; i++) + orig_num[i] = get_logical_num_lines (linep, &screen->terms[i]); linep->len = screen->column; - new_num = get_logical_num_lines (linep); - - if (orig_num != new_num) - { - mode = ALL_LINES; - down = 1; - } if (update) - update_screen (screen, screen->line, screen->column, 0, down, mode); + { + new_num = get_logical_num_lines (linep, &screen->terms[i]); + for (i = 0; i < screen->nterms; i++) + { + if (orig_num[i] != new_num) + update_screen (screen, &screen->terms[i], + screen->line, screen->column, 0, 1, ALL_LINES); + else + update_screen (screen, &screen->terms[i], + screen->line, screen->column, 0, 0, SINGLE_LINE); + } + } } else if (screen->line + 1 < screen->num_lines) { @@ -786,7 +924,11 @@ yank (struct screen *screen, int update) static int open_line (struct screen *screen, int update) { - int saved_y = screen->y; + int saved_y[screen->nterms]; + unsigned i; + + for (i = 0; i < screen->nterms; i++) + saved_y[i] = screen->terms[i].y; if (! insert_string (screen, "\n", 0)) return 0; @@ -794,52 +936,23 @@ open_line (struct screen *screen, int update) if (! backward_char (screen, 0)) return 0; - screen->y = saved_y; + for (i = 0; i < screen->nterms; i++) + screen->terms[i].y = saved_y[i]; if (update) - update_screen (screen, screen->line, screen->column, 0, 1, ALL_LINES); + update_screen_all (screen, screen->line, screen->column, 0, 1, ALL_LINES); return 1; } /* A completion hook to print items. */ static void -store_completion (const char *item, grub_completion_type_t type, int count) +store_completion (const char *item, grub_completion_type_t type, + int count __attribute__ ((unused))) { char *p; - if (count == 0) - { - /* If this is the first time, print a label. */ - const char *what; - - switch (type) - { - case GRUB_COMPLETION_TYPE_COMMAND: - what = "commands"; - break; - case GRUB_COMPLETION_TYPE_DEVICE: - what = "devices"; - break; - case GRUB_COMPLETION_TYPE_FILE: - what = "files"; - break; - case GRUB_COMPLETION_TYPE_PARTITION: - what = "partitions"; - break; - case GRUB_COMPLETION_TYPE_ARGUMENT: - what = "arguments"; - break; - default: - what = "things"; - break; - } - - grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf (" "); - grub_printf_ (N_("Possible %s are:"), what); - grub_printf ("\n "); - } + completion_type = type; /* Make sure that the completion buffer has enough room. */ if (completion_buffer.max_len < (completion_buffer.len @@ -873,21 +986,21 @@ store_completion (const char *item, grub_completion_type_t type, int count) static int complete (struct screen *screen, int continuous, int update) { - grub_uint16_t pos; char saved_char; struct line *linep; int restore; char *insert; static int count = -1; + unsigned i; + grub_uint32_t *ucs4; + grub_size_t buflen; + grub_ssize_t ucs4len; if (continuous) count++; else count = 0; - pos = grub_getxy (); - grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - completion_buffer.buf = 0; completion_buffer.len = 0; completion_buffer.max_len = 0; @@ -900,35 +1013,86 @@ complete (struct screen *screen, int continuous, int update) linep->buf[screen->column] = saved_char; - if (restore) + buflen = grub_strlen (completion_buffer.buf); + ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); + + if (!ucs4) { - char *p = completion_buffer.buf; - - screen->completion_shown = 1; - - if (p) - { - int num_sections = ((completion_buffer.len + GRUB_TERM_WIDTH - 8 - 1) - / (GRUB_TERM_WIDTH - 8)); - char *endp; - - p += (count % num_sections) * (GRUB_TERM_WIDTH - 8); - endp = p + (GRUB_TERM_WIDTH - 8); - - if (p != completion_buffer.buf) - grub_putcode (GRUB_TERM_DISP_LEFT); - else - grub_putchar (' '); - - while (*p && p < endp) - grub_putchar (*p++); - - if (*p) - grub_putcode (GRUB_TERM_DISP_RIGHT); - } + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + return 1; } - grub_gotoxy (pos >> 8, pos & 0xFF); + ucs4len = grub_utf8_to_ucs4 (ucs4, buflen, + (grub_uint8_t *) completion_buffer.buf, + buflen, 0); + ucs4[ucs4len] = 0; + + if (restore) + for (i = 0; i < screen->nterms; i++) + { + int num_sections = ((completion_buffer.len + + grub_term_width (screen->terms[i].term) - 8 - 1) + / (grub_term_width (screen->terms[i].term) - 8)); + grub_uint32_t *endp; + grub_uint16_t pos; + grub_uint32_t *p = ucs4; + + pos = grub_term_getxy (screen->terms[i].term); + grub_term_gotoxy (screen->terms[i].term, 0, + grub_term_height (screen->terms[i].term) - 3); + + screen->completion_shown = 1; + + grub_term_gotoxy (screen->terms[i].term, 0, + grub_term_height (screen->terms[i].term) - 3); + grub_puts_terminal (" ", screen->terms[i].term); + switch (completion_type) + { + case GRUB_COMPLETION_TYPE_COMMAND: + grub_puts_terminal (_("Possible commands are:"), + screen->terms[i].term); + break; + case GRUB_COMPLETION_TYPE_DEVICE: + grub_puts_terminal (_("Possible devices are:"), + screen->terms[i].term); + break; + case GRUB_COMPLETION_TYPE_FILE: + grub_puts_terminal (_("Possible files are:"), + screen->terms[i].term); + break; + case GRUB_COMPLETION_TYPE_PARTITION: + grub_puts_terminal (_("Possible partitions are:"), + screen->terms[i].term); + break; + case GRUB_COMPLETION_TYPE_ARGUMENT: + grub_puts_terminal (_("Possible arguments are:"), + screen->terms[i].term); + break; + default: + grub_puts_terminal (_("Possible things are:"), + screen->terms[i].term); + break; + } + + grub_puts_terminal ("\n ", screen->terms[i].term); + + p += (count % num_sections) + * (grub_term_width (screen->terms[i].term) - 8); + endp = p + (grub_term_width (screen->terms[i].term) - 8); + + if (p != ucs4) + grub_putcode (GRUB_TERM_DISP_LEFT, screen->terms[i].term); + else + grub_putcode (' ', screen->terms[i].term); + + while (*p && p < endp) + grub_putcode (*p++, screen->terms[i].term); + + if (*p) + grub_putcode (GRUB_TERM_DISP_RIGHT, screen->terms[i].term); + grub_term_gotoxy (screen->terms[i].term, pos >> 8, pos & 0xFF); + } if (insert) { @@ -945,23 +1109,33 @@ complete (struct screen *screen, int continuous, int update) /* Clear displayed completions. */ static void -clear_completions (void) +clear_completions (struct per_term_screen *term_screen) { grub_uint16_t pos; - int i, j; + unsigned i, j; - pos = grub_getxy (); - grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + pos = grub_term_getxy (term_screen->term); + grub_term_gotoxy (term_screen->term, 0, + grub_term_height (term_screen->term) - 3); for (i = 0; i < 2; i++) { - for (j = 0; j < GRUB_TERM_WIDTH - 1; j++) - grub_putchar (' '); - grub_putchar ('\n'); + for (j = 0; j < grub_term_width (term_screen->term) - 1; j++) + grub_putcode (' ', term_screen->term); + grub_putcode ('\n', term_screen->term); } - grub_gotoxy (pos >> 8, pos & 0xFF); - grub_refresh (); + grub_term_gotoxy (term_screen->term, pos >> 8, pos & 0xFF); + grub_term_refresh (term_screen->term); +} + +static void +clear_completions_all (struct screen *screen) +{ + unsigned i; + + for (i = 0; i < screen->nterms; i++) + clear_completions (&screen->terms[i]); } /* Execute the command list in the screen SCREEN. */ @@ -1033,6 +1207,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) struct screen *screen; int prev_c; grub_err_t err = GRUB_ERR_NONE; + unsigned i; err = grub_auth_check_authentication (NULL); @@ -1049,9 +1224,11 @@ grub_menu_entry_run (grub_menu_entry_t entry) refresh: /* Draw the screen. */ - grub_menu_init_page (0, 1); - update_screen (screen, 0, 0, 1, 1, ALL_LINES); - grub_setcursor (1); + for (i = 0; i < screen->nterms; i++) + grub_menu_init_page (0, 1, screen->terms[i].term); + update_screen_all (screen, 0, 0, 1, 1, ALL_LINES); + for (i = 0; i < screen->nterms; i++) + grub_term_setcursor (screen->terms[i].term, 1); prev_c = '\0'; while (1) @@ -1060,7 +1237,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) if (screen->completion_shown) { - clear_completions (); + clear_completions_all (screen); screen->completion_shown = 0; } diff --git a/normal/menu_text.c b/normal/menu_text.c index 4f2dfb78e..edb315524 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -26,96 +26,66 @@ #include #include #include - -/* Time to delay after displaying an error message about a default/fallback - entry failing to boot. */ -#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500 +#include static grub_uint8_t grub_color_menu_normal; static grub_uint8_t grub_color_menu_highlight; -/* Wait until the user pushes any key so that the user - can see what happened. */ -void -grub_wait_after_message (void) +struct menu_viewer_data { - grub_putchar ('\n'); - grub_printf_ (N_("Press any key to continue...")); - (void) grub_getkey (); - grub_putchar ('\n'); -} + int first, offset; + grub_menu_t menu; + struct grub_term_output *term; +}; static void -print_spaces (int number_spaces) +print_spaces (int number_spaces, struct grub_term_output *term) { int i; for (i = 0; i < number_spaces; i++) - grub_putchar (' '); + grub_putcode (' ', term); } void grub_print_ucs4 (const grub_uint32_t * str, - const grub_uint32_t * last_position) + const grub_uint32_t * last_position, + struct grub_term_output *term) { while (str < last_position) { - grub_putcode (*str); + grub_putcode (*str, term); str++; } } -int -grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, - grub_uint32_t **last_position) -{ - grub_ssize_t msg_len = grub_strlen (msg); - - *unicode_msg = grub_malloc (grub_strlen (msg) * sizeof (grub_uint32_t)); - - if (!*unicode_msg) - { - grub_printf ("utf8_to_ucs4 ERROR1: %s", msg); - return -1; - } - - msg_len = grub_utf8_to_ucs4 (*unicode_msg, msg_len, - (grub_uint8_t *) msg, -1, 0); - - *last_position = *unicode_msg + msg_len; - - if (msg_len < 0) - { - grub_printf ("utf8_to_ucs4 ERROR2: %s", msg); - grub_free (*unicode_msg); - } - return msg_len; -} - grub_ssize_t -grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position) +grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position, + struct grub_term_output *term) { grub_ssize_t width = 0; while (str < last_position) { - width += grub_getcharwidth (*str); + width += grub_term_getcharwidth (term, *str); str++; } return width; } void -grub_print_message_indented (const char *msg, int margin_left, int margin_right) +grub_print_message_indented (const char *msg, int margin_left, int margin_right, + struct grub_term_output *term) { int line_len; - line_len = GRUB_TERM_WIDTH - grub_getcharwidth ('m') * - (margin_left + margin_right); grub_uint32_t *unicode_msg; grub_uint32_t *last_position; int msg_len; + line_len = grub_term_width (term) - grub_term_getcharwidth (term, 'm') * + (margin_left + margin_right); + msg_len = grub_utf8_to_ucs4_alloc (msg, &unicode_msg, &last_position); if (msg_len < 0) @@ -132,11 +102,12 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right) while (current_position < last_position) { if (! first_loop) - grub_putchar ('\n'); + grub_putcode ('\n', term); next_new_line = (grub_uint32_t *) last_position; - while (grub_getstringwidth (current_position, next_new_line) > line_len + while (grub_getstringwidth (current_position, next_new_line,term) + > line_len || (*next_new_line != ' ' && next_new_line > current_position && next_new_line != last_position)) { @@ -149,8 +120,8 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right) (grub_uint32_t *) last_position : next_new_line + line_len; } - print_spaces (margin_left); - grub_print_ucs4 (current_position, next_new_line); + print_spaces (margin_left, term); + grub_print_ucs4 (current_position, next_new_line, term); next_new_line++; current_position = next_new_line; @@ -161,52 +132,54 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right) static void -draw_border (void) +draw_border (struct grub_term_output *term) { unsigned i; - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); - grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y); - grub_putcode (GRUB_TERM_DISP_UL); - for (i = 0; i < (unsigned) GRUB_TERM_BORDER_WIDTH - 2; i++) - grub_putcode (GRUB_TERM_DISP_HLINE); - grub_putcode (GRUB_TERM_DISP_UR); + grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y); + grub_putcode (GRUB_TERM_DISP_UL, term); + for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++) + grub_putcode (GRUB_TERM_DISP_HLINE, term); + grub_putcode (GRUB_TERM_DISP_UR, term); - for (i = 0; i < (unsigned) GRUB_TERM_NUM_ENTRIES; i++) + for (i = 0; i < (unsigned) grub_term_num_entries (term); i++) { - grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1); - grub_putcode (GRUB_TERM_DISP_VLINE); - grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1, - GRUB_TERM_TOP_BORDER_Y + i + 1); - grub_putcode (GRUB_TERM_DISP_VLINE); + grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1); + grub_putcode (GRUB_TERM_DISP_VLINE, term); + grub_term_gotoxy (term, GRUB_TERM_MARGIN + grub_term_border_width (term) + - 1, + GRUB_TERM_TOP_BORDER_Y + i + 1); + grub_putcode (GRUB_TERM_DISP_VLINE, term); } - grub_gotoxy (GRUB_TERM_MARGIN, - GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1); - grub_putcode (GRUB_TERM_DISP_LL); - for (i = 0; i < (unsigned) GRUB_TERM_BORDER_WIDTH - 2; i++) - grub_putcode (GRUB_TERM_DISP_HLINE); - grub_putcode (GRUB_TERM_DISP_LR); + grub_term_gotoxy (term, GRUB_TERM_MARGIN, + GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + 1); + grub_putcode (GRUB_TERM_DISP_LL, term); + for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++) + grub_putcode (GRUB_TERM_DISP_HLINE, term); + grub_putcode (GRUB_TERM_DISP_LR, term); - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); - grub_gotoxy (GRUB_TERM_MARGIN, - (GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES - + GRUB_TERM_MARGIN + 1)); + grub_term_gotoxy (term, GRUB_TERM_MARGIN, + (GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + + GRUB_TERM_MARGIN + 1)); } static void -print_message (int nested, int edit) +print_message (int nested, int edit, struct grub_term_output *term) { - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); if (edit) { - grub_putchar ('\n'); + grub_putcode ('\n', term); grub_print_message_indented (_("Minimum Emacs-like screen editing is \ supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \ -command-line or ESC to return menu."), STANDARD_MARGIN, STANDARD_MARGIN); +command-line or ESC to return menu."), STANDARD_MARGIN, STANDARD_MARGIN, + term); } else { @@ -218,12 +191,14 @@ entry is highlighted.\n"); grub_sprintf (msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); grub_putchar ('\n'); - grub_print_message_indented (msg_translated, STANDARD_MARGIN, STANDARD_MARGIN); + grub_print_message_indented (msg_translated, STANDARD_MARGIN, + STANDARD_MARGIN, term); grub_free (msg_translated); grub_print_message_indented (_("Press enter to boot the selected OS, \ -\'e\' to edit the commands before booting or \'c\' for a command-line.\n"), STANDARD_MARGIN, STANDARD_MARGIN); +\'e\' to edit the commands before booting or \'c\' for a command-line.\n"), + STANDARD_MARGIN, STANDARD_MARGIN, term); if (nested) { @@ -234,7 +209,8 @@ entry is highlighted.\n"); } static void -print_entry (int y, int highlight, grub_menu_entry_t entry) +print_entry (int y, int highlight, grub_menu_entry_t entry, + struct grub_term_output *term) { int x; const char *title; @@ -260,482 +236,248 @@ print_entry (int y, int highlight, grub_menu_entry_t entry) return; } - grub_getcolor (&old_color_normal, &old_color_highlight); - grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight); - grub_setcolorstate (highlight - ? GRUB_TERM_COLOR_HIGHLIGHT - : GRUB_TERM_COLOR_NORMAL); + grub_term_getcolor (term, &old_color_normal, &old_color_highlight); + grub_term_setcolor (term, grub_color_menu_normal, grub_color_menu_highlight); + grub_term_setcolorstate (term, highlight + ? GRUB_TERM_COLOR_HIGHLIGHT + : GRUB_TERM_COLOR_NORMAL); - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y); + grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y); for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0; - x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN; + x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term) + - GRUB_TERM_MARGIN); i++) { if (i < len - && x <= (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - - GRUB_TERM_MARGIN - 1)) + && x <= (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term) + - GRUB_TERM_MARGIN - 1)) { grub_ssize_t width; - width = grub_getcharwidth (unicode_title[i]); + width = grub_term_getcharwidth (term, unicode_title[i]); - if (x + width > (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - - GRUB_TERM_MARGIN - 1)) - grub_putcode (GRUB_TERM_DISP_RIGHT); + if (x + width > (int) (GRUB_TERM_LEFT_BORDER_X + + grub_term_border_width (term) + - GRUB_TERM_MARGIN - 1)) + grub_putcode (GRUB_TERM_DISP_RIGHT, term); else - grub_putcode (unicode_title[i]); + grub_putcode (unicode_title[i], term); x += width; } else { - grub_putchar (' '); + grub_putcode (' ', term); x++; } } - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); - grub_putchar (' '); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); + grub_putcode (' ', term); - grub_gotoxy (GRUB_TERM_CURSOR_X, y); + grub_term_gotoxy (term, grub_term_cursor_x (term), y); - grub_setcolor (old_color_normal, old_color_highlight); - grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_term_setcolor (term, old_color_normal, old_color_highlight); + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); grub_free (unicode_title); } static void -print_entries (grub_menu_t menu, int first, int offset) +print_entries (grub_menu_t menu, int first, int offset, + struct grub_term_output *term) { grub_menu_entry_t e; int i; - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH, - GRUB_TERM_FIRST_ENTRY_Y); + grub_term_gotoxy (term, + GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term), + GRUB_TERM_FIRST_ENTRY_Y); if (first) - grub_putcode (GRUB_TERM_DISP_UP); + grub_putcode (GRUB_TERM_DISP_UP, term); else - grub_putchar (' '); + grub_putcode (' ', term); e = grub_menu_get_entry (menu, first); - for (i = 0; i < GRUB_TERM_NUM_ENTRIES; i++) + for (i = 0; i < grub_term_num_entries (term); i++) { - print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, offset == i, e); + print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, offset == i, e, term); if (e) e = e->next; } - grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH, - GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES); + grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X + + grub_term_border_width (term), + GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term)); if (e) - grub_putcode (GRUB_TERM_DISP_DOWN); + grub_putcode (GRUB_TERM_DISP_DOWN, term); else - grub_putchar (' '); + grub_putcode (' ', term); - grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); + grub_term_gotoxy (term, grub_term_cursor_x (term), + GRUB_TERM_FIRST_ENTRY_Y + offset); } /* Initialize the screen. If NESTED is non-zero, assume that this menu is run from another menu or a command-line. If EDIT is non-zero, show a message for the menu entry editor. */ void -grub_menu_init_page (int nested, int edit) +grub_menu_init_page (int nested, int edit, + struct grub_term_output *term) { grub_uint8_t old_color_normal, old_color_highlight; - grub_getcolor (&old_color_normal, &old_color_highlight); + grub_term_getcolor (term, &old_color_normal, &old_color_highlight); /* By default, use the same colors for the menu. */ grub_color_menu_normal = old_color_normal; grub_color_menu_highlight = old_color_highlight; /* Then give user a chance to replace them. */ - grub_parse_color_name_pair (&grub_color_menu_normal, grub_env_get ("menu_color_normal")); - grub_parse_color_name_pair (&grub_color_menu_highlight, grub_env_get ("menu_color_highlight")); + grub_parse_color_name_pair (&grub_color_menu_normal, + grub_env_get ("menu_color_normal")); + grub_parse_color_name_pair (&grub_color_menu_highlight, + grub_env_get ("menu_color_highlight")); - grub_normal_init_page (); - grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight); - draw_border (); - grub_setcolor (old_color_normal, old_color_highlight); - print_message (nested, edit); -} - -/* Get the entry number from the variable NAME. */ -static int -get_entry_number (const char *name) -{ - char *val; - int entry; - - val = grub_env_get (name); - if (! val) - return -1; - - grub_error_push (); - - entry = (int) grub_strtoul (val, 0, 0); - - if (grub_errno != GRUB_ERR_NONE) - { - grub_errno = GRUB_ERR_NONE; - entry = -1; - } - - grub_error_pop (); - - return entry; + grub_normal_init_page (term); + grub_term_setcolor (term, grub_color_menu_normal, grub_color_menu_highlight); + draw_border (term); + grub_term_setcolor (term, old_color_normal, old_color_highlight); + print_message (nested, edit, term); } static void -print_timeout (int timeout, int offset) +menu_text_print_timeout (int timeout, void *dataptr) { const char *msg = _("The highlighted entry will be booted automatically in %ds."); - - grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - - char *msg_translated = - grub_malloc (sizeof (char) * grub_strlen (msg) + 5); - - grub_sprintf (msg_translated, msg, timeout); - grub_print_message_indented (msg_translated, 3, 0); - + struct menu_viewer_data *data = dataptr; + char *msg_translated; int posx; - posx = grub_getxy() >> 8; - print_spaces (GRUB_TERM_WIDTH - posx - 1); - grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); - grub_refresh (); -} + grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3); -/* Show the menu and handle menu entry selection. Returns the menu entry - index that should be executed or -1 if no entry should be executed (e.g., - Esc pressed to exit a sub-menu or switching menu viewers). - If the return value is not -1, then *AUTO_BOOT is nonzero iff the menu - entry to be executed is a result of an automatic default selection because - of the timeout. */ -static int -run_menu (grub_menu_t menu, int nested, int *auto_boot) -{ - int first, offset; - grub_uint64_t saved_time; - int default_entry; - int timeout; - - first = 0; - - default_entry = get_entry_number ("default"); - - /* If DEFAULT_ENTRY is not within the menu entries, fall back to - the first entry. */ - if (default_entry < 0 || default_entry >= menu->size) - default_entry = 0; - - /* If timeout is 0, drawing is pointless (and ugly). */ - if (grub_menu_get_timeout () == 0) - { - *auto_boot = 1; - return default_entry; - } - - offset = default_entry; - if (offset > GRUB_TERM_NUM_ENTRIES - 1) - { - first = offset - (GRUB_TERM_NUM_ENTRIES - 1); - offset = GRUB_TERM_NUM_ENTRIES - 1; - } - - /* Initialize the time. */ - saved_time = grub_get_time_ms (); - - refresh: - grub_setcursor (0); - grub_menu_init_page (nested, 0); - print_entries (menu, first, offset); - grub_refresh (); - - timeout = grub_menu_get_timeout (); - - if (timeout > 0) - print_timeout (timeout, offset); - - while (1) - { - int c; - timeout = grub_menu_get_timeout (); - - if (timeout > 0) - { - grub_uint64_t current_time; - - current_time = grub_get_time_ms (); - if (current_time - saved_time >= 1000) - { - timeout--; - grub_menu_set_timeout (timeout); - saved_time = current_time; - print_timeout (timeout, offset); - } - } - - if (timeout == 0) - { - grub_env_unset ("timeout"); - *auto_boot = 1; - return default_entry; - } - - if (grub_checkkey () >= 0 || timeout < 0) - { - c = GRUB_TERM_ASCII_CHAR (grub_getkey ()); - - if (timeout >= 0) - { - grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - print_spaces (GRUB_TERM_WIDTH - 1); - - grub_env_unset ("timeout"); - grub_env_unset ("fallback"); - grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); - } - - switch (c) - { - case GRUB_TERM_HOME: - first = 0; - offset = 0; - print_entries (menu, first, offset); - break; - - case GRUB_TERM_END: - offset = menu->size - 1; - if (offset > GRUB_TERM_NUM_ENTRIES - 1) - { - first = offset - (GRUB_TERM_NUM_ENTRIES - 1); - offset = GRUB_TERM_NUM_ENTRIES - 1; - } - print_entries (menu, first, offset); - break; - - case GRUB_TERM_UP: - case '^': - if (offset > 0) - { - print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 0, - grub_menu_get_entry (menu, first + offset)); - offset--; - print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 1, - grub_menu_get_entry (menu, first + offset)); - } - else if (first > 0) - { - first--; - print_entries (menu, first, offset); - } - break; - - case GRUB_TERM_DOWN: - case 'v': - if (menu->size > first + offset + 1) - { - if (offset < GRUB_TERM_NUM_ENTRIES - 1) - { - print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 0, - grub_menu_get_entry (menu, first + offset)); - offset++; - print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 1, - grub_menu_get_entry (menu, first + offset)); - } - else - { - first++; - print_entries (menu, first, offset); - } - } - break; - - case GRUB_TERM_PPAGE: - if (first == 0) - { - offset = 0; - } - else - { - first -= GRUB_TERM_NUM_ENTRIES; - - if (first < 0) - { - offset += first; - first = 0; - } - } - print_entries (menu, first, offset); - break; - - case GRUB_TERM_NPAGE: - if (offset == 0) - { - offset += GRUB_TERM_NUM_ENTRIES - 1; - if (first + offset >= menu->size) - { - offset = menu->size - first - 1; - } - } - else - { - first += GRUB_TERM_NUM_ENTRIES; - - if (first + offset >= menu->size) - { - first -= GRUB_TERM_NUM_ENTRIES; - offset += GRUB_TERM_NUM_ENTRIES; - - if (offset > menu->size - 1 || - offset > GRUB_TERM_NUM_ENTRIES - 1) - { - offset = menu->size - first - 1; - } - if (offset > GRUB_TERM_NUM_ENTRIES) - { - first += offset - GRUB_TERM_NUM_ENTRIES + 1; - offset = GRUB_TERM_NUM_ENTRIES - 1; - } - } - } - print_entries (menu, first, offset); - break; - - case '\n': - case '\r': - case 6: - grub_setcursor (1); - *auto_boot = 0; - return first + offset; - - case '\e': - if (nested) - { - grub_setcursor (1); - return -1; - } - break; - - case 'c': - grub_cmdline_run (1); - goto refresh; - - case 'e': - { - grub_menu_entry_t e = grub_menu_get_entry (menu, first + offset); - if (e) - grub_menu_entry_run (e); - } - goto refresh; - - default: - break; - } - - grub_refresh (); - } - } - - /* Never reach here. */ - return -1; -} - -/* Callback invoked immediately before a menu entry is executed. */ -static void -notify_booting (grub_menu_entry_t entry, - void *userdata __attribute__((unused))) -{ - grub_printf (" "); - grub_printf_ (N_("Booting \'%s\'"), entry->title); - grub_printf ("\n\n"); -} - -/* Callback invoked when a default menu entry executed because of a timeout - has failed and an attempt will be made to execute the next fallback - entry, ENTRY. */ -static void -notify_fallback (grub_menu_entry_t entry, - void *userdata __attribute__((unused))) -{ - grub_printf ("\n "); - grub_printf_ (N_("Falling back to \'%s\'"), entry->title); - grub_printf ("\n\n"); - grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); -} - -/* Callback invoked when a menu entry has failed and there is no remaining - fallback entry to attempt. */ -static void -notify_execution_failure (void *userdata __attribute__((unused))) -{ - if (grub_errno != GRUB_ERR_NONE) + msg_translated = grub_malloc (sizeof (char) * grub_strlen (msg) + 5); + if (!msg_translated) { grub_print_error (); grub_errno = GRUB_ERR_NONE; + return; } - grub_printf ("\n "); - grub_printf_ (N_("Failed to boot default entries.\n")); - grub_wait_after_message (); + + grub_sprintf (msg_translated, msg, timeout); + grub_print_message_indented (msg_translated, 3, 0, data->term); + + posx = grub_term_getxy (data->term) >> 8; + print_spaces (grub_term_width (data->term) - posx - 1, data->term); + + grub_term_gotoxy (data->term, + grub_term_cursor_x (data->term), + GRUB_TERM_FIRST_ENTRY_Y + data->offset); + grub_term_refresh (data->term); } -/* Callbacks used by the text menu to provide user feedback when menu entries - are executed. */ -static struct grub_menu_execute_callback execution_callback = +static void +menu_text_set_chosen_entry (int entry, void *dataptr) { - .notify_booting = notify_booting, - .notify_fallback = notify_fallback, - .notify_failure = notify_execution_failure -}; - -static grub_err_t -show_text_menu (grub_menu_t menu, int nested) -{ - while (1) + struct menu_viewer_data *data = dataptr; + int oldoffset = data->offset; + int complete_redraw = 0; + data->offset = entry - data->first; + if (data->offset > grub_term_num_entries (data->term) - 1) { - int boot_entry; - grub_menu_entry_t e; - int auto_boot; - - boot_entry = run_menu (menu, nested, &auto_boot); - if (boot_entry < 0) - break; - - e = grub_menu_get_entry (menu, boot_entry); - if (! e) - continue; /* Menu is empty. */ - - grub_cls (); - grub_setcursor (1); - - if (auto_boot) - { - grub_menu_execute_with_fallback (menu, e, &execution_callback, 0); - } - else - { - grub_errno = GRUB_ERR_NONE; - grub_menu_execute_entry (e); - if (grub_errno != GRUB_ERR_NONE) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - grub_wait_after_message (); - } - } + data->first = data->offset - (grub_term_num_entries (data->term) - 1); + data->offset = grub_term_num_entries (data->term) - 1; + complete_redraw = 1; } - - return GRUB_ERR_NONE; + if (data->offset < 0) + { + data->offset = 0; + data->first = entry; + complete_redraw = 1; + } + if (complete_redraw) + print_entries (data->menu, data->first, data->offset, data->term); + else + { + print_entry (GRUB_TERM_FIRST_ENTRY_Y + oldoffset, 0, + grub_menu_get_entry (data->menu, data->first + oldoffset), + data->term); + print_entry (GRUB_TERM_FIRST_ENTRY_Y + data->offset, 1, + grub_menu_get_entry (data->menu, data->first + data->offset), + data->term); + } + grub_term_refresh (data->term); } -struct grub_menu_viewer grub_normal_text_menu_viewer = +static void +menu_text_fini (void *dataptr) { - .name = "text", - .show_menu = show_text_menu -}; + struct menu_viewer_data *data = dataptr; + + grub_term_setcursor (data->term, 1); +} + +static void +menu_text_clear_timeout (void *dataptr) +{ + struct menu_viewer_data *data = dataptr; + + grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3); + print_spaces (grub_term_width (data->term) - 1, data->term); + grub_term_gotoxy (data->term, grub_term_cursor_x (data->term), + GRUB_TERM_FIRST_ENTRY_Y + data->offset); + grub_term_refresh (data->term); +} + +void +grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested) +{ + struct menu_viewer_data *data; + struct grub_menu_viewer *instance; + struct grub_term_output *term; + + for (term = grub_term_outputs; term; term = term->next) + { + if (!grub_term_is_active (term)) + continue; + instance = grub_zalloc (sizeof (*instance)); + if (!instance) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + continue; + } + data = grub_zalloc (sizeof (*data)); + if (!data) + { + grub_free (instance); + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + continue; + } + data->term = term; + instance->data = data; + instance->set_chosen_entry = menu_text_set_chosen_entry; + instance->print_timeout = menu_text_print_timeout; + instance->clear_timeout = menu_text_clear_timeout; + instance->fini = menu_text_fini; + + data->menu = menu; + + data->offset = entry; + data->first = 0; + if (data->offset > grub_term_num_entries (data->term) - 1) + { + data->first = data->offset - (grub_term_num_entries (data->term) - 1); + data->offset = grub_term_num_entries (data->term) - 1; + } + + grub_term_setcursor (data->term, 0); + grub_menu_init_page (nested, 0, data->term); + print_entries (menu, data->first, data->offset, data->term); + grub_term_refresh (data->term); + } +} diff --git a/normal/menu_viewer.c b/normal/menu_viewer.c index 1bd271a21..b600e7500 100644 --- a/normal/menu_viewer.c +++ b/normal/menu_viewer.c @@ -23,59 +23,4 @@ #include #include -/* The list of menu viewers. */ -static grub_menu_viewer_t menu_viewer_list; - -void -grub_menu_viewer_register (grub_menu_viewer_t viewer) -{ - viewer->next = menu_viewer_list; - menu_viewer_list = viewer; -} - -static grub_menu_viewer_t get_current_menu_viewer (void) -{ - const char *selected_name = grub_env_get ("menuviewer"); - - /* If none selected, pick the last registered one. */ - if (selected_name == 0) - return menu_viewer_list; - - grub_menu_viewer_t cur; - for (cur = menu_viewer_list; cur; cur = cur->next) - { - if (grub_strcmp (cur->name, selected_name) == 0) - return cur; - } - - /* Fall back to the first entry (or null). */ - return menu_viewer_list; -} - -grub_err_t -grub_menu_viewer_show_menu (grub_menu_t menu, int nested) -{ - grub_menu_viewer_t cur = get_current_menu_viewer (); - grub_err_t err1, err2; - if (!cur) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "No menu viewer available."); - - while (1) - { - err1 = cur->show_menu (menu, nested); - grub_print_error (); - - err2 = grub_auth_check_authentication (NULL); - if (err2) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - continue; - } - - break; - } - - return err1; -} diff --git a/normal/term.c b/normal/term.c index 73eab548a..ff5120d48 100644 --- a/normal/term.c +++ b/normal/term.c @@ -16,8 +16,12 @@ * along with GRUB. If not, see . */ +#include +#include +#include + /* The amount of lines counted by the pager. */ -static int grub_more_lines; +static unsigned grub_more_lines; /* If the more pager is active. */ static int grub_more; @@ -25,36 +29,37 @@ static int grub_more; static void process_newline (void) { - if (code == '\n') + struct grub_term_output *cur; + unsigned height = -1; + + for (cur = grub_term_outputs; cur; cur = cur->next) + if (grub_term_is_active(cur) && grub_term_height (cur) < height) + height = grub_term_height (cur); + grub_more_lines++; + + if (grub_more && grub_more_lines == height - 1) { - grub_putcode ('\r'); + char key; + grub_uint16_t *pos; - grub_more_lines++; + pos = grub_term_save_pos (); - if (grub_more && grub_more_lines == height - 1) - { - char key; - int pos = term->getxy (); + grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); + grub_printf ("--MORE--"); + grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); - /* Show --MORE-- on the lower left side of the screen. */ - term->gotoxy (1, height - 1); - grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); - grub_printf ("--MORE--"); - grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); + key = grub_getkey (); - key = grub_getkey (); + /* Remove the message. */ + grub_term_restore_pos (pos); + grub_printf (" "); + grub_term_restore_pos (pos); - /* Remove the message. */ - term->gotoxy (1, height - 1); - grub_printf (" "); - term->gotoxy (pos >> 8, pos & 0xFF); - - /* Scroll one lines or an entire page, depending on the key. */ - if (key == '\r' || key =='\n') - grub_more_lines--; - else - grub_more_lines = 0; - } + /* Scroll one lines or an entire page, depending on the key. */ + if (key == '\r' || key =='\n') + grub_more_lines--; + else + grub_more_lines = 0; } } @@ -67,6 +72,7 @@ grub_set_more (int onoff) grub_more--; grub_more_lines = 0; + grub_newline_hook = process_newline; } void @@ -74,21 +80,14 @@ grub_puts_terminal (const char *str, struct grub_term_output *term) { grub_uint32_t code; grub_ssize_t ret; - const char *ptr = str; - unsigned i; + const grub_uint8_t *ptr = (const grub_uint8_t *) str; + const grub_uint8_t *end; + end = (const grub_uint8_t *) (str + grub_strlen (str)); while (*ptr) { - ret = grub_utf8_to_ucs4 (&code, 1, ptr, - grub_strlen (ptr), &ptr); - if (ret < 0) - { - grub_putcode ('?', term); - ptr++; - continue; - } - else - grub_putcode (code, term); + ret = grub_utf8_to_ucs4 (&code, 1, ptr, end - ptr, &ptr); + grub_putcode (code, term); } } @@ -100,16 +99,17 @@ grub_term_save_pos (void) grub_uint16_t *ret, *ptr; for (cur = grub_term_outputs; cur; cur = cur->next) - if (cur->flags & GRUB_TERM_ACTIVE) + if (grub_term_is_active (cur)) cnt++; ret = grub_malloc (cnt * sizeof (ret[0])); if (!ret) return NULL; + ptr = ret; for (cur = grub_term_outputs; cur; cur = cur->next) - if (cur->flags & GRUB_TERM_ACTIVE) - *ptr++ = cur->getxy (); + if (grub_term_is_active (cur)) + *ptr++ = grub_term_getxy (cur); return ret; } @@ -118,11 +118,15 @@ void grub_term_restore_pos (grub_uint16_t *pos) { struct grub_term_output *cur; + grub_uint16_t *ptr = pos; if (!pos) return; for (cur = grub_term_outputs; cur; cur = cur->next) - if (cur->flags & GRUB_TERM_ACTIVE) - cur->gotoxy ((*ptr & 0xff00) >> 8, *ptr & 0xff); + if (grub_term_is_active (cur)) + { + grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff); + ptr++; + } } diff --git a/term/efi/console.c b/term/efi/console.c index f3845089c..bde101ebc 100644 --- a/term/efi/console.c +++ b/term/efi/console.c @@ -352,7 +352,7 @@ static struct grub_term_output grub_console_term_output = .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, .setcursor = grub_console_setcursor, - .flags = 0, + .flags = GRUB_TERM_ACTIVE, }; void diff --git a/term/i386/pc/console.c b/term/i386/pc/console.c index b54e2f6f1..6f56fc0d7 100644 --- a/term/i386/pc/console.c +++ b/term/i386/pc/console.c @@ -66,7 +66,7 @@ static struct grub_term_output grub_console_term_output = .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, .setcursor = grub_console_setcursor, - .flags = 0, + .flags = GRUB_TERM_ACTIVE, }; void diff --git a/term/i386/pc/vga_text.c b/term/i386/pc/vga_text.c index 170f74de8..4fc54a60d 100644 --- a/term/i386/pc/vga_text.c +++ b/term/i386/pc/vga_text.c @@ -164,10 +164,17 @@ static struct grub_term_output grub_vga_text_term = .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, .setcursor = grub_vga_text_setcursor, +#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) + .flags = GRUB_TERM_ACTIVE, +#endif }; GRUB_MOD_INIT(vga_text) { +#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) + grub_vga_text_init_fini (); +#endif + grub_term_register_output ("vga_text", &grub_vga_text_term); } diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index ab11e9fb2..95479379e 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -415,7 +415,7 @@ static struct grub_term_output grub_ofconsole_term_output = .getcolor = grub_ofconsole_getcolor, .setcursor = grub_ofconsole_setcursor, .refresh = grub_ofconsole_refresh, - .flags = 0, + .flags = GRUB_TERM_ACTIVE, }; void diff --git a/util/console.c b/util/console.c index 9d8bb1a63..d9a907308 100644 --- a/util/console.c +++ b/util/console.c @@ -368,7 +368,7 @@ static struct grub_term_output grub_ncurses_term_output = .getcolor = grub_ncurses_getcolor, .setcursor = grub_ncurses_setcursor, .refresh = grub_ncurses_refresh, - .flags = 0, + .flags = GRUB_TERM_ACTIVE }; void From 2322a1269372e8b9186da63c2384a407f73cbffb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 16:25:10 +0100 Subject: [PATCH 045/164] remove list iterators to save space --- kern/term.c | 85 +++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 58 deletions(-) diff --git a/kern/term.c b/kern/term.c index b71c12334..d0d29eb9c 100644 --- a/kern/term.c +++ b/kern/term.c @@ -67,24 +67,16 @@ grub_putchar (int c) grub_uint32_t code; grub_ssize_t ret; - auto int do_putcode (grub_list_t item); - int do_putcode (grub_list_t item) - { - struct grub_term_output *term = (struct grub_term_output *) item; - - if (grub_term_is_active (term)) - grub_putcode (code, term); - - return 0; - } - buf[size++] = c; ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0); if (ret != 0) { + struct grub_term_output *term; size = 0; - grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), do_putcode); + for (term = grub_term_outputs; term; term = term->next) + if (grub_term_is_active (term)) + grub_putcode (code, term); } if (ret == '\n' && grub_newline_hook) grub_newline_hook (); @@ -114,62 +106,39 @@ grub_getkeystatus (void) void grub_cls (void) { - auto int hook (grub_list_t item); - int hook (grub_list_t item) - { - struct grub_term_output *term = (struct grub_term_output *) item; + struct grub_term_output *term; + + for (term = grub_term_outputs; term; term = term->next) + { + if (! grub_term_is_active (term)) + continue; - if (! grub_term_is_active (term)) - return 0; - - if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) - { - grub_putcode ('\n', term); - grub_refresh (); - } - else - (term->cls) (); - - return 0; - } - - grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); + if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) + { + grub_putcode ('\n', term); + grub_refresh (); + } + else + (term->cls) (); + } } void grub_setcolorstate (grub_term_color_state state) { - auto int hook (grub_list_t item); - int hook (grub_list_t item) - { - struct grub_term_output *term = (struct grub_term_output *) item; - - if (! grub_term_is_active (term)) - return 0; - - grub_term_setcolorstate (term, state); - - return 0; - } - - grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); + struct grub_term_output *term; + + for (term = grub_term_outputs; term; term = term->next) + if (grub_term_is_active (term)) + grub_term_setcolorstate (term, state); } void grub_refresh (void) { - auto int hook (grub_list_t item); - int hook (grub_list_t item) - { - struct grub_term_output *term = (struct grub_term_output *) item; + struct grub_term_output *term; - if (!grub_term_is_active (term)) - return 0; - - grub_term_refresh (term); - - return 0; - } - - grub_list_iterate (GRUB_AS_LIST (grub_term_outputs), hook); + for (term = grub_term_outputs; term; term = term->next) + if (grub_term_is_active (term)) + grub_term_refresh (term); } From 8eca55a6eb63bf2ad24fe2655286e644e8d2ddd8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 24 Dec 2009 17:08:14 +0100 Subject: [PATCH 046/164] Imported nyu's multi-input --- commands/keystatus.c | 17 +++++++++++----- include/grub/term.h | 19 ++++-------------- kern/misc.c | 4 +++- kern/term.c | 48 ++++++++++++++++++++++++++++++++------------ util/console.c | 1 - util/grub-editenv.c | 3 --- 6 files changed, 54 insertions(+), 38 deletions(-) diff --git a/commands/keystatus.c b/commands/keystatus.c index 0a4667645..1bb22bde3 100644 --- a/commands/keystatus.c +++ b/commands/keystatus.c @@ -48,13 +48,20 @@ grub_cmd_keystatus (grub_extcmd_t cmd, if (state[2].set) expect_mods |= GRUB_TERM_STATUS_ALT; + grub_dprintf ("keystatus", "expect_mods: %d\n", expect_mods); + /* Without arguments, just check whether getkeystatus is supported at all. */ - if (!grub_cur_term_input->getkeystatus) - return grub_error (GRUB_ERR_TEST_FAILURE, "false"); - grub_dprintf ("keystatus", "expect_mods: %d\n", expect_mods); - if (!expect_mods) - return 0; + if (expect_mods == 0) + { + grub_term_input_t term; + + FOR_ACTIVE_TERM_INPUTS (term) + if (term->getkeystatus) + return 0; + + return grub_error (GRUB_ERR_TEST_FAILURE, "false"); + } mods = grub_getkeystatus (); grub_dprintf ("keystatus", "mods: %d\n", mods); diff --git a/include/grub/term.h b/include/grub/term.h index a0b96b497..fb9ed6f0c 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -197,14 +197,14 @@ struct grub_term_output }; typedef struct grub_term_output *grub_term_output_t; -extern struct grub_handler_class EXPORT_VAR(grub_term_input_class); extern struct grub_term_output *EXPORT_VAR(grub_term_outputs); +extern struct grub_term_input *EXPORT_VAR(grub_term_inputs); static inline void grub_term_register_input (const char *name __attribute__ ((unused)), grub_term_input_t term) { - grub_handler_register (&grub_term_input_class, GRUB_AS_HANDLER (term)); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } static inline void @@ -217,7 +217,7 @@ grub_term_register_output (const char *name __attribute__ ((unused)), static inline void grub_term_unregister_input (grub_term_input_t term) { - grub_handler_unregister (&grub_term_input_class, GRUB_AS_HANDLER (term)); + grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } static inline void @@ -226,18 +226,7 @@ grub_term_unregister_output (grub_term_output_t term) grub_list_remove (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } -static inline grub_err_t -grub_term_set_current_input (grub_term_input_t term) -{ - return grub_handler_set_current (&grub_term_input_class, - GRUB_AS_HANDLER (term)); -} - -static inline grub_term_input_t -grub_term_get_current_input (void) -{ - return (grub_term_input_t) grub_term_input_class.cur_handler; -} +#define FOR_ACTIVE_TERM_INPUTS(var) for (var = grub_term_inputs; var; var = var->next) void EXPORT_FUNC(grub_putchar) (int c); void EXPORT_FUNC(grub_putcode) (grub_uint32_t code, diff --git a/kern/misc.c b/kern/misc.c index ef782f5dd..af6f97758 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -975,7 +975,9 @@ grub_abort (void) { grub_printf ("\nAborted."); - if (grub_term_get_current_input ()) +#ifndef GRUB_UTIL + if (grub_term_inputs) +#endif { grub_printf (" Press any key to exit."); grub_getkey (); diff --git a/kern/term.c b/kern/term.c index d0d29eb9c..9ce906719 100644 --- a/kern/term.c +++ b/kern/term.c @@ -21,15 +21,10 @@ #include #include #include - -struct grub_handler_class grub_term_input_class = - { - .name = "terminal_input" - }; - -#define grub_cur_term_input grub_term_get_current_input () +#include struct grub_term_output *grub_term_outputs; +struct grub_term_input *grub_term_inputs; void (*grub_newline_hook) (void) = NULL; @@ -85,22 +80,49 @@ grub_putchar (int c) int grub_getkey (void) { - return (grub_cur_term_input->getkey) (); + grub_term_input_t term; + + while (1) + { + FOR_ACTIVE_TERM_INPUTS(term) + { + int key = term->checkkey (); + if (key != -1) + return term->getkey (); + } + + grub_cpu_idle (); + } } int grub_checkkey (void) { - return (grub_cur_term_input->checkkey) (); + grub_term_input_t term; + + FOR_ACTIVE_TERM_INPUTS(term) + { + int key = term->checkkey (); + if (key != -1) + return key; + } + + return -1; } int grub_getkeystatus (void) { - if (grub_cur_term_input->getkeystatus) - return (grub_cur_term_input->getkeystatus) (); - else - return 0; + int status = 0; + grub_term_input_t term; + + FOR_ACTIVE_TERM_INPUTS(term) + { + if (term->getkeystatus) + status |= term->getkeystatus (); + } + + return status; } void diff --git a/util/console.c b/util/console.c index d9a907308..be64eb9d8 100644 --- a/util/console.c +++ b/util/console.c @@ -377,7 +377,6 @@ grub_console_init (void) grub_term_register_output ("console", &grub_ncurses_term_output); grub_term_register_input ("console", &grub_ncurses_term_input); grub_term_set_current_output (&grub_ncurses_term_output); - grub_term_set_current_input (&grub_ncurses_term_input); } void diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 68fb23b15..e75892430 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -46,9 +46,6 @@ grub_refresh (void) fflush (stdout); } -struct grub_handler_class grub_term_input_class; -struct grub_handler_class grub_term_output_class; - int grub_getkey (void) { From 3be7f8de12a9ea524cf8209770bf39e7c464736c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 17:51:43 +0100 Subject: [PATCH 047/164] FORALL_ACTIVE_TERM_OUTPUTS macro --- commands/help.c | 34 ++++++++++---------- include/grub/term.h | 1 + kern/term.c | 38 ++++++++++------------- normal/cmdline.c | 18 +++++------ normal/color.c | 17 +++++----- normal/main.c | 18 +++++------ normal/menu_text.c | 76 ++++++++++++++++++++++----------------------- normal/term.c | 25 +++++++-------- 8 files changed, 106 insertions(+), 121 deletions(-) diff --git a/commands/help.c b/commands/help.c index 5e8f0b27a..bfca5e0cc 100644 --- a/commands/help.c +++ b/commands/help.c @@ -39,22 +39,20 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, { struct grub_term_output *cur; int desclen = grub_strlen (cmd->summary); - for (cur = grub_term_outputs; cur; cur = cur->next) - { - if (!grub_term_is_active (cur)) - continue; - int width = grub_term_width(cur); - char description[width / 2]; + FOR_ACTIVE_TERM_OUTPUTS(cur) + { + int width = grub_term_width(cur); + char description[width / 2]; - /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled - with the description followed by spaces. */ - grub_memset (description, ' ', width / 2 - 1); - description[width / 2 - 1] = '\0'; - grub_memcpy (description, cmd->summary, - (desclen < width / 2 - 1 - ? desclen : width / 2 - 1)); - grub_puts_terminal (description, cur); - } + /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled + with the description followed by spaces. */ + grub_memset (description, ' ', width / 2 - 1); + description[width / 2 - 1] = '\0'; + grub_memcpy (description, cmd->summary, + (desclen < width / 2 - 1 + ? desclen : width / 2 - 1)); + grub_puts_terminal (description, cur); + } if ((cnt++) % 2) grub_printf ("\n"); else @@ -83,7 +81,11 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, } if (argc == 0) - grub_command_iterate (print_command_info); + { + grub_command_iterate (print_command_info); + if (!(cnt % 2)) + grub_printf ("\n"); + } else { int i; diff --git a/include/grub/term.h b/include/grub/term.h index fb9ed6f0c..bf6766af6 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -227,6 +227,7 @@ grub_term_unregister_output (grub_term_output_t term) } #define FOR_ACTIVE_TERM_INPUTS(var) for (var = grub_term_inputs; var; var = var->next) +#define FOR_ACTIVE_TERM_OUTPUTS(var) for (var = grub_term_outputs; var; var = var->next) if (grub_term_is_active (var)) void EXPORT_FUNC(grub_putchar) (int c); void EXPORT_FUNC(grub_putcode) (grub_uint32_t code, diff --git a/kern/term.c b/kern/term.c index 9ce906719..dbcac1b19 100644 --- a/kern/term.c +++ b/kern/term.c @@ -69,9 +69,8 @@ grub_putchar (int c) { struct grub_term_output *term; size = 0; - for (term = grub_term_outputs; term; term = term->next) - if (grub_term_is_active (term)) - grub_putcode (code, term); + FOR_ACTIVE_TERM_OUTPUTS(term) + grub_putcode (code, term); } if (ret == '\n' && grub_newline_hook) grub_newline_hook (); @@ -129,20 +128,17 @@ void grub_cls (void) { struct grub_term_output *term; - - for (term = grub_term_outputs; term; term = term->next) - { - if (! grub_term_is_active (term)) - continue; - if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) - { - grub_putcode ('\n', term); - grub_refresh (); - } - else - (term->cls) (); - } + FOR_ACTIVE_TERM_OUTPUTS(term) + { + if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) + { + grub_putcode ('\n', term); + grub_refresh (); + } + else + (term->cls) (); + } } void @@ -150,9 +146,8 @@ grub_setcolorstate (grub_term_color_state state) { struct grub_term_output *term; - for (term = grub_term_outputs; term; term = term->next) - if (grub_term_is_active (term)) - grub_term_setcolorstate (term, state); + FOR_ACTIVE_TERM_OUTPUTS(term) + grub_term_setcolorstate (term, state); } void @@ -160,7 +155,6 @@ grub_refresh (void) { struct grub_term_output *term; - for (term = grub_term_outputs; term; term = term->next) - if (grub_term_is_active (term)) - grub_term_refresh (term); + FOR_ACTIVE_TERM_OUTPUTS(term) + grub_term_refresh (term); } diff --git a/normal/cmdline.c b/normal/cmdline.c index 1412a6d6a..0f90fc2fe 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -363,21 +363,19 @@ grub_cmdline_get (const char *prompt) struct cmdline_term *cl_term_cur; struct grub_term_output *cur; nterms = 0; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active (cur)) - nterms++; + FOR_ACTIVE_TERM_OUTPUTS(cur) + nterms++; cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); if (!cl_terms) return 0; cl_term_cur = cl_terms; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active (cur)) - { - cl_term_cur->term = cur; - init_clterm (cl_term_cur); - cl_term_cur++; - } + FOR_ACTIVE_TERM_OUTPUTS(cur) + { + cl_term_cur->term = cur; + init_clterm (cl_term_cur); + cl_term_cur++; + } } if (hist_used == 0) diff --git a/normal/color.c b/normal/color.c index 80a285787..bae082911 100644 --- a/normal/color.c +++ b/normal/color.c @@ -110,17 +110,14 @@ set_colors (void) { struct grub_term_output *term; - for (term = grub_term_outputs; term; term = term->next) - { - if (! grub_term_is_active (term)) - continue; + FOR_ACTIVE_TERM_OUTPUTS(term) + { + /* Reloads terminal `normal' and `highlight' colors. */ + grub_term_setcolor (term, color_normal, color_highlight); - /* Reloads terminal `normal' and `highlight' colors. */ - grub_term_setcolor (term, color_normal, color_highlight); - - /* Propagates `normal' color to terminal current color. */ - grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); - } + /* Propagates `normal' color to terminal current color. */ + grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); + } } /* Replace default `normal' colors with the ones specified by user (if any). */ diff --git a/normal/main.c b/normal/main.c index b490f49e5..e1ffddae7 100644 --- a/normal/main.c +++ b/normal/main.c @@ -520,16 +520,14 @@ grub_normal_reader_init (void) grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : ""); - for (term = grub_term_outputs; term; term = term->next) - { - if (! (term->flags & GRUB_TERM_ACTIVE)) - continue; - grub_normal_init_page (term); - grub_term_setcursor (term, 1); - - grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); - grub_puts ("\n"); - } + FOR_ACTIVE_TERM_OUTPUTS(term) + { + grub_normal_init_page (term); + grub_term_setcursor (term, 1); + + grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); + grub_puts ("\n"); + } grub_free (msg_formatted); return 0; diff --git a/normal/menu_text.c b/normal/menu_text.c index edb315524..991a9ba4d 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -439,45 +439,43 @@ grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested) struct grub_menu_viewer *instance; struct grub_term_output *term; - for (term = grub_term_outputs; term; term = term->next) - { - if (!grub_term_is_active (term)) + FOR_ACTIVE_TERM_OUTPUTS(term) + { + instance = grub_zalloc (sizeof (*instance)); + if (!instance) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; continue; - instance = grub_zalloc (sizeof (*instance)); - if (!instance) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - continue; - } - data = grub_zalloc (sizeof (*data)); - if (!data) - { - grub_free (instance); - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - continue; - } - data->term = term; - instance->data = data; - instance->set_chosen_entry = menu_text_set_chosen_entry; - instance->print_timeout = menu_text_print_timeout; - instance->clear_timeout = menu_text_clear_timeout; - instance->fini = menu_text_fini; + } + data = grub_zalloc (sizeof (*data)); + if (!data) + { + grub_free (instance); + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + continue; + } + data->term = term; + instance->data = data; + instance->set_chosen_entry = menu_text_set_chosen_entry; + instance->print_timeout = menu_text_print_timeout; + instance->clear_timeout = menu_text_clear_timeout; + instance->fini = menu_text_fini; + + data->menu = menu; + + data->offset = entry; + data->first = 0; + if (data->offset > grub_term_num_entries (data->term) - 1) + { + data->first = data->offset - (grub_term_num_entries (data->term) - 1); + data->offset = grub_term_num_entries (data->term) - 1; + } - data->menu = menu; - - data->offset = entry; - data->first = 0; - if (data->offset > grub_term_num_entries (data->term) - 1) - { - data->first = data->offset - (grub_term_num_entries (data->term) - 1); - data->offset = grub_term_num_entries (data->term) - 1; - } - - grub_term_setcursor (data->term, 0); - grub_menu_init_page (nested, 0, data->term); - print_entries (menu, data->first, data->offset, data->term); - grub_term_refresh (data->term); - } + grub_term_setcursor (data->term, 0); + grub_menu_init_page (nested, 0, data->term); + print_entries (menu, data->first, data->offset, data->term); + grub_term_refresh (data->term); + } } diff --git a/normal/term.c b/normal/term.c index ff5120d48..eb8f8e844 100644 --- a/normal/term.c +++ b/normal/term.c @@ -32,8 +32,8 @@ process_newline (void) struct grub_term_output *cur; unsigned height = -1; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active(cur) && grub_term_height (cur) < height) + FOR_ACTIVE_TERM_OUTPUTS(cur) + if (grub_term_height (cur) < height) height = grub_term_height (cur); grub_more_lines++; @@ -98,18 +98,16 @@ grub_term_save_pos (void) unsigned cnt = 0; grub_uint16_t *ret, *ptr; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active (cur)) - cnt++; + FOR_ACTIVE_TERM_OUTPUTS(cur) + cnt++; ret = grub_malloc (cnt * sizeof (ret[0])); if (!ret) return NULL; ptr = ret; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active (cur)) - *ptr++ = grub_term_getxy (cur); + FOR_ACTIVE_TERM_OUTPUTS(cur) + *ptr++ = grub_term_getxy (cur); return ret; } @@ -123,10 +121,9 @@ grub_term_restore_pos (grub_uint16_t *pos) if (!pos) return; - for (cur = grub_term_outputs; cur; cur = cur->next) - if (grub_term_is_active (cur)) - { - grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff); - ptr++; - } + FOR_ACTIVE_TERM_OUTPUTS(cur) + { + grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff); + ptr++; + } } From 0aa6339849fb73487ccc304ec37cddc4f1bfd63e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 21:54:37 +0100 Subject: [PATCH 048/164] Working multi-terminal --- commands/handler.c | 29 +---- commands/terminal.c | 290 +++++++++++++++++++++++++++++++++++++++++ genhandlerlist.sh | 6 +- include/grub/term.h | 42 ++++-- kern/term.c | 2 + term/i386/pc/console.c | 7 +- 6 files changed, 334 insertions(+), 42 deletions(-) create mode 100644 commands/terminal.c diff --git a/commands/handler.c b/commands/handler.c index d65a703e4..60889dd5e 100644 --- a/commands/handler.c +++ b/commands/handler.c @@ -25,10 +25,9 @@ #include static grub_err_t -grub_cmd_handler (struct grub_command *cmd, +grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { - char *class_name; void *curr_item = 0; grub_handler_class_t head; @@ -43,23 +42,19 @@ grub_cmd_handler (struct grub_command *cmd, return 0; } - class_name = (grub_strcmp (cmd->name, "handler")) ? (char *) cmd->name : 0; - head = grub_handler_class_list; - if ((argc == 0) && (class_name == 0)) + if (argc == 0) { grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_item); } else { + char *class_name; grub_handler_class_t class; - if (class_name == 0) - { - class_name = args[0]; - argc--; - args++; - } + class_name = args[0]; + argc--; + args++; class = grub_named_list_find (GRUB_AS_NAMED_LIST (head), class_name); if (! class) @@ -89,7 +84,7 @@ grub_cmd_handler (struct grub_command *cmd, return 0; } -static grub_command_t cmd_handler, cmd_terminal_input, cmd_terminal_output; +static grub_command_t cmd_handler; GRUB_MOD_INIT(handler) { @@ -97,19 +92,9 @@ GRUB_MOD_INIT(handler) grub_register_command ("handler", grub_cmd_handler, "handler [class [handler]]", "List or select a handler."); - cmd_terminal_input = - grub_register_command ("terminal_input", grub_cmd_handler, - "terminal_input [handler]", - "List or select an input terminal."); - cmd_terminal_output = - grub_register_command ("terminal_output", grub_cmd_handler, - "terminal_output [handler]", - "List or select an output terminal."); } GRUB_MOD_FINI(handler) { grub_unregister_command (cmd_handler); - grub_unregister_command (cmd_terminal_input); - grub_unregister_command (cmd_terminal_output); } diff --git a/commands/terminal.c b/commands/terminal.c new file mode 100644 index 000000000..850d8296a --- /dev/null +++ b/commands/terminal.c @@ -0,0 +1,290 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +grub_err_t +grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + int i; + grub_term_input_t term; + + if (argc == 0) + { + grub_puts_ (N_ ("Active input terminals:")); + FOR_ACTIVE_TERM_INPUTS(term) + grub_printf ("%s ", term->name); + grub_printf ("\n"); + grub_puts_ (N_ ("Available input terminals:")); + FOR_DISABLED_TERM_INPUTS(term) + grub_printf ("%s ", term->name); + grub_printf ("\n"); + return GRUB_ERR_NONE; + } + i = 0; + + if (grub_strcmp (args[0], "--append") == 0 + || grub_strcmp (args[0], "--removed") == 0) + i++; + + if (i == argc) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified")); + + for (; i < argc; i++) + { + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + } + + if (grub_strcmp (args[0], "--append") == 0) + { + for (i = 1; i < argc; i++) + { + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), + GRUB_AS_LIST (term)); + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), + GRUB_AS_LIST (term)); + } + } + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[0], "--remove") == 0) + { + for (i = 1; i < argc; i++) + { + FOR_ACTIVE_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + if (!term->next && term == grub_term_inputs) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "can't remove the last terminal"); + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)), + GRUB_AS_LIST (term)); + if (term->fini) + term->fini (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); + } + } + return GRUB_ERR_NONE; + } + for (i = 0; i < argc; i++) + { + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), + GRUB_AS_LIST (term)); + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), + GRUB_AS_LIST (term)); + } + } + + FOR_ACTIVE_TERM_INPUTS(term) + { + for (i = 0; i < argc; i++) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (i != argc) + { + if (!term->next && term == grub_term_inputs) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "can't remove the last terminal"); + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)), + GRUB_AS_LIST (term)); + if (term->fini) + term->fini (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); + } + } + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + int i; + grub_term_output_t term; + + if (argc == 0) + { + grub_puts_ (N_ ("Active output terminals:")); + FOR_ACTIVE_TERM_OUTPUTS(term) + grub_printf ("%s ", term->name); + grub_printf ("\n"); + grub_puts_ (N_ ("Available output terminals:")); + FOR_DISABLED_TERM_OUTPUTS(term) + grub_printf ("%s ", term->name); + grub_printf ("\n"); + return GRUB_ERR_NONE; + } + i = 0; + + if (grub_strcmp (args[0], "--append") == 0 + || grub_strcmp (args[0], "--removed") == 0) + i++; + + if (i == argc) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified")); + + for (; i < argc; i++) + { + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + } + + if (grub_strcmp (args[0], "--append") == 0) + { + for (i = 1; i < argc; i++) + { + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), + GRUB_AS_LIST (term)); + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), + GRUB_AS_LIST (term)); + } + } + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[0], "--remove") == 0) + { + for (i = 1; i < argc; i++) + { + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + if (!term->next && term == grub_term_outputs) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "can't remove the last terminal"); + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)), + GRUB_AS_LIST (term)); + if (term->fini) + term->fini (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); + } + } + return GRUB_ERR_NONE; + } + for (i = 0; i < argc; i++) + { + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) + { + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), + GRUB_AS_LIST (term)); + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), + GRUB_AS_LIST (term)); + } + } + + FOR_ACTIVE_TERM_OUTPUTS(term) + { + for (i = 0; i < argc; i++) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (i != argc) + { + if (!term->next && term == grub_term_outputs) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "can't remove the last terminal"); + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)), + GRUB_AS_LIST (term)); + if (term->fini) + term->fini (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); + } + } + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_terminal_input, cmd_terminal_output; + +GRUB_MOD_INIT(terminal) +{ + cmd_terminal_input = + grub_register_command ("terminal_input", grub_cmd_terminal_input, + "terminal_input [--append|--remove] " + "[TERMINAL1] [TERMINAL2] ...", + "List or select an input terminal."); + cmd_terminal_output = + grub_register_command ("terminal_output", grub_cmd_terminal_output, + "terminal_output [--append|--remove] " + "[TERMINAL1] [TERMINAL2] ...", + "List or select an output terminal."); +} + +GRUB_MOD_FINI(terminal) +{ + grub_unregister_command (cmd_terminal_input); + grub_unregister_command (cmd_terminal_output); +} diff --git a/genhandlerlist.sh b/genhandlerlist.sh index 6446a98ff..e4cb0d9de 100644 --- a/genhandlerlist.sh +++ b/genhandlerlist.sh @@ -16,8 +16,4 @@ module=$1 grep -v "^#" | sed -n \ - -e "/grub_parser_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/parser.\1: $module/;p;}" \ - -e "/grub_reader_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/reader.\1: $module/;p;}" \ - -e "/grub_term_register_input *( *\"/{s/.*( *\"\([^\"]*\)\".*/terminal_input.\1: $module/;p;}" \ - -e "/grub_term_register_output *( *\"/{s/.*( *\"\([^\"]*\)\".*/terminal_output.\1: $module/;p;}" \ - -e "/grub_menu_viewer_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/menu_viewer.\1: $module/;p;}" + -e "/grub_parser_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/parser.\1: $module/;p;}" diff --git a/include/grub/term.h b/include/grub/term.h index bf6766af6..24bb503ba 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -68,8 +68,6 @@ grub_term_color_state; #define GRUB_TERM_NO_EDIT (1 << 1) /* Set when the terminal cannot do fancy things. */ #define GRUB_TERM_DUMB (1 << 2) -/* Terminal is used as general output. */ -#define GRUB_TERM_ACTIVE (1 << 3) /* Set when the terminal needs to be initialized. */ #define GRUB_TERM_NEED_INIT (1 << 16) @@ -197,37 +195,65 @@ struct grub_term_output }; typedef struct grub_term_output *grub_term_output_t; +extern struct grub_term_output *EXPORT_VAR(grub_term_outputs_disabled); +extern struct grub_term_input *EXPORT_VAR(grub_term_inputs_disabled); extern struct grub_term_output *EXPORT_VAR(grub_term_outputs); extern struct grub_term_input *EXPORT_VAR(grub_term_inputs); +static inline void +grub_term_register_input_active (const char *name __attribute__ ((unused)), + grub_term_input_t term) +{ + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); +} + static inline void grub_term_register_input (const char *name __attribute__ ((unused)), grub_term_input_t term) { - grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); +} + +static inline void +grub_term_register_output_active (const char *name __attribute__ ((unused)), + grub_term_output_t term) +{ + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } static inline void grub_term_register_output (const char *name __attribute__ ((unused)), grub_term_output_t term) { - grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); } static inline void grub_term_unregister_input (grub_term_input_t term) { grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); } static inline void grub_term_unregister_output (grub_term_output_t term) { grub_list_remove (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), + GRUB_AS_LIST (term)); } #define FOR_ACTIVE_TERM_INPUTS(var) for (var = grub_term_inputs; var; var = var->next) -#define FOR_ACTIVE_TERM_OUTPUTS(var) for (var = grub_term_outputs; var; var = var->next) if (grub_term_is_active (var)) +#define FOR_DISABLED_TERM_INPUTS(var) for (var = grub_term_inputs_disabled; var; var = var->next) +#define FOR_ACTIVE_TERM_OUTPUTS(var) for (var = grub_term_outputs; var; var = var->next) +#define FOR_DISABLED_TERM_OUTPUTS(var) for (var = grub_term_outputs_disabled; var; var = var->next) void EXPORT_FUNC(grub_putchar) (int c); void EXPORT_FUNC(grub_putcode) (grub_uint32_t code, @@ -335,12 +361,6 @@ grub_term_setcursor (struct grub_term_output *term, int on) term->setcursor (on); } -static inline int -grub_term_is_active (struct grub_term_output *term) -{ - return !!(term->flags & GRUB_TERM_ACTIVE); -} - static inline grub_ssize_t grub_term_getcharwidth (struct grub_term_output *term, grub_uint32_t c) { diff --git a/kern/term.c b/kern/term.c index dbcac1b19..51eee3b08 100644 --- a/kern/term.c +++ b/kern/term.c @@ -23,6 +23,8 @@ #include #include +struct grub_term_output *grub_term_outputs_disabled; +struct grub_term_input *grub_term_inputs_disabled; struct grub_term_output *grub_term_outputs; struct grub_term_input *grub_term_inputs; diff --git a/term/i386/pc/console.c b/term/i386/pc/console.c index 6f56fc0d7..3c0fcccad 100644 --- a/term/i386/pc/console.c +++ b/term/i386/pc/console.c @@ -65,15 +65,14 @@ static struct grub_term_output grub_console_term_output = .setcolorstate = grub_console_setcolorstate, .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, - .setcursor = grub_console_setcursor, - .flags = GRUB_TERM_ACTIVE, + .setcursor = grub_console_setcursor }; void grub_console_init (void) { - grub_term_register_output ("console", &grub_console_term_output); - grub_term_register_input ("console", &grub_console_term_input); + grub_term_register_output_active ("console", &grub_console_term_output); + grub_term_register_input_active ("console", &grub_console_term_input); } void From 4b4513adb360888c8e438bf5828d4d624e0da110 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 22:55:06 +0100 Subject: [PATCH 049/164] bugfix in cmdline handling --- normal/cmdline.c | 113 ++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/normal/cmdline.c b/normal/cmdline.c index 0f90fc2fe..c71ac47ce 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -41,7 +41,7 @@ grub_err_t grub_set_history (int newsize) { grub_uint32_t **old_hist_lines = hist_lines; - hist_lines = grub_malloc (sizeof (char *) * newsize); + hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); /* Copy the old lines into the new buffer. */ if (old_hist_lines) @@ -68,16 +68,16 @@ grub_set_history (int newsize) if (hist_pos < hist_end) grub_memmove (hist_lines, old_hist_lines + hist_pos, - (hist_end - hist_pos) * sizeof (char *)); + (hist_end - hist_pos) * sizeof (grub_uint32_t *)); else if (hist_used) { /* Copy the older part. */ grub_memmove (hist_lines, old_hist_lines + hist_pos, - (hist_size - hist_pos) * sizeof (char *)); + (hist_size - hist_pos) * sizeof (grub_uint32_t *)); /* Copy the newer part. */ grub_memmove (hist_lines + hist_size - hist_pos, old_hist_lines, - hist_end * sizeof (char *)); + hist_end * sizeof (grub_uint32_t *)); } } @@ -109,24 +109,25 @@ strlen_ucs4 (const grub_uint32_t *s) return p - s; } -static grub_uint32_t * -strdup_ucs4 (const grub_uint32_t *s) +/* Replace the history entry on position POS with the string S. */ +static void +grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) { - grub_size_t len; - char *p; - - len = strlen_ucs4 (s) + 1; - p = (char *) grub_malloc (len * sizeof (grub_uint32_t)); - if (! p) - return 0; - - return grub_memcpy (p, s, len * sizeof (grub_uint32_t)); + grub_free (hist_lines[pos]); + hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); + if (!hist_lines[pos]) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + return ; + } + grub_memcpy (hist_lines[pos], s, len * sizeof (grub_uint32_t)); + hist_lines[pos][len] = 0; } - /* Insert a new history line S on the top of the history. */ static void -grub_history_add (grub_uint32_t *s) +grub_history_add (grub_uint32_t *s, grub_size_t len) { /* Remove the oldest entry in the history to make room for a new entry. */ @@ -147,16 +148,15 @@ grub_history_add (grub_uint32_t *s) hist_pos = hist_size + hist_pos; /* Insert into history. */ - hist_lines[hist_pos] = strdup_ucs4 (s); + hist_lines[hist_pos] = NULL; + grub_history_set (hist_pos, s, len); } /* Replace the history entry on position POS with the string S. */ static void -grub_history_replace (int pos, grub_uint32_t *s) +grub_history_replace (int pos, grub_uint32_t *s, grub_size_t len) { - pos = (hist_pos + pos) % hist_size; - grub_free (hist_lines[pos]); - hist_lines[pos] = strdup_ucs4 (s); + grub_history_set ((hist_pos + pos) % hist_size, s, len); } /* A completion hook to print items. */ @@ -322,7 +322,8 @@ grub_cmdline_get (const char *prompt) lpos = saved_lpos; cl_set_pos_all (); - grub_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1); + grub_memmove (buf + lpos, buf + lpos + len, + sizeof (grub_uint32_t) * (llen - lpos + 1)); llen -= len; cl_print_all (lpos, 0); cl_set_pos_all (); @@ -379,7 +380,7 @@ grub_cmdline_get (const char *prompt) } if (hist_used == 0) - grub_history_add (buf); + grub_history_add (buf, llen); while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r') { @@ -413,11 +414,9 @@ grub_cmdline_get (const char *prompt) case 9: /* Ctrl-i or TAB */ { - grub_uint32_t *insert; int restore; - char *bufu8, *insertu8; - grub_size_t insertlen; - grub_size_t t; + char *insertu8; + char *bufu8; buf[lpos] = '\0'; @@ -432,21 +431,6 @@ grub_cmdline_get (const char *prompt) insertu8 = grub_normal_do_completion (bufu8, &restore, print_completion); grub_free (bufu8); - insertlen = grub_strlen (bufu8); - insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); - if (!insert) - { - grub_free (insertu8); - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - break; - } - t = grub_utf8_to_ucs4 (insert, insertlen, - (grub_uint8_t *) insertu8, - insertlen, 0); - insert[t] = 0; - - grub_free (insertu8); if (restore) { @@ -456,9 +440,31 @@ grub_cmdline_get (const char *prompt) cl_print_all (0, 0); } - if (insert) + if (insertu8) { - cl_insert (insert); + grub_size_t insertlen; + grub_ssize_t t; + grub_uint32_t *insert; + + insertlen = grub_strlen (insertu8); + insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); + if (!insert) + { + grub_free (insertu8); + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + break; + } + t = grub_utf8_to_ucs4 (insert, insertlen, + (grub_uint8_t *) insertu8, + insertlen, 0); + if (t > 0) + { + insert[t] = 0; + cl_insert (insert); + } + + grub_free (insertu8); grub_free (insert); } } @@ -470,12 +476,19 @@ grub_cmdline_get (const char *prompt) if (kill_buf) grub_free (kill_buf); - kill_buf = strdup_ucs4 (buf + lpos); + kill_buf = grub_malloc ((llen - lpos + 1) + * sizeof (grub_uint32_t)); if (grub_errno) { grub_print_error (); grub_errno = GRUB_ERR_NONE; } + else + { + grub_memcpy (kill_buf, buf + lpos, + (llen - lpos + 1) * sizeof (grub_uint32_t)); + kill_buf[llen - lpos] = 0; + } cl_delete (llen - lpos); } @@ -489,7 +502,7 @@ grub_cmdline_get (const char *prompt) if (histpos > 0) { - grub_history_replace (histpos, buf); + grub_history_replace (histpos, buf, llen); histpos--; } @@ -507,7 +520,7 @@ grub_cmdline_get (const char *prompt) if (histpos < hist_used - 1) { - grub_history_replace (histpos, buf); + grub_history_replace (histpos, buf, llen); histpos++; } @@ -592,8 +605,8 @@ grub_cmdline_get (const char *prompt) if (strlen_ucs4 (buf) > 0) { grub_uint32_t empty[] = { 0 }; - grub_history_replace (histpos, buf); - grub_history_add (empty); + grub_history_replace (histpos, buf, llen); + grub_history_add (empty, 0); } ret = grub_ucs4_to_utf8_alloc (buf + lpos, llen - lpos + 1); From 686ff5b4d17d22198b6150479878560ddb53a3f2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 23:19:54 +0100 Subject: [PATCH 050/164] Don't output unnecessary newline in command line prompt --- normal/cmdline.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/normal/cmdline.c b/normal/cmdline.c index c71ac47ce..d7f41c7e3 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -356,8 +356,13 @@ grub_cmdline_get (const char *prompt) lpos = llen = 0; buf[0] = '\0'; - grub_putchar ('\n'); + { + grub_term_output_t term; + FOR_ACTIVE_TERM_OUTPUTS(term) + if ((grub_term_getxy (term) >> 8) != 0) + grub_putcode ('\n', term); + } grub_printf ("%s", prompt_translated); { From 9f0cd916a48f554707dd58ae4aad13114a7c7e6a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 23:20:43 +0100 Subject: [PATCH 051/164] Restrict terminfo to serial --- include/grub/terminfo.h | 14 ++++++++------ term/i386/pc/serial.c | 13 +++++++------ term/terminfo.c | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/grub/terminfo.h b/include/grub/terminfo.h index 1ea741e04..e3a2c170a 100644 --- a/include/grub/terminfo.h +++ b/include/grub/terminfo.h @@ -21,15 +21,17 @@ #include #include +#include char *grub_terminfo_get_current (void); grub_err_t grub_terminfo_set_current (const char *); -void grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y); -void grub_terminfo_cls (void); -void grub_terminfo_reverse_video_on (void); -void grub_terminfo_reverse_video_off (void); -void grub_terminfo_cursor_on (void); -void grub_terminfo_cursor_off (void); +void grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y, + grub_term_output_t oterm); +void grub_terminfo_cls (grub_term_output_t oterm); +void grub_terminfo_reverse_video_on (grub_term_output_t oterm); +void grub_terminfo_reverse_video_off (grub_term_output_t oterm); +void grub_terminfo_cursor_on (grub_term_output_t oterm); +void grub_terminfo_cursor_off (grub_term_output_t oterm); #endif /* ! GRUB_TERMINFO_HEADER */ diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index 3f1c6d062..12612efcd 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -30,6 +30,7 @@ #define TEXT_WIDTH 80 #define TEXT_HEIGHT 25 +static struct grub_term_output grub_serial_term_output; static unsigned int xpos, ypos; static unsigned int keep_track = 1; static unsigned int registered = 0; @@ -413,7 +414,7 @@ grub_serial_gotoxy (grub_uint8_t x, grub_uint8_t y) else { keep_track = 0; - grub_terminfo_gotoxy (x, y); + grub_terminfo_gotoxy (x, y, &grub_serial_term_output); keep_track = 1; xpos = x; @@ -425,7 +426,7 @@ static void grub_serial_cls (void) { keep_track = 0; - grub_terminfo_cls (); + grub_terminfo_cls (&grub_serial_term_output); keep_track = 1; xpos = ypos = 0; @@ -439,10 +440,10 @@ grub_serial_setcolorstate (const grub_term_color_state state) { case GRUB_TERM_COLOR_STANDARD: case GRUB_TERM_COLOR_NORMAL: - grub_terminfo_reverse_video_off (); + grub_terminfo_reverse_video_off (&grub_serial_term_output); break; case GRUB_TERM_COLOR_HIGHLIGHT: - grub_terminfo_reverse_video_on (); + grub_terminfo_reverse_video_on (&grub_serial_term_output); break; default: break; @@ -454,9 +455,9 @@ static void grub_serial_setcursor (const int on) { if (on) - grub_terminfo_cursor_on (); + grub_terminfo_cursor_on (&grub_serial_term_output); else - grub_terminfo_cursor_off (); + grub_terminfo_cursor_off (&grub_serial_term_output); } static struct grub_term_input grub_serial_term_input = diff --git a/term/terminfo.c b/term/terminfo.c index 80ae9b100..a793564fd 100644 --- a/term/terminfo.c +++ b/term/terminfo.c @@ -108,52 +108,52 @@ grub_terminfo_set_current (const char *str) /* Wrapper for grub_putchar to write strings. */ static void -putstr (const char *str) +putstr (const char *str, grub_term_output_t oterm) { while (*str) - grub_putchar (*str++); + grub_putcode (*str++, oterm); } /* Move the cursor to the given position starting with "0". */ void -grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y) +grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y, grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.gotoxy, y, x)); + putstr (grub_terminfo_tparm (term.gotoxy, y, x), oterm); } /* Clear the screen. */ void -grub_terminfo_cls (void) +grub_terminfo_cls (grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.cls)); + putstr (grub_terminfo_tparm (term.cls), oterm); } /* Set reverse video mode on. */ void -grub_terminfo_reverse_video_on (void) +grub_terminfo_reverse_video_on (grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.reverse_video_on)); + putstr (grub_terminfo_tparm (term.reverse_video_on), oterm); } /* Set reverse video mode off. */ void -grub_terminfo_reverse_video_off (void) +grub_terminfo_reverse_video_off (grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.reverse_video_off)); + putstr (grub_terminfo_tparm (term.reverse_video_off), oterm); } /* Show cursor. */ void -grub_terminfo_cursor_on (void) +grub_terminfo_cursor_on (grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.cursor_on)); + putstr (grub_terminfo_tparm (term.cursor_on), oterm); } /* Hide cursor. */ void -grub_terminfo_cursor_off (void) +grub_terminfo_cursor_off (grub_term_output_t oterm) { - putstr (grub_terminfo_tparm (term.cursor_off)); + putstr (grub_terminfo_tparm (term.cursor_off), oterm); } /* GRUB Command. */ From abd1cab3d9a2ad8f56cea3466b221c429fc880b0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 23:21:27 +0100 Subject: [PATCH 052/164] Fix terminal_* commands --- commands/terminal.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/commands/terminal.c b/commands/terminal.c index 850d8296a..a667825f4 100644 --- a/commands/terminal.c +++ b/commands/terminal.c @@ -45,7 +45,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), i = 0; if (grub_strcmp (args[0], "--append") == 0 - || grub_strcmp (args[0], "--removed") == 0) + || grub_strcmp (args[0], "--remove") == 0) i++; if (i == argc) @@ -57,7 +57,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), if (grub_strcmp (args[i], term->name) == 0) break; if (term == 0) - FOR_DISABLED_TERM_INPUTS(term) + FOR_ACTIVE_TERM_INPUTS(term) if (grub_strcmp (args[i], term->name) == 0) break; if (term == 0) @@ -128,7 +128,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), for (i = 0; i < argc; i++) if (grub_strcmp (args[i], term->name) == 0) break; - if (i != argc) + if (i == argc) { if (!term->next && term == grub_term_inputs) return grub_error (GRUB_ERR_BAD_ARGUMENT, @@ -167,7 +167,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), i = 0; if (grub_strcmp (args[0], "--append") == 0 - || grub_strcmp (args[0], "--removed") == 0) + || grub_strcmp (args[0], "--remove") == 0) i++; if (i == argc) @@ -179,7 +179,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), if (grub_strcmp (args[i], term->name) == 0) break; if (term == 0) - FOR_DISABLED_TERM_OUTPUTS(term) + FOR_ACTIVE_TERM_OUTPUTS(term) if (grub_strcmp (args[i], term->name) == 0) break; if (term == 0) @@ -229,6 +229,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), } return GRUB_ERR_NONE; } + for (i = 0; i < argc; i++) { FOR_DISABLED_TERM_OUTPUTS(term) @@ -250,7 +251,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), for (i = 0; i < argc; i++) if (grub_strcmp (args[i], term->name) == 0) break; - if (i != argc) + if (i == argc) { if (!term->next && term == grub_term_outputs) return grub_error (GRUB_ERR_BAD_ARGUMENT, From 6d305d4f7da4e3203e279a2748e388bcdd183cf9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Dec 2009 23:37:38 +0100 Subject: [PATCH 053/164] Fix paging. --- kern/term.c | 10 +++------- normal/term.c | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/kern/term.c b/kern/term.c index 51eee3b08..8f8576aa2 100644 --- a/kern/term.c +++ b/kern/term.c @@ -34,10 +34,6 @@ void (*grub_newline_hook) (void) = NULL; void grub_putcode (grub_uint32_t code, struct grub_term_output *term) { - int height; - - height = grub_term_height (term); - if (code == '\t' && term->getxy) { int n; @@ -62,7 +58,7 @@ grub_putchar (int c) static grub_size_t size = 0; static grub_uint8_t buf[6]; grub_uint32_t code; - grub_ssize_t ret; + grub_size_t ret; buf[size++] = c; ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0); @@ -73,9 +69,9 @@ grub_putchar (int c) size = 0; FOR_ACTIVE_TERM_OUTPUTS(term) grub_putcode (code, term); + if (code == '\n' && grub_newline_hook) + grub_newline_hook (); } - if (ret == '\n' && grub_newline_hook) - grub_newline_hook (); } int diff --git a/normal/term.c b/normal/term.c index eb8f8e844..5a8e9cffc 100644 --- a/normal/term.c +++ b/normal/term.c @@ -37,7 +37,7 @@ process_newline (void) height = grub_term_height (cur); grub_more_lines++; - if (grub_more && grub_more_lines == height - 1) + if (grub_more && grub_more_lines >= height - 1) { char key; grub_uint16_t *pos; @@ -57,7 +57,7 @@ process_newline (void) /* Scroll one lines or an entire page, depending on the key. */ if (key == '\r' || key =='\n') - grub_more_lines--; + grub_more_lines = height - 2; else grub_more_lines = 0; } From 288031b37cc2046898f91249c1001d251eb485f0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 00:07:52 +0100 Subject: [PATCH 054/164] REtrieve position from right console in loader/i386/linux.c --- loader/i386/linux.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 140ed1957..e3b8638d2 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -548,8 +548,30 @@ grub_linux_boot (void) /* Initialize these last, because terminal position could be affected by printfs above. */ if (params->have_vga == GRUB_VIDEO_TYPE_TEXT) { - params->video_cursor_x = grub_console_getxy () >> 8; - params->video_cursor_y = grub_console_getxy () & 0xff; + grub_term_output_t term; + int found = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "vga_text") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + found = 1; + } + if (!found) + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "console") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + found = 1; + } + if (!found) + { + params->video_cursor_x = 0; + params->video_cursor_y = 0; + } } #ifdef __x86_64__ From 840f2e6e08124fc5bdd3c82de78de38eedb4177e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 00:12:36 +0100 Subject: [PATCH 055/164] Remove NEED_INIT. --- include/grub/term.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/grub/term.h b/include/grub/term.h index 24bb503ba..479081d86 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -68,8 +68,6 @@ grub_term_color_state; #define GRUB_TERM_NO_EDIT (1 << 1) /* Set when the terminal cannot do fancy things. */ #define GRUB_TERM_DUMB (1 << 2) -/* Set when the terminal needs to be initialized. */ -#define GRUB_TERM_NEED_INIT (1 << 16) /* Bitmasks for modifier keys returned by grub_getkeystatus. */ From 4fc4ee303dc7449db542cce7209f2dd4e5cd5042 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 00:13:03 +0100 Subject: [PATCH 056/164] Set default console on non-i386-pc --- term/efi/console.c | 7 +++---- term/i386/pc/at_keyboard.c | 4 ++++ term/i386/pc/vga_text.c | 11 ++++------- term/ieee1275/ofconsole.c | 7 +++---- util/console.c | 8 +++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/term/efi/console.c b/term/efi/console.c index bde101ebc..dc07c401e 100644 --- a/term/efi/console.c +++ b/term/efi/console.c @@ -351,8 +351,7 @@ static struct grub_term_output grub_console_term_output = .setcolorstate = grub_console_setcolorstate, .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, - .setcursor = grub_console_setcursor, - .flags = GRUB_TERM_ACTIVE, + .setcursor = grub_console_setcursor }; void @@ -366,8 +365,8 @@ grub_console_init (void) return; } - grub_term_register_input ("console", &grub_console_term_input); - grub_term_register_output ("console", &grub_console_term_output); + grub_term_register_input_active ("console", &grub_console_term_input); + grub_term_register_output_active ("console", &grub_console_term_output); } void diff --git a/term/i386/pc/at_keyboard.c b/term/i386/pc/at_keyboard.c index cf30e7242..379cb3a4b 100644 --- a/term/i386/pc/at_keyboard.c +++ b/term/i386/pc/at_keyboard.c @@ -233,7 +233,11 @@ static struct grub_term_input grub_at_keyboard_term = GRUB_MOD_INIT(at_keyboard) { +#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) + grub_term_register_input_active ("at_keyboard", &grub_at_keyboard_term); +#else grub_term_register_input ("at_keyboard", &grub_at_keyboard_term); +#endif } GRUB_MOD_FINI(at_keyboard) diff --git a/term/i386/pc/vga_text.c b/term/i386/pc/vga_text.c index 4fc54a60d..01191cef0 100644 --- a/term/i386/pc/vga_text.c +++ b/term/i386/pc/vga_text.c @@ -163,19 +163,16 @@ static struct grub_term_output grub_vga_text_term = .setcolorstate = grub_console_setcolorstate, .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, - .setcursor = grub_vga_text_setcursor, -#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) - .flags = GRUB_TERM_ACTIVE, -#endif + .setcursor = grub_vga_text_setcursor }; GRUB_MOD_INIT(vga_text) { #if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) - grub_vga_text_init_fini (); -#endif - + grub_term_register_output_active ("vga_text", &grub_vga_text_term); +#else grub_term_register_output ("vga_text", &grub_vga_text_term); +#endif } GRUB_MOD_FINI(vga_text) diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 95479379e..f5db7c146 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -414,15 +414,14 @@ static struct grub_term_output grub_ofconsole_term_output = .setcolor = grub_ofconsole_setcolor, .getcolor = grub_ofconsole_getcolor, .setcursor = grub_ofconsole_setcursor, - .refresh = grub_ofconsole_refresh, - .flags = GRUB_TERM_ACTIVE, + .refresh = grub_ofconsole_refresh }; void grub_console_init (void) { - grub_term_register_input ("ofconsole", &grub_ofconsole_term_input); - grub_term_register_output ("ofconsole", &grub_ofconsole_term_output); + grub_term_register_input_active ("ofconsole", &grub_ofconsole_term_input); + grub_term_register_output_active ("ofconsole", &grub_ofconsole_term_output); } void diff --git a/util/console.c b/util/console.c index be64eb9d8..40ee3a638 100644 --- a/util/console.c +++ b/util/console.c @@ -367,16 +367,14 @@ static struct grub_term_output grub_ncurses_term_output = .setcolor = grub_ncurses_setcolor, .getcolor = grub_ncurses_getcolor, .setcursor = grub_ncurses_setcursor, - .refresh = grub_ncurses_refresh, - .flags = GRUB_TERM_ACTIVE + .refresh = grub_ncurses_refresh }; void grub_console_init (void) { - grub_term_register_output ("console", &grub_ncurses_term_output); - grub_term_register_input ("console", &grub_ncurses_term_input); - grub_term_set_current_output (&grub_ncurses_term_output); + grub_term_register_output_active ("console", &grub_ncurses_term_output); + grub_term_register_input_active ("console", &grub_ncurses_term_input); } void From fa533ebb5c44bdc61e9fb74f8c7c6108fec81c01 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 01:13:21 +0100 Subject: [PATCH 057/164] Various fixes to make multiterm work --- include/grub/term.h | 20 +++++++++++++++++++- kern/term.c | 2 +- normal/main.c | 2 +- normal/menu.c | 10 ++++++---- normal/menu_text.c | 13 +++++++++---- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/include/grub/term.h b/include/grub/term.h index 479081d86..e8cf727be 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -359,6 +359,18 @@ grub_term_setcursor (struct grub_term_output *term, int on) term->setcursor (on); } +static inline void +grub_term_cls (struct grub_term_output *term) +{ + if (term->cls) + (term->cls) (); + else + { + grub_putcode ('\n', term); + grub_term_refresh (term); + } +} + static inline grub_ssize_t grub_term_getcharwidth (struct grub_term_output *term, grub_uint32_t c) { @@ -372,7 +384,13 @@ static inline void grub_term_getcolor (struct grub_term_output *term, grub_uint8_t *normal_color, grub_uint8_t *highlight_color) { - term->getcolor (normal_color, highlight_color); + if (term->getcolor) + term->getcolor (normal_color, highlight_color); + else + { + *normal_color = 0x07; + *highlight_color = 0x07; + } } extern void (*EXPORT_VAR (grub_newline_hook)) (void); diff --git a/kern/term.c b/kern/term.c index 8f8576aa2..b76771d86 100644 --- a/kern/term.c +++ b/kern/term.c @@ -132,7 +132,7 @@ grub_cls (void) if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) { grub_putcode ('\n', term); - grub_refresh (); + grub_term_refresh (term); } else (term->cls) (); diff --git a/normal/main.c b/normal/main.c index e1ffddae7..b4af09be9 100644 --- a/normal/main.c +++ b/normal/main.c @@ -409,7 +409,7 @@ grub_normal_init_page (struct grub_term_output *term) grub_uint32_t *unicode_msg; grub_uint32_t *last_position; - grub_cls (); + grub_term_cls (term); grub_sprintf (msg_formatted, msg, PACKAGE_VERSION); diff --git a/normal/menu.c b/normal/menu.c index 824779db6..b64213185 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -391,13 +391,15 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) case GRUB_TERM_UP: case '^': - current_entry--; + if (current_entry > 0) + current_entry--; menu_set_chosen_entry (current_entry); break; case GRUB_TERM_DOWN: case 'v': - current_entry++; + if (current_entry < menu->size - 1) + current_entry++; menu_set_chosen_entry (current_entry); break; @@ -411,9 +413,9 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) case GRUB_TERM_NPAGE: if (current_entry + GRUB_MENU_PAGE_SIZE < menu->size) - current_entry = 0; - else current_entry += GRUB_MENU_PAGE_SIZE; + else + current_entry = menu->size - 1; menu_set_chosen_entry (current_entry); break; diff --git a/normal/menu_text.c b/normal/menu_text.c index 991a9ba4d..71bd104aa 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -202,8 +202,8 @@ entry is highlighted.\n"); if (nested) { - grub_printf ("\n "); - grub_printf_ (N_("ESC to return previous menu.")); + grub_puts_terminal ("\n ", term); + grub_puts_terminal (_("ESC to return previous menu."), term); } } } @@ -385,10 +385,11 @@ menu_text_set_chosen_entry (int entry, void *dataptr) struct menu_viewer_data *data = dataptr; int oldoffset = data->offset; int complete_redraw = 0; + data->offset = entry - data->first; if (data->offset > grub_term_num_entries (data->term) - 1) { - data->first = data->offset - (grub_term_num_entries (data->term) - 1); + data->first = entry - (grub_term_num_entries (data->term) - 1); data->offset = grub_term_num_entries (data->term) - 1; complete_redraw = 1; } @@ -418,6 +419,8 @@ menu_text_fini (void *dataptr) struct menu_viewer_data *data = dataptr; grub_term_setcursor (data->term, 1); + grub_term_cls (data->term); + } static void @@ -456,13 +459,14 @@ grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested) grub_errno = GRUB_ERR_NONE; continue; } + data->term = term; instance->data = data; instance->set_chosen_entry = menu_text_set_chosen_entry; instance->print_timeout = menu_text_print_timeout; instance->clear_timeout = menu_text_clear_timeout; instance->fini = menu_text_fini; - + data->menu = menu; data->offset = entry; @@ -477,5 +481,6 @@ grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested) grub_menu_init_page (nested, 0, data->term); print_entries (menu, data->first, data->offset, data->term); grub_term_refresh (data->term); + grub_menu_register_viewer (instance); } } From ca04c7a550d7309ede0e91a5debb44544207719f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 01:20:44 +0100 Subject: [PATCH 058/164] Colin Watson's request --- commands/keystatus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/commands/keystatus.c b/commands/keystatus.c index 1bb22bde3..580e25f5d 100644 --- a/commands/keystatus.c +++ b/commands/keystatus.c @@ -55,12 +55,16 @@ grub_cmd_keystatus (grub_extcmd_t cmd, if (expect_mods == 0) { grub_term_input_t term; + int nterms = 0; FOR_ACTIVE_TERM_INPUTS (term) - if (term->getkeystatus) - return 0; - - return grub_error (GRUB_ERR_TEST_FAILURE, "false"); + if (!term->getkeystatus) + return grub_error (GRUB_ERR_TEST_FAILURE, "false"); + else + nterms++; + if (!nterms) + return grub_error (GRUB_ERR_TEST_FAILURE, "false"); + return 0; } mods = grub_getkeystatus (); From bf2ebfbe0299b984979c05c714b6ef9f412cbfb6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 03:36:42 +0100 Subject: [PATCH 059/164] Lost hunk --- conf/common.rmk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conf/common.rmk b/conf/common.rmk index 83168557d..caad3c571 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -644,6 +644,11 @@ charset_mod_SOURCES = lib/charset.c charset_mod_CFLAGS = $(COMMON_CFLAGS) charset_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += terminal.mod +terminal_mod_SOURCES = commands/terminal.c +terminal_mod_CFLAGS = $(COMMON_CFLAGS) +terminal_mod_LDFLAGS = $(COMMON_LDFLAGS) + pkglib_MODULES += crypto.mod crypto_mod_SOURCES = lib/crypto.c crypto_mod_CFLAGS = $(COMMON_CFLAGS) From 33c1ed4c8d1ef6bfa463a9f51fa709b72fb9b71d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 03:37:20 +0100 Subject: [PATCH 060/164] terminal modules autoloading --- Makefile.in | 5 +- commands/terminal.c | 109 ++++++++++++++++++++++++++++++------- genmk.rb | 7 +++ genterminallist.sh | 22 ++++++++ include/grub/normal.h | 2 + include/grub/term.h | 10 ++++ normal/main.c | 1 + normal/term.c | 123 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 260 insertions(+), 19 deletions(-) create mode 100644 genterminallist.sh diff --git a/Makefile.in b/Makefile.in index b28b660da..413c6a59d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -169,7 +169,7 @@ endif ### General targets. CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo -pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst +pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk cat $(DEFSYMFILES) /dev/null \ | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \ @@ -187,6 +187,9 @@ partmap.lst: $(PARTMAPFILES) handler.lst: $(HANDLERFILES) cat $^ /dev/null | sort > $@ +terminal.lst: $(TERMINALFILES) + cat $^ /dev/null | sort > $@ + parttool.lst: $(PARTTOOLFILES) cat $^ /dev/null | sort | uniq > $@ diff --git a/commands/terminal.c b/commands/terminal.c index a667825f4..5befecd31 100644 --- a/commands/terminal.c +++ b/commands/terminal.c @@ -23,12 +23,16 @@ #include #include +struct grub_term_autoload *grub_term_input_autoload = NULL; +struct grub_term_autoload *grub_term_output_autoload = NULL; + grub_err_t grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { int i; grub_term_input_t term; + struct grub_term_autoload *aut; if (argc == 0) { @@ -39,6 +43,20 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), grub_puts_ (N_ ("Available input terminals:")); FOR_DISABLED_TERM_INPUTS(term) grub_printf ("%s ", term->name); + /* This is quadratic but we don't expect mode than 30 terminal + modules ever. */ + for (aut = grub_term_input_autoload; aut; aut = aut->next) + { + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (term->name, aut->name) == 0) + break; + if (!term) + FOR_ACTIVE_TERM_INPUTS(term) + if (grub_strcmp (term->name, aut->name) == 0) + break; + if (!term) + grub_printf ("%s ", aut->name); + } grub_printf ("\n"); return GRUB_ERR_NONE; } @@ -53,16 +71,36 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), for (; i < argc; i++) { - FOR_DISABLED_TERM_INPUTS(term) - if (grub_strcmp (args[i], term->name) == 0) - break; - if (term == 0) - FOR_ACTIVE_TERM_INPUTS(term) - if (grub_strcmp (args[i], term->name) == 0) + int again = 0; + while (1) + { + FOR_DISABLED_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + FOR_ACTIVE_TERM_INPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) break; - if (term == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", - args[i]); + if (again) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + for (aut = grub_term_input_autoload; aut; aut = aut->next) + if (grub_strcmp (args[i], aut->name) == 0) + { + grub_dl_t mod; + mod = grub_dl_load (aut->modname); + if (mod) + grub_dl_ref (mod); + grub_errno = GRUB_ERR_NONE; + break; + } + if (!aut) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + again = 1; + } } if (grub_strcmp (args[0], "--append") == 0) @@ -151,6 +189,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), { int i; grub_term_output_t term; + struct grub_term_autoload *aut; if (argc == 0) { @@ -161,6 +200,20 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), grub_puts_ (N_ ("Available output terminals:")); FOR_DISABLED_TERM_OUTPUTS(term) grub_printf ("%s ", term->name); + /* This is quadratic but we don't expect mode than 30 terminal + modules ever. */ + for (aut = grub_term_output_autoload; aut; aut = aut->next) + { + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, aut->name) == 0) + break; + if (!term) + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, aut->name) == 0) + break; + if (!term) + grub_printf ("%s ", aut->name); + } grub_printf ("\n"); return GRUB_ERR_NONE; } @@ -175,16 +228,36 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), for (; i < argc; i++) { - FOR_DISABLED_TERM_OUTPUTS(term) - if (grub_strcmp (args[i], term->name) == 0) - break; - if (term == 0) - FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (args[i], term->name) == 0) + int again = 0; + while (1) + { + FOR_DISABLED_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term == 0) + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (args[i], term->name) == 0) + break; + if (term) break; - if (term == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", - args[i]); + if (again) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + for (aut = grub_term_output_autoload; aut; aut = aut->next) + if (grub_strcmp (args[i], aut->name) == 0) + { + grub_dl_t mod; + mod = grub_dl_load (aut->modname); + if (mod) + grub_dl_ref (mod); + grub_errno = GRUB_ERR_NONE; + break; + } + if (!aut) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", + args[i]); + again = 1; + } } if (grub_strcmp (args[0], "--append") == 0) diff --git a/genmk.rb b/genmk.rb index b3dbe8678..43eaef150 100644 --- a/genmk.rb +++ b/genmk.rb @@ -192,6 +192,7 @@ endif fs = 'fs-' + obj.suffix('lst') partmap = 'partmap-' + obj.suffix('lst') handler = 'handler-' + obj.suffix('lst') + terminal = 'terminal-' + obj.suffix('lst') parttool = 'parttool-' + obj.suffix('lst') video = 'video-' + obj.suffix('lst') dep = deps[i] @@ -213,6 +214,7 @@ FSFILES += #{fs} PARTTOOLFILES += #{parttool} PARTMAPFILES += #{partmap} HANDLERFILES += #{handler} +TERMINALFILES += #{terminal} VIDEOFILES += #{video} #{command}: #{src} $(#{src}_DEPENDENCIES) gencmdlist.sh @@ -240,6 +242,11 @@ VIDEOFILES += #{video} $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ | sh $(srcdir)/genhandlerlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) +#{terminal}: #{src} $(#{src}_DEPENDENCIES) genterminlist.sh + set -e; \ + $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ + | sh $(srcdir)/genterminallist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) + #{video}: #{src} $(#{src}_DEPENDENCIES) genvideolist.sh set -e; \ $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ diff --git a/genterminallist.sh b/genterminallist.sh new file mode 100644 index 000000000..eb0de0c32 --- /dev/null +++ b/genterminallist.sh @@ -0,0 +1,22 @@ +#! /bin/sh +# +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# This script is free software; the author +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# Read source code from stdin and detect command names. + +module=$1 + +grep -v "^#" | sed -n \ + -e "/grub_term_register_input *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $module/;p;}" \ + -e "/grub_term_register_input_active *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $module/;p;}" \ + -e "/grub_term_register_output *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $module/;p;}" \ + -e "/grub_term_register_output_active *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $module/;p;}" diff --git a/include/grub/normal.h b/include/grub/normal.h index 91457fc09..af8e00a71 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -103,6 +103,8 @@ void read_fs_list (void); void read_crypto_list (void); +void read_terminal_list (void); + void grub_set_more (int onoff); #ifdef GRUB_UTIL diff --git a/include/grub/term.h b/include/grub/term.h index e8cf727be..922ccb2d2 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -395,6 +395,16 @@ grub_term_getcolor (struct grub_term_output *term, extern void (*EXPORT_VAR (grub_newline_hook)) (void); +struct grub_term_autoload +{ + struct grub_term_autoload *next; + char *name; + char *modname; +}; + +extern struct grub_term_autoload *grub_term_input_autoload; +extern struct grub_term_autoload *grub_term_output_autoload; + /* For convenience. */ #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff) diff --git a/normal/main.c b/normal/main.c index b4af09be9..3ee4d295d 100644 --- a/normal/main.c +++ b/normal/main.c @@ -443,6 +443,7 @@ grub_normal_execute (const char *config, int nested, int batch) read_fs_list (); read_handler_list (); read_crypto_list (); + read_terminal_list (); grub_command_execute ("parser.grub", 0, 0); reader_nested = nested; diff --git a/normal/term.c b/normal/term.c index 5a8e9cffc..b099ae84c 100644 --- a/normal/term.c +++ b/normal/term.c @@ -19,6 +19,10 @@ #include #include #include +#include +#include +#include +#include /* The amount of lines counted by the pager. */ static unsigned grub_more_lines; @@ -127,3 +131,122 @@ grub_term_restore_pos (grub_uint16_t *pos) ptr++; } } + +static void +grub_terminal_autoload_free (void) +{ + struct grub_term_autoload *cur, *next; + unsigned i; + for (i = 0; i < 2; i++) + for (cur = i ? grub_term_input_autoload : grub_term_output_autoload; + cur; cur = next) + { + next = cur->next; + grub_free (cur->name); + grub_free (cur->modname); + grub_free (cur); + } + grub_term_input_autoload = NULL; + grub_term_output_autoload = NULL; +} + + +/* Read the file terminal.lst for auto-loading. */ +void +read_terminal_list (void) +{ + const char *prefix; + char *filename; + grub_file_t file; + char *buf = NULL; + + prefix = grub_env_get ("prefix"); + if (!prefix) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + filename = grub_malloc (grub_strlen (prefix) + sizeof ("/crypto.lst")); + if (!filename) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + grub_sprintf (filename, "%s/terminal.lst", prefix); + file = grub_file_open (filename); + if (!file) + { + grub_errno = GRUB_ERR_NONE; + return; + } + + /* Override previous terminal.lst. */ + grub_terminal_autoload_free (); + + for (;; grub_free (buf)) + { + char *p, *name; + struct grub_term_autoload *cur; + struct grub_term_autoload **target = NULL; + + buf = grub_file_getline (file); + + if (! buf) + break; + + switch (buf[0]) + { + case 'i': + target = &grub_term_input_autoload; + break; + + case 'o': + target = &grub_term_output_autoload; + break; + } + if (!target) + continue; + + name = buf + 1; + + p = grub_strchr (name, ':'); + if (! p) + continue; + + *p = '\0'; + while (*++p == ' ') + ; + + cur = grub_malloc (sizeof (*cur)); + if (!cur) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + + cur->name = grub_strdup (name); + if (! name) + { + grub_errno = GRUB_ERR_NONE; + grub_free (cur); + continue; + } + + cur->modname = grub_strdup (p); + if (! cur->modname) + { + grub_errno = GRUB_ERR_NONE; + grub_free (cur); + grub_free (cur->name); + continue; + } + cur->next = *target; + *target = cur; + } + + grub_file_close (file); + + grub_errno = GRUB_ERR_NONE; +} From 2e5b307c47308b92a0c94ab4702ba348a8495e26 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 04:12:29 +0100 Subject: [PATCH 061/164] Make menu editor work --- normal/menu.c | 2 ++ normal/menu_entry.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/normal/menu.c b/normal/menu.c index b64213185..8cf0e158d 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -435,10 +435,12 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) break; case 'c': + menu_fini (); grub_cmdline_run (1); goto refresh; case 'e': + menu_fini (); { grub_menu_entry_t e = grub_menu_get_entry (menu, current_entry); if (e) diff --git a/normal/menu_entry.c b/normal/menu_entry.c index da4eff496..8caba4336 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -135,8 +135,16 @@ print_line (struct line *linep, int offset, int start, int y, else { int i; + char *p, c; + + p = linep->buf + linep->len; + c = *p; + *p = 0; + grub_puts_terminal (linep->buf + offset + start, term_screen->term); + *p = c; + for (i = 0; - i <= grub_term_entry_width (term_screen->term) - linep->len + offset; + i < grub_term_entry_width (term_screen->term) - linep->len + offset; i++) grub_putcode (' ', term_screen->term); } @@ -1208,6 +1216,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) int prev_c; grub_err_t err = GRUB_ERR_NONE; unsigned i; + grub_term_output_t term; err = grub_auth_check_authentication (NULL); @@ -1222,7 +1231,27 @@ grub_menu_entry_run (grub_menu_entry_t entry) if (! screen) return; + screen->terms = NULL; + refresh: + grub_free (screen->terms); + screen->nterms = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + screen->nterms++; + screen->terms = grub_malloc (screen->nterms * sizeof (screen->terms[0])); + if (!screen->terms) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + return; + } + i = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + { + screen->terms[i].term = term; + screen->terms[i].x = 0; + screen->terms[i].y = 0; + } /* Draw the screen. */ for (i = 0; i < screen->nterms; i++) grub_menu_init_page (0, 1, screen->terms[i].term); From a999b9d96538f0e868bab734980370026bcb607d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 13:17:27 +0100 Subject: [PATCH 062/164] Fix refresh in cmdline --- normal/cmdline.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/normal/cmdline.c b/normal/cmdline.c index d7f41c7e3..3521c3cbd 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -306,8 +306,6 @@ grub_cmdline_get (const char *prompt) cl_print_all (lpos - len, 0); cl_set_pos_all (); } - - grub_refresh (); } void cl_delete (unsigned len) @@ -328,8 +326,6 @@ grub_cmdline_get (const char *prompt) cl_print_all (lpos, 0); cl_set_pos_all (); } - - grub_refresh (); } void init_clterm (struct cmdline_term *cl_term_cur) @@ -596,6 +592,7 @@ grub_cmdline_get (const char *prompt) } break; } + grub_refresh (); } grub_putchar ('\n'); From 0e76d18c5b1cae408f7440da730e1808fe85a7b8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 13:18:08 +0100 Subject: [PATCH 063/164] Fix various issues in menu editor --- normal/menu_entry.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 8caba4336..9599abd97 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -124,8 +124,7 @@ print_line (struct line *linep, int offset, int start, int y, if (linep->len >= offset + grub_term_entry_width (term_screen->term)) { char *p, c; - p = linep->buf + offset + start - + grub_term_entry_width (term_screen->term); + p = linep->buf + offset + grub_term_entry_width (term_screen->term); c = *p; *p = 0; grub_puts_terminal (linep->buf + offset + start, term_screen->term); @@ -144,7 +143,7 @@ print_line (struct line *linep, int offset, int start, int y, *p = c; for (i = 0; - i < grub_term_entry_width (term_screen->term) - linep->len + offset; + i <= grub_term_entry_width (term_screen->term) - linep->len + offset; i++) grub_putcode (' ', term_screen->term); } @@ -1251,6 +1250,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) screen->terms[i].term = term; screen->terms[i].x = 0; screen->terms[i].y = 0; + i++; } /* Draw the screen. */ for (i = 0; i < screen->nterms; i++) From 6066889c88dd92fba5a9e845a8215ab115a96726 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 16:28:31 +0100 Subject: [PATCH 064/164] normal_exit command --- include/grub/normal.h | 2 +- normal/main.c | 55 ++++++++++++++++++++++++++++++++----------- normal/menu.c | 6 +++++ normal/menu_entry.c | 6 +++++ 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/include/grub/normal.h b/include/grub/normal.h index af8e00a71..58b2c7966 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -46,7 +46,7 @@ enum grub_completion_type typedef enum grub_completion_type grub_completion_type_t; extern struct grub_menu_viewer grub_normal_text_menu_viewer; - +extern int grub_normal_exit_level; /* Defined in `main.c'. */ void grub_enter_normal_mode (const char *config); diff --git a/normal/main.c b/normal/main.c index 3ee4d295d..14e8971b0 100644 --- a/normal/main.c +++ b/normal/main.c @@ -34,6 +34,9 @@ #define GRUB_DEFAULT_HISTORY_SIZE 50 +static int nested_level = 0; +int grub_normal_exit_level = 0; + /* Read a line from the file FILE. */ char * grub_file_getline (grub_file_t file) @@ -430,8 +433,6 @@ grub_normal_init_page (struct grub_term_output *term) grub_free (unicode_msg); } -static int reader_nested; - /* Read the config file CONFIG and execute the menu interface or the command line interface if BATCH is false. */ void @@ -446,8 +447,6 @@ grub_normal_execute (const char *config, int nested, int batch) read_terminal_list (); grub_command_execute ("parser.grub", 0, 0); - reader_nested = nested; - if (config) { menu = read_config_file (config); @@ -471,8 +470,12 @@ grub_normal_execute (const char *config, int nested, int batch) void grub_enter_normal_mode (const char *config) { + nested_level++; grub_normal_execute (config, 0, 0); - grub_cmdline_run (1); + grub_cmdline_run (0); + nested_level--; + if (grub_normal_exit_level) + grub_normal_exit_level--; } /* Enter normal mode from rescue mode. */ @@ -508,8 +511,20 @@ quit: return 0; } +/* Exit from normal mode to rescue mode. */ static grub_err_t -grub_normal_reader_init (void) +grub_cmd_normal_exit (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + if (nested_level <= grub_normal_exit_level) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "not in normal environment"); + grub_normal_exit_level++; + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_normal_reader_init (int nested) { struct grub_term_output *term; const char *msg = _("Minimal BASH-like line editing is supported. For " @@ -519,7 +534,7 @@ grub_normal_reader_init (void) char *msg_formatted = grub_malloc (sizeof (char) * (grub_strlen (msg) + grub_strlen(msg_esc) + 1)); - grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : ""); + grub_sprintf (msg_formatted, msg, nested ? msg_esc : ""); FOR_ACTIVE_TERM_OUTPUTS(term) { @@ -536,12 +551,15 @@ grub_normal_reader_init (void) static grub_err_t -grub_normal_read_line (char **line, int cont) +grub_normal_read_line_real (char **line, int cont, int nested) { grub_parser_t parser = grub_parser_get_current (); char prompt[sizeof("> ") + grub_strlen (parser->name)]; - grub_sprintf (prompt, "%s> ", parser->name); + if (cont) + grub_sprintf (prompt, "> "); + else + grub_sprintf (prompt, "%s> ", parser->name); while (1) { @@ -549,7 +567,7 @@ grub_normal_read_line (char **line, int cont) if (*line) break; - if ((reader_nested) || (cont)) + if (cont || nested) { grub_free (*line); *line = 0; @@ -560,6 +578,12 @@ grub_normal_read_line (char **line, int cont) return 0; } +static grub_err_t +grub_normal_read_line (char **line, int cont) +{ + return grub_normal_read_line_real (line, cont, 0); +} + void grub_cmdline_run (int nested) { @@ -574,19 +598,20 @@ grub_cmdline_run (int nested) return; } - reader_nested = nested; - - grub_normal_reader_init (); + grub_normal_reader_init (nested); while (1) { char *line; + if (grub_normal_exit_level) + break; + /* Print an error, if any. */ grub_print_error (); grub_errno = GRUB_ERR_NONE; - grub_normal_read_line (&line, 0); + grub_normal_read_line_real (&line, 0, nested); if (! line) break; @@ -623,6 +648,8 @@ GRUB_MOD_INIT(normal) /* Register a command "normal" for the rescue mode. */ grub_register_command ("normal", grub_cmd_normal, 0, "Enter normal mode"); + grub_register_command ("normal_exit", grub_cmd_normal_exit, + 0, "Exit from normal mode"); /* Reload terminal colors when these variables are written to. */ grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal); diff --git a/normal/menu.c b/normal/menu.c index 8cf0e158d..62f33b61b 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -344,6 +344,9 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) int c; timeout = grub_menu_get_timeout (); + if (grub_normal_exit_level) + return -1; + if (timeout > 0) { grub_uint64_t current_time; @@ -554,6 +557,9 @@ grub_show_menu (grub_menu_t menu, int nested) err1 = show_menu (menu, nested); grub_print_error (); + if (grub_normal_exit_level) + break; + err2 = grub_auth_check_authentication (NULL); if (err2) { diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 9599abd97..7236f78e1 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -1270,6 +1270,12 @@ grub_menu_entry_run (grub_menu_entry_t entry) screen->completion_shown = 0; } + if (grub_normal_exit_level) + { + destroy_screen (screen); + return; + } + switch (c) { case 16: /* C-p */ From d75d75d93b4ddc291bb1085756bee26acd6d49f4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 25 Dec 2009 16:53:54 +0100 Subject: [PATCH 065/164] Fix glitch with escape message --- normal/menu_text.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/normal/menu_text.c b/normal/menu_text.c index 71bd104aa..791f831a0 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -196,15 +196,22 @@ entry is highlighted.\n"); grub_free (msg_translated); - grub_print_message_indented (_("Press enter to boot the selected OS, \ -\'e\' to edit the commands before booting or \'c\' for a command-line.\n"), - STANDARD_MARGIN, STANDARD_MARGIN, term); - if (nested) - { - grub_puts_terminal ("\n ", term); - grub_puts_terminal (_("ESC to return previous menu."), term); - } + { + grub_print_message_indented + (_("Press enter to boot the selected OS, " + "\'e\' to edit the commands before booting " + "or \'c\' for a command-line. ESC to return previous menu.\n"), + STANDARD_MARGIN, STANDARD_MARGIN, term); + } + else + { + grub_print_message_indented + (_("Press enter to boot the selected OS, " + "\'e\' to edit the commands before booting " + "or \'c\' for a command-line.\n"), + STANDARD_MARGIN, STANDARD_MARGIN, term); + } } } From 27a8ee52b4a624071d70c40ff78d0f575388d289 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Dec 2009 16:39:16 +0100 Subject: [PATCH 066/164] Remove menu init hooks. They are useless --- genmk.rb | 2 +- include/grub/menu_viewer.h | 10 +++-- normal/main.c | 7 ---- normal/menu.c | 48 ++++++++++++------------ normal/menu_text.c | 76 ++++++++++++++++++-------------------- 5 files changed, 67 insertions(+), 76 deletions(-) diff --git a/genmk.rb b/genmk.rb index 43eaef150..6cb7b5a89 100644 --- a/genmk.rb +++ b/genmk.rb @@ -242,7 +242,7 @@ VIDEOFILES += #{video} $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ | sh $(srcdir)/genhandlerlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) -#{terminal}: #{src} $(#{src}_DEPENDENCIES) genterminlist.sh +#{terminal}: #{src} $(#{src}_DEPENDENCIES) genterminallist.sh set -e; \ $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ | sh $(srcdir)/genterminallist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) diff --git a/include/grub/menu_viewer.h b/include/grub/menu_viewer.h index 3821219a3..c6513c4e8 100644 --- a/include/grub/menu_viewer.h +++ b/include/grub/menu_viewer.h @@ -24,6 +24,7 @@ #include #include #include +#include struct grub_menu_viewer { @@ -37,8 +38,11 @@ struct grub_menu_viewer void grub_menu_register_viewer (struct grub_menu_viewer *viewer); -grub_err_t grub_menu_register_viewer_init (void (*callback) (int entry, - grub_menu_t menu, - int nested)); +grub_err_t +grub_menu_try_text (struct grub_term_output *term, + int entry, grub_menu_t menu, int nested); + +extern grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu, + int nested); #endif /* GRUB_MENU_VIEWER_HEADER */ diff --git a/normal/main.c b/normal/main.c index 14e8971b0..6d7a558f3 100644 --- a/normal/main.c +++ b/normal/main.c @@ -636,13 +636,6 @@ GRUB_MOD_INIT(normal) grub_set_history (GRUB_DEFAULT_HISTORY_SIZE); - grub_menu_register_viewer_init (grub_menu_text_register_instances); - if (grub_errno) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - } - grub_register_variable_hook ("pager", 0, grub_env_write_pager); /* Register a command "normal" for the rescue mode. */ diff --git a/normal/menu.c b/normal/menu.c index 62f33b61b..24c1588d8 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -28,18 +28,14 @@ #include #include #include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ #define DEFAULT_ENTRY_ERROR_DELAY_MS 2500 -struct menu_run_callback -{ - struct menu_run_callback *next; - void (*hook) (int entry, grub_menu_t menu, int nested); -}; - -struct menu_run_callback *callbacks = NULL; +grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu, + int nested) = NULL; /* Wait until the user pushes any key so that the user can see what happened. */ @@ -237,9 +233,27 @@ menu_fini (void) static void menu_init (int entry, grub_menu_t menu, int nested) { - struct menu_run_callback *cb; - for (cb = callbacks; cb; cb = cb->next) - cb->hook (entry, menu, nested); + struct grub_term_output *term; + + FOR_ACTIVE_TERM_OUTPUTS(term) + { + grub_err_t err; + + if (grub_gfxmenu_try_hook && grub_strcmp (term->name, "gfxterm") == 0) + { + err = grub_gfxmenu_try_hook (entry, menu, nested); + if(!err) + continue; + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + + err = grub_menu_try_text (term, entry, menu, nested); + if(!err) + continue; + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } } static void @@ -257,20 +271,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) viewers = viewer; } -grub_err_t -grub_menu_register_viewer_init (void (*callback) (int entry, grub_menu_t menu, - int nested)) -{ - struct menu_run_callback *cb; - cb = grub_malloc (sizeof (*cb)); - if (!cb) - return grub_errno; - cb->hook = callback; - cb->next = callbacks; - callbacks = cb; - return GRUB_ERR_NONE; -} - /* Get the entry number from the variable NAME. */ static int get_entry_number (const char *name) diff --git a/normal/menu_text.c b/normal/menu_text.c index 791f831a0..91000c1d4 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -442,52 +442,46 @@ menu_text_clear_timeout (void *dataptr) grub_term_refresh (data->term); } -void -grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested) +grub_err_t +grub_menu_try_text (struct grub_term_output *term, + int entry, grub_menu_t menu, int nested) { struct menu_viewer_data *data; struct grub_menu_viewer *instance; - struct grub_term_output *term; - FOR_ACTIVE_TERM_OUTPUTS(term) - { - instance = grub_zalloc (sizeof (*instance)); - if (!instance) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - continue; - } - data = grub_zalloc (sizeof (*data)); - if (!data) - { - grub_free (instance); - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - continue; - } + instance = grub_zalloc (sizeof (*instance)); + if (!instance) + return grub_errno; - data->term = term; - instance->data = data; - instance->set_chosen_entry = menu_text_set_chosen_entry; - instance->print_timeout = menu_text_print_timeout; - instance->clear_timeout = menu_text_clear_timeout; - instance->fini = menu_text_fini; + data = grub_zalloc (sizeof (*data)); + if (!data) + { + grub_free (instance); + return grub_errno; + } - data->menu = menu; - - data->offset = entry; - data->first = 0; - if (data->offset > grub_term_num_entries (data->term) - 1) - { - data->first = data->offset - (grub_term_num_entries (data->term) - 1); - data->offset = grub_term_num_entries (data->term) - 1; - } + data->term = term; + instance->data = data; + instance->set_chosen_entry = menu_text_set_chosen_entry; + instance->print_timeout = menu_text_print_timeout; + instance->clear_timeout = menu_text_clear_timeout; + instance->fini = menu_text_fini; - grub_term_setcursor (data->term, 0); - grub_menu_init_page (nested, 0, data->term); - print_entries (menu, data->first, data->offset, data->term); - grub_term_refresh (data->term); - grub_menu_register_viewer (instance); - } + data->menu = menu; + + data->offset = entry; + data->first = 0; + if (data->offset > grub_term_num_entries (data->term) - 1) + { + data->first = data->offset - (grub_term_num_entries (data->term) - 1); + data->offset = grub_term_num_entries (data->term) - 1; + } + + grub_term_setcursor (data->term, 0); + grub_menu_init_page (nested, 0, data->term); + print_entries (menu, data->first, data->offset, data->term); + grub_term_refresh (data->term); + grub_menu_register_viewer (instance); + + return GRUB_ERR_NONE; } From 731ffd8773c9e6c09b675289cb932f1a286e9ce4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Dec 2009 22:16:14 +0100 Subject: [PATCH 067/164] Fix EFI compilation --- loader/i386/efi/linux.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index 8cd4d23f2..a869ca71a 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -693,13 +693,41 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), params->ext_mem = ((32 * 0x100000) >> 10); params->alt_mem = ((32 * 0x100000) >> 10); - params->video_cursor_x = grub_getxy () >> 8; - params->video_cursor_y = grub_getxy () & 0xff; + { + grub_term_output_t term; + int found = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "vga_text") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); + found = 1; + } + if (!found) + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "console") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); + found = 1; + } + if (!found) + { + params->video_cursor_x = 0; + params->video_cursor_y = 0; + params->video_width = 80; + params->video_height = 25; + } + } params->video_page = 0; /* ??? */ params->video_mode = grub_efi_system_table->con_out->mode->mode; - params->video_width = (grub_getwh () >> 8); params->video_ega_bx = 0; - params->video_height = (grub_getwh () & 0xff); params->have_vga = 0; params->font_size = 16; /* XXX */ From 562e438b775b204ef0ab4aeb0128a91571c2c413 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 17:21:49 +0100 Subject: [PATCH 068/164] Add defines for yeeloong --- term/gfxterm.c | 4 ++++ term/i386/pc/at_keyboard.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/term/gfxterm.c b/term/gfxterm.c index f161499e6..2a22b9168 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -953,7 +953,11 @@ static grub_command_t cmd; GRUB_MOD_INIT(term_gfxterm) { +#ifdef GRUB_MACHINE_MIPS_YEELOONG + grub_term_register_output_active ("gfxterm", &grub_video_term); +#else grub_term_register_output ("gfxterm", &grub_video_term); +#endif cmd = grub_register_command ("background_image", grub_gfxterm_background_image_cmd, 0, "Load background image for active terminal"); diff --git a/term/i386/pc/at_keyboard.c b/term/i386/pc/at_keyboard.c index 379cb3a4b..fd9767736 100644 --- a/term/i386/pc/at_keyboard.c +++ b/term/i386/pc/at_keyboard.c @@ -233,7 +233,7 @@ static struct grub_term_input grub_at_keyboard_term = GRUB_MOD_INIT(at_keyboard) { -#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) +#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_YEELOONG) grub_term_register_input_active ("at_keyboard", &grub_at_keyboard_term); #else grub_term_register_input ("at_keyboard", &grub_at_keyboard_term); From 1975ecdc59b51e2b52a1457c7325333ecd77b4f8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 17:40:36 +0100 Subject: [PATCH 069/164] Fix include in kern/term.c --- kern/term.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kern/term.c b/kern/term.c index b76771d86..3d8777133 100644 --- a/kern/term.c +++ b/kern/term.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include struct grub_term_output *grub_term_outputs_disabled; struct grub_term_input *grub_term_inputs_disabled; From 3851cc386e1d98f5407fadc2932815f0f6831205 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 22:29:22 +0100 Subject: [PATCH 070/164] Prevent NULL dereferencing when unregistering ciphers --- lib/crypto.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/crypto.c b/lib/crypto.c index 021560d6c..d11f0994f 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -59,7 +59,10 @@ grub_cipher_unregister (gcry_cipher_spec_t *cipher) gcry_cipher_spec_t **ciph; for (ciph = &grub_ciphers; *ciph; ciph = &((*ciph)->next)) if (*ciph == cipher) - *ciph = (*ciph)->next; + { + *ciph = (*ciph)->next; + break; + } } void @@ -75,7 +78,10 @@ grub_md_unregister (gcry_md_spec_t *cipher) gcry_md_spec_t **ciph; for (ciph = &grub_digests; *ciph; ciph = &((*ciph)->next)) if (*ciph == cipher) - *ciph = (*ciph)->next; + { + *ciph = (*ciph)->next; + break; + } } void From f45e1a9fb790237b066d2f1e706e896fcc5a9e15 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 22:34:49 +0100 Subject: [PATCH 071/164] Allocate correct size --- normal/term.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/normal/term.c b/normal/term.c index b099ae84c..667d27ee9 100644 --- a/normal/term.c +++ b/normal/term.c @@ -167,7 +167,7 @@ read_terminal_list (void) return; } - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/crypto.lst")); + filename = grub_malloc (grub_strlen (prefix) + sizeof ("/terminal.lst")); if (!filename) { grub_errno = GRUB_ERR_NONE; From dc71441293ffa0682ee2fc1f759c34bb772bb8d2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 22:35:40 +0100 Subject: [PATCH 072/164] Output \n\r like it was done previously because ncurses is confused by \r\n --- kern/term.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kern/term.c b/kern/term.c index 3d8777133..50fbbf302 100644 --- a/kern/term.c +++ b/kern/term.c @@ -45,9 +45,9 @@ grub_putcode (grub_uint32_t code, struct grub_term_output *term) return; } + (term->putchar) (code); if (code == '\n') (term->putchar) ('\r'); - (term->putchar) (code); } /* Put a character. C is one byte of a UTF-8 stream. From 13d1f24696a905e83c4edd7c96fafbc2081554dc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 27 Dec 2009 22:36:09 +0100 Subject: [PATCH 073/164] Fix grub-emu compilation --- conf/any-emu.rmk | 1 + util/console.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index bbc564c80..85ff972ab 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -28,6 +28,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/menu_text.c normal/crypto.c normal/term.c \ + commands/terminal.c lib/charset.c \ script/main.c script/execute.c script/function.c \ script/lexer.c script/script.c grub_script.tab.c \ partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \ diff --git a/util/console.c b/util/console.c index 40ee3a638..73195765e 100644 --- a/util/console.c +++ b/util/console.c @@ -19,14 +19,6 @@ #include -#if defined(HAVE_NCURSES_CURSES_H) -# include -#elif defined(HAVE_NCURSES_H) -# include -#elif defined(HAVE_CURSES_H) -# include -#endif - /* For compatibility. */ #ifndef A_NORMAL # define A_NORMAL 0 @@ -39,6 +31,14 @@ #include #include +#if defined(HAVE_NCURSES_CURSES_H) +# include +#elif defined(HAVE_NCURSES_H) +# include +#elif defined(HAVE_CURSES_H) +# include +#endif + static int grub_console_attr = A_NORMAL; grub_uint8_t grub_console_cur_color = 7; From a6f106ce3780a76d6b9fd4199c8774bd07ad77ed Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 28 Dec 2009 22:06:30 +0100 Subject: [PATCH 074/164] Fix i386-ieee1275 compilation --- loader/i386/ieee1275/linux.c | 34 ++++++++++++++++++++++++++++++++-- term/ieee1275/ofconsole.c | 4 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index 529d1590a..33488d443 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -109,8 +109,38 @@ grub_linux_boot (void) params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET; - params->video_width = (grub_getwh () >> 8); - params->video_height = (grub_getwh () & 0xff); + { + grub_term_output_t term; + int found = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "vga_text") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); + found = 1; + } + if (!found) + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "console") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); + found = 1; + } + if (!found) + { + params->video_cursor_x = 0; + params->video_cursor_y = 0; + params->video_width = 80; + params->video_height = 25; + } + } params->font_size = 16; params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE; diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index f5db7c146..4b9c9060e 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -88,7 +88,7 @@ grub_ofconsole_putchar (grub_uint32_t c) grub_curr_x++; if (grub_curr_x > grub_ofconsole_width) { - grub_putcode ('\n'); + grub_ofconsole_putchar ('\n'); grub_curr_x++; } } @@ -319,7 +319,7 @@ grub_ofconsole_cls (void) * ANSI escape sequence. Using video console, Apple Open Firmware (version * 3.1.1) only recognizes the literal ^L. So use both. */ grub_ofconsole_writeesc (" \e[2J"); - grub_gotoxy (0, 0); + grub_ofconsole_gotoxy (0, 0); } static void From bd2b242ea20d6c696f7f737ae56056c60b281a18 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 10:24:10 +0100 Subject: [PATCH 075/164] Fix space after completion --- normal/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/normal/cmdline.c b/normal/cmdline.c index 3521c3cbd..317f63fe3 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -436,7 +436,7 @@ grub_cmdline_get (const char *prompt) if (restore) { /* Restore the prompt. */ - grub_printf ("\n%s", prompt_translated); + grub_printf ("\n%s ", prompt_translated); init_clterm_all (); cl_print_all (0, 0); } From 37f7fb26a379f3ea88bc30107ae371a70e85e0e8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 13:03:22 +0100 Subject: [PATCH 076/164] always_inline cl_print to avoid regparm=3 bug --- normal/cmdline.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/normal/cmdline.c b/normal/cmdline.c index 317f63fe3..a0e678778 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -222,7 +222,8 @@ grub_cmdline_get (const char *prompt) int histpos = 0; auto void cl_insert (const grub_uint32_t *str); auto void cl_delete (unsigned len); - auto void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c); + auto inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, + grub_uint32_t c); auto void cl_set_pos (struct cmdline_term *cl_term); auto void cl_print_all (int pos, grub_uint32_t c); auto void cl_set_pos_all (void); @@ -245,7 +246,7 @@ grub_cmdline_get (const char *prompt) cl_set_pos (&cl_terms[i]); } - void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c) + inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c) { grub_uint32_t *p; From d8a1cbbd0b3a9e31d064d25ba193b1bcdb685404 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 17:54:27 +0100 Subject: [PATCH 077/164] Fix compilation warning --- commands/terminal.c | 4 ++-- normal/cmdline.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/terminal.c b/commands/terminal.c index 5befecd31..0fff70a69 100644 --- a/commands/terminal.c +++ b/commands/terminal.c @@ -26,7 +26,7 @@ struct grub_term_autoload *grub_term_input_autoload = NULL; struct grub_term_autoload *grub_term_output_autoload = NULL; -grub_err_t +static grub_err_t grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { @@ -183,7 +183,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } -grub_err_t +static grub_err_t grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { diff --git a/normal/cmdline.c b/normal/cmdline.c index a0e678778..f2c2edf9b 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -227,6 +227,8 @@ grub_cmdline_get (const char *prompt) auto void cl_set_pos (struct cmdline_term *cl_term); auto void cl_print_all (int pos, grub_uint32_t c); auto void cl_set_pos_all (void); + auto void init_clterm (struct cmdline_term *cl_term_cur); + auto void init_clterm_all (void); const char *prompt_translated = _(prompt); struct cmdline_term *cl_terms; char *ret; From 33433555f30fa99eda7ceed7ce7d6f0d202c22c7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 31 Dec 2009 15:03:09 +0100 Subject: [PATCH 078/164] 2009-12-31 BVK Chaitanya * include/grub/list.h (grub_assert_fail): Removed. (grub_bad_type_cast_real): New function. (grub_bad_type_cast): New macro. (GRUB_AS_LIST): Use grub_bad_type_cast. (GRUB_AS_LIST_P): Likewise. (GRUB_AS_NAMED_LIST): Likewise. (GRUB_AS_NAMED_LIST_P): Likewise. (GRUB_AS_PRIO_LIST): Likewise. (GRUB_AS_PRIO_LIST_P): Likewise. * include/grub/handler.h (GRUB_AS_HANDLER): Likewise. --- ChangeLog | 13 +++++++++++++ include/grub/handler.h | 2 +- include/grub/list.h | 34 +++++++++++++++++----------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9a5d4eb2..64ebf0e78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-12-31 BVK Chaitanya + + * include/grub/list.h (grub_assert_fail): Removed. + (grub_bad_type_cast_real): New function. + (grub_bad_type_cast): New macro. + (GRUB_AS_LIST): Use grub_bad_type_cast. + (GRUB_AS_LIST_P): Likewise. + (GRUB_AS_NAMED_LIST): Likewise, + (GRUB_AS_NAMED_LIST_P): Likewise. + (GRUB_AS_PRIO_LIST): Likewise, + (GRUB_AS_PRIO_LIST_P): Likewise. + * include/grub/handler.h (GRUB_AS_HANDLER): Likewise, + 2009-12-29 Vladimir Serbinenko * loader/sparc64/ieee1275/linux.c (GRUB_MOD_INIT (linux)): diff --git a/include/grub/handler.h b/include/grub/handler.h index 3331bb417..77dd7d9c1 100644 --- a/include/grub/handler.h +++ b/include/grub/handler.h @@ -55,6 +55,6 @@ grub_err_t EXPORT_FUNC(grub_handler_set_current) (grub_handler_class_t class, GRUB_FIELD_MATCH (ptr, grub_handler_t, name) && \ GRUB_FIELD_MATCH (ptr, grub_handler_t, init) && \ GRUB_FIELD_MATCH (ptr, grub_handler_t, fini)) ? \ - (grub_handler_t) ptr : grub_assert_fail ()) + (grub_handler_t) ptr : grub_bad_type_cast ()) #endif /* ! GRUB_HANDLER_HEADER */ diff --git a/include/grub/list.h b/include/grub/list.h index 2dffdc08d..86a5381cd 100644 --- a/include/grub/list.h +++ b/include/grub/list.h @@ -22,6 +22,7 @@ #include #include +#include struct grub_list { @@ -39,31 +40,30 @@ int EXPORT_FUNC(grub_list_iterate) (grub_list_t head, grub_list_hook_t hook); void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item, grub_list_test_t test); -/* This function doesn't exist, so if assertion is false for some reason, the - linker would fail. */ -#ifdef APPLE_CC -/* This approach fails with Apple's gcc. Use grub_abort. */ -#include static inline void * -grub_assert_fail (void) +grub_bad_type_cast_real (int line, const char *file) + __attribute__ ((error ("bad type cast between incompatible grub types"))); + +static inline void * +grub_bad_type_cast_real (int line, const char *file) { - grub_abort (); - return 0; + grub_fatal ("error:%s:%u: bad type cast between incompatible grub types", + file, line); + return 0; } -#else -extern void* grub_assert_fail (void); -#endif + +#define grub_bad_type_cast() grub_bad_type_cast_real(__LINE__, __FILE__) #define GRUB_FIELD_MATCH(ptr, type, field) \ ((char *) &(ptr)->field == (char *) &((type) (ptr))->field) #define GRUB_AS_LIST(ptr) \ (GRUB_FIELD_MATCH (ptr, grub_list_t, next) ? \ - (grub_list_t) ptr : grub_assert_fail ()) + (grub_list_t) ptr : grub_bad_type_cast ()) #define GRUB_AS_LIST_P(pptr) \ (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) ? \ - (grub_list_t *) (void *) pptr : grub_assert_fail ()) + (grub_list_t *) (void *) pptr : grub_bad_type_cast ()) struct grub_named_list { @@ -78,12 +78,12 @@ void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head, #define GRUB_AS_NAMED_LIST(ptr) \ ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) && \ GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \ - (grub_named_list_t) ptr : grub_assert_fail ()) + (grub_named_list_t) ptr : grub_bad_type_cast ()) #define GRUB_AS_NAMED_LIST_P(pptr) \ ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) && \ GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \ - (grub_named_list_t *) (void *) pptr : grub_assert_fail ()) + (grub_named_list_t *) (void *) pptr : grub_bad_type_cast ()) #define GRUB_PRIO_LIST_PRIO_MASK 0xff #define GRUB_PRIO_LIST_FLAG_ACTIVE 0x100 @@ -111,12 +111,12 @@ grub_prio_list_remove (grub_prio_list_t *head, grub_prio_list_t item) ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \ GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \ GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \ - (grub_prio_list_t) ptr : grub_assert_fail ()) + (grub_prio_list_t) ptr : grub_bad_type_cast ()) #define GRUB_AS_PRIO_LIST_P(pptr) \ ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \ GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \ GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio))? \ - (grub_prio_list_t *) (void *) pptr : grub_assert_fail ()) + (grub_prio_list_t *) (void *) pptr : grub_bad_type_cast ()) #endif /* ! GRUB_LIST_HEADER */ From e44721e811e42f4a3d6135ab052615150699f5d1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 31 Dec 2009 15:05:12 +0100 Subject: [PATCH 079/164] Fix punctuation in ChangeLog --- ChangeLog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64ebf0e78..b7734a5f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,11 +5,11 @@ (grub_bad_type_cast): New macro. (GRUB_AS_LIST): Use grub_bad_type_cast. (GRUB_AS_LIST_P): Likewise. - (GRUB_AS_NAMED_LIST): Likewise, + (GRUB_AS_NAMED_LIST): Likewise. (GRUB_AS_NAMED_LIST_P): Likewise. - (GRUB_AS_PRIO_LIST): Likewise, + (GRUB_AS_PRIO_LIST): Likewise. (GRUB_AS_PRIO_LIST_P): Likewise. - * include/grub/handler.h (GRUB_AS_HANDLER): Likewise, + * include/grub/handler.h (GRUB_AS_HANDLER): Likewise. 2009-12-29 Vladimir Serbinenko From 3fd3b8d81a7a0b8db4e655b93e72779007b18c06 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 1 Jan 2010 12:33:45 +0000 Subject: [PATCH 080/164] 2010-01-01 Robert Millan Import from Gnulib. * gnulib/getdelim.c: New file. * gnulib/getline.c: Likewise. --- ChangeLog | 7 +++ gnulib/getdelim.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++ gnulib/getline.c | 30 +++++++++++ 3 files changed, 170 insertions(+) create mode 100644 gnulib/getdelim.c create mode 100644 gnulib/getline.c diff --git a/ChangeLog b/ChangeLog index b7734a5f4..17ddc35d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-01 Robert Millan + + Import from Gnulib. + + * gnulib/getdelim.c: New file. + * gnulib/getline.c: Likewise. + 2009-12-31 BVK Chaitanya * include/grub/list.h (grub_assert_fail): Removed. diff --git a/gnulib/getdelim.c b/gnulib/getdelim.c new file mode 100644 index 000000000..12f2167c9 --- /dev/null +++ b/gnulib/getdelim.c @@ -0,0 +1,133 @@ +/* getdelim.c --- Implementation of replacement getdelim function. + Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, + 2008, 2009 Free Software Foundation, Inc. + + 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; either version 2, or (at + your option) any later version. + + 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 Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +/* Ported from glibc by Simon Josefsson. */ + +#include + +#include + +#include +#include +#include +#include + +#ifndef SSIZE_MAX +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) +#endif + +#if USE_UNLOCKED_IO +# include "unlocked-io.h" +# define getc_maybe_unlocked(fp) getc(fp) +#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED +# undef flockfile +# undef funlockfile +# define flockfile(x) ((void) 0) +# define funlockfile(x) ((void) 0) +# define getc_maybe_unlocked(fp) getc(fp) +#else +# define getc_maybe_unlocked(fp) getc_unlocked(fp) +#endif + +/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + +ssize_t +getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) +{ + ssize_t result; + size_t cur_len = 0; + + if (lineptr == NULL || n == NULL || fp == NULL) + { + errno = EINVAL; + return -1; + } + + flockfile (fp); + + if (*lineptr == NULL || *n == 0) + { + char *new_lineptr; + *n = 120; + new_lineptr = (char *) realloc (*lineptr, *n); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + *lineptr = new_lineptr; + } + + for (;;) + { + int i; + + i = getc_maybe_unlocked (fp); + if (i == EOF) + { + result = -1; + break; + } + + /* Make enough space for len+1 (for final NUL) bytes. */ + if (cur_len + 1 >= *n) + { + size_t needed_max = + SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; + size_t needed = 2 * *n + 1; /* Be generous. */ + char *new_lineptr; + + if (needed_max < needed) + needed = needed_max; + if (cur_len + 1 >= needed) + { + result = -1; + errno = EOVERFLOW; + goto unlock_return; + } + + new_lineptr = (char *) realloc (*lineptr, needed); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + + *lineptr = new_lineptr; + *n = needed; + } + + (*lineptr)[cur_len] = i; + cur_len++; + + if (i == delimiter) + break; + } + (*lineptr)[cur_len] = '\0'; + result = cur_len ? cur_len : result; + + unlock_return: + funlockfile (fp); /* doesn't set errno */ + + return result; +} diff --git a/gnulib/getline.c b/gnulib/getline.c new file mode 100644 index 000000000..eb8f055a8 --- /dev/null +++ b/gnulib/getline.c @@ -0,0 +1,30 @@ +/* getline.c --- Implementation of replacement getline function. + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + + 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; either version 2, or (at + your option) any later version. + + 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 Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +/* Written by Simon Josefsson. */ + +#include + +#include +#include + +ssize_t +getline (char **lineptr, size_t *n, FILE *stream) +{ + return getdelim (lineptr, n, '\n', stream); +} From 3393790450750da09ac9eaa34c10065f68a485a8 Mon Sep 17 00:00:00 2001 From: carles Date: Fri, 1 Jan 2010 18:58:00 +0100 Subject: [PATCH 081/164] 2010-01-01 Carles Pina i Estany * commands/help.c: Include `grub/mm.h' and `grub/normal.h'. (grub_cmd_help): Print the cmd->name before the cmd->summary. Cut the string using string width. * normal/menu_text.c (grub_print_message_indented): Use grub_print_spaces and not print_spaces. (print_timeout): Likewise. (print_spaces): Move to... * include/grub/term.h: ... here. Change the name to grub_print_spaces. --- ChangeLog | 11 ++++++++++ commands/help.c | 51 +++++++++++++++++++++++++++++++++++---------- include/grub/term.h | 8 +++++++ normal/menu_text.c | 14 +++---------- 4 files changed, 62 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17ddc35d7..634e8aad0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-01-01 Carles Pina i Estany + + * commands/help.c: Include `grub/mm.h' and `grub/normal.h'. + (grub_cmd_help): Print the cmd->name before the cmd->summary. Cut the + string using string width. + * normal/menu_text.c (grub_print_message_indented): Use + grub_print_spaces and not print_spaces. + (print_timeout): Likewise. + (print_spaces): Move to... + * include/grub/term.h: ... here. Change the name to grub_print_spaces. + 2010-01-01 Robert Millan Import from Gnulib. diff --git a/commands/help.c b/commands/help.c index 9f0ee7528..8ca2a5b1f 100644 --- a/commands/help.c +++ b/commands/help.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include static grub_err_t grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, @@ -38,19 +40,46 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)) { - char description[GRUB_TERM_WIDTH / 2]; - const char* summary_translated = _(cmd->summary); - int desclen = grub_strlen (summary_translated); + char *command_help; + int stringwidth; + grub_uint32_t *unicode_command_help; + grub_uint32_t *unicode_last_position; + grub_uint32_t *unicode_last_screen_position; + const char *summary_translated = _(cmd->summary); - /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled - with the description followed by spaces. */ - grub_memset (description, ' ', GRUB_TERM_WIDTH / 2 - 1); - description[GRUB_TERM_WIDTH / 2 - 1] = '\0'; - grub_memcpy (description, summary_translated, - (desclen < GRUB_TERM_WIDTH / 2 - 1 - ? desclen : GRUB_TERM_WIDTH / 2 - 1)); + command_help = grub_malloc (grub_strlen (cmd->name) + + sizeof (" ") - 1 + + grub_strlen (summary_translated)); + + grub_sprintf(command_help, "%s %s", cmd->name, summary_translated); - grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " "); + grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help, + &unicode_last_position); + + unicode_last_screen_position = unicode_command_help; + + stringwidth = 0; + + while (unicode_last_screen_position < unicode_last_position && + stringwidth < ((GRUB_TERM_WIDTH / 2) - 2)) + { + stringwidth += grub_getcharwidth (*unicode_last_screen_position); + unicode_last_screen_position++; + } + + grub_print_ucs4 (unicode_command_help, unicode_last_screen_position); + + if ((cnt++) % 2) + { + grub_putchar ('\n'); + } + else + { + grub_print_spaces (GRUB_TERM_WIDTH / 2 - stringwidth); + } + + grub_free (command_help); + grub_free (unicode_command_help); } return 0; } diff --git a/include/grub/term.h b/include/grub/term.h index 316d75390..ec158353d 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -299,6 +299,14 @@ int EXPORT_FUNC(grub_getcursor) (void); void EXPORT_FUNC(grub_refresh) (void); void EXPORT_FUNC(grub_set_more) (int onoff); +static inline void +grub_print_spaces (int number_spaces) +{ + while (--number_spaces >= 0) + grub_putchar (' '); +} + + /* For convenience. */ #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff) diff --git a/normal/menu_text.c b/normal/menu_text.c index bac15f32b..5c985fa6f 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -45,14 +45,6 @@ grub_wait_after_message (void) grub_putchar ('\n'); } -static void -print_spaces (int number_spaces) -{ - int i; - for (i = 0; i < number_spaces; i++) - grub_putchar (' '); -} - void grub_print_ucs4 (const grub_uint32_t * str, const grub_uint32_t * last_position) @@ -149,7 +141,7 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right) (grub_uint32_t *) last_position : next_new_line + line_len; } - print_spaces (margin_left); + grub_print_spaces (margin_left); grub_print_ucs4 (current_position, next_new_line); next_new_line++; @@ -405,7 +397,7 @@ print_timeout (int timeout, int offset) int posx; posx = grub_getxy() >> 8; - print_spaces (GRUB_TERM_WIDTH - posx - 1); + grub_print_spaces (GRUB_TERM_WIDTH - posx - 1); grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); grub_refresh (); @@ -495,7 +487,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) if (timeout >= 0) { grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - print_spaces (GRUB_TERM_WIDTH - 1); + grub_print_spaces (GRUB_TERM_WIDTH - 1); grub_env_unset ("timeout"); grub_env_unset ("fallback"); From cec573c894e79f5d55697ff6722f4e148962aac2 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Fri, 1 Jan 2010 20:33:15 +0100 Subject: [PATCH 082/164] 2009-01-01 Yves Blusseau * config.rpath: new file used to configure compilation with NLS --- config.rpath | 666 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 666 insertions(+) create mode 100755 config.rpath diff --git a/config.rpath b/config.rpath new file mode 100755 index 000000000..c547c6882 --- /dev/null +++ b/config.rpath @@ -0,0 +1,666 @@ +#! /bin/sh +# Output a system dependent set of variables, describing how to set the +# run time search path of shared libraries in an executable. +# +# Copyright 1996-2007 Free Software Foundation, Inc. +# Taken from GNU libtool, 2001 +# Originally by Gordon Matzigkeit , 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# The first argument passed to this file is the canonical host specification, +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld +# should be set by the caller. +# +# The set of defined variables is at the end of this script. + +# Known limitations: +# - On IRIX 6.5 with CC="cc", the run time search patch must not be longer +# than 256 bytes, otherwise the compiler driver will dump core. The only +# known workaround is to choose shorter directory names for the build +# directory and/or the installation directory. + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a +shrext=.so + +host="$1" +host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` + +# Code taken from libtool.m4's _LT_CC_BASENAME. + +for cc_temp in $CC""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` + +# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC. + +wl= +if test "$GCC" = yes; then + wl='-Wl,' +else + case "$host_os" in + aix*) + wl='-Wl,' + ;; + darwin*) + case $cc_basename in + xlc*) + wl='-Wl,' + ;; + esac + ;; + mingw* | cygwin* | pw32* | os2*) + ;; + hpux9* | hpux10* | hpux11*) + wl='-Wl,' + ;; + irix5* | irix6* | nonstopux*) + wl='-Wl,' + ;; + newsos6) + ;; + linux* | k*bsd*-gnu) + case $cc_basename in + icc* | ecc*) + wl='-Wl,' + ;; + pgcc | pgf77 | pgf90) + wl='-Wl,' + ;; + ccc*) + wl='-Wl,' + ;; + como) + wl='-lopt=' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + wl='-Wl,' + ;; + esac + ;; + esac + ;; + osf3* | osf4* | osf5*) + wl='-Wl,' + ;; + rdos*) + ;; + solaris*) + wl='-Wl,' + ;; + sunos4*) + wl='-Qoption ld ' + ;; + sysv4 | sysv4.2uw2* | sysv4.3*) + wl='-Wl,' + ;; + sysv4*MP*) + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + wl='-Wl,' + ;; + unicos*) + wl='-Wl,' + ;; + uts4*) + ;; + esac +fi + +# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS. + +hardcode_libdir_flag_spec= +hardcode_libdir_separator= +hardcode_direct=no +hardcode_minus_L=no + +case "$host_os" in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; +esac + +ld_shlibs=yes +if test "$with_gnu_ld" = yes; then + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + # Unlike libtool, we use -rpath here, not --rpath, since the documented + # option of GNU ld is called -rpath, not --rpath. + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + case "$host_os" in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs=no + fi + ;; + amigaos*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we cannot use + # them. + ld_shlibs=no + ;; + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + cygwin* | mingw* | pw32*) + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + interix[3-9]*) + hardcode_direct=no + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + gnu* | linux* | k*bsd*-gnu) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + netbsd*) + ;; + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + else + ld_shlibs=no + fi + ;; + esac + ;; + sunos4*) + hardcode_direct=yes + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + esac + if test "$ld_shlibs" = no; then + hardcode_libdir_flag_spec= + fi +else + case "$host_os" in + aix3*) + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test "$GCC" = yes; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + else + aix_use_runtimelinking=no + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + fi + hardcode_direct=yes + hardcode_libdir_separator=':' + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + fi + # Begin _LT_AC_SYS_LIBPATH_AIX. + echo 'int main () { return 0; }' > conftest.c + ${CC} ${LDFLAGS} conftest.c -o conftest + aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` + if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` + fi + if test -z "$aix_libpath"; then + aix_libpath="/usr/lib:/lib" + fi + rm -f conftest.c conftest + # End _LT_AC_SYS_LIBPATH_AIX. + if test "$aix_use_runtimelinking" = yes; then + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' + else + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + fi + fi + ;; + amigaos*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + # see comment about different semantics on the GNU ld section + ld_shlibs=no + ;; + bsdi[45]*) + ;; + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec=' ' + libext=lib + ;; + darwin* | rhapsody*) + hardcode_direct=no + if test "$GCC" = yes ; then + : + else + case $cc_basename in + xlc*) + ;; + *) + ld_shlibs=no + ;; + esac + fi + ;; + dgux*) + hardcode_libdir_flag_spec='-L$libdir' + ;; + freebsd1*) + ld_shlibs=no + ;; + freebsd2.2*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + freebsd2*) + hardcode_direct=yes + hardcode_minus_L=yes + ;; + freebsd* | dragonfly*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + hpux9*) + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + hpux10*) + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + hpux11*) + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + ;; + *) + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + irix5* | irix6* | nonstopux*) + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + netbsd*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + newsos6) + hardcode_direct=yes + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + openbsd*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + else + case "$host_os" in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + hardcode_libdir_flag_spec='-R$libdir' + ;; + *) + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + esac + fi + else + ld_shlibs=no + fi + ;; + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + osf3*) + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + osf4* | osf5*) + if test "$GCC" = yes; then + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + else + # Both cc and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + hardcode_libdir_separator=: + ;; + solaris*) + hardcode_libdir_flag_spec='-R$libdir' + ;; + sunos4*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + ;; + sysv4) + case $host_vendor in + sni) + hardcode_direct=yes # is this really true??? + ;; + siemens) + hardcode_direct=no + ;; + motorola) + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + ;; + sysv4.3*) + ;; + sysv4*MP*) + if test -d /usr/nec; then + ld_shlibs=yes + fi + ;; + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + ;; + sysv5* | sco3.2v5* | sco5v6*) + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator=':' + ;; + uts4*) + hardcode_libdir_flag_spec='-L$libdir' + ;; + *) + ld_shlibs=no + ;; + esac +fi + +# Check dynamic linker characteristics +# Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER. +# Unlike libtool.m4, here we don't care about _all_ names of the library, but +# only about the one the linker finds when passed -lNAME. This is the last +# element of library_names_spec in libtool.m4, or possibly two of them if the +# linker has special search rules. +library_names_spec= # the last element of library_names_spec in libtool.m4 +libname_spec='lib$name' +case "$host_os" in + aix3*) + library_names_spec='$libname.a' + ;; + aix4* | aix5*) + library_names_spec='$libname$shrext' + ;; + amigaos*) + library_names_spec='$libname.a' + ;; + beos*) + library_names_spec='$libname$shrext' + ;; + bsdi[45]*) + library_names_spec='$libname$shrext' + ;; + cygwin* | mingw* | pw32*) + shrext=.dll + library_names_spec='$libname.dll.a $libname.lib' + ;; + darwin* | rhapsody*) + shrext=.dylib + library_names_spec='$libname$shrext' + ;; + dgux*) + library_names_spec='$libname$shrext' + ;; + freebsd1*) + ;; + freebsd* | dragonfly*) + case "$host_os" in + freebsd[123]*) + library_names_spec='$libname$shrext$versuffix' ;; + *) + library_names_spec='$libname$shrext' ;; + esac + ;; + gnu*) + library_names_spec='$libname$shrext' + ;; + hpux9* | hpux10* | hpux11*) + case $host_cpu in + ia64*) + shrext=.so + ;; + hppa*64*) + shrext=.sl + ;; + *) + shrext=.sl + ;; + esac + library_names_spec='$libname$shrext' + ;; + interix[3-9]*) + library_names_spec='$libname$shrext' + ;; + irix5* | irix6* | nonstopux*) + library_names_spec='$libname$shrext' + case "$host_os" in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;; + *) libsuff= shlibsuff= ;; + esac + ;; + esac + ;; + linux*oldld* | linux*aout* | linux*coff*) + ;; + linux* | k*bsd*-gnu) + library_names_spec='$libname$shrext' + ;; + knetbsd*-gnu) + library_names_spec='$libname$shrext' + ;; + netbsd*) + library_names_spec='$libname$shrext' + ;; + newsos6) + library_names_spec='$libname$shrext' + ;; + nto-qnx*) + library_names_spec='$libname$shrext' + ;; + openbsd*) + library_names_spec='$libname$shrext$versuffix' + ;; + os2*) + libname_spec='$name' + shrext=.dll + library_names_spec='$libname.a' + ;; + osf3* | osf4* | osf5*) + library_names_spec='$libname$shrext' + ;; + rdos*) + ;; + solaris*) + library_names_spec='$libname$shrext' + ;; + sunos4*) + library_names_spec='$libname$shrext$versuffix' + ;; + sysv4 | sysv4.3*) + library_names_spec='$libname$shrext' + ;; + sysv4*MP*) + library_names_spec='$libname$shrext' + ;; + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + library_names_spec='$libname$shrext' + ;; + uts4*) + library_names_spec='$libname$shrext' + ;; +esac + +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' +escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` +shlibext=`echo "$shrext" | sed -e 's,^\.,,'` +escaped_libname_spec=`echo "X$libname_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` +escaped_library_names_spec=`echo "X$library_names_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` +escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` + +LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' < Date: Fri, 1 Jan 2010 21:32:30 +0100 Subject: [PATCH 083/164] 2009-01-01 Yves Blusseau * configure.ac: check external intl library * Makefile.in: add compiler and linker flags to properly compile with intl library * include/grub/i18n.h: add a check to disable NLS * util/misc.c (grub_util_init_nls): new function * include/grub/util/misc.h: likewise * util/elf/grub-mkimage.c: use the new function below to initialize NLS * util/grub-editenv.c: likewise * util/grub-emu.c: likewise * util/grub-fstest.c: likewise * util/grub-mkdevicemap.c: likewise * util/grub-mkfont.c: likewise * util/grub-mkrelpath.c: likewise * util/grub-probe.c: likewise * util/i386/pc/grub-mkimage.c: likewise * util/i386/pc/grub-setup.c: likewise * util/sparc64/ieee1275/grub-mkimage.c: likewise * util/sparc64/ieee1275/grub-ofpathname.c: likewise * util/sparc64/ieee1275/grub-setup.c: likewise * util/mkisofs/mkisofs.h: add a check to disable NLS * util/mkisofs/mkisofs.c: likewise --- Makefile.in | 9 ++++-- configure.ac | 4 +-- include/grub/i18n.h | 41 ++++++++++++++++++++----- include/grub/util/misc.h | 4 ++- util/elf/grub-mkimage.c | 7 ++--- util/grub-editenv.c | 7 ++--- util/grub-emu.c | 7 ++--- util/grub-fstest.c | 7 ++--- util/grub-mkdevicemap.c | 7 ++--- util/grub-mkfont.c | 7 ++--- util/grub-mkrelpath.c | 7 ++--- util/grub-probe.c | 7 ++--- util/i386/pc/grub-mkimage.c | 7 ++--- util/i386/pc/grub-setup.c | 7 ++--- util/misc.c | 13 +++++++- util/mkisofs/mkisofs.c | 4 ++- util/mkisofs/mkisofs.h | 19 ++++++++++-- util/sparc64/ieee1275/grub-mkimage.c | 7 ++--- util/sparc64/ieee1275/grub-ofpathname.c | 7 ++--- util/sparc64/ieee1275/grub-setup.c | 7 ++--- 20 files changed, 115 insertions(+), 70 deletions(-) diff --git a/Makefile.in b/Makefile.in index 46b380cd5..927db2cee 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ # -*- makefile -*- # -# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # This Makefile.in is free software; the author # gives unlimited permission to copy and/or distribute it, @@ -41,6 +41,9 @@ includedir = @includedir@ pkgdatadir = $(datadir)/`echo @PACKAGE_TARNAME@ | sed '$(transform)'` pkglibdir = $(libdir)/`echo @PACKAGE_TARNAME@/$(target_cpu)-$(platform) | sed '$(transform)'` +# Internationalization library. +LIBINTL = @LIBINTL@ + XGETTEXT = @XGETTEXT@ MSGMERGE = @MSGMERGE@ MSGFMT = @MSGFMT@ @@ -72,10 +75,12 @@ MKDIR_P = @MKDIR_P@ mkinstalldirs = $(srcdir)/mkinstalldirs +LIBS = @LIBS@ $(LIBINTL) + CC = @CC@ CFLAGS = @CFLAGS@ ASFLAGS = @ASFLAGS@ -LDFLAGS = @LDFLAGS@ +LDFLAGS = @LDFLAGS@ $(LIBS) CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \ -DGRUB_LIBDIR=\"$(pkglibdir)\" -DLOCALEDIR=\"$(localedir)\" TARGET_CC = @TARGET_CC@ diff --git a/configure.ac b/configure.ac index 3cac421e8..4b5b5dd5a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # This configure.ac is free software; the author # gives unlimited permission to copy and/or distribute it, @@ -178,7 +178,7 @@ AC_PROG_CC test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required]) AC_GNU_SOURCE -AM_GNU_GETTEXT +AM_GNU_GETTEXT([external]) AC_SYS_LARGEFILE # Identify characteristics of the host architecture. diff --git a/include/grub/i18n.h b/include/grub/i18n.h index f6f468744..4d4a0b7bd 100644 --- a/include/grub/i18n.h +++ b/include/grub/i18n.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,17 +19,42 @@ #ifndef GRUB_I18N_H #define GRUB_I18N_H 1 -#ifdef GRUB_UTIL -# include -# include -# define _(str) gettext(str) -#else -# define _(str) grub_gettext(str) +#include +#include const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s); extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s); -#endif +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +# ifdef GRUB_UTIL + +# include +# include + +# endif /* GRUB_UTIL */ + +#else /* ! ENABLE_NLS */ + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# ifdef GRUB_UTIL +# define gettext(Msgid) ((const char *) (Msgid)) +# else +# define grub_gettext(str) ((const char *) (str)) +# endif /* GRUB_UTIL */ + +#endif /* ENABLE_NLS */ + +#ifdef GRUB_UTIL +# define _(str) gettext(str) +#else +# define _(str) grub_gettext(str) +#endif /* GRUB_UTIL */ #define N_(str) str diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 09108547c..373fff8bb 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -88,4 +88,6 @@ grub_int64_t grub_util_get_disk_size (char *name); char *make_system_path_relative_to_its_root (const char *path); +void grub_util_init_nls (void); + #endif /* ! GRUB_UTIL_MISC_HEADER */ diff --git a/util/elf/grub-mkimage.c b/util/elf/grub-mkimage.c index 5750543ad..6ba8b1ae2 100644 --- a/util/elf/grub-mkimage.c +++ b/util/elf/grub-mkimage.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -361,9 +361,8 @@ main (int argc, char *argv[]) int chrp = 0; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); while (1) { diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 68fb23b15..b6b731549 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -1,7 +1,7 @@ /* grub-editenv.c - tool to edit environment block. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -256,9 +256,8 @@ main (int argc, char *argv[]) char *command; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/grub-emu.c b/util/grub-emu.c index e65c8585e..3f2acaaec 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -159,9 +159,8 @@ main (int argc, char *argv[]) int opt; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1) switch (opt) diff --git a/util/grub-fstest.c b/util/grub-fstest.c index fa54fe414..586dda0f9 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -1,7 +1,7 @@ /* grub-fstest.c - debug tool for filesystem driver */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -384,9 +384,8 @@ main (int argc, char *argv[]) int i, cmd, num_opts, image_index, num_disks = 1; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Find the first non option entry. */ for (num_opts = 1; num_opts < argc; num_opts++) diff --git a/util/grub-mkdevicemap.c b/util/grub-mkdevicemap.c index 2b69f905e..b4febbb8d 100644 --- a/util/grub-mkdevicemap.c +++ b/util/grub-mkdevicemap.c @@ -1,7 +1,7 @@ /* grub-mkdevicemap.c - make a device map file automatically */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,9 +112,8 @@ main (int argc, char *argv[]) int floppy_disks = 1; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 9775e0803..a358ba5b0 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -476,9 +476,8 @@ main (int argc, char *argv[]) memset (&font_info, 0, sizeof (font_info)); set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c index 956e52ed7..62e400814 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -1,7 +1,7 @@ /* grub-mkrelpath.c - make a system path relative to its root */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,9 +56,8 @@ main (int argc, char *argv[]) char *argument, *relpath; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/grub-probe.c b/util/grub-probe.c index ebf5142d4..4ba8a98e5 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -1,7 +1,7 @@ /* grub-probe.c - probe device information for a given path */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -338,9 +338,8 @@ main (int argc, char *argv[]) char *argument; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index 3c2cb7549..aaa1a13db 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -1,7 +1,7 @@ /* grub-mkimage.c - make a bootable image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -351,9 +351,8 @@ main (int argc, char *argv[]) FILE *fp = stdout; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); while (1) { diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index c2b9b9268..5a1cbb27a 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -1,7 +1,7 @@ /* grub-setup.c - make GRUB usable */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -641,9 +641,8 @@ main (int argc, char *argv[]) int must_embed = 0, force = 0, fs_probe = 1; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) diff --git a/util/misc.c b/util/misc.c index 6aa92fb64..d8aa041be 100644 --- a/util/misc.c +++ b/util/misc.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,6 +38,7 @@ #include #include #include +#include #include "progname.h" @@ -566,3 +567,13 @@ make_system_path_relative_to_its_root (const char *path) return buf3; } + +void +grub_util_init_nls (void) +{ +#if ENABLE_NLS + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); +#endif /* ENABLE_NLS */ +} diff --git a/util/mkisofs/mkisofs.c b/util/mkisofs/mkisofs.c index 8e99d5c18..dffe4f703 100644 --- a/util/mkisofs/mkisofs.c +++ b/util/mkisofs/mkisofs.c @@ -6,7 +6,7 @@ Copyright 1993 Yggdrasil Computing, Incorporated - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009,2010 Free Software Foundation, Inc. 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 @@ -645,9 +645,11 @@ int FDECL2(main, int, argc, char **, argv){ char *log_file = 0; set_program_name (argv[0]); +#if ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); +#endif /* ENABLE_NLS */ if (argc < 2) usage(); diff --git a/util/mkisofs/mkisofs.h b/util/mkisofs/mkisofs.h index 79ae50251..482db6ceb 100644 --- a/util/mkisofs/mkisofs.h +++ b/util/mkisofs/mkisofs.h @@ -5,7 +5,7 @@ Copyright 1993 Yggdrasil Computing, Incorporated - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009,2010 Free Software Foundation, Inc. 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 @@ -30,8 +30,21 @@ #include #include -#include -#include +#if ENABLE_NLS + +# include +# include + +#else /* ! ENABLE_NLS */ + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# define gettext(Msgid) ((const char *) (Msgid)) +#endif /* ENABLE_NLS */ + #define _(str) gettext(str) #define N_(str) str diff --git a/util/sparc64/ieee1275/grub-mkimage.c b/util/sparc64/ieee1275/grub-mkimage.c index d756586af..b79bbeb41 100644 --- a/util/sparc64/ieee1275/grub-mkimage.c +++ b/util/sparc64/ieee1275/grub-mkimage.c @@ -1,7 +1,7 @@ /* grub-mkimage.c - make a bootable image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -222,9 +222,8 @@ main (int argc, char *argv[]) FILE *fp = stdout; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_ls (); while (1) { diff --git a/util/sparc64/ieee1275/grub-ofpathname.c b/util/sparc64/ieee1275/grub-ofpathname.c index 166ce4cbe..3ac6fce8b 100644 --- a/util/sparc64/ieee1275/grub-ofpathname.c +++ b/util/sparc64/ieee1275/grub-ofpathname.c @@ -1,7 +1,7 @@ /* grub-ofpathname.c - Find OpenBOOT path for a given device */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,9 +29,8 @@ int main(int argc, char **argv) char *of_path; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); if (argc != 2) { diff --git a/util/sparc64/ieee1275/grub-setup.c b/util/sparc64/ieee1275/grub-setup.c index ade1bd595..9d8e67562 100644 --- a/util/sparc64/ieee1275/grub-setup.c +++ b/util/sparc64/ieee1275/grub-setup.c @@ -1,7 +1,7 @@ /* grub-setup.c - make GRUB usable */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -620,9 +620,8 @@ main (int argc, char *argv[]) struct grub_setup_info ginfo; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); init_info (&ginfo); if (!parse_options (&ginfo, argc, argv)) From b1c10d44120800299ca43c0757943e305a56f813 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Fri, 1 Jan 2010 21:41:59 +0100 Subject: [PATCH 084/164] 2009-01-01 Yves Blusseau * util/mkisofs/mkisofs.c: fix a warning about a bad cast when NLS is disabled --- util/mkisofs/mkisofs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/mkisofs/mkisofs.c b/util/mkisofs/mkisofs.c index dffe4f703..588345232 100644 --- a/util/mkisofs/mkisofs.c +++ b/util/mkisofs/mkisofs.c @@ -490,7 +490,7 @@ void usage(){ int comma; int len; unsigned int j; - char *arg; + const char *arg; printf (" "); From 18f81dfc029736979a16b2cdea80aa29abfb2937 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Fri, 1 Jan 2010 22:48:52 +0100 Subject: [PATCH 085/164] 2010-01-01 Yves Blusseau * kern/misc.c (memcmp): add missing memcmp "alias" function for Apple platforms (memset): add missing memset "alias" function for Apple platforms --- kern/misc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kern/misc.c b/kern/misc.c index f6d189e94..63007510e 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -1,7 +1,7 @@ /* misc.c - definitions of misc functions */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -227,6 +227,11 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n) #ifndef APPLE_CC int memcmp (const void *s1, const void *s2, grub_size_t n) __attribute__ ((alias ("grub_memcmp"))); +#else +int memcmp (const void *s1, const void *s2, grub_size_t n) +{ + return grub_memcmp (s1, s2, n); +} #endif int @@ -512,6 +517,11 @@ grub_memset (void *s, int c, grub_size_t n) #ifndef APPLE_CC void *memset (void *s, int c, grub_size_t n) __attribute__ ((alias ("grub_memset"))); +#else +void *memset (void *s, int c, grub_size_t n) +{ + return grub_memset (s, c, n); +} #endif grub_size_t From da8d5c53e9f0fa207c259e7713518aa6a21119a5 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 2 Jan 2010 15:19:57 +0000 Subject: [PATCH 086/164] 2010-01-02 Colin Watson * term/i386/pc/at_keyboard.c (keyboard_controller_wait_untill_ready): Rename to ... (keyboard_controller_wait_until_ready): ... this. Update all users. --- ChangeLog | 6 ++++++ term/i386/pc/at_keyboard.c | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 634e8aad0..3b7ccab32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-02 Colin Watson + + * term/i386/pc/at_keyboard.c + (keyboard_controller_wait_untill_ready): Rename to ... + (keyboard_controller_wait_until_ready): ... this. Update all users. + 2010-01-01 Carles Pina i Estany * commands/help.c: Include `grub/mm.h' and `grub/normal.h'. diff --git a/term/i386/pc/at_keyboard.c b/term/i386/pc/at_keyboard.c index 4ad60c65c..6382c954a 100644 --- a/term/i386/pc/at_keyboard.c +++ b/term/i386/pc/at_keyboard.c @@ -72,7 +72,7 @@ static char keyboard_map_shift[128] = static grub_uint8_t grub_keyboard_controller_orig; static void -keyboard_controller_wait_untill_ready (void) +keyboard_controller_wait_until_ready (void) { while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))); } @@ -80,7 +80,7 @@ keyboard_controller_wait_untill_ready (void) static void grub_keyboard_controller_write (grub_uint8_t c) { - keyboard_controller_wait_untill_ready (); + keyboard_controller_wait_until_ready (); grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS); grub_outb (c, KEYBOARD_REG_DATA); } @@ -88,7 +88,7 @@ grub_keyboard_controller_write (grub_uint8_t c) static grub_uint8_t grub_keyboard_controller_read (void) { - keyboard_controller_wait_untill_ready (); + keyboard_controller_wait_until_ready (); grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS); return grub_inb (KEYBOARD_REG_DATA); } @@ -96,9 +96,9 @@ grub_keyboard_controller_read (void) static void keyboard_controller_led (grub_uint8_t leds) { - keyboard_controller_wait_untill_ready (); + keyboard_controller_wait_until_ready (); grub_outb (0xed, KEYBOARD_REG_DATA); - keyboard_controller_wait_untill_ready (); + keyboard_controller_wait_until_ready (); grub_outb (leds & 0x7, KEYBOARD_REG_DATA); } From 77a795923bd2fdde4b27233c0d7a918d46ce68ed Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 19:24:22 +0100 Subject: [PATCH 087/164] 2010-01-03 Carles Pina i Estany * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files. --- ChangeLog | 51 ++++++++++++++++++++++++++ commands/acpi.c | 31 ++++++++-------- commands/blocklist.c | 3 +- commands/boot.c | 3 +- commands/cat.c | 3 +- commands/cmp.c | 3 +- commands/configfile.c | 11 +++--- commands/crc.c | 5 ++- commands/date.c | 5 ++- commands/echo.c | 7 ++-- commands/efi/fixvideo.c | 3 +- commands/efi/loadbios.c | 5 ++- commands/gptsync.c | 7 ++-- commands/halt.c | 5 ++- commands/handler.c | 13 ++++--- commands/hdparm.c | 35 +++++++++--------- commands/hexdump.c | 9 +++-- commands/i386/cpuid.c | 5 ++- commands/i386/pc/drivemap.c | 11 +++--- commands/i386/pc/halt.c | 5 ++- commands/i386/pc/pxecmd.c | 3 +- commands/i386/pc/vbeinfo.c | 3 +- commands/i386/pc/vbetest.c | 3 +- commands/ieee1275/suspend.c | 3 +- commands/keystatus.c | 11 +++--- commands/loadenv.c | 3 +- commands/ls.c | 11 +++--- commands/lsmmap.c | 3 +- commands/lspci.c | 3 +- commands/memrw.c | 15 ++++---- commands/minicmd.c | 17 +++++---- commands/parttool.c | 3 +- commands/password.c | 7 ++-- commands/probe.c | 17 +++++---- commands/read.c | 5 ++- commands/reboot.c | 3 +- commands/search.c | 2 +- commands/sleep.c | 9 +++-- commands/test.c | 5 ++- commands/true.c | 5 ++- commands/usbtest.c | 3 +- commands/videotest.c | 3 +- commands/xnu_uuid.c | 7 ++-- disk/loopback.c | 9 +++-- hello/hello.c | 3 +- loader/i386/bsd.c | 73 +++++++++++++++++++------------------ po/POTFILES | 55 ++++++++++++++++++++++++++-- term/i386/pc/serial.c | 17 +++++---- 48 files changed, 333 insertions(+), 188 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b7ccab32..7da0c929e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,54 @@ +2010-01-03 Carles Pina i Estany + + * commands/acpi.c: Gettextizze help strings and/or options. Include + `grub/i18n.h' if needed. + * commands/blocklist.c: Likewise. + * commands/boot.c: Likewise. + * commands/cat.c: Likewise. + * commands/cmp.c: Likewise. + * commands/configfile.c: Likewise. + * commands/crc.c: Likewise. + * commands/date.c: Likewise. + * commands/echo.c: Likewise. + * commands/efi/fixvideo.c: Likewise. + * commands/efi/loadbios.c: Likewise. + * commands/gptsync.c: Likewise. + * commands/halt.c: Likewise. + * commands/handler.c: Likewise. + * commands/hdparm.c: Likewise. + * commands/hexdump.c: Likewise. + * commands/i386/cpuid.c: Likewise. + * commands/i386/pc/drivemap.c: Likewise. + * commands/i386/pc/halt.c: Likewise. + * commands/i386/pc/pxecmd.c: Likewise. + * commands/i386/pc/vbeinfo.c: Likewise. + * commands/i386/pc/vbetest.c: Likewise. + * commands/ieee1275/suspend.c: Likewise. + * commands/keystatus.c: Likewise. + * commands/loadenv.c: Likewise. + * commands/ls.c: Likewise. + * commands/lsmmap.c: Likewise. + * commands/lspci.c: Likewise. + * commands/memrw.c: Likewise. + * commands/minicmd.c: Likewise. + * commands/parttool.c: Likewise. + * commands/password.c: Likewise. + * commands/probe.c: Likewise. + * commands/read.c: Likewise. + * commands/reboot.c: Likewise. + * commands/search.c: Likewise. + * commands/sleep.c: Likewise. + * commands/test.c: Likewise. + * commands/true.c: Likewise. + * commands/usbtest.c: Likewise. + * commands/videotest.c: Likewise. + * commands/xnu_uuid.c: Likewise. + * disk/loopback.c: Likewise. + * hello/hello.c: Likewise. + * loader/i386/bsd.c: Likewise. + * term/i386/pc/serial.c: Likewise. + * po/POTFILES: Add new files. + 2010-01-02 Colin Watson * term/i386/pc/at_keyboard.c diff --git a/commands/acpi.c b/commands/acpi.c index ce4e2db36..4d54539fd 100644 --- a/commands/acpi.c +++ b/commands/acpi.c @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_EFI #include @@ -36,23 +37,23 @@ static const struct grub_arg_option options[] = { {"exclude", 'x', 0, - "Don't load host tables specified by comma-separated list.", + N_("Don't load host tables specified by comma-separated list."), 0, ARG_TYPE_STRING}, {"load-only", 'n', 0, - "Load only tables specified by comma-separated list.", 0, ARG_TYPE_STRING}, - {"v1", '1', 0, "Expose v1 tables.", 0, ARG_TYPE_NONE}, - {"v2", '2', 0, "Expose v2 and v3 tables.", 0, ARG_TYPE_NONE}, - {"oemid", 'o', 0, "Set OEMID of RSDP, XSDT and RSDT.", 0, ARG_TYPE_STRING}, + N_("Load only tables specified by comma-separated list."), 0, ARG_TYPE_STRING}, + {"v1", '1', 0, N_("Expose v1 tables."), 0, ARG_TYPE_NONE}, + {"v2", '2', 0, N_("Expose v2 and v3 tables."), 0, ARG_TYPE_NONE}, + {"oemid", 'o', 0, N_("Set OEMID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING}, {"oemtable", 't', 0, - "Set OEMTABLE ID of RSDP, XSDT and RSDT.", 0, ARG_TYPE_STRING}, + N_("Set OEMTABLE ID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING}, {"oemtablerev", 'r', 0, - "Set OEMTABLE revision of RSDP, XSDT and RSDT.", 0, ARG_TYPE_INT}, + N_("Set OEMTABLE revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT}, {"oemtablecreator", 'c', 0, - "Set creator field of RSDP, XSDT and RSDT.", 0, ARG_TYPE_STRING}, + N_("Set creator field of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING}, {"oemtablecreatorrev", 'd', 0, - "Set creator revision of RSDP, XSDT and RSDT.", 0, ARG_TYPE_INT}, - {"no-ebda", 'e', 0, "Don't update EBDA. May fix failures or hangs on some." - " BIOSes but makes it ineffective with OS not receiving RSDP from GRUB.", + N_("Set creator revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT}, + {"no-ebda", 'e', 0, N_("Don't update EBDA. May fix failures or hangs on some." + " BIOSes but makes it ineffective with OS not receiving RSDP from GRUB."), 0, ARG_TYPE_NONE}, {0, 0, 0, 0, 0, 0} }; @@ -759,11 +760,11 @@ GRUB_MOD_INIT(acpi) { cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, GRUB_COMMAND_FLAG_BOTH, - "[-1|-2] [--exclude=table1,table2|" + N_("[-1|-2] [--exclude=table1,table2|" "--load-only=table1,table2] filename1 " - " [filename2] [...]", - "Load host acpi tables and tables " - "specified by arguments.", + " [filename2] [...]"), + N_("Load host acpi tables and tables " + "specified by arguments."), options); } diff --git a/commands/blocklist.c b/commands/blocklist.c index 3c9ef3a58..fec59a828 100644 --- a/commands/blocklist.c +++ b/commands/blocklist.c @@ -24,6 +24,7 @@ #include #include #include +#include static grub_err_t grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)), @@ -110,7 +111,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(blocklist) { cmd = grub_register_command ("blocklist", grub_cmd_blocklist, - "FILE", "Print a block list."); + N_("FILE"), N_("Print a block list.")); } GRUB_MOD_FINI(blocklist) diff --git a/commands/boot.c b/commands/boot.c index fe0453b8a..1ec1e6f77 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -23,6 +23,7 @@ #include #include #include +#include static grub_err_t (*grub_loader_boot_func) (void); static grub_err_t (*grub_loader_unload_func) (void); @@ -186,7 +187,7 @@ GRUB_MOD_INIT(boot) { cmd_boot = grub_register_command ("boot", grub_cmd_boot, - 0, "Boot an operating system."); + 0, N_("Boot an operating system.")); } GRUB_MOD_FINI(boot) diff --git a/commands/cat.c b/commands/cat.c index 9d0373b3a..844034777 100644 --- a/commands/cat.c +++ b/commands/cat.c @@ -24,6 +24,7 @@ #include #include #include +#include static grub_err_t grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)), @@ -78,7 +79,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(cat) { cmd = grub_register_command_p1 ("cat", grub_cmd_cat, - "FILE", "Show the contents of a file."); + N_("FILE"), N_("Show the contents of a file.")); } GRUB_MOD_FINI(cat) diff --git a/commands/cmp.c b/commands/cmp.c index bdd8ff82d..8fd939640 100644 --- a/commands/cmp.c +++ b/commands/cmp.c @@ -23,6 +23,7 @@ #include #include #include +#include #define BUFFER_SIZE 512 @@ -109,7 +110,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(cmp) { cmd = grub_register_command ("cmp", grub_cmd_cmp, - "FILE1 FILE2", "Compare two files."); + N_("FILE1 FILE2"), N_("Compare two files.")); } GRUB_MOD_FINI(cmp) diff --git a/commands/configfile.c b/commands/configfile.c index d1fe9169e..469447711 100644 --- a/commands/configfile.c +++ b/commands/configfile.c @@ -22,6 +22,7 @@ #include #include #include +#include static grub_err_t grub_cmd_source (grub_command_t cmd, int argc, char **args) @@ -53,16 +54,16 @@ GRUB_MOD_INIT(configfile) { cmd_configfile = grub_register_command ("configfile", grub_cmd_source, - "FILE", "Load another config file."); + N_("FILE"), N_("Load another config file.")); cmd_source = grub_register_command ("source", grub_cmd_source, - "FILE", - "Load another config file without changing context." + N_("FILE"), + N_("Load another config file without changing context.") ); cmd_dot = grub_register_command (".", grub_cmd_source, - "FILE", - "Load another config file without changing context." + N_("FILE"), + N_("Load another config file without changing context.") ); } diff --git a/commands/crc.c b/commands/crc.c index a6c17caf0..dff9fd55c 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -23,6 +23,7 @@ #include #include #include +#include static grub_err_t grub_cmd_crc (grub_command_t cmd __attribute__ ((unused)), @@ -57,8 +58,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(crc) { cmd = grub_register_command ("crc", grub_cmd_crc, - "FILE", - "Calculate the crc32 checksum of a file."); + N_("FILE"), + N_("Calculate the crc32 checksum of a file.")); } GRUB_MOD_FINI(crc) diff --git a/commands/date.c b/commands/date.c index 7197b066e..623db4943 100644 --- a/commands/date.c +++ b/commands/date.c @@ -22,6 +22,7 @@ #include #include #include +#include #define GRUB_DATETIME_SET_YEAR 1 #define GRUB_DATETIME_SET_MONTH 2 @@ -135,8 +136,8 @@ GRUB_MOD_INIT(date) { cmd = grub_register_command ("date", grub_cmd_date, - "[[year-]month-day] [hour:minute[:second]]", - "Command to display/set current datetime."); + N_("[[year-]month-day] [hour:minute[:second]]"), + N_("Command to display/set current datetime.")); } GRUB_MOD_FINI(date) diff --git a/commands/echo.c b/commands/echo.c index 4d5a59df3..4fea091cb 100644 --- a/commands/echo.c +++ b/commands/echo.c @@ -20,11 +20,12 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {0, 'n', 0, "Do not output the trailing newline.", 0, 0}, - {0, 'e', 0, "Enable interpretation of backslash escapes.", 0, 0}, + {0, 'n', 0, N_("Do not output the trailing newline."), 0, 0}, + {0, 'e', 0, N_("Enable interpretation of backslash escapes."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -113,7 +114,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(echo) { cmd = grub_register_extcmd ("echo", grub_cmd_echo, GRUB_COMMAND_FLAG_BOTH, - "[-e|-n] STRING", "Display a line of text.", + N_("[-e|-n] STRING"), N_("Display a line of text."), options); } diff --git a/commands/efi/fixvideo.c b/commands/efi/fixvideo.c index 685662237..0f821b7a2 100644 --- a/commands/efi/fixvideo.c +++ b/commands/efi/fixvideo.c @@ -22,6 +22,7 @@ #include #include #include +#include static struct grub_video_patch { @@ -99,7 +100,7 @@ static grub_command_t cmd_fixvideo; GRUB_MOD_INIT(fixvideo) { cmd_fixvideo = grub_register_command ("fix_video", grub_cmd_fixvideo, - 0, "Fix video problem."); + 0, N_("Fix video problem.")); } diff --git a/commands/efi/loadbios.c b/commands/efi/loadbios.c index de975c724..0f0d7bc10 100644 --- a/commands/efi/loadbios.c +++ b/commands/efi/loadbios.c @@ -23,6 +23,7 @@ #include #include #include +#include static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID; static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID; @@ -201,11 +202,11 @@ static grub_command_t cmd_fakebios, cmd_loadbios; GRUB_MOD_INIT(loadbios) { cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios, - 0, "Fake bios."); + 0, N_("Fake bios.")); cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios, "BIOS_DUMP [INT10_DUMP]", - "Load bios dump."); + N_("Load bios dump.")); } GRUB_MOD_FINI(loadbios) diff --git a/commands/gptsync.c b/commands/gptsync.c index b5fe0b8ed..d217b5d5c 100644 --- a/commands/gptsync.c +++ b/commands/gptsync.c @@ -27,6 +27,7 @@ #include #include #include +#include /* Convert a LBA address to a CHS address in the INT 13 format. */ /* Taken from grub1. */ @@ -240,13 +241,13 @@ GRUB_MOD_INIT(gptsync) { (void) mod; /* To stop warning. */ cmd = grub_register_command ("gptsync", grub_cmd_gptsync, - "DEVICE [PARTITION[+/-[TYPE]]] ...", - "Fill hybrid MBR of GPT drive DEVICE. " + N_("DEVICE [PARTITION[+/-[TYPE]]] ..."), + N_("Fill hybrid MBR of GPT drive DEVICE. " "specified partitions will be a part " "of hybrid mbr. Up to 3 partitions are " "allowed. TYPE is an MBR type. " "+ means that partition is active. " - "Only one partition can be active."); + "Only one partition can be active.")); } GRUB_MOD_FINI(gptsync) diff --git a/commands/halt.c b/commands/halt.c index 09431d3cb..3400115a0 100644 --- a/commands/halt.c +++ b/commands/halt.c @@ -20,6 +20,7 @@ #include #include #include +#include static grub_err_t grub_cmd_halt (grub_command_t cmd __attribute__ ((unused)), @@ -35,8 +36,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(halt) { cmd = grub_register_command ("halt", grub_cmd_halt, - 0, "Halts the computer. This command does not" - " work on all firmware implementations."); + 0, N_("Halts the computer. This command does" + " not work on all firmware implementations.")); } GRUB_MOD_FINI(halt) diff --git a/commands/handler.c b/commands/handler.c index 09b8ff5d0..7316db304 100644 --- a/commands/handler.c +++ b/commands/handler.c @@ -23,6 +23,7 @@ #include #include #include +#include static grub_err_t grub_cmd_handler (struct grub_command *cmd, @@ -95,16 +96,16 @@ GRUB_MOD_INIT(handler) { cmd_handler = grub_register_command ("handler", grub_cmd_handler, - "[class [handler]]", - "List or select a handler."); + N_("[class [handler]]"), + N_("List or select a handler.")); cmd_terminal_input = grub_register_command ("terminal_input", grub_cmd_handler, - "[handler]", - "List or select an input terminal."); + N_("[handler]"), + N_("List or select an input terminal.")); cmd_terminal_output = grub_register_command ("terminal_output", grub_cmd_handler, - "[handler]", - "List or select an output terminal."); + N_("[handler]"), + N_("List or select an output terminal.")); } GRUB_MOD_FINI(handler) diff --git a/commands/hdparm.c b/commands/hdparm.c index fbcd7f6a8..a3f8bbff0 100644 --- a/commands/hdparm.c +++ b/commands/hdparm.c @@ -24,29 +24,30 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"apm", 'B', 0, "Set Advanced Power Management\n" - "(1=low, ..., 254=high, 255=off).", + {"apm", 'B', 0, N_("Set Advanced Power Management\n" + "(1=low, ..., 254=high, 255=off)."), 0, ARG_TYPE_INT}, - {"power", 'C', 0, "Check power mode.", 0, ARG_TYPE_NONE}, - {"security-freeze", 'F', 0, "Freeze ATA security settings until reset.", + {"power", 'C', 0, N_("Check power mode."), 0, ARG_TYPE_NONE}, + {"security-freeze", 'F', 0, N_("Freeze ATA security settings until reset."), 0, ARG_TYPE_NONE}, - {"health", 'H', 0, "Check SMART health status.", 0, ARG_TYPE_NONE}, - {"aam", 'M', 0, "Set Automatic Acoustic Management\n" - "(0=off, 128=quiet, ..., 254=fast).", + {"health", 'H', 0, N_("Check SMART health status."), 0, ARG_TYPE_NONE}, + {"aam", 'M', 0, N_("Set Automatic Acoustic Management\n" + "(0=off, 128=quiet, ..., 254=fast)."), 0, ARG_TYPE_INT}, - {"standby-timeout", 'S', 0, "Set standby timeout\n" - "(0=off, 1=5s, 2=10s, ..., 240=20m, 241=30m, ...).", + {"standby-timeout", 'S', 0, N_("Set standby timeout\n" + "(0=off, 1=5s, 2=10s, ..., 240=20m, 241=30m, ...)."), 0, ARG_TYPE_INT}, - {"standby", 'y', 0, "Set drive to standby mode.", 0, ARG_TYPE_NONE}, - {"sleep", 'Y', 0, "Set drive to sleep mode.", 0, ARG_TYPE_NONE}, - {"identify", 'i', 0, "Print drive identity and settings.", + {"standby", 'y', 0, N_("Set drive to standby mode."), 0, ARG_TYPE_NONE}, + {"sleep", 'Y', 0, N_("Set drive to sleep mode."), 0, ARG_TYPE_NONE}, + {"identify", 'i', 0, N_("Print drive identity and settings."), 0, ARG_TYPE_NONE}, - {"dumpid", 'I', 0, "Dump contents of ATA IDENTIFY sector.", + {"dumpid", 'I', 0, N_("Dump contents of ATA IDENTIFY sector."), 0, ARG_TYPE_NONE}, - {"smart", -1, 0, "Disable/enable SMART (0/1).", 0, ARG_TYPE_INT}, - {"quiet", 'q', 0, "Do not print messages.", 0, ARG_TYPE_NONE}, + {"smart", -1, 0, N_("Disable/enable SMART (0/1)."), 0, ARG_TYPE_INT}, + {"quiet", 'q', 0, N_("Do not print messages."), 0, ARG_TYPE_NONE}, {0, 0, 0, 0, 0, 0} }; @@ -410,8 +411,8 @@ GRUB_MOD_INIT(hdparm) { cmd = grub_register_extcmd ("hdparm", grub_cmd_hdparm, GRUB_COMMAND_FLAG_BOTH, - "[OPTIONS] DISK", - "Get/set ATA disk parameters.", options); + N_("[OPTIONS] DISK"), + N_("Get/set ATA disk parameters."), options); } GRUB_MOD_FINI(hdparm) diff --git a/commands/hexdump.c b/commands/hexdump.c index 771cde34d..5bdbb1f76 100644 --- a/commands/hexdump.c +++ b/commands/hexdump.c @@ -24,11 +24,12 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"skip", 's', 0, "Skip offset bytes from the beginning of file.", 0, + {"skip", 's', 0, N_("Skip offset bytes from the beginning of file."), 0, ARG_TYPE_INT}, - {"length", 'n', 0, "Read only LENGTH bytes.", 0, ARG_TYPE_INT}, + {"length", 'n', 0, N_("Read only LENGTH bytes."), 0, ARG_TYPE_INT}, {0, 0, 0, 0, 0, 0} }; @@ -121,8 +122,8 @@ GRUB_MOD_INIT (hexdump) { cmd = grub_register_extcmd ("hexdump", grub_cmd_hexdump, GRUB_COMMAND_FLAG_BOTH, - "[OPTIONS] FILE_OR_DEVICE", - "Dump the contents of a file or memory.", + N_("[OPTIONS] FILE_OR_DEVICE"), + N_("Dump the contents of a file or memory."), options); } diff --git a/commands/i386/cpuid.c b/commands/i386/cpuid.c index b1752ca89..6eebf91a1 100644 --- a/commands/i386/cpuid.c +++ b/commands/i386/cpuid.c @@ -25,6 +25,7 @@ #include #include #include +#include #define cpuid(num,a,b,c,d) \ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ @@ -33,7 +34,7 @@ static const struct grub_arg_option options[] = { - {"long-mode", 'l', 0, "Check for long mode flag (default).", 0, 0}, + {"long-mode", 'l', 0, N_("Check for long mode flag (default)."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -88,7 +89,7 @@ done: #endif cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, GRUB_COMMAND_FLAG_BOTH, - "[-l]", "Check for CPU features.", options); + "[-l]", N_("Check for CPU features."), options); } GRUB_MOD_FINI(cpuid) diff --git a/commands/i386/pc/drivemap.c b/commands/i386/pc/drivemap.c index adef57576..3d1dcf614 100644 --- a/commands/i386/pc/drivemap.c +++ b/commands/i386/pc/drivemap.c @@ -26,6 +26,7 @@ #include #include #include +#include /* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */ @@ -33,9 +34,9 @@ static grub_uint32_t *const int13slot = UINT_TO_PTR (4 * 0x13); /* Remember to update enum opt_idxs accordingly. */ static const struct grub_arg_option options[] = { - {"list", 'l', 0, "Show the current mappings.", 0, 0}, - {"reset", 'r', 0, "Reset all mappings to the default values.", 0, 0}, - {"swap", 's', 0, "Perform both direct and reverse mappings.", 0, 0}, + {"list", 'l', 0, N_("Show the current mappings."), 0, 0}, + {"reset", 'r', 0, N_("Reset all mappings to the default values."), 0, 0}, + {"swap", 's', 0, N_("Perform both direct and reverse mappings."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -403,8 +404,8 @@ GRUB_MOD_INIT (drivemap) cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap, GRUB_COMMAND_FLAG_BOTH, "drivemap" - " -l | -r | [-s] grubdev osdisk", - "Manage the BIOS drive mappings.", + N_(" -l | -r | [-s] grubdev osdisk"), + N_("Manage the BIOS drive mappings."), options); drivemap_hook = grub_loader_register_preboot_hook (&install_int13_handler, diff --git a/commands/i386/pc/halt.c b/commands/i386/pc/halt.c index c2e22882f..73c3a2e11 100644 --- a/commands/i386/pc/halt.c +++ b/commands/i386/pc/halt.c @@ -20,10 +20,11 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"no-apm", 'n', 0, "Do not use APM to halt the computer.", 0, 0}, + {"no-apm", 'n', 0, N_("Do not use APM to halt the computer."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -47,7 +48,7 @@ GRUB_MOD_INIT(halt) { cmd = grub_register_extcmd ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH, "[-n]", - "Halt the system, if possible using APM.", + N_("Halt the system, if possible using APM."), options); } diff --git a/commands/i386/pc/pxecmd.c b/commands/i386/pc/pxecmd.c index 1d4fb6a4d..b576a8ea4 100644 --- a/commands/i386/pc/pxecmd.c +++ b/commands/i386/pc/pxecmd.c @@ -22,6 +22,7 @@ #include #include #include +#include static grub_err_t grub_cmd_pxe_unload (grub_command_t cmd __attribute__ ((unused)), @@ -42,7 +43,7 @@ GRUB_MOD_INIT(pxecmd) { cmd = grub_register_command ("pxe_unload", grub_cmd_pxe_unload, 0, - "Unload PXE environment."); + N_("Unload PXE environment.")); } GRUB_MOD_FINI(pxecmd) diff --git a/commands/i386/pc/vbeinfo.c b/commands/i386/pc/vbeinfo.c index ee9f3c186..14f03846e 100644 --- a/commands/i386/pc/vbeinfo.c +++ b/commands/i386/pc/vbeinfo.c @@ -24,6 +24,7 @@ #include #include #include +#include static void * real2pm (grub_vbe_farptr_t ptr) @@ -175,7 +176,7 @@ GRUB_MOD_INIT(vbeinfo) { cmd = grub_register_command ("vbeinfo", grub_cmd_vbeinfo, 0, - "List compatible VESA BIOS extension video modes."); + N_("List compatible VESA BIOS extension video modes.")); } GRUB_MOD_FINI(vbeinfo) diff --git a/commands/i386/pc/vbetest.c b/commands/i386/pc/vbetest.c index 4050c869e..d97323087 100644 --- a/commands/i386/pc/vbetest.c +++ b/commands/i386/pc/vbetest.c @@ -25,6 +25,7 @@ #include #include #include +#include static grub_err_t grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)), @@ -168,7 +169,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(vbetest) { cmd = grub_register_command ("vbetest", grub_cmd_vbetest, - 0, "Test VESA BIOS Extension 2.0+ support."); + 0, N_("Test VESA BIOS Extension 2.0+ support.")); } GRUB_MOD_FINI(vbetest) diff --git a/commands/ieee1275/suspend.c b/commands/ieee1275/suspend.c index fd538f8ea..f096cc9ba 100644 --- a/commands/ieee1275/suspend.c +++ b/commands/ieee1275/suspend.c @@ -22,6 +22,7 @@ #include #include #include +#include static grub_err_t grub_cmd_suspend (grub_command_t cmd __attribute__ ((unused)), @@ -39,7 +40,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(ieee1275_suspend) { cmd = grub_register_command ("suspend", grub_cmd_suspend, - 0, "Return to Open Firmware prompt."); + 0, N_("Return to Open Firmware prompt.")); } GRUB_MOD_FINI(ieee1275_suspend) diff --git a/commands/keystatus.c b/commands/keystatus.c index 4f82550be..a0a429284 100644 --- a/commands/keystatus.c +++ b/commands/keystatus.c @@ -21,12 +21,13 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"shift", 's', 0, "Check Shift key.", 0, 0}, - {"ctrl", 'c', 0, "Check Control key.", 0, 0}, - {"alt", 'a', 0, "Check Alt key.", 0, 0}, + {"shift", 's', 0, N_("Check Shift key."), 0, 0}, + {"ctrl", 'c', 0, N_("Check Control key."), 0, 0}, + {"alt", 'a', 0, N_("Check Alt key."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -70,8 +71,8 @@ GRUB_MOD_INIT(keystatus) { cmd = grub_register_extcmd ("keystatus", grub_cmd_keystatus, GRUB_COMMAND_FLAG_BOTH, - "[--shift] [--ctrl] [--alt]", - "Check key modifier status.", + N_("[--shift] [--ctrl] [--alt]"), + N_("Check key modifier status."), options); } diff --git a/commands/loadenv.c b/commands/loadenv.c index 6ee4d204a..6f8714411 100644 --- a/commands/loadenv.c +++ b/commands/loadenv.c @@ -26,10 +26,11 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"file", 'f', 0, "Specify filename.", 0, ARG_TYPE_PATHNAME}, + {"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME}, {0, 0, 0, 0, 0, 0} }; diff --git a/commands/ls.c b/commands/ls.c index 4b1500398..9afca7907 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -30,12 +30,13 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"long", 'l', 0, "Show a long list with more detailed information.", 0, 0}, - {"human-readable", 'h', 0, "Print sizes in a human readable format.", 0, 0}, - {"all", 'a', 0, "List all files.", 0, 0}, + {"long", 'l', 0, N_("Show a long list with more detailed information."), 0, 0}, + {"human-readable", 'h', 0, N_("Print sizes in a human readable format."), 0, 0}, + {"all", 'a', 0, N_("List all files."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -260,8 +261,8 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(ls) { cmd = grub_register_extcmd ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH, - "[-l|-h|-a] [FILE]", - "List devices and files.", options); + N_("[-l|-h|-a] [FILE]"), + N_("List devices and files."), options); } GRUB_MOD_FINI(ls) diff --git a/commands/lsmmap.c b/commands/lsmmap.c index 09f141ea0..d5eef1ce9 100644 --- a/commands/lsmmap.c +++ b/commands/lsmmap.c @@ -20,6 +20,7 @@ #include #include #include +#include static grub_err_t grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)), @@ -43,7 +44,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(lsmmap) { cmd = grub_register_command ("lsmmap", grub_cmd_lsmmap, - 0, "List memory map provided by firmware."); + 0, N_("List memory map provided by firmware.")); } GRUB_MOD_FINI(lsmmap) diff --git a/commands/lspci.c b/commands/lspci.c index 63e60abe0..c2abd8736 100644 --- a/commands/lspci.c +++ b/commands/lspci.c @@ -21,6 +21,7 @@ #include #include #include +#include struct grub_pci_classname { @@ -218,7 +219,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(lspci) { cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, GRUB_COMMAND_FLAG_BOTH, - "[-i]", "List PCI devices.", options); + "[-i]", N_("List PCI devices."), options); } GRUB_MOD_FINI(lspci) diff --git a/commands/memrw.c b/commands/memrw.c index 8e9c3db11..d0908a237 100644 --- a/commands/memrw.c +++ b/commands/memrw.c @@ -21,13 +21,14 @@ #include #include #include +#include static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword; static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword; static const struct grub_arg_option options[] = { - {0, 'v', 0, "Save read value into variable VARNAME.", + {0, 'v', 0, N_("Save read value into variable VARNAME."), "VARNAME", ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -119,22 +120,22 @@ GRUB_MOD_INIT(memrw) { cmd_read_byte = grub_register_extcmd ("read_byte", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH, - "ADDR", "Read byte from ADDR.", options); + N_("ADDR"), N_("Read byte from ADDR."), options); cmd_read_word = grub_register_extcmd ("read_word", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH, - "ADDR", "Read word from ADDR.", options); + N_("ADDR"), N_("Read word from ADDR."), options); cmd_read_dword = grub_register_extcmd ("read_dword", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH, - "ADDR", "Read dword from ADDR.", options); + N_("ADDR"), N_("Read dword from ADDR."), options); cmd_write_byte = grub_register_command ("write_byte", grub_cmd_write, - "ADDR VALUE [MASK]", "Write byte VALUE to ADDR."); + N_("ADDR VALUE [MASK]"), N_("Write byte VALUE to ADDR.")); cmd_write_word = grub_register_command ("write_word", grub_cmd_write, - "ADDR VALUE [MASK]", "Write word VALUE to ADDR."); + N_("ADDR VALUE [MASK]"), N_("Write word VALUE to ADDR.")); cmd_write_dword = grub_register_command ("write_dword", grub_cmd_write, - "ADDR VALUE [MASK]", "Write dword VALUE to ADDR."); + N_("ADDR VALUE [MASK]"), N_("Write dword VALUE to ADDR.")); } GRUB_MOD_FINI(memrw) diff --git a/commands/minicmd.c b/commands/minicmd.c index 47b57e3ed..72e855faf 100644 --- a/commands/minicmd.c +++ b/commands/minicmd.c @@ -27,6 +27,7 @@ #include #include #include +#include /* cat FILE */ static grub_err_t @@ -354,28 +355,28 @@ GRUB_MOD_INIT(minicmd) { cmd_cat = grub_register_command ("cat", grub_mini_cmd_cat, - "FILE", "Show the contents of a file."); + N_("FILE"), N_("Show the contents of a file.")); cmd_help = grub_register_command ("help", grub_mini_cmd_help, - 0, "Show this message."); + 0, N_("Show this message.")); cmd_root = grub_register_command ("root", grub_mini_cmd_root, - "[DEVICE]", "Set the root device."); + N_("[DEVICE]"), N_("Set the root device.")); cmd_dump = grub_register_command ("dump", grub_mini_cmd_dump, - "ADDR", "Dump memory."); + N_("ADDR"), N_("Dump memory.")); cmd_rmmod = grub_register_command ("rmmod", grub_mini_cmd_rmmod, - "MODULE", "Remove a module."); + N_("MODULE"), N_("Remove a module.")); cmd_lsmod = grub_register_command ("lsmod", grub_mini_cmd_lsmod, - 0, "Show loaded modules."); + 0, N_("Show loaded modules.")); cmd_exit = grub_register_command ("exit", grub_mini_cmd_exit, - 0, "Exit from GRUB."); + 0, N_("Exit from GRUB.")); cmd_clear = grub_register_command ("clear", grub_mini_cmd_clear, - 0, "Clear the screen."); + 0, N_("Clear the screen.")); } GRUB_MOD_FINI(minicmd) diff --git a/commands/parttool.c b/commands/parttool.c index 62fe5ad2b..3f69d5525 100644 --- a/commands/parttool.c +++ b/commands/parttool.c @@ -29,6 +29,7 @@ #include #include #include +#include static struct grub_parttool *parts = 0; static int curhandle = 0; @@ -322,7 +323,7 @@ GRUB_MOD_INIT(parttool) { mymod = mod; cmd = grub_register_command ("parttool", grub_cmd_parttool, - "PARTITION COMMANDS", + N_("PARTITION COMMANDS"), helpmsg); } diff --git a/commands/password.c b/commands/password.c index d9b31f962..2869ffc53 100644 --- a/commands/password.c +++ b/commands/password.c @@ -23,6 +23,7 @@ #include #include #include +#include static grub_dl_t my_mod; @@ -75,9 +76,9 @@ GRUB_MOD_INIT(password) { my_mod = mod; cmd = grub_register_command ("password", grub_cmd_password, - "USER PASSWORD", - "Set user password (plaintext). " - "Unrecommended and insecure."); + N_("USER PASSWORD"), + N_("Set user password (plaintext). " + "Unrecommended and insecure.")); } GRUB_MOD_FINI(password) diff --git a/commands/probe.c b/commands/probe.c index 7de1c1d34..c2cc599e9 100644 --- a/commands/probe.c +++ b/commands/probe.c @@ -30,16 +30,17 @@ #include #include #include +#include static const struct grub_arg_option options[] = { {"set", 's', GRUB_ARG_OPTION_OPTIONAL, - "Set a variable to return value.", "VAR", ARG_TYPE_STRING}, - {"driver", 'd', 0, "Determine driver.", 0, 0}, - {"partmap", 'p', 0, "Determine partition map type.", 0, 0}, - {"fs", 'f', 0, "Determine filesystem type.", 0, 0}, - {"fs-uuid", 'u', 0, "Determine filesystem UUID.", 0, 0}, - {"label", 'l', 0, "Determine filesystem label.", 0, 0}, + N_("Set a variable to return value."), "VAR", ARG_TYPE_STRING}, + {"driver", 'd', 0, N_("Determine driver."), 0, 0}, + {"partmap", 'p', 0, N_("Determine partition map type."), 0, 0}, + {"fs", 'f', 0, N_("Determine filesystem type."), 0, 0}, + {"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), 0, 0}, + {"label", 'l', 0, N_("Determine filesystem label."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -150,8 +151,8 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT (probe) { cmd = grub_register_extcmd ("probe", grub_cmd_probe, GRUB_COMMAND_FLAG_BOTH, - "[DEVICE]", - "Retrieve device info.", options); + N_("[DEVICE]"), + N_("Retrieve device info."), options); } GRUB_MOD_FINI (probe) diff --git a/commands/read.c b/commands/read.c index 5f4451a72..8a7c4a01f 100644 --- a/commands/read.c +++ b/commands/read.c @@ -24,6 +24,7 @@ #include #include #include +#include static char * grub_getline (void) @@ -79,8 +80,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(read) { cmd = grub_register_command ("read", grub_cmd_read, - "[ENVVAR]", - "Set variable with user input."); + N_("[ENVVAR]"), + N_("Set variable with user input.")); } GRUB_MOD_FINI(read) diff --git a/commands/reboot.c b/commands/reboot.c index 2add295ef..eedd53c91 100644 --- a/commands/reboot.c +++ b/commands/reboot.c @@ -20,6 +20,7 @@ #include #include #include +#include static grub_err_t grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)), @@ -35,7 +36,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(reboot) { cmd = grub_register_command ("reboot", grub_cmd_reboot, - 0, "Reboot the computer."); + 0, N_("Reboot the computer.")); } GRUB_MOD_FINI(reboot) diff --git a/commands/search.c b/commands/search.c index 01e83739b..2f0cef8aa 100644 --- a/commands/search.c +++ b/commands/search.c @@ -165,7 +165,7 @@ GRUB_MOD_INIT(search_fs_label) { cmd = grub_register_command (COMMAND_NAME, grub_cmd_do_search, - "NAME [VARIABLE]", + N_("NAME [VARIABLE]"), "Search devices by " SEARCH_TARGET "." " If VARIABLE is specified, " "the first device found is set to a variable."); diff --git a/commands/sleep.c b/commands/sleep.c index eb9aeb510..a2caad89a 100644 --- a/commands/sleep.c +++ b/commands/sleep.c @@ -24,11 +24,12 @@ #include #include #include +#include static const struct grub_arg_option options[] = { - {"verbose", 'v', 0, "Verbose countdown.", 0, 0}, - {"interruptible", 'i', 0, "Interruptible with ESC.", 0, 0}, + {"verbose", 'v', 0, N_("Verbose countdown."), 0, 0}, + {"interruptible", 'i', 0, N_("Interruptible with ESC."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -105,8 +106,8 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(sleep) { cmd = grub_register_extcmd ("sleep", grub_cmd_sleep, GRUB_COMMAND_FLAG_BOTH, - "NUMBER_OF_SECONDS", - "Wait for a specified number of seconds.", + N_("NUMBER_OF_SECONDS"), + N_("Wait for a specified number of seconds."), options); } diff --git a/commands/test.c b/commands/test.c index 8d1e24859..318a42264 100644 --- a/commands/test.c +++ b/commands/test.c @@ -25,6 +25,7 @@ #include #include #include +#include /* A simple implementation for signed numbers. */ static int @@ -420,9 +421,9 @@ static grub_command_t cmd_1, cmd_2; GRUB_MOD_INIT(test) { cmd_1 = grub_register_command ("[", grub_cmd_test, - "EXPRESSION ]", "Evaluate an expression."); + N_("EXPRESSION ]"), N_("Evaluate an expression.")); cmd_2 = grub_register_command ("test", grub_cmd_test, - "EXPRESSION", "Evaluate an expression."); + N_("EXPRESSION"), N_("Evaluate an expression.")); } GRUB_MOD_FINI(test) diff --git a/commands/true.c b/commands/true.c index ef9f65889..aa8125853 100644 --- a/commands/true.c +++ b/commands/true.c @@ -19,6 +19,7 @@ #include #include +#include static grub_err_t grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)), @@ -43,10 +44,10 @@ GRUB_MOD_INIT(true) { cmd_true = grub_register_command ("true", grub_cmd_true, - 0, "Do nothing, successfully."); + 0, N_("Do nothing, successfully.")); cmd_false = grub_register_command ("false", grub_cmd_false, - 0, "Do nothing, unsuccessfully."); + 0, N_("Do nothing, unsuccessfully.")); } GRUB_MOD_FINI(true) diff --git a/commands/usbtest.c b/commands/usbtest.c index df124ca18..b884a93f1 100644 --- a/commands/usbtest.c +++ b/commands/usbtest.c @@ -25,6 +25,7 @@ #include #include #include +#include static const char *usb_classes[] = { @@ -195,7 +196,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(usbtest) { cmd = grub_register_command ("usb", grub_cmd_usbtest, - 0, "Test USB support."); + 0, N_("Test USB support.")); } GRUB_MOD_FINI(usbtest) diff --git a/commands/videotest.c b/commands/videotest.c index e27552510..850639bd9 100644 --- a/commands/videotest.c +++ b/commands/videotest.c @@ -24,6 +24,7 @@ #include #include #include +#include static grub_err_t grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), @@ -178,7 +179,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(videotest) { cmd = grub_register_command ("videotest", grub_cmd_videotest, - 0, "Test video subsystem."); + 0, N_("Test video subsystem.")); } GRUB_MOD_FINI(videotest) diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index 31e69ad13..32288636b 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -31,6 +31,7 @@ #include #include #include +#include struct tohash { @@ -377,9 +378,9 @@ static grub_command_t cmd; GRUB_MOD_INIT (xnu_uuid) { cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid, - "GRUBUUID [VARNAME]", - "Transform 64-bit UUID to format " - "suitable for xnu."); + N_("GRUBUUID [VARNAME]"), + N_("Transform 64-bit UUID to format " + "suitable for xnu.")); } GRUB_MOD_FINI (xnu_uuid) diff --git a/disk/loopback.c b/disk/loopback.c index c877dd8af..fbec0426f 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -23,6 +23,7 @@ #include #include #include +#include struct grub_loopback { @@ -36,8 +37,8 @@ static struct grub_loopback *loopback_list; static const struct grub_arg_option options[] = { - {"delete", 'd', 0, "delete the loopback device entry", 0, 0}, - {"partitions", 'p', 0, "simulate a hard drive with partitions", 0, 0}, + {"delete", 'd', 0, N_("delete the loopback device entry"), 0, 0}, + {"partitions", 'p', 0, N_("simulate a hard drive with partitions"), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -245,8 +246,8 @@ GRUB_MOD_INIT(loop) { cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, GRUB_COMMAND_FLAG_BOTH, - "loopback [-d|-p] DEVICENAME FILE", - "Make a device of a file.", options); + N_("loopback [-d|-p] DEVICENAME FILE"), + N_("Make a device of a file."), options); grub_disk_dev_register (&grub_loopback_dev); } diff --git a/hello/hello.c b/hello/hello.c index be60761ec..1e2a4ba7f 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -24,6 +24,7 @@ #include #include #include +#include static grub_err_t grub_cmd_hello (struct grub_extcmd *cmd __attribute__ ((unused)), @@ -39,7 +40,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(hello) { cmd = grub_register_extcmd ("hello", grub_cmd_hello, GRUB_COMMAND_FLAG_BOTH, - "hello", "Say hello", 0); + "hello", N_("Say hello"), 0); } GRUB_MOD_FINI(hello) diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index ca60b0be9..a7a860bb2 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_PCBIOS #include @@ -61,20 +62,20 @@ static grub_uint32_t openbsd_root; static const struct grub_arg_option freebsd_opts[] = { - {"dual", 'D', 0, "Display output on all consoles.", 0, 0}, - {"serial", 'h', 0, "Use serial console.", 0, 0}, - {"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0}, - {"cdrom", 'C', 0, "Use cdrom as root.", 0, 0}, - {"config", 'c', 0, "Invoke user configuration routing.", 0, 0}, - {"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0}, - {"gdb", 'g', 0, "Use GDB remote debugger instead of DDB.", 0, 0}, - {"mute", 'm', 0, "Disable all boot output.", 0, 0}, + {"dual", 'D', 0, N_("Display output on all consoles."), 0, 0}, + {"serial", 'h', 0, N_("Use serial console."), 0, 0}, + {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0}, + {"cdrom", 'C', 0, N_("Use cdrom as root."), 0, 0}, + {"config", 'c', 0, N_("Invoke user configuration routing."), 0, 0}, + {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0}, + {"gdb", 'g', 0, N_("Use GDB remote debugger instead of DDB."), 0, 0}, + {"mute", 'm', 0, N_("Disable all boot output."), 0, 0}, {"nointr", 'n', 0, "", 0, 0}, - {"pause", 'p', 0, "Wait for keypress after every line of output.", 0, 0}, + {"pause", 'p', 0, N_("Wait for keypress after every line of output."), 0, 0}, {"quiet", 'q', 0, "", 0, 0}, - {"dfltroot", 'r', 0, "Use compiled-in rootdev.", 0, 0}, - {"single", 's', 0, "Boot into single mode.", 0, 0}, - {"verbose", 'v', 0, "Boot with verbose messages.", 0, 0}, + {"dfltroot", 'r', 0, N_("Use compiled-in rootdev."), 0, 0}, + {"single", 's', 0, N_("Boot into single mode."), 0, 0}, + {"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -89,12 +90,12 @@ static const grub_uint32_t freebsd_flags[] = static const struct grub_arg_option openbsd_opts[] = { - {"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0}, - {"halt", 'b', 0, "Don't reboot, just halt.", 0, 0}, - {"config", 'c', 0, "Change configured devices.", 0, 0}, - {"single", 's', 0, "Boot into single mode.", 0, 0}, - {"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0}, - {"root", 'r', 0, "Set root device.", "wdXY", ARG_TYPE_STRING}, + {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0}, + {"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0}, + {"config", 'c', 0, N_("Change configured devices."), 0, 0}, + {"single", 's', 0, N_("Boot into single mode."), 0, 0}, + {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0}, + {"root", 'r', 0, N_("Set root device."), "wdXY", ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -108,19 +109,19 @@ static const grub_uint32_t openbsd_flags[] = static const struct grub_arg_option netbsd_opts[] = { - {"no-smp", '1', 0, "Disable SMP.", 0, 0}, - {"no-acpi", '2', 0, "Disable ACPI.", 0, 0}, - {"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0}, - {"halt", 'b', 0, "Don't reboot, just halt.", 0, 0}, - {"config", 'c', 0, "Change configured devices.", 0, 0}, - {"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0}, + {"no-smp", '1', 0, N_("Disable SMP."), 0, 0}, + {"no-acpi", '2', 0, N_("Disable ACPI."), 0, 0}, + {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0}, + {"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0}, + {"config", 'c', 0, N_("Change configured devices."), 0, 0}, + {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0}, {"miniroot", 'm', 0, "", 0, 0}, - {"quiet", 'q', 0, "Don't display boot diagnostic messages.", 0, 0}, - {"single", 's', 0, "Boot into single mode.", 0, 0}, - {"verbose", 'v', 0, "Boot with verbose messages.", 0, 0}, - {"debug", 'x', 0, "Boot with debug messages.", 0, 0}, - {"silent", 'z', 0, "Supress normal output (warnings remain).", 0, 0}, - {"root", 'r', 0, "Set root device.", "DEVICE", ARG_TYPE_STRING}, + {"quiet", 'q', 0, N_("Don't display boot diagnostic messages."), 0, 0}, + {"single", 's', 0, N_("Boot into single mode."), 0, 0}, + {"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0}, + {"debug", 'x', 0, N_("Boot with debug messages."), 0, 0}, + {"silent", 'z', 0, N_("Supress normal output (warnings remain)."), 0, 0}, + {"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -1280,25 +1281,25 @@ GRUB_MOD_INIT (bsd) { cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd, GRUB_COMMAND_FLAG_BOTH, - "FILE", "Load kernel of FreeBSD.", + N_("FILE"), N_("Load kernel of FreeBSD."), freebsd_opts); cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd, GRUB_COMMAND_FLAG_BOTH, - "FILE", "Load kernel of OpenBSD.", + N_("FILE"), N_("Load kernel of OpenBSD."), openbsd_opts); cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd, GRUB_COMMAND_FLAG_BOTH, - "FILE", "Load kernel of NetBSD.", + N_("FILE"), N_("Load kernel of NetBSD."), netbsd_opts); cmd_freebsd_loadenv = grub_register_command ("kfreebsd_loadenv", grub_cmd_freebsd_loadenv, - 0, "Load FreeBSD env."); + 0, N_("Load FreeBSD env.")); cmd_freebsd_module = grub_register_command ("kfreebsd_module", grub_cmd_freebsd_module, - 0, "Load FreeBSD kernel module."); + 0, N_("Load FreeBSD kernel module.")); cmd_freebsd_module_elf = grub_register_command ("kfreebsd_module_elf", grub_cmd_freebsd_module_elf, - 0, "Load FreeBSD kernel module (ELF)."); + 0, N_("Load FreeBSD kernel module (ELF).")); my_mod = mod; } diff --git a/po/POTFILES b/po/POTFILES index 6efa12219..4e7e032ec 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,13 +1,62 @@ # List of files which contain translatable strings. -commands/i386/pc/play.c -commands/loadenv.c -commands/search.c +commands/acpi.c +commands/blocklist.c +commands/boot.c +commands/cat.c +commands/cmp.c +commands/configfile.c +commands/crc.c +commands/date.c +commands/echo.c +commands/efi/fixvideo.c +commands/efi/loadbios.c +commands/gptsync.c +commands/halt.c +commands/handler.c +commands/hdparm.c commands/help.c +commands/hexdump.c +commands/i386/cpuid.c +commands/i386/pc/drivemap.c +commands/i386/pc/halt.c +commands/i386/pc/play.c +commands/i386/pc/pxecmd.c +commands/i386/pc/vbeinfo.c +commands/i386/pc/vbetest.c +commands/ieee1275/suspend.c +commands/keystatus.c +commands/loadenv.c +commands/ls.c +commands/lsmmap.c +commands/lspci.c +commands/memrw.c +commands/minicmd.c +commands/parttool.c +commands/password.c +commands/probe.c +commands/read.c +commands/reboot.c +commands/search.c +commands/search.c +commands/sleep.c +commands/test.c +commands/true.c +commands/usbtest.c +commands/videotest.c +commands/xnu_uuid.c + +disk/loopback.c + +hello/hello.c lib/arg.c +loader/i386/bsd.c + normal/dyncmd.c +term/i386/pc/serial.c + util/i386/pc/grub-mkimage.c util/i386/pc/grub-setup.c diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index 1c68f9bfc..e4e3c2755 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -26,6 +26,7 @@ #include #include #include +#include #define TEXT_WIDTH 80 #define TEXT_HEIGHT 25 @@ -41,12 +42,12 @@ static unsigned int npending = 0; /* Argument options. */ static const struct grub_arg_option options[] = { - {"unit", 'u', 0, "Set the serial unit", 0, ARG_TYPE_INT}, - {"port", 'p', 0, "Set the serial port address", 0, ARG_TYPE_STRING}, - {"speed", 's', 0, "Set the serial port speed", 0, ARG_TYPE_INT}, - {"word", 'w', 0, "Set the serial port word length", 0, ARG_TYPE_INT}, - {"parity", 'r', 0, "Set the serial port parity", 0, ARG_TYPE_STRING}, - {"stop", 't', 0, "Set the serial port stop bits", 0, ARG_TYPE_INT}, + {"unit", 'u', 0, N_("Set the serial unit"), 0, ARG_TYPE_INT}, + {"port", 'p', 0, N_("Set the serial port address"), 0, ARG_TYPE_STRING}, + {"speed", 's', 0, N_("Set the serial port speed"), 0, ARG_TYPE_INT}, + {"word", 'w', 0, N_("Set the serial port word length"), 0, ARG_TYPE_INT}, + {"parity", 'r', 0, N_("Set the serial port parity"), 0, ARG_TYPE_STRING}, + {"stop", 't', 0, N_("Set the serial port stop bits"), 0, ARG_TYPE_INT}, {0, 0, 0, 0, 0, 0} }; @@ -602,8 +603,8 @@ GRUB_MOD_INIT(serial) { cmd = grub_register_extcmd ("serial", grub_cmd_serial, GRUB_COMMAND_FLAG_BOTH, - "serial [OPTIONS...]", - "Configure serial port.", options); + N_("serial [OPTIONS...]"), + N_("Configure serial port."), options); /* Set default settings. */ serial_settings.port = serial_hw_get_port (0); From 29c44ad156207a17b8825e7dbc7b192ba3e571c7 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 19:50:51 +0100 Subject: [PATCH 088/164] 2010-01-03 Carles Pina i Estany * commands/acpi.c (GRUB_MOD_INIT): Capitalise some words from help. * commands/efi/loadbios.c (GRUB_MOD_INIT): Capitalise BIOS. * commands/i386/pc/drivemap.c (GRUB_MOD_INIT): Remove space. Add full stop. * commands/loadenv.c (GRUB_MOD_INIT): Remove command name from summary. Gettextizze the strings. * commands/probe.c (grub_cmd_probe): Capitalise UUID and FS. * commands/xnu_uuid.c (GRUB_MOD_INIT): Capitalise XNU. * disk/loopback.c (grub_arg_options): Capitalise first letter. Add full stop. (GRUB_MOD_INIT): Remove command name from summary. * hello/hello.c (GRUD_MOT_INIT): Add missing full stop. Improve the summary. * loader/i386/bsd.c (grub_arg_option): Capitalise CDROM. * term/i386/pc/serial.c (options): Add full stops. (GRUB_MOD_INIT): Remove command name from the summary. --- ChangeLog | 19 +++++++++++++++++++ commands/acpi.c | 8 ++++---- commands/efi/loadbios.c | 4 ++-- commands/i386/pc/drivemap.c | 2 +- commands/loadenv.c | 12 ++++++------ commands/xnu_uuid.c | 2 +- disk/loopback.c | 6 +++--- hello/hello.c | 2 +- loader/i386/bsd.c | 2 +- term/i386/pc/serial.c | 14 +++++++------- 10 files changed, 45 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7da0c929e..d90116d4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-01-03 Carles Pina i Estany + + * commands/acpi.c (GRUB_MOD_INIT): Capitalise some words from help. + * commands/efi/loadbios.c (GRUB_MOD_INIT): Capitalise BIOS. + * commands/i386/pc/drivemap.c (GRUB_MOD_INIT): Remove space. Add + full stop. + * commands/loadenv.c (GRUB_MOD_INIT): Remove command name from + summary. Gettextizze the strings. + * commands/probe.c (grub_cmd_probe): Capitalise UUID and FS. + * commands/xnu_uuid.c (GRUB_MOD_INIT): Capitalise XNU. + * disk/loopback.c (grub_arg_options): Capitalise first letter. Add + full stop. + (GRUB_MOD_INIT): Remove command name from summary. + * hello/hello.c (GRUD_MOT_INIT): Add missing full stop. Improve the + summary. + * loader/i386/bsd.c (grub_arg_option): Capitalise CDROM. + * term/i386/pc/serial.c (options): Add full stops. + (GRUB_MOD_INIT): Remove command name from the summary. + 2010-01-03 Carles Pina i Estany * commands/acpi.c: Gettextizze help strings and/or options. Include diff --git a/commands/acpi.c b/commands/acpi.c index 4d54539fd..f62592115 100644 --- a/commands/acpi.c +++ b/commands/acpi.c @@ -760,10 +760,10 @@ GRUB_MOD_INIT(acpi) { cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, GRUB_COMMAND_FLAG_BOTH, - N_("[-1|-2] [--exclude=table1,table2|" - "--load-only=table1,table2] filename1 " - " [filename2] [...]"), - N_("Load host acpi tables and tables " + N_("[-1|-2] [--exclude=TABLE1,TABLE2|" + "--load-only=table1,table2] FILE1" + " [FILE2] [...]"), + N_("Load host ACPI tables and tables " "specified by arguments."), options); } diff --git a/commands/efi/loadbios.c b/commands/efi/loadbios.c index 0f0d7bc10..653327d6c 100644 --- a/commands/efi/loadbios.c +++ b/commands/efi/loadbios.c @@ -202,11 +202,11 @@ static grub_command_t cmd_fakebios, cmd_loadbios; GRUB_MOD_INIT(loadbios) { cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios, - 0, N_("Fake bios.")); + 0, N_("Fake BIOS.")); cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios, "BIOS_DUMP [INT10_DUMP]", - N_("Load bios dump.")); + N_("Load BIOS dump.")); } GRUB_MOD_FINI(loadbios) diff --git a/commands/i386/pc/drivemap.c b/commands/i386/pc/drivemap.c index 3d1dcf614..3baacba49 100644 --- a/commands/i386/pc/drivemap.c +++ b/commands/i386/pc/drivemap.c @@ -404,7 +404,7 @@ GRUB_MOD_INIT (drivemap) cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap, GRUB_COMMAND_FLAG_BOTH, "drivemap" - N_(" -l | -r | [-s] grubdev osdisk"), + N_("-l | -r | [-s] grubdev osdisk."), N_("Manage the BIOS drive mappings."), options); drivemap_hook = diff --git a/commands/loadenv.c b/commands/loadenv.c index 6f8714411..910392614 100644 --- a/commands/loadenv.c +++ b/commands/loadenv.c @@ -385,20 +385,20 @@ GRUB_MOD_INIT(loadenv) cmd_load = grub_register_extcmd ("load_env", grub_cmd_load_env, GRUB_COMMAND_FLAG_BOTH, - "load_env [-f FILE]", - "Load variables from environment block file.", + N_("[-f FILE]"), + N_("Load variables from environment block file."), options); cmd_list = grub_register_extcmd ("list_env", grub_cmd_list_env, GRUB_COMMAND_FLAG_BOTH, - "list_env [-f FILE]", - "List variables from environment block file.", + N_("[-f FILE]"), + N_("List variables from environment block file."), options); cmd_save = grub_register_extcmd ("save_env", grub_cmd_save_env, GRUB_COMMAND_FLAG_BOTH, - "[-f FILE] variable_name [...]", - "Save variables to environment block file.", + N_("[-f FILE] variable_name [...]"), + N_("Save variables to environment block file."), options); } diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index 32288636b..b94dc0dc7 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -380,7 +380,7 @@ GRUB_MOD_INIT (xnu_uuid) cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid, N_("GRUBUUID [VARNAME]"), N_("Transform 64-bit UUID to format " - "suitable for xnu.")); + "suitable for XNU.")); } GRUB_MOD_FINI (xnu_uuid) diff --git a/disk/loopback.c b/disk/loopback.c index fbec0426f..a8b7cf5d7 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -37,8 +37,8 @@ static struct grub_loopback *loopback_list; static const struct grub_arg_option options[] = { - {"delete", 'd', 0, N_("delete the loopback device entry"), 0, 0}, - {"partitions", 'p', 0, N_("simulate a hard drive with partitions"), 0, 0}, + {"delete", 'd', 0, N_("Delete the loopback device entry."), 0, 0}, + {"partitions", 'p', 0, N_("Simulate a hard drive with partitions."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -246,7 +246,7 @@ GRUB_MOD_INIT(loop) { cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, GRUB_COMMAND_FLAG_BOTH, - N_("loopback [-d|-p] DEVICENAME FILE"), + N_("[-d|-p] DEVICENAME FILE."), N_("Make a device of a file."), options); grub_disk_dev_register (&grub_loopback_dev); } diff --git a/hello/hello.c b/hello/hello.c index 1e2a4ba7f..eff07d941 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -40,7 +40,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(hello) { cmd = grub_register_extcmd ("hello", grub_cmd_hello, GRUB_COMMAND_FLAG_BOTH, - "hello", N_("Say hello"), 0); + 0, N_("Say \"Hello World\"."), 0); } GRUB_MOD_FINI(hello) diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index a7a860bb2..d0f0c464b 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -65,7 +65,7 @@ static const struct grub_arg_option freebsd_opts[] = {"dual", 'D', 0, N_("Display output on all consoles."), 0, 0}, {"serial", 'h', 0, N_("Use serial console."), 0, 0}, {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0}, - {"cdrom", 'C', 0, N_("Use cdrom as root."), 0, 0}, + {"cdrom", 'C', 0, N_("Use CDROM as root."), 0, 0}, {"config", 'c', 0, N_("Invoke user configuration routing."), 0, 0}, {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0}, {"gdb", 'g', 0, N_("Use GDB remote debugger instead of DDB."), 0, 0}, diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index e4e3c2755..0f4749eae 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -42,12 +42,12 @@ static unsigned int npending = 0; /* Argument options. */ static const struct grub_arg_option options[] = { - {"unit", 'u', 0, N_("Set the serial unit"), 0, ARG_TYPE_INT}, - {"port", 'p', 0, N_("Set the serial port address"), 0, ARG_TYPE_STRING}, - {"speed", 's', 0, N_("Set the serial port speed"), 0, ARG_TYPE_INT}, - {"word", 'w', 0, N_("Set the serial port word length"), 0, ARG_TYPE_INT}, - {"parity", 'r', 0, N_("Set the serial port parity"), 0, ARG_TYPE_STRING}, - {"stop", 't', 0, N_("Set the serial port stop bits"), 0, ARG_TYPE_INT}, + {"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT}, + {"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING}, + {"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT}, + {"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT}, + {"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING}, + {"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT}, {0, 0, 0, 0, 0, 0} }; @@ -603,7 +603,7 @@ GRUB_MOD_INIT(serial) { cmd = grub_register_extcmd ("serial", grub_cmd_serial, GRUB_COMMAND_FLAG_BOTH, - N_("serial [OPTIONS...]"), + N_("[OPTIONS...]"), N_("Configure serial port."), options); /* Set default settings. */ From f936862eda35bf430e9d1c135fdbc37cb1a2c358 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 20:41:26 +0100 Subject: [PATCH 089/164] 2010-01-03 Carles Pina i Estany * po/POTFILES: Sort correctly. --- ChangeLog | 4 ++++ po/POTFILES | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d90116d4d..6cdfd57d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-03 Carles Pina i Estany + + * po/POTFILES: Sort correctly. + 2010-01-03 Carles Pina i Estany * commands/acpi.c (GRUB_MOD_INIT): Capitalise some words from help. diff --git a/po/POTFILES b/po/POTFILES index 4e7e032ec..cecf8a049 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -53,7 +53,13 @@ lib/arg.c loader/i386/bsd.c +normal/auth.c +normal/color.c normal/dyncmd.c +normal/main.c +normal/menu_entry.c +normal/menu_text.c +normal/misc.c term/i386/pc/serial.c @@ -68,10 +74,3 @@ util/mkisofs/multi.c util/mkisofs/rock.c util/mkisofs/tree.c util/mkisofs/write.c - -normal/auth.c -normal/color.c -normal/main.c -normal/menu_entry.c -normal/menu_text.c -normal/misc.c From 136d24f6433f82ec261654c6a395107268087614 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 21:08:51 +0100 Subject: [PATCH 090/164] 2010-01-03 Carles Pina i Estany * kern/env.c (grub_env_unset): Set the variable to "" if has hooks. --- ChangeLog | 4 ++++ kern/env.c | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6cdfd57d7..4b5080ebf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-03 Carles Pina i Estany + + * kern/env.c (grub_env_unset): Set the variable to "" if has hooks. + 2010-01-03 Carles Pina i Estany * po/POTFILES: Sort correctly. diff --git a/kern/env.c b/kern/env.c index 969227dec..8f94e891e 100644 --- a/kern/env.c +++ b/kern/env.c @@ -264,10 +264,11 @@ grub_env_unset (const char *name) if (! var) return; - /* XXX: It is not possible to unset variables with a read or write - hook. */ if (var->read_hook || var->write_hook) - return; + { + grub_env_set (name, ""); + return; + } grub_env_remove (var); From 7fa7ff743964bdcf0c12743835382fbe2cbb66f0 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 21:30:04 +0100 Subject: [PATCH 091/164] 2010-01-03 Carles Pina i Estany * normal/menu_entry.c (store_completion): Gettextizze. --- ChangeLog | 4 ++++ normal/menu_entry.c | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b5080ebf..ce81611c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-03 Carles Pina i Estany + + * normal/menu_entry.c (store_completion): Gettextizze. + 2010-01-03 Carles Pina i Estany * kern/env.c (grub_env_unset): Set the variable to "" if has hooks. diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 7a31c27af..bd97d17d7 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -816,28 +816,28 @@ store_completion (const char *item, grub_completion_type_t type, int count) switch (type) { case GRUB_COMPLETION_TYPE_COMMAND: - what = "commands"; + what = N_("commands"); break; case GRUB_COMPLETION_TYPE_DEVICE: - what = "devices"; + what = N_("devices"); break; case GRUB_COMPLETION_TYPE_FILE: - what = "files"; + what = N_("files"); break; case GRUB_COMPLETION_TYPE_PARTITION: - what = "partitions"; + what = N_("partitions"); break; case GRUB_COMPLETION_TYPE_ARGUMENT: - what = "arguments"; + what = N_("arguments"); break; default: - what = "things"; + what = N_("things"); break; } grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); grub_printf (" "); - grub_printf_ (N_("Possible %s are:"), what); + grub_printf_ (N_("Possible %s are:"), _(what)); grub_printf ("\n "); } From a173283f78235489c0004c35ba1e1790cc6c4fc5 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 3 Jan 2010 21:48:09 +0100 Subject: [PATCH 092/164] 2010-01-03 Carles Pina i Estany * normal/menu_text.c (print_message): Change messages. --- ChangeLog | 4 ++++ normal/menu_text.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce81611c9..916e2bc1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-03 Carles Pina i Estany + + * normal/menu_text.c (print_message): Change messages. + 2010-01-03 Carles Pina i Estany * normal/menu_entry.c (store_completion): Gettextizze. diff --git a/normal/menu_text.c b/normal/menu_text.c index 5c985fa6f..8ab67a35c 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -214,8 +214,8 @@ entry is highlighted.\n"); grub_free (msg_translated); - grub_print_message_indented (_("Press enter to boot the selected OS, \ -\'e\' to edit the commands before booting or \'c\' for a command-line.\n"), STANDARD_MARGIN, STANDARD_MARGIN); + grub_print_message_indented (_("Press enter to execute the selected \ +entry, \'e\' to edit the commands before booting or \'c\' for a command-line.\n"), STANDARD_MARGIN, STANDARD_MARGIN); if (nested) { @@ -385,7 +385,7 @@ static void print_timeout (int timeout, int offset) { const char *msg = - _("The highlighted entry will be booted automatically in %ds."); + _("The highlighted entry will be executed automatically in %ds."); grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); From e2d70b5cea62f2b4c57a2fb8e1885d9b7569f741 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 3 Jan 2010 21:50:53 +0000 Subject: [PATCH 093/164] 2010-01-03 Colin Watson * include/grub/misc.h (GNUC_PREREQ): New macro. (ATTRIBUTE_ERROR): New macro. * include/grub/list.h (grub_bad_type_cast_real): Use ATTRIBUTE_ERROR. --- ChangeLog | 7 +++++++ include/grub/list.h | 2 +- include/grub/misc.h | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 916e2bc1e..e5e4f42ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-03 Colin Watson + + * include/grub/misc.h (GNUC_PREREQ): New macro. + (ATTRIBUTE_ERROR): New macro. + * include/grub/list.h (grub_bad_type_cast_real): Use + ATTRIBUTE_ERROR. + 2010-01-03 Carles Pina i Estany * normal/menu_text.c (print_message): Change messages. diff --git a/include/grub/list.h b/include/grub/list.h index 86a5381cd..b7703e214 100644 --- a/include/grub/list.h +++ b/include/grub/list.h @@ -42,7 +42,7 @@ void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item, static inline void * grub_bad_type_cast_real (int line, const char *file) - __attribute__ ((error ("bad type cast between incompatible grub types"))); + ATTRIBUTE_ERROR ("bad type cast between incompatible grub types"); static inline void * grub_bad_type_cast_real (int line, const char *file) diff --git a/include/grub/misc.h b/include/grub/misc.h index 92fb460cf..c5eb953e2 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -1,7 +1,7 @@ /* misc.h - prototypes for misc functions */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,22 @@ #include #include +/* GCC version checking borrowed from glibc. */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) +# define GNUC_PREREQ(maj,min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +# define GNUC_PREREQ(maj,min) 0 +#endif + +/* Does this compiler support compile-time error attributes? */ +#if GNUC_PREREQ(4,3) +# define ATTRIBUTE_ERROR(msg) \ + __attribute__ ((__error__ (msg))) +#else +# define ATTRIBUTE_ERROR(msg) +#endif + #define ALIGN_UP(addr, align) \ ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1)) #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) From 58bc8bd5b146cfd5c9be6ed09693fcf73aebf768 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 3 Jan 2010 22:05:07 +0000 Subject: [PATCH 094/164] 2010-01-03 Robert Millan * boot/i386/pc/boot.S: Update copyright year. * boot/i386/pc/cdboot.S: Likewise. * boot/i386/pc/diskboot.S: Likewise. * boot/i386/pc/lnxboot.S: Likewise. * boot/i386/pc/pxeboot.S: Likewise. * bus/pci.c: Likewise. * commands/cmp.c: Likewise. * commands/help.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/play.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/ls.c: Likewise. * commands/test.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/i386/pc/biosdisk.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/lvm.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * fs/affs.c: Likewise. * fs/cpio.c: Likewise. * fs/ext2.c: Likewise. * fs/hfs.c: Likewise. * fs/iso9660.c: Likewise. * fs/ntfs.c: Likewise. * fs/sfs.c: Likewise. * fs/udf.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gencmdlist.sh: Likewise. * genmk.rb: Likewise. * include/grub/disk.h: Likewise. * include/grub/efi/api.h: Likewise. * include/grub/efi/efi.h: Likewise. * include/grub/efi/pe32.h: Likewise. * include/grub/elf.h: Likewise. * include/grub/fs.h: Likewise. * include/grub/i386/at_keyboard.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * include/grub/i386/pc/vbe.h: Likewise. * include/grub/i386/pci.h: Likewise. * include/grub/i386/tsc.h: Likewise. * include/grub/ieee1275/ieee1275.h: Likewise. * include/grub/ntfs.h: Likewise. * include/grub/sparc64/ieee1275/ieee1275.h: Likewise. * include/grub/sparc64/libgcc.h: Likewise. * include/grub/symbol.h: Likewise. * include/grub/types.h: Likewise. * include/multiboot2.h: Likewise. * io/gzio.c: Likewise. * kern/device.c: Likewise. * kern/disk.c: Likewise. * kern/efi/efi.c: Likewise. * kern/efi/mm.c: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/i386/dl.c: Likewise. * kern/i386/pc/init.c: Likewise. * kern/i386/pc/startup.S: Likewise. * kern/ieee1275/ieee1275.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/main.c: Likewise. * kern/mm.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * kern/x86_64/dl.c: Likewise. * lib/hexdump.c: Likewise. * loader/efi/appleloader.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * normal/completion.c: Likewise. * normal/menu_entry.c: Likewise. * partmap/apple.c: Likewise. * util/grub.d/10_hurd.in: Likewise. * util/hostfs.c: Likewise. * video/readers/png.c: Likewise. --- ChangeLog | 88 ++++++++++++++++++++++++ boot/i386/pc/boot.S | 2 +- boot/i386/pc/cdboot.S | 2 +- boot/i386/pc/diskboot.S | 2 +- boot/i386/pc/lnxboot.S | 2 +- boot/i386/pc/pxeboot.S | 2 +- bus/pci.c | 2 +- commands/cmp.c | 2 +- commands/help.c | 2 +- commands/hexdump.c | 2 +- commands/i386/pc/halt.c | 2 +- commands/i386/pc/play.c | 2 +- commands/i386/pc/vbeinfo.c | 2 +- commands/ls.c | 2 +- commands/test.c | 2 +- disk/dmraid_nvidia.c | 2 +- disk/i386/pc/biosdisk.c | 2 +- disk/ieee1275/nand.c | 2 +- disk/ieee1275/ofdisk.c | 2 +- disk/lvm.c | 2 +- disk/raid.c | 2 +- disk/raid6_recover.c | 2 +- disk/scsi.c | 2 +- fs/affs.c | 2 +- fs/cpio.c | 2 +- fs/ext2.c | 2 +- fs/hfs.c | 2 +- fs/iso9660.c | 2 +- fs/ntfs.c | 2 +- fs/sfs.c | 2 +- fs/udf.c | 2 +- fs/ufs.c | 2 +- fs/xfs.c | 2 +- gencmdlist.sh | 2 +- genmk.rb | 2 +- include/grub/disk.h | 2 +- include/grub/efi/api.h | 2 +- include/grub/efi/efi.h | 2 +- include/grub/efi/pe32.h | 2 +- include/grub/elf.h | 2 +- include/grub/fs.h | 2 +- include/grub/i386/at_keyboard.h | 2 +- include/grub/i386/pc/memory.h | 2 +- include/grub/i386/pc/vbe.h | 2 +- include/grub/i386/pci.h | 2 +- include/grub/i386/tsc.h | 2 +- include/grub/ieee1275/ieee1275.h | 2 +- include/grub/ntfs.h | 2 +- include/grub/sparc64/ieee1275/ieee1275.h | 2 +- include/grub/sparc64/libgcc.h | 2 +- include/grub/symbol.h | 2 +- include/grub/types.h | 2 +- include/multiboot2.h | 2 +- io/gzio.c | 2 +- kern/device.c | 2 +- kern/disk.c | 2 +- kern/efi/efi.c | 2 +- kern/efi/mm.c | 2 +- kern/elf.c | 2 +- kern/file.c | 2 +- kern/i386/dl.c | 2 +- kern/i386/pc/init.c | 2 +- kern/i386/pc/startup.S | 2 +- kern/ieee1275/ieee1275.c | 2 +- kern/ieee1275/init.c | 2 +- kern/main.c | 2 +- kern/mm.c | 2 +- kern/powerpc/dl.c | 2 +- kern/sparc64/dl.c | 2 +- kern/x86_64/dl.c | 2 +- lib/hexdump.c | 2 +- loader/efi/appleloader.c | 2 +- loader/i386/ieee1275/linux.c | 2 +- loader/i386/pc/chainloader.c | 2 +- loader/i386/pc/linux.c | 2 +- loader/i386/pc/multiboot2.c | 2 +- loader/ieee1275/multiboot2.c | 2 +- loader/multiboot2.c | 2 +- loader/multiboot_loader.c | 2 +- loader/powerpc/ieee1275/linux.c | 2 +- normal/completion.c | 2 +- normal/menu_entry.c | 2 +- partmap/apple.c | 2 +- util/grub.d/10_hurd.in | 2 +- util/hostfs.c | 2 +- video/readers/png.c | 2 +- 86 files changed, 173 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5e4f42ca..db63c66f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,91 @@ +2010-01-03 Robert Millan + + * boot/i386/pc/boot.S: Update copyright year. + * boot/i386/pc/cdboot.S: Likewise. + * boot/i386/pc/diskboot.S: Likewise. + * boot/i386/pc/lnxboot.S: Likewise. + * boot/i386/pc/pxeboot.S: Likewise. + * bus/pci.c: Likewise. + * commands/cmp.c: Likewise. + * commands/help.c: Likewise. + * commands/hexdump.c: Likewise. + * commands/i386/pc/halt.c: Likewise. + * commands/i386/pc/play.c: Likewise. + * commands/i386/pc/vbeinfo.c: Likewise. + * commands/ls.c: Likewise. + * commands/test.c: Likewise. + * disk/dmraid_nvidia.c: Likewise. + * disk/i386/pc/biosdisk.c: Likewise. + * disk/ieee1275/nand.c: Likewise. + * disk/ieee1275/ofdisk.c: Likewise. + * disk/lvm.c: Likewise. + * disk/raid.c: Likewise. + * disk/raid6_recover.c: Likewise. + * disk/scsi.c: Likewise. + * fs/affs.c: Likewise. + * fs/cpio.c: Likewise. + * fs/ext2.c: Likewise. + * fs/hfs.c: Likewise. + * fs/iso9660.c: Likewise. + * fs/ntfs.c: Likewise. + * fs/sfs.c: Likewise. + * fs/udf.c: Likewise. + * fs/ufs.c: Likewise. + * fs/xfs.c: Likewise. + * gencmdlist.sh: Likewise. + * genmk.rb: Likewise. + * include/grub/disk.h: Likewise. + * include/grub/efi/api.h: Likewise. + * include/grub/efi/efi.h: Likewise. + * include/grub/efi/pe32.h: Likewise. + * include/grub/elf.h: Likewise. + * include/grub/fs.h: Likewise. + * include/grub/i386/at_keyboard.h: Likewise. + * include/grub/i386/pc/memory.h: Likewise. + * include/grub/i386/pc/vbe.h: Likewise. + * include/grub/i386/pci.h: Likewise. + * include/grub/i386/tsc.h: Likewise. + * include/grub/ieee1275/ieee1275.h: Likewise. + * include/grub/ntfs.h: Likewise. + * include/grub/sparc64/ieee1275/ieee1275.h: Likewise. + * include/grub/sparc64/libgcc.h: Likewise. + * include/grub/symbol.h: Likewise. + * include/grub/types.h: Likewise. + * include/multiboot2.h: Likewise. + * io/gzio.c: Likewise. + * kern/device.c: Likewise. + * kern/disk.c: Likewise. + * kern/efi/efi.c: Likewise. + * kern/efi/mm.c: Likewise. + * kern/elf.c: Likewise. + * kern/file.c: Likewise. + * kern/i386/dl.c: Likewise. + * kern/i386/pc/init.c: Likewise. + * kern/i386/pc/startup.S: Likewise. + * kern/ieee1275/ieee1275.c: Likewise. + * kern/ieee1275/init.c: Likewise. + * kern/main.c: Likewise. + * kern/mm.c: Likewise. + * kern/powerpc/dl.c: Likewise. + * kern/sparc64/dl.c: Likewise. + * kern/x86_64/dl.c: Likewise. + * lib/hexdump.c: Likewise. + * loader/efi/appleloader.c: Likewise. + * loader/i386/ieee1275/linux.c: Likewise. + * loader/i386/pc/chainloader.c: Likewise. + * loader/i386/pc/linux.c: Likewise. + * loader/i386/pc/multiboot2.c: Likewise. + * loader/ieee1275/multiboot2.c: Likewise. + * loader/multiboot2.c: Likewise. + * loader/multiboot_loader.c: Likewise. + * loader/powerpc/ieee1275/linux.c: Likewise. + * normal/completion.c: Likewise. + * normal/menu_entry.c: Likewise. + * partmap/apple.c: Likewise. + * util/grub.d/10_hurd.in: Likewise. + * util/hostfs.c: Likewise. + * video/readers/png.c: Likewise. + 2010-01-03 Colin Watson * include/grub/misc.h (GNUC_PREREQ): New macro. diff --git a/boot/i386/pc/boot.S b/boot/i386/pc/boot.S index 865326ee2..257f9044e 100644 --- a/boot/i386/pc/boot.S +++ b/boot/i386/pc/boot.S @@ -1,7 +1,7 @@ /* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/boot/i386/pc/cdboot.S b/boot/i386/pc/cdboot.S index ccc9d64de..33569ce9d 100644 --- a/boot/i386/pc/cdboot.S +++ b/boot/i386/pc/cdboot.S @@ -1,7 +1,7 @@ /* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/boot/i386/pc/diskboot.S b/boot/i386/pc/diskboot.S index e5e4a4ef3..6b621190d 100644 --- a/boot/i386/pc/diskboot.S +++ b/boot/i386/pc/diskboot.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/boot/i386/pc/lnxboot.S b/boot/i386/pc/lnxboot.S index 43d170c6e..b4f0030b8 100644 --- a/boot/i386/pc/lnxboot.S +++ b/boot/i386/pc/lnxboot.S @@ -1,7 +1,7 @@ /* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/boot/i386/pc/pxeboot.S b/boot/i386/pc/pxeboot.S index 2fc53bc81..28c90e29b 100644 --- a/boot/i386/pc/pxeboot.S +++ b/boot/i386/pc/pxeboot.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2000,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/bus/pci.c b/bus/pci.c index fe4cad181..65d848a18 100644 --- a/bus/pci.c +++ b/bus/pci.c @@ -1,7 +1,7 @@ /* pci.c - Generic PCI interfaces. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/cmp.c b/commands/cmp.c index 8fd939640..626e1d022 100644 --- a/commands/cmp.c +++ b/commands/cmp.c @@ -1,7 +1,7 @@ /* cmd.c - command to cmp an operating system */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2005,2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/help.c b/commands/help.c index 8ca2a5b1f..7edc23563 100644 --- a/commands/help.c +++ b/commands/help.c @@ -1,7 +1,7 @@ /* help.c - command to show a help text. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/hexdump.c b/commands/hexdump.c index 5bdbb1f76..c1d4ecba9 100644 --- a/commands/hexdump.c +++ b/commands/hexdump.c @@ -1,7 +1,7 @@ /* hexdump.c - command to dump the contents of a file or memory */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/i386/pc/halt.c b/commands/i386/pc/halt.c index 73c3a2e11..4c39612ae 100644 --- a/commands/i386/pc/halt.c +++ b/commands/i386/pc/halt.c @@ -1,7 +1,7 @@ /* halt.c - command to halt the computer. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 96d9f6df5..1151dddf4 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -1,7 +1,7 @@ /* play.c - command to play a tune */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/i386/pc/vbeinfo.c b/commands/i386/pc/vbeinfo.c index 14f03846e..c266bbfcb 100644 --- a/commands/i386/pc/vbeinfo.c +++ b/commands/i386/pc/vbeinfo.c @@ -1,7 +1,7 @@ /* vbeinfo.c - command to list compatible VBE video modes. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/ls.c b/commands/ls.c index 9afca7907..57409c4f6 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -1,7 +1,7 @@ /* ls.c - command to list files and devices */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/commands/test.c b/commands/test.c index 318a42264..6995165cf 100644 --- a/commands/test.c +++ b/commands/test.c @@ -1,7 +1,7 @@ /* test.c -- The test command.. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/dmraid_nvidia.c b/disk/dmraid_nvidia.c index 46eac6ac5..c4e3922cf 100644 --- a/disk/dmraid_nvidia.c +++ b/disk/dmraid_nvidia.c @@ -1,7 +1,7 @@ /* dmraid_nvidia.c - module to handle Nvidia fakeraid. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index af184b1ba..19ee3f981 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/ieee1275/nand.c b/disk/ieee1275/nand.c index a9ed553cf..df2ee81f3 100644 --- a/disk/ieee1275/nand.c +++ b/disk/ieee1275/nand.c @@ -1,7 +1,7 @@ /* nand.c - NAND flash disk access. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index c2a3a2c3a..c8c4d1a4e 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -1,7 +1,7 @@ /* ofdisk.c - Open Firmware disk access. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2004,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/lvm.c b/disk/lvm.c index 8d0c75a6d..2c54ca3b3 100644 --- a/disk/lvm.c +++ b/disk/lvm.c @@ -1,7 +1,7 @@ /* lvm.c - module to read Logical Volumes. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/raid.c b/disk/raid.c index c48a41d8d..5d2793a07 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -1,7 +1,7 @@ /* raid.c - module to read RAID arrays. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/raid6_recover.c b/disk/raid6_recover.c index ed0e92523..550968ceb 100644 --- a/disk/raid6_recover.c +++ b/disk/raid6_recover.c @@ -1,7 +1,7 @@ /* raid6_recover.c - module to recover from faulty RAID6 arrays. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/scsi.c b/disk/scsi.c index 21b888559..2a5e934f0 100644 --- a/disk/scsi.c +++ b/disk/scsi.c @@ -1,7 +1,7 @@ /* scsi.c - scsi support. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/affs.c b/fs/affs.c index de20fbca1..3dc80752d 100644 --- a/fs/affs.c +++ b/fs/affs.c @@ -1,7 +1,7 @@ /* affs.c - Amiga Fast FileSystem. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/cpio.c b/fs/cpio.c index 852c4dcd8..17c37975d 100644 --- a/fs/cpio.c +++ b/fs/cpio.c @@ -1,7 +1,7 @@ /* cpio.c - cpio and tar filesystem. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * 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 diff --git a/fs/ext2.c b/fs/ext2.c index e7a20a43b..58be3e6fc 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -1,7 +1,7 @@ /* ext2.c - Second Extended filesystem */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/hfs.c b/fs/hfs.c index 4dd1e3131..f7dc2484f 100644 --- a/fs/hfs.c +++ b/fs/hfs.c @@ -1,7 +1,7 @@ /* hfs.c - HFS. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/iso9660.c b/fs/iso9660.c index 2fb0ffb63..0647ca8fc 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -2,7 +2,7 @@ SUSP, Rock Ridge. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/ntfs.c b/fs/ntfs.c index 87db1a561..c1b4b2fe1 100644 --- a/fs/ntfs.c +++ b/fs/ntfs.c @@ -1,7 +1,7 @@ /* ntfs.c - NTFS filesystem */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * 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 diff --git a/fs/sfs.c b/fs/sfs.c index 4f70ad3ec..68f8b3a6e 100644 --- a/fs/sfs.c +++ b/fs/sfs.c @@ -1,7 +1,7 @@ /* sfs.c - Amiga Smart FileSystem. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/udf.c b/fs/udf.c index b44fa8a6d..cecb6eb78 100644 --- a/fs/udf.c +++ b/fs/udf.c @@ -1,7 +1,7 @@ /* udf.c - Universal Disk Format filesystem. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/ufs.c b/fs/ufs.c index f95a6e12e..9f3743d8b 100644 --- a/fs/ufs.c +++ b/fs/ufs.c @@ -1,7 +1,7 @@ /* ufs.c - Unix File System */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/fs/xfs.c b/fs/xfs.c index c15ec7341..8b512de37 100644 --- a/fs/xfs.c +++ b/fs/xfs.c @@ -1,7 +1,7 @@ /* xfs.c - XFS. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/gencmdlist.sh b/gencmdlist.sh index 7f2549099..ed5965f07 100644 --- a/gencmdlist.sh +++ b/gencmdlist.sh @@ -1,6 +1,6 @@ #! /bin/sh # -# Copyright (C) 2005 Free Software Foundation, Inc. +# Copyright (C) 2005,2009 Free Software Foundation, Inc. # # This gensymlist.sh is free software; the author # gives unlimited permission to copy and/or distribute it, diff --git a/genmk.rb b/genmk.rb index b3dbe8678..b1cce3831 100644 --- a/genmk.rb +++ b/genmk.rb @@ -1,6 +1,6 @@ #! /usr/bin/ruby -w # -# Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. +# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. # # This genmk.rb is free software; the author # gives unlimited permission to copy and/or distribute it, diff --git a/include/grub/disk.h b/include/grub/disk.h index de71bb588..6efbfe58a 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 32904150e..4a81207c6 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -1,7 +1,7 @@ /* efi.h - declare EFI types and functions */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index b12205ad3..5852a476f 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -1,7 +1,7 @@ /* efi.h - declare variables and functions for EFI support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index 4fb8d098c..21b56ae27 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/elf.h b/include/grub/elf.h index 1a1ec1310..e54989cde 100644 --- a/include/grub/elf.h +++ b/include/grub/elf.h @@ -1,5 +1,5 @@ /* This file defines standard ELF types, structures, and macros. - Copyright (C) 1995-1999, 2000, 2001, 2002,2008 Free Software Foundation, Inc. + Copyright (C) 1995-1999,2000,2001,2002,2008,2009 Free Software Foundation, Inc. This file was part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/include/grub/fs.h b/include/grub/fs.h index 132ab4755..45f515768 100644 --- a/include/grub/fs.h +++ b/include/grub/fs.h @@ -1,7 +1,7 @@ /* fs.h - filesystem manager */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/i386/at_keyboard.h b/include/grub/i386/at_keyboard.h index 017b58a62..e6ee60d28 100644 --- a/include/grub/i386/at_keyboard.h +++ b/include/grub/i386/at_keyboard.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/i386/pc/memory.h b/include/grub/i386/pc/memory.h index e14cc3e96..841b06164 100644 --- a/include/grub/i386/pc/memory.h +++ b/include/grub/i386/pc/memory.h @@ -1,7 +1,7 @@ /* memory.h - describe the memory map */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index 32427679b..9c4c4dd3d 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/i386/pci.h b/include/grub/i386/pci.h index 5b5f5f0df..31217d5f5 100644 --- a/include/grub/i386/pci.h +++ b/include/grub/i386/pci.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/i386/tsc.h b/include/grub/i386/tsc.h index 46041c2b2..dad9d062d 100644 --- a/include/grub/i386/tsc.h +++ b/include/grub/i386/tsc.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 0e6aae548..8b31e32e2 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -1,7 +1,7 @@ /* ieee1275.h - Access the Open Firmware client interface. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h index 6f9d4ad6e..31b99398b 100644 --- a/include/grub/ntfs.h +++ b/include/grub/ntfs.h @@ -1,7 +1,7 @@ /* ntfs.h - header for the NTFS filesystem */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index 7626e93c1..b25e98a6d 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -1,7 +1,7 @@ /* ieee1275.h - Access the Open Firmware client interface. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/sparc64/libgcc.h b/include/grub/sparc64/libgcc.h index 008821d81..e73abe29c 100644 --- a/include/grub/sparc64/libgcc.h +++ b/include/grub/sparc64/libgcc.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2007 Free Software Foundation, Inc. + * Copyright (C) 2004,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/symbol.h b/include/grub/symbol.h index 6bf512d12..63ed19436 100644 --- a/include/grub/symbol.h +++ b/include/grub/symbol.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/grub/types.h b/include/grub/types.h index 5f6b7ec62..93174b424 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/multiboot2.h b/include/multiboot2.h index e55af8392..275aa5a9b 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -1,7 +1,7 @@ /* multiboot2.h - multiboot 2 header file. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/io/gzio.c b/io/gzio.c index a38bfb372..39f6d7b13 100644 --- a/io/gzio.c +++ b/io/gzio.c @@ -1,7 +1,7 @@ /* gzio.c - decompression support for gzip */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 1999,2005,2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/device.c b/kern/device.c index 9f219949b..f519c63b2 100644 --- a/kern/device.c +++ b/kern/device.c @@ -1,7 +1,7 @@ /* device.c - device manager */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/disk.c b/kern/disk.c index e463626fb..1f10c8731 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/efi/efi.c b/kern/efi/efi.c index 501ab4578..c6ce04c5e 100644 --- a/kern/efi/efi.c +++ b/kern/efi/efi.c @@ -1,7 +1,7 @@ /* efi.c - generic EFI support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/efi/mm.c b/kern/efi/mm.c index e1fca81f3..ceb8fc9ba 100644 --- a/kern/efi/mm.c +++ b/kern/efi/mm.c @@ -1,7 +1,7 @@ /* mm.c - generic EFI memory management */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/elf.c b/kern/elf.c index 10fe9c758..7625f6acd 100644 --- a/kern/elf.c +++ b/kern/elf.c @@ -1,7 +1,7 @@ /* elf.c - load ELF files */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/file.c b/kern/file.c index 4224cf910..e17c35f95 100644 --- a/kern/file.c +++ b/kern/file.c @@ -1,7 +1,7 @@ /* file.c - file I/O functions */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/i386/dl.c b/kern/i386/dl.c index 91121f614..57854964b 100644 --- a/kern/i386/dl.c +++ b/kern/i386/dl.c @@ -1,7 +1,7 @@ /* dl-386.c - arch-dependent part of loadable module support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index ebe4bb6ea..0f2374c6d 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S index 06e26dea3..23f3f398e 100644 --- a/kern/i386/pc/startup.S +++ b/kern/i386/pc/startup.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/ieee1275/ieee1275.c b/kern/ieee1275/ieee1275.c index 37a98071c..8a5773c23 100644 --- a/kern/ieee1275/ieee1275.c +++ b/kern/ieee1275/ieee1275.c @@ -1,7 +1,7 @@ /* of.c - Access the Open Firmware client interface. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index f3305d71c..3e11d2369 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -1,7 +1,7 @@ /* init.c -- Initialize GRUB on the newworld mac (PPC). */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/main.c b/kern/main.c index 9215d55e7..b3b33e93b 100644 --- a/kern/main.c +++ b/kern/main.c @@ -1,7 +1,7 @@ /* main.c - the kernel main routine */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/mm.c b/kern/mm.c index cbcb99560..ef97b018e 100644 --- a/kern/mm.c +++ b/kern/mm.c @@ -1,7 +1,7 @@ /* mm.c - functions for memory manager */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/powerpc/dl.c b/kern/powerpc/dl.c index fa112b16f..ad19e5600 100644 --- a/kern/powerpc/dl.c +++ b/kern/powerpc/dl.c @@ -1,7 +1,7 @@ /* dl.c - arch-dependent part of loadable module support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/sparc64/dl.c b/kern/sparc64/dl.c index 7932b4969..7b6266cac 100644 --- a/kern/sparc64/dl.c +++ b/kern/sparc64/dl.c @@ -1,7 +1,7 @@ /* dl.c - arch-dependent part of loadable module support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/kern/x86_64/dl.c b/kern/x86_64/dl.c index 73a7337e7..090ad78b8 100644 --- a/kern/x86_64/dl.c +++ b/kern/x86_64/dl.c @@ -1,7 +1,7 @@ /* dl-x86_64.c - arch-dependent part of loadable module support */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/lib/hexdump.c b/lib/hexdump.c index c69cb093b..800beb2ba 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -1,7 +1,7 @@ /* hexdump.c - hexdump function */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/efi/appleloader.c b/loader/efi/appleloader.c index a7c2183ab..a64530748 100644 --- a/loader/efi/appleloader.c +++ b/loader/efi/appleloader.c @@ -1,7 +1,7 @@ /* appleloader.c - apple legacy boot loader. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index b577de964..e8a6f1a52 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux zImage or bzImage */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index 27dda4f4f..a153d80a9 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -1,7 +1,7 @@ /* chainloader.c - boot another boot loader */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/i386/pc/linux.c b/loader/i386/pc/linux.c index b93754559..77b7966bf 100644 --- a/loader/i386/pc/linux.c +++ b/loader/i386/pc/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux zImage or bzImage */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/i386/pc/multiboot2.c b/loader/i386/pc/multiboot2.c index 9bfe5d248..005c8a823 100644 --- a/loader/i386/pc/multiboot2.c +++ b/loader/i386/pc/multiboot2.c @@ -1,7 +1,7 @@ /* multiboot2.c - boot a multiboot 2 OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/ieee1275/multiboot2.c b/loader/ieee1275/multiboot2.c index 8c0bc09ec..846550ee5 100644 --- a/loader/ieee1275/multiboot2.c +++ b/loader/ieee1275/multiboot2.c @@ -1,7 +1,7 @@ /* multiboot.c - boot a multiboot 2 OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/multiboot2.c b/loader/multiboot2.c index dbdee9c87..cfc7b400c 100644 --- a/loader/multiboot2.c +++ b/loader/multiboot2.c @@ -1,7 +1,7 @@ /* multiboot2.c - boot a multiboot 2 OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/multiboot_loader.c b/loader/multiboot_loader.c index 24c0c5eac..9e5cf1628 100644 --- a/loader/multiboot_loader.c +++ b/loader/multiboot_loader.c @@ -1,7 +1,7 @@ /* multiboot_loader.c - boot multiboot 1 or 2 OS image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/loader/powerpc/ieee1275/linux.c b/loader/powerpc/ieee1275/linux.c index 7996a22f6..085f5c026 100644 --- a/loader/powerpc/ieee1275/linux.c +++ b/loader/powerpc/ieee1275/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/normal/completion.c b/normal/completion.c index d264028cc..f9d8307e8 100644 --- a/normal/completion.c +++ b/normal/completion.c @@ -1,7 +1,7 @@ /* completion.c - complete a command, a disk, a partition or a file */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/normal/menu_entry.c b/normal/menu_entry.c index bd97d17d7..1b26be1fd 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/partmap/apple.c b/partmap/apple.c index 765912672..7934c90fd 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -1,7 +1,7 @@ /* apple.c - Read macintosh partition tables. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index e693c7dfa..19fd8ec27 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/util/hostfs.c b/util/hostfs.c index 83db2f1a9..df930b42e 100644 --- a/util/hostfs.c +++ b/util/hostfs.c @@ -1,7 +1,7 @@ /* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/video/readers/png.c b/video/readers/png.c index 4e16bf27e..8eec421dd 100644 --- a/video/readers/png.c +++ b/video/readers/png.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From ab0eeb0c33df3b11fb52397b8bd2595275eb2a8b Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 3 Jan 2010 22:15:44 +0000 Subject: [PATCH 095/164] 2010-01-03 Robert Millan * loader/efi/appleloader.c: Remove. Update all users. --- ChangeLog | 4 + conf/i386-efi.rmk | 7 +- conf/x86_64-efi.rmk | 7 +- loader/efi/appleloader.c | 218 --------------------------------------- 4 files changed, 6 insertions(+), 230 deletions(-) delete mode 100644 loader/efi/appleloader.c diff --git a/ChangeLog b/ChangeLog index db63c66f5..51c6a644e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-03 Robert Millan + + * loader/efi/appleloader.c: Remove. Update all users. + 2010-01-03 Robert Millan * boot/i386/pc/boot.S: Update copyright year. diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 3a219e71b..df4768be1 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -30,7 +30,7 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod appleldr.mod \ +pkglib_MODULES = kernel.img chain.mod \ linux.mod halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod @@ -88,11 +88,6 @@ chain_mod_SOURCES = loader/efi/chainloader.c chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For appleldr.mod. -appleldr_mod_SOURCES = loader/efi/appleloader.c -appleldr_mod_CFLAGS = $(COMMON_CFLAGS) -appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For linux.mod. linux_mod_SOURCES = loader/i386/efi/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index a82b35222..c0d3c22c1 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -29,7 +29,7 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod appleldr.mod \ +pkglib_MODULES = kernel.img chain.mod \ halt.mod reboot.mod linux.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod ata.mod @@ -93,11 +93,6 @@ chain_mod_SOURCES = loader/efi/chainloader.c chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For appleldr.mod. -appleldr_mod_SOURCES = loader/efi/appleloader.c -appleldr_mod_CFLAGS = $(COMMON_CFLAGS) -appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For linux.mod. linux_mod_SOURCES = loader/i386/efi/linux.c loader/i386/linux_trampoline.S linux_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/loader/efi/appleloader.c b/loader/efi/appleloader.c deleted file mode 100644 index a64530748..000000000 --- a/loader/efi/appleloader.c +++ /dev/null @@ -1,218 +0,0 @@ -/* appleloader.c - apple legacy boot loader. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static grub_dl_t my_mod; - -static grub_efi_handle_t image_handle; -static grub_efi_char16_t *cmdline; - -static grub_err_t -grub_appleloader_unload (void) -{ - grub_efi_boot_services_t *b; - - b = grub_efi_system_table->boot_services; - efi_call_1 (b->unload_image, image_handle); - - grub_free (cmdline); - cmdline = 0; - - grub_dl_unref (my_mod); - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_appleloader_boot (void) -{ - grub_efi_boot_services_t *b; - - b = grub_efi_system_table->boot_services; - efi_call_3 (b->start_image, image_handle, 0, 0); - - grub_appleloader_unload (); - - return grub_errno; -} - -/* early 2006 Core Duo / Core Solo models */ -static grub_uint8_t devpath_1[] = -{ - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, -}; - -/* mid-2006 Mac Pro (and probably other Core 2 models) */ -static grub_uint8_t devpath_2[] = -{ - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, -}; - -/* mid-2007 MBP ("Santa Rosa" based models) */ -static grub_uint8_t devpath_3[] = -{ - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, -}; - -/* early-2008 MBA */ -static grub_uint8_t devpath_4[] = -{ - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, -}; - -/* late-2008 MB/MBP (NVidia chipset) */ -static grub_uint8_t devpath_5[] = { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x40, 0xCB, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, -}; - -struct devdata -{ - char *model; - grub_efi_device_path_t *devpath; -}; - -struct devdata devs[] = -{ - {"Core Duo/Solo", (grub_efi_device_path_t *) devpath_1}, - {"Mac Pro", (grub_efi_device_path_t *) devpath_2}, - {"MBP", (grub_efi_device_path_t *) devpath_3}, - {"MBA", (grub_efi_device_path_t *) devpath_4}, - {"MB NV", (grub_efi_device_path_t *) devpath_5}, - {NULL, NULL}, -}; - -static grub_err_t -grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) -{ - grub_efi_boot_services_t *b; - grub_efi_loaded_image_t *loaded_image; - struct devdata *pdev; - - grub_dl_ref (my_mod); - - /* Initialize some global variables. */ - image_handle = 0; - - b = grub_efi_system_table->boot_services; - - for (pdev = devs ; pdev->devpath ; pdev++) - if (efi_call_6 (b->load_image, 0, grub_efi_image_handle, pdev->devpath, - NULL, 0, &image_handle) == GRUB_EFI_SUCCESS) - break; - - if (! pdev->devpath) - { - grub_error (GRUB_ERR_BAD_OS, "can't find model"); - goto fail; - } - - grub_printf ("Model : %s\n", pdev->model); - - loaded_image = grub_efi_get_loaded_image (image_handle); - if (! loaded_image) - { - grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); - goto fail; - } - - if (argc > 0) - { - int i, len; - grub_efi_char16_t *p16; - - for (i = 0, len = 0; i < argc; i++) - len += grub_strlen (argv[i]) + 1; - - len *= sizeof (grub_efi_char16_t); - cmdline = p16 = grub_malloc (len); - if (! cmdline) - goto fail; - - for (i = 0; i < argc; i++) - { - char *p8; - - p8 = argv[i]; - while (*p8) - *(p16++) = *(p8++); - - *(p16++) = ' '; - } - *(--p16) = 0; - - loaded_image->load_options = cmdline; - loaded_image->load_options_size = len; - } - - grub_loader_set (grub_appleloader_boot, grub_appleloader_unload, 0); - - return 0; - - fail: - - grub_dl_unref (my_mod); - return grub_errno; -} - -static grub_command_t cmd; - -GRUB_MOD_INIT(appleloader) -{ - cmd = grub_register_command ("appleloader", grub_cmd_appleloader, - "[OPTS]", "Boot legacy system."); - my_mod = mod; -} - -GRUB_MOD_FINI(appleloader) -{ - grub_unregister_command (cmd); -} From 3a73dcb6f5a2a6887752290602a3327c7bab3481 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 3 Jan 2010 22:34:03 +0000 Subject: [PATCH 096/164] 2010-01-03 Robert Millan * boot/i386/pc/diskboot.S: Fix inaccurate comment. * util/i386/pc/grub-setup.c: Include `'. (struct boot_blocklist): Move from here ... * include/grub/i386/pc/boot.h [ASM_FILE] (struct grub_boot_blocklist): ... to here. Update all users. (setup): Only initialize `start' member of `first_block' structure. Add assert() calls to verify the other members. * util/i386/pc/grub-mkimage.c: Include `'. (generate_image): Fix broken blocklist length initialization. Add assert() call to verify blocklist `segment' field. --- ChangeLog | 15 +++++++++++++++ boot/i386/pc/diskboot.S | 4 ++-- include/grub/i386/pc/boot.h | 14 +++++++++++++- util/i386/pc/grub-mkimage.c | 16 ++++++++++++---- util/i386/pc/grub-setup.c | 28 +++++++++++----------------- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51c6a644e..ba26f07d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-01-03 Robert Millan + + * boot/i386/pc/diskboot.S: Fix inaccurate comment. + + * util/i386/pc/grub-setup.c: Include `'. + (struct boot_blocklist): Move from here ... + * include/grub/i386/pc/boot.h [ASM_FILE] + (struct grub_boot_blocklist): ... to here. Update all users. + (setup): Only initialize `start' member of `first_block' + structure. Add assert() calls to verify the other members. + + * util/i386/pc/grub-mkimage.c: Include `'. + (generate_image): Fix broken blocklist length initialization. + Add assert() call to verify blocklist `segment' field. + 2010-01-03 Robert Millan * loader/efi/appleloader.c: Remove. Update all users. diff --git a/boot/i386/pc/diskboot.S b/boot/i386/pc/diskboot.S index 6b621190d..92f223f0d 100644 --- a/boot/i386/pc/diskboot.S +++ b/boot/i386/pc/diskboot.S @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2006,2007,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2006,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -370,7 +370,7 @@ blocklist_default_start: the start of the disk, sector 0 */ .long 2, 0 blocklist_default_len: - /* this is the number of sectors to read the command "install" + /* this is the number of sectors to read. grub-mkimage will fill this up */ .word 0 blocklist_default_seg: diff --git a/include/grub/i386/pc/boot.h b/include/grub/i386/pc/boot.h index f45fe6da0..508b10742 100644 --- a/include/grub/i386/pc/boot.h +++ b/include/grub/i386/pc/boot.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2002,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2002,2005,2006,2007,2008,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,4 +66,16 @@ /* The size of a block list used in the kernel startup code. */ #define GRUB_BOOT_MACHINE_LIST_SIZE 12 +#ifndef ASM_FILE + +/* This is the blocklist used in the diskboot image. */ +struct grub_boot_blocklist +{ + grub_uint64_t start; + grub_uint16_t len; + grub_uint16_t segment; +} __attribute__ ((packed)); + +#endif /* ! ASM_FILE */ + #endif /* ! BOOT_MACHINE_HEADER */ diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index aaa1a13db..ebf1bc7ff 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -33,6 +33,7 @@ #include #include #include +#include #define _GNU_SOURCE 1 #include @@ -212,10 +213,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], boot_img = grub_util_read_image (boot_path); - /* i386 is a little endian architecture. */ - *((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE - - GRUB_BOOT_MACHINE_LIST_SIZE + 8)) - = grub_cpu_to_le16 (num); + { + struct grub_boot_blocklist *block; + block = (struct grub_boot_blocklist *) (boot_img + + GRUB_DISK_SECTOR_SIZE + - sizeof (*block)); + block->len = grub_host_to_target16 (num); + + /* This is filled elsewhere. Verify it just in case. */ + assert (block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG + + (GRUB_DISK_SECTOR_SIZE >> 4))); + } grub_util_write_image (boot_img, boot_size, out); free (boot_img); diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 5a1cbb27a..909a521eb 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -48,6 +48,7 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P #include #include #include +#include #include "progname.h" #define _GNU_SOURCE 1 @@ -56,14 +57,6 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P #define DEFAULT_BOOT_FILE "boot.img" #define DEFAULT_CORE_FILE "core.img" -/* This is the blocklist used in the diskboot image. */ -struct boot_blocklist -{ - grub_uint64_t start; - grub_uint16_t len; - grub_uint16_t segment; -} __attribute__ ((packed)); - void grub_putchar (int c) { @@ -99,7 +92,7 @@ setup (const char *dir, grub_uint8_t *boot_drive; grub_disk_addr_t *kernel_sector; grub_uint16_t *boot_drive_check; - struct boot_blocklist *first_block, *block; + struct grub_boot_blocklist *first_block, *block; grub_int32_t *install_dos_part, *install_bsd_part; grub_int32_t dos_part, bsd_part; char *tmp_img; @@ -171,7 +164,7 @@ setup (const char *dir, void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset, unsigned length) { - struct boot_blocklist *prev = block + 1; + struct grub_boot_blocklist *prev = block + 1; grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x", sector, offset, length, (unsigned) current_segment); @@ -226,9 +219,9 @@ setup (const char *dir, core_img = grub_util_read_image (core_path); /* Have FIRST_BLOCK to point to the first blocklist. */ - first_block = (struct boot_blocklist *) (core_img - + GRUB_DISK_SECTOR_SIZE - - sizeof (*block)); + first_block = (struct grub_boot_blocklist *) (core_img + + GRUB_DISK_SECTOR_SIZE + - sizeof (*block)); install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART); @@ -389,10 +382,11 @@ setup (const char *dir, /* The first blocklist contains the whole sectors. */ first_block->start = grub_cpu_to_le64 (embed_region.start + 1); - first_block->len = grub_cpu_to_le16 (core_sectors - 1); - first_block->segment - = grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG - + (GRUB_DISK_SECTOR_SIZE >> 4)); + + /* These are filled elsewhere. Verify them just in case. */ + assert (first_block->len == grub_host_to_target16 (core_sectors - 1)); + assert (first_block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG + + (GRUB_DISK_SECTOR_SIZE >> 4))); /* Make sure that the second blocklist is a terminator. */ block = first_block - 1; From 98ff6a54de1223845d5a8a297015311256befe5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 4 Jan 2010 14:53:15 +0100 Subject: [PATCH 097/164] 2010-01-04 Vladimir Serbinenko * loader/efi/appleloader.c: Restored. Update all users. --- ChangeLog | 4 + conf/i386-efi.rmk | 7 +- conf/x86_64-efi.rmk | 7 +- loader/efi/appleloader.c | 218 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 loader/efi/appleloader.c diff --git a/ChangeLog b/ChangeLog index ba26f07d7..db0c0d2f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-04 Vladimir Serbinenko + + * loader/efi/appleloader.c: Restored. Update all users. + 2010-01-03 Robert Millan * boot/i386/pc/diskboot.S: Fix inaccurate comment. diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index df4768be1..3a219e71b 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -30,7 +30,7 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod \ +pkglib_MODULES = kernel.img chain.mod appleldr.mod \ linux.mod halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod @@ -88,6 +88,11 @@ chain_mod_SOURCES = loader/efi/chainloader.c chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For appleldr.mod. +appleldr_mod_SOURCES = loader/efi/appleloader.c +appleldr_mod_CFLAGS = $(COMMON_CFLAGS) +appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For linux.mod. linux_mod_SOURCES = loader/i386/efi/linux.c linux_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index c0d3c22c1..a82b35222 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -29,7 +29,7 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod \ +pkglib_MODULES = kernel.img chain.mod appleldr.mod \ halt.mod reboot.mod linux.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod ata.mod @@ -93,6 +93,11 @@ chain_mod_SOURCES = loader/efi/chainloader.c chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For appleldr.mod. +appleldr_mod_SOURCES = loader/efi/appleloader.c +appleldr_mod_CFLAGS = $(COMMON_CFLAGS) +appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For linux.mod. linux_mod_SOURCES = loader/i386/efi/linux.c loader/i386/linux_trampoline.S linux_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/loader/efi/appleloader.c b/loader/efi/appleloader.c new file mode 100644 index 000000000..a64530748 --- /dev/null +++ b/loader/efi/appleloader.c @@ -0,0 +1,218 @@ +/* appleloader.c - apple legacy boot loader. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static grub_dl_t my_mod; + +static grub_efi_handle_t image_handle; +static grub_efi_char16_t *cmdline; + +static grub_err_t +grub_appleloader_unload (void) +{ + grub_efi_boot_services_t *b; + + b = grub_efi_system_table->boot_services; + efi_call_1 (b->unload_image, image_handle); + + grub_free (cmdline); + cmdline = 0; + + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_appleloader_boot (void) +{ + grub_efi_boot_services_t *b; + + b = grub_efi_system_table->boot_services; + efi_call_3 (b->start_image, image_handle, 0, 0); + + grub_appleloader_unload (); + + return grub_errno; +} + +/* early 2006 Core Duo / Core Solo models */ +static grub_uint8_t devpath_1[] = +{ + 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, + 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +}; + +/* mid-2006 Mac Pro (and probably other Core 2 models) */ +static grub_uint8_t devpath_2[] = +{ + 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, + 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +}; + +/* mid-2007 MBP ("Santa Rosa" based models) */ +static grub_uint8_t devpath_3[] = +{ + 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, + 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +}; + +/* early-2008 MBA */ +static grub_uint8_t devpath_4[] = +{ + 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, + 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +}; + +/* late-2008 MB/MBP (NVidia chipset) */ +static grub_uint8_t devpath_5[] = { + 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, + 0x00, 0x40, 0xCB, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, + 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +}; + +struct devdata +{ + char *model; + grub_efi_device_path_t *devpath; +}; + +struct devdata devs[] = +{ + {"Core Duo/Solo", (grub_efi_device_path_t *) devpath_1}, + {"Mac Pro", (grub_efi_device_path_t *) devpath_2}, + {"MBP", (grub_efi_device_path_t *) devpath_3}, + {"MBA", (grub_efi_device_path_t *) devpath_4}, + {"MB NV", (grub_efi_device_path_t *) devpath_5}, + {NULL, NULL}, +}; + +static grub_err_t +grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_efi_boot_services_t *b; + grub_efi_loaded_image_t *loaded_image; + struct devdata *pdev; + + grub_dl_ref (my_mod); + + /* Initialize some global variables. */ + image_handle = 0; + + b = grub_efi_system_table->boot_services; + + for (pdev = devs ; pdev->devpath ; pdev++) + if (efi_call_6 (b->load_image, 0, grub_efi_image_handle, pdev->devpath, + NULL, 0, &image_handle) == GRUB_EFI_SUCCESS) + break; + + if (! pdev->devpath) + { + grub_error (GRUB_ERR_BAD_OS, "can't find model"); + goto fail; + } + + grub_printf ("Model : %s\n", pdev->model); + + loaded_image = grub_efi_get_loaded_image (image_handle); + if (! loaded_image) + { + grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); + goto fail; + } + + if (argc > 0) + { + int i, len; + grub_efi_char16_t *p16; + + for (i = 0, len = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + + len *= sizeof (grub_efi_char16_t); + cmdline = p16 = grub_malloc (len); + if (! cmdline) + goto fail; + + for (i = 0; i < argc; i++) + { + char *p8; + + p8 = argv[i]; + while (*p8) + *(p16++) = *(p8++); + + *(p16++) = ' '; + } + *(--p16) = 0; + + loaded_image->load_options = cmdline; + loaded_image->load_options_size = len; + } + + grub_loader_set (grub_appleloader_boot, grub_appleloader_unload, 0); + + return 0; + + fail: + + grub_dl_unref (my_mod); + return grub_errno; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(appleloader) +{ + cmd = grub_register_command ("appleloader", grub_cmd_appleloader, + "[OPTS]", "Boot legacy system."); + my_mod = mod; +} + +GRUB_MOD_FINI(appleloader) +{ + grub_unregister_command (cmd); +} From 52c2d97f266b37af831db945f9ad2900b7e358bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 4 Jan 2010 14:59:06 +0100 Subject: [PATCH 098/164] 2010-01-04 Vladimir Serbinenko * include/grub/efi/api.h (GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE): New constant. (grub_efi_piwg_device_path): New structure (grub_efi_piwg_device_path_t): New type. * loader/efi/appleloader.c (piwg_full_device_path): New structure. (devpath_1): Transform to a structure. All users updated. (devpath_2): Likewise. (devpath_3): Likewise. (devpath_4): Likewise. (devpath_5): Likewise. --- ChangeLog | 13 +++ include/grub/efi/api.h | 10 ++ loader/efi/appleloader.c | 195 +++++++++++++++++++++++++++++++-------- 3 files changed, 177 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index db0c0d2f2..c71862f78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-01-04 Vladimir Serbinenko + + * include/grub/efi/api.h (GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE): + New constant. + (grub_efi_piwg_device_path): New structure + (grub_efi_piwg_device_path_t): New type. + * loader/efi/appleloader.c (piwg_full_device_path): New structure. + (devpath_1): Transform to a structure. All users updated. + (devpath_2): Likewise. + (devpath_3): Likewise. + (devpath_4): Likewise. + (devpath_5): Likewise. + 2010-01-04 Vladimir Serbinenko * loader/efi/appleloader.c: Restored. Update all users. diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 4a81207c6..36363ae1e 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -584,6 +584,16 @@ struct grub_efi_protocol_device_path }; typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t; +#define GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE 6 + +struct grub_efi_piwg_device_path +{ + grub_efi_device_path_t header; + grub_efi_guid_t guid __attribute__ ((packed)); +}; +typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t; + + /* BIOS Boot Specification Device Path. */ #define GRUB_EFI_BIOS_DEVICE_PATH_TYPE 5 diff --git a/loader/efi/appleloader.c b/loader/efi/appleloader.c index a64530748..114a0a506 100644 --- a/loader/efi/appleloader.c +++ b/loader/efi/appleloader.c @@ -59,58 +59,171 @@ grub_appleloader_boot (void) return grub_errno; } -/* early 2006 Core Duo / Core Solo models */ -static grub_uint8_t devpath_1[] = +struct piwg_full_device_path { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, + struct grub_efi_memory_mapped_device_path comp1; + struct grub_efi_piwg_device_path comp2; + struct grub_efi_device_path end; +}; + +/* early 2006 Core Duo / Core Solo models */ +static struct piwg_full_device_path devpath_1 = +{ + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffe00000, + .end_address = 0xfff9ffff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } }; /* mid-2006 Mac Pro (and probably other Core 2 models) */ -static grub_uint8_t devpath_2[] = +static struct piwg_full_device_path devpath_2 = { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffe00000, + .end_address = 0xfff7ffff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } }; /* mid-2007 MBP ("Santa Rosa" based models) */ -static grub_uint8_t devpath_3[] = +static struct piwg_full_device_path devpath_3 = { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffe00000, + .end_address = 0xfff8ffff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } }; /* early-2008 MBA */ -static grub_uint8_t devpath_4[] = +static struct piwg_full_device_path devpath_4 = { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffc00000, + .end_address = 0xfff8ffff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } }; /* late-2008 MB/MBP (NVidia chipset) */ -static grub_uint8_t devpath_5[] = { - 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00, - 0x00, 0x40, 0xCB, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B, - 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00, +static struct piwg_full_device_path devpath_5 = +{ + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffcb4000, + .end_address = 0xffffbfff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } }; struct devdata @@ -121,11 +234,11 @@ struct devdata struct devdata devs[] = { - {"Core Duo/Solo", (grub_efi_device_path_t *) devpath_1}, - {"Mac Pro", (grub_efi_device_path_t *) devpath_2}, - {"MBP", (grub_efi_device_path_t *) devpath_3}, - {"MBA", (grub_efi_device_path_t *) devpath_4}, - {"MB NV", (grub_efi_device_path_t *) devpath_5}, + {"Core Duo/Solo", (grub_efi_device_path_t *) &devpath_1}, + {"Mac Pro", (grub_efi_device_path_t *) &devpath_2}, + {"MBP", (grub_efi_device_path_t *) &devpath_3}, + {"MBA", (grub_efi_device_path_t *) &devpath_4}, + {"MB NV", (grub_efi_device_path_t *) &devpath_5}, {NULL, NULL}, }; From 732c47f005838e6ea893ee374fd8e11113cd7bc0 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 4 Jan 2010 22:47:30 +0000 Subject: [PATCH 099/164] 2010-01-04 Robert Millan * commands/crc.c (grub_cmd_crc): Abort on read errors. * fs/iso9660.c (grub_iso9660_read): Check for read error and pass it to upper layer. --- commands/crc.c | 7 +++++-- fs/iso9660.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/commands/crc.c b/commands/crc.c index dff9fd55c..1c1a690aa 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -1,7 +1,7 @@ /* crc.c - command to calculate the crc32 checksum of a file */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,10 +46,13 @@ grub_cmd_crc (grub_command_t cmd __attribute__ ((unused)), while ((size = grub_file_read (file, buf, sizeof (buf))) > 0) crc = grub_getcrc32 (crc, buf, size); - grub_file_close (file); + if (grub_errno) + goto fail; grub_printf ("%08x\n", crc); + fail: + grub_file_close (file); return 0; } diff --git a/fs/iso9660.c b/fs/iso9660.c index 0647ca8fc..1ab98be3f 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -2,7 +2,7 @@ SUSP, Rock Ridge. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -773,7 +773,10 @@ grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len) data->first_sector << GRUB_ISO9660_LOG2_BLKSZ, file->offset, len, buf); - data->disk->read_hook = 0; + data->disk->read_hook = NULL; + + if (grub_errno) + return -1; return len; } From 4b856776a991f1b87f36a18653923d030f28ea11 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 4 Jan 2010 22:49:59 +0000 Subject: [PATCH 100/164] forgot to commit ChangeLog... --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index c71862f78..0bcb062fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-04 Robert Millan + + * commands/crc.c (grub_cmd_crc): Abort on read errors. + * fs/iso9660.c (grub_iso9660_read): Check for read error and pass + it to upper layer. + 2010-01-04 Vladimir Serbinenko * include/grub/efi/api.h (GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE): From e33ace066e186e6b3000b9c41dd2d3d574d6bc23 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 4 Jan 2010 23:30:27 +0000 Subject: [PATCH 101/164] 2010-01-04 Robert Millan * disk/i386/pc/biosdisk.c (grub_biosdisk_rw): Use ALIGN_UP macro instead of manual alignment. * kern/disk.c (grub_disk_read): Remove grub_dprintf call (excessively verbose). Avoid attempts to read past end of the device (grub_disk_adjust_range() guarantees that we can read `size' bytes, but GRUB_DISK_CACHE_SIZE may exceed that). --- ChangeLog | 9 +++++++++ disk/i386/pc/biosdisk.c | 4 ++-- kern/disk.c | 9 ++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bcb062fb..df0eaad34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-04 Robert Millan + + * disk/i386/pc/biosdisk.c (grub_biosdisk_rw): Use ALIGN_UP macro + instead of manual alignment. + * kern/disk.c (grub_disk_read): Remove grub_dprintf call (excessively + verbose). Avoid attempts to read past end of the device + (grub_disk_adjust_range() guarantees that we can read `size' bytes, + but GRUB_DISK_CACHE_SIZE may exceed that). + 2010-01-04 Robert Millan * commands/crc.c (grub_cmd_crc): Abort on read errors. diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index 19ee3f981..5f04ecc1e 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -222,7 +222,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk, if (cmd) return grub_error (GRUB_ERR_WRITE_ERROR, "can\'t write to cdrom"); - dap->blocks = (dap->blocks + 3) >> 2; + dap->blocks = ALIGN_UP (dap->blocks, 4) >> 2; dap->block >>= 2; for (i = 0; i < GRUB_BIOSDISK_CDROM_RETRY_COUNT; i++) diff --git a/kern/disk.c b/kern/disk.c index 1f10c8731..544896f2f 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -386,8 +386,6 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, char *tmp_buf; unsigned real_offset; - grub_dprintf ("disk", "Reading `%s'...\n", disk->name); - /* First of all, check if the region is within the disk. */ if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) { @@ -432,8 +430,9 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, else { /* Otherwise read data from the disk actually. */ - if ((disk->dev->read) (disk, start_sector, - GRUB_DISK_CACHE_SIZE, tmp_buf) + if (start_sector + GRUB_DISK_CACHE_SIZE > disk->total_sectors + || (disk->dev->read) (disk, start_sector, + GRUB_DISK_CACHE_SIZE, tmp_buf) != GRUB_ERR_NONE) { /* Uggh... Failed. Instead, just read necessary data. */ From 7c302978579298a8bd0d8950790c3f2ac887b85b Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 5 Jan 2010 00:31:07 +0000 Subject: [PATCH 102/164] 2010-01-05 Robert Millan Remove grub-mkfloppy. Images produced by grub-mkrescue are valid floppy images now. * util/i386/pc/grub-mkfloppy.in: Remove. Update all users. --- ChangeLog | 7 ++ conf/i386-pc.rmk | 3 - util/i386/pc/grub-mkfloppy.in | 116 ---------------------------------- 3 files changed, 7 insertions(+), 119 deletions(-) delete mode 100644 util/i386/pc/grub-mkfloppy.in diff --git a/ChangeLog b/ChangeLog index df0eaad34..d9d327bac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-05 Robert Millan + + Remove grub-mkfloppy. Images produced by grub-mkrescue are valid + floppy images now. + + * util/i386/pc/grub-mkfloppy.in: Remove. Update all users. + 2010-01-04 Robert Millan * disk/i386/pc/biosdisk.c (grub_biosdisk_rw): Use ALIGN_UP macro diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 4ae753776..afdf47e5a 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -115,9 +115,6 @@ grub_install_SOURCES = util/grub-install.in bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in -bin_SCRIPTS += grub-mkfloppy -grub_mkfloppy_SOURCES = util/i386/pc/grub-mkfloppy.in - pkglib_MODULES = biosdisk.mod chain.mod \ multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \ diff --git a/util/i386/pc/grub-mkfloppy.in b/util/i386/pc/grub-mkfloppy.in deleted file mode 100644 index 3b5518690..000000000 --- a/util/i386/pc/grub-mkfloppy.in +++ /dev/null @@ -1,116 +0,0 @@ -#! /bin/sh -e - -# Make GRUB rescue floppy -# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. -# -# GRUB 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, either version 3 of the License, or -# (at your option) any later version. -# -# GRUB 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 GRUB. If not, see . - -# Initialize some variables. -transform="@program_transform_name@" - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -libdir=@libdir@ -PACKAGE_NAME=@PACKAGE_NAME@ -PACKAGE_TARNAME=@PACKAGE_TARNAME@ -PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -platform=@platform@ -pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` - -# Usage: usage -# Print the usage. -usage () { - cat <. -EOF -} - -input_dir=${pkglibdir} - -# Check the arguments. -for option in "$@"; do - case "$option" in - -h | --help) - usage - exit 0 ;; - -v | --version) - echo "$0 (GNU GRUB ${PACKAGE_VERSION})" - exit 0 ;; - --modules=*) - modules=`echo "$option" | sed 's/--modules=//'` ;; - --output=*) - output_image=`echo "$option" | sed 's/--output=//'` ;; - -*) - echo "Unrecognized option \`$option'" 1>&2 - usage - exit 1 - ;; - *) - if test "x$output_image" != x; then - echo "Unrecognized option \`$option'" 1>&2 - usage - exit 1 - fi - output_image="${option}" ;; - esac -done - -if test "x$output_image" = x; then - usage - exit 1 -fi - -aux_dir=`mktemp -d` -mkdir -p ${aux_dir}/boot/grub - -for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \ - ${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \ - ${input_dir}/handler.lst ${input_dir}/parttool.lst; do - if test -f "$file"; then - cp -f "$file" ${aux_dir}/boot/grub/ - fi -done - -modules="$(cat ${input_dir}/partmap.lst) ${modules}" -for i in ${modules} ; do - echo "insmod $i" -done > ${aux_dir}/boot/grub/grub.cfg - -# build memdisk -memdisk_img=`mktemp` -tar -C ${aux_dir} -cf ${memdisk_img} boot -rm -rf ${aux_dir} - -# build core.img -core_img=`mktemp` -grub-mkimage -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar biosdisk -rm -f ${memdisk_img} - -# build floppy image -cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${output_image} -rm -f ${core_img} - -exit 0 From b445cfaa4dadc0ce15d9dddd9764e8db295feffb Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:30:14 +0000 Subject: [PATCH 103/164] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub-mkconfig_lib.in (save_default_entry): Only set saved_entry if boot_once is unset. * util/grub.d/00_header.in: Set boot_once to "true" if there was a previous saved entry (i.e. grub-reboot). --- ChangeLog.savedefault | 8 ++++++++ util/grub-mkconfig_lib.in | 8 ++++++-- util/grub.d/00_header.in | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 7457c3f71..f07bd6beb 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,11 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub-mkconfig_lib.in (save_default_entry): Only set + saved_entry if boot_once is unset. + * util/grub.d/00_header.in: Set boot_once to "true" if there was a + previous saved entry (i.e. grub-reboot). + 2009-12-08 Colin Watson * util/grub.d/30_os-prober.in: Call save_default_entry for hurd. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 95fd02ad9..acfc9f6ea 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -93,8 +93,12 @@ convert_system_path_to_grub_path () save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then - echo 'set saved_entry=${chosen}' - echo 'save_env saved_entry' + cat << EOF +if [ -z \${boot_once} ]; then + set saved_entry=${chosen} + save_env saved_entry +fi +EOF fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 4cd8fd30c..85ce0d4a0 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -48,6 +48,7 @@ if [ \${prev_saved_entry} ]; then save_env saved_entry set prev_saved_entry= save_env prev_saved_entry + set boot_once=true fi EOF From fcab4f04e5e32cd2d3247e25d2c629085fcb23bf Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:39:30 +0000 Subject: [PATCH 104/164] missing backslash --- util/grub-mkconfig_lib.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index acfc9f6ea..72e0e38f9 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -95,7 +95,7 @@ save_default_entry () if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then cat << EOF if [ -z \${boot_once} ]; then - set saved_entry=${chosen} + set saved_entry=\${chosen} save_env saved_entry fi EOF From 5c23bb0f529f6b3d1577dbfa405338e3ec81fbf3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 10:41:51 +0000 Subject: [PATCH 105/164] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub.d/00_header.in: Define a "savedefault" function for use in menu entries. * util/grub-mkconfig_lib.in (save_default_entry): Use it. --- ChangeLog.savedefault | 7 +++++++ util/grub-mkconfig_lib.in | 5 +---- util/grub.d/00_header.in | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index f07bd6beb..90875588e 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,10 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub.d/00_header.in: Define a "savedefault" function for use + in menu entries. + * util/grub-mkconfig_lib.in (save_default_entry): Use it. + 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 72e0e38f9..380ba1a48 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -94,10 +94,7 @@ save_default_entry () { if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then cat << EOF -if [ -z \${boot_once} ]; then - set saved_entry=\${chosen} - save_env saved_entry -fi +savedefault EOF fi } diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 85ce0d4a0..cfb8648ca 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -50,6 +50,13 @@ if [ \${prev_saved_entry} ]; then save_env prev_saved_entry set boot_once=true fi + +function savedefault { + if [ -z \${boot_once} ]; then + saved_entry=\${chosen} + save_env saved_entry + fi +} EOF case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in From cf2fd2a6d1a58ad0c47cf8b968ff695d0073b57a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 11:16:42 +0000 Subject: [PATCH 106/164] 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson * util/grub-reboot.in: Make sure prev_saved_entry always gets a non-empty value. --- ChangeLog.savedefault | 6 ++++++ util/grub-reboot.in | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 90875588e..722769776 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,3 +1,9 @@ +2010-10-05 Jordan Uggla +2010-10-05 Colin Watson + + * util/grub-reboot.in: Make sure prev_saved_entry always gets a + non-empty value. + 2010-10-05 Jordan Uggla 2010-10-05 Colin Watson diff --git a/util/grub-reboot.in b/util/grub-reboot.in index 16abdf6f4..20f2b10bc 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -96,7 +96,11 @@ prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry if [ "$prev_saved_entry" ]; then $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry" else - $grub_editenv ${grubdir}/grubenv unset prev_saved_entry + # We need some non-empty value for prev_saved_entry so that GRUB will + # recognise that grub-reboot has been used and restore the previous + # saved entry. "0" is the same as an empty value, i.e. the first menu + # entry. + $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0 fi $grub_editenv ${grubdir}/grubenv set saved_entry="$entry" From a1368118864dea5cf293eb3e669a75cf6af14773 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 12:40:30 +0000 Subject: [PATCH 107/164] 2010-01-05 Colin Watson * util/mkisofs/write.c (padblock_write): Check return value of fread. --- ChangeLog | 5 +++++ util/mkisofs/write.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d9d327bac..061fadc18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-05 Colin Watson + + * util/mkisofs/write.c (padblock_write): Check return value of + fread. + 2010-01-05 Robert Millan Remove grub-mkfloppy. Images produced by grub-mkrescue are valid diff --git a/util/mkisofs/write.c b/util/mkisofs/write.c index 896e2833b..d9b1fd05d 100644 --- a/util/mkisofs/write.c +++ b/util/mkisofs/write.c @@ -1437,7 +1437,9 @@ static int FDECL1(padblock_write, FILE *, outfile) if (! fp) error (1, errno, _("Unable to open %s"), boot_image_embed); - fread (buffer, 2048 * PADBLOCK_SIZE, 1, fp); + if (fread (buffer, 2048 * PADBLOCK_SIZE, 1, fp) == 0) + error (1, errno, _("cannot read %llu bytes from %s"), + (size_t) (2048 * PADBLOCK_SIZE), boot_image_embed); if (fgetc (fp) != EOF) error (1, 0, _("%s is too big for embed area"), boot_image_embed); } From 3bff18c5c6ebcd62c9e722f7e575cff1cff04e73 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 5 Jan 2010 16:09:02 +0000 Subject: [PATCH 108/164] 2010-01-05 Colin Watson * util/mkisofs/write.c (padblock_write): Switch size and nmemb arguments to fread so that we get a return value in bytes, rather than something that will normally be rounded down to 0. Adjust error handling to avoid producing garbage when size_t is not the same size as long long. --- ChangeLog | 8 ++++++++ util/mkisofs/write.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 061fadc18..bd32107f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-05 Colin Watson + + * util/mkisofs/write.c (padblock_write): Switch size and nmemb + arguments to fread so that we get a return value in bytes, rather + than something that will normally be rounded down to 0. + Adjust error handling to avoid producing garbage when size_t is not + the same size as long long. + 2010-01-05 Colin Watson * util/mkisofs/write.c (padblock_write): Check return value of diff --git a/util/mkisofs/write.c b/util/mkisofs/write.c index d9b1fd05d..5447229c8 100644 --- a/util/mkisofs/write.c +++ b/util/mkisofs/write.c @@ -1437,9 +1437,9 @@ static int FDECL1(padblock_write, FILE *, outfile) if (! fp) error (1, errno, _("Unable to open %s"), boot_image_embed); - if (fread (buffer, 2048 * PADBLOCK_SIZE, 1, fp) == 0) - error (1, errno, _("cannot read %llu bytes from %s"), - (size_t) (2048 * PADBLOCK_SIZE), boot_image_embed); + if (fread (buffer, 1, 2048 * PADBLOCK_SIZE, fp) == 0) + error (1, errno, _("cannot read %d bytes from %s"), + 2048 * PADBLOCK_SIZE, boot_image_embed); if (fgetc (fp) != EOF) error (1, 0, _("%s is too big for embed area"), boot_image_embed); } From 6581dd3a58f9a00fc342385d36bad6e8792de184 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Tue, 5 Jan 2010 18:24:10 +0100 Subject: [PATCH 109/164] 2010-01-05 Yves Blusseau * util/sparc64/ieee1275/grub-mkimage.c (main): Typo fix. --- ChangeLog | 4 ++++ util/sparc64/ieee1275/grub-mkimage.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bd32107f0..019049bb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-05 Yves Blusseau + + * util/sparc64/ieee1275/grub-mkimage.c (main): Typo fix. + 2010-01-05 Colin Watson * util/mkisofs/write.c (padblock_write): Switch size and nmemb diff --git a/util/sparc64/ieee1275/grub-mkimage.c b/util/sparc64/ieee1275/grub-mkimage.c index b79bbeb41..96ddfe3d7 100644 --- a/util/sparc64/ieee1275/grub-mkimage.c +++ b/util/sparc64/ieee1275/grub-mkimage.c @@ -223,7 +223,7 @@ main (int argc, char *argv[]) set_program_name (argv[0]); - grub_util_init_ls (); + grub_util_init_nls (); while (1) { From 465c787b508e940e8ef6c336aaf18b4d3f2e765f Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Tue, 5 Jan 2010 22:04:15 +0100 Subject: [PATCH 110/164] 2010-01-05 Yves Blusseau * commands/acpi.c (grub_acpi_create_ebda): fix incorrect message. --- ChangeLog | 4 ++++ commands/acpi.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 019049bb0..ac66e6050 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-05 Yves Blusseau + + * commands/acpi.c (grub_acpi_create_ebda): fix incorrect message. + 2010-01-05 Yves Blusseau * util/sparc64/ieee1275/grub-mkimage.c (main): Typo fix. diff --git a/commands/acpi.c b/commands/acpi.c index f62592115..5bbfd008b 100644 --- a/commands/acpi.c +++ b/commands/acpi.c @@ -229,7 +229,7 @@ grub_acpi_create_ebda (void) sizeof (struct grub_acpi_rsdp_v10)) == 0) { grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10)); - grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target); + grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target); v1inebda = target; target += sizeof (struct grub_acpi_rsdp_v10); target = (grub_uint8_t *) ((((long) target - 1) | 0xf) + 1); From 83507e68bd6f2246b3d309f1650f3b7c8a171846 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 5 Jan 2010 22:44:00 +0000 Subject: [PATCH 111/164] 2010-01-05 Robert Millan * config.rpath: Update from Gnulib. --- ChangeLog | 4 ++++ config.rpath | 34 ++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac66e6050..01483a3ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-05 Robert Millan + + * config.rpath: Update from Gnulib. + 2010-01-05 Yves Blusseau * commands/acpi.c (grub_acpi_create_ebda): fix incorrect message. diff --git a/config.rpath b/config.rpath index c547c6882..85c2f209b 100755 --- a/config.rpath +++ b/config.rpath @@ -2,7 +2,7 @@ # Output a system dependent set of variables, describing how to set the # run time search path of shared libraries in an executable. # -# Copyright 1996-2007 Free Software Foundation, Inc. +# Copyright 1996-2008 Free Software Foundation, Inc. # Taken from GNU libtool, 2001 # Originally by Gordon Matzigkeit , 1996 # @@ -47,7 +47,7 @@ for cc_temp in $CC""; do done cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` -# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC. +# Code taken from libtool.m4's _LT_COMPILER_PIC. wl= if test "$GCC" = yes; then @@ -64,7 +64,7 @@ else ;; esac ;; - mingw* | cygwin* | pw32* | os2*) + mingw* | cygwin* | pw32* | os2* | cegcc*) ;; hpux9* | hpux10* | hpux11*) wl='-Wl,' @@ -76,7 +76,13 @@ else ;; linux* | k*bsd*-gnu) case $cc_basename in - icc* | ecc*) + ecc*) + wl='-Wl,' + ;; + icc* | ifort*) + wl='-Wl,' + ;; + lf95*) wl='-Wl,' ;; pgcc | pgf77 | pgf90) @@ -124,7 +130,7 @@ else esac fi -# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS. +# Code taken from libtool.m4's _LT_LINKER_SHLIBS. hardcode_libdir_flag_spec= hardcode_libdir_separator= @@ -132,7 +138,7 @@ hardcode_direct=no hardcode_minus_L=no case "$host_os" in - cygwin* | mingw* | pw32*) + cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. @@ -158,7 +164,7 @@ if test "$with_gnu_ld" = yes; then # option of GNU ld is called -rpath, not --rpath. hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' case "$host_os" in - aix3* | aix4* | aix5*) + aix[3-9]*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then ld_shlibs=no @@ -182,7 +188,7 @@ if test "$with_gnu_ld" = yes; then ld_shlibs=no fi ;; - cygwin* | mingw* | pw32*) + cygwin* | mingw* | pw32* | cegcc*) # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' @@ -254,7 +260,7 @@ else hardcode_direct=unsupported fi ;; - aix4* | aix5*) + aix[4-9]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. @@ -264,7 +270,7 @@ else # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. - case $host_os in aix4.[23]|aix4.[23].*|aix5*) + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes @@ -326,7 +332,7 @@ else ;; bsdi[45]*) ;; - cygwin* | mingw* | pw32*) + cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is @@ -494,7 +500,7 @@ else fi # Check dynamic linker characteristics -# Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER. +# Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER. # Unlike libtool.m4, here we don't care about _all_ names of the library, but # only about the one the linker finds when passed -lNAME. This is the last # element of library_names_spec in libtool.m4, or possibly two of them if the @@ -505,7 +511,7 @@ case "$host_os" in aix3*) library_names_spec='$libname.a' ;; - aix4* | aix5*) + aix[4-9]*) library_names_spec='$libname$shrext' ;; amigaos*) @@ -517,7 +523,7 @@ case "$host_os" in bsdi[45]*) library_names_spec='$libname$shrext' ;; - cygwin* | mingw* | pw32*) + cygwin* | mingw* | pw32* | cegcc*) shrext=.dll library_names_spec='$libname.dll.a $libname.lib' ;; From 40e3a41f854559d5faa08b4afe1d6e393442fb05 Mon Sep 17 00:00:00 2001 From: carles Date: Wed, 6 Jan 2010 21:36:34 +0000 Subject: [PATCH 112/164] 2010-01-06 Carles Pina i Estany * commands/search.c (GRUB_MOD_INIT): Use HELP_MESSAGE. * commands/search_file.c (HELP_MESSAGE): New macro. * commands/search_label.c (HELP_MESSAGE): Likewise. * commands/search_uuid.c (HELP_MESSAGE): Likewise. * po/POTFILES: Add `commands/search_file.c', `commands/search_label.c', `commands_uuid.c'. Remove duplicate `commands/search.c'. --- ChangeLog | 10 ++++++++++ commands/search.c | 4 +--- commands/search_file.c | 1 + commands/search_label.c | 1 + commands/search_uuid.c | 1 + po/POTFILES | 4 +++- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01483a3ba..52cb5d401 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-01-06 Carles Pina i Estany + + * commands/search.c (GRUB_MOD_INIT): Use HELP_MESSAGE. + * commands/search_file.c (HELP_MESSAGE): New macro. + * commands/search_label.c (HELP_MESSAGE): Likewise. + * commands/search_uuid.c (HELP_MESSAGE): Likewise. + * po/POTFILES: Add `commands/search_file.c', + `commands/search_label.c', `commands_uuid.c'. Remove duplicate + `commands/search.c'. + 2010-01-05 Robert Millan * config.rpath: Update from Gnulib. diff --git a/commands/search.c b/commands/search.c index 2f0cef8aa..ec736de3c 100644 --- a/commands/search.c +++ b/commands/search.c @@ -166,9 +166,7 @@ GRUB_MOD_INIT(search_fs_label) cmd = grub_register_command (COMMAND_NAME, grub_cmd_do_search, N_("NAME [VARIABLE]"), - "Search devices by " SEARCH_TARGET "." - " If VARIABLE is specified, " - "the first device found is set to a variable."); + HELP_MESSAGE); } #ifdef DO_SEARCH_FILE diff --git a/commands/search_file.c b/commands/search_file.c index 265220001..73ce89ccc 100644 --- a/commands/search_file.c +++ b/commands/search_file.c @@ -2,4 +2,5 @@ #define FUNC_NAME grub_search_fs_file #define COMMAND_NAME "search.file" #define SEARCH_TARGET "file" +#define HELP_MESSAGE N_("Search devices by file. If VARIABLE is specified, the first device found is set to a variable.") #include "search.c" diff --git a/commands/search_label.c b/commands/search_label.c index 0047b0e8c..ee9c792be 100644 --- a/commands/search_label.c +++ b/commands/search_label.c @@ -2,4 +2,5 @@ #define FUNC_NAME grub_search_label #define COMMAND_NAME "search.fs_label" #define SEARCH_TARGET "filesystem label" +#define HELP_MESSAGE N_("Search devices by label. If VARIABLE is specified, the first device found is set to a variable.") #include "search.c" diff --git a/commands/search_uuid.c b/commands/search_uuid.c index 9767d6501..52f83812c 100644 --- a/commands/search_uuid.c +++ b/commands/search_uuid.c @@ -2,4 +2,5 @@ #define FUNC_NAME grub_search_fs_uuid #define COMMAND_NAME "search.fs_uuid" #define SEARCH_TARGET "filesystem UUID" +#define HELP_MESSAGE N_("Search devices by UUID. If VARIABLE is specified, the first device found is set to a variable.") #include "search.c" diff --git a/po/POTFILES b/po/POTFILES index cecf8a049..c4ae9d562 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -37,7 +37,9 @@ commands/probe.c commands/read.c commands/reboot.c commands/search.c -commands/search.c +commands/search_file.c +commands/search_label.c +commands/search_uuid.c commands/sleep.c commands/test.c commands/true.c From e7730de786199ba5ca7c962d018b9af92fd32122 Mon Sep 17 00:00:00 2001 From: carles Date: Wed, 6 Jan 2010 22:00:57 +0000 Subject: [PATCH 113/164] 2010-01-06 Carles Pina i Estany * kern/err.c: Include `'. (grub_print_error): Add full stop. Gettextizze. * loader/i386/bsd.c (grub_netbsd_boot): Change grub_error description. (grub_bsd_load_elf): Capitalise ELF. (grub_cmd_freebsd_loadenv): Add `s' in error string. (grub_cmd_freebsd_module): Likewise. (grub_cmd_freebsd_module_elf): Likewise. * loader/i386/bsdXX.c (SUFFIX): Capitalise ELF. --- ChangeLog | 11 +++++++++++ kern/err.c | 3 ++- loader/i386/bsd.c | 14 +++++++------- loader/i386/bsdXX.c | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52cb5d401..3bd67bfba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-01-06 Carles Pina i Estany + + * kern/err.c: Include `'. + (grub_print_error): Add full stop. Gettextizze. + * loader/i386/bsd.c (grub_netbsd_boot): Change grub_error description. + (grub_bsd_load_elf): Capitalise ELF. + (grub_cmd_freebsd_loadenv): Add `s' in error string. + (grub_cmd_freebsd_module): Likewise. + (grub_cmd_freebsd_module_elf): Likewise. + * loader/i386/bsdXX.c (SUFFIX): Capitalise ELF. + 2010-01-06 Carles Pina i Estany * commands/search.c (GRUB_MOD_INIT): Use HELP_MESSAGE. diff --git a/kern/err.c b/kern/err.c index 311130154..02d7d879f 100644 --- a/kern/err.c +++ b/kern/err.c @@ -20,6 +20,7 @@ #include #include #include +#include #define GRUB_MAX_ERRMSG 256 #define GRUB_ERROR_STACK_SIZE 10 @@ -121,7 +122,7 @@ grub_print_error (void) do { if (grub_errno != GRUB_ERR_NONE) - grub_err_printf ("error: %s\n", grub_errmsg); + grub_err_printf (_("error: %s.\n"), grub_errmsg); } while (grub_error_pop ()); diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index d0f0c464b..0785a3fc1 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -680,7 +680,7 @@ grub_netbsd_boot (void) + sizeof (struct grub_netbsd_btinfo_mmap_header) + count * sizeof (struct grub_netbsd_btinfo_mmap_entry) > grub_os_area_addr + grub_os_area_size) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, "no memory for boot info"); + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory"); curarg = mmap = (struct grub_netbsd_btinfo_mmap_header *) kern_end; pm = (struct grub_netbsd_btinfo_mmap_entry *) (mmap + 1); @@ -888,7 +888,7 @@ grub_bsd_load_elf (grub_elf_t elf) return grub_elf64_load (elf, grub_bsd_elf64_hook, 0, 0); } else - return grub_error (GRUB_ERR_BAD_OS, "invalid elf"); + return grub_error (GRUB_ERR_BAD_OS, "invalid ELF"); } static grub_err_t @@ -1081,7 +1081,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)), if (kernel_type != KERNEL_TYPE_FREEBSD) return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only FreeBSD support environment"); + "only FreeBSD supports environment"); if (argc == 0) { @@ -1175,11 +1175,11 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)), if (kernel_type != KERNEL_TYPE_FREEBSD) return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only FreeBSD support module"); + "only FreeBSD supports module"); if (!is_elf_kernel) return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only ELF kernel support module"); + "only ELF kernel supports module"); /* List the current modules if no parameter. */ if (!argc) @@ -1241,11 +1241,11 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)), if (kernel_type != KERNEL_TYPE_FREEBSD) return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only FreeBSD support module"); + "only FreeBSD supports module"); if (! is_elf_kernel) return grub_error (GRUB_ERR_BAD_ARGUMENT, - "only ELF kernel support module"); + "only ELF kernel supports module"); /* List the current modules if no parameter. */ if (! argc) diff --git a/loader/i386/bsdXX.c b/loader/i386/bsdXX.c index 4c1c035a9..b4d574821 100644 --- a/loader/i386/bsdXX.c +++ b/loader/i386/bsdXX.c @@ -271,7 +271,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (grub_file_t file, grub_addr_t *kern_end) (grub_ssize_t) symsize) { if (! grub_errno) - return grub_error (GRUB_ERR_BAD_OS, "invalid elf"); + return grub_error (GRUB_ERR_BAD_OS, "invalid ELF"); return grub_errno; } curload += symsize; @@ -285,7 +285,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (grub_file_t file, grub_addr_t *kern_end) != (grub_ssize_t) strsize) { if (! grub_errno) - return grub_error (GRUB_ERR_BAD_OS, "invalid elf"); + return grub_error (GRUB_ERR_BAD_OS, "invalid ELF"); return grub_errno; } curload += strsize; From 42841caa75a0ed911cbecee0c04bf340fdab9b56 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jan 2010 23:25:57 +0100 Subject: [PATCH 114/164] 2010-01-06 Vladimir Serbinenko Fix descent and ascent calculation. * util/grub-mkfont.c (grub_font_info): New fields 'asce' and 'max_y'. (options): New option "asce". (usage): Likewise. (add_char): Ignore invalid glyphs for descent calculation. Calculate ascent from actual content. (print_glyphs): Use 'asce'. (write_font): Likewise. Allow ascent override. (main): Handle "asce" option. --- ChangeLog | 13 +++++++++++++ util/grub-mkfont.c | 31 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bd67bfba..59f4e41f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-01-06 Vladimir Serbinenko + + Fix descent and ascent calculation. + + * util/grub-mkfont.c (grub_font_info): New fields 'asce' and 'max_y'. + (options): New option "asce". + (usage): Likewise. + (add_char): Ignore invalid glyphs for descent calculation. + Calculate ascent from actual content. + (print_glyphs): Use 'asce'. + (write_font): Likewise. Allow ascent override. + (main): Handle "asce" option. + 2010-01-06 Carles Pina i Estany * kern/err.c: Include `'. diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index a358ba5b0..3d1c6faac 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -59,10 +59,12 @@ struct grub_font_info char* name; int style; int desc; + int asce; int size; int max_width; int max_height; int min_y; + int max_y; int flags; int num_range; grub_uint32_t *ranges; @@ -77,6 +79,7 @@ static struct option options[] = {"range", required_argument, 0, 'r'}, {"size", required_argument, 0, 's'}, {"desc", required_argument, 0, 'd'}, + {"asce", required_argument, 0, 'c'}, {"bold", no_argument, 0, 'b'}, {"no-bitmap", no_argument, 0, 0x100}, {"no-hinting", no_argument, 0, 0x101}, @@ -104,6 +107,7 @@ Usage: %s [OPTIONS] FONT_FILES\n\ -n, --name=S set font family name\n\ -s, --size=N set font size\n\ -d, --desc=N set font descent\n\ + -c, --asce=N set font ascent\n\ -b, --bold convert to bold font\n\ -a, --force-autohint force autohint\n\ --no-hinting disable hinting\n\ @@ -193,9 +197,12 @@ add_char (struct grub_font_info *font_info, FT_Face face, if (height > font_info->max_height) font_info->max_height = height; - if (glyph_info->y_ofs < font_info->min_y) + if (glyph_info->y_ofs < font_info->min_y && glyph_info->y_ofs > -font_info->size) font_info->min_y = glyph_info->y_ofs; + if (glyph_info->y_ofs + height > font_info->max_y) + font_info->max_y = glyph_info->y_ofs + height; + mask = 0; data = &glyph_info->bitmap[0] - 1; for (j = 0; j < height; j++) @@ -284,8 +291,8 @@ print_glyphs (struct grub_font_info *font_info) xmin = 0; ymax = glyph->y_ofs + glyph->height; - if (ymax < font_info->size - font_info->desc) - ymax = font_info->size - font_info->desc; + if (ymax < font_info->asce) + ymax = font_info->asce; ymin = glyph->y_ofs; if (ymin > - font_info->desc) @@ -316,7 +323,7 @@ print_glyphs (struct grub_font_info *font_info) else if ((x >= 0) && (x < glyph->device_width) && (y >= - font_info->desc) && - (y < font_info->size - font_info->desc)) + (y < font_info->asce)) { line[line_pos++] = ((x == 0) || (y == 0)) ? '+' : '.'; } @@ -392,7 +399,15 @@ write_font (struct grub_font_info *font_info, char *output_file) font_info->desc = - font_info->min_y; } - write_be16_section ("ASCE", font_info->size - font_info->desc, &offset, file); + if (! font_info->asce) + { + if (font_info->max_y <= 0) + font_info->asce = 1; + else + font_info->asce = font_info->max_y; + } + + write_be16_section ("ASCE", font_info->asce, &offset, file); write_be16_section ("DESC", font_info->desc, &offset, file); if (font_verbosity > 0) @@ -400,7 +415,7 @@ write_font (struct grub_font_info *font_info, char *output_file) printf ("Font name: %s\n", font_name); printf ("Max width: %d\n", font_info->max_width); printf ("Max height: %d\n", font_info->max_height); - printf ("Font ascent: %d\n", font_info->size - font_info->desc); + printf ("Font ascent: %d\n", font_info->asce); printf ("Font descent: %d\n", font_info->desc); } @@ -560,6 +575,10 @@ main (int argc, char *argv[]) font_info.desc = strtoul (optarg, NULL, 0); break; + case 'e': + font_info.asce = strtoul (optarg, NULL, 0); + break; + case 'h': usage (0); break; From 5a1ed29ebd132255cd70c14fcd4e1838ac4c6717 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 7 Jan 2010 01:21:32 +0000 Subject: [PATCH 115/164] Simplify terminal check in loader/i386/efi/linux.c and loader/i386/linux.c Revert loader/i386/ieee1275/linux.c change --- loader/i386/efi/linux.c | 15 +++------------ loader/i386/ieee1275/linux.c | 34 ++-------------------------------- loader/i386/linux.c | 13 +++---------- 3 files changed, 8 insertions(+), 54 deletions(-) diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index c6acab641..a1d08b3d7 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -697,7 +697,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_term_output_t term; int found = 0; FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "vga_text") == 0) + if (grub_strcmp (term->name, "vga_text") == 0 + || grub_strcmp (term->name, "console") == 0) { grub_uint16_t pos = grub_term_getxy (term); params->video_cursor_x = pos >> 8; @@ -705,18 +706,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), params->video_width = grub_term_width (term); params->video_height = grub_term_height (term); found = 1; + break; } - if (!found) - FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "console") == 0) - { - grub_uint16_t pos = grub_term_getxy (term); - params->video_cursor_x = pos >> 8; - params->video_cursor_y = pos & 0xff; - params->video_width = grub_term_width (term); - params->video_height = grub_term_height (term); - found = 1; - } if (!found) { params->video_cursor_x = 0; diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index 33076ea5b..e8a6f1a52 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -109,38 +109,8 @@ grub_linux_boot (void) params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET; - { - grub_term_output_t term; - int found = 0; - FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "vga_text") == 0) - { - grub_uint16_t pos = grub_term_getxy (term); - params->video_cursor_x = pos >> 8; - params->video_cursor_y = pos & 0xff; - params->video_width = grub_term_width (term); - params->video_height = grub_term_height (term); - found = 1; - } - if (!found) - FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "console") == 0) - { - grub_uint16_t pos = grub_term_getxy (term); - params->video_cursor_x = pos >> 8; - params->video_cursor_y = pos & 0xff; - params->video_width = grub_term_width (term); - params->video_height = grub_term_height (term); - found = 1; - } - if (!found) - { - params->video_cursor_x = 0; - params->video_cursor_y = 0; - params->video_width = 80; - params->video_height = 25; - } - } + params->video_width = (grub_getwh () >> 8); + params->video_height = (grub_getwh () & 0xff); params->font_size = 16; params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE; diff --git a/loader/i386/linux.c b/loader/i386/linux.c index c1649e9e6..863090025 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -551,21 +551,14 @@ grub_linux_boot (void) grub_term_output_t term; int found = 0; FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "vga_text") == 0) - { - grub_uint16_t pos = grub_term_getxy (term); - params->video_cursor_x = pos >> 8; - params->video_cursor_y = pos & 0xff; - found = 1; - } - if (!found) - FOR_ACTIVE_TERM_OUTPUTS(term) - if (grub_strcmp (term->name, "console") == 0) + if (grub_strcmp (term->name, "vga_text") == 0 + || grub_strcmp (term->name, "console") == 0) { grub_uint16_t pos = grub_term_getxy (term); params->video_cursor_x = pos >> 8; params->video_cursor_y = pos & 0xff; found = 1; + break; } if (!found) { From 5d2c52b8ca8c20cf527eaad3afc5e48e41ff8f6e Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 7 Jan 2010 19:55:16 +0000 Subject: [PATCH 116/164] 2010-01-07 Robert Millan * include/multiboot.h (MULTIBOOT_UNSUPPORTED): Moved from here ... * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): ... to here. Update all users. --- ChangeLog | 6 ++++++ include/multiboot.h | 3 --- loader/i386/multiboot.c | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a5823bd8f..d7b84f6b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-07 Robert Millan + + * include/multiboot.h (MULTIBOOT_UNSUPPORTED): Moved from here ... + * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): ... to here. Update + all users. + 2010-01-07 Robert Millan 2010-01-07 Vladimir Serbinenko diff --git a/include/multiboot.h b/include/multiboot.h index 587f50832..da7afd9b3 100644 --- a/include/multiboot.h +++ b/include/multiboot.h @@ -31,9 +31,6 @@ /* This should be in %eax. */ #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 -/* The bits in the required part of flags field we don't support. */ -#define MULTIBOOT_UNSUPPORTED 0x0000fffc - /* Alignment of multiboot modules. */ #define MULTIBOOT_MOD_ALIGN 0x00001000 diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index a52b8d5d6..f4869594e 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -27,6 +27,9 @@ * - APM table */ +/* The bits in the required part of flags field we don't support. */ +#define UNSUPPORTED_FLAGS 0x0000fffc + #include #include #include @@ -261,7 +264,7 @@ grub_multiboot (int argc, char *argv[]) goto fail; } - if (header->flags & MULTIBOOT_UNSUPPORTED) + if (header->flags & UNSUPPORTED_FLAGS) { grub_error (GRUB_ERR_UNKNOWN_OS, "unsupported flag: 0x%x", header->flags); From bc8b32b3ec017a72f96ccb428a7444d38edcc2f2 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 7 Jan 2010 21:05:25 +0000 Subject: [PATCH 117/164] 2010-01-07 Robert Millan Reset Multiboot 2 support. New loader implements the draft in /branches/multiboot2 and shares as much code as possible with the production Multiboot 1 implementation. * loader/ieee1275/multiboot2.c: Remove file. Update all users. * loader/multiboot2.c: Likewise. * loader/i386/multiboot_helper.S: Likewise. * include/multiboot2.h: Replace with latest version from the draft in /branches/multiboot2. * conf/i386-coreboot.rmk (multiboot_mod_SOURCES): Remove `loader/i386/multiboot_helper.S', `loader/i386/pc/multiboot2.c' and `loader/multiboot2.c'. (pkglib_MODULES): Add `multiboot2.mod'. (multiboot2_mod_SOURCES): New variable. (multiboot2_mod_LDFLAGS): Likewise. (multiboot2_mod_CFLAGS): Likewise. Define `GRUB_USE_MULTIBOOT2'. * conf/i386-pc.rmk: Likewise. * conf/powerpc-ieee1275.rmk (pkglib_MODULES): Remove `multiboot.mod'. (multiboot_mod_SOURCES): Remove variable. (multiboot_mod_LDFLAGS): Likewise. (multiboot_mod_CFLAGS): Likewise. * include/grub/multiboot.h [GRUB_USE_MULTIBOOT2]: Include `' instead of `'. [GRUB_USE_MULTIBOOT2] (MULTIBOOT_BOOTLOADER_MAGIC) (MULTIBOOT_HEADER_MAGIC): New macros. * loader/multiboot_loader.c (module_version_status): Remove variable. (find_multi_boot2_header): Remove function. (grub_cmd_multiboot_loader): Remove Multiboot 2 / Multiboot 1 selection logic. Always check for the Multiboot version we're compiling for. (grub_cmd_module_loader): Likewise. [GRUB_USE_MULTIBOOT2] (GRUB_MOD_INIT(multiboot)): Register `multiboot2' command instead of `multiboot'. --- ChangeLog | 40 +++ conf/i386-coreboot.rmk | 14 +- conf/i386-pc.rmk | 14 +- conf/powerpc-ieee1275.rmk | 8 - include/grub/multiboot.h | 9 +- include/multiboot2.h | 262 +++++++++++++------ loader/i386/multiboot_helper.S | 43 --- loader/ieee1275/multiboot2.c | 147 ----------- loader/multiboot2.c | 461 --------------------------------- loader/multiboot_loader.c | 91 +------ 10 files changed, 266 insertions(+), 823 deletions(-) delete mode 100644 loader/i386/multiboot_helper.S delete mode 100644 loader/ieee1275/multiboot2.c delete mode 100644 loader/multiboot2.c diff --git a/ChangeLog b/ChangeLog index d7b84f6b3..749b0e68c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +2010-01-07 Robert Millan + + Reset Multiboot 2 support. New loader implements the draft in + /branches/multiboot2 and shares as much code as possible with the + production Multiboot 1 implementation. + + * loader/ieee1275/multiboot2.c: Remove file. Update all users. + * loader/multiboot2.c: Likewise. + * loader/i386/multiboot_helper.S: Likewise. + * include/multiboot2.h: Replace with latest version from the draft + in /branches/multiboot2. + + * conf/i386-coreboot.rmk (multiboot_mod_SOURCES): Remove + `loader/i386/multiboot_helper.S', `loader/i386/pc/multiboot2.c' + and `loader/multiboot2.c'. + (pkglib_MODULES): Add `multiboot2.mod'. + (multiboot2_mod_SOURCES): New variable. + (multiboot2_mod_LDFLAGS): Likewise. + (multiboot2_mod_CFLAGS): Likewise. Define `GRUB_USE_MULTIBOOT2'. + + * conf/i386-pc.rmk: Likewise. + + * conf/powerpc-ieee1275.rmk (pkglib_MODULES): Remove `multiboot.mod'. + (multiboot_mod_SOURCES): Remove variable. + (multiboot_mod_LDFLAGS): Likewise. + (multiboot_mod_CFLAGS): Likewise. + + * include/grub/multiboot.h [GRUB_USE_MULTIBOOT2]: Include + `' instead of `'. + [GRUB_USE_MULTIBOOT2] (MULTIBOOT_BOOTLOADER_MAGIC) + (MULTIBOOT_HEADER_MAGIC): New macros. + + * loader/multiboot_loader.c (module_version_status): Remove variable. + (find_multi_boot2_header): Remove function. + (grub_cmd_multiboot_loader): Remove Multiboot 2 / Multiboot 1 selection + logic. Always check for the Multiboot version we're compiling for. + (grub_cmd_module_loader): Likewise. + [GRUB_USE_MULTIBOOT2] (GRUB_MOD_INIT(multiboot)): Register `multiboot2' + command instead of `multiboot'. + 2010-01-07 Robert Millan * include/multiboot.h (MULTIBOOT_UNSUPPORTED): Moved from here ... diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 8b69f7796..797b29daf 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -102,7 +102,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. -pkglib_MODULES = linux.mod multiboot.mod \ +pkglib_MODULES = linux.mod \ aout.mod play.mod serial.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ halt.mod datetime.mod date.mod datehook.mod \ @@ -140,16 +140,20 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For multiboot.mod. +pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_helper.S \ - loader/i386/pc/multiboot2.c \ - loader/multiboot2.c \ loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) +pkglib_MODULES += multiboot2.mod +multiboot2_mod_SOURCES = loader/i386/multiboot.c \ + loader/multiboot_loader.c +multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 +multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) + # For aout.mod. aout_mod_SOURCES = loader/aout.c aout_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index afdf47e5a..e02ee4665 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -116,7 +116,7 @@ bin_SCRIPTS += grub-mkrescue grub_mkrescue_SOURCES = util/grub-mkrescue.in pkglib_MODULES = biosdisk.mod chain.mod \ - multiboot.mod reboot.mod halt.mod \ + reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \ vga.mod memdisk.mod pci.mod lspci.mod \ aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ @@ -201,16 +201,20 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For multiboot.mod. +pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_helper.S \ - loader/i386/pc/multiboot2.c \ - loader/multiboot2.c \ loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) +pkglib_MODULES += multiboot2.mod +multiboot2_mod_SOURCES = loader/i386/multiboot.c \ + loader/multiboot_loader.c +multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 +multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) + # For vbe.mod. vbe_mod_SOURCES = video/i386/pc/vbe.c vbe_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 122455280..000434f33 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -61,7 +61,6 @@ pkglib_MODULES = halt.mod \ linux.mod \ reboot.mod \ suspend.mod \ - multiboot.mod \ memdisk.mod \ lsmmap.mod @@ -91,13 +90,6 @@ halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For multiboot.mod -multiboot_mod_SOURCES = loader/ieee1275/multiboot2.c \ - loader/multiboot2.c \ - loader/multiboot_loader.c -multiboot_mod_CFLAGS = $(COMMON_CFLAGS) -multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For memdisk.mod. memdisk_mod_SOURCES = disk/memdisk.c memdisk_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index c54874942..041ee1f18 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -1,7 +1,7 @@ /* multiboot.h - multiboot header file with grub definitions. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2008,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,14 @@ #ifndef GRUB_MULTIBOOT_HEADER #define GRUB_MULTIBOOT_HEADER 1 +#ifdef GRUB_USE_MULTIBOOT2 +#include +/* Same thing as far as our loader is concerned. */ +#define MULTIBOOT_BOOTLOADER_MAGIC MULTIBOOT2_BOOTLOADER_MAGIC +#define MULTIBOOT_HEADER_MAGIC MULTIBOOT2_HEADER_MAGIC +#else #include +#endif void grub_multiboot (int argc, char *argv[]); void grub_module (int argc, char *argv[]); diff --git a/include/multiboot2.h b/include/multiboot2.h index 275aa5a9b..0488849d7 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -1,110 +1,220 @@ -/* multiboot2.h - multiboot 2 header file. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2009 Free Software Foundation, Inc. +/* multiboot2.h - Multiboot 2 header file. */ +/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * GRUB 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY + * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef MULTIBOOT2_HEADER -#define MULTIBOOT2_HEADER 1 +#ifndef MULTIBOOT_HEADER +#define MULTIBOOT_HEADER 1 /* How many bytes from the start of the file we search for the header. */ -#define MULTIBOOT2_HEADER_SEARCH 8192 +#define MULTIBOOT_SEARCH 8192 /* The magic field should contain this. */ -#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6 +#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6 -/* Passed from the bootloader to the kernel. */ -#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289 +/* This should be in %eax. */ +#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289 /* Alignment of multiboot modules. */ -#define MULTIBOOT2_MOD_ALIGN 0x00001000 +#define MULTIBOOT_MOD_ALIGN 0x00001000 + +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT_INFO_ALIGN 0x00000004 + +/* Flags set in the 'flags' member of the multiboot header. */ + +/* Align all boot modules on i386 page (4KB) boundaries. */ +#define MULTIBOOT_PAGE_ALIGN 0x00000001 + +/* Must pass memory information to OS. */ +#define MULTIBOOT_MEMORY_INFO 0x00000002 + +/* Must pass video information to OS. */ +#define MULTIBOOT_VIDEO_MODE 0x00000004 + +/* This flag indicates the use of the address fields in the header. */ +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 + +/* Flags to be set in the 'flags' member of the multiboot info structure. */ + +/* is there basic lower/upper memory information? */ +#define MULTIBOOT_INFO_MEMORY 0x00000001 +/* is there a boot device set? */ +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +/* is the command-line defined? */ +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +/* are there modules to do something with? */ +#define MULTIBOOT_INFO_MODS 0x00000008 + +/* These next two are mutually exclusive */ + +/* is there a symbol table loaded? */ +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +/* is there an ELF section header table? */ +#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 + +/* is there a full memory map? */ +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 + +/* Is there drive info? */ +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 + +/* Is there a config table? */ +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 + +/* Is there a boot loader name? */ +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 + +/* Is there a APM table? */ +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 + +/* Is there video information? */ +#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 #ifndef ASM_FILE -#ifndef __WORDSIZE -#include -#endif +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; -/* XXX not portable? */ -#if __WORDSIZE == 64 -typedef uint64_t multiboot2_word; -#else -typedef uint32_t multiboot2_word; -#endif - -struct multiboot2_header +struct multiboot_header { - uint32_t magic; - uint32_t flags; + /* Must be MULTIBOOT_MAGIC - see above. */ + multiboot_uint32_t magic; + + /* Feature flags. */ + multiboot_uint32_t flags; + + /* The above fields plus this one must equal 0 mod 2^32. */ + multiboot_uint32_t checksum; + + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + multiboot_uint32_t header_addr; + multiboot_uint32_t load_addr; + multiboot_uint32_t load_end_addr; + multiboot_uint32_t bss_end_addr; + multiboot_uint32_t entry_addr; + + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + multiboot_uint32_t mode_type; + multiboot_uint32_t width; + multiboot_uint32_t height; + multiboot_uint32_t depth; }; -struct multiboot2_tag_header +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table { - uint32_t key; - uint32_t len; + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; }; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; -#define MULTIBOOT2_TAG_RESERVED1 0 -#define MULTIBOOT2_TAG_RESERVED2 (~0) - -#define MULTIBOOT2_TAG_START 1 -struct multiboot2_tag_start +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table { - struct multiboot2_tag_header header; - multiboot2_word size; /* Total size of all multiboot tags. */ + multiboot_uint32_t num; + multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; }; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; -#define MULTIBOOT2_TAG_NAME 2 -struct multiboot2_tag_name +struct multiboot_info { - struct multiboot2_tag_header header; - char name[1]; -}; + /* Multiboot info version number */ + multiboot_uint32_t flags; -#define MULTIBOOT2_TAG_MODULE 3 -struct multiboot2_tag_module -{ - struct multiboot2_tag_header header; - multiboot2_word addr; - multiboot2_word size; - char type[36]; - char cmdline[1]; -}; + /* Available memory from BIOS */ + multiboot_uint32_t mem_lower; + multiboot_uint32_t mem_upper; -#define MULTIBOOT2_TAG_MEMORY 4 -struct multiboot2_tag_memory -{ - struct multiboot2_tag_header header; - multiboot2_word addr; - multiboot2_word size; - multiboot2_word type; -}; + /* "root" partition */ + multiboot_uint32_t boot_device; -#define MULTIBOOT2_TAG_UNUSED 5 -struct multiboot2_tag_unused -{ - struct multiboot2_tag_header header; -}; + /* Kernel command line */ + multiboot_uint32_t cmdline; -#define MULTIBOOT2_TAG_END 0xffff -struct multiboot2_tag_end -{ - struct multiboot2_tag_header header; + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; + + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; + + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; + multiboot_uint16_t vbe_mode; + multiboot_uint16_t vbe_interface_seg; + multiboot_uint16_t vbe_interface_off; + multiboot_uint16_t vbe_interface_len; }; +typedef struct multiboot_info multiboot_info_t; + +struct multiboot_mmap_entry +{ + multiboot_uint32_t size; + multiboot_uint64_t addr; + multiboot_uint64_t len; +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 + multiboot_uint32_t type; +} __attribute__((packed)); +typedef struct multiboot_mmap_entry multiboot_memory_map_t; + +struct multiboot_mod_list +{ + /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ + multiboot_uint32_t mod_start; + multiboot_uint32_t mod_end; + + /* Module command line */ + multiboot_uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + multiboot_uint32_t pad; +}; +typedef struct multiboot_mod_list multiboot_module_t; #endif /* ! ASM_FILE */ -#endif /* ! MULTIBOOT2_HEADER */ +#endif /* ! MULTIBOOT_HEADER */ diff --git a/loader/i386/multiboot_helper.S b/loader/i386/multiboot_helper.S deleted file mode 100644 index 2f9af778b..000000000 --- a/loader/i386/multiboot_helper.S +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include - - .p2align 2 /* force 4-byte alignment */ - -/* - * This starts the multiboot 2 kernel. - */ - -FUNCTION(grub_multiboot2_real_boot) - /* Push the entry address on the stack. */ - pushl %eax - /* Move the address of the multiboot information structure to ebx. */ - movl %edx,%ebx - - /* Interrupts should be disabled. */ - cli - - /* Move the magic value into eax and jump to the kernel. */ - movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax - popl %ecx - - cld - jmp *%ecx diff --git a/loader/ieee1275/multiboot2.c b/loader/ieee1275/multiboot2.c deleted file mode 100644 index 846550ee5..000000000 --- a/loader/ieee1275/multiboot2.c +++ /dev/null @@ -1,147 +0,0 @@ -/* multiboot.c - boot a multiboot 2 OS image. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __i386__ -#include -#endif - -typedef void (*kernel_entry_t) (unsigned long, void *, int (void *), - unsigned long, unsigned long); - -/* Claim the memory occupied by the multiboot kernel. */ -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, - grub_addr_t *addr __attribute__((unused)), - int *do_load) -{ - int rc; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz); - if (rc) - return grub_error(GRUB_ERR_OUT_OF_MEMORY, "couldn't claim %x - %x", - phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); - - grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr->p_paddr, - phdr->p_paddr + phdr->p_memsz); - - return GRUB_ERR_NONE; -} - -/* Claim the memory occupied by the multiboot kernel. */ -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, - grub_addr_t *addr __attribute__((unused)), - int *do_load) -{ - int rc; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz); - if (rc) - return grub_error(GRUB_ERR_OUT_OF_MEMORY, "couldn't claim 0x%lx - 0x%lx", - phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); - - grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n", - (unsigned long) phdr->p_paddr, - (unsigned long) (phdr->p_paddr + phdr->p_memsz)); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr) -{ - int rc; - - /* XXX Will need to map on some firmwares. */ - rc = grub_ieee1275_claim (0, size, MULTIBOOT2_MOD_ALIGN, addr); - if (rc) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - "firmware couldn't allocate memory (size 0x%lx)", size); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size) -{ - grub_ieee1275_release (addr, size); - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_tags_arch_create (void) -{ - /* Nothing special. */ - return GRUB_ERR_NONE; -} - -/* Release the memory we claimed from Open Firmware above. */ -void -grub_mb2_arch_unload (struct multiboot2_tag_header *tags) -{ - struct multiboot2_tag_header *tag; - - /* Free all module memory in the tag list. */ - for_each_tag (tag, tags) - { - if (tag->key == MULTIBOOT2_TAG_MODULE) - { - struct multiboot2_tag_module *module = - (struct multiboot2_tag_module *) tag; - grub_ieee1275_release (module->addr, module->size); - } - } -} - -void -grub_mb2_arch_boot (grub_addr_t entry_addr, void *tags) -{ -#if defined(__powerpc__) - kernel_entry_t entry = (kernel_entry_t) entry_addr; - entry (MULTIBOOT2_BOOTLOADER_MAGIC, tags, grub_ieee1275_entry_fn, 0, 0); -#elif defined(__i386__) - grub_multiboot2_real_boot (entry_addr, tags); -#else -#error -#endif -} diff --git a/loader/multiboot2.c b/loader/multiboot2.c deleted file mode 100644 index cfc7b400c..000000000 --- a/loader/multiboot2.c +++ /dev/null @@ -1,461 +0,0 @@ -/* multiboot2.c - boot a multiboot 2 OS image. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static grub_addr_t entry; -extern grub_dl_t my_mod; - -static char *grub_mb2_tags; -static char *grub_mb2_tags_pos; -static grub_size_t grub_mb2_tags_len; -static int grub_mb2_tags_count; - -static void -grub_mb2_tags_free (void) -{ - grub_dprintf ("loader", "Freeing all tags...\n"); - grub_free (grub_mb2_tags); - grub_mb2_tags = 0; - grub_mb2_tags_pos = 0; - grub_mb2_tags_len = 0; - grub_mb2_tags_count = 0; -} - -grub_err_t -grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len) -{ - struct multiboot2_tag_header *tag; - grub_size_t used; - grub_size_t needed; - - grub_dprintf ("loader", "Allocating tag: key 0x%x, size 0x%lx.\n", - key, (unsigned long) len); - - used = grub_mb2_tags_pos - grub_mb2_tags; - len = ALIGN_UP (len, sizeof (multiboot2_word)); - - needed = used + len; - - if (needed > grub_mb2_tags_len) - { - /* Allocate new buffer. */ - grub_size_t newsize = needed * 2; - char *newarea; - - grub_dprintf ("loader", "Reallocating tag buffer (new size 0x%lx).\n", - (unsigned long) newsize); - - newarea = grub_malloc (newsize); - if (! newarea) - return grub_errno; - grub_memcpy (newarea, grub_mb2_tags, grub_mb2_tags_len); - grub_free (grub_mb2_tags); - - grub_mb2_tags_len = newsize; - grub_mb2_tags = newarea; - grub_mb2_tags_pos = newarea + used; - } - - tag = (struct multiboot2_tag_header *) grub_mb2_tags_pos; - grub_mb2_tags_pos += len; - - tag->key = key; - tag->len = len; - - if (addr) - *addr = (grub_addr_t) tag; - - grub_mb2_tags_count++; - - grub_dprintf ("loader", "Allocated tag %u at %p.\n", grub_mb2_tags_count, tag); - - return 0; -} - -static grub_err_t -grub_mb2_tag_start_create (void) -{ - return grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_START, - sizeof (struct multiboot2_tag_start)); -} - -static grub_err_t -grub_mb2_tag_name_create (void) -{ - struct multiboot2_tag_name *name; - grub_addr_t name_addr; - grub_err_t err; - const char *grub_version = PACKAGE_STRING; - - err = grub_mb2_tag_alloc (&name_addr, MULTIBOOT2_TAG_NAME, - sizeof (struct multiboot2_tag_name) + - sizeof (grub_version) + 1); - if (err) - return err; - - name = (struct multiboot2_tag_name *) name_addr; - grub_strcpy (name->name, grub_version); - - return GRUB_ERR_NONE; -} - -typedef grub_err_t (*tag_create_t) (void); -static tag_create_t grub_mb2_tag_creators[] = { - grub_mb2_tag_start_create, - grub_mb2_tag_name_create, - grub_mb2_tags_arch_create, - 0, -}; - -static grub_err_t -grub_mb2_tags_create (void) -{ - tag_create_t *creator; - grub_err_t err; - - for (creator = grub_mb2_tag_creators; *creator != 0; creator++) - { - err = (*creator) (); - if (err) - goto error; - } - - return GRUB_ERR_NONE; - -error: - grub_error_push (); - grub_mb2_tags_free (); - grub_error_pop (); - return err; -} - -static grub_err_t -grub_mb2_tags_finish (void) -{ - struct multiboot2_tag_start *start; - grub_err_t err; - - /* Create the `end' tag. */ - err = grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_END, - sizeof (struct multiboot2_tag_end)); - if (err) - goto error; - - /* We created the `start' tag first. Update it now. */ - start = (struct multiboot2_tag_start *) grub_mb2_tags; - start->size = grub_mb2_tags_pos - grub_mb2_tags; - return GRUB_ERR_NONE; - -error: - grub_error_push (); - grub_mb2_tags_free (); - grub_error_pop (); - return err; -} - -static grub_err_t -grub_mb2_boot (void) -{ - grub_mb2_tags_finish (); - - grub_dprintf ("loader", "Tags at %p\n", grub_mb2_tags); - grub_mb2_arch_boot (entry, grub_mb2_tags); - - /* Not reached. */ - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_mb2_unload (void) -{ - struct multiboot2_tag_header *tag; - struct multiboot2_tag_header *tags = - (struct multiboot2_tag_header *) grub_mb2_tags; - - /* Free all module memory in the tag list. */ - for_each_tag (tag, tags) - { - if (tag->key == MULTIBOOT2_TAG_MODULE) - { - struct multiboot2_tag_module *module = - (struct multiboot2_tag_module *) tag; - grub_free ((void *) module->addr); - } - } - - /* Allow architecture to un-reserve memory. */ - grub_mb2_arch_unload (tags); - - /* Free the tags themselves. */ - grub_mb2_tags_free (); - - grub_dl_unref (my_mod); - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_mb2_load_other (grub_file_t file __attribute__ ((unused)), - void *buffer __attribute__ ((unused))) -{ - /* XXX Create module tag here. */ - return grub_error (GRUB_ERR_UNKNOWN_OS, "currently only ELF is supported"); -} - -/* Create the tag containing the cmdline and the address of the module data. */ -static grub_err_t -grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize, - char *type, int key, int argc, char *argv[]) -{ - struct multiboot2_tag_module *module; - grub_ssize_t argslen = 0; - grub_err_t err; - char *p; - grub_addr_t module_addr; - int i; - - /* Allocate enough space for the arguments and spaces between them. */ - for (i = 0; i < argc; i++) - argslen += grub_strlen (argv[i]) + 1; - - /* Note: includes implicit 1-byte cmdline. */ - err = grub_mb2_tag_alloc (&module_addr, key, - sizeof (struct multiboot2_tag_module) + argslen); - if (err) - return grub_errno; - - module = (struct multiboot2_tag_module *) module_addr; - module->addr = modaddr; - module->size = modsize; - grub_strcpy(module->type, type); - - /* Fill in the command line. */ - p = module->cmdline; - for (i = 0; i < argc; i++) - { - p = grub_stpcpy (p, argv[i]); - *p++ = ' '; - } - module->cmdline[argslen] = '\0'; - - return GRUB_ERR_NONE; -} - -/* Load ELF32 or ELF64. */ -static grub_err_t -grub_mb2_load_elf (grub_elf_t elf, int argc, char *argv[]) -{ - grub_addr_t kern_base; - grub_size_t kern_size; - grub_err_t err; - - if (grub_elf_is_elf32 (elf)) - { - entry = elf->ehdr.ehdr32.e_entry; - err = grub_elf32_load (elf, grub_mb2_arch_elf32_hook, &kern_base, - &kern_size); - } - else if (grub_elf_is_elf64 (elf)) - { - entry = elf->ehdr.ehdr64.e_entry; - err = grub_elf64_load (elf, grub_mb2_arch_elf64_hook, &kern_base, - &kern_size); - } - else - err = grub_error (GRUB_ERR_UNKNOWN_OS, "unknown ELF class"); - - if (err) - goto fail; - - grub_dprintf ("loader", "Entry point is 0x%lx.\n", (unsigned long) entry); - - grub_mb2_tag_module_create (kern_base, kern_size, "kernel", - MULTIBOOT2_TAG_MODULE, argc, argv); - -fail: - return err; -} - -void -grub_multiboot2 (int argc, char *argv[]) -{ - char *buffer; - grub_file_t file = 0; - grub_elf_t elf = 0; - struct multiboot2_header *header = 0; - char *p; - grub_ssize_t len; - grub_err_t err; - int header_found = 0; - - grub_loader_unset (); - - if (argc == 0) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified"); - goto fail; - } - - file = grub_gzfile_open (argv[0], 1); - if (! file) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file"); - goto fail; - } - - buffer = grub_malloc (MULTIBOOT2_HEADER_SEARCH); - if (! buffer) - return; - - len = grub_file_read (file, buffer, MULTIBOOT2_HEADER_SEARCH); - if (len < 32) - { - grub_error (GRUB_ERR_BAD_OS, "file too small"); - goto fail; - } - - /* Look for the multiboot header in the buffer. The header should - be at least 8 bytes and aligned on a 8-byte boundary. */ - for (p = buffer; p <= buffer + len - 8; p += 8) - { - header = (struct multiboot2_header *) p; - if (header->magic == MULTIBOOT2_HEADER_MAGIC) - { - header_found = 1; - break; - } - } - - if (! header_found) - grub_dprintf ("loader", "No multiboot 2 header found.\n"); - - - /* Create the basic tags. */ - grub_dprintf ("loader", "Creating multiboot 2 tags\n"); - grub_mb2_tags_create (); - - /* Load the kernel and create its tag. */ - elf = grub_elf_file (file); - if (elf) - { - grub_dprintf ("loader", "Loading ELF multiboot 2 file.\n"); - err = grub_mb2_load_elf (elf, argc-1, &argv[1]); - grub_elf_close (elf); - } - else - { - grub_errno = 0; - grub_dprintf ("loader", "Loading non-ELF multiboot 2 file.\n"); - - if (header) - err = grub_mb2_load_other (file, header); - else - err = grub_error (GRUB_ERR_BAD_OS, - "need multiboot 2 header to load non-ELF files"); - grub_file_close (file); - } - - grub_free (buffer); - - if (err) - goto fail; - - /* Good to go. */ - grub_loader_set (grub_mb2_boot, grub_mb2_unload, 1); - return; - -fail: - grub_mb2_tags_free (); - grub_dl_unref (my_mod); -} - -void -grub_module2 (int argc, char *argv[]) -{ - grub_file_t file; - grub_addr_t modaddr = 0; - grub_ssize_t modsize = 0; - grub_err_t err; - - if (argc == 0) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified"); - return; - } - - if (argc == 1) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "no module type specified"); - return; - } - - if (entry == 0) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, - "you need to load the multiboot kernel first"); - return; - } - - /* Load module data. */ - file = grub_gzfile_open (argv[0], 1); - if (! file) - goto out; - - modsize = grub_file_size (file); - err = grub_mb2_arch_module_alloc (modsize, &modaddr); - if (err) - goto out; - - grub_dprintf ("loader", "Loading module at 0x%x - 0x%x\n", modaddr, - modaddr + modsize); - if (grub_file_read (file, (void *) modaddr, modsize) != modsize) - { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); - goto out; - } - - /* Create the module tag. */ - err = grub_mb2_tag_module_create (modaddr, modsize, - argv[1], MULTIBOOT2_TAG_MODULE, - argc-2, &argv[2]); - if (err) - goto out; - -out: - grub_error_push (); - - if (file) - grub_file_close (file); - - if (modaddr) - grub_mb2_arch_module_free (modaddr, modsize); - - grub_error_pop (); -} diff --git a/loader/multiboot_loader.c b/loader/multiboot_loader.c index 9e5cf1628..790f14d9a 100644 --- a/loader/multiboot_loader.c +++ b/loader/multiboot_loader.c @@ -1,7 +1,7 @@ -/* multiboot_loader.c - boot multiboot 1 or 2 OS image */ +/* multiboot_loader.c - boot multiboot kernel image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,8 +18,6 @@ */ #include -#include -#include #include #include #include @@ -31,15 +29,6 @@ grub_dl_t my_mod; -/* This tracks which version of multiboot to use when using - * the module command. By default use multiboot version 1. - * values: - * 1 - Multiboot version 1 - * 2 - Multiboot version 2 - */ - -static unsigned int module_version_status = 1; - static int find_multi_boot1_header (grub_file_t file) { @@ -69,34 +58,6 @@ find_multi_boot1_header (grub_file_t file) return found_status; } -static int -find_multi_boot2_header (grub_file_t file) -{ - struct multiboot_header *header; - char buffer[MULTIBOOT_SEARCH]; - int found_status = 0; - grub_ssize_t len; - - len = grub_file_read (file, buffer, MULTIBOOT_SEARCH); - if (len < 32) - return found_status; - - /* Look for the multiboot header in the buffer. The header should - be at least 8 bytes and aligned on a 8-byte boundary. */ - for (header = (struct multiboot_header *) buffer; - ((char *) header <= buffer + len - 8) || (header = 0); - header = (struct multiboot_header *) ((char *) header + 8)) - { - if (header->magic == MULTIBOOT2_HEADER_MAGIC) - { - found_status = 1; - break; - } - } - - return found_status; -} - static grub_err_t grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) @@ -122,8 +83,6 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)), /* find which header is in the file */ if (find_multi_boot1_header (file)) header_multi_ver_found = 1; - else if (find_multi_boot2_header (file)) - header_multi_ver_found = 2; else { grub_error (GRUB_ERR_BAD_OS, "multiboot header not found"); @@ -136,25 +95,9 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)), /* Launch multi boot with header */ - /* XXX Find a better way to identify this. - This is for i386-pc */ -#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_COREBOOT) || \ - defined(GRUB_MACHINE_QEMU) - if (header_multi_ver_found == 1) - { - grub_dprintf ("multiboot_loader", - "Launching multiboot 1 grub_multiboot() function\n"); - grub_multiboot (argc, argv); - module_version_status = 1; - } -#endif - if (header_multi_ver_found == 0 || header_multi_ver_found == 2) - { - grub_dprintf ("multiboot_loader", - "Launching multiboot 2 grub_multiboot2() function\n"); - grub_multiboot2 (argc, argv); - module_version_status = 2; - } + grub_dprintf ("multiboot_loader", + "Launching multiboot 1 grub_multiboot() function\n"); + grub_multiboot (argc, argv); return grub_errno; @@ -172,21 +115,9 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { -#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_COREBOOT) || \ - defined(GRUB_MACHINE_QEMU) - if (module_version_status == 1) - { - grub_dprintf("multiboot_loader", - "Launching multiboot 1 grub_module() function\n"); - grub_module (argc, argv); - } -#endif - if (module_version_status == 2) - { - grub_dprintf("multiboot_loader", - "Launching multiboot 2 grub_module2() function\n"); - grub_module2 (argc, argv); - } + grub_dprintf("multiboot_loader", + "Launching multiboot 1 grub_module() function\n"); + grub_module (argc, argv); return grub_errno; } @@ -196,8 +127,14 @@ static grub_command_t cmd_multiboot, cmd_module; GRUB_MOD_INIT(multiboot) { cmd_multiboot = +#ifdef GRUB_USE_MULTIBOOT2 + grub_register_command ("multiboot2", grub_cmd_multiboot_loader, + 0, "Load a multiboot 2 kernel."); +#else grub_register_command ("multiboot", grub_cmd_multiboot_loader, 0, "Load a multiboot kernel."); +#endif + cmd_module = grub_register_command ("module", grub_cmd_module_loader, 0, "Load a multiboot module."); From fc054c9cb891c10d80c6eb3727ebbbab09aba460 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 7 Jan 2010 22:18:59 +0100 Subject: [PATCH 118/164] Various cleanups --- commands/xnu_uuid.c | 1 - conf/any-emu.rmk | 2 +- conf/common.rmk | 2 +- conf/i386-coreboot.rmk | 4 ++-- conf/i386-efi.rmk | 2 +- conf/i386-ieee1275.rmk | 2 +- conf/i386-pc.rmk | 2 +- conf/powerpc-ieee1275.rmk | 2 +- conf/sparc64-ieee1275.rmk | 2 +- conf/x86_64-efi.rmk | 2 +- kern/reader.c | 24 ------------------------ normal/menu_viewer.c | 25 ------------------------- 12 files changed, 10 insertions(+), 60 deletions(-) delete mode 100644 kern/reader.c delete mode 100644 normal/menu_viewer.c diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index ecf8ba00a..b6f2b2604 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -33,7 +33,6 @@ #include #include #include -#include /* This prefix is used by xnu and boot-132 to hash together with volume serial. */ diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index 0f6312ef7..bd1798946 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -28,7 +28,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/color.c \ - normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ + normal/menu.c normal/menu_entry.c \ normal/menu_text.c normal/crypto.c normal/term.c \ commands/terminal.c lib/charset.c \ script/main.c script/execute.c script/function.c \ diff --git a/conf/common.rmk b/conf/common.rmk index 6d57a75ea..3f1689370 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -549,7 +549,7 @@ keystatus_mod_LDFLAGS = $(COMMON_LDFLAGS) normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \ normal/auth.c normal/autofs.c normal/handler.c \ normal/color.c normal/completion.c normal/datetime.c normal/menu.c \ - normal/menu_entry.c normal/menu_text.c normal/menu_viewer.c \ + normal/menu_entry.c normal/menu_text.c \ normal/misc.c normal/crypto.c normal/term.c normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 8b69f7796..c71997d97 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -21,7 +21,7 @@ kernel_img_SOURCES = kern/i386/coreboot/startup.S \ kern/i386/halt.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ @@ -65,7 +65,7 @@ kernel_img_SOURCES = kern/i386/qemu/startup.S \ kern/i386/halt.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 3a219e71b..f3281a1bc 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -39,7 +39,7 @@ pkglib_MODULES = kernel.img chain.mod appleldr.mod \ kernel_img_EXPORTS = no kernel_img_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 2a90fd2be..5c3a5aaf6 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -19,7 +19,7 @@ kernel_img_SOURCES = kern/i386/ieee1275/startup.S \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ kern/env.c \ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index afdf47e5a..44a306581 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -48,7 +48,7 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \ kern/i386/misc.S \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/$(target_cpu)/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \ diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 122455280..4587e171e 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -31,7 +31,7 @@ pkglib_PROGRAMS = kernel.img kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/ieee1275/init.c \ diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 9d020a84f..4ba098619 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -35,7 +35,7 @@ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \ kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/sparc64/ieee1275/ieee1275.c \ diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index a82b35222..4f6ace057 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -39,7 +39,7 @@ kernel_img_EXPORTS = no kernel_img_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/reader.c kern/term.c \ + kern/misc.c kern/mm.c kern/term.c \ kern/rescue_parser.c kern/rescue_reader.c \ kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ diff --git a/kern/reader.c b/kern/reader.c deleted file mode 100644 index 74698d34b..000000000 --- a/kern/reader.c +++ /dev/null @@ -1,24 +0,0 @@ -/* reader.c - reader support */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include - diff --git a/normal/menu_viewer.c b/normal/menu_viewer.c deleted file mode 100644 index b52442f40..000000000 --- a/normal/menu_viewer.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - From 3b88cbbda5aed8d33e703128a2e1de07690eeb1f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 7 Jan 2010 22:22:11 +0100 Subject: [PATCH 119/164] Warning fixes --- normal/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/normal/main.c b/normal/main.c index 739ad3763..7a5e3ee8e 100644 --- a/normal/main.c +++ b/normal/main.c @@ -433,8 +433,6 @@ grub_normal_init_page (struct grub_term_output *term) grub_free (unicode_msg); } -static int reader_nested; - static char * read_lists (struct grub_env_var *var __attribute__ ((unused)), const char *val) From 1dcb8d30a9d0cfb0c223b56a657f668c7349c815 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 7 Jan 2010 22:22:24 +0100 Subject: [PATCH 120/164] ChangeLog --- ChangeLog.multiterm | 122 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 ChangeLog.multiterm diff --git a/ChangeLog.multiterm b/ChangeLog.multiterm new file mode 100644 index 000000000..3228f902a --- /dev/null +++ b/ChangeLog.multiterm @@ -0,0 +1,122 @@ +2010-01-07 Vladimir Serbinenko +2010-01-07 Robert Millan + + Support for multiple terminals. + + * Makefile.in (pkglib_DATA): terminal.lst. + (terminal.lst): New target. + * commands/handler.c (grub_cmd_handler): Don't handle terminals. + (GRUB_MOD_INIT(handler)): Likewise. + (GRUB_MOD_FINI(handler)): Likewise. + * commands/help.c (grub_cmd_help): Handle multiple terminals. + * commands/keystatus.c (grub_cmd_keystatus): Likewise. + * commands/sleep.c (do_print): Use grub_term_restore_pos. + (grub_cmd_sleep): Use grub_term_save_pos. + * commands/terminal.c: New file. + * conf/any-emu.rmk (grub_emu_SOURCES): Add normal/term.c + commands/terminal.c and lib/charset.c. + * conf/common.rmk (normal_mod_SOURCES): Add normal/term.c. + (pkglib_MODULES): Add terminal.mod. + (terminal_mod_SOURCES): New variable. + (terminal_mod_CFLAGS): Likewise. + (terminal_mod_LDFLAGS): Likewise. + * genhandlerlist.sh: Don't handle terminals. + * genmk.rb: Generate terminal-*.lst. + * genterminallist.sh: New file. + * include/grub/charset.h (grub_ucs4_to_utf8_alloc): New proto. + (grub_is_valid_utf8): Likewise. + (grub_utf8_to_ucs4_alloc): Likewise. + * include/grub/menu_viewer.h (grub_menu_viewer): Rewritten. + (grub_menu_register_viewer): Changed argument. + (grub_menu_try_text): New proto. + (grub_gfxmenu_try_hook): New declaration. + * include/grub/normal.h (grub_normal_exit_level): New declaration. + (grub_menu_init_page): Additional argument term. + (grub_normal_init_page): Likewise. + (grub_cmdline_get): Arguments simplified. + (grub_utf8_to_ucs4_alloc): Removed. + (grub_print_ucs4): Additional argument term. + (grub_getstringwidth): Likewise. + (grub_print_message_indented): Likewise. + (grub_menu_text_register_instances): New proto. + (grub_show_menu): Likewise. + (read_terminal_list): Likewise. + (grub_set_more): Likewise. + * include/grub/parser.h: Include handler.h. + * include/grub/reader.h: Rewritten. + * include/grub/term.h (GRUB_TERM_NEED_INIT): Removed. + (GRUB_TERM_WIDTH): Changed to function. + (GRUB_TERM_HEIGHT): Likewise. + (GRUB_TERM_BORDER_WIDTH): Likewise. + (GRUB_TERM_BORDER_HEIGHT): Likewise. + (GRUB_TERM_NUM_ENTRIES): Likewise. + (GRUB_TERM_ENTRY_WIDTH): Likewise. + (GRUB_TERM_CURSOR_X): Likewise. + (grub_term_input_class): Likewise. + (grub_term_output_class): Likewise. + (grub_term_outputs_disabled): New declaration. + (grub_term_inputs_disabled): Likewise. + (grub_term_outputs): Likewise. + (grub_term_inputs): Likewise. + (grub_term_register_input_active): New function. + (grub_term_register_output_active): Likewise. + (grub_term_register_input): Rewritten. + (grub_term_register_output): Likewise. + (grub_term_unregister_input): Likewise. + (grub_term_unregister_output): Likewise. + (FOR_ACTIVE_TERM_INPUTS): New macro. + (FOR_DISABLED_TERM_INPUTS): Likewise. + (FOR_ACTIVE_TERM_OUTPUTS): Likewise. + (FOR_DISABLED_TERM_OUTPUTS): Likewise. + * include/grub/terminfo.h: Add oterm argument to all protypes. + * kern/main.c (grub_main): Don't call grub_register_rescue_reader. + Use grub_rescue_run. + * kern/misc.c (grub_utf8_to_ucs4): Put '?' for invalid characters. + All users updated. + * kern/reader.c: Removed. All users updated. + * kern/rescue_reader.c (grub_rescue_init): Removed. + (grub_rescue_reader): Likewise. + (grub_register_rescue_reader): Likewise. + (grub_rescue_run): New function based on kern/reader.c. + * kern/term.c: Adapted for multiterm. + * lib/charset.c (grub_ucs4_to_utf8_alloc): New function. + (grub_is_valid_utf8): Likewise. + (grub_utf8_to_ucs4_alloc): Moved from normal/menu_text.c. + * loader/i386/efi/linux.c (grub_cmd_linux): Retrieve parameters of + right terminal. + * loader/i386/linux.c (grub_linux_boot): Likewise. + * normal/auth.c (grub_username_get): New function. + (grub_auth_check_authentication): Use grub_username_get. + * normal/cmdline.c: Changed to UCS4. Adapted for multiterm. + * normal/color.c: Adapt for multiterm. + * normal/main.c (read_config_file): Don't use grub_reader_loop. + (grub_normal_init_page): Additional argument term. + (read_lists): Call read_terminal_lists. + (grub_enter_normal_mode): Call grub_cmdline_run. + Handle grub_normal_exit_level. + (grub_cmd_normal): Make reentrant. + (grub_cmd_normal_exit): New function. + (grub_normal_reader_init): Additional argument nested. Handle multiterm. + * normal/menu.c: Adapt for multiterm. + * normal/menu_entry.c: Likewise. + * normal/menu_text.c: Likewise. + * normal/menu_viewer.c: Removed. All users updated. + * normal/term.c: New file. + * term/efi/console.c (grub_console_init): Use + grub_term_register_input_active and grub_term_register_output_active. + * term/gfxterm.c (GRUB_MOD_INIT) [GRUB_MACHINE_MIPS_YEELOONG]: Likewise. + * term/i386/pc/at_keyboard.c (GRUB_MOD_INIT) + [GRUB_MACHINE_MIPS_YEELOONG] || [GRUB_MACHINE_COREBOOT] + || [GRUB_MACHINE_QEMU]: Likewise. + * term/i386/pc/vga_text.c (GRUB_MOD_INIT) [GRUB_MACHINE_COREBOOT] + || [GRUB_MACHINE_QEMU]: Likewise. + * term/i386/pc/console.c (grub_console_init): Likewise. + * term/ieee1275/ofconsole.c (grub_console_init): Likewise. + * util/console.c: Change order of includes to workaround a bug in + ncurses headers. + (grub_console_init): Use + grub_term_register_input_active and grub_term_register_output_active. + * term/terminfo.c: New argument oterm on all exported functions. + All users updated. + * util/grub-editenv.c (grub_term_input_class): Removed. + (grub_term_output_class): Likewise. From 6fc804ffbb7d0163a3f6a73dbd2b6f7c5f954fff Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 15:19:10 +0530 Subject: [PATCH 121/164] unit testing framework --- Makefile.in | 19 +++- conf/tests.rmk | 41 ++++++++ genmk.rb | 6 +- include/grub/test.h | 88 ++++++++++++++++++ tests/example_functional_test.c | 17 ++++ tests/example_grub_script_test.in | 3 + tests/example_scripted_test.in | 3 + tests/example_unit_test.c | 20 ++++ tests/lib/functional_test.c | 75 +++++++++++++++ tests/lib/test.c | 150 ++++++++++++++++++++++++++++++ tests/lib/unit_test.c | 122 ++++++++++++++++++++++++ tests/util/grub-shell-tester.in | 109 ++++++++++++++++++++++ tests/util/grub-shell.in | 125 +++++++++++++++++++++++++ 13 files changed, 774 insertions(+), 4 deletions(-) create mode 100644 conf/tests.rmk create mode 100644 include/grub/test.h create mode 100644 tests/example_functional_test.c create mode 100644 tests/example_grub_script_test.in create mode 100644 tests/example_scripted_test.in create mode 100644 tests/example_unit_test.c create mode 100644 tests/lib/functional_test.c create mode 100644 tests/lib/test.c create mode 100644 tests/lib/unit_test.c create mode 100644 tests/util/grub-shell-tester.in create mode 100644 tests/util/grub-shell.in diff --git a/Makefile.in b/Makefile.in index ffa8716ed..2358060f2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,6 +141,7 @@ PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) \ $(lib_SCRIPTS) INFOS = $(info_INFOS) +TESTS = $(check_UNITTESTS) $(check_FUNCTIONALTESTS) $(check_SCRIPTEDTESTS) CLEANFILES = MOSTLYCLEANFILES = @@ -167,6 +168,8 @@ ifeq ($(platform), emu) include $(srcdir)/conf/any-emu.mk else include $(srcdir)/conf/$(target_cpu)-$(platform).mk +# For tests. +include $(srcdir)/conf/tests.mk # For external modules. -include $(wildcard $(GRUB_CONTRIB)/*/conf/common.mk) endif @@ -458,7 +461,21 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -check: +$(TESTS): $(check_SCRIPTS) $(check_MODULES) $(check_PROGRAMS) +check: all $(TESTS) + @list="$(check_UNITTESTS) $(check_SCRIPTEDTESTS)"; \ + for file in $$list; do \ + if $(builddir)/$$file; then \ + echo "$$file: PASS"; \ + else \ + echo "$$file: FAIL"; \ + fi; \ + done + @list="$(check_FUNCTIONALTESTS)"; \ + for test in $$list; do \ + echo "insmod functional_test; insmod $test; functional_test" \ + | $(builddir)/grub-shell; \ + done .SUFFIX: .SUFFIX: .c .o .S .d diff --git a/conf/tests.rmk b/conf/tests.rmk new file mode 100644 index 000000000..03d6acbd1 --- /dev/null +++ b/conf/tests.rmk @@ -0,0 +1,41 @@ +# -*- makefile -*- + +# For grub-shell +grub-shell: tests/util/grub-shell.in config.status + ./config.status --file=$@:$< + chmod +x $@ +check_SCRIPTS += grub-shell +CLEANFILES += grub-shell + +# For grub-shell-tester +grub-shell-tester: tests/util/grub-shell-tester.in config.status + ./config.status --file=$@:$< + chmod +x $@ +check_SCRIPTS += grub-shell-tester +CLEANFILES += grub-shell-tester + +check_MODULES += functional_test.mod +functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c +functional_test_mod_CFLAGS = $(COMMON_CFLAGS) +functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# Unit tests + +check_UNITTESTS += example_unit_test +example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c +example_unit_test_CFLAGS = -Wno-format + +# Functional tests + +check_FUNCTIONALTESTS += example_functional_test.mod +example_functional_test_mod_SOURCES = tests/example_functional_test.c +example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) +example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# Scripted tests + +check_SCRIPTEDTESTS += example_scripted_test +example_scripted_test_SOURCES = tests/example_scripted_test.in + +check_SCRIPTEDTESTS += example_grub_script_test +example_grub_script_test_SOURCES = tests/example_grub_script_test.in diff --git a/genmk.rb b/genmk.rb index b1cce3831..006fc3d29 100644 --- a/genmk.rb +++ b/genmk.rb @@ -407,12 +407,12 @@ while l = gets Image.new(prefix, img) end - when 'MODULES' + when 'MODULES', 'FUNCTIONALTESTS' pmodules += args.split(/\s+/).collect do |pmod| PModule.new(prefix, pmod) end - when 'UTILITIES' + when 'UTILITIES', 'UNITTESTS' utils += args.split(/\s+/).collect do |util| Utility.new(prefix, util) end @@ -422,7 +422,7 @@ while l = gets Program.new(prefix, prog) end - when 'SCRIPTS' + when 'SCRIPTS', 'SCRIPTEDTESTS' scripts += args.split(/\s+/).collect do |script| Script.new(prefix, script) end diff --git a/include/grub/test.h b/include/grub/test.h new file mode 100644 index 000000000..fbc2bff8c --- /dev/null +++ b/include/grub/test.h @@ -0,0 +1,88 @@ +#ifndef GRUB_TEST_HEADER +#define GRUB_TEST_HEADER + +#include +#include +#include +#include +#include + +struct grub_test +{ + /* The next test. */ + struct grub_test *next; + + /* The test name. */ + char *name; + + /* The test main function. */ + void (*main) (void); +}; +typedef struct grub_test *grub_test_t; + +extern grub_test_t EXPORT_VAR (grub_test_list); + +void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); + +void EXPORT_FUNC (grub_test_unregister) (const char *name); + +/* Execute a test and print results. */ +int grub_test_run (const char *name); + +/* Test `cond' for nonzero; log failure otherwise. */ +void grub_test_nonzero (int cond, const char *file, + const char *func, grub_uint32_t line, + const char *fmt, ...) + __attribute__ ((format (printf, 5, 6))); + +#ifdef __STDC_VERSION__ +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "" +# endif +#endif +#else +#define __func__ "" +#endif + +/* Macro to fill in location details and an optional error message. */ +#define grub_test_assert(cond, ...) \ + grub_test_nonzero(cond, __FILE__, __func__, __LINE__, \ + ## __VA_ARGS__, \ + "assert failed: %s", #cond) + +/* Macro to define a unit test. */ +#define GRUB_UNIT_TEST(name, funp) \ + void grub_unit_test_init (void) \ + { \ + grub_test_register (name, funp); \ + } \ + \ + void grub_unit_test_fini (void) \ + { \ + grub_test_unregister (name); \ + } + +/* Macro to define a functional test. */ +#define GRUB_FUNCTIONAL_TEST(name, funp) \ + GRUB_MOD_INIT(functional_test_##funp) \ + { \ + grub_test_register (name, funp); \ + } \ + \ + GRUB_MOD_FINI(functional_test_##funp) \ + { \ + grub_test_unregister (name); \ + } + +/* Functions that are defined differently for unit and functional tests. */ +void *grub_test_malloc (grub_size_t size); +void grub_test_free (void *ptr); +char *grub_test_strdup (const char *str); +int grub_test_vsprintf (char *str, const char *fmt, va_list args); +int grub_test_printf (const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + +#endif /* ! GRUB_TEST_HEADER */ diff --git a/tests/example_functional_test.c b/tests/example_functional_test.c new file mode 100644 index 000000000..475d1c7f0 --- /dev/null +++ b/tests/example_functional_test.c @@ -0,0 +1,17 @@ +/* All tests need to include test.h for GRUB testing framework. */ +#include + +/* Functional test main method. */ +static void +example_test (void) +{ + /* Check if 1st argument is true and report with default error message. */ + grub_test_assert (1 == 1); + + /* Check if 1st argument is true and report with custom error message. */ + grub_test_assert (2 == 2, "2 equal 2 expected"); + grub_test_assert (2 == 3, "2 is not equal to %d", 3); +} + +/* Register example_test method as a functional test. */ +GRUB_FUNCTIONAL_TEST ("example_functional_test", example_test); diff --git a/tests/example_grub_script_test.in b/tests/example_grub_script_test.in new file mode 100644 index 000000000..93a90a18e --- /dev/null +++ b/tests/example_grub_script_test.in @@ -0,0 +1,3 @@ +#! @builddir@/grub-shell-tester --modules=echo + +echo "hello world" diff --git a/tests/example_scripted_test.in b/tests/example_scripted_test.in new file mode 100644 index 000000000..9ac0424c0 --- /dev/null +++ b/tests/example_scripted_test.in @@ -0,0 +1,3 @@ +#!/bin/sh -e + +true diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c new file mode 100644 index 000000000..e2fad06ff --- /dev/null +++ b/tests/example_unit_test.c @@ -0,0 +1,20 @@ +/* Unit tests are normal programs, so they can include C library. */ +#include + +/* All tests need to include test.h for GRUB testing framework. */ +#include + +/* Unit test main method. */ +static void +example_test (void) +{ + /* Check if 1st argument is true and report with default error message. */ + grub_test_assert (1 == 1); + + /* Check if 1st argument is true and report with custom error message. */ + grub_test_assert (2 == 2, "2 equal 2 expected"); + grub_test_assert (2 == 3, "2 is not equal to %d", 3); +} + +/* Register example_test method as a unit test. */ +GRUB_UNIT_TEST ("example_unit_test", example_test); diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c new file mode 100644 index 000000000..24e82932e --- /dev/null +++ b/tests/lib/functional_test.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +void * +grub_test_malloc (grub_size_t size) +{ + return grub_malloc (size); +} + +void +grub_test_free (void *ptr) +{ + grub_free (ptr); +} + +int +grub_test_vsprintf (char *str, const char *fmt, va_list args) +{ + return grub_vsprintf (str, fmt, args); +} + +char * +grub_test_strdup (const char *str) +{ + return grub_strdup (str); +} + +int +grub_test_printf (const char *fmt, ...) +{ + int r; + va_list ap; + + va_start (ap, fmt); + r = grub_vprintf (fmt, ap); + va_end (ap); + + return r; +} + +static grub_err_t +grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + int i; + int status; + grub_test_t test; + + status = 0; + for (i = 0; i < argc; i++) + { + test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), + args[i]); + status = grub_test_run (test->name) ? : status; + } + + return status; +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT (functional_test) +{ + cmd = grub_register_extcmd ("functional_test", grub_functional_test, + GRUB_COMMAND_FLAG_CMDLINE, 0, + "Run all functional tests.", 0); +} + +GRUB_MOD_FINI (functional_test) +{ + grub_unregister_extcmd (cmd); +} diff --git a/tests/lib/test.c b/tests/lib/test.c new file mode 100644 index 000000000..37f8fff72 --- /dev/null +++ b/tests/lib/test.c @@ -0,0 +1,150 @@ +#include +#include + +struct grub_test_failure +{ + /* The next failure. */ + struct grub_test_failure *next; + + /* The test source file name. */ + char *file; + + /* The test function name. */ + char *funp; + + /* The test call line number. */ + grub_uint32_t line; + + /* The test failure message. */ + char *message; +}; +typedef struct grub_test_failure *grub_test_failure_t; + +grub_test_t grub_test_list; +static grub_test_failure_t failure_list; + +static void +add_failure (const char *file, + const char *funp, + grub_uint32_t line, const char *fmt, va_list args) +{ + char buf[1024]; + grub_test_failure_t failure; + + failure = (grub_test_failure_t) grub_test_malloc (sizeof (*failure)); + if (!failure) + return; + + grub_test_vsprintf (buf, fmt, args); + + failure->file = grub_test_strdup (file ? : ""); + failure->funp = grub_test_strdup (funp ? : ""); + failure->line = line; + failure->message = grub_test_strdup (buf); + + grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure)); +} + +static void +free_failures (void) +{ + grub_test_failure_t item; + + while ((item = grub_list_pop (GRUB_AS_LIST_P (&failure_list))) != 0) + { + if (item->message) + grub_test_free (item->message); + + if (item->funp) + grub_test_free (item->funp); + + if (item->file) + grub_test_free (item->file); + + grub_test_free (item); + } + failure_list = 0; +} + +void +grub_test_nonzero (int cond, + const char *file, + const char *funp, grub_uint32_t line, const char *fmt, ...) +{ + va_list ap; + + if (cond) + return; + + va_start (ap, fmt); + add_failure (file, funp, line, fmt, ap); + va_end (ap); +} + +void +grub_test_register (const char *name, void (*test_main) (void)) +{ + grub_test_t test; + + test = (grub_test_t) grub_test_malloc (sizeof (*test)); + if (!test) + return; + + test->name = grub_test_strdup (name); + test->main = test_main; + + grub_list_push (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); +} + +void +grub_test_unregister (const char *name) +{ + grub_test_t test; + + test = (grub_test_t) grub_named_list_find + (GRUB_AS_NAMED_LIST (grub_test_list), name); + + if (test) + { + grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), + GRUB_AS_LIST (test)); + + if (test->name) + grub_test_free (test->name); + + grub_test_free (test); + } +} + +int +grub_test_run (const char *name) +{ + grub_test_t test; + + auto int print_failure (grub_test_failure_t item); + int print_failure (grub_test_failure_t item) + { + grub_test_failure_t failure = (grub_test_failure_t) item; + + grub_test_printf (" %s:%s:%u: %s\n", + (failure->file ? : ""), + (failure->funp ? : ""), + failure->line, (failure->message ? : "")); + return 0; + } + + test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), name); + if (!test) + return GRUB_ERR_FILE_NOT_FOUND; + + test->main (); + + if (!failure_list) + return GRUB_ERR_NONE; + + grub_test_printf ("%s:\n", test->name); + grub_list_iterate (GRUB_AS_LIST (failure_list), + (grub_list_hook_t) print_failure); + free_failures (); + return GRUB_ERR_TEST_FAILURE; +} diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c new file mode 100644 index 000000000..15bb0da5d --- /dev/null +++ b/tests/lib/unit_test.c @@ -0,0 +1,122 @@ +#include +#include +#include +#include + +#include +#include +#include + +void * +grub_test_malloc (grub_size_t size) +{ + return malloc (size); +} + +void +grub_test_free (void *ptr) +{ + free (ptr); +} + +int +grub_test_vsprintf (char *str, const char *fmt, va_list args) +{ + return vsprintf (str, fmt, args); +} + +char * +grub_test_strdup (const char *str) +{ + return strdup (str); +} + +int +grub_test_printf (const char *fmt, ...) +{ + int r; + va_list ap; + + va_start (ap, fmt); + r = vprintf (fmt, ap); + va_end (ap); + + return r; +} + +int +main (int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + int status = 0; + + extern void grub_unit_test_init (void); + extern void grub_unit_test_fini (void); + + auto int run_test (grub_test_t test); + int run_test (grub_test_t test) + { + status = grub_test_run (test->name) ? : status; + return 0; + } + + grub_unit_test_init (); + grub_list_iterate (GRUB_AS_LIST (grub_test_list), + (grub_list_hook_t) run_test); + grub_unit_test_fini (); + + exit (status); +} + +/* Other misc. functions necessary for successful linking. */ + +char * +grub_env_get (const char *name __attribute__ ((unused))) +{ + return NULL; +} + +grub_err_t +grub_error (grub_err_t n, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + vfprintf (stderr, fmt, ap); + va_end (ap); + + return n; +} + +void * +grub_malloc (grub_size_t size) +{ + return malloc (size); +} + +void +grub_refresh (void) +{ + fflush (stdout); +} + +void +grub_putchar (int c) +{ + putchar (c); +} + +int +grub_getkey (void) +{ + return -1; +} + +void +grub_exit (void) +{ + exit (1); +} + +struct grub_handler_class grub_term_input_class; +struct grub_handler_class grub_term_output_class; diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in new file mode 100644 index 000000000..18f5e79b7 --- /dev/null +++ b/tests/util/grub-shell-tester.in @@ -0,0 +1,109 @@ +#! /bin/bash -e + +# Compares GRUB script output with BASH output. +# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# +# GRUB 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, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB 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 GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +builddir=@builddir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +target_cpu=@target_cpu@ + +# Force build directory components +PATH=${builddir}:$PATH +export PATH + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//'` + modules="$modules,$ms" ;; + --qemu-opts=*) + qs=`echo "$option" | sed -e 's/--qemu-opts=//'` + qemuopts="$qemuopts $qs" ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +outfile1=`mktemp` +@builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1} + +outfile2=`mktemp` +bash ${source} >${outfile2} + +if ! diff -q ${outfile1} ${outfile2} >/dev/null +then + echo "$1: GRUB and BASH outputs (${outfile1}, ${outfile2}) did not match" + status=1 +else + rm -f ${outfile1} ${outfile2} +fi + +exit $status + + diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in new file mode 100644 index 000000000..c1b2ef258 --- /dev/null +++ b/tests/util/grub-shell.in @@ -0,0 +1,125 @@ +#! /bin/bash -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +# +# GRUB 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, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB 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 GRUB. If not, see . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +builddir=@builddir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +target_cpu=@target_cpu@ + +# Force build directory components +PATH=${builddir}:$PATH +export PATH + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//' -e 's/,/ /g'` + modules="$modules $ms" ;; + --qemu-opts=*) + qs=`echo "$option" | sed -e 's/--qemu-opts=//'` + qemuopts="$qemuopts $qs" ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +cfgfile=`mktemp` +cat <${cfgfile} +grubshell=yes +insmod serial +serial +terminal_input serial +terminal_output serial +EOF + +for mod in ${modules} +do + echo "insmod ${mod}" >> ${cfgfile} +done + +cat <>${cfgfile} +source /boot/grub/testcase.cfg +halt +EOF + +isofile=`mktemp` +grub-mkrescue --output=${isofile} --override-directory=${builddir} \ + /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \ + >/dev/null 2>&1 + +outfile=`mktemp` +qemu ${qemuopts} -nographic -serial stdio -cdrom ${isofile} -boot d | tr -d "\r" >${outfile} + +cat $outfile + +rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} +exit 0 + + From 169b1cd2d87102670dfdb1717aef8723143d8c4b Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 16:35:32 +0530 Subject: [PATCH 122/164] added functional tests to make-check --- Makefile.in | 19 +++++++++++++------ conf/tests.rmk | 14 +++++++------- genmk.rb | 6 +++--- include/grub/test.h | 2 +- tests/lib/functional_test.c | 21 +++++++++------------ tests/lib/test.c | 18 +++++++----------- tests/lib/unit_test.c | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Makefile.in b/Makefile.in index 2358060f2..567571897 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,7 +141,6 @@ PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) \ $(lib_SCRIPTS) INFOS = $(info_INFOS) -TESTS = $(check_UNITTESTS) $(check_FUNCTIONALTESTS) $(check_SCRIPTEDTESTS) CLEANFILES = MOSTLYCLEANFILES = @@ -461,19 +460,27 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -$(TESTS): $(check_SCRIPTS) $(check_MODULES) $(check_PROGRAMS) +TESTS = $(check_UTILITIES) $(check_SCRIPTS) $(check_MODULES) +$(TESTS): $(test_framework_SCRIPTS) $(test_framework_MODULES) + check: all $(TESTS) - @list="$(check_UNITTESTS) $(check_SCRIPTEDTESTS)"; \ + @list="$(check_UTILITIES)"; \ for file in $$list; do \ + $(builddir)/$$file; \ + done + @list="$(check_SCRIPTS)"; \ + for file in $$list; do \ + echo "$$file:"; \ if $(builddir)/$$file; then \ echo "$$file: PASS"; \ else \ echo "$$file: FAIL"; \ fi; \ done - @list="$(check_FUNCTIONALTESTS)"; \ - for test in $$list; do \ - echo "insmod functional_test; insmod $test; functional_test" \ + @list="$(check_MODULES)"; \ + for file in $$list; do \ + mod=`basename $$file .mod`; \ + echo "insmod functional_test; insmod $$mod; functional_test" \ | $(builddir)/grub-shell; \ done diff --git a/conf/tests.rmk b/conf/tests.rmk index 03d6acbd1..c35ea0baa 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,38 +4,38 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -check_SCRIPTS += grub-shell +test_framework_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -check_SCRIPTS += grub-shell-tester +test_framework_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester -check_MODULES += functional_test.mod +test_framework_MODULES += functional_test.mod functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Unit tests -check_UNITTESTS += example_unit_test +check_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format # Functional tests -check_FUNCTIONALTESTS += example_functional_test.mod +check_MODULES += example_functional_test.mod example_functional_test_mod_SOURCES = tests/example_functional_test.c example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Scripted tests -check_SCRIPTEDTESTS += example_scripted_test +check_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -check_SCRIPTEDTESTS += example_grub_script_test +check_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in diff --git a/genmk.rb b/genmk.rb index 006fc3d29..b1cce3831 100644 --- a/genmk.rb +++ b/genmk.rb @@ -407,12 +407,12 @@ while l = gets Image.new(prefix, img) end - when 'MODULES', 'FUNCTIONALTESTS' + when 'MODULES' pmodules += args.split(/\s+/).collect do |pmod| PModule.new(prefix, pmod) end - when 'UTILITIES', 'UNITTESTS' + when 'UTILITIES' utils += args.split(/\s+/).collect do |util| Utility.new(prefix, util) end @@ -422,7 +422,7 @@ while l = gets Program.new(prefix, prog) end - when 'SCRIPTS', 'SCRIPTEDTESTS' + when 'SCRIPTS' scripts += args.split(/\s+/).collect do |script| Script.new(prefix, script) end diff --git a/include/grub/test.h b/include/grub/test.h index fbc2bff8c..4b028371b 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -27,7 +27,7 @@ void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); void EXPORT_FUNC (grub_test_unregister) (const char *name); /* Execute a test and print results. */ -int grub_test_run (const char *name); +int grub_test_run (grub_test_t test); /* Test `cond' for nonzero; log failure otherwise. */ void grub_test_nonzero (int cond, const char *file, diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c index 24e82932e..2e03dabc4 100644 --- a/tests/lib/functional_test.c +++ b/tests/lib/functional_test.c @@ -45,19 +45,16 @@ grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { - int i; - int status; - grub_test_t test; + auto int run_test (grub_test_t test); + int run_test (grub_test_t test) + { + grub_test_run (test); + return 0; + } - status = 0; - for (i = 0; i < argc; i++) - { - test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), - args[i]); - status = grub_test_run (test->name) ? : status; - } - - return status; + grub_list_iterate (GRUB_AS_LIST (grub_test_list), + (grub_list_hook_t) run_test); + return GRUB_ERR_NONE; } static grub_extcmd_t cmd; diff --git a/tests/lib/test.c b/tests/lib/test.c index 37f8fff72..562c2f6e4 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -117,10 +117,8 @@ grub_test_unregister (const char *name) } int -grub_test_run (const char *name) +grub_test_run (grub_test_t test) { - grub_test_t test; - auto int print_failure (grub_test_failure_t item); int print_failure (grub_test_failure_t item) { @@ -133,18 +131,16 @@ grub_test_run (const char *name) return 0; } - test = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_test_list), name); - if (!test) - return GRUB_ERR_FILE_NOT_FOUND; - test->main (); - if (!failure_list) - return GRUB_ERR_NONE; - grub_test_printf ("%s:\n", test->name); grub_list_iterate (GRUB_AS_LIST (failure_list), (grub_list_hook_t) print_failure); + if (!failure_list) + grub_test_printf ("%s: PASS\n", test->name); + else + grub_test_printf ("%s: FAIL\n", test->name); + free_failures (); - return GRUB_ERR_TEST_FAILURE; + return GRUB_ERR_NONE; } diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c index 15bb0da5d..59931898a 100644 --- a/tests/lib/unit_test.c +++ b/tests/lib/unit_test.c @@ -56,7 +56,7 @@ main (int argc __attribute__ ((unused)), auto int run_test (grub_test_t test); int run_test (grub_test_t test) { - status = grub_test_run (test->name) ? : status; + status = grub_test_run (test) ? : status; return 0; } From cd943b7587561adf229fe9eb35cd05ad71fcb178 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 8 Jan 2010 15:19:42 +0000 Subject: [PATCH 123/164] 2010-01-08 Robert Millan * util/mkisofs/defaults.h (APPID_DEFAULT): Redefine using PACKAGE_NAME. (SYSTEM_ID_DEFAULT): Set to "GNU" unconditionally. * util/mkisofs/mkisofs.c (main): Readjust --version output. --- ChangeLog | 6 ++++++ util/mkisofs/defaults.h | 38 ++------------------------------------ util/mkisofs/mkisofs.c | 2 +- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 749b0e68c..b1f35e795 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-08 Robert Millan + + * util/mkisofs/defaults.h (APPID_DEFAULT): Redefine using PACKAGE_NAME. + (SYSTEM_ID_DEFAULT): Set to "GNU" unconditionally. + * util/mkisofs/mkisofs.c (main): Readjust --version output. + 2010-01-07 Robert Millan Reset Multiboot 2 support. New loader implements the draft in diff --git a/util/mkisofs/defaults.h b/util/mkisofs/defaults.h index dc9ad380c..2ce9e8d6b 100644 --- a/util/mkisofs/defaults.h +++ b/util/mkisofs/defaults.h @@ -8,7 +8,7 @@ #define PREPARER_DEFAULT NULL #define PUBLISHER_DEFAULT NULL #ifndef APPID_DEFAULT -#define APPID_DEFAULT "MKISOFS ISO 9660 FILESYSTEM BUILDER" +#define APPID_DEFAULT PACKAGE_NAME " ISO 9660 filesystem builder" #endif #define COPYRIGHT_DEFAULT NULL #define BIBLIO_DEFAULT NULL @@ -17,38 +17,4 @@ #define VOLUME_ID_DEFAULT "CDROM" #define BOOT_CATALOG_DEFAULT "boot.catalog" #define BOOT_IMAGE_DEFAULT NULL -#ifdef __QNX__ -#define SYSTEM_ID_DEFAULT "QNX" -#endif - -#ifdef __osf__ -#define SYSTEM_ID_DEFAULT "OSF" -#endif - -#ifdef __sun -#ifdef __SVR4 -#define SYSTEM_ID_DEFAULT "Solaris" -#else -#define SYSTEM_ID_DEFAULT "SunOS" -#endif -#endif - -#ifdef __hpux -#define SYSTEM_ID_DEFAULT "HP-UX" -#endif - -#ifdef __sgi -#define SYSTEM_ID_DEFAULT "SGI" -#endif - -#ifdef _AIX -#define SYSTEM_ID_DEFAULT "AIX" -#endif - -#ifdef _WIN -#define SYSTEM_ID_DEFAULT "Win32" -#endif /* _WIN */ - -#ifndef SYSTEM_ID_DEFAULT -#define SYSTEM_ID_DEFAULT "LINUX" -#endif +#define SYSTEM_ID_DEFAULT "GNU" diff --git a/util/mkisofs/mkisofs.c b/util/mkisofs/mkisofs.c index 588345232..b6084a24a 100644 --- a/util/mkisofs/mkisofs.c +++ b/util/mkisofs/mkisofs.c @@ -914,7 +914,7 @@ int FDECL2(main, int, argc, char **, argv){ exit (0); break; case OPTION_VERSION: - printf ("%s (%s %s)\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); + printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); exit (0); break; case OPTION_NOSPLIT_SL_COMPONENT: From b394b2cab89ea8882345624286815ef1b9a81e88 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 8 Jan 2010 15:22:40 +0000 Subject: [PATCH 124/164] 2010-01-08 Robert Millan * src/mkisofs.c: Remove `ifdef linux' portability kludge. --- ChangeLog | 6 +++++- util/mkisofs/mkisofs.c | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1f35e795..e91e87536 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2010-01-08 Robert Millan +2010-01-08 Robert Millan + + * src/mkisofs.c: Remove `ifdef linux' portability kludge. + +2010-01-08 Robert Millan * util/mkisofs/defaults.h (APPID_DEFAULT): Redefine using PACKAGE_NAME. (SYSTEM_ID_DEFAULT): Set to "GNU" unconditionally. diff --git a/util/mkisofs/mkisofs.c b/util/mkisofs/mkisofs.c index b6084a24a..69b4b3d0d 100644 --- a/util/mkisofs/mkisofs.c +++ b/util/mkisofs/mkisofs.c @@ -26,12 +26,7 @@ #include "config.h" #include "mkisofs.h" #include "match.h" - -#ifdef linux -#include -#else #include "getopt.h" -#endif #include "iso9660.h" #include From 1afc27d06b9030b83f3398edd13344d8fbe81c24 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 21:28:57 +0530 Subject: [PATCH 125/164] added changelog file --- ChangeLog.unit-testing-framework | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ChangeLog.unit-testing-framework diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework new file mode 100644 index 000000000..a451108c4 --- /dev/null +++ b/ChangeLog.unit-testing-framework @@ -0,0 +1,26 @@ +2010-01-08 BVK Chaitanya + + Unit testing framework for GRUB. + + * Makefile.in: Test framework build rules for 'make check'. + * conf/tests.rmk: Build rules for individual tests and framework. + + * include/grub/test.h: Header file for whitebox tests. + * tests/lib/functional_test.c: Framework support for whitebox + functional tests. + * tests/lib/test.c: Common whitebox testing code for unit and + functional tests. + * tests/lib/unit_test.c: Framework support for whitebox unit + tests. + + * tests/util/grub-shell-tester.in: Support utility for grub-script + tests. + * tests/util/grub-shell.in: Utility to execute grub-script + commands in a Qemu instance. + + * tests/example_functional_test.c: Example whitebox functional + test. + * tests/example_grub_script_test.in: Example grub-script test. + * tests/example_scripted_test.in: Example scripted test. + * tests/example_unit_test.c: Example whitebox unit test. + From 5cc318eb3532f333dc324627dc977fe2f5bef40a Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 8 Jan 2010 22:06:46 +0530 Subject: [PATCH 126/164] replaced __func__ with simpler __FUNCTION__ macro --- include/grub/test.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/include/grub/test.h b/include/grub/test.h index 4b028371b..b4851bbf6 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -35,22 +35,10 @@ void grub_test_nonzero (int cond, const char *file, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); -#ifdef __STDC_VERSION__ -#if __STDC_VERSION__ < 199901L -# if __GNUC__ >= 2 -# define __func__ __FUNCTION__ -# else -# define __func__ "" -# endif -#endif -#else -#define __func__ "" -#endif - /* Macro to fill in location details and an optional error message. */ -#define grub_test_assert(cond, ...) \ - grub_test_nonzero(cond, __FILE__, __func__, __LINE__, \ - ## __VA_ARGS__, \ +#define grub_test_assert(cond, ...) \ + grub_test_nonzero(cond, __FILE__, __FUNCTION__, __LINE__, \ + ## __VA_ARGS__, \ "assert failed: %s", #cond) /* Macro to define a unit test. */ From 809bbfebfe4b03402be3bbaaf631ee4d562262d1 Mon Sep 17 00:00:00 2001 From: carles Date: Fri, 8 Jan 2010 21:35:38 +0000 Subject: [PATCH 127/164] 2010-01-08 Carles Pina i Estany * loader/efi/appleloader.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'. --- ChangeLog | 39 +++++++++++++++++++++++++++++++++ loader/efi/appleloader.c | 3 ++- loader/efi/chainloader.c | 3 ++- loader/i386/efi/linux.c | 7 +++--- loader/i386/ieee1275/linux.c | 7 +++--- loader/i386/linux.c | 7 +++--- loader/i386/pc/chainloader.c | 3 ++- loader/i386/pc/linux.c | 7 +++--- loader/i386/xnu.c | 3 ++- loader/multiboot_loader.c | 7 +++--- loader/powerpc/ieee1275/linux.c | 5 +++-- loader/sparc64/ieee1275/linux.c | 7 +++--- loader/xnu.c | 21 +++++++++--------- po/POTFILES | 12 ++++++++++ 14 files changed, 97 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index e91e87536..43accdc25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,42 @@ +2010-01-08 Carles Pina i Estany + + * loader/efi/appleloader.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * loader/efi/chainloader.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/efi/linux.c: Include `'. + (grub_cmd_linux): Capitalise Linux. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/ieee1275/linux.c: Include `'. + (grub_cmd_linux): Capitalise Linux. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/linux.c: Include `'. + (grub_cmd_linux): Capitalise Linux. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/pc/chainloader.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/pc/linux.c: Include `'. + (grub_cmd_linux): Capitalise Linux. + (GRUB_MOD_INIT): Gettextizze. + * loader/i386/xnu.c: Include `'. + (grub_cpu_xnu_init): Gettextizze. + * loader/multiboot_loader.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * loader/powerpc/ieee1275/linux.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * loader/sparc64/ieee1275/linux.c: Include `'. + (grub_linux_load64): Capitalise Linux. + (GRUB_MOD_INIT): Gettextizze. + * loader/xnu.c: Include `'. + (GRUB_MOD_INIT): Gettextizze. + * po/POTFILES: Add `loader/efi/appleloader.c', + `loader/efi/chainloader.c', `loader/i386/efi/linux.c', + `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', + `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', + `loader/i386/xnu.c', `loader/multiboot_loader.c', + `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' + and `loader/xnu.c'. + 2010-01-08 Robert Millan * src/mkisofs.c: Remove `ifdef linux' portability kludge. diff --git a/loader/efi/appleloader.c b/loader/efi/appleloader.c index 114a0a506..dc42683a6 100644 --- a/loader/efi/appleloader.c +++ b/loader/efi/appleloader.c @@ -25,6 +25,7 @@ #include #include #include +#include static grub_dl_t my_mod; @@ -321,7 +322,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(appleloader) { cmd = grub_register_command ("appleloader", grub_cmd_appleloader, - "[OPTS]", "Boot legacy system."); + "[OPTS]", N_("Boot legacy system.")); my_mod = mod; } diff --git a/loader/efi/chainloader.c b/loader/efi/chainloader.c index 559c3f52a..a095ad931 100644 --- a/loader/efi/chainloader.c +++ b/loader/efi/chainloader.c @@ -33,6 +33,7 @@ #include #include #include +#include static grub_dl_t my_mod; @@ -336,7 +337,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(chainloader) { cmd = grub_register_command ("chainloader", grub_cmd_chainloader, - 0, "Load another boot loader."); + 0, N_("Load another boot loader.")); my_mod = mod; } diff --git a/loader/i386/efi/linux.c b/loader/i386/efi/linux.c index 1c256e377..848c1ef7d 100644 --- a/loader/i386/efi/linux.c +++ b/loader/i386/efi/linux.c @@ -33,6 +33,7 @@ #include #include #include +#include #define GRUB_LINUX_CL_OFFSET 0x1000 #define GRUB_LINUX_CL_END_OFFSET 0x2000 @@ -619,7 +620,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header"); + grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); goto fail; } @@ -989,9 +990,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { cmd_linux = grub_register_command ("linux", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index e8a6f1a52..7d556ee00 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -32,6 +32,7 @@ #include #include #include +#include #define GRUB_OFW_LINUX_PARAMS_ADDR 0x90000 #define GRUB_OFW_LINUX_KERNEL_ADDR 0x100000 @@ -165,7 +166,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header"); + grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); goto fail; } @@ -276,9 +277,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { cmd_linux = grub_register_command ("linux", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 899216783..4375a1162 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -33,6 +33,7 @@ #include #include #include +#include #define GRUB_LINUX_CL_OFFSET 0x1000 #define GRUB_LINUX_CL_END_OFFSET 0x2000 @@ -613,7 +614,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header"); + grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); goto fail; } @@ -982,9 +983,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { cmd_linux = grub_register_command ("linux", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index a153d80a9..81cfddac1 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -32,6 +32,7 @@ #include #include #include +#include static grub_dl_t my_mod; static int boot_drive; @@ -146,7 +147,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(chainloader) { cmd = grub_register_command ("chainloader", grub_cmd_chainloader, - 0, "Load another boot loader."); + 0, N_("Load another boot loader.")); my_mod = mod; } diff --git a/loader/i386/pc/linux.c b/loader/i386/pc/linux.c index 77b7966bf..24bb39555 100644 --- a/loader/i386/pc/linux.c +++ b/loader/i386/pc/linux.c @@ -30,6 +30,7 @@ #include #include #include +#include #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF @@ -81,7 +82,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header"); + grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); goto fail; } @@ -383,10 +384,10 @@ GRUB_MOD_INIT(linux16) { cmd_linux = grub_register_command ("linux16", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd16", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/i386/xnu.c b/loader/i386/xnu.c index f71e2c306..23a8a6f7b 100644 --- a/loader/i386/xnu.c +++ b/loader/i386/xnu.c @@ -32,6 +32,7 @@ #include #include #include +#include char grub_xnu_cmdline[1024]; grub_uint32_t grub_xnu_heap_will_be_at; @@ -1026,7 +1027,7 @@ grub_cpu_xnu_init (void) { cmd_devprop_load = grub_register_command ("xnu_devprop_load", grub_cmd_devprop_load, - 0, "Load device-properties dump."); + 0, N_("Load device-properties dump.")); } void diff --git a/loader/multiboot_loader.c b/loader/multiboot_loader.c index 790f14d9a..6d042fa81 100644 --- a/loader/multiboot_loader.c +++ b/loader/multiboot_loader.c @@ -26,6 +26,7 @@ #include #include #include +#include grub_dl_t my_mod; @@ -129,15 +130,15 @@ GRUB_MOD_INIT(multiboot) cmd_multiboot = #ifdef GRUB_USE_MULTIBOOT2 grub_register_command ("multiboot2", grub_cmd_multiboot_loader, - 0, "Load a multiboot 2 kernel."); + 0, N_("Load a multiboot 2 kernel.")); #else grub_register_command ("multiboot", grub_cmd_multiboot_loader, - 0, "Load a multiboot kernel."); + 0, N_("Load a multiboot kernel.")); #endif cmd_module = grub_register_command ("module", grub_cmd_module_loader, - 0, "Load a multiboot module."); + 0, N_("Load a multiboot module.")); my_mod = mod; } diff --git a/loader/powerpc/ieee1275/linux.c b/loader/powerpc/ieee1275/linux.c index 085f5c026..39ba2ad0a 100644 --- a/loader/powerpc/ieee1275/linux.c +++ b/loader/powerpc/ieee1275/linux.c @@ -26,6 +26,7 @@ #include #include #include +#include #define ELF32_LOADMASK (0xc0000000UL) #define ELF64_LOADMASK (0xc000000000000000ULL) @@ -349,9 +350,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { cmd_linux = grub_register_command ("linux", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 6ffad202e..4d5723c19 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -27,6 +27,7 @@ #include #include #include +#include static grub_dl_t my_mod; @@ -263,7 +264,7 @@ grub_linux_load64 (grub_elf_t elf) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't map physical memory"); - grub_dprintf ("loader", "Loading linux at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n", + grub_dprintf ("loader", "Loading Linux at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n", linux_addr, paddr, linux_size); linux_paddr = paddr; @@ -516,9 +517,9 @@ GRUB_MOD_INIT(linux) fetch_translations (); cmd_linux = grub_register_command ("linux", grub_cmd_linux, - 0, "Load Linux."); + 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, - 0, "Load initrd."); + 0, N_("Load initrd.")); my_mod = mod; } diff --git a/loader/xnu.c b/loader/xnu.c index f3ae3888a..c3dcee3ed 100644 --- a/loader/xnu.c +++ b/loader/xnu.c @@ -32,6 +32,7 @@ #include #include #include +#include struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0; static int driverspackagenum = 0; @@ -1404,25 +1405,25 @@ static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume, cmd_splash; GRUB_MOD_INIT(xnu) { cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0, - "Load XNU image."); + N_("Load XNU image.")); cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64, - 0, "Load 64-bit XNU image."); + 0, N_("Load 64-bit XNU image.")); cmd_mkext = grub_register_command ("xnu_mkext", grub_cmd_xnu_mkext, 0, - "Load XNU extension package."); + N_("Load XNU extension package.")); cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0, - "Load XNU extension."); + N_("Load XNU extension.")); cmd_kextdir = grub_register_command ("xnu_kextdir", grub_cmd_xnu_kextdir, - "DIRECTORY [OSBundleRequired]", - "Load XNU extension directory."); + N_("DIRECTORY [OSBundleRequired]"), + N_("Load XNU extension directory.")); cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0, - "Load XNU ramdisk. " - "It will be seen as md0."); + N_("Load XNU ramdisk. " + "It will be seen as md0.")); cmd_splash = grub_register_command ("xnu_splash", grub_cmd_xnu_splash, 0, - "Load a splash image for XNU."); + N_("Load a splash image for XNU.")); #ifndef GRUB_UTIL cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume, - 0, "Load XNU hibernate image."); + 0, N_("Load XNU hibernate image.")); #endif grub_cpu_xnu_init (); diff --git a/po/POTFILES b/po/POTFILES index c4ae9d562..32927256c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -53,7 +53,19 @@ hello/hello.c lib/arg.c +loader/efi/appleloader.c +loader/efi/chainloader.c loader/i386/bsd.c +loader/i386/efi/linux.c +loader/i386/ieee1275/linux.c +loader/i386/linux.c +loader/i386/pc/chainloader.c +loader/i386/pc/linux.c +loader/i386/xnu.c +loader/multiboot_loader.c +loader/powerpc/ieee1275/linux.c +loader/sparc64/ieee1275/linux.c +loader/xnu.c normal/auth.c normal/color.c From 5ce0a83a15fa27b89f6725293710c394679d0fdf Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 9 Jan 2010 20:20:27 +0000 Subject: [PATCH 128/164] 2010-01-09 Carles Pina i Estany * gettext/gettext.c (GRUB_MOD_INIT): Gettextizze. --- ChangeLog | 4 ++++ gettext/gettext.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43accdc25..4ebdb2a48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-09 Carles Pina i Estany + + * gettext/gettext.c (GRUB_MOD_INIT): Gettextizze. + 2010-01-08 Carles Pina i Estany * loader/efi/appleloader.c: Include `'. diff --git a/gettext/gettext.c b/gettext/gettext.c index 165feb332..6fa6271f2 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -347,8 +347,8 @@ GRUB_MOD_INIT (gettext) grub_gettext_init_ext (lang); grub_register_command_p1 ("gettext", grub_cmd_translate, - "STRING", - "Translates the string with the current settings."); + N_("STRING"), + N_("Translates the string with the current settings.")); /* Reload .mo file information if lang changes. */ grub_register_variable_hook ("lang", NULL, grub_gettext_env_write_lang); From 1a064917fef933ad4ac943ea4c4841b5efd0b949 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 9 Jan 2010 22:02:00 +0000 Subject: [PATCH 129/164] 2010-01-09 Robert Millan Make loader output a bit more user-friendly. * util/grub.d/10_hurd.in: Print message indicating that GNU Mach is being loaded. Likewise for the Hurd. * util/grub.d/10_kfreebsd.in (kfreebsd_entry): Print message indicating that kernel of FreeBSD ${version} is being loaded. * loader/i386/linux.c (grub_cmd_linux): Move debug info to grub_dprintf(). (grub_cmd_initrd): Likewise. * util/grub.d/10_linux.in (linux_entry): Print message indicating that Linux ${version} is being loaded. Likewise for initrd. --- ChangeLog | 16 ++++++++++++++++ loader/i386/linux.c | 10 +++++----- util/grub.d/10_hurd.in | 10 ++++++---- util/grub.d/10_kfreebsd.in | 7 ++++--- util/grub.d/10_linux.in | 4 +++- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ebdb2a48..6f3598e6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-01-09 Robert Millan + + Make loader output a bit more user-friendly. + + * util/grub.d/10_hurd.in: Print message indicating that GNU Mach + is being loaded. Likewise for the Hurd. + + * util/grub.d/10_kfreebsd.in (kfreebsd_entry): Print message indicating + that kernel of FreeBSD ${version} is being loaded. + + * loader/i386/linux.c (grub_cmd_linux): Move debug info to + grub_dprintf(). + (grub_cmd_initrd): Likewise. + * util/grub.d/10_linux.in (linux_entry): Print message indicating + that Linux ${version} is being loaded. Likewise for initrd. + 2010-01-09 Carles Pina i Estany * gettext/gettext.c (GRUB_MOD_INIT): Gettextizze. diff --git a/loader/i386/linux.c b/loader/i386/linux.c index 4375a1162..7c4b061b8 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -713,8 +713,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE); - grub_printf (" [Linux-bzImage, setup=0x%x, size=0x%x]\n", - (unsigned) real_size, (unsigned) prot_size); + grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n", + (unsigned) real_size, (unsigned) prot_size); /* Look for memory size and video mode specified on the command line. */ linux_mem_size = 0; @@ -964,8 +964,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - grub_printf (" [Initrd, addr=0x%x, size=0x%x]\n", - (unsigned) addr, (unsigned) size); + grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n", + (unsigned) addr, (unsigned) size); lh->ramdisk_image = addr; lh->ramdisk_size = size; diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 19fd8ec27..ff883f461 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,16 +73,18 @@ menuentry "${OS}" { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF - multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} + echo $(gettext "Loading GNU Mach ...") + multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} EOF prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" cat << EOF - module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ + echo $(gettext "Loading the Hurd ...") + module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ --multiboot-command-line='\${kernel-command-line}' \\ --host-priv-port='\${host-port}' \\ --device-master-port='\${device-port}' \\ --exec-server-task='\${exec-task}' -T typed '\${root}' \\ '\$(task-create)' '\$(task-resume)' - module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' + module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' } EOF diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 1329bba1f..0da7cabbc 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,12 +44,13 @@ kfreebsd_entry () fi printf '%s\n' "${prepare_boot_cache}" cat << EOF - kfreebsd ${rel_dirname}/${basename} + echo $(printf "$(gettext "Loading kernel of FreeBSD %s ...")" ${version}) + kfreebsd ${rel_dirname}/${basename} EOF if test -n "${devices}" ; then cat << EOF - kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename} + kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename} EOF fi diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 5fea5338e..0accf8f23 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -1,7 +1,7 @@ #! /bin/sh -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -64,10 +64,12 @@ linux_entry () fi printf '%s\n' "${prepare_boot_cache}" cat << EOF + echo $(printf "$(gettext "Loading Linux %s ...")" ${version}) linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then cat << EOF + echo $(gettext "Loading initial ramdisk ...") initrd ${rel_dirname}/${initrd} EOF fi From 822873a7da694d3336505bb31e4bc7cd7e019974 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 9 Jan 2010 23:42:17 +0100 Subject: [PATCH 130/164] Eliminate grub_term_register_{input,output}_active. Default terminals are automatically activated because they're the only terminal that has been loaded. This solution is temporary. In the future, all terminals should auto-enable, but this is non-trivial due to resource conflict, and it shouldn't prevent merge in trunk. --- ChangeLog.multiterm | 16 +------------- genterminallist.sh | 4 +--- include/grub/term.h | 45 +++++++++++++++++++------------------- term/efi/console.c | 4 ++-- term/gfxterm.c | 4 ---- term/i386/pc/at_keyboard.c | 4 ---- term/i386/pc/console.c | 4 ++-- term/i386/pc/vga_text.c | 6 +---- term/ieee1275/ofconsole.c | 4 ++-- util/console.c | 4 ++-- 10 files changed, 33 insertions(+), 62 deletions(-) diff --git a/ChangeLog.multiterm b/ChangeLog.multiterm index 3228f902a..d16bb2222 100644 --- a/ChangeLog.multiterm +++ b/ChangeLog.multiterm @@ -1,5 +1,5 @@ 2010-01-07 Vladimir Serbinenko -2010-01-07 Robert Millan +2010-01-09 Robert Millan Support for multiple terminals. @@ -58,8 +58,6 @@ (grub_term_inputs_disabled): Likewise. (grub_term_outputs): Likewise. (grub_term_inputs): Likewise. - (grub_term_register_input_active): New function. - (grub_term_register_output_active): Likewise. (grub_term_register_input): Rewritten. (grub_term_register_output): Likewise. (grub_term_unregister_input): Likewise. @@ -102,20 +100,8 @@ * normal/menu_text.c: Likewise. * normal/menu_viewer.c: Removed. All users updated. * normal/term.c: New file. - * term/efi/console.c (grub_console_init): Use - grub_term_register_input_active and grub_term_register_output_active. - * term/gfxterm.c (GRUB_MOD_INIT) [GRUB_MACHINE_MIPS_YEELOONG]: Likewise. - * term/i386/pc/at_keyboard.c (GRUB_MOD_INIT) - [GRUB_MACHINE_MIPS_YEELOONG] || [GRUB_MACHINE_COREBOOT] - || [GRUB_MACHINE_QEMU]: Likewise. - * term/i386/pc/vga_text.c (GRUB_MOD_INIT) [GRUB_MACHINE_COREBOOT] - || [GRUB_MACHINE_QEMU]: Likewise. - * term/i386/pc/console.c (grub_console_init): Likewise. - * term/ieee1275/ofconsole.c (grub_console_init): Likewise. * util/console.c: Change order of includes to workaround a bug in ncurses headers. - (grub_console_init): Use - grub_term_register_input_active and grub_term_register_output_active. * term/terminfo.c: New argument oterm on all exported functions. All users updated. * util/grub-editenv.c (grub_term_input_class): Removed. diff --git a/genterminallist.sh b/genterminallist.sh index eb0de0c32..60f5b9105 100644 --- a/genterminallist.sh +++ b/genterminallist.sh @@ -1,6 +1,6 @@ #! /bin/sh # -# Copyright (C) 2009 Free Software Foundation, Inc. +# Copyright (C) 2009,2010 Free Software Foundation, Inc. # # This script is free software; the author # gives unlimited permission to copy and/or distribute it, @@ -17,6 +17,4 @@ module=$1 grep -v "^#" | sed -n \ -e "/grub_term_register_input *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $module/;p;}" \ - -e "/grub_term_register_input_active *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $module/;p;}" \ -e "/grub_term_register_output *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $module/;p;}" \ - -e "/grub_term_register_output_active *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $module/;p;}" diff --git a/include/grub/term.h b/include/grub/term.h index 1c57a4ede..3d644b848 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -198,38 +198,37 @@ extern struct grub_term_input *EXPORT_VAR(grub_term_inputs_disabled); extern struct grub_term_output *EXPORT_VAR(grub_term_outputs); extern struct grub_term_input *EXPORT_VAR(grub_term_inputs); -static inline void -grub_term_register_input_active (const char *name __attribute__ ((unused)), - grub_term_input_t term) -{ - if (term->init) - term->init (); - grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); -} - static inline void grub_term_register_input (const char *name __attribute__ ((unused)), grub_term_input_t term) { - grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), - GRUB_AS_LIST (term)); -} - -static inline void -grub_term_register_output_active (const char *name __attribute__ ((unused)), - grub_term_output_t term) -{ - if (term->init) - term->init (); - grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); + if (grub_term_inputs) + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); + else + { + /* If this is the first terminal, enable automatically. */ + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); + } } static inline void grub_term_register_output (const char *name __attribute__ ((unused)), grub_term_output_t term) { - grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), - GRUB_AS_LIST (term)); + if (grub_term_outputs) + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); + else + { + /* If this is the first terminal, enable automatically. */ + if (term->init) + term->init (); + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), + GRUB_AS_LIST (term)); + } } static inline void diff --git a/term/efi/console.c b/term/efi/console.c index dc07c401e..264770cae 100644 --- a/term/efi/console.c +++ b/term/efi/console.c @@ -365,8 +365,8 @@ grub_console_init (void) return; } - grub_term_register_input_active ("console", &grub_console_term_input); - grub_term_register_output_active ("console", &grub_console_term_output); + grub_term_register_input ("console", &grub_console_term_input); + grub_term_register_output ("console", &grub_console_term_output); } void diff --git a/term/gfxterm.c b/term/gfxterm.c index 2a7886aa0..fa19a5d85 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -953,11 +953,7 @@ static grub_command_t cmd; GRUB_MOD_INIT(term_gfxterm) { -#ifdef GRUB_MACHINE_MIPS_YEELOONG - grub_term_register_output_active ("gfxterm", &grub_video_term); -#else grub_term_register_output ("gfxterm", &grub_video_term); -#endif cmd = grub_register_command ("background_image", grub_gfxterm_background_image_cmd, 0, "Load background image for active terminal."); diff --git a/term/i386/pc/at_keyboard.c b/term/i386/pc/at_keyboard.c index 594ed6787..6382c954a 100644 --- a/term/i386/pc/at_keyboard.c +++ b/term/i386/pc/at_keyboard.c @@ -278,11 +278,7 @@ static struct grub_term_input grub_at_keyboard_term = GRUB_MOD_INIT(at_keyboard) { -#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_YEELOONG) - grub_term_register_input_active ("at_keyboard", &grub_at_keyboard_term); -#else grub_term_register_input ("at_keyboard", &grub_at_keyboard_term); -#endif } GRUB_MOD_FINI(at_keyboard) diff --git a/term/i386/pc/console.c b/term/i386/pc/console.c index 3c0fcccad..43cfe2f2a 100644 --- a/term/i386/pc/console.c +++ b/term/i386/pc/console.c @@ -71,8 +71,8 @@ static struct grub_term_output grub_console_term_output = void grub_console_init (void) { - grub_term_register_output_active ("console", &grub_console_term_output); - grub_term_register_input_active ("console", &grub_console_term_input); + grub_term_register_output ("console", &grub_console_term_output); + grub_term_register_input ("console", &grub_console_term_input); } void diff --git a/term/i386/pc/vga_text.c b/term/i386/pc/vga_text.c index 01191cef0..170f74de8 100644 --- a/term/i386/pc/vga_text.c +++ b/term/i386/pc/vga_text.c @@ -163,16 +163,12 @@ static struct grub_term_output grub_vga_text_term = .setcolorstate = grub_console_setcolorstate, .setcolor = grub_console_setcolor, .getcolor = grub_console_getcolor, - .setcursor = grub_vga_text_setcursor + .setcursor = grub_vga_text_setcursor, }; GRUB_MOD_INIT(vga_text) { -#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) - grub_term_register_output_active ("vga_text", &grub_vga_text_term); -#else grub_term_register_output ("vga_text", &grub_vga_text_term); -#endif } GRUB_MOD_FINI(vga_text) diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 44cbb763d..3977c6286 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -420,8 +420,8 @@ static struct grub_term_output grub_ofconsole_term_output = void grub_console_init (void) { - grub_term_register_input_active ("ofconsole", &grub_ofconsole_term_input); - grub_term_register_output_active ("ofconsole", &grub_ofconsole_term_output); + grub_term_register_input ("ofconsole", &grub_ofconsole_term_input); + grub_term_register_output ("ofconsole", &grub_ofconsole_term_output); } void diff --git a/util/console.c b/util/console.c index 73195765e..382fd7f89 100644 --- a/util/console.c +++ b/util/console.c @@ -373,8 +373,8 @@ static struct grub_term_output grub_ncurses_term_output = void grub_console_init (void) { - grub_term_register_output_active ("console", &grub_ncurses_term_output); - grub_term_register_input_active ("console", &grub_ncurses_term_input); + grub_term_register_output ("console", &grub_ncurses_term_output); + grub_term_register_input ("console", &grub_ncurses_term_input); } void From cdec4d31936dae6af0db3ce99b0f4f1cda0686e2 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 10 Jan 2010 00:47:19 +0000 Subject: [PATCH 131/164] 2010-01-09 Robert Millan Fix grub-emu build. * conf/any-emu.rmk (grub_emu_SOURCES): Remove `kern/reader.c'. --- ChangeLog | 6 ++++++ conf/any-emu.rmk | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d5ca433a2..9879050bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-09 Robert Millan + + Fix grub-emu build. + + * conf/any-emu.rmk (grub_emu_SOURCES): Remove `kern/reader.c'. + 2010-01-07 Vladimir Serbinenko 2010-01-09 Robert Millan diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index bd1798946..cee9e8338 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -23,7 +23,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \ kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ - kern/partition.c kern/reader.c kern/term.c \ + kern/partition.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ From 0e60bae74e46ff8eb6f4b2745ede4e76736e2169 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 10 Jan 2010 01:10:39 +0000 Subject: [PATCH 132/164] 2010-01-10 Robert Millan Fix i386-ieee1275 build. * loader/i386/ieee1275/linux.c (grub_linux_boot): Use grub_term_width() and grub_term_height() for video_{width,height} initialization. --- ChangeLog | 9 ++++++++- loader/i386/ieee1275/linux.c | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9879050bf..f5ff60553 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ -2010-01-09 Robert Millan +2010-01-10 Robert Millan + + Fix i386-ieee1275 build. + + * loader/i386/ieee1275/linux.c (grub_linux_boot): Use grub_term_width() + and grub_term_height() for video_{width,height} initialization. + +2010-01-10 Robert Millan Fix grub-emu build. diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index 7d556ee00..f6352bb9f 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux zImage or bzImage */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,8 +110,8 @@ grub_linux_boot (void) params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET; - params->video_width = (grub_getwh () >> 8); - params->video_height = (grub_getwh () & 0xff); + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); params->font_size = 16; params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE; From f0d0c0b726d1a947b4bd50f45e42d1052633eb11 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 10 Jan 2010 01:43:42 +0000 Subject: [PATCH 133/164] 2010-01-10 Robert Millan * loader/i386/ieee1275/linux.c (grub_linux_boot): Rework video position initialization with similar approach as with other Linux loaders. --- ChangeLog | 5 +++++ loader/i386/ieee1275/linux.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5ff60553..5f141d6a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-10 Robert Millan + + * loader/i386/ieee1275/linux.c (grub_linux_boot): Rework video position + initialization with similar approach as with other Linux loaders. + 2010-01-10 Robert Millan Fix i386-ieee1275 build. diff --git a/loader/i386/ieee1275/linux.c b/loader/i386/ieee1275/linux.c index f6352bb9f..8780804fd 100644 --- a/loader/i386/ieee1275/linux.c +++ b/loader/i386/ieee1275/linux.c @@ -110,8 +110,29 @@ grub_linux_boot (void) params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET; - params->video_width = grub_term_width (term); - params->video_height = grub_term_height (term); + { + grub_term_output_t term; + int found = 0; + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "ofconsole") == 0) + { + grub_uint16_t pos = grub_term_getxy (term); + params->video_cursor_x = pos >> 8; + params->video_cursor_y = pos & 0xff; + params->video_width = grub_term_width (term); + params->video_height = grub_term_height (term); + found = 1; + break; + } + if (!found) + { + params->video_cursor_x = 0; + params->video_cursor_y = 0; + params->video_width = 80; + params->video_height = 25; + } + } + params->font_size = 16; params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE; From cd0514794a7948f5166c26cf7383f430e6a04b6a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 18:58:18 +0100 Subject: [PATCH 134/164] MAnipulate mbi in abstract way --- ChangeLog.abstractmbi | 25 +++ conf/i386-coreboot.rmk | 6 +- conf/i386-pc.rmk | 4 +- include/grub/multiboot.h | 13 ++ loader/i386/multiboot.c | 320 +++++++------------------------- loader/i386/multiboot_elfxx.c | 5 +- loader/i386/multiboot_mbi.c | 336 ++++++++++++++++++++++++++++++++++ 7 files changed, 453 insertions(+), 256 deletions(-) create mode 100644 ChangeLog.abstractmbi create mode 100644 loader/i386/multiboot_mbi.c diff --git a/ChangeLog.abstractmbi b/ChangeLog.abstractmbi new file mode 100644 index 000000000..a5ff55b08 --- /dev/null +++ b/ChangeLog.abstractmbi @@ -0,0 +1,25 @@ +2010-01-10 Vladimir Serbinenko + + * conf/i386-coreboot.rmk (multiboot_mod_SOURCES): + Add loader/i386/multiboot_mbi.c. + (multiboot2_mod_SOURCES): Likewise. + * conf/i386-pc.rmk (multiboot_mod_SOURCES): Likewise. + (multiboot2_mod_SOURCES): Likewise. + * include/grub/multiboot.h (grub_multiboot_get_mbi_size): New proto. + (grub_multiboot_make_mbi): Likewise. + (grub_multiboot_free_mbi): Likewise. + (grub_multiboot_init_mbi): Likewise. + (grub_multiboot_add_module): Likewise. + (grub_multiboot_set_bootdev): Likewise. + * loader/i386/multiboot.c (mbi): Removed. + (mbi_dest): Likewise. + (alloc_mbi): New variable. + (grub_multiboot_payload_size): Removed. All users updated. + (grub_multiboot_pure_size): New variable. + (grub_multiboot_boot): Use grub_multiboot_make_mbi. + (grub_multiboot_unload): Use grub_multiboot_free_mbi. + (grub_get_multiboot_mmap_len): Moved to loader/i386/multiboot_mbi.c. + (grub_fill_multiboot_mmap): Likewise. + (grub_multiboot_get_bootdev): Likewise. + (grub_multiboot): Use multiboot_mbi functions. + * loader/i386/multiboot_mbi.c: New file. diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 95ee79436..d73c9f0e2 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -142,14 +142,16 @@ serial_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) pkglib_MODULES += multiboot2.mod multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/multiboot_loader.c \ + loader/i386/multiboot_mbi.c multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 4215f0a34..2a69571aa 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -203,6 +203,7 @@ serial_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += multiboot.mod multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ loader/multiboot_loader.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) @@ -210,7 +211,8 @@ multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) pkglib_MODULES += multiboot2.mod multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index 041ee1f18..f9edb0c59 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -29,7 +29,20 @@ #include #endif +#include +#include + void grub_multiboot (int argc, char *argv[]); void grub_module (int argc, char *argv[]); +grub_size_t grub_multiboot_get_mbi_size (void); +grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, + grub_off_t buf_off, grub_size_t bufsize); +void grub_multiboot_free_mbi (void); +grub_err_t grub_multiboot_init_mbi (int argc, char *argv[]); +grub_err_t grub_multiboot_add_module (grub_addr_t start, grub_size_t size, + int argc, char *argv[]); +void grub_multiboot_set_bootdev (void); + + #endif /* ! GRUB_MULTIBOOT_HEADER */ diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index f4869594e..2a69327b4 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -45,31 +45,24 @@ #include #include #include -#ifdef GRUB_MACHINE_PCBIOS -#include -#include -#include -#include -#endif #include extern grub_dl_t my_mod; -static struct multiboot_info *mbi, *mbi_dest; - -static grub_size_t code_size; +static grub_size_t code_size, alloc_mbi; char *grub_multiboot_payload_orig; grub_addr_t grub_multiboot_payload_dest; -grub_size_t grub_multiboot_payload_size; +grub_size_t grub_multiboot_pure_size; grub_uint32_t grub_multiboot_payload_eip; static grub_err_t grub_multiboot_boot (void) { + grub_size_t mbi_size; + grub_err_t err; struct grub_relocator32_state state = { .eax = MULTIBOOT_BOOTLOADER_MAGIC, - .ebx = PTR_TO_UINT32 (mbi_dest), .ecx = 0, .edx = 0, .eip = grub_multiboot_payload_eip, @@ -78,6 +71,24 @@ grub_multiboot_boot (void) .esp = 0x7ff00 }; + mbi_size = grub_multiboot_get_mbi_size (); + if (alloc_mbi < mbi_size) + { + grub_multiboot_payload_orig + = grub_relocator32_realloc (grub_multiboot_payload_orig, + grub_multiboot_pure_size + mbi_size); + if (!grub_multiboot_payload_orig) + return grub_errno; + alloc_mbi = mbi_size; + } + + state.ebx = grub_multiboot_payload_dest + grub_multiboot_pure_size; + err = grub_multiboot_make_mbi (grub_multiboot_payload_orig, + grub_multiboot_payload_dest, + grub_multiboot_pure_size, mbi_size); + if (err) + return err; + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); @@ -89,69 +100,18 @@ grub_multiboot_boot (void) static grub_err_t grub_multiboot_unload (void) { - if (mbi) - { - unsigned int i; - for (i = 0; i < mbi->mods_count; i++) - { - grub_free ((void *) - ((struct multiboot_mod_list *) mbi->mods_addr)[i].mod_start); - grub_free ((void *) - ((struct multiboot_mod_list *) mbi->mods_addr)[i].cmdline); - } - grub_free ((void *) mbi->mods_addr); - } + grub_multiboot_free_mbi (); + grub_relocator32_free (grub_multiboot_payload_orig); - mbi = NULL; + alloc_mbi = 0; + grub_multiboot_payload_orig = NULL; grub_dl_unref (my_mod); return GRUB_ERR_NONE; } -/* Return the length of the Multiboot mmap that will be needed to allocate - our platform's map. */ -static grub_uint32_t -grub_get_multiboot_mmap_len (void) -{ - grub_size_t count = 0; - - auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); - int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)), - grub_uint64_t size __attribute__ ((unused)), - grub_uint32_t type __attribute__ ((unused))) - { - count++; - return 0; - } - - grub_mmap_iterate (hook); - - return count * sizeof (struct multiboot_mmap_entry); -} - -/* Fill previously allocated Multiboot mmap. */ -static void -grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) -{ - struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry; - - auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); - int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) - { - mmap_entry->addr = addr; - mmap_entry->len = size; - mmap_entry->type = type; - mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size); - mmap_entry++; - - return 0; - } - - grub_mmap_iterate (hook); -} - #define MULTIBOOT_LOAD_ELF64 #include "multiboot_elfxx.c" #undef MULTIBOOT_LOAD_ELF64 @@ -172,58 +132,13 @@ grub_multiboot_load_elf (grub_file_t file, void *buffer) return grub_error (GRUB_ERR_UNKNOWN_OS, "unknown ELF class"); } -static int -grub_multiboot_get_bootdev (grub_uint32_t *bootdev) -{ -#ifdef GRUB_MACHINE_PCBIOS - char *p; - grub_uint32_t biosdev, slice = ~0, part = ~0; - grub_device_t dev; - - biosdev = grub_get_root_biosnumber (); - - dev = grub_device_open (0); - if (dev && dev->disk && dev->disk->partition) - { - - p = dev->disk->partition->partmap->get_name (dev->disk->partition); - if (p) - { - if ((p[0] >= '0') && (p[0] <= '9')) - { - slice = grub_strtoul (p, &p, 0) - 1; - - if ((p) && (p[0] == ',')) - p++; - } - - if ((p[0] >= 'a') && (p[0] <= 'z')) - part = p[0] - 'a'; - } - } - if (dev) - grub_device_close (dev); - - *bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16) - | ((part & 0xff) << 8) | 0xff; - return (biosdev != ~0UL); -#else - *bootdev = 0xffffffff; - return 0; -#endif -} - void grub_multiboot (int argc, char *argv[]) { grub_file_t file = 0; - char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p; + char buffer[MULTIBOOT_SEARCH]; struct multiboot_header *header; - grub_ssize_t len, cmdline_length, boot_loader_name_length; - grub_uint32_t mmap_length; - int i; - int cmdline_argc; - char **cmdline_argv; + grub_ssize_t len; grub_loader_unset (); @@ -274,31 +189,8 @@ grub_multiboot (int argc, char *argv[]) grub_relocator32_free (grub_multiboot_payload_orig); grub_multiboot_payload_orig = NULL; - mmap_length = grub_get_multiboot_mmap_len (); - - /* Figure out cmdline length. */ /* Skip filename. */ - cmdline_argc = argc - 1; - cmdline_argv = argv + 1; - - for (i = 0, cmdline_length = 0; i < cmdline_argc; i++) - cmdline_length += grub_strlen (cmdline_argv[i]) + 1; - - if (cmdline_length == 0) - cmdline_length = 1; - - boot_loader_name_length = sizeof(PACKAGE_STRING); - -#define cmdline_addr(x) ((void *) ((x) + code_size)) -#define boot_loader_name_addr(x) \ - ((void *) ((x) + code_size + cmdline_length)) -#define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length)) -#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct multiboot_info))) - - grub_multiboot_payload_size = cmdline_length - /* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */ - + boot_loader_name_length + 3 - + sizeof (struct multiboot_info) + mmap_length; + grub_multiboot_init_mbi (argc - 1, argv + 1); if (header->flags & MULTIBOOT_AOUT_KLUDGE) { @@ -313,10 +205,12 @@ grub_multiboot (int argc, char *argv[]) code_size = load_size; grub_multiboot_payload_dest = header->load_addr; - grub_multiboot_payload_size += code_size; + grub_multiboot_pure_size += code_size; + /* Allocate a bit more to avoid relocations in most cases. */ + alloc_mbi = grub_multiboot_get_mbi_size () + 65536; grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_payload_size); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); if (! grub_multiboot_payload_orig) goto fail; @@ -338,53 +232,35 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; - /* This provides alignment for the MBI, the memory map and the backward relocator. */ - boot_loader_name_length += (0x04 - ((unsigned long) mbi_addr (grub_multiboot_payload_dest) & 0x03)); - - mbi = mbi_addr (grub_multiboot_payload_orig); - mbi_dest = mbi_addr (grub_multiboot_payload_dest); - grub_memset (mbi, 0, sizeof (struct multiboot_info)); - mbi->mmap_length = mmap_length; - - grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig)); - - /* FIXME: grub_uint32_t will break for addresses above 4 GiB, but is mandated - by the spec. Is there something we can do about it? */ - mbi->mmap_addr = (grub_uint32_t) mmap_addr (grub_multiboot_payload_dest); - mbi->flags |= MULTIBOOT_INFO_MEM_MAP; - - /* Convert from bytes to kilobytes. */ - mbi->mem_lower = grub_mmap_get_lower () / 1024; - mbi->mem_upper = grub_mmap_get_upper () / 1024; - mbi->flags |= MULTIBOOT_INFO_MEMORY; - - cmdline = p = cmdline_addr (grub_multiboot_payload_orig); - if (! cmdline) - goto fail; - - for (i = 0; i < cmdline_argc; i++) + if (header->flags & MULTIBOOT_VIDEO_MODE) { - p = grub_stpcpy (p, cmdline_argv[i]); - *(p++) = ' '; + switch (header->mode_type) + { + case 1: + grub_env_set ("gfxpayload", "text"); + break; + + case 0: + { + char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; + if (header->depth && header->width && header->height) + grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, + header->height, header->depth, header->width, + header->height); + else if (header->width && header->height) + grub_sprintf (buf, "%dx%d,auto", header->width, header->height); + else + grub_sprintf (buf, "auto"); + + grub_env_set ("gfxpayload", buf); + break; + } + } } - /* Remove the space after the last word. */ - if (p != cmdline) - p--; - *p = 0; + grub_multiboot_set_bootdev (); - mbi->flags |= MULTIBOOT_INFO_CMDLINE; - mbi->cmdline = (grub_uint32_t) cmdline_addr (grub_multiboot_payload_dest); - - - grub_strcpy (boot_loader_name_addr (grub_multiboot_payload_orig), PACKAGE_STRING); - mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME; - mbi->boot_loader_name = (grub_uint32_t) boot_loader_name_addr (grub_multiboot_payload_dest); - - if (grub_multiboot_get_bootdev (&mbi->boot_device)) - mbi->flags |= MULTIBOOT_INFO_BOOTDEV; - - grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 1); + grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); fail: if (file) @@ -392,22 +268,18 @@ grub_multiboot (int argc, char *argv[]) if (grub_errno != GRUB_ERR_NONE) { - grub_free (cmdline); - grub_free (mbi); + grub_relocator32_free (grub_multiboot_payload_orig); grub_dl_unref (my_mod); } } - void grub_module (int argc, char *argv[]) { grub_file_t file = 0; - grub_ssize_t size, len = 0; - char *module = 0, *cmdline = 0, *p; - int i; - int cmdline_argc; - char **cmdline_argv; + grub_ssize_t size; + char *module = 0; + grub_err_t err; if (argc == 0) { @@ -415,7 +287,7 @@ grub_module (int argc, char *argv[]) goto fail; } - if (!mbi) + if (!grub_multiboot_payload_orig) { grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the multiboot kernel first"); @@ -431,73 +303,19 @@ grub_module (int argc, char *argv[]) if (! module) goto fail; + err = grub_multiboot_add_module ((grub_addr_t) module, size, + argc - 1, argv + 1); + if (err) + goto fail; + if (grub_file_read (file, module, size) != size) { grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); goto fail; } - /* Skip module name. */ - cmdline_argc = argc - 1; - cmdline_argv = argv + 1; - - for (i = 0; i < cmdline_argc; i++) - len += grub_strlen (cmdline_argv[i]) + 1; - - if (len == 0) - len = 1; - - cmdline = p = grub_malloc (len); - if (! cmdline) - goto fail; - - for (i = 0; i < cmdline_argc; i++) - { - p = grub_stpcpy (p, cmdline_argv[i]); - *(p++) = ' '; - } - - /* Remove the space after the last word. */ - if (p != cmdline) - p--; - *p = '\0'; - - if (mbi->flags & MULTIBOOT_INFO_MODS) - { - struct multiboot_mod_list *modlist = (struct multiboot_mod_list *) mbi->mods_addr; - - modlist = grub_realloc (modlist, (mbi->mods_count + 1) - * sizeof (struct multiboot_mod_list)); - if (! modlist) - goto fail; - mbi->mods_addr = (grub_uint32_t) modlist; - modlist += mbi->mods_count; - modlist->mod_start = (grub_uint32_t) module; - modlist->mod_end = (grub_uint32_t) module + size; - modlist->cmdline = (grub_uint32_t) cmdline; - modlist->pad = 0; - mbi->mods_count++; - } - else - { - struct multiboot_mod_list *modlist = grub_zalloc (sizeof (struct multiboot_mod_list)); - if (! modlist) - goto fail; - modlist->mod_start = (grub_uint32_t) module; - modlist->mod_end = (grub_uint32_t) module + size; - modlist->cmdline = (grub_uint32_t) cmdline; - mbi->mods_count = 1; - mbi->mods_addr = (grub_uint32_t) modlist; - mbi->flags |= MULTIBOOT_INFO_MODS; - } - fail: if (file) grub_file_close (file); - - if (grub_errno != GRUB_ERR_NONE) - { - grub_free (module); - grub_free (cmdline); - } } + diff --git a/loader/i386/multiboot_elfxx.c b/loader/i386/multiboot_elfxx.c index 80db25144..8f6367432 100644 --- a/loader/i386/multiboot_elfxx.c +++ b/loader/i386/multiboot_elfxx.c @@ -100,10 +100,11 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) code_size = (phdr(highest_segment)->p_paddr + phdr(highest_segment)->p_memsz) - phdr(lowest_segment)->p_paddr; grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr; - grub_multiboot_payload_size += code_size; + grub_multiboot_pure_size += code_size; + alloc_mbi = grub_multiboot_get_mbi_size (); grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_payload_size); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); if (!grub_multiboot_payload_orig) return grub_errno; diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c new file mode 100644 index 000000000..58802d44c --- /dev/null +++ b/loader/i386/multiboot_mbi.c @@ -0,0 +1,336 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#ifdef GRUB_MACHINE_PCBIOS +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +struct module +{ + struct module *next; + grub_addr_t start; + grub_size_t size; + char *cmdline; + int cmdline_size; +}; + +struct module *modules, *modules_last; +static grub_size_t cmdline_size; +static grub_size_t total_modcmd; +static unsigned modcnt; +static char *cmdline = NULL; +static grub_uint32_t bootdev; +static int bootdev_set; + +/* Return the length of the Multiboot mmap that will be needed to allocate + our platform's map. */ +static grub_uint32_t +grub_get_multiboot_mmap_len (void) +{ + grub_size_t count = 0; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)), + grub_uint64_t size __attribute__ ((unused)), + grub_uint32_t type __attribute__ ((unused))) + { + count++; + return 0; + } + + grub_mmap_iterate (hook); + + return count * sizeof (struct multiboot_mmap_entry); +} + +grub_size_t +grub_multiboot_get_mbi_size (void) +{ + return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd + + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len (); +} + +/* Fill previously allocated Multiboot mmap. */ +static void +grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) +{ + struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) + { + mmap_entry->addr = addr; + mmap_entry->len = size; + switch (type) + { + case GRUB_MACHINE_MEMORY_AVAILABLE: + mmap_entry->type = MULTIBOOT_MEMORY_AVAILABLE; + break; + + default: + mmap_entry->type = MULTIBOOT_MEMORY_RESERVED; + break; + } + mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size); + mmap_entry++; + + return 0; + } + + grub_mmap_iterate (hook); +} + +grub_err_t +grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, + grub_size_t bufsize) +{ + grub_uint8_t *ptrorig = (grub_uint8_t *) orig + buf_off; + grub_uint32_t ptrdest = dest + buf_off; + struct multiboot_info *mbi; + struct multiboot_mod_list *modlist; + unsigned i; + struct module *cur; + grub_size_t mmap_size; + + if (bufsize < grub_multiboot_get_mbi_size ()) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "mbi buffer is too small"); + + mbi = (struct multiboot_info *) ptrorig; + ptrorig += sizeof (*mbi); + ptrdest += sizeof (*mbi); + grub_memset (mbi, 0, sizeof (*mbi)); + + grub_memcpy (ptrorig, cmdline, cmdline_size); + mbi->flags |= MULTIBOOT_INFO_CMDLINE; + mbi->cmdline = ptrdest; + ptrorig += ALIGN_UP (cmdline_size, 4); + ptrdest += ALIGN_UP (cmdline_size, 4); + + grub_memcpy (ptrorig, PACKAGE_STRING, sizeof(PACKAGE_STRING)); + mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME; + mbi->boot_loader_name = ptrdest; + ptrorig += ALIGN_UP (sizeof(PACKAGE_STRING), 4); + ptrdest += ALIGN_UP (sizeof(PACKAGE_STRING), 4); + + if (modcnt) + { + mbi->flags |= MULTIBOOT_INFO_MODS; + mbi->mods_addr = ptrdest; + mbi->mods_count = modcnt; + modlist = (struct multiboot_mod_list *) ptrorig; + ptrorig += modcnt * sizeof (struct multiboot_mod_list); + ptrdest += modcnt * sizeof (struct multiboot_mod_list); + + for (i = 0, cur = modules; i < modcnt; i++, cur = cur->next) + { + modlist[i].mod_start = cur->start; + modlist[i].mod_end = modlist[i].mod_start + cur->size; + modlist[i].cmdline = ptrdest; + grub_memcpy (ptrorig, cur->cmdline, cur->cmdline_size); + ptrorig += ALIGN_UP (cur->cmdline_size, 4); + ptrdest += ALIGN_UP (cur->cmdline_size, 4); + } + } + else + { + mbi->mods_addr = 0; + mbi->mods_count = 0; + } + + mmap_size = grub_get_multiboot_mmap_len (); + grub_fill_multiboot_mmap ((struct multiboot_mmap_entry *) ptrorig); + mbi->mmap_length = mmap_size; + mbi->mmap_addr = ptrdest; + mbi->flags |= MULTIBOOT_INFO_MEM_MAP; + ptrorig += mmap_size; + ptrdest += mmap_size; + + /* Convert from bytes to kilobytes. */ + mbi->mem_lower = grub_mmap_get_lower () / 1024; + mbi->mem_upper = grub_mmap_get_upper () / 1024; + mbi->flags |= MULTIBOOT_INFO_MEMORY; + + if (bootdev_set) + { + mbi->boot_device = bootdev; + mbi->flags |= MULTIBOOT_INFO_BOOTDEV; + } + + return GRUB_ERR_NONE; +} + +void +grub_multiboot_free_mbi (void) +{ + struct module *cur, *next; + + cmdline_size = 0; + total_modcmd = 0; + modcnt = 0; + grub_free (cmdline); + cmdline = NULL; + bootdev_set = 0; + + for (cur = modules; cur; cur = next) + { + next = cur->next; + grub_free (cur->cmdline); + grub_free (cur); + } + modules = NULL; + modules_last = NULL; +} + +grub_err_t +grub_multiboot_init_mbi (int argc, char *argv[]) +{ + grub_ssize_t len = 0; + char *p; + int i; + + grub_multiboot_free_mbi (); + + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + if (len == 0) + len = 1; + + cmdline = p = grub_malloc (len); + if (! cmdline) + return grub_errno; + cmdline_size = len; + + for (i = 0; i < argc; i++) + { + p = grub_stpcpy (p, argv[i]); + *(p++) = ' '; + } + + /* Remove the space after the last word. */ + if (p != cmdline) + p--; + *p = '\0'; + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_multiboot_add_module (grub_addr_t start, grub_size_t size, + int argc, char *argv[]) +{ + struct module *newmod; + char *p; + grub_ssize_t len = 0; + int i; + + newmod = grub_malloc (sizeof (*newmod)); + if (!newmod) + return grub_errno; + newmod->start = start; + newmod->size = size; + + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + + if (len == 0) + len = 1; + + newmod->cmdline = p = grub_malloc (len); + if (! newmod->cmdline) + { + grub_free (newmod); + return grub_errno; + } + newmod->cmdline_size = len; + total_modcmd += ALIGN_UP (len, 4); + + for (i = 0; i < argc; i++) + { + p = grub_stpcpy (p, argv[i]); + *(p++) = ' '; + } + + /* Remove the space after the last word. */ + if (p != newmod->cmdline) + p--; + *p = '\0'; + + if (modules_last) + modules_last->next = newmod; + else + { + modules = newmod; + modules_last->next = NULL; + } + modules_last = newmod; + + modcnt++; + + return GRUB_ERR_NONE; +} + +void +grub_multiboot_set_bootdev (void) +{ + char *p; + grub_uint32_t biosdev, slice = ~0, part = ~0; + grub_device_t dev; + +#ifdef GRUB_MACHINE_PCBIOS + biosdev = grub_get_root_biosnumber (); +#else + biosdev = 0xffffffff; +#endif + + dev = grub_device_open (0); + if (dev && dev->disk && dev->disk->partition) + { + + p = dev->disk->partition->partmap->get_name (dev->disk->partition); + if (p) + { + if ((p[0] >= '0') && (p[0] <= '9')) + { + slice = grub_strtoul (p, &p, 0) - 1; + + if ((p) && (p[0] == ',')) + p++; + } + + if ((p[0] >= 'a') && (p[0] <= 'z')) + part = p[0] - 'a'; + } + } + if (dev) + grub_device_close (dev); + + bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16) + | ((part & 0xff) << 8) | 0xff; + bootdev_set = 1; +} From e9060a9d3b1509656241f9128480250ad6824543 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 22:34:25 +0100 Subject: [PATCH 135/164] 2010-01-10 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error which resulted in garbled command line at the end of screen. --- ChangeLog | 5 +++++ normal/cmdline.c | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f141d6a5..65da2542d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-10 Vladimir Serbinenko + + * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error + which resulted in garbled command line at the end of screen. + 2010-01-10 Robert Millan * loader/i386/ieee1275/linux.c (grub_linux_boot): Rework video position diff --git a/normal/cmdline.c b/normal/cmdline.c index 656b14c6a..429c84be7 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -254,21 +254,20 @@ grub_cmdline_get (const char *prompt) for (p = buf + pos; p < buf + llen; p++) { - if (cl_term->xpos++ > cl_term->width - 2) - { - grub_putcode ('\n', cl_term->term); - - cl_term->xpos = 1; - if (cl_term->ypos == (unsigned) (cl_term->height)) - cl_term->ystart--; - else - cl_term->ypos++; - } - if (c) grub_putcode (c, cl_term->term); else grub_putcode (*p, cl_term->term); + cl_term->xpos++; + if (cl_term->xpos >= cl_term->width - 1) + { + cl_term->xpos = 0; + if (cl_term->ypos >= (unsigned) (cl_term->height - 1)) + cl_term->ystart--; + else + cl_term->ypos++; + grub_putcode ('\n', cl_term->term); + } } } From ffa8e3d2775628355960eefa2d4433d15b13d5d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jan 2010 22:35:46 +0100 Subject: [PATCH 136/164] 2010-01-10 Vladimir Serbinenko * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted in premature implicit newline. --- ChangeLog | 5 +++++ term/i386/pc/vga_text.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 65da2542d..321baa439 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-10 Vladimir Serbinenko + + * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted + in premature implicit newline. + 2010-01-10 Vladimir Serbinenko * normal/cmdline.c (grub_cmdline_get): Fix off-by-one error diff --git a/term/i386/pc/vga_text.c b/term/i386/pc/vga_text.c index 170f74de8..f954cab43 100644 --- a/term/i386/pc/vga_text.c +++ b/term/i386/pc/vga_text.c @@ -77,7 +77,7 @@ inc_y (void) static void inc_x (void) { - if (grub_curr_x >= COLS - 2) + if (grub_curr_x >= COLS - 1) inc_y (); else grub_curr_x++; From a788afb626011e4fbf98d929a818735e9d2bdf1c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 11 Jan 2010 12:00:57 +0000 Subject: [PATCH 137/164] 2010-01-11 Colin Watson * util/grub-install.in (usage): Clarify meaning of --root-directory, and make it clearer that it's optional. Based on confusion witnessed on IRC. --- ChangeLog | 6 ++++++ util/grub-install.in | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 321baa439..42343a8b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-11 Colin Watson + + * util/grub-install.in (usage): Clarify meaning of --root-directory, + and make it clearer that it's optional. Based on confusion + witnessed on IRC. + 2010-01-10 Vladimir Serbinenko * term/i386/pc/vga_text.c (inc_y): Fix off-by-one error which resulted diff --git a/util/grub-install.in b/util/grub-install.in index 1fcfb1aca..f3fd88188 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -87,9 +87,11 @@ fi INSTALL_DEVICE can be a GRUB device name or a system device filename. -grub-install copies GRUB images into the DIR/boot directory specified by ---root-directory, and uses grub-setup to install grub into the boot -sector. +grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and +OpenBSD), and uses grub-setup to install grub into the boot sector. + +If the --root-directory option is used, then grub-install will copy +images into the operating system installation rooted at that directory. Report bugs to . EOF From 92ab12b09225525d1e3ebd4deb9201f21cab82e8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 11 Jan 2010 14:55:20 +0000 Subject: [PATCH 138/164] 2010-01-11 Robert Millan * util/misc.c (canonicalize_file_name): New function. (make_system_path_relative_to_its_root): Use canonicalize_file_name() instead of realpath(). --- ChangeLog | 6 ++++++ util/misc.c | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 42343a8b6..768a65944 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-11 Robert Millan + + * util/misc.c (canonicalize_file_name): New function. + (make_system_path_relative_to_its_root): Use canonicalize_file_name() + instead of realpath(). + 2010-01-11 Colin Watson * util/grub-install.in (usage): Clarify meaning of --root-directory, diff --git a/util/misc.c b/util/misc.c index d8aa041be..47dd8c78d 100644 --- a/util/misc.c +++ b/util/misc.c @@ -479,6 +479,19 @@ fail: #endif /* __MINGW32__ */ +char * +canonicalize_file_name (const char *path) +{ + char *ret; +#ifdef PATH_MAX + ret = xmalloc (PATH_MAX); + (void) realpath (path, ret); +#else + ret = realpath (path, NULL); +#endif + return ret; +} + /* This function never prints trailing slashes (so that its output can be appended a slash unconditionally). */ char * @@ -491,15 +504,11 @@ make_system_path_relative_to_its_root (const char *path) size_t len; /* canonicalize. */ - p = realpath (path, NULL); + p = canonicalize_file_name (path); if (p == NULL) - { - if (errno != EINVAL) - grub_util_error ("failed to get realpath of %s", path); - else - grub_util_error ("realpath not supporting (path, NULL)"); - } + grub_util_error ("failed to get canonical path of %s", path); + len = strlen (p) + 1; buf = strdup (p); free (p); From afdc9ad0065bfa84b2d9a981c038a89aaba67f14 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 09:00:55 +0530 Subject: [PATCH 139/164] fixed an error message --- ChangeLog.unit-testing-framework | 4 ++++ tests/util/grub-shell-tester.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index a451108c4..5fd7a2f28 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,3 +1,7 @@ +2010-01-12 BVK Chaitanya + + * tests/util/grub-shell-tester.in: Fix error message. + 2010-01-08 BVK Chaitanya Unit testing framework for GRUB. diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index 18f5e79b7..6ed4ebcac 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -98,7 +98,7 @@ bash ${source} >${outfile2} if ! diff -q ${outfile1} ${outfile2} >/dev/null then - echo "$1: GRUB and BASH outputs (${outfile1}, ${outfile2}) did not match" + echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})" status=1 else rm -f ${outfile1} ${outfile2} From 350285caaefc8384ca73263fe42f89f66ec28779 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 09:23:24 +0530 Subject: [PATCH 140/164] removed unnecessary EXPORT_* macro usage --- ChangeLog.unit-testing-framework | 2 ++ include/grub/test.h | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 5fd7a2f28..973a7c756 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,7 @@ 2010-01-12 BVK Chaitanya + * include/grub/test.h: Removed EXPORT_* usage. + * tests/util/grub-shell-tester.in: Fix error message. 2010-01-08 BVK Chaitanya diff --git a/include/grub/test.h b/include/grub/test.h index b4851bbf6..bd5b7d806 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -20,11 +20,10 @@ struct grub_test }; typedef struct grub_test *grub_test_t; -extern grub_test_t EXPORT_VAR (grub_test_list); +extern grub_test_t grub_test_list; -void EXPORT_FUNC (grub_test_register) (const char *name, void (*test) (void)); - -void EXPORT_FUNC (grub_test_unregister) (const char *name); +void grub_test_register (const char *name, void (*test) (void)); +void grub_test_unregister (const char *name); /* Execute a test and print results. */ int grub_test_run (grub_test_t test); From c5431d4029cfe61dcdd3f28a3bd6d9f22a0b80ea Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 10:16:17 +0530 Subject: [PATCH 141/164] build tests on make, but run on make check --- ChangeLog.unit-testing-framework | 5 ++++- Makefile.in | 21 +++++++++------------ conf/tests.rmk | 31 ++++++++++++++++++------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 973a7c756..620ac80cf 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,6 +1,9 @@ 2010-01-12 BVK Chaitanya - * include/grub/test.h: Removed EXPORT_* usage. + * conf/tests.rmk: Build tests on make. + * Makefile.in (check): Use new variables. + + * include/grub/test.h: Remove EXPORT_* usage. * tests/util/grub-shell-tester.in: Fix error message. diff --git a/Makefile.in b/Makefile.in index 567571897..45c6f3e45 100644 --- a/Makefile.in +++ b/Makefile.in @@ -460,15 +460,18 @@ distcheck: dist @echo "$(distdir).tar.gz is ready for distribution" | \ sed 'h;s/./=/g;p;x;p;x' -TESTS = $(check_UTILITIES) $(check_SCRIPTS) $(check_MODULES) -$(TESTS): $(test_framework_SCRIPTS) $(test_framework_MODULES) - -check: all $(TESTS) - @list="$(check_UTILITIES)"; \ +check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS) + @list="$(UNIT_TESTS)"; \ for file in $$list; do \ $(builddir)/$$file; \ done - @list="$(check_SCRIPTS)"; \ + @list="$(FUNCTIONAL_TESTS)"; \ + for file in $$list; do \ + mod=`basename $$file .mod`; \ + echo "insmod functional_test; insmod $$mod; functional_test" \ + | $(builddir)/grub-shell; \ + done + @list="$(SCRIPTED_TESTS)"; \ for file in $$list; do \ echo "$$file:"; \ if $(builddir)/$$file; then \ @@ -477,12 +480,6 @@ check: all $(TESTS) echo "$$file: FAIL"; \ fi; \ done - @list="$(check_MODULES)"; \ - for file in $$list; do \ - mod=`basename $$file .mod`; \ - echo "insmod functional_test; insmod $$mod; functional_test" \ - | $(builddir)/grub-shell; \ - done .SUFFIX: .SUFFIX: .c .o .S .d diff --git a/conf/tests.rmk b/conf/tests.rmk index c35ea0baa..e894323ae 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,38 +4,43 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -test_framework_SCRIPTS += grub-shell +bin_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -test_framework_SCRIPTS += grub-shell-tester +bin_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester -test_framework_MODULES += functional_test.mod +pkglib_MODULES += functional_test.mod functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) -# Unit tests - -check_UTILITIES += example_unit_test +# Rules for unit tests +bin_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format -# Functional tests - -check_MODULES += example_functional_test.mod +# Rules for functional tests +pkglib_MODULES += example_functional_test.mod example_functional_test_mod_SOURCES = tests/example_functional_test.c example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) -# Scripted tests - -check_SCRIPTS += example_scripted_test +# Rules for scripted tests +bin_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -check_SCRIPTS += example_grub_script_test +bin_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in + + +# List of tests to execute on "make check" + +SCRIPTED_TESTS = example_scripted_test +SCRIPTED_TESTS += example_grub_script_test +UNIT_TESTS = example_unit_test +FUNCTIONAL_TESTS = example_functional_test.mod From afafb37e9b56158454aeacc6072b368b8198e55f Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 10:54:37 +0530 Subject: [PATCH 142/164] added boot device selection to grub-shell --- ChangeLog.unit-testing-framework | 2 ++ tests/util/grub-shell.in | 40 ++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 620ac80cf..8641d09ee 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,7 @@ 2010-01-12 BVK Chaitanya + * tests/util/grub-shell.in: New --boot option. + * conf/tests.rmk: Build tests on make. * Makefile.in (check): Use new variables. diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index c1b2ef258..b103872ba 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -42,6 +42,7 @@ Run GRUB script in a Qemu instance. -h, --help print this message and exit -v, --version print the version information and exit + --boot=[fd|hd|cd] boot method for Qemu instance --modules=MODULES pre-load specified modules MODULES --qemu-opts=OPTIONS extra options to pass to Qemu instance @@ -67,11 +68,20 @@ for option in "$@"; do --qemu-opts=*) qs=`echo "$option" | sed -e 's/--qemu-opts=//'` qemuopts="$qemuopts $qs" ;; + --boot=*) + dev=`echo "$option" | sed -e 's/--boot=//'` + if [ "$dev" = "fd" ] ; then bootdev=a; + elif [ "$dev" = "hd" ] ; then bootdev=c; + elif [ "$dev" = "cd" ] ; then bootdev=d; + else + echo "Unrecognized boot method \`$dev'" 1>&2 + usage + exit 1 + fi ;; -*) echo "Unrecognized option \`$option'" 1>&2 usage - exit 1 - ;; + exit 1 ;; *) if [ "x${source}" != x ] ; then echo "too many parameters at the end" 1>&2 @@ -83,11 +93,15 @@ for option in "$@"; do done if [ "x${source}" = x ] ; then - tmpfile=`mktemp` - while read; do - echo $REPLY >> ${tmpfile} - done - source=${tmpfile} + tmpfile=`mktemp` + while read; do + echo $REPLY >> ${tmpfile} + done + source=${tmpfile} +fi + +if [ "x${bootdev}" = x ] ; then + bootdev=c # default is boot as disk image fi cfgfile=`mktemp` @@ -101,7 +115,7 @@ EOF for mod in ${modules} do - echo "insmod ${mod}" >> ${cfgfile} + echo "insmod ${mod}" >> ${cfgfile} done cat <>${cfgfile} @@ -114,12 +128,18 @@ grub-mkrescue --output=${isofile} --override-directory=${builddir} \ /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \ >/dev/null 2>&1 +hdafile=`mktemp` +cp ${isofile} ${hdafile} + +fdafile=`mktemp` +cp ${isofile} ${fdafile} + outfile=`mktemp` -qemu ${qemuopts} -nographic -serial stdio -cdrom ${isofile} -boot d | tr -d "\r" >${outfile} +qemu ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} cat $outfile -rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} +rm -f ${tmpfile} ${outfile} ${cfgfile} ${isofile} ${hdafile} ${fdafile} exit 0 From 4d362fde5883655a9a0d5a56068e16d0e81bf9be Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Tue, 12 Jan 2010 15:49:40 +0530 Subject: [PATCH 143/164] build only functional tests on make --- ChangeLog.unit-testing-framework | 2 +- conf/tests.rmk | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 8641d09ee..aa4d4fd03 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -2,7 +2,7 @@ * tests/util/grub-shell.in: New --boot option. - * conf/tests.rmk: Build tests on make. + * conf/tests.rmk: Build functional tests on make. * Makefile.in (check): Use new variables. * include/grub/test.h: Remove EXPORT_* usage. diff --git a/conf/tests.rmk b/conf/tests.rmk index e894323ae..18b23ff5a 100644 --- a/conf/tests.rmk +++ b/conf/tests.rmk @@ -4,14 +4,14 @@ grub-shell: tests/util/grub-shell.in config.status ./config.status --file=$@:$< chmod +x $@ -bin_SCRIPTS += grub-shell +check_SCRIPTS += grub-shell CLEANFILES += grub-shell # For grub-shell-tester grub-shell-tester: tests/util/grub-shell-tester.in config.status ./config.status --file=$@:$< chmod +x $@ -bin_SCRIPTS += grub-shell-tester +check_SCRIPTS += grub-shell-tester CLEANFILES += grub-shell-tester pkglib_MODULES += functional_test.mod @@ -20,7 +20,7 @@ functional_test_mod_CFLAGS = $(COMMON_CFLAGS) functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Rules for unit tests -bin_UTILITIES += example_unit_test +check_UTILITIES += example_unit_test example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c example_unit_test_CFLAGS = -Wno-format @@ -31,16 +31,20 @@ example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS) example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS) # Rules for scripted tests -bin_SCRIPTS += example_scripted_test +check_SCRIPTS += example_scripted_test example_scripted_test_SOURCES = tests/example_scripted_test.in -bin_SCRIPTS += example_grub_script_test +check_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in # List of tests to execute on "make check" - SCRIPTED_TESTS = example_scripted_test SCRIPTED_TESTS += example_grub_script_test UNIT_TESTS = example_unit_test FUNCTIONAL_TESTS = example_functional_test.mod + +# dependencies between tests and testing-tools +$(SCRIPTED_TESTS): grub-shell grub-shell-tester +$(FUNCTIONAL_TESTS): functional_test.mod + From 0b8a223cb157791e7dde5e0bf40f3327e3ac537d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 13:36:44 +0100 Subject: [PATCH 144/164] 2010-01-12 Vladimir Serbinenko MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. Reported by: GrĂ©goire Sutre --- ChangeLog | 5 +++++ util/grub-mkpasswd-pbkdf2.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 768a65944..86deb525f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-12 Vladimir Serbinenko + + * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. + Reported by: GrĂ©goire Sutre + 2010-01-11 Robert Millan * util/misc.c (canonicalize_file_name): New function. diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index 2f7c5efaa..b27a4e893 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -123,9 +123,8 @@ main (int argc, char *argv[]) int tty_changed; set_program_name (argv[0]); - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + + grub_util_init_nls (); /* Check for options. */ while (1) From 10891398fd51394ace8504f83af419820e45070b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 17:56:05 +0100 Subject: [PATCH 145/164] 2010-01-12 Vladimir Serbinenko * loader/i386/pc/multiboot2.c: Removed stalled file. --- ChangeLog | 4 ++ loader/i386/pc/multiboot2.c | 122 ------------------------------------ 2 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 loader/i386/pc/multiboot2.c diff --git a/ChangeLog b/ChangeLog index 86deb525f..e2fd92f68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-12 Vladimir Serbinenko + + * loader/i386/pc/multiboot2.c: Removed stalled file. + 2010-01-12 Vladimir Serbinenko * util/grub-mkpasswd-pbkdf2.c (main): Use grub_util_init_nls. diff --git a/loader/i386/pc/multiboot2.c b/loader/i386/pc/multiboot2.c deleted file mode 100644 index 005c8a823..000000000 --- a/loader/i386/pc/multiboot2.c +++ /dev/null @@ -1,122 +0,0 @@ -/* multiboot2.c - boot a multiboot 2 OS image. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB 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, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, - grub_addr_t *addr __attribute__ ((unused)), - int *do_load) -{ - Elf32_Addr paddr = phdr->p_paddr; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) - return grub_error(GRUB_ERR_OUT_OF_RANGE,"address 0x%x is out of range", - paddr); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, - grub_addr_t *addr __attribute__ ((unused)), - int *do_load) -{ - Elf64_Addr paddr = phdr->p_paddr; - - if (phdr->p_type != PT_LOAD) - { - *do_load = 0; - return 0; - } - *do_load = 1; - - if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "address 0x%x is out of range", - paddr); - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr) -{ - grub_addr_t modaddr; - - modaddr = (grub_addr_t) grub_memalign (MULTIBOOT2_MOD_ALIGN, size); - if (! modaddr) - return grub_errno; - - *addr = modaddr; - return GRUB_ERR_NONE; -} - -grub_err_t -grub_mb2_arch_module_free (grub_addr_t addr, - grub_size_t size __attribute__ ((unused))) -{ - grub_free((void *) addr); - return GRUB_ERR_NONE; -} - -void -grub_mb2_arch_boot (grub_addr_t entry, void *tags) -{ - grub_multiboot2_real_boot (entry, tags); -} - -void -grub_mb2_arch_unload (struct multiboot2_tag_header *tags) -{ - struct multiboot2_tag_header *tag; - - /* Free all module memory in the tag list. */ - for_each_tag (tag, tags) - { - if (tag->key == MULTIBOOT2_TAG_MODULE) - { - struct multiboot2_tag_module *module = - (struct multiboot2_tag_module *) tag; - grub_free((void *) module->addr); - } - } -} - -grub_err_t -grub_mb2_tags_arch_create (void) -{ - /* XXX Create boot device et al. */ - return GRUB_ERR_NONE; -} From b16ff4662ea7a3d3187499c435c3b45a85af7563 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 12 Jan 2010 19:47:02 +0100 Subject: [PATCH 146/164] Small cleanup --- loader/i386/multiboot.c | 26 -------------------------- loader/i386/multiboot_elfxx.c | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 2a69327b4..5dc304117 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -232,32 +232,6 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; - if (header->flags & MULTIBOOT_VIDEO_MODE) - { - switch (header->mode_type) - { - case 1: - grub_env_set ("gfxpayload", "text"); - break; - - case 0: - { - char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; - if (header->depth && header->width && header->height) - grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, - header->height, header->depth, header->width, - header->height); - else if (header->width && header->height) - grub_sprintf (buf, "%dx%d,auto", header->width, header->height); - else - grub_sprintf (buf, "auto"); - - grub_env_set ("gfxpayload", buf); - break; - } - } - } - grub_multiboot_set_bootdev (); grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); diff --git a/loader/i386/multiboot_elfxx.c b/loader/i386/multiboot_elfxx.c index 8f6367432..2e35183a4 100644 --- a/loader/i386/multiboot_elfxx.c +++ b/loader/i386/multiboot_elfxx.c @@ -104,7 +104,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) alloc_mbi = grub_multiboot_get_mbi_size (); grub_multiboot_payload_orig - = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi); + = grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi + 65536); if (!grub_multiboot_payload_orig) return grub_errno; From 58655a160bd56ab3ca8ed9944639260eff21bfa8 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 13 Jan 2010 19:10:57 +0000 Subject: [PATCH 147/164] 2010-01-13 Robert Millan * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. --- ChangeLog | 4 ++++ util/mkisofs/rock.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2fd92f68..788328502 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-13 Robert Millan + + * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. + 2010-01-12 Vladimir Serbinenko * loader/i386/pc/multiboot2.c: Removed stalled file. diff --git a/util/mkisofs/rock.c b/util/mkisofs/rock.c index a4cc27fa9..f18b0bd83 100644 --- a/util/mkisofs/rock.c +++ b/util/mkisofs/rock.c @@ -5,7 +5,7 @@ Copyright 1993 Yggdrasil Computing, Incorporated - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009,2010 Free Software Foundation, Inc. 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 @@ -306,7 +306,7 @@ int deep_opt; * the symbolic link won't fit into one SL System Use Field * print an error message and continue with splited one */ - fprintf(stderr, _("symbolic link ``%s'' to long for one SL System Use Field, splitting"), cpnt); + fprintf (stderr, _("symbolic link ``%s'' too long for one SL System Use Field, splitting"), cpnt); } if(MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes)) add_CE_entry(); } From c1f28820101867513d188fbe7354d5d35b0f08cb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 13 Jan 2010 20:43:48 +0100 Subject: [PATCH 148/164] 2010-01-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. (grub_ofconsole_getwh): Split to ... (grub_ofconsole_getwh): ... this. (grub_ofconsole_dimensions): ...and this. (grub_ofconsole_init_output): Call grub_ofconsole_dimensions. --- ChangeLog | 8 ++++++++ term/ieee1275/ofconsole.c | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 788328502..95eebe4b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-13 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. + (grub_ofconsole_getwh): Split to ... + (grub_ofconsole_getwh): ... this. + (grub_ofconsole_dimensions): ...and this. + (grub_ofconsole_init_output): Call grub_ofconsole_dimensions. + 2010-01-13 Robert Millan * util/mkisofs/rock.c (generate_rock_ridge_attributes): Fix a typo. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 3977c6286..a9834e23e 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -83,12 +83,17 @@ grub_ofconsole_putchar (grub_uint32_t c) grub_curr_y++; grub_curr_x = 0; } + else if (c == '\r') + { + grub_curr_x = 0; + } else { grub_curr_x++; - if (grub_curr_x > grub_ofconsole_width) + if (grub_curr_x >= grub_ofconsole_width) { grub_ofconsole_putchar ('\n'); + grub_ofconsole_putchar ('\r'); grub_curr_x++; } } @@ -234,16 +239,13 @@ grub_ofconsole_getxy (void) return ((grub_curr_x - 1) << 8) | grub_curr_y; } -static grub_uint16_t -grub_ofconsole_getwh (void) +static void +grub_ofconsole_dimensions (void) { grub_ieee1275_ihandle_t options; char *val; grub_ssize_t lval; - if (grub_ofconsole_width && grub_ofconsole_height) - return (grub_ofconsole_width << 8) | grub_ofconsole_height; - if (! grub_ieee1275_finddevice ("/options", &options) && options != (grub_ieee1275_ihandle_t) -1) { @@ -280,7 +282,11 @@ grub_ofconsole_getwh (void) grub_ofconsole_width = 80; if (! grub_ofconsole_height) grub_ofconsole_height = 24; +} +static grub_uint16_t +grub_ofconsole_getwh (void) +{ return (grub_ofconsole_width << 8) | grub_ofconsole_height; } @@ -379,6 +385,8 @@ grub_ofconsole_init_output (void) grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL); } + grub_ofconsole_dimensions (); + return 0; } From 17383dfe962e366b2c77f70506a4438602619122 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 13 Jan 2010 22:53:12 +0100 Subject: [PATCH 149/164] 2010-01-13 Vladimir Serbinenko * kern/efi/init.c (grub_efi_fini): Don't call grub_efi_mm_fini as it would result in module crash. --- ChangeLog | 5 +++++ kern/efi/init.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 95eebe4b2..f86ff3ddd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-13 Vladimir Serbinenko + + * kern/efi/init.c (grub_efi_fini): Don't call grub_efi_mm_fini as + it would result in module crash. + 2010-01-13 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_putchar): Handle '\r'. diff --git a/kern/efi/init.c b/kern/efi/init.c index f9ba03852..8862eb2f9 100644 --- a/kern/efi/init.c +++ b/kern/efi/init.c @@ -82,6 +82,5 @@ void grub_efi_fini (void) { grub_efidisk_fini (); - grub_efi_mm_fini (); grub_console_fini (); } From 0b8891c276ae3b1f3d93ff881a13a405d6471269 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 14 Jan 2010 17:17:51 +0530 Subject: [PATCH 150/164] removed unnecessary grub_test_* wrappers --- ChangeLog.unit-testing-framework | 20 +++++++++++++++ include/grub/test.h | 8 ------ tests/lib/functional_test.c | 37 --------------------------- tests/lib/test.c | 44 ++++++++++++++++---------------- tests/lib/unit_test.c | 43 +++++-------------------------- 5 files changed, 48 insertions(+), 104 deletions(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index aa4d4fd03..6643e9989 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,3 +1,23 @@ +2010-01-14 BVK Chaitanya + + Removed unnecessary grub_test_* wrappers. + + * tests/lib/unit_test.c (grub_test_malloc): Removed. + (grub_test_vsprintf): Removed. + (grub_test_strdup): Removed. + (grub_test_printf): Removed. + (grub_test_free): Replaced with.... + (grub_free): ...new wrapper. + * tests/lib/functional_test.c (grub_test_malloc): Removed. + (grub_test_free): Removed. + (grub_test_vsprintf): Removed. + (grub_test_strdup): Removed. + (grub_test_printf): Removed. + * tests/lib/test.c: Replaced + grub_test_{malloc,free,strdup,printf,vsprintf} methods with + grub_{malloc,free,strdup,printf,vsprintf} methods. + * include/grub/test.h: Removed prototypes for the above. + 2010-01-12 BVK Chaitanya * tests/util/grub-shell.in: New --boot option. diff --git a/include/grub/test.h b/include/grub/test.h index bd5b7d806..544e1c817 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -64,12 +64,4 @@ void grub_test_nonzero (int cond, const char *file, grub_test_unregister (name); \ } -/* Functions that are defined differently for unit and functional tests. */ -void *grub_test_malloc (grub_size_t size); -void grub_test_free (void *ptr); -char *grub_test_strdup (const char *str); -int grub_test_vsprintf (char *str, const char *fmt, va_list args); -int grub_test_printf (const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); - #endif /* ! GRUB_TEST_HEADER */ diff --git a/tests/lib/functional_test.c b/tests/lib/functional_test.c index 2e03dabc4..8ad034503 100644 --- a/tests/lib/functional_test.c +++ b/tests/lib/functional_test.c @@ -3,43 +3,6 @@ #include #include -void * -grub_test_malloc (grub_size_t size) -{ - return grub_malloc (size); -} - -void -grub_test_free (void *ptr) -{ - grub_free (ptr); -} - -int -grub_test_vsprintf (char *str, const char *fmt, va_list args) -{ - return grub_vsprintf (str, fmt, args); -} - -char * -grub_test_strdup (const char *str) -{ - return grub_strdup (str); -} - -int -grub_test_printf (const char *fmt, ...) -{ - int r; - va_list ap; - - va_start (ap, fmt); - r = grub_vprintf (fmt, ap); - va_end (ap); - - return r; -} - static grub_err_t grub_functional_test (struct grub_extcmd *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/tests/lib/test.c b/tests/lib/test.c index 562c2f6e4..aba2f4415 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -1,3 +1,4 @@ +#include #include #include @@ -31,16 +32,16 @@ add_failure (const char *file, char buf[1024]; grub_test_failure_t failure; - failure = (grub_test_failure_t) grub_test_malloc (sizeof (*failure)); + failure = (grub_test_failure_t) grub_malloc (sizeof (*failure)); if (!failure) return; - grub_test_vsprintf (buf, fmt, args); + grub_vsprintf (buf, fmt, args); - failure->file = grub_test_strdup (file ? : ""); - failure->funp = grub_test_strdup (funp ? : ""); + failure->file = grub_strdup (file ? : ""); + failure->funp = grub_strdup (funp ? : ""); failure->line = line; - failure->message = grub_test_strdup (buf); + failure->message = grub_strdup (buf); grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure)); } @@ -53,15 +54,15 @@ free_failures (void) while ((item = grub_list_pop (GRUB_AS_LIST_P (&failure_list))) != 0) { if (item->message) - grub_test_free (item->message); + grub_free (item->message); if (item->funp) - grub_test_free (item->funp); + grub_free (item->funp); if (item->file) - grub_test_free (item->file); + grub_free (item->file); - grub_test_free (item); + grub_free (item); } failure_list = 0; } @@ -86,11 +87,11 @@ grub_test_register (const char *name, void (*test_main) (void)) { grub_test_t test; - test = (grub_test_t) grub_test_malloc (sizeof (*test)); + test = (grub_test_t) grub_malloc (sizeof (*test)); if (!test) return; - test->name = grub_test_strdup (name); + test->name = grub_strdup (name); test->main = test_main; grub_list_push (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); @@ -106,13 +107,12 @@ grub_test_unregister (const char *name) if (test) { - grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), - GRUB_AS_LIST (test)); + grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); if (test->name) - grub_test_free (test->name); + grub_free (test->name); - grub_test_free (test); + grub_free (test); } } @@ -124,22 +124,22 @@ grub_test_run (grub_test_t test) { grub_test_failure_t failure = (grub_test_failure_t) item; - grub_test_printf (" %s:%s:%u: %s\n", - (failure->file ? : ""), - (failure->funp ? : ""), - failure->line, (failure->message ? : "")); + grub_printf (" %s:%s:%u: %s\n", + (failure->file ? : ""), + (failure->funp ? : ""), + failure->line, (failure->message ? : "")); return 0; } test->main (); - grub_test_printf ("%s:\n", test->name); + grub_printf ("%s:\n", test->name); grub_list_iterate (GRUB_AS_LIST (failure_list), (grub_list_hook_t) print_failure); if (!failure_list) - grub_test_printf ("%s: PASS\n", test->name); + grub_printf ("%s: PASS\n", test->name); else - grub_test_printf ("%s: FAIL\n", test->name); + grub_printf ("%s: FAIL\n", test->name); free_failures (); return GRUB_ERR_NONE; diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c index 59931898a..2ca011433 100644 --- a/tests/lib/unit_test.c +++ b/tests/lib/unit_test.c @@ -7,43 +7,6 @@ #include #include -void * -grub_test_malloc (grub_size_t size) -{ - return malloc (size); -} - -void -grub_test_free (void *ptr) -{ - free (ptr); -} - -int -grub_test_vsprintf (char *str, const char *fmt, va_list args) -{ - return vsprintf (str, fmt, args); -} - -char * -grub_test_strdup (const char *str) -{ - return strdup (str); -} - -int -grub_test_printf (const char *fmt, ...) -{ - int r; - va_list ap; - - va_start (ap, fmt); - r = vprintf (fmt, ap); - va_end (ap); - - return r; -} - int main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused))) @@ -70,6 +33,12 @@ main (int argc __attribute__ ((unused)), /* Other misc. functions necessary for successful linking. */ +void +grub_free (void *ptr) +{ + free (ptr); +} + char * grub_env_get (const char *name __attribute__ ((unused))) { From 2285d4642a6a6177d6c9d9daa2658b347ba183c2 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Thu, 14 Jan 2010 18:39:12 +0530 Subject: [PATCH 151/164] use qemu-system-i386 instead of qemu --- ChangeLog.unit-testing-framework | 4 ++++ tests/util/grub-shell.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.unit-testing-framework b/ChangeLog.unit-testing-framework index 6643e9989..ba5ba8cc5 100644 --- a/ChangeLog.unit-testing-framework +++ b/ChangeLog.unit-testing-framework @@ -1,5 +1,9 @@ 2010-01-14 BVK Chaitanya + Use qemu-system-i386 instead of qemu. + + * tests/util/grub-shell.in (outfile): Use qemu-system-i386. + Removed unnecessary grub_test_* wrappers. * tests/lib/unit_test.c (grub_test_malloc): Removed. diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index b103872ba..e6fef8313 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -135,7 +135,7 @@ fdafile=`mktemp` cp ${isofile} ${fdafile} outfile=`mktemp` -qemu ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} +qemu-system-i386 ${qemuopts} -nographic -serial stdio -hda ${hdafile} -fda ${fdafile} -cdrom ${isofile} -boot ${bootdev} | tr -d "\r" >${outfile} cat $outfile From 6d1e76899b216af8e83516a93231bafc9570edf7 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 14 Jan 2010 14:06:36 +0000 Subject: [PATCH 152/164] fix changelog dates --- ChangeLog.savedefault | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ChangeLog.savedefault b/ChangeLog.savedefault index 722769776..d68d75eab 100644 --- a/ChangeLog.savedefault +++ b/ChangeLog.savedefault @@ -1,18 +1,18 @@ -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub-reboot.in: Make sure prev_saved_entry always gets a non-empty value. -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub.d/00_header.in: Define a "savedefault" function for use in menu entries. * util/grub-mkconfig_lib.in (save_default_entry): Use it. -2010-10-05 Jordan Uggla -2010-10-05 Colin Watson +2010-01-05 Jordan Uggla +2010-01-05 Colin Watson * util/grub-mkconfig_lib.in (save_default_entry): Only set saved_entry if boot_once is unset. From 0a46429a55ee7701dfb450ac648b1d1a07e6287c Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 14 Jan 2010 21:08:31 +0000 Subject: [PATCH 153/164] 2010-01-14 Robert Millan * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... (grub_linux16_real_boot): ... this. * kern/i386/loader.S: Likewise. * loader/i386/pc/linux.c: Include `' and `'. (grub_linux16_boot): New function. Switches to text mode and calls grub_linux16_real_boot(). * loader/i386/bsd.c: Include `'. (grub_freebsd_boot, grub_openbsd_boot, grub_netbsd_boot): Switch to text mode before calling grub_unix_real_boot(). * loader/i386/multiboot.c: Include `'. (grub_multiboot_boot): Switch to text mode before calling grub_relocator32_boot(). * loader/i386/pc/chainloader.c: Include `'. (grub_chainloader_boot): Switch to text mode before calling grub_chainloader_real_boot(). --- ChangeLog | 21 +++++++++++++++++++++ include/grub/i386/loader.h | 4 ++-- kern/i386/loader.S | 2 +- loader/i386/bsd.c | 10 ++++++++-- loader/i386/multiboot.c | 5 ++++- loader/i386/pc/chainloader.c | 4 +++- loader/i386/pc/linux.c | 14 +++++++++++++- 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0fa70ecf6..652cc145a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2010-01-14 Robert Millan + + * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... + (grub_linux16_real_boot): ... this. + * kern/i386/loader.S: Likewise. + * loader/i386/pc/linux.c: Include `' and `'. + (grub_linux16_boot): New function. Switches to text mode and calls + grub_linux16_real_boot(). + + * loader/i386/bsd.c: Include `'. + (grub_freebsd_boot, grub_openbsd_boot, grub_netbsd_boot): Switch to + text mode before calling grub_unix_real_boot(). + + * loader/i386/multiboot.c: Include `'. + (grub_multiboot_boot): Switch to text mode before calling + grub_relocator32_boot(). + + * loader/i386/pc/chainloader.c: Include `'. + (grub_chainloader_boot): Switch to text mode before calling + grub_chainloader_real_boot(). + 2010-01-05 Jordan Uggla 2010-01-05 Colin Watson diff --git a/include/grub/i386/loader.h b/include/grub/i386/loader.h index 0df5f757f..05954b6db 100644 --- a/include/grub/i386/loader.h +++ b/include/grub/i386/loader.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size); extern char *EXPORT_VAR(grub_linux_tmp_addr); extern char *EXPORT_VAR(grub_linux_real_addr); extern grub_int32_t EXPORT_VAR(grub_linux_is_bzimage); -grub_err_t EXPORT_FUNC(grub_linux16_boot) (void); +grub_err_t EXPORT_FUNC(grub_linux16_real_boot) (void); #endif #endif /* ! GRUB_LOADER_CPU_HEADER */ diff --git a/kern/i386/loader.S b/kern/i386/loader.S index 3e9c71327..ed57c43ca 100644 --- a/kern/i386/loader.S +++ b/kern/i386/loader.S @@ -59,7 +59,7 @@ VARIABLE(grub_linux_real_addr) VARIABLE(grub_linux_is_bzimage) .long 0 -FUNCTION(grub_linux16_boot) +FUNCTION(grub_linux16_real_boot) /* Must be done before zImage copy. */ call EXT_C(grub_dl_unload_all) diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 0785a3fc1..49be758c6 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ #include #include #include - +#include #ifdef GRUB_MACHINE_PCBIOS #include #endif @@ -509,6 +509,8 @@ grub_freebsd_boot (void) bi.bi_kernend = kern_end; + grub_video_set_mode ("text", NULL); + if (is_64bit) { grub_uint32_t *gdt; @@ -617,6 +619,8 @@ grub_openbsd_boot (void) pa->ba_type = OPENBSD_BOOTARG_END; pa++; + grub_video_set_mode ("text", NULL); + grub_unix_real_boot (entry, bootflags, openbsd_root, OPENBSD_BOOTARG_APIVER, 0, (grub_uint32_t) (grub_mmap_get_upper () >> 10), (grub_uint32_t) (grub_mmap_get_lower () >> 10), @@ -713,6 +717,8 @@ grub_netbsd_boot (void) bootinfo->bi_data[0] = mmap; } + grub_video_set_mode ("text", NULL); + grub_unix_real_boot (entry, bootflags, 0, bootinfo, 0, (grub_uint32_t) (grub_mmap_get_upper () >> 10), (grub_uint32_t) (grub_mmap_get_lower () >> 10)); diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 5dc304117..4360e8a2c 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -1,7 +1,7 @@ /* multiboot.c - boot a multiboot OS image. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,6 +46,7 @@ #include #include #include +#include extern grub_dl_t my_mod; static grub_size_t code_size, alloc_mbi; @@ -89,6 +90,8 @@ grub_multiboot_boot (void) if (err) return err; + grub_video_set_mode ("text", NULL); + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index 81cfddac1..e28a4e7f9 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -1,7 +1,7 @@ /* chainloader.c - boot another boot loader */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2004,2007,2009 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include #include #include +#include static grub_dl_t my_mod; static int boot_drive; @@ -41,6 +42,7 @@ static void *boot_part_addr; static grub_err_t grub_chainloader_boot (void) { + grub_video_set_mode ("text", NULL); grub_chainloader_real_boot (boot_drive, boot_part_addr); /* Never reach here. */ diff --git a/loader/i386/pc/linux.c b/loader/i386/pc/linux.c index 24bb39555..96973adb9 100644 --- a/loader/i386/pc/linux.c +++ b/loader/i386/pc/linux.c @@ -1,7 +1,7 @@ /* linux.c - boot Linux zImage or bzImage */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,8 @@ #include #include #include +#include +#include #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF @@ -48,6 +50,16 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } +static grub_err_t +grub_linux16_boot (void) +{ + grub_video_set_mode ("text", NULL); + grub_linux16_real_boot (); + + /* Not reached. */ + return GRUB_ERR_NONE; +} + static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) From ba2f6848e06aa654bf8d6df02d5737aca73035b9 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 22:31:06 +0000 Subject: [PATCH 154/164] 2010-01-14 Carles Pina i Estany * gettext/gettext.c (grub_gettext_translate): Push and pop grub_errno. (grub_gettext_delete_list): Change comment style. * kern/err.c (grub_error): Gettextizze. (grub_fatal): Gettextizze. --- ChangeLog | 8 ++++++++ gettext/gettext.c | 17 ++++++++++++++--- kern/err.c | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 652cc145a..17083d1b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-14 Carles Pina i Estany + + * gettext/gettext.c (grub_gettext_translate): Push and pop + grub_errno. + (grub_gettext_delete_list): Change comment style. + * kern/err.c (grub_error): Gettextizze. + (grub_fatal): Gettextizze. + 2010-01-14 Robert Millan * include/grub/i386/loader.h (grub_linux16_boot): Renamed to ... diff --git a/gettext/gettext.c b/gettext/gettext.c index 6fa6271f2..83497b7f6 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -148,14 +148,24 @@ grub_gettext_translate (const char *orig) struct grub_gettext_msg *cur; + /* Make sure we can use grub_gettext_translate for error messages. Push + active error message to error stack and reset error message. */ + grub_error_push (); + cur = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_gettext_msg_list), orig); if (cur) - return cur->translated; + { + grub_error_pop (); + return cur->translated; + } if (fd_mo == 0) - return orig; + { + grub_error_pop (); + return orig; + } min = 0; max = grub_gettext_max; @@ -205,6 +215,7 @@ grub_gettext_translate (const char *orig) grub_errno = GRUB_ERR_NONE; } + grub_error_pop (); return ret; } @@ -308,7 +319,7 @@ grub_gettext_delete_list (void) char *original = (char *) ((struct grub_gettext_msg *) item)->name; grub_free (original); - // Don't delete the translated message because could be in use. + /* Don't delete the translated message because could be in use. */ } } diff --git a/kern/err.c b/kern/err.c index 02d7d879f..1a881db25 100644 --- a/kern/err.c +++ b/kern/err.c @@ -45,7 +45,7 @@ grub_error (grub_err_t n, const char *fmt, ...) grub_errno = n; va_start (ap, fmt); - grub_vsprintf (grub_errmsg, fmt, ap); + grub_vsprintf (grub_errmsg, _(fmt), ap); va_end (ap); return n; @@ -57,7 +57,7 @@ grub_fatal (const char *fmt, ...) va_list ap; va_start (ap, fmt); - grub_vprintf (fmt, ap); + grub_vprintf (_(fmt), ap); va_end (ap); grub_abort (); From c586fbb2064081efec63333dee9d73999e2c6f42 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:04:49 +0000 Subject: [PATCH 155/164] 2001-01-14 Carles Pina i Estany * loader/i386/pc/chainloader.c: Include `'. --- ChangeLog | 4 ++++ loader/i386/pc/chainloader.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 17083d1b1..fe54d5c3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-01-14 Carles Pina i Estany + + * loader/i386/pc/chainloader.c: Include `'. + 2010-01-14 Carles Pina i Estany * gettext/gettext.c (grub_gettext_translate): Push and pop diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index e28a4e7f9..1d6de1de7 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -34,6 +34,7 @@ #include #include #include +#include static grub_dl_t my_mod; static int boot_drive; From cca15b52c11e5f469f2fce8ce61ff1ded3b20137 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:07:44 +0000 Subject: [PATCH 156/164] 2010-01-14 Carles Pina i Estany * normal/cmdline.c (print_completion): Gettextizze. --- ChangeLog | 4 ++++ normal/cmdline.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe54d5c3a..0478d6cb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-14 Carles Pina i Estany + + * normal/cmdline.c (print_completion): Gettextizze. + 2001-01-14 Carles Pina i Estany * loader/i386/pc/chainloader.c: Include `'. diff --git a/normal/cmdline.c b/normal/cmdline.c index 429c84be7..bcffffeab 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -166,31 +166,30 @@ print_completion (const char *item, grub_completion_type_t type, int count) if (count == 0) { /* If this is the first time, print a label. */ - const char *what; - + + grub_puts (""); switch (type) { case GRUB_COMPLETION_TYPE_COMMAND: - what = "commands"; + grub_puts_ (N_("Possible commands are:")); break; case GRUB_COMPLETION_TYPE_DEVICE: - what = "devices"; + grub_puts_ (N_("Possible devices are:")); break; case GRUB_COMPLETION_TYPE_FILE: - what = "files"; + grub_puts_ (N_("Possible files are:")); break; case GRUB_COMPLETION_TYPE_PARTITION: - what = "partitions"; + grub_puts_ (N_("Possible partitions are:")); break; case GRUB_COMPLETION_TYPE_ARGUMENT: - what = "arguments"; + grub_puts_ (N_("Possible arguments are:")); break; default: - what = "things"; + grub_puts_ (N_("Possible things are:")); break; } - - grub_printf ("\nPossible %s are:\n", what); + grub_puts (""); } if (type == GRUB_COMPLETION_TYPE_PARTITION) From 5c71db1b9ba1aee67cdee92cb2b7a71c9aadbf46 Mon Sep 17 00:00:00 2001 From: carles Date: Thu, 14 Jan 2010 23:20:13 +0000 Subject: [PATCH 157/164] 2010-01-14 Carles Pina i Estany * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain `var=val'. --- ChangeLog | 5 +++++ util/grub.d/30_os-prober.in | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0478d6cb1..e2d8a81f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-14 Carles Pina i Estany + + * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain + `var=val'. + 2010-01-14 Carles Pina i Estany * normal/cmdline.c (print_completion): Gettextizze. diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index da6eea6b6..edef37e66 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -45,10 +45,10 @@ EOF prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF insmod ${GRUB_VIDEO_BACKEND} - do_resume=0 + set do_resume=0 if [ /var/vm/sleepimage -nt10 / ]; then if xnu_resume /var/vm/sleepimage; then - do_resume=1 + set do_resume=1 fi fi if [ \$do_resume == 0 ]; then From 0d90e8a6fb31c9d6b9200b3a34fa3b2ffa38214d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 16:11:18 +0100 Subject: [PATCH 158/164] 2010-01-15 Vladimir Serbinenko Video driver ids. * include/grub/video.h (grub_video_driver_id): New type. (grub_video_adapter): New member 'id'. All users updated. (grub_video_get_driver_id): New proto. * video/video.c (grub_video_get_driver_id): New function. --- ChangeLog | 9 +++++++++ include/grub/video.h | 12 ++++++++++++ video/efi_gop.c | 1 + video/efi_uga.c | 1 + video/i386/pc/vbe.c | 1 + video/video.c | 8 ++++++++ 6 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index e2d8a81f5..dc123888b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-01-15 Vladimir Serbinenko + + Video driver ids. + + * include/grub/video.h (grub_video_driver_id): New type. + (grub_video_adapter): New member 'id'. All users updated. + (grub_video_get_driver_id): New proto. + * video/video.c (grub_video_get_driver_id): New function. + 2010-01-14 Carles Pina i Estany * util/grub.d/30_os-prober.in: Use `set var=val' rather than plain diff --git a/include/grub/video.h b/include/grub/video.h index 4145db465..437c98eb9 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -159,10 +159,19 @@ struct grub_video_palette_data grub_uint8_t a; /* Reserved bits value (0-255). */ }; +typedef enum grub_video_driver_id + { + GRUB_VIDEO_DRIVER_NONE, + GRUB_VIDEO_DRIVER_VBE, + GRUB_VIDEO_DRIVER_EFI_UGA, + GRUB_VIDEO_DRIVER_EFI_GOP + } grub_video_driver_id_t; + struct grub_video_adapter { /* The video adapter name. */ const char *name; + grub_video_driver_id_t id; /* Initialize the video adapter. */ grub_err_t (*init) (void); @@ -310,4 +319,7 @@ grub_err_t grub_video_set_mode (const char *modestring, int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p, struct grub_video_mode_info *mode_info)); +grub_video_driver_id_t +grub_video_get_driver_id (void); + #endif /* ! GRUB_VIDEO_HEADER */ diff --git a/video/efi_gop.c b/video/efi_gop.c index 30863c1ed..13ef0ddae 100644 --- a/video/efi_gop.c +++ b/video/efi_gop.c @@ -353,6 +353,7 @@ grub_video_gop_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_gop_adapter = { .name = "EFI GOP driver", + .id = GRUB_VIDEO_DRIVER_EFI_GOP, .init = grub_video_gop_init, .fini = grub_video_gop_fini, diff --git a/video/efi_uga.c b/video/efi_uga.c index 12ca35cde..7ef7594cc 100644 --- a/video/efi_uga.c +++ b/video/efi_uga.c @@ -300,6 +300,7 @@ grub_video_uga_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_uga_adapter = { .name = "EFI UGA driver", + .id = GRUB_VIDEO_DRIVER_EFI_UGA, .init = grub_video_uga_init, .fini = grub_video_uga_fini, diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index 17d9b3282..918bab0b0 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -557,6 +557,7 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, static struct grub_video_adapter grub_video_vbe_adapter = { .name = "VESA BIOS Extension Video Driver", + .id = GRUB_VIDEO_DRIVER_VBE, .init = grub_video_vbe_init, .fini = grub_video_vbe_fini, diff --git a/video/video.c b/video/video.c index 682bebcbf..e678c2982 100644 --- a/video/video.c +++ b/video/video.c @@ -93,6 +93,14 @@ grub_video_get_info (struct grub_video_mode_info *mode_info) return grub_video_adapter_active->get_info (mode_info); } +grub_video_driver_id_t +grub_video_get_driver_id (void) +{ + if (! grub_video_adapter_active) + return GRUB_VIDEO_DRIVER_NONE; + return grub_video_adapter_active->id; +} + /* Get information about active video mode. */ grub_err_t grub_video_get_info_and_fini (struct grub_video_mode_info *mode_info, From 884ade56545bc515a13307e24a9694b0ef357a8a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 16:30:57 +0100 Subject: [PATCH 159/164] 2010-01-15 Vladimir Serbinenko Video multiboot support. * include/grub/multiboot.h (grub_multiboot_set_accepts_video): New prototype. * include/multiboot.h: Resynced with multiboot specification. * include/multiboot2.h: Likewise. * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): Support video flags. (grub_multiboot): Parse MULTIBOOT_VIDEO_MODE fields. * loader/i386/multiboot_mbi.c (DEFAULT_VIDEO_MODE): New constant. (HAS_VGA_TEXT): Likewise. (accepts_video): New variable. (grub_multiboot_set_accepts_video): New function. (grub_multiboot_get_mbi_size): Account for video structures. (set_video_mode): New function. (retrieve_video_parameters): Likewise. (grub_multiboot_make_mbi): Fill video fields. --- ChangeLog | 19 ++++++ include/grub/multiboot.h | 2 + include/multiboot.h | 38 ++++++++++- include/multiboot2.h | 38 ++++++++++- loader/i386/multiboot.c | 34 ++++++++-- loader/i386/multiboot_mbi.c | 129 +++++++++++++++++++++++++++++++++++- 6 files changed, 252 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc123888b..8d3245ea3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-01-15 Vladimir Serbinenko + + Video multiboot support. + + * include/grub/multiboot.h (grub_multiboot_set_accepts_video): + New prototype. + * include/multiboot.h: Resynced with multiboot specification. + * include/multiboot2.h: Likewise. + * loader/i386/multiboot.c (UNSUPPORTED_FLAGS): Support video flags. + (grub_multiboot): Parse MULTIBOOT_VIDEO_MODE fields. + * loader/i386/multiboot_mbi.c (DEFAULT_VIDEO_MODE): New constant. + (HAS_VGA_TEXT): Likewise. + (accepts_video): New variable. + (grub_multiboot_set_accepts_video): New function. + (grub_multiboot_get_mbi_size): Account for video structures. + (set_video_mode): New function. + (retrieve_video_parameters): Likewise. + (grub_multiboot_make_mbi): Fill video fields. + 2010-01-15 Vladimir Serbinenko Video driver ids. diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index f9edb0c59..665292e33 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -35,6 +35,8 @@ void grub_multiboot (int argc, char *argv[]); void grub_module (int argc, char *argv[]); +void grub_multiboot_set_accepts_video (int val); + grub_size_t grub_multiboot_get_mbi_size (void); grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, grub_size_t bufsize); diff --git a/include/multiboot.h b/include/multiboot.h index da7afd9b3..57c154c98 100644 --- a/include/multiboot.h +++ b/include/multiboot.h @@ -85,10 +85,12 @@ #define MULTIBOOT_INFO_APM_TABLE 0x00000400 /* Is there video information? */ -#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE +typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; typedef unsigned int multiboot_uint32_t; typedef unsigned long long multiboot_uint64_t; @@ -187,9 +189,43 @@ struct multiboot_info multiboot_uint16_t vbe_interface_seg; multiboot_uint16_t vbe_interface_off; multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; }; typedef struct multiboot_info multiboot_info_t; +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + struct multiboot_mmap_entry { multiboot_uint32_t size; diff --git a/include/multiboot2.h b/include/multiboot2.h index 0488849d7..a241a70ad 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -85,10 +85,12 @@ #define MULTIBOOT_INFO_APM_TABLE 0x00000400 /* Is there video information? */ -#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE +typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; typedef unsigned int multiboot_uint32_t; typedef unsigned long long multiboot_uint64_t; @@ -187,9 +189,43 @@ struct multiboot_info multiboot_uint16_t vbe_interface_seg; multiboot_uint16_t vbe_interface_off; multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; }; typedef struct multiboot_info multiboot_info_t; +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + struct multiboot_mmap_entry { multiboot_uint32_t size; diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 4360e8a2c..637bc5d49 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -28,13 +28,11 @@ */ /* The bits in the required part of flags field we don't support. */ -#define UNSUPPORTED_FLAGS 0x0000fffc +#define UNSUPPORTED_FLAGS 0x0000fff8 #include #include #include -#include -#include #include #include #include @@ -90,8 +88,6 @@ grub_multiboot_boot (void) if (err) return err; - grub_video_set_mode ("text", NULL); - grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); @@ -235,6 +231,34 @@ grub_multiboot (int argc, char *argv[]) else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE) goto fail; + if (header->flags & MULTIBOOT_VIDEO_MODE) + { + switch (header->mode_type) + { + case 1: + grub_env_set ("gfxpayload", "text"); + break; + + case 0: + { + char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; + if (header->depth && header->width && header->height) + grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, + header->height, header->depth, header->width, + header->height); + else if (header->width && header->height) + grub_sprintf (buf, "%dx%d,auto", header->width, header->height); + else + grub_sprintf (buf, "auto"); + + grub_env_set ("gfxpayload", buf); + break; + } + } + } + + grub_multiboot_set_accepts_video (!!(header->flags & MULTIBOOT_VIDEO_MODE)); + grub_multiboot_set_bootdev (); grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c index 58802d44c..5f33a7314 100644 --- a/loader/i386/multiboot_mbi.c +++ b/loader/i386/multiboot_mbi.c @@ -29,6 +29,16 @@ #include #include #include +#include + +#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) +#include +#define DEFAULT_VIDEO_MODE "text" +#define HAS_VGA_TEXT 1 +#else +#define DEFAULT_VIDEO_MODE "auto" +#define HAS_VGA_TEXT 0 +#endif struct module { @@ -46,6 +56,13 @@ static unsigned modcnt; static char *cmdline = NULL; static grub_uint32_t bootdev; static int bootdev_set; +static int accepts_video; + +void +grub_multiboot_set_accepts_video (int val) +{ + accepts_video = val; +} /* Return the length of the Multiboot mmap that will be needed to allocate our platform's map. */ @@ -73,7 +90,8 @@ grub_multiboot_get_mbi_size (void) { return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd - + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len (); + + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len () + + 256 * sizeof (struct multiboot_color); } /* Fill previously allocated Multiboot mmap. */ @@ -106,6 +124,107 @@ grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) grub_mmap_iterate (hook); } +static grub_err_t +set_video_mode (void) +{ + grub_err_t err; + const char *modevar; + + if (accepts_video || !HAS_VGA_TEXT) + { + modevar = grub_env_get ("gfxpayload"); + if (! modevar || *modevar == 0) + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0); + else + { + char *tmp; + tmp = grub_malloc (grub_strlen (modevar) + + sizeof (DEFAULT_VIDEO_MODE) + 1); + if (! tmp) + return grub_errno; + grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); + err = grub_video_set_mode (tmp, 0); + grub_free (tmp); + } + } + else + err = grub_video_set_mode ("text", 0); + + return err; +} + +static grub_err_t +retrieve_video_parameters (struct multiboot_info *mbi, + grub_uint8_t *ptrorig, grub_uint32_t ptrdest) +{ + grub_err_t err; + struct grub_video_mode_info mode_info; + void *framebuffer; + grub_video_driver_id_t driv_id; + struct grub_video_palette_data palette[256]; + + err = set_video_mode (); + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + + grub_video_get_palette (0, ARRAY_SIZE (palette), palette); + + driv_id = grub_video_get_driver_id (); + if (driv_id == GRUB_VIDEO_DRIVER_NONE) + return GRUB_ERR_NONE; + + err = grub_video_get_info_and_fini (&mode_info, &framebuffer); + if (err) + return err; + + mbi->framebuffer_addr = (grub_addr_t) framebuffer; + mbi->framebuffer_pitch = mode_info.pitch; + + mbi->framebuffer_width = mode_info.width; + mbi->framebuffer_height = mode_info.height; + + mbi->framebuffer_bpp = mode_info.bpp; + + if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) + { + struct multiboot_color *mb_palette; + unsigned i; + mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED; + mbi->framebuffer_palette_addr = ptrdest; + mbi->framebuffer_palette_num_colors = mode_info.number_of_colors; + if (mbi->framebuffer_palette_num_colors > ARRAY_SIZE (palette)) + mbi->framebuffer_palette_num_colors = ARRAY_SIZE (palette); + mb_palette = (struct multiboot_color *) ptrorig; + for (i = 0; i < mbi->framebuffer_palette_num_colors; i++) + { + mb_palette[i].red = palette[i].r; + mb_palette[i].green = palette[i].g; + mb_palette[i].blue = palette[i].b; + } + ptrorig += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + ptrdest += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + } + else + { + mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_RGB; + mbi->framebuffer_red_field_position = mode_info.green_field_pos; + mbi->framebuffer_red_mask_size = mode_info.green_mask_size; + mbi->framebuffer_green_field_position = mode_info.green_field_pos; + mbi->framebuffer_green_mask_size = mode_info.green_mask_size; + mbi->framebuffer_blue_field_position = mode_info.blue_field_pos; + mbi->framebuffer_blue_mask_size = mode_info.blue_mask_size; + } + + mbi->flags |= MULTIBOOT_INFO_FRAMEBUFFER_INFO; + + return GRUB_ERR_NONE; +} + grub_err_t grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, grub_size_t bufsize) @@ -117,6 +236,7 @@ grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, unsigned i; struct module *cur; grub_size_t mmap_size; + grub_err_t err; if (bufsize < grub_multiboot_get_mbi_size ()) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "mbi buffer is too small"); @@ -182,6 +302,13 @@ grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off, mbi->flags |= MULTIBOOT_INFO_BOOTDEV; } + err = retrieve_video_parameters (mbi, ptrorig, ptrdest); + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + return GRUB_ERR_NONE; } From a0b766fc9b50388d12eb5ed08756f5c5ab0ad480 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 21:11:51 +0100 Subject: [PATCH 160/164] 2010-01-15 Vladimir Serbinenko Enable multiboot on non-pc. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (pkglib_MODULES): Move multiboot.mod and multiboot2.mod to ... * conf/i386.rmk (pkglib_MODULES): ... here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_SOURCES): Moved to ... * conf/i386.rmk (multiboot_mod_SOURCES): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_CFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_CFLAGS): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_ASFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_ASFLAGS): .. here. * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_LDFLAGS): Moved to ... * conf/i386.rmk (multiboot_mod_LDFLAGS): .. here. * conf/x86_64-efi.rmk (pkglib_MODULES): Remove ata.mod and relocator.mod. (ata_mod_SOURCES): Removed. (ata_mod_CFLAGS): Likewise. (ata_mod_LDFLAGS): Likewise. (relocator_mod_SOURCES): Removed. (relocator_mod_CFLAGS): Likewise. (relocator_mod_ASFLAGS): Likewise. (relocator_mod_LDFLAGS): Likewise. Include i386.mk. * include/grub/x86_64/multiboot.h: New file. * loader/i386/multiboot.c (grub_multiboot_boot) [GRUB_MACHINE_EFI]: Terminate EFI. --- ChangeLog | 33 +++++++++++++++++++++++++++++++++ conf/i386-coreboot.rmk | 16 ---------------- conf/i386-pc.rmk | 16 ---------------- conf/i386.rmk | 16 ++++++++++++++++ conf/x86_64-efi.rmk | 14 ++------------ include/grub/x86_64/multiboot.h | 1 + loader/i386/multiboot.c | 9 +++++++++ 7 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 include/grub/x86_64/multiboot.h diff --git a/ChangeLog b/ChangeLog index 8d3245ea3..3acc543d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2010-01-15 Vladimir Serbinenko + + Enable multiboot on non-pc. + + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (pkglib_MODULES): Move + multiboot.mod and multiboot2.mod to ... + * conf/i386.rmk (pkglib_MODULES): ... here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_SOURCES): + Moved to ... + * conf/i386.rmk (multiboot_mod_SOURCES): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_CFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_CFLAGS): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_ASFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_ASFLAGS): .. here. + * conf/i386-coreboot.rmk, conf/i386-pc.rmk (multiboot_mod_LDFLAGS): + Moved to ... + * conf/i386.rmk (multiboot_mod_LDFLAGS): .. here. + * conf/x86_64-efi.rmk (pkglib_MODULES): Remove ata.mod and + relocator.mod. + (ata_mod_SOURCES): Removed. + (ata_mod_CFLAGS): Likewise. + (ata_mod_LDFLAGS): Likewise. + (relocator_mod_SOURCES): Removed. + (relocator_mod_CFLAGS): Likewise. + (relocator_mod_ASFLAGS): Likewise. + (relocator_mod_LDFLAGS): Likewise. + Include i386.mk. + * include/grub/x86_64/multiboot.h: New file. + * loader/i386/multiboot.c (grub_multiboot_boot) [GRUB_MACHINE_EFI]: + Terminate EFI. + 2010-01-15 Vladimir Serbinenko Video multiboot support. diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index d73c9f0e2..57fb3350c 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -140,22 +140,6 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += multiboot.mod -multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot_mod_CFLAGS = $(COMMON_CFLAGS) -multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += multiboot2.mod -multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/multiboot_loader.c \ - loader/i386/multiboot_mbi.c -multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 -multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) - # For aout.mod. aout_mod_SOURCES = loader/aout.c aout_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 2a69571aa..a89203dea 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -201,22 +201,6 @@ serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) -pkglib_MODULES += multiboot.mod -multiboot_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot_mod_CFLAGS = $(COMMON_CFLAGS) -multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) - -pkglib_MODULES += multiboot2.mod -multiboot2_mod_SOURCES = loader/i386/multiboot.c \ - loader/i386/multiboot_mbi.c \ - loader/multiboot_loader.c -multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 -multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) -multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) - # For vbe.mod. vbe_mod_SOURCES = video/i386/pc/vbe.c vbe_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386.rmk b/conf/i386.rmk index c3f036d0f..7ef337c61 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -25,3 +25,19 @@ pkglib_MODULES += ata.mod ata_mod_SOURCES = disk/ata.c ata_mod_CFLAGS = $(COMMON_CFLAGS) ata_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += multiboot.mod +multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c +multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) + +pkglib_MODULES += multiboot2.mod +multiboot2_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_mbi.c \ + loader/multiboot_loader.c +multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 +multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 4f6ace057..122700711 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -32,7 +32,7 @@ grub_install_SOURCES = util/i386/efi/grub-install.in pkglib_MODULES = kernel.img chain.mod appleldr.mod \ halt.mod reboot.mod linux.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod ata.mod + fixvideo.mod mmap.mod acpi.mod # For kernel.img. kernel_img_EXPORTS = no @@ -77,11 +77,6 @@ acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c acpi_mod_CFLAGS = $(COMMON_CFLAGS) acpi_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For ata.mod -ata_mod_SOURCES = disk/ata.c -ata_mod_CFLAGS = $(COMMON_CFLAGS) -ata_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \ mmap/efi/mmap.c @@ -166,10 +161,5 @@ xnu_mod_CFLAGS = $(COMMON_CFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) -pkglib_MODULES += relocator.mod -relocator_mod_SOURCES = lib/i386/relocator.c lib/i386/relocator_asm.S lib/i386/relocator_backward.S -relocator_mod_CFLAGS = $(COMMON_CFLAGS) -relocator_mod_ASFLAGS = $(COMMON_ASFLAGS) -relocator_mod_LDFLAGS = $(COMMON_LDFLAGS) - +include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk diff --git a/include/grub/x86_64/multiboot.h b/include/grub/x86_64/multiboot.h new file mode 100644 index 000000000..957c7a5ad --- /dev/null +++ b/include/grub/x86_64/multiboot.h @@ -0,0 +1 @@ +#include diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 637bc5d49..d06f18692 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -46,6 +46,10 @@ #include #include +#ifdef GRUB_MACHINE_EFI +#include +#endif + extern grub_dl_t my_mod; static grub_size_t code_size, alloc_mbi; @@ -88,6 +92,11 @@ grub_multiboot_boot (void) if (err) return err; +#ifdef GRUB_MACHINE_EFI + if (! grub_efi_finish_boot_services ()) + grub_fatal ("cannot exit boot services"); +#endif + grub_relocator32_boot (grub_multiboot_payload_orig, grub_multiboot_payload_dest, state); From 70a14d3d49985c98f60bcec788e9261ff5e2db16 Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 16 Jan 2010 00:26:52 +0000 Subject: [PATCH 161/164] 2010-01-16 Carles Pina i Estany * util/misc.c (grub_util_warn): Gettextizze, print full stop after the message. (grub_util_info): Likewise. (grub_util_error): Likewise. * util/elf/grub-mkimage.c: Fix capitalisation, quotes, full stops and/or new lines in `grub_util_warna', `grub_util_info', `grub_util_error' calls. * util/getroot.c: Likewise. * util/grub-editenv.c: Likewise. * util/grub-emu.c: Likewise. * util/grub-fstest.c: Likewise. * util/grub-mkdevicemap.c: Likewise. * util/grub-mkfont.c: Likewise. * util/grub-mkpasswd-pbkdf2.c: Likewise. * util/grub-mkrelpath.c: Likewise. * util/grub-pe2elf.c: Likewise. * util/grub-probe.c: Likewise. * util/hostdisk.c: Likewise. * util/i386/efi/grub-mkimage.c: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/i386/pc/grub-setup.c: Likewise. * util/ieee1275/ofpath.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/write.c: Likewise. * util/raid.c: Likewise. * util/sparc64/ieee1275/grub-mkimage.c: Likewise. * util/sparc64/ieee1275/grub-setup.c: Likewise. --- ChangeLog | 31 +++++++++++++++++++++ util/elf/grub-mkimage.c | 2 +- util/getroot.c | 26 +++++++++--------- util/grub-editenv.c | 2 +- util/grub-emu.c | 6 ++--- util/grub-fstest.c | 34 +++++++++++------------ util/grub-mkdevicemap.c | 2 +- util/grub-mkfont.c | 12 ++++----- util/grub-mkpasswd-pbkdf2.c | 22 +++++++-------- util/grub-mkrelpath.c | 2 +- util/grub-pe2elf.c | 14 +++++----- util/grub-probe.c | 12 ++++----- util/hostdisk.c | 4 +-- util/i386/efi/grub-mkimage.c | 4 +-- util/i386/pc/grub-mkimage.c | 4 +-- util/i386/pc/grub-setup.c | 40 ++++++++++++++-------------- util/ieee1275/ofpath.c | 12 ++++----- util/misc.c | 15 ++++++----- util/mkisofs/eltorito.c | 6 ++--- util/mkisofs/rock.c | 2 +- util/mkisofs/write.c | 2 +- util/raid.c | 6 ++--- util/sparc64/ieee1275/grub-mkimage.c | 2 +- util/sparc64/ieee1275/grub-setup.c | 40 ++++++++++++++-------------- 24 files changed, 168 insertions(+), 134 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3acc543d4..0effe5e10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2010-01-16 Carles Pina i Estany + + * util/misc.c (grub_util_warn): Gettextizze, print full stop after + the message. + (grub_util_info): Likewise. + (grub_util_error): Likewise. + * util/elf/grub-mkimage.c: Fix capitalisation, quotes, full stops + and/or new lines in `grub_util_warna', `grub_util_info', + `grub_util_error' calls. + * util/getroot.c: Likewise. + * util/grub-editenv.c: Likewise. + * util/grub-emu.c: Likewise. + * util/grub-fstest.c: Likewise. + * util/grub-mkdevicemap.c: Likewise. + * util/grub-mkfont.c: Likewise. + * util/grub-mkpasswd-pbkdf2.c: Likewise. + * util/grub-mkrelpath.c: Likewise. + * util/grub-pe2elf.c: Likewise. + * util/grub-probe.c: Likewise. + * util/hostdisk.c: Likewise. + * util/i386/efi/grub-mkimage.c: Likewise. + * util/i386/pc/grub-mkimage.c: Likewise. + * util/i386/pc/grub-setup.c: Likewise. + * util/ieee1275/ofpath.c: Likewise. + * util/mkisofs/eltorito.c: Likewise. + * util/mkisofs/rock.c: Likewise. + * util/mkisofs/write.c: Likewise. + * util/raid.c: Likewise. + * util/sparc64/ieee1275/grub-mkimage.c: Likewise. + * util/sparc64/ieee1275/grub-setup.c: Likewise. + 2010-01-15 Vladimir Serbinenko Enable multiboot on non-pc. diff --git a/util/elf/grub-mkimage.c b/util/elf/grub-mkimage.c index 6ba8b1ae2..c0736b83f 100644 --- a/util/elf/grub-mkimage.c +++ b/util/elf/grub-mkimage.c @@ -328,7 +328,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s -o FILE [OPTION]... [MODULES]\n\ diff --git a/util/getroot.c b/util/getroot.c index 22ad7e967..6357c8a26 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -115,14 +115,14 @@ grub_get_prefix (const char *dir) saved_cwd = xgetcwd (); if (chdir (dir) < 0) - grub_util_error ("Cannot change directory to `%s'", dir); + grub_util_error ("cannot change directory to `%s'", dir); abs_dir = xgetcwd (); strip_extra_slashes (abs_dir); prev_dir = xstrdup (abs_dir); if (stat (".", &prev_st) < 0) - grub_util_error ("Cannot stat `%s'", dir); + grub_util_error ("cannot stat `%s'", dir); if (! S_ISDIR (prev_st.st_mode)) grub_util_error ("`%s' is not a directory", dir); @@ -130,13 +130,13 @@ grub_get_prefix (const char *dir) while (1) { if (chdir ("..") < 0) - grub_util_error ("Cannot change directory to the parent"); + grub_util_error ("cannot change directory to the parent"); if (stat (".", &st) < 0) - grub_util_error ("Cannot stat current directory"); + grub_util_error ("cannot stat current directory"); if (! S_ISDIR (st.st_mode)) - grub_util_error ("Current directory is not a directory???"); + grub_util_error ("current directory is not a directory???"); if (prev_st.st_dev != st.st_dev || prev_st.st_ino == st.st_ino) break; @@ -153,7 +153,7 @@ grub_get_prefix (const char *dir) strip_extra_slashes (prefix); if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot change directory to `%s'", dir); + grub_util_error ("cannot change directory to `%s'", dir); #ifdef __CYGWIN__ if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16)) @@ -236,7 +236,7 @@ find_root_device (const char *dir, dev_t dev) if (res) { if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -279,7 +279,7 @@ find_root_device (const char *dir, dev_t dev) continue; if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -288,7 +288,7 @@ find_root_device (const char *dir, dev_t dev) } if (chdir (saved_cwd) < 0) - grub_util_error ("Cannot restore the original directory"); + grub_util_error ("cannot restore the original directory"); free (saved_cwd); closedir (dp); @@ -445,7 +445,7 @@ grub_guess_root_device (const char *dir) struct stat st; if (stat (dir, &st) < 0) - grub_util_error ("Cannot stat `%s'", dir); + grub_util_error ("cannot stat `%s'", dir); #ifdef __CYGWIN__ /* Cygwin specific function. */ @@ -591,7 +591,7 @@ grub_util_get_grub_dev (const char *os_dev) free (p); } else - grub_util_error ("Unknown kind of RAID device `%s'", os_dev); + grub_util_error ("unknown kind of RAID device `%s'", os_dev); break; @@ -608,7 +608,7 @@ grub_util_check_block_device (const char *blk_dev) struct stat st; if (stat (blk_dev, &st) < 0) - grub_util_error ("Cannot stat `%s'", blk_dev); + grub_util_error ("cannot stat `%s'", blk_dev); if (S_ISBLK (st.st_mode)) return (blk_dev); @@ -622,7 +622,7 @@ grub_util_check_char_device (const char *blk_dev) struct stat st; if (stat (blk_dev, &st) < 0) - grub_util_error ("Cannot stat `%s'", blk_dev); + grub_util_error ("cannot stat `%s'", blk_dev); if (S_ISCHR (st.st_mode)) return (blk_dev); diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 1fb1422df..ea0e4da19 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -69,7 +69,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-editenv --help'' for more information.\n"); + fprintf (stderr, "Try `grub-editenv --help' for more information.\n"); else printf ("\ Usage: grub-editenv [OPTIONS] [FILENAME] COMMAND\n\ diff --git a/util/grub-emu.c b/util/grub-emu.c index 3f2acaaec..a04aeae78 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -129,7 +129,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``grub-emu --help'' for more information.\n"); + "Try `grub-emu --help' for more information.\n"); else printf ( "Usage: grub-emu [OPTION]...\n" @@ -220,14 +220,14 @@ main (int argc, char *argv[]) { char *device_name = grub_guess_root_device (dir); if (! device_name) - grub_util_error ("cannot find a device for %s.\n", dir); + grub_util_error ("cannot find a device for %s", dir); root_dev = grub_util_get_grub_dev (device_name); if (! root_dev) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''."); + grub_util_error ("cannot guess the root device. Specify the option `--root-device'"); } } diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 586dda0f9..4470cbfa5 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -71,7 +71,7 @@ execute_command (char *name, int n, char **args) cmd = grub_command_find (name); if (! cmd) - grub_util_error ("Can\'t find command %s", name); + grub_util_error ("can\'t find command %s", name); return (cmd->func) (cmd, n, args); } @@ -100,9 +100,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) dev = grub_device_open (0); if ((! dev) || (! dev->disk)) - grub_util_error ("Can\'t open device."); + grub_util_error ("can\'t open device"); - grub_util_info ("total sectors : %lld.", + grub_util_info ("total sectors : %lld", (unsigned long long) dev->disk->total_sectors); if (! leng) @@ -115,7 +115,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) len = (leng > BUF_SIZE) ? BUF_SIZE : leng; if (grub_disk_read (dev->disk, 0, skip, len, buf)) - grub_util_error ("Disk read fails at offset %lld, length %d.", + grub_util_error ("disk read fails at offset %lld, length %d", skip, len); if (hook (skip, buf, len)) @@ -132,15 +132,15 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) file = grub_file_open (pathname); if (!file) { - grub_util_error ("cannot open file %s.", pathname); + grub_util_error ("cannot open file %s", pathname); return; } - grub_util_info ("file size : %lld.", (unsigned long long) file->size); + grub_util_info ("file size : %lld", (unsigned long long) file->size); if (skip > file->size) { - grub_util_error ("invalid skip value %lld.", (unsigned long long) skip); + grub_util_error ("invalid skip value %lld", (unsigned long long) skip); return; } @@ -158,7 +158,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len); if (sz < 0) { - grub_util_error ("read error at offset %llu.", ofs); + grub_util_error ("read error at offset %llu", ofs); break; } @@ -184,7 +184,7 @@ cmd_cp (char *src, char *dest) if ((int) fwrite (buf, 1, len, ff) != len) { - grub_util_error ("write error."); + grub_util_error ("write error"); return 1; } @@ -194,7 +194,7 @@ cmd_cp (char *src, char *dest) ff = fopen (dest, "wb"); if (ff == NULL) { - grub_util_error ("open error."); + grub_util_error ("open error"); return; } read_file (src, cp_hook); @@ -212,7 +212,7 @@ cmd_cmp (char *src, char *dest) { if ((int) fread (buf_1, 1, len, ff) != len) { - grub_util_error ("read error at offset %llu.", ofs); + grub_util_error ("read error at offset %llu", ofs); return 1; } @@ -223,7 +223,7 @@ cmd_cmp (char *src, char *dest) for (i = 0; i < len; i++, ofs++) if (buf_1[i] != buf[i]) { - grub_util_error ("compare fail at offset %llu.", ofs); + grub_util_error ("compare fail at offset %llu", ofs); return 1; } } @@ -233,12 +233,12 @@ cmd_cmp (char *src, char *dest) ff = fopen (dest, "rb"); if (ff == NULL) { - grub_util_error ("open error."); + grub_util_error ("open error"); return; } if ((skip) && (fseeko (ff, skip, SEEK_SET))) - grub_util_error ("seek error."); + grub_util_error ("seek error"); read_file (src, cmp_hook); fclose (ff); @@ -286,13 +286,13 @@ fstest (char **images, int num_disks, int cmd, int n, char **args) for (i = 0; i < num_disks; i++) { if (grub_strlen (images[i]) + 7 > sizeof (host_file)) - grub_util_error ("Pathname %s too long.", images[i]); + grub_util_error ("pathname %s too long", images[i]); grub_sprintf (loop_name, "loop%d", i); grub_sprintf (host_file, "(host)%s", images[i]); if (execute_command ("loopback", 3, argv)) - grub_util_error ("loopback command fails."); + grub_util_error ("loopback command fails"); } grub_lvm_fini (); @@ -349,7 +349,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\ diff --git a/util/grub-mkdevicemap.c b/util/grub-mkdevicemap.c index b4febbb8d..c68482af1 100644 --- a/util/grub-mkdevicemap.c +++ b/util/grub-mkdevicemap.c @@ -84,7 +84,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``%s --help'' for more information.\n", program_name); + "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]...\n\ diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 3d1c6faac..fcd35afd4 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -96,7 +96,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] FONT_FILES\n\ @@ -347,7 +347,7 @@ write_font (struct grub_font_info *font_info, char *output_file) file = fopen (output_file, "wb"); if (! file) - grub_util_error ("Can\'t write to file %s.", output_file); + grub_util_error ("can\'t write to file %s.", output_file); offset = 0; @@ -546,7 +546,7 @@ main (int argc, char *argv[]) a = strtoul (p, &p, 0); if (*p != '-') - grub_util_error ("Invalid font range"); + grub_util_error ("invalid font range"); b = strtoul (p + 1, &p, 0); if ((font_info.num_range & (GRUB_FONT_RANGE_BLOCK - 1)) == 0) font_info.ranges = xrealloc (font_info.ranges, @@ -561,7 +561,7 @@ main (int argc, char *argv[]) if (*p) { if (*p != ',') - grub_util_error ("Invalid font range"); + grub_util_error ("invalid font range"); else p++; } @@ -598,7 +598,7 @@ main (int argc, char *argv[]) } if (! output_file) - grub_util_error ("No output file is specified."); + grub_util_error ("no output file is specified"); if (FT_Init_FreeType (&ft_lib)) grub_util_error ("FT_Init_FreeType fails"); @@ -610,7 +610,7 @@ main (int argc, char *argv[]) if (FT_New_Face (ft_lib, argv[optind], font_index, &ft_face)) { - grub_util_info ("Can't open file %s, index %d\n", argv[optind], + grub_util_info ("can't open file %s, index %d", argv[optind], font_index); continue; } diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index b27a4e893..f5fdcca96 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -74,7 +74,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-scrypt --help'' for more information.\n"); + fprintf (stderr, "Try `grub-scrypt --help' for more information.\n"); else printf ("\ Usage: grub-scrypt [OPTIONS]\n\ @@ -165,12 +165,12 @@ main (int argc, char *argv[]) bufhex = malloc (buflen * 2 + 1); if (!bufhex) - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); buf = malloc (buflen); if (!buf) { free (bufhex); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } salt = malloc (saltlen); @@ -178,7 +178,7 @@ main (int argc, char *argv[]) { free (bufhex); free (buf); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } salthex = malloc (saltlen * 2 + 1); if (!salthex) @@ -186,7 +186,7 @@ main (int argc, char *argv[]) free (salt); free (bufhex); free (buf); - grub_util_error ("Out of memory"); + grub_util_error ("out of memory"); } /* Disable echoing. Based on glibc. */ @@ -225,7 +225,7 @@ main (int argc, char *argv[]) /* Restore the original setting. */ if (tty_changed) (void) tcsetattr (fileno (in), TCSAFLUSH, &s); - grub_util_error ("Failure to read password"); + grub_util_error ("failure to read password"); } if (nr >= 1 && pass1[nr-1] == '\n') pass1[nr-1] = 0; @@ -249,7 +249,7 @@ main (int argc, char *argv[]) free (bufhex); free (salthex); free (salt); - grub_util_error ("Failure to read password"); + grub_util_error ("failure to read password"); } if (nr >= 1 && pass2[nr-1] == '\n') pass2[nr-1] = 0; @@ -264,7 +264,7 @@ main (int argc, char *argv[]) free (bufhex); free (salthex); free (salt); - grub_util_error ("Passwords don't match"); + grub_util_error ("passwords don't match"); } memset (pass2, 0, strlen (pass2)); free (pass2); @@ -286,7 +286,7 @@ main (int argc, char *argv[]) free (salthex); free (salt); fclose (f); - grub_util_error ("Couldn't retrieve random data for salt"); + grub_util_error ("couldn't retrieve random data for salt"); } rd = fread (salt, 1, saltlen, f); if (rd != saltlen) @@ -299,7 +299,7 @@ main (int argc, char *argv[]) free (salthex); free (salt); fclose (f); - grub_util_error ("Couldn't retrieve random data for salt"); + grub_util_error ("couldn't retrieve random data for salt"); } fclose (f); } @@ -321,7 +321,7 @@ main (int argc, char *argv[]) memset (salthex, 0, 2 * saltlen); free (salt); free (salthex); - grub_util_error ("Cryptographic error number %d", gcry_err); + grub_util_error ("cryptographic error number %d", gcry_err); } hexify (bufhex, buf, buflen); diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c index 62e400814..327f0c866 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -34,7 +34,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] PATH\n\ diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index fb370d9ec..488ad9b23 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -40,7 +40,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTIONS] input [output]\n\ @@ -182,7 +182,7 @@ write_section_data (FILE* fp, char *image, char name[5 + strlen (pe_shdr->name)]; if (num_sections >= MAX_SECTIONS) - grub_util_error ("Too many sections"); + grub_util_error ("too many sections"); sprintf (name, ".rel%s", pe_shdr->name); @@ -230,14 +230,14 @@ write_reloc_section (FILE* fp, char *image, if ((pe_rel->symtab_index >= pe_chdr->num_symbols) || (symtab_map[pe_rel->symtab_index] == -1)) - grub_util_error ("Invalid symbol"); + grub_util_error ("invalid symbol"); if (pe_rel->type == GRUB_PE32_REL_I386_DIR32) type = R_386_32; else if (pe_rel->type == GRUB_PE32_REL_I386_REL32) type = R_386_PC32; else - grub_util_error ("Unknown pe relocation type %d\n", pe_rel->type); + grub_util_error ("unknown pe relocation type %d\n", pe_rel->type); ofs = pe_rel->offset - pe_sec->virtual_address; addr = (grub_uint32_t *)(image + pe_sec->raw_data_offset + ofs); @@ -248,14 +248,14 @@ write_reloc_section (FILE* fp, char *image, code = image[pe_sec->raw_data_offset + ofs - 1]; if (((code != 0xe8) && (code != 0xe9)) || (*addr)) - grub_util_error ("Invalid relocation (%x %x)", code, *addr); + grub_util_error ("invalid relocation (%x %x)", code, *addr); modified = 1; if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx) { if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx != shdr[i].sh_info) - grub_util_error ("Cross section call is not allowed"); + grub_util_error ("cross section call is not allowed"); *addr = (symtab[symtab_map[pe_rel->symtab_index]].st_value - ofs - 4); @@ -440,7 +440,7 @@ convert_pe (FILE* fp, char *image) pe_chdr = (struct grub_pe32_coff_header *) image; if (grub_le_to_cpu16 (pe_chdr->machine) != GRUB_PE32_MACHINE_I386) - grub_util_error ("Invalid coff image"); + grub_util_error ("invalid coff image"); strtab = xmalloc (STRTAB_BLOCK); strtab_max = STRTAB_BLOCK; diff --git a/util/grub-probe.c b/util/grub-probe.c index 4ba8a98e5..879098542 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -84,7 +84,7 @@ probe_partmap (grub_disk_t disk) { if (disk->partition == NULL) { - grub_util_info ("No partition map found for %s", disk->name); + grub_util_info ("no partition map found for %s", disk->name); return; } @@ -113,17 +113,17 @@ probe (const char *path, char *device_name) { #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (! grub_util_check_char_device (device_name)) - grub_util_error ("%s is not a character device.\n", device_name); + grub_util_error ("%s is not a character device", device_name); #else if (! grub_util_check_block_device (device_name)) - grub_util_error ("%s is not a block device.\n", device_name); + grub_util_error ("%s is not a block device", device_name); #endif } else device_name = grub_guess_root_device (path); if (! device_name) - grub_util_error ("cannot find a device for %s (is /dev mounted?).\n", path); + grub_util_error ("cannot find a device for %s (is /dev mounted?)", path); if (print == PRINT_DEVICE) { @@ -133,7 +133,7 @@ probe (const char *path, char *device_name) drive_name = grub_util_get_grub_dev (device_name); if (! drive_name) - grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name); + grub_util_error ("cannot find a GRUB drive for %s. Check your device.map", device_name); if (print == PRINT_DRIVE) { @@ -309,7 +309,7 @@ usage (int status) { if (status) fprintf (stderr, - "Try ``%s --help'' for more information.\n", program_name); + "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... [PATH|DEVICE]\n\ diff --git a/util/hostdisk.c b/util/hostdisk.c index c94f4237e..603445801 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -568,7 +568,7 @@ read_device_map (const char *dev_map) fp = fopen (dev_map, "r"); if (! fp) { - grub_util_info (_("Cannot open `%s'"), dev_map); + grub_util_info (_("cannot open `%s'"), dev_map); return; } @@ -639,7 +639,7 @@ read_device_map (const char *dev_map) symbolic links. */ map[drive].device = xmalloc (PATH_MAX); if (! realpath (p, map[drive].device)) - grub_util_error ("Cannot get the real path of `%s'", p); + grub_util_error ("cannot get the real path of `%s'", p); #else map[drive].device = xstrdup (p); #endif diff --git a/util/i386/efi/grub-mkimage.c b/util/i386/efi/grub-mkimage.c index 7f5141531..8fee3e8d9 100644 --- a/util/i386/efi/grub-mkimage.c +++ b/util/i386/efi/grub-mkimage.c @@ -778,7 +778,7 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e, if ((ELF_R_TYPE (info) == R_X86_64_32) || (ELF_R_TYPE (info) == R_X86_64_32S)) { - grub_util_error ("Can\'t add fixup entry for R_X86_64_32(S)"); + grub_util_error ("can\'t add fixup entry for R_X86_64_32(S)"); } else if (ELF_R_TYPE (info) == R_X86_64_64) { @@ -1029,7 +1029,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``grub-mkimage --help'' for more information.\n"); + fprintf (stderr, "Try `grub-mkimage --help' for more information.\n"); else printf ("\ Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\ diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index ebf1bc7ff..08807b4d1 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -289,7 +289,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], #ifdef GRUB_MACHINE_PCBIOS if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER) - grub_util_error (_("Core image is too big (%p > %p)\n"), + grub_util_error (_("core image is too big (%p > %p)"), GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER); #endif @@ -326,7 +326,7 @@ static void usage (int status) { if (status) - fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name); + fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ Usage: grub-mkimage [OPTION]... [MODULES]\n\ diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 909a521eb..64b017296 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -156,7 +156,7 @@ setup (const char *dir, sector, offset, length); if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The first sector of the core file is not sector-aligned")); + grub_util_error (_("the first sector of the core file is not sector-aligned")); first_sector = sector; } @@ -170,7 +170,7 @@ setup (const char *dir, sector, offset, length, (unsigned) current_segment); if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Non-sector-aligned data is found in the core file")); + grub_util_error (_("non-sector-aligned data is found in the core file")); if (block != first_block && (grub_le_to_cpu64 (prev->start) @@ -184,7 +184,7 @@ setup (const char *dir, block--; if (block->len) - grub_util_error (_("The sectors of the core file are too fragmented")); + grub_util_error (_("the sectors of the core file are too fragmented")); } last_length = length; @@ -195,7 +195,7 @@ setup (const char *dir, boot_path = grub_util_get_path (dir, boot_file); boot_size = grub_util_get_image_size (boot_path); if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is not %u"), + grub_util_error (_("the size of `%s' is not %u"), boot_path, GRUB_DISK_SECTOR_SIZE); boot_img = grub_util_read_image (boot_path); free (boot_path); @@ -212,9 +212,9 @@ setup (const char *dir, core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); if (core_size < GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is too small"), core_path); + grub_util_error (_("the size of `%s' is too small"), core_path); else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("The size of `%s' is too large"), core_path); + grub_util_error (_("the size of `%s' is too large"), core_path); core_img = grub_util_read_image (core_path); @@ -251,7 +251,7 @@ setup (const char *dir, grub_fs_t fs; fs = grub_fs_probe (dest_dev); if (! fs) - grub_util_error (_("Unable to identify a filesystem in %s; safety check can't be performed"), + grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"), dest_dev->disk->name); if (! fs->reserved_first_sector) @@ -304,7 +304,7 @@ setup (const char *dir, bsd_part = -1; } else - grub_util_error (_("No DOS-style partitions found")); + grub_util_error (_("no DOS-style partitions found")); } else dos_part = bsd_part = -1; @@ -413,14 +413,14 @@ setup (const char *dir, unable_to_embed: if (must_embed) - grub_util_error (_("Embedding is not possible, but this is required when " - "the root device is on a RAID array or LVM volume.")); + grub_util_error (_("embedding is not possible, but this is required when " + "the root device is on a RAID array or LVM volume")); grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this " "setup by using blocklists. However, blocklists are UNRELIABLE and " "its use is discouraged.")); if (! force) - grub_util_error (_("If you really want blocklists, use --force.")); + grub_util_error (_("if you really want blocklists, use --force")); /* Make sure that GRUB reads the identical image as the OS. */ tmp_img = xmalloc (core_size); @@ -495,7 +495,7 @@ unable_to_embed: } if (i == MAX_TRIES) - grub_util_error (_("Cannot read `%s' correctly"), core_path_dev); + grub_util_error (_("cannot read `%s' correctly"), core_path_dev); /* Clean out the blocklists. */ block = first_block; @@ -508,7 +508,7 @@ unable_to_embed: block--; if ((char *) block <= core_img) - grub_util_error (_("No terminator in the core image")); + grub_util_error (_("no terminator in the core image")); } /* Now read the core image to determine where the sectors are. */ @@ -519,13 +519,13 @@ unable_to_embed: file->read_hook = save_first_sector; if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Failed to read the first sector of the core image")); + grub_util_error (_("failed to read the first sector of the core image")); block = first_block; file->read_hook = save_blocklists; if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE) != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("Failed to read the rest sectors of the core image")); + grub_util_error (_("failed to read the rest sectors of the core image")); grub_file_close (file); @@ -544,7 +544,7 @@ unable_to_embed: grub_util_info ("opening the core image `%s'", core_path); fp = fopen (core_path, "r+b"); if (! fp) - grub_util_error (_("Cannot open `%s'"), core_path); + grub_util_error (_("cannot open `%s'"), core_path); grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp); fclose (fp); @@ -584,13 +584,13 @@ static void usage (int status) { if (status) - fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name); + fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ Usage: grub-setup [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ -DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\ +DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ -b, --boot-image=FILE use FILE as the boot image [default=%s]\n\ -c, --core-image=FILE use FILE as the core image [default=%s]\n\ @@ -751,7 +751,7 @@ main (int argc, char *argv[]) char *tmp = get_device_name (root_dev); if (! tmp) - grub_util_error (_("Invalid root device `%s'"), root_dev); + grub_util_error (_("invalid root device `%s'"), root_dev); tmp = xstrdup (tmp); free (root_dev); @@ -764,7 +764,7 @@ main (int argc, char *argv[]) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error (_("Cannot guess the root device. Specify the option ``--root-device''.")); + grub_util_error (_("cannot guess the root device. Specify the option `--root-device'")); } } diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index e90488fc3..79a0e8be5 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -131,12 +131,12 @@ block_device_get_sysfs_path_and_link(const char *devicenode, snprintf(sysfs_path, sysfs_path_len, "/sys/block/%s", devicenode); if (!realpath (sysfs_path, rpath)) - grub_util_error ("Cannot get the real path of `%s'", sysfs_path); + grub_util_error ("cannot get the real path of `%s'", sysfs_path); strcat(rpath, "/device"); if (!realpath (rpath, sysfs_path)) - grub_util_error ("Cannot get the real path of `%s'", rpath); + grub_util_error ("cannot get the real path of `%s'", rpath); free (rpath); } @@ -247,12 +247,12 @@ vendor_is_ATA(const char *path) snprintf(buf, PATH_MAX, "%s/vendor", path); fd = open(buf, O_RDONLY); if (fd < 0) - grub_util_error ("Cannot open 'vendor' node of `%s'", path); + grub_util_error ("cannot open 'vendor' node of `%s'", path); memset(buf, 0, PATH_MAX); err = read(fd, buf, PATH_MAX); if (err < 0) - grub_util_error ("Cannot read 'vendor' node of `%s'", path); + grub_util_error ("cannot read 'vendor' node of `%s'", path); close(fd); @@ -288,7 +288,7 @@ check_sas (char *sysfs_path, int *tgt) fd = open(path, O_RDONLY); if (fd < 0) - grub_util_error("Cannot open SAS PHY ID '%s'\n", path); + grub_util_error("cannot open SAS PHY ID `%s'\n", path); memset (phy, 0, sizeof (phy)); read (fd, phy, sizeof (phy)); @@ -375,7 +375,7 @@ grub_util_devname_to_ofpath (char *devname) name_buf = xmalloc (PATH_MAX); name_buf = realpath (devname, name_buf); if (! name_buf) - grub_util_error ("Cannot get the real path of `%s'", devname); + grub_util_error ("cannot get the real path of `%s'", devname); device = get_basename (devname); devnode = strip_trailing_digits (devname); diff --git a/util/misc.c b/util/misc.c index 47dd8c78d..7f347c872 100644 --- a/util/misc.c +++ b/util/misc.c @@ -60,11 +60,12 @@ grub_util_warn (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: warn: ", program_name); + fprintf (stderr, _("%s: warn:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (stderr, ".\n"); fflush (stderr); } @@ -75,11 +76,12 @@ grub_util_info (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: info: ", program_name); + fprintf (stderr, _("%s: info:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (".\n", stderr); fflush (stderr); } } @@ -89,11 +91,12 @@ grub_util_error (const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s: error: ", program_name); + fprintf (stderr, _("%s: error:"), program_name); + fprintf (stderr, " "); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fputc ('\n', stderr); + fprintf (stderr, ".\n"); exit (1); } diff --git a/util/mkisofs/eltorito.c b/util/mkisofs/eltorito.c index a134dfc48..1d2a715e0 100644 --- a/util/mkisofs/eltorito.c +++ b/util/mkisofs/eltorito.c @@ -288,7 +288,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) struct eltorito_boot_info bi_table; bootimage = fopen (de->whole_name, "r+b"); if (bootimage == NULL) - error (1, errno, _("Error opening boot image file '%s' for update"), + error (1, errno, _("Error opening boot image file `%s' for update"), de->whole_name); /* Compute checksum of boot image, sans 64 bytes */ total_len = 0; @@ -296,7 +296,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) while ((len = fread (csum_buffer, 1, SECTOR_SIZE, bootimage)) > 0) { if (total_len & 3) - error (1, 0, _("Odd alignment at non-end-of-file in boot image '%s'"), + error (1, 0, _("Odd alignment at non-end-of-file in boot image `%s'"), de->whole_name); if (total_len < 64) memset (csum_buffer, 0, 64 - total_len); @@ -308,7 +308,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) } if (total_len != de->size) - error (1, 0, _("Boot image file '%s' changed unexpectedly"), + error (1, 0, _("Boot image file `%s' changed unexpectedly"), de->whole_name); /* End of file, set position to byte 8 */ fseeko (bootimage, (off_t) 8, SEEK_SET); diff --git a/util/mkisofs/rock.c b/util/mkisofs/rock.c index f18b0bd83..a7a39f774 100644 --- a/util/mkisofs/rock.c +++ b/util/mkisofs/rock.c @@ -306,7 +306,7 @@ int deep_opt; * the symbolic link won't fit into one SL System Use Field * print an error message and continue with splited one */ - fprintf (stderr, _("symbolic link ``%s'' too long for one SL System Use Field, splitting"), cpnt); + fprintf (stderr, _("symbolic link `%s' too long for one SL System Use Field, splitting"), cpnt); } if(MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes)) add_CE_entry(); } diff --git a/util/mkisofs/write.c b/util/mkisofs/write.c index 5447229c8..e1cdd213e 100644 --- a/util/mkisofs/write.c +++ b/util/mkisofs/write.c @@ -158,7 +158,7 @@ void FDECL4(xfwrite, void *, buffer, uint64_t, count, uint64_t, size, FILE *, fi sprintf(nbuf, "%s_%02d", outfile, idx++); file = freopen(nbuf, "wb", file); if (file == NULL) - error (1, errno, _("Cannot open '%s'"), nbuf); + error (1, errno, _("Cannot open `%s'"), nbuf); } while(count) diff --git a/util/raid.c b/util/raid.c index 83a0ee6e2..ec3ecd26e 100644 --- a/util/raid.c +++ b/util/raid.c @@ -50,7 +50,7 @@ grub_util_getdiskname (int major, int minor) else if (major == SCSI_DISK0_MAJOR) sprintf (name, "/dev/sd%c", 'a' + minor / 16); else - grub_util_error ("Unknown device number: %d, %d", major, minor); + grub_util_error ("unknown device number: %d, %d", major, minor); return name; } @@ -72,7 +72,7 @@ grub_util_raid_getmembers (char *name) fd = open (devname, O_RDONLY); if (fd == -1) - grub_util_error ("Can't open %s: %s", devname, strerror (errno)); + grub_util_error ("can't open %s: %s", devname, strerror (errno)); free (devname); @@ -81,7 +81,7 @@ grub_util_raid_getmembers (char *name) grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno)); if (version.major != 0 || version.minor != 90) - grub_util_error ("Unsupported RAID version: %d.%d", + grub_util_error ("unsupported RAID version: %d.%d", version.major, version.minor); ret = ioctl (fd, GET_ARRAY_INFO, &info); diff --git a/util/sparc64/ieee1275/grub-mkimage.c b/util/sparc64/ieee1275/grub-mkimage.c index 96ddfe3d7..6907b8d8a 100644 --- a/util/sparc64/ieee1275/grub-mkimage.c +++ b/util/sparc64/ieee1275/grub-mkimage.c @@ -191,7 +191,7 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... [MODULES]\n\ diff --git a/util/sparc64/ieee1275/grub-setup.c b/util/sparc64/ieee1275/grub-setup.c index 9d8e67562..c39ea853f 100644 --- a/util/sparc64/ieee1275/grub-setup.c +++ b/util/sparc64/ieee1275/grub-setup.c @@ -161,7 +161,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("first sector is <%llu,%u,%u>", sector, offset, length); if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The first sector of the core file " + grub_util_error ("the first sector of the core file " "is not sector-aligned"); first_sector = sector; @@ -176,7 +176,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("saving <%llu,%u,%u>", sector, offset, length); if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Non-sector-aligned data is found in the core file"); + grub_util_error ("non-sector-aligned data is found in the core file"); if (block != first_block && (grub_be_to_cpu64 (prev->start) @@ -189,7 +189,7 @@ setup (const char *prefix, const char *dir, block--; if (block->len) - grub_util_error ("The sectors of the core file are too fragmented"); + grub_util_error ("the sectors of the core file are too fragmented"); } last_length = length; @@ -201,7 +201,7 @@ setup (const char *prefix, const char *dir, boot_path = grub_util_get_path (dir, boot_file); boot_size = grub_util_get_image_size (boot_path); if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The size of `%s' is not %d", + grub_util_error ("the size of `%s' is not %d", boot_path, GRUB_DISK_SECTOR_SIZE); boot_img = grub_util_read_image (boot_path); free (boot_path); @@ -219,7 +219,7 @@ setup (const char *prefix, const char *dir, core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); if (core_size < GRUB_DISK_SECTOR_SIZE) - grub_util_error ("The size of `%s' is too small", core_path); + grub_util_error ("the size of `%s' is too small", core_path); core_img = grub_util_read_image (core_path); free (core_path); @@ -229,7 +229,7 @@ setup (const char *prefix, const char *dir, + GRUB_DISK_SECTOR_SIZE - sizeof (*block)); - grub_util_info ("root is '%s', dest is '%s', and dest_ofpath is '%s'", + grub_util_info ("root is `%s', dest is `%s', and dest_ofpath is `%s'", root, dest, dest_ofpath); /* Open the root device and the destination device. */ @@ -320,7 +320,7 @@ setup (const char *prefix, const char *dir, } if (i == MAX_TRIES) - grub_util_error ("Cannot read `%s' correctly", core_path); + grub_util_error ("cannot read `%s' correctly", core_path); /* Clean out the blocklists. */ block = first_block; @@ -332,7 +332,7 @@ setup (const char *prefix, const char *dir, block--; if ((char *) block <= core_img) - grub_util_error ("No terminator in the core image"); + grub_util_error ("no terminator in the core image"); } /* Now read the core image to determine where the sectors are. */ @@ -343,13 +343,13 @@ setup (const char *prefix, const char *dir, file->read_hook = save_first_sector; if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Failed to read the first sector of the core image"); + grub_util_error ("failed to read the first sector of the core image"); block = first_block; file->read_hook = save_blocklists; if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE) != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE) - grub_util_error ("Failed to read the rest sectors of the core image"); + grub_util_error ("failed to read the rest sectors of the core image"); grub_file_close (file); @@ -368,7 +368,7 @@ setup (const char *prefix, const char *dir, grub_util_info ("opening the core image `%s'", core_path); fp = fopen (core_path, "r+b"); if (! fp) - grub_util_error ("Cannot open `%s'", core_path); + grub_util_error ("cannot open `%s'", core_path); grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE, fp); fclose (fp); @@ -404,13 +404,13 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ Usage: %s [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ -DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\ +DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ -b, --boot-image=FILE use FILE as the boot image [default=%s]\n\ -c, --core-image=FILE use FILE as the core image [default=%s]\n\ @@ -559,14 +559,14 @@ find_dest_dev (struct grub_setup_info *gp, char *argv[]) fprintf (stderr, "Invalid device `%s'.\n", argv[optind]); usage (1); } - grub_util_info ("transformed OS device '%s' into GRUB device '%s'", + grub_util_info ("transformed OS device `%s' into GRUB device `%s'", argv[optind], gp->dest_dev); } else { /* For simplicity. */ gp->dest_dev = xstrdup (gp->dest_dev); - grub_util_info ("Using '%s' as GRUB device", gp->dest_dev); + grub_util_info ("Using `%s' as GRUB device", gp->dest_dev); } } @@ -578,7 +578,7 @@ check_root_dev (struct grub_setup_info *gp) char *tmp = get_device_name (gp->root_dev); if (! tmp) - grub_util_error ("Invalid root device `%s'", gp->root_dev); + grub_util_error ("invalid root device `%s'", gp->root_dev); tmp = xstrdup (tmp); free (gp->root_dev); @@ -594,11 +594,11 @@ check_root_dev (struct grub_setup_info *gp) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); - grub_util_error ("Cannot guess the root device. " - "Specify the option ``--root-device''."); + grub_util_error ("cannot guess the root device. " + "Specify the option `--root-device'"); } - grub_util_info ("Guessed root device '%s' and root_dev '%s' from " - "dir '%s'", root_device, gp->root_dev, dir); + grub_util_info ("guessed root device `%s' and root_dev `%s' from " + "dir `%s'", root_device, gp->root_dev, dir); } } From 409ae1c92a9eb99a653adc3dba377ae2ed7b024e Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 16 Jan 2010 00:39:14 +0000 Subject: [PATCH 162/164] 2010-01-16 Carles Pina i Estany * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded string. * util/grub-emu.c (usage): Likewise. * util/grub-mkpasswd-pbkdf2.c (usage): Likewise. * util/i386/efi/grub-mkimage.c (usage): Likewise. * util/i386/pc/grub-mkimage.c (usage): Likewise. * util/i386/pc/grub-setup.c (usage): Likewise. --- ChangeLog | 10 ++++++++++ util/grub-editenv.c | 6 +++--- util/grub-emu.c | 6 +++--- util/grub-mkpasswd-pbkdf2.c | 6 +++--- util/i386/efi/grub-mkimage.c | 6 +++--- util/i386/pc/grub-mkimage.c | 4 ++-- util/i386/pc/grub-setup.c | 3 ++- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0effe5e10..793746986 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-01-16 Carles Pina i Estany + + * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded + string. + * util/grub-emu.c (usage): Likewise. + * util/grub-mkpasswd-pbkdf2.c (usage): Likewise. + * util/i386/efi/grub-mkimage.c (usage): Likewise. + * util/i386/pc/grub-mkimage.c (usage): Likewise. + * util/i386/pc/grub-setup.c (usage): Likewise. + 2010-01-16 Carles Pina i Estany * util/misc.c (grub_util_warn): Gettextizze, print full stop after diff --git a/util/grub-editenv.c b/util/grub-editenv.c index ea0e4da19..f21042c97 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -69,10 +69,10 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-editenv --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-editenv [OPTIONS] [FILENAME] COMMAND\n\ +Usage: %s [OPTIONS] [FILENAME] COMMAND\n\ \n\ Tool to edit environment block.\n\ \nCommands:\n\ @@ -88,7 +88,7 @@ Tool to edit environment block.\n\ If not given explicitly, FILENAME defaults to %s.\n\ \n\ Report bugs to <%s>.\n", -DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT); +program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/grub-emu.c b/util/grub-emu.c index a04aeae78..21fc6fa09 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -129,10 +129,10 @@ usage (int status) { if (status) fprintf (stderr, - "Try `grub-emu --help' for more information.\n"); + "Try `%s --help' for more information.\n", program_name); else printf ( - "Usage: grub-emu [OPTION]...\n" + "Usage: %s [OPTION]...\n" "\n" "GRUB emulator.\n" "\n" @@ -144,7 +144,7 @@ usage (int status) " -h, --help display this message and exit\n" " -V, --version print version information and exit\n" "\n" - "Report bugs to <%s>.\n", DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); + "Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); return status; } diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index f5fdcca96..82437fdca 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -74,16 +74,16 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-scrypt --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-scrypt [OPTIONS]\n\ +Usage: %s [OPTIONS]\n\ \nOptions:\n\ -c number, --iteration-count=number Number of PBKDF2 iterations\n\ -l number, --buflen=number Length of generated hash\n\ -s number, --salt=number Length of salt\n\ \n\ -Report bugs to <%s>.\n", PACKAGE_BUGREPORT); +Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/efi/grub-mkimage.c b/util/i386/efi/grub-mkimage.c index 8fee3e8d9..f8c0f152e 100644 --- a/util/i386/efi/grub-mkimage.c +++ b/util/i386/efi/grub-mkimage.c @@ -1029,10 +1029,10 @@ static void usage (int status) { if (status) - fprintf (stderr, "Try `grub-mkimage --help' for more information.\n"); + fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\ +Usage: %s -o FILE [OPTION]... [MODULES]\n\ \n\ Make a bootable image of GRUB.\n\ \n\ @@ -1044,7 +1044,7 @@ Make a bootable image of GRUB.\n\ -v, --verbose print verbose messages\n\ \n\ Report bugs to <%s>.\n\ -", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); +", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c index 08807b4d1..16b2c6619 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/i386/pc/grub-mkimage.c @@ -329,7 +329,7 @@ usage (int status) fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ -Usage: grub-mkimage [OPTION]... [MODULES]\n\ +Usage: %s [OPTION]... [MODULES]\n\ \n\ Make a bootable image of GRUB.\n\ \n\ @@ -343,7 +343,7 @@ Make a bootable image of GRUB.\n\ -v, --verbose print verbose messages\n\ \n\ Report bugs to <%s>.\n\ -"), GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); +"), program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); exit (status); } diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 64b017296..4e2517ef2 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -587,7 +587,7 @@ usage (int status) fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); else printf (_("\ -Usage: grub-setup [OPTION]... DEVICE\n\ +Usage: %s [OPTION]... DEVICE\n\ \n\ Set up images to boot from DEVICE.\n\ DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ @@ -605,6 +605,7 @@ DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ \n\ Report bugs to <%s>.\n\ "), + program_name, DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY, DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT); From e15c215ebd8df7096d114e84167b25a19f0fd9d0 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Sat, 16 Jan 2010 11:57:47 +0100 Subject: [PATCH 163/164] =?UTF-8?q?2010-01-16=20=20Gr=C3=A9goire=20Sutre?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. --- ChangeLog | 4 ++++ genmk.rb | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 793746986..e71c4ec0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-16 GrĂ©goire Sutre + + * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. + 2010-01-16 Carles Pina i Estany * util/grub-editenv.c (usage): Use `program_name' instead of hardcoded diff --git a/genmk.rb b/genmk.rb index 810a2f1be..afd1582aa 100644 --- a/genmk.rb +++ b/genmk.rb @@ -370,8 +370,7 @@ class Script "CLEANFILES += #{@name} #{@name}: #{src} $(#{src}_DEPENDENCIES) config.status - ./config.status --file=#{name}:#{src} - sed -i -e 's,@pkglib_DATA@,$(pkglib_DATA),g' $@ + ./config.status --file=-:#{src} | sed -e 's,@pkglib_DATA@,$(pkglib_DATA),g' > $@ chmod +x $@ " From ea379330f97a1a2157bb5165a94d72fb83d3ca29 Mon Sep 17 00:00:00 2001 From: carles Date: Sun, 17 Jan 2010 14:42:19 +0000 Subject: [PATCH 164/164] 2010-01-17 Carles Pina i Estany * util/misc.c (grub_util_info): Fix the order of the parameters in a fprintf call. --- ChangeLog | 5 +++++ util/misc.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e71c4ec0e..748a55565 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-01-17 Carles Pina i Estany + + * util/misc.c (grub_util_info): Fix the order of the parameters in a + fprintf call. + 2010-01-16 GrĂ©goire Sutre * genmk.rb (class SCRIPT): Replace option -i of sed by a pipe. diff --git a/util/misc.c b/util/misc.c index 7f347c872..0b682c445 100644 --- a/util/misc.c +++ b/util/misc.c @@ -81,7 +81,7 @@ grub_util_info (const char *fmt, ...) va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); - fprintf (".\n", stderr); + fprintf (stderr, ".\n"); fflush (stderr); } }