merge mainline into lazy
This commit is contained in:
commit
00542307eb
326 changed files with 18667 additions and 4092 deletions
27
.bzrignore
27
.bzrignore
|
@ -26,12 +26,16 @@ docs/*.info
|
|||
docs/stamp-vti
|
||||
docs/version.texi
|
||||
*.elf
|
||||
example_grub_script_test
|
||||
example_scripted_test
|
||||
example_unit_test
|
||||
*.exec
|
||||
genkernsyms.sh
|
||||
gensymlist.sh
|
||||
gentrigtables
|
||||
grub-bin2h
|
||||
grub-dumpbios
|
||||
grub_cmd_echo
|
||||
grub_cmd_regexp
|
||||
grub-editenv
|
||||
grub-emu
|
||||
grub_emu_init.c
|
||||
|
@ -49,9 +53,28 @@ grub-probe
|
|||
grub_probe_init.c
|
||||
grub_probe_init.h
|
||||
grub-reboot
|
||||
grub_script_blanklines
|
||||
grub_script_blockarg
|
||||
grub_script_break
|
||||
grub-script-check
|
||||
grub_script_check_init.c
|
||||
grub_script_check_init.h
|
||||
grub_script_comments
|
||||
grub_script_continue
|
||||
grub_script_dollar
|
||||
grub_script_echo1
|
||||
grub_script_echo_keywords
|
||||
grub_script_expansion
|
||||
grub_script_final_semicolon
|
||||
grub_script_for1
|
||||
grub_script_functions
|
||||
grub_script_if
|
||||
grub_script_not
|
||||
grub_script_return
|
||||
grub_script_setparams
|
||||
grub_script_shift
|
||||
grub_script_vars1
|
||||
grub_script_while1
|
||||
grub_script.tab.c
|
||||
grub_script.tab.h
|
||||
grub_script.yy.c
|
||||
|
@ -75,6 +98,7 @@ Makefile
|
|||
*.mod
|
||||
mod-*.c
|
||||
missing
|
||||
partmap_test
|
||||
*.pf2
|
||||
*.pp
|
||||
po/*.mo
|
||||
|
@ -109,6 +133,7 @@ grub-core/Makefile.gcry.def
|
|||
grub-core/contrib
|
||||
grub-core/genmod.sh
|
||||
grub-core/gensyminfo.sh
|
||||
grub-core/modinfo.sh
|
||||
grub-core/*.module
|
||||
grub-core/*.pp
|
||||
util/bash-completion.d/grub
|
||||
|
|
|
@ -35,6 +35,7 @@ library = {
|
|||
common_nodist = grub_script.tab.h;
|
||||
|
||||
common = grub-core/commands/blocklist.c;
|
||||
common = grub-core/commands/testload.c;
|
||||
common = grub-core/commands/extcmd.c;
|
||||
common = grub-core/commands/ls.c;
|
||||
common = grub-core/disk/dmraid_nvidia.c;
|
||||
|
@ -61,11 +62,14 @@ library = {
|
|||
common = grub-core/fs/jfs.c;
|
||||
common = grub-core/fs/minix.c;
|
||||
common = grub-core/fs/minix2.c;
|
||||
common = grub-core/fs/minix3.c;
|
||||
common = grub-core/fs/nilfs2.c;
|
||||
common = grub-core/fs/ntfs.c;
|
||||
common = grub-core/fs/ntfscomp.c;
|
||||
common = grub-core/fs/reiserfs.c;
|
||||
common = grub-core/fs/romfs.c;
|
||||
common = grub-core/fs/sfs.c;
|
||||
common = grub-core/fs/squash4.c;
|
||||
common = grub-core/fs/tar.c;
|
||||
common = grub-core/fs/udf.c;
|
||||
common = grub-core/fs/ufs2.c;
|
||||
|
@ -93,6 +97,7 @@ library = {
|
|||
common = grub-core/partmap/gpt.c;
|
||||
common = grub-core/partmap/msdos.c;
|
||||
common = grub-core/partmap/sun.c;
|
||||
common = grub-core/partmap/dvh.c;
|
||||
common = grub-core/partmap/sunpc.c;
|
||||
common = grub-core/partmap/bsdlabel.c;
|
||||
common = grub-core/script/function.c;
|
||||
|
@ -101,6 +106,7 @@ library = {
|
|||
common = grub-core/script/script.c;
|
||||
common = grub-core/script/argv.c;
|
||||
common = grub-core/io/gzio.c;
|
||||
common = grub-core/kern/ia64/dl_helper.c;
|
||||
};
|
||||
|
||||
program = {
|
||||
|
@ -110,7 +116,7 @@ program = {
|
|||
ldadd = libgrubkern.a;
|
||||
ldadd = grub-core/gnulib/libgnu.a;
|
||||
ldadd = '$(LIBINTL) $(LIBDEVMAPPER)';
|
||||
mansection = 1;
|
||||
installdir = noinst;
|
||||
};
|
||||
|
||||
program = {
|
||||
|
@ -283,6 +289,7 @@ program = {
|
|||
program = {
|
||||
name = grub-ofpathname;
|
||||
installdir = sbin;
|
||||
mansection = 8;
|
||||
ieee1275 = util/ieee1275/grub-ofpathname.c;
|
||||
ieee1275 = util/ieee1275/ofpath.c;
|
||||
|
||||
|
@ -383,7 +390,8 @@ script = {
|
|||
x86 = util/grub-mkrescue.in;
|
||||
powerpc_ieee1275 = util/powerpc/ieee1275/grub-mkrescue.in;
|
||||
enable = i386_pc;
|
||||
enable = x86_efi;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
enable = i386_qemu;
|
||||
enable = i386_multiboot;
|
||||
enable = i386_coreboot;
|
||||
|
|
|
@ -25,13 +25,13 @@ endif
|
|||
if COND_i386_ieee1275
|
||||
CFLAGS_PLATFORM += -mrtd -mregparm=3
|
||||
endif
|
||||
if COND_mips_yeeloong
|
||||
if COND_mips_loongson
|
||||
CFLAGS_PLATFORM += -mexplicit-relocs
|
||||
CPPFLAGS_PLATFORM = -DUSE_ASCII_FAILBACK
|
||||
CCASFLAGS_PLATFORM = -march=mips3
|
||||
endif
|
||||
if COND_mips
|
||||
CFLAGS_PLATFORM += -mflush-func=grub_cpu_flush_cache
|
||||
CCASFLAGS_PLATFORM = -march=mips3
|
||||
endif
|
||||
if COND_sparc64_ieee1275
|
||||
CFLAGS_PLATFORM += -mno-app-regs
|
||||
|
|
60
configure.ac
60
configure.ac
|
@ -32,7 +32,7 @@ dnl type, so there is no conflict. Variables with the prefix "TARGET_"
|
|||
dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
|
||||
dnl type.
|
||||
|
||||
AC_INIT([GRUB],[1.99~rc2],[bug-grub@gnu.org])
|
||||
AC_INIT([GRUB],[1.99],[bug-grub@gnu.org])
|
||||
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
|
||||
|
@ -72,7 +72,7 @@ case "$target_cpu" in
|
|||
amd64) target_cpu=x86_64 ;;
|
||||
sparc) target_cpu=sparc64 ;;
|
||||
mipsel|mips64el)
|
||||
target_cpu=mips;
|
||||
target_cpu=mipsel;
|
||||
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1";
|
||||
;;
|
||||
mips|mips64)
|
||||
|
@ -96,7 +96,9 @@ if test "x$with_platform" = x; then
|
|||
powerpc-*) platform=ieee1275 ;;
|
||||
powerpc64-*) platform=ieee1275 ;;
|
||||
sparc64-*) platform=ieee1275 ;;
|
||||
mips-*) platform=yeeloong ;;
|
||||
mipsel-*) platform=loongson ;;
|
||||
mips-*) platform=arc ;;
|
||||
ia64-*) platform=efi ;;
|
||||
*) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
|
||||
esac
|
||||
else
|
||||
|
@ -122,8 +124,15 @@ case "$target_cpu"-"$platform" in
|
|||
i386-qemu) ;;
|
||||
powerpc-ieee1275) ;;
|
||||
sparc64-ieee1275) ;;
|
||||
mips-qemu-mips) ;;
|
||||
mips-yeeloong) ;;
|
||||
ia64-efi) ;;
|
||||
mips-qemu_mips) ;;
|
||||
mips-qemu-mips) platform=qemu_mips;;
|
||||
mips-arc) ;;
|
||||
mipsel-qemu_mips) ;;
|
||||
mipsel-qemu-mips) platform=qemu_mips;;
|
||||
mipsel-yeeloong) platform=loongson ;;
|
||||
mipsel-fuloong) platform=loongson ;;
|
||||
mipsel-loongson) ;;
|
||||
*-emu) ;;
|
||||
*) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
|
||||
esac
|
||||
|
@ -156,14 +165,19 @@ case "$platform" in
|
|||
qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
|
||||
pc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
|
||||
emu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
|
||||
yeeloong) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
|
||||
qemu-mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
|
||||
loongson) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
|
||||
qemu_mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
|
||||
arc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
|
||||
esac
|
||||
case "$target_cpu" in
|
||||
mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;;
|
||||
mips |mipsel) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;;
|
||||
sparc64) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_SPARC64=1" ;;
|
||||
esac
|
||||
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
|
||||
if test x${target_cpu} = xmipsel ; then
|
||||
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
|
||||
else
|
||||
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
|
||||
fi
|
||||
|
||||
HOST_CPPFLAGS="$HOST_CPPFLAGS $machine_CPPFLAGS"
|
||||
TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS"
|
||||
|
@ -219,8 +233,8 @@ for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
|
|||
done
|
||||
done
|
||||
|
||||
if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xyeeloong ); then
|
||||
AC_MSG_ERROR([qemu and yeeloong ports need unifont])
|
||||
if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson ); then
|
||||
AC_MSG_ERROR([qemu and loongson ports need unifont])
|
||||
fi
|
||||
|
||||
AC_SUBST([FONT_SOURCE])
|
||||
|
@ -398,7 +412,7 @@ if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
|
|||
TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
|
||||
fi
|
||||
|
||||
if test "${target_cpu}-${platform}" = mips-yeeloong; then
|
||||
if test "${target_cpu}-${platform}" = mipsel-loongson; then
|
||||
AC_CACHE_CHECK([whether -march=loongson2f works], [grub_cv_cc_march_loongson2f], [
|
||||
SAVE_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -march=loongson2f"
|
||||
|
@ -590,7 +604,7 @@ CFLAGS="$CFLAGS -Wl,--defsym,abort=main"
|
|||
fi
|
||||
|
||||
# Check for libgcc symbols
|
||||
AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x)
|
||||
AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3)
|
||||
|
||||
if test "x$TARGET_APPLE_CC" = x1 ; then
|
||||
CFLAGS="$TARGET_CFLAGS -nostdlib"
|
||||
|
@ -945,16 +959,18 @@ AC_SUBST(NEED_REGISTER_FRAME_INFO)
|
|||
AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
|
||||
AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
|
||||
AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
|
||||
AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
|
||||
AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
|
||||
AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
|
||||
AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
|
||||
AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
|
||||
AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
|
||||
AM_CONDITIONAL([COND_mips_yeeloong], [test x$target_cpu = xmips -a x$platform = xyeeloong])
|
||||
AM_CONDITIONAL([COND_mips_qemu_mips], [test x$target_cpu = xmips -a x$platform = xqemu_mips])
|
||||
AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
|
||||
AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips])
|
||||
AM_CONDITIONAL([COND_mips_arc], [test x$target_cpu = xmips -a x$platform = xarc])
|
||||
AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
|
||||
AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
|
||||
AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips])
|
||||
AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
|
||||
|
||||
AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
|
||||
AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
|
||||
|
@ -976,19 +992,23 @@ AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
|
|||
AM_CONDITIONAL([COND_CYGWIN], [test x$host_os = xcygwin])
|
||||
|
||||
# Output files.
|
||||
cpudir="${target_cpu}"
|
||||
if test x${cpudir} = xmipsel; then
|
||||
cpudir=mips;
|
||||
fi
|
||||
grub_CHECK_LINK_DIR
|
||||
if test x"$link_dir" = xyes ; then
|
||||
AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu])
|
||||
AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
|
||||
if test "$platform" != emu ; then
|
||||
AC_CONFIG_LINKS([include/grub/machine:include/grub/$target_cpu/$platform])
|
||||
AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
|
||||
fi
|
||||
else
|
||||
mkdir -p include/grub 2>/dev/null
|
||||
rm -rf include/grub/cpu
|
||||
cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
|
||||
cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
|
||||
if test "$platform" != emu ; then
|
||||
rm -rf include/grub/machine
|
||||
cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
|
||||
cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
109
docs/grub.texi
109
docs/grub.texi
|
@ -528,21 +528,15 @@ system (@pxref{Obtaining and Building GRUB}). You can do this either
|
|||
from the source tarball, or as a package for your OS.
|
||||
|
||||
After you have done that, you need to install the boot loader on a
|
||||
drive (floppy or hard disk). There are two ways of doing that - either
|
||||
using the utility @command{grub-install} (@pxref{Invoking
|
||||
grub-install}) on a UNIX-like OS, or by running GRUB itself from a
|
||||
floppy. These are quite similar, however the utility might probe a
|
||||
wrong BIOS drive, so you should be careful.
|
||||
|
||||
Also, if you install GRUB on a UNIX-like OS, please make sure that you
|
||||
have an emergency boot disk ready, so that you can rescue your computer
|
||||
if, by any chance, your hard drive becomes unusable (unbootable).
|
||||
drive (floppy or hard disk) by using the utility
|
||||
@command{grub-install} (@pxref{Invoking grub-install}) on a UNIX-like OS.
|
||||
|
||||
GRUB comes with boot images, which are normally put in the directory
|
||||
@file{/usr/lib/grub/i386-pc}. Hereafter, the directory where GRUB images are
|
||||
initially placed (normally @file{/usr/lib/grub/i386-pc}) will be
|
||||
@file{/usr/lib/grub/<cpu>-<platform>} (for BIOS-based machines
|
||||
@file{/usr/lib/grub/i386-pc}). Hereafter, the directory where GRUB images are
|
||||
initially placed (normally @file{/usr/lib/grub/<cpu>-<platform>}) will be
|
||||
called the @dfn{image directory}, and the directory where the boot
|
||||
loader needs to find them (usually @file{/boot/grub}) will be called
|
||||
loader needs to find them (usually @file{/boot}) will be called
|
||||
the @dfn{boot directory}.
|
||||
|
||||
@menu
|
||||
|
@ -556,27 +550,18 @@ the @dfn{boot directory}.
|
|||
@node Installing GRUB using grub-install
|
||||
@section Installing GRUB using grub-install
|
||||
|
||||
@strong{Caution:} This procedure is definitely less safe, because
|
||||
there are several ways in which your computer can become
|
||||
unbootable. For example, most operating systems don't tell GRUB how to
|
||||
map BIOS drives to OS devices correctly---GRUB merely @dfn{guesses}
|
||||
the mapping. This will succeed in most cases, but not
|
||||
always. Therefore, GRUB provides you with a map file called the
|
||||
@dfn{device map}, which you must fix if it is wrong. @xref{Device
|
||||
map}, for more details.
|
||||
|
||||
For information on where GRUB should be installed on PC BIOS platforms,
|
||||
@pxref{BIOS installation}.
|
||||
|
||||
If you still do want to install GRUB under a UNIX-like OS (such
|
||||
In order to install GRUB under a UNIX-like OS (such
|
||||
as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking
|
||||
grub-install}) as the superuser (@dfn{root}).
|
||||
|
||||
The usage is basically very simple. You only need to specify one
|
||||
argument to the program, namely, where to install the boot loader. The
|
||||
argument can be either a device file (like @samp{/dev/hda}) or a
|
||||
partition specified in GRUB's notation. For example, under Linux the
|
||||
following will install GRUB into the MBR of the first IDE disk:
|
||||
argument has to be either a device file (like @samp{/dev/hda}).
|
||||
For example, under Linux the following will install GRUB into the MBR
|
||||
of the first IDE disk:
|
||||
|
||||
@example
|
||||
# @kbd{grub-install /dev/hda}
|
||||
|
@ -588,37 +573,22 @@ Likewise, under GNU/Hurd, this has the same effect:
|
|||
# @kbd{grub-install /dev/hd0}
|
||||
@end example
|
||||
|
||||
But all the above examples assume that GRUB should use images under
|
||||
the root directory. If you want GRUB to use images under a directory
|
||||
other than the root directory, you need to specify the option
|
||||
@option{--root-directory}. The typical usage is that you create a GRUB
|
||||
But all the above examples assume that GRUB should put images under
|
||||
the @file{/boot} directory. If you want GRUB to put images under a directory
|
||||
other than @file{/boot}, you need to specify the option
|
||||
@option{--boot-directory}. The typical usage is that you create a GRUB
|
||||
boot floppy with a filesystem. Here is an example:
|
||||
|
||||
@example
|
||||
@group
|
||||
# @kbd{mke2fs /dev/fd0}
|
||||
# @kbd{mount -t ext2 /dev/fd0 /mnt}
|
||||
# @kbd{grub-install --root-directory=/mnt fd0}
|
||||
# @kbd{mkdir /mnt/boot}
|
||||
# @kbd{grub-install --boot-directory=/mnt/boot /dev/fd0}
|
||||
# @kbd{umount /mnt}
|
||||
@end group
|
||||
@end example
|
||||
|
||||
Another example is when you have a separate boot partition
|
||||
which is mounted at @file{/boot}. Since GRUB is a boot loader, it
|
||||
doesn't know anything about mountpoints at all. Thus, you need to run
|
||||
@command{grub-install} like this:
|
||||
|
||||
@example
|
||||
# @kbd{grub-install --root-directory=/boot /dev/hda}
|
||||
@end example
|
||||
|
||||
By the way, as noted above, it is quite difficult to guess BIOS drives
|
||||
correctly under a UNIX-like OS. Thus, @command{grub-install} will prompt
|
||||
you to check if it could really guess the correct mappings, after the
|
||||
installation. The format is defined in @ref{Device map}. Please be
|
||||
quite careful. If the output is wrong, it is unlikely that your
|
||||
computer will be able to boot with no problem.
|
||||
|
||||
Some BIOSes have a bug of exposing the first partition of a USB drive as a
|
||||
floppy instead of exposing the USB drive as a hard disk (they call it
|
||||
``USB-FDD'' boot). In such cases, you need to install like this:
|
||||
|
@ -1199,8 +1169,14 @@ NetBSD.
|
|||
|
||||
@item GRUB_CMDLINE_XEN
|
||||
@itemx GRUB_CMDLINE_XEN_DEFAULT
|
||||
As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
|
||||
Linux and Xen.
|
||||
The values of these options are appended to the values of
|
||||
@samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux
|
||||
and Xen menu entries.
|
||||
|
||||
@item GRUB_CMDLINE_LINUX_XEN_REPLACE
|
||||
@item GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT
|
||||
The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX}
|
||||
and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries.
|
||||
|
||||
@item GRUB_DISABLE_LINUX_UUID
|
||||
Normally, @command{grub-mkconfig} will generate menu entries that use
|
||||
|
@ -3966,6 +3942,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel
|
|||
@item @tab BIOS @tab Coreboot
|
||||
@item BIOS chainloading @tab yes @tab no (1)
|
||||
@item NTLDR @tab yes @tab no (1)
|
||||
@item Freedos @tab yes @tab no (1)
|
||||
@item FreeBSD bootloader @tab yes @tab crashes (1)
|
||||
@item 32-bit kFreeBSD @tab yes @tab crashes (2,6)
|
||||
@item 64-bit kFreeBSD @tab yes @tab crashes (2,6)
|
||||
|
@ -3990,6 +3967,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel
|
|||
@item @tab Multiboot @tab Qemu
|
||||
@item BIOS chainloading @tab no (1) @tab no (1)
|
||||
@item NTLDR @tab no (1) @tab no (1)
|
||||
@item FreeDOS @tab no (1) @tab no (1)
|
||||
@item FreeBSD bootloader @tab crashes (1) @tab crashes (1)
|
||||
@item 32-bit kFreeBSD @tab crashes (6) @tab crashes (6)
|
||||
@item 64-bit kFreeBSD @tab crashes (6) @tab crashes (6)
|
||||
|
@ -4014,6 +3992,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel
|
|||
@item @tab 32-bit EFI @tab 64-bit EFI
|
||||
@item BIOS chainloading @tab no (1) @tab no (1)
|
||||
@item NTLDR @tab no (1) @tab no (1)
|
||||
@item FreeDOS @tab no (1) @tab no (1)
|
||||
@item FreeBSD bootloader @tab crashes (1) @tab crashes (1)
|
||||
@item 32-bit kFreeBSD @tab headless @tab headless
|
||||
@item 64-bit kFreeBSD @tab headless @tab headless
|
||||
|
@ -4038,6 +4017,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel
|
|||
@item @tab IEEE1275
|
||||
@item BIOS chainloading @tab no (1)
|
||||
@item NTLDR @tab no (1)
|
||||
@item FreeDOS @tab no (1)
|
||||
@item FreeBSD bootloader @tab crashes (1)
|
||||
@item 32-bit kFreeBSD @tab crashes (6)
|
||||
@item 64-bit kFreeBSD @tab crashes (6)
|
||||
|
@ -4127,6 +4107,8 @@ device), then you can correct this and enter normal mode manually:
|
|||
@group
|
||||
# Inspect the current prefix (and other preset variables):
|
||||
set
|
||||
# Find out which devices are available:
|
||||
ls
|
||||
# Set to the correct value, which might be something like this:
|
||||
set prefix=(hd0,1)/grub
|
||||
set root=(hd0,1)
|
||||
|
@ -4193,15 +4175,28 @@ Print a summary of the command-line options and exit.
|
|||
@item --version
|
||||
Print the version number of GRUB and exit.
|
||||
|
||||
@item --root-directory=@var{dir}
|
||||
Install GRUB images under the directory @var{dir} instead of the root
|
||||
directory. This option is useful when you want to install GRUB into a
|
||||
separate partition or a removable disk. Here is an example in which
|
||||
you have a separate @dfn{boot} partition which is mounted on
|
||||
@file{/boot}:
|
||||
@item --boot-directory=@var{dir}
|
||||
Install GRUB images under the directory @file{@var{dir}/grub/}
|
||||
This option is useful when you want to install GRUB into a
|
||||
separate partition or a removable disk.
|
||||
If this option is not specified then it defaults to @file{/boot}, so
|
||||
|
||||
@example
|
||||
@kbd{grub-install --root-directory=/boot hd0}
|
||||
@kbd{grub-install /dev/sda}
|
||||
@end example
|
||||
|
||||
is equivalent to
|
||||
|
||||
@example
|
||||
@kbd{grub-install --boot-directory=/boot/ /dev/sda}
|
||||
@end example
|
||||
|
||||
Here is an example in which you have a separate @dfn{boot} partition which is
|
||||
mounted on
|
||||
@file{/mnt/boot}:
|
||||
|
||||
@example
|
||||
@kbd{grub-install --boot-directory=/mnt/boot /dev/sdb}
|
||||
@end example
|
||||
|
||||
@item --recheck
|
||||
|
@ -4335,11 +4330,11 @@ how to get the latest version.
|
|||
@end quotation
|
||||
|
||||
GRUB is available from the GNU alpha archive site
|
||||
@uref{ftp://alpha.gnu.org/gnu/grub} or any of its mirrors. The file
|
||||
@uref{ftp://ftp.gnu.org/gnu/grub} or any of its mirrors. The file
|
||||
will be named grub-version.tar.gz. The current version is
|
||||
@value{VERSION}, so the file you should grab is:
|
||||
|
||||
@uref{ftp://alpha.gnu.org/gnu/grub/grub-@value{VERSION}.tar.gz}
|
||||
@uref{ftp://ftp.gnu.org/gnu/grub/grub-@value{VERSION}.tar.gz}
|
||||
|
||||
To unbundle GRUB use the instruction:
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[NAME]
|
||||
grub-bin2h \- convert a binary file to a C header
|
|
@ -1,2 +1,5 @@
|
|||
[NAME]
|
||||
grub-editenv \- edit GRUB environment block
|
||||
[SEE ALSO]
|
||||
.BR grub-reboot (8),
|
||||
.BR grub-set-default (8)
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
[NAME]
|
||||
grub-emu \- GRUB emulator
|
||||
[SEE ALSO]
|
||||
If you are trying to install GRUB, then you should use
|
||||
.BR grub-install (8)
|
||||
rather than this program.
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-fstest \- debug tool for GRUB filesystem drivers
|
||||
[SEE ALSO]
|
||||
.BR grub-probe (8)
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
[NAME]
|
||||
grub-install \- install GRUB to a device
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8),
|
||||
.BR grub-mkimage (1),
|
||||
.BR grub-setup (8),
|
||||
.BR grub-mkrescue (1)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-macho2img \- convert Mach-O to raw image
|
||||
[SEE ALSO]
|
||||
.BR grub-mkimage (1)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
[NAME]
|
||||
grub-menulst2cfg \- transform legacy menu.lst into grub.cfg
|
||||
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkconfig \- generate a GRUB configuration file
|
||||
[SEE ALSO]
|
||||
.BR grub-install (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkdevicemap \- generate a GRUB device map file automatically
|
||||
[SEE ALSO]
|
||||
.BR grub-install (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkfont \- make GRUB font files
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8)
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
[NAME]
|
||||
grub-mkimage \- make a bootable image of GRUB
|
||||
[SEE ALSO]
|
||||
.BR grub-install (8),
|
||||
.BR grub-setup (8),
|
||||
.BR grub-mkrescue (1),
|
||||
.BR grub-mknetdir (8)
|
||||
|
|
|
@ -1,2 +1,10 @@
|
|||
[NAME]
|
||||
grub-mklayout \- generate a GRUB keyboard layout file
|
||||
[DESCRIPTION]
|
||||
grub-mklayout processes a keyboard layout description in
|
||||
.BR keymaps (5)
|
||||
format into a format that can be used by GRUB's
|
||||
.B keymap
|
||||
command.
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mknetdir \- prepare a GRUB netboot directory.
|
||||
[SEE ALSO]
|
||||
.BR grub-mkimage (1)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkpasswd-pbkdf2 \- generate hashed password for GRUB
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkrelpath \- make a system path relative to its root
|
||||
[SEE ALSO]
|
||||
.BR grub-probe (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-mkrescue \- make a GRUB rescue image
|
||||
[SEE ALSO]
|
||||
.BR grub-mkimage (1)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-ofpathname \- find OpenBOOT path for a device
|
||||
[SEE ALSO]
|
||||
.BR grub-probe (8)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-pe2elf \- convert PE image to ELF
|
||||
[SEE ALSO]
|
||||
.BR grub-mkimage (1)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-probe \- probe device information for GRUB
|
||||
[SEE ALSO]
|
||||
.BR grub-fstest (1)
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
[NAME]
|
||||
grub-reboot \- set the default boot entry for GRUB, for the next boot only
|
||||
[SEE ALSO]
|
||||
.BR grub-set-default (8),
|
||||
.BR grub-editenv (1)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[NAME]
|
||||
grub-script-check \- check grub.cfg for syntax errors
|
||||
[SEE ALSO]
|
||||
.BR grub-mkconfig (8)
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
[NAME]
|
||||
grub-set-default \- set the saved default boot entry for GRUB
|
||||
[SEE ALSO]
|
||||
.BR grub-reboot (8),
|
||||
.BR grub-editenv (1)
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
[NAME]
|
||||
grub-setup \- set up a device to boot using GRUB
|
||||
[SEE ALSO]
|
||||
.BR grub-install (8),
|
||||
.BR grub-mkimage (1),
|
||||
.BR grub-mkrescue (1)
|
||||
|
|
21
gentpl.py
21
gentpl.py
|
@ -6,8 +6,9 @@
|
|||
|
||||
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
|
||||
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
|
||||
"mips_yeeloong", "sparc64_ieee1275",
|
||||
"powerpc_ieee1275" ]
|
||||
"mips_loongson", "sparc64_ieee1275",
|
||||
"powerpc_ieee1275", "mips_arc", "ia64_efi",
|
||||
"mips_qemu_mips" ]
|
||||
|
||||
GROUPS = {}
|
||||
|
||||
|
@ -17,29 +18,31 @@ GROUPS["common"] = GRUB_PLATFORMS[:]
|
|||
GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
|
||||
GROUPS["x86_64"] = [ "x86_64_efi" ]
|
||||
GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
|
||||
GROUPS["mips"] = [ "mips_yeeloong" ]
|
||||
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
|
||||
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
|
||||
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
|
||||
|
||||
# Groups based on firmware
|
||||
GROUPS["x86_efi"] = [ "i386_efi", "x86_64_efi" ]
|
||||
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi" ]
|
||||
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
|
||||
|
||||
# emu is a special case so many core functionality isn't needed on this platform
|
||||
GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
|
||||
|
||||
# Groups based on hardware features
|
||||
GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi")
|
||||
GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"]
|
||||
GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips",
|
||||
"sparc64_ieee1275", "powerpc_ieee1275"]
|
||||
GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi")
|
||||
GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"]
|
||||
GROUPS["usb"] = GROUPS["pci"]
|
||||
|
||||
# If gfxterm is main output console integrate it into kernel
|
||||
GROUPS["videoinkernel"] = ["mips_yeeloong"]
|
||||
GROUPS["videoinkernel"] = ["mips_loongson", "mips_qemu_mips"]
|
||||
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
|
||||
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
|
||||
|
||||
# Similar for terminfo
|
||||
GROUPS["terminfoinkernel"] = ["mips_yeeloong"] + GROUPS["ieee1275"];
|
||||
GROUPS["terminfoinkernel"] = ["mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["ieee1275"];
|
||||
GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
|
||||
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
|
||||
|
||||
|
@ -238,7 +241,7 @@ def foreach_enabled_platform(closure):
|
|||
# noemu = bus/usb/usbhub.c;
|
||||
# enable = emu;
|
||||
# enable = i386;
|
||||
# enable = mips_yeeloong;
|
||||
# enable = mips_loongson;
|
||||
# emu_condition = COND_GRUB_EMU_USB;
|
||||
# };
|
||||
#
|
||||
|
|
|
@ -79,6 +79,7 @@ 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
|
||||
|
||||
|
@ -99,10 +100,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 +128,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 +180,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 +203,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
|
||||
|
@ -305,6 +346,7 @@ CLEANFILES += config.log syminfo.lst moddep.lst
|
|||
$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT)
|
||||
TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
|
||||
platform_DATA += $(MOD_FILES)
|
||||
platform_DATA += modinfo.sh
|
||||
CLEANFILES += $(MOD_FILES)
|
||||
|
||||
if COND_ENABLE_EFIEMU
|
||||
|
|
|
@ -12,14 +12,26 @@ script = {
|
|||
common = genmod.sh.in;
|
||||
};
|
||||
|
||||
script = {
|
||||
installdir = noinst;
|
||||
name = modinfo.sh;
|
||||
common = modinfo.sh.in;
|
||||
};
|
||||
|
||||
kernel = {
|
||||
name = kernel;
|
||||
|
||||
nostrip = emu;
|
||||
|
||||
emu_ldflags = '-Wl,-r,-d';
|
||||
x86_efi_ldflags = '-Wl,-r,-d';
|
||||
x86_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment';
|
||||
i386_efi_ldflags = '-Wl,-r,-d';
|
||||
i386_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment';
|
||||
x86_64_efi_ldflags = '-Wl,-r,-d';
|
||||
x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment';
|
||||
|
||||
ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput';
|
||||
ia64_efi_ldflags = '-Wl,-r,-d';
|
||||
ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment';
|
||||
|
||||
i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
|
||||
i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200';
|
||||
|
@ -32,11 +44,13 @@ kernel = {
|
|||
i386_coreboot_ldflags = '-Wl,-Ttext=0x8200';
|
||||
i386_multiboot_ldflags = '-Wl,-Ttext=0x8200';
|
||||
i386_ieee1275_ldflags = '-Wl,-Ttext=0x10000';
|
||||
mips_yeeloong_ldflags = '-Wl,-Ttext,0x80200000';
|
||||
mips_loongson_ldflags = '-Wl,-Ttext,0x80200000';
|
||||
powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
|
||||
sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400';
|
||||
mips_arc_ldflags = '-Wl,-Ttext,0x8bd00000';
|
||||
mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000';
|
||||
|
||||
mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK';
|
||||
mips_loongson_cppflags = '-DUSE_ASCII_FAILBACK';
|
||||
i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
|
||||
emu_cflags = '$(CFLAGS_GNULIB)';
|
||||
emu_cppflags = '$(CPPFLAGS_GNULIB)';
|
||||
|
@ -48,7 +62,7 @@ kernel = {
|
|||
i386_ieee1275_startup = kern/i386/ieee1275/startup.S;
|
||||
i386_coreboot_startup = kern/i386/coreboot/startup.S;
|
||||
i386_multiboot_startup = kern/i386/coreboot/startup.S;
|
||||
mips_yeeloong_startup = kern/mips/startup.S;
|
||||
mips_startup = kern/mips/startup.S;
|
||||
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
|
||||
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
|
||||
|
||||
|
@ -77,11 +91,10 @@ kernel = {
|
|||
noemu_nodist = symlist.c;
|
||||
|
||||
i386_pc = kern/generic/rtc_get_time_ms.c;
|
||||
x86_efi = kern/generic/rtc_get_time_ms.c;
|
||||
i386_qemu = kern/generic/rtc_get_time_ms.c;
|
||||
i386_coreboot = kern/generic/rtc_get_time_ms.c;
|
||||
i386_multiboot = kern/generic/rtc_get_time_ms.c;
|
||||
mips_yeeloong = kern/generic/rtc_get_time_ms.c;
|
||||
mips = kern/generic/rtc_get_time_ms.c;
|
||||
|
||||
ieee1275 = disk/ieee1275/ofdisk.c;
|
||||
ieee1275 = kern/ieee1275/cmain.c;
|
||||
|
@ -89,6 +102,7 @@ kernel = {
|
|||
ieee1275 = kern/ieee1275/mmap.c;
|
||||
ieee1275 = kern/ieee1275/openfw.c;
|
||||
ieee1275 = term/ieee1275/ofconsole.c;
|
||||
ieee1275 = kern/ieee1275/init.c;
|
||||
|
||||
terminfoinkernel = term/terminfo.c;
|
||||
terminfoinkernel = term/tparm.c;
|
||||
|
@ -105,18 +119,24 @@ kernel = {
|
|||
|
||||
x86 = kern/i386/pit.c;
|
||||
|
||||
x86_efi = disk/efi/efidisk.c;
|
||||
x86_efi = kern/efi/efi.c;
|
||||
x86_efi = kern/efi/init.c;
|
||||
x86_efi = kern/efi/mm.c;
|
||||
x86_efi = kern/i386/efi/init.c;
|
||||
x86_efi = term/efi/console.c;
|
||||
efi = disk/efi/efidisk.c;
|
||||
efi = kern/efi/efi.c;
|
||||
efi = kern/efi/init.c;
|
||||
efi = kern/efi/mm.c;
|
||||
efi = term/efi/console.c;
|
||||
|
||||
i386_efi = kern/i386/tsc.c;
|
||||
i386_efi = kern/i386/efi/init.c;
|
||||
|
||||
x86_64_efi = kern/i386/tsc.c;
|
||||
x86_64_efi = kern/x86_64/dl.c;
|
||||
x86_64_efi = kern/x86_64/efi/callwrap.S;
|
||||
x86_64_efi = kern/i386/efi/init.c;
|
||||
|
||||
ia64_efi = kern/ia64/efi/startup.S;
|
||||
ia64_efi = kern/ia64/efi/init.c;
|
||||
ia64_efi = kern/ia64/dl.c;
|
||||
ia64_efi = kern/ia64/dl_helper.c;
|
||||
|
||||
i386_pc = kern/i386/pc/init.c;
|
||||
i386_pc = kern/i386/pc/mmap.c;
|
||||
|
@ -124,7 +144,7 @@ kernel = {
|
|||
i386_pc = term/i386/pc/console.c;
|
||||
|
||||
i386_qemu = bus/pci.c;
|
||||
i386_qemu = kern/i386/qemu/init.c;
|
||||
i386_qemu = kern/vga_init.c;
|
||||
i386_qemu = kern/i386/qemu/mmap.c;
|
||||
i386_qemu = kern/i386/tsc.c;
|
||||
|
||||
|
@ -134,35 +154,46 @@ kernel = {
|
|||
i386_multiboot = kern/i386/multiboot_mmap.c;
|
||||
i386_multiboot = kern/i386/tsc.c;
|
||||
|
||||
i386_ieee1275 = kern/ieee1275/init.c;
|
||||
mips = kern/mips/cache.S;
|
||||
mips = kern/mips/dl.c;
|
||||
mips = kern/mips/init.c;
|
||||
|
||||
mips_yeeloong = term/ns8250.c;
|
||||
mips_yeeloong = bus/bonito.c;
|
||||
mips_yeeloong = bus/cs5536.c;
|
||||
mips_yeeloong = bus/pci.c;
|
||||
mips_yeeloong = kern/mips/cache.S;
|
||||
mips_yeeloong = kern/mips/dl.c;
|
||||
mips_yeeloong = kern/mips/init.c;
|
||||
mips_yeeloong = kern/mips/yeeloong/init.c;
|
||||
mips_yeeloong = term/at_keyboard.c;
|
||||
mips_yeeloong = term/serial.c;
|
||||
mips_yeeloong = video/sm712.c;
|
||||
mips_qemu_mips = kern/mips/qemu_mips/init.c;
|
||||
mips_qemu_mips = term/ns8250.c;
|
||||
mips_qemu_mips = term/serial.c;
|
||||
mips_qemu_mips = term/at_keyboard.c;
|
||||
mips_qemu_mips = commands/keylayouts.c;
|
||||
mips_qemu_mips = term/i386/pc/vga_text.c;
|
||||
mips_qemu_mips = term/i386/vga_common.c;
|
||||
mips_qemu_mips = kern/vga_init.c;
|
||||
|
||||
mips_arc = kern/mips/arc/init.c;
|
||||
mips_arc = term/arc/console.c;
|
||||
mips_arc = disk/arc/arcdisk.c;
|
||||
|
||||
mips_loongson = term/ns8250.c;
|
||||
mips_loongson = bus/bonito.c;
|
||||
mips_loongson = bus/cs5536.c;
|
||||
mips_loongson = bus/pci.c;
|
||||
mips_loongson = kern/mips/loongson/init.c;
|
||||
mips_loongson = term/at_keyboard.c;
|
||||
mips_loongson = term/serial.c;
|
||||
mips_loongson = video/sm712.c;
|
||||
mips_loongson = video/sis315pro.c;
|
||||
extra_dist = video/sm712_init.c;
|
||||
mips_yeeloong = commands/keylayouts.c;
|
||||
mips_loongson = commands/keylayouts.c;
|
||||
|
||||
powerpc_ieee1275 = kern/ieee1275/init.c;
|
||||
powerpc_ieee1275 = kern/powerpc/cache.S;
|
||||
powerpc_ieee1275 = kern/powerpc/dl.c;
|
||||
|
||||
sparc64_ieee1275 = kern/sparc64/cache.S;
|
||||
sparc64_ieee1275 = kern/sparc64/dl.c;
|
||||
sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c;
|
||||
sparc64_ieee1275 = kern/sparc64/ieee1275/init.c;
|
||||
|
||||
emu = disk/host.c;
|
||||
emu = gnulib/progname.c;
|
||||
emu = gnulib/error.c;
|
||||
emu = kern/emu/cache.S;
|
||||
emu = kern/emu/cache_s.S;
|
||||
emu = kern/emu/console.c;
|
||||
emu = kern/emu/getroot.c;
|
||||
emu = kern/emu/raid.c;
|
||||
|
@ -172,6 +203,7 @@ kernel = {
|
|||
emu = kern/emu/misc.c;
|
||||
emu = kern/emu/mm.c;
|
||||
emu = kern/emu/time.c;
|
||||
emu = kern/emu/cache.c;
|
||||
|
||||
videoinkernel = term/gfxterm.c;
|
||||
videoinkernel = font/font.c;
|
||||
|
@ -179,6 +211,7 @@ kernel = {
|
|||
videoinkernel = io/bufio.c;
|
||||
videoinkernel = video/bitmap.c;
|
||||
videoinkernel = video/bitmap_scale.c;
|
||||
videoinkernel = video/colors.c;
|
||||
videoinkernel = video/fb/fbblit.c;
|
||||
videoinkernel = video/fb/fbfill.c;
|
||||
videoinkernel = video/fb/fbutil.c;
|
||||
|
@ -296,12 +329,12 @@ image = {
|
|||
common = lib/xzembed/xz_dec_lzma2.c;
|
||||
common = lib/xzembed/xz_dec_stream.c;
|
||||
|
||||
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed';
|
||||
|
||||
mips_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
|
||||
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1';
|
||||
|
||||
objcopyflags = '-O binary';
|
||||
ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000';
|
||||
ldadd = '-lgcc';
|
||||
cflags = '-static-libgcc';
|
||||
enable = mips;
|
||||
|
@ -312,10 +345,12 @@ image = {
|
|||
mips = boot/mips/startup_raw.S;
|
||||
common = boot/decompressor/none.c;
|
||||
|
||||
mips_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
|
||||
cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1';
|
||||
|
||||
objcopyflags = '-O binary';
|
||||
ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
|
||||
mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000';
|
||||
ldadd = '-lgcc';
|
||||
cflags = '-static-libgcc';
|
||||
enable = mips;
|
||||
|
@ -323,10 +358,18 @@ image = {
|
|||
|
||||
image = {
|
||||
name = fwstart;
|
||||
mips_yeeloong = boot/mips/yeeloong/fwstart.S;
|
||||
mips_loongson = boot/mips/loongson/fwstart.S;
|
||||
objcopyflags = '-O binary';
|
||||
ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic';
|
||||
enable = mips_yeeloong;
|
||||
enable = mips_loongson;
|
||||
};
|
||||
|
||||
image = {
|
||||
name = fwstart_fuloong;
|
||||
mips_loongson = boot/mips/loongson/fuloong.S;
|
||||
objcopyflags = '-O binary';
|
||||
ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic';
|
||||
enable = mips_loongson;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -350,8 +393,8 @@ module = {
|
|||
|
||||
module = {
|
||||
name = lsspd;
|
||||
mips_yeeloong = commands/mips/yeeloong/lsspd.c;
|
||||
enable = mips_yeeloong;
|
||||
mips_loongson = commands/mips/loongson/lsspd.c;
|
||||
enable = mips_loongson;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -402,13 +445,21 @@ module = {
|
|||
|
||||
enable = emu;
|
||||
enable = i386_pc;
|
||||
enable = x86_efi;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
enable = i386_ieee1275;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
emu_condition = COND_GRUB_EMU_PCI;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = lsdev;
|
||||
common = commands/arc/lsdev.c;
|
||||
|
||||
enable = mips_arc;
|
||||
};
|
||||
|
||||
library = {
|
||||
name = libgnulib.a;
|
||||
common = gnulib/regex.c;
|
||||
|
@ -441,12 +492,12 @@ module = {
|
|||
name = acpi;
|
||||
|
||||
common = commands/acpi.c;
|
||||
x86_efi = commands/efi/acpi.c;
|
||||
efi = commands/efi/acpi.c;
|
||||
i386_pc = commands/i386/pc/acpi.c;
|
||||
i386_coreboot = commands/i386/pc/acpi.c;
|
||||
i386_multiboot = commands/i386/pc/acpi.c;
|
||||
|
||||
enable = x86_efi;
|
||||
enable = efi;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
|
@ -457,7 +508,7 @@ module = {
|
|||
|
||||
common = commands/lsacpi.c;
|
||||
|
||||
enable = x86_efi;
|
||||
enable = efi;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
|
@ -468,7 +519,7 @@ module = {
|
|||
|
||||
common = commands/efi/lsefisystab.c;
|
||||
|
||||
enable = x86_efi;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -476,7 +527,7 @@ module = {
|
|||
|
||||
common = commands/efi/lssal.c;
|
||||
|
||||
enable = x86_efi;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -484,7 +535,7 @@ module = {
|
|||
|
||||
common = commands/efi/lsefimmap.c;
|
||||
|
||||
enable = x86_efi;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -547,8 +598,9 @@ module = {
|
|||
|
||||
module = {
|
||||
name = fixvideo;
|
||||
x86_efi = commands/efi/fixvideo.c;
|
||||
enable = x86_efi;
|
||||
common = commands/efi/fixvideo.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -563,11 +615,12 @@ module = {
|
|||
i386_pc = commands/acpihalt.c;
|
||||
i386_coreboot = commands/acpihalt.c;
|
||||
i386_multiboot = commands/acpihalt.c;
|
||||
x86_efi = commands/acpihalt.c;
|
||||
i386_efi = commands/acpihalt.c;
|
||||
x86_64_efi = commands/acpihalt.c;
|
||||
i386_multiboot = lib/i386/halt.c;
|
||||
i386_coreboot = lib/i386/halt.c;
|
||||
i386_qemu = lib/i386/halt.c;
|
||||
x86_efi = lib/efi/halt.c;
|
||||
efi = lib/efi/halt.c;
|
||||
ieee1275 = lib/ieee1275/halt.c;
|
||||
emu = lib/emu/halt.c;
|
||||
};
|
||||
|
@ -582,6 +635,7 @@ module = {
|
|||
common = commands/hdparm.c;
|
||||
common = lib/hexdump.c;
|
||||
enable = pci;
|
||||
enable = mips_qemu_mips;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -602,8 +656,9 @@ module = {
|
|||
|
||||
module = {
|
||||
name = loadbios;
|
||||
x86_efi = commands/efi/loadbios.c;
|
||||
enable = x86_efi;
|
||||
common = commands/efi/loadbios.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -665,12 +720,6 @@ module = {
|
|||
common = commands/probe.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = pxecmd;
|
||||
i386_pc = commands/i386/pc/pxecmd.c;
|
||||
enable = i386_pc;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = read;
|
||||
common = commands/read.c;
|
||||
|
@ -812,14 +861,22 @@ module = {
|
|||
name = ata;
|
||||
common = disk/ata.c;
|
||||
enable = pci;
|
||||
enable = mips_qemu_mips;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = ata_pthru;
|
||||
common = disk/ata_pthru.c;
|
||||
name = ahci;
|
||||
common = disk/ahci.c;
|
||||
enable = pci;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = pata;
|
||||
common = disk/pata.c;
|
||||
enable = pci;
|
||||
enable = mips_qemu_mips;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = biosdisk;
|
||||
i386_pc = disk/i386/pc/biosdisk.c;
|
||||
|
@ -960,6 +1017,11 @@ module = {
|
|||
common = fs/minix2.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = minix3;
|
||||
common = fs/minix3.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = nilfs2;
|
||||
common = fs/nilfs2.c;
|
||||
|
@ -980,11 +1042,21 @@ module = {
|
|||
common = fs/reiserfs.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = romfs;
|
||||
common = fs/romfs.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = sfs;
|
||||
common = fs/sfs.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = squash4;
|
||||
common = fs/squash4.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = tar;
|
||||
common = fs/tar.c;
|
||||
|
@ -1025,7 +1097,7 @@ module = {
|
|||
|
||||
module = {
|
||||
name = pxe;
|
||||
i386_pc = fs/i386/pc/pxe.c;
|
||||
i386_pc = net/drivers/i386/pc/pxe.c;
|
||||
enable = i386_pc;
|
||||
};
|
||||
|
||||
|
@ -1052,7 +1124,6 @@ module = {
|
|||
common = gfxmenu/gui_progress_bar.c;
|
||||
common = gfxmenu/gui_util.c;
|
||||
common = gfxmenu/gui_string_util.c;
|
||||
common = gfxmenu/named_colors.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1098,7 +1169,7 @@ module = {
|
|||
x86_64 = lib/x86_64/relocator_asm.S;
|
||||
x86 = lib/i386/relocator.c;
|
||||
ieee1275 = lib/ieee1275/relocator.c;
|
||||
x86_efi = lib/efi/relocator.c;
|
||||
efi = lib/efi/relocator.c;
|
||||
mips = lib/mips/relocator_asm.S;
|
||||
mips = lib/mips/relocator.c;
|
||||
powerpc = lib/powerpc/relocator_asm.S;
|
||||
|
@ -1115,9 +1186,13 @@ module = {
|
|||
module = {
|
||||
name = datetime;
|
||||
cmos = lib/cmos_datetime.c;
|
||||
x86_efi = lib/efi/datetime.c;
|
||||
efi = lib/efi/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/datetime.c;
|
||||
powerpc_ieee1275 = lib/ieee1275/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/cmos.c;
|
||||
powerpc_ieee1275 = lib/ieee1275/cmos.c;
|
||||
|
||||
mips_arc = lib/arc/datetime.c;
|
||||
enable = noemu;
|
||||
};
|
||||
|
||||
|
@ -1129,6 +1204,7 @@ module = {
|
|||
extra_dist = lib/x86_64/setjmp.S;
|
||||
extra_dist = lib/sparc64/setjmp.S;
|
||||
extra_dist = lib/powerpc/setjmp.S;
|
||||
extra_dist = lib/ia64/setjmp.S;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1162,6 +1238,12 @@ module = {
|
|||
enable = i386_pc;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = freedos;
|
||||
i386_pc = loader/i386/pc/freedos.c;
|
||||
enable = i386_pc;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = multiboot2;
|
||||
cppflags = "-DGRUB_USE_MULTIBOOT2";
|
||||
|
@ -1187,6 +1269,7 @@ module = {
|
|||
mips = loader/mips/linux.c;
|
||||
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
|
||||
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
|
||||
ia64_efi = loader/ia64/efi/linux.c;
|
||||
common = lib/cmdline.c;
|
||||
enable = noemu;
|
||||
};
|
||||
|
@ -1206,16 +1289,19 @@ module = {
|
|||
|
||||
module = {
|
||||
name = appleldr;
|
||||
x86_efi = loader/efi/appleloader.c;
|
||||
enable = x86_efi;
|
||||
common = loader/efi/appleloader.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = chain;
|
||||
x86_efi = loader/efi/chainloader.c;
|
||||
efi = loader/efi/chainloader.c;
|
||||
i386_pc = loader/i386/pc/chainloader.c;
|
||||
i386_coreboot = loader/i386/coreboot/chainloader.c;
|
||||
enable = i386_pc;
|
||||
enable = x86_efi;
|
||||
enable = i386_coreboot;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1227,12 +1313,13 @@ module = {
|
|||
i386_pc = mmap/i386/pc/mmap.c;
|
||||
i386_pc = mmap/i386/pc/mmap_helper.S;
|
||||
|
||||
x86_efi = mmap/efi/mmap.c;
|
||||
efi = mmap/efi/mmap.c;
|
||||
|
||||
mips_yeeloong = mmap/mips/yeeloong/uppermem.c;
|
||||
mips = mmap/mips/uppermem.c;
|
||||
|
||||
enable = x86;
|
||||
enable = mips_yeeloong;
|
||||
enable = ia64_efi;
|
||||
enable = mips;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1306,6 +1393,11 @@ module = {
|
|||
common = partmap/sun.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = part_dvh;
|
||||
common = partmap/dvh.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = part_bsd;
|
||||
common = partmap/bsdlabel.c;
|
||||
|
@ -1339,8 +1431,7 @@ module = {
|
|||
x86 = term/ns8250.c;
|
||||
|
||||
enable = emu;
|
||||
enable = i386;
|
||||
enable = x86_64_efi;
|
||||
enable = x86;
|
||||
emu_condition = COND_GRUB_EMU_USB;
|
||||
};
|
||||
|
||||
|
@ -1365,8 +1456,10 @@ module = {
|
|||
|
||||
module = {
|
||||
name = vga;
|
||||
i386_pc = video/i386/pc/vga.c;
|
||||
common = video/i386/pc/vga.c;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1416,14 +1509,15 @@ module = {
|
|||
|
||||
module = {
|
||||
name = efi_gop;
|
||||
x86_efi = video/efi_gop.c;
|
||||
enable = x86_efi;
|
||||
efi = video/efi_gop.c;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = efi_uga;
|
||||
x86_efi = video/efi_uga.c;
|
||||
enable = x86_efi;
|
||||
efi = video/efi_uga.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1443,8 +1537,10 @@ module = {
|
|||
|
||||
module = {
|
||||
name = vbe;
|
||||
i386_pc = video/i386/pc/vbe.c;
|
||||
common = video/i386/pc/vbe.c;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1459,13 +1555,14 @@ module = {
|
|||
module = {
|
||||
name = video;
|
||||
common = video/video.c;
|
||||
common = video/colors.c;
|
||||
enable = videomodules;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = ieee1275_fb;
|
||||
ieee1275 = video/ieee1275.c;
|
||||
enable = powerpc;
|
||||
enable = powerpc_ieee1275;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1480,6 +1577,40 @@ module = {
|
|||
common = hook/datehook.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = net;
|
||||
common = net/net.c;
|
||||
common = net/bootp.c;
|
||||
common = net/ip.c;
|
||||
common = net/udp.c;
|
||||
common = net/ethernet.c;
|
||||
common = net/arp.c;
|
||||
common = net/netbuff.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = tftp;
|
||||
common = net/tftp.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = ofnet;
|
||||
common = net/drivers/ieee1275/ofnet.c;
|
||||
enable = ieee1275;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = efinet;
|
||||
common = net/drivers/efi/efinet.c;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = emunet;
|
||||
emu = net/drivers/emu/emunet.c;
|
||||
enable = emu;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = legacycfg;
|
||||
common = commands/legacycfg.c;
|
||||
|
@ -1519,3 +1650,8 @@ module = {
|
|||
common = commands/keylayouts.c;
|
||||
enable = videomodules;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = time;
|
||||
common = commands/time.c;
|
||||
};
|
||||
|
|
|
@ -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++;
|
||||
|
|
2
grub-core/boot/mips/loongson/fuloong.S
Normal file
2
grub-core/boot/mips/loongson/fuloong.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define FULOONG 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 FULOONG
|
||||
#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 Fuloong serial is past
|
||||
Geode, so on Fuloong we need Geode first.
|
||||
*/
|
||||
#ifndef FULOONG
|
||||
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 FULOONG
|
||||
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 FULOONG
|
||||
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 Fuloong have only one memory slot. */
|
||||
/* Output first byte on serial for debugging. */
|
||||
ori $a1, $zero, GRUB_SMB_RAM_START_ADDR
|
||||
bal read_spd
|
||||
|
@ -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 FULOONG
|
||||
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 FULOONG
|
||||
.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 FULOONG
|
||||
.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 FULOONG
|
||||
.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 FULOONG
|
||||
addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG)
|
||||
#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
|
||||
|
@ -43,21 +44,45 @@ compressed_size:
|
|||
. = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE
|
||||
uncompressed_size:
|
||||
.long 0
|
||||
. = _start + GRUB_KERNEL_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_fuloong_verstr, GRUB_ARCH_MACHINE_FULOONG)
|
||||
2:
|
||||
b argcont
|
||||
addiu $t0, $t0, 4
|
||||
|
@ -120,8 +153,47 @@ 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_fuloong_str: .asciiz "machtype=lemote-fuloong-"
|
||||
pmon_yeeloong_str: .asciiz "PMON_VER=LM8"
|
||||
pmon_fuloong_str: .asciiz "PMON_VER=LM6"
|
||||
pmon_yeeloong_verstr: .asciiz "Version=LM8"
|
||||
pmon_fuloong_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_fuloong_str, GRUB_ARCH_MACHINE_FULOONG)
|
||||
DO_CHECKA1 (pmon_fuloong_str, GRUB_ARCH_MACHINE_FULOONG)
|
||||
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 +222,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,8 +238,7 @@ argdone:
|
|||
subu $a0, $a0, $t0
|
||||
addu $a0, $a0, $s0
|
||||
|
||||
lui $a1, %hi(GRUB_MACHINE_LINK_ADDR)
|
||||
addiu $a1, %lo(GRUB_MACHINE_LINK_ADDR)
|
||||
lw $a1, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR - BASE_ADDR)($s0)
|
||||
lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0)
|
||||
lw $a3, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0)
|
||||
move $s1, $a1
|
||||
|
@ -170,9 +248,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
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#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>
|
||||
|
||||
|
@ -217,26 +220,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)
|
||||
|
@ -277,17 +260,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);
|
||||
|
@ -299,11 +271,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_FULOONG:
|
||||
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,6 +20,9 @@
|
|||
#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+");
|
||||
|
||||
|
@ -28,17 +31,28 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|||
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)
|
||||
{
|
||||
|
@ -101,13 +115,13 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
|||
continue;
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
/* Skip ghosts. */
|
||||
if (id == GRUB_YEELOONG_OHCI_PCIID
|
||||
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
|
||||
if (id == GRUB_LOONGSON_OHCI_PCIID
|
||||
&& dev.function == GRUB_LOONGSON_OHCI_GHOST_FUNCTION)
|
||||
continue;
|
||||
if (id == GRUB_YEELOONG_EHCI_PCIID
|
||||
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
|
||||
if (id == GRUB_LOONGSON_EHCI_PCIID
|
||||
&& dev.function == GRUB_LOONGSON_EHCI_GHOST_FUNCTION)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -1424,18 +1426,22 @@ static struct grub_usb_controller_dev usb_controller =
|
|||
.detect_dev = grub_ohci_detect_dev
|
||||
};
|
||||
|
||||
static void *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);
|
||||
}
|
||||
|
|
|
@ -185,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;
|
||||
|
|
|
@ -215,6 +215,8 @@ 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);
|
||||
hub->controller->dev->pending_reset = 0;
|
||||
|
@ -350,8 +352,8 @@ 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",
|
||||
dev, i, status);
|
||||
grub_dprintf ("usb", "dev = %p, i = %d, status = %08x\n",
|
||||
dev, i, status);
|
||||
|
||||
if (err)
|
||||
continue;
|
||||
|
|
|
@ -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,37 +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);
|
||||
}
|
|
@ -94,10 +94,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
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)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/ata.h>
|
||||
#include <grub/scsi.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
|
@ -63,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;
|
||||
|
@ -126,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");
|
||||
|
@ -140,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)
|
||||
|
@ -151,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)
|
||||
|
@ -275,6 +280,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)
|
||||
|
@ -285,9 +291,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;
|
||||
|
@ -313,15 +316,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)
|
||||
{
|
||||
|
@ -332,28 +357,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,
|
||||
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
|
||||
|
@ -369,7 +394,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
|
||||
|
@ -385,7 +410,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*"));
|
||||
|
@ -394,11 +419,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);
|
||||
|
|
|
@ -46,12 +46,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");
|
||||
|
@ -63,13 +68,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;
|
||||
|
|
|
@ -192,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))
|
||||
{
|
||||
|
@ -227,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);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -60,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;
|
||||
|
@ -134,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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
@ -255,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');
|
||||
|
|
|
@ -74,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)
|
||||
|
|
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 ("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);
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
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)
|
||||
|
@ -41,7 +42,13 @@ 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)
|
||||
|
@ -122,6 +129,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
FOR_VIDEO_ADAPTERS (adapter)
|
||||
{
|
||||
struct grub_video_mode_info info;
|
||||
|
||||
grub_printf ("Adapter '%s':\n", adapter->name);
|
||||
|
||||
if (!adapter->iterate)
|
||||
|
@ -130,7 +139,17 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
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 ())
|
||||
{
|
||||
|
@ -145,6 +164,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
adapter->iterate (hook);
|
||||
|
||||
current_mode = NULL;
|
||||
|
||||
if (adapter->id != id)
|
||||
{
|
||||
if (adapter->fini ())
|
||||
|
|
|
@ -255,8 +255,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;
|
||||
}
|
||||
|
@ -288,6 +287,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;
|
||||
|
@ -340,20 +341,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;
|
||||
|
@ -423,8 +421,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;
|
||||
|
|
738
grub-core/disk/ahci.c
Normal file
738
grub-core/disk/ahci.c
Normal file
|
@ -0,0 +1,738 @@
|
|||
/*
|
||||
* 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;
|
||||
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->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 void *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);
|
||||
}
|
295
grub-core/disk/arc/arcdisk.c
Normal file
295
grub-core/disk/arc/arcdisk.c
Normal file
|
@ -0,0 +1,295 @@
|
|||
/* 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 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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
return grub_arc_iterate_devs (hook, 1);
|
||||
}
|
||||
|
||||
#define RAW_SUFFIX "partition(10)"
|
||||
|
||||
static grub_err_t
|
||||
reopen (const char *name)
|
||||
{
|
||||
grub_arc_fileno_t handle;
|
||||
|
||||
if (last_path && grub_strcmp (last_path, name) == 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (GRUB_ARC_FIRMWARE_VECTOR->open (name, 0, &handle))
|
||||
{
|
||||
grub_dprintf ("arcdisk", "couldn't open %s\n", name);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't open %s", name);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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 __attribute ((unused)),
|
||||
grub_disk_addr_t sector __attribute ((unused)),
|
||||
grub_size_t size __attribute ((unused)),
|
||||
const char *buf __attribute ((unused)))
|
||||
{
|
||||
return GRUB_ERR_NOT_IMPLEMENTED_YET;
|
||||
}
|
||||
|
||||
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,108 +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>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* 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;
|
||||
}
|
|
@ -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;
|
||||
|
@ -499,7 +454,8 @@ get_device (struct grub_efidisk_data *devices, int num)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efidisk_open (const char *name, struct grub_disk *disk)
|
||||
grub_efidisk_open (const char *name, struct grub_disk *disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
{
|
||||
int num;
|
||||
struct grub_efidisk_data *d = 0;
|
||||
|
@ -536,8 +492,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 +519,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 +545,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");
|
||||
|
@ -711,7 +668,35 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
|
|||
char *
|
||||
grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
||||
{
|
||||
grub_efi_device_path_t *dp, *ldp;
|
||||
grub_efi_device_path_t *dp, *ldp, *sdp;
|
||||
/* This is a hard disk partition. */
|
||||
grub_disk_t parent = 0;
|
||||
auto int find_parent_disk (const char *name);
|
||||
|
||||
/* 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 (grub_efi_compare_device_paths (d->device_path, sdp) == 0)
|
||||
{
|
||||
parent = disk;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dp = grub_efi_get_device_path (handle);
|
||||
if (! dp)
|
||||
|
@ -725,40 +710,12 @@ 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;
|
||||
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);
|
||||
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)
|
||||
|
@ -785,7 +742,11 @@ 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);
|
||||
sdp = dup_dp;
|
||||
|
||||
grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_NONE);
|
||||
if (!parent)
|
||||
grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_REMOVABLE);
|
||||
grub_free (dup_dp);
|
||||
|
||||
if (! parent)
|
||||
|
@ -793,19 +754,27 @@ 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;
|
||||
device_name = grub_strdup (parent->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *partition_name;
|
||||
|
||||
{
|
||||
char *partition_name = grub_partition_get_name (tpart);
|
||||
device_name = grub_xasprintf ("%s,%s", parent->name, partition_name);
|
||||
grub_free (partition_name);
|
||||
}
|
||||
grub_partition_iterate (parent, find_partition);
|
||||
|
||||
if (! tpart)
|
||||
{
|
||||
grub_disk_close (parent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
partition_name = grub_partition_get_name (tpart);
|
||||
device_name = grub_xasprintf ("%s,%s", parent->name, partition_name);
|
||||
grub_free (partition_name);
|
||||
}
|
||||
grub_disk_close (parent);
|
||||
|
||||
return device_name;
|
||||
|
@ -813,36 +782,17 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
|
|||
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;
|
||||
sdp = dp;
|
||||
|
||||
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);
|
||||
grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_NONE);
|
||||
if (!parent)
|
||||
grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_REMOVABLE);
|
||||
if (!parent)
|
||||
return NULL;
|
||||
device_name = grub_strdup (parent->name);
|
||||
grub_disk_close (parent);
|
||||
return device_name;
|
||||
}
|
||||
|
||||
|
|
|
@ -350,7 +350,8 @@ grub_biosdisk_open (const char *name, grub_disk_t disk,
|
|||
if ((cd_drive) && (drive == cd_drive))
|
||||
{
|
||||
data->flags = GRUB_BIOSDISK_FLAG_LBA | GRUB_BIOSDISK_FLAG_CDROM;
|
||||
data->sectors = 32;
|
||||
data->sectors = 8;
|
||||
disk->log_sector_size = 11;
|
||||
/* TODO: get the correct size. */
|
||||
total_sectors = GRUB_DISK_SIZE_UNKNOWN;
|
||||
}
|
||||
|
@ -359,6 +360,8 @@ grub_biosdisk_open (const char *name, grub_disk_t disk,
|
|||
/* HDD */
|
||||
int version;
|
||||
|
||||
disk->log_sector_size = 9;
|
||||
|
||||
version = grub_biosdisk_check_int13_extensions (drive);
|
||||
if (version)
|
||||
{
|
||||
|
@ -379,6 +382,15 @@ grub_biosdisk_open (const char *name, grub_disk_t disk,
|
|||
correctly but returns zero. So if it is zero, compute
|
||||
it by C/H/S returned by the LBA BIOS call. */
|
||||
total_sectors = drp->cylinders * drp->heads * drp->sectors;
|
||||
if (drp->bytes_per_sector
|
||||
&& !(drp->bytes_per_sector & (drp->bytes_per_sector - 1))
|
||||
&& drp->bytes_per_sector >= 512
|
||||
&& drp->bytes_per_sector <= 16384)
|
||||
{
|
||||
for (disk->log_sector_size = 0;
|
||||
(1 << disk->log_sector_size) < drp->bytes_per_sector;
|
||||
disk->log_sector_size++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +453,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
|
|||
|
||||
dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR
|
||||
+ (data->sectors
|
||||
<< GRUB_DISK_SECTOR_BITS));
|
||||
<< disk->log_sector_size));
|
||||
dap->length = sizeof (*dap);
|
||||
dap->reserved = 0;
|
||||
dap->blocks = size;
|
||||
|
@ -455,9 +467,6 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
|
|||
if (cmd)
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR, "can\'t write to cdrom");
|
||||
|
||||
dap->blocks = ALIGN_UP (dap->blocks, 4) >> 2;
|
||||
dap->block >>= 2;
|
||||
|
||||
for (i = 0; i < GRUB_BIOSDISK_CDROM_RETRY_COUNT; i++)
|
||||
if (! grub_biosdisk_rw_int13_extensions (0x42, data->drive, dap))
|
||||
break;
|
||||
|
@ -513,10 +522,12 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
|
|||
|
||||
/* Return the number of sectors which can be read safely at a time. */
|
||||
static grub_size_t
|
||||
get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors)
|
||||
get_safe_sectors (grub_disk_t disk, grub_disk_addr_t sector)
|
||||
{
|
||||
grub_size_t size;
|
||||
grub_uint32_t offset;
|
||||
grub_uint64_t offset;
|
||||
struct grub_biosdisk_data *data = disk->data;
|
||||
grub_uint32_t sectors = data->sectors;
|
||||
|
||||
/* OFFSET = SECTOR % SECTORS */
|
||||
grub_divmod64 (sector, sectors, &offset);
|
||||
|
@ -524,8 +535,8 @@ get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors)
|
|||
size = sectors - offset;
|
||||
|
||||
/* Limit the max to 0x7f because of Phoenix EDD. */
|
||||
if (size > 0x7f)
|
||||
size = 0x7f;
|
||||
if (size > ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size))
|
||||
size = ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -534,21 +545,11 @@ static grub_err_t
|
|||
grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
{
|
||||
struct grub_biosdisk_data *data = disk->data;
|
||||
|
||||
while (size)
|
||||
{
|
||||
grub_size_t len;
|
||||
grub_size_t cdoff = 0;
|
||||
|
||||
len = get_safe_sectors (sector, data->sectors);
|
||||
|
||||
if (data->flags & GRUB_BIOSDISK_FLAG_CDROM)
|
||||
{
|
||||
cdoff = (sector & 3) << GRUB_DISK_SECTOR_BITS;
|
||||
len = ALIGN_UP (sector + len, 4) - (sector & ~3);
|
||||
sector &= ~3;
|
||||
}
|
||||
len = get_safe_sectors (disk, sector);
|
||||
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
@ -557,9 +558,10 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
GRUB_MEMORY_MACHINE_SCRATCH_SEG))
|
||||
return grub_errno;
|
||||
|
||||
grub_memcpy (buf, (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + cdoff),
|
||||
len << GRUB_DISK_SECTOR_BITS);
|
||||
buf += len << GRUB_DISK_SECTOR_BITS;
|
||||
grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR,
|
||||
len << disk->log_sector_size);
|
||||
|
||||
buf += len << disk->log_sector_size;
|
||||
sector += len;
|
||||
size -= len;
|
||||
}
|
||||
|
@ -580,18 +582,18 @@ grub_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
{
|
||||
grub_size_t len;
|
||||
|
||||
len = get_safe_sectors (sector, data->sectors);
|
||||
len = get_safe_sectors (disk, sector);
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
||||
grub_memcpy ((void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf,
|
||||
len << GRUB_DISK_SECTOR_BITS);
|
||||
len << disk->log_sector_size);
|
||||
|
||||
if (grub_biosdisk_rw (GRUB_BIOSDISK_WRITE, disk, sector, len,
|
||||
GRUB_MEMORY_MACHINE_SCRATCH_SEG))
|
||||
return grub_errno;
|
||||
|
||||
buf += len << GRUB_DISK_SECTOR_BITS;
|
||||
buf += len << disk->log_sector_size;
|
||||
sector += len;
|
||||
size -= len;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ struct grub_nand_data
|
|||
};
|
||||
|
||||
static int
|
||||
grub_nand_iterate (int (*hook) (const char *name))
|
||||
grub_nand_iterate (int (*hook) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
auto int dev_iterate (struct grub_ieee1275_devalias *alias);
|
||||
int dev_iterate (struct grub_ieee1275_devalias *alias)
|
||||
|
@ -46,6 +47,9 @@ grub_nand_iterate (int (*hook) (const char *name))
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
return grub_devalias_iterate (dev_iterate);
|
||||
}
|
||||
|
||||
|
@ -54,7 +58,8 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
grub_size_t size, char *buf);
|
||||
|
||||
static grub_err_t
|
||||
grub_nand_open (const char *name, grub_disk_t disk)
|
||||
grub_nand_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
{
|
||||
grub_ieee1275_ihandle_t dev_ihandle = 0;
|
||||
struct grub_nand_data *data = 0;
|
||||
|
|
|
@ -152,9 +152,14 @@ scan (void)
|
|||
}
|
||||
|
||||
static int
|
||||
grub_ofdisk_iterate (int (*hook) (const char *name))
|
||||
grub_ofdisk_iterate (int (*hook) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
scan ();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (ofdisk_hash); i++)
|
||||
|
@ -228,7 +233,8 @@ compute_dev_path (const char *name)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
grub_ofdisk_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
{
|
||||
grub_ieee1275_phandle_t dev;
|
||||
char *devpath;
|
||||
|
@ -243,14 +249,24 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|||
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
|
||||
|
||||
if (grub_ieee1275_finddevice (devpath, &dev))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
|
||||
{
|
||||
grub_free (devpath);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"can't read device properties");
|
||||
}
|
||||
|
||||
if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
|
||||
&actual))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
|
||||
{
|
||||
grub_free (devpath);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
|
||||
}
|
||||
|
||||
if (grub_strcmp (prop, "block"))
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
|
||||
{
|
||||
grub_free (devpath);
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
|
||||
}
|
||||
|
||||
/* XXX: There is no property to read the number of blocks. There
|
||||
should be a property `#blocks', but it is not there. Perhaps it
|
||||
|
|
|
@ -304,9 +304,9 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector,
|
|||
/* This is a striped segment. We have to find the right PV
|
||||
similar to RAID0. */
|
||||
struct grub_lvm_node *stripe = seg->nodes;
|
||||
grub_uint32_t a, b;
|
||||
grub_uint64_t a, b;
|
||||
grub_uint64_t seg_offset; /* Offset of the segment in PV device. */
|
||||
unsigned int stripenr;
|
||||
grub_uint64_t stripenr;
|
||||
|
||||
offset = sector - ((grub_uint64_t) seg->start_extent
|
||||
* (grub_uint64_t) vg->extent_size);
|
||||
|
|
|
@ -221,10 +221,10 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
|
|||
return grub_errno;
|
||||
|
||||
uuid = (grub_uint32_t *) array->uuid;
|
||||
uuid[0] = sb.set_uuid0;
|
||||
uuid[1] = sb.set_uuid1;
|
||||
uuid[2] = sb.set_uuid2;
|
||||
uuid[3] = sb.set_uuid3;
|
||||
uuid[0] = grub_swap_bytes32 (sb.set_uuid0);
|
||||
uuid[1] = grub_swap_bytes32 (sb.set_uuid1);
|
||||
uuid[2] = grub_swap_bytes32 (sb.set_uuid2);
|
||||
uuid[3] = grub_swap_bytes32 (sb.set_uuid3);
|
||||
|
||||
*start_sector = 0;
|
||||
|
||||
|
|
534
grub-core/disk/pata.c
Normal file
534
grub-core/disk/pata.c
Normal file
|
@ -0,0 +1,534 @@
|
|||
/* 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/scsi.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/mm.h>
|
||||
#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS
|
||||
#include <grub/pci.h>
|
||||
#include <grub/cs5536.h>
|
||||
#else
|
||||
#define GRUB_MACHINE_PCI_IO_BASE 0xb4000000
|
||||
#endif
|
||||
#include <grub/time.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* At the moment, only two IDE ports are supported. */
|
||||
static const grub_port_t grub_pata_ioaddress[] = { GRUB_ATA_CH0_PORT1,
|
||||
GRUB_ATA_CH1_PORT1 };
|
||||
|
||||
struct grub_pata_device
|
||||
{
|
||||
/* IDE port to use. */
|
||||
int port;
|
||||
|
||||
/* IO addresses on which the registers for this device can be
|
||||
found. */
|
||||
grub_port_t ioaddress;
|
||||
|
||||
/* Two devices can be connected to a single cable. Use this field
|
||||
to select device 0 (commonly known as "master") or device 1
|
||||
(commonly known as "slave"). */
|
||||
int device;
|
||||
|
||||
int present;
|
||||
|
||||
struct grub_pata_device *next;
|
||||
};
|
||||
|
||||
static struct grub_pata_device *grub_pata_devices;
|
||||
|
||||
static inline void
|
||||
grub_pata_regset (struct grub_pata_device *dev, int reg, int val)
|
||||
{
|
||||
grub_outb (val, dev->ioaddress + reg);
|
||||
}
|
||||
|
||||
static inline grub_uint8_t
|
||||
grub_pata_regget (struct grub_pata_device *dev, int reg)
|
||||
{
|
||||
return grub_inb (dev->ioaddress + reg);
|
||||
}
|
||||
|
||||
/* Wait for !BSY. */
|
||||
static grub_err_t
|
||||
grub_pata_wait_not_busy (struct grub_pata_device *dev, int milliseconds)
|
||||
{
|
||||
/* ATA requires 400ns (after a write to CMD register) or
|
||||
1 PIO cycle (after a DRQ block transfer) before
|
||||
first check of BSY. */
|
||||
grub_millisleep (1);
|
||||
|
||||
int i = 1;
|
||||
grub_uint8_t sts;
|
||||
while ((sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS))
|
||||
& GRUB_ATA_STATUS_BUSY)
|
||||
{
|
||||
if (i >= milliseconds)
|
||||
{
|
||||
grub_dprintf ("pata", "timeout: %dms, status=0x%x\n",
|
||||
milliseconds, sts);
|
||||
return grub_error (GRUB_ERR_TIMEOUT, "PATA timeout");
|
||||
}
|
||||
|
||||
grub_millisleep (1);
|
||||
i++;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static inline grub_err_t
|
||||
grub_pata_check_ready (struct grub_pata_device *dev, int spinup)
|
||||
{
|
||||
if (grub_pata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY)
|
||||
return grub_pata_wait_not_busy (dev, spinup ? GRUB_ATA_TOUT_SPINUP
|
||||
: GRUB_ATA_TOUT_STD);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_pata_wait (void)
|
||||
{
|
||||
grub_millisleep (50);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pata_pio_read (struct grub_pata_device *dev, char *buf, grub_size_t size)
|
||||
{
|
||||
grub_uint16_t *buf16 = (grub_uint16_t *) buf;
|
||||
unsigned int i;
|
||||
|
||||
/* Read in the data, word by word. */
|
||||
for (i = 0; i < size / 2; i++)
|
||||
buf16[i] = grub_le_to_cpu16 (grub_inw(dev->ioaddress + GRUB_ATA_REG_DATA));
|
||||
if (size & 1)
|
||||
buf[size - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress
|
||||
+ GRUB_ATA_REG_DATA));
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pata_pio_write (struct grub_pata_device *dev, char *buf, grub_size_t size)
|
||||
{
|
||||
grub_uint16_t *buf16 = (grub_uint16_t *) buf;
|
||||
unsigned int i;
|
||||
|
||||
/* Write the data, word by word. */
|
||||
for (i = 0; i < size / 2; i++)
|
||||
grub_outw(grub_cpu_to_le16 (buf16[i]), dev->ioaddress + GRUB_ATA_REG_DATA);
|
||||
}
|
||||
|
||||
/* ATA pass through support, used by hdparm.mod. */
|
||||
static grub_err_t
|
||||
grub_pata_readwrite (struct grub_ata *disk,
|
||||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup)
|
||||
{
|
||||
struct grub_pata_device *dev = (struct grub_pata_device *) disk->data;
|
||||
grub_size_t nread = 0;
|
||||
int i;
|
||||
|
||||
if (! (parms->cmdsize == 0 || parms->cmdsize == 12))
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"ATAPI non-12 byte commands not supported");
|
||||
|
||||
grub_dprintf ("pata", "pata_pass_through: cmd=0x%x, features=0x%x, sectors=0x%x\n",
|
||||
parms->taskfile.cmd,
|
||||
parms->taskfile.features,
|
||||
parms->taskfile.sectors);
|
||||
grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%"
|
||||
PRIuGRUB_SIZE "\n",
|
||||
parms->taskfile.lba_high,
|
||||
parms->taskfile.lba_mid,
|
||||
parms->taskfile.lba_low, parms->size);
|
||||
|
||||
/* Set registers. */
|
||||
grub_pata_regset (dev, GRUB_ATA_REG_DISK, (dev->device << 4)
|
||||
| (parms->taskfile.disk & 0xef));
|
||||
if (grub_pata_check_ready (dev, spinup))
|
||||
return grub_errno;
|
||||
|
||||
for (i = GRUB_ATA_REG_SECTORS; i <= GRUB_ATA_REG_LBAHIGH; i++)
|
||||
grub_pata_regset (dev, i,
|
||||
parms->taskfile.raw[7 + (i - GRUB_ATA_REG_SECTORS)]);
|
||||
for (i = GRUB_ATA_REG_FEATURES; i <= GRUB_ATA_REG_LBAHIGH; i++)
|
||||
grub_pata_regset (dev, i, parms->taskfile.raw[i - GRUB_ATA_REG_FEATURES]);
|
||||
|
||||
/* Start command. */
|
||||
grub_pata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile.cmd);
|
||||
|
||||
/* Check status. */
|
||||
grub_int8_t sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS);
|
||||
grub_dprintf ("pata", "status=0x%x\n", sts);
|
||||
|
||||
if (parms->cmdsize)
|
||||
{
|
||||
grub_uint8_t irs;
|
||||
/* Wait for !BSY. */
|
||||
if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA))
|
||||
return grub_errno;
|
||||
|
||||
irs = grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON);
|
||||
/* OK if DRQ is asserted and interrupt reason is as expected. */
|
||||
if (!((sts & GRUB_ATA_STATUS_DRQ)
|
||||
&& (irs & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_CMD_OUT))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "ATAPI protocol error");
|
||||
/* Write the packet. */
|
||||
grub_pata_pio_write (dev, parms->cmd, parms->cmdsize);
|
||||
}
|
||||
|
||||
/* Transfer data. */
|
||||
while (nread < parms->size
|
||||
&& ((sts & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR))
|
||||
== GRUB_ATA_STATUS_DRQ)
|
||||
&& (!parms->cmdsize
|
||||
|| ((grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON)
|
||||
& GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_DATA_IN)))
|
||||
{
|
||||
unsigned cnt;
|
||||
|
||||
/* Wait for !BSY. */
|
||||
if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA))
|
||||
return grub_errno;
|
||||
|
||||
if (parms->cmdsize)
|
||||
{
|
||||
cnt = grub_pata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8
|
||||
| grub_pata_regget (dev, GRUB_ATAPI_REG_CNTLOW);
|
||||
grub_dprintf("pata", "DRQ count=%u\n", cnt);
|
||||
|
||||
/* Count of last transfer may be uneven. */
|
||||
if (! (0 < cnt && cnt <= parms->size - nread
|
||||
&& (! (cnt & 1) || cnt == parms->size - nread)))
|
||||
return grub_error (GRUB_ERR_READ_ERROR,
|
||||
"invalid ATAPI transfer count");
|
||||
}
|
||||
else
|
||||
cnt = GRUB_DISK_SECTOR_SIZE;
|
||||
if (cnt > parms->size - nread)
|
||||
cnt = parms->size - nread;
|
||||
|
||||
if (parms->write)
|
||||
grub_pata_pio_write (dev, (char *) parms->buffer + nread, cnt);
|
||||
else
|
||||
grub_pata_pio_read (dev, (char *) parms->buffer + nread, cnt);
|
||||
|
||||
nread += cnt;
|
||||
}
|
||||
if (parms->write)
|
||||
{
|
||||
/* Check for write error. */
|
||||
if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA))
|
||||
return grub_errno;
|
||||
|
||||
if (grub_pata_regget (dev, GRUB_ATA_REG_STATUS)
|
||||
& (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR))
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error");
|
||||
}
|
||||
parms->size = nread;
|
||||
|
||||
/* Wait for !BSY. */
|
||||
if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA))
|
||||
return grub_errno;
|
||||
|
||||
/* Return registers. */
|
||||
for (i = GRUB_ATA_REG_ERROR; i <= GRUB_ATA_REG_STATUS; i++)
|
||||
parms->taskfile.raw[i - GRUB_ATA_REG_FEATURES] = grub_pata_regget (dev, i);
|
||||
|
||||
grub_dprintf ("pata", "status=0x%x, error=0x%x, sectors=0x%x\n",
|
||||
parms->taskfile.status,
|
||||
parms->taskfile.error,
|
||||
parms->taskfile.sectors);
|
||||
|
||||
if (parms->taskfile.status
|
||||
& (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR))
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "PATA passthrough failed");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
check_device (struct grub_pata_device *dev)
|
||||
{
|
||||
grub_pata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4);
|
||||
grub_pata_wait ();
|
||||
|
||||
/* Try to detect if the port is in use by writing to it,
|
||||
waiting for a while and reading it again. If the value
|
||||
was preserved, there is a device connected. */
|
||||
grub_pata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A);
|
||||
grub_pata_wait ();
|
||||
grub_uint8_t sec = grub_pata_regget (dev, GRUB_ATA_REG_SECTORS);
|
||||
grub_dprintf ("ata", "sectors=0x%x\n", sec);
|
||||
if (sec != 0x5A)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no device connected");
|
||||
|
||||
/* The above test may detect a second (slave) device
|
||||
connected to a SATA controller which supports only one
|
||||
(master) device. It is not safe to use the status register
|
||||
READY bit to check for controller channel existence. Some
|
||||
ATAPI commands (RESET, DIAGNOSTIC) may clear this bit. */
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pata_device_initialize (int port, int device, int addr)
|
||||
{
|
||||
struct grub_pata_device *dev;
|
||||
struct grub_pata_device **devp;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dprintf ("pata", "detecting device %d,%d (0x%x)\n",
|
||||
port, device, addr);
|
||||
|
||||
dev = grub_malloc (sizeof(*dev));
|
||||
if (! dev)
|
||||
return grub_errno;
|
||||
|
||||
/* Setup the device information. */
|
||||
dev->port = port;
|
||||
dev->device = device;
|
||||
dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE;
|
||||
dev->present = 1;
|
||||
dev->next = NULL;
|
||||
|
||||
/* Register the device. */
|
||||
for (devp = &grub_pata_devices; *devp; devp = &(*devp)->next);
|
||||
*devp = dev;
|
||||
|
||||
err = check_device (dev);
|
||||
if (err)
|
||||
grub_print_error ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS
|
||||
static int NESTED_FUNC_ATTR
|
||||
grub_pata_pciinit (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid)
|
||||
{
|
||||
static int compat_use[2] = { 0 };
|
||||
grub_pci_address_t addr;
|
||||
grub_uint32_t class;
|
||||
grub_uint32_t bar1;
|
||||
grub_uint32_t bar2;
|
||||
int rega;
|
||||
int i;
|
||||
static int controller = 0;
|
||||
int cs5536 = 0;
|
||||
int nports = 2;
|
||||
|
||||
/* Read class. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class = grub_pci_read (addr);
|
||||
|
||||
/* AMD CS5536 Southbridge. */
|
||||
if (pciid == GRUB_CS5536_PCIID)
|
||||
{
|
||||
cs5536 = 1;
|
||||
nports = 1;
|
||||
}
|
||||
|
||||
/* Check if this class ID matches that of a PCI IDE Controller. */
|
||||
if (!cs5536 && (class >> 16 != 0x0101))
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < nports; i++)
|
||||
{
|
||||
/* Set to 0 when the channel operated in compatibility mode. */
|
||||
int compat;
|
||||
|
||||
/* We don't support non-compatibility mode for CS5536. */
|
||||
if (cs5536)
|
||||
compat = 0;
|
||||
else
|
||||
compat = (class >> (8 + 2 * i)) & 1;
|
||||
|
||||
rega = 0;
|
||||
|
||||
/* If the channel is in compatibility mode, just assign the
|
||||
default registers. */
|
||||
if (compat == 0 && !compat_use[i])
|
||||
{
|
||||
rega = grub_pata_ioaddress[i];
|
||||
compat_use[i] = 1;
|
||||
}
|
||||
else if (compat)
|
||||
{
|
||||
/* Read the BARs, which either contain a mmapped IO address
|
||||
or the IO port address. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES
|
||||
+ sizeof (grub_uint64_t) * i);
|
||||
bar1 = grub_pci_read (addr);
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES
|
||||
+ sizeof (grub_uint64_t) * i
|
||||
+ sizeof (grub_uint32_t));
|
||||
bar2 = grub_pci_read (addr);
|
||||
|
||||
/* Check if the BARs describe an IO region. */
|
||||
if ((bar1 & 1) && (bar2 & 1))
|
||||
{
|
||||
rega = bar1 & ~3;
|
||||
}
|
||||
}
|
||||
|
||||
grub_dprintf ("pata",
|
||||
"PCI dev (%d,%d,%d) compat=%d rega=0x%x\n",
|
||||
grub_pci_get_bus (dev), grub_pci_get_device (dev),
|
||||
grub_pci_get_function (dev), compat, rega);
|
||||
|
||||
if (rega)
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
grub_pata_device_initialize (controller * 2 + i, 0, rega);
|
||||
|
||||
/* Most errors raised by grub_ata_device_initialize() are harmless.
|
||||
They just indicate this particular drive is not responding, most
|
||||
likely because it doesn't exist. We might want to ignore specific
|
||||
error types here, instead of printing them. */
|
||||
if (grub_errno)
|
||||
{
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_pata_device_initialize (controller * 2 + i, 1, rega);
|
||||
|
||||
/* Likewise. */
|
||||
if (grub_errno)
|
||||
{
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
controller++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pata_initialize (void)
|
||||
{
|
||||
grub_pci_iterate (grub_pata_pciinit);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static grub_err_t
|
||||
grub_pata_initialize (void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
grub_pata_device_initialize (i, 0, grub_pata_ioaddress[i]);
|
||||
grub_pata_device_initialize (i, 1, grub_pata_ioaddress[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static grub_err_t
|
||||
grub_pata_open (int id, int devnum, struct grub_ata *ata)
|
||||
{
|
||||
struct grub_pata_device *dev;
|
||||
struct grub_pata_device *devfnd = 0;
|
||||
grub_err_t err;
|
||||
|
||||
if (id != GRUB_SCSI_SUBSYSTEM_PATA)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a PATA device");
|
||||
|
||||
for (dev = grub_pata_devices; dev; dev = dev->next)
|
||||
{
|
||||
if (dev->port * 2 + dev->device == devnum)
|
||||
{
|
||||
devfnd = dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
grub_dprintf ("pata", "opening PATA dev `ata%d'\n", devnum);
|
||||
|
||||
if (! devfnd)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such PATA device");
|
||||
|
||||
err = check_device (devfnd);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
ata->data = devfnd;
|
||||
ata->dma = 0;
|
||||
ata->present = &devfnd->present;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_pata_iterate (int (*hook) (int id, int bus),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
struct grub_pata_device *dev;
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
for (dev = grub_pata_devices; dev; dev = dev->next)
|
||||
if (hook (GRUB_SCSI_SUBSYSTEM_PATA, dev->port * 2 + dev->device))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct grub_ata_dev grub_pata_dev =
|
||||
{
|
||||
.iterate = grub_pata_iterate,
|
||||
.open = grub_pata_open,
|
||||
.readwrite = grub_pata_readwrite,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
GRUB_MOD_INIT(ata_pthru)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* ATA initialization. */
|
||||
grub_pata_initialize ();
|
||||
|
||||
grub_ata_dev_register (&grub_pata_dev);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(ata_pthru)
|
||||
{
|
||||
grub_ata_dev_unregister (&grub_pata_dev);
|
||||
}
|
|
@ -358,7 +358,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
case 10:
|
||||
{
|
||||
grub_disk_addr_t read_sector, far_ofs;
|
||||
grub_uint32_t disknr, b, near, far, ofs;
|
||||
grub_uint64_t disknr, b, near, far, ofs;
|
||||
|
||||
read_sector = grub_divmod64 (sector, array->chunk_size, &b);
|
||||
far = ofs = near = 1;
|
||||
|
@ -464,7 +464,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
case 6:
|
||||
{
|
||||
grub_disk_addr_t read_sector;
|
||||
grub_uint32_t b, p, n, disknr, e;
|
||||
grub_uint64_t b, p, n, disknr, e;
|
||||
|
||||
/* n = 1 for level 4 and 5, 2 for level 6. */
|
||||
n = array->level / 3;
|
||||
|
@ -795,6 +795,49 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
|||
scanner_name);
|
||||
#endif
|
||||
|
||||
{
|
||||
int max_used_number = 0, len, need_new_name = 0;
|
||||
int add_us = 0;
|
||||
len = grub_strlen (array->name);
|
||||
if (len && grub_isdigit (array->name[len-1]))
|
||||
add_us = 1;
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
{
|
||||
int cur_num;
|
||||
char *num, *end;
|
||||
if (grub_strncmp (p->name, array->name, len) != 0)
|
||||
continue;
|
||||
if (p->name[len] == 0)
|
||||
{
|
||||
need_new_name = 1;
|
||||
continue;
|
||||
}
|
||||
if (add_us && p->name[len] != '_')
|
||||
continue;
|
||||
if (add_us)
|
||||
num = p->name + len + 1;
|
||||
else
|
||||
num = p->name + len;
|
||||
if (!grub_isdigit (num[0]))
|
||||
continue;
|
||||
cur_num = grub_strtoull (num, &end, 10);
|
||||
if (end[0])
|
||||
continue;
|
||||
if (cur_num > max_used_number)
|
||||
max_used_number = cur_num;
|
||||
}
|
||||
if (need_new_name)
|
||||
{
|
||||
char *tmp;
|
||||
tmp = grub_xasprintf ("%s%s%d", array->name, add_us ? "_" : "",
|
||||
max_used_number + 1);
|
||||
if (!tmp)
|
||||
return grub_errno;
|
||||
grub_free (array->name);
|
||||
array->name = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add our new array to the list. */
|
||||
array->next = array_list;
|
||||
array_list = array;
|
||||
|
|
|
@ -32,6 +32,12 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|||
|
||||
static grub_scsi_dev_t grub_scsi_dev_list;
|
||||
|
||||
const char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5] = {
|
||||
[GRUB_SCSI_SUBSYSTEM_USBMS] = "usb",
|
||||
[GRUB_SCSI_SUBSYSTEM_PATA] = "ata",
|
||||
[GRUB_SCSI_SUBSYSTEM_AHCI] = "ahci"
|
||||
};
|
||||
|
||||
void
|
||||
grub_scsi_dev_register (grub_scsi_dev_t dev)
|
||||
{
|
||||
|
@ -321,9 +327,9 @@ grub_scsi_iterate (int (*hook) (const char *name),
|
|||
{
|
||||
grub_scsi_dev_t p;
|
||||
|
||||
auto int scsi_iterate (int bus, int luns);
|
||||
auto int NESTED_FUNC_ATTR scsi_iterate (int id, int bus, int luns);
|
||||
|
||||
int scsi_iterate (int bus, int luns)
|
||||
int NESTED_FUNC_ATTR scsi_iterate (int id, int bus, int luns)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -332,7 +338,7 @@ grub_scsi_iterate (int (*hook) (const char *name),
|
|||
{
|
||||
char *sname;
|
||||
int ret;
|
||||
sname = grub_xasprintf ("%s%d", p->name, bus);
|
||||
sname = grub_xasprintf ("%s%d", grub_scsi_names[id], bus);
|
||||
if (!sname)
|
||||
return 1;
|
||||
ret = hook (sname);
|
||||
|
@ -346,7 +352,7 @@ grub_scsi_iterate (int (*hook) (const char *name),
|
|||
{
|
||||
char *sname;
|
||||
int ret;
|
||||
sname = grub_xasprintf ("%s%d%c", p->name, bus, 'a' + i);
|
||||
sname = grub_xasprintf ("%s%d%c", grub_scsi_names[id], bus, 'a' + i);
|
||||
if (!sname)
|
||||
return 1;
|
||||
ret = hook (sname);
|
||||
|
@ -357,11 +363,8 @@ grub_scsi_iterate (int (*hook) (const char *name),
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
for (p = grub_scsi_dev_list; p; p = p->next)
|
||||
if (p->iterate && (p->iterate) (scsi_iterate))
|
||||
if (p->iterate && (p->iterate) (scsi_iterate, pull))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -377,6 +380,7 @@ grub_scsi_open (const char *name, grub_disk_t disk,
|
|||
int lun, bus;
|
||||
grub_uint64_t maxtime;
|
||||
const char *nameend;
|
||||
unsigned id;
|
||||
|
||||
nameend = name + grub_strlen (name) - 1;
|
||||
/* Try to detect a LUN ('a'-'z'), otherwise just use the first
|
||||
|
@ -401,15 +405,25 @@ grub_scsi_open (const char *name, grub_disk_t disk,
|
|||
if (! scsi)
|
||||
return grub_errno;
|
||||
|
||||
for (id = 0; id < ARRAY_SIZE (grub_scsi_names); id++)
|
||||
if (grub_strncmp (grub_scsi_names[id], name, nameend - name) == 0)
|
||||
break;
|
||||
|
||||
if (id == ARRAY_SIZE (grub_scsi_names))
|
||||
{
|
||||
grub_free (scsi);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a SCSI disk");
|
||||
}
|
||||
|
||||
for (p = grub_scsi_dev_list; p; p = p->next)
|
||||
{
|
||||
if (grub_strncmp (p->name, name, nameend - name) != 0)
|
||||
continue;
|
||||
if (p->open (id, bus, scsi))
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p->open (bus, scsi))
|
||||
continue;
|
||||
|
||||
disk->id = grub_make_scsi_id (p->id, bus, lun);
|
||||
disk->id = grub_make_scsi_id (id, bus, lun);
|
||||
disk->data = scsi;
|
||||
scsi->dev = p;
|
||||
scsi->lun = lun;
|
||||
|
@ -470,22 +484,26 @@ grub_scsi_open (const char *name, grub_disk_t disk,
|
|||
return err;
|
||||
}
|
||||
|
||||
/* SCSI blocks can be something else than 512, although GRUB
|
||||
wants 512 byte blocks. */
|
||||
disk->total_sectors = ((grub_uint64_t)scsi->size
|
||||
* (grub_uint64_t)scsi->blocksize)
|
||||
>> GRUB_DISK_SECTOR_BITS;
|
||||
disk->total_sectors = scsi->size;
|
||||
if (scsi->blocksize & (scsi->blocksize - 1) || !scsi->blocksize)
|
||||
{
|
||||
grub_free (scsi);
|
||||
return grub_error (GRUB_ERR_IO, "invalid sector size %d",
|
||||
scsi->blocksize);
|
||||
}
|
||||
for (disk->log_sector_size = 0;
|
||||
(1 << disk->log_sector_size) < scsi->blocksize;
|
||||
disk->log_sector_size++);
|
||||
|
||||
grub_dprintf ("scsi", "blocks=%u, blocksize=%u\n",
|
||||
scsi->size, scsi->blocksize);
|
||||
grub_dprintf ("scsi", "Disk total 512 sectors = %llu\n",
|
||||
grub_dprintf ("scsi", "Disk total sectors = %llu\n",
|
||||
(unsigned long long) disk->total_sectors);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_free (scsi);
|
||||
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a SCSI disk");
|
||||
}
|
||||
|
||||
|
@ -508,36 +526,36 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
|
||||
scsi = disk->data;
|
||||
|
||||
/* SCSI sectors are variable in size. GRUB uses 512 byte
|
||||
sectors. */
|
||||
if (scsi->blocksize != GRUB_DISK_SECTOR_SIZE)
|
||||
while (size)
|
||||
{
|
||||
unsigned spb = scsi->blocksize >> GRUB_DISK_SECTOR_BITS;
|
||||
if (spb == 0 || (scsi->blocksize & (GRUB_DISK_SECTOR_SIZE - 1)) != 0)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported SCSI block size");
|
||||
/* PATA doesn't support more than 32K reads.
|
||||
Not sure about AHCI and USB. If it's confirmed that either of
|
||||
them can do bigger reads reliably this value can be moved to 'scsi'
|
||||
structure. */
|
||||
grub_size_t len = 32768 >> disk->log_sector_size;
|
||||
grub_err_t err;
|
||||
if (len > size)
|
||||
len = size;
|
||||
/* Depending on the type, select a read function. */
|
||||
switch (scsi->devtype)
|
||||
{
|
||||
case grub_scsi_devtype_direct:
|
||||
err = grub_scsi_read10 (disk, sector, len, buf);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
|
||||
grub_uint32_t sector_mod = 0;
|
||||
sector = grub_divmod64 (sector, spb, §or_mod);
|
||||
|
||||
if (! (sector_mod == 0 && size % spb == 0))
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unaligned SCSI read not supported");
|
||||
|
||||
size /= spb;
|
||||
case grub_scsi_devtype_cdrom:
|
||||
err = grub_scsi_read12 (disk, sector, len, buf);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
}
|
||||
size -= len;
|
||||
sector += len;
|
||||
buf += len << disk->log_sector_size;
|
||||
}
|
||||
|
||||
/* Depending on the type, select a read function. */
|
||||
switch (scsi->devtype)
|
||||
{
|
||||
case grub_scsi_devtype_direct:
|
||||
return grub_scsi_read10 (disk, sector, size, buf);
|
||||
|
||||
case grub_scsi_devtype_cdrom:
|
||||
return grub_scsi_read12 (disk, sector, size, buf);
|
||||
}
|
||||
|
||||
/* XXX: Never reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
#if 0 /* Workaround - it works - but very slowly, from some reason
|
||||
|
|
|
@ -211,16 +211,20 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
|||
|
||||
|
||||
static int
|
||||
grub_usbms_iterate (int (*hook) (int bus, int luns))
|
||||
grub_usbms_iterate (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
grub_usb_poll_devices ();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
|
||||
if (grub_usbms_devices[i])
|
||||
{
|
||||
if (hook (i, grub_usbms_devices[i]->luns))
|
||||
if (hook (GRUB_SCSI_SUBSYSTEM_USBMS, i, grub_usbms_devices[i]->luns))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -390,8 +394,12 @@ grub_usbms_write (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_usbms_open (int devnum, struct grub_scsi *scsi)
|
||||
grub_usbms_open (int id, int devnum, struct grub_scsi *scsi)
|
||||
{
|
||||
if (id != GRUB_SCSI_SUBSYSTEM_USBMS)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"not USB Mass Storage device");
|
||||
|
||||
grub_usb_poll_devices ();
|
||||
|
||||
if (!grub_usbms_devices[devnum])
|
||||
|
@ -406,8 +414,6 @@ grub_usbms_open (int devnum, struct grub_scsi *scsi)
|
|||
|
||||
static struct grub_scsi_dev grub_usbms_dev =
|
||||
{
|
||||
.name = "usb",
|
||||
.id = GRUB_SCSI_SUBSYSTEM_USBMS,
|
||||
.iterate = grub_usbms_iterate,
|
||||
.open = grub_usbms_open,
|
||||
.read = grub_usbms_read,
|
||||
|
|
|
@ -193,7 +193,7 @@ grub_efiemu_load_file (const char *filename)
|
|||
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return 0;
|
||||
return grub_errno;
|
||||
|
||||
err = grub_efiemu_mm_init ();
|
||||
if (err)
|
||||
|
|
|
@ -316,10 +316,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
|
|||
return 1;
|
||||
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
|
||||
if (!font->bmp_idx)
|
||||
{
|
||||
grub_free (font->char_index);
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));
|
||||
|
||||
|
||||
|
@ -494,7 +491,7 @@ grub_font_load (const char *filename)
|
|||
#endif
|
||||
|
||||
/* Allocate the font object. */
|
||||
font = (grub_font_t) grub_malloc (sizeof (struct grub_font));
|
||||
font = (grub_font_t) grub_zalloc (sizeof (struct grub_font));
|
||||
if (!font)
|
||||
goto fail;
|
||||
|
||||
|
@ -640,6 +637,11 @@ grub_font_load (const char *filename)
|
|||
return 0;
|
||||
|
||||
fail:
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
if (font)
|
||||
font->file = 0;
|
||||
|
||||
free_font (font);
|
||||
return 1;
|
||||
}
|
||||
|
@ -799,6 +801,7 @@ free_font (grub_font_t font)
|
|||
grub_free (font->name);
|
||||
grub_free (font->family);
|
||||
grub_free (font->char_index);
|
||||
grub_free (font->bmp_idx);
|
||||
grub_free (font);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,11 @@ loadfont_command (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
while (argc--)
|
||||
if (grub_font_load (*args++) != 0)
|
||||
return GRUB_ERR_BAD_FONT;
|
||||
{
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_FONT, "invalid font");
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -52,12 +52,20 @@ struct grub_affs_rblock
|
|||
grub_uint32_t hashtable[1];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_affs_time
|
||||
{
|
||||
grub_int32_t day;
|
||||
grub_uint32_t min;
|
||||
grub_uint32_t hz;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* The second part of a file header block. */
|
||||
struct grub_affs_file
|
||||
{
|
||||
grub_uint8_t unused1[12];
|
||||
grub_uint32_t size;
|
||||
grub_uint8_t unused2[104];
|
||||
grub_uint8_t unused2[92];
|
||||
struct grub_affs_time mtime;
|
||||
grub_uint8_t namelen;
|
||||
grub_uint8_t name[30];
|
||||
grub_uint8_t unused3[33];
|
||||
|
@ -87,9 +95,9 @@ struct grub_affs_file
|
|||
struct grub_fshelp_node
|
||||
{
|
||||
struct grub_affs_data *data;
|
||||
int block;
|
||||
int size;
|
||||
int parent;
|
||||
grub_disk_addr_t block;
|
||||
struct grub_fshelp_node *parent;
|
||||
struct grub_affs_file di;
|
||||
};
|
||||
|
||||
/* Information about a "mounted" affs filesystem. */
|
||||
|
@ -117,7 +125,7 @@ grub_affs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
int block = node->block;
|
||||
struct grub_affs_file file;
|
||||
struct grub_affs_data *data = node->data;
|
||||
grub_uint32_t mod;
|
||||
grub_uint64_t mod;
|
||||
|
||||
/* Find the block that points to the fileblock we are looking up by
|
||||
following the chain until the right table is reached. */
|
||||
|
@ -156,7 +164,7 @@ grub_affs_read_file (grub_fshelp_node_t node,
|
|||
{
|
||||
return grub_fshelp_read_file (node->data->disk, node, read_hook,
|
||||
pos, len, buf, grub_affs_read_block,
|
||||
node->size, 0);
|
||||
grub_be_to_cpu32 (node->di.size), 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,7 +176,6 @@ grub_affs_mount (grub_disk_t disk)
|
|||
struct grub_affs_rblock *rblock;
|
||||
|
||||
int checksum = 0;
|
||||
int checksumr = 0;
|
||||
int blocksize = 0;
|
||||
|
||||
data = grub_malloc (sizeof (struct grub_affs_data));
|
||||
|
@ -218,8 +225,6 @@ grub_affs_mount (grub_disk_t disk)
|
|||
/* The filesystem blocksize is not stored anywhere in the filesystem
|
||||
itself. One way to determine it is reading blocks for the
|
||||
rootblock until the checksum is correct. */
|
||||
checksumr = grub_be_to_cpu32 (rblock->checksum);
|
||||
rblock->checksum = 0;
|
||||
for (blocksize = 0; blocksize < 8; blocksize++)
|
||||
{
|
||||
grub_uint32_t *currblock = rootblock + GRUB_DISK_SECTOR_SIZE * blocksize;
|
||||
|
@ -228,10 +233,10 @@ grub_affs_mount (grub_disk_t disk)
|
|||
for (i = 0; i < GRUB_DISK_SECTOR_SIZE / sizeof (*currblock); i++)
|
||||
checksum += grub_be_to_cpu32 (currblock[i]);
|
||||
|
||||
if (checksumr == -checksum)
|
||||
if (checksum == 0)
|
||||
break;
|
||||
}
|
||||
if (-checksum != checksumr)
|
||||
if (checksum != 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "AFFS blocksize couldn't be determined");
|
||||
goto fail;
|
||||
|
@ -243,6 +248,8 @@ grub_affs_mount (grub_disk_t disk)
|
|||
data->htsize = grub_be_to_cpu32 (rblock->htsize);
|
||||
data->diropen.data = data;
|
||||
data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock);
|
||||
data->diropen.parent = NULL;
|
||||
grub_memcpy (&data->diropen.di, rootblock, sizeof (data->diropen.di));
|
||||
|
||||
grub_free (rootblock);
|
||||
|
||||
|
@ -293,12 +300,15 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
struct grub_affs_data *data = dir->data;
|
||||
grub_uint32_t *hashtable;
|
||||
|
||||
auto int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, int block,
|
||||
int size, int type);
|
||||
auto int NESTED_FUNC_ATTR grub_affs_create_node (const char *name,
|
||||
grub_disk_addr_t block,
|
||||
const struct grub_affs_file *fil);
|
||||
|
||||
int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, int block,
|
||||
int size, int type)
|
||||
int NESTED_FUNC_ATTR grub_affs_create_node (const char *name,
|
||||
grub_disk_addr_t block,
|
||||
const struct grub_affs_file *fil)
|
||||
{
|
||||
int type;
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
{
|
||||
|
@ -306,10 +316,19 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
return 1;
|
||||
}
|
||||
|
||||
if ((int) grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_DIR)
|
||||
type = GRUB_FSHELP_REG;
|
||||
else if (grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_REG)
|
||||
type = GRUB_FSHELP_DIR;
|
||||
else if (grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_SYMLINK)
|
||||
type = GRUB_FSHELP_SYMLINK;
|
||||
else
|
||||
type = GRUB_FSHELP_UNKNOWN;
|
||||
|
||||
node->data = data;
|
||||
node->size = size;
|
||||
node->block = block;
|
||||
node->parent = grub_be_to_cpu32 (file.parent);
|
||||
node->di = *fil;
|
||||
node->parent = dir;
|
||||
|
||||
if (hook (name, type, node))
|
||||
{
|
||||
|
@ -319,6 +338,24 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Create the directory entries for `.' and `..'. */
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
return 1;
|
||||
|
||||
*node = *dir;
|
||||
if (hook (".", GRUB_FSHELP_DIR, node))
|
||||
return 1;
|
||||
if (dir->parent)
|
||||
{
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
return 1;
|
||||
*node = *dir->parent;
|
||||
if (hook ("..", GRUB_FSHELP_DIR, node))
|
||||
return 1;
|
||||
}
|
||||
|
||||
hashtable = grub_malloc (data->htsize * sizeof (*hashtable));
|
||||
if (!hashtable)
|
||||
return 1;
|
||||
|
@ -328,16 +365,8 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
/* Create the directory entries for `.' and `..'. */
|
||||
if (grub_affs_create_node (".", dir->block, dir->size, GRUB_FSHELP_DIR))
|
||||
return 1;
|
||||
if (grub_affs_create_node ("..", dir->parent ? dir->parent : dir->block,
|
||||
dir->size, GRUB_FSHELP_DIR))
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < data->htsize; i++)
|
||||
{
|
||||
enum grub_fshelp_filetype type;
|
||||
grub_uint64_t next;
|
||||
|
||||
if (!hashtable[i])
|
||||
|
@ -358,17 +387,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
|
||||
file.name[file.namelen] = '\0';
|
||||
|
||||
if ((int) grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_DIR)
|
||||
type = GRUB_FSHELP_REG;
|
||||
else if (grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_REG)
|
||||
type = GRUB_FSHELP_DIR;
|
||||
else if (grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_SYMLINK)
|
||||
type = GRUB_FSHELP_SYMLINK;
|
||||
else
|
||||
type = GRUB_FSHELP_UNKNOWN;
|
||||
|
||||
if (grub_affs_create_node ((char *) (file.name), next,
|
||||
grub_be_to_cpu32 (file.size), type))
|
||||
if (grub_affs_create_node ((char *) (file.name), next, &file))
|
||||
return 1;
|
||||
|
||||
next = grub_be_to_cpu32 (file.next);
|
||||
|
@ -403,7 +422,7 @@ grub_affs_open (struct grub_file *file, const char *name)
|
|||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
file->size = fdiro->size;
|
||||
file->size = grub_be_to_cpu32 (fdiro->di.size);
|
||||
data->diropen = *fdiro;
|
||||
grub_free (fdiro);
|
||||
|
||||
|
@ -467,6 +486,11 @@ grub_affs_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_be_to_cpu32 (node->di.mtime.day) * 86400
|
||||
+ grub_be_to_cpu32 (node->di.mtime.min) * 60
|
||||
+ grub_be_to_cpu32 (node->di.mtime.hz) / 50
|
||||
+ 8 * 365 * 86400 + 86400 * 2;
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
|
|
@ -589,10 +589,14 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
struct grub_btrfs_key *key;
|
||||
struct grub_btrfs_chunk_item *chunk;
|
||||
grub_uint64_t csize;
|
||||
grub_err_t err;
|
||||
grub_err_t err = 0;
|
||||
struct grub_btrfs_key key_out;
|
||||
int challoc = 0;
|
||||
grub_device_t dev;
|
||||
struct grub_btrfs_key key_in;
|
||||
grub_size_t chsize;
|
||||
grub_disk_addr_t chaddr;
|
||||
|
||||
grub_dprintf ("btrfs", "searching for laddr %" PRIxGRUB_UINT64_T "\n",
|
||||
addr);
|
||||
for (ptr = data->sblock.bootstrap_mapping;
|
||||
|
@ -616,9 +620,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
+ sizeof (struct grub_btrfs_chunk_stripe)
|
||||
* grub_le_to_cpu16 (chunk->nstripes);
|
||||
}
|
||||
struct grub_btrfs_key key_in;
|
||||
grub_size_t chsize;
|
||||
grub_disk_addr_t chaddr;
|
||||
|
||||
key_in.object_id = GRUB_BTRFS_OBJECT_ID_CHUNK;
|
||||
key_in.type = GRUB_BTRFS_ITEM_TYPE_CHUNK;
|
||||
key_in.offset = addr;
|
||||
|
@ -647,7 +649,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
|
||||
chunk_found:
|
||||
{
|
||||
grub_uint32_t stripen;
|
||||
grub_uint64_t stripen;
|
||||
grub_uint64_t stripe_offset;
|
||||
grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset);
|
||||
unsigned redundancy = 1;
|
||||
|
@ -677,10 +679,10 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_uint64_t stripe_length;
|
||||
grub_dprintf ("btrfs", "single\n");
|
||||
stripe_length = grub_divmod64_full (grub_le_to_cpu64 (chunk->size),
|
||||
grub_le_to_cpu16 (chunk->nstripes),
|
||||
NULL);
|
||||
stripen = grub_divmod64_full (off, stripe_length, &stripe_offset);
|
||||
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
|
||||
grub_le_to_cpu16 (chunk->nstripes),
|
||||
NULL);
|
||||
stripen = grub_divmod64 (off, stripe_length, &stripe_offset);
|
||||
csize = (stripen + 1) * stripe_length - off;
|
||||
break;
|
||||
}
|
||||
|
@ -697,7 +699,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
case GRUB_BTRFS_CHUNK_TYPE_RAID0:
|
||||
{
|
||||
grub_uint64_t middle, high;
|
||||
grub_uint32_t low;
|
||||
grub_uint64_t low;
|
||||
grub_dprintf ("btrfs", "RAID0\n");
|
||||
middle = grub_divmod64 (off,
|
||||
grub_le_to_cpu64 (chunk->stripe_length),
|
||||
|
@ -713,7 +715,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
case GRUB_BTRFS_CHUNK_TYPE_RAID10:
|
||||
{
|
||||
grub_uint64_t middle, high;
|
||||
grub_uint32_t low;
|
||||
grub_uint64_t low;
|
||||
middle = grub_divmod64 (off,
|
||||
grub_le_to_cpu64 (chunk->stripe_length),
|
||||
&low);
|
||||
|
@ -758,7 +760,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
|
||||
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
||||
"+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %"
|
||||
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT32_T
|
||||
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
|
||||
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
||||
grub_le_to_cpu64 (key->offset),
|
||||
grub_le_to_cpu64 (chunk->size),
|
||||
|
@ -1052,6 +1054,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
const char *ctoken;
|
||||
grub_size_t ctokenlen;
|
||||
char *path_alloc = NULL;
|
||||
char *origpath = NULL;
|
||||
unsigned symlinks_max = 32;
|
||||
|
||||
*type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
||||
|
@ -1060,6 +1063,9 @@ find_path (struct grub_btrfs_data *data,
|
|||
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
||||
key->offset = 0;
|
||||
skip_default = 1;
|
||||
origpath = grub_strdup (path);
|
||||
if (!origpath)
|
||||
return grub_errno;
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -1084,6 +1090,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
||||
{
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||
}
|
||||
|
||||
|
@ -1096,13 +1103,16 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
if (key_cmp (key, &key_out) != 0)
|
||||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
|
||||
struct grub_btrfs_dir_item *cdirel;
|
||||
|
@ -1114,6 +1124,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
if (!direl)
|
||||
{
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return grub_errno;
|
||||
}
|
||||
}
|
||||
|
@ -1123,6 +1134,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1154,9 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!skip_default)
|
||||
|
@ -1156,6 +1170,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return grub_error (GRUB_ERR_SYMLINK_LOOP,
|
||||
"too deep nesting of symlinks");
|
||||
}
|
||||
|
@ -1166,6 +1181,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
tmp = grub_malloc (grub_le_to_cpu64 (inode.size)
|
||||
|
@ -1174,6 +1190,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -1184,12 +1201,14 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
grub_free (tmp);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path,
|
||||
grub_strlen (path) + 1);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
path = path_alloc = tmp;
|
||||
if (path[0] == '/')
|
||||
{
|
||||
|
@ -1216,6 +1235,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
if (cdirel->key.object_id != key_out.object_id
|
||||
|
@ -1223,7 +1243,9 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
err = grub_btrfs_read_logical (data, elemaddr,
|
||||
&ri, sizeof (ri));
|
||||
|
@ -1231,6 +1253,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
||||
|
@ -1244,7 +1267,9 @@ find_path (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_free (direl);
|
||||
grub_free (path_alloc);
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
grub_free (origpath);
|
||||
return err;
|
||||
}
|
||||
*key = cdirel->key;
|
||||
if (*type == GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
||||
|
@ -1252,6 +1277,7 @@ find_path (struct grub_btrfs_data *data,
|
|||
break;
|
||||
default:
|
||||
grub_free (path_alloc);
|
||||
grub_free (origpath);
|
||||
grub_free (direl);
|
||||
return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x",
|
||||
cdirel->key.type);
|
||||
|
|
|
@ -80,7 +80,7 @@ static grub_dl_t my_mod;
|
|||
|
||||
static grub_err_t
|
||||
grub_cpio_find_file (struct grub_cpio_data *data, char **name,
|
||||
grub_uint32_t * ofs)
|
||||
grub_int32_t *mtime, grub_uint32_t * ofs)
|
||||
{
|
||||
#ifndef MODE_USTAR
|
||||
struct head hd;
|
||||
|
@ -93,6 +93,8 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
|
|||
return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive");
|
||||
|
||||
data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2;
|
||||
if (mtime)
|
||||
*mtime = (((grub_uint32_t) hd.mtime_1) << 16) + hd.mtime_2;
|
||||
|
||||
if (hd.namesize & 1)
|
||||
hd.namesize++;
|
||||
|
@ -141,6 +143,8 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
|
|||
data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
|
||||
*ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
|
||||
~(GRUB_DISK_SECTOR_SIZE - 1));
|
||||
if (mtime)
|
||||
*mtime = grub_strtoul (hd.mtime, NULL, 8);
|
||||
#endif
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
@ -206,7 +210,9 @@ grub_cpio_dir (grub_device_t device, const char *path,
|
|||
data->hofs = 0;
|
||||
while (1)
|
||||
{
|
||||
if (grub_cpio_find_file (data, &name, &ofs))
|
||||
grub_int32_t mtime;
|
||||
|
||||
if (grub_cpio_find_file (data, &name, &mtime, &ofs))
|
||||
goto fail;
|
||||
|
||||
if (!ofs)
|
||||
|
@ -229,10 +235,11 @@ grub_cpio_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = (p != NULL);
|
||||
info.mtime = mtime;
|
||||
info.mtimeset = 1;
|
||||
|
||||
hook (name + len, &info);
|
||||
if (prev)
|
||||
grub_free (prev);
|
||||
grub_free (prev);
|
||||
prev = name;
|
||||
}
|
||||
else
|
||||
|
@ -243,11 +250,8 @@ grub_cpio_dir (grub_device_t device, const char *path,
|
|||
|
||||
fail:
|
||||
|
||||
if (prev)
|
||||
grub_free (prev);
|
||||
|
||||
if (data)
|
||||
grub_free (data);
|
||||
grub_free (prev);
|
||||
grub_free (data);
|
||||
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
|
@ -271,7 +275,7 @@ grub_cpio_open (grub_file_t file, const char *name)
|
|||
data->hofs = 0;
|
||||
while (1)
|
||||
{
|
||||
if (grub_cpio_find_file (data, &fn, &ofs))
|
||||
if (grub_cpio_find_file (data, &fn, NULL, &ofs))
|
||||
goto fail;
|
||||
|
||||
if (!ofs)
|
||||
|
@ -318,8 +322,7 @@ grub_cpio_open (grub_file_t file, const char *name)
|
|||
|
||||
fail:
|
||||
|
||||
if (data)
|
||||
grub_free (data);
|
||||
grub_free (data);
|
||||
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/fat.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -51,52 +52,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|||
| GRUB_FAT_ATTR_ARCHIVE \
|
||||
| GRUB_FAT_ATTR_VOLUME_ID)
|
||||
|
||||
struct grub_fat_bpb
|
||||
{
|
||||
grub_uint8_t jmp_boot[3];
|
||||
grub_uint8_t oem_name[8];
|
||||
grub_uint16_t bytes_per_sector;
|
||||
grub_uint8_t sectors_per_cluster;
|
||||
grub_uint16_t num_reserved_sectors;
|
||||
grub_uint8_t num_fats;
|
||||
grub_uint16_t num_root_entries;
|
||||
grub_uint16_t num_total_sectors_16;
|
||||
grub_uint8_t media;
|
||||
grub_uint16_t sectors_per_fat_16;
|
||||
grub_uint16_t sectors_per_track;
|
||||
grub_uint16_t num_heads;
|
||||
grub_uint32_t num_hidden_sectors;
|
||||
grub_uint32_t num_total_sectors_32;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
grub_uint8_t num_ph_drive;
|
||||
grub_uint8_t reserved;
|
||||
grub_uint8_t boot_sig;
|
||||
grub_uint32_t num_serial;
|
||||
grub_uint8_t label[11];
|
||||
grub_uint8_t fstype[8];
|
||||
} __attribute__ ((packed)) fat12_or_fat16;
|
||||
struct
|
||||
{
|
||||
grub_uint32_t sectors_per_fat_32;
|
||||
grub_uint16_t extended_flags;
|
||||
grub_uint16_t fs_version;
|
||||
grub_uint32_t root_cluster;
|
||||
grub_uint16_t fs_info;
|
||||
grub_uint16_t backup_boot_sector;
|
||||
grub_uint8_t reserved[12];
|
||||
grub_uint8_t num_ph_drive;
|
||||
grub_uint8_t reserved1;
|
||||
grub_uint8_t boot_sig;
|
||||
grub_uint32_t num_serial;
|
||||
grub_uint8_t label[11];
|
||||
grub_uint8_t fstype[8];
|
||||
} __attribute__ ((packed)) fat32;
|
||||
} __attribute__ ((packed)) version_specific;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_fat_dir_entry
|
||||
{
|
||||
grub_uint8_t name[11];
|
||||
|
@ -610,6 +565,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
char *dirname, *dirp;
|
||||
char *origpath = NULL;
|
||||
int call_hook;
|
||||
int found = 0;
|
||||
|
||||
|
@ -650,6 +606,10 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
origpath = grub_strdup (path);
|
||||
if (!origpath)
|
||||
return 0;
|
||||
|
||||
/* Extract a directory name. */
|
||||
while (*path == '/')
|
||||
path++;
|
||||
|
@ -661,7 +621,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|||
|
||||
dirname = grub_malloc (len + 1);
|
||||
if (! dirname)
|
||||
return 0;
|
||||
goto fail;
|
||||
|
||||
grub_memcpy (dirname, path, len);
|
||||
dirname[len] = '\0';
|
||||
|
@ -674,9 +634,11 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|||
|
||||
grub_fat_iterate_dir (disk, data, iter_hook);
|
||||
if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook)
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
|
||||
fail:
|
||||
grub_free (dirname);
|
||||
grub_free (origpath);
|
||||
|
||||
return found ? dirp : 0;
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
|||
name = next;
|
||||
}
|
||||
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path);
|
||||
}
|
||||
|
||||
if (!path || path[0] != '/')
|
||||
|
|
|
@ -133,6 +133,8 @@ struct grub_hfs_dirrec
|
|||
grub_uint8_t type;
|
||||
grub_uint8_t unused[5];
|
||||
grub_uint32_t dirid;
|
||||
grub_uint32_t ctime;
|
||||
grub_uint32_t mtime;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* Information about a file. */
|
||||
|
@ -144,7 +146,9 @@ struct grub_hfs_filerec
|
|||
grub_uint32_t fileid;
|
||||
grub_uint8_t unused2[2];
|
||||
grub_uint32_t size;
|
||||
grub_uint8_t unused3[44];
|
||||
grub_uint8_t unused3[18];
|
||||
grub_uint32_t mtime;
|
||||
grub_uint8_t unused4[22];
|
||||
|
||||
/* The first 3 extents of the file. The other extents can be found
|
||||
in the extent overflow file. */
|
||||
|
@ -917,7 +921,7 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
|
|||
if (! grub_hfs_find_node (data, (char *) &key, data->cat_root,
|
||||
0, (char *) &fdrec.frec, sizeof (fdrec.frec)))
|
||||
{
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -953,19 +957,29 @@ grub_hfs_dir (grub_device_t device, const char *path,
|
|||
int dir_hook (struct grub_hfs_record *rec)
|
||||
{
|
||||
char fname[32] = { 0 };
|
||||
char *filetype = rec->data;
|
||||
struct grub_hfs_dirrec *drec = rec->data;
|
||||
struct grub_hfs_filerec *frec = rec->data;
|
||||
struct grub_hfs_catalog_key *ckey = rec->key;
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
|
||||
grub_strncpy (fname, (char *) (ckey->str), ckey->strlen);
|
||||
|
||||
if (*filetype == GRUB_HFS_FILETYPE_DIR
|
||||
|| *filetype == GRUB_HFS_FILETYPE_FILE)
|
||||
if (drec->type == GRUB_HFS_FILETYPE_DIR)
|
||||
{
|
||||
info.dir = (*filetype == GRUB_HFS_FILETYPE_DIR);
|
||||
info.dir = 1;
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_be_to_cpu32 (drec->mtime) - 2082844800;
|
||||
return hook (fname, &info);
|
||||
}
|
||||
if (frec->type == GRUB_HFS_FILETYPE_FILE)
|
||||
{
|
||||
info.dir = 0;
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_be_to_cpu32 (frec->mtime) - 2082844800;
|
||||
return hook (fname, &info);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1074,6 +1088,22 @@ grub_hfs_label (grub_device_t device, char **label)
|
|||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_hfs_mtime (grub_device_t device, grub_int32_t *tm)
|
||||
{
|
||||
struct grub_hfs_data *data;
|
||||
|
||||
data = grub_hfs_mount (device->disk);
|
||||
|
||||
if (data)
|
||||
*tm = grub_be_to_cpu32 (data->sblock.mtime) - 2082844800;
|
||||
else
|
||||
*tm = 0;
|
||||
|
||||
grub_free (data);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_hfs_uuid (grub_device_t device, char **uuid)
|
||||
{
|
||||
|
@ -1109,6 +1139,7 @@ static struct grub_fs grub_hfs_fs =
|
|||
.close = grub_hfs_close,
|
||||
.label = grub_hfs_label,
|
||||
.uuid = grub_hfs_uuid,
|
||||
.mtime = grub_hfs_mtime,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
|
|
|
@ -1,657 +0,0 @@
|
|||
/* pxe.c - Driver to provide access to the pxe filesystem */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/bufio.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
#include <grub/machine/pxe.h>
|
||||
#include <grub/machine/int.h>
|
||||
#include <grub/machine/memory.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define SEGMENT(x) ((x) >> 4)
|
||||
#define OFFSET(x) ((x) & 0xF)
|
||||
#define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x))
|
||||
#define LINEAR(x) (void *) (((x >> 16) <<4) + (x & 0xFFFF))
|
||||
|
||||
struct grub_pxe_disk_data
|
||||
{
|
||||
grub_uint32_t server_ip;
|
||||
grub_uint32_t gateway_ip;
|
||||
};
|
||||
|
||||
struct grub_pxe_bangpxe *grub_pxe_pxenv;
|
||||
static grub_uint32_t grub_pxe_your_ip;
|
||||
static grub_uint32_t grub_pxe_default_server_ip;
|
||||
static grub_uint32_t grub_pxe_default_gateway_ip;
|
||||
static unsigned grub_pxe_blksize = GRUB_PXE_MIN_BLKSIZE;
|
||||
|
||||
static grub_file_t curr_file = 0;
|
||||
|
||||
struct grub_pxe_data
|
||||
{
|
||||
grub_uint32_t packet_number;
|
||||
grub_uint32_t block_size;
|
||||
char filename[0];
|
||||
};
|
||||
|
||||
static grub_uint32_t pxe_rm_entry = 0;
|
||||
|
||||
static struct grub_pxe_bangpxe *
|
||||
grub_pxe_scan (void)
|
||||
{
|
||||
struct grub_bios_int_registers regs;
|
||||
struct grub_pxenv *pxenv;
|
||||
struct grub_pxe_bangpxe *bangpxe;
|
||||
|
||||
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
|
||||
|
||||
regs.ebx = 0;
|
||||
regs.ecx = 0;
|
||||
regs.eax = 0x5650;
|
||||
regs.es = 0;
|
||||
|
||||
grub_bios_interrupt (0x1a, ®s);
|
||||
|
||||
if ((regs.eax & 0xffff) != 0x564e)
|
||||
return NULL;
|
||||
|
||||
pxenv = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff));
|
||||
if (grub_memcmp (pxenv->signature, GRUB_PXE_SIGNATURE,
|
||||
sizeof (pxenv->signature))
|
||||
!= 0)
|
||||
return NULL;
|
||||
|
||||
if (pxenv->version < 0x201)
|
||||
return NULL;
|
||||
|
||||
bangpxe = (void *) ((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4)
|
||||
+ (pxenv->pxe_ptr & 0xffff));
|
||||
|
||||
if (!bangpxe)
|
||||
return NULL;
|
||||
|
||||
if (grub_memcmp (bangpxe->signature, GRUB_PXE_BANGPXE_SIGNATURE,
|
||||
sizeof (bangpxe->signature)) != 0)
|
||||
return NULL;
|
||||
|
||||
pxe_rm_entry = bangpxe->rm_entry;
|
||||
|
||||
return bangpxe;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_pxe_iterate (int (*hook) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
if (hook ("pxe"))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
parse_ip (const char *val, grub_uint32_t *ip, const char **rest)
|
||||
{
|
||||
grub_uint32_t newip = 0;
|
||||
unsigned long t;
|
||||
int i;
|
||||
const char *ptr = val;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
t = grub_strtoul (ptr, (char **) &ptr, 0);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
if (t & ~0xff)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP.");
|
||||
newip >>= 8;
|
||||
newip |= (t << 24);
|
||||
if (i != 3 && *ptr != '.')
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP.");
|
||||
ptr++;
|
||||
}
|
||||
*ip = newip;
|
||||
if (rest)
|
||||
*rest = ptr - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxe_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
{
|
||||
struct grub_pxe_disk_data *data;
|
||||
|
||||
if (grub_strcmp (name, "pxe") != 0
|
||||
&& grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a pxe disk");
|
||||
|
||||
data = grub_malloc (sizeof (*data));
|
||||
if (!data)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0)
|
||||
{
|
||||
const char *ptr;
|
||||
grub_err_t err;
|
||||
|
||||
ptr = name + sizeof ("pxe:") - 1;
|
||||
err = parse_ip (ptr, &(data->server_ip), &ptr);
|
||||
if (err)
|
||||
return err;
|
||||
if (*ptr == ':')
|
||||
{
|
||||
err = parse_ip (ptr + 1, &(data->gateway_ip), 0);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
else
|
||||
data->gateway_ip = grub_pxe_default_gateway_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->server_ip = grub_pxe_default_server_ip;
|
||||
data->gateway_ip = grub_pxe_default_gateway_ip;
|
||||
}
|
||||
|
||||
disk->total_sectors = 0;
|
||||
disk->id = (unsigned long) data;
|
||||
|
||||
disk->data = data;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pxe_close (grub_disk_t disk)
|
||||
{
|
||||
grub_free (disk->data);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxe_read (grub_disk_t disk __attribute((unused)),
|
||||
grub_disk_addr_t sector __attribute((unused)),
|
||||
grub_size_t size __attribute((unused)),
|
||||
char *buf __attribute((unused)))
|
||||
{
|
||||
return GRUB_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxe_write (grub_disk_t disk __attribute((unused)),
|
||||
grub_disk_addr_t sector __attribute((unused)),
|
||||
grub_size_t size __attribute((unused)),
|
||||
const char *buf __attribute((unused)))
|
||||
{
|
||||
return GRUB_ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
static struct grub_disk_dev grub_pxe_dev =
|
||||
{
|
||||
.name = "pxe",
|
||||
.id = GRUB_DISK_DEVICE_PXE_ID,
|
||||
.iterate = grub_pxe_iterate,
|
||||
.open = grub_pxe_open,
|
||||
.close = grub_pxe_close,
|
||||
.read = grub_pxe_read,
|
||||
.write = grub_pxe_write,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_pxefs_dir (grub_device_t device,
|
||||
const char *path __attribute__ ((unused)),
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info)
|
||||
__attribute__ ((unused)))
|
||||
{
|
||||
if (device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID)
|
||||
return grub_error (GRUB_ERR_IO, "not a pxe disk");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxefs_open (struct grub_file *file, const char *name)
|
||||
{
|
||||
union
|
||||
{
|
||||
struct grub_pxenv_tftp_get_fsize c1;
|
||||
struct grub_pxenv_tftp_open c2;
|
||||
} c;
|
||||
struct grub_pxe_data *data;
|
||||
struct grub_pxe_disk_data *disk_data = file->device->disk->data;
|
||||
grub_file_t file_int, bufio;
|
||||
|
||||
if (file->device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID)
|
||||
return grub_error (GRUB_ERR_IO, "not a pxe disk");
|
||||
|
||||
if (curr_file != 0)
|
||||
{
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2, pxe_rm_entry);
|
||||
curr_file = 0;
|
||||
}
|
||||
|
||||
c.c1.server_ip = disk_data->server_ip;
|
||||
c.c1.gateway_ip = disk_data->gateway_ip;
|
||||
grub_strcpy ((char *)&c.c1.filename[0], name);
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry);
|
||||
if (c.c1.status)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
|
||||
file->size = c.c1.file_size;
|
||||
|
||||
c.c2.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT);
|
||||
c.c2.packet_size = grub_pxe_blksize;
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2, pxe_rm_entry);
|
||||
if (c.c2.status)
|
||||
return grub_error (GRUB_ERR_BAD_FS, "open fails");
|
||||
|
||||
data = grub_zalloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
|
||||
if (! data)
|
||||
return grub_errno;
|
||||
|
||||
data->block_size = c.c2.packet_size;
|
||||
grub_strcpy (data->filename, name);
|
||||
|
||||
file_int = grub_malloc (sizeof (*file_int));
|
||||
if (! file_int)
|
||||
{
|
||||
grub_free (data);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
file->data = data;
|
||||
file->not_easily_seekable = 1;
|
||||
grub_memcpy (file_int, file, sizeof (struct grub_file));
|
||||
curr_file = file_int;
|
||||
|
||||
bufio = grub_bufio_open (file_int, data->block_size);
|
||||
if (! bufio)
|
||||
{
|
||||
grub_free (file_int);
|
||||
grub_free (data);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_memcpy (file, bufio, sizeof (struct grub_file));
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
struct grub_pxenv_tftp_read c;
|
||||
struct grub_pxe_data *data;
|
||||
struct grub_pxe_disk_data *disk_data = file->device->disk->data;
|
||||
grub_uint32_t pn, r;
|
||||
|
||||
data = file->data;
|
||||
|
||||
pn = grub_divmod64 (file->offset, data->block_size, &r);
|
||||
if (r)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS,
|
||||
"read access must be aligned to packet size");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((curr_file != file) || (data->packet_number > pn))
|
||||
{
|
||||
struct grub_pxenv_tftp_open o;
|
||||
|
||||
if (curr_file != 0)
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o, pxe_rm_entry);
|
||||
|
||||
o.server_ip = disk_data->server_ip;
|
||||
o.gateway_ip = disk_data->gateway_ip;
|
||||
grub_strcpy ((char *)&o.filename[0], data->filename);
|
||||
o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT);
|
||||
o.packet_size = data->block_size;
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o, pxe_rm_entry);
|
||||
if (o.status)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "open fails");
|
||||
return -1;
|
||||
}
|
||||
data->block_size = o.packet_size;
|
||||
data->packet_number = 0;
|
||||
curr_file = file;
|
||||
}
|
||||
|
||||
c.buffer = SEGOFS (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
||||
while (pn >= data->packet_number)
|
||||
{
|
||||
c.buffer_size = data->block_size;
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_READ, &c, pxe_rm_entry);
|
||||
if (c.status)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "read fails");
|
||||
return -1;
|
||||
}
|
||||
data->packet_number++;
|
||||
}
|
||||
|
||||
grub_memcpy (buf, (char *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxefs_close (grub_file_t file)
|
||||
{
|
||||
struct grub_pxenv_tftp_close c;
|
||||
|
||||
if (curr_file == file)
|
||||
{
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c, pxe_rm_entry);
|
||||
curr_file = 0;
|
||||
}
|
||||
|
||||
grub_free (file->data);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pxefs_label (grub_device_t device __attribute ((unused)),
|
||||
char **label __attribute ((unused)))
|
||||
{
|
||||
*label = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_fs grub_pxefs_fs =
|
||||
{
|
||||
.name = "pxefs",
|
||||
.dir = grub_pxefs_dir,
|
||||
.open = grub_pxefs_open,
|
||||
.read = grub_pxefs_read,
|
||||
.close = grub_pxefs_close,
|
||||
.label = grub_pxefs_label,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
static char *
|
||||
grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val __attribute__ ((unused)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len)
|
||||
{
|
||||
char buf[(sizeof ("XX:") - 1) * mac_len + 1];
|
||||
char *ptr = buf;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < mac_len; i++)
|
||||
{
|
||||
grub_snprintf (ptr, sizeof (buf) - (ptr - buf),
|
||||
"%02x:", mac_addr[i] & 0xff);
|
||||
ptr += (sizeof ("XX:") - 1);
|
||||
}
|
||||
if (mac_len)
|
||||
*(ptr - 1) = 0;
|
||||
else
|
||||
buf[0] = 0;
|
||||
|
||||
grub_env_set ("net_pxe_mac", buf);
|
||||
/* XXX: Is it possible to change MAC in PXE? */
|
||||
grub_register_variable_hook ("net_pxe_mac", 0, grub_env_write_readonly);
|
||||
grub_env_export ("net_pxe_mac");
|
||||
}
|
||||
|
||||
static void
|
||||
set_env_limn_ro (const char *varname, char *value, grub_size_t len)
|
||||
{
|
||||
char c;
|
||||
c = value[len];
|
||||
value[len] = 0;
|
||||
grub_env_set (varname, value);
|
||||
value[len] = c;
|
||||
grub_register_variable_hook (varname, 0, grub_env_write_readonly);
|
||||
grub_env_export (varname);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_dhcp_vendor (void *vend, int limit)
|
||||
{
|
||||
grub_uint8_t *ptr, *ptr0;
|
||||
|
||||
ptr = ptr0 = vend;
|
||||
|
||||
if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) != 0x63825363)
|
||||
return;
|
||||
ptr = ptr + sizeof (grub_uint32_t);
|
||||
while (ptr - ptr0 < limit)
|
||||
{
|
||||
grub_uint8_t tagtype;
|
||||
grub_uint8_t taglength;
|
||||
|
||||
tagtype = *ptr++;
|
||||
|
||||
/* Pad tag. */
|
||||
if (tagtype == 0)
|
||||
continue;
|
||||
|
||||
/* End tag. */
|
||||
if (tagtype == 0xff)
|
||||
return;
|
||||
|
||||
taglength = *ptr++;
|
||||
|
||||
switch (tagtype)
|
||||
{
|
||||
case 12:
|
||||
set_env_limn_ro ("net_pxe_hostname", (char *) ptr, taglength);
|
||||
break;
|
||||
|
||||
case 15:
|
||||
set_env_limn_ro ("net_pxe_domain", (char *) ptr, taglength);
|
||||
break;
|
||||
|
||||
case 17:
|
||||
set_env_limn_ro ("net_pxe_rootpath", (char *) ptr, taglength);
|
||||
break;
|
||||
|
||||
case 18:
|
||||
set_env_limn_ro ("net_pxe_extensionspath", (char *) ptr, taglength);
|
||||
break;
|
||||
|
||||
/* If you need any other options please contact GRUB
|
||||
development team. */
|
||||
}
|
||||
|
||||
ptr += taglength;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pxe_detect (void)
|
||||
{
|
||||
struct grub_pxe_bangpxe *pxenv;
|
||||
struct grub_pxenv_get_cached_info ci;
|
||||
struct grub_pxenv_boot_player *bp;
|
||||
|
||||
pxenv = grub_pxe_scan ();
|
||||
if (! pxenv)
|
||||
return;
|
||||
|
||||
ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK;
|
||||
ci.buffer = 0;
|
||||
ci.buffer_size = 0;
|
||||
grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry);
|
||||
if (ci.status)
|
||||
return;
|
||||
|
||||
bp = LINEAR (ci.buffer);
|
||||
|
||||
grub_pxe_your_ip = bp->your_ip;
|
||||
grub_pxe_default_server_ip = bp->server_ip;
|
||||
grub_pxe_default_gateway_ip = bp->gateway_ip;
|
||||
set_mac_env (bp->mac_addr, bp->hw_len < sizeof (bp->mac_addr) ? bp->hw_len
|
||||
: sizeof (bp->mac_addr));
|
||||
set_env_limn_ro ("net_pxe_boot_file", (char *) bp->boot_file,
|
||||
sizeof (bp->boot_file));
|
||||
set_env_limn_ro ("net_pxe_dhcp_server_name", (char *) bp->server_name,
|
||||
sizeof (bp->server_name));
|
||||
parse_dhcp_vendor (&bp->vendor, sizeof (bp->vendor));
|
||||
grub_pxe_pxenv = pxenv;
|
||||
}
|
||||
|
||||
void
|
||||
grub_pxe_unload (void)
|
||||
{
|
||||
if (grub_pxe_pxenv)
|
||||
{
|
||||
grub_fs_unregister (&grub_pxefs_fs);
|
||||
grub_disk_dev_unregister (&grub_pxe_dev);
|
||||
|
||||
grub_pxe_pxenv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_ip_env (char *varname, grub_uint32_t ip)
|
||||
{
|
||||
char buf[sizeof ("XXX.XXX.XXX.XXX")];
|
||||
|
||||
grub_snprintf (buf, sizeof (buf), "%d.%d.%d.%d", (ip & 0xff),
|
||||
(ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff);
|
||||
grub_env_set (varname, buf);
|
||||
}
|
||||
|
||||
static char *
|
||||
write_ip_env (grub_uint32_t *ip, const char *val)
|
||||
{
|
||||
char *buf;
|
||||
grub_err_t err;
|
||||
grub_uint32_t newip;
|
||||
|
||||
err = parse_ip (val, &newip, 0);
|
||||
if (err)
|
||||
return 0;
|
||||
|
||||
/* Normalize the IP. */
|
||||
buf = grub_xasprintf ("%d.%d.%d.%d", (newip & 0xff), (newip >> 8) & 0xff,
|
||||
(newip >> 16) & 0xff, (newip >> 24) & 0xff);
|
||||
if (!buf)
|
||||
return 0;
|
||||
|
||||
*ip = newip;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_env_write_pxe_default_server (struct grub_env_var *var
|
||||
__attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
return write_ip_env (&grub_pxe_default_server_ip, val);
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_env_write_pxe_default_gateway (struct grub_env_var *var
|
||||
__attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
return write_ip_env (&grub_pxe_default_gateway_ip, val);
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
unsigned size;
|
||||
char *buf;
|
||||
|
||||
size = grub_strtoul (val, 0, 0);
|
||||
if (grub_errno)
|
||||
return 0;
|
||||
|
||||
if (size < GRUB_PXE_MIN_BLKSIZE)
|
||||
size = GRUB_PXE_MIN_BLKSIZE;
|
||||
else if (size > GRUB_PXE_MAX_BLKSIZE)
|
||||
size = GRUB_PXE_MAX_BLKSIZE;
|
||||
|
||||
buf = grub_xasprintf ("%d", size);
|
||||
if (!buf)
|
||||
return 0;
|
||||
|
||||
grub_pxe_blksize = size;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
GRUB_MOD_INIT(pxe)
|
||||
{
|
||||
grub_pxe_detect ();
|
||||
if (grub_pxe_pxenv)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
buf = grub_xasprintf ("%d", grub_pxe_blksize);
|
||||
if (buf)
|
||||
grub_env_set ("pxe_blksize", buf);
|
||||
grub_free (buf);
|
||||
|
||||
set_ip_env ("pxe_default_server", grub_pxe_default_server_ip);
|
||||
set_ip_env ("pxe_default_gateway", grub_pxe_default_gateway_ip);
|
||||
set_ip_env ("net_pxe_ip", grub_pxe_your_ip);
|
||||
grub_register_variable_hook ("pxe_default_server", 0,
|
||||
grub_env_write_pxe_default_server);
|
||||
grub_register_variable_hook ("pxe_default_gateway", 0,
|
||||
grub_env_write_pxe_default_gateway);
|
||||
|
||||
|
||||
/* XXX: Is it possible to change IP in PXE? */
|
||||
grub_register_variable_hook ("net_pxe_ip", 0,
|
||||
grub_env_write_readonly);
|
||||
grub_register_variable_hook ("pxe_blksize", 0,
|
||||
grub_env_write_pxe_blocksize);
|
||||
|
||||
grub_env_export ("pxe_default_server");
|
||||
grub_env_export ("pxe_default_gateway");
|
||||
grub_env_export ("net_pxe_ip");
|
||||
grub_env_export ("pxe_blksize");
|
||||
|
||||
grub_disk_dev_register (&grub_pxe_dev);
|
||||
grub_fs_register (&grub_pxefs_fs);
|
||||
}
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(pxe)
|
||||
{
|
||||
grub_pxe_unload ();
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/datetime.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -55,6 +56,17 @@ struct grub_iso9660_voldesc
|
|||
grub_uint8_t version;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_iso9660_date2
|
||||
{
|
||||
grub_uint8_t year;
|
||||
grub_uint8_t month;
|
||||
grub_uint8_t day;
|
||||
grub_uint8_t hour;
|
||||
grub_uint8_t minute;
|
||||
grub_uint8_t second;
|
||||
grub_uint8_t offset;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* A directory entry. */
|
||||
struct grub_iso9660_dir
|
||||
{
|
||||
|
@ -64,7 +76,7 @@ struct grub_iso9660_dir
|
|||
grub_uint32_t first_sector_be;
|
||||
grub_uint32_t size;
|
||||
grub_uint32_t size_be;
|
||||
grub_uint8_t unused1[7];
|
||||
struct grub_iso9660_date2 mtime;
|
||||
grub_uint8_t flags;
|
||||
grub_uint8_t unused2[6];
|
||||
grub_uint8_t namelen;
|
||||
|
@ -146,6 +158,7 @@ struct grub_iso9660_data
|
|||
struct grub_fshelp_node
|
||||
{
|
||||
struct grub_iso9660_data *data;
|
||||
struct grub_iso9660_dir dirent;
|
||||
unsigned int size;
|
||||
unsigned int blk;
|
||||
unsigned int dir_blk;
|
||||
|
@ -155,6 +168,52 @@ struct grub_fshelp_node
|
|||
static grub_dl_t my_mod;
|
||||
|
||||
|
||||
static grub_err_t
|
||||
iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix)
|
||||
{
|
||||
struct grub_datetime datetime;
|
||||
|
||||
if (! i->year[0] && ! i->year[1]
|
||||
&& ! i->year[2] && ! i->year[3]
|
||||
&& ! i->month[0] && ! i->month[1]
|
||||
&& ! i->day[0] && ! i->day[1]
|
||||
&& ! i->hour[0] && ! i->hour[1]
|
||||
&& ! i->minute[0] && ! i->minute[1]
|
||||
&& ! i->second[0] && ! i->second[1]
|
||||
&& ! i->hundredth[0] && ! i->hundredth[1])
|
||||
return grub_error (GRUB_ERR_BAD_NUMBER, "empty date");
|
||||
datetime.year = (i->year[0] - '0') * 1000 + (i->year[1] - '0') * 100
|
||||
+ (i->year[2] - '0') * 10 + (i->year[3] - '0');
|
||||
datetime.month = (i->month[0] - '0') * 10 + (i->month[1] - '0');
|
||||
datetime.day = (i->day[0] - '0') * 10 + (i->day[1] - '0');
|
||||
datetime.hour = (i->hour[0] - '0') * 10 + (i->hour[1] - '0');
|
||||
datetime.minute = (i->minute[0] - '0') * 10 + (i->minute[1] - '0');
|
||||
datetime.second = (i->second[0] - '0') * 10 + (i->second[1] - '0');
|
||||
|
||||
if (!grub_datetime2unixtime (&datetime, nix))
|
||||
return grub_error (GRUB_ERR_BAD_NUMBER, "incorrect date");
|
||||
*nix -= i->offset * 60 * 15;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix)
|
||||
{
|
||||
struct grub_datetime datetime;
|
||||
|
||||
datetime.year = i->year + 1900;
|
||||
datetime.month = i->month;
|
||||
datetime.day = i->day;
|
||||
datetime.hour = i->hour;
|
||||
datetime.minute = i->minute;
|
||||
datetime.second = i->second;
|
||||
|
||||
if (!grub_datetime2unixtime (&datetime, nix))
|
||||
return 0;
|
||||
*nix -= i->offset * 60 * 15;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Iterate over the susp entries, starting with block SUA_BLOCK on the
|
||||
offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for
|
||||
every entry. */
|
||||
|
@ -366,7 +425,6 @@ grub_iso9660_mount (grub_disk_t disk)
|
|||
static char *
|
||||
grub_iso9660_read_symlink (grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_iso9660_dir dirent;
|
||||
int sua_off;
|
||||
int sua_size;
|
||||
char *symlink = 0;
|
||||
|
@ -444,13 +502,10 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (grub_disk_read (node->data->disk, node->dir_blk, node->dir_off,
|
||||
sizeof (dirent), (char *) &dirent))
|
||||
return 0;
|
||||
|
||||
sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2)
|
||||
sua_off = (sizeof (node->dirent) + node->dirent.namelen + 1
|
||||
- (node->dirent.namelen % 2)
|
||||
+ node->data->susp_skip);
|
||||
sua_size = dirent.len - sua_off;
|
||||
sua_size = node->dirent.len - sua_off;
|
||||
|
||||
symlink = grub_malloc (1);
|
||||
if (!symlink)
|
||||
|
@ -543,7 +598,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
|
|||
return 0;
|
||||
}
|
||||
|
||||
while (offset < dir->size)
|
||||
for (; offset < dir->size; offset += dirent.len)
|
||||
{
|
||||
if (grub_disk_read (dir->data->disk,
|
||||
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
|
||||
|
@ -621,10 +676,9 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
|
|||
if (filename)
|
||||
*filename = '\0';
|
||||
|
||||
if (dirent.namelen == 1 && name[0] == 0)
|
||||
filename = ".";
|
||||
else if (dirent.namelen == 1 && name[0] == 1)
|
||||
filename = "..";
|
||||
/* . and .. */
|
||||
if (dirent.namelen == 1 && (name[0] == 0 || name[0] == 1))
|
||||
continue;
|
||||
else
|
||||
filename = name;
|
||||
}
|
||||
|
@ -647,6 +701,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
|
|||
filename_alloc = 1;
|
||||
}
|
||||
|
||||
node->dirent = dirent;
|
||||
if (hook (filename, type, node))
|
||||
{
|
||||
if (filename_alloc)
|
||||
|
@ -656,8 +711,6 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
|
|||
if (filename_alloc)
|
||||
grub_free (filename);
|
||||
}
|
||||
|
||||
offset += dirent.len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -685,6 +738,8 @@ grub_iso9660_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtimeset = !!iso9660_to_unixtime2 (&node->dirent.mtime, &info.mtime);
|
||||
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
@ -882,6 +937,32 @@ grub_iso9660_uuid (grub_device_t device, char **uuid)
|
|||
return grub_errno;
|
||||
}
|
||||
|
||||
/* Get writing time of filesystem. */
|
||||
static grub_err_t
|
||||
grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf)
|
||||
{
|
||||
struct grub_iso9660_data *data;
|
||||
grub_disk_t disk = device->disk;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
data = grub_iso9660_mount (disk);
|
||||
if (!data)
|
||||
{
|
||||
grub_dl_unref (my_mod);
|
||||
return grub_errno;
|
||||
}
|
||||
err = iso9660_to_unixtime (&data->voldesc.modified, timebuf);
|
||||
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
grub_free (data);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static struct grub_fs grub_iso9660_fs =
|
||||
|
@ -893,6 +974,7 @@ static struct grub_fs grub_iso9660_fs =
|
|||
.close = grub_iso9660_close,
|
||||
.label = grub_iso9660_label,
|
||||
.uuid = grub_iso9660_uuid,
|
||||
.mtime = grub_iso9660_mtime,
|
||||
.next = 0
|
||||
};
|
||||
|
||||
|
|
|
@ -155,6 +155,12 @@ struct grub_jfs_leaf_next_dirent
|
|||
grub_uint16_t namepart[15];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_jfs_time
|
||||
{
|
||||
grub_int32_t sec;
|
||||
grub_int32_t nanosec;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_jfs_inode
|
||||
{
|
||||
grub_uint32_t stamp;
|
||||
|
@ -164,7 +170,10 @@ struct grub_jfs_inode
|
|||
grub_uint64_t size;
|
||||
grub_uint8_t unused2[20];
|
||||
grub_uint32_t mode;
|
||||
grub_uint8_t unused3[72];
|
||||
struct grub_jfs_time atime;
|
||||
struct grub_jfs_time ctime;
|
||||
struct grub_jfs_time mtime;
|
||||
grub_uint8_t unused3[48];
|
||||
grub_uint8_t unused4[96];
|
||||
|
||||
union
|
||||
|
@ -690,7 +699,7 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
|
|||
}
|
||||
|
||||
grub_jfs_closedir (diro);
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -760,6 +769,8 @@ grub_jfs_dir (grub_device_t device, const char *path,
|
|||
|
||||
info.dir = (grub_le_to_cpu32 (inode.mode)
|
||||
& GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR;
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_le_to_cpu32 (inode.mtime.sec);
|
||||
if (hook (diro->name, &info))
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -27,14 +27,17 @@
|
|||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#ifdef MODE_MINIX2
|
||||
#ifdef MODE_MINIX3
|
||||
#define GRUB_MINIX_MAGIC 0x4D5A
|
||||
#elif defined(MODE_MINIX2)
|
||||
#define GRUB_MINIX_MAGIC 0x2468
|
||||
#define GRUB_MINIX_MAGIC_30 0x2478
|
||||
#else
|
||||
#define GRUB_MINIX_MAGIC 0x137F
|
||||
#define GRUB_MINIX_MAGIC_30 0x138F
|
||||
#endif
|
||||
#define GRUB_MINIX_BSIZE 1024U
|
||||
|
||||
#define GRUB_MINIX_INODE_DIR_BLOCKS 7
|
||||
#define GRUB_MINIX_LOG2_BSIZE 1
|
||||
#define GRUB_MINIX_ROOT_INODE 1
|
||||
#define GRUB_MINIX_MAX_SYMLNK_CNT 8
|
||||
|
@ -43,7 +46,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|||
#define GRUB_MINIX_IFDIR 0040000U
|
||||
#define GRUB_MINIX_IFLNK 0120000U
|
||||
|
||||
#ifdef MODE_MINIX2
|
||||
#if defined(MODE_MINIX2) || defined(MODE_MINIX3)
|
||||
typedef grub_uint32_t grub_minix_uintn_t;
|
||||
#define grub_minix_le_to_cpu_n grub_le_to_cpu32
|
||||
#else
|
||||
|
@ -52,6 +55,13 @@ typedef grub_uint16_t grub_minix_uintn_t;
|
|||
#endif
|
||||
|
||||
#define GRUB_MINIX_INODE_BLKSZ(data) sizeof (grub_minix_uintn_t)
|
||||
#ifdef MODE_MINIX3
|
||||
typedef grub_uint32_t grub_minix_ino_t;
|
||||
#define grub_minix_le_to_cpu_ino grub_le_to_cpu32
|
||||
#else
|
||||
typedef grub_uint16_t grub_minix_ino_t;
|
||||
#define grub_minix_le_to_cpu_ino grub_le_to_cpu16
|
||||
#endif
|
||||
|
||||
#define GRUB_MINIX_INODE_SIZE(data) (grub_minix_le_to_cpu_n (data->inode.size))
|
||||
#define GRUB_MINIX_INODE_MODE(data) (grub_le_to_cpu16 (data->inode.mode))
|
||||
|
@ -62,11 +72,39 @@ typedef grub_uint16_t grub_minix_uintn_t;
|
|||
#define GRUB_MINIX_INODE_DINDIR_ZONE(data) (grub_minix_le_to_cpu_n \
|
||||
(data->inode.double_indir_zone))
|
||||
|
||||
#ifndef MODE_MINIX3
|
||||
#define GRUB_MINIX_LOG2_ZONESZ (GRUB_MINIX_LOG2_BSIZE \
|
||||
+ grub_le_to_cpu16 (sblock->log2_zone_size))
|
||||
#define GRUB_MINIX_ZONESZ (GRUB_MINIX_BSIZE \
|
||||
<< grub_le_to_cpu16 (sblock->log2_zone_size))
|
||||
+ grub_le_to_cpu16 (data->sblock.log2_zone_size))
|
||||
#endif
|
||||
#define GRUB_MINIX_ZONESZ (data->block_size \
|
||||
<< grub_le_to_cpu16 (data->sblock.log2_zone_size))
|
||||
|
||||
#ifdef MODE_MINIX3
|
||||
#define GRUB_MINIX_ZONE2SECT(zone) ((zone) * (data->block_size / GRUB_DISK_SECTOR_SIZE))
|
||||
#else
|
||||
#define GRUB_MINIX_ZONE2SECT(zone) ((zone) << GRUB_MINIX_LOG2_ZONESZ)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODE_MINIX3
|
||||
struct grub_minix_sblock
|
||||
{
|
||||
grub_uint32_t inode_cnt;
|
||||
grub_uint16_t zone_cnt;
|
||||
grub_uint16_t inode_bmap_size;
|
||||
grub_uint16_t zone_bmap_size;
|
||||
grub_uint16_t first_data_zone;
|
||||
grub_uint16_t log2_zone_size;
|
||||
grub_uint16_t pad;
|
||||
grub_uint32_t max_file_size;
|
||||
grub_uint32_t zones;
|
||||
grub_uint16_t magic;
|
||||
|
||||
grub_uint16_t pad2;
|
||||
grub_uint16_t block_size;
|
||||
grub_uint8_t disk_version;
|
||||
};
|
||||
#else
|
||||
struct grub_minix_sblock
|
||||
{
|
||||
grub_uint16_t inode_cnt;
|
||||
|
@ -78,23 +116,9 @@ struct grub_minix_sblock
|
|||
grub_uint32_t max_file_size;
|
||||
grub_uint16_t magic;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef MODE_MINIX2
|
||||
struct grub_minix_inode
|
||||
{
|
||||
grub_uint16_t mode;
|
||||
grub_uint16_t uid;
|
||||
grub_uint16_t size;
|
||||
grub_uint32_t ctime;
|
||||
grub_uint8_t gid;
|
||||
grub_uint8_t nlinks;
|
||||
grub_uint16_t dir_zones[7];
|
||||
grub_uint16_t indir_zone;
|
||||
grub_uint16_t double_indir_zone;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#if defined(MODE_MINIX3) || defined(MODE_MINIX2)
|
||||
struct grub_minix_inode
|
||||
{
|
||||
grub_uint16_t mode;
|
||||
|
@ -111,6 +135,19 @@ struct grub_minix_inode
|
|||
grub_uint32_t unused;
|
||||
|
||||
};
|
||||
#else
|
||||
struct grub_minix_inode
|
||||
{
|
||||
grub_uint16_t mode;
|
||||
grub_uint16_t uid;
|
||||
grub_uint16_t size;
|
||||
grub_uint32_t ctime;
|
||||
grub_uint8_t gid;
|
||||
grub_uint8_t nlinks;
|
||||
grub_uint16_t dir_zones[7];
|
||||
grub_uint16_t indir_zone;
|
||||
grub_uint16_t double_indir_zone;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -123,6 +160,7 @@ struct grub_minix_data
|
|||
int linknest;
|
||||
grub_disk_t disk;
|
||||
int filename_size;
|
||||
grub_size_t block_size;
|
||||
};
|
||||
|
||||
static grub_dl_t my_mod;
|
||||
|
@ -133,7 +171,6 @@ static grub_err_t grub_minix_find_file (struct grub_minix_data *data,
|
|||
static int
|
||||
grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk)
|
||||
{
|
||||
struct grub_minix_sblock *sblock = &data->sblock;
|
||||
int indir;
|
||||
|
||||
auto int grub_get_indir (int, int);
|
||||
|
@ -143,18 +180,18 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk)
|
|||
{
|
||||
grub_minix_uintn_t indirn;
|
||||
grub_disk_read (data->disk,
|
||||
zone << GRUB_MINIX_LOG2_ZONESZ,
|
||||
GRUB_MINIX_ZONE2SECT(zone),
|
||||
sizeof (grub_minix_uintn_t) * num,
|
||||
sizeof (grub_minix_uintn_t), (char *) &indirn);
|
||||
return grub_minix_le_to_cpu_n (indirn);
|
||||
}
|
||||
|
||||
/* Direct block. */
|
||||
if (blk < 7)
|
||||
if (blk < GRUB_MINIX_INODE_DIR_BLOCKS)
|
||||
return GRUB_MINIX_INODE_DIR_ZONES (data, blk);
|
||||
|
||||
/* Indirect block. */
|
||||
blk -= 7;
|
||||
blk -= GRUB_MINIX_INODE_DIR_BLOCKS;
|
||||
if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))
|
||||
{
|
||||
indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk);
|
||||
|
@ -187,25 +224,26 @@ static grub_ssize_t
|
|||
grub_minix_read_file (struct grub_minix_data *data,
|
||||
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
|
||||
unsigned offset, unsigned length),
|
||||
int pos, grub_disk_addr_t len, char *buf)
|
||||
grub_off_t pos, grub_disk_addr_t len, char *buf)
|
||||
{
|
||||
struct grub_minix_sblock *sblock = &data->sblock;
|
||||
int i;
|
||||
int blockcnt;
|
||||
grub_disk_addr_t i;
|
||||
grub_disk_addr_t blockcnt;
|
||||
grub_uint64_t posblock;
|
||||
grub_uint64_t blockoff;
|
||||
|
||||
/* Adjust len so it we can't read past the end of the file. */
|
||||
if (len + pos > GRUB_MINIX_INODE_SIZE (data))
|
||||
len = GRUB_MINIX_INODE_SIZE (data) - pos;
|
||||
|
||||
blockcnt = (len + pos + GRUB_MINIX_BSIZE - 1) / GRUB_MINIX_BSIZE;
|
||||
blockcnt = grub_divmod64 ((len + pos + data->block_size - 1),
|
||||
data->block_size, 0);
|
||||
posblock = grub_divmod64 (pos, data->block_size, &blockoff);
|
||||
|
||||
for (i = pos / GRUB_MINIX_BSIZE; i < blockcnt; i++)
|
||||
for (i = posblock; i < blockcnt; i++)
|
||||
{
|
||||
int blknr;
|
||||
int blockoff = pos % GRUB_MINIX_BSIZE;
|
||||
int blockend = GRUB_MINIX_BSIZE;
|
||||
|
||||
int skipfirst = 0;
|
||||
grub_disk_addr_t blknr;
|
||||
grub_uint64_t blockend = data->block_size;
|
||||
grub_off_t skipfirst = 0;
|
||||
|
||||
blknr = grub_minix_get_file_block (data, i);
|
||||
if (grub_errno)
|
||||
|
@ -214,28 +252,28 @@ grub_minix_read_file (struct grub_minix_data *data,
|
|||
/* Last block. */
|
||||
if (i == blockcnt - 1)
|
||||
{
|
||||
blockend = (len + pos) % GRUB_MINIX_BSIZE;
|
||||
grub_divmod64 (len + pos, data->block_size, &blockend);
|
||||
|
||||
if (!blockend)
|
||||
blockend = GRUB_MINIX_BSIZE;
|
||||
blockend = data->block_size;
|
||||
}
|
||||
|
||||
/* First block. */
|
||||
if (i == (pos / (int) GRUB_MINIX_BSIZE))
|
||||
if (i == posblock)
|
||||
{
|
||||
skipfirst = blockoff;
|
||||
blockend -= skipfirst;
|
||||
}
|
||||
|
||||
data->disk->read_hook = read_hook;
|
||||
grub_disk_read (data->disk, blknr << GRUB_MINIX_LOG2_ZONESZ,
|
||||
grub_disk_read (data->disk,
|
||||
GRUB_MINIX_ZONE2SECT(blknr),
|
||||
skipfirst, blockend, buf);
|
||||
|
||||
data->disk->read_hook = 0;
|
||||
if (grub_errno)
|
||||
return -1;
|
||||
|
||||
buf += GRUB_MINIX_BSIZE - skipfirst;
|
||||
buf += data->block_size - skipfirst;
|
||||
}
|
||||
|
||||
return len;
|
||||
|
@ -250,16 +288,13 @@ grub_minix_read_inode (struct grub_minix_data *data, int ino)
|
|||
struct grub_minix_sblock *sblock = &data->sblock;
|
||||
|
||||
/* Block in which the inode is stored. */
|
||||
int block;
|
||||
grub_disk_addr_t block;
|
||||
data->ino = ino;
|
||||
|
||||
/* The first inode in minix is inode 1. */
|
||||
ino--;
|
||||
|
||||
block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size)
|
||||
+ grub_le_to_cpu16 (sblock->zone_bmap_size))
|
||||
<< GRUB_MINIX_LOG2_BSIZE);
|
||||
|
||||
block = GRUB_MINIX_ZONE2SECT (2 + grub_le_to_cpu16 (sblock->inode_bmap_size)
|
||||
+ grub_le_to_cpu16 (sblock->zone_bmap_size));
|
||||
block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode));
|
||||
int offs = (ino % (GRUB_DISK_SECTOR_SIZE
|
||||
/ sizeof (struct grub_minix_inode))
|
||||
|
@ -335,7 +370,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
|
|||
|
||||
do
|
||||
{
|
||||
grub_uint16_t ino;
|
||||
grub_minix_ino_t ino;
|
||||
char filename[data->filename_size + 1];
|
||||
|
||||
if (grub_strlen (name) == 0)
|
||||
|
@ -355,7 +390,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
|
|||
if (!grub_strcmp (name, filename))
|
||||
{
|
||||
dirino = data->ino;
|
||||
grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
|
||||
grub_minix_read_inode (data, grub_minix_le_to_cpu_ino (ino));
|
||||
|
||||
/* Follow the symlink. */
|
||||
if ((GRUB_MINIX_INODE_MODE (data)
|
||||
|
@ -389,7 +424,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
|
|||
pos += sizeof (ino) + data->filename_size;
|
||||
} while (pos < GRUB_MINIX_INODE_SIZE (data));
|
||||
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -411,20 +446,35 @@ grub_minix_mount (grub_disk_t disk)
|
|||
goto fail;
|
||||
|
||||
if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC)
|
||||
{
|
||||
#if !defined(MODE_MINIX3)
|
||||
data->filename_size = 14;
|
||||
#else
|
||||
data->filename_size = 60;
|
||||
#endif
|
||||
}
|
||||
#if !defined(MODE_MINIX3)
|
||||
else if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC_30)
|
||||
data->filename_size = 30;
|
||||
#endif
|
||||
else
|
||||
goto fail;
|
||||
|
||||
data->disk = disk;
|
||||
data->linknest = 0;
|
||||
#ifdef MODE_MINIX3
|
||||
data->block_size = grub_le_to_cpu16 (data->sblock.block_size);
|
||||
#else
|
||||
data->block_size = 1024U;
|
||||
#endif
|
||||
|
||||
return data;
|
||||
|
||||
fail:
|
||||
grub_free (data);
|
||||
#ifdef MODE_MINIX2
|
||||
#if defined(MODE_MINIX3)
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a minix3 filesystem");
|
||||
#elif defined(MODE_MINIX2)
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a minix2 filesystem");
|
||||
#else
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a minix filesystem");
|
||||
|
@ -460,7 +510,7 @@ grub_minix_dir (grub_device_t device, const char *path,
|
|||
|
||||
while (pos < GRUB_MINIX_INODE_SIZE (data))
|
||||
{
|
||||
grub_uint16_t ino;
|
||||
grub_minix_ino_t ino;
|
||||
char filename[data->filename_size + 1];
|
||||
int dirino = data->ino;
|
||||
struct grub_dirhook_info info;
|
||||
|
@ -476,12 +526,22 @@ grub_minix_dir (grub_device_t device, const char *path,
|
|||
(char *) filename) < 0)
|
||||
return grub_errno;
|
||||
filename[data->filename_size] = '\0';
|
||||
if (!ino)
|
||||
{
|
||||
pos += sizeof (ino) + data->filename_size;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* The filetype is not stored in the dirent. Read the inode to
|
||||
find out the filetype. This *REALLY* sucks. */
|
||||
grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
|
||||
grub_minix_read_inode (data, grub_minix_le_to_cpu_ino (ino));
|
||||
info.dir = ((GRUB_MINIX_INODE_MODE (data)
|
||||
& GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR);
|
||||
info.mtimeset = 1;
|
||||
#ifndef MODE_MINIX2
|
||||
info.mtime = grub_le_to_cpu32 (data->inode.ctime);
|
||||
#else
|
||||
info.mtime = grub_le_to_cpu32 (data->inode.mtime);
|
||||
#endif
|
||||
|
||||
if (hook (filename, &info) ? 1 : 0)
|
||||
break;
|
||||
|
||||
|
@ -558,7 +618,9 @@ grub_minix_close (grub_file_t file)
|
|||
|
||||
static struct grub_fs grub_minix_fs =
|
||||
{
|
||||
#ifdef MODE_MINIX2
|
||||
#if defined(MODE_MINIX3)
|
||||
.name = "minix3",
|
||||
#elif defined(MODE_MINIX2)
|
||||
.name = "minix2",
|
||||
#else
|
||||
.name = "minix",
|
||||
|
@ -570,7 +632,9 @@ static struct grub_fs grub_minix_fs =
|
|||
.next = 0
|
||||
};
|
||||
|
||||
#ifdef MODE_MINIX2
|
||||
#if defined(MODE_MINIX3)
|
||||
GRUB_MOD_INIT(minix3)
|
||||
#elif defined(MODE_MINIX2)
|
||||
GRUB_MOD_INIT(minix2)
|
||||
#else
|
||||
GRUB_MOD_INIT(minix)
|
||||
|
@ -580,7 +644,9 @@ GRUB_MOD_INIT(minix)
|
|||
my_mod = mod;
|
||||
}
|
||||
|
||||
#ifdef MODE_MINIX2
|
||||
#if defined(MODE_MINIX3)
|
||||
GRUB_MOD_FINI(minix3)
|
||||
#elif defined(MODE_MINIX2)
|
||||
GRUB_MOD_FINI(minix2)
|
||||
#else
|
||||
GRUB_MOD_FINI(minix)
|
||||
|
|
2
grub-core/fs/minix3.c
Normal file
2
grub-core/fs/minix3.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define MODE_MINIX3 1
|
||||
#include "minix.c"
|
|
@ -303,7 +303,7 @@ grub_nilfs2_palloc_entries_per_group (struct grub_nilfs2_data *data)
|
|||
|
||||
static inline grub_uint64_t
|
||||
grub_nilfs2_palloc_group (struct grub_nilfs2_data *data,
|
||||
grub_uint64_t nr, grub_uint32_t * offset)
|
||||
grub_uint64_t nr, grub_uint64_t * offset)
|
||||
{
|
||||
return grub_divmod64 (nr, grub_nilfs2_palloc_entries_per_group (data),
|
||||
offset);
|
||||
|
@ -368,13 +368,15 @@ grub_nilfs2_palloc_entry_offset (struct grub_nilfs2_data *data,
|
|||
grub_uint64_t nr, unsigned long entry_size)
|
||||
{
|
||||
unsigned long group;
|
||||
grub_uint32_t group_offset;
|
||||
grub_uint64_t group_offset;
|
||||
|
||||
group = grub_nilfs2_palloc_group (data, nr, &group_offset);
|
||||
|
||||
return grub_nilfs2_palloc_bitmap_block_offset (data, group,
|
||||
entry_size) + 1 +
|
||||
group_offset / grub_nilfs2_entries_per_block (data, entry_size);
|
||||
grub_divmod64 (group_offset, grub_nilfs2_entries_per_block (data,
|
||||
entry_size),
|
||||
NULL);
|
||||
|
||||
}
|
||||
|
||||
|
@ -577,7 +579,7 @@ grub_nilfs2_dat_translate (struct grub_nilfs2_data *data, grub_uint64_t key)
|
|||
struct grub_nilfs2_dat_entry entry;
|
||||
grub_disk_t disk = data->disk;
|
||||
grub_uint64_t pptr;
|
||||
grub_uint32_t blockno, offset;
|
||||
grub_uint64_t blockno, offset;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
||||
blockno = grub_nilfs2_palloc_entry_offset (data, key,
|
||||
|
@ -641,7 +643,7 @@ grub_nilfs2_read_checkpoint (struct grub_nilfs2_data *data,
|
|||
struct grub_nilfs2_checkpoint *cpp)
|
||||
{
|
||||
grub_uint64_t blockno;
|
||||
grub_uint32_t offset;
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t pptr;
|
||||
grub_disk_t disk = data->disk;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
@ -679,7 +681,7 @@ grub_nilfs2_read_inode (struct grub_nilfs2_data *data,
|
|||
grub_uint64_t ino, struct grub_nilfs2_inode *inodep)
|
||||
{
|
||||
grub_uint64_t blockno;
|
||||
unsigned int offset;
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t pptr;
|
||||
grub_disk_t disk = data->disk;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
|
|
@ -431,7 +431,7 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
|
|||
if (at->flags & AF_GPOS)
|
||||
{
|
||||
grub_disk_addr_t st0, st1;
|
||||
grub_uint32_t m;
|
||||
grub_uint64_t m;
|
||||
|
||||
grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, &m);
|
||||
|
||||
|
@ -612,6 +612,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,
|
|||
|
||||
fdiro->data = diro->data;
|
||||
fdiro->ino = u32at (pos, 0);
|
||||
if (u64at (pos, 0x20) > u64at (pos, 0x28))
|
||||
fdiro->mtime = u64at (pos, 0x20);
|
||||
else
|
||||
fdiro->mtime = u64at (pos, 0x28);
|
||||
|
||||
ustr = grub_malloc (ns * 4 + 1);
|
||||
if (ustr == NULL)
|
||||
|
@ -882,6 +886,10 @@ grub_ntfs_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_divmod64 (node->mtime, 10000000, 0)
|
||||
- 86400ULL * 365 * (1970 - 1601)
|
||||
- 86400ULL * ((1970 - 1601) / 4) + 86400ULL * ((1970 - 1601) / 100);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
|
|
@ -224,6 +224,7 @@ struct grub_fshelp_node
|
|||
grub_uint32_t block_number; /* 0 if node is not found. */
|
||||
grub_uint16_t block_position;
|
||||
grub_uint64_t next_offset;
|
||||
grub_int32_t mtime;
|
||||
enum grub_reiserfs_item_type type; /* To know how to read the header. */
|
||||
struct grub_reiserfs_item_header header;
|
||||
};
|
||||
|
@ -870,6 +871,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
|
|||
entry_v1_stat.rdev,
|
||||
entry_v1_stat.first_direct_byte);
|
||||
#endif
|
||||
entry_item->mtime = grub_le_to_cpu32 (entry_v1_stat.mtime);
|
||||
if ((grub_le_to_cpu16 (entry_v1_stat.mode) & S_IFLNK)
|
||||
== S_IFLNK)
|
||||
entry_type = GRUB_FSHELP_SYMLINK;
|
||||
|
@ -916,6 +918,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
|
|||
entry_v2_stat.blocks,
|
||||
entry_v2_stat.first_direct_byte);
|
||||
#endif
|
||||
entry_item->mtime = grub_le_to_cpu32 (entry_v2_stat.mtime);
|
||||
if ((grub_le_to_cpu16 (entry_v2_stat.mode) & S_IFLNK)
|
||||
== S_IFLNK)
|
||||
entry_type = GRUB_FSHELP_SYMLINK;
|
||||
|
@ -1278,6 +1281,8 @@ grub_reiserfs_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtimeset = 1;
|
||||
info.mtime = node->mtime;
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
|
460
grub-core/fs/romfs.c
Normal file
460
grub-core/fs/romfs.c
Normal file
|
@ -0,0 +1,460 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/file.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/fshelp.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_romfs_superblock
|
||||
{
|
||||
char magic[8];
|
||||
#define GRUB_ROMFS_MAGIC "-rom1fs-"
|
||||
grub_uint32_t total_size;
|
||||
grub_uint32_t chksum;
|
||||
char label[0];
|
||||
};
|
||||
|
||||
struct grub_romfs_file_header
|
||||
{
|
||||
grub_uint32_t next_file;
|
||||
grub_uint32_t spec;
|
||||
grub_uint32_t size;
|
||||
grub_uint32_t chksum;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
struct grub_romfs_data
|
||||
{
|
||||
grub_disk_addr_t first_file;
|
||||
grub_disk_t disk;
|
||||
};
|
||||
|
||||
struct grub_fshelp_node
|
||||
{
|
||||
grub_disk_addr_t addr;
|
||||
struct grub_romfs_data *data;
|
||||
grub_disk_addr_t data_addr;
|
||||
/* Not filled for root. */
|
||||
struct grub_romfs_file_header file;
|
||||
};
|
||||
|
||||
#define GRUB_ROMFS_ALIGN 16
|
||||
#define GRUB_ROMFS_TYPE_MASK 7
|
||||
#define GRUB_ROMFS_TYPE_HARDLINK 0
|
||||
#define GRUB_ROMFS_TYPE_DIRECTORY 1
|
||||
#define GRUB_ROMFS_TYPE_REGULAR 2
|
||||
#define GRUB_ROMFS_TYPE_SYMLINK 3
|
||||
|
||||
static grub_err_t
|
||||
do_checksum (void *in, grub_size_t insize)
|
||||
{
|
||||
grub_uint32_t *a = in;
|
||||
grub_size_t sz = insize / 4;
|
||||
grub_uint32_t *b = a + sz;
|
||||
grub_uint32_t csum = 0;
|
||||
|
||||
while (a < b)
|
||||
csum += grub_be_to_cpu32 (*a++);
|
||||
if (csum)
|
||||
return grub_error (GRUB_ERR_BAD_FS, "invalid checksum");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_romfs_data *
|
||||
grub_romfs_mount (grub_device_t dev)
|
||||
{
|
||||
union {
|
||||
struct grub_romfs_superblock sb;
|
||||
char d[512];
|
||||
} sb;
|
||||
grub_err_t err;
|
||||
char *ptr;
|
||||
grub_disk_addr_t sec = 0;
|
||||
struct grub_romfs_data *data;
|
||||
if (!dev->disk)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a disk");
|
||||
return NULL;
|
||||
}
|
||||
err = grub_disk_read (dev->disk, 0, 0, sizeof (sb), &sb);
|
||||
if (err == GRUB_ERR_OUT_OF_RANGE)
|
||||
err = grub_errno = GRUB_ERR_BAD_FS;
|
||||
if (err)
|
||||
return NULL;
|
||||
if (grub_be_to_cpu32 (sb.sb.total_size) < sizeof (sb))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "too short filesystem");
|
||||
return NULL;
|
||||
}
|
||||
err = do_checksum (&sb, sizeof (sb) < grub_be_to_cpu32 (sb.sb.total_size) ?
|
||||
sizeof (sb) : grub_be_to_cpu32 (sb.sb.total_size));
|
||||
if (err)
|
||||
return NULL;
|
||||
for (ptr = sb.sb.label; (void *) ptr < (void *) (&sb + 1)
|
||||
&& ptr < sb.d + grub_be_to_cpu32 (sb.sb.total_size); ptr++)
|
||||
if (!*ptr)
|
||||
break;
|
||||
if ((void *) ptr == &sb + 1)
|
||||
for (sec++; ; sec++)
|
||||
{
|
||||
err = grub_disk_read (dev->disk, sec, 0, sizeof (sb), &sb);
|
||||
if (err == GRUB_ERR_OUT_OF_RANGE)
|
||||
err = grub_errno = GRUB_ERR_BAD_FS;
|
||||
if (err)
|
||||
return NULL;
|
||||
for (ptr = sb.d; (void *) ptr < (void *) (&sb + 1)
|
||||
&& ptr < sb.d + grub_be_to_cpu32 (sb.sb.total_size); ptr++)
|
||||
if (!*ptr)
|
||||
break;
|
||||
}
|
||||
data = grub_malloc (sizeof (*data));
|
||||
if (!data)
|
||||
return NULL;
|
||||
data->first_file = ALIGN_UP (ptr - sb.d, GRUB_ROMFS_ALIGN) + sec * 512;
|
||||
data->disk = dev->disk;
|
||||
return data;
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_romfs_read_symlink (grub_fshelp_node_t node)
|
||||
{
|
||||
char *ret;
|
||||
grub_err_t err;
|
||||
ret = grub_malloc (grub_be_to_cpu32 (node->file.size) + 1);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
err = grub_disk_read (node->data->disk,
|
||||
(node->data_addr) >> GRUB_DISK_SECTOR_BITS,
|
||||
(node->data_addr) & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
grub_be_to_cpu32 (node->file.size), ret);
|
||||
if (err)
|
||||
{
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
ret[grub_be_to_cpu32 (node->file.size)] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_romfs_iterate_dir (grub_fshelp_node_t dir,
|
||||
int NESTED_FUNC_ATTR
|
||||
(*hook) (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node))
|
||||
{
|
||||
grub_disk_addr_t caddr;
|
||||
struct grub_romfs_file_header hdr;
|
||||
grub_size_t a = 0;
|
||||
char *name = NULL;
|
||||
unsigned nptr;
|
||||
unsigned i, j;
|
||||
for (caddr = dir->data_addr; caddr;
|
||||
caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1))
|
||||
{
|
||||
grub_disk_addr_t naddr = caddr + sizeof (hdr);
|
||||
grub_uint32_t csum = 0;
|
||||
enum grub_fshelp_filetype filetype = GRUB_FSHELP_UNKNOWN;
|
||||
struct grub_fshelp_node *node;
|
||||
grub_err_t err;
|
||||
|
||||
err = grub_disk_read (dir->data->disk, caddr >> GRUB_DISK_SECTOR_BITS,
|
||||
caddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
sizeof (hdr), &hdr);
|
||||
if (err)
|
||||
{
|
||||
grub_free (name);
|
||||
return 1;
|
||||
}
|
||||
for (nptr = 0; ; nptr++, naddr += 16)
|
||||
{
|
||||
if (a >= nptr)
|
||||
{
|
||||
char *on;
|
||||
a = 2 * (nptr + 1);
|
||||
on = name;
|
||||
name = grub_realloc (name, a * 16);
|
||||
if (!name)
|
||||
{
|
||||
grub_free (on);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
err = grub_disk_read (dir->data->disk, naddr >> GRUB_DISK_SECTOR_BITS,
|
||||
naddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
16, name + 16 * nptr);
|
||||
if (err)
|
||||
return 1;
|
||||
for (j = 0; j < 16; j++)
|
||||
if (!name[16 * nptr + j])
|
||||
break;
|
||||
if (j != 16)
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < sizeof (hdr) / sizeof (grub_uint32_t); i++)
|
||||
csum += grub_be_to_cpu32 (((grub_uint32_t *) &hdr)[i]);
|
||||
for (i = 0; i < (nptr + 1) * 4; i++)
|
||||
csum += grub_be_to_cpu32 (((grub_uint32_t *) name)[i]);
|
||||
if (csum != 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "invalid checksum");
|
||||
grub_free (name);
|
||||
return 1;
|
||||
}
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
return 1;
|
||||
node->addr = caddr;
|
||||
node->data_addr = caddr + (nptr + 1) * 16 + sizeof (hdr);
|
||||
node->data = dir->data;
|
||||
node->file = hdr;
|
||||
switch (grub_be_to_cpu32 (hdr.next_file) & GRUB_ROMFS_TYPE_MASK)
|
||||
{
|
||||
case GRUB_ROMFS_TYPE_REGULAR:
|
||||
filetype = GRUB_FSHELP_REG;
|
||||
break;
|
||||
case GRUB_ROMFS_TYPE_SYMLINK:
|
||||
filetype = GRUB_FSHELP_SYMLINK;
|
||||
break;
|
||||
case GRUB_ROMFS_TYPE_DIRECTORY:
|
||||
node->data_addr = grub_be_to_cpu32 (hdr.spec);
|
||||
filetype = GRUB_FSHELP_DIR;
|
||||
break;
|
||||
case GRUB_ROMFS_TYPE_HARDLINK:
|
||||
{
|
||||
grub_disk_addr_t laddr;
|
||||
node->addr = laddr = grub_be_to_cpu32 (hdr.spec);
|
||||
err = grub_disk_read (dir->data->disk,
|
||||
laddr >> GRUB_DISK_SECTOR_BITS,
|
||||
laddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
sizeof (node->file), &node->file);
|
||||
if (err)
|
||||
return 1;
|
||||
if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK)
|
||||
== GRUB_ROMFS_TYPE_REGULAR
|
||||
|| (grub_be_to_cpu32 (node->file.next_file)
|
||||
& GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_SYMLINK)
|
||||
{
|
||||
laddr += sizeof (hdr);
|
||||
while (1)
|
||||
{
|
||||
char buf[16];
|
||||
err = grub_disk_read (dir->data->disk,
|
||||
laddr >> GRUB_DISK_SECTOR_BITS,
|
||||
laddr & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
16, buf);
|
||||
if (err)
|
||||
return 1;
|
||||
for (i = 0; i < 16; i++)
|
||||
if (!buf[i])
|
||||
break;
|
||||
if (i != 16)
|
||||
break;
|
||||
laddr += 16;
|
||||
}
|
||||
node->data_addr = laddr + 16;
|
||||
}
|
||||
if ((grub_be_to_cpu32 (node->file.next_file)
|
||||
& GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_REGULAR)
|
||||
filetype = GRUB_FSHELP_REG;
|
||||
if ((grub_be_to_cpu32 (node->file.next_file)
|
||||
& GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_SYMLINK)
|
||||
filetype = GRUB_FSHELP_SYMLINK;
|
||||
if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK)
|
||||
== GRUB_ROMFS_TYPE_DIRECTORY)
|
||||
{
|
||||
node->data_addr = grub_be_to_cpu32 (node->file.spec);
|
||||
filetype = GRUB_FSHELP_DIR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hook (name, filetype, node))
|
||||
{
|
||||
grub_free (name);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
grub_free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_romfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_romfs_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0, start;
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
data = grub_romfs_mount (device);
|
||||
if (! data)
|
||||
goto fail;
|
||||
|
||||
start.addr = data->first_file;
|
||||
start.data_addr = data->first_file;
|
||||
start.data = data;
|
||||
grub_fshelp_find_file (path, &start, &fdiro, grub_romfs_iterate_dir,
|
||||
grub_romfs_read_symlink, GRUB_FSHELP_DIR);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
grub_romfs_iterate_dir (fdiro, iterate);
|
||||
|
||||
fail:
|
||||
grub_free (data);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_romfs_open (struct grub_file *file, const char *name)
|
||||
{
|
||||
struct grub_romfs_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0, start;
|
||||
|
||||
data = grub_romfs_mount (file->device);
|
||||
if (! data)
|
||||
goto fail;
|
||||
|
||||
start.addr = data->first_file;
|
||||
start.data_addr = data->first_file;
|
||||
start.data = data;
|
||||
|
||||
grub_fshelp_find_file (name, &start, &fdiro, grub_romfs_iterate_dir,
|
||||
grub_romfs_read_symlink, GRUB_FSHELP_REG);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
file->size = grub_be_to_cpu32 (fdiro->file.size);
|
||||
file->data = fdiro;
|
||||
|
||||
fail:
|
||||
grub_free (data);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_romfs_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
struct grub_fshelp_node *data = file->data;
|
||||
|
||||
/* XXX: The file is stored in as a single extent. */
|
||||
data->data->disk->read_hook = file->read_hook;
|
||||
grub_disk_read (data->data->disk,
|
||||
(data->data_addr + file->offset) >> GRUB_DISK_SECTOR_BITS,
|
||||
(data->data_addr + file->offset) & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
len, buf);
|
||||
data->data->disk->read_hook = NULL;
|
||||
|
||||
if (grub_errno)
|
||||
return -1;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_romfs_close (grub_file_t file)
|
||||
{
|
||||
grub_free (file->data);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_romfs_label (grub_device_t device, char **label)
|
||||
{
|
||||
struct grub_romfs_data *data;
|
||||
grub_err_t err;
|
||||
|
||||
*label = NULL;
|
||||
|
||||
data = grub_romfs_mount (device);
|
||||
if (!data)
|
||||
return grub_errno;
|
||||
*label = grub_malloc (data->first_file + 1
|
||||
- sizeof (struct grub_romfs_superblock));
|
||||
if (!*label)
|
||||
{
|
||||
grub_free (data);
|
||||
return grub_errno;
|
||||
}
|
||||
err = grub_disk_read (device->disk, 0, sizeof (struct grub_romfs_superblock),
|
||||
data->first_file
|
||||
- sizeof (struct grub_romfs_superblock),
|
||||
*label);
|
||||
if (err)
|
||||
{
|
||||
grub_free (data);
|
||||
grub_free (*label);
|
||||
*label = NULL;
|
||||
return err;
|
||||
}
|
||||
(*label)[data->first_file - sizeof (struct grub_romfs_superblock)] = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
static struct grub_fs grub_romfs_fs =
|
||||
{
|
||||
.name = "romfs",
|
||||
.dir = grub_romfs_dir,
|
||||
.open = grub_romfs_open,
|
||||
.read = grub_romfs_read,
|
||||
.close = grub_romfs_close,
|
||||
.label = grub_romfs_label,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(romfs)
|
||||
{
|
||||
grub_fs_register (&grub_romfs_fs);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(romfs)
|
||||
{
|
||||
grub_fs_unregister (&grub_romfs_fs);
|
||||
}
|
|
@ -68,7 +68,7 @@ struct grub_sfs_obj
|
|||
grub_uint32_t dir_objc;
|
||||
} dir __attribute__ ((packed));
|
||||
} file_dir;
|
||||
grub_uint8_t unused3[4];
|
||||
grub_uint32_t mtime;
|
||||
grub_uint8_t type;
|
||||
grub_uint8_t filename[1];
|
||||
grub_uint8_t comment[1];
|
||||
|
@ -121,6 +121,7 @@ struct grub_fshelp_node
|
|||
struct grub_sfs_data *data;
|
||||
int block;
|
||||
int size;
|
||||
grub_uint32_t mtime;
|
||||
};
|
||||
|
||||
/* Information about a "mounted" sfs filesystem. */
|
||||
|
@ -357,10 +358,12 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir,
|
|||
int pos;
|
||||
|
||||
auto int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block,
|
||||
int size, int type);
|
||||
int size, int type,
|
||||
grub_uint32_t mtime);
|
||||
|
||||
int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block,
|
||||
int size, int type)
|
||||
int size, int type,
|
||||
grub_uint32_t mtime)
|
||||
{
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (!node)
|
||||
|
@ -369,6 +372,7 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir,
|
|||
node->data = data;
|
||||
node->size = size;
|
||||
node->block = block;
|
||||
node->mtime = mtime;
|
||||
|
||||
return hook (name, type, node);
|
||||
}
|
||||
|
@ -428,7 +432,7 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir,
|
|||
|
||||
if (grub_sfs_create_node (filename, block,
|
||||
grub_be_to_cpu32 (obj->file_dir.file.size),
|
||||
type))
|
||||
type, grub_be_to_cpu32 (obj->mtime)))
|
||||
{
|
||||
grub_free (objc_data);
|
||||
return 1;
|
||||
|
@ -527,6 +531,8 @@ grub_sfs_dir (grub_device_t device, const char *path,
|
|||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtime = node->mtime + 8 * 365 * 86400 + 86400 * 2;
|
||||
info.mtimeset = 1;
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
|
548
grub-core/fs/squash4.c
Normal file
548
grub-core/fs/squash4.c
Normal file
|
@ -0,0 +1,548 @@
|
|||
/* squash4.c - SquashFS */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/deflate.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/*
|
||||
object format Pointed by
|
||||
superblock RAW Fixed offset (0)
|
||||
data RAW ? Fixed offset (60)
|
||||
inode table Chunk superblock
|
||||
dir table Chunk superblock
|
||||
fragment table Chunk unk1
|
||||
unk1 RAW, Chunk superblock
|
||||
unk2 RAW superblock
|
||||
UID/GID Chunk exttblptr
|
||||
exttblptr RAW superblock
|
||||
|
||||
UID/GID table is the array ot uint32_t
|
||||
unk1 contains pointer to unk3 followed by some chunk.
|
||||
unk2 containts one uint64_t
|
||||
*/
|
||||
|
||||
struct grub_squash_super
|
||||
{
|
||||
grub_uint32_t magic;
|
||||
#define SQUASH_MAGIC 0x73717368
|
||||
grub_uint32_t dummy1;
|
||||
grub_uint32_t creation_time;
|
||||
grub_uint32_t dummy2;
|
||||
grub_uint64_t dummy3;
|
||||
grub_uint8_t flags;
|
||||
#define SQUASH_FLAG_UNCOMPRESSED_INODES 1
|
||||
#define SQUASH_FLAG_UNCOMPRESSED_DATA 2
|
||||
#define SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS 8
|
||||
grub_uint8_t dummy4[7];
|
||||
grub_uint16_t root_ino_offset;
|
||||
grub_uint32_t root_ino_chunk;
|
||||
grub_uint16_t dummy5;
|
||||
grub_uint64_t total_size;
|
||||
grub_uint64_t exttbloffset;
|
||||
grub_uint64_t dummy6;
|
||||
grub_uint64_t inodeoffset;
|
||||
grub_uint64_t diroffset;
|
||||
grub_uint64_t unk1offset;
|
||||
grub_uint64_t unk2offset;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
/* Chunk-based */
|
||||
struct grub_squash_inode
|
||||
{
|
||||
/* Same values as direlem types. */
|
||||
grub_uint16_t type;
|
||||
grub_uint16_t dummy[3];
|
||||
grub_uint32_t mtime;
|
||||
union
|
||||
{
|
||||
struct {
|
||||
grub_uint32_t dummy;
|
||||
grub_uint32_t chunk;
|
||||
grub_uint32_t fragment;
|
||||
grub_uint32_t offset;
|
||||
grub_uint32_t size;
|
||||
} __attribute__ ((packed)) file;
|
||||
struct {
|
||||
grub_uint32_t dummy1;
|
||||
grub_uint32_t chunk;
|
||||
grub_uint32_t dummy2;
|
||||
grub_uint16_t size;
|
||||
grub_uint32_t offset;
|
||||
grub_uint16_t dummy3;
|
||||
} __attribute__ ((packed)) dir;
|
||||
struct {
|
||||
grub_uint64_t dummy;
|
||||
grub_uint32_t namelen;
|
||||
char name[0];
|
||||
} __attribute__ ((packed)) symlink;
|
||||
} __attribute__ ((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* Chunk-based. */
|
||||
struct grub_squash_dirent_header
|
||||
{
|
||||
/* Actually the value is the number of elements - 1. */
|
||||
grub_uint32_t nelems;
|
||||
grub_uint64_t ino_chunk;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_squash_dirent
|
||||
{
|
||||
grub_uint16_t ino_offset;
|
||||
grub_uint16_t dummy;
|
||||
grub_uint16_t type;
|
||||
#define SQUASH_TYPE_DIR 1
|
||||
#define SQUASH_TYPE_REGULAR 2
|
||||
#define SQUASH_TYPE_SYMLINK 3
|
||||
/* Actually the value is the length of name - 1. */
|
||||
grub_uint16_t namelen;
|
||||
char name[0];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_squash_frag_desc
|
||||
{
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t dummy;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define SQUASH_CHUNK_SIZE 0x2000
|
||||
#define SQUASH_CHUNK_FLAGS 0x8000
|
||||
#define SQUASH_CHUNK_UNCOMPRESSED 0x8000
|
||||
|
||||
struct grub_squash_data
|
||||
{
|
||||
grub_disk_t disk;
|
||||
struct grub_squash_super sb;
|
||||
struct grub_squash_inode ino;
|
||||
grub_uint64_t fragments;
|
||||
};
|
||||
|
||||
struct grub_fshelp_node
|
||||
{
|
||||
struct grub_squash_data *data;
|
||||
struct grub_squash_inode ino;
|
||||
grub_uint32_t ino_chunk;
|
||||
grub_uint16_t ino_offset;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
read_chunk (grub_disk_t disk, void *buf, grub_size_t len,
|
||||
grub_uint64_t chunk, grub_off_t offset)
|
||||
{
|
||||
grub_uint64_t chunk_start;
|
||||
chunk_start = grub_le_to_cpu64 (chunk);
|
||||
while (len > 0)
|
||||
{
|
||||
grub_uint64_t csize;
|
||||
grub_uint16_t d;
|
||||
grub_err_t err;
|
||||
while (1)
|
||||
{
|
||||
err = grub_disk_read (disk, chunk_start >> GRUB_DISK_SECTOR_BITS,
|
||||
chunk_start & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
sizeof (d), &d);
|
||||
if (err)
|
||||
return err;
|
||||
if (offset < SQUASH_CHUNK_SIZE)
|
||||
break;
|
||||
offset -= SQUASH_CHUNK_SIZE;
|
||||
chunk_start += 2 + (grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS);
|
||||
}
|
||||
|
||||
csize = SQUASH_CHUNK_SIZE - offset;
|
||||
if (csize > len)
|
||||
csize = len;
|
||||
|
||||
if (grub_le_to_cpu16 (d) & SQUASH_CHUNK_UNCOMPRESSED)
|
||||
{
|
||||
grub_disk_addr_t a = chunk_start + 2 + offset;
|
||||
err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS),
|
||||
a & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
csize, buf);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *tmp;
|
||||
grub_size_t bsize = grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS;
|
||||
grub_disk_addr_t a = chunk_start + 2;
|
||||
tmp = grub_malloc (bsize);
|
||||
if (!tmp)
|
||||
return grub_errno;
|
||||
/* FIXME: buffer uncompressed data. */
|
||||
err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS),
|
||||
a & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
bsize, tmp);
|
||||
if (err)
|
||||
{
|
||||
grub_free (tmp);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (grub_zlib_decompress (tmp, bsize, offset,
|
||||
buf, csize) < 0)
|
||||
{
|
||||
grub_free (tmp);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_free (tmp);
|
||||
}
|
||||
len -= csize;
|
||||
offset += csize;
|
||||
buf = (char *) buf + csize;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_squash_data *
|
||||
squash_mount (grub_disk_t disk)
|
||||
{
|
||||
struct grub_squash_super sb;
|
||||
grub_err_t err;
|
||||
struct grub_squash_data *data;
|
||||
grub_uint64_t frag;
|
||||
|
||||
err = grub_disk_read (disk, 0, 0, sizeof (sb), &sb);
|
||||
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a squash4");
|
||||
if (err)
|
||||
return NULL;
|
||||
if (grub_le_to_cpu32 (sb.magic) != SQUASH_MAGIC)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not squash4");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = grub_disk_read (disk, grub_le_to_cpu32 (sb.unk1offset)
|
||||
>> GRUB_DISK_SECTOR_BITS,
|
||||
grub_le_to_cpu32 (sb.unk1offset)
|
||||
& (GRUB_DISK_SECTOR_SIZE - 1), sizeof (frag), &frag);
|
||||
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a squash4");
|
||||
if (err)
|
||||
return NULL;
|
||||
|
||||
data = grub_malloc (sizeof (*data));
|
||||
if (!data)
|
||||
return NULL;
|
||||
data->sb = sb;
|
||||
data->disk = disk;
|
||||
data->fragments = frag;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_squash_read_symlink (grub_fshelp_node_t node)
|
||||
{
|
||||
char *ret;
|
||||
grub_err_t err;
|
||||
ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1);
|
||||
|
||||
err = read_chunk (node->data->disk, ret,
|
||||
grub_le_to_cpu32 (node->ino.symlink.namelen),
|
||||
grub_le_to_cpu64 (node->data->sb.inodeoffset)
|
||||
+ node->ino_chunk,
|
||||
node->ino_offset + (node->ino.symlink.name
|
||||
- (char *) &node->ino));
|
||||
if (err)
|
||||
{
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
ret[grub_le_to_cpu32 (node->ino.symlink.namelen)] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_squash_iterate_dir (grub_fshelp_node_t dir,
|
||||
int NESTED_FUNC_ATTR
|
||||
(*hook) (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node))
|
||||
{
|
||||
grub_uint32_t off = grub_le_to_cpu16 (dir->ino.dir.offset);
|
||||
grub_uint32_t endoff;
|
||||
unsigned i;
|
||||
|
||||
/* FIXME: why - 3 ? */
|
||||
endoff = grub_le_to_cpu32 (dir->ino.dir.size) + off - 3;
|
||||
|
||||
while (off < endoff)
|
||||
{
|
||||
struct grub_squash_dirent_header dh;
|
||||
grub_err_t err;
|
||||
|
||||
err = read_chunk (dir->data->disk, &dh, sizeof (dh),
|
||||
grub_le_to_cpu64 (dir->data->sb.diroffset)
|
||||
+ grub_le_to_cpu32 (dir->ino.dir.chunk), off);
|
||||
if (err)
|
||||
return 0;
|
||||
off += sizeof (dh);
|
||||
for (i = 0; i < (unsigned) grub_le_to_cpu16 (dh.nelems) + 1; i++)
|
||||
{
|
||||
char *buf;
|
||||
int r;
|
||||
struct grub_fshelp_node *node;
|
||||
enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG;
|
||||
struct grub_squash_dirent di;
|
||||
struct grub_squash_inode ino;
|
||||
|
||||
err = read_chunk (dir->data->disk, &di, sizeof (di),
|
||||
grub_le_to_cpu64 (dir->data->sb.diroffset)
|
||||
+ grub_le_to_cpu32 (dir->ino.dir.chunk), off);
|
||||
if (err)
|
||||
return 0;
|
||||
off += sizeof (di);
|
||||
|
||||
err = read_chunk (dir->data->disk, &ino, sizeof (ino),
|
||||
grub_le_to_cpu64 (dir->data->sb.inodeoffset)
|
||||
+ grub_le_to_cpu32 (dh.ino_chunk),
|
||||
grub_cpu_to_le16 (di.ino_offset));
|
||||
if (err)
|
||||
return 0;
|
||||
|
||||
buf = grub_malloc (grub_le_to_cpu16 (di.namelen) + 2);
|
||||
if (!buf)
|
||||
return 0;
|
||||
err = read_chunk (dir->data->disk, buf,
|
||||
grub_le_to_cpu16 (di.namelen) + 1,
|
||||
grub_le_to_cpu64 (dir->data->sb.diroffset)
|
||||
+ grub_le_to_cpu32 (dir->ino.dir.chunk), off);
|
||||
if (err)
|
||||
return 0;
|
||||
|
||||
off += grub_le_to_cpu16 (di.namelen) + 1;
|
||||
buf[grub_le_to_cpu16 (di.namelen) + 1] = 0;
|
||||
if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_DIR)
|
||||
filetype = GRUB_FSHELP_DIR;
|
||||
if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK)
|
||||
filetype = GRUB_FSHELP_SYMLINK;
|
||||
|
||||
node = grub_malloc (sizeof (*node));
|
||||
if (! node)
|
||||
return 0;
|
||||
*node = *dir;
|
||||
node->ino = ino;
|
||||
node->ino_chunk = grub_le_to_cpu32 (dh.ino_chunk);
|
||||
node->ino_offset = grub_le_to_cpu16 (di.ino_offset);
|
||||
|
||||
r = hook (buf, filetype, node);
|
||||
|
||||
grub_free (buf);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root)
|
||||
{
|
||||
grub_memset (root, 0, sizeof (*root));
|
||||
root->data = data;
|
||||
|
||||
return read_chunk (data->disk, &root->ino, sizeof (root->ino),
|
||||
grub_le_to_cpu64 (data->sb.inodeoffset)
|
||||
+ grub_le_to_cpu16 (data->sb.root_ino_chunk),
|
||||
grub_cpu_to_le16 (data->sb.root_ino_offset));
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_squash_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_le_to_cpu32 (node->ino.mtime);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
struct grub_squash_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
struct grub_fshelp_node root;
|
||||
grub_err_t err;
|
||||
|
||||
data = squash_mount (device->disk);
|
||||
if (! data)
|
||||
return grub_errno;
|
||||
|
||||
err = make_root_node (data, &root);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_fshelp_find_file (path, &root, &fdiro, grub_squash_iterate_dir,
|
||||
grub_squash_read_symlink, GRUB_FSHELP_DIR);
|
||||
if (!grub_errno)
|
||||
grub_squash_iterate_dir (fdiro, iterate);
|
||||
|
||||
grub_free (data);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_squash_open (struct grub_file *file, const char *name)
|
||||
{
|
||||
struct grub_squash_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
struct grub_fshelp_node root;
|
||||
grub_err_t err;
|
||||
|
||||
data = squash_mount (file->device->disk);
|
||||
if (! data)
|
||||
return grub_errno;
|
||||
|
||||
err = make_root_node (data, &root);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_fshelp_find_file (name, &root, &fdiro, grub_squash_iterate_dir,
|
||||
grub_squash_read_symlink, GRUB_FSHELP_REG);
|
||||
if (grub_errno)
|
||||
{
|
||||
grub_free (data);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
file->data = data;
|
||||
data->ino = fdiro->ino;
|
||||
file->size = grub_le_to_cpu32 (fdiro->ino.file.size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_squash_read_data (struct grub_squash_data *data,
|
||||
grub_disk_t disk, const struct grub_squash_inode *ino,
|
||||
grub_off_t off, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_uint64_t a, b;
|
||||
int compressed = 0;
|
||||
|
||||
if (grub_le_to_cpu16 (ino->file.fragment) == 0xffff)
|
||||
{
|
||||
if (grub_le_to_cpu32 (ino->file.chunk))
|
||||
a = grub_le_to_cpu32 (ino->file.chunk);
|
||||
else
|
||||
a = sizeof (struct grub_squash_super);
|
||||
compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct grub_squash_frag_desc frag;
|
||||
err = read_chunk (disk, &frag, sizeof (frag),
|
||||
data->fragments, sizeof (frag)
|
||||
* grub_le_to_cpu16 (ino->file.fragment));
|
||||
if (err)
|
||||
return -1;
|
||||
a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->file.chunk);
|
||||
compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS);
|
||||
}
|
||||
|
||||
b = grub_le_to_cpu32 (data->ino.file.offset) + off;
|
||||
|
||||
/* FIXME: cache uncompressed chunks. */
|
||||
if (compressed)
|
||||
err = grub_zlib_disk_read (disk, a, b, buf, len);
|
||||
else
|
||||
err = grub_disk_read (disk, (a + b) >> GRUB_DISK_SECTOR_BITS,
|
||||
(a + b) & (GRUB_DISK_SECTOR_SIZE - 1), len, buf);
|
||||
if (err)
|
||||
return -1;
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_squash_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
struct grub_squash_data *data = file->data;
|
||||
|
||||
return grub_squash_read_data (data, file->device->disk, &data->ino,
|
||||
file->offset, buf, len);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_squash_close (grub_file_t file)
|
||||
{
|
||||
grub_free (file->data);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_squash_mtime (grub_device_t dev, grub_int32_t *tm)
|
||||
{
|
||||
struct grub_squash_data *data = 0;
|
||||
|
||||
data = squash_mount (dev->disk);
|
||||
if (! data)
|
||||
return grub_errno;
|
||||
*tm = grub_le_to_cpu32 (data->sb.creation_time);
|
||||
grub_free (data);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_fs grub_squash_fs =
|
||||
{
|
||||
.name = "squash4",
|
||||
.dir = grub_squash_dir,
|
||||
.open = grub_squash_open,
|
||||
.read = grub_squash_read,
|
||||
.close = grub_squash_close,
|
||||
.mtime = grub_squash_mtime,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(squash4)
|
||||
{
|
||||
grub_fs_register (&grub_squash_fs);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(squash4)
|
||||
{
|
||||
grub_fs_unregister (&grub_squash_fs);
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/datetime.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -545,8 +546,7 @@ grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
}
|
||||
|
||||
fail:
|
||||
if (buf)
|
||||
grub_free (buf);
|
||||
grub_free (buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -885,6 +885,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
|||
|
||||
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
|
||||
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
|
||||
if (child->fe.icbtag.file_type == GRUB_UDF_ICBTAG_TYPE_SYMLINK)
|
||||
type = GRUB_FSHELP_SYMLINK;
|
||||
|
||||
if ((grub_udf_read_file (dir, 0, offset,
|
||||
dirent.file_ident_length,
|
||||
|
@ -912,6 +914,25 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_ufs_read_symlink (grub_fshelp_node_t node)
|
||||
{
|
||||
grub_size_t sz = U64 (node->fe.file_size);
|
||||
grub_uint8_t *raw;
|
||||
char *ret;
|
||||
|
||||
if (sz < 4)
|
||||
return NULL;
|
||||
raw = grub_malloc (sz - 4);
|
||||
if (!raw)
|
||||
return NULL;
|
||||
if (grub_udf_read_file (node, NULL, 4, sz - 4, (char *) raw) < 0)
|
||||
return NULL;
|
||||
ret = read_string (raw, sz - 4);
|
||||
grub_free (raw);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_udf_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
|
@ -930,8 +951,36 @@ grub_udf_dir (grub_device_t device, const char *path,
|
|||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
const struct grub_udf_timestamp *tstamp = NULL;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE)
|
||||
tstamp = &node->fe.modification_time;
|
||||
else if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_EFE)
|
||||
tstamp = &node->efe.modification_time;
|
||||
|
||||
if (tstamp && (U16 (tstamp->type_and_timezone) & 0xf000) == 0x1000)
|
||||
{
|
||||
grub_int16_t tz;
|
||||
struct grub_datetime datetime;
|
||||
|
||||
datetime.year = U16 (tstamp->year);
|
||||
datetime.month = tstamp->month;
|
||||
datetime.day = tstamp->day;
|
||||
datetime.hour = tstamp->hour;
|
||||
datetime.minute = tstamp->minute;
|
||||
datetime.second = tstamp->second;
|
||||
|
||||
tz = U16 (tstamp->type_and_timezone) & 0xfff;
|
||||
if (tz & 0x800)
|
||||
tz |= 0xf000;
|
||||
if (tz == -2047)
|
||||
tz = 0;
|
||||
|
||||
info.mtimeset = !!grub_datetime2unixtime (&datetime, &info.mtime);
|
||||
|
||||
info.mtime -= 60 * tz;
|
||||
}
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
@ -947,7 +996,8 @@ grub_udf_dir (grub_device_t device, const char *path,
|
|||
|
||||
if (grub_fshelp_find_file (path, &rootnode,
|
||||
&foundnode,
|
||||
grub_udf_iterate_dir, 0, GRUB_FSHELP_DIR))
|
||||
grub_udf_iterate_dir, grub_ufs_read_symlink,
|
||||
GRUB_FSHELP_DIR))
|
||||
goto fail;
|
||||
|
||||
grub_udf_iterate_dir (foundnode, iterate);
|
||||
|
@ -981,7 +1031,8 @@ grub_udf_open (struct grub_file *file, const char *name)
|
|||
|
||||
if (grub_fshelp_find_file (name, &rootnode,
|
||||
&foundnode,
|
||||
grub_udf_iterate_dir, 0, GRUB_FSHELP_REG))
|
||||
grub_udf_iterate_dir, grub_ufs_read_symlink,
|
||||
GRUB_FSHELP_REG))
|
||||
goto fail;
|
||||
|
||||
file->data = foundnode;
|
||||
|
|
|
@ -514,7 +514,7 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
|
|||
pos += grub_le_to_cpu16 (dirent.direntlen);
|
||||
} while (pos < INODE_SIZE (data));
|
||||
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,13 +100,22 @@ struct grub_xfs_btree_root
|
|||
grub_uint64_t keys[1];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_xfs_time
|
||||
{
|
||||
grub_uint32_t sec;
|
||||
grub_uint32_t nanosec;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_xfs_inode
|
||||
{
|
||||
grub_uint8_t magic[2];
|
||||
grub_uint16_t mode;
|
||||
grub_uint8_t version;
|
||||
grub_uint8_t format;
|
||||
grub_uint8_t unused2[50];
|
||||
grub_uint8_t unused2[26];
|
||||
struct grub_xfs_time atime;
|
||||
struct grub_xfs_time mtime;
|
||||
struct grub_xfs_time ctime;
|
||||
grub_uint64_t size;
|
||||
grub_uint64_t nblocks;
|
||||
grub_uint32_t extsize;
|
||||
|
@ -315,8 +324,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
}
|
||||
}
|
||||
|
||||
if (leaf)
|
||||
grub_free (leaf);
|
||||
grub_free (leaf);
|
||||
|
||||
return GRUB_XFS_FSB_TO_BLOCK(node->data, ret);
|
||||
}
|
||||
|
@ -654,6 +662,11 @@ grub_xfs_dir (grub_device_t device, const char *path,
|
|||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
if (node->inode_read)
|
||||
{
|
||||
info.mtimeset = 1;
|
||||
info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec);
|
||||
}
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include <grub/zfs/sa_impl.h>
|
||||
#include <grub/zfs/dsl_dir.h>
|
||||
#include <grub/zfs/dsl_dataset.h>
|
||||
#include <grub/deflate.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -163,13 +164,30 @@ struct grub_zfs_data
|
|||
grub_disk_addr_t vdev_phys_sector;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
zlib_decompress (void *s, void *d,
|
||||
grub_size_t slen, grub_size_t dlen)
|
||||
{
|
||||
if (grub_zlib_decompress (s, slen, 0, d, dlen) < 0)
|
||||
return grub_errno;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = {
|
||||
{"inherit", NULL}, /* ZIO_COMPRESS_INHERIT */
|
||||
{"on", lzjb_decompress}, /* ZIO_COMPRESS_ON */
|
||||
{"off", NULL}, /* ZIO_COMPRESS_OFF */
|
||||
{"lzjb", lzjb_decompress}, /* ZIO_COMPRESS_LZJB */
|
||||
{"empty", NULL}, /* ZIO_COMPRESS_EMPTY */
|
||||
{"gzip", NULL}, /* ZIO_COMPRESS_GZIP */
|
||||
{"gzip-1", zlib_decompress}, /* ZIO_COMPRESS_GZIP1 */
|
||||
{"gzip-2", zlib_decompress}, /* ZIO_COMPRESS_GZIP2 */
|
||||
{"gzip-3", zlib_decompress}, /* ZIO_COMPRESS_GZIP3 */
|
||||
{"gzip-4", zlib_decompress}, /* ZIO_COMPRESS_GZIP4 */
|
||||
{"gzip-5", zlib_decompress}, /* ZIO_COMPRESS_GZIP5 */
|
||||
{"gzip-6", zlib_decompress}, /* ZIO_COMPRESS_GZIP6 */
|
||||
{"gzip-7", zlib_decompress}, /* ZIO_COMPRESS_GZIP7 */
|
||||
{"gzip-8", zlib_decompress}, /* ZIO_COMPRESS_GZIP8 */
|
||||
{"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */
|
||||
};
|
||||
|
||||
static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
|
||||
|
@ -527,7 +545,7 @@ zio_read (blkptr_t * bp, grub_zfs_endian_t endian, void **buf,
|
|||
*buf = NULL;
|
||||
|
||||
checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff;
|
||||
comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7;
|
||||
comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff;
|
||||
lsize = (BP_IS_HOLE(bp) ? 0 :
|
||||
(((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1)
|
||||
<< SPA_MINBLOCKSHIFT));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#! /bin/sh -e
|
||||
#
|
||||
#! /bin/sh
|
||||
set -e
|
||||
|
||||
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
#
|
||||
# This gensymlist.sh is free software; the author
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#! /bin/sh -e
|
||||
#
|
||||
#! /bin/sh
|
||||
set -e
|
||||
|
||||
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
#
|
||||
# This gensymlist.sh is free software; the author
|
||||
|
|
|
@ -47,7 +47,7 @@ grub_register_exported_symbols (void)
|
|||
EOF
|
||||
|
||||
cat <<EOF
|
||||
struct symtab { const char *name; void *addr; };
|
||||
struct symtab { const char *name; void *addr; int isfunc; };
|
||||
struct symtab *p;
|
||||
static struct symtab tab[] =
|
||||
{
|
||||
|
@ -56,16 +56,16 @@ EOF
|
|||
(while read LINE; do echo $LINE; done) \
|
||||
| grep -v '^#' \
|
||||
| sed -n \
|
||||
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/ {"\1", \1},/;p;}' \
|
||||
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/ {"\1", \&\1},/;p;}' \
|
||||
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/ {"\1", \1, 1},/;p;}' \
|
||||
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/ {"\1", \&\1, 0},/;p;}' \
|
||||
| sort -u
|
||||
|
||||
cat <<EOF
|
||||
{0, 0}
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
COMPILE_TIME_ASSERT (sizeof (tab) > sizeof (tab[0]));
|
||||
for (p = tab; p->name; p++)
|
||||
grub_dl_register_symbol (p->name, p->addr, 0);
|
||||
grub_dl_register_symbol (p->name, p->addr, p->isfunc, 0);
|
||||
}
|
||||
EOF
|
||||
|
|
|
@ -48,7 +48,7 @@ struct grub_gui_label
|
|||
char *text;
|
||||
char *template;
|
||||
grub_font_t font;
|
||||
grub_gui_color_t color;
|
||||
grub_video_rgba_color_t color;
|
||||
int value;
|
||||
enum align_mode align;
|
||||
};
|
||||
|
@ -107,7 +107,7 @@ label_paint (void *vself, const grub_video_rect_t *region)
|
|||
grub_gui_set_viewport (&self->bounds, &vpsave);
|
||||
grub_font_draw_string (self->text,
|
||||
self->font,
|
||||
grub_gui_map_color (self->color),
|
||||
grub_video_map_rgba_color (self->color),
|
||||
left_x,
|
||||
grub_font_get_ascent (self->font));
|
||||
grub_gui_restore_viewport (&vpsave);
|
||||
|
@ -186,7 +186,7 @@ label_set_property (void *vself, const char *name, const char *value)
|
|||
}
|
||||
else if (grub_strcmp (name, "color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->color);
|
||||
grub_video_parse_color (value, &self->color);
|
||||
}
|
||||
else if (grub_strcmp (name, "align") == 0)
|
||||
{
|
||||
|
|
|
@ -41,9 +41,9 @@ struct grub_gui_list_impl
|
|||
int item_spacing;
|
||||
grub_font_t item_font;
|
||||
grub_font_t selected_item_font;
|
||||
grub_gui_color_t item_color;
|
||||
grub_video_rgba_color_t item_color;
|
||||
int selected_item_color_set;
|
||||
grub_gui_color_t selected_item_color;
|
||||
grub_video_rgba_color_t selected_item_color;
|
||||
|
||||
int draw_scrollbar;
|
||||
int need_to_recreate_scrollbar;
|
||||
|
@ -269,13 +269,13 @@ draw_menu (list_impl_t self, int num_shown_items)
|
|||
(is_selected && self->selected_item_font
|
||||
? self->selected_item_font
|
||||
: self->item_font);
|
||||
grub_gui_color_t text_color =
|
||||
grub_video_rgba_color_t text_color =
|
||||
((is_selected && self->selected_item_color_set)
|
||||
? self->selected_item_color
|
||||
: self->item_color);
|
||||
grub_font_draw_string (item_title,
|
||||
font,
|
||||
grub_gui_map_color (text_color),
|
||||
grub_video_map_rgba_color (text_color),
|
||||
sel_leftpad + self->icon_width + icon_text_space,
|
||||
(item_top + (item_height - (ascent + descent))
|
||||
/ 2 + ascent));
|
||||
|
@ -431,7 +431,7 @@ list_set_property (void *vself, const char *name, const char *value)
|
|||
}
|
||||
else if (grub_strcmp (name, "item_color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->item_color);
|
||||
grub_video_parse_color (value, &self->item_color);
|
||||
}
|
||||
else if (grub_strcmp (name, "selected_item_color") == 0)
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ list_set_property (void *vself, const char *name, const char *value)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (grub_gui_parse_color (value, &self->selected_item_color)
|
||||
if (grub_video_parse_color (value, &self->selected_item_color)
|
||||
== GRUB_ERR_NONE)
|
||||
self->selected_item_color_set = 1;
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ grub_gui_list_new (void)
|
|||
{
|
||||
list_impl_t self;
|
||||
grub_font_t default_font;
|
||||
grub_gui_color_t default_fg_color;
|
||||
grub_video_rgba_color_t default_fg_color;
|
||||
|
||||
self = grub_zalloc (sizeof (*self));
|
||||
if (! self)
|
||||
|
@ -576,7 +576,7 @@ grub_gui_list_new (void)
|
|||
self->visible = 1;
|
||||
|
||||
default_font = grub_font_get ("Unknown Regular 16");
|
||||
default_fg_color = grub_gui_color_rgb (0, 0, 0);
|
||||
default_fg_color = grub_video_rgba_color_rgb (0, 0, 0);
|
||||
|
||||
self->icon_width = 32;
|
||||
self->icon_height = 32;
|
||||
|
|
|
@ -40,10 +40,10 @@ struct grub_gui_progress_bar
|
|||
int show_text;
|
||||
char *template;
|
||||
grub_font_t font;
|
||||
grub_gui_color_t text_color;
|
||||
grub_gui_color_t border_color;
|
||||
grub_gui_color_t bg_color;
|
||||
grub_gui_color_t fg_color;
|
||||
grub_video_rgba_color_t text_color;
|
||||
grub_video_rgba_color_t border_color;
|
||||
grub_video_rgba_color_t bg_color;
|
||||
grub_video_rgba_color_t fg_color;
|
||||
|
||||
char *theme_dir;
|
||||
int need_to_recreate_pixmaps;
|
||||
|
@ -109,7 +109,7 @@ draw_filled_rect_bar (grub_gui_progress_bar_t self)
|
|||
f.height = self->bounds.height - 2;
|
||||
|
||||
/* Border. */
|
||||
grub_video_fill_rect (grub_gui_map_color (self->border_color),
|
||||
grub_video_fill_rect (grub_video_map_rgba_color (self->border_color),
|
||||
f.x - 1, f.y - 1,
|
||||
f.width + 2, f.height + 2);
|
||||
|
||||
|
@ -117,12 +117,12 @@ draw_filled_rect_bar (grub_gui_progress_bar_t self)
|
|||
int barwidth = (f.width
|
||||
* (self->value - self->start)
|
||||
/ (self->end - self->start));
|
||||
grub_video_fill_rect (grub_gui_map_color (self->bg_color),
|
||||
grub_video_fill_rect (grub_video_map_rgba_color (self->bg_color),
|
||||
f.x + barwidth, f.y,
|
||||
f.width - barwidth, f.height);
|
||||
|
||||
/* Bar foreground. */
|
||||
grub_video_fill_rect (grub_gui_map_color (self->fg_color),
|
||||
grub_video_fill_rect (grub_video_map_rgba_color (self->fg_color),
|
||||
f.x, f.y,
|
||||
barwidth, f.height);
|
||||
}
|
||||
|
@ -161,7 +161,8 @@ draw_text (grub_gui_progress_bar_t self)
|
|||
if (self->template)
|
||||
{
|
||||
grub_font_t font = self->font;
|
||||
grub_video_color_t text_color = grub_gui_map_color (self->text_color);
|
||||
grub_video_color_t text_color =
|
||||
grub_video_map_rgba_color (self->text_color);
|
||||
int width = self->bounds.width;
|
||||
int height = self->bounds.height;
|
||||
char *text;
|
||||
|
@ -298,19 +299,19 @@ progress_bar_set_property (void *vself, const char *name, const char *value)
|
|||
}
|
||||
else if (grub_strcmp (name, "text_color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->text_color);
|
||||
grub_video_parse_color (value, &self->text_color);
|
||||
}
|
||||
else if (grub_strcmp (name, "border_color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->border_color);
|
||||
grub_video_parse_color (value, &self->border_color);
|
||||
}
|
||||
else if (grub_strcmp (name, "bg_color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->bg_color);
|
||||
grub_video_parse_color (value, &self->bg_color);
|
||||
}
|
||||
else if (grub_strcmp (name, "fg_color") == 0)
|
||||
{
|
||||
grub_gui_parse_color (value, &self->fg_color);
|
||||
grub_video_parse_color (value, &self->fg_color);
|
||||
}
|
||||
else if (grub_strcmp (name, "bar_style") == 0)
|
||||
{
|
||||
|
@ -379,9 +380,9 @@ grub_gui_progress_bar_new (void)
|
|||
self->progress.component.ops = &progress_bar_ops;
|
||||
self->visible = 1;
|
||||
self->font = grub_font_get ("Unknown Regular 16");
|
||||
grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 };
|
||||
grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 };
|
||||
grub_gui_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 };
|
||||
grub_video_rgba_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 };
|
||||
grub_video_rgba_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 };
|
||||
grub_video_rgba_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 };
|
||||
self->text_color = black;
|
||||
self->border_color = black;
|
||||
self->bg_color = gray;
|
||||
|
|
|
@ -204,124 +204,3 @@ grub_get_dirname (const char *file_path)
|
|||
|
||||
return grub_new_substring (file_path, 0, last_slash + 1);
|
||||
}
|
||||
|
||||
static __inline int
|
||||
my_isxdigit (char c)
|
||||
{
|
||||
return ((c >= '0' && c <= '9')
|
||||
|| (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static int
|
||||
parse_hex_color_component (const char *s, unsigned start, unsigned end)
|
||||
{
|
||||
unsigned len;
|
||||
char buf[3];
|
||||
|
||||
len = end - start;
|
||||
/* Check the limits so we don't overrun the buffer. */
|
||||
if (len < 1 || len > 2)
|
||||
return 0;
|
||||
|
||||
if (len == 1)
|
||||
{
|
||||
buf[0] = s[start]; /* Get the first and only hex digit. */
|
||||
buf[1] = buf[0]; /* Duplicate the hex digit. */
|
||||
}
|
||||
else if (len == 2)
|
||||
{
|
||||
buf[0] = s[start];
|
||||
buf[1] = s[start + 1];
|
||||
}
|
||||
|
||||
buf[2] = '\0';
|
||||
|
||||
return grub_strtoul (buf, 0, 16);
|
||||
}
|
||||
|
||||
/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA",
|
||||
"#RRGGBB", or "#RRGGBBAA". */
|
||||
grub_err_t
|
||||
grub_gui_parse_color (const char *s, grub_gui_color_t *color)
|
||||
{
|
||||
grub_gui_color_t c;
|
||||
|
||||
/* Skip whitespace. */
|
||||
while (*s && grub_isspace (*s))
|
||||
s++;
|
||||
|
||||
if (*s == '#')
|
||||
{
|
||||
/* HTML-style. Number if hex digits:
|
||||
[6] #RRGGBB [3] #RGB
|
||||
[8] #RRGGBBAA [4] #RGBA */
|
||||
|
||||
s++; /* Skip the '#'. */
|
||||
/* Count the hexits to determine the format. */
|
||||
int hexits = 0;
|
||||
const char *end = s;
|
||||
while (my_isxdigit (*end))
|
||||
{
|
||||
end++;
|
||||
hexits++;
|
||||
}
|
||||
|
||||
/* Parse the color components based on the format. */
|
||||
if (hexits == 3 || hexits == 4)
|
||||
{
|
||||
c.red = parse_hex_color_component (s, 0, 1);
|
||||
c.green = parse_hex_color_component (s, 1, 2);
|
||||
c.blue = parse_hex_color_component (s, 2, 3);
|
||||
if (hexits == 4)
|
||||
c.alpha = parse_hex_color_component (s, 3, 4);
|
||||
else
|
||||
c.alpha = 255;
|
||||
}
|
||||
else if (hexits == 6 || hexits == 8)
|
||||
{
|
||||
c.red = parse_hex_color_component (s, 0, 2);
|
||||
c.green = parse_hex_color_component (s, 2, 4);
|
||||
c.blue = parse_hex_color_component (s, 4, 6);
|
||||
if (hexits == 8)
|
||||
c.alpha = parse_hex_color_component (s, 6, 8);
|
||||
else
|
||||
c.alpha = 255;
|
||||
}
|
||||
else
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"invalid HTML-type color string `%s'", s);
|
||||
}
|
||||
else if (grub_isdigit (*s))
|
||||
{
|
||||
/* Comma separated decimal values. */
|
||||
c.red = grub_strtoul (s, 0, 0);
|
||||
if ((s = grub_strchr (s, ',')) == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"missing 1st comma separator in color `%s'", s);
|
||||
s++;
|
||||
c.green = grub_strtoul (s, 0, 0);
|
||||
if ((s = grub_strchr (s, ',')) == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"missing 2nd comma separator in color `%s'", s);
|
||||
s++;
|
||||
c.blue = grub_strtoul (s, 0, 0);
|
||||
if ((s = grub_strchr (s, ',')) == 0)
|
||||
c.alpha = 255;
|
||||
else
|
||||
{
|
||||
s++;
|
||||
c.alpha = grub_strtoul (s, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! grub_gui_get_named_color (s, &c))
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"invalid named color `%s'", s);
|
||||
}
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
*color = c;
|
||||
return grub_errno;
|
||||
}
|
||||
|
|
|
@ -135,11 +135,11 @@ theme_set_string (grub_gfxmenu_view_t view,
|
|||
return grub_errno;
|
||||
}
|
||||
else if (! grub_strcmp ("title-color", name))
|
||||
grub_gui_parse_color (value, &view->title_color);
|
||||
grub_video_parse_color (value, &view->title_color);
|
||||
else if (! grub_strcmp ("message-color", name))
|
||||
grub_gui_parse_color (value, &view->message_color);
|
||||
grub_video_parse_color (value, &view->message_color);
|
||||
else if (! grub_strcmp ("message-bg-color", name))
|
||||
grub_gui_parse_color (value, &view->message_bg_color);
|
||||
grub_video_parse_color (value, &view->message_bg_color);
|
||||
else if (! grub_strcmp ("desktop-image", name))
|
||||
{
|
||||
struct grub_video_bitmap *raw_bitmap;
|
||||
|
@ -170,7 +170,7 @@ theme_set_string (grub_gfxmenu_view_t view,
|
|||
view->desktop_image = scaled_bitmap;
|
||||
}
|
||||
else if (! grub_strcmp ("desktop-color", name))
|
||||
grub_gui_parse_color (value, &view->desktop_color);
|
||||
grub_video_parse_color (value, &view->desktop_color);
|
||||
else if (! grub_strcmp ("terminal-box", name))
|
||||
{
|
||||
grub_err_t err;
|
||||
|
|
|
@ -50,8 +50,8 @@ grub_gfxmenu_view_new (const char *theme_path,
|
|||
{
|
||||
grub_gfxmenu_view_t view;
|
||||
grub_font_t default_font;
|
||||
grub_gui_color_t default_fg_color;
|
||||
grub_gui_color_t default_bg_color;
|
||||
grub_video_rgba_color_t default_fg_color;
|
||||
grub_video_rgba_color_t default_bg_color;
|
||||
|
||||
view = grub_malloc (sizeof (*view));
|
||||
if (! view)
|
||||
|
@ -63,8 +63,8 @@ grub_gfxmenu_view_new (const char *theme_path,
|
|||
view->screen.height = height;
|
||||
|
||||
default_font = grub_font_get ("Unknown Regular 16");
|
||||
default_fg_color = grub_gui_color_rgb (0, 0, 0);
|
||||
default_bg_color = grub_gui_color_rgb (255, 255, 255);
|
||||
default_fg_color = grub_video_rgba_color_rgb (0, 0, 0);
|
||||
default_bg_color = grub_video_rgba_color_rgb (255, 255, 255);
|
||||
|
||||
view->canvas = 0;
|
||||
|
||||
|
@ -131,7 +131,7 @@ redraw_background (grub_gfxmenu_view_t view,
|
|||
}
|
||||
else
|
||||
{
|
||||
grub_video_fill_rect (grub_gui_map_color (view->desktop_color),
|
||||
grub_video_fill_rect (grub_video_map_rgba_color (view->desktop_color),
|
||||
bounds->x, bounds->y,
|
||||
bounds->width, bounds->height);
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ draw_title (grub_gfxmenu_view_t view)
|
|||
int y = 40 + grub_font_get_ascent (view->title_font);
|
||||
grub_font_draw_string (view->title_text,
|
||||
view->title_font,
|
||||
grub_gui_map_color (view->title_color),
|
||||
grub_video_map_rgba_color (view->title_color),
|
||||
x, y);
|
||||
}
|
||||
|
||||
|
@ -244,13 +244,13 @@ draw_message (grub_gfxmenu_view_t view)
|
|||
return;
|
||||
|
||||
grub_font_t font = view->message_font;
|
||||
grub_video_color_t color = grub_gui_map_color (view->message_color);
|
||||
grub_video_color_t color = grub_video_map_rgba_color (view->message_color);
|
||||
|
||||
/* Border. */
|
||||
grub_video_fill_rect (color,
|
||||
f.x-1, f.y-1, f.width+2, f.height+2);
|
||||
/* Fill. */
|
||||
grub_video_fill_rect (grub_gui_map_color (view->message_bg_color),
|
||||
grub_video_fill_rect (grub_video_map_rgba_color (view->message_bg_color),
|
||||
f.x, f.y, f.width, f.height);
|
||||
|
||||
/* Center the text. */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue