From 3197c86ba826bd114f44cc09bb380b4be398ed73 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 10:07:12 +0200 Subject: [PATCH 01/75] Remove dead code in decompressor --- grub-core/kern/i386/pc/lzma_decode.S | 63 ---------------------------- 1 file changed, 63 deletions(-) diff --git a/grub-core/kern/i386/pc/lzma_decode.S b/grub-core/kern/i386/pc/lzma_decode.S index a5a86848a..88c668d5e 100644 --- a/grub-core/kern/i386/pc/lzma_decode.S +++ b/grub-core/kern/i386/pc/lzma_decode.S @@ -77,69 +77,6 @@ #define RepLenCoder (LenCoder + kNumLenProbs) #define Literal (RepLenCoder + kNumLenProbs) - -#if 0 - -DbgOut: - pushf - pushl %ebp - pushl %edi - pushl %esi - pushl %edx - pushl %ecx - pushl %ebx - pushl %eax - - call _DebugPrint - - popl %eax - popl %ebx - popl %ecx - popl %edx - popl %esi - popl %edi - popl %ebp - popf - - ret - - -/* - * int LzmaDecodeProperties(CLzmaProperties *propsRes, - * const unsigned char *propsData, - * int size); - */ - -_LzmaDecodePropertiesA: - movb (%edx), %dl - - xorl %ecx, %ecx -1: - cmpb $45, %dl - jb 2f - incl %ecx - subb $45, %dl - jmp 1b -2: - movl %ecx, 8(%eax) /* pb */ - xorl %ecx, %ecx -1: - cmpb $9, %dl - jb 2f - incl %ecx - subb $9, %dl -2: - movl %ecx, 4(%eax) /* lp */ - movb %dl, %cl - movl %ecx, (%eax) /* lc */ - -#endif - -#ifndef ASM_FILE - xorl %eax, %eax -#endif - ret - #define out_size 8(%ebp) #define now_pos -4(%ebp) From c5b4cd370ee3342d226cd0f4193f2c560f855b2d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 10:14:08 +0200 Subject: [PATCH 02/75] asm part for mips decompressor --- grub-core/Makefile.core.def | 13 ++ grub-core/boot/mips/startup_raw.S | 186 +++++++++++++++++++++++++++++ grub-core/kern/mips/cache.S | 3 + grub-core/kern/mips/cache_flush.S | 4 +- grub-core/kern/mips/startup.S | 148 ++++------------------- grub-core/lib/mips/relocator_asm.S | 7 +- include/grub/offsets.h | 12 +- util/grub-mkimage.c | 51 ++++++-- 8 files changed, 278 insertions(+), 146 deletions(-) create mode 100644 grub-core/boot/mips/startup_raw.S diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2fca91430..3341cb678 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -275,6 +275,19 @@ image = { enable = i386_pc; }; +image = { + name = decompress; + mips = boot/mips/startup_raw.S; + common = lib/LzmaDec.c; + + mips_cppflags = '-DGRUB_MACHINE_LINK_ADDR=0x80200000'; + + objcopyflags = '-O binary'; + ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000'; + cflags = '-static-libgcc'; + enable = mips; +}; + image = { name = fwstart; mips_yeeloong = boot/mips/yeeloong/fwstart.S; diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S new file mode 100644 index 000000000..67dc2ec03 --- /dev/null +++ b/grub-core/boot/mips/startup_raw.S @@ -0,0 +1,186 @@ +/* startup.S - Startup code for the MIPS. */ +/* + * 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 + +#define BASE_ADDR 8 + +.extern __bss_start +.extern _end + + .globl __start, _start, start + .set noreorder + .set nomacro +__start: +_start: +start: + + bal codestart + nop +base: + . = _start + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE +compressed_size: + .long 0 + . = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE +uncompressed_size: + .long 0 +codestart: + /* Save our base. */ + move $s0, $ra + + /* Parse arguments. Has to be done before relocation. + So need to do it in asm. */ +#if 0 // def GRUB_MACHINE_MIPS_YEELOONG + move $s2, $zero + move $s3, $zero + move $s4, $zero + move $s5, $zero + + /* $a2 has the environment. */ + addiu $t0, $a2, 1 + beq $t0, $zero, argdone + nop + move $t0, $a2 +argcont: + lw $t1, 0($t0) + beq $t1, $zero, argdone + nop +#define DO_PARSE(str, reg) \ + addiu $t2, $s0, (str-base);\ + bal parsestr;\ + beq $v0, $zero, 1f;\ + nop ;\ + b 2f;\ + move reg, $v0; +1: + DO_PARSE (busclockstr, $s2) + DO_PARSE (cpuclockstr, $s3) + DO_PARSE (memsizestr, $s4) + DO_PARSE (highmemsizestr, $s5) +2: + b argcont + addiu $t0, $t0, 4 +parsestr: + move $v0, $zero + move $t3, $t1 +3: + lb $t4, 0($t2) + lb $t5, 0($t3) + addiu $t2, $t2, 1 + addiu $t3, $t3, 1 + beq $t5, $zero, 1f + nop + beq $t5, $t4, 3b + nop + bne $t4, $zero, 1f + nop + + addiu $t3, $t3, 0xffff +digcont: + lb $t5, 0($t3) + /* Substract '0' from digit. */ + addiu $t5, $t5, 0xffd0 + bltz $t5, 1f + nop + addiu $t4, $t5, 0xfff7 + bgtz $t4, 1f + nop + /* Multiply $v0 by 10 with bitshifts. */ + sll $v0, $v0, 1 + sll $t4, $v0, 2 + addu $v0, $v0, $t4 + addu $v0, $v0, $t5 + addiu $t3, $t3, 1 + b digcont + nop +1: + jr $ra + nop +busclockstr: .asciiz "busclock=" +cpuclockstr: .asciiz "cpuclock=" +memsizestr: .asciiz "memsize=" +highmemsizestr: .asciiz "highmemsize=" + .p2align 2 +argdone: +#endif + /* Copy the decompressor. */ + lui $t1, %hi(base) + addiu $t1, $t1, %lo(base) + lui $t3, %hi(__bss_start) + addiu $t3, $t3, %lo(__bss_start) + move $t2, $s0 + +1: + beq $t1, $t3, 2f + lb $t4, 0($t2) + sb $t4, 0($t1) + addiu $t1, $t1, 1 + b 1b + addiu $t2, $t2, 1 +2: + /* Clean out its BSS. */ + lui $t1, %hi(__bss_start) + addiu $t1, $t1, %lo(__bss_start) + lui $t2, %hi(_end) + addiu $t2, $t2, %lo(_end) +1: + beq $t1, $t2, 2f + nop + sb $zero, 0($t1) + b 1b + addiu $t1, $t1, 1 +2: + + /* Decompress the payload. */ + lui $a0, %hi(__bss_start) + addiu $a0, $a0, %lo(__bss_start) + lui $t0, %hi(base) + addiu $t0, $t0, %lo(base) + subu $a0, $a0, $t0 + addu $a0, $a0, $s0 + + lui $a1, %hi(GRUB_MACHINE_LINK_ADDR) + addiu $a1, %lo(GRUB_MACHINE_LINK_ADDR) + lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0) + lw $a3, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0) + move $s1, $a1 + + /* $a0 contains source compressed address, $a1 is destination, + $a2 is compressed size, $a3 is uncompressed size. + */ + move $s6, $a3 + + lui $sp, %hi(_start) + + bal EXT_C(grub_decompress_core) + addiu $sp, $sp, %lo(_start) + + move $a0, $s1 + move $a1, $s6 + +#include "../../kern/mips/cache_flush.S" + + lui $t1, %hi(GRUB_MACHINE_LINK_ADDR) + addiu $t1, %lo(GRUB_MACHINE_LINK_ADDR) + + jr $t1 + nop diff --git a/grub-core/kern/mips/cache.S b/grub-core/kern/mips/cache.S index 2c35b6da2..02dc3355f 100644 --- a/grub-core/kern/mips/cache.S +++ b/grub-core/kern/mips/cache.S @@ -1,6 +1,9 @@ #include + .set nomacro + .set noreorder + FUNCTION (grub_cpu_flush_cache) FUNCTION (grub_arch_sync_caches) #include "cache_flush.S" diff --git a/grub-core/kern/mips/cache_flush.S b/grub-core/kern/mips/cache_flush.S index 5667ee7b4..11096c035 100644 --- a/grub-core/kern/mips/cache_flush.S +++ b/grub-core/kern/mips/cache_flush.S @@ -9,15 +9,15 @@ subu $t1, $t3, $t2 1: cache 1, 0($t0) - addiu $t0, $t0, 0x1 addiu $t1, $t1, 0xffff bne $t1, $zero, 1b + addiu $t0, $t0, 0x1 sync move $t0, $t2 subu $t1, $t3, $t2 2: cache 0, 0($t0) - addiu $t0, $t0, 0x1 addiu $t1, $t1, 0xffff bne $t1, $zero, 2b + addiu $t0, $t0, 0x1 sync diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 6811353ea..1b27a5b1f 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -22,128 +22,19 @@ #include #include -#define BASE_ADDR 8 - -.extern __bss_start -.extern _end - +#define BASE_ADDR 8 + .globl __start, _start, start + .set noreorder + .set nomacro __start: _start: -start: - bal codestart -base: - . = _start + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE -compressed_size: - .long 0 - . = _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE -total_module_size: - .long 0 - . = _start + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE -kernel_image_size: - .long 0 -codestart: - /* Save our base. */ - move $s0, $ra +start: +.extern __bss_start +.extern _end + bal cont + nop - /* Parse arguments. Has to be done before relocation. - So need to do it in asm. */ -#ifdef GRUB_MACHINE_MIPS_YEELOONG - move $s2, $zero - move $s3, $zero - move $s4, $zero - move $s5, $zero - - /* $a2 has the environment. */ - addiu $t0, $a2, 1 - beq $t0, $zero, argdone - move $t0, $a2 -argcont: - lw $t1, 0($t0) - beq $t1, $zero, argdone -#define DO_PARSE(str, reg) \ - addiu $t2, $s0, (str-base);\ - bal parsestr;\ - beq $v0, $zero, 1f;\ - move reg, $v0;\ - b 2f;\ -1: - DO_PARSE (busclockstr, $s2) - DO_PARSE (cpuclockstr, $s3) - DO_PARSE (memsizestr, $s4) - DO_PARSE (highmemsizestr, $s5) -2: - addiu $t0, $t0, 4 - b argcont -parsestr: - move $v0, $zero - move $t3, $t1 -3: - lb $t4, 0($t2) - lb $t5, 0($t3) - addiu $t2, $t2, 1 - addiu $t3, $t3, 1 - beq $t5, $zero, 1f - beq $t5, $t4, 3b - bne $t4, $zero, 1f - - addiu $t3, $t3, 0xffff -digcont: - lb $t5, 0($t3) - /* Substract '0' from digit. */ - addiu $t5, $t5, 0xffd0 - bltz $t5, 1f - addiu $t4, $t5, 0xfff7 - bgtz $t4, 1f - /* Multiply $v0 by 10 with bitshifts. */ - sll $v0, $v0, 1 - sll $t4, $v0, 2 - addu $v0, $v0, $t4 - addu $v0, $v0, $t5 - addiu $t3, $t3, 1 - b digcont -1: - jr $ra -busclockstr: .asciiz "busclock=" -cpuclockstr: .asciiz "cpuclock=" -memsizestr: .asciiz "memsize=" -highmemsizestr: .asciiz "highmemsize=" - .p2align 2 -argdone: -#endif - - /* Decompress the payload. */ - addiu $a0, $s0, GRUB_KERNEL_MACHINE_RAW_SIZE - BASE_ADDR - lui $a1, %hi(compressed) - addiu $a1, %lo(compressed) - lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0) - move $s1, $a1 - - /* $a0 contains source compressed address, $a1 is destination, - $a2 is compressed size. FIXME: put LZMA here. Don't clober $s0, - $s1, $s2, $s3, $s4 and $s5. - On return $v0 contains uncompressed size. - */ - move $v0, $a2 -reloccont: - lb $t4, 0($a0) - sb $t4, 0($a1) - addiu $a1,$a1,1 - addiu $a0,$a0,1 - addiu $a2, 0xffff - bne $a2, $0, reloccont - - move $a0, $s1 - move $a1, $v0 - -#include "cache_flush.S" - - lui $t1, %hi(cont) - addiu $t1, %lo(cont) - - jr $t1 - . = _start + GRUB_KERNEL_MACHINE_RAW_SIZE -compressed: . = _start + GRUB_KERNEL_MACHINE_PREFIX VARIABLE(grub_prefix) @@ -166,6 +57,8 @@ VARIABLE (grub_arch_highmemsize) .long 0 #endif cont: + /* Save our base. */ + move $s0, $ra #ifdef GRUB_MACHINE_MIPS_YEELOONG lui $t1, %hi(grub_arch_busclock) @@ -177,10 +70,8 @@ cont: #endif /* Move the modules out of BSS. */ - lui $t1, %hi(_start) - addiu $t1, %lo(_start) - lw $t2, (GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE - BASE_ADDR)($s0) - addu $t2, $t1, $t2 + lui $t2, %hi(_end) + addiu $t2, %lo(_end) lui $t1, %hi(_end) addiu $t1, %lo(_end) @@ -201,11 +92,11 @@ cont: modulesmovcont: lb $t4, 0($t2) sb $t4, 0($t1) - addiu $t1,$t1,0xffff - addiu $t2,$t2,0xffff - addiu $t3, 0xffff + addiu $t1, $t1, -1 + addiu $t3, $t3, -1 bne $t3, $0, modulesmovcont - + addiu $t2, $t2, -1 + /* Clean BSS. */ lui $t1, %hi(__bss_start) @@ -214,13 +105,14 @@ modulesmovcont: addiu $t2, %lo(_end) bsscont: sb $0,0($t1) - addiu $t1,$t1,1 - sltu $t3,$t1,$t2 + sltu $t3, $t1, $t2 bne $t3, $0, bsscont + addiu $t1, $t1, 1 li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH lui $t1, %hi(grub_main) addiu $t1, %lo(grub_main) jr $t1 + nop diff --git a/grub-core/lib/mips/relocator_asm.S b/grub-core/lib/mips/relocator_asm.S index 3408b59e1..1d142a4f3 100644 --- a/grub-core/lib/mips/relocator_asm.S +++ b/grub-core/lib/mips/relocator_asm.S @@ -20,6 +20,9 @@ .p2align 4 /* force 16-byte alignment */ + .set noreorder + .set nomacro + VARIABLE (grub_relocator_forward_start) move $a0, $9 move $a1, $10 @@ -28,9 +31,9 @@ copycont1: lb $11,0($8) sb $11,0($9) addiu $8, $8, 1 - addiu $9, $9, 1 addiu $10, $10, -1 bne $10, $0, copycont1 + addiu $9, $9, 1 #include "../../kern/mips/cache_flush.S" @@ -49,9 +52,9 @@ copycont2: lb $11,0($8) sb $11,0($9) addiu $8, $8, -1 - addiu $9, $9, -1 addiu $10, $10, -1 bne $10, $0, copycont2 + addiu $9, $9, -1 #include "../../kern/mips/cache_flush.S" diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 47eb6c9bd..8caa27c2f 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -102,13 +102,12 @@ #define GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN 32 -#define GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE 0x200 -#define GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE 0x8 -#define GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE 0xc -#define GRUB_KERNEL_MIPS_YEELOONG_KERNEL_IMAGE_SIZE 0x10 +#define GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE 0x8 +#define GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE 0xc -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE + 0x48 +#define GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE 0x08 +#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX 0x0c +#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END 0x54 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_EFI_PREFIX 0x8 @@ -158,6 +157,7 @@ #define GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _TOTAL_MODULE_SIZE) #define GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _KERNEL_IMAGE_SIZE) #define GRUB_KERNEL_MACHINE_COMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _COMPRESSED_SIZE) +#define GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _UNCOMPRESSED_SIZE) #define GRUB_KERNEL_MACHINE_PREFIX GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _PREFIX) #define GRUB_KERNEL_MACHINE_PREFIX_END GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, MACHINE, _PREFIX_END) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index d798ad052..ee007a54b 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -248,13 +248,13 @@ struct image_target_desc image_targets[] = .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_FLASH, - .flags = PLATFORM_FLAGS_NONE, + .flags = PLATFORM_FLAGS_LZMA, .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, - .raw_size = GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE, + .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, - .compressed_size = GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE, - .kernel_image_size = GRUB_KERNEL_MIPS_YEELOONG_KERNEL_IMAGE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -268,13 +268,13 @@ struct image_target_desc image_targets[] = .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_ELF, - .flags = PLATFORM_FLAGS_NONE, + .flags = PLATFORM_FLAGS_LZMA, .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, - .raw_size = GRUB_KERNEL_MIPS_YEELOONG_RAW_SIZE, + .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, - .compressed_size = GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE, - .kernel_image_size = GRUB_KERNEL_MIPS_YEELOONG_KERNEL_IMAGE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -680,6 +680,41 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], = grub_host_to_target32 (-2); } + if (image_target->id == IMAGE_YEELOONG_FLASH + || image_target->id == IMAGE_YEELOONG_ELF) + { + char *full_img; + size_t full_size; + char *decompress_path, *decompress_img; + size_t decompress_size; + + decompress_path = grub_util_get_path (dir, "decompress.img"); + decompress_size = grub_util_get_image_size (decompress_path); + decompress_img = grub_util_read_image (decompress_path); + + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE)) + = grub_host_to_target32 (core_size); + + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE)) + = grub_host_to_target32 (kernel_size + total_module_size); + + full_size = core_size + decompress_size; + + full_img = xmalloc (full_size); + memset (full_img, 0, full_size); + + memcpy (full_img, decompress_img, decompress_size); + + memcpy (full_img + decompress_size, core_img, core_size); + + memset (full_img + decompress_size + core_size, 0, + full_size - (decompress_size + core_size)); + + free (core_img); + core_img = full_img; + core_size = full_size; + } + switch (image_target->id) { case IMAGE_I386_PC: From f8926c32b4d132a9c2c641a4f331f27b99866f41 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 11:22:52 +0200 Subject: [PATCH 03/75] C part of decompressor --- grub-core/Makefile.core.def | 9 +- grub-core/boot/decompressor.c | 115 ++++++++++++++++++++++++++ grub-core/kern/mips/cache.S | 2 +- grub-core/lib/LzmaDec.c | 40 +++++++-- grub-core/lib/xzembed/xz_dec_bcj.c | 11 ++- grub-core/lib/xzembed/xz_dec_lzma2.c | 28 ++++++- grub-core/lib/xzembed/xz_dec_stream.c | 57 +++++++++++-- include/grub/decompressor.h | 28 +++++++ include/grub/lib/LzmaDec.h | 2 +- 9 files changed, 272 insertions(+), 20 deletions(-) create mode 100644 grub-core/boot/decompressor.c create mode 100644 include/grub/decompressor.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 3341cb678..58fd7cf5d 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -278,9 +278,14 @@ image = { image = { name = decompress; mips = boot/mips/startup_raw.S; - common = lib/LzmaDec.c; + common = boot/decompressor.c; + common = lib/xzembed/xz_dec_bcj.c; + common = lib/xzembed/xz_dec_lzma2.c; + common = lib/xzembed/xz_dec_stream.c; - mips_cppflags = '-DGRUB_MACHINE_LINK_ADDR=0x80200000'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed'; + + mips_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; objcopyflags = '-O binary'; ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000'; diff --git a/grub-core/boot/decompressor.c b/grub-core/boot/decompressor.c new file mode 100644 index 000000000..5c16fb932 --- /dev/null +++ b/grub-core/boot/decompressor.c @@ -0,0 +1,115 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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 "xz.h" +#include "xz_stream.h" + +void * +memset (void *s, int c, grub_size_t len) +{ + grub_uint8_t *ptr; + for (ptr = s; len; ptr++, len--) + *ptr = c; + return s; +} + +void * +grub_memmove (void *dest, const void *src, grub_size_t n) +{ + char *d = (char *) dest; + const char *s = (const char *) src; + + if (d < s) + while (n--) + *d++ = *s++; + else + { + d += n; + s += n; + + while (n--) + *--d = *--s; + } + + return dest; +} + +int +grub_memcmp (const void *s1, const void *s2, grub_size_t n) +{ + const char *t1 = s1; + const char *t2 = s2; + + while (n--) + { + if (*t1 != *t2) + return (int) *t1 - (int) *t2; + + t1++; + t2++; + } + + return 0; +} + +int memcmp (const void *s1, const void *s2, grub_size_t n) + __attribute__ ((alias ("grub_memcmp"))); + +void *memmove (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); + +void *memcpy (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); + +void +grub_decompress_core (void *src, void *dst, unsigned long srcsize, + unsigned long dstsize) +{ + struct xz_dec *dec; + struct xz_buf buf; + + dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE); + + buf.in = src; + buf.in_pos = 0; + buf.in_size = srcsize; + buf.out = dst; + buf.out_pos = 0; + buf.out_size = dstsize; + + while (buf.in_pos != buf.in_size) + { + enum xz_ret xzret; + xzret = xz_dec_run (dec, &buf); + switch (xzret) + { + case XZ_MEMLIMIT_ERROR: + case XZ_FORMAT_ERROR: + case XZ_OPTIONS_ERROR: + case XZ_DATA_ERROR: + case XZ_BUF_ERROR: + return; + default: + break; + } + } +} diff --git a/grub-core/kern/mips/cache.S b/grub-core/kern/mips/cache.S index 02dc3355f..999872f6b 100644 --- a/grub-core/kern/mips/cache.S +++ b/grub-core/kern/mips/cache.S @@ -1,8 +1,8 @@ #include - .set nomacro .set noreorder + .set nomacro FUNCTION (grub_cpu_flush_cache) FUNCTION (grub_arch_sync_caches) diff --git a/grub-core/lib/LzmaDec.c b/grub-core/lib/LzmaDec.c index 62ebee686..4d6890b60 100644 --- a/grub-core/lib/LzmaDec.c +++ b/grub-core/lib/LzmaDec.c @@ -26,7 +26,14 @@ #include -#include +static void +memcpy (void *a_, const void *b_, unsigned s) +{ + char *a = a_; + const char *b = b_; + while (s--) + *a++ = *b++; +} #define kNumTopBits 24 #define kTopValue ((UInt32)1 << kNumTopBits) @@ -294,14 +301,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte prob = probs + RepLenCoder; } { - unsigned limit, offset; + unsigned limit2, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; - limit = (1 << kLenNumLowBits); + limit2 = (1 << kLenNumLowBits); } else { @@ -312,17 +319,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte UPDATE_0(probLen); probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; - limit = (1 << kLenNumMidBits); + limit2 = (1 << kLenNumMidBits); } else { UPDATE_1(probLen); probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; - limit = (1 << kLenNumHighBits); + limit2 = (1 << kLenNumHighBits); } } - TREE_DECODE(probLen, limit, len); + TREE_DECODE(probLen, limit2, len); len += offset; } @@ -718,7 +725,7 @@ static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) p->needFlush = 0; } -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) +static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) { p->needFlush = 1; p->remainLen = 0; @@ -915,6 +922,7 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) { + return ; alloc->Free(alloc, p->probs); p->probs = 0; } @@ -957,13 +965,16 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) return SZ_OK; } +static char sal[30000], *sptr = sal; + static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) { UInt32 numProbs = LzmaProps_GetNumProbs(propNew); if (p->probs == 0 || numProbs != p->numProbs) { LzmaDec_FreeProbs(p, alloc); - p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); + p->probs = (CLzmaProb *) sptr; + sptr += sizeof (CLzmaProb); p->numProbs = numProbs; if (p->probs == 0) return SZ_ERROR_MEM; @@ -1033,3 +1044,16 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, LzmaDec_FreeProbs(&p, alloc); return res; } + +void +grub_decompress_core (void *src, void *dst, unsigned long srcsize, unsigned long dstsize); + +void +grub_decompress_core (void *src, void *dst, unsigned long srcsize, unsigned long dstsize) +{ + char *src_ = src, *dst_ = dst; + (void) dstsize; + while (srcsize--) + *dst_++ = *src_++ ^ 0x5a; +} + diff --git a/grub-core/lib/xzembed/xz_dec_bcj.c b/grub-core/lib/xzembed/xz_dec_bcj.c index 7eec9de7d..f517b0acc 100644 --- a/grub-core/lib/xzembed/xz_dec_bcj.c +++ b/grub-core/lib/xzembed/xz_dec_bcj.c @@ -520,9 +520,18 @@ enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s, return s->ret; } +#ifdef GRUB_EMBED_DECOMPRESSOR +struct xz_dec_bcj bcj; +#endif + struct xz_dec_bcj * xz_dec_bcj_create(bool single_call) { - struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL); + struct xz_dec_bcj *s; +#ifdef GRUB_EMBED_DECOMPRESSOR + s = &bcj; +#else + s = kmalloc(sizeof(*s), GFP_KERNEL); +#endif if (s != NULL) s->single_call = single_call; diff --git a/grub-core/lib/xzembed/xz_dec_lzma2.c b/grub-core/lib/xzembed/xz_dec_lzma2.c index a0d422697..c55773ce0 100644 --- a/grub-core/lib/xzembed/xz_dec_lzma2.c +++ b/grub-core/lib/xzembed/xz_dec_lzma2.c @@ -1100,10 +1100,17 @@ enum xz_ret xz_dec_lzma2_run( return XZ_OK; } +#ifdef GRUB_EMBED_DECOMPRESSOR +#include +static struct xz_dec_lzma2 lzma2; +static char dict[GRUB_DECOMPRESSOR_DICT_SIZE]; +#endif + struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max) { struct xz_dec_lzma2 *s; +#ifndef GRUB_EMBED_DECOMPRESSOR /* Maximum supported dictionary by this implementation is 3 GiB. */ if (dict_max > ((uint32_t)3 << 30)) return NULL; @@ -1120,6 +1127,17 @@ struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max) } } +#else + if (dict_max > GRUB_DECOMPRESSOR_DICT_SIZE) + return NULL; + + s = &lzma2; + + if (dict_max > 0) { + s->dict.buf = (void *) &dict; + } +#endif + s->dict.allocated = dict_max; return s; @@ -1135,6 +1153,7 @@ enum xz_ret xz_dec_lzma2_reset( s->dict.size = 2 + (props & 1); s->dict.size <<= (props >> 1) + 11; +#ifndef GRUB_EMBED_DECOMPRESSOR if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size) { /* enlarge dictionary buffer */ @@ -1146,7 +1165,10 @@ enum xz_ret xz_dec_lzma2_reset( s->dict.buf = newdict; s->dict.allocated = s->dict.size; } - +#else + if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size) + return XZ_MEMLIMIT_ERROR; +#endif s->dict.end = s->dict.size; s->lzma.len = 0; @@ -1159,10 +1181,12 @@ enum xz_ret xz_dec_lzma2_reset( return XZ_OK; } -void xz_dec_lzma2_end(struct xz_dec_lzma2 *s) +void xz_dec_lzma2_end(struct xz_dec_lzma2 *s __attribute__ ((unused))) { +#ifndef GRUB_EMBED_DECOMPRESSOR if (s->dict.allocated > 0) vfree(s->dict.buf); kfree(s); +#endif } diff --git a/grub-core/lib/xzembed/xz_dec_stream.c b/grub-core/lib/xzembed/xz_dec_stream.c index 273041edb..3bf201d50 100644 --- a/grub-core/lib/xzembed/xz_dec_stream.c +++ b/grub-core/lib/xzembed/xz_dec_stream.c @@ -31,7 +31,9 @@ struct xz_dec_hash { vli_type unpadded; vli_type uncompressed; +#ifndef GRUB_EMBED_DECOMPRESSOR uint8_t *crc32_context; +#endif }; struct xz_dec { @@ -247,9 +249,11 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b) > s->block_header.uncompressed) return XZ_DATA_ERROR; +#ifndef GRUB_EMBED_DECOMPRESSOR if (s->has_crc32) GRUB_MD_CRC32->write(s->crc32_context,b->out + s->out_start, b->out_pos - s->out_start); +#endif if (ret == XZ_STREAM_END) { if (s->block_header.compressed != VLI_UNKNOWN @@ -269,8 +273,10 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b) s->block.hash.uncompressed += s->block.uncompressed; +#ifndef GRUB_EMBED_DECOMPRESSOR GRUB_MD_CRC32->write(s->block.hash.crc32_context, (const uint8_t *)&s->block.hash, 2 * sizeof(vli_type)); +#endif ++s->block.count; } @@ -283,7 +289,9 @@ static void index_update(struct xz_dec *s, const struct xz_buf *b) { size_t in_used = b->in_pos - s->in_start; s->index.size += in_used; +#ifndef GRUB_EMBED_DECOMPRESSOR GRUB_MD_CRC32->write(s->crc32_context,b->in + s->in_start, in_used); +#endif } /* @@ -328,8 +336,10 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b) case SEQ_INDEX_UNCOMPRESSED: s->index.hash.uncompressed += s->vli; +#ifndef GRUB_EMBED_DECOMPRESSOR GRUB_MD_CRC32->write(s->index.hash.crc32_context, (const uint8_t *)&s->index.hash, 2 * sizeof(vli_type)); +#endif --s->index.count; s->index.sequence = SEQ_INDEX_UNPADDED; @@ -346,24 +356,30 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b) */ static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b) { +#ifndef GRUB_EMBED_DECOMPRESSOR if(s->crc32_temp == 0) { GRUB_MD_CRC32->final(s->crc32_context); s->crc32_temp = get_unaligned_be32(GRUB_MD_CRC32->read(s->crc32_context)); } +#endif do { if (b->in_pos == b->in_size) return XZ_OK; +#ifndef GRUB_EMBED_DECOMPRESSOR if (((s->crc32_temp >> s->pos) & 0xFF) != b->in[b->in_pos++]) return XZ_DATA_ERROR; +#endif s->pos += 8; } while (s->pos < 32); +#ifndef GRUB_EMBED_DECOMPRESSOR GRUB_MD_CRC32->init(s->crc32_context); +#endif s->crc32_temp = 0; s->pos = 0; @@ -376,6 +392,7 @@ static enum xz_ret dec_stream_header(struct xz_dec *s) if (! memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE)) return XZ_FORMAT_ERROR; +#ifndef GRUB_EMBED_DECOMPRESSOR uint8_t crc32_context[GRUB_MD_CRC32->contextsize]; GRUB_MD_CRC32->init(crc32_context); @@ -387,6 +404,7 @@ static enum xz_ret dec_stream_header(struct xz_dec *s) if(resultcrc != readcrc) return XZ_DATA_ERROR; +#endif /* * Decode the Stream Flags field. Of integrity checks, we support @@ -407,6 +425,7 @@ static enum xz_ret dec_stream_footer(struct xz_dec *s) if (! memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE)) return XZ_DATA_ERROR; +#ifndef GRUB_EMBED_DECOMPRESSOR uint8_t crc32_context[GRUB_MD_CRC32->contextsize]; GRUB_MD_CRC32->init(crc32_context); @@ -418,6 +437,7 @@ static enum xz_ret dec_stream_footer(struct xz_dec *s) if(resultcrc != readcrc) return XZ_DATA_ERROR; +#endif /* * Validate Backward Size. Note that we never added the size of the @@ -447,7 +467,7 @@ static enum xz_ret dec_block_header(struct xz_dec *s) * eight bytes so this is safe. */ s->temp.size -= 4; - +#ifndef GRUB_EMBED_DECOMPRESSOR uint8_t crc32_context[GRUB_MD_CRC32->contextsize]; GRUB_MD_CRC32->init(crc32_context); @@ -459,6 +479,7 @@ static enum xz_ret dec_block_header(struct xz_dec *s) if (resultcrc != readcrc) return XZ_DATA_ERROR; +#endif s->temp.pos = 2; @@ -669,6 +690,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) /* Finish the CRC32 value and Index size. */ index_update(s, b); +#ifndef GRUB_EMBED_DECOMPRESSOR /* Compare the hashes to validate the Index field. */ GRUB_MD_CRC32->final(s->block.hash.crc32_context); GRUB_MD_CRC32->final(s->index.hash.crc32_context); @@ -681,6 +703,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) { return XZ_DATA_ERROR; } +#endif s->sequence = SEQ_INDEX_CRC32; @@ -764,12 +787,22 @@ enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b) return ret; } +#ifdef GRUB_EMBED_DECOMPRESSOR +struct xz_dec decoder; +#endif + struct xz_dec * xz_dec_init(uint32_t dict_max) { - struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL); + struct xz_dec *s; +#ifdef GRUB_EMBED_DECOMPRESSOR + s = &decoder; +#else + s = kmalloc(sizeof(*s), GFP_KERNEL); if (s == NULL) return NULL; +#endif +#ifndef GRUB_EMBED_DECOMPRESSOR /* prepare CRC32 calculators */ if(GRUB_MD_CRC32 == NULL) { @@ -803,10 +836,11 @@ struct xz_dec * xz_dec_init(uint32_t dict_max) GRUB_MD_CRC32->init(s->crc32_context); - s->crc32_temp = 0; GRUB_MD_CRC32->init(s->index.hash.crc32_context); GRUB_MD_CRC32->init(s->block.hash.crc32_context); +#endif + s->crc32_temp = 0; s->single_call = dict_max == 0; @@ -828,7 +862,9 @@ error_lzma2: xz_dec_bcj_end(s->bcj); error_bcj: #endif +#ifndef GRUB_EMBED_DECOMPRESSOR kfree(s); +#endif return NULL; } @@ -839,34 +875,45 @@ void xz_dec_reset(struct xz_dec *s) s->pos = 0; { +#ifndef GRUB_EMBED_DECOMPRESSOR uint8_t *t; t = s->block.hash.crc32_context; +#endif memzero(&s->block, sizeof(s->block)); +#ifndef GRUB_EMBED_DECOMPRESSOR s->block.hash.crc32_context = t; t = s->index.hash.crc32_context; +#endif memzero(&s->index, sizeof(s->index)); +#ifndef GRUB_EMBED_DECOMPRESSOR s->index.hash.crc32_context = t; +#endif } s->temp.pos = 0; s->temp.size = STREAM_HEADER_SIZE; +#ifndef GRUB_EMBED_DECOMPRESSOR GRUB_MD_CRC32->init(s->crc32_context); - s->crc32_temp = 0; GRUB_MD_CRC32->init(s->index.hash.crc32_context); GRUB_MD_CRC32->init(s->block.hash.crc32_context); - +#endif + s->crc32_temp = 0; } void xz_dec_end(struct xz_dec *s) { if (s != NULL) { xz_dec_lzma2_end(s->lzma2); +#ifndef GRUB_EMBED_DECOMPRESSOR kfree(s->index.hash.crc32_context); kfree(s->block.hash.crc32_context); kfree(s->crc32_context); +#endif #ifdef XZ_DEC_BCJ xz_dec_bcj_end(s->bcj); #endif +#ifndef GRUB_EMBED_DECOMPRESSOR kfree(s); +#endif } } diff --git a/include/grub/decompressor.h b/include/grub/decompressor.h new file mode 100644 index 000000000..4d99c41f7 --- /dev/null +++ b/include/grub/decompressor.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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_DECOMPRESSOR_HEADER +#define GRUB_DECOMPRESSOR_HEADER 1 + +void +grub_decompress_core (void *src, void *dst, unsigned long srcsize, + unsigned long dstsize); + +#define GRUB_DECOMPRESSOR_DICT_SIZE (1 << 16) + +#endif diff --git a/include/grub/lib/LzmaDec.h b/include/grub/lib/LzmaDec.h index 1e66b74d7..16914c961 100644 --- a/include/grub/lib/LzmaDec.h +++ b/include/grub/lib/LzmaDec.h @@ -27,7 +27,7 @@ #ifndef __LZMADEC_H #define __LZMADEC_H -#include "Types.h" +#include "LzmaTypes.h" /* #define _LZMA_PROB32 */ /* _LZMA_PROB32 can increase the speed on some CPUs, From e0a8ef26e4aebe108caf7fc7c852b81c4f7c9b89 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 19:39:51 +0200 Subject: [PATCH 04/75] MAke a separate scratch for decompressor --- grub-core/boot/decompressor.c | 23 +++++++++++++++++++++++ grub-core/boot/mips/startup_raw.S | 2 +- grub-core/kern/mips/startup.S | 4 ++-- grub-core/lib/xzembed/xz_dec_lzma2.c | 12 +----------- include/grub/decompressor.h | 6 ++++++ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/grub-core/boot/decompressor.c b/grub-core/boot/decompressor.c index 5c16fb932..604fc754c 100644 --- a/grub-core/boot/decompressor.c +++ b/grub-core/boot/decompressor.c @@ -80,6 +80,27 @@ void *memmove (void *dest, const void *src, grub_size_t n) void *memcpy (void *dest, const void *src, grub_size_t n) __attribute__ ((alias ("grub_memmove"))); +void *grub_decompressor_scratch; + +void +find_scratch (void *src, void *dst, unsigned long srcsize, + unsigned long dstsize) +{ +#ifdef _mips + /* Decoding from ROM. */ + if (((grub_addr_t) src & 0x10000000)) + { + grub_decompressor_scratch = (char *) dst + dstsize; + return; + } +#endif + if ((char *) src + srcsize > (char *) dst + dstsize) + grub_decompressor_scratch = (char *) src + srcsize; + else + grub_decompressor_scratch = (char *) dst + dstsize; + return; +} + void grub_decompress_core (void *src, void *dst, unsigned long srcsize, unsigned long dstsize) @@ -87,6 +108,8 @@ grub_decompress_core (void *src, void *dst, unsigned long srcsize, struct xz_dec *dec; struct xz_buf buf; + find_scratch (src, dst, srcsize, dstsize); + dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE); buf.in = src; diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 67dc2ec03..d810f2fb4 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -49,7 +49,7 @@ codestart: /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ -#if 0 // def GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_YEELOONG move $s2, $zero move $s3, $zero move $s4, $zero diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 1b27a5b1f..97145b818 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -109,10 +109,10 @@ bsscont: bne $t3, $0, bsscont addiu $t1, $t1, 1 - li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH lui $t1, %hi(grub_main) addiu $t1, %lo(grub_main) + lui $sp, %hi(GRUB_MACHINE_MEMORY_STACK_HIGH) jr $t1 - nop + addiu $sp, $sp, %lo(GRUB_MACHINE_MEMORY_STACK_HIGH) diff --git a/grub-core/lib/xzembed/xz_dec_lzma2.c b/grub-core/lib/xzembed/xz_dec_lzma2.c index c55773ce0..7899e9e87 100644 --- a/grub-core/lib/xzembed/xz_dec_lzma2.c +++ b/grub-core/lib/xzembed/xz_dec_lzma2.c @@ -1103,7 +1103,6 @@ enum xz_ret xz_dec_lzma2_run( #ifdef GRUB_EMBED_DECOMPRESSOR #include static struct xz_dec_lzma2 lzma2; -static char dict[GRUB_DECOMPRESSOR_DICT_SIZE]; #endif struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max) @@ -1128,14 +1127,8 @@ struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max) } #else - if (dict_max > GRUB_DECOMPRESSOR_DICT_SIZE) - return NULL; - s = &lzma2; - - if (dict_max > 0) { - s->dict.buf = (void *) &dict; - } + s->dict.buf = grub_decompressor_scratch; #endif s->dict.allocated = dict_max; @@ -1165,9 +1158,6 @@ enum xz_ret xz_dec_lzma2_reset( s->dict.buf = newdict; s->dict.allocated = s->dict.size; } -#else - if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size) - return XZ_MEMLIMIT_ERROR; #endif s->dict.end = s->dict.size; diff --git a/include/grub/decompressor.h b/include/grub/decompressor.h index 4d99c41f7..a6eefb01b 100644 --- a/include/grub/decompressor.h +++ b/include/grub/decompressor.h @@ -23,6 +23,12 @@ void grub_decompress_core (void *src, void *dst, unsigned long srcsize, unsigned long dstsize); +void +find_scratch (void *src, void *dst, unsigned long srcsize, + unsigned long dstsize); + #define GRUB_DECOMPRESSOR_DICT_SIZE (1 << 16) +extern void *grub_decompressor_scratch; + #endif From 758194b076cb4f279feceabea2c1b28cd7a16257 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 20:30:28 +0200 Subject: [PATCH 05/75] Allow compression algorithm specification --- grub-core/Makefile.core.def | 18 ++- .../minilib.c} | 39 ------- grub-core/boot/decompressor/none.c | 39 +++++++ grub-core/boot/decompressor/xz.c | 60 ++++++++++ util/grub-mkimage.c | 107 +++++++++++++++--- 5 files changed, 208 insertions(+), 55 deletions(-) rename grub-core/boot/{decompressor.c => decompressor/minilib.c} (76%) create mode 100644 grub-core/boot/decompressor/none.c create mode 100644 grub-core/boot/decompressor/xz.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 58fd7cf5d..48579896c 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -276,9 +276,10 @@ image = { }; image = { - name = decompress; + name = xz_decompress; mips = boot/mips/startup_raw.S; - common = boot/decompressor.c; + common = boot/decompressor/minilib.c; + common = boot/decompressor/xz.c; common = lib/xzembed/xz_dec_bcj.c; common = lib/xzembed/xz_dec_lzma2.c; common = lib/xzembed/xz_dec_stream.c; @@ -293,6 +294,19 @@ image = { enable = mips; }; +image = { + name = none_decompress; + mips = boot/mips/startup_raw.S; + common = boot/decompressor/none.c; + + mips_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; + + objcopyflags = '-O binary'; + ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000'; + cflags = '-static-libgcc'; + enable = mips; +}; + image = { name = fwstart; mips_yeeloong = boot/mips/yeeloong/fwstart.S; diff --git a/grub-core/boot/decompressor.c b/grub-core/boot/decompressor/minilib.c similarity index 76% rename from grub-core/boot/decompressor.c rename to grub-core/boot/decompressor/minilib.c index 604fc754c..d1f021933 100644 --- a/grub-core/boot/decompressor.c +++ b/grub-core/boot/decompressor/minilib.c @@ -20,9 +20,6 @@ #include #include -#include "xz.h" -#include "xz_stream.h" - void * memset (void *s, int c, grub_size_t len) { @@ -100,39 +97,3 @@ find_scratch (void *src, void *dst, unsigned long srcsize, grub_decompressor_scratch = (char *) dst + dstsize; return; } - -void -grub_decompress_core (void *src, void *dst, unsigned long srcsize, - unsigned long dstsize) -{ - struct xz_dec *dec; - struct xz_buf buf; - - find_scratch (src, dst, srcsize, dstsize); - - dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE); - - buf.in = src; - buf.in_pos = 0; - buf.in_size = srcsize; - buf.out = dst; - buf.out_pos = 0; - buf.out_size = dstsize; - - while (buf.in_pos != buf.in_size) - { - enum xz_ret xzret; - xzret = xz_dec_run (dec, &buf); - switch (xzret) - { - case XZ_MEMLIMIT_ERROR: - case XZ_FORMAT_ERROR: - case XZ_OPTIONS_ERROR: - case XZ_DATA_ERROR: - case XZ_BUF_ERROR: - return; - default: - break; - } - } -} diff --git a/grub-core/boot/decompressor/none.c b/grub-core/boot/decompressor/none.c new file mode 100644 index 000000000..44f56ce90 --- /dev/null +++ b/grub-core/boot/decompressor/none.c @@ -0,0 +1,39 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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 + +void +grub_decompress_core (void *src, void *dest, unsigned long n, + unsigned long dstsize __attribute__ ((unused))) +{ + char *d = (char *) dest; + const char *s = (const char *) src; + + if (d < s) + while (n--) + *d++ = *s++; + else + { + d += n; + s += n; + + while (n--) + *--d = *--s; + } +} diff --git a/grub-core/boot/decompressor/xz.c b/grub-core/boot/decompressor/xz.c new file mode 100644 index 000000000..2279118e1 --- /dev/null +++ b/grub-core/boot/decompressor/xz.c @@ -0,0 +1,60 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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 "xz.h" +#include "xz_stream.h" + +void +grub_decompress_core (void *src, void *dst, unsigned long srcsize, + unsigned long dstsize) +{ + struct xz_dec *dec; + struct xz_buf buf; + + find_scratch (src, dst, srcsize, dstsize); + + dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE); + + buf.in = src; + buf.in_pos = 0; + buf.in_size = srcsize; + buf.out = dst; + buf.out_pos = 0; + buf.out_size = dstsize; + + while (buf.in_pos != buf.in_size) + { + enum xz_ret xzret; + xzret = xz_dec_run (dec, &buf); + switch (xzret) + { + case XZ_MEMLIMIT_ERROR: + case XZ_FORMAT_ERROR: + case XZ_OPTIONS_ERROR: + case XZ_DATA_ERROR: + case XZ_BUF_ERROR: + return; + default: + break; + } + } +} diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index ee007a54b..75343ac30 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -46,6 +46,11 @@ #define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof)) #define TARGET_NO_FIELD 0xffffffff + +typedef enum { + COMPRESSION_AUTO, COMPRESSION_NONE, COMPRESSION_XZ +} grub_compression_t; + struct image_target_desc { const char *name; @@ -60,7 +65,8 @@ struct image_target_desc enum { PLATFORM_FLAGS_NONE = 0, - PLATFORM_FLAGS_LZMA = 1 + PLATFORM_FLAGS_LZMA = 1, + PLATFORM_FLAGS_DECOMPRESSORS = 2 } flags; unsigned prefix; unsigned prefix_end; @@ -75,6 +81,7 @@ struct image_target_desc unsigned install_dos_part, install_bsd_part; grub_uint64_t link_addr; unsigned mod_gap, mod_align; + grub_compression_t default_compression; }; struct image_target_desc image_targets[] = @@ -248,7 +255,7 @@ struct image_target_desc image_targets[] = .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_FLASH, - .flags = PLATFORM_FLAGS_LZMA, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, .raw_size = 0, @@ -261,14 +268,15 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, .elf_target = EM_MIPS, - .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN + .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .default_compression = COMPRESSION_XZ }, { .name = "mipsel-yeeloong-elf", .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_ELF, - .flags = PLATFORM_FLAGS_LZMA, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, .raw_size = 0, @@ -281,7 +289,8 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, .elf_target = EM_MIPS, - .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN + .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .default_compression = COMPRESSION_NONE }, { .name = "powerpc-ieee1275", @@ -483,7 +492,39 @@ compress_kernel_lzma (char *kernel_img, size_t kernel_size, memcpy (*core_img, kernel_img, raw_size); *core_size = kernel_size - raw_size; - if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size, + if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size, + (unsigned char *) kernel_img + raw_size, + kernel_size - raw_size, + &props, out_props, &out_props_size, + 0, NULL, &g_Alloc, &g_Alloc) != SZ_OK) + grub_util_error (_("cannot compress the kernel image")); + + *core_size += raw_size; +} + +static void +compress_kernel_xz (char *kernel_img, size_t kernel_size, + char **core_img, size_t *core_size, size_t raw_size) +{ + CLzmaEncProps props; + unsigned char out_props[5]; + size_t out_props_size = 5; + + LzmaEncProps_Init(&props); + props.dictSize = 1 << 16; + props.lc = 3; + props.lp = 0; + props.pb = 2; + props.numThreads = 1; + + if (kernel_size < raw_size) + grub_util_error (_("the core image is too small")); + + *core_img = xmalloc (kernel_size); + memcpy (*core_img, kernel_img, raw_size); + + *core_size = kernel_size - raw_size; + if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size, (unsigned char *) kernel_img + raw_size, kernel_size - raw_size, &props, out_props, &out_props_size, @@ -495,7 +536,8 @@ compress_kernel_lzma (char *kernel_img, size_t kernel_size, static void compress_kernel (struct image_target_desc *image_target, char *kernel_img, - size_t kernel_size, char **core_img, size_t *core_size) + size_t kernel_size, char **core_img, size_t *core_size, + grub_compression_t comp) { if (image_target->flags & PLATFORM_FLAGS_LZMA) { @@ -504,6 +546,14 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img, return; } + if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS + && (comp == COMPRESSION_XZ)) + { + compress_kernel_xz (kernel_img, kernel_size, core_img, + core_size, image_target->raw_size); + return; + } + *core_img = xmalloc (kernel_size); memcpy (*core_img, kernel_img, kernel_size); *core_size = kernel_size; @@ -527,7 +577,8 @@ struct fixup_block_list static void generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path, char *config_path, - struct image_target_desc *image_target, int note) + struct image_target_desc *image_target, int note, + grub_compression_t comp) { char *kernel_img, *core_img; size_t kernel_size, total_module_size, core_size, exec_size; @@ -539,6 +590,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_uint64_t start_address; void *rel_section; grub_size_t reloc_size, align; + + if (comp == COMPRESSION_AUTO) + comp = image_target->default_compression; + path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods); kernel_path = grub_util_get_path (dir, "kernel.img"); @@ -655,7 +710,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); compress_kernel (image_target, kernel_img, kernel_size + total_module_size, - &core_img, &core_size); + &core_img, &core_size, comp); grub_util_info ("the core size is 0x%x", core_size); @@ -680,15 +735,27 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], = grub_host_to_target32 (-2); } - if (image_target->id == IMAGE_YEELOONG_FLASH - || image_target->id == IMAGE_YEELOONG_ELF) + if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) { char *full_img; size_t full_size; char *decompress_path, *decompress_img; size_t decompress_size; + const char *name; + + switch (comp) + { + case COMPRESSION_XZ: + name = "xz_decompress.img"; + break; + case COMPRESSION_NONE: + name = "none_decompress.img"; + break; + default: + grub_util_error ("unknown compression %d\n", comp); + } - decompress_path = grub_util_get_path (dir, "decompress.img"); + decompress_path = grub_util_get_path (dir, name); decompress_size = grub_util_get_image_size (decompress_path); decompress_img = grub_util_read_image (decompress_path); @@ -1253,6 +1320,7 @@ static struct option options[] = {"output", required_argument, 0, 'o'}, {"note", no_argument, 0, 'n'}, {"format", required_argument, 0, 'O'}, + {"compression", required_argument, 0, 'C'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, @@ -1295,6 +1363,7 @@ Make a bootable image of GRUB.\n\ -o, --output=FILE output a generated image to FILE [default=stdout]\n\ -O, --format=FORMAT generate an image in format\n\ available formats: %s\n\ + -C, --compression=(xz|none|auto) choose the compression to use\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ -v, --verbose print verbose messages\n\ @@ -1321,6 +1390,7 @@ main (int argc, char *argv[]) FILE *fp = stdout; int note = 0; struct image_target_desc *image_target = NULL; + grub_compression_t comp = COMPRESSION_AUTO; set_program_name (argv[0]); @@ -1328,7 +1398,7 @@ main (int argc, char *argv[]) while (1) { - int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:hVvn", options, 0); + int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:C:hVvn", options, 0); if (c == -1) break; @@ -1385,6 +1455,15 @@ main (int argc, char *argv[]) config = xstrdup (optarg); break; + case 'C': + if (grub_strcmp (optarg, "xz") == 0) + comp = COMPRESSION_XZ; + else if (grub_strcmp (optarg, "none") == 0) + comp = COMPRESSION_NONE; + else + grub_util_error ("Unknown compression format %s", optarg); + break; + case 'h': usage (0); break; @@ -1443,7 +1522,7 @@ main (int argc, char *argv[]) generate_image (dir, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk, config, - image_target, note); + image_target, note, comp); fclose (fp); From 2c44e493c756cb211f2a7f85e048f446773382fd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 21 Sep 2010 21:35:46 +0200 Subject: [PATCH 06/75] Compressor part --- Makefile.util.def | 1 + configure.ac | 6 ++++ util/grub-mkimage.c | 79 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index f56eab339..6ed4ccb65 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -113,6 +113,7 @@ program = { extra_dist = util/grub-mkimagexx.c; ldadd = libgrub.a; + ldadd = '$(LIBLZMA)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; cppflags = '-DGRUB_PKGLIBROOTDIR=\"$(pkglibrootdir)\"'; }; diff --git a/configure.ac b/configure.ac index 10723987b..225e02a0d 100644 --- a/configure.ac +++ b/configure.ac @@ -849,6 +849,12 @@ fi AC_SUBST([LIBDEVMAPPER]) +AC_CHECK_LIB([lzma], [lzma_code], + [LIBLZMA="-llzma" + AC_DEFINE([HAVE_LIBLZMA], [1], + [Define to 1 if you have the LZMA library.])],) +AC_SUBST([LIBLZMA]) + AC_CHECK_LIB([zfs], [libzfs_init], [LIBZFS="-lzfs" AC_DEFINE([HAVE_LIBZFS], [1], diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 75343ac30..8a907b414 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -45,6 +45,10 @@ #define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof)) +#ifdef HAVE_LIBLZMA +#include +#endif + #define TARGET_NO_FIELD 0xffffffff typedef enum { @@ -269,7 +273,11 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, .elf_target = EM_MIPS, .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, +#ifdef HAVE_LIBLZMA .default_compression = COMPRESSION_XZ +#else + .default_compression = COMPRESSION_NONE +#endif }, { .name = "mipsel-yeeloong-elf", @@ -492,7 +500,7 @@ compress_kernel_lzma (char *kernel_img, size_t kernel_size, memcpy (*core_img, kernel_img, raw_size); *core_size = kernel_size - raw_size; - if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size, + if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size, (unsigned char *) kernel_img + raw_size, kernel_size - raw_size, &props, out_props, &out_props_size, @@ -506,30 +514,52 @@ static void compress_kernel_xz (char *kernel_img, size_t kernel_size, char **core_img, size_t *core_size, size_t raw_size) { - CLzmaEncProps props; - unsigned char out_props[5]; - size_t out_props_size = 5; - - LzmaEncProps_Init(&props); - props.dictSize = 1 << 16; - props.lc = 3; - props.lp = 0; - props.pb = 2; - props.numThreads = 1; + lzma_stream strm = LZMA_STREAM_INIT; + lzma_ret xzret; + lzma_options_lzma lzopts = { + .dict_size = 1 << 16, + .preset_dict = NULL, + .preset_dict_size = 0, + .lc = 3, + .lp = 0, + .pb = 2, + .mode = LZMA_MODE_NORMAL, + .nice_len = 64, + .mf = LZMA_MF_BT4, + .depth = 0, + }; + lzma_filter fltrs[] = { + { .id = LZMA_FILTER_LZMA2, .options = &lzopts}, + { .id = LZMA_VLI_UNKNOWN, .options = NULL} + }; if (kernel_size < raw_size) grub_util_error (_("the core image is too small")); + xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE); + if (xzret != LZMA_OK) + grub_util_error (_("cannot compress the kernel image")); + *core_img = xmalloc (kernel_size); memcpy (*core_img, kernel_img, raw_size); *core_size = kernel_size - raw_size; - if (LzmaEncode ((unsigned char *) *core_img + raw_size, core_size - raw_size, - (unsigned char *) kernel_img + raw_size, - kernel_size - raw_size, - &props, out_props, &out_props_size, - 0, NULL, &g_Alloc, &g_Alloc) != SZ_OK) - grub_util_error (_("cannot compress the kernel image")); + strm.next_in = (unsigned char *) kernel_img + raw_size; + strm.avail_in = kernel_size - raw_size; + strm.next_out = (unsigned char *) *core_img + raw_size; + strm.avail_out = *core_size; + + while (1) + { + xzret = lzma_code (&strm, LZMA_FINISH); + if (xzret == LZMA_OK) + continue; + if (xzret == LZMA_STREAM_END) + break; + grub_util_error (_("cannot compress the kernel image")); + } + + *core_size -= strm.avail_out; *core_size += raw_size; } @@ -546,6 +576,7 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img, return; } +#ifdef HAVE_LIBLZMA if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS && (comp == COMPRESSION_XZ)) { @@ -553,6 +584,11 @@ compress_kernel (struct image_target_desc *image_target, char *kernel_img, core_size, image_target->raw_size); return; } +#endif + + if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS + && (comp != COMPRESSION_NONE)) + grub_util_error ("unknown compression %d\n", comp); *core_img = xmalloc (kernel_size); memcpy (*core_img, kernel_img, kernel_size); @@ -1457,7 +1493,14 @@ main (int argc, char *argv[]) case 'C': if (grub_strcmp (optarg, "xz") == 0) - comp = COMPRESSION_XZ; + { +#ifdef HAVE_LIBLZMA + comp = COMPRESSION_XZ; +#else + grub_util_error ("grub-mkimage is compiled without XZ support", + optarg); +#endif + } else if (grub_strcmp (optarg, "none") == 0) comp = COMPRESSION_NONE; else From bf5f1dc6d267a6734cd4ead2cbcf7d200411158c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 00:51:54 +0200 Subject: [PATCH 07/75] Write total module size before compressing --- util/grub-mkimage.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 8a907b414..73713f2bc 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -273,11 +273,7 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, .elf_target = EM_MIPS, .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, -#ifdef HAVE_LIBLZMA - .default_compression = COMPRESSION_XZ -#else .default_compression = COMPRESSION_NONE -#endif }, { .name = "mipsel-yeeloong-elf", @@ -744,13 +740,19 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], offset += config_size; } + if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) + && (image_target->total_module_size != TARGET_NO_FIELD)) + *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) + = grub_host_to_target32 (total_module_size); + grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); compress_kernel (image_target, kernel_img, kernel_size + total_module_size, &core_img, &core_size, comp); grub_util_info ("the core size is 0x%x", core_size); - if (image_target->total_module_size != TARGET_NO_FIELD) + if (!(image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) + && image_target->total_module_size != TARGET_NO_FIELD) *((grub_uint32_t *) (core_img + image_target->total_module_size)) = grub_host_to_target32 (total_module_size); if (image_target->kernel_image_size != TARGET_NO_FIELD) From 67c4bb722d425aacd968d4462ca4aff8beb7b303 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 00:52:33 +0200 Subject: [PATCH 08/75] Align scratch --- grub-core/boot/decompressor/minilib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grub-core/boot/decompressor/minilib.c b/grub-core/boot/decompressor/minilib.c index d1f021933..f2a2ef7e5 100644 --- a/grub-core/boot/decompressor/minilib.c +++ b/grub-core/boot/decompressor/minilib.c @@ -87,13 +87,16 @@ find_scratch (void *src, void *dst, unsigned long srcsize, /* Decoding from ROM. */ if (((grub_addr_t) src & 0x10000000)) { - grub_decompressor_scratch = (char *) dst + dstsize; + grub_decompressor_scratch = (void *) ALIGN_UP((grub_addr_t) dst + dstsize, + 256); return; } #endif if ((char *) src + srcsize > (char *) dst + dstsize) - grub_decompressor_scratch = (char *) src + srcsize; + grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) src + srcsize, + 256); else - grub_decompressor_scratch = (char *) dst + dstsize; + grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) dst + dstsize, + 256); return; } From 9a0e5c815e76c48141d1e126682b1473036be669 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 00:53:34 +0200 Subject: [PATCH 09/75] Fix bugs in asm code --- grub-core/boot/mips/startup_raw.S | 7 ++++--- grub-core/kern/mips/startup.S | 34 +++++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index d810f2fb4..c41ce8257 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -67,10 +67,11 @@ argcont: #define DO_PARSE(str, reg) \ addiu $t2, $s0, (str-base);\ bal parsestr;\ + nop ;\ beq $v0, $zero, 1f;\ nop ;\ b 2f;\ - move reg, $v0; + move reg, $v0; \ 1: DO_PARSE (busclockstr, $s2) DO_PARSE (cpuclockstr, $s3) @@ -169,10 +170,10 @@ argdone: */ move $s6, $a3 - lui $sp, %hi(_start) + lui $sp, %hi(_start - 256) bal EXT_C(grub_decompress_core) - addiu $sp, $sp, %lo(_start) + addiu $sp, $sp, %lo(_start - 256) move $a0, $s1 move $a1, $s6 diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 97145b818..ae0e0b187 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -35,6 +35,10 @@ start: bal cont nop + . = _start + GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE +total_module_size: + .long 0 + . = _start + GRUB_KERNEL_MACHINE_PREFIX VARIABLE(grub_prefix) @@ -70,13 +74,13 @@ cont: #endif /* Move the modules out of BSS. */ - lui $t2, %hi(_end) - addiu $t2, %lo(_end) + lui $t2, %hi(__bss_start) + addiu $t2, %lo(__bss_start) lui $t1, %hi(_end) addiu $t1, %lo(_end) - addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN-1) - li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN-1) + addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) + li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) nor $t3, $t3, $0 and $t1, $t1, $t3 @@ -85,29 +89,33 @@ cont: /* Backward copy. */ add $t1, $t1, $t3 add $t2, $t2, $t3 - addiu $t1, $t1, 0xffff - addiu $t2, $t2, 0xffff + addiu $t1, $t1, -1 + addiu $t2, $t2, -1 /* $t2 is source. $t1 is destination. $t3 is size. */ modulesmovcont: + beq $t3, $0, modulesmovdone + nop lb $t4, 0($t2) sb $t4, 0($t1) + addiu $t2, $t2, -1 addiu $t1, $t1, -1 - addiu $t3, $t3, -1 - bne $t3, $0, modulesmovcont - addiu $t2, $t2, -1 - + b modulesmovcont + addiu $t3, $t3, -1 +modulesmovdone: + /* Clean BSS. */ lui $t1, %hi(__bss_start) - addiu $t1, %lo(__bss_start) + addiu $t1, $t1, %lo(__bss_start) lui $t2, %hi(_end) - addiu $t2, %lo(_end) + addiu $t2, $t2, %lo(_end) bsscont: sb $0,0($t1) + addiu $t1, $t1, 1 sltu $t3, $t1, $t2 bne $t3, $0, bsscont - addiu $t1, $t1, 1 + nop lui $t1, %hi(grub_main) addiu $t1, %lo(grub_main) From 8f03f0b580d253ca87faf46d84b251fec121b64c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 22 Sep 2010 16:57:49 +0100 Subject: [PATCH 10/75] * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi): Fix typo in __i386__ conditional. --- ChangeLog | 5 +++++ grub-core/loader/multiboot_mbi2.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 70588bf17..178547359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-22 Colin Watson + + * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi): Fix + typo in __i386__ conditional. + 2010-09-22 Vladimir Serbinenko * grub-core/loader/multiboot_mbi2.c (GRUB_MACHINE_EFI): Add missing diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 6e1d5c8be..a20c82cad 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -715,7 +715,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } #endif -#if defined (GRUB_MACHINE_EFI) && __i386_ +#if defined (GRUB_MACHINE_EFI) && __i386__ { struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi32 *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI32; From 1b655af6854ff0f1f4ad141342335d8211a204bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Wed, 22 Sep 2010 23:32:58 +0200 Subject: [PATCH 11/75] Define FLOPPY_MAJOR on NetBSD. --- ChangeLog | 4 ++++ grub-core/kern/emu/hostdisk.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 178547359..63f497c39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-09-22 GrĂ©goire Sutre + + * grub-core/kern/emu/hostdisk.c [__NetBSD__]: Define FLOPPY_MAJOR. + 2010-09-22 Colin Watson * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi): Fix diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d38208fdc..19d3856a2 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -115,6 +115,9 @@ struct hd_geometry # include /* getrawpartition */ # endif /* HAVE_GETRAWPARTITION */ # include +# ifndef FLOPPY_MAJOR +# define FLOPPY_MAJOR 2 +# endif /* ! FLOPPY_MAJOR */ # ifndef RAW_FLOPPY_MAJOR # define RAW_FLOPPY_MAJOR 9 # endif /* ! RAW_FLOPPY_MAJOR */ From f5a109e2779b8ea62583301d3cbcbeebbdd5abbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Fri, 24 Sep 2010 01:13:50 +0200 Subject: [PATCH 12/75] Variable initialization. --- ChangeLog | 4 ++++ grub-core/commands/acpihalt.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cf5cae534..d02901863 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-09-23 GrĂ©goire Sutre + + * grub-core/commands/acpihalt.c (get_sleep_type): Initialize prev. + 2010-09-23 Vladimir Serbinenko Support xz compression on yeeloong. diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index 0cd32f389..a39635677 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -136,7 +136,7 @@ skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end) static int get_sleep_type (grub_uint8_t *table, grub_uint8_t *end) { - grub_uint8_t *ptr, *prev; + grub_uint8_t *ptr, *prev = table; int sleep_type = -1; ptr = table + sizeof (struct grub_acpi_table_header); From dd363028e45e6505e50208519b5137c750d3bb82 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 24 Sep 2010 08:46:15 +0530 Subject: [PATCH 13/75] * Makefile.util.def (example_unit_test): Add grub-core/gnulib/libgnu.a. --- ChangeLog | 5 +++++ Makefile.util.def | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index d02901863..525b4c6e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-24 BVK Chaitanya + + * Makefile.util.def (example_unit_test): Add + grub-core/gnulib/libgnu.a. + 2010-09-23 GrĂ©goire Sutre * grub-core/commands/acpihalt.c (get_sleep_type): Initialize prev. diff --git a/Makefile.util.def b/Makefile.util.def index 21314e04a..42165df3d 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -583,6 +583,7 @@ program = { common = grub-core/tests/lib/test.c; cflags = -Wno-format; ldadd = libgrub.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER)'; }; From 1d12cf2947a6deb38bb9368470876b37f89ac4d2 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Fri, 24 Sep 2010 09:19:57 +0200 Subject: [PATCH 14/75] * grub-core/lib/LzFind.c: Add missing include. * grub-core/lib/LzmaEnc.c: Likewise. * grub-core/script/lexer.c: Likewise. * grub-core/script/yylex.l: Likewise. * util/grub-macho2img.c: Likewise. * util/grub-menulst2cfg.c: Likewise. * util/grub-mklayout.c: Likewise. * util/grub-mkpasswd-pbkdf2.c * util/grub-mkrelpath.c: Likewise. * util/resolve.c: Likewise. --- ChangeLog | 13 +++++++++++++ grub-core/lib/LzFind.c | 3 +++ grub-core/lib/LzmaEnc.c | 2 ++ grub-core/script/lexer.c | 2 ++ grub-core/script/yylex.l | 2 ++ util/grub-macho2img.c | 2 ++ util/grub-menulst2cfg.c | 2 ++ util/grub-mklayout.c | 2 ++ util/grub-mkpasswd-pbkdf2.c | 2 ++ util/grub-mkrelpath.c | 2 ++ util/resolve.c | 2 ++ 11 files changed, 34 insertions(+) diff --git a/ChangeLog b/ChangeLog index 525b4c6e1..b5117bee5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-09-24 Yves Blusseau + + * grub-core/lib/LzFind.c: Add missing include. + * grub-core/lib/LzmaEnc.c: Likewise. + * grub-core/script/lexer.c: Likewise. + * grub-core/script/yylex.l: Likewise. + * util/grub-macho2img.c: Likewise. + * util/grub-menulst2cfg.c: Likewise. + * util/grub-mklayout.c: Likewise. + * util/grub-mkpasswd-pbkdf2.c + * util/grub-mkrelpath.c: Likewise. + * util/resolve.c: Likewise. + 2010-09-24 BVK Chaitanya * Makefile.util.def (example_unit_test): Add diff --git a/grub-core/lib/LzFind.c b/grub-core/lib/LzFind.c index cd7a1cbab..d2bb15c65 100644 --- a/grub-core/lib/LzFind.c +++ b/grub-core/lib/LzFind.c @@ -24,6 +24,9 @@ * See , for more information about LZMA. */ + +#include + #include #include diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c index 842d43ac1..01ffa91f9 100644 --- a/grub-core/lib/LzmaEnc.c +++ b/grub-core/lib/LzmaEnc.c @@ -24,6 +24,8 @@ * See , for more information about LZMA. */ +#include + #include #include diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c index 8d1623fb8..909b515fa 100644 --- a/grub-core/script/lexer.c +++ b/grub-core/script/lexer.c @@ -17,6 +17,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 55620b6bd..53ae4c54f 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -71,6 +71,8 @@ static void copy_string (struct grub_parser_param *, const char *, %top{ +#include + #include typedef size_t yy_size_t; diff --git a/util/grub-macho2img.c b/util/grub-macho2img.c index 23ffafb04..bce0a06d1 100644 --- a/util/grub-macho2img.c +++ b/util/grub-macho2img.c @@ -17,6 +17,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c index 512239e89..e29c6b17c 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -16,6 +16,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index ac59981c7..e90d955ff 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -16,6 +16,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index d552d1acd..fe1887f8f 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -16,6 +16,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c index eccb49cdc..3fe3fe698 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -17,6 +17,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include diff --git a/util/resolve.c b/util/resolve.c index 7eadffd38..63bd7ccb2 100644 --- a/util/resolve.c +++ b/util/resolve.c @@ -16,6 +16,8 @@ * along with GRUB. If not, see . */ +#include + #include #include #include From e1fd193905e0ef3afc1a98893940e44fd81a37d3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 24 Sep 2010 09:48:27 +0100 Subject: [PATCH 15/75] Re-enable grub-extras. * autogen.sh: Create symlinks to ${GRUB_CONTRIB} if necessary to avoid confusing Automake. Run autogen only twice, once for the top level and once for grub-core. Add Makefile.util.def and Makefile.core.def from extra modules to the appropriate autogen invocations. If Makefile.common exists in an extra module, include it in both Makefile.util.am and grub-core/Makefile.core.am; similarly, include any Makefile.util.common file in Makefile.util.am and any Makefile.core.common file in grub-core/Makefile.core.am. * conf/Makefile.common ($(top_srcdir)/grub-core/Makefile.core.am): Depend on $(top_srcdir)/grub-core/Makefile.gcry.def. ($(top_srcdir)/grub-core/Makefile.gcry.def): Remove. * grub-core/Makefile.am: Remove inclusion of Makefile.gcry.am. * gentpl.py (gvar_add): Turn GVARS into a set. (global_variable_initializers): Sort global variables on output. (vars_init): New function. (first_time): Likewise. (library): Ensure that non-global variable initialisations are emitted before the first time we emit code for a library block. Append to variables rather than setting them. Only emit noinst_LIBRARIES, BUILT_SOURCES, and CLEANFILES the first time for each conditional path. (program): installdir() emits an Autogen macro, so must be passed to var_add rather than gvar_add. (data): Likewise. (script): Likewise. (rules): New function, centralising handling for different target types. Set up Guile association lists for first_time and vars_init, and send most output to a diversion so that variable initialisations can be emitted first. (module_rules): Use new rules function. (kernel_rules): Likewise. (image_rules): Likewise. (library_rules): Likewise. (program_rules): Likewise. (script_rules): Likewise. (data_rules): Likewise. * configure.ac: Add AC_PROG_LN_S, for the benefit of ntldr-img. * .bzrignore: Add contrib and grub-core/contrib. Remove grub-core/Makefile.gcry.am. --- .bzrignore | 3 +- ChangeLog | 47 +++++++++++++++++++++ autogen.sh | 47 +++++++++++++++++++-- conf/Makefile.common | 10 ++--- configure.ac | 1 + gentpl.py | 97 +++++++++++++++++++++++++++++-------------- grub-core/Makefile.am | 1 - 7 files changed, 163 insertions(+), 43 deletions(-) diff --git a/.bzrignore b/.bzrignore index 06dd94341..7c5597bce 100644 --- a/.bzrignore +++ b/.bzrignore @@ -104,9 +104,10 @@ grub-core/lib/libgcrypt-grub **/.deps-core **/.dirstamp Makefile.util.am +contrib grub-core/Makefile.core.am -grub-core/Makefile.gcry.am grub-core/Makefile.gcry.def +grub-core/contrib grub-core/genmod.sh grub-core/gensyminfo.sh grub-core/*.module diff --git a/ChangeLog b/ChangeLog index b5117bee5..95a0ae2fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2010-09-24 Colin Watson + + Re-enable grub-extras. + + * autogen.sh: Create symlinks to ${GRUB_CONTRIB} if necessary to + avoid confusing Automake. Run autogen only twice, once for the top + level and once for grub-core. Add Makefile.util.def and + Makefile.core.def from extra modules to the appropriate autogen + invocations. If Makefile.common exists in an extra module, include + it in both Makefile.util.am and grub-core/Makefile.core.am; + similarly, include any Makefile.util.common file in Makefile.util.am + and any Makefile.core.common file in grub-core/Makefile.core.am. + * conf/Makefile.common ($(top_srcdir)/grub-core/Makefile.core.am): + Depend on $(top_srcdir)/grub-core/Makefile.gcry.def. + ($(top_srcdir)/grub-core/Makefile.gcry.def): Remove. + * grub-core/Makefile.am: Remove inclusion of Makefile.gcry.am. + + * gentpl.py (gvar_add): Turn GVARS into a set. + (global_variable_initializers): Sort global variables on output. + (vars_init): New function. + (first_time): Likewise. + (library): Ensure that non-global variable initialisations are + emitted before the first time we emit code for a library block. + Append to variables rather than setting them. Only emit + noinst_LIBRARIES, BUILT_SOURCES, and CLEANFILES the first time for + each conditional path. + (program): installdir() emits an Autogen macro, so must be passed to + var_add rather than gvar_add. + (data): Likewise. + (script): Likewise. + (rules): New function, centralising handling for different target + types. Set up Guile association lists for first_time and vars_init, + and send most output to a diversion so that variable initialisations + can be emitted first. + (module_rules): Use new rules function. + (kernel_rules): Likewise. + (image_rules): Likewise. + (library_rules): Likewise. + (program_rules): Likewise. + (script_rules): Likewise. + (data_rules): Likewise. + + * configure.ac: Add AC_PROG_LN_S, for the benefit of ntldr-img. + + * .bzrignore: Add contrib and grub-core/contrib. Remove + grub-core/Makefile.gcry.am. + 2010-09-24 Yves Blusseau * grub-core/lib/LzFind.c: Add missing include. diff --git a/autogen.sh b/autogen.sh index f052499ae..96b1e33e2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -14,9 +14,50 @@ echo "Creating Makefile.tpl..." python gentpl.py | sed -e '/^$/{N;/^\n$/D;}' > Makefile.tpl echo "Running autogen..." -autogen -T Makefile.tpl Makefile.util.def | sed -e '/^$/{N;/^\n$/D;}' > Makefile.util.am -autogen -T Makefile.tpl grub-core/Makefile.core.def | sed -e '/^$/{N;/^\n$/D;}' > grub-core/Makefile.core.am -autogen -T Makefile.tpl grub-core/Makefile.gcry.def | sed -e '/^$/{N;/^\n$/D;}' > grub-core/Makefile.gcry.am + +# Automake doesn't like including files from a path outside the project. +rm -f contrib grub-core/contrib +if [ "x${GRUB_CONTRIB}" != x ]; then + [ "${GRUB_CONTRIB}" = contrib ] || ln -s "${GRUB_CONTRIB}" contrib + [ "${GRUB_CONTRIB}" = grub-core/contrib ] || ln -s ../contrib grub-core/contrib +fi + +UTIL_DEFS=Makefile.util.def +CORE_DEFS='grub-core/Makefile.core.def grub-core/Makefile.gcry.def' + +for extra in contrib/*/Makefile.util.def; do + if test -e "$extra"; then + UTIL_DEFS="$UTIL_DEFS $extra" + fi +done + +for extra in contrib/*/Makefile.core.def; do + if test -e "$extra"; then + CORE_DEFS="$CORE_DEFS $extra" + fi +done + +cat $UTIL_DEFS | autogen -T Makefile.tpl | sed -e '/^$/{N;/^\n$/D;}' > Makefile.util.am +cat $CORE_DEFS | autogen -T Makefile.tpl | sed -e '/^$/{N;/^\n$/D;}' > grub-core/Makefile.core.am + +for extra in contrib/*/Makefile.common; do + if test -e "$extra"; then + echo "include $extra" >> Makefile.util.am + echo "include $extra" >> grub-core/Makefile.core.am + fi +done + +for extra in contrib/*/Makefile.util.common; do + if test -e "$extra"; then + echo "include $extra" >> Makefile.util.am + fi +done + +for extra in contrib/*/Makefile.core.common; do + if test -e "$extra"; then + echo "include $extra" >> grub-core/Makefile.core.am + fi +done echo "Saving timestamps..." echo timestamp > stamp-h.in diff --git a/conf/Makefile.common b/conf/Makefile.common index ea16ab159..81bb3567e 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -146,11 +146,7 @@ $(top_srcdir)/Makefile.util.am: $(top_srcdir)/Makefile.util.def $(top_srcdir)/Ma mv $@.new $@ .PRECIOUS: $(top_srcdir)/grub-core/Makefile.core.am -$(top_srcdir)/grub-core/Makefile.core.am: $(top_srcdir)/grub-core/Makefile.core.def $(top_srcdir)/Makefile.tpl - autogen -T $(top_srcdir)/Makefile.tpl $< | sed -e '/^$$/{N;/^\\n$$/D;}' > $@.new || (rm -f $@.new; exit 1) - mv $@.new $@ - -.PRECIOUS: $(top_srcdir)/grub-core/Makefile.gcry.am -$(top_srcdir)/grub-core/Makefile.gcry.am: $(top_srcdir)/grub-core/Makefile.gcry.def $(top_srcdir)/Makefile.tpl - autogen -T $(top_srcdir)/Makefile.tpl $< | sed -e '/^$$/{N;/^\\n$$/D;}' > $@.new || (rm -f $@.new; exit 1) +$(top_srcdir)/grub-core/Makefile.core.am: $(top_srcdir)/grub-core/Makefile.core.def $(top_srcdir)/grub-core/Makefile.gcry.def $(top_srcdir)/Makefile.tpl + if [ "x$$GRUB_CONTRIB" != x ]; then echo "You need to run ./autogen.sh manually." >&2; exit 1; fi + autogen -T $(top_srcdir)/Makefile.tpl $(top_srcdir)/grub-core/Makefile.core.def $(top_srcdir)/grub-core/Makefile.gcry.def | sed -e '/^$$/{N;/^\\n$$/D;}' > $@.new || (rm -f $@.new; exit 1) mv $@.new $@ diff --git a/configure.ac b/configure.ac index fc0579cad..66d4a6877 100644 --- a/configure.ac +++ b/configure.ac @@ -235,6 +235,7 @@ AC_PROG_LEX AC_PROG_YACC AC_PROG_MAKE_SET AC_PROG_MKDIR_P +AC_PROG_LN_S if test "x$LEX" = "x:"; then AC_MSG_ERROR([flex is not found]) diff --git a/gentpl.py b/gentpl.py index 3fe995dc0..109ce7981 100644 --- a/gentpl.py +++ b/gentpl.py @@ -70,16 +70,15 @@ for platform in GRUB_PLATFORMS: # # Global variables # -GVARS = [] +GVARS = set() def gvar_add(var, value): - if var not in GVARS: - GVARS.append(var) + GVARS.add(var) return var + " += " + value + "\n" def global_variable_initializers(): r = "" - for var in GVARS: + for var in sorted(GVARS): r += var + " ?= \n" return r @@ -87,6 +86,16 @@ def global_variable_initializers(): # Per PROGRAM/SCRIPT variables # +def vars_init(*var_list): + r = "[+ IF (if (not (assoc-ref seen-vars (get \".name\"))) \"seen\") +]" + r += "[+ (out-suspend \"v\") +]" + for var in var_list: + r += var + " = \n" + r += "[+ (out-resume \"v\") +]" + r += "[+ (set! seen-vars (assoc-set! seen-vars (get \".name\") 0)) +]" + r += "[+ ENDIF +]" + return first_time(r) + def var_set(var, value): return var + " = " + value + "\n" @@ -257,6 +266,15 @@ def platform_ccasflags(p): return platform_specific_values(p, "_ccasflags", "cca def platform_stripflags(p): return platform_specific_values(p, "_stripflags", "stripflags") def platform_objcopyflags(p): return platform_specific_values(p, "_objcopyflags", "objcopyflags") +# +# Emit snippet only the first time through for the current name. +# +def first_time(snippet): + r = "[+ IF (if (not (assoc-ref seen-target (get \".name\"))) \"seen\") +]" + r += snippet + r += "[+ ENDIF +]" + return r + def module(platform): r = set_canonical_name_suffix(".module") @@ -341,18 +359,25 @@ fi def library(platform): r = set_canonical_name_suffix("") - r += gvar_add("noinst_LIBRARIES", "[+ name +]") - r += var_set(cname() + "_SOURCES", platform_sources(platform)) - r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform)) - r += var_set(cname() + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_LIBRARY) " + platform_cflags(platform)) - r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) " + platform_cppflags(platform)) - r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) " + platform_ccasflags(platform)) - # r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform)) + + r += vars_init(cname() + "_SOURCES", + "nodist_" + cname() + "_SOURCES", + cname() + "_CFLAGS", + cname() + "_CPPFLAGS", + cname() + "_CCASFLAGS") + # cname() + "_DEPENDENCIES") + + r += first_time(gvar_add("noinst_LIBRARIES", "[+ name +]")) + r += var_add(cname() + "_SOURCES", platform_sources(platform)) + r += var_add("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform)) + r += var_add(cname() + "_CFLAGS", first_time("$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(platform)) + r += var_add(cname() + "_CPPFLAGS", first_time("$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(platform)) + r += var_add(cname() + "_CCASFLAGS", first_time("$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(platform)) + # r += var_add(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform)) r += gvar_add("EXTRA_DIST", extra_dist()) - r += gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)") - r += gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)") - + r += first_time(gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)")) + r += first_time(gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)")) return r def installdir(default="bin"): @@ -376,7 +401,7 @@ def program(platform, test=False): r += gvar_add("check_PROGRAMS", "[+ name +]") r += gvar_add("TESTS", "[+ name +]") r += "[+ ELSE +]" - r += gvar_add(installdir() + "_PROGRAMS", "[+ name +]") + r += var_add(installdir() + "_PROGRAMS", "[+ name +]") r += "[+ IF mansection +]" + manpage() + "[+ ENDIF +]" r += "[+ ENDIF +]" @@ -397,7 +422,7 @@ def program(platform, test=False): def data(platform): r = gvar_add("EXTRA_DIST", platform_sources(platform)) r += gvar_add("EXTRA_DIST", extra_dist()) - r += gvar_add(installdir() + "_DATA", platform_sources(platform)) + r += var_add(installdir() + "_DATA", platform_sources(platform)) return r def script(platform): @@ -405,7 +430,7 @@ def script(platform): r += gvar_add("check_SCRIPTS", "[+ name +]") r += gvar_add ("TESTS", "[+ name +]") r += "[+ ELSE +]" - r += gvar_add(installdir() + "_SCRIPTS", "[+ name +]") + r += var_add(installdir() + "_SCRIPTS", "[+ name +]") r += "[+ IF mansection +]" + manpage() + "[+ ENDIF +]" r += "[+ ENDIF +]" @@ -418,33 +443,43 @@ chmod a+x [+ name +] r += gvar_add("dist_noinst_DATA", platform_sources(platform)) return r +def rules(target, closure): + # Create association lists for the benefit of first_time and vars_init. + r = "[+ (define seen-target '()) +]" + r += "[+ (define seen-vars '()) +]" + # Most output goes to a diversion. This allows us to emit variable + # initializations before everything else. + r += "[+ (out-push-new) +]" + + r += "[+ FOR " + target + " +]" + r += foreach_enabled_platform( + lambda p: under_platform_specific_conditionals(p, closure(p))) + # Remember that we've seen this target. + r += "[+ (set! seen-target (assoc-set! seen-target (get \".name\") 0)) +]" + r += "[+ ENDFOR +]" + r += "[+ (out-pop #t) +]" + return r + def module_rules(): - return "[+ FOR module +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, module(p))) + "[+ ENDFOR +]" + return rules("module", module) def kernel_rules(): - return "[+ FOR kernel +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, kernel(p))) + "[+ ENDFOR +]" + return rules("kernel", kernel) def image_rules(): - return "[+ FOR image +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, image(p))) + "[+ ENDFOR +]" + return rules("image", image) def library_rules(): - return "[+ FOR library +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, library(p))) + "[+ ENDFOR +]" + return rules("library", library) def program_rules(): - return "[+ FOR program +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, program(p))) + "[+ ENDFOR +]" + return rules("program", program) def script_rules(): - return "[+ FOR script +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, script(p))) + "[+ ENDFOR +]" + return rules("script", script) def data_rules(): - return "[+ FOR data +]" + foreach_enabled_platform( - lambda p: under_platform_specific_conditionals(p, data(p))) + "[+ ENDFOR +]" + return rules("data", data) print "[+ AutoGen5 template +]\n" a = module_rules() diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index addc83417..cff6b3782 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -51,7 +51,6 @@ grub_script.yy.c: grub_script.yy.h CLEANFILES += grub_script.yy.c grub_script.yy.h include $(srcdir)/Makefile.core.am -include $(srcdir)/Makefile.gcry.am KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h From 4f0de6881cef5f8396333ab6c12c6e571b0f8d26 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Sep 2010 14:05:47 +0200 Subject: [PATCH 16/75] C part of Reed-Solomon --- Makefile.util.def | 1 + grub-core/kern/i386/pc/startup.S | 2 + grub-core/partmap/gpt.c | 14 +- grub-core/partmap/msdos.c | 16 +- include/grub/offsets.h | 9 +- include/grub/partition.h | 5 +- include/grub/reed_solomon.h | 30 ++ util/grub-setup.c | 34 ++- util/reed_solomon.c | 465 +++++++++++++++++++++++++++++++ 9 files changed, 553 insertions(+), 23 deletions(-) create mode 100644 include/grub/reed_solomon.h create mode 100644 util/reed_solomon.c diff --git a/Makefile.util.def b/Makefile.util.def index 21314e04a..5d091f7f5 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -244,6 +244,7 @@ program = { common = util/grub-setup.c; common = util/raid.c; common = util/lvm.c; + common = util/reed_solomon.c; sparc64_ieee1275 = util/ieee1275/ofpath.c; diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 46e6b1fac..01825396c 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -100,6 +100,8 @@ VARIABLE(grub_install_dos_part) .long 0xFFFFFFFF VARIABLE(grub_install_bsd_part) .long 0xFFFFFFFF +reed_solomon_redundancy: + .long 0 #ifdef APPLE_CC bss_start: diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c index c9393d932..7f2c36143 100644 --- a/grub-core/partmap/gpt.c +++ b/grub-core/partmap/gpt.c @@ -124,9 +124,9 @@ gpt_partition_map_iterate (grub_disk_t disk, #ifdef GRUB_UTIL static grub_err_t -gpt_partition_map_embed (struct grub_disk *disk, unsigned int nsectors, +gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, grub_embed_type_t embed_type, - grub_disk_addr_t *sectors) + grub_disk_addr_t **sectors) { grub_disk_addr_t start = 0, len = 0; unsigned i; @@ -168,13 +168,17 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int nsectors, "This GPT partition label has no BIOS Boot Partition;" " embedding won't be possible!"); - if (len < nsectors) + if (len < *nsectors) return grub_error (GRUB_ERR_OUT_OF_RANGE, "Your BIOS Boot Partition is too small;" " embedding won't be possible!"); - for (i = 0; i < nsectors; i++) - sectors[i] = start + i; + *nsectors = len; + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) + (*sectors)[i] = start + i; return GRUB_ERR_NONE; } diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 921e2554e..f99e27a6e 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -145,9 +145,9 @@ grub_partition_msdos_iterate (grub_disk_t disk, #ifdef GRUB_UTIL static grub_err_t -pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors, +pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, grub_embed_type_t embed_type, - grub_disk_addr_t *sectors) + grub_disk_addr_t **sectors) { grub_disk_addr_t end = ~0ULL; struct grub_msdos_partition_mbr mbr; @@ -232,11 +232,15 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors, break; } - if (end >= nsectors + 1) + if (end >= *nsectors + 1) { int i; - for (i = 0; i < nsectors; i++) - sectors[i] = 1 + i; + *nsectors = end - 1; + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) + (*sectors)[i] = 1 + i; return GRUB_ERR_NONE; } @@ -245,7 +249,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors, "This msdos-style partition label has no " "post-MBR gap; embedding won't be possible!"); - if (nsectors > 62) + if (*nsectors > 62) return grub_error (GRUB_ERR_OUT_OF_RANGE, "Your core.img is unusually large. " "It won't fit in the embedding area."); diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 359b32244..d1cf8720f 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -34,11 +34,16 @@ /* The offset of GRUB_INSTALL_BSD_PART. */ #define GRUB_KERNEL_I386_PC_INSTALL_BSD_PART 0x18 +/* Offset of reed_solomon_redundancy. */ +#define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x1c + /* The offset of multiboot signature. */ -#define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x1c +#define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20 /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0x5D8 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0x5E0 + +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x300 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE diff --git a/include/grub/partition.h b/include/grub/partition.h index 7ccb7cffd..e7e00ef7f 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -48,8 +48,9 @@ struct grub_partition_map const grub_partition_t partition)); #ifdef GRUB_UTIL /* Determine sectors available for embedding. */ - grub_err_t (*embed) (struct grub_disk *disk, unsigned int nsectors, - grub_embed_type_t embed_type, grub_disk_addr_t *sectors); + grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors, + grub_embed_type_t embed_type, + grub_disk_addr_t **sectors); #endif }; typedef struct grub_partition_map *grub_partition_map_t; diff --git a/include/grub/reed_solomon.h b/include/grub/reed_solomon.h new file mode 100644 index 000000000..596dff246 --- /dev/null +++ b/include/grub/reed_solomon.h @@ -0,0 +1,30 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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_REED_SOLOMON_HEADER +#define GRUB_REED_SOLOMON_HEADER 1 + +void +grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, + grub_size_t redundancy); + +void +grub_reed_solomon_recover (void *buffer, grub_size_t data_size, + grub_size_t redundancy); + +#endif diff --git a/util/grub-setup.c b/util/grub-setup.c index 0c5470830..1518bb0a8 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -48,6 +48,7 @@ #include #include #include "progname.h" +#include #define _GNU_SOURCE 1 #include @@ -336,9 +337,10 @@ setup (const char *dir, grub_partition_t container = dest_dev->disk->partition; int multiple_partmaps = 0; grub_err_t err; - grub_disk_addr_t sectors[core_sectors]; + grub_disk_addr_t *sectors; int i; grub_fs_t fs; + unsigned int nsec; /* Unlike root_dev, with dest_dev we're interested in the partition map even if dest_dev itself is a whole disk. */ @@ -419,8 +421,11 @@ setup (const char *dir, goto unable_to_embed; } - err = dest_partmap->embed (dest_dev->disk, core_sectors, - GRUB_EMBED_PCBIOS, sectors); + nsec = core_sectors; + err = dest_partmap->embed (dest_dev->disk, &nsec, + GRUB_EMBED_PCBIOS, §ors); + if (nsec > 2 * core_sectors) + nsec = 2 * core_sectors; if (err) { @@ -439,6 +444,20 @@ setup (const char *dir, write_rootdev (core_img, root_dev, boot_img, first_sector); + core_img = realloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE); + first_block = (struct grub_boot_blocklist *) (core_img + + GRUB_DISK_SECTOR_SIZE + - sizeof (*block)); + + *(grub_uint32_t *) (core_img + GRUB_DISK_SECTOR_SIZE + + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY) + = grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size); + + grub_reed_solomon_add_redundancy (core_img + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + GRUB_DISK_SECTOR_SIZE, + core_size - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART - GRUB_DISK_SECTOR_SIZE, + nsec * GRUB_DISK_SECTOR_SIZE + - core_size); + /* Make sure that the second blocklist is a terminator. */ block = first_block - 1; block->start = 0; @@ -446,14 +465,13 @@ setup (const char *dir, block->segment = 0; /* Write the core image onto the disk. */ - for (i = 0; i < core_sectors; i++) + for (i = 0; i < nsec; i++) grub_disk_write (dest_dev->disk, sectors[i], 0, - (core_size - i * GRUB_DISK_SECTOR_SIZE - < GRUB_DISK_SECTOR_SIZE) ? core_size - - i * GRUB_DISK_SECTOR_SIZE - : GRUB_DISK_SECTOR_SIZE, + GRUB_DISK_SECTOR_SIZE, core_img + i * GRUB_DISK_SECTOR_SIZE); + grub_free (sectors); + goto finish; } #endif diff --git a/util/reed_solomon.c b/util/reed_solomon.c new file mode 100644 index 000000000..c20d023e7 --- /dev/null +++ b/util/reed_solomon.c @@ -0,0 +1,465 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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. + * + * 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 . + */ + +#ifdef TEST +#include +#include +#include +typedef unsigned int grub_size_t; +typedef unsigned char grub_uint8_t; +typedef unsigned short grub_uint16_t; +#define xmalloc malloc +#define grub_memset memset +#define grub_memcpy memcpy +#else +#include +#include +#include +#include +#endif + +#define GF_SIZE 8 +typedef grub_uint8_t gf_single_t; +typedef grub_uint16_t gf_double_t; +const gf_single_t gf_polynomial = 0x1d; + +#define SECTOR_SIZE 512 +#define MAX_BLOCK_SIZE (200 * SECTOR_SIZE) + +static gf_single_t +gf_reduce (gf_double_t a) +{ + int i; + for (i = GF_SIZE - 1; i >= 0; i--) + if (a & (1ULL << (i + GF_SIZE))) + a ^= (((gf_double_t) gf_polynomial) << i); + return a & ((1ULL << GF_SIZE) - 1); +} + +static gf_single_t +gf_mul (gf_single_t a, gf_single_t b) +{ + gf_double_t res = 0; + int i; + for (i = 0; i < GF_SIZE; i++) + if (b & (1 << i)) + res ^= ((gf_double_t) a) << i; + return gf_reduce (res); +} + +static int +bin_log2 (gf_double_t a) +{ + int i = 0; + while (a) + { + a >>= 1; + i++; + } + return i - 1; +} + +static gf_single_t +gf_invert (gf_single_t a) +{ + /* We start with: */ + /* 1 * a + 0 * p = a */ + /* 0 * a + 1 * p = p */ + gf_double_t x1 = 1, y1 = 0, z1 = a, x2 = 0, y2 = 1; + gf_double_t z2 = gf_polynomial | (1ULL << GF_SIZE), t; + /* invariant: z1 < z2*/ + while (z1 != 0) + { + int k; + k = bin_log2 (z2) - bin_log2 (z1); + x2 ^= (x1 << k); + y2 ^= (y1 << k); + z2 ^= (z1 << k); + + if (z1 >= z2) + { + t = x2; + x2 = x1; + x1 = t; + t = y2; + y2 = y1; + y1 = t; + t = z2; + z2 = z1; + z1 = t; + } + } + + return gf_reduce (x2); +} + +static gf_single_t +pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x) +{ + int i; + gf_single_t xn = 1, s = 0; + for (i = degree; i >= 0; i--) + { + s ^= gf_mul (pol[i], xn); + xn = gf_mul (x, xn); + } + return s; +} + +static void +rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) +{ + gf_single_t *rs_polynomial, a = 1; + int i, j; + gf_single_t *m; + m = xmalloc ((s + rs) * sizeof (gf_single_t)); + grub_memcpy (m, data, s * sizeof (gf_single_t)); + grub_memset (m + s, 0, rs * sizeof (gf_single_t)); + rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); + grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); + rs_polynomial[rs] = 1; + /* Multiply with X - a^r */ + for (j = 0; j < rs; j++) + { + if (a & (1 << (GF_SIZE - 1))) + { + a <<= 1; + a ^= gf_polynomial; + } + else + a <<= 1; + for (i = 0; i < rs; i++) + rs_polynomial[i] = rs_polynomial[i + 1] ^ gf_mul (a, rs_polynomial[i]); + rs_polynomial[rs] = gf_mul (a, rs_polynomial[rs]); + } + for (j = 0; j < s; j++) + if (m[j]) + { + gf_single_t f = m[j]; + for (i = 0; i <= rs; i++) + m[i+j] ^= gf_mul (rs_polynomial[i], f); + } + free (rs_polynomial); + grub_memcpy (data + s, m + s, rs * sizeof (gf_single_t)); + free (m); + +} + +static void +syndroms (gf_single_t *m, grub_size_t s, grub_size_t rs, + gf_single_t *sy) +{ + gf_single_t xn = 1; + int i; + for (i = 0; i < rs; i++) + { + if (xn & (1 << (GF_SIZE - 1))) + { + xn <<= 1; + xn ^= gf_polynomial; + } + else + xn <<= 1; + sy[i] = pol_evaluate (m, s + rs - 1, xn); + } +} + +static void +rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) +{ + grub_size_t rs2 = rs / 2; + gf_single_t *sigma; + gf_single_t *errpot; + int *errpos; + gf_single_t *sy; + int errnum = 0; + int i, j; + + sigma = xmalloc (rs2 * sizeof (gf_single_t)); + errpot = xmalloc (rs2 * sizeof (gf_single_t)); + errpos = xmalloc (rs2 * sizeof (int)); + sy = xmalloc (rs * sizeof (gf_single_t)); + + syndroms (m, s, rs, sy); + + { + gf_single_t *eq; + int *chosen; + + eq = xmalloc (rs2 * (rs2 + 1) * sizeof (gf_single_t)); + chosen = xmalloc (rs2 * sizeof (int)); + + for (i = 0; i < rs; i++) + if (sy[i] != 0) + break; + + /* No error detected. */ + if (i == rs) + return; + + for (i = 0; i < rs2; i++) + for (j = 0; j < rs2 + 1; j++) + eq[i * (rs2 + 1) + j] = sy[i+j]; + + grub_memset (sigma, 0, rs2 * sizeof (gf_single_t)); + grub_memset (chosen, -1, rs2 * sizeof (int)); + + for (i = 0 ; i < rs2; i++) + { + int nzidx; + int k; + gf_single_t r; + for (nzidx = 0; nzidx < rs2 && (eq[i * (rs2 + 1) + nzidx] == 0); + nzidx++); + if (nzidx == rs2) + { + break; + } + chosen[i] = nzidx; + r = gf_invert (eq[i * (rs2 + 1) + nzidx]); + for (j = 0; j < rs2 + 1; j++) + eq[i * (rs2 + 1) + j] = gf_mul (eq[i * (rs2 + 1) + j], r); + for (j = i + 1; j < rs2; j++) + { + gf_single_t rr = eq[j * (rs2 + 1) + nzidx]; + for (k = 0; k < rs2 + 1; k++) + eq[j * (rs2 + 1) + k] ^= gf_mul (eq[i * (rs2 + 1) + k], rr);; + } + } + for (i = rs2 - 1; i >= 0; i--) + { + gf_single_t s = 0; + if (chosen[i] == -1) + continue; + for (j = 0; j < rs2; j++) + s ^= gf_mul (eq[i * (rs2 + 1) + j], sigma[j]); + s ^= eq[i * (rs2 + 1) + rs2]; + sigma[chosen[i]] = s; + } + + free (chosen); + free (eq); + } + + { + gf_single_t xn = 1, xx = gf_invert (2), yn = 1; + int lp = 0; + for (i = 0; i < rs + s; i++) + { + gf_single_t ev = (gf_mul (pol_evaluate (sigma, rs2 - 1, xn), xn) ^ 1); + if (ev == 0) + { + errpot[errnum] = yn; + errpos[errnum++] = s + rs - i - 1; + } + yn = gf_mul (yn, 2); + xn = gf_mul (xn, xx); + } + } + { + gf_single_t *eq; + int *chosen; + gf_single_t *errvals; + + eq = xmalloc (rs * (errnum + 1) * sizeof (gf_single_t)); + chosen = xmalloc (rs * sizeof (int)); + errvals = xmalloc (errnum * sizeof (int)); + + grub_memset (chosen, -1, rs * sizeof (int)); + grub_memset (errvals, 0, errnum * sizeof (gf_single_t)); + + for (j = 0; j < errnum; j++) + eq[j] = errpot[j]; + eq[errnum] = sy[0]; + for (i = 1; i < rs; i++) + { + for (j = 0; j < errnum; j++) + eq[(errnum + 1) * i + j] = gf_mul (errpot[j], + eq[(errnum + 1) * (i - 1) + j]); + eq[(errnum + 1) * i + errnum] = sy[i]; + } + for (i = 0 ; i < rs; i++) + { + int nzidx; + int k; + gf_single_t r; + for (nzidx = 0; nzidx < errnum && (eq[i * (errnum + 1) + nzidx] == 0); + nzidx++); + if (nzidx == errnum) + continue; + chosen[i] = nzidx; + r = gf_invert (eq[i * (errnum + 1) + nzidx]); + for (j = 0; j < errnum + 1; j++) + eq[i * (errnum + 1) + j] = gf_mul (eq[i * (errnum + 1) + j], r); + for (j = i + 1; j < rs; j++) + { + gf_single_t rr = eq[j * (errnum + 1) + nzidx]; + for (k = 0; k < errnum + 1; k++) + eq[j * (errnum + 1) + k] ^= gf_mul (eq[i * (errnum + 1) + k], rr); + } + } + for (i = rs - 1; i >= 0; i--) + { + gf_single_t s = 0; + if (chosen[i] == -1) + continue; + for (j = 0; j < errnum; j++) + s ^= gf_mul (eq[i * (errnum + 1) + j], errvals[j]); + s ^= eq[i * (errnum + 1) + errnum]; + errvals[chosen[i]] = s; + } + for (i = 0; i < errnum; i++) + m[errpos[i]] ^= errvals[i]; + } + free (sy); +} + +static void +decode_block (gf_single_t *ptr, grub_size_t s, + gf_single_t *rptr, grub_size_t rs) +{ + grub_size_t ss; + int i, j, k; + for (i = 0; i < SECTOR_SIZE; i++) + { + grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; + grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; + gf_single_t m[ds + rr]; + + for (j = 0; j < ds; j++) + m[j] = ptr[SECTOR_SIZE * j + i]; + for (j = 0; j < rr; j++) + m[j + ds] = rptr[SECTOR_SIZE * j + i]; + + rs_recover (m, ds, rr); + + for (j = 0; j < ds; j++) + ptr[SECTOR_SIZE * j + i] = m[j]; + } +} + +static void +encode_block (gf_single_t *ptr, grub_size_t s, + gf_single_t *rptr, grub_size_t rs) +{ + grub_size_t ss; + int i, j; + for (i = 0; i < SECTOR_SIZE; i++) + { + grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; + grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; + gf_single_t m[ds + rr]; + for (j = 0; j < ds; j++) + m[j] = ptr[SECTOR_SIZE * j + i]; + rs_encode (m, ds, rr); + for (j = 0; j < rr; j++) + rptr[SECTOR_SIZE * j + i] = m[j + ds]; + } +} + +void +grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, + grub_size_t redundancy) +{ + grub_size_t s = data_size; + grub_size_t rs = redundancy; + gf_single_t *ptr = buffer; + gf_single_t *rptr = ptr + s; + + while (s > 0) + { + grub_size_t tt; + grub_size_t cs, crs; + cs = s; + crs = rs; + tt = cs + crs; + if (tt > MAX_BLOCK_SIZE) + { + cs = (cs * MAX_BLOCK_SIZE) / tt; + crs = (crs * MAX_BLOCK_SIZE) / tt; + } + encode_block (ptr, cs, rptr, crs); + ptr += cs; + rptr += crs; + s -= cs; + rs -= crs; + } +} + +void +grub_reed_solomon_recover (void *ptr, grub_size_t s, grub_size_t rs) +{ + gf_single_t *rptr = ptr + s; + while (s > 0) + { + grub_size_t tt; + grub_size_t cs, crs; + cs = s; + crs = rs; + tt = cs + crs; + if (tt > MAX_BLOCK_SIZE) + { + cs = cs * MAX_BLOCK_SIZE / tt; + crs = crs * MAX_BLOCK_SIZE / tt; + } + decode_block (ptr, cs, rptr, crs); + ptr += cs; + rptr += crs; + s -= cs; + rs -= crs; + } +} + +#ifdef TEST +int +main (int argc, char **argv) +{ + FILE *in, *out; + grub_size_t s, rs; + char *buf; + in = fopen ("tst.bin", "rb"); + if (!in) + return 1; + fseek (in, 0, SEEK_END); + s = ftell (in); + fseek (in, 0, SEEK_SET); + rs = 1024 * ((s + MAX_BLOCK_SIZE - 1) / (MAX_BLOCK_SIZE - 1024)); + buf = xmalloc (s + rs + SECTOR_SIZE); + fread (buf, 1, s, in); + + grub_reed_solomon_add_redundancy (buf, s, rs); + + out = fopen ("tst_rs.bin", "wb"); + fwrite (buf, 1, s + rs, out); + fclose (out); + + grub_memset (buf + 512 * 15, 0, 512); + + out = fopen ("tst_dam.bin", "wb"); + fwrite (buf, 1, s + rs, out); + fclose (out); + + grub_reed_solomon_recover (buf, s, rs); + + out = fopen ("tst_rec.bin", "wb"); + fwrite (buf, 1, s, out); + fclose (out); + + return 0; +} +#endif From 449333eb7df96f6db3baa6965ede4c59cf8fa261 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 25 Sep 2010 10:43:09 +0530 Subject: [PATCH 17/75] Fix grub-emu build. * grub-core/kern/emu/main.c: Remove #include . * grub-core/kern/emu/full.c: Split grub_mdraid_{init,fini} into mdraid09 and mdraid1x. --- ChangeLog | 8 ++++++++ grub-core/kern/emu/full.c | 6 ++++-- grub-core/kern/emu/main.c | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95a0ae2fb..c2aa58c02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-09-25 BVK Chaitanya + + Fix grub-emu build. + + * grub-core/kern/emu/main.c: Remove #include . + * grub-core/kern/emu/full.c: Split grub_mdraid_{init,fini} into + mdraid09 and mdraid1x. + 2010-09-24 Colin Watson Re-enable grub-extras. diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index a5801db2f..422ca6ec6 100644 --- a/grub-core/kern/emu/full.c +++ b/grub-core/kern/emu/full.c @@ -61,9 +61,11 @@ void grub_emu_post_init (void) { grub_lvm_fini (); - grub_mdraid_fini (); + grub_mdraid09_fini (); + grub_mdraid1x_fini (); grub_raid_fini (); grub_raid_init (); - grub_mdraid_init (); + grub_mdraid09_fini (); + grub_mdraid1x_fini (); grub_lvm_init (); } diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index c575beb4b..0a7645992 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include From 96510fafd246b1c8d44e1fef210e500f95b68a06 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Sat, 25 Sep 2010 10:48:48 +0530 Subject: [PATCH 18/75] fix typo --- ChangeLog | 4 ++++ grub-core/kern/emu/full.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2aa58c02..0bc9ac7c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-09-25 BVK Chaitanya + + * grub-core/kern/emu/full.c (grub_emu_post_init): Fix typo. + 2010-09-25 BVK Chaitanya Fix grub-emu build. diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index 422ca6ec6..70bcae78f 100644 --- a/grub-core/kern/emu/full.c +++ b/grub-core/kern/emu/full.c @@ -65,7 +65,7 @@ grub_emu_post_init (void) grub_mdraid1x_fini (); grub_raid_fini (); grub_raid_init (); - grub_mdraid09_fini (); - grub_mdraid1x_fini (); + grub_mdraid09_init (); + grub_mdraid1x_init (); grub_lvm_init (); } From 419cbeb06d2733095b4cf9dad8b088f2338e1420 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Sep 2010 19:33:05 +0200 Subject: [PATCH 19/75] hook Reed-Solomon into startup.S --- Makefile.util.def | 2 +- grub-core/Makefile.am | 4 + grub-core/kern/i386/pc/startup.S | 16 ++ {util => grub-core/lib}/reed_solomon.c | 327 ++++++++++++++----------- include/grub/offsets.h | 4 +- 5 files changed, 209 insertions(+), 144 deletions(-) rename {util => grub-core/lib}/reed_solomon.c (63%) diff --git a/Makefile.util.def b/Makefile.util.def index 5d091f7f5..bf66d45bc 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -244,7 +244,7 @@ program = { common = util/grub-setup.c; common = util/raid.c; common = util/lvm.c; - common = util/reed_solomon.c; + common = grub-core/lib/reed_solomon.c; sparc64_ieee1275 = util/ieee1275/ofpath.c; diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index addc83417..307467f44 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -48,6 +48,10 @@ CLEANFILES += grub_script.tab.c grub_script.tab.h grub_script.yy.h: script/yylex.l $(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $< grub_script.yy.c: grub_script.yy.h + +rs_decoder.S: $(srcdir)/lib/reed_solomon.c + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< + CLEANFILES += grub_script.yy.c grub_script.yy.h include $(srcdir)/Makefile.core.am diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 01825396c..283fc4f49 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -206,6 +206,22 @@ LOCAL (codestart): incl %eax call grub_gate_a20 + movl EXT_C(grub_kernel_image_size), %eax + addl EXT_C(grub_total_module_size), %eax + movl reed_solomon_redundancy, %ecx + leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %edx + testl %eax, %eax + jz post_reed_solomon + call EXT_C (grub_reed_solomon_recover) + jmp post_reed_solomon + +#include "/home/phcoder/compile/grub-core/rs_decoder.S" + + .text + + . = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART +post_reed_solomon: + #ifdef ENABLE_LZMA movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi diff --git a/util/reed_solomon.c b/grub-core/lib/reed_solomon.c similarity index 63% rename from util/reed_solomon.c rename to grub-core/lib/reed_solomon.c index c20d023e7..290eb9482 100644 --- a/util/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -18,25 +18,48 @@ #ifdef TEST #include +#define xmalloc malloc +#define grub_memset memset +#define grub_memcpy memcpy +#endif + +#ifndef STANDALONE +#ifdef TEST #include #include typedef unsigned int grub_size_t; typedef unsigned char grub_uint8_t; typedef unsigned short grub_uint16_t; -#define xmalloc malloc -#define grub_memset memset -#define grub_memcpy memcpy #else #include #include #include #include #endif +#endif + +#ifdef STANDALONE +#ifdef TEST +typedef unsigned int grub_size_t; +typedef unsigned char grub_uint8_t; +typedef unsigned short grub_uint16_t; +#else +#include +#endif +void +grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs); +#endif #define GF_SIZE 8 typedef grub_uint8_t gf_single_t; typedef grub_uint16_t gf_double_t; -const gf_single_t gf_polynomial = 0x1d; +#define GF_POLYNOMIAL 0x1d +#define GF_INVERT2 0x8e +#ifdef STANDALONE +static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100000; +#else +static char *scratch; +#endif #define SECTOR_SIZE 512 #define MAX_BLOCK_SIZE (200 * SECTOR_SIZE) @@ -47,7 +70,7 @@ gf_reduce (gf_double_t a) int i; for (i = GF_SIZE - 1; i >= 0; i--) if (a & (1ULL << (i + GF_SIZE))) - a ^= (((gf_double_t) gf_polynomial) << i); + a ^= (((gf_double_t) GF_POLYNOMIAL) << i); return a & ((1ULL << GF_SIZE) - 1); } @@ -62,50 +85,19 @@ gf_mul (gf_single_t a, gf_single_t b) return gf_reduce (res); } -static int -bin_log2 (gf_double_t a) +static grub_uint8_t gf_invert[256]; + +static void +init_inverts (void) { - int i = 0; - while (a) + gf_single_t a = 1, ai = 1; + do { - a >>= 1; - i++; + a = gf_mul (a, 2); + ai = gf_mul (ai, GF_INVERT2); + gf_invert[a] = ai; } - return i - 1; -} - -static gf_single_t -gf_invert (gf_single_t a) -{ - /* We start with: */ - /* 1 * a + 0 * p = a */ - /* 0 * a + 1 * p = p */ - gf_double_t x1 = 1, y1 = 0, z1 = a, x2 = 0, y2 = 1; - gf_double_t z2 = gf_polynomial | (1ULL << GF_SIZE), t; - /* invariant: z1 < z2*/ - while (z1 != 0) - { - int k; - k = bin_log2 (z2) - bin_log2 (z1); - x2 ^= (x1 << k); - y2 ^= (y1 << k); - z2 ^= (z1 << k); - - if (z1 >= z2) - { - t = x2; - x2 = x1; - x1 = t; - t = y2; - y2 = y1; - y1 = t; - t = z2; - z2 = z1; - z1 = t; - } - } - - return gf_reduce (x2); + while (a != 1); } static gf_single_t @@ -121,6 +113,7 @@ pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x) return s; } +#if !defined (STANDALONE) || defined (TEST) static void rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) { @@ -139,7 +132,7 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) if (a & (1 << (GF_SIZE - 1))) { a <<= 1; - a ^= gf_polynomial; + a ^= GF_POLYNOMIAL; } else a <<= 1; @@ -157,21 +150,21 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) free (rs_polynomial); grub_memcpy (data + s, m + s, rs * sizeof (gf_single_t)); free (m); - } +#endif static void syndroms (gf_single_t *m, grub_size_t s, grub_size_t rs, gf_single_t *sy) { gf_single_t xn = 1; - int i; + unsigned i; for (i = 0; i < rs; i++) { if (xn & (1 << (GF_SIZE - 1))) { xn <<= 1; - xn ^= gf_polynomial; + xn ^= GF_POLYNOMIAL; } else xn <<= 1; @@ -179,6 +172,66 @@ syndroms (gf_single_t *m, grub_size_t s, grub_size_t rs, } } +static void +gauss_eliminate (gf_single_t *eq, int n, int m, int *chosen) +{ + int i, j; + + for (i = 0 ; i < n; i++) + { + int nzidx; + int k; + gf_single_t r; + for (nzidx = 0; nzidx < m && (eq[i * (m + 1) + nzidx] == 0); + nzidx++); + if (nzidx == m) + continue; + chosen[i] = nzidx; + r = gf_invert [eq[i * (m + 1) + nzidx]]; + for (j = 0; j < m + 1; j++) + eq[i * (m + 1) + j] = gf_mul (eq[i * (m + 1) + j], r); + for (j = i + 1; j < n; j++) + { + gf_single_t rr = eq[j * (m + 1) + nzidx]; + for (k = 0; k < m + 1; k++) + eq[j * (m + 1) + k] ^= gf_mul (eq[i * (m + 1) + k], rr); + } + } +} + +static void +gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol) +{ + int *chosen; + int i, j; + +#ifndef STANDALONE + chosen = xmalloc (n * sizeof (int)); + grub_memset (chosen, -1, n * sizeof (int)); +#else + chosen = (void *) scratch; + scratch += n; +#endif + for (i = 0; i < m; i++) + sol[i] = 0; + gauss_eliminate (eq, n, m, chosen); + for (i = n - 1; i >= 0; i--) + { + gf_single_t s = 0; + if (chosen[i] == -1) + continue; + for (j = 0; j < m; j++) + s ^= gf_mul (eq[i * (m + 1) + j], sol[j]); + s ^= eq[i * (m + 1) + m]; + sol[chosen[i]] = s; + } +#ifndef STANDALONE + free (chosen); +#else + scratch -= n; +#endif +} + static void rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) { @@ -190,76 +243,61 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) int errnum = 0; int i, j; +#ifndef STANDALONE sigma = xmalloc (rs2 * sizeof (gf_single_t)); errpot = xmalloc (rs2 * sizeof (gf_single_t)); errpos = xmalloc (rs2 * sizeof (int)); sy = xmalloc (rs * sizeof (gf_single_t)); +#else + sigma = (void *) scratch; + scratch += rs2 * sizeof (gf_single_t); + errpot = (void *) scratch; + scratch += rs2 * sizeof (gf_single_t); + errpos = (void *) scratch; + scratch += rs2 * sizeof (int); + sy = (void *) scratch; + scratch += rs * sizeof (gf_single_t); +#endif syndroms (m, s, rs, sy); { gf_single_t *eq; - int *chosen; +#ifndef STANDALONE eq = xmalloc (rs2 * (rs2 + 1) * sizeof (gf_single_t)); - chosen = xmalloc (rs2 * sizeof (int)); +#else + eq = (void *) scratch; + scratch += rs2 * (rs2 + 1) * sizeof (gf_single_t); +#endif - for (i = 0; i < rs; i++) + for (i = 0; i < (int) rs; i++) if (sy[i] != 0) break; /* No error detected. */ - if (i == rs) + if (i == (int) rs) return; - for (i = 0; i < rs2; i++) - for (j = 0; j < rs2 + 1; j++) + for (i = 0; i < (int) rs2; i++) + for (j = 0; j < (int) rs2 + 1; j++) eq[i * (rs2 + 1) + j] = sy[i+j]; - grub_memset (sigma, 0, rs2 * sizeof (gf_single_t)); - grub_memset (chosen, -1, rs2 * sizeof (int)); + for (i = 0; i < (int) rs2; i++) + sigma[i] = 0; - for (i = 0 ; i < rs2; i++) - { - int nzidx; - int k; - gf_single_t r; - for (nzidx = 0; nzidx < rs2 && (eq[i * (rs2 + 1) + nzidx] == 0); - nzidx++); - if (nzidx == rs2) - { - break; - } - chosen[i] = nzidx; - r = gf_invert (eq[i * (rs2 + 1) + nzidx]); - for (j = 0; j < rs2 + 1; j++) - eq[i * (rs2 + 1) + j] = gf_mul (eq[i * (rs2 + 1) + j], r); - for (j = i + 1; j < rs2; j++) - { - gf_single_t rr = eq[j * (rs2 + 1) + nzidx]; - for (k = 0; k < rs2 + 1; k++) - eq[j * (rs2 + 1) + k] ^= gf_mul (eq[i * (rs2 + 1) + k], rr);; - } - } - for (i = rs2 - 1; i >= 0; i--) - { - gf_single_t s = 0; - if (chosen[i] == -1) - continue; - for (j = 0; j < rs2; j++) - s ^= gf_mul (eq[i * (rs2 + 1) + j], sigma[j]); - s ^= eq[i * (rs2 + 1) + rs2]; - sigma[chosen[i]] = s; - } + gauss_solve (eq, rs2, rs2, sigma); - free (chosen); +#ifndef STANDALONE free (eq); +#else + scratch -= rs2 * (rs2 + 1) * sizeof (gf_single_t); +#endif } { - gf_single_t xn = 1, xx = gf_invert (2), yn = 1; - int lp = 0; - for (i = 0; i < rs + s; i++) + gf_single_t xn = 1, yn = 1; + for (i = 0; i < (int) (rs + s); i++) { gf_single_t ev = (gf_mul (pol_evaluate (sigma, rs2 - 1, xn), xn) ^ 1); if (ev == 0) @@ -268,96 +306,87 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) errpos[errnum++] = s + rs - i - 1; } yn = gf_mul (yn, 2); - xn = gf_mul (xn, xx); + xn = gf_mul (xn, GF_INVERT2); } } { - gf_single_t *eq; - int *chosen; gf_single_t *errvals; + gf_single_t *eq; +#ifndef STANDALONE eq = xmalloc (rs * (errnum + 1) * sizeof (gf_single_t)); - chosen = xmalloc (rs * sizeof (int)); errvals = xmalloc (errnum * sizeof (int)); - - grub_memset (chosen, -1, rs * sizeof (int)); - grub_memset (errvals, 0, errnum * sizeof (gf_single_t)); +#else + eq = (void *) scratch; + scratch += rs * (errnum + 1) * sizeof (gf_single_t); + errvals = (void *) scratch; + scratch += errnum * sizeof (int); +#endif for (j = 0; j < errnum; j++) eq[j] = errpot[j]; eq[errnum] = sy[0]; - for (i = 1; i < rs; i++) + for (i = 1; i < (int) rs; i++) { - for (j = 0; j < errnum; j++) + for (j = 0; j < (int) errnum; j++) eq[(errnum + 1) * i + j] = gf_mul (errpot[j], eq[(errnum + 1) * (i - 1) + j]); eq[(errnum + 1) * i + errnum] = sy[i]; } - for (i = 0 ; i < rs; i++) - { - int nzidx; - int k; - gf_single_t r; - for (nzidx = 0; nzidx < errnum && (eq[i * (errnum + 1) + nzidx] == 0); - nzidx++); - if (nzidx == errnum) - continue; - chosen[i] = nzidx; - r = gf_invert (eq[i * (errnum + 1) + nzidx]); - for (j = 0; j < errnum + 1; j++) - eq[i * (errnum + 1) + j] = gf_mul (eq[i * (errnum + 1) + j], r); - for (j = i + 1; j < rs; j++) - { - gf_single_t rr = eq[j * (errnum + 1) + nzidx]; - for (k = 0; k < errnum + 1; k++) - eq[j * (errnum + 1) + k] ^= gf_mul (eq[i * (errnum + 1) + k], rr); - } - } - for (i = rs - 1; i >= 0; i--) - { - gf_single_t s = 0; - if (chosen[i] == -1) - continue; - for (j = 0; j < errnum; j++) - s ^= gf_mul (eq[i * (errnum + 1) + j], errvals[j]); - s ^= eq[i * (errnum + 1) + errnum]; - errvals[chosen[i]] = s; - } - for (i = 0; i < errnum; i++) + + gauss_solve (eq, rs, errnum, errvals); + + for (i = 0; i < (int) errnum; i++) m[errpos[i]] ^= errvals[i]; +#ifndef STANDALONE + free (eq); + free (errvals); +#else + scratch -= rs * (errnum + 1) * sizeof (gf_single_t); + scratch -= errnum * sizeof (int); +#endif } +#ifndef STANDALONE + free (sigma); + free (errpot); + free (errpos); free (sy); +#else + scratch -= rs2 * sizeof (gf_single_t); + scratch -= rs2 * sizeof (gf_single_t); + scratch -= rs2 * sizeof (int); + scratch -= rs * sizeof (gf_single_t); +#endif } static void decode_block (gf_single_t *ptr, grub_size_t s, gf_single_t *rptr, grub_size_t rs) { - grub_size_t ss; - int i, j, k; + int i, j; for (i = 0; i < SECTOR_SIZE; i++) { grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; gf_single_t m[ds + rr]; - for (j = 0; j < ds; j++) + for (j = 0; j < (int) ds; j++) m[j] = ptr[SECTOR_SIZE * j + i]; - for (j = 0; j < rr; j++) + for (j = 0; j < (int) rr; j++) m[j + ds] = rptr[SECTOR_SIZE * j + i]; rs_recover (m, ds, rr); - for (j = 0; j < ds; j++) + for (j = 0; j < (int) ds; j++) ptr[SECTOR_SIZE * j + i] = m[j]; } } +#if !defined (STANDALONE) || defined (TEST) static void encode_block (gf_single_t *ptr, grub_size_t s, gf_single_t *rptr, grub_size_t rs) { - grub_size_t ss; int i, j; for (i = 0; i < SECTOR_SIZE; i++) { @@ -371,7 +400,9 @@ encode_block (gf_single_t *ptr, grub_size_t s, rptr[SECTOR_SIZE * j + i] = m[j + ds]; } } +#endif +#if !defined (STANDALONE) || defined (TEST) void grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, grub_size_t redundancy) @@ -400,11 +431,18 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, rs -= crs; } } +#endif void -grub_reed_solomon_recover (void *ptr, grub_size_t s, grub_size_t rs) +grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) { + gf_single_t *ptr = ptr_; gf_single_t *rptr = ptr + s; + +#if defined (STANDALONE) && !defined (TEST) + init_inverts (); +#endif + while (s > 0) { grub_size_t tt; @@ -432,6 +470,13 @@ main (int argc, char **argv) FILE *in, *out; grub_size_t s, rs; char *buf; + +#ifdef STANDALONE + scratch = xmalloc (1048576); +#endif + + init_inverts (); + in = fopen ("tst.bin", "rb"); if (!in) return 1; diff --git a/include/grub/offsets.h b/include/grub/offsets.h index d1cf8720f..b8fbe40d4 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -41,9 +41,9 @@ #define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20 /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0x5E0 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc6c -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x300 +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x748 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE From 3ac9e7920712be587214e904139a3871add55392 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Sep 2010 20:40:26 +0200 Subject: [PATCH 20/75] Multiple bugs correction for Reed-Solomon --- grub-core/Makefile.am | 2 +- grub-core/kern/i386/pc/startup.S | 10 +++++----- grub-core/lib/reed_solomon.c | 28 +++++++++++++++++++--------- include/grub/offsets.h | 4 ++-- util/grub-setup.c | 2 +- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 307467f44..a740cb5cb 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -50,7 +50,7 @@ grub_script.yy.h: script/yylex.l grub_script.yy.c: grub_script.yy.h rs_decoder.S: $(srcdir)/lib/reed_solomon.c - $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 CLEANFILES += grub_script.yy.c grub_script.yy.h diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 283fc4f49..9319df98e 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -206,16 +206,16 @@ LOCAL (codestart): incl %eax call grub_gate_a20 - movl EXT_C(grub_kernel_image_size), %eax - addl EXT_C(grub_total_module_size), %eax + movl EXT_C(grub_compressed_size), %edx + addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx movl reed_solomon_redundancy, %ecx - leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %edx - testl %eax, %eax + leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax + testl %edx, %edx jz post_reed_solomon call EXT_C (grub_reed_solomon_recover) jmp post_reed_solomon -#include "/home/phcoder/compile/grub-core/rs_decoder.S" +#include .text diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 290eb9482..f87ff1552 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -55,10 +55,12 @@ typedef grub_uint8_t gf_single_t; typedef grub_uint16_t gf_double_t; #define GF_POLYNOMIAL 0x1d #define GF_INVERT2 0x8e -#ifdef STANDALONE -static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100000; +#if defined (STANDALONE) && !defined (TEST) +static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000; +static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100; #else static char *scratch; +static grub_uint8_t gf_invert[256]; #endif #define SECTOR_SIZE 512 @@ -85,8 +87,6 @@ gf_mul (gf_single_t a, gf_single_t b) return gf_reduce (res); } -static grub_uint8_t gf_invert[256]; - static void init_inverts (void) { @@ -113,7 +113,7 @@ pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x) return s; } -#if !defined (STANDALONE) || defined (TEST) +#if !defined (STANDALONE) static void rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) { @@ -382,7 +382,7 @@ decode_block (gf_single_t *ptr, grub_size_t s, } } -#if !defined (STANDALONE) || defined (TEST) +#if !defined (STANDALONE) static void encode_block (gf_single_t *ptr, grub_size_t s, gf_single_t *rptr, grub_size_t rs) @@ -402,7 +402,7 @@ encode_block (gf_single_t *ptr, grub_size_t s, } #endif -#if !defined (STANDALONE) || defined (TEST) +#if !defined (STANDALONE) void grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, grub_size_t redundancy) @@ -412,6 +412,8 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, gf_single_t *ptr = buffer; gf_single_t *rptr = ptr + s; + grub_printf ("solomon: %p, %x, %x\n", buffer, data_size, redundancy); + while (s > 0) { grub_size_t tt; @@ -439,7 +441,7 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) gf_single_t *ptr = ptr_; gf_single_t *rptr = ptr + s; -#if defined (STANDALONE) && !defined (TEST) +#if defined (STANDALONE) init_inverts (); #endif @@ -475,7 +477,9 @@ main (int argc, char **argv) scratch = xmalloc (1048576); #endif +#ifndef STANDALONE init_inverts (); +#endif in = fopen ("tst.bin", "rb"); if (!in) @@ -487,6 +491,10 @@ main (int argc, char **argv) buf = xmalloc (s + rs + SECTOR_SIZE); fread (buf, 1, s, in); + s = 0x5fbb; + rs = 0x6af9; + +#if 0 grub_reed_solomon_add_redundancy (buf, s, rs); out = fopen ("tst_rs.bin", "wb"); @@ -498,7 +506,9 @@ main (int argc, char **argv) out = fopen ("tst_dam.bin", "wb"); fwrite (buf, 1, s + rs, out); fclose (out); - +#endif + s = 0x5fbb; + rs = 0x6af9; grub_reed_solomon_recover (buf, s, rs); out = fopen ("tst_rec.bin", "wb"); diff --git a/include/grub/offsets.h b/include/grub/offsets.h index b8fbe40d4..28db0115c 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -41,9 +41,9 @@ #define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20 /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc6c +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc80 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x748 +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x75c /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE diff --git a/util/grub-setup.c b/util/grub-setup.c index 1518bb0a8..953f0038b 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -438,7 +438,7 @@ setup (const char *dir, 0, GRUB_DISK_SECTOR_SIZE); block = first_block; - for (i = 1; i < core_sectors; i++) + for (i = 1; i < nsec; i++) save_blocklists (sectors[i] + grub_partition_get_start (container), 0, GRUB_DISK_SECTOR_SIZE); From 25e09515ad227965a31fde020aa406afdb0c4492 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Sep 2010 21:42:13 +0200 Subject: [PATCH 21/75] Make mb header to protected part --- grub-core/kern/i386/pc/startup.S | 106 +++++++++++++++---------------- include/grub/offsets.h | 4 +- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 9319df98e..c4abc31b8 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -109,7 +109,58 @@ bss_start: bss_end: .long 0 #endif +/* + * This is the area for all of the special variables. + */ +VARIABLE(grub_boot_drive) + .byte 0 + +/* the real mode code continues... */ +LOCAL (codestart): + cli /* we're not safe here! */ + + /* set up %ds, %ss, and %es */ + xorw %ax, %ax + movw %ax, %ds + movw %ax, %ss + movw %ax, %es + + /* set up the real mode/BIOS stack */ + movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp + movl %ebp, %esp + + sti /* we're safe again */ + + /* save the boot drive */ + ADDR32 movb %dl, EXT_C(grub_boot_drive) + + /* reset disk system (%ah = 0) */ + int $0x13 + + /* transition to protected mode */ + DATA32 call real_to_prot + + /* The ".code32" directive takes GAS out of 16-bit mode. */ + .code32 + + incl %eax + call grub_gate_a20 + + movl EXT_C(grub_compressed_size), %edx + addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx + movl reed_solomon_redundancy, %ecx + leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax + testl %edx, %edx + jz post_reed_solomon + call EXT_C (grub_reed_solomon_recover) + jmp post_reed_solomon + +#include + + .text + + . = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). * This uses the a.out kludge to load raw binary to the area starting at 1MB, @@ -173,53 +224,7 @@ multiboot_trampoline: movb $0xFF, %dh /* enter the usual booting */ call prot_to_real - .code16 -/* the real mode code continues... */ -LOCAL (codestart): - cli /* we're not safe here! */ - - /* set up %ds, %ss, and %es */ - xorw %ax, %ax - movw %ax, %ds - movw %ax, %ss - movw %ax, %es - - /* set up the real mode/BIOS stack */ - movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp - movl %ebp, %esp - - sti /* we're safe again */ - - /* save the boot drive */ - ADDR32 movb %dl, EXT_C(grub_boot_drive) - - /* reset disk system (%ah = 0) */ - int $0x13 - - /* transition to protected mode */ - DATA32 call real_to_prot - - /* The ".code32" directive takes GAS out of 16-bit mode. */ - .code32 - - incl %eax - call grub_gate_a20 - - movl EXT_C(grub_compressed_size), %edx - addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx - movl reed_solomon_redundancy, %ecx - leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax - testl %edx, %edx - jz post_reed_solomon - call EXT_C (grub_reed_solomon_recover) - jmp post_reed_solomon - -#include - - .text - - . = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART post_reed_solomon: #ifdef ENABLE_LZMA @@ -289,15 +294,6 @@ post_reed_solomon: */ call EXT_C(grub_main) -/* - * This is the area for all of the special variables. - */ - -VARIABLE(grub_boot_drive) - .byte 0 - - .p2align 2 /* force 4-byte alignment */ - #include "../realmode.S" /* diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 28db0115c..f11dffaca 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -41,9 +41,9 @@ #define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20 /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc80 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc90 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x75c +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x6f8 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE From 53c9e7798cd9c70bc7b04220fa514013dfc28a6b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Sep 2010 21:42:36 +0200 Subject: [PATCH 22/75] Remove debug printf --- grub-core/lib/reed_solomon.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index f87ff1552..4c6e160e4 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -412,8 +412,6 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, gf_single_t *ptr = buffer; gf_single_t *rptr = ptr + s; - grub_printf ("solomon: %p, %x, %x\n", buffer, data_size, redundancy); - while (s > 0) { grub_size_t tt; From 40ca6b29fdcf97422cb8c882b5a9cffce87b2107 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Sep 2010 21:43:04 +0200 Subject: [PATCH 23/75] Fix missing mreparm=3 --- grub-core/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index a740cb5cb..294888909 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -50,7 +50,7 @@ grub_script.yy.h: script/yylex.l grub_script.yy.c: grub_script.yy.h rs_decoder.S: $(srcdir)/lib/reed_solomon.c - $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 CLEANFILES += grub_script.yy.c grub_script.yy.h From 4e2b20a79afe61df9901e943a453624f2453018f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Sep 2010 13:37:08 +0200 Subject: [PATCH 24/75] Add missing dependency on rs_Decoder.S --- grub-core/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 294888909..1881c5844 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -52,6 +52,8 @@ grub_script.yy.c: grub_script.yy.h rs_decoder.S: $(srcdir)/lib/reed_solomon.c $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 +kern/i386/pc/startup.S: $(builddir)/rs_decoder.S + CLEANFILES += grub_script.yy.c grub_script.yy.h include $(srcdir)/Makefile.core.am From f9130836402773d115acf026adbe36b3185d707d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 26 Sep 2010 15:53:05 +0200 Subject: [PATCH 25/75] 2010-09-26 Robert Millan Build fixes for GNU/kFreeBSD. * Makefile.util.def: Add `$(LIBZFS) $(LIBNVPAIR)' library dependencies to programs that require ZFS conversion. * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Support kernels that don't have FLOPPY_MAJOR. --- ChangeLog | 9 +++++++++ Makefile.util.def | 24 ++++++++++++------------ grub-core/kern/emu/hostdisk.c | 11 ++++++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bc9ac7c2..379549b95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-09-26 Robert Millan + + Build fixes for GNU/kFreeBSD. + + * Makefile.util.def: Add `$(LIBZFS) $(LIBNVPAIR)' library dependencies + to programs that require ZFS conversion. + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Support + kernels that don't have FLOPPY_MAJOR. + 2010-09-25 BVK Chaitanya * grub-core/kern/emu/full.c (grub_emu_post_init): Fix typo. diff --git a/Makefile.util.def b/Makefile.util.def index 42165df3d..21dda2df7 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -109,7 +109,7 @@ program = { ldadd = libgrub.a; ldadd = '$(LIBLZMA)'; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; cppflags = '-DGRUB_PKGLIBROOTDIR=\"$(pkglibrootdir)\"'; }; @@ -121,7 +121,7 @@ program = { common = util/grub-mkrelpath.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -132,7 +132,7 @@ program = { common = util/grub-script-check.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -143,7 +143,7 @@ program = { common = util/grub-editenv.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -154,7 +154,7 @@ program = { common = util/grub-mkpasswd-pbkdf2.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; cflags = '$(CFLAGS_GCRY)'; cppflags = '$(CPPFLAGS_GCRY)'; @@ -190,7 +190,7 @@ program = { cppflags = '$(CPPFLAGS_GCRY)'; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -203,7 +203,7 @@ program = { cflags = '$(freetype_cflags)'; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(freetype_libs)'; condition = COND_GRUB_MKFONT; @@ -222,7 +222,7 @@ program = { sparc64_ieee1275 = util/ieee1275/devicemap.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -233,7 +233,7 @@ program = { common = util/grub-probe.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -248,7 +248,7 @@ program = { sparc64_ieee1275 = util/ieee1275/ofpath.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; enable = i386_pc; @@ -274,7 +274,7 @@ program = { common = util/grub-mklayout.c; ldadd = libgrub.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; @@ -595,6 +595,6 @@ program = { common = grub-core/lib/i386/pc/vesa_modes_table.c; ldadd = libgrub.a; - ldflags = '$(LIBINTL) $(LIBDEVMAPPER)'; + ldflags = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; ldadd = grub-core/gnulib/libgnu.a; }; diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 19d3856a2..08f60ee66 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1,7 +1,7 @@ /* hostdisk.c - emulate biosdisk */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,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 @@ -1627,7 +1627,16 @@ grub_util_biosdisk_is_floppy (grub_disk_t disk) return 1; #endif +#if defined(FLOPPY_MAJOR) if (major(st.st_rdev) == FLOPPY_MAJOR) +#else + /* Some kernels (e.g. kFreeBSD) don't have a static major number + for floppies, but they still use a "fd[0-9]" pathname. */ + if (map[disk->id].device[5] == 'f' + && map[disk->id].device[6] == 'd' + && map[disk->id].device[7] >= '0' + && map[disk->id].device[7] <= '9') +#endif return 1; return 0; From 8e57a6ca44dca7bff5867e0576105b0ba82f2bdf Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 26 Sep 2010 16:11:33 +0200 Subject: [PATCH 26/75] 2010-09-26 Robert Millan Support degraded ZFS arrays in "grub-probe -t device" resolution. * grub-core/kern/emu/getroot.c (find_root_device_from_libzfs): When the pool is an array of devices, iterate through it and return the first device that passes a stat() test (instead of blindly returning the first one). --- ChangeLog | 9 +++++++++ grub-core/kern/emu/getroot.c | 31 ++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 379549b95..803cd3168 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-09-26 Robert Millan + + Support degraded ZFS arrays in "grub-probe -t device" resolution. + + * grub-core/kern/emu/getroot.c (find_root_device_from_libzfs): When + the pool is an array of devices, iterate through it and return the + first device that passes a stat() test (instead of blindly returning + the first one). + 2010-09-26 Robert Millan Build fixes for GNU/kFreeBSD. diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 003fe9333..0433d49ed 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -189,31 +189,40 @@ find_root_device_from_libzfs (const char *dir) { zpool_handle_t *zpool; libzfs_handle_t *libzfs; - nvlist_t *nvlist; - nvlist_t **nvlist_array; + nvlist_t *config, *vdev_tree; + nvlist_t **children, **path; unsigned int nvlist_count; + unsigned int i; libzfs = grub_get_libzfs_handle (); if (! libzfs) return NULL; zpool = zpool_open (libzfs, poolname); - nvlist = zpool_get_config (zpool, NULL); + config = zpool_get_config (zpool, NULL); - if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0) + if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) != 0) error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")"); - if (nvlist_lookup_nvlist_array (nvlist, "children", &nvlist_array, &nvlist_count) != 0) + if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0) error (1, errno, "nvlist_lookup_nvlist_array (\"children\")"); + assert (nvlist_count > 0); - do + while (nvlist_lookup_nvlist_array (children[0], "children", + &children, &nvlist_count) == 0) + assert (nvlist_count > 0); + + for (i = 0; i < nvlist_count; i++) { - assert (nvlist_count > 0); - } while (nvlist_lookup_nvlist_array (nvlist_array[0], "children", - &nvlist_array, &nvlist_count) == 0); + if (nvlist_lookup_string (children[i], "path", &device) != 0) + error (1, errno, "nvlist_lookup_string (\"path\")"); - if (nvlist_lookup_string (nvlist_array[0], "path", &device) != 0) - error (1, errno, "nvlist_lookup_string (\"path\")"); + struct stat st; + if (stat (device, &st) == 0) + break; + + device = NULL; + } zpool_close (zpool); } From f772623bc030fb29e0dca57c7176284902fd50a4 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Mon, 27 Sep 2010 11:11:38 +0200 Subject: [PATCH 27/75] Fix generation of kernel_syms.lst * grub-core/Makefile.am (kernel_syms.lst): Fix value and position of ASM_PREFIX --- ChangeLog | 7 +++++++ grub-core/Makefile.am | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 803cd3168..e428dcd53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-09-27 Yves Blusseau + + Fix generation of kernel_syms.lst + + * grub-core/Makefile.am (kernel_syms.lst): Fix value and position of + ASM_PREFIX + 2010-09-26 Robert Millan Support degraded ZFS arrays in "grub-probe -t device" resolution. diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index cff6b3782..0659d1c14 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -173,7 +173,7 @@ CLEANFILES += symlist.c BUILT_SOURCES += symlist.c if COND_HAVE_ASM_USCORE -ASM_PREFIX=1 +ASM_PREFIX=_ else ASM_PREFIX= endif @@ -183,8 +183,8 @@ noinst_DATA += kernel_syms.lst kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input cat kernel_syms.input | grep -v '^#' | sed -n \ - -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined '"$(ASM_PREFIX)"'kernel \1/;p;}' \ - -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined '"$(ASM_PREFIX)"' kernel \1/;p;}' \ + -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ | sort -u >$@ rm -f kernel_syms.input CLEANFILES += kernel_syms.lst From 0b4b227faecce80c0d8a5406c82df59c45bce754 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 28 Sep 2010 17:38:34 +0100 Subject: [PATCH 28/75] * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi): Fix i386 and x86-64 definedness tests. --- ChangeLog | 5 +++++ grub-core/loader/multiboot_mbi2.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e428dcd53..f33ddb6af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-28 Colin Watson + + * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi): Fix + i386 and x86-64 definedness tests. + 2010-09-27 Yves Blusseau Fix generation of kernel_syms.lst diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index a20c82cad..75eaec33d 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -705,7 +705,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } } -#if defined (GRUB_MACHINE_EFI) && __x86_64__ +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__) { struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi64 *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI64; @@ -715,7 +715,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } #endif -#if defined (GRUB_MACHINE_EFI) && __i386__ +#if defined (GRUB_MACHINE_EFI) && defined (__i386__) { struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi32 *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI32; From edde54e656a3219a6ad5e7118e0212d50af01697 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 22:45:57 +0200 Subject: [PATCH 29/75] * grub-core/boot/i386/pc/lnxboot.S: Replace GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE with GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART. --- ChangeLog | 6 ++++++ grub-core/boot/i386/pc/lnxboot.S | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fe48dc277..91049acdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-09-29 Vladimir Serbinenko + + * grub-core/boot/i386/pc/lnxboot.S: Replace + GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE with + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART. + 2010-09-29 Vladimir Serbinenko Write embedding zone using Reed-Solomon. diff --git a/grub-core/boot/i386/pc/lnxboot.S b/grub-core/boot/i386/pc/lnxboot.S index 9348553c3..9a599c261 100644 --- a/grub-core/boot/i386/pc/lnxboot.S +++ b/grub-core/boot/i386/pc/lnxboot.S @@ -185,7 +185,7 @@ real_code_2: call LOCAL(move_memory) /* Check for multiboot signature. */ - cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE) + cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART) jz 1f movl (ramdisk_image - start), %esi From 44a1b4327ad982dd040aba6f442d993c9e6e5503 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 22:48:38 +0200 Subject: [PATCH 30/75] * grub-core/lib/arg.c (grub_arg_parse): Fix treating of all commands as if they were BSD-style. --- ChangeLog | 5 +++++ grub-core/lib/arg.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 91049acdd..4e03814fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-29 Vladimir Serbinenko + + * grub-core/lib/arg.c (grub_arg_parse): Fix treating of all commands as + if they were BSD-style. + 2010-09-29 Vladimir Serbinenko * grub-core/boot/i386/pc/lnxboot.S: Replace diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c index dabf4e8ce..1c765f12a 100644 --- a/grub-core/lib/arg.c +++ b/grub-core/lib/arg.c @@ -260,7 +260,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, char *option = 0; /* No option is used. */ - if ((num && GRUB_COMMAND_OPTIONS_AT_START) + if ((num && (cmd->cmd->flags & GRUB_COMMAND_OPTIONS_AT_START)) || arg[0] != '-' || grub_strlen (arg) == 1) { if (add_arg (arg) != 0) From d33613fcf3e4d2076a8df6d6d5aa24927fc6fdd5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 22:51:12 +0200 Subject: [PATCH 31/75] * grub-core/loader/i386/bsd.c (grub_cmd_netbsd): Provide default serial parameters. --- ChangeLog | 5 +++++ grub-core/loader/i386/bsd.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4e03814fd..bd8b33b53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-29 Vladimir Serbinenko + + * grub-core/loader/i386/bsd.c (grub_cmd_netbsd): Provide default serial + parameters. + 2010-09-29 Vladimir Serbinenko * grub-core/lib/arg.c (grub_arg_parse): Fix treating of all commands as diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 456c5f36c..b7cf115d9 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -1559,6 +1559,9 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) grub_memset (&serial, 0, sizeof (serial)); grub_strcpy (serial.devname, "com"); + serial.addr = grub_ns8250_hw_get_port (0); + serial.speed = 9600; + if (ctxt->state[NETBSD_SERIAL_ARG].arg) { ptr = ctxt->state[NETBSD_SERIAL_ARG].arg; @@ -1581,7 +1584,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) return grub_errno; } } - + grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial)); } else From 2a4066114dc79c669ce2eb2f99809b4eaf7531bb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 23:19:21 +0200 Subject: [PATCH 32/75] * grub-core/lib/relocator.c (malloc_in_range): Trim too verbose debug messages. (grub_relocator_prepare_relocs): Set movers_chunk.srcv. --- ChangeLog | 6 ++++++ grub-core/lib/relocator.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd8b33b53..63c6e83ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-09-29 Vladimir Serbinenko + + * grub-core/lib/relocator.c (malloc_in_range): Trim too verbose + debug messages. + (grub_relocator_prepare_relocs): Set movers_chunk.srcv. + 2010-09-29 Vladimir Serbinenko * grub-core/loader/i386/bsd.c (grub_cmd_netbsd): Provide default serial diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 9a6941332..a0cab55af 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -586,8 +586,6 @@ malloc_in_range (struct grub_relocator *rel, continue; do { - grub_dprintf ("relocator", "free block %p+0x%lx\n", - p, (unsigned long) p->size); if (p->magic != GRUB_MM_FREE_MAGIC) grub_fatal (__FILE__":%d free magic broken at %p (0x%x)\n", __LINE__, p, p->magic); @@ -1504,7 +1502,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, grub_relocator_align, rel->relocators_size, &movers_chunk, 1, 1)) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory"); - rels = rels0 = grub_map_memory (movers_chunk.src, movers_chunk.size); + movers_chunk.srcv = rels = rels0 + = grub_map_memory (movers_chunk.src, movers_chunk.size); if (relsize) *relsize = rel->relocators_size; From 579940128bcd6feeffed7e261b21d6a75c010226 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 23:51:12 +0200 Subject: [PATCH 33/75] Fix coreboot compilation. * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_get_mbi_size): Take VBE info into account even if only text is supported. (fill_vbe_info): Take into account the case when only VGA text is supported. * include/grub/multiboot.h (GRUB_MACHINE_HAS_VBE): Set to zero on coreboot, multiboot and qemu. --- ChangeLog | 11 ++++++++++ grub-core/loader/i386/multiboot_mbi.c | 29 +++++++++++++++++++++------ include/grub/multiboot.h | 12 +++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63c6e83ee..4614a1cac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-09-29 Vladimir Serbinenko + + Fix coreboot compilation. + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_get_mbi_size): + Take VBE info into account even if only text is supported. + (fill_vbe_info): Take into account the case when only VGA text + is supported. + * include/grub/multiboot.h (GRUB_MACHINE_HAS_VBE): Set to zero + on coreboot, multiboot and qemu. + 2010-09-29 Vladimir Serbinenko * grub-core/lib/relocator.c (malloc_in_range): Trim too verbose diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 283b84c5a..79f72ee0f 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -187,6 +187,10 @@ grub_multiboot_load (grub_file_t file) return err; } +#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT +#include +#endif + static grub_size_t grub_multiboot_get_mbi_size (void) { @@ -196,7 +200,7 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry) + elf_sec_entsize * elf_sec_num + 256 * sizeof (struct multiboot_color) -#if GRUB_MACHINE_HAS_VBE +#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT + sizeof (struct grub_vbe_info_block) + sizeof (struct grub_vbe_mode_info_block) #endif @@ -247,15 +251,17 @@ grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) grub_mmap_iterate (hook); } -#if GRUB_MACHINE_HAS_VBE +#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT + static grub_err_t fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig, grub_uint32_t ptrdest, int fill_generic) { - grub_vbe_status_t status; grub_uint32_t vbe_mode; - void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; struct grub_vbe_mode_info_block *mode_info; +#if GRUB_MACHINE_HAS_VBE + grub_vbe_status_t status; + void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; status = grub_vbe_bios_get_controller_info (scratch); if (status != GRUB_VBE_STATUS_OK) @@ -265,11 +271,18 @@ fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig, grub_memcpy (ptrorig, scratch, sizeof (struct grub_vbe_info_block)); ptrorig += sizeof (struct grub_vbe_info_block); ptrdest += sizeof (struct grub_vbe_info_block); - +#else + mbi->vbe_control_info = 0; +#endif + +#if GRUB_MACHINE_HAS_VBE status = grub_vbe_bios_get_mode (scratch); vbe_mode = *(grub_uint32_t *) scratch; if (status != GRUB_VBE_STATUS_OK) return grub_error (GRUB_ERR_IO, "can't get VBE mode"); +#else + vbe_mode = 3; +#endif mbi->vbe_mode = vbe_mode; mode_info = (struct grub_vbe_mode_info_block *) ptrorig; @@ -284,18 +297,22 @@ fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig, } else { +#if GRUB_MACHINE_HAS_VBE status = grub_vbe_bios_get_mode_info (vbe_mode, scratch); if (status != GRUB_VBE_STATUS_OK) return grub_error (GRUB_ERR_IO, "can't get mode info"); grub_memcpy (mode_info, scratch, sizeof (struct grub_vbe_mode_info_block)); +#endif } ptrorig += sizeof (struct grub_vbe_mode_info_block); ptrdest += sizeof (struct grub_vbe_mode_info_block); - + +#if GRUB_MACHINE_HAS_VBE grub_vbe_bios_get_pm_interface (&mbi->vbe_interface_seg, &mbi->vbe_interface_off, &mbi->vbe_interface_len); +#endif mbi->flags |= MULTIBOOT_INFO_VBE_INFO; diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index 364dc3ca6..9a0b57359 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -53,15 +53,19 @@ grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize, grub_uint32_t grub_get_multiboot_mmap_count (void); grub_err_t grub_multiboot_set_video_mode (void); -#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU) -#include -#define GRUB_MACHINE_HAS_VGA_TEXT 1 +/* FIXME: support coreboot as well. */ +#if defined (GRUB_MACHINE_PCBIOS) #define GRUB_MACHINE_HAS_VBE 1 #else -#define GRUB_MACHINE_HAS_VGA_TEXT 0 #define GRUB_MACHINE_HAS_VBE 0 #endif +#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU) +#define GRUB_MACHINE_HAS_VGA_TEXT 1 +#else +#define GRUB_MACHINE_HAS_VGA_TEXT 0 +#endif + #if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) #define GRUB_MACHINE_HAS_ACPI 1 #else From aa438e6818359e01a62d092aafdf366499a1653e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Sep 2010 23:58:43 +0200 Subject: [PATCH 34/75] * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi] [GRUB_MACHINE_EFI && __i386__]: Fix typo. --- ChangeLog | 5 +++++ grub-core/loader/multiboot_mbi2.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4614a1cac..ec2db1936 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-29 Vladimir Serbinenko + + * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi] + [GRUB_MACHINE_EFI && __i386__]: Fix typo. + 2010-09-29 Vladimir Serbinenko Fix coreboot compilation. diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 75eaec33d..3141f0028 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -717,7 +717,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) #if defined (GRUB_MACHINE_EFI) && defined (__i386__) { - struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi32 *) ptrorig; + struct multiboot_tag_efi32 *tag = (struct multiboot_tag_efi32 *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_EFI32; tag->size = sizeof (*tag); tag->pointer = (grub_addr_t) grub_efi_system_table; From ee74fa4822da5ea1d757e5842a9875e57a6cc614 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 30 Sep 2010 17:50:01 +0200 Subject: [PATCH 35/75] Put terminfo into core on ieee1275 and yeeloong (needed for console). * gentpl.py: New groups terminfoinkernel and terminfomodule. * grub-core/Makefile.am (KERNEL_HEADER_FILES): Include extcmd.h, arg.h and terminfo.h when needed. * grub-core/Makefile.core.def (kernel): Include term/terminfo.c, term/tparm.c, commands/extcmd.c, lib/arg.c on terminfokernel. (terminfo): Enable only on terminfokernel. (extcmd): Likewise. * include/grub/extcmd.h: Add missing EXPORT_FUNC. * include/grub/lib/arg.h: Likewise. * grub-core/term/ieee1275/ofconsole.c (grub_ofconsole_dimensions): Fix incorrect usage of ->. --- ChangeLog | 16 ++++++++++++++ gentpl.py | 5 +++++ grub-core/Makefile.am | 11 ++++++++++ grub-core/Makefile.core.def | 12 +++++----- grub-core/term/ieee1275/ofconsole.c | 12 +++++----- include/grub/extcmd.h | 34 ++++++++++++++--------------- include/grub/lib/arg.h | 2 +- 7 files changed, 62 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec2db1936..197158f50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-09-30 Vladimir Serbinenko + + Put terminfo into core on ieee1275 and yeeloong (needed for console). + + * gentpl.py: New groups terminfoinkernel and terminfomodule. + * grub-core/Makefile.am (KERNEL_HEADER_FILES): Include extcmd.h, arg.h + and terminfo.h when needed. + * grub-core/Makefile.core.def (kernel): Include term/terminfo.c, + term/tparm.c, commands/extcmd.c, lib/arg.c on terminfokernel. + (terminfo): Enable only on terminfokernel. + (extcmd): Likewise. + * include/grub/extcmd.h: Add missing EXPORT_FUNC. + * include/grub/lib/arg.h: Likewise. + * grub-core/term/ieee1275/ofconsole.c (grub_ofconsole_dimensions): Fix + incorrect usage of ->. + 2010-09-29 Vladimir Serbinenko * grub-core/loader/multiboot_mbi2.c (grub_multiboot_make_mbi] diff --git a/gentpl.py b/gentpl.py index 109ce7981..a42a60667 100644 --- a/gentpl.py +++ b/gentpl.py @@ -38,6 +38,11 @@ GROUPS["videoinkernel"] = ["mips_yeeloong"] GROUPS["videomodules"] = GRUB_PLATFORMS[:]; for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) +# Similar for terminfo +GROUPS["terminfoinkernel"] = ["mips_yeeloong"] + GROUPS["ieee1275"]; +GROUPS["terminfomodule"] = GRUB_PLATFORMS[:]; +for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) + # Miscelaneous groups schedulded to disappear in future GROUPS["nosparc64"] = GRUB_PLATFORMS[:]; GROUPS["nosparc64"].remove("sparc64_ieee1275") GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"] diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index f08bb765c..9792dd974 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -113,6 +113,8 @@ endif if COND_i386_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif @@ -138,15 +140,24 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h endif if COND_powerpc_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h endif if COND_sparc64_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h endif if COND_emu diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 49628cb84..8845c26ea 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -92,10 +92,10 @@ kernel = { ieee1275 = kern/ieee1275/openfw.c; ieee1275 = term/ieee1275/ofconsole.c; - ieee1275 = term/terminfo.c; - ieee1275 = term/tparm.c; - mips = term/terminfo.c; - mips = term/tparm.c; + terminfoinkernel = term/terminfo.c; + terminfoinkernel = term/tparm.c; + terminfoinkernel = commands/extcmd.c; + terminfoinkernel = lib/arg.c; i386 = kern/i386/dl.c; @@ -173,9 +173,7 @@ kernel = { emu = kern/emu/mm.c; emu = kern/emu/time.c; - videoinkernel = lib/arg.c; videoinkernel = term/gfxterm.c; - videoinkernel = commands/extcmd.c; videoinkernel = font/font.c; videoinkernel = font/font_cmd.c; videoinkernel = io/bufio.c; @@ -542,6 +540,7 @@ module = { name = extcmd; common = commands/extcmd.c; common = lib/arg.c; + enable = terminfomodule; }; module = { @@ -1337,6 +1336,7 @@ module = { name = terminfo; common = term/terminfo.c; common = term/tparm.c; + enable = terminfomodule; }; module = { diff --git a/grub-core/term/ieee1275/ofconsole.c b/grub-core/term/ieee1275/ofconsole.c index 944056ba6..2b0bddbbb 100644 --- a/grub-core/term/ieee1275/ofconsole.c +++ b/grub-core/term/ieee1275/ofconsole.c @@ -90,7 +90,7 @@ grub_ofconsole_dimensions (void) if (! grub_ieee1275_get_property (options, "screen-#columns", val, lval, 0)) - grub_ofconsole_terminfo_output->width + grub_ofconsole_terminfo_output.width = (grub_uint8_t) grub_strtoul (val, 0, 10); } if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval) @@ -99,16 +99,16 @@ grub_ofconsole_dimensions (void) char val[lval]; if (! grub_ieee1275_get_property (options, "screen-#rows", val, lval, 0)) - grub_ofconsole_terminfo_output->height + grub_ofconsole_terminfo_output.height = (grub_uint8_t) grub_strtoul (val, 0, 10); } } /* Use a small console by default. */ - if (! grub_ofconsole_terminfo_output->width) - grub_ofconsole_terminfo_output->width = 80; - if (! grub_ofconsole_terminfo_output->height) - grub_ofconsole_terminfo_output->height = 24; + if (! grub_ofconsole_terminfo_output.width) + grub_ofconsole_terminfo_output.width = 80; + if (! grub_ofconsole_terminfo_output.height) + grub_ofconsole_terminfo_output.height = 24; } static void diff --git a/include/grub/extcmd.h b/include/grub/extcmd.h index c34a1df66..19fe59266 100644 --- a/include/grub/extcmd.h +++ b/include/grub/extcmd.h @@ -55,25 +55,25 @@ struct grub_extcmd_context }; typedef struct grub_extcmd_context *grub_extcmd_context_t; -grub_extcmd_t grub_register_extcmd (const char *name, - grub_extcmd_func_t func, - grub_command_flags_t flags, - const char *summary, - const char *description, - const struct grub_arg_option *parser); +grub_extcmd_t EXPORT_FUNC(grub_register_extcmd) (const char *name, + grub_extcmd_func_t func, + grub_command_flags_t flags, + const char *summary, + const char *description, + const struct grub_arg_option *parser); -grub_extcmd_t grub_register_extcmd_prio (const char *name, - grub_extcmd_func_t func, - grub_command_flags_t flags, - const char *summary, - const char *description, - const struct grub_arg_option *parser, - int prio); +grub_extcmd_t EXPORT_FUNC(grub_register_extcmd_prio) (const char *name, + grub_extcmd_func_t func, + grub_command_flags_t flags, + const char *summary, + const char *description, + const struct grub_arg_option *parser, + int prio); -void grub_unregister_extcmd (grub_extcmd_t cmd); +void EXPORT_FUNC(grub_unregister_extcmd) (grub_extcmd_t cmd); -grub_err_t -grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args, - struct grub_script *script); +grub_err_t EXPORT_FUNC(grub_extcmd_dispatcher) (struct grub_command *cmd, + int argc, char **args, + struct grub_script *script); #endif /* ! GRUB_EXTCMD_HEADER */ diff --git a/include/grub/lib/arg.h b/include/grub/lib/arg.h index 3bab27781..b61f6f30e 100644 --- a/include/grub/lib/arg.h +++ b/include/grub/lib/arg.h @@ -72,7 +72,7 @@ struct grub_extcmd; int grub_arg_parse (struct grub_extcmd *cmd, int argc, char **argv, struct grub_arg_list *usr, char ***args, int *argnum); -void grub_arg_show_help (struct grub_extcmd *cmd); +void EXPORT_FUNC(grub_arg_show_help) (struct grub_extcmd *cmd); struct grub_arg_list* grub_arg_list_alloc (struct grub_extcmd *cmd, int argc, char *argv[]); From 17821956e7cc616e7e4e2d4a44106f4b6fde8588 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 30 Sep 2010 19:27:28 +0200 Subject: [PATCH 36/75] * util/grub-setup.c (main) [GRUB_MACHINE_IEEE1275]: Propagate argp usage. --- ChangeLog | 5 +++++ util/grub-setup.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 197158f50..85fcbb02c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-30 Vladimir Serbinenko + + * util/grub-setup.c (main) [GRUB_MACHINE_IEEE1275]: Propagate argp + usage. + 2010-09-30 Vladimir Serbinenko Put terminfo into core on ieee1275 and yeeloong (needed for console). diff --git a/util/grub-setup.c b/util/grub-setup.c index 953f0038b..920d867f2 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -838,10 +838,6 @@ main (int argc, char *argv[]) int must_embed = 0; struct arguments arguments; -#ifdef GRUB_MACHINE_IEEE1275 - force = 1; -#endif - set_program_name (argv[0]); grub_util_init_nls (); @@ -857,6 +853,10 @@ main (int argc, char *argv[]) exit(1); } +#ifdef GRUB_MACHINE_IEEE1275 + arguments.force = 1; +#endif + if (verbosity > 1) grub_env_set ("debug", "all"); From 74ccb5b5e2bb29a037bcdc4b3b1fbd89b26b57d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 30 Sep 2010 20:59:20 +0200 Subject: [PATCH 37/75] * grub-core/script/execute.c (grub_script_execute_sourcecode): Set flags. --- ChangeLog | 5 +++++ grub-core/script/execute.c | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 85fcbb02c..b89679741 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-30 Vladimir Serbinenko + + * grub-core/script/execute.c (grub_script_execute_sourcecode): Set + flags. + 2010-09-30 Vladimir Serbinenko * util/grub-setup.c (main) [GRUB_MACHINE_IEEE1275]: Propagate argp diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index 2cadb0e1b..d859a13bd 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -513,6 +513,7 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args) new_scope.argv.argc = argc; new_scope.argv.args = args; + new_scope.flags = 0; old_scope = scope; scope = &new_scope; From e6d983ba6d26a9f48707fad5e872375e81392887 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 30 Sep 2010 21:04:09 +0200 Subject: [PATCH 38/75] * grub-core/normal/term.c (read_terminal_list): Free in a right order. --- ChangeLog | 4 ++++ grub-core/normal/term.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b89679741..c223a869c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-09-30 Vladimir Serbinenko + + * grub-core/normal/term.c (read_terminal_list): Free in a right order. + 2010-09-30 Vladimir Serbinenko * grub-core/script/execute.c (grub_script_execute_sourcecode): Set diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index fe6240eb0..00721c447 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -376,8 +376,8 @@ read_terminal_list (const char *prefix) if (! cur->modname) { grub_errno = GRUB_ERR_NONE; - grub_free (cur); grub_free (cur->name); + grub_free (cur); continue; } cur->next = *target; From 6e3c515d5bf4480a38f0b6bb336f4e71a51af347 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 30 Sep 2010 21:07:51 +0200 Subject: [PATCH 39/75] * grub-core/gettext/gettext.c (grub_gettext_init_ext): Avoid using mo_file after freeing. --- ChangeLog | 5 +++++ grub-core/gettext/gettext.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c223a869c..0f0b65827 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-09-30 Vladimir Serbinenko + + * grub-core/gettext/gettext.c (grub_gettext_init_ext): Avoid using + mo_file after freeing. + 2010-09-30 Vladimir Serbinenko * grub-core/normal/term.c (read_terminal_list): Free in a right order. diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 2f94ac030..9ab4c3b8d 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -287,8 +287,10 @@ grub_gettext_init_ext (const char *lang) /* Will try adding .gz as well. */ if (fd_mo == NULL) { - grub_free (mo_file); + char *mo_file_old; + mo_file_old = mo_file; mo_file = grub_xasprintf ("%s.gz", mo_file); + grub_free (mo_file_old); if (!mo_file) return; fd_mo = grub_mofile_open (mo_file); From bf26bcc435756008603a7c5bf9a6d3d847a2b731 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 1 Oct 2010 16:24:43 +0200 Subject: [PATCH 40/75] * grub-core/loader/i386/linux.c (DEFAULT_VIDEO_MODE) [GRUB_MACHINE_EFI]: Set to "auto". --- ChangeLog | 5 +++++ grub-core/loader/i386/linux.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0f0b65827..3ed524a4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-01 Vladimir Serbinenko + + * grub-core/loader/i386/linux.c (DEFAULT_VIDEO_MODE) [GRUB_MACHINE_EFI]: + Set to "auto". + 2010-09-30 Vladimir Serbinenko * grub-core/gettext/gettext.c (grub_gettext_init_ext): Avoid using diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 4a6b7eafa..d7622dabd 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -41,7 +41,7 @@ #ifdef GRUB_MACHINE_EFI #include #define HAS_VGA_TEXT 0 -#define DEFAULT_VIDEO_MODE "800x600" +#define DEFAULT_VIDEO_MODE "auto" #elif defined (GRUB_MACHINE_IEEE1275) #include #define HAS_VGA_TEXT 0 From 441cfe65c0b6ea1015a457d61563a8a255725fc2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 1 Oct 2010 16:54:38 +0200 Subject: [PATCH 41/75] Clear out 0x80 color bit on EFI. Tested by: decoder Reported by: decoder and meta tech. * grub-core/term/efi/console.c (grub_console_standard_color): Removed. (grub_console_setcolorstate): Clear out 0x80 bit. Use GRUB_TERM_DEFAULT_STANDARD_COLOR. (grub_console_output): Use GRUB_TERM_DEFAULT_NORMAL_COLOR. Use GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR. --- ChangeLog | 12 ++++++++++++ grub-core/term/efi/console.c | 17 ++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ed524a4c..9b36f3426 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-10-01 Vladimir Serbinenko + + Clear out 0x80 color bit on EFI. + Tested by: decoder + Reported by: decoder and meta tech. + + * grub-core/term/efi/console.c (grub_console_standard_color): Removed. + (grub_console_setcolorstate): Clear out 0x80 bit. + Use GRUB_TERM_DEFAULT_STANDARD_COLOR. + (grub_console_output): Use GRUB_TERM_DEFAULT_NORMAL_COLOR. + Use GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR. + 2010-10-01 Vladimir Serbinenko * grub-core/loader/i386/linux.c (DEFAULT_VIDEO_MODE) [GRUB_MACHINE_EFI]: diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c index 4872a9a3f..8fd89b093 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -24,10 +24,6 @@ #include #include -static const grub_uint8_t -grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW, - GRUB_EFI_BACKGROUND_BLACK); - static grub_uint32_t map_char (grub_uint32_t c) { @@ -208,13 +204,14 @@ grub_console_setcolorstate (struct grub_term_output *term, switch (state) { case GRUB_TERM_COLOR_STANDARD: - efi_call_2 (o->set_attributes, o, grub_console_standard_color); + efi_call_2 (o->set_attributes, o, GRUB_TERM_DEFAULT_STANDARD_COLOR + & 0x7f); break; case GRUB_TERM_COLOR_NORMAL: - efi_call_2 (o->set_attributes, o, term->normal_color); + efi_call_2 (o->set_attributes, o, term->normal_color & 0x7f); break; case GRUB_TERM_COLOR_HIGHLIGHT: - efi_call_2 (o->set_attributes, o, term->highlight_color); + efi_call_2 (o->set_attributes, o, term->highlight_color & 0x7f); break; default: break; @@ -266,10 +263,8 @@ static struct grub_term_output grub_console_term_output = .cls = grub_console_cls, .setcolorstate = grub_console_setcolorstate, .setcursor = grub_console_setcursor, - .normal_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_LIGHTGRAY, - GRUB_EFI_BACKGROUND_BLACK), - .highlight_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_BLACK, - GRUB_EFI_BACKGROUND_LIGHTGRAY), + .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR, + .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR, .flags = GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS }; From a94551944e90b5c0b6d8c1e6ef5061e2db834a64 Mon Sep 17 00:00:00 2001 From: starous Date: Sat, 2 Oct 2010 20:49:05 +0200 Subject: [PATCH 42/75] usbtrans.c - wrong max packet size for bulk transfer --- ChangeLog | 7 +++++++ grub-core/bus/usb/ohci.c | 2 +- grub-core/bus/usb/uhci.c | 11 ++++++----- grub-core/bus/usb/usbtrans.c | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b36f3426..326ce1a44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-10-02 AleÅ¡ Nesrsta + + * grub-core/bus/usb/ohci.c, grub-core/bus/usb/uhci.c: + Increased number of TDs. + * grub-core/bus/usb/usbtrans.c (grub_usb_bulk_setup_readwrite): + Corrected endpoint maxpacket size. + 2010-10-01 Vladimir Serbinenko Clear out 0x80 color bit on EFI. diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index bf5aaa7c0..3c3ce4b89 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -150,7 +150,7 @@ typedef enum #define GRUB_OHCI_RESET_CONNECT_CHANGE (1 << 16) #define GRUB_OHCI_CTRL_EDS 256 #define GRUB_OHCI_BULK_EDS 510 -#define GRUB_OHCI_TDS 256 +#define GRUB_OHCI_TDS 640 #define GRUB_OHCI_ED_ADDR_MASK 0x7ff diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 711d87d86..d082beac4 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -29,6 +29,7 @@ #define GRUB_UHCI_IOMASK (0x7FF << 5) #define N_QH 256 +#define N_TD 640 typedef enum { @@ -105,7 +106,7 @@ struct grub_uhci /* N_QH Queue Heads. */ grub_uhci_qh_t qh; - /* 256 Transfer Descriptors. */ + /* N_TD Transfer Descriptors. */ grub_uhci_td_t td; /* Free Transfer Descriptors. */ @@ -213,7 +214,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev, /* The QH pointer of UHCI is only 32 bits, make sure this code works on on 64 bits architectures. */ - u->qh = (grub_uhci_qh_t) grub_memalign (4096, 4096); + u->qh = (grub_uhci_qh_t) grub_memalign (4096, sizeof(struct grub_uhci_qh)*N_QH); if (! u->qh) goto fail; @@ -227,7 +228,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev, /* The TD pointer of UHCI is only 32 bits, make sure this code works on on 64 bits architectures. */ - u->td = (grub_uhci_td_t) grub_memalign (4096, 4096*2); + u->td = (grub_uhci_td_t) grub_memalign (4096, sizeof(struct grub_uhci_td)*N_TD); if (! u->td) goto fail; @@ -244,9 +245,9 @@ grub_uhci_pci_iter (grub_pci_device_t dev, /* Link all Transfer Descriptors in a list of available Transfer Descriptors. */ - for (i = 0; i < 256; i++) + for (i = 0; i < N_TD; i++) u->td[i].linkptr = (grub_uint32_t) (grub_addr_t) &u->td[i + 1]; - u->td[255 - 1].linkptr = 0; + u->td[N_TD - 2].linkptr = 0; u->tdfree = u->td; /* Make sure UHCI is disabled! */ diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c index afd2eb0a5..ebb8a2eb6 100644 --- a/grub-core/bus/usb/usbtrans.c +++ b/grub-core/bus/usb/usbtrans.c @@ -228,7 +228,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev, if (dev->initialized) { struct grub_usb_desc_endp *endpdesc; - endpdesc = grub_usb_get_endpdescriptor (dev, 0); + endpdesc = grub_usb_get_endpdescriptor (dev, endpoint); if (endpdesc) max = endpdesc->maxpacket; From 3ef068df41e64e3922e9adab0653325d44357dcc Mon Sep 17 00:00:00 2001 From: starous Date: Sat, 2 Oct 2010 20:55:10 +0200 Subject: [PATCH 43/75] SCSI - cache ID bug --- ChangeLog | 5 +++++ include/grub/scsi.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 326ce1a44..cc3c87445 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-02 AleÅ¡ Nesrsta + + * include/grub/scsi.h: + SCSI - cache ID bug + 2010-10-02 AleÅ¡ Nesrsta * grub-core/bus/usb/ohci.c, grub-core/bus/usb/uhci.c: diff --git a/include/grub/scsi.h b/include/grub/scsi.h index b3c60f3e8..b30d317c7 100644 --- a/include/grub/scsi.h +++ b/include/grub/scsi.h @@ -40,7 +40,7 @@ static inline grub_uint32_t grub_make_scsi_id (int subsystem, int bus, int lun) { return (subsystem << GRUB_SCSI_ID_SUBSYSTEM_SHIFT) - | (bus << GRUB_SCSI_ID_BUS_SHIFT) | (lun << GRUB_SCSI_ID_BUS_SHIFT); + | (bus << GRUB_SCSI_ID_BUS_SHIFT) | (lun << GRUB_SCSI_ID_LUN_SHIFT); } struct grub_scsi_dev From c7980ad945126e44fb1adce9a6f2624c3aef23ca Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Oct 2010 19:42:51 +0200 Subject: [PATCH 44/75] Correct 2 last Changelog entries --- ChangeLog | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc3c87445..61810897b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,15 @@ 2010-10-02 AleÅ¡ Nesrsta - * include/grub/scsi.h: - SCSI - cache ID bug + * include/grub/scsi.h (grub_make_scsi_id): Fix incorrect usgae of + GRUB_SCSI_ID_BUS_SHIFT instead of GRUB_SCSI_ID_LUN_SHIFT. 2010-10-02 AleÅ¡ Nesrsta - * grub-core/bus/usb/ohci.c, grub-core/bus/usb/uhci.c: - Increased number of TDs. + * grub-core/bus/usb/ohci.c (GRUB_OHCI_TDS): Increase. + * grub-core/bus/usb/uhci.c (N_TD): New definition. All previous implicit + users updated. * grub-core/bus/usb/usbtrans.c (grub_usb_bulk_setup_readwrite): - Corrected endpoint maxpacket size. + Use right endpoint when querying descriptor. 2010-10-01 Vladimir Serbinenko From 74baff844e41ab6eb8391ba2d02194901e0146a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Oct 2010 19:46:20 +0200 Subject: [PATCH 45/75] * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Fix incorrect handling of special keys. --- ChangeLog | 5 +++++ grub-core/kern/i386/pc/startup.S | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61810897b..09b5d5c29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-09 Vladimir Serbinenko + + * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Fix incorrect + handling of special keys. + 2010-10-02 AleÅ¡ Nesrsta * include/grub/scsi.h (grub_make_scsi_id): Fix incorrect usgae of diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index c4abc31b8..31bd86c65 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -615,6 +615,7 @@ LOCAL(bypass_table_end): FUNCTION(grub_console_getkey) pushl %ebp + pushl %edi call prot_to_real .code16 @@ -644,15 +645,16 @@ FUNCTION(grub_console_getkey) jz 1f andl %edx, %eax - cmp %eax, 0x20 + cmpl $0x20, %eax ja 2f movl %edx, %eax - leal LOCAL(bypass_table), %esi + leal LOCAL(bypass_table), %edi movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx - repne cmpsw + repne scasw jz 3f - addl $('a' - 1 | GRUB_TERM_CTRL), %eax + andl $0xff, %eax + addl $(('a' - 1) | GRUB_TERM_CTRL), %eax jmp 2f 3: andl $0xff, %eax @@ -661,7 +663,8 @@ FUNCTION(grub_console_getkey) 1: movl %edx, %eax shrl $8, %eax orl $GRUB_TERM_EXTENDED, %eax -2: +2: + popl %edi popl %ebp ret From 20c6bb7e9ed66d6d0e7b63999eec5b804d48983a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Oct 2010 23:27:27 +0200 Subject: [PATCH 46/75] Correctly distinguish mdraid flavours. * grub-core/disk/raid.c (grub_raid_getname) [GRUB_UTIL]: New function. (insert_array): New argument raid. * include/grub/disk.h (grub_disk_dev) [GRUB_UTIL]: New member raidname. * include/grub/raid.h (grub_raid_array) [GRUB_UTIL]: New member driver. * util/grub-probe.c (probe): PRint raidname instead of plainly "mdraid". --- ChangeLog | 10 ++++++++++ grub-core/disk/raid.c | 18 ++++++++++++++++-- include/grub/disk.h | 1 + include/grub/raid.h | 4 ++++ util/grub-probe.c | 3 ++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09b5d5c29..79030343b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-10-08 Vladimir Serbinenko + + Correctly distinguish mdraid flavours. + + * grub-core/disk/raid.c (grub_raid_getname) [GRUB_UTIL]: New function. + (insert_array): New argument raid. + * include/grub/disk.h (grub_disk_dev) [GRUB_UTIL]: New member raidname. + * include/grub/raid.h (grub_raid_array) [GRUB_UTIL]: New member driver. + * util/grub-probe.c (probe): PRint raidname instead of plainly "mdraid". + 2010-10-09 Vladimir Serbinenko * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Fix incorrect diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 2fd6aa9de..c7c641ebd 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -107,6 +107,14 @@ grub_raid_memberlist (grub_disk_t disk) return list; } + +static const char * +grub_raid_getname (struct grub_disk *disk) +{ + struct grub_raid_array *array = disk->data; + + return array->driver->name; +} #endif static grub_err_t @@ -476,7 +484,8 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)), static grub_err_t insert_array (grub_disk_t disk, struct grub_raid_array *new_array, - grub_disk_addr_t start_sector, const char *scanner_name) + grub_disk_addr_t start_sector, const char *scanner_name, + grub_raid_t raid __attribute__ ((unused))) { struct grub_raid_array *array = 0, *p; @@ -524,6 +533,9 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, *array = *new_array; array->nr_devs = 0; +#ifdef GRUB_UTIL + array->driver = raid; +#endif grub_memset (&array->device, 0, sizeof (array->device)); grub_memset (&array->start_sector, 0, sizeof (array->start_sector)); @@ -662,7 +674,8 @@ grub_raid_register (grub_raid_t raid) if ((disk->total_sectors != GRUB_ULONG_MAX) && (! grub_raid_list->detect (disk, &array, &start_sector)) && - (! insert_array (disk, &array, start_sector, grub_raid_list->name))) + (! insert_array (disk, &array, start_sector, grub_raid_list->name, + grub_raid_list))) return 0; /* This error usually means it's not raid, no need to display @@ -706,6 +719,7 @@ static struct grub_disk_dev grub_raid_dev = .write = grub_raid_write, #ifdef GRUB_UTIL .memberlist = grub_raid_memberlist, + .raidname = grub_raid_getname, #endif .next = 0 }; diff --git a/include/grub/disk.h b/include/grub/disk.h index 9c5653e00..66db1149a 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -78,6 +78,7 @@ struct grub_disk_dev #ifdef GRUB_UTIL struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk); + const char * (*raidname) (struct grub_disk *disk); #endif /* The next disk device. */ diff --git a/include/grub/raid.h b/include/grub/raid.h index 711a7f79c..b7e18b567 100644 --- a/include/grub/raid.h +++ b/include/grub/raid.h @@ -54,6 +54,10 @@ struct grub_raid_array grub_disk_addr_t start_sector[GRUB_RAID_MAX_DEVICES]; /* Start of each device, in 512 byte sectors. */ struct grub_raid_array *next; + +#ifdef GRUB_UTIL + struct grub_raid *driver; +#endif }; struct grub_raid diff --git a/util/grub-probe.c b/util/grub-probe.c index b92d301f0..1d00a7db3 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -175,7 +175,8 @@ probe (const char *path, char *device_name) printf ("raid5rec "); if (is_raid6) printf ("raid6rec "); - printf ("mdraid "); + if (dev->disk->dev->raidname) + printf ("%s ", dev->disk->dev->raidname (dev->disk)); } if (is_lvm) From 219b35646a0c71fe95d8997a79c474b1ab96bf87 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Tue, 12 Oct 2010 14:47:04 +0200 Subject: [PATCH 47/75] 2010-10-12 Robert Millan * util/grub-mkconfig.in: Merge `GRUB_DISABLE_LINUX_RECOVERY' and `GRUB_DISABLE_NETBSD_RECOVERY' into a single `GRUB_DISABLE_RECOVERY' variable. All references updated. * util/grub.d/10_kfreebsd.in: Support recovery boot entries. --- ChangeLog | 8 ++++++++ docs/grub.texi | 10 +++------- util/grub-mkconfig.in | 3 +-- util/grub.d/10_kfreebsd.in | 17 ++++++++++++----- util/grub.d/10_linux.in | 2 +- util/grub.d/10_netbsd.in | 2 +- util/grub.d/20_linux_xen.in | 2 +- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79030343b..b0b3f83b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-10-12 Robert Millan + + * util/grub-mkconfig.in: Merge `GRUB_DISABLE_LINUX_RECOVERY' and + `GRUB_DISABLE_NETBSD_RECOVERY' into a single `GRUB_DISABLE_RECOVERY' + variable. All references updated. + + * util/grub.d/10_kfreebsd.in: Support recovery boot entries. + 2010-10-08 Vladimir Serbinenko Correctly distinguish mdraid flavours. diff --git a/docs/grub.texi b/docs/grub.texi index 3a72bbacb..4995b1df7 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1073,7 +1073,7 @@ A command to configure the serial port when using the serial console. Command-line arguments to add to menu entries for the Linux kernel. @item GRUB_CMDLINE_LINUX_DEFAULT -Unless @samp{GRUB_DISABLE_LINUX_RECOVERY} is set to @samp{true}, two menu +Unless @samp{GRUB_DISABLE_RECOVERY} is set to @samp{true}, two menu entries will be generated for each Linux kernel: one default entry and one entry for recovery mode. This option lists command-line arguments to add only to the default menu entry, after those listed in @@ -1096,13 +1096,9 @@ the Linux kernel, using a @samp{root=UUID=...} kernel parameter. This is usually more reliable, but in some cases it may not be appropriate. To disable the use of UUIDs, set this option to @samp{true}. -@item GRUB_DISABLE_LINUX_RECOVERY +@item GRUB_DISABLE_RECOVERY If this option is set to @samp{true}, disable the generation of recovery -mode menu entries for Linux. - -@item GRUB_DISABLE_NETBSD_RECOVERY -If this option is set to @samp{true}, disable the generation of recovery -mode menu entries for NetBSD. +mode menu entries. @item GRUB_VIDEO_BACKEND If graphical video support is required, either because the @samp{gfxterm} diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 4a06e19bc..b59911cd0 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -257,8 +257,7 @@ export GRUB_DEFAULT \ GRUB_TERMINAL_OUTPUT \ GRUB_SERIAL_COMMAND \ GRUB_DISABLE_LINUX_UUID \ - GRUB_DISABLE_LINUX_RECOVERY \ - GRUB_DISABLE_NETBSD_RECOVERY \ + GRUB_DISABLE_RECOVERY \ GRUB_VIDEO_BACKEND \ GRUB_GFXMODE \ GRUB_BACKGROUND \ diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 591fbc4b1..4d71b5a63 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -68,9 +68,13 @@ kfreebsd_entry () { os="$1" version="$2" - recovery="$3" # not used yet - args="$4" # not used yet - title="$(gettext_quoted "%s, with kFreeBSD %s")" + recovery="$3" + args="$4" + if ${recovery} ; then + title="$(gettext_quoted "%s, with kFreeBSD %s (recovery mode)")" + else + title="$(gettext_quoted "%s, with kFreeBSD %s")" + fi printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" save_default_entry | sed -e "s/^/\t/" if [ -z "${prepare_boot_cache}" ]; then @@ -80,7 +84,7 @@ kfreebsd_entry () printf '%s\n' "${prepare_boot_cache}" cat << EOF echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})' - kfreebsd ${rel_dirname}/${basename} + kfreebsd ${rel_dirname}/${basename} ${args} EOF if test -n "${devices}" ; then @@ -172,7 +176,10 @@ while [ "x$list" != "x" ] ; do module_dir_rel=$(make_system_path_relative_to_its_root $module_dir) fi - kfreebsd_entry "${OS}" "${version}" + kfreebsd_entry "${OS}" "${version}" false + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then + kfreebsd_entry "${OS}" "${version}" true "-s" + fi list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '` done diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 14b85c7f1..6cb6f0be7 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -136,7 +136,7 @@ while [ "x$list" != "x" ] ; do linux_entry "${OS}" "${version}" false \ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then linux_entry "${OS}" "${version}" true \ "single ${GRUB_CMDLINE_LINUX}" fi diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in index 1a8c4eb36..13f9d923a 100644 --- a/util/grub.d/10_netbsd.in +++ b/util/grub.d/10_netbsd.in @@ -80,7 +80,7 @@ for k in $(ls -t /netbsd*) ; do echo "Found NetBSD kernel: $k" >&2 netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}" netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}" - if [ "x${GRUB_DISABLE_NETBSD_RECOVERY}" != "xtrue" ]; then + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then netbsd_entry "knetbsd" "$k" true "-s" netbsd_entry "multiboot" "$k" true "-s" fi diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 5333d44ec..d5833070d 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -133,7 +133,7 @@ while [ "x${xen_list}" != "x" ] ; do linux_entry "${OS}" "${version}" "${xen_version}" false \ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}" - if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then linux_entry "${OS}" "${version}" "${xen_version}" true \ "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}" fi From d87c681fd4e2a60ead314b35f881e61bad7664c6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 14 Oct 2010 15:35:55 +0200 Subject: [PATCH 48/75] * grub-core/kern/i386/pc/startup.S (bypass_table): Use 0x1b explicitly rather than 0x1b. (grub_console_getkey): Use correct jae opcode rather than ja. --- ChangeLog | 6 ++++++ grub-core/kern/i386/pc/startup.S | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0b3f83b0..a0ae8b2a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-10-14 Vladimir Serbinenko + + * grub-core/kern/i386/pc/startup.S (bypass_table): Use 0x1b explicitly + rather than 0x1b. + (grub_console_getkey): Use correct jae opcode rather than ja. + 2010-10-12 Robert Millan * util/grub-mkconfig.in: Merge `GRUB_DISABLE_LINUX_RECOVERY' and diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 31bd86c65..e03fc8301 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -591,7 +591,7 @@ FUNCTION(grub_console_putchar) LOCAL(bypass_table): - .word 0x0100 | '\e',0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r' + .word 0x011b, 0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r' .word 0x1c00 | '\n' LOCAL(bypass_table_end): @@ -646,7 +646,7 @@ FUNCTION(grub_console_getkey) andl %edx, %eax cmpl $0x20, %eax - ja 2f + jae 2f movl %edx, %eax leal LOCAL(bypass_table), %edi movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx From d0f4c1ea0f281c1ac081f63da54270030668f37d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 14 Oct 2010 15:44:04 +0200 Subject: [PATCH 49/75] * grub-core/efiemu/main.c (grub_efiemu_prepare): Handle errors from grub_efiemu_autocore. --- ChangeLog | 5 +++++ grub-core/efiemu/main.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a0ae8b2a0..5553a991c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-14 Vladimir Serbinenko + + * grub-core/efiemu/main.c (grub_efiemu_prepare): Handle errors from + grub_efiemu_autocore. + 2010-10-14 Vladimir Serbinenko * grub-core/kern/i386/pc/startup.S (bypass_table): Use 0x1b explicitly diff --git a/grub-core/efiemu/main.c b/grub-core/efiemu/main.c index ee78afe7d..da813b00d 100644 --- a/grub-core/efiemu/main.c +++ b/grub-core/efiemu/main.c @@ -266,11 +266,13 @@ grub_efiemu_prepare (void) if (prepared) return GRUB_ERR_NONE; + err = grub_efiemu_autocore (); + if (err) + return err; + grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n", 8 * grub_efiemu_sizeof_uintn_t ()); - err = grub_efiemu_autocore (); - /* Create NVRAM. */ grub_efiemu_pnvram (); From 2d5fed60d0845e5dc339f82659e9d2ebe4e00a86 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 15 Oct 2010 12:06:13 +0200 Subject: [PATCH 50/75] 2010-10-15 Robert Millan * util/grub.d/10_linux.in (list): Expand "vmlinu[zx]" instances to guarantee compressed ones are processed first. --- ChangeLog | 5 +++++ util/grub.d/10_linux.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5553a991c..a40deb780 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-15 Robert Millan + + * util/grub.d/10_linux.in (list): Expand "vmlinu[zx]" instances to + guarantee compressed ones are processed first. + 2010-10-14 Vladimir Serbinenko * grub-core/efiemu/main.c (grub_efiemu_prepare): Handle errors from diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 6cb6f0be7..e37bab21b 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -102,7 +102,7 @@ EOF EOF } -list=`for i in /boot/vmlinu[zx]-* /vmlinu[zx]-* ; do +list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` prepare_boot_cache= From 1eb01cd2761e472860874579a90c8657338db96f Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 16 Oct 2010 02:30:14 +0200 Subject: [PATCH 51/75] 2010-10-16 Robert Millan * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Fix premature return when processing non-root ZFS filesystems. --- ChangeLog | 6 ++++++ grub-core/kern/emu/misc.c | 21 +++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index a40deb780..ce683bbb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-10-16 Robert Millan + + * grub-core/kern/emu/misc.c + (grub_make_system_path_relative_to_its_root): Fix premature return + when processing non-root ZFS filesystems. + 2010-10-15 Robert Millan * util/grub.d/10_linux.in (list): Expand "vmlinu[zx]" instances to diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index d8db3be9d..cfc143bf9 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -406,21 +406,7 @@ grub_make_system_path_relative_to_its_root (const char *path) /* buf is another filesystem; we found it. */ if (st.st_dev != num) - { - /* offset == 0 means path given is the mount point. - This works around special-casing of "/" in Un*x. This function never - prints trailing slashes (so that its output can be appended a slash - unconditionally). Each slash in is considered a preceding slash, and - therefore the root directory is an empty string. */ - if (offset == 0) - { - free (buf); - free (buf2); - return xstrdup (""); - } - else - break; - } + break; offset = p - buf; /* offset == 1 means root directory. */ @@ -448,7 +434,10 @@ grub_make_system_path_relative_to_its_root (const char *path) } #endif - /* Remove trailing slashes, return empty string if root directory. */ + /* This works around special-casing of "/" in Un*x. This function never + prints trailing slashes (so that its output can be appended a slash + unconditionally). Each slash in it is considered a preceding slash, + and therefore the root directory is an empty string. */ len = strlen (buf3); while (len > 0 && buf3[len - 1] == '/') { From 5f8b440b6b24057b29f1692d275a409c18ee35a1 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 16 Oct 2010 02:34:10 +0200 Subject: [PATCH 52/75] Mention who reported this bug. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index ce683bbb0..4b2a7a705 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Fix premature return when processing non-root ZFS filesystems. + Reported by Sergio Talens-Oliag. 2010-10-15 Robert Millan From 24977b4451d626057ac1bf5e813baddc045ec5ec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 17:29:12 +0200 Subject: [PATCH 53/75] * grub-core/term/ns8250.c (do_real_config): Set port->broken to 0. (serial_hw_put): Wait based on real time rather than port reads. Don't roken ports. * include/grub/serial.h (grub_serial_port): New field broken. --- ChangeLog | 7 +++++++ grub-core/term/ns8250.c | 23 +++++++++++++++++++---- include/grub/serial.h | 6 +++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b2a7a705..3f9c5a8cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-10-16 Vladimir Serbinenko + + * grub-core/term/ns8250.c (do_real_config): Set port->broken to 0. + (serial_hw_put): Wait based on real time rather than port reads. Don't + roken ports. + * include/grub/serial.h (grub_serial_port): New field broken. + 2010-10-16 Robert Millan * grub-core/kern/emu/misc.c diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c index 550ee6341..4be528df8 100644 --- a/grub-core/term/ns8250.c +++ b/grub-core/term/ns8250.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_PCBIOS #include @@ -90,6 +91,8 @@ do_real_config (struct grub_serial_port *port) if (port->configured) return; + port->broken = 0; + divisor = serial_get_divisor (port->config.speed); /* Turn off the interrupt. */ @@ -145,18 +148,30 @@ serial_hw_fetch (struct grub_serial_port *port) static void serial_hw_put (struct grub_serial_port *port, const int c) { - unsigned int timeout = 100000; + grub_uint64_t endtime; do_real_config (port); + if (port->broken > 5) + endtime = grub_get_time_ms (); + else if (port->broken > 1) + endtime = grub_get_time_ms () + 50; + else + endtime = grub_get_time_ms () + 200; /* Wait until the transmitter holding register is empty. */ while ((grub_inb (port->port + UART_LSR) & UART_EMPTY_TRANSMITTER) == 0) { - if (--timeout == 0) - /* There is something wrong. But what can I do? */ - return; + if (grub_get_time_ms () > endtime) + { + port->broken++; + /* There is something wrong. But what can I do? */ + return; + } } + if (port->broken) + port->broken--; + grub_outb (c, port->port + UART_TX); } diff --git a/include/grub/serial.h b/include/grub/serial.h index 652268b2e..9540bee64 100644 --- a/include/grub/serial.h +++ b/include/grub/serial.h @@ -72,7 +72,11 @@ struct grub_serial_port */ union { - grub_port_t port; + struct + { + grub_port_t port; + int broken; + }; struct { grub_usb_device_t usbdev; From 65f7ed7c9a61c2bcda5c9845db23b5c06c47a093 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 17:44:35 +0200 Subject: [PATCH 54/75] * grub-core/kern/efi/mm.c (BYTES_TO_PAGES): Round up instead of down. (grub_efi_mm_init): Take into account the memory map size increase. --- ChangeLog | 5 +++++ grub-core/kern/efi/mm.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3f9c5a8cd..7292b1d3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-16 Vladimir Serbinenko + + * grub-core/kern/efi/mm.c (BYTES_TO_PAGES): Round up instead of down. + (grub_efi_mm_init): Take into account the memory map size increase. + 2010-10-16 Vladimir Serbinenko * grub-core/term/ns8250.c (do_real_config): Set port->broken to 0. diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index c845d7df1..6205abf9b 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -25,7 +25,7 @@ #define NEXT_MEMORY_DESCRIPTOR(desc, size) \ ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) -#define BYTES_TO_PAGES(bytes) ((bytes) >> 12) +#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) #define PAGES_TO_BYTES(pages) ((pages) << 12) /* The size of a memory map obtained from the firmware. This must be @@ -447,6 +447,9 @@ grub_efi_mm_init (void) ((grub_efi_physical_address_t) ((grub_addr_t) memory_map), 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + /* Freeing/allocating operations may increase memory map size. */ + map_size += desc_size * 32; + memory_map = grub_efi_allocate_pages (0, 2 * BYTES_TO_PAGES (map_size)); if (! memory_map) grub_fatal ("cannot allocate memory"); From fbfbeb394f45984974dcf97b11141b166b8325c1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 17:50:48 +0200 Subject: [PATCH 55/75] Remove dead grub_efi_mm_fini. * grub-core/kern/efi/mm.c (allocated_page): Removed. (ALLOCATED_PAGES_SIZE): Likewise. (MAX_ALLOCATED_PAGES): Likewise. (allocated_pages): Likewise. (grub_efi_allocate_pages): Don't record allocated pages. (grub_efi_free_pages): Likewise. (grub_efi_mm_init): Likewise. (grub_efi_mm_fini): Removed. --- ChangeLog | 13 ++++++++ grub-core/kern/efi/mm.c | 72 ----------------------------------------- 2 files changed, 13 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7292b1d3f..1d72f60f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-10-16 Vladimir Serbinenko + + Remove dead grub_efi_mm_fini. + + * grub-core/kern/efi/mm.c (allocated_page): Removed. + (ALLOCATED_PAGES_SIZE): Likewise. + (MAX_ALLOCATED_PAGES): Likewise. + (allocated_pages): Likewise. + (grub_efi_allocate_pages): Don't record allocated pages. + (grub_efi_free_pages): Likewise. + (grub_efi_mm_init): Likewise. + (grub_efi_mm_fini): Removed. + 2010-10-16 Vladimir Serbinenko * grub-core/kern/efi/mm.c (BYTES_TO_PAGES): Round up instead of down. diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 6205abf9b..a715da076 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -32,19 +32,6 @@ a multiplier of 4KB. */ #define MEMORY_MAP_SIZE 0x3000 -/* Maintain the list of allocated pages. */ -struct allocated_page -{ - grub_efi_physical_address_t addr; - grub_efi_uint64_t num_pages; -}; - -#define ALLOCATED_PAGES_SIZE 0x1000 -#define MAX_ALLOCATED_PAGES \ - (ALLOCATED_PAGES_SIZE / sizeof (struct allocated_page)) - -static struct allocated_page *allocated_pages = 0; - /* The minimum and maximum heap size for GRUB itself. */ #define MIN_HEAP_SIZE 0x100000 #define MAX_HEAP_SIZE (1600 * 0x100000) @@ -102,22 +89,6 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, return 0; } - if (allocated_pages) - { - unsigned i; - - for (i = 0; i < MAX_ALLOCATED_PAGES; i++) - if (allocated_pages[i].addr == 0) - { - allocated_pages[i].addr = address; - allocated_pages[i].num_pages = pages; - break; - } - - if (i == MAX_ALLOCATED_PAGES) - grub_fatal ("too many page allocations"); - } - return (void *) ((grub_addr_t) address); } @@ -128,20 +99,6 @@ grub_efi_free_pages (grub_efi_physical_address_t address, { grub_efi_boot_services_t *b; - if (allocated_pages - && ((grub_efi_physical_address_t) ((grub_addr_t) allocated_pages) - != address)) - { - unsigned i; - - for (i = 0; i < MAX_ALLOCATED_PAGES; i++) - if (allocated_pages[i].addr == address) - { - allocated_pages[i].addr = 0; - break; - } - } - b = grub_efi_system_table->boot_services; efi_call_2 (b->free_pages, address, pages); } @@ -422,14 +379,6 @@ grub_efi_mm_init (void) grub_efi_uint64_t required_pages; int mm_status; - /* First of all, allocate pages to maintain allocations. */ - allocated_pages - = grub_efi_allocate_pages (0, BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE)); - if (! allocated_pages) - grub_fatal ("cannot allocate memory"); - - grub_memset (allocated_pages, 0, ALLOCATED_PAGES_SIZE); - /* Prepare a memory region to store two memory maps. */ memory_map = grub_efi_allocate_pages (0, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); @@ -502,24 +451,3 @@ grub_efi_mm_init (void) grub_efi_free_pages ((grub_addr_t) memory_map, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } - -void -grub_efi_mm_fini (void) -{ - if (allocated_pages) - { - unsigned i; - - for (i = 0; i < MAX_ALLOCATED_PAGES; i++) - { - struct allocated_page *p; - - p = allocated_pages + i; - if (p->addr != 0) - grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages); - } - - grub_efi_free_pages ((grub_addr_t) allocated_pages, - BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE)); - } -} From c32b51c9f97f392605b6b03593b412feaacfac1b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 19:06:55 +0200 Subject: [PATCH 56/75] Userspace ACPI parser debugging. * grub-core/commands/acpihalt.c [GRUB_DSDT_TEST]: Include userspace headers and add relevant defines. Don't include standard headers. (main) [GRUB_DSDT_TEST]: New function. * include/grub/acpi.h [GRUB_DSDT_TEST]: Don't include standard headers. Don't declare functions. --- ChangeLog | 10 ++++++ grub-core/commands/acpihalt.c | 61 +++++++++++++++++++++++++++++++++++ include/grub/acpi.h | 4 +++ 3 files changed, 75 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1d72f60f7..052fd1e27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-10-16 Vladimir Serbinenko + + Userspace ACPI parser debugging. + + * grub-core/commands/acpihalt.c [GRUB_DSDT_TEST]: Include userspace + headers and add relevant defines. Don't include standard headers. + (main) [GRUB_DSDT_TEST]: New function. + * include/grub/acpi.h [GRUB_DSDT_TEST]: Don't include standard headers. + Don't declare functions. + 2010-10-16 Vladimir Serbinenko Remove dead grub_efi_mm_fini. diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index a39635677..1e42f447f 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -16,9 +16,28 @@ * along with GRUB. If not, see . */ +#ifdef GRUB_DSDT_TEST +#include +#include +#include +#include +#include + +#define grub_dprintf(cond, args...) printf ( args ) +#define grub_printf printf +typedef uint64_t grub_uint64_t; +typedef uint32_t grub_uint32_t; +typedef uint16_t grub_uint16_t; +typedef uint8_t grub_uint8_t; + +#endif + #include + +#ifndef GRUB_DSDT_TEST #include #include +#endif static inline grub_uint32_t decode_length (const grub_uint8_t *ptr, int *numlen) @@ -208,6 +227,47 @@ get_sleep_type (grub_uint8_t *table, grub_uint8_t *end) return sleep_type; } +#ifdef GRUB_DSDT_TEST +int +main (int argc, char **argv) +{ + FILE *f; + size_t len; + unsigned char *buf; + if (argc < 2) + printf ("Usage: %s FILE\n", argv[0]); + f = fopen (argv[1], "rb"); + if (!f) + { + printf ("Couldn't open file\n"); + return 1; + } + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + buf = malloc (len); + if (!buf) + { + printf ("Couldn't malloc buffer\n"); + fclose (f); + return 2; + } + if (fread (buf, 1, len, f) != len) + { + printf ("Read failed\n"); + free (buf); + fclose (f); + return 2; + } + + printf ("Sleep type = %d\n", get_sleep_type (buf, buf + len)); + free (buf); + fclose (f); + return 0; +} + +#else + void grub_acpi_halt (void) { @@ -264,3 +324,4 @@ grub_acpi_halt (void) grub_printf ("ACPI shutdown failed\n"); } +#endif diff --git a/include/grub/acpi.h b/include/grub/acpi.h index aebc8dd4f..c7ab82dad 100644 --- a/include/grub/acpi.h +++ b/include/grub/acpi.h @@ -19,8 +19,10 @@ #ifndef GRUB_ACPI_HEADER #define GRUB_ACPI_HEADER 1 +#ifndef GRUB_DSDT_TEST #include #include +#endif struct grub_acpi_rsdp_v10 { @@ -139,6 +141,7 @@ enum GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED = 1 }; +#ifndef GRUB_DSDT_TEST struct grub_acpi_rsdp_v10 *grub_acpi_get_rsdpv1 (void); struct grub_acpi_rsdp_v20 *grub_acpi_get_rsdpv2 (void); struct grub_acpi_rsdp_v10 *grub_machine_acpi_get_rsdpv1 (void); @@ -148,6 +151,7 @@ grub_uint8_t grub_byte_checksum (void *base, grub_size_t size); grub_err_t grub_acpi_create_ebda (void); void grub_acpi_halt (void); +#endif #define GRUB_ACPI_SLP_EN (1 << 13) #define GRUB_ACPI_SLP_TYP_OFFSET 10 From 6c8d300275faaaa4a0e3c48fa9d45dd177528942 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 19:12:18 +0200 Subject: [PATCH 57/75] * grub-core/commands/acpihalt.c (get_sleep_type): Accept \_S5_ as synonym to _S5_. Needed for some DSDTs. --- ChangeLog | 5 +++++ grub-core/commands/acpihalt.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 052fd1e27..34a092ca2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-16 Vladimir Serbinenko + + * grub-core/commands/acpihalt.c (get_sleep_type): Accept \_S5_ as + synonym to _S5_. Needed for some DSDTs. + 2010-10-16 Vladimir Serbinenko Userspace ACPI parser debugging. diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index 1e42f447f..d28a74323 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -175,11 +175,12 @@ get_sleep_type (grub_uint8_t *table, grub_uint8_t *end) break; case GRUB_ACPI_OPCODE_NAME: ptr++; - if (memcmp (ptr, "_S5_", 4) == 0) + if (memcmp (ptr, "_S5_", 4) == 0 || memcmp (ptr, "\\_S5_", 4) == 0) { int ll; grub_uint8_t *ptr2 = ptr; - ptr2 += 4; + grub_dprintf ("acpi", "S5 found\n"); + ptr2 += skip_name_string (ptr, end); if (*ptr2 != 0x12) { grub_printf ("Unknown opcode in _S5: 0x%x\n", *ptr2); From e19b016b303596747027ac4ddb41caef11fc8fbf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 20:01:30 +0200 Subject: [PATCH 58/75] * grub-core/commands/acpihalt.c (skip_ext_op): Skip index field op. * include/grub/acpi.h (GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP): New enum value. --- ChangeLog | 6 ++++++ grub-core/commands/acpihalt.c | 1 + include/grub/acpi.h | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 34a092ca2..1c21262b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-10-16 Vladimir Serbinenko + + * grub-core/commands/acpihalt.c (skip_ext_op): Skip index field op. + * include/grub/acpi.h (GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP): New + enum value. + 2010-10-16 Vladimir Serbinenko * grub-core/commands/acpihalt.c (get_sleep_type): Accept \_S5_ as diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index d28a74323..2789e2eca 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -142,6 +142,7 @@ skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end) return 0; break; case GRUB_ACPI_EXTOPCODE_FIELD_OP: + case GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP: ptr++; ptr += decode_length (ptr, 0); break; diff --git a/include/grub/acpi.h b/include/grub/acpi.h index c7ab82dad..c843a0621 100644 --- a/include/grub/acpi.h +++ b/include/grub/acpi.h @@ -169,7 +169,8 @@ enum { GRUB_ACPI_EXTOPCODE_MUTEX = 0x01, GRUB_ACPI_EXTOPCODE_OPERATION_REGION = 0x80, - GRUB_ACPI_EXTOPCODE_FIELD_OP = 0x81 + GRUB_ACPI_EXTOPCODE_FIELD_OP = 0x81, + GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP = 0x86, }; #endif /* ! GRUB_ACPI_HEADER */ From 6bdda8f87750cd55d511d433e3299100d34102e4 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 16 Oct 2010 22:16:52 +0200 Subject: [PATCH 59/75] * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel): Set-but-not-used variable ifdef'ed. * grub-core/lib/legacy_parse.c (grub_legacy_parse): Likewise. * grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Set-but-not-used variable removed. * grub-core/disk/lvm.c (grub_lvm_scan_device): Likewise. * grub-core/fs/jfs.c (grub_jfs_find_file): Likewise. * grub-core/fs/minix.c (grub_minix_dir): Likewise. * grub-core/fs/sfs.c (grub_sfs_read_extent): Likewise. * grub-core/fs/ufs.c (grub_ufs_dir): Likewise. * grub-core/gfxmenu/gui_list.c (grub_gui_list_new): Likewise. * grub-core/gfxmenu/view.c (redraw_menu_visit): Likewise. * grub-core/gfxmenu/widget-box.c (draw): Likewise. * grub-core/lib/relocator.c (malloc_in_range): Likewise. * grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): Likewise. * grub-core/loader/i386/bsd_pagetable.c (fill_bsd64_pagetable): Likewise. --- ChangeLog | 20 ++++++++++++++++++++ grub-core/bus/usb/ohci.c | 2 -- grub-core/commands/legacycfg.c | 4 ++++ grub-core/disk/lvm.c | 4 +--- grub-core/fs/jfs.c | 3 --- grub-core/fs/minix.c | 3 --- grub-core/fs/sfs.c | 3 --- grub-core/fs/ufs.c | 3 --- grub-core/gfxmenu/gui_list.c | 2 -- grub-core/gfxmenu/view.c | 2 -- grub-core/gfxmenu/widget-box.c | 12 ------------ grub-core/lib/legacy_parse.c | 16 ++++++++++------ grub-core/lib/relocator.c | 10 ++-------- grub-core/loader/i386/bsdXX.c | 4 ---- grub-core/loader/i386/bsd_pagetable.c | 3 +-- 15 files changed, 38 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c21262b9..4a06eaefa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2010-10-16 Szymon Janc + + * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel): + Set-but-not-used variable ifdef'ed. + * grub-core/lib/legacy_parse.c (grub_legacy_parse): Likewise. + * grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Set-but-not-used + variable removed. + * grub-core/disk/lvm.c (grub_lvm_scan_device): Likewise. + * grub-core/fs/jfs.c (grub_jfs_find_file): Likewise. + * grub-core/fs/minix.c (grub_minix_dir): Likewise. + * grub-core/fs/sfs.c (grub_sfs_read_extent): Likewise. + * grub-core/fs/ufs.c (grub_ufs_dir): Likewise. + * grub-core/gfxmenu/gui_list.c (grub_gui_list_new): Likewise. + * grub-core/gfxmenu/view.c (redraw_menu_visit): Likewise. + * grub-core/gfxmenu/widget-box.c (draw): Likewise. + * grub-core/lib/relocator.c (malloc_in_range): Likewise. + * grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): Likewise. + * grub-core/loader/i386/bsd_pagetable.c (fill_bsd64_pagetable): + Likewise. + 2010-10-16 Vladimir Serbinenko * grub-core/commands/acpihalt.c (skip_ext_op): Skip index field op. diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index 3c3ce4b89..8adaee6e0 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -220,7 +220,6 @@ grub_ohci_pci_iter (grub_pci_device_t dev, grub_pci_address_t addr; struct grub_ohci *o; grub_uint32_t revision; - int cs5536; int j; /* Determine IO base address. */ @@ -230,7 +229,6 @@ grub_ohci_pci_iter (grub_pci_device_t dev, { grub_uint64_t basereg; - cs5536 = 1; basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_OHCI_BASE); if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE)) { diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index 1b0e968c5..d5441db06 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -225,7 +225,9 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), int argc, char **args) { int i; +#ifdef TODO int no_mem_option = 0; +#endif struct grub_command *cmd; char **cutargs; int cutargc; @@ -235,7 +237,9 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), /* FIXME: really support this. */ if (argc >= 1 && grub_strcmp (args[0], "--no-mem-option") == 0) { +#ifdef TODO no_mem_option = 1; +#endif argc--; args++; continue; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 94cf9a1aa..d2d2f620b 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -259,7 +259,7 @@ grub_lvm_scan_device (const char *name) { grub_err_t err; grub_disk_t disk; - grub_uint64_t da_offset, da_size, mda_offset, mda_size; + grub_uint64_t mda_offset, mda_size; char buf[GRUB_LVM_LABEL_SIZE]; char vg_id[GRUB_LVM_ID_STRLEN+1]; char pv_id[GRUB_LVM_ID_STRLEN+1]; @@ -319,8 +319,6 @@ grub_lvm_scan_device (const char *name) pv_id[j] = '\0'; dlocn = pvh->disk_areas_xl; - da_offset = grub_le_to_cpu64 (dlocn->offset); - da_size = grub_le_to_cpu64 (dlocn->size); dlocn++; /* Is it possible to have multiple data/metadata areas? I haven't diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index c9839a22f..76ef2e540 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -601,7 +601,6 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) char fpath[grub_strlen (path)]; char *name = fpath; char *next; - unsigned int pos = 0; struct grub_jfs_diropen *diro; grub_strncpy (fpath, path, grub_strlen (path) + 1); @@ -664,8 +663,6 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) if (!next) return 0; - pos = 0; - name = next; next = grub_strchr (name, '/'); if (next) diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index aa5b9a0c9..679e1ec51 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -436,7 +436,6 @@ grub_minix_dir (grub_device_t device, const char *path, const struct grub_dirhook_info *info)) { struct grub_minix_data *data = 0; - struct grub_minix_sblock *sblock; unsigned int pos = 0; data = grub_minix_mount (device->disk); @@ -447,8 +446,6 @@ grub_minix_dir (grub_device_t device, const char *path, if (grub_errno) goto fail; - sblock = &data->sblock; - grub_minix_find_file (data, path); if (grub_errno) goto fail; diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 68f8b3a6e..4a5005908 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -149,7 +149,6 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block, struct grub_sfs_btree *tree; int i; int next; - int prev; treeblock = grub_malloc (data->blocksize); if (!block) @@ -161,8 +160,6 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block, /* Handle this level in the btree. */ do { - prev = 0; - grub_disk_read (data->disk, next, 0, data->blocksize, treeblock); if (grub_errno) { diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index 40cf068e6..2b1021db6 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -568,7 +568,6 @@ grub_ufs_dir (grub_device_t device, const char *path, const struct grub_dirhook_info *info)) { struct grub_ufs_data *data; - struct grub_ufs_sblock *sblock; unsigned int pos = 0; data = grub_ufs_mount (device->disk); @@ -579,8 +578,6 @@ grub_ufs_dir (grub_device_t device, const char *path, if (grub_errno) return grub_errno; - sblock = &data->sblock; - if (!path || path[0] != '/') { grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); diff --git a/grub-core/gfxmenu/gui_list.c b/grub-core/gfxmenu/gui_list.c index 8058fcc4f..b6b07dfd6 100644 --- a/grub-core/gfxmenu/gui_list.c +++ b/grub-core/gfxmenu/gui_list.c @@ -563,7 +563,6 @@ grub_gui_list_new (void) list_impl_t self; grub_font_t default_font; grub_gui_color_t default_fg_color; - grub_gui_color_t default_bg_color; self = grub_zalloc (sizeof (*self)); if (! self) @@ -576,7 +575,6 @@ grub_gui_list_new (void) default_font = grub_font_get ("Unknown Regular 16"); default_fg_color = grub_gui_color_rgb (0, 0, 0); - default_bg_color = grub_gui_color_rgb (255, 255, 255); self->icon_width = 32; self->icon_height = 32; diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c index 518c3ba53..901cdc889 100644 --- a/grub-core/gfxmenu/view.c +++ b/grub-core/gfxmenu/view.c @@ -309,10 +309,8 @@ redraw_menu_visit (grub_gui_component_t component, view = userdata; if (component->ops->is_instance (component, "list")) { - grub_gui_list_t list; grub_video_rect_t bounds; - list = (grub_gui_list_t) component; component->ops->get_bounds (component, &bounds); grub_gfxmenu_view_redraw (view, &bounds); } diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c index 079fd66d4..244fe1e6c 100644 --- a/grub-core/gfxmenu/widget-box.c +++ b/grub-core/gfxmenu/widget-box.c @@ -79,21 +79,9 @@ static void draw (grub_gfxmenu_box_t self, int x, int y) { int height_n; - int height_s; - int height_e; - int height_w; - int width_n; - int width_s; - int width_e; int width_w; height_n = get_height (self->scaled_pixmaps[BOX_PIXMAP_N]); - height_s = get_height (self->scaled_pixmaps[BOX_PIXMAP_S]); - height_e = get_height (self->scaled_pixmaps[BOX_PIXMAP_E]); - height_w = get_height (self->scaled_pixmaps[BOX_PIXMAP_W]); - width_n = get_width (self->scaled_pixmaps[BOX_PIXMAP_N]); - width_s = get_width (self->scaled_pixmaps[BOX_PIXMAP_S]); - width_e = get_width (self->scaled_pixmaps[BOX_PIXMAP_E]); width_w = get_width (self->scaled_pixmaps[BOX_PIXMAP_W]); /* Draw sides. */ diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index ae27048a2..cd3bc8d40 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -486,8 +486,12 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) if (legacy_commands[cmdnum].flags & FLAG_TERMINAL) { - int dumb = 0, no_echo = 0, no_edit = 0, lines = 24; - int console = 0, serial = 0, hercules = 0; + int dumb = 0, lines = 24; +#ifdef TODO + int no_echo = 0, no_edit = 0; + int hercules = 0; +#endif + int console = 0, serial = 0; /* Big enough for any possible resulting command. */ char outbuf[256] = ""; char *outptr; @@ -497,13 +501,13 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) " [console] [serial] [hercules]"*/ if (grub_memcmp (ptr, "--dumb", sizeof ("--dumb") - 1) == 0) dumb = 1; - +#ifdef TODO if (grub_memcmp (ptr, "--no-echo", sizeof ("--no-echo") - 1) == 0) no_echo = 1; if (grub_memcmp (ptr, "--no-edit", sizeof ("--no-edit") - 1) == 0) no_edit = 1; - +#endif if (grub_memcmp (ptr, "--lines=", sizeof ("--lines=") - 1) == 0) { lines = grub_strtoul (ptr + sizeof ("--lines=") - 1, 0, 0); @@ -519,10 +523,10 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) if (grub_memcmp (ptr, "serial", sizeof ("serial") - 1) == 0) serial = 1; - +#ifdef TODO if (grub_memcmp (ptr, "hercules", sizeof ("hercules") - 1) == 0) hercules = 1; - +#endif while (*ptr && !grub_isspace (*ptr)) ptr++; while (*ptr && grub_isspace (*ptr)) diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index a0cab55af..b1412e73a 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -579,7 +579,6 @@ malloc_in_range (struct grub_relocator *rel, for (ra = &base_saved, r = *ra; r; ra = &(r->next), r = *ra) { - int pre_added = 0; pa = r->first; p = pa->next; if (p->magic == GRUB_MM_ALLOC_MAGIC) @@ -591,7 +590,6 @@ malloc_in_range (struct grub_relocator *rel, __LINE__, p, p->magic); if (p == (grub_mm_header_t) (r + 1)) { - pre_added = 1; events[N].type = REG_BEG_START; events[N].pos = grub_vtop (r) - r->pre_size; events[N].reg = r; @@ -667,7 +665,6 @@ malloc_in_range (struct grub_relocator *rel, const int nlefto = 0; #endif grub_addr_t starta = 0; - int numstarted; for (j = from_low_priv ? 0 : N - 1; from_low_priv ? j < N : (j + 1); from_low_priv ? j++ : j--) { @@ -725,11 +722,8 @@ malloc_in_range (struct grub_relocator *rel, isinsideafter = (!ncollisions && (nstarted || ((nlefto || nstartedfw) && !nblockfw))); if (!isinsidebefore && isinsideafter) - { - starta = from_low_priv ? ALIGN_UP (events[j].pos, align) - : ALIGN_DOWN (events[j].pos - size, align) + size; - numstarted = j; - } + starta = from_low_priv ? ALIGN_UP (events[j].pos, align) + : ALIGN_DOWN (events[j].pos - size, align) + size; if (isinsidebefore && !isinsideafter && from_low_priv) { target = starta; diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c index 073f01da2..29892e5fb 100644 --- a/grub-core/loader/i386/bsdXX.c +++ b/grub-core/loader/i386/bsdXX.c @@ -396,10 +396,8 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, Elf_Shdr *s, *symsh, *strsh; char *shdr; unsigned symsize, strsize; - Elf_Sym *sym; void *sym_chunk; grub_uint8_t *curload; - const char *str; grub_size_t chunk_size; Elf_Ehdr *e2; struct grub_netbsd_btinfo_symtab symtab; @@ -473,7 +471,6 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, if (grub_file_seek (file, symsh->sh_offset) == (grub_off_t) -1) return grub_errno; - sym = (Elf_Sym *) curload; if (grub_file_read (file, curload, symsize) != (grub_ssize_t) symsize) { if (! grub_errno) @@ -484,7 +481,6 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, if (grub_file_seek (file, strsh->sh_offset) == (grub_off_t) -1) return grub_errno; - str = (char *) curload; if (grub_file_read (file, curload, strsize) != (grub_ssize_t) strsize) { if (! grub_errno) diff --git a/grub-core/loader/i386/bsd_pagetable.c b/grub-core/loader/i386/bsd_pagetable.c index 13348cc83..9ec5abffc 100644 --- a/grub-core/loader/i386/bsd_pagetable.c +++ b/grub-core/loader/i386/bsd_pagetable.c @@ -53,7 +53,7 @@ static void fill_bsd64_pagetable (grub_uint8_t *src, grub_addr_t target) { grub_uint64_t *pt2, *pt3, *pt4; - grub_addr_t pt2t, pt3t, pt4t; + grub_addr_t pt2t, pt3t; int i; #define PG_V 0x001 @@ -65,7 +65,6 @@ fill_bsd64_pagetable (grub_uint8_t *src, grub_addr_t target) pt3 = (grub_uint64_t *) (src + 4096); pt2 = (grub_uint64_t *) (src + 8192); - pt4t = target; pt3t = target + 4096; pt2t = target + 8192; From 27d9ee3253f2b9963b091ba14a24ad600f38c42c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Oct 2010 23:38:30 +0200 Subject: [PATCH 60/75] * docs/grub.texi (Installation): Document embedding zone. Remove obsolete grub-install example. --- ChangeLog | 5 +++++ docs/grub.texi | 15 ++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a06eaefa..7fa6586d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-16 Vladimir Serbinenko + + * docs/grub.texi (Installation): Document embedding zone. Remove + obsolete grub-install example. + 2010-10-16 Szymon Janc * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel): diff --git a/docs/grub.texi b/docs/grub.texi index 4995b1df7..1bf652e15 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -559,6 +559,8 @@ always. Therefore, GRUB provides you with a map file called the @dfn{device map}, which you must fix if it is wrong. @xref{Device map}, for more details. +On BIOS platforms GRUB has to use a so called embedding zone. On msdos partition tables it's the space between MBR and first partition (called MBR gap), on GPT partition it uses a BIOS Boot Partition (a partition having type 21686148-6449-6e6f-744e656564454649). If you use GRUB on BIOS be sure to supply at least 31 KiB of embedding zone (512KiB or more recommended). + If you still do want to install GRUB under a UNIX-like OS (such as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking grub-install}) as the superuser (@dfn{root}). @@ -579,18 +581,6 @@ Likewise, under GNU/Hurd, this has the same effect: # @kbd{grub-install /dev/hd0} @end example -If it is the first BIOS drive, this is the same as well: - -@example -# @kbd{grub-install '(hd0)'} -@end example - -Or you can omit the parentheses: - -@example -# @kbd{grub-install hd0} -@end example - But all the above examples assume that GRUB should use images under the root directory. If you want GRUB to use images under a directory other than the root directory, you need to specify the option @@ -629,7 +619,6 @@ using @command{grub-install}. Don't do that, however, unless you are very familiar with the internals of GRUB. Installing a boot loader on a running OS may be extremely dangerous. - @node Making a GRUB bootable CD-ROM @section Making a GRUB bootable CD-ROM From f77a8c24709523ab1074b6272cf8dafe0f5de7d9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 00:25:23 +0200 Subject: [PATCH 61/75] * util/grub-setup.c (setup): Don't clean blocklists before readability verfification. --- ChangeLog | 5 +++++ util/grub-setup.c | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7fa6586d1..731abcb0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-17 Vladimir Serbinenko + + * util/grub-setup.c (setup): Don't clean blocklists before readability + verfification. + 2010-10-16 Vladimir Serbinenko * docs/grub.texi (Installation): Document embedding zone. Remove diff --git a/util/grub-setup.c b/util/grub-setup.c index 920d867f2..ab0098468 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -319,18 +319,6 @@ setup (const char *dir, } #endif - /* Clean out the blocklists. */ - block = first_block; - while (block->len) - { - grub_memset (block, 0, sizeof (block)); - - block--; - - if ((char *) block <= core_img) - grub_util_error ("No terminator in the core image"); - } - #ifdef GRUB_MACHINE_PCBIOS { grub_partition_map_t dest_partmap = NULL; @@ -434,6 +422,18 @@ setup (const char *dir, goto unable_to_embed; } + /* Clean out the blocklists. */ + block = first_block; + while (block->len) + { + grub_memset (block, 0, sizeof (block)); + + block--; + + if ((char *) block <= core_img) + grub_util_error ("No terminator in the core image"); + } + save_first_sector (sectors[0] + grub_partition_get_start (container), 0, GRUB_DISK_SECTOR_SIZE); From 861dfd4cb2dcb882ea4a4334172ee7114fd85d6e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 00:28:19 +0200 Subject: [PATCH 62/75] * util/grub-install.in: Handle partitionless disks. --- ChangeLog | 4 ++++ util/grub-install.in | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 731abcb0f..b5c091ee1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-10-17 Vladimir Serbinenko + + * util/grub-install.in: Handle partitionless disks. + 2010-10-17 Vladimir Serbinenko * util/grub-setup.c (setup): Don't clean blocklists before readability diff --git a/util/grub-install.in b/util/grub-install.in index cace82593..21ac20f8d 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -512,7 +512,7 @@ if [ "x${devabstraction_module}" = "x" ] ; then grub_drive="`$grub_probe --target=drive --device ${grub_device}`" || exit 1 # Strip partition number - grub_partition="`echo ${grub_drive} | sed -e 's/^[^,]*,//; s/)$//'`" + grub_partition="`echo ${grub_drive} | sed -e 's/^[^,]*[,)]//; s/)$//'`" grub_drive="`echo ${grub_drive} | sed -e s/,[a-z0-9,]*//g`" if [ "$disk_module" = ata ] ; then # generic method (used on coreboot and ata mod) @@ -537,7 +537,11 @@ if [ "x${devabstraction_module}" = "x" ] ; then modules="$modules search_fs_uuid" elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ]; then # we need to hardcode the partition number in the core image's prefix. - prefix_drive="(,$grub_partition)" + if [ x"$grub_partition" = x ]; then + prefix_drive="()" + else + prefix_drive="(,$grub_partition)" + fi fi else prefix_drive=`$grub_probe --target=drive --device ${grub_device}` || exit 1 From fdf2ec9c8ceef98d8e4aca6c176f56514f4103ee Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 00:35:14 +0200 Subject: [PATCH 63/75] * util/grub-setup.c (setup): New parameter allow_floppy. (arguments): New member allow_floppy. (argp_parser): Handle --allow-floppy. (main): Pass allow_floppy. * util/grub-install.in: New option --allow-floppy passed though to grub-setup. --- ChangeLog | 9 +++++++++ util/grub-install.in | 9 ++++++++- util/grub-setup.c | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5c091ee1..4e0d4a81e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-10-17 Vladimir Serbinenko + + * util/grub-setup.c (setup): New parameter allow_floppy. + (arguments): New member allow_floppy. + (argp_parser): Handle --allow-floppy. + (main): Pass allow_floppy. + * util/grub-install.in: New option --allow-floppy passed though to + grub-setup. + 2010-10-17 Vladimir Serbinenko * util/grub-install.in: Handle partitionless disks. diff --git a/util/grub-install.in b/util/grub-install.in index 21ac20f8d..8b0f5ebe1 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -107,6 +107,8 @@ Install GRUB on your drive. --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap --grub-probe=FILE use FILE as grub-probe --no-floppy do not probe any floppy drive + --allow-floppy Make the drive also bootable as floppy + (default for fdX devices). May break on some BIOSes. --recheck probe a device map even if it already exists --force install even if problems are detected EOF @@ -148,6 +150,8 @@ argument () { echo $1 } +allow_floppy="" + # Check the arguments. while test $# -gt 0 do @@ -221,6 +225,9 @@ do --removable) removable=yes ;; + --allow-floppy) + allow_floppy="--allow-floppy" ;; + --disk-module) if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then disk_module=`argument $option "$@"`; shift; @@ -576,7 +583,7 @@ fi # Perform the platform-dependent install if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then # Now perform the installation. - $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} \ + $grub_setup ${allow_floppy} ${setup_verbose} ${setup_force} --directory=${grubdir} \ --device-map=${device_map} ${install_device} || exit 1 elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then if [ x"$update_nvram" = xyes ]; then diff --git a/util/grub-setup.c b/util/grub-setup.c index ab0098468..8ab33590b 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -177,7 +177,7 @@ static void setup (const char *dir, const char *boot_file, const char *core_file, const char *root, const char *dest, int must_embed, int force, - int fs_probe) + int fs_probe, int allow_floppy) { char *boot_path, *core_path, *core_path_dev, *core_path_dev_full; char *boot_img, *core_img; @@ -313,7 +313,7 @@ setup (const char *dir, /* If DEST_DRIVE is a hard disk, enable the workaround, which is for buggy BIOSes which don't pass boot drive correctly. Instead, they pass 0x00 or 0x01 even when booted from 0x80. */ - if (!grub_util_biosdisk_is_floppy (dest_dev->disk)) + if (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk)) /* Replace the jmp (2 bytes) with double nop's. */ *boot_drive_check = 0x9090; } @@ -678,6 +678,9 @@ static struct argp_option options[] = { N_("Do not probe for filesystems in DEVICE"), 0}, {"verbose", 'v', 0, 0, N_("Print verbose messages."), 0}, + {"allow-floppy", 'a', 0, 0, + N_("Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0}, + { 0, 0, 0, 0, 0, 0 } }; @@ -712,6 +715,7 @@ struct arguments char *root_dev; int force; int fs_probe; + int allow_floppy; char *device; }; @@ -737,6 +741,10 @@ argp_parser (int key, char *arg, struct argp_state *state) switch (key) { + case 'a': + arguments->allow_floppy = 1; + break; + case 'b': if (arguments->boot_file) free (arguments->boot_file); @@ -950,7 +958,8 @@ main (int argc, char *argv[]) arguments.boot_file ? : DEFAULT_BOOT_FILE, arguments.core_file ? : DEFAULT_CORE_FILE, root_dev, grub_util_get_grub_dev (devicelist[i]), 1, - arguments.force, arguments.fs_probe); + arguments.force, arguments.fs_probe, + arguments.allow_floppy); } } else @@ -959,7 +968,8 @@ main (int argc, char *argv[]) setup (arguments.dir ? : DEFAULT_DIRECTORY, arguments.boot_file ? : DEFAULT_BOOT_FILE, arguments.core_file ? : DEFAULT_CORE_FILE, - root_dev, dest_dev, must_embed, arguments.force, arguments.fs_probe); + root_dev, dest_dev, must_embed, arguments.force, + arguments.fs_probe, arguments.allow_floppy); /* Free resources. */ grub_fini_all (); From ba5f65cfa17f410e6cb61e2b3ad858fcc1d0804a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 00:38:57 +0200 Subject: [PATCH 64/75] * docs/grub.texi (Installation): Indent. --- ChangeLog | 4 ++++ docs/grub.texi | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4e0d4a81e..805f8326d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-10-17 Vladimir Serbinenko + + * docs/grub.texi (Installation): Indent. + 2010-10-17 Vladimir Serbinenko * util/grub-setup.c (setup): New parameter allow_floppy. diff --git a/docs/grub.texi b/docs/grub.texi index 1bf652e15..9a457a073 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -559,7 +559,12 @@ always. Therefore, GRUB provides you with a map file called the @dfn{device map}, which you must fix if it is wrong. @xref{Device map}, for more details. -On BIOS platforms GRUB has to use a so called embedding zone. On msdos partition tables it's the space between MBR and first partition (called MBR gap), on GPT partition it uses a BIOS Boot Partition (a partition having type 21686148-6449-6e6f-744e656564454649). If you use GRUB on BIOS be sure to supply at least 31 KiB of embedding zone (512KiB or more recommended). +On BIOS platforms GRUB has to use a so called embedding zone. On msdos +partition tables it's the space between MBR and first partition (called +MBR gap), on GPT partition it uses a BIOS Boot Partition (a partition +having type 21686148-6449-6e6f-744e656564454649). If you use GRUB on +BIOS be sure to supply at least 31 KiB of embedding zone (512KiB or more +recommended). If you still do want to install GRUB under a UNIX-like OS (such as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking From 5b0276902e71aee083eafc8b705b00da704d2498 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 00:46:39 +0200 Subject: [PATCH 65/75] * docs/grub.texi (Installation): Document buggy BIOS install. --- ChangeLog | 4 ++++ docs/grub.texi | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 805f8326d..fbd4b2752 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-10-17 Vladimir Serbinenko + + * docs/grub.texi (Installation): Document buggy BIOS install. + 2010-10-17 Vladimir Serbinenko * docs/grub.texi (Installation): Indent. diff --git a/docs/grub.texi b/docs/grub.texi index 9a457a073..a04e31605 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -617,6 +617,19 @@ installation. The format is defined in @ref{Device map}. Please be quite careful. If the output is wrong, it is unlikely that your computer will be able to boot with no problem. +Some BIOSes have a bug of exposing first partition of USB pendrive as a floppy +instead of exposing pendrive as a hard disk (they call it ``USB-FDD'' boot) +In such cases you need to install as following: + +@example +# @kbd{losetup /dev/loop0 /dev/sdb1} +# @kbd{mount /dev/loop0 /mnt/usb} +# @kbd{grub-install --boot-directory=/mnt/usb/bugbios --force --allow-floppy /dev/loop0} +@end example + +This install doesn't conflict with standard install as long as they are in +separate directories. + Note that @command{grub-install} is actually just a shell script and the real task is done by @command{grub-mkimage} and @command{grub-setup}. Therefore, you may run those commands directly to install GRUB, without From 7bced4583e072271583ba2ee28f054dd025ec152 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 01:49:06 +0200 Subject: [PATCH 66/75] * grub-core/kern/i386/pc/startup.S (grub_console_setcursor): Check cursor shape for sanity. --- ChangeLog | 5 +++++ grub-core/kern/i386/pc/startup.S | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index fbd4b2752..128c5f959 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-17 Vladimir Serbinenko + + * grub-core/kern/i386/pc/startup.S (grub_console_setcursor): Check + cursor shape for sanity. + 2010-10-17 Vladimir Serbinenko * docs/grub.texi (Installation): Document buggy BIOS install. diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index e03fc8301..6b43d9f14 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -820,6 +820,10 @@ FUNCTION(grub_console_setcursor) DATA32 call real_to_prot .code32 + cmp %cl, %ch + jb 3f + movw $0x0d0e, %cx +3: movw %cx, console_cursor_shape 1: /* set %cx to the designated cursor shape */ From d82df574cda02226b9f0f444cda920a5e613bce4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 17 Oct 2010 02:08:08 +0200 Subject: [PATCH 67/75] * docs/grub.texi (GNU/Linux): Document APM unavailability with 32-bit linux protocol. --- ChangeLog | 5 +++++ docs/grub.texi | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 128c5f959..ddebabefc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-17 Vladimir Serbinenko + + * docs/grub.texi (GNU/Linux): Document APM unavailability with + 32-bit linux protocol. + 2010-10-17 Vladimir Serbinenko * grub-core/kern/i386/pc/startup.S (grub_console_setcursor): Check diff --git a/docs/grub.texi b/docs/grub.texi index a04e31605..751dd9dc2 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -895,6 +895,14 @@ grub> @kbd{linux /vmlinuz root=/dev/sda1 acpi=off} See the documentation in the Linux source tree for complete information on the available options. +With @command{linux} GRUB uses 32-bit protocol. Some BIOS services like APM +or EDD aren't available with this protocol. In this case you need to use +@command{linux16} + +@example +grub> @kbd{linux16 /vmlinuz root=/dev/sda1 acpi=off} +@end example + @item If you use an initrd, execute the command @command{initrd} (@pxref{initrd}) after @command{linux}: @@ -903,6 +911,12 @@ after @command{linux}: grub> @kbd{initrd /initrd} @end example +If you used @command{linux16} you need to use @command{initrd16}: + +@example +grub> @kbd{initrd16 /initrd} +@end example + @item Finally, run the command @command{boot} (@pxref{boot}). @end enumerate From 800e6a9be56dcf3e0cc496d7edfbc5c68afbd935 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 17 Oct 2010 15:41:54 +0200 Subject: [PATCH 68/75] * grub-core/normal/auth.c (grub_auth_check_authentication): Set-but-not-used variable removed. --- ChangeLog | 5 +++++ grub-core/normal/auth.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddebabefc..0f75bc762 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-17 Szymon Janc + + * grub-core/normal/auth.c (grub_auth_check_authentication): + Set-but-not-used variable removed. + 2010-10-17 Vladimir Serbinenko * docs/grub.texi (GNU/Linux): Document APM unavailability with diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c index 459d4cdbd..e5d187f0e 100644 --- a/grub-core/normal/auth.c +++ b/grub-core/normal/auth.c @@ -201,7 +201,6 @@ grub_auth_check_authentication (const char *userlist) { char login[1024]; struct grub_auth_user *cur = NULL; - grub_err_t err; static unsigned long punishment_delay = 1; char entered[GRUB_AUTH_MAX_PASSLEN]; struct grub_auth_user *user; @@ -233,7 +232,7 @@ grub_auth_check_authentication (const char *userlist) if (!cur || ! cur->callback) goto access_denied; - err = cur->callback (login, entered, cur->arg); + cur->callback (login, entered, cur->arg); if (is_authenticated (userlist)) { punishment_delay = 1; From 6351c13140046cb9de35f293f6f6f235d1f17bd2 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 18 Oct 2010 13:38:42 +0530 Subject: [PATCH 69/75] fix built-in initramfs case --- util/grub.d/10_linux.in | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index e37bab21b..ceee61154 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -127,10 +127,20 @@ while [ "x$list" != "x" ] ; do break fi done + + initramfs= + for i in "config-${version}" "config-${alt_version}"; do + if test -e "${dirname}/${i}" ; then + initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"` + break + fi + done + if test -n "${initrd}" ; then echo "Found initrd image: ${dirname}/${initrd}" >&2 - else - # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here. + elif test -z "${initramfs}" ; then + # "UUID=" magic is parsed by initrd or initramfs. Since there's + # no initrd or builtin initramfs, it can't work here. linux_root_device_thisversion=${GRUB_DEVICE} fi From 05f43cdd03235e140f42bbbbfe293c0a66b79bf4 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 18 Oct 2010 13:41:00 +0530 Subject: [PATCH 70/75] add change log entry --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0f75bc762..a41f8563e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-18 BVK Chaitanya + + * util/grub.d/10_linux.in: Fix built-in initramfs image mode for + Linux kernel, reported by Dennis Schridde. + 2010-10-17 Szymon Janc * grub-core/normal/auth.c (grub_auth_check_authentication): From b65ea1551499ec6ed900e57ac1bcdad80ebf3164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Mon, 18 Oct 2010 22:50:01 +0200 Subject: [PATCH 71/75] Make mktemp invocations portable. --- ChangeLog | 16 ++++++++++++++++ Makefile.am | 16 ++++++++-------- grub-core/genmod.sh.in | 4 ++-- tests/grub_script_blockarg.in | 2 +- tests/partmap_test.in | 4 ++-- tests/util/grub-shell-tester.in | 6 +++--- tests/util/grub-shell.in | 12 ++++++------ util/grub-mkrescue.in | 20 ++++++-------------- util/powerpc/ieee1275/grub-mkrescue.in | 4 ++-- 9 files changed, 46 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index a41f8563e..1ded89247 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-10-18 GrĂ©goire Sutre + + Make mktemp invocations portable. + + * grub-core/genmod.sh.in: Use mktemp with an explicit template, and + exit if mktemp fails. + * tests/grub_script_blockarg.in: Likewise. + * tests/partmap_test.in: Likewise. + * tests/util/grub-shell-tester.in: Likewise. + * tests/util/grub-shell.in: Likewise. + * util/powerpc/ieee1275/grub-mkrescue.in: Likewise. + * Makefile.am: Likewise, and chain shell commands with `&&' + instead of ';'. + * util/grub-mkrescue.in: Use the same explicit template as above, and + exit if mktemp fails. + 2010-10-18 BVK Chaitanya * util/grub.d/10_linux.in: Fix built-in initramfs image mode for diff --git a/Makefile.am b/Makefile.am index 931ea02e8..15dae9642 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,31 +189,31 @@ kopenbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux-initramfs.i386: linux.init.i386 Makefile - TDIR=`mktemp -d`; cp $< $$TDIR/init; (cd $$TDIR; echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@; rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.x86_64: linux.init.x86_64 Makefile - TDIR=`mktemp -d`; cp $< $$TDIR/init; (cd $$TDIR; echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@; rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR kfreebsd-mfsroot.i386.img: kfreebsd.init.i386 Makefile - TDIR=`mktemp -d`; mkdir $$TDIR/dev; mkdir $$TDIR/sbin; cp $< $$TDIR/sbin/init; makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR; rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR knetbsd.image.i386: knetbsd.init.i386 $(srcdir)/grub-core/tests/boot/kbsd.spec.txt - TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR kopenbsd.image.i386: kopenbsd.init.i386 $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt - TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@ + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@ kopenbsd.image.x86_64: kopenbsd.init.x86_64 $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt - TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@ + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@ knetbsd.miniroot-image.i386.img: knetbsd.image.i386 $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.i386 $(OBJCOPY) --add-section=miniroot=$< $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.i386 $@ kfreebsd-mfsroot.x86_64.img: kfreebsd.init.x86_64 Makefile - TDIR=`mktemp -d`; mkdir $$TDIR/dev; mkdir $$TDIR/sbin; cp $< $$TDIR/sbin/init; makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR; rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR knetbsd.image.x86_64: knetbsd.init.x86_64 $(srcdir)/grub-core/tests/boot/kbsd.spec.txt - TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR knetbsd.miniroot-image.x86_64.img: knetbsd.image.x86_64 $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.x86_64 $(OBJCOPY) --add-section=miniroot=$< $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.x86_64 $@ diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index faac2b605..8dfd5d347 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -38,10 +38,10 @@ rm -f $tmpfile $outfile objcopy -R .modname -R .moddeps $infile $tmpfile # Attach .modname and .moddeps sections -t1=`mktemp` +t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 printf "$modname\0" >$t1 -t2=`mktemp` +t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 for dep in $deps; do printf "$dep\0" >> $t2; done if test -n "$deps"; then diff --git a/tests/grub_script_blockarg.in b/tests/grub_script_blockarg.in index 783cee8e0..2765b61ac 100644 --- a/tests/grub_script_blockarg.in +++ b/tests/grub_script_blockarg.in @@ -27,7 +27,7 @@ cmd='test_blockarg { true }' v=`echo "$cmd" | @builddir@/grub-shell` error_if_not "$v" '{ true }' -tmp=`mktemp` +tmp=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cmd='test_blockarg { test_blockarg { true } }' echo "$cmd" | @builddir@/grub-shell >$tmp error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { true } }' diff --git a/tests/partmap_test.in b/tests/partmap_test.in index 14897e9da..5a9c1a93d 100644 --- a/tests/partmap_test.in +++ b/tests/partmap_test.in @@ -51,8 +51,8 @@ list_parts () { echo } -imgfile=`mktemp` -outfile=`mktemp` +imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +outfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 # # MSDOS partition types diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index ed34a5e17..02e49d3a4 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -83,17 +83,17 @@ for option in "$@"; do done if [ "x${source}" = x ] ; then - tmpfile=`mktemp` + tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 while read REPLY; do echo $REPLY >> ${tmpfile} done source=${tmpfile} fi -outfile1=`mktemp` +outfile1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 @builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1} -outfile2=`mktemp` +outfile2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 bash ${source} >${outfile2} if ! diff -q ${outfile1} ${outfile2} >/dev/null diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index c8247d29d..fc14ca7b0 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -107,14 +107,14 @@ for option in "$@"; do done if [ "x${source}" = x ] ; then - tmpfile=`mktemp` + tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 while read REPLY; do echo "$REPLY" >> ${tmpfile} done source=${tmpfile} fi -cfgfile=`mktemp` +cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cat <${cfgfile} grubshell=yes insmod serial @@ -123,7 +123,7 @@ terminal_input serial terminal_output serial EOF -rom_directory=`mktemp -d` +rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 for mod in ${modules} do @@ -135,7 +135,7 @@ source /boot/grub/testcase.cfg halt EOF -isofile=`mktemp` +isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 if [ x$boot != xnet ]; then sh @builddir@/grub-mkrescue --grub-mkimage=${builddir}/grub-mkimage --output=${isofile} --override-directory=${builddir}/grub-core \ --rom-directory="${rom_directory}" \ @@ -161,7 +161,7 @@ if [ x$boot = xqemu ]; then fi if [ x$boot = xcoreboot ]; then - imgfile=`mktemp` + imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cp "${GRUB_COREBOOT_ROM}" "${imgfile}" "${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload bootdev="-bios ${imgfile}" @@ -169,7 +169,7 @@ if [ x$boot = xcoreboot ]; then fi if [ x$boot = xnet ]; then - netdir=`mktemp -d` + netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 sh @builddir@/grub-mknetdir --grub-mkimage=${builddir}/grub-mkimage --override-directory=${builddir}/grub-core --net-directory=$netdir cp ${cfgfile} $netdir/boot/grub/grub.cfg cp ${source} $netdir/boot/grub/testcase.cfg diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index f2714c486..690bddb30 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -152,15 +152,7 @@ else exit 1 fi -if test "x$TMP" != x; then - MKTEMP_TEMPLATE="$TMP/grub-mkrescue.XXXXXXXXXX" -elif test "x$TEMP" != x; then - MKTEMP_TEMPLATE="$TEMP/grub-mkrescue.XXXXXXXXXX" -else - MKTEMP_TEMPLATE="/tmp/grub-mkrescue.XXXXXXXXXX" -fi - -iso9660_dir=`mktemp -d "$MKTEMP_TEMPLATE"` +iso9660_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 mkdir -p ${iso9660_dir}/boot/grub process_input_dir () @@ -197,8 +189,8 @@ make_image () echo "Enabling $2 support ..." - memdisk_img=`mktemp "$MKTEMP_TEMPLATE"` - memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"` + memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 mkdir -p ${memdisk_dir}/boot/grub cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg @@ -263,12 +255,12 @@ grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${i # build BIOS core.img if test -e "${pc_dir}" ; then echo "Enabling BIOS support ..." - core_img=`mktemp "$MKTEMP_TEMPLATE"` + core_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 $grub_mkimage -O i386-pc -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \ iso9660 biosdisk cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img - embed_img=`mktemp "$MKTEMP_TEMPLATE"` + embed_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cat ${pc_dir}/boot.img ${core_img} > ${embed_img} rm -f ${core_img} @@ -287,7 +279,7 @@ fi make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard" if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then - efi_dir=`mktemp -d "$MKTEMP_TEMPLATE"` + efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 mkdir -p "${efi_dir}/efi/boot" # build bootx64.efi diff --git a/util/powerpc/ieee1275/grub-mkrescue.in b/util/powerpc/ieee1275/grub-mkrescue.in index aefedff3f..d688431c3 100644 --- a/util/powerpc/ieee1275/grub-mkrescue.in +++ b/util/powerpc/ieee1275/grub-mkrescue.in @@ -121,13 +121,13 @@ if [ "x${modules}" = "x" ] ; then modules=`cd ${input_dir}/ && ls *.mod` fi -map_file=`mktemp` +map_file=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cat >${map_file} < Date: Fri, 22 Oct 2010 14:17:33 +0100 Subject: [PATCH 72/75] * docs/grub.texi (Installing GRUB using grub-install): Proofread. (Supported kernels): Likewise. --- ChangeLog | 5 +++++ docs/grub.texi | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ded89247..00ec9d6a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-22 Colin Watson + + * docs/grub.texi (Installing GRUB using grub-install): Proofread. + (Supported kernels): Likewise. + 2010-10-18 GrĂ©goire Sutre Make mktemp invocations portable. diff --git a/docs/grub.texi b/docs/grub.texi index 751dd9dc2..b37a5bfac 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -559,11 +559,12 @@ always. Therefore, GRUB provides you with a map file called the @dfn{device map}, which you must fix if it is wrong. @xref{Device map}, for more details. -On BIOS platforms GRUB has to use a so called embedding zone. On msdos -partition tables it's the space between MBR and first partition (called -MBR gap), on GPT partition it uses a BIOS Boot Partition (a partition -having type 21686148-6449-6e6f-744e656564454649). If you use GRUB on -BIOS be sure to supply at least 31 KiB of embedding zone (512KiB or more +On BIOS platforms GRUB has to use a so-called embedding zone. On msdos +partition tables, this is the space between the MBR and the first partition +(called the MBR gap or the boot track), while on GPT partition tables it +uses a BIOS Boot Partition (a partition with GUID +21686148-6449-6e6f-744e656564454649). If you use GRUB on a BIOS system, make +sure that the embedding zone is at least 31 KiB (512KiB or more recommended). If you still do want to install GRUB under a UNIX-like OS (such @@ -617,9 +618,9 @@ installation. The format is defined in @ref{Device map}. Please be quite careful. If the output is wrong, it is unlikely that your computer will be able to boot with no problem. -Some BIOSes have a bug of exposing first partition of USB pendrive as a floppy -instead of exposing pendrive as a hard disk (they call it ``USB-FDD'' boot) -In such cases you need to install as following: +Some BIOSes have a bug of exposing the first partition of a USB drive as a +floppy instead of exposing the USB drive as a hard disk (they call it +``USB-FDD'' boot). In such cases, you need to install like this: @example # @kbd{losetup /dev/loop0 /dev/sdb1} @@ -3295,7 +3296,7 @@ commands. @node Supported kernels @chapter Supported boot targets -X86 support is summarised in following table. ``Yes'' means that kernel works on the given platform, ``crashes'' means an early kernel crash which we hove will be fixed by concerned kernel developpers. ``no'' means GRUB doesn't load given kernel on a given platform. ``headless'' means that the kernel works but lacks console drivers (you can still use serial or network console). In case of ``no'' and ``crashes'' the reason is given in footnote. +X86 support is summarised in the following table. ``Yes'' means that the kernel works on the given platform, ``crashes'' means an early kernel crash which we hope will be fixed by concerned kernel developers. ``no'' means GRUB doesn't load the given kernel on a given platform. ``headless'' means that the kernel works but lacks console drivers (you can still use serial or network console). In case of ``no'' and ``crashes'' the reason is given in footnote. @multitable @columnfractions .50 .22 .22 @item @tab BIOS @tab Coreboot @item BIOS chainloading @tab yes @tab no (1) From e138c4583608b07376f1ce1bdc0aea88875adf3a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Oct 2010 22:49:36 +0200 Subject: [PATCH 73/75] * grub-core/lib/relocator.c (grub_relocator_subchunk): Remove now useless field head. All users updated. (free_subchunk): Correct handling of IN_REGION subchunk. --- ChangeLog | 6 ++++++ grub-core/lib/relocator.c | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00ec9d6a5..85ff4d088 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-10-22 Vladimir Serbinenko + + * grub-core/lib/relocator.c (grub_relocator_subchunk): Remove now + useless field head. All users updated. + (free_subchunk): Correct handling of IN_REGION subchunk. + 2010-10-22 Colin Watson * docs/grub.texi (Installing GRUB using grub-install): Proofread. diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index b1412e73a..90f6802d7 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -40,7 +40,6 @@ struct grub_relocator_subchunk #endif } type; grub_mm_region_t reg; - grub_mm_header_t head; grub_phys_addr_t start; grub_size_t size; grub_size_t pre_size; @@ -355,11 +354,11 @@ free_subchunk (const struct grub_relocator_subchunk *subchu) } case CHUNK_TYPE_IN_REGION: { - grub_mm_header_t h = (grub_mm_header_t) ALIGN_DOWN ((grub_addr_t) subchu->head, + grub_mm_header_t h = (grub_mm_header_t) ALIGN_DOWN ((grub_addr_t) subchu->start, GRUB_MM_ALIGN); h->size = ((subchu->start + subchu->size + GRUB_MM_ALIGN - 1) / GRUB_MM_ALIGN) - - (subchu->start / GRUB_MM_ALIGN); + - (subchu->start / GRUB_MM_ALIGN) - 1; h->next = h; h->magic = GRUB_MM_ALLOC_MAGIC; grub_free (h + 1); @@ -971,7 +970,6 @@ malloc_in_range (struct grub_relocator *rel, || typepre == CHUNK_TYPE_IN_REGION) { curschu->reg = events[last_start].reg; - curschu->head = events[last_start].head; curschu->pre_size = alloc_start - events[j - 1].pos; } if (!oom && (typepre == CHUNK_TYPE_REGION_START From 5c81f8b349e4844d65d5b1717a1ebe61defd6062 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Oct 2010 20:34:50 +0200 Subject: [PATCH 74/75] * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Revert r2882. --- ChangeLog | 5 +++++ grub-core/kern/emu/misc.c | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85ff4d088..bdeb62500 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-22 Vladimir Serbinenko + + * grub-core/kern/emu/misc.c + (grub_make_system_path_relative_to_its_root): Revert r2882. + 2010-10-22 Vladimir Serbinenko * grub-core/lib/relocator.c (grub_relocator_subchunk): Remove now diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index cfc143bf9..d8db3be9d 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -406,7 +406,21 @@ grub_make_system_path_relative_to_its_root (const char *path) /* buf is another filesystem; we found it. */ if (st.st_dev != num) - break; + { + /* offset == 0 means path given is the mount point. + This works around special-casing of "/" in Un*x. This function never + prints trailing slashes (so that its output can be appended a slash + unconditionally). Each slash in is considered a preceding slash, and + therefore the root directory is an empty string. */ + if (offset == 0) + { + free (buf); + free (buf2); + return xstrdup (""); + } + else + break; + } offset = p - buf; /* offset == 1 means root directory. */ @@ -434,10 +448,7 @@ grub_make_system_path_relative_to_its_root (const char *path) } #endif - /* This works around special-casing of "/" in Un*x. This function never - prints trailing slashes (so that its output can be appended a slash - unconditionally). Each slash in it is considered a preceding slash, - and therefore the root directory is an empty string. */ + /* Remove trailing slashes, return empty string if root directory. */ len = strlen (buf3); while (len > 0 && buf3[len - 1] == '/') { From 4f6a2e217510c7fa0fb663418838cbbb632c3634 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Oct 2010 20:39:08 +0200 Subject: [PATCH 75/75] * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root) [HAVE_LIBZFS && HAVE_LIBNVPAIR]: Fix mountpoint return on ZFS. --- ChangeLog | 8 +++++++- grub-core/kern/emu/misc.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bdeb62500..fe368aa57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -2010-10-22 Vladimir Serbinenko +2010-10-23 Vladimir Serbinenko + + * grub-core/kern/emu/misc.c + (grub_make_system_path_relative_to_its_root) + [HAVE_LIBZFS && HAVE_LIBNVPAIR]: Fix mountpoint return on ZFS. + +2010-10-23 Vladimir Serbinenko * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Revert r2882. diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index d8db3be9d..c8b95443b 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -416,6 +416,10 @@ grub_make_system_path_relative_to_its_root (const char *path) { free (buf); free (buf2); +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (poolfs) + return xasprintf ("/%s/@", poolfs); +#endif return xstrdup (""); } else