merge mainline into cbi
This commit is contained in:
commit
d68538e928
699 changed files with 77518 additions and 15443 deletions
|
@ -1,4 +1,4 @@
|
|||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
AUTOMAKE_OPTIONS = subdir-objects -Wno-portability
|
||||
|
||||
DEPDIR=.deps-core
|
||||
|
||||
|
@ -30,7 +30,7 @@ CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
|
|||
|
||||
# gentrigtables
|
||||
gentrigtables: gentrigtables.c
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(CPPFLAGS) -lm $<
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(CPPFLAGS) $< -lm
|
||||
CLEANFILES += gentrigtables
|
||||
|
||||
# trigtables.c
|
||||
|
@ -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 -mregparm=3
|
||||
$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3
|
||||
|
||||
kern/i386/pc/startup.S: $(builddir)/rs_decoder.S
|
||||
|
||||
|
@ -78,12 +78,11 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
|
||||
|
||||
if COND_i386_pc
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loader.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
|
||||
|
@ -99,10 +98,12 @@ endif
|
|||
|
||||
if COND_i386_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h
|
||||
endif
|
||||
|
||||
if COND_i386_multiboot
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h
|
||||
endif
|
||||
|
||||
if COND_i386_qemu
|
||||
|
@ -125,7 +126,39 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h
|
||||
endif
|
||||
|
||||
if COND_mips_yeeloong
|
||||
if COND_ia64_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
endif
|
||||
|
||||
if COND_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h
|
||||
endif
|
||||
|
||||
if COND_mips_arc
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h
|
||||
endif
|
||||
|
||||
if COND_mips_qemu_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/cache.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap_scale.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.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_mips_loongson
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/cache.h
|
||||
|
@ -145,6 +178,11 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
|
||||
endif
|
||||
|
||||
if COND_mips_qemu_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.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
|
||||
|
@ -163,6 +201,7 @@ endif
|
|||
if COND_emu
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.h
|
||||
if COND_GRUB_EMU_SDL
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
|
||||
endif
|
||||
|
@ -237,9 +276,9 @@ command.lst: $(MARKER_FILES)
|
|||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" \
|
||||
-e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
|
||||
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" $$pp; \
|
||||
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
|
||||
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += command.lst
|
||||
CLEANFILES += command.lst
|
||||
|
@ -303,8 +342,9 @@ platform_DATA += moddep.lst
|
|||
CLEANFILES += config.log syminfo.lst moddep.lst
|
||||
|
||||
$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT)
|
||||
sh $^ $@
|
||||
TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
|
||||
platform_DATA += $(MOD_FILES)
|
||||
platform_DATA += modinfo.sh
|
||||
CLEANFILES += $(MOD_FILES)
|
||||
|
||||
if COND_ENABLE_EFIEMU
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,6 +25,9 @@ grub_decompress_core (void *src, void *dest, unsigned long n,
|
|||
char *d = (char *) dest;
|
||||
const char *s = (const char *) src;
|
||||
|
||||
if (d == s)
|
||||
return;
|
||||
|
||||
if (d < s)
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
|
||||
/*
|
||||
|
@ -459,6 +458,8 @@ fd_probe_error_string: .asciz "Floppy"
|
|||
1:
|
||||
/* perform read */
|
||||
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
|
||||
movw %bx, %es
|
||||
xorw %bx, %bx
|
||||
movw $0x201, %ax
|
||||
movb $0, %ch
|
||||
movb $0, %dh
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <multiboot.h>
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <multiboot.h>
|
||||
|
@ -178,15 +177,21 @@ real_code_2:
|
|||
pushw %es
|
||||
popw %ds
|
||||
|
||||
movl $0x200, %ecx
|
||||
addl %ecx, %esi
|
||||
movl $0x1000, %ecx
|
||||
addl $0x200, %esi
|
||||
movl $DATA_ADDR, %edi
|
||||
|
||||
call LOCAL(move_memory)
|
||||
|
||||
/* Check for multiboot signature. */
|
||||
cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART)
|
||||
movl $DATA_ADDR, %edi
|
||||
3:
|
||||
movl %ss:(%edi), %eax
|
||||
cmpl $MULTIBOOT_HEADER_MAGIC, %eax
|
||||
jz 1f
|
||||
addl $4, %edi
|
||||
cmpl $(DATA_ADDR + 0x1000), %edi
|
||||
jne 3b
|
||||
|
||||
movl (ramdisk_image - start), %esi
|
||||
movl (ramdisk_size - start), %ecx
|
||||
|
@ -195,17 +200,13 @@ real_code_2:
|
|||
|
||||
1:
|
||||
|
||||
movl %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE), %ecx
|
||||
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx
|
||||
movl $(DATA_ADDR + 0x1000), %edi
|
||||
movl %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE), %ecx
|
||||
addl $GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE, %ecx
|
||||
|
||||
2:
|
||||
call LOCAL(move_memory)
|
||||
|
||||
movsbl %dh, %eax
|
||||
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)
|
||||
movsbl (reg_edx + 2 - start), %eax
|
||||
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
|
||||
|
||||
movb $0xFF, %dh
|
||||
|
||||
ljmp $(DATA_ADDR >> 4), $0
|
||||
|
|
354
grub-core/boot/i386/pc/startup_raw.S
Normal file
354
grub-core/boot/i386/pc/startup_raw.S
Normal file
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009,2011 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
|
||||
#define ABS(x) ((x) - LOCAL (base) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
|
||||
|
||||
.file "startup_raw.S"
|
||||
|
||||
.text
|
||||
|
||||
/* Tell GAS to generate 16-bit instructions so that this code works
|
||||
in real mode. */
|
||||
.code16
|
||||
|
||||
.globl start, _start
|
||||
start:
|
||||
_start:
|
||||
LOCAL (base):
|
||||
/*
|
||||
* Guarantee that "main" is loaded at 0x0:0x8200.
|
||||
*/
|
||||
#ifdef __APPLE__
|
||||
ljmp $0, $(ABS(LOCAL (codestart)) - 0x10000)
|
||||
#else
|
||||
ljmp $0, $ABS(LOCAL (codestart))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a special data area.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE
|
||||
LOCAL(compressed_size):
|
||||
.long 0
|
||||
. = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE
|
||||
LOCAL(uncompressed_size):
|
||||
.long 0
|
||||
|
||||
. = _start + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY
|
||||
reed_solomon_redundancy:
|
||||
.long 0
|
||||
. = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH
|
||||
.short (LOCAL(reed_solomon_part) - _start)
|
||||
|
||||
/*
|
||||
* This is the area for all of the special variables.
|
||||
*/
|
||||
. = _start + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE
|
||||
LOCAL(boot_dev):
|
||||
.byte 0xFF, 0xFF, 0xFF
|
||||
LOCAL(boot_drive):
|
||||
.byte 0x00
|
||||
|
||||
/* 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, LOCAL(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
|
||||
cld
|
||||
call grub_gate_a20
|
||||
|
||||
movl LOCAL(compressed_size), %edx
|
||||
addl $(LOCAL(decompressor_end) - LOCAL(reed_solomon_part)), %edx
|
||||
movl reed_solomon_redundancy, %ecx
|
||||
leal LOCAL(reed_solomon_part), %eax
|
||||
cld
|
||||
call EXT_C (grub_reed_solomon_recover)
|
||||
jmp post_reed_solomon
|
||||
|
||||
#include "../../../kern/i386/realmode.S"
|
||||
|
||||
#include <rs_decoder.S>
|
||||
|
||||
.text
|
||||
|
||||
/*
|
||||
* grub_gate_a20(int on)
|
||||
*
|
||||
* Gate address-line 20 for high memory.
|
||||
*
|
||||
* This routine is probably overconservative in what it does, but so what?
|
||||
*
|
||||
* It also eats any keystrokes in the keyboard buffer. :-(
|
||||
*/
|
||||
|
||||
grub_gate_a20:
|
||||
movl %eax, %edx
|
||||
|
||||
gate_a20_test_current_state:
|
||||
/* first of all, test if already in a good state */
|
||||
call gate_a20_check_state
|
||||
cmpb %al, %dl
|
||||
jnz gate_a20_try_bios
|
||||
ret
|
||||
|
||||
gate_a20_try_bios:
|
||||
/* second, try a BIOS call */
|
||||
pushl %ebp
|
||||
call prot_to_real
|
||||
|
||||
.code16
|
||||
movw $0x2400, %ax
|
||||
testb %dl, %dl
|
||||
jz 1f
|
||||
incw %ax
|
||||
1: int $0x15
|
||||
|
||||
DATA32 call real_to_prot
|
||||
.code32
|
||||
|
||||
popl %ebp
|
||||
call gate_a20_check_state
|
||||
cmpb %al, %dl
|
||||
jnz gate_a20_try_system_control_port_a
|
||||
ret
|
||||
|
||||
gate_a20_try_system_control_port_a:
|
||||
/*
|
||||
* In macbook, the keyboard test would hang the machine, so we move
|
||||
* this forward.
|
||||
*/
|
||||
/* fourth, try the system control port A */
|
||||
inb $0x92
|
||||
andb $(~0x03), %al
|
||||
testb %dl, %dl
|
||||
jz 6f
|
||||
orb $0x02, %al
|
||||
6: outb $0x92
|
||||
|
||||
/* When turning off Gate A20, do not check the state strictly,
|
||||
because a failure is not fatal usually, and Gate A20 is always
|
||||
on some modern machines. */
|
||||
testb %dl, %dl
|
||||
jz 7f
|
||||
call gate_a20_check_state
|
||||
cmpb %al, %dl
|
||||
jnz gate_a20_try_keyboard_controller
|
||||
7: ret
|
||||
|
||||
gate_a20_flush_keyboard_buffer:
|
||||
inb $0x64
|
||||
andb $0x02, %al
|
||||
jnz gate_a20_flush_keyboard_buffer
|
||||
2:
|
||||
inb $0x64
|
||||
andb $0x01, %al
|
||||
jz 3f
|
||||
inb $0x60
|
||||
jmp 2b
|
||||
3:
|
||||
ret
|
||||
|
||||
gate_a20_try_keyboard_controller:
|
||||
/* third, try the keyboard controller */
|
||||
call gate_a20_flush_keyboard_buffer
|
||||
|
||||
movb $0xd1, %al
|
||||
outb $0x64
|
||||
4:
|
||||
inb $0x64
|
||||
andb $0x02, %al
|
||||
jnz 4b
|
||||
|
||||
movb $0xdd, %al
|
||||
testb %dl, %dl
|
||||
jz 5f
|
||||
orb $0x02, %al
|
||||
5: outb $0x60
|
||||
call gate_a20_flush_keyboard_buffer
|
||||
|
||||
/* output a dummy command (USB keyboard hack) */
|
||||
movb $0xff, %al
|
||||
outb $0x64
|
||||
call gate_a20_flush_keyboard_buffer
|
||||
|
||||
call gate_a20_check_state
|
||||
cmpb %al, %dl
|
||||
/* everything failed, so restart from the beginning */
|
||||
jnz gate_a20_try_bios
|
||||
ret
|
||||
|
||||
gate_a20_check_state:
|
||||
/* iterate the checking for a while */
|
||||
movl $100, %ecx
|
||||
1:
|
||||
call 3f
|
||||
cmpb %al, %dl
|
||||
jz 2f
|
||||
loop 1b
|
||||
2:
|
||||
ret
|
||||
3:
|
||||
pushl %ebx
|
||||
pushl %ecx
|
||||
xorl %eax, %eax
|
||||
/* compare the byte at 0x8000 with that at 0x108000 */
|
||||
movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx
|
||||
pushl %ebx
|
||||
/* save the original byte in CL */
|
||||
movb (%ebx), %cl
|
||||
/* store the value at 0x108000 in AL */
|
||||
addl $0x100000, %ebx
|
||||
movb (%ebx), %al
|
||||
/* try to set one less value at 0x8000 */
|
||||
popl %ebx
|
||||
movb %al, %ch
|
||||
decb %ch
|
||||
movb %ch, (%ebx)
|
||||
/* serialize */
|
||||
outb %al, $0x80
|
||||
outb %al, $0x80
|
||||
/* obtain the value at 0x108000 in CH */
|
||||
pushl %ebx
|
||||
addl $0x100000, %ebx
|
||||
movb (%ebx), %ch
|
||||
/* this result is 1 if A20 is on or 0 if it is off */
|
||||
subb %ch, %al
|
||||
xorb $1, %al
|
||||
/* restore the original */
|
||||
popl %ebx
|
||||
movb %cl, (%ebx)
|
||||
popl %ecx
|
||||
popl %ebx
|
||||
ret
|
||||
|
||||
LOCAL(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,
|
||||
* and relocates itself after loaded.
|
||||
*/
|
||||
.p2align 2 /* force 4-byte alignment */
|
||||
multiboot_header:
|
||||
/* magic */
|
||||
.long 0x1BADB002
|
||||
/* flags */
|
||||
.long (1 << 16)
|
||||
/* checksum */
|
||||
.long -0x1BADB002 - (1 << 16)
|
||||
/* header addr */
|
||||
.long multiboot_header - _start + 0x100000 + 0x200
|
||||
/* load addr */
|
||||
.long 0x100000
|
||||
/* load end addr */
|
||||
.long 0
|
||||
/* bss end addr */
|
||||
.long 0
|
||||
/* entry addr */
|
||||
.long multiboot_entry - _start + 0x100000 + 0x200
|
||||
|
||||
multiboot_entry:
|
||||
.code32
|
||||
/* obtain the boot device */
|
||||
movl 12(%ebx), %edx
|
||||
|
||||
movl $GRUB_MEMORY_MACHINE_PROT_STACK, %ebp
|
||||
movl %ebp, %esp
|
||||
|
||||
/* relocate the code */
|
||||
movl $(LOCAL(decompressor_end) + 0x200), %ecx
|
||||
addl LOCAL(compressed_size) - _start + 0x100000 + 0x200, %ecx
|
||||
movl $0x100000, %esi
|
||||
movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi
|
||||
cld
|
||||
rep
|
||||
movsb
|
||||
/* jump to the real address */
|
||||
movl $multiboot_trampoline, %eax
|
||||
jmp *%eax
|
||||
|
||||
multiboot_trampoline:
|
||||
/* fill the boot information */
|
||||
movl %edx, LOCAL(boot_dev)
|
||||
shrl $24, %edx
|
||||
/* enter the usual booting */
|
||||
call prot_to_real
|
||||
.code16
|
||||
jmp LOCAL (codestart)
|
||||
.code32
|
||||
|
||||
post_reed_solomon:
|
||||
|
||||
#ifdef ENABLE_LZMA
|
||||
movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
|
||||
movl $LOCAL(decompressor_end), %esi
|
||||
pushl %edi
|
||||
movl LOCAL (uncompressed_size), %ecx
|
||||
leal (%edi, %ecx), %ebx
|
||||
/* Don't remove this push: it's an argument. */
|
||||
push %ecx
|
||||
call _LzmaDecodeA
|
||||
pop %ecx
|
||||
/* _LzmaDecodeA clears DF, so no need to run cld */
|
||||
popl %esi
|
||||
#endif
|
||||
|
||||
movl LOCAL(boot_dev), %edx
|
||||
movl $prot_to_real, %edi
|
||||
movl $real_to_prot, %ecx
|
||||
jmp *%esi
|
||||
|
||||
#ifdef ENABLE_LZMA
|
||||
#include "lzma_decode.S"
|
||||
#endif
|
||||
|
||||
.p2align 4
|
||||
|
||||
LOCAL(decompressor_end):
|
2
grub-core/boot/mips/loongson/fuloong2f.S
Normal file
2
grub-core/boot/mips/loongson/fuloong2f.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define FULOONG2F 1
|
||||
#include "fwstart.S"
|
|
@ -16,51 +16,73 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mips/yeeloong/serial.h>
|
||||
#include <grub/mips/yeeloong/pci.h>
|
||||
#include <grub/mips/loongson/serial.h>
|
||||
#include <grub/mips/loongson/pci.h>
|
||||
#include <grub/mips/loongson.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/machine/serial.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/ns8250.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/smbus.h>
|
||||
|
||||
#ifdef FULOONG2F
|
||||
#define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2
|
||||
#define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200
|
||||
#else
|
||||
#define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT0
|
||||
#define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200
|
||||
#endif
|
||||
|
||||
.set noreorder
|
||||
.set noat
|
||||
.set nomacro
|
||||
.set mips3
|
||||
|
||||
.global start,_start,__start
|
||||
start:
|
||||
_start:
|
||||
__start:
|
||||
/* Put serial init as soon as possible. But on Fuloong2f serial is past
|
||||
Geode, so on Fuloong2f we need Geode first.
|
||||
*/
|
||||
#ifndef FULOONG2F
|
||||
bal serial_hw_init
|
||||
nop
|
||||
#endif
|
||||
|
||||
/* Find CS5536 controller. */
|
||||
/* $t4 chooses device in priority encoding. */
|
||||
/* Resulting value is kept in GRUB_MACHINE_PCI_CONF_CTRL_REG.
|
||||
This way we don't need to sacrifice a register for it. */
|
||||
retry_cs5536:
|
||||
/* We have only one bus (0). Function is 0. */
|
||||
lui $t0, %hi(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR)
|
||||
lui $t1, %hi(GRUB_MACHINE_PCI_CONFSPACE)
|
||||
lui $t3, %hi(GRUB_CS5536_PCIID)
|
||||
addiu $t3, $t3, %lo(GRUB_CS5536_PCIID)
|
||||
ori $t4, $zero, 1
|
||||
lui $a0, %hi(no_cs5536)
|
||||
1:
|
||||
andi $t4, $t4, ((1 << GRUB_PCI_NUM_DEVICES) - 1)
|
||||
beql $t4, $zero, fatal
|
||||
addiu $a0, $a0, %lo(no_cs5536)
|
||||
/* In case of failure try again. CS5536 may be slow to come up. */
|
||||
beql $t4, $zero, retry_cs5536
|
||||
nop
|
||||
sw $t4, %lo(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) ($t0)
|
||||
lw $t2, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_PCI_REG_PCI_ID) ($t1)
|
||||
bnel $t2, $t3, 1b
|
||||
sll $t4, $t4, 1
|
||||
|
||||
#ifndef FULOONG2F
|
||||
bal message
|
||||
addiu $a0, $a0, %lo(cs5536_found)
|
||||
bal printhex
|
||||
move $a0, $t4
|
||||
#endif
|
||||
|
||||
/* Initialise SMBus controller. */
|
||||
lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE)
|
||||
li $t1, GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED
|
||||
sw $t1, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_CS5536_MSR_MAILBOX_CONFIG) ($t0)
|
||||
|
||||
/* Set GPIO LBAR. */
|
||||
lui $a0, %hi(GRUB_CS5536_MSR_GPIO_BAR)
|
||||
addiu $a0, $a0, %lo(GRUB_CS5536_MSR_GPIO_BAR)
|
||||
|
@ -70,6 +92,15 @@ __start:
|
|||
ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \
|
||||
| GRUB_CS5536_LBAR_ENABLE) >> 32)
|
||||
|
||||
bal gpio_init
|
||||
nop
|
||||
|
||||
#ifdef FULOONG2F
|
||||
bal serial_hw_init
|
||||
nop
|
||||
#endif
|
||||
|
||||
/* Initialise SMBus controller. */
|
||||
/* Set SMBUS LBAR. */
|
||||
lui $a0, %hi(GRUB_CS5536_MSR_SMB_BAR)
|
||||
addiu $a0, $a0, %lo(GRUB_CS5536_MSR_SMB_BAR)
|
||||
|
@ -83,14 +114,6 @@ __start:
|
|||
bal message
|
||||
addiu $a0, $a0, %lo(smbus_enabled)
|
||||
|
||||
/* Enable SMBus controller pins. */
|
||||
lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO)
|
||||
ori $t1, $zero, GRUB_GPIO_SMBUS_PINS
|
||||
sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_OUT_EN) ($t0)
|
||||
sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_OUT_AUX1) ($t0)
|
||||
sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_IN_EN) ($t0)
|
||||
sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_IN_AUX1) ($t0)
|
||||
|
||||
lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS)
|
||||
|
||||
/* Disable SMB. */
|
||||
|
@ -107,7 +130,7 @@ __start:
|
|||
sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL3) ($t0)
|
||||
sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL2) ($t0)
|
||||
|
||||
/* Yeeloong has only one memory slot. */
|
||||
/* Yeeloong and Fuloong2f have only one memory slot. */
|
||||
/* Output first byte on serial for debugging. */
|
||||
ori $a1, $zero, GRUB_SMB_RAM_START_ADDR
|
||||
bal read_spd
|
||||
|
@ -120,7 +143,7 @@ __start:
|
|||
ori $t0, $zero, GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2
|
||||
lui $a0, %hi(unimplemented_memory_type)
|
||||
bne $t0, $v0, fatal
|
||||
addiu $a0, $a0, %hi(unimplemented_memory_type)
|
||||
addiu $a0, $a0, %lo(unimplemented_memory_type)
|
||||
|
||||
/* And here is our goal: DDR2 controller initialisation. */
|
||||
lui $t0, %hi(GRUB_CPU_LOONGSON_CORECFG)
|
||||
|
@ -206,10 +229,54 @@ other_exception:
|
|||
b fatal
|
||||
addiu $a0, $a0, %lo(unhandled_exception)
|
||||
|
||||
gpio_init:
|
||||
lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO)
|
||||
addiu $t0, $t0, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO)
|
||||
lui $t1, %hi (gpio_dump)
|
||||
addiu $t1, $t1, %lo (gpio_dump)
|
||||
|
||||
1:
|
||||
lw $t2, 0($t1)
|
||||
sw $t2, 0($t0)
|
||||
addiu $t0, $t0, 4
|
||||
addiu $t1, $t1, 4
|
||||
lui $t2, %hi (gpio_dump_end)
|
||||
addiu $t2, $t2, %lo (gpio_dump_end)
|
||||
bne $t1, $t2, 1b
|
||||
nop
|
||||
jr $ra
|
||||
nop
|
||||
|
||||
/* Same as similarly named C function but in asm since
|
||||
we need it early. */
|
||||
/* In: none. Out: none. Clobbered: $t0, $t1, $a0. */
|
||||
/* In: none. Out: none. Clobbered: $t0, $t1, $t2, $a0, $a1, $a2. */
|
||||
serial_hw_init:
|
||||
move $t2, $ra
|
||||
#ifdef FULOONG2F
|
||||
lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_LEG_IO)
|
||||
addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_LEG_IO)
|
||||
lui $a1, %hi (GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 \
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP \
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 \
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1)
|
||||
ori $a1, $a1, (GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 \
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1)
|
||||
bal wrmsr
|
||||
move $a2, $zero
|
||||
|
||||
lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART1_CONF)
|
||||
addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART1_CONF)
|
||||
li $a1, 2
|
||||
bal wrmsr
|
||||
move $a2, $zero
|
||||
|
||||
lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART2_CONF)
|
||||
addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART2_CONF)
|
||||
li $a1, 2
|
||||
bal wrmsr
|
||||
move $a2, $zero
|
||||
#endif
|
||||
|
||||
lui $t0, %hi (GRUB_MACHINE_SERIAL_PORT)
|
||||
|
||||
/* Turn off the interrupt. */
|
||||
|
@ -239,6 +306,7 @@ serial_hw_init:
|
|||
/* Let message return to original caller. */
|
||||
lui $a0, %hi(notification_string)
|
||||
addiu $a0, $a0, %lo(notification_string)
|
||||
move $ra, $t2
|
||||
|
||||
/* Print message on serial console. */
|
||||
/* In: $a0 = asciiz message. Out: none. Clobbered: $t0, $t1, $a0. */
|
||||
|
@ -379,7 +447,6 @@ read_spd_fail:
|
|||
ori $v0, $v0, 0x100
|
||||
|
||||
notification_string: .asciz "GRUB "
|
||||
no_cs5536: .asciz "No CS5536 found.\n\r"
|
||||
cs5536_found: .asciz "CS5536 at "
|
||||
sm_failed: .asciz "SM transaction failed.\n\r"
|
||||
unhandled_tlb_refill: .asciz "Unhandled TLB refill.\n\r"
|
||||
|
@ -404,14 +471,22 @@ regdump:
|
|||
.quad 0x0100020200010101 /* 4 */
|
||||
.quad 0x0a04030603050203 /* 6 */
|
||||
.quad 0x0f0e040000010a0b /* 7 */
|
||||
#ifdef FULOONG2F
|
||||
.quad 0x0000000100000001 /* 8 */
|
||||
#else
|
||||
.quad 0x0000010200000102 /* 8 */
|
||||
#endif
|
||||
.quad 0x0000060c00000000 /* 9 */
|
||||
.quad 0x2323233f3f1f0200 /* a */
|
||||
.quad 0x5f7f232323232323 /* b */
|
||||
.quad 0x002a3c0615000000 /* c */
|
||||
.quad 0x002a002a002a002a /* d */
|
||||
.quad 0x002a002a002a002a /* e */
|
||||
#ifdef FULOONG2F
|
||||
.quad 0x00b40020005b0004 /* f */
|
||||
#else
|
||||
.quad 0x00b40020006d0004 /* f */
|
||||
#endif
|
||||
.quad 0x070007ff00000087 /* 10 */
|
||||
.quad 0x000000000016101f /* 11 */
|
||||
.quad 0x001c000000000000 /* 12 */
|
||||
|
@ -426,6 +501,45 @@ regdump:
|
|||
.quad 0 /* 1b */
|
||||
.quad 0 /* 1c */
|
||||
|
||||
/* Dump of GPIO connections. FIXME: Remove useless and macroify. */
|
||||
gpio_dump:
|
||||
#ifdef FULOONG2F
|
||||
.long 0xffff0000, 0x2eefd110, 0xffff0000, 0xffff0000
|
||||
.long 0x2eefd110, 0xffff0000, 0x1000efff, 0xefff1000
|
||||
.long 0x3df3c20c, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0x7df3820c, 0x3df3c20c, 0xffff0000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0x3de3c21c, 0x3d83c27c
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000
|
||||
.long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0xefff1000, 0xefff1000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
#else
|
||||
.long 0xffff0000, 0x2ffdd002, 0xffff0000, 0xffff0000
|
||||
.long 0x2fffd000, 0xffff0000, 0x1000efff, 0xefff1000
|
||||
.long 0x3ffbc004, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0x3ffbc004, 0x3ffbc004, 0xffff0000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0x3ffbc004, 0x3f9bc064
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000
|
||||
.long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000
|
||||
.long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000
|
||||
.long 0xffff0000, 0xffff0000, 0xefff1000, 0xffff0000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x00000000, 0x00000000, 0x00000000
|
||||
.long 0x00000000, 0x50000000, 0x00000000, 0x00000000
|
||||
#endif
|
||||
gpio_dump_end:
|
||||
|
||||
.p2align
|
||||
|
||||
write_dumpreg:
|
||||
|
@ -626,6 +740,10 @@ continue:
|
|||
lui $t0, %hi(cached_continue - 0x20000000)
|
||||
addiu $t0, $t0, %lo(cached_continue - 0x20000000)
|
||||
jr $t0
|
||||
addiu $a2, $zero, -1
|
||||
#ifdef FULOONG2F
|
||||
addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG2F)
|
||||
#else
|
||||
addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_YEELOONG)
|
||||
#endif
|
||||
|
||||
cached_continue:
|
||||
cached_continue:
|
|
@ -20,6 +20,7 @@
|
|||
#include <grub/symbol.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/offsets.h>
|
||||
|
||||
#define BASE_ADDR 8
|
||||
|
@ -37,27 +38,51 @@ start:
|
|||
bal codestart
|
||||
nop
|
||||
base:
|
||||
. = _start + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
|
||||
. = _start + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE
|
||||
compressed_size:
|
||||
.long 0
|
||||
. = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE
|
||||
. = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE
|
||||
uncompressed_size:
|
||||
.long 0
|
||||
. = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR
|
||||
uncompressed_addr:
|
||||
.long 0
|
||||
codestart:
|
||||
/* Save our base. */
|
||||
move $s0, $ra
|
||||
|
||||
/* Parse arguments. Has to be done before relocation.
|
||||
So need to do it in asm. */
|
||||
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
||||
#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS
|
||||
lui $t0, %hi (((16 << 20) - 264 + 4) | 0x80000000)
|
||||
lw $t1, %lo (((16 << 20) - 264 + 4) | 0x80000000) ($t0)
|
||||
|
||||
lui $t2, 0x1234
|
||||
ori $t2, 0x5678
|
||||
|
||||
bne $t1, $t2, 1f
|
||||
nop
|
||||
|
||||
lui $t0, %hi (((16 << 20) - 264) | 0x80000000)
|
||||
b 2f
|
||||
lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0)
|
||||
|
||||
1:
|
||||
li $s4, 0
|
||||
2:
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
move $s2, $zero
|
||||
move $s3, $zero
|
||||
move $s4, $zero
|
||||
move $s5, $zero
|
||||
move $s7, $zero
|
||||
|
||||
/* $a2 has the environment. */
|
||||
addiu $t0, $a2, 1
|
||||
beq $t0, $zero, argdone
|
||||
addiu $t0, $zero, -0x10
|
||||
and $t1, $a2, $t0
|
||||
beq $t0, $t1, argfw
|
||||
nop
|
||||
move $t0, $a2
|
||||
argcont:
|
||||
|
@ -72,11 +97,19 @@ argcont:
|
|||
nop ;\
|
||||
b 2f;\
|
||||
move reg, $v0; \
|
||||
1:
|
||||
1:
|
||||
#define DO_CHECKT1(str, val) \
|
||||
move $t6, $t1 ;\
|
||||
addiu $t7, $s0, (str - base);\
|
||||
bal do_check ;\
|
||||
li $t2, val
|
||||
|
||||
DO_PARSE (busclockstr, $s2)
|
||||
DO_PARSE (cpuclockstr, $s3)
|
||||
DO_PARSE (memsizestr, $s4)
|
||||
DO_PARSE (highmemsizestr, $s5)
|
||||
DO_CHECKT1 (pmon_yeeloong_verstr, GRUB_ARCH_MACHINE_YEELOONG)
|
||||
DO_CHECKT1 (pmon_fuloong2f_verstr, GRUB_ARCH_MACHINE_FULOONG2F)
|
||||
2:
|
||||
b argcont
|
||||
addiu $t0, $t0, 4
|
||||
|
@ -120,8 +153,49 @@ busclockstr: .asciiz "busclock="
|
|||
cpuclockstr: .asciiz "cpuclock="
|
||||
memsizestr: .asciiz "memsize="
|
||||
highmemsizestr: .asciiz "highmemsize="
|
||||
machtype_yeeloong_str1: .asciiz "machtype=8.9"
|
||||
machtype_yeeloong_str2: .asciiz "machtype=lemote-yeeloong-"
|
||||
machtype_fuloong2f_str: .asciiz "machtype=lemote-fuloong-2f"
|
||||
machtype_fuloong2e_str: .asciiz "machtype=lemote-fuloong-2e"
|
||||
pmon_yeeloong_str: .asciiz "PMON_VER=LM8"
|
||||
pmon_fuloong2f_str: .asciiz "PMON_VER=LM6"
|
||||
pmon_yeeloong_verstr: .asciiz "Version=LM8"
|
||||
pmon_fuloong2f_verstr: .asciiz "Version=LM6"
|
||||
.p2align 2
|
||||
|
||||
argdone:
|
||||
beq $a0, $zero, cmdlinedone
|
||||
nop
|
||||
#define DO_CHECKA1(str, val) \
|
||||
lw $t6, 0($a1) ;\
|
||||
addiu $t7, $s0, (str - base);\
|
||||
bal do_check ;\
|
||||
li $t2, val
|
||||
DO_CHECKA1 (machtype_yeeloong_str1, GRUB_ARCH_MACHINE_YEELOONG)
|
||||
DO_CHECKA1 (machtype_yeeloong_str2, GRUB_ARCH_MACHINE_YEELOONG)
|
||||
DO_CHECKA1 (pmon_yeeloong_str, GRUB_ARCH_MACHINE_YEELOONG)
|
||||
DO_CHECKA1 (machtype_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F)
|
||||
DO_CHECKA1 (machtype_fuloong2e_str, GRUB_ARCH_MACHINE_FULOONG2E)
|
||||
DO_CHECKA1 (pmon_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F)
|
||||
addiu $a0, $a0, -1
|
||||
b argdone
|
||||
addiu $a1, $a1, 4
|
||||
do_check:
|
||||
lb $t4, 0($t7)
|
||||
beq $t4, $zero, 1f
|
||||
lb $t3, 0($t6)
|
||||
bne $t3, $t4, 2f
|
||||
addiu $t6, $t6, 1
|
||||
b do_check
|
||||
addiu $t7, $t7, 1
|
||||
1:
|
||||
move $s7, $t2
|
||||
2:
|
||||
jr $ra
|
||||
nop
|
||||
argfw:
|
||||
not $s7, $a2
|
||||
cmdlinedone:
|
||||
#endif
|
||||
/* Copy the decompressor. */
|
||||
lui $t1, %hi(base)
|
||||
|
@ -150,6 +224,13 @@ argdone:
|
|||
b 1b
|
||||
addiu $t1, $t1, 1
|
||||
2:
|
||||
lui $a0, %hi(base)
|
||||
addiu $a0, $a0, %lo(base)
|
||||
lui $a1, %hi(_end)
|
||||
addiu $a1, %lo(_end)
|
||||
subu $a1,$a1,$a0
|
||||
|
||||
#include "../../kern/mips/cache_flush.S"
|
||||
|
||||
/* Decompress the payload. */
|
||||
lui $a0, %hi(__bss_start)
|
||||
|
@ -159,10 +240,9 @@ argdone:
|
|||
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)
|
||||
lw $a1, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR - BASE_ADDR)($s0)
|
||||
lw $a2, (GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0)
|
||||
lw $a3, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0)
|
||||
move $s1, $a1
|
||||
|
||||
/* $a0 contains source compressed address, $a1 is destination,
|
||||
|
@ -170,9 +250,11 @@ argdone:
|
|||
*/
|
||||
move $s6, $a3
|
||||
|
||||
lui $sp, %hi(_start - 256)
|
||||
lui $t0, %hi(EXT_C(grub_decompress_core))
|
||||
addiu $t0, $t0, %lo(EXT_C(grub_decompress_core))
|
||||
|
||||
bal EXT_C(grub_decompress_core)
|
||||
lui $sp, %hi(_start - 256)
|
||||
jalr $t0
|
||||
addiu $sp, $sp, %lo(_start - 256)
|
||||
|
||||
move $a0, $s1
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
|
||||
.text
|
||||
|
@ -29,9 +28,6 @@ pic_base:
|
|||
call boot_continue
|
||||
mov %o4, CIF_REG
|
||||
|
||||
. = _start + GRUB_BOOT_MACHINE_VER_MAJ
|
||||
boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
|
||||
|
||||
/* The offsets to these locations are defined by the
|
||||
* GRUB_BOOT_MACHINE_foo macros in include/grub/sparc/ieee1275/boot.h,
|
||||
* and grub-setup uses this to patch these next three values as needed.
|
||||
|
@ -44,6 +40,7 @@ boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
|
|||
* After loading in that block we will execute it by jumping to the
|
||||
* load address plus the size of the prepended A.OUT header (32 bytes).
|
||||
*/
|
||||
. = _start + GRUB_BOOT_MACHINE_BOOT_DEVPATH
|
||||
boot_path:
|
||||
. = _start + GRUB_BOOT_MACHINE_KERNEL_BYTE
|
||||
boot_path_end:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/offsets.h>
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ write_bases (void)
|
|||
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
|
||||
reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT)
|
||||
& GRUB_MACHINE_PCI_WIN_MASK)
|
||||
>> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE));
|
||||
<< (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE));
|
||||
GRUB_MACHINE_PCI_IO_CTRL_REG = reg;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
#include <grub/pci.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/ata.h>
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
#include <grub/machine/kernel.h>
|
||||
#endif
|
||||
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
int
|
||||
grub_cs5536_find (grub_pci_device_t *devp)
|
||||
|
@ -90,8 +97,6 @@ grub_cs5536_smbus_wait (grub_port_t smbbase)
|
|||
if (grub_get_time_ms () > start + 40)
|
||||
return grub_error (GRUB_ERR_IO, "SM stalled");
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
|
@ -213,26 +218,6 @@ grub_cs5536_read_spd (grub_port_t smbbase, grub_uint8_t dev,
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Dump of GPIO connections. FIXME: Remove useless and macroify. */
|
||||
static grub_uint32_t gpiodump[] = {
|
||||
0xffff0000, 0x2ffdd002, 0xffff0000, 0xffff0000,
|
||||
0x2fffd000, 0xffff0000, 0x1000efff, 0xefff1000,
|
||||
0x3ffbc004, 0xffff0000, 0xffff0000, 0xffff0000,
|
||||
0x3ffbc004, 0x3ffbc004, 0xffff0000, 0x00000000,
|
||||
0xffff0000, 0xffff0000, 0x3ffbc004, 0x3f9bc064,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
|
||||
0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000,
|
||||
0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000,
|
||||
0xefff1000, 0xefff1000, 0xffff0000, 0x00000000,
|
||||
0xffff0000, 0xffff0000, 0xefff1000, 0xffff0000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x50000000, 0x00000000, 0x00000000,
|
||||
};
|
||||
|
||||
static inline void
|
||||
set_io_space (grub_pci_device_t dev, int num, grub_uint16_t start,
|
||||
grub_uint16_t len)
|
||||
|
@ -273,17 +258,6 @@ set_p2d (grub_pci_device_t dev, int num, int dest, grub_uint32_t start)
|
|||
void
|
||||
grub_cs5536_init_geode (grub_pci_device_t dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Make sure GPIO is where we expect it to be. */
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_GPIO_BAR,
|
||||
GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_GPIO);
|
||||
|
||||
/* Setup GPIO. */
|
||||
for (i = 0; i < (int) ARRAY_SIZE (gpiodump); i++)
|
||||
((volatile grub_uint32_t *) (GRUB_MACHINE_PCI_IO_BASE
|
||||
+ GRUB_CS5536_LBAR_GPIO)) [i] = gpiodump[i];
|
||||
|
||||
/* Enable more BARs. */
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_IRQ_MAP_BAR,
|
||||
GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_IRQ_MAP);
|
||||
|
@ -295,11 +269,27 @@ grub_cs5536_init_geode (grub_pci_device_t dev)
|
|||
GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_PM);
|
||||
|
||||
/* Setup DIVIL. */
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO,
|
||||
GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1);
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
switch (grub_arch_machine)
|
||||
{
|
||||
case GRUB_ARCH_MACHINE_YEELOONG:
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO,
|
||||
GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1);
|
||||
break;
|
||||
case GRUB_ARCH_MACHINE_FULOONG2F:
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO,
|
||||
GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0
|
||||
| GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK,
|
||||
(~GRUB_CS5536_DIVIL_LPC_INTERRUPTS) & 0xffff);
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK,
|
||||
|
|
|
@ -20,23 +20,39 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm_private.h>
|
||||
#include <grub/cache.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* FIXME: correctly support 64-bit architectures. */
|
||||
/* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */
|
||||
struct grub_pci_dma_chunk *
|
||||
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
|
||||
{
|
||||
return grub_memalign (align, size);
|
||||
void *ret;
|
||||
if (align < 64)
|
||||
align = 64;
|
||||
size = ALIGN_UP (size, align);
|
||||
ret = grub_memalign (align, size);
|
||||
if (!ret)
|
||||
return 0;
|
||||
grub_arch_sync_dma_caches (ret, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* FIXME: evil. */
|
||||
void
|
||||
grub_dma_free (struct grub_pci_dma_chunk *ch)
|
||||
{
|
||||
grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN;
|
||||
grub_arch_sync_dma_caches (ch, size);
|
||||
grub_free (ch);
|
||||
}
|
||||
/* #endif */
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
volatile void *
|
||||
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
|
||||
{
|
||||
|
@ -90,17 +106,14 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
|||
|
||||
/* Check if there is a device present. */
|
||||
if (id >> 16 == 0xFFFF)
|
||||
continue;
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
||||
/* Skip ghosts. */
|
||||
if (id == GRUB_YEELOONG_OHCI_PCIID
|
||||
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
|
||||
continue;
|
||||
if (id == GRUB_YEELOONG_EHCI_PCIID
|
||||
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
|
||||
continue;
|
||||
#endif
|
||||
{
|
||||
if (dev.function == 0)
|
||||
/* Devices are required to implement function 0, so if
|
||||
it's missing then there is no device here. */
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hook (dev, id))
|
||||
return;
|
||||
|
|
1846
grub-core/bus/usb/ehci.c
Normal file
1846
grub-core/bus/usb/ehci.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -24,6 +24,8 @@
|
|||
#include <grub/usb.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
||||
static struct grub_usb_controller_dev usb_controller =
|
||||
{
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <grub/cs5536.h>
|
||||
#include <grub/loader.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_ohci_hcca
|
||||
{
|
||||
/* Pointers to Interrupt Endpoint Descriptors. Not used by
|
||||
|
@ -220,7 +222,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 +231,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))
|
||||
{
|
||||
|
@ -454,10 +454,12 @@ grub_ohci_pci_iter (grub_pci_device_t dev,
|
|||
|
||||
fail:
|
||||
if (o)
|
||||
grub_dma_free (o->td_chunk);
|
||||
grub_dma_free (o->ed_bulk_chunk);
|
||||
grub_dma_free (o->ed_ctrl_chunk);
|
||||
grub_dma_free (o->hcca_chunk);
|
||||
{
|
||||
grub_dma_free (o->td_chunk);
|
||||
grub_dma_free (o->ed_bulk_chunk);
|
||||
grub_dma_free (o->ed_ctrl_chunk);
|
||||
grub_dma_free (o->hcca_chunk);
|
||||
}
|
||||
grub_free (o);
|
||||
|
||||
return 0;
|
||||
|
@ -1150,8 +1152,8 @@ grub_ohci_check_transfer (grub_usb_controller_t dev,
|
|||
return parse_halt (dev, transfer, actual);
|
||||
|
||||
/* Finished ED detection */
|
||||
if ( (grub_le_to_cpu32 (cdata->ed_virt->td_head) & ~0xf) ==
|
||||
(grub_le_to_cpu32 (cdata->ed_virt->td_tail) & ~0xf) ) /* Empty ED */
|
||||
if ( (grub_le_to_cpu32 (cdata->ed_virt->td_head) & ~0xfU) ==
|
||||
(grub_le_to_cpu32 (cdata->ed_virt->td_tail) & ~0xfU) ) /* Empty ED */
|
||||
{
|
||||
/* Check the HALT bit */
|
||||
/* It looks like nonsense - it was tested previously...
|
||||
|
@ -1424,18 +1426,22 @@ static struct grub_usb_controller_dev usb_controller =
|
|||
.detect_dev = grub_ohci_detect_dev
|
||||
};
|
||||
|
||||
static struct grub_preboot *fini_hnd;
|
||||
|
||||
GRUB_MOD_INIT(ohci)
|
||||
{
|
||||
COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_td) == 32);
|
||||
COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_ed) == 16);
|
||||
grub_ohci_inithw ();
|
||||
grub_usb_controller_dev_register (&usb_controller);
|
||||
grub_loader_register_preboot_hook (grub_ohci_fini_hw, grub_ohci_restore_hw,
|
||||
GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
|
||||
fini_hnd = grub_loader_register_preboot_hook (grub_ohci_fini_hw,
|
||||
grub_ohci_restore_hw,
|
||||
GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(ohci)
|
||||
{
|
||||
grub_ohci_fini_hw (0);
|
||||
grub_loader_unregister_preboot_hook (fini_hnd);
|
||||
grub_usb_controller_dev_unregister (&usb_controller);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
#include <grub/serial.h>
|
||||
#include <grub/usbserial.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
void
|
||||
grub_usbserial_fini (struct grub_serial_port *port)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/usb.h>
|
||||
#include <grub/usbserial.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_FTDI_MODEM_CTRL = 0x01,
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/usb.h>
|
||||
#include <grub/usbserial.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* Convert speed to divisor. */
|
||||
static grub_uint32_t
|
||||
is_speed_supported (unsigned int speed)
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/i386/io.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define GRUB_UHCI_IOMASK (0x7FF << 5)
|
||||
|
||||
#define N_QH 256
|
||||
|
@ -34,11 +36,33 @@
|
|||
typedef enum
|
||||
{
|
||||
GRUB_UHCI_REG_USBCMD = 0x00,
|
||||
GRUB_UHCI_REG_USBINTR = 0x04,
|
||||
GRUB_UHCI_REG_FLBASEADD = 0x08,
|
||||
GRUB_UHCI_REG_PORTSC1 = 0x10,
|
||||
GRUB_UHCI_REG_PORTSC2 = 0x12
|
||||
GRUB_UHCI_REG_PORTSC2 = 0x12,
|
||||
GRUB_UHCI_REG_USBLEGSUP = 0xc0
|
||||
} grub_uhci_reg_t;
|
||||
|
||||
/* R/WC legacy support bits */
|
||||
#define GRUB_UHCI_LEGSUP_END_A20GATE (1 << 15)
|
||||
#define GRUB_UHCI_TRAP_BY_64H_WSTAT (1 << 11)
|
||||
#define GRUB_UHCI_TRAP_BY_64H_RSTAT (1 << 10)
|
||||
#define GRUB_UHCI_TRAP_BY_60H_WSTAT (1 << 9)
|
||||
#define GRUB_UHCI_TRAP_BY_60H_RSTAT (1 << 8)
|
||||
|
||||
/* Reset all legacy support - clear all R/WC bits and all R/W bits */
|
||||
#define GRUB_UHCI_RESET_LEGSUP_SMI ( GRUB_UHCI_LEGSUP_END_A20GATE \
|
||||
| GRUB_UHCI_TRAP_BY_64H_WSTAT \
|
||||
| GRUB_UHCI_TRAP_BY_64H_RSTAT \
|
||||
| GRUB_UHCI_TRAP_BY_60H_WSTAT \
|
||||
| GRUB_UHCI_TRAP_BY_60H_RSTAT )
|
||||
|
||||
/* Some UHCI commands */
|
||||
#define GRUB_UHCI_CMD_RUN_STOP (1 << 0)
|
||||
#define GRUB_UHCI_CMD_HCRESET (1 << 1)
|
||||
#define GRUB_UHCI_CMD_MAXP (1 << 7)
|
||||
|
||||
/* Important bits in structures */
|
||||
#define GRUB_UHCI_LINK_TERMINATE 1
|
||||
#define GRUB_UHCI_LINK_QUEUE_HEAD 2
|
||||
|
||||
|
@ -179,6 +203,11 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
|
|||
if (class != 0x0c || subclass != 0x03 || interf != 0x00)
|
||||
return 0;
|
||||
|
||||
/* Set bus master - needed for coreboot or broken BIOSes */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
|
||||
grub_pci_write_word(addr,
|
||||
GRUB_PCI_COMMAND_BUS_MASTER | grub_pci_read_word(addr));
|
||||
|
||||
/* Determine IO base address. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG4);
|
||||
base = grub_pci_read (addr);
|
||||
|
@ -193,6 +222,19 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
|
|||
|
||||
u->iobase = base & GRUB_UHCI_IOMASK;
|
||||
|
||||
/* Reset PIRQ and SMI */
|
||||
addr = grub_pci_make_address (dev, GRUB_UHCI_REG_USBLEGSUP);
|
||||
grub_pci_write_word(addr, GRUB_UHCI_RESET_LEGSUP_SMI);
|
||||
/* Reset the HC */
|
||||
grub_uhci_writereg16(u, GRUB_UHCI_REG_USBCMD, GRUB_UHCI_CMD_HCRESET);
|
||||
grub_millisleep(5);
|
||||
/* Disable interrupts and commands (just to be safe) */
|
||||
grub_uhci_writereg16(u, GRUB_UHCI_REG_USBINTR, 0);
|
||||
/* Finish HC reset, HC remains disabled */
|
||||
grub_uhci_writereg16(u, GRUB_UHCI_REG_USBCMD, 0);
|
||||
/* Read back to be sure PCI write is done */
|
||||
grub_uhci_readreg16(u, GRUB_UHCI_REG_USBCMD);
|
||||
|
||||
/* Reserve a page for the frame list. */
|
||||
u->framelist = grub_memalign (4096, 4096);
|
||||
if (! u->framelist)
|
||||
|
@ -250,9 +292,6 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
|
|||
u->td[N_TD - 2].linkptr = 0;
|
||||
u->tdfree = u->td;
|
||||
|
||||
/* Make sure UHCI is disabled! */
|
||||
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 0);
|
||||
|
||||
/* Setup the frame list pointers. Since no isochronous transfers
|
||||
are and will be supported, they all point to the (same!) queue
|
||||
head. */
|
||||
|
@ -283,7 +322,8 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
|
|||
u->qh[N_QH - 1].linkptr = 1;
|
||||
|
||||
/* Enable UHCI again. */
|
||||
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 1 | (1 << 7));
|
||||
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD,
|
||||
GRUB_UHCI_CMD_RUN_STOP | GRUB_UHCI_CMD_MAXP);
|
||||
|
||||
/* UHCI is initialized and ready for transfers. */
|
||||
grub_dprintf ("uhci", "UHCI initialized\n");
|
||||
|
@ -504,8 +544,11 @@ grub_uhci_setup_transfer (grub_usb_controller_t dev,
|
|||
{
|
||||
grub_size_t actual = 0;
|
||||
/* Terminate and free. */
|
||||
td_prev->linkptr2 = 0;
|
||||
td_prev->linkptr = 1;
|
||||
if (td_prev)
|
||||
{
|
||||
td_prev->linkptr2 = 0;
|
||||
td_prev->linkptr = 1;
|
||||
}
|
||||
|
||||
if (cdata->td_first)
|
||||
grub_free_queue (u, cdata->qh, cdata->td_first, NULL, &actual);
|
||||
|
@ -749,8 +792,7 @@ grub_uhci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
|
|||
else if (port == 1)
|
||||
reg = GRUB_UHCI_REG_PORTSC2;
|
||||
else
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
"UHCI Root Hub port does not exist");
|
||||
return GRUB_USB_SPEED_NONE;
|
||||
|
||||
status = grub_uhci_readreg16 (u, reg);
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@
|
|||
#include <grub/list.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_usb_controller_dev_t grub_usb_list;
|
||||
struct grub_usb_attach_desc *attach_hooks;
|
||||
static struct grub_usb_attach_desc *attach_hooks;
|
||||
|
||||
void
|
||||
grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
|
||||
|
@ -183,6 +185,12 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||
for (i = 0; i < 8; i++)
|
||||
dev->config[i].descconf = NULL;
|
||||
|
||||
if (descdev->configcnt == 0)
|
||||
{
|
||||
err = GRUB_USB_ERR_BADDEVICE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (i = 0; i < descdev->configcnt; i++)
|
||||
{
|
||||
int pos;
|
||||
|
@ -332,7 +340,7 @@ grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
|
|||
void
|
||||
grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&attach_hooks), GRUB_AS_LIST (desc));
|
||||
grub_list_remove (GRUB_AS_LIST (desc));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,12 +39,14 @@ struct grub_usb_hub
|
|||
grub_usb_device_t dev;
|
||||
};
|
||||
|
||||
struct grub_usb_hub *hubs;
|
||||
static struct grub_usb_hub *hubs;
|
||||
|
||||
/* Add a device that currently has device number 0 and resides on
|
||||
CONTROLLER, the Hub reported that the device speed is SPEED. */
|
||||
static grub_usb_device_t
|
||||
grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
|
||||
grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
grub_usb_speed_t speed,
|
||||
int port, int hubaddr)
|
||||
{
|
||||
grub_usb_device_t dev;
|
||||
int i;
|
||||
|
@ -56,6 +58,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
|
|||
|
||||
dev->controller = *controller;
|
||||
dev->speed = speed;
|
||||
dev->port = port;
|
||||
dev->hubaddr = hubaddr;
|
||||
|
||||
err = grub_usb_device_initialize (dev);
|
||||
if (err)
|
||||
|
@ -97,6 +101,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
|
|||
dev->initialized = 1;
|
||||
grub_usb_devs[i] = dev;
|
||||
|
||||
grub_dprintf ("usb", "Added new usb device: %08x, addr=%d\n",
|
||||
(grub_uint32_t)dev, i);
|
||||
grub_dprintf ("usb", "speed=%d, port=%d, hubaddr=%d\n",
|
||||
speed, port, hubaddr);
|
||||
|
||||
/* Wait "recovery interval", spec. says 2ms */
|
||||
grub_millisleep (2);
|
||||
|
||||
|
@ -110,7 +119,7 @@ static grub_usb_err_t
|
|||
grub_usb_add_hub (grub_usb_device_t dev)
|
||||
{
|
||||
struct grub_usb_usb_hubdesc hubdesc;
|
||||
grub_err_t err;
|
||||
grub_usb_err_t err;
|
||||
int i;
|
||||
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
|
||||
|
@ -158,11 +167,13 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
|||
if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
|
||||
== GRUB_USB_EP_INTERRUPT)
|
||||
{
|
||||
grub_size_t len;
|
||||
dev->hub_endpoint = endp;
|
||||
len = endp->maxpacket;
|
||||
if (len > sizeof (dev->statuschange))
|
||||
len = sizeof (dev->statuschange);
|
||||
dev->hub_transfer
|
||||
= grub_usb_bulk_read_background (dev, endp->endp_addr,
|
||||
grub_min (endp->maxpacket,
|
||||
sizeof (dev->statuschange)),
|
||||
= grub_usb_bulk_read_background (dev, endp->endp_addr, len,
|
||||
(char *) &dev->statuschange);
|
||||
break;
|
||||
}
|
||||
|
@ -215,8 +226,10 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
|
|||
return;
|
||||
hub->controller->dev->pending_reset = grub_get_time_ms () + 5000;
|
||||
|
||||
grub_millisleep (10);
|
||||
|
||||
/* Enable the port and create a device. */
|
||||
dev = grub_usb_hub_add_dev (hub->controller, speed);
|
||||
dev = grub_usb_hub_add_dev (hub->controller, speed, portno, 0);
|
||||
hub->controller->dev->pending_reset = 0;
|
||||
if (! dev)
|
||||
return;
|
||||
|
@ -312,7 +325,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
|||
grub_usb_err_t err;
|
||||
unsigned i;
|
||||
grub_uint8_t changed;
|
||||
grub_size_t actual;
|
||||
grub_size_t actual, len;
|
||||
int j, total;
|
||||
|
||||
if (!dev->hub_transfer)
|
||||
|
@ -325,10 +338,11 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
|||
|
||||
changed = dev->statuschange;
|
||||
|
||||
len = dev->hub_endpoint->maxpacket;
|
||||
if (len > sizeof (dev->statuschange))
|
||||
len = sizeof (dev->statuschange);
|
||||
dev->hub_transfer
|
||||
= grub_usb_bulk_read_background (dev, dev->hub_endpoint->endp_addr,
|
||||
grub_min (dev->hub_endpoint->maxpacket,
|
||||
sizeof (dev->statuschange)),
|
||||
= grub_usb_bulk_read_background (dev, dev->hub_endpoint->endp_addr, len,
|
||||
(char *) &dev->statuschange);
|
||||
|
||||
if (err || actual == 0 || changed == 0)
|
||||
|
@ -350,7 +364,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
|||
GRUB_USB_REQ_GET_STATUS,
|
||||
0, i, sizeof (status), (char *) &status);
|
||||
|
||||
grub_printf ("dev = %p, i = %d, status = %08x\n",
|
||||
grub_dprintf ("usb", "dev = %p, i = %d, status = %08x\n",
|
||||
dev, i, status);
|
||||
|
||||
if (err)
|
||||
|
@ -470,7 +484,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
|||
grub_millisleep (10);
|
||||
|
||||
/* Add the device and assign a device address to it. */
|
||||
next_dev = grub_usb_hub_add_dev (&dev->controller, speed);
|
||||
next_dev = grub_usb_hub_add_dev (&dev->controller, speed, i, dev->addr);
|
||||
dev->controller.dev->pending_reset = 0;
|
||||
if (! next_dev)
|
||||
continue;
|
||||
|
|
|
@ -97,7 +97,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
|||
if (! transfer)
|
||||
{
|
||||
grub_dma_free (data_chunk);
|
||||
return grub_errno;
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
setupdata_chunk = grub_memalign_dma32 (32, sizeof (*setupdata));
|
||||
|
@ -105,7 +105,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
|||
{
|
||||
grub_free (transfer);
|
||||
grub_dma_free (data_chunk);
|
||||
return grub_errno;
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
setupdata = grub_dma_get_virt (setupdata_chunk);
|
||||
|
@ -139,7 +139,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
|||
grub_free (transfer);
|
||||
grub_dma_free (setupdata_chunk);
|
||||
grub_dma_free (data_chunk);
|
||||
return grub_errno;
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
/* Build a Setup packet. XXX: Endianness. */
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <grub/efi/api.h>
|
||||
#endif
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"exclude", 'x', 0,
|
||||
N_("Don't load host tables specified by comma-separated list."),
|
||||
|
@ -136,6 +138,7 @@ iszero (grub_uint8_t *reg, int size)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
grub_err_t
|
||||
grub_acpi_create_ebda (void)
|
||||
{
|
||||
|
@ -163,7 +166,7 @@ grub_acpi_create_ebda (void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ebda = (grub_uint8_t *) UINT_TO_PTR ((*((grub_uint16_t *)0x40e)) << 4);
|
||||
ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)0x40e)) << 4);
|
||||
ebda_kb_len = *(grub_uint16_t *) ebda;
|
||||
if (! ebda || ebda_kb_len > 16)
|
||||
ebda_kb_len = 0;
|
||||
|
@ -171,14 +174,14 @@ grub_acpi_create_ebda (void)
|
|||
|
||||
/* FIXME: use low-memory mm allocation once it's available. */
|
||||
grub_mmap_iterate (find_hook);
|
||||
targetebda = (grub_uint8_t *) UINT_TO_PTR (highestlow);
|
||||
targetebda = (grub_uint8_t *) (grub_addr_t) highestlow;
|
||||
grub_dprintf ("acpi", "creating ebda @%llx\n",
|
||||
(unsigned long long) highestlow);
|
||||
if (! highestlow)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"couldn't find space for the new EBDA");
|
||||
|
||||
mmapregion = grub_mmap_register (PTR_TO_UINT64 (targetebda), ebda_len,
|
||||
mmapregion = grub_mmap_register ((grub_addr_t) targetebda, ebda_len,
|
||||
GRUB_MEMORY_RESERVED);
|
||||
if (! mmapregion)
|
||||
return grub_errno;
|
||||
|
@ -295,6 +298,7 @@ grub_acpi_create_ebda (void)
|
|||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Create tables common to ACPIv1 and ACPIv2+ */
|
||||
static void
|
||||
|
@ -326,13 +330,13 @@ setup_common_tables (void)
|
|||
if (grub_memcmp (fadt->hdr.signature, GRUB_ACPI_FADT_SIGNATURE,
|
||||
sizeof (fadt->hdr.signature)) == 0)
|
||||
{
|
||||
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
|
||||
fadt->dsdt_addr = (grub_addr_t) table_dsdt;
|
||||
fadt->facs_addr = facs_addr;
|
||||
|
||||
/* Does a revision 2 exist at all? */
|
||||
if (fadt->hdr.revision >= 3)
|
||||
{
|
||||
fadt->dsdt_xaddr = PTR_TO_UINT64 (table_dsdt);
|
||||
fadt->dsdt_xaddr = (grub_addr_t) table_dsdt;
|
||||
fadt->facs_xaddr = facs_addr;
|
||||
}
|
||||
|
||||
|
@ -363,7 +367,7 @@ setup_common_tables (void)
|
|||
rsdt->creator_rev = root_creator_rev;
|
||||
|
||||
for (cur = acpi_tables; cur; cur = cur->next)
|
||||
*(rsdt_entry++) = PTR_TO_UINT32 (cur->addr);
|
||||
*(rsdt_entry++) = (grub_addr_t) cur->addr;
|
||||
|
||||
/* Recompute checksum. */
|
||||
rsdt->checksum = 0;
|
||||
|
@ -381,7 +385,7 @@ setv1table (void)
|
|||
sizeof (rsdpv1_new->signature));
|
||||
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
|
||||
rsdpv1_new->revision = 0;
|
||||
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
|
||||
rsdpv1_new->rsdt_addr = (grub_addr_t) rsdt_addr;
|
||||
rsdpv1_new->checksum = 0;
|
||||
rsdpv1_new->checksum = 1 + ~grub_byte_checksum (rsdpv1_new,
|
||||
sizeof (*rsdpv1_new));
|
||||
|
@ -406,7 +410,7 @@ setv2table (void)
|
|||
|
||||
xsdt_entry = (grub_uint64_t *)(xsdt + 1);
|
||||
for (cur = acpi_tables; cur; cur = cur->next)
|
||||
*(xsdt_entry++) = PTR_TO_UINT64 (cur->addr);
|
||||
*(xsdt_entry++) = (grub_addr_t) cur->addr;
|
||||
grub_memcpy (&(xsdt->signature), "XSDT", 4);
|
||||
xsdt->length = sizeof (struct grub_acpi_table_header) + 8 * numoftables;
|
||||
xsdt->revision = 1;
|
||||
|
@ -426,12 +430,12 @@ setv2table (void)
|
|||
grub_memcpy (&(rsdpv2_new->rsdpv1.oemid), root_oemid,
|
||||
sizeof (rsdpv2_new->rsdpv1.oemid));
|
||||
rsdpv2_new->rsdpv1.revision = rev2;
|
||||
rsdpv2_new->rsdpv1.rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
|
||||
rsdpv2_new->rsdpv1.rsdt_addr = (grub_addr_t) rsdt_addr;
|
||||
rsdpv2_new->rsdpv1.checksum = 0;
|
||||
rsdpv2_new->rsdpv1.checksum = 1 + ~grub_byte_checksum
|
||||
(&(rsdpv2_new->rsdpv1), sizeof (rsdpv2_new->rsdpv1));
|
||||
rsdpv2_new->length = sizeof (*rsdpv2_new);
|
||||
rsdpv2_new->xsdt_addr = PTR_TO_UINT64 (xsdt);
|
||||
rsdpv2_new->xsdt_addr = (grub_addr_t) xsdt;
|
||||
rsdpv2_new->checksum = 0;
|
||||
rsdpv2_new->checksum = 1 + ~grub_byte_checksum (rsdpv2_new,
|
||||
rsdpv2_new->length);
|
||||
|
@ -461,7 +465,6 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
struct grub_arg_list *state = ctxt->state;
|
||||
struct grub_acpi_rsdp_v10 *rsdp;
|
||||
struct efiemu_acpi_table *cur, *t;
|
||||
grub_err_t err;
|
||||
int i, mmapregion;
|
||||
int numoftables;
|
||||
|
||||
|
@ -504,7 +507,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
/* Set revision variables to replicate the same version as host. */
|
||||
rev1 = ! rsdp->revision;
|
||||
rev2 = rsdp->revision;
|
||||
rsdt = (struct grub_acpi_table_header *) UINT_TO_PTR (rsdp->rsdt_addr);
|
||||
rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr;
|
||||
/* Load host tables. */
|
||||
for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
|
||||
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
|
||||
|
@ -514,7 +517,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
char signature[5];
|
||||
struct efiemu_acpi_table *table;
|
||||
struct grub_acpi_table_header *curtable
|
||||
= (struct grub_acpi_table_header *) UINT_TO_PTR (*entry_ptr);
|
||||
= (struct grub_acpi_table_header *) (grub_addr_t) *entry_ptr;
|
||||
signature[4] = 0;
|
||||
for (i = 0; i < 4;i++)
|
||||
signature[i] = grub_tolower (curtable->signature[i]);
|
||||
|
@ -538,7 +541,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
|
||||
/* Load DSDT if not excluded. */
|
||||
dsdt = (struct grub_acpi_table_header *)
|
||||
UINT_TO_PTR (fadt->dsdt_addr);
|
||||
(grub_addr_t) fadt->dsdt_addr;
|
||||
if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt"))
|
||||
&& (! load_only || grub_strword (load_only, "dsdt"))
|
||||
&& dsdt->length >= sizeof (*dsdt))
|
||||
|
@ -646,15 +649,17 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
{
|
||||
grub_file_close (file);
|
||||
free_tables ();
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"couldn't read file %s", args[i]);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (grub_file_read (file, buf, size) != (int) size)
|
||||
{
|
||||
grub_file_close (file);
|
||||
free_tables ();
|
||||
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]);
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
args[i]);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_file_close (file);
|
||||
|
||||
|
@ -730,13 +735,20 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
|||
}
|
||||
acpi_tables = 0;
|
||||
|
||||
if (! state[9].set && (err = grub_acpi_create_ebda ()))
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
if (! state[9].set)
|
||||
{
|
||||
rsdpv1_new = 0;
|
||||
rsdpv2_new = 0;
|
||||
grub_mmap_free_and_unregister (mmapregion);
|
||||
return err;
|
||||
grub_err_t err;
|
||||
err = grub_acpi_create_ebda ();
|
||||
if (err)
|
||||
{
|
||||
rsdpv1_new = 0;
|
||||
rsdpv2_new = 0;
|
||||
grub_mmap_free_and_unregister (mmapregion);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
{
|
||||
|
|
|
@ -16,9 +16,30 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef GRUB_DSDT_TEST
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 <grub/acpi.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#ifndef GRUB_DSDT_TEST
|
||||
#include <grub/misc.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#endif
|
||||
|
||||
static inline grub_uint32_t
|
||||
decode_length (const grub_uint8_t *ptr, int *numlen)
|
||||
|
@ -123,6 +144,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;
|
||||
|
@ -156,11 +178,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);
|
||||
|
@ -208,6 +231,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)
|
||||
{
|
||||
|
@ -262,5 +326,8 @@ grub_acpi_halt (void)
|
|||
}
|
||||
}
|
||||
|
||||
grub_printf ("ACPI shutdown failed\n");
|
||||
grub_millisleep (1500);
|
||||
|
||||
grub_puts_ (N_("ACPI shutdown failed"));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* pxe.c - command to control the pxe driver */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,35 +17,37 @@
|
|||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/machine/pxe.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/arc/arc.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_pxe_unload (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
grub_cmd_lsdev (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
if (! grub_pxe_pxenv)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no pxe environment");
|
||||
|
||||
grub_pxe_unload ();
|
||||
|
||||
auto int hook (const char *name, const struct grub_arc_component *comp);
|
||||
int hook (const char *name, const struct grub_arc_component *comp __attribute__ ((unused)))
|
||||
{
|
||||
grub_printf ("%s\n", name);
|
||||
return 0;
|
||||
}
|
||||
grub_arc_iterate_devs (hook, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(pxecmd)
|
||||
GRUB_MOD_INIT(lsdev)
|
||||
{
|
||||
cmd = grub_register_command ("pxe_unload", grub_cmd_pxe_unload,
|
||||
0,
|
||||
N_("Unload PXE environment."));
|
||||
cmd = grub_register_command ("lsdev", grub_cmd_lsdev, "",
|
||||
N_("List devices."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(pxecmd)
|
||||
GRUB_MOD_FINI(lsdev)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
|
|
|
@ -25,21 +25,23 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t (*grub_loader_boot_func) (void);
|
||||
static grub_err_t (*grub_loader_unload_func) (void);
|
||||
static int grub_loader_noreturn;
|
||||
|
||||
struct grub_preboot_t
|
||||
struct grub_preboot
|
||||
{
|
||||
grub_err_t (*preboot_func) (int);
|
||||
grub_err_t (*preboot_rest_func) (void);
|
||||
grub_loader_preboot_hook_prio_t prio;
|
||||
struct grub_preboot_t *next;
|
||||
struct grub_preboot_t *prev;
|
||||
struct grub_preboot *next;
|
||||
struct grub_preboot *prev;
|
||||
};
|
||||
|
||||
static int grub_loader_loaded;
|
||||
static struct grub_preboot_t *preboots_head = 0,
|
||||
static struct grub_preboot *preboots_head = 0,
|
||||
*preboots_tail = 0;
|
||||
|
||||
int
|
||||
|
@ -49,18 +51,18 @@ grub_loader_is_loaded (void)
|
|||
}
|
||||
|
||||
/* Register a preboot hook. */
|
||||
void *
|
||||
struct grub_preboot *
|
||||
grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noreturn),
|
||||
grub_err_t (*preboot_rest_func) (void),
|
||||
grub_loader_preboot_hook_prio_t prio)
|
||||
{
|
||||
struct grub_preboot_t *cur, *new_preboot;
|
||||
struct grub_preboot *cur, *new_preboot;
|
||||
|
||||
if (! preboot_func && ! preboot_rest_func)
|
||||
return 0;
|
||||
|
||||
new_preboot = (struct grub_preboot_t *)
|
||||
grub_malloc (sizeof (struct grub_preboot_t));
|
||||
new_preboot = (struct grub_preboot *)
|
||||
grub_malloc (sizeof (struct grub_preboot));
|
||||
if (! new_preboot)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
|
||||
|
@ -94,9 +96,9 @@ grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noreturn),
|
|||
}
|
||||
|
||||
void
|
||||
grub_loader_unregister_preboot_hook (void *hnd)
|
||||
grub_loader_unregister_preboot_hook (struct grub_preboot *hnd)
|
||||
{
|
||||
struct grub_preboot_t *preb = hnd;
|
||||
struct grub_preboot *preb = hnd;
|
||||
|
||||
if (preb->next)
|
||||
preb->next->prev = preb->prev;
|
||||
|
@ -141,7 +143,7 @@ grub_err_t
|
|||
grub_loader_boot (void)
|
||||
{
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
struct grub_preboot_t *cur;
|
||||
struct grub_preboot *cur;
|
||||
|
||||
if (! grub_loader_loaded)
|
||||
return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
|
||||
|
|
58
grub-core/commands/cacheinfo.c
Normal file
58
grub-core/commands/cacheinfo.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* cacheinfo.c - disk cache statistics */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/disk.h>
|
||||
|
||||
static grub_err_t
|
||||
grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
unsigned long hits, misses;
|
||||
|
||||
grub_disk_cache_get_performance (&hits, &misses);
|
||||
grub_printf_ (N_("Disk cache: hits = %lu, misses = %lu "), hits, misses);
|
||||
if (hits + misses)
|
||||
{
|
||||
unsigned long ratio = hits * 10000 / (hits + misses);
|
||||
grub_printf ("(%lu.%lu%%)\n", ratio / 100, ratio % 100);
|
||||
}
|
||||
else
|
||||
grub_puts_ (N_("(N/A)"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_cacheinfo;
|
||||
|
||||
GRUB_MOD_INIT(cacheinfo)
|
||||
{
|
||||
cmd_cacheinfo =
|
||||
grub_register_command ("cacheinfo", grub_rescue_cmd_info,
|
||||
0, N_("Get disk cache info."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(cacheinfo)
|
||||
{
|
||||
grub_unregister_command (cmd_cacheinfo);
|
||||
}
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"dos", -1, 0, N_("Accept DOS-style CR/NL line endings."), 0, 0},
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define BUFFER_SIZE 512
|
||||
|
||||
static grub_err_t
|
||||
|
@ -40,8 +42,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
|||
if (argc != 2)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments required");
|
||||
|
||||
grub_printf ("Compare file `%s' with `%s':\n", args[0],
|
||||
args[1]);
|
||||
grub_printf_ (N_("Compare file `%s' with `%s':\n"), args[0],
|
||||
args[1]);
|
||||
|
||||
file1 = grub_file_open (args[0]);
|
||||
file2 = grub_file_open (args[1]);
|
||||
|
@ -49,9 +51,9 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
|||
goto cleanup;
|
||||
|
||||
if (grub_file_size (file1) != grub_file_size (file2))
|
||||
grub_printf ("Files differ in size: %llu [%s], %llu [%s]\n",
|
||||
(unsigned long long) grub_file_size (file1), args[0],
|
||||
(unsigned long long) grub_file_size (file2), args[1]);
|
||||
grub_printf_ (N_("Files differ in size: %llu [%s], %llu [%s]\n"),
|
||||
(unsigned long long) grub_file_size (file1), args[0],
|
||||
(unsigned long long) grub_file_size (file2), args[1]);
|
||||
else
|
||||
{
|
||||
pos = 0;
|
||||
|
@ -76,9 +78,9 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
|||
{
|
||||
if (buf1[i] != buf2[i])
|
||||
{
|
||||
grub_printf ("Files differ at the offset %llu: 0x%x [%s], 0x%x [%s]\n",
|
||||
(unsigned long long) (i + pos), buf1[i], args[0],
|
||||
buf2[i], args[1]);
|
||||
grub_printf_ (N_("Files differ at the offset %llu: 0x%x [%s], 0x%x [%s]\n"),
|
||||
(unsigned long long) (i + pos), buf1[i],
|
||||
args[0], buf2[i], args[1]);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
@ -87,15 +89,14 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
while (rd2);
|
||||
|
||||
grub_printf ("The files are identical.\n");
|
||||
/* TRANSLATORS: it's always exactly 2 files. */
|
||||
grub_printf_ (N_("The files are identical.\n"));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
if (buf1)
|
||||
grub_free (buf1);
|
||||
if (buf2)
|
||||
grub_free (buf2);
|
||||
grub_free (buf1);
|
||||
grub_free (buf2);
|
||||
if (file1)
|
||||
grub_file_close (file1);
|
||||
if (file2)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_source (grub_command_t cmd, int argc, char **args)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define GRUB_DATETIME_SET_YEAR 1
|
||||
#define GRUB_DATETIME_SET_MONTH 2
|
||||
#define GRUB_DATETIME_SET_DAY 4
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* echo.c - Command to display a line of text */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2006,2007 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2006,2007,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
|
||||
|
@ -21,6 +21,9 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
|
@ -43,8 +46,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
char *arg = *args;
|
||||
/* Unescaping results in a string no longer than the original. */
|
||||
char *unescaped = grub_malloc (grub_strlen (arg) + 1);
|
||||
char *p = unescaped;
|
||||
args++;
|
||||
|
||||
if (!unescaped)
|
||||
return grub_errno;
|
||||
|
||||
while (*arg)
|
||||
{
|
||||
/* In case `-e' is used, parse backslashes. */
|
||||
|
@ -57,11 +66,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
switch (*arg)
|
||||
{
|
||||
case '\\':
|
||||
grub_printf ("\\");
|
||||
*p++ = '\\';
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
grub_printf ("\a");
|
||||
*p++ = '\a';
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
|
@ -69,23 +78,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
break;
|
||||
|
||||
case 'f':
|
||||
grub_printf ("\f");
|
||||
*p++ = '\f';
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
grub_printf ("\n");
|
||||
*p++ = '\n';
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
grub_printf ("\r");
|
||||
*p++ = '\r';
|
||||
break;
|
||||
|
||||
case 't':
|
||||
grub_printf ("\t");
|
||||
*p++ = '\t';
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
grub_printf ("\v");
|
||||
*p++ = '\v';
|
||||
break;
|
||||
}
|
||||
arg++;
|
||||
|
@ -94,10 +103,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
|
||||
/* This was not an escaped character, or escaping is not
|
||||
enabled. */
|
||||
grub_printf ("%c", *arg);
|
||||
*p++ = *arg;
|
||||
arg++;
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
grub_xputs (unescaped);
|
||||
grub_free (unescaped);
|
||||
|
||||
/* If another argument follows, insert a space. */
|
||||
if (i != argc - 1)
|
||||
grub_printf (" " );
|
||||
|
@ -106,6 +119,8 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
if (newline)
|
||||
grub_printf ("\n");
|
||||
|
||||
grub_refresh ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static struct grub_video_patch
|
||||
{
|
||||
const char *name;
|
||||
|
@ -54,24 +56,24 @@ scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
|
|||
{
|
||||
grub_target_addr_t base;
|
||||
|
||||
grub_printf ("Found graphic card: %s\n", p->name);
|
||||
grub_dprintf ("fixvideo", "Found graphic card: %s\n", p->name);
|
||||
addr += 8 + p->mmio_bar * 4;
|
||||
base = grub_pci_read (addr);
|
||||
if ((! base) || (base & GRUB_PCI_ADDR_SPACE_IO) ||
|
||||
(base & GRUB_PCI_ADDR_MEM_PREFETCH))
|
||||
grub_printf ("Invalid MMIO bar %d\n", p->mmio_bar);
|
||||
grub_dprintf ("fixvideo", "Invalid MMIO bar %d\n", p->mmio_bar);
|
||||
else
|
||||
{
|
||||
base &= GRUB_PCI_ADDR_MEM_MASK;
|
||||
base += p->mmio_reg;
|
||||
|
||||
if (*((volatile grub_uint32_t *) base) != p->mmio_old)
|
||||
grub_printf ("Old value don't match\n");
|
||||
grub_dprintf ("fixvideo", "Old value doesn't match\n");
|
||||
else
|
||||
{
|
||||
*((volatile grub_uint32_t *) base) = 0;
|
||||
if (*((volatile grub_uint32_t *) base))
|
||||
grub_printf ("Set MMIO fails\n");
|
||||
grub_dprintf ("fixvideo", "Setting MMIO fails\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +82,7 @@ scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
|
|||
p++;
|
||||
}
|
||||
|
||||
grub_printf ("Unknown graphic card: %x\n", pciid);
|
||||
grub_dprintf ("fixvideo", "Unknown graphic card: %x\n", pciid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
|
||||
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
|
||||
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
|
||||
|
@ -47,7 +49,7 @@ enable_rom_area (void)
|
|||
rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
|
||||
if (*rom_ptr != BLANK_MEM)
|
||||
{
|
||||
grub_printf ("ROM image is present.\n");
|
||||
grub_puts_ (N_("ROM image is present."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -65,7 +67,7 @@ enable_rom_area (void)
|
|||
*rom_ptr = 0;
|
||||
if (*rom_ptr != 0)
|
||||
{
|
||||
grub_printf ("Can\'t enable ROM area.\n");
|
||||
grub_puts_ (N_("Can\'t enable ROM area."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -207,7 +209,7 @@ GRUB_MOD_INIT(loadbios)
|
|||
0, N_("Fake BIOS."));
|
||||
|
||||
cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
|
||||
"BIOS_DUMP [INT10_DUMP]",
|
||||
N_("BIOS_DUMP [INT10_DUMP]"),
|
||||
N_("Load BIOS dump."));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <grub/efi/efi.h>
|
||||
#include <grub/command.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
|
||||
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
|
||||
|
||||
|
|
|
@ -18,12 +18,15 @@
|
|||
*/
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/normal.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct guid_mapping
|
||||
{
|
||||
grub_efi_guid_t guid;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <grub/charset.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static void
|
||||
disp_sal (void *table)
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/script_sh.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
grub_err_t
|
||||
grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args,
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <grub/fs.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* Convert a LBA address to a CHS address in the INT 13 format. */
|
||||
/* Taken from grub1. */
|
||||
/* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63.
|
||||
|
@ -229,7 +231,7 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
|
|||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_printf ("New MBR is written to '%s'\n", args[0]);
|
||||
grub_printf_ (N_("New MBR is written to '%s'\n"), args[0]);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static grub_err_t
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t __attribute__ ((noreturn))
|
||||
grub_cmd_halt (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_halt ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/normal.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"hash", 'h', 0, N_("Specify hash to use."), N_("HASH"), ARG_TYPE_STRING},
|
||||
{"check", 'c', 0, N_("Check hash list file."), N_("FILE"), ARG_TYPE_STRING},
|
||||
|
@ -36,7 +38,7 @@ static const struct grub_arg_option options[] = {
|
|||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
struct { const char *name; const char *hashname; } aliases[] =
|
||||
static struct { const char *name; const char *hashname; } aliases[] =
|
||||
{
|
||||
{"sha256sum", "sha256"},
|
||||
{"sha512sum", "sha512"},
|
||||
|
@ -139,7 +141,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
|||
grub_file_close (file);
|
||||
if (err)
|
||||
{
|
||||
grub_printf ("%s: READ ERROR\n", p);
|
||||
grub_printf_ (N_("%s: READ ERROR\n"), p);
|
||||
if (!keep)
|
||||
{
|
||||
grub_file_close (hashlist);
|
||||
|
@ -153,7 +155,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
|||
}
|
||||
if (grub_crypto_memcmp (expected, actual, hash->mdlen) != 0)
|
||||
{
|
||||
grub_printf ("%s: HASH MISMATCH\n", p);
|
||||
grub_printf_ (N_("%s: HASH MISMATCH\n"), p);
|
||||
if (!keep)
|
||||
{
|
||||
grub_file_close (hashlist);
|
||||
|
@ -164,7 +166,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
|||
mismatch++;
|
||||
continue;
|
||||
}
|
||||
grub_printf ("%s: OK\n", p);
|
||||
grub_printf_ (N_("%s: OK\n"), p);
|
||||
}
|
||||
if (mismatch || unread)
|
||||
return grub_error (GRUB_ERR_TEST_FAILURE,
|
||||
|
@ -255,8 +257,8 @@ static grub_extcmd_t cmd, cmd_md5, cmd_sha1, cmd_sha256, cmd_sha512, cmd_crc;
|
|||
GRUB_MOD_INIT(hashsum)
|
||||
{
|
||||
cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum, 0,
|
||||
"hashsum -h HASH [-c FILE [-p PREFIX]] "
|
||||
"[FILE1 [FILE2 ...]]",
|
||||
N_("-h HASH [-c FILE [-p PREFIX]] "
|
||||
"[FILE1 [FILE2 ...]]"),
|
||||
N_("Compute or check hash checksum."),
|
||||
options);
|
||||
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum, 0,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/ata.h>
|
||||
#include <grub/scsi.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
|
@ -26,6 +27,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"apm", 'B', 0, N_("Set Advanced Power Management\n"
|
||||
"(1=low, ..., 254=high, 255=off)."),
|
||||
|
@ -61,60 +64,64 @@ enum grub_ata_smart_commands
|
|||
static int quiet = 0;
|
||||
|
||||
static grub_err_t
|
||||
grub_hdparm_do_ata_cmd (grub_disk_t disk, grub_uint8_t cmd,
|
||||
grub_hdparm_do_ata_cmd (grub_ata_t ata, grub_uint8_t cmd,
|
||||
grub_uint8_t features, grub_uint8_t sectors,
|
||||
void * buffer, int size)
|
||||
{
|
||||
struct grub_disk_ata_pass_through_parms apt;
|
||||
grub_memset (&apt, 0, sizeof (apt));
|
||||
|
||||
apt.taskfile[GRUB_ATA_REG_CMD] = cmd;
|
||||
apt.taskfile[GRUB_ATA_REG_FEATURES] = features;
|
||||
apt.taskfile[GRUB_ATA_REG_SECTORS] = sectors;
|
||||
apt.taskfile.cmd = cmd;
|
||||
apt.taskfile.features = features;
|
||||
apt.taskfile.sectors = sectors;
|
||||
apt.taskfile.disk = 0xE0;
|
||||
|
||||
apt.buffer = buffer;
|
||||
apt.size = size;
|
||||
|
||||
if (grub_disk_ata_pass_through (disk, &apt))
|
||||
if (ata->dev->readwrite (ata, &apt, 0))
|
||||
return grub_errno;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_hdparm_do_check_powermode_cmd (grub_disk_t disk)
|
||||
grub_hdparm_do_check_powermode_cmd (grub_ata_t ata)
|
||||
{
|
||||
struct grub_disk_ata_pass_through_parms apt;
|
||||
grub_memset (&apt, 0, sizeof (apt));
|
||||
|
||||
apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_CHECK_POWER_MODE;
|
||||
apt.taskfile.cmd = GRUB_ATA_CMD_CHECK_POWER_MODE;
|
||||
apt.taskfile.disk = 0xE0;
|
||||
|
||||
if (grub_disk_ata_pass_through (disk, &apt))
|
||||
if (ata->dev->readwrite (ata, &apt, 0))
|
||||
return -1;
|
||||
|
||||
return apt.taskfile[GRUB_ATA_REG_SECTORS];
|
||||
return apt.taskfile.sectors;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_hdparm_do_smart_cmd (grub_disk_t disk, grub_uint8_t features)
|
||||
grub_hdparm_do_smart_cmd (grub_ata_t ata, grub_uint8_t features)
|
||||
{
|
||||
struct grub_disk_ata_pass_through_parms apt;
|
||||
grub_memset (&apt, 0, sizeof (apt));
|
||||
|
||||
apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_SMART;
|
||||
apt.taskfile[GRUB_ATA_REG_FEATURES] = features;
|
||||
apt.taskfile[GRUB_ATA_REG_LBAMID] = 0x4f;
|
||||
apt.taskfile[GRUB_ATA_REG_LBAHIGH] = 0xc2;
|
||||
apt.taskfile.cmd = GRUB_ATA_CMD_SMART;
|
||||
apt.taskfile.features = features;
|
||||
apt.taskfile.lba_mid = 0x4f;
|
||||
apt.taskfile.lba_high = 0xc2;
|
||||
apt.taskfile.disk = 0xE0;
|
||||
|
||||
if (grub_disk_ata_pass_through (disk, &apt))
|
||||
if (ata->dev->readwrite (ata, &apt, 0))
|
||||
return -1;
|
||||
|
||||
if (features == GRUB_ATA_FEAT_SMART_STATUS)
|
||||
{
|
||||
if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0x4f
|
||||
&& apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0xc2)
|
||||
if ( apt.taskfile.lba_mid == 0x4f
|
||||
&& apt.taskfile.lba_high == 0xc2)
|
||||
return 0; /* Good SMART status. */
|
||||
else if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0xf4
|
||||
&& apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0x2c)
|
||||
else if ( apt.taskfile.lba_mid == 0xf4
|
||||
&& apt.taskfile.lba_high == 0x2c)
|
||||
return 1; /* Bad SMART status. */
|
||||
else
|
||||
return -1;
|
||||
|
@ -124,12 +131,12 @@ grub_hdparm_do_smart_cmd (grub_disk_t disk, grub_uint8_t features)
|
|||
|
||||
static grub_err_t
|
||||
grub_hdparm_simple_cmd (const char * msg,
|
||||
grub_disk_t disk, grub_uint8_t cmd)
|
||||
grub_ata_t ata, grub_uint8_t cmd)
|
||||
{
|
||||
if (! quiet && msg)
|
||||
grub_printf ("%s", msg);
|
||||
|
||||
grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, 0, 0, NULL, 0);
|
||||
grub_err_t err = grub_hdparm_do_ata_cmd (ata, cmd, 0, 0, NULL, 0);
|
||||
|
||||
if (! quiet && msg)
|
||||
grub_printf ("%s\n", ! err ? "" : ": not supported");
|
||||
|
@ -138,7 +145,7 @@ grub_hdparm_simple_cmd (const char * msg,
|
|||
|
||||
static grub_err_t
|
||||
grub_hdparm_set_val_cmd (const char * msg, int val,
|
||||
grub_disk_t disk, grub_uint8_t cmd,
|
||||
grub_ata_t ata, grub_uint8_t cmd,
|
||||
grub_uint8_t features, grub_uint8_t sectors)
|
||||
{
|
||||
if (! quiet && msg && *msg)
|
||||
|
@ -149,7 +156,7 @@ grub_hdparm_set_val_cmd (const char * msg, int val,
|
|||
grub_printf ("Disable %s", msg);
|
||||
}
|
||||
|
||||
grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, features, sectors,
|
||||
grub_err_t err = grub_hdparm_do_ata_cmd (ata, cmd, features, sectors,
|
||||
NULL, 0);
|
||||
|
||||
if (! quiet && msg)
|
||||
|
@ -158,22 +165,20 @@ grub_hdparm_set_val_cmd (const char * msg, int val,
|
|||
}
|
||||
|
||||
static const char *
|
||||
le16_to_char (char *dest, const grub_uint16_t * src16, unsigned bytes)
|
||||
le16_to_char (grub_uint16_t *dest, const grub_uint16_t * src16, unsigned bytes)
|
||||
{
|
||||
grub_uint16_t * dest16 = (grub_uint16_t *) dest;
|
||||
unsigned i;
|
||||
for (i = 0; i < bytes / 2; i++)
|
||||
dest16[i] = grub_be_to_cpu16 (src16[i]);
|
||||
return dest;
|
||||
dest[i] = grub_be_to_cpu16 (src16[i]);
|
||||
dest[i] = 0;
|
||||
return (char *) dest;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_hdparm_print_identify (const char * idbuf)
|
||||
grub_hdparm_print_identify (const grub_uint16_t * idw)
|
||||
{
|
||||
const grub_uint16_t * idw = (const grub_uint16_t *) idbuf;
|
||||
|
||||
/* Print identity strings. */
|
||||
char tmp[40];
|
||||
grub_uint16_t tmp[21];
|
||||
grub_printf ("Model: \"%.40s\"\n", le16_to_char (tmp, &idw[27], 40));
|
||||
grub_printf ("Firmware: \"%.8s\"\n", le16_to_char (tmp, &idw[23], 8));
|
||||
grub_printf ("Serial: \"%.20s\"\n", le16_to_char (tmp, &idw[10], 20));
|
||||
|
@ -273,6 +278,7 @@ static grub_err_t
|
|||
grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
||||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
struct grub_ata *ata;
|
||||
|
||||
/* Check command line. */
|
||||
if (argc != 1)
|
||||
|
@ -283,9 +289,6 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "argument is not a device name");
|
||||
args[0][len - 1] = 0;
|
||||
|
||||
if (! grub_disk_ata_pass_through)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "ATA pass through not available");
|
||||
|
||||
int i = 0;
|
||||
int apm = get_int_arg (&state[i++]);
|
||||
int power = state[i++].set;
|
||||
|
@ -311,15 +314,37 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "partition not allowed");
|
||||
}
|
||||
|
||||
switch (disk->dev->id)
|
||||
{
|
||||
case GRUB_DISK_DEVICE_ATA_ID:
|
||||
ata = disk->data;
|
||||
break;
|
||||
case GRUB_DISK_DEVICE_SCSI_ID:
|
||||
if (((disk->id >> GRUB_SCSI_ID_SUBSYSTEM_SHIFT) & 0xFF)
|
||||
== GRUB_SCSI_SUBSYSTEM_PATA
|
||||
|| (((disk->id >> GRUB_SCSI_ID_SUBSYSTEM_SHIFT) & 0xFF)
|
||||
== GRUB_SCSI_SUBSYSTEM_AHCI))
|
||||
{
|
||||
ata = ((struct grub_scsi *) disk->data)->data;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return grub_error (GRUB_ERR_IO, "not an ATA device");
|
||||
}
|
||||
|
||||
|
||||
/* Change settings. */
|
||||
if (aam >= 0)
|
||||
grub_hdparm_set_val_cmd ("Automatic Acoustic Management", (aam ? aam : -1),
|
||||
disk, GRUB_ATA_CMD_SET_FEATURES, (aam ? 0x42 : 0xc2), aam);
|
||||
ata, GRUB_ATA_CMD_SET_FEATURES,
|
||||
(aam ? 0x42 : 0xc2), aam);
|
||||
|
||||
if (apm >= 0)
|
||||
grub_hdparm_set_val_cmd ("Advanced Power Management",
|
||||
(apm != 255 ? apm : -1), disk, GRUB_ATA_CMD_SET_FEATURES,
|
||||
(apm != 255 ? 0x05 : 0x85), (apm != 255 ? apm : 0));
|
||||
(apm != 255 ? apm : -1), ata,
|
||||
GRUB_ATA_CMD_SET_FEATURES,
|
||||
(apm != 255 ? 0x05 : 0x85),
|
||||
(apm != 255 ? apm : 0));
|
||||
|
||||
if (standby_tout >= 0)
|
||||
{
|
||||
|
@ -330,28 +355,28 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
grub_printf (")");
|
||||
}
|
||||
/* The IDLE cmd sets disk to idle mode and configures standby timer. */
|
||||
grub_hdparm_set_val_cmd ("", -1, disk, GRUB_ATA_CMD_IDLE, 0, standby_tout);
|
||||
grub_hdparm_set_val_cmd ("", -1, ata, GRUB_ATA_CMD_IDLE, 0, standby_tout);
|
||||
}
|
||||
|
||||
if (enable_smart >= 0)
|
||||
{
|
||||
if (! quiet)
|
||||
grub_printf ("%sable SMART operations", (enable_smart ? "En" : "Dis"));
|
||||
int err = grub_hdparm_do_smart_cmd (disk, (enable_smart ?
|
||||
int err = grub_hdparm_do_smart_cmd (ata, (enable_smart ?
|
||||
GRUB_ATA_FEAT_SMART_ENABLE : GRUB_ATA_FEAT_SMART_DISABLE));
|
||||
if (! quiet)
|
||||
grub_printf ("%s\n", err ? ": not supported" : "");
|
||||
}
|
||||
|
||||
if (sec_freeze)
|
||||
grub_hdparm_simple_cmd ("Freeze security settings", disk,
|
||||
grub_hdparm_simple_cmd ("Freeze security settings", ata,
|
||||
GRUB_ATA_CMD_SECURITY_FREEZE_LOCK);
|
||||
|
||||
/* Print/dump IDENTIFY. */
|
||||
if (ident || dumpid)
|
||||
{
|
||||
char buf[GRUB_DISK_SECTOR_SIZE];
|
||||
if (grub_hdparm_do_ata_cmd (disk, GRUB_ATA_CMD_IDENTIFY_DEVICE,
|
||||
grub_uint16_t buf[GRUB_DISK_SECTOR_SIZE / 2];
|
||||
if (grub_hdparm_do_ata_cmd (ata, GRUB_ATA_CMD_IDENTIFY_DEVICE,
|
||||
0, 0, buf, sizeof (buf)))
|
||||
grub_printf ("Cannot read ATA IDENTIFY data\n");
|
||||
else
|
||||
|
@ -359,7 +384,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
if (ident)
|
||||
grub_hdparm_print_identify (buf);
|
||||
if (dumpid)
|
||||
hexdump (0, buf, sizeof (buf));
|
||||
hexdump (0, (char *) buf, sizeof (buf));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +392,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
if (power)
|
||||
{
|
||||
grub_printf ("Disk power mode is: ");
|
||||
int mode = grub_hdparm_do_check_powermode_cmd (disk);
|
||||
int mode = grub_hdparm_do_check_powermode_cmd (ata);
|
||||
if (mode < 0)
|
||||
grub_printf ("unknown\n");
|
||||
else
|
||||
|
@ -383,7 +408,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
{
|
||||
if (! quiet)
|
||||
grub_printf ("SMART status is: ");
|
||||
int err = grub_hdparm_do_smart_cmd (disk, GRUB_ATA_FEAT_SMART_STATUS);
|
||||
int err = grub_hdparm_do_smart_cmd (ata, GRUB_ATA_FEAT_SMART_STATUS);
|
||||
if (! quiet)
|
||||
grub_printf ("%s\n", (err < 0 ? "unknown" :
|
||||
err == 0 ? "OK" : "*BAD*"));
|
||||
|
@ -392,11 +417,11 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) // state????
|
|||
|
||||
/* Change power mode. */
|
||||
if (standby_now)
|
||||
grub_hdparm_simple_cmd ("Set disk to standby mode", disk,
|
||||
grub_hdparm_simple_cmd ("Set disk to standby mode", ata,
|
||||
GRUB_ATA_CMD_STANDBY_IMMEDIATE);
|
||||
|
||||
if (sleep_now)
|
||||
grub_hdparm_simple_cmd ("Set disk to sleep mode", disk,
|
||||
grub_hdparm_simple_cmd ("Set disk to sleep mode", ata,
|
||||
GRUB_ATA_CMD_SLEEP);
|
||||
|
||||
grub_disk_close (disk);
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/normal.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc,
|
||||
char **args)
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"skip", 's', 0, N_("Skip offset bytes from the beginning of file."), 0,
|
||||
ARG_TYPE_INT},
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/cmos.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
parse_args (int argc, char *argv[], int *byte, int *bit)
|
||||
|
@ -44,12 +47,17 @@ grub_cmd_cmostest (struct grub_command *cmd __attribute__ ((unused)),
|
|||
{
|
||||
int byte, bit;
|
||||
grub_err_t err;
|
||||
grub_uint8_t value;
|
||||
|
||||
err = parse_args (argc, argv, &byte, &bit);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (grub_cmos_read (byte) & (1 << bit))
|
||||
err = grub_cmos_read (byte, &value);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (value & (1 << bit))
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||
|
@ -61,13 +69,16 @@ grub_cmd_cmosclean (struct grub_command *cmd __attribute__ ((unused)),
|
|||
{
|
||||
int byte, bit;
|
||||
grub_err_t err;
|
||||
grub_uint8_t value;
|
||||
|
||||
err = parse_args (argc, argv, &byte, &bit);
|
||||
if (err)
|
||||
return err;
|
||||
err = grub_cmos_read (byte, &value);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_cmos_write (byte, grub_cmos_read (byte) & (~(1 << bit)));
|
||||
return GRUB_ERR_NONE;
|
||||
return grub_cmos_write (byte, value & (~(1 << bit)));
|
||||
}
|
||||
|
||||
static grub_command_t cmd, cmd_clean;
|
||||
|
@ -76,11 +87,11 @@ static grub_command_t cmd, cmd_clean;
|
|||
GRUB_MOD_INIT(cmostest)
|
||||
{
|
||||
cmd = grub_register_command ("cmostest", grub_cmd_cmostest,
|
||||
"cmostest BYTE:BIT",
|
||||
"Test bit at BYTE:BIT in CMOS.");
|
||||
N_("BYTE:BIT"),
|
||||
N_("Test bit at BYTE:BIT in CMOS."));
|
||||
cmd_clean = grub_register_command ("cmosclean", grub_cmd_cmosclean,
|
||||
"cmosclean BYTE:BIT",
|
||||
"Clean bit at BYTE:BIT in CMOS.");
|
||||
N_("BYTE:BIT"),
|
||||
N_("Clean bit at BYTE:BIT in CMOS."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(cmostest)
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <grub/i386/cpuid.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define cpuid(num,a,b,c,d) \
|
||||
asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
|
||||
: "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
|
||||
|
|
|
@ -29,9 +29,10 @@
|
|||
#include <grub/memory.h>
|
||||
#include <grub/machine/memory.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */
|
||||
static grub_uint32_t *const int13slot = UINT_TO_PTR (4 * 0x13);
|
||||
static grub_uint32_t *const int13slot = (grub_uint32_t *) (4 * 0x13);
|
||||
|
||||
/* Remember to update enum opt_idxs accordingly. */
|
||||
static const struct grub_arg_option options[] = {
|
||||
|
@ -177,11 +178,11 @@ list_mappings (void)
|
|||
/* Show: list mappings. */
|
||||
if (! map_head)
|
||||
{
|
||||
grub_printf ("No drives have been remapped\n");
|
||||
grub_puts_ (N_("No drives have been remapped"));
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_printf ("OS disk #num ------> GRUB/BIOS device\n");
|
||||
grub_puts_ (N_("OS disk #num ------> GRUB/BIOS device"));
|
||||
drivemap_node_t *curnode = map_head;
|
||||
while (curnode)
|
||||
{
|
||||
|
@ -362,7 +363,7 @@ uninstall_int13_handler (void)
|
|||
static int
|
||||
grub_get_root_biosnumber_drivemap (void)
|
||||
{
|
||||
char *biosnum;
|
||||
const char *biosnum;
|
||||
int ret = -1;
|
||||
grub_device_t dev;
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/machine/int.h>
|
||||
#include <grub/acpi.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"no-apm", 'n', 0, N_("Do not use APM to halt the computer."), 0, 0},
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
int
|
||||
grub_apm_get_info (struct grub_apm_info *info)
|
||||
{
|
||||
|
@ -72,27 +74,27 @@ grub_cmd_lsapm (grub_command_t cmd __attribute__ ((unused)),
|
|||
if (!grub_apm_get_info (&info))
|
||||
return grub_error (GRUB_ERR_IO, "no APM found");
|
||||
|
||||
grub_printf ("Vesion %u.%u\n"
|
||||
"32-bit CS = 0x%x, len = 0x%x, offset = 0x%x\n"
|
||||
"16-bit CS = 0x%x, len = 0x%x\n"
|
||||
"DS = 0x%x, len = 0x%x\n",
|
||||
info.version >> 8, info.version & 0xff,
|
||||
info.cseg, info.cseg_len, info.offset,
|
||||
info.cseg_16, info.cseg_16_len,
|
||||
info.dseg, info.dseg_len);
|
||||
grub_printf_ (N_("Vesion %u.%u\n"
|
||||
"32-bit CS = 0x%x, len = 0x%x, offset = 0x%x\n"
|
||||
"16-bit CS = 0x%x, len = 0x%x\n"
|
||||
"DS = 0x%x, len = 0x%x\n"),
|
||||
info.version >> 8, info.version & 0xff,
|
||||
info.cseg, info.cseg_len, info.offset,
|
||||
info.cseg_16, info.cseg_16_len,
|
||||
info.dseg, info.dseg_len);
|
||||
grub_xputs (info.flags & GRUB_APM_FLAGS_16BITPROTECTED_SUPPORTED
|
||||
? "16-bit protected interface supported\n"
|
||||
: "16-bit protected interface unsupported\n");
|
||||
? _("16-bit protected interface supported\n")
|
||||
: _("16-bit protected interface unsupported\n"));
|
||||
grub_xputs (info.flags & GRUB_APM_FLAGS_32BITPROTECTED_SUPPORTED
|
||||
? "32-bit protected interface supported\n"
|
||||
: "32-bit protected interface unsupported\n");
|
||||
? _("32-bit protected interface supported\n")
|
||||
: _("32-bit protected interface unsupported\n"));
|
||||
grub_xputs (info.flags & GRUB_APM_FLAGS_CPUIDLE_SLOWS_DOWN
|
||||
? "CPU Idle slows down processor\n"
|
||||
: "CPU Idle doesn't slow down processor\n");
|
||||
? _("CPU Idle slows down processor\n")
|
||||
: _("CPU Idle doesn't slow down processor\n"));
|
||||
grub_xputs (info.flags & GRUB_APM_FLAGS_DISABLED
|
||||
? "APM disabled\n" : "APM enabled\n");
|
||||
? _("APM disabled\n") : _("APM enabled\n"));
|
||||
grub_xputs (info.flags & GRUB_APM_FLAGS_DISENGAGED
|
||||
? "APM disengaged\n" : "APM engaged\n");
|
||||
? _("APM disengaged\n") : _("APM engaged\n"));
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define BASE_TEMPO (60 * GRUB_TICKS_PER_SECOND)
|
||||
|
||||
/* The speaker port. */
|
||||
|
@ -190,7 +192,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
|||
file = grub_file_open (args[0]);
|
||||
|
||||
if (! file)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]);
|
||||
|
||||
if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo))
|
||||
{
|
||||
|
@ -225,7 +227,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
if (*end)
|
||||
/* Was not a number either, assume it was supposed to be a file name. */
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]);
|
||||
|
||||
grub_dprintf ("play","tempo = %d\n", tempo);
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv2+");
|
||||
|
||||
static char sendkey[0x20];
|
||||
/* Length of sendkey. */
|
||||
|
@ -33,23 +36,23 @@ static int keylen = 0;
|
|||
static int noled = 0;
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"num", 'n', 0, "set numlock mode", "[on|off]", ARG_TYPE_STRING},
|
||||
{"caps", 'c', 0, "set capslock mode", "[on|off]", ARG_TYPE_STRING},
|
||||
{"scroll", 's', 0, "set scrolllock mode", "[on|off]", ARG_TYPE_STRING},
|
||||
{"insert", 0, 0, "set insert mode", "[on|off]", ARG_TYPE_STRING},
|
||||
{"pause", 0, 0, "set pause mode", "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-shift", 0, 0, "press left shift", "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-shift", 0, 0, "press right shift", "[on|off]", ARG_TYPE_STRING},
|
||||
{"sysrq", 0, 0, "press SysRq", "[on|off]", ARG_TYPE_STRING},
|
||||
{"numkey", 0, 0, "press NumLock key", "[on|off]", ARG_TYPE_STRING},
|
||||
{"capskey", 0, 0, "press CapsLock key", "[on|off]", ARG_TYPE_STRING},
|
||||
{"scrollkey", 0, 0, "press ScrollLock key", "[on|off]", ARG_TYPE_STRING},
|
||||
{"insertkey", 0, 0, "press Insert key", "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-alt", 0, 0, "press left alt", "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-alt", 0, 0, "press right alt", "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-ctrl", 0, 0, "press left ctrl", "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-ctrl", 0, 0, "press right ctrl", "[on|off]", ARG_TYPE_STRING},
|
||||
{"no-led", 0, 0, "don't update LED state", 0, 0},
|
||||
{"num", 'n', 0, N_("set numlock mode"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"caps", 'c', 0, N_("set capslock mode"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"scroll", 's', 0, N_("set scrolllock mode"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"insert", 0, 0, N_("set insert mode"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"pause", 0, 0, N_("set pause mode"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-shift", 0, 0, N_("press left shift"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-shift", 0, 0, N_("press right shift"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"sysrq", 0, 0, N_("press SysRq"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"numkey", 0, 0, N_("press NumLock key"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"capskey", 0, 0, N_("press CapsLock key"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"scrollkey", 0, 0, N_("press ScrollLock key"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"insertkey", 0, 0, N_("press Insert key"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-alt", 0, 0, N_("press left alt"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-alt", 0, 0, N_("press right alt"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"left-ctrl", 0, 0, N_("press left ctrl"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"right-ctrl", 0, 0, N_("press right ctrl"), "[on|off]", ARG_TYPE_STRING},
|
||||
{"no-led", 0, 0, N_("don't update LED state"), 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
static int simple_flag_offsets[]
|
||||
|
@ -60,8 +63,8 @@ static grub_uint32_t andmask = 0xffffffff, ormask = 0;
|
|||
struct
|
||||
keysym
|
||||
{
|
||||
char *unshifted_name; /* the name in unshifted state */
|
||||
char *shifted_name; /* the name in shifted state */
|
||||
const char *unshifted_name; /* the name in unshifted state */
|
||||
const char *shifted_name; /* the name in shifted state */
|
||||
unsigned char unshifted_ascii; /* the ascii code in unshifted state */
|
||||
unsigned char shifted_ascii; /* the ascii code in shifted state */
|
||||
unsigned char keycode; /* keyboard scancode */
|
||||
|
@ -362,13 +365,13 @@ grub_cmd_sendkey (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
}
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
static void *preboot_hook;
|
||||
static struct grub_preboot *preboot_hook;
|
||||
|
||||
GRUB_MOD_INIT (sendkey)
|
||||
{
|
||||
cmd = grub_register_extcmd ("sendkey", grub_cmd_sendkey, 0,
|
||||
"sendkey [KEYSTROKE1] [KEYSTROKE2] ...",
|
||||
"Emulate a keystroke", options);
|
||||
N_("[KEYSTROKE1] [KEYSTROKE2] ..."),
|
||||
N_("Emulate a keystroke"), options);
|
||||
|
||||
preboot_hook
|
||||
= grub_loader_register_preboot_hook (grub_sendkey_preboot,
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_suspend (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_printf ("Run 'go' to resume GRUB.\n");
|
||||
grub_puts_ (N_("Run 'go' to resume GRUB."));
|
||||
grub_ieee1275_enter ();
|
||||
grub_cls ();
|
||||
return 0;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <grub/cpu/io.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword;
|
||||
static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword;
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/file.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static struct grub_keyboard_layout layout_us = {
|
||||
.keyboard_map = {
|
||||
/* Keyboard errors. Handled by driver. */
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <grub/term.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"shift", 's', 0, N_("Check Shift key."), 0, 0},
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <grub/disk.h>
|
||||
#include <grub/partition.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
legacy_file (const char *filename)
|
||||
{
|
||||
|
@ -83,9 +85,13 @@ legacy_file (const char *filename)
|
|||
{
|
||||
char *oldname = NULL;
|
||||
char *newsuffix;
|
||||
char *ptr;
|
||||
|
||||
for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
|
||||
|
||||
oldname = entryname;
|
||||
parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
|
||||
parsed = grub_legacy_parse (ptr, &entryname, &newsuffix);
|
||||
grub_free (buf);
|
||||
buf = NULL;
|
||||
if (newsuffix)
|
||||
{
|
||||
|
@ -177,9 +183,6 @@ legacy_file (const char *filename)
|
|||
grub_free (suffix);
|
||||
grub_free (entrysrc);
|
||||
|
||||
if (menu && menu->size)
|
||||
grub_show_menu (menu, 1);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -194,8 +197,8 @@ grub_cmd_legacy_source (struct grub_command *cmd,
|
|||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
|
||||
|
||||
extractor = (cmd->name[0] == 'e');
|
||||
new_env = (cmd->name[extractor ? sizeof ("extract_legacy_entries_") - 1
|
||||
: sizeof ("legacy_") - 1] == 'c');
|
||||
new_env = (cmd->name[extractor ? (sizeof ("extract_legacy_entries_") - 1)
|
||||
: (sizeof ("legacy_") - 1)] == 'c');
|
||||
|
||||
if (new_env)
|
||||
grub_cls ();
|
||||
|
@ -207,8 +210,15 @@ grub_cmd_legacy_source (struct grub_command *cmd,
|
|||
|
||||
ret = legacy_file (args[0]);
|
||||
|
||||
if (new_env && !extractor)
|
||||
grub_env_context_close ();
|
||||
if (new_env)
|
||||
{
|
||||
grub_menu_t menu;
|
||||
menu = grub_env_get_menu ();
|
||||
if (menu && menu->size)
|
||||
grub_show_menu (menu, 1, 0);
|
||||
if (!extractor)
|
||||
grub_env_context_close ();
|
||||
}
|
||||
if (extractor)
|
||||
grub_env_extractor_close (!new_env);
|
||||
|
||||
|
@ -225,7 +235,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 +247,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;
|
||||
|
@ -330,7 +344,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
|||
int bsd_part = -1;
|
||||
{
|
||||
grub_device_t dev;
|
||||
char *hdbiasstr;
|
||||
const char *hdbiasstr;
|
||||
int hdbias = 0;
|
||||
hdbiasstr = grub_env_get ("legacy_hdbias");
|
||||
if (hdbiasstr)
|
||||
|
@ -709,7 +723,7 @@ grub_cmd_legacy_check_password (struct grub_command *mycmd __attribute__ ((unuse
|
|||
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "arguments expected");
|
||||
grub_printf ("Enter password:");
|
||||
grub_puts_ (N_("Enter password: "));
|
||||
if (!grub_password_get (entered, GRUB_AUTH_MAX_PASSLEN))
|
||||
return GRUB_ACCESS_DENIED;
|
||||
|
||||
|
@ -757,12 +771,12 @@ GRUB_MOD_INIT(legacycfg)
|
|||
= grub_register_command ("extract_legacy_entries_source",
|
||||
grub_cmd_legacy_source,
|
||||
N_("FILE"),
|
||||
N_("Parse legacy config in same context taking onl entries"));
|
||||
N_("Parse legacy config in same context taking only menu entries"));
|
||||
cmd_configfile_extract
|
||||
= grub_register_command ("extract_legacy_entries_configfile",
|
||||
grub_cmd_legacy_source,
|
||||
N_("FILE"),
|
||||
N_("Parse legacy config in new context taking onl entries"));
|
||||
N_("Parse legacy config in new context taking only menu entries"));
|
||||
|
||||
cmd_kernel = grub_register_command ("legacy_kernel",
|
||||
grub_cmd_legacy_kernel,
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME},
|
||||
|
@ -41,7 +43,7 @@ open_envblk_file (char *filename)
|
|||
|
||||
if (! filename)
|
||||
{
|
||||
char *prefix;
|
||||
const char *prefix;
|
||||
|
||||
prefix = grub_env_get ("prefix");
|
||||
if (prefix)
|
||||
|
@ -344,7 +346,7 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
|
||||
while (argc)
|
||||
{
|
||||
char *value;
|
||||
const char *value;
|
||||
|
||||
value = grub_env_get (args[0]);
|
||||
if (value)
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
|
@ -58,6 +61,22 @@ grub_ls_list_devices (int longlist)
|
|||
|
||||
grub_device_iterate (grub_ls_print_devices);
|
||||
grub_xputs ("\n");
|
||||
|
||||
#ifndef GRUB_UTIL
|
||||
{
|
||||
grub_net_app_level_t proto;
|
||||
int first = 1;
|
||||
FOR_NET_APP_LEVEL (proto)
|
||||
{
|
||||
if (first)
|
||||
grub_puts_ (N_ ("Network protocols:"));
|
||||
first = 0;
|
||||
grub_printf ("%s ", proto->name);
|
||||
}
|
||||
grub_xputs ("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
grub_refresh ();
|
||||
|
||||
return 0;
|
||||
|
@ -132,11 +151,12 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
|
||||
if (units)
|
||||
{
|
||||
grub_uint32_t whole, fraction;
|
||||
grub_uint64_t whole, fraction;
|
||||
|
||||
whole = grub_divmod64 (fsize, 100, &fraction);
|
||||
grub_snprintf (buf, sizeof (buf),
|
||||
"%u.%02u%c", whole, fraction,
|
||||
"%" PRIuGRUB_UINT64_T
|
||||
".%02" PRIuGRUB_UINT64_T "%c", whole, fraction,
|
||||
grub_human_sizes[units]);
|
||||
grub_printf ("%-12s", buf);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static void
|
||||
print_strn (grub_uint8_t *str, grub_size_t len)
|
||||
{
|
||||
|
|
|
@ -22,15 +22,17 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/memory.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const char *names[] =
|
||||
{
|
||||
[GRUB_MEMORY_AVAILABLE] = "available",
|
||||
[GRUB_MEMORY_RESERVED] = "reserved",
|
||||
[GRUB_MEMORY_ACPI] = "ACPI reclamaible",
|
||||
[GRUB_MEMORY_NVS] = "NVS",
|
||||
[GRUB_MEMORY_BADRAM] = "BadRAM",
|
||||
[GRUB_MEMORY_CODE] = "firmware code",
|
||||
[GRUB_MEMORY_HOLE] = "hole"
|
||||
[GRUB_MEMORY_AVAILABLE] = N_("available"),
|
||||
[GRUB_MEMORY_RESERVED] = N_("reserved"),
|
||||
[GRUB_MEMORY_ACPI] = N_("ACPI reclamaible"),
|
||||
[GRUB_MEMORY_NVS] = N_("ACPI non-volatile storage"),
|
||||
[GRUB_MEMORY_BADRAM] = N_("BadRAM"),
|
||||
[GRUB_MEMORY_CODE] = N_("firmware code"),
|
||||
[GRUB_MEMORY_HOLE] = N_("hole")
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
|
@ -44,11 +46,11 @@ grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)),
|
|||
grub_memory_type_t type)
|
||||
{
|
||||
if (type < ARRAY_SIZE (names) && names[type])
|
||||
grub_printf ("base_addr = 0x%llx, length = 0x%llx, %s\n",
|
||||
(long long) addr, (long long) size, names[type]);
|
||||
grub_printf_ (N_("base_addr = 0x%llx, length = 0x%llx, %s\n"),
|
||||
(long long) addr, (long long) size, _(names[type]));
|
||||
else
|
||||
grub_printf ("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n",
|
||||
(long long) addr, (long long) size, type);
|
||||
grub_printf_ (N_("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n"),
|
||||
(long long) addr, (long long) size, type);
|
||||
return 0;
|
||||
}
|
||||
#ifndef GRUB_MACHINE_EMU
|
||||
|
|
|
@ -23,11 +23,13 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_pci_classname
|
||||
{
|
||||
int class;
|
||||
int subclass;
|
||||
char *desc;
|
||||
const char *desc;
|
||||
};
|
||||
|
||||
static const struct grub_pci_classname grub_pci_classes[] =
|
||||
|
|
|
@ -23,13 +23,15 @@
|
|||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword;
|
||||
static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword;
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{0, 'v', 0, N_("Save read value into variable VARNAME."),
|
||||
"VARNAME", ARG_TYPE_STRING},
|
||||
N_("VARNAME"), ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
|
|
@ -28,19 +28,19 @@
|
|||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"class", 1, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("Menu entry type."), "STRING", ARG_TYPE_STRING},
|
||||
N_("Menu entry type."), N_("STRING"), ARG_TYPE_STRING},
|
||||
{"users", 2, 0,
|
||||
N_("Users allowed to boot this entry."), "USERNAME", ARG_TYPE_STRING},
|
||||
N_("Users allowed to boot this entry."), N_("USERNAME"), ARG_TYPE_STRING},
|
||||
{"hotkey", 3, 0,
|
||||
N_("Keyboard key for this entry."), "KEY", ARG_TYPE_STRING},
|
||||
N_("Keyboard key for this entry."), N_("KEY"), ARG_TYPE_STRING},
|
||||
{"source", 4, 0,
|
||||
N_("Menu entry definition as a string."), "STRING", ARG_TYPE_STRING},
|
||||
N_("Menu entry definition as a string."), N_("STRING"), ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
int key;
|
||||
} hotkey_aliases[] =
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes,
|
|||
if (! menu_sourcecode)
|
||||
return grub_errno;
|
||||
|
||||
if (classes)
|
||||
if (classes && classes[0])
|
||||
{
|
||||
int i;
|
||||
for (i = 0; classes[i]; i++); /* count # of menuentry classes */
|
||||
|
@ -206,20 +206,6 @@ setparams_prefix (int argc, char **args)
|
|||
char *p;
|
||||
char *result;
|
||||
grub_size_t len = 10;
|
||||
static const char *escape_characters = "\"\\";
|
||||
|
||||
auto char *strescpy (char *, const char *, const char *);
|
||||
char * strescpy (char *d, const char *s, const char *escapes)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (grub_strchr (escapes, *s))
|
||||
*d++ = '\\';
|
||||
*d++ = *s++;
|
||||
}
|
||||
*d = '\0';
|
||||
return d;
|
||||
}
|
||||
|
||||
/* Count resulting string length */
|
||||
for (i = 0; i < argc; i++)
|
||||
|
@ -227,7 +213,7 @@ setparams_prefix (int argc, char **args)
|
|||
len += 3; /* 3 = 1 space + 2 quotes */
|
||||
p = args[i];
|
||||
while (*p)
|
||||
len += grub_strchr (escape_characters, *p++) ? 2 : 1;
|
||||
len += (*p++ == '\'' ? 3 : 1);
|
||||
}
|
||||
|
||||
result = grub_malloc (len + 2);
|
||||
|
@ -235,17 +221,17 @@ setparams_prefix (int argc, char **args)
|
|||
return 0;
|
||||
|
||||
grub_strcpy (result, "setparams");
|
||||
i = 9;
|
||||
p = result + 9;
|
||||
|
||||
for (j = 0; j < argc; j++)
|
||||
{
|
||||
result[i++] = ' ';
|
||||
result[i++] = '"';
|
||||
i = strescpy (result + i, args[j], escape_characters) - result;
|
||||
result[i++] = '"';
|
||||
*p++ = ' ';
|
||||
*p++ = '\'';
|
||||
p = grub_strchrsub (p, args[j], '\'', "'\\''");
|
||||
*p++ = '\'';
|
||||
}
|
||||
result[i++] = '\n';
|
||||
result[i] = '\0';
|
||||
*p++ = '\n';
|
||||
*p = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -269,7 +255,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
|
||||
if (! ctxt->script)
|
||||
return grub_normal_add_menu_entry (argc, (const char **) args,
|
||||
ctxt->state[0].args, ctxt->state[1].arg,
|
||||
(ctxt->state[0].set ? ctxt->state[0].args
|
||||
: NULL), ctxt->state[1].arg,
|
||||
ctxt->state[2].arg, 0,
|
||||
ctxt->state[3].arg,
|
||||
ctxt->extcmd->cmd->name[0] == 's');
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* cat FILE */
|
||||
static grub_err_t
|
||||
grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
|
||||
|
@ -88,26 +90,6 @@ grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
grub_rescue_cmd_info (void)
|
||||
{
|
||||
extern void grub_disk_cache_get_performance (unsigned long *,
|
||||
unsigned long *);
|
||||
unsigned long hits, misses;
|
||||
|
||||
grub_disk_cache_get_performance (&hits, &misses);
|
||||
grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
|
||||
if (hits + misses)
|
||||
{
|
||||
unsigned long ratio = hits * 10000 / (hits + misses);
|
||||
grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
|
||||
}
|
||||
else
|
||||
grub_printf ("(N/A)\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* dump ADDRESS [SIZE] */
|
||||
static grub_err_t
|
||||
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
|
||||
|
@ -163,7 +145,7 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
|
|||
{
|
||||
grub_dl_t mod;
|
||||
|
||||
grub_printf ("Name\tRef Count\tDependencies\n");
|
||||
grub_printf_ (N_("Name\tRef Count\tDependencies\n"));
|
||||
FOR_DL_MODULES (mod)
|
||||
{
|
||||
grub_dl_dep_t dep;
|
||||
|
@ -183,13 +165,13 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
|
|||
}
|
||||
|
||||
/* exit */
|
||||
static grub_err_t
|
||||
static grub_err_t __attribute__ ((noreturn))
|
||||
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
grub_exit ();
|
||||
return 0;
|
||||
/* Not reached. */
|
||||
}
|
||||
|
||||
static grub_command_t cmd_cat, cmd_help;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_lsspd (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
@ -36,43 +39,44 @@ grub_cmd_lsspd (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
if (!grub_cs5536_find (&dev))
|
||||
{
|
||||
grub_printf ("No CS5536 found\n");
|
||||
grub_puts_ (N_("No CS5536 found"));
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
grub_printf ("CS5536 at %d:%d.%d\n", grub_pci_get_bus (dev),
|
||||
grub_pci_get_device (dev), grub_pci_get_function (dev));
|
||||
grub_printf_ (N_("CS5536 at %d:%d.%d\n"), grub_pci_get_bus (dev),
|
||||
grub_pci_get_device (dev), grub_pci_get_function (dev));
|
||||
|
||||
err = grub_cs5536_init_smbus (dev, 0x7fff, &smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_printf ("SMB base = 0x%x\n", smbbase);
|
||||
grub_printf_ (N_("SMB base = 0x%x\n"), smbbase);
|
||||
|
||||
for (i = GRUB_SMB_RAM_START_ADDR;
|
||||
i < GRUB_SMB_RAM_START_ADDR + GRUB_SMB_RAM_NUM_MAX; i++)
|
||||
{
|
||||
struct grub_smbus_spd spd;
|
||||
grub_memset (&spd, 0, sizeof (spd));
|
||||
grub_printf ("Device %d\n", i);
|
||||
grub_printf_ (N_("Device %d\n"), i);
|
||||
err = grub_cs5536_read_spd (smbbase, i, &spd);
|
||||
if (err)
|
||||
{
|
||||
grub_print_error ();
|
||||
continue;
|
||||
}
|
||||
grub_printf ("Written SPD bytes: %d B.\n", spd.written_size);
|
||||
grub_printf ("Total flash size: %d B.\n", 1 << spd.log_total_flash_size);
|
||||
grub_printf_ (N_("Written SPD bytes: %d B.\n"), spd.written_size);
|
||||
grub_printf_ (N_("Total flash size: %d B.\n"),
|
||||
1 << spd.log_total_flash_size);
|
||||
if (spd.memory_type == GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2)
|
||||
{
|
||||
char str[sizeof (spd.ddr2.part_number) + 1];
|
||||
grub_printf ("Memory type: DDR2.\n");
|
||||
grub_puts_ (N_("Memory type: DDR2."));
|
||||
grub_memcpy (str, spd.ddr2.part_number,
|
||||
sizeof (spd.ddr2.part_number));
|
||||
str[sizeof (spd.ddr2.part_number)] = 0;
|
||||
grub_printf ("Part no: %s.\n", str);
|
||||
grub_printf_ (N_("Part no: %s.\n"), str);
|
||||
}
|
||||
else
|
||||
grub_printf ("Memory type: Unknown.\n");
|
||||
grub_puts_ (N_("Memory type: Unknown."));
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -83,7 +87,7 @@ static grub_command_t cmd;
|
|||
GRUB_MOD_INIT(lsspd)
|
||||
{
|
||||
cmd = grub_register_command ("lsspd", grub_cmd_lsspd, 0,
|
||||
"Print Memory information.");
|
||||
N_("Print Memory information."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(lsspd)
|
|
@ -31,13 +31,15 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv2+");
|
||||
|
||||
static struct grub_parttool *parts = 0;
|
||||
static int curhandle = 0;
|
||||
static grub_dl_t mymod;
|
||||
static char helpmsg[] =
|
||||
"Perform COMMANDS on partition.\n"
|
||||
"Use \"parttool PARTITION help\" for the list "
|
||||
"of available commands.";
|
||||
N_("Perform COMMANDS on partition.\n"
|
||||
"Use \"parttool PARTITION help\" for the list "
|
||||
"of available commands.");
|
||||
|
||||
int
|
||||
grub_parttool_register(const char *part_name,
|
||||
|
@ -126,7 +128,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
|||
break;
|
||||
|
||||
case GRUB_PARTTOOL_ARG_VAL:
|
||||
grub_printf ("=VAL");
|
||||
grub_xputs (_("=VAL"));
|
||||
spacing -= 4;
|
||||
break;
|
||||
|
||||
|
@ -135,18 +137,18 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
while (spacing-- > 0)
|
||||
grub_printf (" ");
|
||||
grub_printf ("%s\n", curarg->desc);
|
||||
grub_puts_ (curarg->desc);
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
grub_printf ("Sorry no parttool is available for %s\n",
|
||||
grub_printf_ (N_("Sorry no parttool is available for %s\n"),
|
||||
dev->disk->partition->partmap->name);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
grub_printf ("%s\n", helpmsg);
|
||||
grub_puts_ (helpmsg);
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_dl_t my_mod;
|
||||
|
||||
static grub_err_t
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_dl_t my_mod;
|
||||
|
||||
struct pbkdf2_password
|
||||
|
|
|
@ -32,9 +32,11 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
|
||||
{"set", 's', 0,
|
||||
N_("Set a variable to return value."), "VAR", ARG_TYPE_STRING},
|
||||
{"driver", 'd', 0, N_("Determine driver."), 0, 0},
|
||||
{"partmap", 'p', 0, N_("Determine partition map type."), 0, 0},
|
||||
|
@ -72,7 +74,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
{
|
||||
const char *val = "none";
|
||||
if (dev->net)
|
||||
val = dev->net->dev->name;
|
||||
val = dev->net->protocol->name;
|
||||
if (dev->disk)
|
||||
val = dev->disk->dev->name;
|
||||
if (state[0].set)
|
||||
|
@ -134,7 +136,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
return err;
|
||||
if (! label)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"uuid for this FS isn't supported yet");
|
||||
"label for this FS isn't supported yet");
|
||||
|
||||
if (state[0].set)
|
||||
grub_env_set (state[0].arg, label);
|
||||
|
@ -150,7 +152,7 @@ static grub_extcmd_t cmd;
|
|||
|
||||
GRUB_MOD_INIT (probe)
|
||||
{
|
||||
cmd = grub_register_extcmd ("probe", grub_cmd_probe, 0, N_("[DEVICE]"),
|
||||
cmd = grub_register_extcmd ("probe", grub_cmd_probe, 0, N_("DEVICE"),
|
||||
N_("Retrieve device info."), options);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static char *
|
||||
grub_getline (void)
|
||||
{
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static grub_err_t
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t __attribute__ ((noreturn))
|
||||
grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_reboot ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <grub/script_sh.h>
|
||||
#include <regex.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{ "set", 's', GRUB_ARG_OPTION_REPEATABLE,
|
||||
|
@ -87,7 +89,6 @@ set_matches (char **varnames, char *str, grub_size_t nmatches,
|
|||
static grub_err_t
|
||||
grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int argn = 0;
|
||||
regex_t regex;
|
||||
int ret;
|
||||
grub_size_t s;
|
||||
|
|
|
@ -31,11 +31,23 @@
|
|||
#include <grub/disk.h>
|
||||
#include <grub/partition.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct cache_entry
|
||||
{
|
||||
struct cache_entry *next;
|
||||
char *key;
|
||||
char *value;
|
||||
};
|
||||
|
||||
static struct cache_entry *cache;
|
||||
|
||||
void
|
||||
FUNC_NAME (const char *key, const char *var, int no_floppy,
|
||||
char **hints, unsigned nhints)
|
||||
{
|
||||
int count = 0;
|
||||
int is_cache = 0;
|
||||
grub_fs_autoload_hook_t saved_autoload;
|
||||
|
||||
auto int iterate_device (const char *name);
|
||||
|
@ -48,6 +60,12 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,
|
|||
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||
return 0;
|
||||
|
||||
#ifdef DO_SEARCH_FS_UUID
|
||||
#define compare_fn grub_strcasecmp
|
||||
#else
|
||||
#define compare_fn grub_strcmp
|
||||
#endif
|
||||
|
||||
#ifdef DO_SEARCH_FILE
|
||||
{
|
||||
char *buf;
|
||||
|
@ -79,10 +97,8 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,
|
|||
fs = grub_fs_probe (dev);
|
||||
|
||||
#ifdef DO_SEARCH_FS_UUID
|
||||
#define compare_fn grub_strcasecmp
|
||||
#define read_fn uuid
|
||||
#else
|
||||
#define compare_fn grub_strcmp
|
||||
#define read_fn label
|
||||
#endif
|
||||
|
||||
|
@ -104,6 +120,31 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!is_cache && found && count == 0)
|
||||
{
|
||||
struct cache_entry *cache_ent;
|
||||
cache_ent = grub_malloc (sizeof (*cache_ent));
|
||||
if (cache_ent)
|
||||
{
|
||||
cache_ent->key = grub_strdup (key);
|
||||
cache_ent->value = grub_strdup (name);
|
||||
if (cache_ent->value && cache_ent->key)
|
||||
{
|
||||
cache_ent->next = cache;
|
||||
cache = cache_ent;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_free (cache_ent->value);
|
||||
grub_free (cache_ent->key);
|
||||
grub_free (cache_ent);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
else
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
count++;
|
||||
|
@ -141,6 +182,32 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,
|
|||
void try (void)
|
||||
{
|
||||
unsigned i;
|
||||
struct cache_entry **prev;
|
||||
struct cache_entry *cache_ent;
|
||||
|
||||
for (prev = &cache, cache_ent = *prev; cache_ent;
|
||||
prev = &cache_ent->next, cache_ent = *prev)
|
||||
if (compare_fn (cache_ent->key, key) == 0)
|
||||
break;
|
||||
if (cache_ent)
|
||||
{
|
||||
is_cache = 1;
|
||||
if (iterate_device (cache_ent->value))
|
||||
{
|
||||
is_cache = 0;
|
||||
return;
|
||||
}
|
||||
is_cache = 0;
|
||||
/* Cache entry was outdated. Remove it. */
|
||||
if (!count)
|
||||
{
|
||||
grub_free (cache_ent->key);
|
||||
grub_free (cache_ent->value);
|
||||
grub_free (cache_ent);
|
||||
*prev = cache_ent->next;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < nhints; i++)
|
||||
{
|
||||
char *end;
|
||||
|
@ -162,17 +229,20 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,
|
|||
dev = grub_device_open (hints[i]);
|
||||
if (!dev)
|
||||
{
|
||||
*end = ',';
|
||||
if (!*end)
|
||||
*end = ',';
|
||||
continue;
|
||||
}
|
||||
if (!dev->disk)
|
||||
{
|
||||
grub_device_close (dev);
|
||||
*end = ',';
|
||||
if (!*end)
|
||||
*end = ',';
|
||||
continue;
|
||||
}
|
||||
ret = grub_partition_iterate (dev->disk, part_hook);
|
||||
*end = ',';
|
||||
if (!*end)
|
||||
*end = ',';
|
||||
grub_device_close (dev);
|
||||
if (ret)
|
||||
return;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <grub/search.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"file", 'f', 0, N_("Search devices by a file."), 0, 0},
|
||||
|
@ -40,6 +42,21 @@ static const struct grub_arg_option options[] =
|
|||
{"hint", 'h', GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{"hint-ieee1275", 0, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT if on IEEE1275. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{"hint-bios", 0, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT if on BIOS. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{"hint-baremetal", 0, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{"hint-efi", 0, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT if on EFI. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{"hint-arc", 0, GRUB_ARG_OPTION_REPEATABLE,
|
||||
N_("First try the device HINT if on ARC. If HINT ends in comma, "
|
||||
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -50,7 +67,12 @@ enum options
|
|||
SEARCH_FS_UUID,
|
||||
SEARCH_SET,
|
||||
SEARCH_NO_FLOPPY,
|
||||
SEARCH_HINT
|
||||
SEARCH_HINT,
|
||||
SEARCH_HINT_IEEE1275,
|
||||
SEARCH_HINT_BIOS,
|
||||
SEARCH_HINT_BAREMETAL,
|
||||
SEARCH_HINT_EFI,
|
||||
SEARCH_HINT_ARC,
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
|
@ -58,27 +80,98 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
const char *var = 0;
|
||||
int nhints = 0;
|
||||
int i = 0, j = 0, nhints = 0;
|
||||
char **hints = NULL;
|
||||
|
||||
if (state[SEARCH_HINT].set)
|
||||
while (state[SEARCH_HINT].args[nhints])
|
||||
for (i = 0; state[SEARCH_HINT].args[i]; i++)
|
||||
nhints++;
|
||||
|
||||
if (argc == 0)
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
if (state[SEARCH_HINT_IEEE1275].set)
|
||||
for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
|
||||
nhints++;
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
if (state[SEARCH_HINT_EFI].set)
|
||||
for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
|
||||
nhints++;
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (state[SEARCH_HINT_BIOS].set)
|
||||
for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
|
||||
nhints++;
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_ARC
|
||||
if (state[SEARCH_HINT_ARC].set)
|
||||
for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
|
||||
nhints++;
|
||||
#endif
|
||||
|
||||
if (state[SEARCH_HINT_BAREMETAL].set)
|
||||
for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
|
||||
nhints++;
|
||||
|
||||
hints = grub_malloc (sizeof (hints[0]) * nhints);
|
||||
if (!hints)
|
||||
return grub_errno;
|
||||
j = 0;
|
||||
|
||||
if (state[SEARCH_HINT].set)
|
||||
for (i = 0; state[SEARCH_HINT].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT].args[i];
|
||||
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
if (state[SEARCH_HINT_IEEE1275].set)
|
||||
for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT_IEEE1275].args[i];
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
if (state[SEARCH_HINT_EFI].set)
|
||||
for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT_EFI].args[i];
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_ARC
|
||||
if (state[SEARCH_HINT_ARC].set)
|
||||
for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT_ARC].args[i];
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (state[SEARCH_HINT_BIOS].set)
|
||||
for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT_BIOS].args[i];
|
||||
#endif
|
||||
|
||||
if (state[SEARCH_HINT_BAREMETAL].set)
|
||||
for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
|
||||
hints[j++] = state[SEARCH_HINT_BAREMETAL].args[i];
|
||||
|
||||
/* Skip hints for future platforms. */
|
||||
for (j = 0; j < argc; j++)
|
||||
if (grub_memcmp (args[j], "--hint-", sizeof ("--hint-") - 1) != 0)
|
||||
break;
|
||||
|
||||
if (argc == j)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
|
||||
|
||||
if (state[SEARCH_SET].set)
|
||||
var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
|
||||
|
||||
if (state[SEARCH_LABEL].set)
|
||||
grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set,
|
||||
state[SEARCH_HINT].args, nhints);
|
||||
grub_search_label (args[j], var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
else if (state[SEARCH_FS_UUID].set)
|
||||
grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set,
|
||||
state[SEARCH_HINT].args, nhints);
|
||||
grub_search_fs_uuid (args[j], var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
else if (state[SEARCH_FILE].set)
|
||||
grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set,
|
||||
state[SEARCH_HINT].args, nhints);
|
||||
grub_search_fs_file (args[j], var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
else
|
||||
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
|
||||
|
||||
|
@ -90,7 +183,8 @@ static grub_extcmd_t cmd;
|
|||
GRUB_MOD_INIT(search)
|
||||
{
|
||||
cmd =
|
||||
grub_register_extcmd ("search", grub_cmd_search, GRUB_COMMAND_FLAG_EXTRACTOR,
|
||||
grub_register_extcmd ("search", grub_cmd_search,
|
||||
GRUB_COMMAND_FLAG_EXTRACTOR | GRUB_COMMAND_ACCEPT_DASH,
|
||||
N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]"
|
||||
" NAME"),
|
||||
N_("Search devices by file, filesystem label"
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct pci_register
|
||||
{
|
||||
const char *name;
|
||||
|
@ -32,7 +34,7 @@ struct pci_register
|
|||
unsigned size;
|
||||
};
|
||||
|
||||
struct pci_register pci_registers[] =
|
||||
static struct pci_register pci_registers[] =
|
||||
{
|
||||
{"VENDOR_ID", GRUB_PCI_REG_VENDOR , 2},
|
||||
{"DEVICE_ID", GRUB_PCI_REG_DEVICE , 2},
|
||||
|
@ -64,12 +66,12 @@ struct pci_register pci_registers[] =
|
|||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{0, 'd', 0, "Select device by vendor and device IDs.",
|
||||
"[vendor]:[device]", ARG_TYPE_STRING},
|
||||
{0, 's', 0, "Select device by its position on the bus.",
|
||||
"[bus]:[slot][.func]", ARG_TYPE_STRING},
|
||||
{0, 'v', 0, "Save read value into variable VARNAME.",
|
||||
"VARNAME", ARG_TYPE_STRING},
|
||||
{0, 'd', 0, N_("Select device by vendor and device IDs."),
|
||||
N_("[vendor]:[device]"), ARG_TYPE_STRING},
|
||||
{0, 's', 0, N_("Select device by its position on the bus."),
|
||||
N_("[bus]:[slot][.func]"), ARG_TYPE_STRING},
|
||||
{0, 'v', 0, N_("Save read value into variable VARNAME."),
|
||||
N_("VARNAME"), ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -126,7 +128,7 @@ grub_setpci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
|
|||
|
||||
if (!write_mask)
|
||||
{
|
||||
grub_printf ("Register %x of %d:%d.%d is %x\n", regaddr,
|
||||
grub_printf (N_("Register %x of %d:%d.%d is %x\n"), regaddr,
|
||||
grub_pci_get_bus (dev),
|
||||
grub_pci_get_device (dev),
|
||||
grub_pci_get_function (dev),
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"verbose", 'v', 0, N_("Verbose countdown."), 0, 0},
|
||||
|
|
|
@ -23,12 +23,15 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_term_autoload *grub_term_input_autoload = NULL;
|
||||
struct grub_term_autoload *grub_term_output_autoload = NULL;
|
||||
|
||||
struct abstract_terminal
|
||||
{
|
||||
struct abstract_terminal *next;
|
||||
struct abstract_terminal *prev;
|
||||
const char *name;
|
||||
grub_err_t (*init) (struct abstract_terminal *term);
|
||||
grub_err_t (*fini) (struct abstract_terminal *term);
|
||||
|
@ -92,11 +95,15 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
while (1)
|
||||
{
|
||||
for (term = *disabled; term; term = term->next)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (term == 0)
|
||||
for (term = *enabled; term; term = term->next)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (term)
|
||||
break;
|
||||
|
@ -105,6 +112,8 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
args[i]);
|
||||
for (aut = autoloads; aut; aut = aut->next)
|
||||
if (grub_strcmp (args[i], aut->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", aut->name) == 0)
|
||||
|| (aut->name[0] && aut->name[grub_strlen (aut->name) - 1] == '*'
|
||||
&& grub_memcmp (args[i], aut->name,
|
||||
grub_strlen (aut->name) - 1) == 0))
|
||||
|
@ -128,14 +137,16 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
for (term = *disabled; term; term = term->next)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (term)
|
||||
{
|
||||
if (term->init && term->init (term) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
}
|
||||
}
|
||||
|
@ -147,14 +158,16 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
for (term = *enabled; term; term = term->next)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (term)
|
||||
{
|
||||
if (!term->next && term == *enabled)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"can't remove the last terminal");
|
||||
grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
if (term->fini)
|
||||
term->fini (term);
|
||||
grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
|
@ -165,14 +178,16 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
for (term = *disabled; term; term = term->next)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (term)
|
||||
{
|
||||
if (term->init && term->init (term) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
}
|
||||
}
|
||||
|
@ -183,14 +198,16 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled,
|
|||
{
|
||||
next = term->next;
|
||||
for (i = 0; i < argc; i++)
|
||||
if (grub_strcmp (args[i], term->name) == 0)
|
||||
if (grub_strcmp (args[i], term->name) == 0
|
||||
|| (grub_strcmp (args[i], "ofconsole") == 0
|
||||
&& grub_strcmp ("console", term->name) == 0))
|
||||
break;
|
||||
if (i == argc)
|
||||
{
|
||||
if (!term->next && term == *enabled)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"can't remove the last terminal");
|
||||
grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
|
||||
grub_list_remove (GRUB_AS_LIST (term));
|
||||
if (term->fini)
|
||||
term->fini (term);
|
||||
grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
|
||||
|
@ -206,15 +223,16 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
|
|||
int argc, char **args)
|
||||
{
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, next);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, prev);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, name);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, init);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, fini);
|
||||
return handle_command (argc, args,
|
||||
(struct abstract_terminal **) &grub_term_inputs,
|
||||
(struct abstract_terminal **) &grub_term_inputs_disabled,
|
||||
grub_term_input_autoload,
|
||||
N_ ("Active input terminals:"),
|
||||
N_ ("Available input terminals:"));
|
||||
(struct abstract_terminal **) (void *) &grub_term_inputs,
|
||||
(struct abstract_terminal **) (void *) &grub_term_inputs_disabled,
|
||||
grub_term_input_autoload,
|
||||
N_ ("Active input terminals:"),
|
||||
N_ ("Available input terminals:"));
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
|
@ -222,14 +240,16 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)),
|
|||
int argc, char **args)
|
||||
{
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, next);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, prev);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, name);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, init);
|
||||
(void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, fini);
|
||||
return handle_command (argc, args, (struct abstract_terminal **) &grub_term_outputs,
|
||||
(struct abstract_terminal **) &grub_term_outputs_disabled,
|
||||
grub_term_output_autoload,
|
||||
N_ ("Active output terminals:"),
|
||||
N_ ("Available output terminals:"));
|
||||
return handle_command (argc, args,
|
||||
(struct abstract_terminal **) (void *) &grub_term_outputs,
|
||||
(struct abstract_terminal **) (void *) &grub_term_outputs_disabled,
|
||||
grub_term_output_autoload,
|
||||
N_ ("Active output terminals:"),
|
||||
N_ ("Available output terminals:"));
|
||||
}
|
||||
|
||||
static grub_command_t cmd_terminal_input, cmd_terminal_output;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* A simple implementation for signed numbers. */
|
||||
static int
|
||||
grub_strtosl (char *arg, char **end, int base)
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
|
|
68
grub-core/commands/time.c
Normal file
68
grub-core/commands/time.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* echo.c - Command to display a line of text */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/time.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
{
|
||||
grub_command_t cmd;
|
||||
grub_uint32_t start;
|
||||
grub_uint32_t end;
|
||||
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "command expected");
|
||||
|
||||
cmd = grub_command_find (args[0]);
|
||||
|
||||
if (!cmd)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_COMMAND, "Unknown command `%s'\n",
|
||||
args[0]);
|
||||
|
||||
start = grub_get_time_ms ();
|
||||
(cmd->func) (cmd, argc - 1, &args[1]);
|
||||
end = grub_get_time_ms ();
|
||||
|
||||
grub_printf_ (N_("Elapsed time: %d.%03d seconds \n"), (end - start) / 1000,
|
||||
(end - start) % 1000);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(time)
|
||||
{
|
||||
cmd = grub_register_command ("time", grub_cmd_time,
|
||||
N_("COMMAND [ARGS]"),
|
||||
N_("Measure time used by COMMAND"));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(time)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
|
@ -21,6 +21,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const char *usb_classes[] =
|
||||
{
|
||||
"Unknown",
|
||||
|
|
|
@ -25,7 +25,10 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static unsigned height, width, depth;
|
||||
static struct grub_video_mode_info *current_mode;
|
||||
|
||||
static int
|
||||
hook (const struct grub_video_mode_info *info)
|
||||
|
@ -39,44 +42,74 @@ hook (const struct grub_video_mode_info *info)
|
|||
if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
|
||||
grub_printf (" ");
|
||||
else
|
||||
grub_printf (" 0x%03x ", info->mode_number);
|
||||
{
|
||||
if (current_mode && info->mode_number == current_mode->mode_number)
|
||||
grub_printf ("*");
|
||||
else
|
||||
grub_printf (" ");
|
||||
grub_printf (" 0x%03x ", info->mode_number);
|
||||
}
|
||||
grub_printf ("%4d x %4d x %2d ", info->width, info->height, info->bpp);
|
||||
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
|
||||
grub_printf ("Text-only ");
|
||||
grub_xputs (_("Text-only "));
|
||||
/* Show mask and position details for direct color modes. */
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)
|
||||
grub_printf ("Direct, mask: %d/%d/%d/%d pos: %d/%d/%d/%d",
|
||||
info->red_mask_size,
|
||||
info->green_mask_size,
|
||||
info->blue_mask_size,
|
||||
info->reserved_mask_size,
|
||||
info->red_field_pos,
|
||||
info->green_field_pos,
|
||||
info->blue_field_pos,
|
||||
info->reserved_field_pos);
|
||||
grub_printf_ (N_("Direct, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
|
||||
info->red_mask_size,
|
||||
info->green_mask_size,
|
||||
info->blue_mask_size,
|
||||
info->reserved_mask_size,
|
||||
info->red_field_pos,
|
||||
info->green_field_pos,
|
||||
info->blue_field_pos,
|
||||
info->reserved_field_pos);
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
|
||||
grub_printf ("Packed ");
|
||||
grub_xputs (_("Packed "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_YUV)
|
||||
grub_printf ("YUV ");
|
||||
grub_xputs (_("YUV "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PLANAR)
|
||||
grub_printf ("Planar ");
|
||||
grub_xputs (_("Planar "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_HERCULES)
|
||||
grub_printf ("Hercules ");
|
||||
grub_xputs (_("Hercules "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_CGA)
|
||||
grub_printf ("CGA ");
|
||||
grub_xputs (_("CGA "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_NONCHAIN4)
|
||||
grub_printf ("Non-chain 4 ");
|
||||
grub_xputs (_("Non-chain 4 "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP)
|
||||
grub_printf ("Monochrome ");
|
||||
grub_xputs (_("Monochrome "));
|
||||
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_UNKNOWN)
|
||||
grub_printf ("Unknown ");
|
||||
grub_xputs (_("Unknown "));
|
||||
|
||||
grub_printf ("\n");
|
||||
grub_xputs ("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
print_edid (struct grub_video_edid_info *edid_info)
|
||||
{
|
||||
unsigned int edid_width, edid_height;
|
||||
|
||||
if (grub_video_edid_checksum (edid_info))
|
||||
{
|
||||
grub_puts_ (N_(" EDID checksum invalid"));
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
grub_printf_ (N_(" EDID version: %u.%u\n"),
|
||||
edid_info->version, edid_info->revision);
|
||||
if (grub_video_edid_preferred_mode (edid_info, &edid_width, &edid_height)
|
||||
== GRUB_ERR_NONE)
|
||||
grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width, edid_height);
|
||||
else
|
||||
{
|
||||
grub_printf_ (N_(" No preferred mode available\n"));
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
|
@ -114,25 +147,38 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
id = grub_video_get_driver_id ();
|
||||
|
||||
grub_printf ("List of supported video modes:\n");
|
||||
grub_printf ("Legend: P=Packed pixel, D=Direct color, "
|
||||
"mask/pos=R/G/B/reserved\n");
|
||||
grub_puts_ (N_("List of supported video modes:"));
|
||||
grub_puts_ (N_("Legend: P=Packed pixel, D=Direct color, "
|
||||
"mask/pos=R/G/B/reserved"));
|
||||
|
||||
FOR_VIDEO_ADAPTERS (adapter)
|
||||
{
|
||||
grub_printf ("Adapter '%s':\n", adapter->name);
|
||||
struct grub_video_mode_info info;
|
||||
struct grub_video_edid_info edid_info;
|
||||
|
||||
grub_printf_ (N_("Adapter '%s':\n"), adapter->name);
|
||||
|
||||
if (!adapter->iterate)
|
||||
{
|
||||
grub_printf (" No info available\n");
|
||||
grub_puts_ (N_(" No info available"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (adapter->id != id)
|
||||
current_mode = NULL;
|
||||
|
||||
if (adapter->id == id)
|
||||
{
|
||||
if (grub_video_get_info (&info) == GRUB_ERR_NONE)
|
||||
current_mode = &info;
|
||||
else
|
||||
/* Don't worry about errors. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (adapter->init ())
|
||||
{
|
||||
grub_printf (" Failed\n");
|
||||
grub_puts_ (N_(" Failed"));
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
continue;
|
||||
}
|
||||
|
@ -143,6 +189,13 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
adapter->iterate (hook);
|
||||
|
||||
if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
|
||||
print_edid (&edid_info);
|
||||
else
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
current_mode = NULL;
|
||||
|
||||
if (adapter->id != id)
|
||||
{
|
||||
if (adapter->fini ())
|
||||
|
@ -162,12 +215,13 @@ static grub_command_t cmd_vbe;
|
|||
|
||||
GRUB_MOD_INIT(videoinfo)
|
||||
{
|
||||
cmd = grub_register_command ("videoinfo", grub_cmd_videoinfo, "[WxH[xD]]",
|
||||
cmd = grub_register_command ("videoinfo", grub_cmd_videoinfo, N_("[WxH[xD]]"),
|
||||
N_("List available video modes. If "
|
||||
"resolution is given show only modes"
|
||||
" matching it."));
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo, "[WxH[xD]]",
|
||||
cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
|
||||
N_("[WxH[xD]]"),
|
||||
N_("List available video modes. If "
|
||||
"resolution is given show only modes"
|
||||
" matching it."));
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <grub/gfxmenu_view.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
|
@ -72,6 +74,8 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
|
|||
grub_video_create_render_target (&text_layer, width, height,
|
||||
GRUB_VIDEO_MODE_TYPE_RGB
|
||||
| GRUB_VIDEO_MODE_TYPE_ALPHA);
|
||||
if (!text_layer)
|
||||
goto fail;
|
||||
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
|
||||
|
@ -189,6 +193,11 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return grub_errno;
|
||||
|
||||
fail:
|
||||
grub_video_delete_render_target (text_layer);
|
||||
grub_video_restore ();
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
|
|
@ -139,6 +139,7 @@ make_regex (const char *start, const char *end, regex_t *regexp)
|
|||
case '.':
|
||||
case '(':
|
||||
case ')':
|
||||
case '@':
|
||||
buffer[i++] = '\\';
|
||||
buffer[i++] = ch;
|
||||
break;
|
||||
|
@ -255,8 +256,7 @@ match_devices (const regex_t *regexp, int noparts)
|
|||
for (i = 0; devs && devs[i]; i++)
|
||||
grub_free (devs[i]);
|
||||
|
||||
if (devs)
|
||||
grub_free (devs);
|
||||
grub_free (devs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -266,7 +266,6 @@ match_files (const char *prefix, const char *suffix, const char *end,
|
|||
const regex_t *regexp)
|
||||
{
|
||||
int i;
|
||||
int error;
|
||||
char **files;
|
||||
unsigned nfile;
|
||||
char *dir;
|
||||
|
@ -289,6 +288,8 @@ match_files (const char *prefix, const char *suffix, const char *end,
|
|||
if (regexec (regexp, name, 0, 0, 0))
|
||||
return 0;
|
||||
|
||||
grub_dprintf ("expand", "matched\n");
|
||||
|
||||
buffer = grub_xasprintf ("%s%s", dir, name);
|
||||
if (! buffer)
|
||||
return 1;
|
||||
|
@ -325,10 +326,15 @@ match_files (const char *prefix, const char *suffix, const char *end,
|
|||
if (! fs)
|
||||
goto fail;
|
||||
|
||||
path = grub_strchr (dir, ')');
|
||||
if (! path)
|
||||
goto fail;
|
||||
path++;
|
||||
if (dir[0] == '(')
|
||||
{
|
||||
path = grub_strchr (dir, ')');
|
||||
if (!path)
|
||||
goto fail;
|
||||
path++;
|
||||
}
|
||||
else
|
||||
path = dir;
|
||||
|
||||
if (fs->dir (dev, path, match))
|
||||
goto fail;
|
||||
|
@ -341,20 +347,17 @@ match_files (const char *prefix, const char *suffix, const char *end,
|
|||
|
||||
fail:
|
||||
|
||||
if (dir)
|
||||
grub_free (dir);
|
||||
grub_free (dir);
|
||||
|
||||
for (i = 0; files && files[i]; i++)
|
||||
grub_free (files[i]);
|
||||
|
||||
if (files)
|
||||
grub_free (files);
|
||||
grub_free (files);
|
||||
|
||||
if (dev)
|
||||
grub_device_close (dev);
|
||||
|
||||
if (device_name)
|
||||
grub_free (device_name);
|
||||
grub_free (device_name);
|
||||
|
||||
grub_error_pop ();
|
||||
return 0;
|
||||
|
@ -424,8 +427,6 @@ wildcard_expand (const char *s, char ***strs)
|
|||
while (*start)
|
||||
{
|
||||
split_path (start, &noregexop, ®exop);
|
||||
if (noregexop >= regexop) /* no more wildcards */
|
||||
break;
|
||||
|
||||
if (make_regex (noregexop, regexop, ®exp))
|
||||
goto fail;
|
||||
|
@ -435,27 +436,8 @@ wildcard_expand (const char *s, char ***strs)
|
|||
if (start == noregexop) /* device part has regexop */
|
||||
paths = match_devices (®exp, *start != '(');
|
||||
|
||||
else if (*start == '(') /* device part explicit wo regexop */
|
||||
else /* device part explicit wo regexop */
|
||||
paths = match_files ("", start, noregexop, ®exp);
|
||||
|
||||
else if (*start == '/') /* no device part */
|
||||
{
|
||||
char **r;
|
||||
unsigned n;
|
||||
char *root;
|
||||
char *prefix;
|
||||
|
||||
root = grub_env_get ("root");
|
||||
if (! root)
|
||||
goto fail;
|
||||
|
||||
prefix = grub_xasprintf ("(%s)", root);
|
||||
if (! prefix)
|
||||
goto fail;
|
||||
|
||||
paths = match_files (prefix, start, noregexop, ®exp);
|
||||
grub_free (prefix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/crypto.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* This prefix is used by xnu and boot-132 to hash
|
||||
together with volume serial. */
|
||||
static grub_uint8_t hash_prefix[16]
|
||||
|
@ -49,10 +51,18 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
|
|||
char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
|
||||
char *ptr;
|
||||
grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
|
||||
int low = 0;
|
||||
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required");
|
||||
|
||||
if (argc > 1 && grub_strcmp (args[0], "-l") == 0)
|
||||
{
|
||||
low = 1;
|
||||
argc--;
|
||||
args++;
|
||||
}
|
||||
|
||||
serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16));
|
||||
|
||||
GRUB_MD_MD5->init (&ctx);
|
||||
|
@ -73,10 +83,11 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
|
|||
(unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
|
||||
(unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
|
||||
(unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
|
||||
for (ptr = uuid_string; *ptr; ptr++)
|
||||
*ptr = grub_toupper (*ptr);
|
||||
if (!low)
|
||||
for (ptr = uuid_string; *ptr; ptr++)
|
||||
*ptr = grub_toupper (*ptr);
|
||||
if (argc == 1)
|
||||
grub_printf ("%s", uuid_string);
|
||||
grub_printf ("%s\n", uuid_string);
|
||||
if (argc > 1)
|
||||
grub_env_set (args[1], uuid_string);
|
||||
|
||||
|
@ -89,9 +100,10 @@ static grub_command_t cmd;
|
|||
GRUB_MOD_INIT (xnu_uuid)
|
||||
{
|
||||
cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid,
|
||||
N_("GRUBUUID [VARNAME]"),
|
||||
N_("[-l] GRUBUUID [VARNAME]"),
|
||||
N_("Transform 64-bit UUID to format "
|
||||
"suitable for XNU."));
|
||||
"suitable for XNU. If -l is given keep "
|
||||
"it lowercase as done by blkid."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI (xnu_uuid)
|
||||
|
|
89
grub-core/disk/AFSplitter.c
Normal file
89
grub-core/disk/AFSplitter.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* AFsplitter - Anti forensic information splitter
|
||||
* Copyright 2004, Clemens Fruhwirth <clemens@endorphin.org>
|
||||
*
|
||||
* AFsplitter diffuses information over a large stripe of data,
|
||||
* therefor supporting secure data destruction.
|
||||
*
|
||||
* This program is grub_free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the grub_free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the grub_free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src,
|
||||
grub_uint8_t * dst, grub_size_t blocksize,
|
||||
grub_size_t blocknumbers);
|
||||
|
||||
static void
|
||||
diffuse (const gcry_md_spec_t * hash, grub_uint8_t * src,
|
||||
grub_uint8_t * dst, grub_size_t size)
|
||||
{
|
||||
grub_size_t i;
|
||||
grub_uint32_t IV; /* host byte order independend hash IV */
|
||||
|
||||
grub_size_t fullblocks = size / hash->mdlen;
|
||||
int padding = size % hash->mdlen;
|
||||
grub_uint8_t final[hash->mdlen];
|
||||
grub_uint8_t temp[sizeof (IV) + hash->mdlen];
|
||||
|
||||
/* hash block the whole data set with different IVs to produce
|
||||
* more than just a single data block
|
||||
*/
|
||||
for (i = 0; i < fullblocks; i++)
|
||||
{
|
||||
IV = grub_cpu_to_be32 (i);
|
||||
grub_memcpy (temp, &IV, sizeof (IV));
|
||||
grub_memcpy (temp + sizeof (IV), src + hash->mdlen * i, hash->mdlen);
|
||||
grub_crypto_hash (hash, dst + hash->mdlen * i, temp,
|
||||
sizeof (IV) + hash->mdlen);
|
||||
}
|
||||
|
||||
if (padding)
|
||||
{
|
||||
IV = grub_cpu_to_be32 (i);
|
||||
grub_memcpy (temp, &IV, sizeof (IV));
|
||||
grub_memcpy (temp + sizeof (IV), src + hash->mdlen * i, padding);
|
||||
grub_crypto_hash (hash, final, temp, sizeof (IV) + padding);
|
||||
grub_memcpy (dst + hash->mdlen * i, final, padding);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the splitted master key stored on disk into the original key
|
||||
*/
|
||||
gcry_err_code_t
|
||||
AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst,
|
||||
grub_size_t blocksize, grub_size_t blocknumbers)
|
||||
{
|
||||
grub_size_t i;
|
||||
grub_uint8_t *bufblock;
|
||||
|
||||
bufblock = grub_zalloc (blocksize);
|
||||
if (bufblock == NULL)
|
||||
return GPG_ERR_OUT_OF_MEMORY;
|
||||
|
||||
grub_memset (bufblock, 0, blocksize);
|
||||
for (i = 0; i < blocknumbers - 1; i++)
|
||||
{
|
||||
grub_crypto_xor (bufblock, src + (blocksize * i), bufblock, blocksize);
|
||||
diffuse (hash, bufblock, bufblock, blocksize);
|
||||
}
|
||||
grub_crypto_xor (dst, src + (i * blocksize), bufblock, blocksize);
|
||||
|
||||
grub_free (bufblock);
|
||||
return GPG_ERR_NO_ERROR;
|
||||
}
|
740
grub-core/disk/ahci.c
Normal file
740
grub-core/disk/ahci.c
Normal file
|
@ -0,0 +1,740 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/ata.h>
|
||||
#include <grub/scsi.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/list.h>
|
||||
#include <grub/loader.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_ahci_cmd_head
|
||||
{
|
||||
grub_uint32_t config;
|
||||
grub_uint32_t transfered;
|
||||
grub_uint64_t command_table_base;
|
||||
grub_uint32_t unused[4];
|
||||
};
|
||||
|
||||
struct grub_ahci_prdt_entry
|
||||
{
|
||||
grub_uint64_t data_base;
|
||||
grub_uint32_t unused;
|
||||
grub_uint32_t size;
|
||||
};
|
||||
|
||||
struct grub_ahci_cmd_table
|
||||
{
|
||||
grub_uint8_t cfis[0x40];
|
||||
grub_uint8_t command[0x10];
|
||||
grub_uint8_t reserved[0x30];
|
||||
struct grub_ahci_prdt_entry prdt[1];
|
||||
};
|
||||
|
||||
struct grub_ahci_hba_port
|
||||
{
|
||||
grub_uint64_t command_list_base;
|
||||
grub_uint64_t fis_base;
|
||||
grub_uint32_t intstatus;
|
||||
grub_uint32_t inten;
|
||||
grub_uint32_t command;
|
||||
grub_uint32_t unused1;
|
||||
grub_uint32_t task_file_data;
|
||||
grub_uint32_t sig;
|
||||
grub_uint32_t status;
|
||||
grub_uint32_t unused2;
|
||||
grub_uint32_t sata_error;
|
||||
grub_uint32_t sata_active;
|
||||
grub_uint32_t command_issue;
|
||||
grub_uint32_t unused3;
|
||||
grub_uint32_t fbs;
|
||||
grub_uint32_t unused4[15];
|
||||
};
|
||||
|
||||
enum grub_ahci_hba_port_command
|
||||
{
|
||||
GRUB_AHCI_HBA_PORT_CMD_ST = 0x01,
|
||||
GRUB_AHCI_HBA_PORT_CMD_FRE = 0x10,
|
||||
GRUB_AHCI_HBA_PORT_CMD_CR = 0x8000,
|
||||
GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000,
|
||||
};
|
||||
|
||||
struct grub_ahci_hba
|
||||
{
|
||||
grub_uint32_t cap;
|
||||
grub_uint32_t global_control;
|
||||
grub_uint32_t intr_status;
|
||||
grub_uint32_t ports_implemented;
|
||||
grub_uint32_t unused1[6];
|
||||
grub_uint32_t bios_handoff;
|
||||
grub_uint32_t unused2[53];
|
||||
struct grub_ahci_hba_port ports[32];
|
||||
};
|
||||
|
||||
struct grub_ahci_received_fis
|
||||
{
|
||||
char raw[4096];
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_AHCI_HBA_CAP_NPORTS_MASK = 0x1f
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_AHCI_HBA_GLOBAL_CONTROL_RESET = 0x00000001,
|
||||
GRUB_AHCI_HBA_GLOBAL_CONTROL_INTR_EN = 0x00000002,
|
||||
GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN = 0x80000000,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED = 1,
|
||||
GRUB_AHCI_BIOS_HANDOFF_OS_OWNED = 2,
|
||||
GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED = 8,
|
||||
GRUB_AHCI_BIOS_HANDOFF_RWC = 8
|
||||
};
|
||||
|
||||
|
||||
struct grub_ahci_device
|
||||
{
|
||||
struct grub_ahci_device *next;
|
||||
struct grub_ahci_device **prev;
|
||||
volatile struct grub_ahci_hba *hba;
|
||||
int port;
|
||||
int num;
|
||||
struct grub_pci_dma_chunk *command_list_chunk;
|
||||
volatile struct grub_ahci_cmd_head *command_list;
|
||||
struct grub_pci_dma_chunk *command_table_chunk;
|
||||
volatile struct grub_ahci_cmd_table *command_table;
|
||||
struct grub_pci_dma_chunk *rfis;
|
||||
int present;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
||||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_AHCI_CONFIG_READ = 0,
|
||||
GRUB_AHCI_CONFIG_CFIS_LENGTH_MASK = 0x1f,
|
||||
GRUB_AHCI_CONFIG_ATAPI = 0x20,
|
||||
GRUB_AHCI_CONFIG_WRITE = 0x40,
|
||||
GRUB_AHCI_CONFIG_PREFETCH = 0x80,
|
||||
GRUB_AHCI_CONFIG_RESET = 0x100,
|
||||
GRUB_AHCI_CONFIG_BIST = 0x200,
|
||||
GRUB_AHCI_CONFIG_CLEAR_R_OK = 0x400,
|
||||
GRUB_AHCI_CONFIG_PMP_MASK = 0xf000,
|
||||
GRUB_AHCI_CONFIG_PRDT_LENGTH_MASK = 0xffff0000,
|
||||
};
|
||||
#define GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT 0
|
||||
#define GRUB_AHCI_CONFIG_PMP_SHIFT 12
|
||||
#define GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT 16
|
||||
#define GRUB_AHCI_INTERRUPT_ON_COMPLETE 0x80000000
|
||||
|
||||
#define GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH 0x200000
|
||||
|
||||
static struct grub_ahci_device *grub_ahci_devices;
|
||||
static int numdevs;
|
||||
|
||||
static int
|
||||
init_port (struct grub_ahci_device *dev)
|
||||
{
|
||||
struct grub_pci_dma_chunk *command_list;
|
||||
struct grub_pci_dma_chunk *command_table;
|
||||
grub_uint64_t endtime;
|
||||
|
||||
command_list = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head));
|
||||
if (!command_list)
|
||||
return 1;
|
||||
|
||||
command_table = grub_memalign_dma32 (1024,
|
||||
sizeof (struct grub_ahci_cmd_table));
|
||||
if (!command_table)
|
||||
{
|
||||
grub_dma_free (command_list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_dprintf ("ahci", "found device ahci%d (port %d)\n", dev->num, dev->port);
|
||||
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop FR\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop CR\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev->hba->ports[dev->port].fbs = 2;
|
||||
|
||||
dev->rfis = grub_memalign_dma32 (4096,
|
||||
sizeof (struct grub_ahci_received_fis));
|
||||
grub_memset ((char *) grub_dma_get_virt (dev->rfis), 0,
|
||||
sizeof (struct grub_ahci_received_fis));
|
||||
dev->hba->ports[dev->port].fis_base = grub_dma_get_phys (dev->rfis);
|
||||
dev->hba->ports[dev->port].command_list_base
|
||||
= grub_dma_get_phys (command_list);
|
||||
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_FRE;
|
||||
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't start FR\n");
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
||||
goto out;
|
||||
}
|
||||
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't start CR\n");
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_CR;
|
||||
goto out_stop_fr;
|
||||
}
|
||||
|
||||
dev->hba->ports[dev->port].command
|
||||
= (dev->hba->ports[dev->port].command & 0x0fffffff) | (1 << 28) | 2 | 4;
|
||||
|
||||
dev->command_list_chunk = command_list;
|
||||
dev->command_list = grub_dma_get_virt (command_list);
|
||||
dev->command_table_chunk = command_table;
|
||||
dev->command_table = grub_dma_get_virt (command_table);
|
||||
dev->command_list->command_table_base
|
||||
= grub_dma_get_phys (command_table);
|
||||
|
||||
return 0;
|
||||
out_stop_fr:
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop FR\n");
|
||||
break;
|
||||
}
|
||||
out:
|
||||
grub_dma_free (command_list);
|
||||
grub_dma_free (command_table);
|
||||
grub_dma_free (dev->rfis);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int NESTED_FUNC_ATTR
|
||||
grub_ahci_pciinit (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_uint32_t class;
|
||||
grub_uint32_t bar;
|
||||
unsigned i, nports;
|
||||
volatile struct grub_ahci_hba *hba;
|
||||
|
||||
/* Read class. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class = grub_pci_read (addr);
|
||||
|
||||
/* Check if this class ID matches that of a PCI IDE Controller. */
|
||||
if (class >> 8 != 0x010601)
|
||||
return 0;
|
||||
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5);
|
||||
bar = grub_pci_read (addr);
|
||||
|
||||
if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK
|
||||
| GRUB_PCI_ADDR_MEM_PREFETCH))
|
||||
!= (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32))
|
||||
return 0;
|
||||
|
||||
hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK,
|
||||
sizeof (hba));
|
||||
|
||||
if (! (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_OS_OWNED))
|
||||
{
|
||||
grub_uint64_t endtime;
|
||||
|
||||
grub_dprintf ("ahci", "Requesting AHCI ownership\n");
|
||||
hba->bios_handoff = (hba->bios_handoff & ~GRUB_AHCI_BIOS_HANDOFF_RWC)
|
||||
| GRUB_AHCI_BIOS_HANDOFF_OS_OWNED;
|
||||
grub_dprintf ("ahci", "Waiting for BIOS to give up ownership\n");
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED)
|
||||
&& grub_get_time_ms () < endtime);
|
||||
if (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED)
|
||||
{
|
||||
grub_dprintf ("ahci", "Forcibly taking ownership\n");
|
||||
hba->bios_handoff = GRUB_AHCI_BIOS_HANDOFF_OS_OWNED;
|
||||
hba->bios_handoff |= GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED;
|
||||
}
|
||||
else
|
||||
grub_dprintf ("ahci", "AHCI ownership obtained\n");
|
||||
}
|
||||
else
|
||||
grub_dprintf ("ahci", "AHCI is already in OS mode\n");
|
||||
|
||||
if (!(hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN))
|
||||
grub_dprintf ("ahci", "AHCI is in compat mode. Switching\n");
|
||||
else
|
||||
grub_dprintf ("ahci", "AHCI is in AHCI mode.\n");
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN;
|
||||
grub_millisleep (1);
|
||||
if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN)
|
||||
break;
|
||||
}
|
||||
if (i == 5)
|
||||
{
|
||||
grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
grub_uint64_t endtime;
|
||||
hba->global_control |= 1;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while (hba->global_control & 1)
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't reset AHCI\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN;
|
||||
grub_millisleep (1);
|
||||
if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN)
|
||||
break;
|
||||
}
|
||||
if (i == 5)
|
||||
{
|
||||
grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1;
|
||||
|
||||
grub_dprintf ("ahci", "%d AHCI ports\n", nports);
|
||||
|
||||
for (i = 0; i < nports; i++)
|
||||
{
|
||||
struct grub_ahci_device *adev;
|
||||
grub_uint32_t st;
|
||||
|
||||
if (!(hba->ports_implemented & (1 << i)))
|
||||
continue;
|
||||
|
||||
grub_dprintf ("ahci", "status %d:%x\n", i, hba->ports[i].status);
|
||||
/* FIXME: support hotplugging. */
|
||||
st = hba->ports[i].status;
|
||||
if ((st & 0xf) != 0x3 && (st & 0xf) != 0x1)
|
||||
continue;
|
||||
|
||||
adev = grub_malloc (sizeof (*adev));
|
||||
if (!adev)
|
||||
return 1;
|
||||
|
||||
adev->hba = hba;
|
||||
adev->port = i;
|
||||
adev->present = 1;
|
||||
adev->num = numdevs++;
|
||||
|
||||
if (init_port (adev))
|
||||
{
|
||||
grub_free (adev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices),
|
||||
GRUB_AS_LIST (adev));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_initialize (void)
|
||||
{
|
||||
grub_pci_iterate (grub_ahci_pciinit);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_fini_hw (int noreturn __attribute__ ((unused)))
|
||||
{
|
||||
struct grub_ahci_device *dev;
|
||||
|
||||
for (dev = grub_ahci_devices; dev; dev = dev->next)
|
||||
{
|
||||
grub_uint64_t endtime;
|
||||
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop FR\n");
|
||||
break;
|
||||
}
|
||||
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop CR\n");
|
||||
break;
|
||||
}
|
||||
grub_dma_free (dev->command_list_chunk);
|
||||
grub_dma_free (dev->command_table_chunk);
|
||||
grub_dma_free (dev->rfis);
|
||||
dev->command_list_chunk = NULL;
|
||||
dev->command_table_chunk = NULL;
|
||||
dev->rfis = NULL;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_restore_hw (void)
|
||||
{
|
||||
struct grub_ahci_device **pdev;
|
||||
|
||||
for (pdev = &grub_ahci_devices; *pdev; pdev = &((*pdev)->next))
|
||||
if (init_port (*pdev))
|
||||
{
|
||||
struct grub_ahci_device *odev;
|
||||
odev = *pdev;
|
||||
*pdev = (*pdev)->next;
|
||||
grub_free (odev);
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
grub_ahci_iterate (int (*hook) (int id, int bus),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
struct grub_ahci_device *dev;
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
FOR_LIST_ELEMENTS(dev, grub_ahci_devices)
|
||||
if (hook (GRUB_SCSI_SUBSYSTEM_AHCI, dev->num))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
find_free_cmd_slot (struct grub_ahci_device *dev)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if (dev->hda->ports[dev->port].command_issue & (1 << i))
|
||||
continue;
|
||||
if (dev->hda->ports[dev->port].sata_active & (1 << i))
|
||||
continue;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_AHCI_FIS_REG_H2D = 0x27
|
||||
};
|
||||
|
||||
static const int register_map[11] = { 3 /* Features */,
|
||||
12 /* Sectors */,
|
||||
4 /* LBA low */,
|
||||
5 /* LBA mid */,
|
||||
6 /* LBA high */,
|
||||
7 /* Device */,
|
||||
2 /* CMD register */,
|
||||
13 /* Sectors 48 */,
|
||||
8 /* LBA48 low */,
|
||||
9 /* LBA48 mid */,
|
||||
10 /* LBA48 high */ };
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
||||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup)
|
||||
{
|
||||
struct grub_pci_dma_chunk *bufc;
|
||||
grub_uint64_t endtime;
|
||||
unsigned i;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
if ((dev->hba->ports[dev->port].task_file_data & 0x80))
|
||||
{
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't stop CR\n");
|
||||
break;
|
||||
}
|
||||
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
endtime = grub_get_time_ms () + (spinup ? 10000 : 1000);
|
||||
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "couldn't start CR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
||||
|
||||
grub_dprintf("ahci", "grub_ahci_read (size=%llu, cmdsize = %llu)\n",
|
||||
(unsigned long long) parms->size,
|
||||
(unsigned long long) parms->cmdsize);
|
||||
|
||||
if (parms->cmdsize != 0 && parms->cmdsize != 12 && parms->cmdsize != 16)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "incorrect ATAPI command size");
|
||||
|
||||
if (parms->size > GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too big data buffer");
|
||||
|
||||
bufc = grub_memalign_dma32 (1024, parms->size + (parms->size & 1));
|
||||
|
||||
dev->hba->ports[dev->port].command |= 8;
|
||||
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
/* FIXME: support port multipliers. */
|
||||
dev->command_list[0].config
|
||||
= (5 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT)
|
||||
// | GRUB_AHCI_CONFIG_CLEAR_R_OK
|
||||
| (0 << GRUB_AHCI_CONFIG_PMP_SHIFT)
|
||||
| (1 << GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT)
|
||||
| (parms->cmdsize ? GRUB_AHCI_CONFIG_ATAPI : 0)
|
||||
| (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ)
|
||||
| (parms->taskfile.cmd == 8 ? (1 << 8) : 0);
|
||||
dev->command_list[0].transfered = 0;
|
||||
dev->command_list[0].command_table_base
|
||||
= grub_dma_get_phys (dev->command_table_chunk);
|
||||
grub_memset ((char *) dev->command_list[0].unused, 0,
|
||||
sizeof (dev->command_list[0].unused));
|
||||
grub_memset ((char *) &dev->command_table[0], 0,
|
||||
sizeof (dev->command_table[0]));
|
||||
if (parms->cmdsize)
|
||||
grub_memcpy ((char *) dev->command_table[0].command, parms->cmd,
|
||||
parms->cmdsize);
|
||||
|
||||
dev->command_table[0].cfis[0] = GRUB_AHCI_FIS_REG_H2D;
|
||||
dev->command_table[0].cfis[1] = 0x80;
|
||||
for (i = 0; i < sizeof (parms->taskfile.raw); i++)
|
||||
dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i];
|
||||
|
||||
grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
dev->command_table[0].cfis[0], dev->command_table[0].cfis[1],
|
||||
dev->command_table[0].cfis[2], dev->command_table[0].cfis[3],
|
||||
dev->command_table[0].cfis[4], dev->command_table[0].cfis[5],
|
||||
dev->command_table[0].cfis[6], dev->command_table[0].cfis[7]);
|
||||
grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
dev->command_table[0].cfis[8], dev->command_table[0].cfis[9],
|
||||
dev->command_table[0].cfis[10], dev->command_table[0].cfis[11],
|
||||
dev->command_table[0].cfis[12], dev->command_table[0].cfis[13],
|
||||
dev->command_table[0].cfis[14], dev->command_table[0].cfis[15]);
|
||||
|
||||
dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc);
|
||||
dev->command_table[0].prdt[0].unused = 0;
|
||||
dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1)
|
||||
| GRUB_AHCI_INTERRUPT_ON_COMPLETE;
|
||||
|
||||
grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%"
|
||||
PRIuGRUB_SIZE ")\n",
|
||||
dev->command_table[0].prdt[0].data_base,
|
||||
dev->command_table[0].prdt[0].unused,
|
||||
dev->command_table[0].prdt[0].size,
|
||||
(char *) &dev->command_table[0].prdt[0]
|
||||
- (char *) &dev->command_table[0]);
|
||||
|
||||
if (parms->write)
|
||||
grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size);
|
||||
|
||||
grub_dprintf ("ahci", "AHCI command schedulded\n");
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
dev->hba->ports[dev->port].inten = 0xffffffff;//(1 << 2) | (1 << 5);
|
||||
dev->hba->ports[dev->port].intstatus = 0xffffffff;//(1 << 2) | (1 << 5);
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
dev->hba->ports[dev->port].command_issue |= 1;
|
||||
grub_dprintf ("ahci", "AHCI sig = %x\n", dev->hba->ports[dev->port].sig);
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
endtime = grub_get_time_ms () + (spinup ? 10000 : 1000);
|
||||
while ((dev->hba->ports[dev->port].command_issue & 1))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "AHCI status <%x %x %x>\n",
|
||||
dev->hba->ports[dev->port].command_issue,
|
||||
dev->hba->ports[dev->port].intstatus,
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
err = grub_error (GRUB_ERR_IO, "AHCI transfer timeouted");
|
||||
break;
|
||||
}
|
||||
|
||||
grub_dprintf ("ahci", "AHCI command completed <%x %x %x %x %x, %x %x>\n",
|
||||
dev->hba->ports[dev->port].command_issue,
|
||||
dev->hba->ports[dev->port].intstatus,
|
||||
dev->hba->ports[dev->port].task_file_data,
|
||||
dev->command_list[0].transfered,
|
||||
dev->hba->ports[dev->port].sata_error,
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x00],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x18]);
|
||||
grub_dprintf ("ahci",
|
||||
"last PIO FIS %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x08],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x09],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0a],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0b],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0c],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0d],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0e],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0f]);
|
||||
grub_dprintf ("ahci",
|
||||
"last REG FIS %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x10],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x11],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x12],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x13],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x14],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x15],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x16],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x17]);
|
||||
|
||||
if (!parms->write)
|
||||
grub_memcpy (parms->buffer, (char *) grub_dma_get_virt (bufc), parms->size);
|
||||
grub_dma_free (bufc);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_readwrite (grub_ata_t disk,
|
||||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup)
|
||||
{
|
||||
return grub_ahci_readwrite_real (disk->data, parms, spinup);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_open (int id, int devnum, struct grub_ata *ata)
|
||||
{
|
||||
struct grub_ahci_device *dev;
|
||||
|
||||
if (id != GRUB_SCSI_SUBSYSTEM_AHCI)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an AHCI device");
|
||||
|
||||
FOR_LIST_ELEMENTS(dev, grub_ahci_devices)
|
||||
if (dev->num == devnum)
|
||||
break;
|
||||
|
||||
if (! dev)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such AHCI device");
|
||||
|
||||
grub_dprintf ("ahci", "opening AHCI dev `ahci%d'\n", dev->num);
|
||||
|
||||
ata->data = dev;
|
||||
ata->dma = 1;
|
||||
ata->maxbuffer = GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH;
|
||||
ata->present = &dev->present;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_ata_dev grub_ahci_dev =
|
||||
{
|
||||
.iterate = grub_ahci_iterate,
|
||||
.open = grub_ahci_open,
|
||||
.readwrite = grub_ahci_readwrite,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static struct grub_preboot *fini_hnd;
|
||||
|
||||
GRUB_MOD_INIT(ahci)
|
||||
{
|
||||
/* To prevent two drivers operating on the same disks. */
|
||||
grub_disk_firmware_is_tainted = 1;
|
||||
if (grub_disk_firmware_fini)
|
||||
{
|
||||
grub_disk_firmware_fini ();
|
||||
grub_disk_firmware_fini = NULL;
|
||||
}
|
||||
|
||||
/* AHCI initialization. */
|
||||
grub_ahci_initialize ();
|
||||
|
||||
/* AHCI devices are handled by scsi.mod. */
|
||||
grub_ata_dev_register (&grub_ahci_dev);
|
||||
|
||||
fini_hnd = grub_loader_register_preboot_hook (grub_ahci_fini_hw,
|
||||
grub_ahci_restore_hw,
|
||||
GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(ahci)
|
||||
{
|
||||
grub_ahci_fini_hw (0);
|
||||
grub_loader_unregister_preboot_hook (fini_hnd);
|
||||
|
||||
grub_ata_dev_unregister (&grub_ahci_dev);
|
||||
}
|
329
grub-core/disk/arc/arcdisk.c
Normal file
329
grub-core/disk/arc/arcdisk.c
Normal file
|
@ -0,0 +1,329 @@
|
|||
/* ofdisk.c - Open Firmware disk access. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2004,2006,2007,2008,2009,2011 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/arc/arc.h>
|
||||
|
||||
static grub_arc_fileno_t last_handle = 0;
|
||||
static char *last_path = NULL;
|
||||
static int handle_writable = 0;
|
||||
|
||||
static int lnum = 0;
|
||||
|
||||
struct arcdisk_hash_ent
|
||||
{
|
||||
char *devpath;
|
||||
int num;
|
||||
struct arcdisk_hash_ent *next;
|
||||
};
|
||||
|
||||
#define ARCDISK_HASH_SZ 8
|
||||
static struct arcdisk_hash_ent *arcdisk_hash[ARCDISK_HASH_SZ];
|
||||
|
||||
static int
|
||||
arcdisk_hash_fn (const char *devpath)
|
||||
{
|
||||
int hash = 0;
|
||||
while (*devpath)
|
||||
hash ^= *devpath++;
|
||||
return (hash & (ARCDISK_HASH_SZ - 1));
|
||||
}
|
||||
|
||||
static struct arcdisk_hash_ent *
|
||||
arcdisk_hash_find (const char *devpath)
|
||||
{
|
||||
struct arcdisk_hash_ent *p = arcdisk_hash[arcdisk_hash_fn (devpath)];
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (!grub_strcmp (p->devpath, devpath))
|
||||
break;
|
||||
p = p->next;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static struct arcdisk_hash_ent *
|
||||
arcdisk_hash_add (char *devpath)
|
||||
{
|
||||
struct arcdisk_hash_ent *p;
|
||||
struct arcdisk_hash_ent **head = &arcdisk_hash[arcdisk_hash_fn(devpath)];
|
||||
|
||||
p = grub_malloc (sizeof (*p));
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
p->devpath = devpath;
|
||||
p->next = *head;
|
||||
p->num = lnum++;
|
||||
*head = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
grub_arcdisk_iterate (int (*hook_in) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
auto int hook (const char *name, const struct grub_arc_component *comp);
|
||||
int hook (const char *name, const struct grub_arc_component *comp)
|
||||
{
|
||||
if (!(comp->type == GRUB_ARC_COMPONENT_TYPE_DISK
|
||||
|| comp->type == GRUB_ARC_COMPONENT_TYPE_DISK
|
||||
|| comp->type == GRUB_ARC_COMPONENT_TYPE_TAPE))
|
||||
return 0;
|
||||
return hook_in (name);
|
||||
}
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
return grub_arc_iterate_devs (hook, 1);
|
||||
}
|
||||
|
||||
#define RAW_SUFFIX "partition(10)"
|
||||
|
||||
static grub_err_t
|
||||
reopen (const char *name, int writable)
|
||||
{
|
||||
grub_arc_fileno_t handle;
|
||||
|
||||
if (last_path && grub_strcmp (last_path, name) == 0
|
||||
&& (!writable || handle_writable))
|
||||
{
|
||||
grub_dprintf ("arcdisk", "using already opened %s\n", name);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
if (last_path)
|
||||
{
|
||||
GRUB_ARC_FIRMWARE_VECTOR->close (last_handle);
|
||||
grub_free (last_path);
|
||||
last_path = NULL;
|
||||
last_handle = 0;
|
||||
handle_writable = 0;
|
||||
}
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->open (name,
|
||||
writable ? GRUB_ARC_FILE_ACCESS_OPEN_RW
|
||||
: GRUB_ARC_FILE_ACCESS_OPEN_RO, &handle))
|
||||
{
|
||||
grub_dprintf ("arcdisk", "couldn't open %s\n", name);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't open %s", name);
|
||||
}
|
||||
handle_writable = writable;
|
||||
last_path = grub_strdup (name);
|
||||
if (!last_path)
|
||||
return grub_errno;
|
||||
last_handle = handle;
|
||||
grub_dprintf ("arcdisk", "opened %s\n", name);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_arcdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
char *fullname, *optr;
|
||||
const char *iptr;
|
||||
int state = 0;
|
||||
grub_err_t err;
|
||||
grub_arc_err_t r;
|
||||
struct grub_arc_fileinfo info;
|
||||
struct arcdisk_hash_ent *hash;
|
||||
|
||||
if (grub_memcmp (name, "arc/", 4) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not arc device");
|
||||
fullname = grub_malloc (2 * grub_strlen (name) + sizeof (RAW_SUFFIX));
|
||||
if (!fullname)
|
||||
return grub_errno;
|
||||
optr = fullname;
|
||||
for (iptr = name + 4; *iptr; iptr++)
|
||||
if (state == 0)
|
||||
{
|
||||
if (!grub_isdigit (*iptr))
|
||||
*optr++ = *iptr;
|
||||
else
|
||||
{
|
||||
*optr++ = '(';
|
||||
*optr++ = *iptr;
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (grub_isdigit (*iptr))
|
||||
*optr++ = *iptr;
|
||||
else
|
||||
{
|
||||
*optr++ = ')';
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
if (state)
|
||||
*optr++ = ')';
|
||||
grub_memcpy (optr, RAW_SUFFIX, sizeof (RAW_SUFFIX));
|
||||
disk->data = fullname;
|
||||
grub_dprintf ("arcdisk", "opening %s\n", fullname);
|
||||
|
||||
hash = arcdisk_hash_find (fullname);
|
||||
if (!hash)
|
||||
hash = arcdisk_hash_add (fullname);
|
||||
if (!hash)
|
||||
return grub_errno;
|
||||
|
||||
err = reopen (fullname, 0);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
r = GRUB_ARC_FIRMWARE_VECTOR->getfileinformation (last_handle, &info);
|
||||
if (r)
|
||||
{
|
||||
grub_uint64_t res = 0;
|
||||
int i;
|
||||
|
||||
grub_dprintf ("arcdisk", "couldn't retrieve size: %ld\n", r);
|
||||
for (i = 40; i >= 9; i--)
|
||||
{
|
||||
grub_uint64_t pos = res | (1ULL << i);
|
||||
char buf[512];
|
||||
long unsigned count = 0;
|
||||
grub_dprintf ("arcdisk",
|
||||
"seek to 0x%" PRIxGRUB_UINT64_T "\n", pos);
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0))
|
||||
continue;
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->read (last_handle, buf,
|
||||
0x200, &count))
|
||||
continue;
|
||||
if (count == 0)
|
||||
continue;
|
||||
res |= (1ULL << i);
|
||||
}
|
||||
grub_dprintf ("arcdisk",
|
||||
"determined disk size 0x%" PRIxGRUB_UINT64_T "\n", res);
|
||||
disk->total_sectors = (res + 0x200) >> 9;
|
||||
}
|
||||
else
|
||||
disk->total_sectors = (info.end >> 9);
|
||||
|
||||
disk->id = hash->num;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_arcdisk_close (grub_disk_t disk)
|
||||
{
|
||||
grub_free (disk->data);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_arcdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_uint64_t pos = sector << 9;
|
||||
unsigned long count;
|
||||
grub_uint64_t totl = size << 9;
|
||||
grub_arc_err_t r;
|
||||
|
||||
err = reopen (disk->data, 0);
|
||||
if (err)
|
||||
return err;
|
||||
r = GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0);
|
||||
if (r)
|
||||
{
|
||||
grub_dprintf ("arcdisk", "seek to 0x%" PRIxGRUB_UINT64_T " failed: %ld\n",
|
||||
pos, r);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't seek");
|
||||
}
|
||||
|
||||
while (totl)
|
||||
{
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->read (last_handle, buf,
|
||||
totl, &count))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "read failed");
|
||||
totl -= count;
|
||||
buf += count;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_arcdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, const char *buf)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_uint64_t pos = sector << 9;
|
||||
unsigned long count;
|
||||
grub_uint64_t totl = size << 9;
|
||||
grub_arc_err_t r;
|
||||
|
||||
err = reopen (disk->data, 1);
|
||||
if (err)
|
||||
return err;
|
||||
r = GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0);
|
||||
if (r)
|
||||
{
|
||||
grub_dprintf ("arcdisk", "seek to 0x%" PRIxGRUB_UINT64_T " failed: %ld\n",
|
||||
pos, r);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't seek");
|
||||
}
|
||||
|
||||
while (totl)
|
||||
{
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->write (last_handle, buf,
|
||||
totl, &count))
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR, "write failed");
|
||||
totl -= count;
|
||||
buf += count;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_disk_dev grub_arcdisk_dev =
|
||||
{
|
||||
.name = "arcdisk",
|
||||
.id = GRUB_DISK_DEVICE_ARCDISK_ID,
|
||||
.iterate = grub_arcdisk_iterate,
|
||||
.open = grub_arcdisk_open,
|
||||
.close = grub_arcdisk_close,
|
||||
.read = grub_arcdisk_read,
|
||||
.write = grub_arcdisk_write,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
void
|
||||
grub_arcdisk_init (void)
|
||||
{
|
||||
grub_disk_dev_register (&grub_arcdisk_dev);
|
||||
}
|
||||
|
||||
void
|
||||
grub_arcdisk_fini (void)
|
||||
{
|
||||
if (last_path)
|
||||
{
|
||||
GRUB_ARC_FIRMWARE_VECTOR->close (last_handle);
|
||||
grub_free (last_path);
|
||||
last_path = NULL;
|
||||
last_handle = 0;
|
||||
}
|
||||
|
||||
grub_disk_dev_unregister (&grub_arcdisk_dev);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,107 +0,0 @@
|
|||
/* ata_pthru.c - ATA pass through for ata.mod. */
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/ata.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
|
||||
/* ATA pass through support, used by hdparm.mod. */
|
||||
static grub_err_t
|
||||
grub_ata_pass_through (grub_disk_t disk,
|
||||
struct grub_disk_ata_pass_through_parms *parms)
|
||||
{
|
||||
if (disk->dev->id != GRUB_DISK_DEVICE_ATA_ID)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
"device not accessed via ata.mod");
|
||||
|
||||
struct grub_ata_device *dev = (struct grub_ata_device *) disk->data;
|
||||
|
||||
if (! (parms->size == 0 || parms->size == GRUB_DISK_SECTOR_SIZE))
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"ATA multi-sector read and DATA OUT not implemented");
|
||||
|
||||
grub_dprintf ("ata", "ata_pass_through: cmd=0x%x, features=0x%x, sectors=0x%x\n",
|
||||
parms->taskfile[GRUB_ATA_REG_CMD],
|
||||
parms->taskfile[GRUB_ATA_REG_FEATURES],
|
||||
parms->taskfile[GRUB_ATA_REG_SECTORS]);
|
||||
grub_dprintf ("ata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%d\n",
|
||||
parms->taskfile[GRUB_ATA_REG_LBAHIGH],
|
||||
parms->taskfile[GRUB_ATA_REG_LBAMID],
|
||||
parms->taskfile[GRUB_ATA_REG_LBALOW], parms->size);
|
||||
|
||||
/* Set registers. */
|
||||
grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4
|
||||
| (parms->taskfile[GRUB_ATA_REG_DISK] & 0xf));
|
||||
if (grub_ata_check_ready (dev))
|
||||
return grub_errno;
|
||||
|
||||
int i;
|
||||
for (i = GRUB_ATA_REG_FEATURES; i <= GRUB_ATA_REG_LBAHIGH; i++)
|
||||
grub_ata_regset (dev, i, parms->taskfile[i]);
|
||||
|
||||
/* Start command. */
|
||||
grub_ata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile[GRUB_ATA_REG_CMD]);
|
||||
|
||||
/* Wait for !BSY. */
|
||||
if (grub_ata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA))
|
||||
return grub_errno;
|
||||
|
||||
/* Check status. */
|
||||
grub_int8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS);
|
||||
grub_dprintf ("ata", "status=0x%x\n", sts);
|
||||
|
||||
/* Transfer data. */
|
||||
if ((sts & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) == GRUB_ATA_STATUS_DRQ)
|
||||
{
|
||||
if (parms->size != GRUB_DISK_SECTOR_SIZE)
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "DRQ unexpected");
|
||||
grub_ata_pio_read (dev, parms->buffer, GRUB_DISK_SECTOR_SIZE);
|
||||
}
|
||||
|
||||
/* Return registers. */
|
||||
for (i = GRUB_ATA_REG_ERROR; i <= GRUB_ATA_REG_STATUS; i++)
|
||||
parms->taskfile[i] = grub_ata_regget (dev, i);
|
||||
|
||||
grub_dprintf ("ata", "status=0x%x, error=0x%x, sectors=0x%x\n",
|
||||
parms->taskfile[GRUB_ATA_REG_STATUS],
|
||||
parms->taskfile[GRUB_ATA_REG_ERROR],
|
||||
parms->taskfile[GRUB_ATA_REG_SECTORS]);
|
||||
|
||||
if (parms->taskfile[GRUB_ATA_REG_STATUS]
|
||||
& (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "ATA passthrough failed");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GRUB_MOD_INIT(ata_pthru)
|
||||
{
|
||||
/* Register ATA pass through function. */
|
||||
grub_disk_ata_pass_through = grub_ata_pass_through;
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(ata_pthru)
|
||||
{
|
||||
if (grub_disk_ata_pass_through == grub_ata_pass_through)
|
||||
grub_disk_ata_pass_through = NULL;
|
||||
}
|
981
grub-core/disk/cryptodisk.c
Normal file
981
grub-core/disk/cryptodisk.c
Normal file
|
@ -0,0 +1,981 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003,2007,2010,2011 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/cryptodisk.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
grub_cryptodisk_dev_t grub_cryptodisk_list;
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"uuid", 'u', 0, N_("Mount by UUID."), 0, 0},
|
||||
{"all", 'a', 0, N_("Mount all."), 0, 0},
|
||||
{"boot", 'b', 0, N_("Mount all volumes marked as boot."), 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */
|
||||
#define GF_POLYNOM 0x87
|
||||
static inline int GF_PER_SECTOR (const struct grub_cryptodisk *dev)
|
||||
{
|
||||
return 1U << (dev->log_sector_size - GRUB_CRYPTODISK_GF_LOG_BYTES);
|
||||
}
|
||||
|
||||
static grub_cryptodisk_t cryptodisk_list = NULL;
|
||||
static grub_uint8_t n = 0;
|
||||
|
||||
static void
|
||||
gf_mul_x (grub_uint8_t *g)
|
||||
{
|
||||
int over = 0, over2 = 0;
|
||||
unsigned j;
|
||||
|
||||
for (j = 0; j < GRUB_CRYPTODISK_GF_BYTES; j++)
|
||||
{
|
||||
over2 = !!(g[j] & 0x80);
|
||||
g[j] <<= 1;
|
||||
g[j] |= over;
|
||||
over = over2;
|
||||
}
|
||||
if (over)
|
||||
g[0] ^= GF_POLYNOM;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gf_mul_x_be (grub_uint8_t *g)
|
||||
{
|
||||
int over = 0, over2 = 0;
|
||||
int j;
|
||||
|
||||
for (j = (int) GRUB_CRYPTODISK_GF_BYTES - 1; j >= 0; j--)
|
||||
{
|
||||
over2 = !!(g[j] & 0x80);
|
||||
g[j] <<= 1;
|
||||
g[j] |= over;
|
||||
over = over2;
|
||||
}
|
||||
if (over)
|
||||
g[GRUB_CRYPTODISK_GF_BYTES - 1] ^= GF_POLYNOM;
|
||||
}
|
||||
|
||||
static void
|
||||
gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b)
|
||||
{
|
||||
unsigned i;
|
||||
grub_uint8_t t[GRUB_CRYPTODISK_GF_BYTES];
|
||||
grub_memset (o, 0, GRUB_CRYPTODISK_GF_BYTES);
|
||||
grub_memcpy (t, b, GRUB_CRYPTODISK_GF_BYTES);
|
||||
for (i = 0; i < GRUB_CRYPTODISK_GF_SIZE; i++)
|
||||
{
|
||||
if (((a[GRUB_CRYPTODISK_GF_BYTES - i / 8 - 1] >> (i % 8))) & 1)
|
||||
grub_crypto_xor (o, o, t, GRUB_CRYPTODISK_GF_BYTES);
|
||||
gf_mul_x_be (t);
|
||||
}
|
||||
}
|
||||
|
||||
static gcry_err_code_t
|
||||
grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher,
|
||||
void *out, void *in, grub_size_t size,
|
||||
void *iv)
|
||||
{
|
||||
grub_uint8_t *inptr, *outptr, *end;
|
||||
grub_uint8_t ivt[cipher->cipher->blocksize];
|
||||
if (!cipher->cipher->decrypt)
|
||||
return GPG_ERR_NOT_SUPPORTED;
|
||||
if (size % cipher->cipher->blocksize != 0)
|
||||
return GPG_ERR_INV_ARG;
|
||||
end = (grub_uint8_t *) in + size;
|
||||
for (inptr = in, outptr = out; inptr < end;
|
||||
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
|
||||
{
|
||||
grub_memcpy (ivt, inptr, cipher->cipher->blocksize);
|
||||
cipher->cipher->decrypt (cipher->ctx, outptr, inptr);
|
||||
grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize);
|
||||
grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize);
|
||||
}
|
||||
return GPG_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
static gcry_err_code_t
|
||||
grub_crypto_pcbc_encrypt (grub_crypto_cipher_handle_t cipher,
|
||||
void *out, void *in, grub_size_t size,
|
||||
void *iv)
|
||||
{
|
||||
grub_uint8_t *inptr, *outptr, *end;
|
||||
grub_uint8_t ivt[cipher->cipher->blocksize];
|
||||
if (!cipher->cipher->decrypt)
|
||||
return GPG_ERR_NOT_SUPPORTED;
|
||||
if (size % cipher->cipher->blocksize != 0)
|
||||
return GPG_ERR_INV_ARG;
|
||||
end = (grub_uint8_t *) in + size;
|
||||
for (inptr = in, outptr = out; inptr < end;
|
||||
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
|
||||
{
|
||||
grub_memcpy (ivt, inptr, cipher->cipher->blocksize);
|
||||
grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize);
|
||||
cipher->cipher->encrypt (cipher->ctx, outptr, inptr);
|
||||
grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize);
|
||||
}
|
||||
return GPG_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
struct lrw_sector
|
||||
{
|
||||
grub_uint8_t low[GRUB_CRYPTODISK_GF_BYTES];
|
||||
grub_uint8_t high[GRUB_CRYPTODISK_GF_BYTES];
|
||||
grub_uint8_t low_byte, low_byte_c;
|
||||
};
|
||||
|
||||
static void
|
||||
generate_lrw_sector (struct lrw_sector *sec,
|
||||
const struct grub_cryptodisk *dev,
|
||||
const grub_uint8_t *iv)
|
||||
{
|
||||
grub_uint8_t idx[GRUB_CRYPTODISK_GF_BYTES];
|
||||
grub_uint16_t c;
|
||||
int j;
|
||||
grub_memcpy (idx, iv, GRUB_CRYPTODISK_GF_BYTES);
|
||||
sec->low_byte = (idx[GRUB_CRYPTODISK_GF_BYTES - 1]
|
||||
& (GF_PER_SECTOR (dev) - 1));
|
||||
sec->low_byte_c = (((GF_PER_SECTOR (dev) - 1) & ~sec->low_byte) + 1);
|
||||
idx[GRUB_CRYPTODISK_GF_BYTES - 1] &= ~(GF_PER_SECTOR (dev) - 1);
|
||||
gf_mul_be (sec->low, dev->lrw_key, idx);
|
||||
if (!sec->low_byte)
|
||||
return;
|
||||
|
||||
c = idx[GRUB_CRYPTODISK_GF_BYTES - 1] + GF_PER_SECTOR (dev);
|
||||
if (c & 0x100)
|
||||
{
|
||||
for (j = GRUB_CRYPTODISK_GF_BYTES - 2; j >= 0; j--)
|
||||
{
|
||||
idx[j]++;
|
||||
if (idx[j] != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
idx[GRUB_CRYPTODISK_GF_BYTES - 1] = c;
|
||||
gf_mul_be (sec->high, dev->lrw_key, idx);
|
||||
}
|
||||
|
||||
static void __attribute__ ((unused))
|
||||
lrw_xor (const struct lrw_sector *sec,
|
||||
const struct grub_cryptodisk *dev,
|
||||
grub_uint8_t *b)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES;
|
||||
i += GRUB_CRYPTODISK_GF_BYTES)
|
||||
grub_crypto_xor (b + i, b + i, sec->low, GRUB_CRYPTODISK_GF_BYTES);
|
||||
grub_crypto_xor (b, b, dev->lrw_precalc + GRUB_CRYPTODISK_GF_BYTES * sec->low_byte,
|
||||
sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES);
|
||||
if (!sec->low_byte)
|
||||
return;
|
||||
|
||||
for (i = sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES;
|
||||
i < (1U << dev->log_sector_size); i += GRUB_CRYPTODISK_GF_BYTES)
|
||||
grub_crypto_xor (b + i, b + i, sec->high, GRUB_CRYPTODISK_GF_BYTES);
|
||||
grub_crypto_xor (b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES,
|
||||
b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES,
|
||||
dev->lrw_precalc, sec->low_byte * GRUB_CRYPTODISK_GF_BYTES);
|
||||
}
|
||||
|
||||
static gcry_err_code_t
|
||||
grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev,
|
||||
grub_uint8_t * data, grub_size_t len,
|
||||
grub_disk_addr_t sector, int encrypt)
|
||||
{
|
||||
grub_size_t i;
|
||||
gcry_err_code_t err;
|
||||
|
||||
/* The only mode without IV. */
|
||||
if (dev->mode == GRUB_CRYPTODISK_MODE_ECB && !dev->rekey)
|
||||
return (encrypt ? grub_crypto_ecb_encrypt (dev->cipher, data, data, len)
|
||||
: grub_crypto_ecb_decrypt (dev->cipher, data, data, len));
|
||||
|
||||
for (i = 0; i < len; i += (1U << dev->log_sector_size))
|
||||
{
|
||||
grub_size_t sz = ((dev->cipher->cipher->blocksize
|
||||
+ sizeof (grub_uint32_t) - 1)
|
||||
/ sizeof (grub_uint32_t));
|
||||
grub_uint32_t iv[sz];
|
||||
|
||||
if (dev->rekey)
|
||||
{
|
||||
grub_uint64_t zone = sector >> dev->rekey_shift;
|
||||
if (zone != dev->last_rekey)
|
||||
{
|
||||
err = dev->rekey (dev, zone);
|
||||
if (err)
|
||||
return err;
|
||||
dev->last_rekey = zone;
|
||||
}
|
||||
}
|
||||
|
||||
grub_memset (iv, 0, sz * sizeof (iv[0]));
|
||||
switch (dev->mode_iv)
|
||||
{
|
||||
case GRUB_CRYPTODISK_MODE_IV_NULL:
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH:
|
||||
{
|
||||
grub_uint64_t tmp;
|
||||
grub_uint64_t ctx[(dev->iv_hash->contextsize + 7) / 8];
|
||||
|
||||
grub_memset (ctx, 0, sizeof (ctx));
|
||||
|
||||
tmp = grub_cpu_to_le64 (sector << dev->log_sector_size);
|
||||
dev->iv_hash->init (ctx);
|
||||
dev->iv_hash->write (ctx, dev->iv_prefix, dev->iv_prefix_len);
|
||||
dev->iv_hash->write (ctx, &tmp, sizeof (tmp));
|
||||
dev->iv_hash->final (ctx);
|
||||
|
||||
grub_memcpy (iv, dev->iv_hash->read (ctx), sizeof (iv));
|
||||
}
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_PLAIN64:
|
||||
iv[1] = grub_cpu_to_le32 (sector >> 32);
|
||||
case GRUB_CRYPTODISK_MODE_IV_PLAIN:
|
||||
iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF);
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64:
|
||||
iv[1] = grub_cpu_to_le32 (sector >> (32 - dev->log_sector_size));
|
||||
iv[0] = grub_cpu_to_le32 ((sector << dev->log_sector_size)
|
||||
& 0xFFFFFFFF);
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_BENBI:
|
||||
{
|
||||
grub_uint64_t num = (sector << dev->benbi_log) + 1;
|
||||
iv[sz - 2] = grub_cpu_to_be32 (num >> 32);
|
||||
iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF);
|
||||
}
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_ESSIV:
|
||||
iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF);
|
||||
err = grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv,
|
||||
dev->cipher->cipher->blocksize);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
switch (dev->mode)
|
||||
{
|
||||
case GRUB_CRYPTODISK_MODE_CBC:
|
||||
if (encrypt)
|
||||
err = grub_crypto_cbc_encrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size), iv);
|
||||
else
|
||||
err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size), iv);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
|
||||
case GRUB_CRYPTODISK_MODE_PCBC:
|
||||
if (encrypt)
|
||||
err = grub_crypto_pcbc_encrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size), iv);
|
||||
else
|
||||
err = grub_crypto_pcbc_decrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size), iv);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_XTS:
|
||||
{
|
||||
unsigned j;
|
||||
err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv,
|
||||
dev->cipher->cipher->blocksize);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
for (j = 0; j < (1U << dev->log_sector_size);
|
||||
j += dev->cipher->cipher->blocksize)
|
||||
{
|
||||
grub_crypto_xor (data + i + j, data + i + j, iv,
|
||||
dev->cipher->cipher->blocksize);
|
||||
if (encrypt)
|
||||
err = grub_crypto_ecb_encrypt (dev->cipher, data + i + j,
|
||||
data + i + j,
|
||||
dev->cipher->cipher->blocksize);
|
||||
else
|
||||
err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j,
|
||||
data + i + j,
|
||||
dev->cipher->cipher->blocksize);
|
||||
if (err)
|
||||
return err;
|
||||
grub_crypto_xor (data + i + j, data + i + j, iv,
|
||||
dev->cipher->cipher->blocksize);
|
||||
gf_mul_x ((grub_uint8_t *) iv);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_LRW:
|
||||
{
|
||||
struct lrw_sector sec;
|
||||
|
||||
generate_lrw_sector (&sec, dev, (grub_uint8_t *) iv);
|
||||
lrw_xor (&sec, dev, data + i);
|
||||
|
||||
if (encrypt)
|
||||
err = grub_crypto_ecb_encrypt (dev->cipher, data + i,
|
||||
data + i,
|
||||
(1U << dev->log_sector_size));
|
||||
else
|
||||
err = grub_crypto_ecb_decrypt (dev->cipher, data + i,
|
||||
data + i,
|
||||
(1U << dev->log_sector_size));
|
||||
if (err)
|
||||
return err;
|
||||
lrw_xor (&sec, dev, data + i);
|
||||
}
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_ECB:
|
||||
if (encrypt)
|
||||
grub_crypto_ecb_encrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size));
|
||||
else
|
||||
grub_crypto_ecb_decrypt (dev->cipher, data + i, data + i,
|
||||
(1U << dev->log_sector_size));
|
||||
break;
|
||||
default:
|
||||
return GPG_ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
sector++;
|
||||
}
|
||||
return GPG_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
gcry_err_code_t
|
||||
grub_cryptodisk_decrypt (struct grub_cryptodisk *dev,
|
||||
grub_uint8_t * data, grub_size_t len,
|
||||
grub_disk_addr_t sector)
|
||||
{
|
||||
return grub_cryptodisk_endecrypt (dev, data, len, sector, 0);
|
||||
}
|
||||
|
||||
gcry_err_code_t
|
||||
grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize)
|
||||
{
|
||||
gcry_err_code_t err;
|
||||
int real_keysize;
|
||||
|
||||
real_keysize = keysize;
|
||||
if (dev->mode == GRUB_CRYPTODISK_MODE_XTS)
|
||||
real_keysize /= 2;
|
||||
if (dev->mode == GRUB_CRYPTODISK_MODE_LRW)
|
||||
real_keysize -= dev->cipher->cipher->blocksize;
|
||||
|
||||
/* Set the PBKDF2 output as the cipher key. */
|
||||
err = grub_crypto_cipher_set_key (dev->cipher, key, real_keysize);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Configure ESSIV if necessary. */
|
||||
if (dev->mode_iv == GRUB_CRYPTODISK_MODE_IV_ESSIV)
|
||||
{
|
||||
grub_size_t essiv_keysize = dev->essiv_hash->mdlen;
|
||||
grub_uint8_t hashed_key[essiv_keysize];
|
||||
|
||||
grub_crypto_hash (dev->essiv_hash, hashed_key, key, keysize);
|
||||
err = grub_crypto_cipher_set_key (dev->essiv_cipher,
|
||||
hashed_key, essiv_keysize);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
if (dev->mode == GRUB_CRYPTODISK_MODE_XTS)
|
||||
{
|
||||
err = grub_crypto_cipher_set_key (dev->secondary_cipher,
|
||||
key + real_keysize,
|
||||
keysize / 2);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (dev->mode == GRUB_CRYPTODISK_MODE_LRW)
|
||||
{
|
||||
unsigned i;
|
||||
grub_uint8_t idx[GRUB_CRYPTODISK_GF_BYTES];
|
||||
|
||||
grub_free (dev->lrw_precalc);
|
||||
grub_memcpy (dev->lrw_key, key + real_keysize,
|
||||
dev->cipher->cipher->blocksize);
|
||||
dev->lrw_precalc = grub_malloc ((1U << dev->log_sector_size));
|
||||
if (!dev->lrw_precalc)
|
||||
return GPG_ERR_OUT_OF_MEMORY;
|
||||
grub_memset (idx, 0, GRUB_CRYPTODISK_GF_BYTES);
|
||||
for (i = 0; i < (1U << dev->log_sector_size);
|
||||
i += GRUB_CRYPTODISK_GF_BYTES)
|
||||
{
|
||||
idx[GRUB_CRYPTODISK_GF_BYTES - 1] = i / GRUB_CRYPTODISK_GF_BYTES;
|
||||
gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key);
|
||||
}
|
||||
}
|
||||
return GPG_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_cryptodisk_iterate (int (*hook) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
grub_cryptodisk_t i;
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
for (i = cryptodisk_list; i != NULL; i = i->next)
|
||||
{
|
||||
char buf[30];
|
||||
grub_snprintf (buf, sizeof (buf), "crypto%lu", i->id);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cryptodisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev;
|
||||
|
||||
if (grub_memcmp (name, "crypto", sizeof ("crypto") - 1) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device");
|
||||
|
||||
if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) == 0)
|
||||
{
|
||||
for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
|
||||
if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) == 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long id = grub_strtoul (name + sizeof ("crypto") - 1, 0, 0);
|
||||
if (grub_errno)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device");
|
||||
/* Search for requested device in the list of CRYPTODISK devices. */
|
||||
for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
|
||||
if (dev->id == id)
|
||||
break;
|
||||
}
|
||||
if (!dev)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device");
|
||||
|
||||
disk->log_sector_size = dev->log_sector_size;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
if (dev->cheat)
|
||||
{
|
||||
if (dev->cheat_fd == -1)
|
||||
dev->cheat_fd = open (dev->cheat, O_RDONLY);
|
||||
if (dev->cheat_fd == -1)
|
||||
return grub_error (GRUB_ERR_IO, "couldn't open %s: %s",
|
||||
dev->cheat, strerror (errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!dev->source_disk)
|
||||
{
|
||||
grub_dprintf ("cryptodisk", "Opening device %s\n", name);
|
||||
/* Try to open the source disk and populate the requested disk. */
|
||||
dev->source_disk = grub_disk_open (dev->source);
|
||||
if (!dev->source_disk)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
disk->data = dev;
|
||||
disk->total_sectors = dev->total_length;
|
||||
disk->id = dev->id;
|
||||
dev->ref++;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_cryptodisk_close (grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
grub_dprintf ("cryptodisk", "Closing disk\n");
|
||||
|
||||
dev->ref--;
|
||||
|
||||
if (dev->ref != 0)
|
||||
return;
|
||||
#ifdef GRUB_UTIL
|
||||
if (dev->cheat)
|
||||
{
|
||||
close (dev->cheat_fd);
|
||||
dev->cheat_fd = -1;
|
||||
}
|
||||
#endif
|
||||
grub_disk_close (dev->source_disk);
|
||||
dev->source_disk = NULL;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
grub_err_t err;
|
||||
gcry_err_code_t gcry_err;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
if (dev->cheat)
|
||||
{
|
||||
err = grub_util_fd_seek (dev->cheat_fd, dev->cheat,
|
||||
sector << disk->log_sector_size);
|
||||
if (err)
|
||||
return err;
|
||||
if (grub_util_fd_read (dev->cheat_fd, buf, size << disk->log_sector_size)
|
||||
!= (ssize_t) (size << disk->log_sector_size))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'",
|
||||
dev->cheat);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
grub_dprintf ("cryptodisk",
|
||||
"Reading %" PRIuGRUB_SIZE " sectors from sector 0x%"
|
||||
PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT64_T "\n",
|
||||
size, sector, dev->offset);
|
||||
|
||||
err = grub_disk_read (dev->source_disk,
|
||||
(sector << (disk->log_sector_size
|
||||
- GRUB_DISK_SECTOR_BITS)) + dev->offset, 0,
|
||||
size << disk->log_sector_size, buf);
|
||||
if (err)
|
||||
{
|
||||
grub_dprintf ("cryptodisk", "grub_disk_read failed with error %d\n", err);
|
||||
return err;
|
||||
}
|
||||
gcry_err = grub_cryptodisk_endecrypt (dev, (grub_uint8_t *) buf,
|
||||
size << disk->log_sector_size,
|
||||
sector, 0);
|
||||
return grub_crypto_gcry_error (gcry_err);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cryptodisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, const char *buf)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
gcry_err_code_t gcry_err;
|
||||
char *tmp;
|
||||
grub_err_t err;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
if (dev->cheat)
|
||||
{
|
||||
err = grub_util_fd_seek (dev->cheat_fd, dev->cheat,
|
||||
sector << disk->log_sector_size);
|
||||
if (err)
|
||||
return err;
|
||||
if (grub_util_fd_write (dev->cheat_fd, buf, size << disk->log_sector_size)
|
||||
!= (ssize_t) (size << disk->log_sector_size))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'",
|
||||
dev->cheat);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
tmp = grub_malloc (size << disk->log_sector_size);
|
||||
if (!tmp)
|
||||
return grub_errno;
|
||||
grub_memcpy (tmp, buf, size << disk->log_sector_size);
|
||||
|
||||
grub_dprintf ("cryptodisk",
|
||||
"Writing %" PRIuGRUB_SIZE " sectors to sector 0x%"
|
||||
PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT64_T "\n",
|
||||
size, sector, dev->offset);
|
||||
|
||||
gcry_err = grub_cryptodisk_endecrypt (dev, (grub_uint8_t *) tmp,
|
||||
size << disk->log_sector_size,
|
||||
sector, 1);
|
||||
if (gcry_err)
|
||||
{
|
||||
grub_free (tmp);
|
||||
return grub_crypto_gcry_error (gcry_err);
|
||||
}
|
||||
|
||||
err = grub_disk_write (dev->source_disk,
|
||||
(sector << (disk->log_sector_size
|
||||
- GRUB_DISK_SECTOR_BITS)) + dev->offset,
|
||||
0, size << disk->log_sector_size, tmp);
|
||||
grub_free (tmp);
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
static grub_disk_memberlist_t
|
||||
grub_cryptodisk_memberlist (grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
grub_disk_memberlist_t list = NULL;
|
||||
|
||||
list = grub_malloc (sizeof (*list));
|
||||
if (list)
|
||||
{
|
||||
list->disk = dev->source_disk;
|
||||
list->next = NULL;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
cryptodisk_cleanup (void)
|
||||
{
|
||||
#if 0
|
||||
grub_cryptodisk_t dev = cryptodisk_list;
|
||||
grub_cryptodisk_t tmp;
|
||||
|
||||
while (dev != NULL)
|
||||
{
|
||||
grub_free (dev->source);
|
||||
grub_free (dev->cipher);
|
||||
grub_free (dev->secondary_cipher);
|
||||
grub_free (dev->essiv_cipher);
|
||||
tmp = dev->next;
|
||||
grub_free (dev);
|
||||
dev = tmp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name,
|
||||
grub_disk_t source)
|
||||
{
|
||||
newdev->source = grub_strdup (name);
|
||||
if (!newdev->source)
|
||||
{
|
||||
grub_free (newdev);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
newdev->id = n++;
|
||||
newdev->source_id = source->id;
|
||||
newdev->source_dev_id = source->dev->id;
|
||||
newdev->next = cryptodisk_list;
|
||||
cryptodisk_list = newdev;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_cryptodisk_t
|
||||
grub_cryptodisk_get_by_uuid (const char *uuid)
|
||||
{
|
||||
grub_cryptodisk_t dev;
|
||||
for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
|
||||
if (grub_strcasecmp (dev->uuid, uuid) == 0)
|
||||
return dev;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_cryptodisk_t
|
||||
grub_cryptodisk_get_by_source_disk (grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev;
|
||||
for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
|
||||
if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id)
|
||||
return dev;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
grub_err_t
|
||||
grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name,
|
||||
grub_disk_t source, const char *cheat)
|
||||
{
|
||||
newdev->cheat = grub_strdup (cheat);
|
||||
newdev->source = grub_strdup (name);
|
||||
if (!newdev->source || !newdev->cheat)
|
||||
{
|
||||
grub_free (newdev->source);
|
||||
grub_free (newdev->cheat);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
newdev->cheat_fd = -1;
|
||||
newdev->source_id = source->id;
|
||||
newdev->source_dev_id = source->dev->id;
|
||||
newdev->id = n++;
|
||||
newdev->next = cryptodisk_list;
|
||||
cryptodisk_list = newdev;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_cryptodisk_print_abstraction (grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
|
||||
grub_printf ("cryptodisk %s ", dev->modname);
|
||||
|
||||
if (dev->cipher)
|
||||
grub_printf ("%s ", dev->cipher->cipher->modname);
|
||||
if (dev->secondary_cipher)
|
||||
grub_printf ("%s ", dev->secondary_cipher->cipher->modname);
|
||||
if (dev->essiv_cipher)
|
||||
grub_printf ("%s ", dev->essiv_cipher->cipher->modname);
|
||||
if (dev->hash)
|
||||
grub_printf ("%s ", dev->hash->modname);
|
||||
if (dev->essiv_hash)
|
||||
grub_printf ("%s ", dev->essiv_hash->modname);
|
||||
if (dev->iv_hash)
|
||||
grub_printf ("%s ", dev->iv_hash->modname);
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_cryptodisk_print_uuid (grub_disk_t disk)
|
||||
{
|
||||
grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data;
|
||||
grub_printf ("%s ", dev->uuid);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int check_boot, have_it;
|
||||
static char *search_uuid;
|
||||
|
||||
static void
|
||||
cryptodisk_close (grub_cryptodisk_t dev)
|
||||
{
|
||||
grub_crypto_cipher_close (dev->cipher);
|
||||
grub_crypto_cipher_close (dev->secondary_cipher);
|
||||
grub_crypto_cipher_close (dev->essiv_cipher);
|
||||
grub_free (dev);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cryptodisk_scan_device_real (const char *name, grub_disk_t source)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_cryptodisk_t dev;
|
||||
grub_cryptodisk_dev_t cr;
|
||||
|
||||
dev = grub_cryptodisk_get_by_source_disk (source);
|
||||
|
||||
if (dev)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
FOR_CRYPTODISK_DEVS (cr)
|
||||
{
|
||||
dev = cr->scan (source, search_uuid, check_boot);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
if (!dev)
|
||||
continue;
|
||||
|
||||
err = cr->recover_key (source, dev);
|
||||
if (err)
|
||||
{
|
||||
cryptodisk_close (dev);
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_cryptodisk_insert (dev, name, source);
|
||||
|
||||
have_it = 1;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/util/misc.h>
|
||||
grub_err_t
|
||||
grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_cryptodisk_t dev;
|
||||
grub_cryptodisk_dev_t cr;
|
||||
grub_disk_t source;
|
||||
|
||||
/* Try to open disk. */
|
||||
source = grub_disk_open (sourcedev);
|
||||
if (!source)
|
||||
return grub_errno;
|
||||
|
||||
dev = grub_cryptodisk_get_by_source_disk (source);
|
||||
|
||||
if (dev)
|
||||
{
|
||||
grub_disk_close (source);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
FOR_CRYPTODISK_DEVS (cr)
|
||||
{
|
||||
dev = cr->scan (source, search_uuid, check_boot);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
if (!dev)
|
||||
continue;
|
||||
|
||||
grub_util_info ("cheatmounted %s (%s) at %s", sourcedev, dev->modname,
|
||||
cheat);
|
||||
err = grub_cryptodisk_cheat_insert (dev, sourcedev, source, cheat);
|
||||
grub_disk_close (source);
|
||||
if (err)
|
||||
grub_free (dev);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_disk_close (source);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
grub_cryptodisk_scan_device (const char *name)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_disk_t source;
|
||||
|
||||
/* Try to open disk. */
|
||||
source = grub_disk_open (name);
|
||||
if (!source)
|
||||
return grub_errno;
|
||||
|
||||
err = grub_cryptodisk_scan_device_real (name, source);
|
||||
|
||||
grub_disk_close (source);
|
||||
|
||||
if (err)
|
||||
grub_print_error ();
|
||||
return have_it && search_uuid ? 1 : 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
|
||||
if (argc < 1 && !state[1].set && !state[2].set)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
|
||||
|
||||
have_it = 0;
|
||||
if (state[0].set)
|
||||
{
|
||||
grub_cryptodisk_t dev;
|
||||
|
||||
dev = grub_cryptodisk_get_by_uuid (args[0]);
|
||||
if (dev)
|
||||
{
|
||||
grub_dprintf ("cryptodisk",
|
||||
"already mounted as crypto%lu\n", dev->id);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
check_boot = state[2].set;
|
||||
search_uuid = args[0];
|
||||
grub_device_iterate (&grub_cryptodisk_scan_device);
|
||||
search_uuid = NULL;
|
||||
|
||||
if (!have_it)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
else if (state[1].set || (argc == 0 && state[2].set))
|
||||
{
|
||||
search_uuid = NULL;
|
||||
check_boot = state[2].set;
|
||||
grub_device_iterate (&grub_cryptodisk_scan_device);
|
||||
search_uuid = NULL;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_disk_t disk;
|
||||
grub_cryptodisk_t dev;
|
||||
|
||||
search_uuid = NULL;
|
||||
check_boot = state[2].set;
|
||||
disk = grub_disk_open (args[0]);
|
||||
if (!disk)
|
||||
return grub_errno;
|
||||
|
||||
dev = grub_cryptodisk_get_by_source_disk (disk);
|
||||
if (dev)
|
||||
{
|
||||
grub_dprintf ("cryptodisk", "already mounted as crypto%lu\n", dev->id);
|
||||
grub_disk_close (disk);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
err = grub_cryptodisk_scan_device_real (args[0], disk);
|
||||
|
||||
grub_disk_close (disk);
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
static struct grub_disk_dev grub_cryptodisk_dev = {
|
||||
.name = "cryptodisk",
|
||||
.id = GRUB_DISK_DEVICE_CRYPTODISK_ID,
|
||||
.iterate = grub_cryptodisk_iterate,
|
||||
.open = grub_cryptodisk_open,
|
||||
.close = grub_cryptodisk_close,
|
||||
.read = grub_cryptodisk_read,
|
||||
.write = grub_cryptodisk_write,
|
||||
#ifdef GRUB_UTIL
|
||||
.memberlist = grub_cryptodisk_memberlist,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
|
||||
GRUB_MOD_INIT (cryptodisk)
|
||||
{
|
||||
grub_disk_dev_register (&grub_cryptodisk_dev);
|
||||
cmd = grub_register_extcmd ("cryptomount", grub_cmd_cryptomount, 0,
|
||||
N_("SOURCE|-u UUID|-a|-b"),
|
||||
N_("Mount a crypto device."), options);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI (cryptodisk)
|
||||
{
|
||||
grub_disk_dev_unregister (&grub_cryptodisk_dev);
|
||||
cryptodisk_cleanup ();
|
||||
}
|
1081
grub-core/disk/diskfilter.c
Normal file
1081
grub-core/disk/diskfilter.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,9 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/raid.h>
|
||||
#include <grub/diskfilter.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define NV_SIGNATURES 4
|
||||
|
||||
|
@ -88,70 +90,91 @@ struct grub_nv_super
|
|||
struct grub_nv_array array; /* Array information */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static grub_err_t
|
||||
grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array,
|
||||
grub_disk_addr_t *start_sector)
|
||||
static struct grub_diskfilter_vg *
|
||||
grub_dmraid_nv_detect (grub_disk_t disk,
|
||||
struct grub_diskfilter_pv_id *id,
|
||||
grub_disk_addr_t *start_sector)
|
||||
{
|
||||
grub_disk_addr_t sector;
|
||||
struct grub_nv_super sb;
|
||||
int level;
|
||||
int layout;
|
||||
grub_uint64_t disk_size;
|
||||
char *uuid;
|
||||
|
||||
if (disk->partition)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "skip partition");
|
||||
|
||||
sector = grub_disk_get_size (disk) - 2;
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "skip partition");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sector = grub_disk_get_size (disk);
|
||||
if (sector == GRUB_DISK_SIZE_UNKNOWN)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
|
||||
return NULL;
|
||||
}
|
||||
sector -= 2;
|
||||
if (grub_disk_read (disk, sector, 0, sizeof (sb), &sb))
|
||||
return grub_errno;
|
||||
return NULL;
|
||||
|
||||
if (grub_memcmp (sb.vendor, NV_ID_STRING, 6))
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sb.version != NV_VERSION)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unknown version: %d.%d", sb.version);
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unknown version: %d.%d", sb.version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (sb.array.raid_level)
|
||||
{
|
||||
case NV_LEVEL_0:
|
||||
array->level = 0;
|
||||
array->disk_size = sb.capacity / sb.array.total_volumes;
|
||||
level = 0;
|
||||
disk_size = sb.capacity / sb.array.total_volumes;
|
||||
break;
|
||||
|
||||
case NV_LEVEL_1:
|
||||
array->level = 1;
|
||||
array->disk_size = sb.capacity;
|
||||
level = 1;
|
||||
disk_size = sb.capacity;
|
||||
break;
|
||||
|
||||
case NV_LEVEL_5:
|
||||
array->level = 5;
|
||||
array->layout = GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC;
|
||||
array->disk_size = sb.capacity / (sb.array.total_volumes - 1);
|
||||
level = 5;
|
||||
layout = GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC;
|
||||
disk_size = sb.capacity / (sb.array.total_volumes - 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported RAID level: %d", sb.array.raid_level);
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported RAID level: %d", sb.array.raid_level);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
array->name = NULL;
|
||||
array->number = 0;
|
||||
array->total_devs = sb.array.total_volumes;
|
||||
array->chunk_size = sb.array.stripe_block_size;
|
||||
array->index = sb.unit_number;
|
||||
array->uuid_len = sizeof (sb.array.signature);
|
||||
array->uuid = grub_malloc (sizeof (sb.array.signature));
|
||||
if (! array->uuid)
|
||||
return grub_errno;
|
||||
uuid = grub_malloc (sizeof (sb.array.signature));
|
||||
if (! uuid)
|
||||
return NULL;
|
||||
|
||||
grub_memcpy (array->uuid, (char *) &sb.array.signature,
|
||||
grub_memcpy (uuid, (char *) &sb.array.signature,
|
||||
sizeof (sb.array.signature));
|
||||
|
||||
id->uuidlen = 0;
|
||||
id->id = sb.unit_number;
|
||||
|
||||
*start_sector = 0;
|
||||
|
||||
return 0;
|
||||
return grub_diskfilter_make_raid (sizeof (sb.array.signature),
|
||||
uuid, sb.array.total_volumes,
|
||||
NULL, disk_size,
|
||||
sb.array.stripe_block_size, layout,
|
||||
level);
|
||||
}
|
||||
|
||||
static struct grub_raid grub_dmraid_nv_dev =
|
||||
static struct grub_diskfilter grub_dmraid_nv_dev =
|
||||
{
|
||||
.name = "dmraid_nv",
|
||||
.detect = grub_dmraid_nv_detect,
|
||||
|
@ -160,10 +183,10 @@ static struct grub_raid grub_dmraid_nv_dev =
|
|||
|
||||
GRUB_MOD_INIT(dm_nv)
|
||||
{
|
||||
grub_raid_register (&grub_dmraid_nv_dev);
|
||||
grub_diskfilter_register (&grub_dmraid_nv_dev);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(dm_nv)
|
||||
{
|
||||
grub_raid_unregister (&grub_dmraid_nv_dev);
|
||||
grub_diskfilter_unregister (&grub_dmraid_nv_dev);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@ struct grub_efidisk_data
|
|||
grub_efi_device_path_t *device_path;
|
||||
grub_efi_device_path_t *last_device_path;
|
||||
grub_efi_block_io_t *block_io;
|
||||
grub_efi_disk_io_t *disk_io;
|
||||
struct grub_efidisk_data *next;
|
||||
};
|
||||
|
||||
/* GUIDs. */
|
||||
static grub_efi_guid_t disk_io_guid = GRUB_EFI_DISK_IO_GUID;
|
||||
/* GUID. */
|
||||
static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
|
||||
|
||||
static struct grub_efidisk_data *fd_devices;
|
||||
|
@ -86,54 +84,6 @@ find_last_device_path (const grub_efi_device_path_t *dp)
|
|||
return p;
|
||||
}
|
||||
|
||||
/* Compare device paths. */
|
||||
static int
|
||||
compare_device_paths (const grub_efi_device_path_t *dp1,
|
||||
const grub_efi_device_path_t *dp2)
|
||||
{
|
||||
if (! dp1 || ! dp2)
|
||||
/* Return non-zero. */
|
||||
return 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
grub_efi_uint8_t type1, type2;
|
||||
grub_efi_uint8_t subtype1, subtype2;
|
||||
grub_efi_uint16_t len1, len2;
|
||||
int ret;
|
||||
|
||||
type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1);
|
||||
type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2);
|
||||
|
||||
if (type1 != type2)
|
||||
return (int) type2 - (int) type1;
|
||||
|
||||
subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1);
|
||||
subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2);
|
||||
|
||||
if (subtype1 != subtype2)
|
||||
return (int) subtype1 - (int) subtype2;
|
||||
|
||||
len1 = GRUB_EFI_DEVICE_PATH_LENGTH (dp1);
|
||||
len2 = GRUB_EFI_DEVICE_PATH_LENGTH (dp2);
|
||||
|
||||
if (len1 != len2)
|
||||
return (int) len1 - (int) len2;
|
||||
|
||||
ret = grub_memcmp (dp1, dp2, len1);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp1))
|
||||
break;
|
||||
|
||||
dp1 = (grub_efi_device_path_t *) ((char *) dp1 + len1);
|
||||
dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_efidisk_data *
|
||||
make_devices (void)
|
||||
{
|
||||
|
@ -143,7 +93,7 @@ make_devices (void)
|
|||
struct grub_efidisk_data *devices = 0;
|
||||
|
||||
/* Find handles which support the disk io interface. */
|
||||
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &disk_io_guid,
|
||||
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &block_io_guid,
|
||||
0, &num_handles);
|
||||
if (! handles)
|
||||
return 0;
|
||||
|
@ -155,7 +105,6 @@ make_devices (void)
|
|||
grub_efi_device_path_t *ldp;
|
||||
struct grub_efidisk_data *d;
|
||||
grub_efi_block_io_t *bio;
|
||||
grub_efi_disk_io_t *dio;
|
||||
|
||||
dp = grub_efi_get_device_path (*handle);
|
||||
if (! dp)
|
||||
|
@ -168,9 +117,7 @@ make_devices (void)
|
|||
|
||||
bio = grub_efi_open_protocol (*handle, &block_io_guid,
|
||||
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
dio = grub_efi_open_protocol (*handle, &disk_io_guid,
|
||||
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
if (! bio || ! dio)
|
||||
if (! bio)
|
||||
/* This should not happen... Why? */
|
||||
continue;
|
||||
|
||||
|
@ -186,7 +133,6 @@ make_devices (void)
|
|||
d->device_path = dp;
|
||||
d->last_device_path = ldp;
|
||||
d->block_io = bio;
|
||||
d->disk_io = dio;
|
||||
d->next = devices;
|
||||
devices = d;
|
||||
}
|
||||
|
@ -220,7 +166,7 @@ find_parent_device (struct grub_efidisk_data *devices,
|
|||
if (parent == d)
|
||||
continue;
|
||||
|
||||
if (compare_device_paths (parent->device_path, dp) == 0)
|
||||
if (grub_efi_compare_device_paths (parent->device_path, dp) == 0)
|
||||
{
|
||||
/* Found. */
|
||||
if (! parent->last_device_path)
|
||||
|
@ -255,7 +201,7 @@ iterate_child_devices (struct grub_efidisk_data *devices,
|
|||
ldp->length[0] = sizeof (*ldp);
|
||||
ldp->length[1] = 0;
|
||||
|
||||
if (compare_device_paths (dp, d->device_path) == 0)
|
||||
if (grub_efi_compare_device_paths (dp, d->device_path) == 0)
|
||||
if (hook (p))
|
||||
{
|
||||
grub_free (dp);
|
||||
|
@ -279,11 +225,11 @@ add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d)
|
|||
{
|
||||
int ret;
|
||||
|
||||
ret = compare_device_paths (find_last_device_path ((*p)->device_path),
|
||||
find_last_device_path (d->device_path));
|
||||
ret = grub_efi_compare_device_paths (find_last_device_path ((*p)->device_path),
|
||||
find_last_device_path (d->device_path));
|
||||
if (ret == 0)
|
||||
ret = compare_device_paths ((*p)->device_path,
|
||||
d->device_path);
|
||||
ret = grub_efi_compare_device_paths ((*p)->device_path,
|
||||
d->device_path);
|
||||
if (ret == 0)
|
||||
return;
|
||||
else if (ret > 0)
|
||||
|
@ -432,34 +378,43 @@ enumerate_disks (void)
|
|||
}
|
||||
|
||||
static int
|
||||
grub_efidisk_iterate (int (*hook) (const char *name))
|
||||
grub_efidisk_iterate (int (*hook) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
struct grub_efidisk_data *d;
|
||||
char buf[16];
|
||||
int count;
|
||||
|
||||
for (d = fd_devices, count = 0; d; d = d->next, count++)
|
||||
switch (pull)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "fd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
case GRUB_DISK_PULL_NONE:
|
||||
for (d = hd_devices, count = 0; d; d = d->next, count++)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "hd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case GRUB_DISK_PULL_REMOVABLE:
|
||||
for (d = fd_devices, count = 0; d; d = d->next, count++)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "fd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (d = hd_devices, count = 0; d; d = d->next, count++)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "hd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (d = cd_devices, count = 0; d; d = d->next, count++)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "cd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
for (d = cd_devices, count = 0; d; d = d->next, count++)
|
||||
{
|
||||
grub_snprintf (buf, sizeof (buf), "cd%d", count);
|
||||
grub_dprintf ("efidisk", "iterating %s\n", buf);
|
||||
if (hook (buf))
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -536,8 +491,13 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
|
|||
and total sectors should be replaced with total blocks. */
|
||||
grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n",
|
||||
m, (unsigned long long) m->last_block, m->block_size);
|
||||
disk->total_sectors = (m->last_block
|
||||
* (m->block_size >> GRUB_DISK_SECTOR_BITS));
|
||||
disk->total_sectors = m->last_block + 1;
|
||||
if (m->block_size & (m->block_size - 1) || !m->block_size)
|
||||
return grub_error (GRUB_ERR_IO, "invalid sector size %d",
|
||||
m->block_size);
|
||||
for (disk->log_sector_size = 0;
|
||||
(1U << disk->log_sector_size) < m->block_size;
|
||||
disk->log_sector_size++);
|
||||
disk->data = d;
|
||||
|
||||
grub_dprintf ("efidisk", "opening %s succeeded\n", name);
|
||||
|
@ -558,22 +518,20 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
|
|||
{
|
||||
/* For now, use the disk io interface rather than the block io's. */
|
||||
struct grub_efidisk_data *d;
|
||||
grub_efi_disk_io_t *dio;
|
||||
grub_efi_block_io_t *bio;
|
||||
grub_efi_status_t status;
|
||||
|
||||
d = disk->data;
|
||||
dio = d->disk_io;
|
||||
bio = d->block_io;
|
||||
|
||||
grub_dprintf ("efidisk",
|
||||
"reading 0x%lx sectors at the sector 0x%llx from %s\n",
|
||||
(unsigned long) size, (unsigned long long) sector, disk->name);
|
||||
|
||||
status = efi_call_5 (dio->read, dio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS,
|
||||
(grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS,
|
||||
buf);
|
||||
status = efi_call_5 (bio->read_blocks, bio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) size << disk->log_sector_size,
|
||||
buf);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error");
|
||||
|
||||
|
@ -586,21 +544,19 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
|
|||
{
|
||||
/* For now, use the disk io interface rather than the block io's. */
|
||||
struct grub_efidisk_data *d;
|
||||
grub_efi_disk_io_t *dio;
|
||||
grub_efi_block_io_t *bio;
|
||||
grub_efi_status_t status;
|
||||
|
||||
d = disk->data;
|
||||
dio = d->disk_io;
|
||||
bio = d->block_io;
|
||||
|
||||
grub_dprintf ("efidisk",
|
||||
"writing 0x%lx sectors at the sector 0x%llx to %s\n",
|
||||
(unsigned long) size, (unsigned long long) sector, disk->name);
|
||||
|
||||
status = efi_call_5 (dio->write, dio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS,
|
||||
(grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS,
|
||||
status = efi_call_5 (bio->write_blocks, bio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) size << disk->log_sector_size,
|
||||
(void *) buf);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR, "efidisk write error");
|
||||
|
@ -708,10 +664,52 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define NEEDED_BUFLEN sizeof ("XdXXXXXXXXXX")
|
||||
static inline int
|
||||
get_diskname_from_path_real (const grub_efi_device_path_t *path,
|
||||
struct grub_efidisk_data *head,
|
||||
char *buf)
|
||||
{
|
||||
int count = 0;
|
||||
struct grub_efidisk_data *d;
|
||||
for (d = head, count = 0; d; d = d->next, count++)
|
||||
if (grub_efi_compare_device_paths (d->device_path, path) == 0)
|
||||
{
|
||||
grub_snprintf (buf, NEEDED_BUFLEN - 1, "d%d", count);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
get_diskname_from_path (const grub_efi_device_path_t *path,
|
||||
char *buf)
|
||||
{
|
||||
if (get_diskname_from_path_real (path, hd_devices, buf + 1))
|
||||
{
|
||||
buf[0] = 'h';
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (get_diskname_from_path_real (path, fd_devices, buf + 1))
|
||||
{
|
||||
buf[0] = 'f';
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (get_diskname_from_path_real (path, cd_devices, buf + 1))
|
||||
{
|
||||
buf[0] = 'c';
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
||||
{
|
||||
grub_efi_device_path_t *dp, *ldp;
|
||||
char device_name[NEEDED_BUFLEN];
|
||||
|
||||
dp = grub_efi_get_device_path (handle);
|
||||
if (! dp)
|
||||
|
@ -725,40 +723,14 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
|||
&& (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp)
|
||||
== GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE))
|
||||
{
|
||||
/* This is a hard disk partition. */
|
||||
grub_disk_t parent = 0;
|
||||
grub_partition_t tpart = NULL;
|
||||
char *device_name;
|
||||
char *partition_name = NULL;
|
||||
char *dev_name;
|
||||
grub_efi_device_path_t *dup_dp, *dup_ldp;
|
||||
grub_efi_hard_drive_device_path_t hd;
|
||||
auto int find_parent_disk (const char *name);
|
||||
grub_disk_t parent = 0;
|
||||
|
||||
auto int find_partition (grub_disk_t disk, const grub_partition_t part);
|
||||
|
||||
/* Find the disk which is the parent of a given hard disk partition. */
|
||||
int find_parent_disk (const char *name)
|
||||
{
|
||||
grub_disk_t disk;
|
||||
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
return 1;
|
||||
|
||||
if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID)
|
||||
{
|
||||
struct grub_efidisk_data *d;
|
||||
|
||||
d = disk->data;
|
||||
if (compare_device_paths (d->device_path, dup_dp) == 0)
|
||||
{
|
||||
parent = disk;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find the identical partition. */
|
||||
int find_partition (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t part)
|
||||
|
@ -766,7 +738,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
|||
if (grub_partition_get_start (part) == hd.partition_start
|
||||
&& grub_partition_get_len (part) == hd.partition_size)
|
||||
{
|
||||
tpart = part;
|
||||
partition_name = grub_partition_get_name (part);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -785,7 +757,9 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
|||
dup_ldp->length[0] = sizeof (*dup_ldp);
|
||||
dup_ldp->length[1] = 0;
|
||||
|
||||
grub_efidisk_iterate (find_parent_disk);
|
||||
if (!get_diskname_from_path (dup_dp, device_name))
|
||||
return 0;
|
||||
parent = grub_disk_open (device_name);
|
||||
grub_free (dup_dp);
|
||||
|
||||
if (! parent)
|
||||
|
@ -793,58 +767,33 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
|||
|
||||
/* Find a partition which matches the hard drive device path. */
|
||||
grub_memcpy (&hd, ldp, sizeof (hd));
|
||||
grub_partition_iterate (parent, find_partition);
|
||||
|
||||
if (! tpart)
|
||||
if (hd.partition_start == 0
|
||||
&& hd.partition_size == grub_disk_get_size (parent))
|
||||
{
|
||||
grub_disk_close (parent);
|
||||
return 0;
|
||||
dev_name = grub_strdup (parent->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_partition_iterate (parent, find_partition);
|
||||
|
||||
{
|
||||
char *partition_name = grub_partition_get_name (tpart);
|
||||
device_name = grub_xasprintf ("%s,%s", parent->name, partition_name);
|
||||
grub_free (partition_name);
|
||||
}
|
||||
if (! partition_name)
|
||||
{
|
||||
grub_disk_close (parent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_name = grub_xasprintf ("%s,%s", parent->name, partition_name);
|
||||
grub_free (partition_name);
|
||||
}
|
||||
grub_disk_close (parent);
|
||||
|
||||
return device_name;
|
||||
return dev_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This should be an entire disk. */
|
||||
auto int find_disk (const char *name);
|
||||
char *device_name = 0;
|
||||
|
||||
int find_disk (const char *name)
|
||||
{
|
||||
grub_disk_t disk;
|
||||
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
return 1;
|
||||
|
||||
if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID)
|
||||
{
|
||||
struct grub_efidisk_data *d;
|
||||
|
||||
d = disk->data;
|
||||
if (compare_device_paths (d->device_path, dp) == 0)
|
||||
{
|
||||
device_name = grub_strdup (disk->name);
|
||||
grub_disk_close (disk);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
grub_efidisk_iterate (find_disk);
|
||||
return device_name;
|
||||
if (!get_diskname_from_path (dp, device_name))
|
||||
return 0;
|
||||
return grub_strdup (device_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue