Compare commits

...

120 Commits

Author SHA1 Message Date
Vladimir Serbinenko
3bf4907004 indent code coming from depthcharge and add missing acknowledgements 2017-05-08 22:21:31 +02:00
Vladimir Serbinenko
8af937d133 Fix spurious diffs with master 2017-05-08 22:16:47 +02:00
Vladimir Serbinenko
fc4b6e8b19 Merge branch 'master' into arm_coreboot 2017-05-08 22:15:39 +02:00
Vladimir Serbinenko
d11ced1e1f arm_coreboot: Support EHCI. 2017-05-08 22:15:05 +02:00
Vladimir Serbinenko
e824ec487b Merge branch 'master' into arm_coreboot 2017-05-08 22:12:00 +02:00
Vladimir Serbinenko
058df7b5a9 ehci: Split core code from PCI part.
On ARM often EHCI is present without PCI and just declared in device
tree. So splitcore from PCI part.
2017-05-08 22:10:26 +02:00
Vladimir Serbinenko
456f220e6a Merge branch 'master' into arm_coreboot 2017-05-08 22:06:47 +02:00
Vladimir Serbinenko
265292f2b0 arm_coreboot: Support DMA.
This is needed to support USB and some other busses.
2017-05-08 22:06:04 +02:00
Vladimir Serbinenko
187f78ec11 Merge branch 'master' into arm_coreboot 2017-05-08 22:01:33 +02:00
Vladimir Serbinenko
656c3b0d7f arm_coreboot: Support loading linux images. 2017-05-08 22:00:06 +02:00
Vladimir Serbinenko
3edabad8fe arm_coreboot: Support grub-mkstandalone. 2017-05-08 21:59:48 +02:00
Vladimir Serbinenko
848bed9d92 arm_coreboot: Support keyboard for vexpress. 2017-05-08 21:42:37 +02:00
Vladimir Serbinenko
216950a4ee at_keyboard: Split protocol from controller code.
On vexpress controller is different but protocol is the same, so reuse the
code.
2017-05-08 21:41:22 +02:00
Vladimir Serbinenko
0558f4cd9b fix mismerge 2017-05-08 21:31:00 +02:00
Vladimir Serbinenko
ac6b41b89f arm-coreboot: Export FDT routines.
We need to use them from modules as well.
2017-05-08 21:29:48 +02:00
Vladimir Serbinenko
80c274084d Merge branch 'master' into arm_coreboot 2017-05-08 21:27:08 +02:00
Vladimir Serbinenko
5a865b3786 arm-coreboot: Support for vexpress timer. 2017-05-08 21:26:36 +02:00
Vladimir Serbinenko
2fee7bb8de Merge branch 'master' into arm_coreboot 2017-05-08 21:21:28 +02:00
Vladimir Serbinenko
fcbb723d4b Add support for device-tree-based drivers. 2017-05-08 21:19:59 +02:00
Vladimir Serbinenko
642ff2676f fix mismerge 2017-05-08 21:08:02 +02:00
Vladimir Serbinenko
46f08fb93b Merge branch 'master' into arm_coreboot 2017-05-08 21:06:51 +02:00
Vladimir Serbinenko
24e37a8852 arm-coreboot: Start new port. 2017-05-08 20:53:28 +02:00
Vladimir Serbinenko
9808c3ef95 Rename uboot/datetime to dummy/datetime.
It's just a stub and is not UBoot-specific.
2017-05-08 19:40:14 +02:00
Vladimir Serbinenko
1daa716c70 Rename uboot/halt.c to dummy/halt.c.
It's not U-Boot specific and it's a stub.
2017-05-08 19:33:56 +02:00
Vladimir Serbinenko
461bfab7b7 coreboot: Split parts that are platform-independent.
We currently assume that coreboot is always i386, it's no longer the case,
so split i386-coreboot parts from generic coreboot code.
2017-05-08 19:10:24 +02:00
Vladimir Serbinenko
b0300c6048 Merge branch 'master' into arm_coreboot 2017-05-08 17:51:27 +02:00
Vladimir Serbinenko
d08c968514 Refactor arm-uboot code to make it genereic.
arm-coreboot startup code can be very similar to arm-uboot but current code has
U-Boot specific references. So split U-Boot part from generic part.
2017-05-08 17:47:57 +02:00
Vladimir Serbinenko
a35ac85430 mkimage: Pass layout to mkimage_generate_elfXX rather than some fields.
This allows easier extension of this function without having too long of
arguments list.
2017-05-08 17:32:15 +02:00
Vladimir Serbinenko
3e6d59d7cb Remove spurious diff with master 2017-05-08 16:47:51 +02:00
Paulo Flabiano Smorigo
d9f7de0ae3 Add Virtual LAN support.
This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging allows
multiple VLANs in a bridged network to share the same physical network link
but maintain isolation:

http://en.wikipedia.org/wiki/IEEE_802.1Q

* grub-core/net/ethernet.c: Add check, get, and set vlan tag id.
* grub-core/net/drivers/ieee1275/ofnet.c: Get vlan tag id from bootargs.
* grub-core/net/arp.c: Add check.
* grub-core/net/ip.c: Likewise.
* include/grub/net/arp.h: Add vlantag attribute.
* include/grub/net/ip.h: Likewise.
2017-05-03 13:03:50 +02:00
Vladimir Serbinenko
dc6e1b5af8 strtoull: Fix behaviour on chars between '9' and 'a'.
Reported by: Aaron Miller <aaronmiller@fb.com>
2017-05-03 12:59:58 +02:00
Vladimir Serbinenko
ede6c96893 Add strtoull test. 2017-05-03 12:58:15 +02:00
Vladimir Serbinenko
a827807a13 Fix shebang for termux.
Termux doesn't have a /bin/sh. So we needto use $SHELL.
Keep /bin/sh as much as possible.
2017-05-03 12:49:31 +02:00
Vladimir Serbinenko
1073ddb120 Add termux path to dict. 2017-05-03 12:48:00 +02:00
Vladimir Serbinenko
4341f82af0 po: Use @SHELL@ rather than /bin/sh.
/bin/sh might not exist.
2017-05-03 12:46:48 +02:00
Vladimir Serbinenko
c2ea443446 Use $(SHELL) rather than /bin/sh.
/bin/sh doesn't exist under termux.
2017-05-03 12:46:38 +02:00
Vladimir Serbinenko
608bec5112 Support lseek64.
Android doesn't have 64-bit off_t, so use off64_t instead.
2017-05-03 12:24:43 +02:00
Vladimir Serbinenko
6dec3a26b3 Don't retrieve fstime when it's not useful. 2017-05-03 12:23:15 +02:00
Vladimir Serbinenko
b43b8cacc8 support busybox date.
Busybox date doesn't understand weekdays in -d input,
so strip them beforehand.
2017-05-03 12:22:05 +02:00
Vladimir Serbinenko
37865c2c4a fs-tester: make sh-compatible 2017-05-03 12:19:44 +02:00
Vladimir Serbinenko
5a0c548ba3 Remove bashisms from tests.
Those tests don't actually need bash. Just use common shebang.
2017-05-03 12:10:36 +02:00
Vladimir Serbinenko
9f8f747605 usbtrans: Fix memory coherence 2016-02-23 12:07:01 +01:00
Vladimir Serbinenko
102016960d ehci: Fix memory coherence 2016-02-23 12:06:48 +01:00
Vladimir Serbinenko
07cd46627b arm: implement grub_arch_sync_dma_caches 2016-02-23 12:06:00 +01:00
Vladimir Serbinenko
9e161d1302 Make dma_caches accept volatile 2016-02-23 11:45:29 +01:00
Vladimir Serbinenko
06c92907c1 cros fix 2016-02-23 11:26:35 +01:00
Vladimir Serbinenko
74cef4ab78 cleaner 2016-02-23 10:19:26 +01:00
Vladimir Serbinenko
f4116c3a42 Decrease frame timeout 2016-02-23 10:15:05 +01:00
Vladimir Serbinenko
2d56c1b117 cleaner 2016-02-23 09:52:08 +01:00
Vladimir Serbinenko
1f72ca020d cleaner 2016-02-23 09:50:43 +01:00
Vladimir Serbinenko
3d300d7247 cleaner 2016-02-23 09:43:57 +01:00
Vladimir Serbinenko
03104c2d98 always use older cros protocol. We don't realy need new one 2016-02-23 09:42:09 +01:00
Vladimir Serbinenko
40562ddf1e cros e0 fix 2016-02-22 21:12:50 +01:00
Vladimir Serbinenko
1ea06af1ae EHCI FDT missing file 2016-02-22 20:40:16 +01:00
Vladimir Serbinenko
df21b9363d cleaner 2016-02-22 19:44:39 +01:00
Vladimir Serbinenko
8efde40d0c cleaner 2016-02-22 19:44:09 +01:00
Vladimir Serbinenko
d624e04af1 cleaner 2016-02-22 19:39:30 +01:00
Vladimir Serbinenko
bbd85a0292 cleaner 2016-02-22 19:38:26 +01:00
Vladimir Serbinenko
4f06545767 cleaner 2016-02-22 19:37:37 +01:00
Vladimir Serbinenko
66d0e16425 cleaner 2016-02-22 19:35:46 +01:00
Vladimir Serbinenko
a98c706755 cleaner 2016-02-22 19:35:16 +01:00
Vladimir Serbinenko
95f663ec1d cleaner 2016-02-22 19:34:30 +01:00
Vladimir Serbinenko
2b2a338ad6 cleaner 2016-02-22 19:33:34 +01:00
Vladimir Serbinenko
6c9512b610 cleaner 2016-02-22 19:33:13 +01:00
Vladimir Serbinenko
f447b3d2bb Dirty cros keyboard import 2016-02-22 19:29:47 +01:00
Vladimir Serbinenko
295fe6c548 Dirty cros keyboard 2016-02-22 19:29:08 +01:00
Vladimir Serbinenko
9cd85f276f frequency 2016-02-22 03:34:35 +01:00
Vladimir Serbinenko
502a7c48e9 ARM caches 2016-02-22 03:34:16 +01:00
Vladimir Serbinenko
418b32f8e9 EHCI reset fix 2016-02-22 03:33:59 +01:00
Vladimir Serbinenko
98490fc328 DMA split 2016-02-22 03:33:18 +01:00
Vladimir Serbinenko
3625fdc0b9 Improve EHCI logging 2016-02-22 03:32:50 +01:00
Vladimir Serbinenko
1ec2b7758b ehci split fixup 2016-02-22 03:28:10 +01:00
Vladimir Serbinenko
f51e8d0dda coreboot 2016-02-22 03:27:39 +01:00
Vladimir Serbinenko
ee52ea80d6 Remove useless include 2016-02-22 03:25:50 +01:00
Vladimir Serbinenko
c55f74a5c5 ehci split 2016-02-22 01:08:27 +01:00
Vladimir Serbinenko
3b1bb7f3eb DTB overrides 2016-02-22 00:05:40 +01:00
Vladimir Serbinenko
0b71582111 coreboot 2016-02-21 20:28:10 +01:00
Vladimir Serbinenko
dc491ff04a fdtbus 2016-02-21 20:27:50 +01:00
Vladimir Serbinenko
192243b13e Out-of-place FDT handling 2016-02-21 20:27:28 +01:00
Vladimir Serbinenko
0f3ae7324a fdt 2016-02-21 19:48:57 +01:00
Vladimir Serbinenko
ab8770a314 pre-located image for veyron 2016-02-21 19:28:56 +01:00
Vladimir Serbinenko
f2df41cffa coreboot 2016-02-21 19:28:40 +01:00
Vladimir Serbinenko
b0227ce4b9 fdt: relax align requirement 2016-02-21 19:28:23 +01:00
Vladimir Serbinenko
f900bea454 coreboot 2016-02-21 18:59:14 +01:00
Vladimir Serbinenko
dc51ac70ee switch to layout 2016-02-21 18:47:29 +01:00
Vladimir Serbinenko
869a0bc476 coreboot 2016-02-21 18:44:55 +01:00
Vladimir Serbinenko
f9ee0c3e5d Simplify reloc 2016-02-21 18:44:18 +01:00
Vladimir Serbinenko
8af26e386c coreboot reloc 2016-02-21 18:42:35 +01:00
Vladimir Serbinenko
78e9b82d2c coreboot memory before _start 2016-02-21 18:41:39 +01:00
Vladimir Serbinenko
86139504b7 pl050 2016-02-21 01:53:44 +01:00
Vladimir Serbinenko
35c1d629f9 fdtbus 2016-02-21 01:53:07 +01:00
Vladimir Serbinenko
bacb8f911f coreboot 2016-02-21 00:05:38 +01:00
Vladimir Serbinenko
fbda565356 fdt 2016-02-21 00:05:21 +01:00
Vladimir Serbinenko
598185f806 fdtbus 2016-02-21 00:04:18 +01:00
Vladimir Serbinenko
ca2fd6c93f ps2 split 2016-02-20 18:45:42 +01:00
Vladimir Serbinenko
a29fb4722c coreboot 2016-02-20 16:26:23 +01:00
Vladimir Serbinenko
7562f4ab53 bus fdt improvements 2016-02-20 16:25:39 +01:00
Vladimir Serbinenko
c7d0aa5450 fdtbus 2016-02-20 14:30:43 +01:00
Vladimir Serbinenko
ceb68c6648 missing files 2016-02-20 14:29:01 +01:00
Vladimir Serbinenko
99291427d2 fdtlib 2016-02-20 14:28:37 +01:00
Vladimir Serbinenko
6ffee98e1b Useless fdt.lst 2016-02-20 14:22:34 +01:00
Vladimir Serbinenko
a6649f5b8e FDT lib improvements 2016-02-20 12:30:06 +01:00
Vladimir Serbinenko
c3c14cffef refresh before abort 2016-02-20 09:12:15 +01:00
Vladimir Serbinenko
84939af253 generic timer safeguard 2016-02-20 09:12:02 +01:00
Vladimir Serbinenko
ba6d40e8bb WIP2 2016-02-19 16:47:36 +01:00
Vladimir Serbinenko
2c3a054f4f WIP 2016-02-19 12:41:50 +01:00
Vladimir Serbinenko
b8eda96422 rename 2016-02-19 12:17:56 +01:00
Vladimir Serbinenko
ca3962ca7b fix relocate 2016-02-19 12:17:20 +01:00
Vladimir Serbinenko
a4f7d77f7d fs 2016-02-19 04:48:50 +01:00
Vladimir Serbinenko
5099975ace fd 2016-02-19 04:48:17 +01:00
Vladimir Serbinenko
2f98d7648e Move cbfb 2016-02-19 04:47:02 +01:00
Vladimir Serbinenko
018e382144 decouple 2016-02-19 04:31:59 +01:00
Vladimir Serbinenko
f5cba79512 Declare arm-coreboot 2016-02-19 03:24:49 +01:00
Vladimir Serbinenko
46569db585 arm-uboot: Make self-relocatable to allow loading at any address 2016-02-19 03:22:10 +01:00
Vladimir Serbinenko
575c7a6e3c Allow _start == 0 with relocatable images 2016-02-19 02:03:28 +01:00
Vladimir Serbinenko
fc489a889d Provide __bss_start and _end symbols in grub-mkimage.
For this ensure that all bss sections are merged.
2016-02-19 02:02:50 +01:00
Vladimir Serbinenko
bfb517bc3b encapsulate 2016-02-19 01:58:11 +01:00
Vladimir Serbinenko
437dba573f Remove useless ifdef 2016-02-19 01:28:16 +01:00
Vladimir Serbinenko
974ba94330 mkimagexx: Split PE and generic part. 2016-02-19 01:14:12 +01:00
Vladimir Serbinenko
963d21b76c file split 2016-02-19 01:14:12 +01:00
133 changed files with 3439 additions and 1183 deletions

View File

@@ -86,9 +86,11 @@ CPPFLAGS_TERMINAL_LIST += '-Dgrub_term_register_output(...)=OUTPUT_TERMINAL_LIST
CPPFLAGS_COMMAND_LIST = '-Dgrub_register_command(...)=COMMAND_LIST_MARKER(__VA_ARGS__)'
CPPFLAGS_COMMAND_LIST += '-Dgrub_register_extcmd(...)=EXTCOMMAND_LIST_MARKER(__VA_ARGS__)'
CPPFLAGS_COMMAND_LIST += '-Dgrub_register_command_p1(...)=P1COMMAND_LIST_MARKER(__VA_ARGS__)'
CPPFLAGS_FDT_LIST := '-Dgrub_fdtbus_register(...)=FDT_DRIVER_LIST_MARKER(__VA_ARGS__)'
CPPFLAGS_MARKER = $(CPPFLAGS_FS_LIST) $(CPPFLAGS_VIDEO_LIST) \
$(CPPFLAGS_PARTTOOL_LIST) $(CPPFLAGS_PARTMAP_LIST) \
$(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST)
$(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST) \
$(CPPFLAGS_FDT_LIST)
# Define these variables to calm down automake

View File

@@ -167,6 +167,7 @@ case "$target_cpu"-"$platform" in
mipsel-fuloong) platform=loongson ;;
mipsel-loongson) ;;
arm-uboot) ;;
arm-coreboot) ;;
arm-efi) ;;
arm64-efi) ;;
*-emu) ;;
@@ -373,7 +374,10 @@ case "$host_os" in
;;
*)
AC_CHECK_SIZEOF(off_t)
test x"$ac_cv_sizeof_off_t" = x8 || AC_MSG_ERROR([Large file support is required]);;
if test x"$ac_cv_sizeof_off_t" != x8 ; then
AC_CHECK_SIZEOF(off64_t)
test x"$ac_cv_sizeof_off64_t" = x8 || AC_MSG_ERROR([Large file support is required])
fi;;
esac
if test x$USE_NLS = xno; then
@@ -456,6 +460,16 @@ case "$build_os" in
esac
AC_SUBST(BUILD_EXEEXT)
# In some build environments like termux /bin/sh is not a valid
# shebang. Use $SHELL instead if it's executable and /bin/sh isn't
BUILD_SHEBANG=/bin/sh
for she in /bin/sh "$SHELL"; do
if test -x "$she" ; then
BUILD_SHEBANG="$she"
fi
done
AC_SUBST(BUILD_SHEBANG)
# For gnulib.
gl_INIT
@@ -1905,6 +1919,7 @@ AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot])
AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])

View File

@@ -31,7 +31,8 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
"i386_xen", "x86_64_xen",
"mips_loongson", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ]
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
"arm_coreboot"]
GROUPS = {}
@@ -44,7 +45,7 @@ GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
GROUPS["arm"] = [ "arm_uboot", "arm_efi" ]
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
GROUPS["arm64"] = [ "arm64_efi" ]
# Groups based on firmware
@@ -52,6 +53,7 @@ GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi"
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
GROUPS["uboot"] = [ "arm_uboot" ]
GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ]
GROUPS["coreboot"] = [ "i386_coreboot", "arm_coreboot" ]
# emu is a special case so many core functionality isn't needed on this platform
GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
@@ -61,10 +63,10 @@ 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"]
GROUPS["usb"] = GROUPS["pci"] + ["arm_coreboot"]
# If gfxterm is main output console integrate it into kernel
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot" ]
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)

View File

@@ -112,7 +112,7 @@ endif
if COND_i386_coreboot
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/coreboot/lbio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
@@ -239,6 +239,20 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
endif
if COND_arm_coreboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.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/bufio.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h
endif
if COND_arm_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/efi/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
@@ -278,7 +292,7 @@ BUILT_SOURCES += symlist.h
symlist.c: symlist.h gensymlist.sh
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1)
cat symlist.p | /bin/sh $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
rm -f symlist.p
CLEANFILES += symlist.c
BUILT_SOURCES += symlist.c
@@ -358,6 +372,16 @@ terminal.lst: $(MARKER_FILES)
platform_DATA += terminal.lst
CLEANFILES += terminal.lst
fdt.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += fdt.lst
CLEANFILES += fdt.lst
parttool.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \

View File

@@ -92,6 +92,8 @@ kernel = {
emu_cppflags = '$(CPPFLAGS_GNULIB)';
arm_uboot_ldflags = '-Wl,-r,-d';
arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
arm_coreboot_ldflags = '-Wl,-r,-d';
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
i386_pc_startup = kern/i386/pc/startup.S;
i386_efi_startup = kern/i386/efi/startup.S;
@@ -105,7 +107,8 @@ kernel = {
mips_startup = kern/mips/startup.S;
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
arm_uboot_startup = kern/arm/uboot/startup.S;
arm_uboot_startup = kern/arm/startup.S;
arm_coreboot_startup = kern/arm/startup.S;
arm_efi_startup = kern/arm/efi/startup.S;
arm64_efi_startup = kern/arm64/efi/startup.S;
@@ -149,6 +152,20 @@ kernel = {
uboot = kern/uboot/init.c;
uboot = kern/uboot/hw.c;
uboot = term/uboot/console.c;
arm_uboot = kern/arm/uboot/init.c;
arm_uboot = kern/arm/uboot/uboot.S;
arm_coreboot = kern/arm/coreboot/init.c;
arm_coreboot = kern/arm/coreboot/timer.c;
arm_coreboot = kern/arm/coreboot/coreboot.S;
arm_coreboot = lib/fdt.c;
arm_coreboot = bus/fdt.c;
arm_coreboot = term/ps2.c;
arm_coreboot = term/arm/pl050.c;
arm_coreboot = term/arm/cros.c;
arm_coreboot = term/arm/cros_ec.c;
arm_coreboot = commands/keylayouts.c;
arm_coreboot = kern/arm/coreboot/dma.c;
terminfoinkernel = term/terminfo.c;
terminfoinkernel = term/tparm.c;
@@ -164,7 +181,7 @@ kernel = {
i386_multiboot = kern/i386/coreboot/init.c;
i386_qemu = kern/i386/qemu/init.c;
i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c;
i386_coreboot = video/i386/coreboot/cbfb.c;
coreboot = video/coreboot/cbfb.c;
efi = disk/efi/efidisk.c;
efi = kern/efi/efi.c;
@@ -225,8 +242,10 @@ kernel = {
i386_qemu = kern/vga_init.c;
i386_qemu = kern/i386/qemu/mmap.c;
i386_coreboot = kern/i386/coreboot/mmap.c;
coreboot = kern/coreboot/mmap.c;
i386_coreboot = kern/i386/coreboot/cbtable.c;
coreboot = kern/coreboot/cbtable.c;
arm_coreboot = kern/arm/coreboot/cbtable.c;
i386_multiboot = kern/i386/multiboot_mmap.c;
@@ -238,6 +257,7 @@ kernel = {
mips_qemu_mips = term/ns8250.c;
mips_qemu_mips = term/serial.c;
mips_qemu_mips = term/at_keyboard.c;
mips_qemu_mips = term/ps2.c;
mips_qemu_mips = commands/boot.c;
mips_qemu_mips = commands/keylayouts.c;
mips_qemu_mips = term/i386/pc/vga_text.c;
@@ -253,6 +273,7 @@ kernel = {
mips_loongson = bus/pci.c;
mips_loongson = kern/mips/loongson/init.c;
mips_loongson = term/at_keyboard.c;
mips_loongson = term/ps2.c;
mips_loongson = commands/boot.c;
mips_loongson = term/serial.c;
mips_loongson = video/sm712.c;
@@ -574,7 +595,10 @@ module = {
module = {
name = ehci;
common = bus/usb/ehci.c;
arm_coreboot = bus/usb/ehci-fdt.c;
pci = bus/usb/ehci-pci.c;
enable = pci;
enable = arm_coreboot;
};
module = {
@@ -641,6 +665,7 @@ module = {
module = {
name = cbtable;
common = kern/i386/coreboot/cbtable.c;
common = kern/coreboot/cbtable.c;
enable = i386_pc;
enable = i386_efi;
enable = i386_qemu;
@@ -754,6 +779,7 @@ module = {
enable = arm_efi;
enable = arm64_efi;
enable = arm_uboot;
enable = arm_coreboot;
};
module = {
@@ -837,7 +863,8 @@ module = {
efi = lib/efi/halt.c;
ieee1275 = lib/ieee1275/halt.c;
emu = lib/emu/halt.c;
uboot = lib/uboot/halt.c;
uboot = lib/dummy/halt.c;
arm_coreboot = lib/dummy/halt.c;
};
module = {
@@ -855,6 +882,7 @@ module = {
mips_qemu_mips = lib/mips/qemu_mips/reboot.c;
xen = lib/xen/reboot.c;
uboot = lib/uboot/reboot.c;
arm_coreboot = lib/dummy/reboot.c;
common = commands/reboot.c;
};
@@ -1548,7 +1576,8 @@ module = {
name = datetime;
cmos = lib/cmos_datetime.c;
efi = lib/efi/datetime.c;
uboot = lib/uboot/datetime.c;
uboot = lib/dummy/datetime.c;
arm_coreboot = lib/dummy/datetime.c;
sparc64_ieee1275 = lib/ieee1275/datetime.c;
powerpc_ieee1275 = lib/ieee1275/datetime.c;
sparc64_ieee1275 = lib/ieee1275/cmos.c;
@@ -1869,6 +1898,7 @@ module = {
module = {
name = at_keyboard;
common = term/at_keyboard.c;
common = term/ps2.c;
enable = x86;
};
@@ -1961,6 +1991,11 @@ module = {
common = tests/example_functional_test.c;
};
module = {
name = strtoull_test;
common = tests/strtoull_test.c;
};
module = {
name = setjmp_test;
common = tests/setjmp_test.c;

255
grub-core/bus/fdt.c Normal file
View File

@@ -0,0 +1,255 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 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/fdtbus.h>
#include <grub/fdt.h>
#include <grub/term.h>
static const void *dtb;
static grub_size_t root_address_cells, root_size_cells;
/* Pointer to this symbol signals invalid mapping. */
char grub_fdtbus_invalid_mapping[1];
struct grub_fdtbus_dev
{
struct grub_fdtbus_dev *next;
struct grub_fdtbus_dev *parent;
int node;
struct grub_fdtbus_driver *driver;
};
struct grub_fdtbus_dev *devs;
struct grub_fdtbus_driver *drivers;
static int
is_compatible (struct grub_fdtbus_driver *driver,
int node)
{
grub_size_t compatible_size;
const char *compatible = grub_fdt_get_prop (dtb, node, "compatible",
&compatible_size);
const char *compatible_end = compatible + compatible_size;
while (compatible < compatible_end)
{
if (grub_strcmp (driver->compatible, compatible) == 0)
return 1;
compatible += grub_strlen (compatible) + 1;
}
return 0;
}
static void
fdtbus_scan (struct grub_fdtbus_dev *parent)
{
int node;
for (node = grub_fdt_first_node (dtb, parent ? parent->node : 0); node >= 0;
node = grub_fdt_next_node (dtb, node))
{
struct grub_fdtbus_dev *dev;
struct grub_fdtbus_driver *driver;
dev = grub_zalloc (sizeof (*dev));
if (!dev)
{
grub_print_error ();
return;
}
dev->node = node;
dev->next = devs;
dev->parent = parent;
devs = dev;
FOR_LIST_ELEMENTS(driver, drivers)
if (!dev->driver && is_compatible (driver, node))
{
if (driver->attach(dev) == GRUB_ERR_NONE)
{
dev->driver = driver;
break;
}
grub_print_error ();
}
fdtbus_scan (dev);
}
}
void
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
{
struct grub_fdtbus_dev *dev;
grub_list_push (GRUB_AS_LIST_P (&drivers),
GRUB_AS_LIST (driver));
for (dev = devs; dev; dev = dev->next)
if (!dev->driver && is_compatible (driver, dev->node))
{
if (driver->attach(dev) == GRUB_ERR_NONE)
dev->driver = driver;
grub_print_error ();
}
}
void
grub_fdtbus_unregister (struct grub_fdtbus_driver *driver)
{
grub_list_remove (GRUB_AS_LIST (driver));
struct grub_fdtbus_dev *dev;
for (dev = devs; dev; dev = dev->next)
if (dev->driver == driver)
{
if (driver->detach)
driver->detach(dev);
dev->driver = 0;
}
}
void
grub_fdtbus_init (const void *dtb_in, grub_size_t size)
{
if (!dtb_in || grub_fdt_check_header (dtb_in, size) < 0)
grub_fatal ("invalid FDT");
dtb = dtb_in;
const grub_uint32_t *prop = grub_fdt_get_prop (dtb, 0, "#address-cells", 0);
if (prop)
root_address_cells = grub_be_to_cpu32 (*prop);
else
root_address_cells = 1;
prop = grub_fdt_get_prop (dtb, 0, "#size-cells", 0);
if (prop)
root_size_cells = grub_be_to_cpu32 (*prop);
else
root_size_cells = 1;
fdtbus_scan (0);
}
static int
get_address_cells (const struct grub_fdtbus_dev *dev)
{
const grub_uint32_t *prop;
if (!dev)
return root_address_cells;
prop = grub_fdt_get_prop (dtb, dev->node, "#address-cells", 0);
if (prop)
return grub_be_to_cpu32 (*prop);
return 1;
}
static int
get_size_cells (const struct grub_fdtbus_dev *dev)
{
const grub_uint32_t *prop;
if (!dev)
return root_size_cells;
prop = grub_fdt_get_prop (dtb, dev->node, "#size-cells", 0);
if (prop)
return grub_be_to_cpu32 (*prop);
return 1;
}
static grub_uint64_t
get64 (const grub_uint32_t *reg, grub_size_t cells)
{
grub_uint64_t val = 0;
if (cells >= 1)
val = grub_be_to_cpu32 (reg[cells - 1]);
if (cells >= 2)
val |= ((grub_uint64_t) grub_be_to_cpu32 (reg[cells - 2])) << 32;
return val;
}
static volatile void *
translate (const struct grub_fdtbus_dev *dev, const grub_uint32_t *reg)
{
volatile void *ret;
const grub_uint32_t *ranges;
grub_size_t ranges_size, cells_per_mapping;
grub_size_t parent_address_cells, child_address_cells, child_size_cells;
grub_size_t nmappings, i;
if (dev == 0)
{
grub_uint64_t val;
val = get64 (reg, root_address_cells);
if (sizeof (void *) == 4 && (val >> 32))
return grub_fdtbus_invalid_mapping;
return (void *) (grub_addr_t) val;
}
ranges = grub_fdt_get_prop (dtb, dev->node, "ranges", &ranges_size);
if (!ranges)
return grub_fdtbus_invalid_mapping;
if (ranges_size == 0)
return translate (dev->parent, reg);
parent_address_cells = get_address_cells (dev->parent);
child_address_cells = get_address_cells (dev);
child_size_cells = get_size_cells (dev);
cells_per_mapping = parent_address_cells + child_address_cells + child_size_cells;
nmappings = ranges_size / 4 / cells_per_mapping;
for (i = 0; i < nmappings; i++)
{
const grub_uint32_t *child_addr = &ranges[i * cells_per_mapping];
const grub_uint32_t *parent_addr = child_addr + child_address_cells;
grub_uint64_t child_size = get64 (parent_addr + parent_address_cells, child_size_cells);
if (child_address_cells > 2 && grub_memcmp (reg, child_addr, (child_address_cells - 2) * 4) != 0)
continue;
if (get64 (reg, child_address_cells) < get64 (child_addr, child_address_cells))
continue;
grub_uint64_t offset = get64 (reg, child_address_cells) - get64 (child_addr, child_address_cells);
if (offset >= child_size)
continue;
ret = translate (dev->parent, parent_addr);
if (grub_fdtbus_is_mapping_valid (ret))
ret = (volatile char *) ret + offset;
return ret;
}
return grub_fdtbus_invalid_mapping;
}
volatile void *
grub_fdtbus_map_reg (const struct grub_fdtbus_dev *dev, int regno, grub_size_t *size)
{
grub_size_t address_cells, size_cells;
address_cells = get_address_cells (dev->parent);
size_cells = get_size_cells (dev->parent);
const grub_uint32_t *reg = grub_fdt_get_prop (dtb, dev->node, "reg", 0);
if (size && size_cells)
*size = reg[(address_cells + size_cells) * regno + address_cells];
if (size && !size_cells)
*size = 0;
return translate (dev->parent, reg + (address_cells + size_cells) * regno);
}
const char *
grub_fdtbus_get_name (const struct grub_fdtbus_dev *dev)
{
return grub_fdt_get_nodename (dtb, dev->node);
}
const void *
grub_fdtbus_get_prop (const struct grub_fdtbus_dev *dev,
const char *name,
grub_uint32_t *len)
{
return grub_fdt_get_prop (dtb, dev->node, name, len);
}
const void *
grub_fdtbus_get_fdt (void)
{
return dtb;
}

View File

@@ -0,0 +1,45 @@
/* ehci.c - EHCI Support. */
/*
* 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/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/usb.h>
#include <grub/fdtbus.h>
static grub_err_t
ehci_attach(const struct grub_fdtbus_dev *dev)
{
grub_dprintf ("ehci", "Found generic-ehci\n");
grub_ehci_init_device (grub_fdtbus_map_reg (dev, 0, 0));
return 0;
}
struct grub_fdtbus_driver ehci =
{
.compatible = "generic-ehci",
.attach = ehci_attach
};
void
grub_ehci_pci_scan (void)
{
grub_fdtbus_register (&ehci);
}

View File

@@ -0,0 +1,208 @@
/* ehci.c - EHCI Support. */
/*
* 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/pci.h>
#include <grub/cpu/pci.h>
#include <grub/cs5536.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/usb.h>
#define GRUB_EHCI_PCI_SBRN_REG 0x60
#define GRUB_EHCI_ADDR_MEM_MASK (~0xff)
/* USBLEGSUP bits and related OS OWNED byte offset */
enum
{
GRUB_EHCI_BIOS_OWNED = (1 << 16),
GRUB_EHCI_OS_OWNED = (1 << 24)
};
/* PCI iteration function... */
static int
grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
void *data __attribute__ ((unused)))
{
volatile grub_uint32_t *regs;
grub_uint32_t base, base_h;
grub_uint32_t eecp_offset;
grub_uint32_t usblegsup = 0;
grub_uint64_t maxtime;
grub_uint32_t interf;
grub_uint32_t subclass;
grub_uint32_t class;
grub_uint8_t release;
grub_uint32_t class_code;
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n");
if (pciid == GRUB_CS5536_PCIID)
{
grub_uint64_t basereg;
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE);
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
{
/* Shouldn't happen. */
grub_dprintf ("ehci", "No EHCI address is assigned\n");
return 0;
}
base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK);
basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE;
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg);
}
else
{
grub_pci_address_t addr;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class_code = grub_pci_read (addr) >> 8;
interf = class_code & 0xFF;
subclass = (class_code >> 8) & 0xFF;
class = class_code >> 16;
/* If this is not an EHCI controller, just return. */
if (class != 0x0c || subclass != 0x03 || interf != 0x20)
return 0;
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n");
/* Check Serial Bus Release Number */
addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG);
release = grub_pci_read_byte (addr);
if (release != 0x20)
{
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n",
release);
return 0;
}
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n");
/* Determine EHCI EHCC registers base address. */
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
base = grub_pci_read (addr);
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1);
base_h = grub_pci_read (addr);
/* Stop if registers are mapped above 4G - GRUB does not currently
* work with registers mapped above 4G */
if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32)
&& (base_h != 0))
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: registers above 4G are not supported\n");
return 0;
}
base &= GRUB_PCI_ADDR_MEM_MASK;
if (!base)
{
grub_dprintf ("ehci",
"EHCI: EHCI is not mapped\n");
return 0;
}
/* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
grub_pci_write_word(addr,
GRUB_PCI_COMMAND_MEM_ENABLED
| GRUB_PCI_COMMAND_BUS_MASTER
| grub_pci_read_word(addr));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n");
}
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n",
(base & GRUB_EHCI_ADDR_MEM_MASK));
regs = grub_pci_device_map_range (dev,
(base & GRUB_EHCI_ADDR_MEM_MASK),
0x100);
/* Is there EECP ? */
eecp_offset = (grub_le_to_cpu32 (regs[2]) >> 8) & 0xff;
/* Determine and change ownership. */
/* EECP offset valid in HCCPARAMS */
/* Ownership can be changed via EECP only */
if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40)
{
grub_pci_address_t pciaddr_eecp;
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset);
usblegsup = grub_pci_read (pciaddr_eecp);
if (usblegsup & GRUB_EHCI_BIOS_OWNED)
{
grub_boot_time ("Taking ownership of EHCI controller");
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n");
/* Ownership change - set OS_OWNED bit */
grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
/* Wait for finish of ownership change, EHCI specification
* doesn't say how long it can take... */
maxtime = grub_get_time_ms () + 1000;
while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
&& (grub_get_time_ms () < maxtime));
if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI change ownership timeout");
/* Change ownership in "hard way" - reset BIOS ownership */
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
}
else if (usblegsup & GRUB_EHCI_OS_OWNED)
/* XXX: What to do in this case - nothing ? Can it happen ? */
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n");
else
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n");
/* XXX: What to do in this case ? Can it happen ?
* Is code below correct ? */
/* Ownership change - set OS_OWNED bit */
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
/* Disable SMI, just to be sure. */
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4);
grub_pci_write (pciaddr_eecp, 0);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n");
grub_ehci_init_device (regs);
return 0;
}
void
grub_ehci_pci_scan (void)
{
grub_pci_iterate (grub_ehci_pci_iter, NULL);
}

View File

@@ -22,13 +22,10 @@
#include <grub/usb.h>
#include <grub/usbtrans.h>
#include <grub/misc.h>
#include <grub/pci.h>
#include <grub/cpu/pci.h>
#include <grub/cpu/io.h>
#include <grub/time.h>
#include <grub/loader.h>
#include <grub/cs5536.h>
#include <grub/disk.h>
#include <grub/dma.h>
#include <grub/cache.h>
GRUB_MOD_LICENSE ("GPLv3+");
@@ -39,8 +36,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
* - is not supporting interrupt transfers
*/
#define GRUB_EHCI_PCI_SBRN_REG 0x60
/* Capability registers offsets */
enum
{
@@ -54,7 +49,6 @@ enum
#define GRUB_EHCI_EECP_MASK (0xff << 8)
#define GRUB_EHCI_EECP_SHIFT 8
#define GRUB_EHCI_ADDR_MEM_MASK (~0xff)
#define GRUB_EHCI_POINTER_MASK (~0x1f)
/* Capability register SPARAMS bits */
@@ -85,13 +79,6 @@ enum
#define GRUB_EHCI_QH_EMPTY 1
/* USBLEGSUP bits and related OS OWNED byte offset */
enum
{
GRUB_EHCI_BIOS_OWNED = (1 << 16),
GRUB_EHCI_OS_OWNED = (1 << 24)
};
/* Operational registers offsets */
enum
{
@@ -455,9 +442,10 @@ grub_ehci_reset (struct grub_ehci *e)
sync_all_caches (e);
grub_dprintf ("ehci", "reset\n");
grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
GRUB_EHCI_CMD_HC_RESET
| grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
GRUB_EHCI_CMD_HC_RESET);
/* Ensure command is written */
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND);
/* XXX: How long time could take reset of HC ? */
@@ -473,116 +461,24 @@ grub_ehci_reset (struct grub_ehci *e)
}
/* PCI iteration function... */
static int
grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
void *data __attribute__ ((unused)))
void
grub_ehci_init_device (volatile void *regs)
{
grub_uint8_t release;
grub_uint32_t class_code;
grub_uint32_t interf;
grub_uint32_t subclass;
grub_uint32_t class;
grub_uint32_t base, base_h;
struct grub_ehci *e;
grub_uint32_t eecp_offset;
grub_uint32_t fp;
int i;
grub_uint32_t usblegsup = 0;
grub_uint64_t maxtime;
grub_uint32_t n_ports;
grub_uint8_t caplen;
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n");
if (pciid == GRUB_CS5536_PCIID)
{
grub_uint64_t basereg;
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE);
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
{
/* Shouldn't happen. */
grub_dprintf ("ehci", "No EHCI address is assigned\n");
return 0;
}
base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK);
basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE;
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg);
}
else
{
grub_pci_address_t addr;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class_code = grub_pci_read (addr) >> 8;
interf = class_code & 0xFF;
subclass = (class_code >> 8) & 0xFF;
class = class_code >> 16;
/* If this is not an EHCI controller, just return. */
if (class != 0x0c || subclass != 0x03 || interf != 0x20)
return 0;
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n");
/* Check Serial Bus Release Number */
addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG);
release = grub_pci_read_byte (addr);
if (release != 0x20)
{
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n",
release);
return 0;
}
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n");
/* Determine EHCI EHCC registers base address. */
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
base = grub_pci_read (addr);
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1);
base_h = grub_pci_read (addr);
/* Stop if registers are mapped above 4G - GRUB does not currently
* work with registers mapped above 4G */
if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32)
&& (base_h != 0))
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: registers above 4G are not supported\n");
return 0;
}
base &= GRUB_PCI_ADDR_MEM_MASK;
if (!base)
{
grub_dprintf ("ehci",
"EHCI: EHCI is not mapped\n");
return 0;
}
/* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
grub_pci_write_word(addr,
GRUB_PCI_COMMAND_MEM_ENABLED
| GRUB_PCI_COMMAND_BUS_MASTER
| grub_pci_read_word(addr));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n");
}
/* Allocate memory for the controller and fill basic values. */
e = grub_zalloc (sizeof (*e));
if (!e)
return 1;
return;
e->framelist_chunk = NULL;
e->td_chunk = NULL;
e->qh_chunk = NULL;
e->iobase_ehcc = grub_pci_device_map_range (dev,
(base & GRUB_EHCI_ADDR_MEM_MASK),
0x100);
e->iobase_ehcc = regs;
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n",
(base & GRUB_EHCI_ADDR_MEM_MASK));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CAPLEN: %02x\n",
grub_ehci_ehcc_read8 (e, GRUB_EHCI_EHCC_CAPLEN));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: VERSION: %04x\n",
@@ -598,7 +494,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
if (caplen & (sizeof (grub_uint32_t) - 1))
{
grub_dprintf ("ehci", "Unaligned caplen\n");
return 0;
return;
}
e->iobase = ((volatile grub_uint32_t *) e->iobase_ehcc
+ (caplen / sizeof (grub_uint32_t)));
@@ -609,7 +505,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
(base & GRUB_EHCI_ADDR_MEM_MASK) + caplen);
(grub_addr_t) e->iobase_ehcc + caplen);
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n",
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n",
@@ -625,10 +521,6 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n",
grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG));
/* Is there EECP ? */
eecp_offset = (grub_ehci_ehcc_read32 (e, GRUB_EHCI_EHCC_CPARAMS)
& GRUB_EHCI_EECP_MASK) >> GRUB_EHCI_EECP_SHIFT;
/* Check format of data structures requested by EHCI */
/* XXX: In fact it is not used at any place, it is prepared for future
* This implementation uses 32-bits pointers only */
@@ -732,65 +624,6 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: QH/TD init. OK\n");
/* Determine and change ownership. */
/* EECP offset valid in HCCPARAMS */
/* Ownership can be changed via EECP only */
if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40)
{
grub_pci_address_t pciaddr_eecp;
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset);
usblegsup = grub_pci_read (pciaddr_eecp);
if (usblegsup & GRUB_EHCI_BIOS_OWNED)
{
grub_boot_time ("Taking ownership of EHCI controller");
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n");
/* Ownership change - set OS_OWNED bit */
grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
/* Wait for finish of ownership change, EHCI specification
* doesn't say how long it can take... */
maxtime = grub_get_time_ms () + 1000;
while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
&& (grub_get_time_ms () < maxtime));
if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI change ownership timeout");
/* Change ownership in "hard way" - reset BIOS ownership */
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
}
else if (usblegsup & GRUB_EHCI_OS_OWNED)
/* XXX: What to do in this case - nothing ? Can it happen ? */
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n");
else
{
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n");
/* XXX: What to do in this case ? Can it happen ?
* Is code below correct ? */
/* Ownership change - set OS_OWNED bit */
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
/* Disable SMI, just to be sure. */
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4);
grub_pci_write (pciaddr_eecp, 0);
/* Ensure PCI register is written */
grub_pci_read (pciaddr_eecp);
}
grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n");
/* Now we can setup EHCI (maybe...) */
/* Check if EHCI is halted and halt it if not */
@@ -864,7 +697,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
grub_dprintf ("ehci",
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
(base & GRUB_EHCI_ADDR_MEM_MASK));
(grub_addr_t) regs);
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n",
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n",
@@ -880,7 +713,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n",
grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG));
return 0;
return;
fail:
if (e)
@@ -894,7 +727,7 @@ fail:
}
grub_free (e);
return 0;
return;
}
static int
@@ -1891,12 +1724,6 @@ grub_ehci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
}
}
static void
grub_ehci_inithw (void)
{
grub_pci_iterate (grub_ehci_pci_iter, NULL);
}
static grub_err_t
grub_ehci_restore_hw (void)
{
@@ -1997,7 +1824,7 @@ GRUB_MOD_INIT (ehci)
grub_stop_disk_firmware ();
grub_boot_time ("Initing EHCI hardware");
grub_ehci_inithw ();
grub_ehci_pci_scan ();
grub_boot_time ("Registering EHCI driver");
grub_usb_controller_dev_register (&usb_controller);
grub_boot_time ("EHCI driver registered");

View File

@@ -18,7 +18,7 @@
*/
#include <grub/dl.h>
#include <grub/pci.h>
#include <grub/dma.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/usb.h>

View File

@@ -20,7 +20,7 @@
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/i386/coreboot/lbio.h>
#include <grub/coreboot/lbio.h>
#include <grub/i386/tsc.h>
GRUB_MOD_LICENSE ("GPLv3+");

View File

@@ -20,7 +20,7 @@
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/i386/coreboot/lbio.h>
#include <grub/coreboot/lbio.h>
#include <grub/i386/tsc.h>
GRUB_MOD_LICENSE ("GPLv3+");

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
# Copyright (C) 2010 Free Software Foundation, Inc.

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
# Copyright (C) 2010 Free Software Foundation, Inc.

View File

@@ -29,6 +29,8 @@ void grub_arm_clean_dcache_range_armv6 (grub_addr_t start, grub_addr_t end,
grub_addr_t dlinesz);
void grub_arm_clean_dcache_range_armv7 (grub_addr_t start, grub_addr_t end,
grub_addr_t dlinesz);
void grub_arm_clean_dcache_range_poc_armv7 (grub_addr_t start, grub_addr_t end,
grub_addr_t dlinesz);
void grub_arm_invalidate_icache_range_armv6 (grub_addr_t start, grub_addr_t end,
grub_addr_t dlinesz);
void grub_arm_invalidate_icache_range_armv7 (grub_addr_t start, grub_addr_t end,
@@ -252,6 +254,38 @@ grub_arch_sync_caches (void *address, grub_size_t len)
}
}
void
grub_arch_sync_dma_caches (volatile void *address, grub_size_t len)
{
grub_addr_t start = (grub_addr_t) address;
grub_addr_t end = start + len;
if (type == ARCH_UNKNOWN)
probe_caches ();
start = ALIGN_DOWN (start, grub_arch_cache_max_linesz);
end = ALIGN_UP (end, grub_arch_cache_max_linesz);
switch (type)
{
case ARCH_ARMV6:
grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz);
grub_arm_invalidate_icache_range_armv6 (start, end,
grub_arch_cache_ilinesz);
break;
case ARCH_ARMV5_WRITE_THROUGH:
case ARCH_ARMV6_UNIFIED:
grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz);
break;
case ARCH_ARMV7:
grub_arm_clean_dcache_range_poc_armv7 (start, end, grub_arch_cache_dlinesz);
grub_arm_invalidate_icache_range_armv7 (start, end,
grub_arch_cache_ilinesz);
break;
/* Pacify GCC. */
case ARCH_UNKNOWN:
break;
}
}
void
grub_arm_disable_caches_mmu (void)
{

View File

@@ -33,6 +33,18 @@
# define ISB isb
#define ARMV7 1
FUNCTION(grub_arm_clean_dcache_range_poc_armv7)
DSB
@ Clean data cache for range to point-of-coherence
1: cmp r0, r1
bge 2f
mcr p15, 0, r0, c7, c14, 1 @ DCCMVAC
add r0, r0, r2 @ Next line
b 1b
2: DSB
bx lr
@ r0 - CLIDR
@ r1 - LoC
@ r2 - current level

View File

@@ -0,0 +1,40 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2013 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/coreboot/lbio.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/dl.h>
#include <grub/arm/startup.h>
GRUB_MOD_LICENSE ("GPLv3+");
#pragma GCC diagnostic ignored "-Wcast-align"
grub_linuxbios_table_header_t
grub_linuxbios_get_tables (void)
{
grub_linuxbios_table_header_t table_header
= (grub_linuxbios_table_header_t) grub_arm_saved_registers.r[0];
if (!grub_linuxbios_check_signature (table_header))
return 0;
return table_header;
}

View File

@@ -0,0 +1,44 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 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/symbol.h>
.file "coreboot.S"
.text
.syntax unified
#if !defined (__thumb2__)
.arch armv7a
.arm
#else
.arch armv7
.thumb
#endif
FUNCTION(grub_arm_pfr1)
mrc p15, 0, r0, c0, c1, 1
bx lr
FUNCTION(grub_armv7_get_timer_value)
isb
mrrc p15, 1, r0, r1, c14
bx lr
FUNCTION(grub_armv7_get_timer_frequency)
mrc p15, 0, r0, c14, c0, 0
bx lr

View File

@@ -0,0 +1,59 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/dma.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/mm_private.h>
#include <grub/cache.h>
struct grub_pci_dma_chunk *
grub_memalign_dma32 (grub_size_t align, grub_size_t 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;
}
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);
}
volatile void *
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
{
return (void *) ch;
}
grub_uint32_t
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
{
return (grub_uint32_t) (grub_addr_t) ch;
}

View File

@@ -0,0 +1,169 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013 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/kernel.h>
#include <grub/mm.h>
#include <grub/memory.h>
#include <grub/machine/console.h>
#include <grub/machine/kernel.h>
#include <grub/offsets.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/loader.h>
#include <grub/env.h>
#include <grub/cache.h>
#include <grub/time.h>
#include <grub/symbol.h>
#include <grub/video.h>
#include <grub/coreboot/lbio.h>
#include <grub/fdtbus.h>
extern grub_uint8_t _start[];
extern grub_uint8_t _end[];
extern grub_uint8_t _edata[];
grub_addr_t start_of_ram = ~(grub_addr_t)0;
void __attribute__ ((noreturn))
grub_exit (void)
{
/* We can't use grub_fatal() in this function. This would create an infinite
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
while (1)
grub_cpu_idle ();
}
static grub_uint64_t modend;
static int have_memory = 0;
/* Helper for grub_machine_init. */
static int
heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
void *data __attribute__ ((unused)))
{
grub_uint64_t begin = addr, end = addr + size;
#if GRUB_CPU_SIZEOF_VOID_P == 4
/* Restrict ourselves to 32-bit memory space. */
if (begin > GRUB_ULONG_MAX)
return 0;
if (end > GRUB_ULONG_MAX)
end = GRUB_ULONG_MAX;
#endif
if (start_of_ram > begin)
start_of_ram = begin;
if (type != GRUB_MEMORY_AVAILABLE)
return 0;
if (modend && begin < modend)
{
if (begin < (grub_addr_t)_start)
{
grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin));
have_memory = 1;
}
begin = modend;
}
/* Avoid DMA problems. */
if (end >= 0xfe000000)
end = 0xfe000000;
if (end <= begin)
return 0;
grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
have_memory = 1;
return 0;
}
static const void *dtb;
static grub_size_t dtb_size;
static int
iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data __attribute__ ((unused)))
{
if (table_item->tag != GRUB_LINUXBIOS_MEMBER_DTB)
return 0;
if (grub_fdt_check_header (table_item + 1, table_item->size) >= 0)
{
dtb = table_item + 1;
dtb_size = table_item->size;
}
else
grub_printf ("Invalid DTB supplied by coreboot\n");
return 0;
}
void
grub_machine_init (void)
{
struct grub_module_header *header;
modend = grub_modules_get_end ();
grub_video_coreboot_fb_early_init ();
grub_machine_mmap_iterate (heap_init, NULL);
if (!have_memory)
grub_fatal ("No memory found");
grub_video_coreboot_fb_late_init ();
grub_font_init ();
grub_gfxterm_init ();
FOR_MODULES (header)
if (header->type == OBJ_TYPE_DTB)
{
char *dtb_orig_addr, *dtb_copy;
dtb_orig_addr = (char *) header + sizeof (struct grub_module_header);
dtb_size = header->size - sizeof (struct grub_module_header);
dtb = dtb_copy = grub_malloc (dtb_size);
grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
break;
}
if (!dtb)
grub_linuxbios_table_iterate (iterate_linuxbios_table, 0);
if (!dtb)
grub_fatal ("No DTB found");
grub_fdtbus_init (dtb, dtb_size);
grub_machine_timer_init ();
grub_cros_init ();
grub_pl050_init ();
}
void
grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
char **path __attribute__ ((unused)))
{
}
void
grub_machine_fini (int flags __attribute__ ((unused)))
{
}

View File

@@ -0,0 +1,101 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 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/mm.h>
#include <grub/machine/kernel.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/time.h>
#include <grub/fdtbus.h>
#include <grub/misc.h>
grub_uint64_t
grub_armv7_get_timer_value(void);
grub_uint32_t
grub_armv7_get_timer_frequency(void);
grub_uint32_t
grub_arm_pfr1(void);
static int have_timer = 0;
static volatile grub_uint32_t *sp804_regs;
static grub_uint64_t
sp804_get_time_ms (void)
{
static grub_uint32_t high, last_low;
grub_uint32_t low = ~sp804_regs[1];
if (last_low > low)
high++;
last_low = low;
return grub_divmod64 ((((grub_uint64_t) high) << 32) | low,
1000, 0);
}
static grub_err_t
sp804_attach(const struct grub_fdtbus_dev *dev)
{
if (have_timer)
return GRUB_ERR_NONE;
sp804_regs = grub_fdtbus_map_reg (dev, 0, 0);
if (!grub_fdtbus_is_mapping_valid (sp804_regs))
return grub_error (GRUB_ERR_IO, "could not map sp804: %p", sp804_regs);
grub_install_get_time_ms (sp804_get_time_ms);
have_timer = 1;
return GRUB_ERR_NONE;
}
struct grub_fdtbus_driver sp804 =
{
.compatible = "arm,sp804",
.attach = sp804_attach
};
static grub_uint32_t timer_frequency_in_khz;
static grub_uint64_t
generic_get_time_ms (void)
{
return grub_divmod64 (grub_armv7_get_timer_value(), timer_frequency_in_khz, 0);
}
static int
try_generic_timer (void)
{
if (((grub_arm_pfr1 () >> 16) & 0xf) != 1)
return 0;
grub_printf ("freq = %x\n", grub_armv7_get_timer_frequency());
timer_frequency_in_khz = 0x016e3600 / 1000; //grub_armv7_get_timer_frequency() / 1000;
if (timer_frequency_in_khz == 0)
return 0;
grub_install_get_time_ms (generic_get_time_ms);
have_timer = 1;
return 1;
}
void
grub_machine_timer_init (void)
{
grub_fdtbus_register (&sp804);
if (!have_timer)
try_generic_timer ();
if (!have_timer)
grub_fatal ("No timer found");
}

View File

@@ -24,6 +24,7 @@
* GRUB is called from U-Boot as a Linux Kernel type image, which
* means among other things that it always enters in ARM state.
*
* coreboot starts in ARM mode as well.
*
* Overview of GRUB image layout:
*
@@ -86,7 +87,7 @@ FUNCTION(codestart)
@ Stack pointer used as start address for signature probing
mov r12, sp
adr sp, entry_state
push {r1-r12,lr} @ store U-Boot context (sp in r12)
push {r0-r12,lr} @ store U-Boot context (sp in r12)
adr r1, _start
ldr r0, bss_start_ptr @ src
@@ -127,6 +128,8 @@ reloc_done:
str r1, EXT_C(grub_modbase)
/* Coreboot already places modules at right place. */
#ifndef GRUB_MACHINE_COREBOOT
add r1, r1, r2
add r0, r0, r2
sub r1, r1, #4
@@ -136,6 +139,7 @@ reloc_done:
str r3, [r1], #-4 @ *dst-- = r3
subs r2, #4 @ remaining -= 4
bne 1b @ while remaining != 0
#endif
@ Since we _are_ the C run-time, we need to manually zero the BSS
@ region before continuing
@@ -153,69 +157,21 @@ reloc_done:
b EXT_C(grub_main)
/*
* uboot_syscall():
* This function is effectively a veneer, so it cannot
* modify the stack or corrupt any registers other than
* r12 (ip). Furthermore it needs to restore r8 for
* U-Boot (Global Data Pointer) and preserve it for Grub.
*/
FUNCTION(grub_uboot_syscall)
str r8, transition_space
str lr, transition_space + 4
str r9, transition_space + 8
ldr r8, gd_backup
ldr r9, gd_backup + 4
bl do_syscall
ldr r8, transition_space
ldr lr, transition_space + 4
ldr r9, transition_space + 8
bx lr
do_syscall:
ldr ip, grub_uboot_syscall_ptr
bx ip
FUNCTION(grub_uboot_return)
adr sp, entry_state_end
pop {r4-r12, lr}
mov sp, r12
bx lr
.align 3
@ U-boot context stack space
entry_state_end:
VARIABLE(grub_uboot_machine_type)
@ U-boot/coreboot context stack space
VARIABLE(grub_arm_saved_registers)
.long 0 @ r0
.long 0 @ r1
VARIABLE(grub_uboot_boot_data)
.long 0 @ r2
.long 0 @ r3
.long 0 @ r4
.long 0 @ r5
.long 0 @ r6
.long 0 @ r7
gd_backup:
.long 0 @ r8 - U-Boot global data pointer up to 2013-09-21
.long 0 @ r9 - U-Boot global data pointer 2013-09-21 onwards
.long 0 @ r8
.long 0 @ r9
.long 0 @ r10
.long 0 @ r11
VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer -
.long 0 @ also API signature address hint.
.long 0 @ sp
.long 0 @ lr
entry_state: @ backup for U-Boot context
@ GRUB context stack space
transition_space:
.long 0 @ r8
.long 0 @ lr
.long 0 @ r9
VARIABLE(grub_uboot_syscall_ptr)
.long 0 @
END
entry_state:

View File

@@ -0,0 +1,70 @@
/* init.c - generic U-Boot initialization and finalization */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 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/uboot/uboot.h>
#include <grub/arm/startup.h>
#include <grub/uboot/api_public.h>
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
grub_uint32_t
grub_uboot_get_machine_type (void)
{
return grub_arm_saved_registers.r[1];
}
grub_addr_t
grub_uboot_get_boot_data (void)
{
return grub_arm_saved_registers.r[2];
}
int
grub_uboot_api_init (void)
{
struct api_signature *start, *end;
struct api_signature *p;
grub_addr_t grub_uboot_search_hint = grub_arm_saved_registers.sp;
if (grub_uboot_search_hint)
{
/* Extended search range to work around Trim Slice U-Boot issue */
start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff)
- 0x00500000);
end =
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
API_SIG_MAGLEN + 0x00500000);
}
else
{
start = 0;
end = (struct api_signature *) (256 * 1024 * 1024);
}
/* Structure alignment is (at least) 8 bytes */
for (p = start; p < end; p = (void *) ((grub_addr_t) p + 8))
{
if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0)
{
grub_uboot_syscall_ptr = p->syscall;
return p->version;
}
}
return 0;
}

View File

@@ -0,0 +1,73 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/offsets.h>
#include <grub/symbol.h>
#include <grub/machine/kernel.h>
/*
* uboot_syscall():
* This function is effectively a veneer, so it cannot
* modify the stack or corrupt any registers other than
* r12 (ip). Furthermore it needs to restore r8 for
* U-Boot (Global Data Pointer) and preserve it for Grub.
*/
FUNCTION(grub_uboot_syscall)
str r8, transition_space
str lr, transition_space + 4
str r9, transition_space + 8
ldr ip, saved_registers_ptr
ldr r8, [ip, #4 * 8]
ldr r9, [ip, #4 * 9]
bl do_syscall
ldr r8, transition_space
ldr lr, transition_space + 4
ldr r9, transition_space + 8
bx lr
do_syscall:
ldr ip, grub_uboot_syscall_ptr
bx ip
FUNCTION(grub_uboot_return)
ldr ip, saved_registers_ptr
ldr sp, [ip, #4 * 4]
pop {r4-r12, lr}
mov sp, r12
bx lr
.align 3
@ GRUB context stack space
transition_space:
.long 0 @ r8
.long 0 @ lr
.long 0 @ r9
saved_registers_ptr:
.long EXT_C(grub_arm_saved_registers)
VARIABLE(grub_uboot_syscall_ptr)
.long 0 @
END

View File

@@ -0,0 +1,72 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2013 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/i386/coreboot/memory.h>
#include <grub/coreboot/lbio.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/dl.h>
#pragma GCC diagnostic ignored "-Wcast-align"
/* Helper for grub_linuxbios_table_iterate. */
int
grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header)
{
if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
return 1;
return 0;
}
grub_err_t
grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
void *),
void *hook_data)
{
grub_linuxbios_table_header_t table_header = grub_linuxbios_get_tables ();
grub_linuxbios_table_item_t table_item;
if (!table_header)
return 0;
signature_found:
table_item =
(grub_linuxbios_table_item_t) ((char *) table_header +
table_header->header_size);
for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
+ table_header->header_size
+ table_header->table_size);
table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
{
if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
&& grub_linuxbios_check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1)))
{
table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1);
goto signature_found;
}
if (hook (table_item, hook_data))
return 1;
}
return 0;
}

View File

@@ -16,8 +16,8 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/memory.h>
#include <grub/machine/lbio.h>
#include <grub/memory.h>
#include <grub/coreboot/lbio.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/misc.h>
@@ -49,6 +49,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
{
grub_uint64_t start = mem_region->addr;
grub_uint64_t end = mem_region->addr + mem_region->size;
#ifdef __i386__
/* Mark region 0xa0000 - 0x100000 as reserved. */
if (start < 0x100000 && end >= 0xa0000
&& mem_region->type == GRUB_MACHINE_MEMORY_AVAILABLE)
@@ -75,6 +76,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
if (end <= start)
continue;
}
#endif
if (ctx->hook (start, end - start,
/* Multiboot mmaps match with the coreboot mmap
definition. Therefore, we can just pass type

View File

@@ -17,7 +17,7 @@
*/
#include <grub/i386/coreboot/memory.h>
#include <grub/i386/coreboot/lbio.h>
#include <grub/coreboot/lbio.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/misc.h>
@@ -25,59 +25,20 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* Helper for grub_linuxbios_table_iterate. */
static int
check_signature (grub_linuxbios_table_header_t tbl_header)
{
if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
return 1;
return 0;
}
grub_err_t
grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
void *),
void *hook_data)
grub_linuxbios_table_header_t
grub_linuxbios_get_tables (void)
{
grub_linuxbios_table_header_t table_header;
grub_linuxbios_table_item_t table_item;
/* Assuming table_header is aligned to its size (8 bytes). */
for (table_header = (grub_linuxbios_table_header_t) 0x500;
table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
if (check_signature (table_header))
goto signature_found;
if (grub_linuxbios_check_signature (table_header))
return table_header;
for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
if (check_signature (table_header))
goto signature_found;
return 0;
signature_found:
table_item =
(grub_linuxbios_table_item_t) ((char *) table_header +
table_header->header_size);
for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
+ table_header->header_size
+ table_header->table_size);
table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
{
if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
&& check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1)))
{
table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1);
goto signature_found;
}
if (hook (table_item, hook_data))
return 1;
}
if (grub_linuxbios_check_signature (table_header))
return table_header;
return 0;
}

View File

@@ -391,12 +391,13 @@ grub_strtoull (const char *str, char **end, int base)
unsigned long digit;
digit = grub_tolower (*str) - '0';
if (digit > 9)
{
digit += '0' - 'a' + 10;
if (digit >= (unsigned long) base)
break;
}
if (digit >= 'a' - '0')
digit += '0' - 'a' + 10;
else if (digit > 9)
break;
if (digit >= (unsigned long) base)
break;
found = 1;

View File

@@ -36,30 +36,14 @@
extern char __bss_start[];
extern char _end[];
extern grub_size_t grub_total_module_size;
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
static unsigned long timer_start;
extern grub_uint32_t grub_uboot_machine_type;
extern grub_addr_t grub_uboot_boot_data;
void
grub_exit (void)
{
grub_uboot_return (0);
}
grub_uint32_t
grub_uboot_get_machine_type (void)
{
return grub_uboot_machine_type;
}
grub_addr_t
grub_uboot_get_boot_data (void)
{
return grub_uboot_boot_data;
}
static grub_uint64_t
uboot_timer_ms (void)
{

View File

@@ -39,48 +39,13 @@
* returns: 0 if the call not found, 1 if serviced
*/
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
extern int grub_uboot_syscall (int, int *, ...);
extern grub_addr_t grub_uboot_search_hint;
static struct sys_info uboot_sys_info;
static struct mem_region uboot_mem_info[5];
static struct device_info * devices;
static int num_devices;
int
grub_uboot_api_init (void)
{
struct api_signature *start, *end;
struct api_signature *p;
if (grub_uboot_search_hint)
{
/* Extended search range to work around Trim Slice U-Boot issue */
start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff)
- 0x00500000);
end =
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
API_SIG_MAGLEN + 0x00500000);
}
else
{
start = 0;
end = (struct api_signature *) (256 * 1024 * 1024);
}
/* Structure alignment is (at least) 8 bytes */
for (p = start; p < end; p = (void *) ((grub_addr_t) p + 8))
{
if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0)
{
grub_uboot_syscall_ptr = p->syscall;
return p->version;
}
}
return 0;
}
/*
* All functions below are wrappers around the grub_uboot_syscall() function

View File

@@ -18,7 +18,6 @@
#include <grub/types.h>
#include <grub/symbol.h>
#include <grub/uboot/uboot.h>
#include <grub/datetime.h>
#include <grub/dl.h>
@@ -30,12 +29,12 @@ grub_err_t
grub_get_datetime (struct grub_datetime *datetime __attribute__ ((unused)))
{
return grub_error (GRUB_ERR_INVALID_COMMAND,
"can\'t get datetime using U-Boot");
"can\'t get datetime on this machine");
}
grub_err_t
grub_set_datetime (struct grub_datetime * datetime __attribute__ ((unused)))
{
return grub_error (GRUB_ERR_INVALID_COMMAND,
"can\'t set datetime using U-Boot");
"can\'t set datetime on this machine");
}

View File

@@ -0,0 +1,32 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/mm.h>
#include <grub/kernel.h>
#include <grub/loader.h>
void
grub_reboot (void)
{
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
/* Just stop here */
while (1);
}

View File

@@ -102,13 +102,13 @@ static grub_uint32_t *get_next_node (const void *fdt, char *node_name)
static int get_mem_rsvmap_size (const void *fdt)
{
int size = 0;
grub_uint64_t *ptr = (void *) ((grub_addr_t) fdt
+ grub_fdt_get_off_mem_rsvmap (fdt));
grub_unaligned_uint64_t *ptr = (void *) ((grub_addr_t) fdt
+ grub_fdt_get_off_mem_rsvmap (fdt));
do
{
size += 2 * sizeof(*ptr);
if (!*ptr && !*(ptr + 1))
if (!ptr[0].val && !ptr[1].val)
return size;
ptr += 2;
} while ((grub_addr_t) ptr <= (grub_addr_t) fdt + grub_fdt_get_totalsize (fdt)
@@ -229,7 +229,7 @@ static int rearrange_blocks (void *fdt, unsigned int clearance)
return 0;
}
static grub_uint32_t *find_prop (void *fdt, unsigned int nodeoffset,
static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset,
const char *name)
{
grub_uint32_t *prop = (void *) ((grub_addr_t) fdt
@@ -268,9 +268,9 @@ static grub_uint32_t *find_prop (void *fdt, unsigned int nodeoffset,
the size allocated for the FDT; if this function is called before the other
functions in this file and returns success, the other functions are
guaranteed not to access memory locations outside the allocated memory. */
int grub_fdt_check_header_nosize (void *fdt)
int grub_fdt_check_header_nosize (const void *fdt)
{
if (((grub_addr_t) fdt & 0x7) || (grub_fdt_get_magic (fdt) != FDT_MAGIC)
if (((grub_addr_t) fdt & 0x3) || (grub_fdt_get_magic (fdt) != FDT_MAGIC)
|| (grub_fdt_get_version (fdt) < FDT_SUPPORTED_VERSION)
|| (grub_fdt_get_last_comp_version (fdt) > FDT_SUPPORTED_VERSION)
|| (grub_fdt_get_off_dt_struct (fdt) & 0x00000003)
@@ -286,7 +286,7 @@ int grub_fdt_check_header_nosize (void *fdt)
return 0;
}
int grub_fdt_check_header (void *fdt, unsigned int size)
int grub_fdt_check_header (const void *fdt, unsigned int size)
{
if (size < sizeof (grub_fdt_header_t)
|| (grub_fdt_get_totalsize (fdt) > size)
@@ -295,41 +295,29 @@ int grub_fdt_check_header (void *fdt, unsigned int size)
return 0;
}
/* Find a direct sub-node of a given parent node. */
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
const char *name)
static const grub_uint32_t *
advance_token (const void *fdt, const grub_uint32_t *token, const grub_uint32_t *end, int skip_current)
{
grub_uint32_t *token, *end;
char *node_name;
if (parentoffset & 0x3)
return -1;
token = (void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
+ parentoffset);
end = (void *) struct_end (fdt);
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
return -1;
SKIP_NODE_NAME(node_name, token, end);
while (token < end)
for (; token < end; skip_current = 0)
{
switch (grub_be_to_cpu32(*token))
switch (grub_be_to_cpu32 (*token))
{
case FDT_BEGIN_NODE:
node_name = (char *) (token + 1);
if (node_name + grub_strlen (name) >= (char *) end)
return -1;
if (!grub_strcmp (node_name, name))
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
- grub_fdt_get_off_dt_struct (fdt));
token = get_next_node (fdt, node_name);
if (!token)
return -1;
break;
if (skip_current)
{
token = get_next_node (fdt, (char *) (token + 1));
continue;
}
char *ptr;
for (ptr = (char *) (token + 1); *ptr && ptr < (char *) end; ptr++);
if (ptr >= (char *) end)
return 0;
return token;
case FDT_PROP:
/* Skip property token and following data (len, nameoff and property
value). */
if (token >= end - 1)
return -1;
return 0;
token += prop_entry_size(grub_be_to_cpu32(*(token + 1)))
/ sizeof(*token);
break;
@@ -337,10 +325,74 @@ int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
token++;
break;
default:
return -1;
return 0;
}
}
return -1;
return 0;
}
int grub_fdt_next_node (const void *fdt, unsigned int currentoffset)
{
const grub_uint32_t *token = (const grub_uint32_t *) fdt + (currentoffset + grub_fdt_get_off_dt_struct (fdt)) / 4;
token = advance_token (fdt, token, (const void *) struct_end (fdt), 1);
if (!token)
return -1;
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
- grub_fdt_get_off_dt_struct (fdt));
}
int grub_fdt_first_node (const void *fdt, unsigned int parentoffset)
{
const grub_uint32_t *token, *end;
char *node_name;
if (parentoffset & 0x3)
return -1;
token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
+ parentoffset);
end = (const void *) struct_end (fdt);
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
return -1;
SKIP_NODE_NAME(node_name, token, end);
token = advance_token (fdt, token, end, 0);
if (!token)
return -1;
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
- grub_fdt_get_off_dt_struct (fdt));
}
/* Find a direct sub-node of a given parent node. */
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
const char *name)
{
const grub_uint32_t *token, *end;
const char *node_name;
int skip_current = 0;
if (parentoffset & 0x3)
return -1;
token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
+ parentoffset);
end = (const void *) struct_end (fdt);
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
return -1;
SKIP_NODE_NAME(node_name, token, end);
while (1) {
token = advance_token (fdt, token, end, skip_current);
if (!token)
return -1;
skip_current = 1;
node_name = (const char *) token + 4;
if (grub_strcmp (node_name, name) == 0)
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
- grub_fdt_get_off_dt_struct (fdt));
}
}
const char *
grub_fdt_get_nodename (const void *fdt, unsigned int nodeoffset)
{
return (const char *) fdt + grub_fdt_get_off_dt_struct(fdt) + nodeoffset + 4;
}
int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
@@ -359,6 +411,24 @@ int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
return add_subnode (fdt, parentoffset, name);
}
const void *
grub_fdt_get_prop (const void *fdt, unsigned int nodeoffset, const char *name,
grub_uint32_t *len)
{
grub_uint32_t *prop;
if ((nodeoffset >= grub_fdt_get_size_dt_struct (fdt)) || (nodeoffset & 0x3)
|| (grub_be_to_cpu32(*(grub_uint32_t *) ((grub_addr_t) fdt
+ grub_fdt_get_off_dt_struct (fdt) + nodeoffset))
!= FDT_BEGIN_NODE))
return 0;
prop = find_prop (fdt, nodeoffset, name);
if (!prop)
return 0;
if (len)
*len = grub_be_to_cpu32 (*(prop + 1));
return prop + 3;
}
int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, grub_uint32_t len)
{

View File

@@ -42,7 +42,7 @@ static grub_size_t linux_size;
static char *linux_args;
static grub_uint32_t machine_type;
static void *fdt_addr;
static const void *current_fdt;
typedef void (*kernel_entry_t) (int, unsigned long, void *);
@@ -54,9 +54,9 @@ typedef void (*kernel_entry_t) (int, unsigned long, void *);
#define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000)
static grub_size_t
get_atag_size (grub_uint32_t *atag)
get_atag_size (const grub_uint32_t *atag)
{
grub_uint32_t *atag0 = atag;
const grub_uint32_t *atag0 = atag;
while (atag[0] && atag[1])
atag += atag[0];
return atag - atag0;
@@ -68,10 +68,11 @@ get_atag_size (grub_uint32_t *atag)
* Merges in command line parameters and sets up initrd addresses.
*/
static grub_err_t
linux_prepare_atag (void)
linux_prepare_atag (void *target_atag)
{
grub_uint32_t *atag_orig = (grub_uint32_t *) fdt_addr;
grub_uint32_t *tmp_atag, *from, *to;
const grub_uint32_t *atag_orig = (const grub_uint32_t *) current_fdt;
grub_uint32_t *tmp_atag, *to;
const grub_uint32_t *from;
grub_size_t tmp_size;
grub_size_t arg_size = grub_strlen (linux_args);
char *cmdline_orig = NULL;
@@ -142,7 +143,7 @@ linux_prepare_atag (void)
to += 2;
/* Copy updated FDT to its launch location */
grub_memcpy (atag_orig, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag));
grub_memcpy (target_atag, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag));
grub_free (tmp_atag);
grub_dprintf ("loader", "ATAG updated for Linux boot\n");
@@ -156,19 +157,19 @@ linux_prepare_atag (void)
* Merges in command line parameters and sets up initrd addresses.
*/
static grub_err_t
linux_prepare_fdt (void)
linux_prepare_fdt (void *target_fdt)
{
int node;
int retval;
int tmp_size;
void *tmp_fdt;
tmp_size = grub_fdt_get_totalsize (fdt_addr) + 0x100 + grub_strlen (linux_args);
tmp_size = grub_fdt_get_totalsize (current_fdt) + 0x100 + grub_strlen (linux_args);
tmp_fdt = grub_malloc (tmp_size);
if (!tmp_fdt)
return grub_errno;
grub_memcpy (tmp_fdt, fdt_addr, grub_fdt_get_totalsize (fdt_addr));
grub_memcpy (tmp_fdt, current_fdt, grub_fdt_get_totalsize (current_fdt));
grub_fdt_set_totalsize (tmp_fdt, tmp_size);
/* Find or create '/chosen' node */
@@ -209,7 +210,7 @@ linux_prepare_fdt (void)
}
/* Copy updated FDT to its launch location */
grub_memcpy (fdt_addr, tmp_fdt, tmp_size);
grub_memcpy (target_fdt, tmp_fdt, tmp_size);
grub_free (tmp_fdt);
grub_dprintf ("loader", "FDT updated for Linux boot\n");
@@ -226,16 +227,17 @@ linux_boot (void)
{
kernel_entry_t linuxmain;
int fdt_valid, atag_valid;
void *target_fdt = 0;
fdt_valid = (fdt_addr && grub_fdt_check_header_nosize (fdt_addr) == 0);
atag_valid = ((((grub_uint16_t *) fdt_addr)[3] & ~3) == 0x5440
&& *((grub_uint32_t *) fdt_addr));
fdt_valid = (current_fdt && grub_fdt_check_header_nosize (current_fdt) == 0);
atag_valid = ((((const grub_uint16_t *) current_fdt)[3] & ~3) == 0x5440
&& *((const grub_uint32_t *) current_fdt));
grub_dprintf ("loader", "atag: %p, %x, %x, %s, %s\n",
fdt_addr,
((grub_uint16_t *) fdt_addr)[3],
*((grub_uint32_t *) fdt_addr),
(char *) fdt_addr,
(char *) fdt_addr + 1);
current_fdt,
((const grub_uint16_t *) current_fdt)[3],
*((const grub_uint32_t *) current_fdt),
(const char *) current_fdt,
(const char *) current_fdt + 1);
if (!fdt_valid && machine_type == GRUB_ARM_MACHINE_TYPE_FDT)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
@@ -245,23 +247,40 @@ linux_boot (void)
grub_dprintf ("loader", "Kernel at: 0x%x\n", linux_addr);
if (fdt_valid || atag_valid)
{
#ifdef GRUB_MACHINE_EFI
grub_size_t size;
if (fdt_valid)
size = grub_fdt_get_totalsize (fdt_addr);
else
size = 4 * get_atag_size (atag_orig);
size += grub_strlen (linux_args) + 256;
target_fdt = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size);
if (!fdt_addr)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
#else
target_fdt = (void *) LINUX_FDT_ADDRESS;
#endif
}
if (fdt_valid)
{
grub_err_t err;
err = linux_prepare_fdt ();
err = linux_prepare_fdt (target_fdt);
if (err)
return err;
grub_dprintf ("loader", "FDT @ 0x%p\n", fdt_addr);
grub_dprintf ("loader", "FDT @ %p\n", target_fdt);
}
else if (atag_valid)
{
grub_err_t err;
err = linux_prepare_atag ();
err = linux_prepare_atag (target_fdt);
if (err)
return err;
grub_dprintf ("loader", "ATAG @ 0x%p\n", fdt_addr);
grub_dprintf ("loader", "ATAG @ %p\n", target_fdt);
}
grub_dprintf ("loader", "Jumping to Linux...\n");
@@ -285,7 +304,7 @@ linux_boot (void)
grub_arm_disable_caches_mmu ();
linuxmain (0, machine_type, fdt_addr);
linuxmain (0, machine_type, target_fdt);
return grub_error (GRUB_ERR_BAD_OS, "Linux call returned");
}
@@ -444,11 +463,26 @@ fail:
static grub_err_t
load_dtb (grub_file_t dtb, int size)
{
if ((grub_file_read (dtb, fdt_addr, size) != size)
|| (grub_fdt_check_header (fdt_addr, size) != 0))
return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
void *new_fdt = grub_zalloc (size);
if (!new_fdt)
return grub_errno;
grub_dprintf ("loader", "Loading device tree to %p\n",
new_fdt);
if ((grub_file_read (dtb, new_fdt, size) != size)
|| (grub_fdt_check_header (new_fdt, size) != 0))
{
grub_free (new_fdt);
return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
}
grub_fdt_set_totalsize (new_fdt, size);
current_fdt = new_fdt;
/*
* We've successfully loaded an FDT, so any machine type passed
* from firmware is now obsolete.
*/
machine_type = GRUB_ARM_MACHINE_TYPE_FDT;
grub_fdt_set_totalsize (fdt_addr, size);
return GRUB_ERR_NONE;
}
@@ -464,42 +498,13 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
dtb = grub_file_open (argv[0]);
if (!dtb)
goto out;
return grub_errno;
size = grub_file_size (dtb);
if (size == 0)
{
grub_error (GRUB_ERR_BAD_OS, "empty file");
goto out;
}
#ifdef GRUB_MACHINE_EFI
fdt_addr = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size);
if (!fdt_addr)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
goto out;
}
#else
fdt_addr = (void *) LINUX_FDT_ADDRESS;
#endif
grub_dprintf ("loader", "Loading device tree to 0x%08x\n",
(grub_addr_t) fdt_addr);
load_dtb (dtb, size);
if (grub_errno != GRUB_ERR_NONE)
{
fdt_addr = NULL;
goto out;
}
/*
* We've successfully loaded an FDT, so any machine type passed
* from firmware is now obsolete.
*/
machine_type = GRUB_ARM_MACHINE_TYPE_FDT;
out:
grub_error (GRUB_ERR_BAD_OS, "empty file");
else
load_dtb (dtb, size);
grub_file_close (dtb);
return grub_errno;
@@ -517,7 +522,7 @@ GRUB_MOD_INIT (linux)
/* TRANSLATORS: DTB stands for device tree blob. */
0, N_("Load DTB file."));
my_mod = mod;
fdt_addr = (void *) grub_arm_firmware_get_boot_data ();
current_fdt = grub_arm_firmware_get_boot_data ();
machine_type = grub_arm_firmware_get_machine_type ();
}

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
# User-controllable options
grub_modinfo_target_cpu=@target_cpu@

View File

@@ -111,8 +111,8 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
}
grub_err_t
grub_net_arp_receive (struct grub_net_buff *nb,
struct grub_net_card *card)
grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,
grub_uint16_t *vlantag)
{
struct arppkt *arp_packet = (struct arppkt *) nb->data;
grub_net_network_level_address_t sender_addr, target_addr;
@@ -138,6 +138,14 @@ grub_net_arp_receive (struct grub_net_buff *nb,
FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
{
/* Verify vlantag id */
if (inf->card == card && inf->vlantag != *vlantag)
{
grub_dprintf ("net", "invalid vlantag! %x != %x\n",
inf->vlantag, *vlantag);
break;
}
/* Am I the protocol address target? */
if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
&& arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST))

View File

@@ -153,11 +153,11 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
char *comma_char = 0;
char *equal_char = 0;
grub_size_t field_counter = 0;
grub_net_network_level_address_t client_addr, gateway_addr, subnet_mask;
grub_net_link_level_address_t hw_addr;
grub_net_interface_flags_t flags = 0;
struct grub_net_network_level_interface *inter = NULL;
grub_uint16_t vlantag = 0;
hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
@@ -175,6 +175,11 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
*equal_char = 0;
grub_env_set_net_property ((*card)->name, args, equal_char + 1,
grub_strlen(equal_char + 1));
if ((grub_strcmp (args, "vtag") == 0) &&
(grub_strlen (equal_char + 1) == 8))
vlantag = grub_strtoul (equal_char + 1 + 4, 0, 16);
*equal_char = '=';
}
else
@@ -213,8 +218,10 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
hw_addr.mac, sizeof(hw_addr.mac), 0);
inter = grub_net_add_addr ((*card)->name, *card, &client_addr, &hw_addr,
flags);
inter->vlantag = vlantag;
grub_net_add_ipv4_local (inter,
__builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)));
}
if (gateway_addr.ipv4 != 0)

View File

@@ -18,6 +18,7 @@
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/env.h>
#include <grub/net/ethernet.h>
#include <grub/net/ip.h>
#include <grub/net/arp.h>
@@ -56,10 +57,17 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
{
struct etherhdr *eth;
grub_err_t err;
grub_uint8_t etherhdr_size;
grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER;
COMPILE_TIME_ASSERT (sizeof (*eth) < GRUB_NET_MAX_LINK_HEADER_SIZE);
etherhdr_size = sizeof (*eth);
COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
err = grub_netbuff_push (nb, sizeof (*eth));
/* Increase ethernet header in case of vlantag */
if (inf->vlantag != 0)
etherhdr_size += 4;
err = grub_netbuff_push (nb, etherhdr_size);
if (err)
return err;
eth = (struct etherhdr *) nb->data;
@@ -76,6 +84,19 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
return err;
inf->card->opened = 1;
}
/* Check and add a vlan-tag if needed. */
if (inf->vlantag != 0)
{
/* Move eth type to the right */
grub_memcpy ((char *) nb->data + etherhdr_size - 2,
(char *) nb->data + etherhdr_size - 6, 2);
/* Add the tag in the middle */
grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2);
grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *) &(inf->vlantag), 2);
}
return inf->card->driver->send (inf->card, nb);
}
@@ -90,10 +111,25 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
grub_net_link_level_address_t hwaddress;
grub_net_link_level_address_t src_hwaddress;
grub_err_t err;
grub_uint8_t etherhdr_size = sizeof (*eth);
grub_uint16_t vlantag = 0;
/* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */
/* longer than the original one. The vlantag id is extracted and the header */
/* is reseted to the original size. */
if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == VLANTAG_IDENTIFIER)
{
vlantag = grub_get_unaligned16 (nb->data + etherhdr_size);
etherhdr_size += 4;
/* Move eth type to the original position */
grub_memcpy((char *) nb->data + etherhdr_size - 6,
(char *) nb->data + etherhdr_size - 2, 2);
}
eth = (struct etherhdr *) nb->data;
type = grub_be_to_cpu16 (eth->type);
err = grub_netbuff_pull (nb, sizeof (*eth));
err = grub_netbuff_pull (nb, etherhdr_size);
if (err)
return err;
@@ -121,13 +157,14 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
{
/* ARP packet. */
case GRUB_NET_ETHERTYPE_ARP:
grub_net_arp_receive (nb, card);
grub_net_arp_receive (nb, card, &vlantag);
grub_netbuff_free (nb);
return GRUB_ERR_NONE;
/* IP packet. */
case GRUB_NET_ETHERTYPE_IP:
case GRUB_NET_ETHERTYPE_IP6:
return grub_net_recv_ip_packets (nb, card, &hwaddress, &src_hwaddress);
return grub_net_recv_ip_packets (nb, card, &hwaddress, &src_hwaddress,
&vlantag);
}
grub_netbuff_free (nb);
return GRUB_ERR_NONE;

View File

@@ -228,12 +228,13 @@ handle_dgram (struct grub_net_buff *nb,
grub_net_ip_protocol_t proto,
const grub_net_network_level_address_t *source,
const grub_net_network_level_address_t *dest,
grub_uint16_t *vlantag,
grub_uint8_t ttl)
{
struct grub_net_network_level_interface *inf = NULL;
grub_err_t err;
int multicast = 0;
/* DHCP needs special treatment since we don't know IP yet. */
{
struct udphdr *udph;
@@ -293,6 +294,15 @@ handle_dgram (struct grub_net_buff *nb,
&& grub_net_addr_cmp (&inf->address, dest) == 0
&& grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0)
break;
/* Verify vlantag id */
if (inf->card == card && inf->vlantag != *vlantag)
{
grub_dprintf ("net", "invalid vlantag! %x != %x\n",
inf->vlantag, *vlantag);
break;
}
/* Solicited node multicast. */
if (inf->card == card
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6
@@ -383,7 +393,8 @@ static grub_err_t
grub_net_recv_ip4_packets (struct grub_net_buff *nb,
struct grub_net_card *card,
const grub_net_link_level_address_t *hwaddress,
const grub_net_link_level_address_t *src_hwaddress)
const grub_net_link_level_address_t *src_hwaddress,
grub_uint16_t *vlantag)
{
struct iphdr *iph = (struct iphdr *) nb->data;
grub_err_t err;
@@ -458,7 +469,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb,
dest.ipv4 = iph->dest;
return handle_dgram (nb, card, src_hwaddress, hwaddress, iph->protocol,
&source, &dest, iph->ttl);
&source, &dest, vlantag, iph->ttl);
}
for (prev = &reassembles, rsm = *prev; rsm; prev = &rsm->next, rsm = *prev)
@@ -594,7 +605,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb,
dest.ipv4 = dst;
return handle_dgram (ret, card, src_hwaddress,
hwaddress, proto, &source, &dest,
hwaddress, proto, &source, &dest, vlantag,
ttl);
}
}
@@ -652,7 +663,8 @@ static grub_err_t
grub_net_recv_ip6_packets (struct grub_net_buff *nb,
struct grub_net_card *card,
const grub_net_link_level_address_t *hwaddress,
const grub_net_link_level_address_t *src_hwaddress)
const grub_net_link_level_address_t *src_hwaddress,
grub_uint16_t *vlantag)
{
struct ip6hdr *iph = (struct ip6hdr *) nb->data;
grub_err_t err;
@@ -703,21 +715,24 @@ grub_net_recv_ip6_packets (struct grub_net_buff *nb,
grub_memcpy (dest.ipv6, &iph->dest, sizeof (dest.ipv6));
return handle_dgram (nb, card, src_hwaddress, hwaddress, iph->protocol,
&source, &dest, iph->ttl);
&source, &dest, vlantag, iph->ttl);
}
grub_err_t
grub_net_recv_ip_packets (struct grub_net_buff *nb,
struct grub_net_card *card,
const grub_net_link_level_address_t *hwaddress,
const grub_net_link_level_address_t *src_hwaddress)
const grub_net_link_level_address_t *src_hwaddress,
grub_uint16_t *vlantag)
{
struct iphdr *iph = (struct iphdr *) nb->data;
if ((iph->verhdrlen >> 4) == 4)
return grub_net_recv_ip4_packets (nb, card, hwaddress, src_hwaddress);
return grub_net_recv_ip4_packets (nb, card, hwaddress, src_hwaddress,
vlantag);
if ((iph->verhdrlen >> 4) == 6)
return grub_net_recv_ip6_packets (nb, card, hwaddress, src_hwaddress);
return grub_net_recv_ip6_packets (nb, card, hwaddress, src_hwaddress,
vlantag);
grub_dprintf ("net", "Bad IP version: %d\n", (iph->verhdrlen >> 4));
grub_netbuff_free (nb);
return GRUB_ERR_NONE;

View File

@@ -77,11 +77,19 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz
int
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
{
#if SIZEOF_OFF_T == 8
off_t offset = (off_t) off;
if (lseek (fd, offset, SEEK_SET) != offset)
return -1;
#elif SIZEOF_OFF64_T == 8
off64_t offset = (off64_t) off;
if (lseek64 (fd, offset, SEEK_SET) != offset)
return -1;
#else
#error "No large file support"
#endif
return 0;
}

119
grub-core/term/arm/cros.c Normal file
View File

@@ -0,0 +1,119 @@
/*
* GRUB -- GRand Unified Bootloader
*
* Copyright (C) 2012 Google Inc.
* Copyright (C) 2016 Free Software Foundation, Inc.
*
* This is based on depthcharge code.
*
* 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/ps2.h>
#include <grub/fdtbus.h>
#include <grub/err.h>
#include <grub/machine/kernel.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/time.h>
#include <grub/fdtbus.h>
#include <grub/arm/cros_ec.h>
struct grub_ps2_state ps2_state;
struct grub_cros_ec_keyscan old_scan;
static grub_uint8_t map_code[GRUB_CROS_EC_KEYSCAN_COLS][GRUB_CROS_EC_KEYSCAN_ROWS];
static grub_uint8_t e0_translate[16] =
{
0x1c, 0x1d, 0x35, 0x00,
0x38, 0x00, 0x47, 0x48,
0x49, 0x4b, 0x4d, 0x4f,
0x50, 0x51, 0x52, 0x53,
};
/* If there is a character pending, return it;
otherwise return GRUB_TERM_NO_KEY. */
static int
grub_cros_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
{
struct grub_cros_ec_keyscan scan;
int i, j;
if (grub_cros_ec_scan_keyboard(&scan) < 0)
return GRUB_TERM_NO_KEY;
for (i = 0; i < GRUB_CROS_EC_KEYSCAN_COLS; i++)
if (scan.data[i] ^ old_scan.data[i])
for (j = 0; j < GRUB_CROS_EC_KEYSCAN_ROWS; j++)
if ((scan.data[i] ^ old_scan.data[i]) & (1 << j))
{
grub_uint8_t code = map_code[i][j];
int ret;
grub_uint8_t brk = 0;
if (!(scan.data[i] & (1 << j)))
brk = 0x80;
grub_dprintf ("cros_keyboard", "key <%d, %d> code %x\n", i, j, code);
if (code < 0x60)
ret = grub_ps2_process_incoming_byte (&ps2_state, code | brk);
else if (code >= 0x60 && code < 0x70 && e0_translate[code - 0x60])
{
grub_ps2_process_incoming_byte (&ps2_state, 0xe0);
ret = grub_ps2_process_incoming_byte (&ps2_state, e0_translate[code - 0x60] | brk);
}
else
ret = GRUB_TERM_NO_KEY;
old_scan.data[i] ^= (1 << j);
if (ret != GRUB_TERM_NO_KEY)
return ret;
}
return GRUB_TERM_NO_KEY;
}
static struct grub_term_input grub_cros_keyboard_term =
{
.name = "cros_keyboard",
.getkey = grub_cros_keyboard_getkey
};
static grub_err_t
cros_attach(const struct grub_fdtbus_dev *dev __attribute__ ((unused)))
{
grub_size_t keymap_size, i;
const grub_uint8_t *keymap = grub_fdtbus_get_prop (dev, "linux,keymap", &keymap_size);
if (keymap)
{
for (i = 0; i + 3 < keymap_size; i += 4)
if (keymap[i+1] < GRUB_CROS_EC_KEYSCAN_COLS && keymap[i] < GRUB_CROS_EC_KEYSCAN_ROWS
&& keymap[i+2] == 0 && keymap[i+3] < 0x80)
map_code[keymap[i+1]][keymap[i]] = keymap[i+3];
}
ps2_state.current_set = 1;
ps2_state.at_keyboard_status = 0;
grub_term_register_input ("cros_keyboard", &grub_cros_keyboard_term);
return GRUB_ERR_NONE;
}
struct grub_fdtbus_driver cros =
{
.compatible = "google,cros-ec-keyb",
.attach = cros_attach
};
void
grub_cros_init (void)
{
grub_fdtbus_register (&cros);
}

View File

@@ -0,0 +1,287 @@
/*
* GRUB -- GRand Unified Bootloader
*
* Copyright (C) 2012 Google Inc.
* Copyright (C) 2016 Free Software Foundation, Inc.
*
* This is based on depthcharge code.
*
* 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/mm.h>
#include <grub/time.h>
#include <grub/misc.h>
#include <grub/arm/cros_ec.h>
static grub_uint64_t
grub_get_time_us (void)
{
return 1000 * grub_get_time_ms ();
}
static void
grub_microsleep (grub_uint64_t len)
{
grub_uint64_t end_time = grub_get_time_us () + len;
while (grub_get_time_us () < end_time)
grub_cpu_idle ();
}
volatile grub_uint32_t *spi = (volatile grub_uint32_t *) 0xff110000;
static int
spi_send (const void *data, grub_size_t sz)
{
const grub_uint8_t *ptr = data, *end = ptr + sz;
spi[2] = 0;
spi[1] = sz - 1;
spi[0] = ((1 << 18) | spi[0]) & ~(1 << 19);
spi[2] = 1;
while (ptr < end)
{
while (spi[9] & 2);
spi[256] = *ptr++;
}
while (spi[9] & 1);
return 0;
}
static int
spi_read (void *data, grub_size_t sz)
{
grub_uint8_t *ptr = data, *end = ptr + sz;
spi[2] = 0;
spi[1] = sz - 1;
spi[0] = ((1 << 19) | spi[0]) & ~(1 << 18);
spi[2] = 1;
while (ptr < end)
{
while (spi[9] & 8);
*ptr++ = spi[512];
}
while (spi[9] & 1);
return 0;
}
static int
spi_start (void)
{
spi[3] = 1;
return 0;
}
static void
spi_stop (void)
{
spi[3] = 0;
}
#define uint8_t grub_uint8_t
#define uint16_t grub_uint16_t
#define uint32_t grub_uint32_t
#define uint64_t grub_uint64_t
#define mdelay grub_millisleep
#define memcpy grub_memcpy
static const uint64_t FramingTimeoutUs = 300 * 1000;
static const uint8_t EcFramingByte = 0xec;
#define EC_CMD_MKBP_STATE 0x60
#define EC_CMD_VERSION0 0xdc
static uint64_t last_transfer;
static void
stop_bus (void)
{
spi_stop ();
last_transfer = grub_get_time_us ();
}
static int
wait_for_frame (void)
{
uint64_t start = grub_get_time_us ();
uint8_t byte;
do
{
if (spi_read (&byte, 1))
return -1;
if (byte != EcFramingByte &&
grub_get_time_us () - start > FramingTimeoutUs)
{
grub_dprintf ("cros", "Timeout waiting for framing byte.\n");
return -1;
}
}
while (byte != EcFramingByte);
return 0;
}
/*
* Calculate a simple 8-bit checksum of a data block
*
* @param data Data block to checksum
* @param size Size of data block in bytes
* @return checksum value (0 to 255)
*/
static uint8_t
cros_ec_calc_checksum (const void *data, int size)
{
uint8_t csum;
const uint8_t *bytes = data;
int i;
for (i = csum = 0; i < size; i++)
csum += bytes[i];
return csum & 0xff;
}
enum
{
/* response, arglen */
CROS_EC_SPI_IN_HDR_SIZE = 2,
/* version, cmd, arglen */
CROS_EC_SPI_OUT_HDR_SIZE = 3
};
static grub_uint8_t busbuf[256];
#define MSG_BYTES ((int)sizeof (busbuf))
static int
ec_command (int cmd, int cmd_version,
const void *dout, int dout_len, void *din, int din_len)
{
uint8_t *bytes;
/* Header + data + checksum. */
uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1;
uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1;
/*
* Sanity-check I/O sizes given transaction overhead in internal
* buffers.
*/
if (out_bytes > MSG_BYTES)
{
grub_dprintf ("cros", "Cannot send %d bytes\n", dout_len);
return -1;
}
if (in_bytes > MSG_BYTES)
{
grub_dprintf ("cros", "Cannot receive %d bytes\n", din_len);
return -1;
}
/* Prepare the output. */
bytes = busbuf;
*bytes++ = EC_CMD_VERSION0 + cmd_version;
*bytes++ = cmd;
*bytes++ = dout_len;
memcpy (bytes, dout, dout_len);
bytes += dout_len;
*bytes++ = cros_ec_calc_checksum (busbuf,
CROS_EC_SPI_OUT_HDR_SIZE + dout_len);
while (grub_get_time_us () - last_transfer < 200)
;
if (spi_start ())
return -1;
/* Allow EC to ramp up clock after being awoken. */
/* See chrome-os-partner:32223 for more details. */
grub_microsleep (100);
if (spi_send (busbuf, out_bytes))
{
stop_bus ();
return -1;
}
/* Wait until the EC is ready. */
if (wait_for_frame ())
{
stop_bus ();
return -1;
}
/* Read the response code and the data length. */
bytes = busbuf;
if (spi_read (bytes, 2))
{
stop_bus ();
return -1;
}
uint8_t result = *bytes++;
uint8_t length = *bytes++;
/* Make sure there's enough room for the data. */
if (CROS_EC_SPI_IN_HDR_SIZE + length + 1 > MSG_BYTES)
{
grub_dprintf ("cros", "Received length %#02x too large\n", length);
stop_bus ();
return -1;
}
/* Read the data and the checksum, and finish up. */
if (spi_read (bytes, length + 1))
{
stop_bus ();
return -1;
}
bytes += length;
int expected = *bytes++;
stop_bus ();
/* Check the integrity of the response. */
if (result != 0)
{
grub_dprintf ("cros", "Received bad result code %d\n", result);
return -result;
}
int csum = cros_ec_calc_checksum (busbuf,
CROS_EC_SPI_IN_HDR_SIZE + length);
if (csum != expected)
{
grub_dprintf ("cros", "Invalid checksum rx %#02x, calced %#02x\n",
expected, csum);
return -1;
}
/* If the caller wants the response, copy it out for them. */
if (length < din_len)
din_len = length;
if (din)
{
memcpy (din, (uint8_t *) busbuf + CROS_EC_SPI_IN_HDR_SIZE, din_len);
}
return din_len;
}
int
grub_cros_ec_scan_keyboard (struct grub_cros_ec_keyscan *scan)
{
if (ec_command (EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
sizeof (*scan)) < (int) sizeof (*scan))
return -1;
return 0;
}

189
grub-core/term/arm/pl050.c Normal file
View File

@@ -0,0 +1,189 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/ps2.h>
#include <grub/fdtbus.h>
#include <grub/err.h>
#include <grub/machine/kernel.h>
#include <grub/at_keyboard.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/time.h>
#include <grub/ps2.h>
#include <grub/fdtbus.h>
static volatile grub_uint32_t *pl050_regs;
struct grub_ps2_state ps2_state;
static void
keyboard_controller_wait_until_ready (void)
{
while (! (pl050_regs[1] & 0x40));
}
static grub_uint8_t
wait_ack (void)
{
grub_uint64_t endtime;
grub_uint8_t ack;
endtime = grub_get_time_ms () + 20;
do
ack = pl050_regs[2];
while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK
&& grub_get_time_ms () < endtime);
return ack;
}
static int
write_mode (int mode)
{
unsigned i;
for (i = 0; i < GRUB_AT_TRIES; i++)
{
grub_uint8_t ack;
keyboard_controller_wait_until_ready ();
pl050_regs[2] = 0xf0;
keyboard_controller_wait_until_ready ();
pl050_regs[2] = mode;
keyboard_controller_wait_until_ready ();
ack = wait_ack ();
if (ack == GRUB_AT_NACK)
continue;
if (ack == GRUB_AT_ACK)
break;
return 0;
}
return (i != GRUB_AT_TRIES);
}
static int
query_mode (void)
{
grub_uint8_t ret;
int e;
e = write_mode (0);
if (!e)
return 0;
keyboard_controller_wait_until_ready ();
do
ret = pl050_regs[2];
while (ret == GRUB_AT_ACK);
/* QEMU translates the set even in no-translate mode. */
if (ret == 0x43 || ret == 1)
return 1;
if (ret == 0x41 || ret == 2)
return 2;
if (ret == 0x3f || ret == 3)
return 3;
return 0;
}
static void
set_scancodes (void)
{
write_mode (2);
ps2_state.current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
if (ps2_state.current_set == 2)
return;
write_mode (1);
ps2_state.current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
if (ps2_state.current_set == 1)
return;
grub_dprintf ("atkeyb", "no supported scancode set found\n");
}
static void
keyboard_controller_led (grub_uint8_t leds)
{
keyboard_controller_wait_until_ready ();
pl050_regs[2] = 0xed;
keyboard_controller_wait_until_ready ();
pl050_regs[2] = leds & 0x7;
}
/* If there is a character pending, return it;
otherwise return GRUB_TERM_NO_KEY. */
static int
grub_pl050_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
{
grub_uint8_t at_key;
int ret;
grub_uint8_t old_led;
if (!(pl050_regs[1] & 0x10))
return -1;
at_key = pl050_regs[2];
old_led = ps2_state.led_status;
ret = grub_ps2_process_incoming_byte (&ps2_state, at_key);
if (old_led != ps2_state.led_status)
keyboard_controller_led (ps2_state.led_status);
return ret;
}
static struct grub_term_input grub_pl050_keyboard_term =
{
.name = "pl050_keyboard",
.getkey = grub_pl050_keyboard_getkey
};
static grub_err_t
pl050_attach(const struct grub_fdtbus_dev *dev)
{
const grub_uint32_t *reg;
reg = grub_fdtbus_get_prop (dev, "reg", 0);
/* Mouse. Nothing to do. */
if (grub_be_to_cpu32 (*reg) == 0x7000)
return 0;
pl050_regs = grub_fdtbus_map_reg (dev, 0, 0);
if (!grub_fdtbus_is_mapping_valid (pl050_regs))
return grub_error (GRUB_ERR_IO, "could not map pl050");
ps2_state.at_keyboard_status = 0;
set_scancodes ();
keyboard_controller_led (ps2_state.led_status);
grub_term_register_input ("pl050_keyboard", &grub_pl050_keyboard_term);
return GRUB_ERR_NONE;
}
struct grub_fdtbus_driver pl050 =
{
.compatible = "arm,pl050",
.attach = pl050_attach
};
void
grub_pl050_init (void)
{
grub_fdtbus_register (&pl050);
}

View File

@@ -22,212 +22,21 @@
#include <grub/cpu/io.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/keyboard_layouts.h>
#include <grub/time.h>
#include <grub/loader.h>
#include <grub/ps2.h>
GRUB_MOD_LICENSE ("GPLv3+");
static short at_keyboard_status = 0;
static int e0_received = 0;
static int f0_received = 0;
static grub_uint8_t led_status;
#define KEYBOARD_LED_SCROLL (1 << 0)
#define KEYBOARD_LED_NUM (1 << 1)
#define KEYBOARD_LED_CAPS (1 << 2)
static grub_uint8_t grub_keyboard_controller_orig;
static grub_uint8_t grub_keyboard_orig_set;
static grub_uint8_t current_set;
struct grub_ps2_state ps2_state;
static int ping_sent;
static void
grub_keyboard_controller_init (void);
static const grub_uint8_t set1_mapping[128] =
{
/* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE,
/* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2,
/* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4,
/* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6,
/* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8,
/* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0,
/* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB,
/* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W,
/* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R,
/* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y,
/* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I,
/* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P,
/* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET,
/* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL,
/* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S,
/* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F,
/* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H,
/* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K,
/* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON,
/* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE,
/* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH,
/* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X,
/* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V,
/* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N,
/* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA,
/* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH,
/* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL,
/* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE,
/* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1,
/* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3,
/* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5,
/* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7,
/* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9,
/* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK,
/* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7,
/* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9,
/* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4,
/* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6,
/* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1,
/* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3,
/* 0x52 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
/* 0x54 */ 0, 0,
/* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11,
/* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0,
/* 0x5a */ 0, 0,
/* 0x5c */ 0, 0,
/* 0x5e */ 0, 0,
/* 0x60 */ 0, 0,
/* 0x62 */ 0, 0,
/* OLPC keys. Just mapped to normal keys. */
/* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP,
/* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT,
/* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0,
/* 0x6a */ 0, 0,
/* 0x6c */ 0, 0,
/* 0x6e */ 0, 0,
/* 0x70 */ 0, 0,
/* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x74 */ 0, 0,
/* 0x76 */ 0, 0,
/* 0x78 */ 0, 0,
/* 0x7a */ 0, 0,
/* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN,
/* 0x7e */ GRUB_KEYBOARD_KEY_KPCOMMA
};
static const struct
{
grub_uint8_t from, to;
} set1_e0_mapping[] =
{
{0x1c, GRUB_KEYBOARD_KEY_NUMENTER},
{0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x35, GRUB_KEYBOARD_KEY_NUMSLASH },
{0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x47, GRUB_KEYBOARD_KEY_HOME},
{0x48, GRUB_KEYBOARD_KEY_UP},
{0x49, GRUB_KEYBOARD_KEY_PPAGE},
{0x4b, GRUB_KEYBOARD_KEY_LEFT},
{0x4d, GRUB_KEYBOARD_KEY_RIGHT},
{0x4f, GRUB_KEYBOARD_KEY_END},
{0x50, GRUB_KEYBOARD_KEY_DOWN},
{0x51, GRUB_KEYBOARD_KEY_NPAGE},
{0x52, GRUB_KEYBOARD_KEY_INSERT},
{0x53, GRUB_KEYBOARD_KEY_DELETE},
};
static const grub_uint8_t set2_mapping[256] =
{
/* 0x00 */ 0, GRUB_KEYBOARD_KEY_F9,
/* 0x02 */ 0, GRUB_KEYBOARD_KEY_F5,
/* 0x04 */ GRUB_KEYBOARD_KEY_F3, GRUB_KEYBOARD_KEY_F1,
/* 0x06 */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F12,
/* 0x08 */ 0, GRUB_KEYBOARD_KEY_F10,
/* 0x0a */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F6,
/* 0x0c */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_TAB,
/* 0x0e */ GRUB_KEYBOARD_KEY_RQUOTE, 0,
/* 0x10 */ 0, GRUB_KEYBOARD_KEY_LEFT_ALT,
/* 0x12 */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, 0,
/* 0x14 */ GRUB_KEYBOARD_KEY_LEFT_CTRL, GRUB_KEYBOARD_KEY_Q,
/* 0x16 */ GRUB_KEYBOARD_KEY_1, 0,
/* 0x18 */ 0, 0,
/* 0x1a */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_S,
/* 0x1c */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_W,
/* 0x1e */ GRUB_KEYBOARD_KEY_2, 0,
/* 0x20 */ 0, GRUB_KEYBOARD_KEY_C,
/* 0x22 */ GRUB_KEYBOARD_KEY_X, GRUB_KEYBOARD_KEY_D,
/* 0x24 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_4,
/* 0x26 */ GRUB_KEYBOARD_KEY_3, 0,
/* 0x28 */ 0, GRUB_KEYBOARD_KEY_SPACE,
/* 0x2a */ GRUB_KEYBOARD_KEY_V, GRUB_KEYBOARD_KEY_F,
/* 0x2c */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_R,
/* 0x2e */ GRUB_KEYBOARD_KEY_5, 0,
/* 0x30 */ 0, GRUB_KEYBOARD_KEY_N,
/* 0x32 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_H,
/* 0x34 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_Y,
/* 0x36 */ GRUB_KEYBOARD_KEY_6, 0,
/* 0x38 */ 0, 0,
/* 0x3a */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_J,
/* 0x3c */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_7,
/* 0x3e */ GRUB_KEYBOARD_KEY_8, 0,
/* 0x40 */ 0, GRUB_KEYBOARD_KEY_COMMA,
/* 0x42 */ GRUB_KEYBOARD_KEY_K, GRUB_KEYBOARD_KEY_I,
/* 0x44 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_0,
/* 0x46 */ GRUB_KEYBOARD_KEY_9, 0,
/* 0x48 */ 0, GRUB_KEYBOARD_KEY_DOT,
/* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L,
/* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P,
/* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0,
/* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0,
/* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x56 */ 0, 0,
/* 0x58 */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_RIGHT_SHIFT,
/* 0x5a */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_RBRACKET,
/* 0x5c */ 0, GRUB_KEYBOARD_KEY_BACKSLASH,
/* 0x5e */ 0, 0,
/* 0x60 */ 0, GRUB_KEYBOARD_KEY_102ND,
/* 0x62 */ 0, 0,
/* 0x64 */ 0, 0,
/* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0,
/* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1,
/* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4,
/* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, GRUB_KEYBOARD_KEY_KPCOMMA,
/* 0x6e */ 0, 0,
/* 0x70 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
/* 0x72 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM5,
/* 0x74 */ GRUB_KEYBOARD_KEY_NUM6, GRUB_KEYBOARD_KEY_NUM8,
/* 0x76 */ GRUB_KEYBOARD_KEY_ESCAPE, GRUB_KEYBOARD_KEY_NUM_LOCK,
/* 0x78 */ GRUB_KEYBOARD_KEY_F11, GRUB_KEYBOARD_KEY_NUMPLUS,
/* 0x7a */ GRUB_KEYBOARD_KEY_NUM3, GRUB_KEYBOARD_KEY_NUMMINUS,
/* 0x7c */ GRUB_KEYBOARD_KEY_NUMMUL, GRUB_KEYBOARD_KEY_NUM9,
/* 0x7e */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, 0,
/* 0x80 */ 0, 0,
/* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7,
};
static const struct
{
grub_uint8_t from, to;
} set2_e0_mapping[] =
{
{0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x4a, GRUB_KEYBOARD_KEY_NUMSLASH},
{0x5a, GRUB_KEYBOARD_KEY_NUMENTER},
{0x69, GRUB_KEYBOARD_KEY_END},
{0x6b, GRUB_KEYBOARD_KEY_LEFT},
{0x6c, GRUB_KEYBOARD_KEY_HOME},
{0x70, GRUB_KEYBOARD_KEY_INSERT},
{0x71, GRUB_KEYBOARD_KEY_DELETE},
{0x72, GRUB_KEYBOARD_KEY_DOWN},
{0x74, GRUB_KEYBOARD_KEY_RIGHT},
{0x75, GRUB_KEYBOARD_KEY_UP},
{0x7a, GRUB_KEYBOARD_KEY_NPAGE},
{0x7d, GRUB_KEYBOARD_KEY_PPAGE},
};
static int ping_sent;
static void
keyboard_controller_wait_until_ready (void)
{
@@ -350,12 +159,12 @@ set_scancodes (void)
if (!grub_keyboard_orig_set)
{
grub_dprintf ("atkeyb", "No sets support assumed\n");
current_set = 1;
ps2_state.current_set = 1;
return;
}
#if !USE_SCANCODE_SET
current_set = 1;
ps2_state.current_set = 1;
return;
#else
@@ -363,15 +172,15 @@ set_scancodes (void)
& ~KEYBOARD_AT_TRANSLATE);
write_mode (2);
current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", current_set);
if (current_set == 2)
ps2_state.current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
if (ps2_state.current_set == 2)
return;
write_mode (1);
current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", current_set);
if (current_set == 1)
ps2_state.current_set = query_mode ();
grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
if (ps2_state.current_set == 1)
return;
grub_dprintf ("atkeyb", "no supported scancode set found\n");
#endif
@@ -386,164 +195,10 @@ keyboard_controller_led (grub_uint8_t leds)
grub_outb (leds & 0x7, KEYBOARD_REG_DATA);
}
static int
fetch_key (int *is_break)
{
int was_ext = 0;
grub_uint8_t at_key;
int ret = 0;
if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
return -1;
at_key = grub_inb (KEYBOARD_REG_DATA);
/* May happen if no keyboard is connected. Just ignore this. */
if (at_key == 0xff)
return -1;
if (at_key == 0xe0)
{
e0_received = 1;
return -1;
}
if ((current_set == 2 || current_set == 3) && at_key == 0xf0)
{
f0_received = 1;
return -1;
}
/* Setting LEDs may generate ACKs. */
if (at_key == GRUB_AT_ACK)
return -1;
was_ext = e0_received;
e0_received = 0;
switch (current_set)
{
case 1:
*is_break = !!(at_key & 0x80);
if (!was_ext)
ret = set1_mapping[at_key & 0x7f];
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++)
if (set1_e0_mapping[i].from == (at_key & 0x7f))
{
ret = set1_e0_mapping[i].to;
break;
}
}
break;
case 2:
*is_break = f0_received;
f0_received = 0;
if (!was_ext)
ret = set2_mapping[at_key];
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++)
if (set2_e0_mapping[i].from == at_key)
{
ret = set2_e0_mapping[i].to;
break;
}
}
break;
default:
return -1;
}
if (!ret)
{
if (was_ext)
grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n",
at_key, current_set);
else
grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n",
at_key, current_set);
return -1;
}
return ret;
}
/* FIXME: This should become an interrupt service routine. For now
it's just used to catch events from control keys. */
static int
grub_keyboard_isr (grub_keyboard_key_t key, int is_break)
{
if (!is_break)
switch (key)
{
case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
at_keyboard_status |= GRUB_TERM_STATUS_LSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
at_keyboard_status |= GRUB_TERM_STATUS_RSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_CTRL:
at_keyboard_status |= GRUB_TERM_STATUS_LCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
at_keyboard_status |= GRUB_TERM_STATUS_RCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_ALT:
at_keyboard_status |= GRUB_TERM_STATUS_RALT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_ALT:
at_keyboard_status |= GRUB_TERM_STATUS_LALT;
return 1;
default:
return 0;
}
else
switch (key)
{
case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
at_keyboard_status &= ~GRUB_TERM_STATUS_LSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
at_keyboard_status &= ~GRUB_TERM_STATUS_RSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_CTRL:
at_keyboard_status &= ~GRUB_TERM_STATUS_LCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
at_keyboard_status &= ~GRUB_TERM_STATUS_RCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_ALT:
at_keyboard_status &= ~GRUB_TERM_STATUS_RALT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_ALT:
at_keyboard_status &= ~GRUB_TERM_STATUS_LALT;
return 1;
default:
return 0;
}
}
/* If there is a raw key pending, return it; otherwise return -1. */
static int
grub_keyboard_getkey (void)
{
int key;
int is_break = 0;
key = fetch_key (&is_break);
if (key == -1)
return -1;
if (grub_keyboard_isr (key, is_break))
return -1;
if (is_break)
return -1;
return key;
}
int
grub_at_keyboard_is_alive (void)
{
if (current_set != 0)
if (ps2_state.current_set != 0)
return 1;
if (ping_sent
&& KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))
@@ -566,51 +221,28 @@ grub_at_keyboard_is_alive (void)
static int
grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
{
int code;
grub_uint8_t at_key;
int ret;
grub_uint8_t old_led;
if (!grub_at_keyboard_is_alive ())
return GRUB_TERM_NO_KEY;
code = grub_keyboard_getkey ();
if (code == -1)
return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "Detected key 0x%x\n", code);
#endif
switch (code)
{
case GRUB_KEYBOARD_KEY_CAPS_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_CAPS;
led_status ^= KEYBOARD_LED_CAPS;
keyboard_controller_led (led_status);
if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
return -1;
at_key = grub_inb (KEYBOARD_REG_DATA);
old_led = ps2_state.led_status;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & GRUB_KEYBOARD_STATUS_CAPS_LOCK));
#endif
return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_NUM_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
led_status ^= KEYBOARD_LED_NUM;
keyboard_controller_led (led_status);
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & GRUB_KEYBOARD_STATUS_NUM_LOCK));
#endif
return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
led_status ^= KEYBOARD_LED_SCROLL;
keyboard_controller_led (led_status);
return GRUB_TERM_NO_KEY;
default:
return grub_term_map_key (code, at_keyboard_status);
}
ret = grub_ps2_process_incoming_byte (&ps2_state, at_key);
if (old_led != ps2_state.led_status)
keyboard_controller_led (ps2_state.led_status);
return ret;
}
static void
grub_keyboard_controller_init (void)
{
at_keyboard_status = 0;
ps2_state.at_keyboard_status = 0;
/* Drain input buffer. */
while (1)
{
@@ -632,13 +264,13 @@ grub_keyboard_controller_init (void)
grub_keyboard_orig_set = query_mode ();
#endif
set_scancodes ();
keyboard_controller_led (led_status);
keyboard_controller_led (ps2_state.led_status);
}
static grub_err_t
grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused)))
{
if (current_set == 0)
if (ps2_state.current_set == 0)
return GRUB_ERR_NONE;
if (grub_keyboard_orig_set)
write_mode (grub_keyboard_orig_set);
@@ -655,7 +287,7 @@ grub_at_fini_hw (int noreturn __attribute__ ((unused)))
static grub_err_t
grub_at_restore_hw (void)
{
if (current_set == 0)
if (ps2_state.current_set == 0)
return GRUB_ERR_NONE;
/* Drain input buffer. */
@@ -668,7 +300,7 @@ grub_at_restore_hw (void)
grub_inb (KEYBOARD_REG_DATA);
}
set_scancodes ();
keyboard_controller_led (led_status);
keyboard_controller_led (ps2_state.led_status);
return GRUB_ERR_NONE;
}

View File

@@ -23,7 +23,7 @@
#include <grub/time.h>
#include <grub/terminfo.h>
#include <grub/dl.h>
#include <grub/i386/coreboot/lbio.h>
#include <grub/coreboot/lbio.h>
#include <grub/command.h>
#include <grub/normal.h>

387
grub-core/term/ps2.c Normal file
View File

@@ -0,0 +1,387 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/keyboard_layouts.h>
#include <grub/ps2.h>
#define KEYBOARD_LED_SCROLL (1 << 0)
#define KEYBOARD_LED_NUM (1 << 1)
#define KEYBOARD_LED_CAPS (1 << 2)
static const grub_uint8_t set1_mapping[128] =
{
/* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE,
/* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2,
/* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4,
/* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6,
/* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8,
/* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0,
/* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB,
/* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W,
/* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R,
/* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y,
/* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I,
/* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P,
/* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET,
/* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL,
/* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S,
/* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F,
/* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H,
/* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K,
/* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON,
/* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE,
/* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH,
/* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X,
/* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V,
/* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N,
/* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA,
/* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH,
/* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL,
/* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE,
/* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1,
/* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3,
/* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5,
/* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7,
/* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9,
/* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK,
/* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7,
/* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9,
/* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4,
/* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6,
/* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1,
/* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3,
/* 0x52 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
/* 0x54 */ 0, 0,
/* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11,
/* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0,
/* 0x5a */ 0, 0,
/* 0x5c */ 0, 0,
/* 0x5e */ 0, 0,
/* 0x60 */ 0, 0,
/* 0x62 */ 0, 0,
/* OLPC keys. Just mapped to normal keys. */
/* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP,
/* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT,
/* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0,
/* 0x6a */ 0, 0,
/* 0x6c */ 0, 0,
/* 0x6e */ 0, 0,
/* 0x70 */ 0, 0,
/* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x74 */ 0, 0,
/* 0x76 */ 0, 0,
/* 0x78 */ 0, 0,
/* 0x7a */ 0, 0,
/* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN,
/* 0x7e */ GRUB_KEYBOARD_KEY_KPCOMMA
};
static const struct
{
grub_uint8_t from, to;
} set1_e0_mapping[] =
{
{0x1c, GRUB_KEYBOARD_KEY_NUMENTER},
{0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x35, GRUB_KEYBOARD_KEY_NUMSLASH },
{0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x47, GRUB_KEYBOARD_KEY_HOME},
{0x48, GRUB_KEYBOARD_KEY_UP},
{0x49, GRUB_KEYBOARD_KEY_PPAGE},
{0x4b, GRUB_KEYBOARD_KEY_LEFT},
{0x4d, GRUB_KEYBOARD_KEY_RIGHT},
{0x4f, GRUB_KEYBOARD_KEY_END},
{0x50, GRUB_KEYBOARD_KEY_DOWN},
{0x51, GRUB_KEYBOARD_KEY_NPAGE},
{0x52, GRUB_KEYBOARD_KEY_INSERT},
{0x53, GRUB_KEYBOARD_KEY_DELETE},
};
static const grub_uint8_t set2_mapping[256] =
{
/* 0x00 */ 0, GRUB_KEYBOARD_KEY_F9,
/* 0x02 */ 0, GRUB_KEYBOARD_KEY_F5,
/* 0x04 */ GRUB_KEYBOARD_KEY_F3, GRUB_KEYBOARD_KEY_F1,
/* 0x06 */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F12,
/* 0x08 */ 0, GRUB_KEYBOARD_KEY_F10,
/* 0x0a */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F6,
/* 0x0c */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_TAB,
/* 0x0e */ GRUB_KEYBOARD_KEY_RQUOTE, 0,
/* 0x10 */ 0, GRUB_KEYBOARD_KEY_LEFT_ALT,
/* 0x12 */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, 0,
/* 0x14 */ GRUB_KEYBOARD_KEY_LEFT_CTRL, GRUB_KEYBOARD_KEY_Q,
/* 0x16 */ GRUB_KEYBOARD_KEY_1, 0,
/* 0x18 */ 0, 0,
/* 0x1a */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_S,
/* 0x1c */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_W,
/* 0x1e */ GRUB_KEYBOARD_KEY_2, 0,
/* 0x20 */ 0, GRUB_KEYBOARD_KEY_C,
/* 0x22 */ GRUB_KEYBOARD_KEY_X, GRUB_KEYBOARD_KEY_D,
/* 0x24 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_4,
/* 0x26 */ GRUB_KEYBOARD_KEY_3, 0,
/* 0x28 */ 0, GRUB_KEYBOARD_KEY_SPACE,
/* 0x2a */ GRUB_KEYBOARD_KEY_V, GRUB_KEYBOARD_KEY_F,
/* 0x2c */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_R,
/* 0x2e */ GRUB_KEYBOARD_KEY_5, 0,
/* 0x30 */ 0, GRUB_KEYBOARD_KEY_N,
/* 0x32 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_H,
/* 0x34 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_Y,
/* 0x36 */ GRUB_KEYBOARD_KEY_6, 0,
/* 0x38 */ 0, 0,
/* 0x3a */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_J,
/* 0x3c */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_7,
/* 0x3e */ GRUB_KEYBOARD_KEY_8, 0,
/* 0x40 */ 0, GRUB_KEYBOARD_KEY_COMMA,
/* 0x42 */ GRUB_KEYBOARD_KEY_K, GRUB_KEYBOARD_KEY_I,
/* 0x44 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_0,
/* 0x46 */ GRUB_KEYBOARD_KEY_9, 0,
/* 0x48 */ 0, GRUB_KEYBOARD_KEY_DOT,
/* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L,
/* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P,
/* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0,
/* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
/* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0,
/* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL,
/* 0x56 */ 0, 0,
/* 0x58 */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_RIGHT_SHIFT,
/* 0x5a */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_RBRACKET,
/* 0x5c */ 0, GRUB_KEYBOARD_KEY_BACKSLASH,
/* 0x5e */ 0, 0,
/* 0x60 */ 0, GRUB_KEYBOARD_KEY_102ND,
/* 0x62 */ 0, 0,
/* 0x64 */ 0, 0,
/* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0,
/* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1,
/* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4,
/* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, GRUB_KEYBOARD_KEY_KPCOMMA,
/* 0x6e */ 0, 0,
/* 0x70 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
/* 0x72 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM5,
/* 0x74 */ GRUB_KEYBOARD_KEY_NUM6, GRUB_KEYBOARD_KEY_NUM8,
/* 0x76 */ GRUB_KEYBOARD_KEY_ESCAPE, GRUB_KEYBOARD_KEY_NUM_LOCK,
/* 0x78 */ GRUB_KEYBOARD_KEY_F11, GRUB_KEYBOARD_KEY_NUMPLUS,
/* 0x7a */ GRUB_KEYBOARD_KEY_NUM3, GRUB_KEYBOARD_KEY_NUMMINUS,
/* 0x7c */ GRUB_KEYBOARD_KEY_NUMMUL, GRUB_KEYBOARD_KEY_NUM9,
/* 0x7e */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, 0,
/* 0x80 */ 0, 0,
/* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7,
};
static const struct
{
grub_uint8_t from, to;
} set2_e0_mapping[] =
{
{0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x4a, GRUB_KEYBOARD_KEY_NUMSLASH},
{0x5a, GRUB_KEYBOARD_KEY_NUMENTER},
{0x69, GRUB_KEYBOARD_KEY_END},
{0x6b, GRUB_KEYBOARD_KEY_LEFT},
{0x6c, GRUB_KEYBOARD_KEY_HOME},
{0x70, GRUB_KEYBOARD_KEY_INSERT},
{0x71, GRUB_KEYBOARD_KEY_DELETE},
{0x72, GRUB_KEYBOARD_KEY_DOWN},
{0x74, GRUB_KEYBOARD_KEY_RIGHT},
{0x75, GRUB_KEYBOARD_KEY_UP},
{0x7a, GRUB_KEYBOARD_KEY_NPAGE},
{0x7d, GRUB_KEYBOARD_KEY_PPAGE},
};
static int
fetch_key (struct grub_ps2_state *ps2_state, grub_uint8_t at_key, int *is_break)
{
int was_ext = 0;
int ret = 0;
/* May happen if no keyboard is connected. Just ignore this. */
if (at_key == 0xff)
return -1;
if (at_key == 0xe0)
{
ps2_state->e0_received = 1;
return -1;
}
if ((ps2_state->current_set == 2 || ps2_state->current_set == 3) && at_key == 0xf0)
{
ps2_state->f0_received = 1;
return -1;
}
/* Setting LEDs may generate ACKs. */
if (at_key == GRUB_AT_ACK)
return -1;
was_ext = ps2_state->e0_received;
ps2_state->e0_received = 0;
switch (ps2_state->current_set)
{
case 1:
*is_break = !!(at_key & 0x80);
if (!was_ext)
ret = set1_mapping[at_key & 0x7f];
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++)
if (set1_e0_mapping[i].from == (at_key & 0x7f))
{
ret = set1_e0_mapping[i].to;
break;
}
}
break;
case 2:
*is_break = ps2_state->f0_received;
ps2_state->f0_received = 0;
if (!was_ext)
ret = set2_mapping[at_key];
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++)
if (set2_e0_mapping[i].from == at_key)
{
ret = set2_e0_mapping[i].to;
break;
}
}
break;
default:
return -1;
}
if (!ret)
{
if (was_ext)
grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n",
at_key, ps2_state->current_set);
else
grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n",
at_key, ps2_state->current_set);
return -1;
}
return ret;
}
/* FIXME: This should become an interrupt service routine. For now
it's just used to catch events from control keys. */
static int
grub_keyboard_isr (struct grub_ps2_state *ps2_state,
grub_keyboard_key_t key, int is_break)
{
if (!is_break)
switch (key)
{
case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_CTRL:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_ALT:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RALT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_ALT:
ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LALT;
return 1;
default:
return 0;
}
else
switch (key)
{
case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RSHIFT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_CTRL:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RCTRL;
return 1;
case GRUB_KEYBOARD_KEY_RIGHT_ALT:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RALT;
return 1;
case GRUB_KEYBOARD_KEY_LEFT_ALT:
ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LALT;
return 1;
default:
return 0;
}
}
/* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */
int
grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state,
grub_uint8_t at_key)
{
int code;
int is_break = 0;
code = fetch_key (ps2_state, at_key, &is_break);
if (code == -1)
return GRUB_TERM_NO_KEY;
if (grub_keyboard_isr (ps2_state, code, is_break))
return GRUB_TERM_NO_KEY;
if (is_break)
return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "Detected key 0x%x\n", code);
#endif
switch (code)
{
case GRUB_KEYBOARD_KEY_CAPS_LOCK:
ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_CAPS;
ps2_state->led_status ^= KEYBOARD_LED_CAPS;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_CAPS_LOCK));
#endif
return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_NUM_LOCK:
ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
ps2_state->led_status ^= KEYBOARD_LED_NUM;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_NUM_LOCK));
#endif
return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
ps2_state->led_status ^= KEYBOARD_LED_SCROLL;
return GRUB_TERM_NO_KEY;
default:
return grub_term_map_key (code, ps2_state->at_keyboard_status);
}
}

View File

@@ -26,14 +26,23 @@ GRUB_MOD_LICENSE ("GPLv3+");
static grub_err_t
grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
int argc,
char **args)
{
grub_test_t test;
int ok = 1;
int i;
FOR_LIST_ELEMENTS (test, grub_test_list)
{
if (argc != 0)
{
for (i = 0; i < argc; i++)
if (grub_strcmp(args[i], test->name) == 0)
break;
if (i == argc)
continue;
}
grub_errno = 0;
ok = ok && !grub_test_run (test);
grub_errno = 0;

View File

@@ -25,7 +25,7 @@
#include <grub/mm.h>
#include <grub/video.h>
#include <grub/video_fb.h>
#include <grub/machine/lbio.h>
#include <grub/coreboot/lbio.h>
#include <grub/machine/console.h>
struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable;

View File

@@ -0,0 +1,29 @@
/*
* 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/>.
*/
#ifndef GRUB_MACHINE_CONSOLE_HEADER
#define GRUB_MACHINE_CONSOLE_HEADER 1
void grub_video_coreboot_fb_init (void);
void grub_video_coreboot_fb_early_init (void);
void grub_video_coreboot_fb_late_init (void);
void grub_video_coreboot_fb_fini (void);
extern struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable;
#endif /* ! GRUB_MACHINE_CONSOLE_HEADER */

View File

@@ -0,0 +1,44 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/>.
*/
#ifndef GRUB_KERNEL_MACHINE_HEADER
#define GRUB_KERNEL_MACHINE_HEADER 1
#ifndef ASM_FILE
#include <grub/symbol.h>
#include <grub/types.h>
struct grub_fdt_board
{
const char *vendor, *part;
const grub_uint8_t *dtb;
grub_size_t dtb_size;
};
extern struct grub_fdt_board grub_fdt_boards[];
void grub_machine_timer_init (void);
void grub_pl050_init (void);
void
grub_cros_init (void);
extern grub_addr_t EXPORT_VAR (start_of_ram);
#endif /* ! ASM_FILE */
#define GRUB_KERNEL_MACHINE_STACK_SIZE GRUB_KERNEL_ARM_STACK_SIZE
#endif /* ! GRUB_KERNEL_MACHINE_HEADER */

View File

View File

@@ -0,0 +1,16 @@
#ifndef GRUB_ARM_CROS_EC_H
#define GRUB_ARM_CROS_EC_H 1
#include <grub/types.h>
#define GRUB_CROS_EC_KEYSCAN_COLS 13
#define GRUB_CROS_EC_KEYSCAN_ROWS 8
struct grub_cros_ec_keyscan {
grub_uint8_t data[GRUB_CROS_EC_KEYSCAN_COLS];
};
int
grub_cros_ec_scan_keyboard(struct grub_cros_ec_keyscan *scan);
#endif

View File

@@ -46,6 +46,22 @@ grub_arm_firmware_get_machine_type (void)
{
return GRUB_ARM_MACHINE_TYPE_FDT;
}
#elif defined (GRUB_MACHINE_COREBOOT)
#include <grub/fdtbus.h>
#include <grub/machine/kernel.h>
# define LINUX_ADDRESS (start_of_ram + 0x8000)
# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
static inline const void *
grub_arm_firmware_get_boot_data (void)
{
return grub_fdtbus_get_fdt ();
}
static inline grub_uint32_t
grub_arm_firmware_get_machine_type (void)
{
return GRUB_ARM_MACHINE_TYPE_FDT;
}
#endif
#define FDT_ADDITIONAL_ENTRIES_SIZE 0x300

View File

@@ -0,0 +1,16 @@
#ifndef GRUB_STARTUP_CPU_HEADER
#define GRUB_STARTUP_CPU_HEADER
struct grub_arm_startup_registers
{
/* registers 0-11 */
/* for U-boot r[1] is machine type */
/* for U-boot r[2] is boot data */
grub_uint32_t r[12];
grub_uint32_t sp;
grub_uint32_t lr;
};
extern struct grub_arm_startup_registers grub_arm_saved_registers;
#endif

View File

@@ -27,10 +27,6 @@
#define KEYBOARD_AT_TRANSLATE 0x40
#define GRUB_AT_ACK 0xfa
#define GRUB_AT_NACK 0xfe
#define GRUB_AT_TRIES 5
#define KEYBOARD_ISMAKE(x) !((x) & 0x80)
#define KEYBOARD_ISREADY(x) ((x) & 0x01)
#define KEYBOARD_SCANCODE(x) ((x) & 0x7f)

View File

@@ -34,15 +34,14 @@ void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
#endif
#ifndef GRUB_MACHINE_EMU
#ifdef _mips
void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address,
grub_size_t len);
#else
#if defined (__i386__) || defined (__x86_64__)
static inline void
grub_arch_sync_dma_caches (volatile void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#else
void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address, grub_size_t len);
#endif
#endif

View File

@@ -20,6 +20,9 @@
#ifndef _GRUB_MACHINE_LBIO_HEADER
#define _GRUB_MACHINE_LBIO_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
struct grub_linuxbios_table_header
{
grub_uint8_t signature[4];
@@ -68,7 +71,8 @@ enum
GRUB_LINUXBIOS_MEMBER_LINK = 0x11,
GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER = 0x12,
GRUB_LINUXBIOS_MEMBER_TIMESTAMPS = 0x16,
GRUB_LINUXBIOS_MEMBER_CBMEMC = 0x17
GRUB_LINUXBIOS_MEMBER_CBMEMC = 0x17,
GRUB_LINUXBIOS_MEMBER_DTB = 0x33,
};
struct grub_linuxbios_table_framebuffer {
@@ -102,4 +106,10 @@ EXPORT_FUNC(grub_linuxbios_table_iterate) (int (*hook) (grub_linuxbios_table_ite
void *),
void *hook_data);
grub_linuxbios_table_header_t
grub_linuxbios_get_tables (void);
int
grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header);
#endif

44
include/grub/dma.h Normal file
View File

@@ -0,0 +1,44 @@
/*
* 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/>.
*/
#ifndef GRUB_DMA_H
#define GRUB_DMA_H 1
struct grub_pci_dma_chunk;
struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align,
grub_size_t size);
void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch);
volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch);
grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch);
static inline void *
grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk)
{
return ((grub_uint8_t *) grub_dma_get_virt (chunk)
+ (phys - grub_dma_get_phys (chunk)));
}
static inline grub_uint32_t
grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk)
{
return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk))
+ grub_dma_get_phys (chunk));
}
#endif

View File

@@ -20,6 +20,7 @@
#define GRUB_FDT_HEADER 1
#include <grub/types.h>
#include <grub/symbol.h>
#define FDT_MAGIC 0xD00DFEED
@@ -95,16 +96,22 @@ struct grub_fdt_empty_tree {
#define grub_fdt_set_size_dt_struct(fdt, value) \
grub_fdt_set_header(fdt, size_dt_struct, value)
int grub_fdt_create_empty_tree (void *fdt, unsigned int size);
int grub_fdt_check_header (void *fdt, unsigned int size);
int grub_fdt_check_header_nosize (void *fdt);
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
const char *name);
int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
int EXPORT_FUNC(grub_fdt_create_empty_tree) (void *fdt, unsigned int size);
int EXPORT_FUNC(grub_fdt_check_header) (const void *fdt, unsigned int size);
int EXPORT_FUNC(grub_fdt_check_header_nosize) (const void *fdt);
int EXPORT_FUNC(grub_fdt_find_subnode) (const void *fdt, unsigned int parentoffset,
const char *name);
int EXPORT_FUNC(grub_fdt_first_node) (const void *fdt, unsigned int parentoffset);
int EXPORT_FUNC(grub_fdt_next_node) (const void *fdt, unsigned int currentoffset);
int EXPORT_FUNC(grub_fdt_add_subnode) (void *fdt, unsigned int parentoffset,
const char *name);
const char *
EXPORT_FUNC(grub_fdt_get_nodename) (const void *fdt, unsigned int nodeoffset);
const void *EXPORT_FUNC(grub_fdt_get_prop) (const void *fdt, unsigned int nodeoffset, const char *name,
grub_uint32_t *len);
int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, grub_uint32_t len);
int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, grub_uint32_t len);
#define grub_fdt_set_prop32(fdt, nodeoffset, name, val) \
({ \
grub_uint32_t _val = grub_cpu_to_be32(val); \

73
include/grub/fdtbus.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 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/>.
*/
#ifndef GRUB_FDTBUS_HEADER
#define GRUB_FDTBUS_HEADER 1
#include <grub/fdt.h>
#include <grub/err.h>
struct grub_fdtbus_dev;
struct grub_fdtbus_driver
{
struct grub_fdtbus_driver *next;
struct grub_fdtbus_driver **prev;
const char *compatible;
grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
void (*detach) (const struct grub_fdtbus_dev *dev);
};
extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
static inline int
grub_fdtbus_is_mapping_valid (volatile void *m)
{
return m != grub_fdtbus_invalid_mapping;
}
volatile void *
EXPORT_FUNC(grub_fdtbus_map_reg) (const struct grub_fdtbus_dev *dev, int reg, grub_size_t *size);
const void *
EXPORT_FUNC(grub_fdtbus_get_fdt) (void);
const char *
EXPORT_FUNC(grub_fdtbus_get_name) (const struct grub_fdtbus_dev *dev);
const void *
EXPORT_FUNC(grub_fdtbus_get_prop) (const struct grub_fdtbus_dev *dev,
const char *name,
grub_uint32_t *len);
void
EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
void
EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
/* Must be called before any register(). */
/* dtb is assumed to be unfreeable and must remain
valid for lifetime of GRUB.
*/
void
grub_fdtbus_init (const void *dtb, grub_size_t size);
#endif

View File

@@ -28,7 +28,8 @@ enum
OBJ_TYPE_MEMDISK,
OBJ_TYPE_CONFIG,
OBJ_TYPE_PREFIX,
OBJ_TYPE_PUBKEY
OBJ_TYPE_PUBKEY,
OBJ_TYPE_DTB
};
/* The module header. */

View File

@@ -291,6 +291,7 @@ struct grub_net_network_level_interface
grub_net_interface_flags_t flags;
struct grub_net_bootp_packet *dhcp_ack;
grub_size_t dhcp_acklen;
grub_uint16_t vlantag;
void *data;
};
@@ -561,4 +562,6 @@ extern char *grub_net_default_server;
#define GRUB_NET_INTERVAL 400
#define GRUB_NET_INTERVAL_ADDITION 20
#define VLANTAG_IDENTIFIER 0x8100
#endif /* ! GRUB_NET_HEADER */

View File

@@ -22,10 +22,11 @@
#include <grub/net.h>
extern grub_err_t grub_net_arp_receive (struct grub_net_buff *nb,
struct grub_net_card *card);
struct grub_net_card *card,
grub_uint16_t *vlantag);
grub_err_t
grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
const grub_net_network_level_address_t *proto_addr);
const grub_net_network_level_address_t *proto_addr);
#endif

View File

@@ -48,7 +48,8 @@ grub_err_t
grub_net_recv_ip_packets (struct grub_net_buff *nb,
struct grub_net_card *card,
const grub_net_link_level_address_t *hwaddress,
const grub_net_link_level_address_t *src_hwaddress);
const grub_net_link_level_address_t *src_hwaddress,
grub_uint16_t *vlantag);
grub_err_t
grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,

View File

@@ -122,6 +122,12 @@
#define GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN 0x8
#define GRUB_KERNEL_ARM_UBOOT_TOTAL_MODULE_SIZE 0x4
#define GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN 0x8
#define GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE 0x4
#define GRUB_KERNEL_ARM_STACK_SIZE 0x40000
#define GRUB_KERNEL_ARM_COREBOOT_MOD_GAP (GRUB_KERNEL_ARM_STACK_SIZE + 1024)
/* Minimal gap between _end and the start of the modules. It's a hack
for PowerMac to prevent "CLAIM failed" error. The real fix is to
rewrite grub-mkimage to generate valid ELF files. */

View File

@@ -142,27 +142,7 @@ grub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev,
void EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook,
void *hook_data);
struct grub_pci_dma_chunk;
struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align,
grub_size_t size);
void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch);
volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch);
grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch);
static inline void *
grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk)
{
return ((grub_uint8_t *) grub_dma_get_virt (chunk)
+ (phys - grub_dma_get_phys (chunk)));
}
static inline grub_uint32_t
grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk)
{
return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk))
+ grub_dma_get_phys (chunk));
}
#include <grub/dma.h>
grub_uint8_t
EXPORT_FUNC (grub_pci_find_capability) (grub_pci_device_t dev, grub_uint8_t cap);

43
include/grub/ps2.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_PS2_HEADER
#define GRUB_PS2_HEADER 1
#include <grub/types.h>
#define GRUB_AT_ACK 0xfa
#define GRUB_AT_NACK 0xfe
#define GRUB_AT_TRIES 5
/* Make sure it's zeroed-out and set current_set at init. */
struct grub_ps2_state
{
int e0_received;
int f0_received;
grub_uint8_t led_status;
short at_keyboard_status;
grub_uint8_t current_set;
};
/* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */
int
grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state,
grub_uint8_t data);
#endif

View File

@@ -321,5 +321,9 @@ grub_usb_err_t
grub_usb_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual);
void
grub_usb_cancel_transfer (grub_usb_transfer_t trans);
void
grub_ehci_init_device (volatile void *regs);
void
grub_ehci_pci_scan (void);
#endif /* GRUB_USB_H */

View File

@@ -29,6 +29,8 @@
#define GRUB_INSTALL_OPTIONS \
{ "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \
0, N_("pre-load specified modules MODULES"), 1 }, \
{ "dtb", GRUB_INSTALL_OPTIONS_DTB, N_("FILE"), \
0, N_("embed a specific DTB"), 1 }, \
{ "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \
N_("MODULES"), 0, \
N_("install only MODULES and their dependencies [default=all]"), 1 }, \
@@ -99,6 +101,7 @@ enum grub_install_plat
GRUB_INSTALL_PLATFORM_I386_XEN,
GRUB_INSTALL_PLATFORM_X86_64_XEN,
GRUB_INSTALL_PLATFORM_ARM64_EFI,
GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
GRUB_INSTALL_PLATFORM_MAX
};
@@ -115,7 +118,8 @@ enum grub_install_options {
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY,
GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY,
GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE,
GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS
GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
GRUB_INSTALL_OPTIONS_DTB
};
extern char *grub_install_source_directory;
@@ -176,7 +180,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
char *config_path,
const struct grub_install_image_target_desc *image_target,
int note,
grub_compression_t comp);
grub_compression_t comp, const char *dtb_file);
const struct grub_install_image_target_desc *
grub_install_get_image_target (const char *arg);

View File

@@ -51,13 +51,13 @@ grub_mkimage_load_image64 (const char *kernel_path,
void
grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
int note, char **core_img, size_t *core_size,
Elf32_Addr target_addr, grub_size_t align,
size_t kernel_size, size_t bss_size);
Elf32_Addr target_addr,
struct grub_mkimage_layout *layout);
void
grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
int note, char **core_img, size_t *core_size,
Elf64_Addr target_addr, grub_size_t align,
size_t kernel_size, size_t bss_size);
Elf64_Addr target_addr,
struct grub_mkimage_layout *layout);
struct grub_install_image_target_desc
{

View File

@@ -15,7 +15,7 @@ PACKAGE = @PACKAGE@
VERSION = @VERSION@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
SHELL = /bin/sh
SHELL = @SHELL@
@SET_MAKE@
srcdir = @srcdir@

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e
true

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
set -e

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2014 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!@BUILD_SHEBANG@
cd '@srcdir@'

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
. "@builddir@/grub-core/modinfo.sh"
@@ -9,7 +9,7 @@ if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = sparc64-ieee1275 ];
fi
pdt="$(date -u +%s)"
dt=`echo date | @builddir@/grub-shell`
dt=`echo date | @builddir@/grub-shell | sed 's, [A-Z][a-z]*$,,'`
dtg="$(date -u -d "$dt" +%s)"
ndt="$(date -u +%s)"

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
# Run GRUB script in a Qemu instance

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
. "@builddir@/grub-core/modinfo.sh"

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
. "@builddir@/grub-core/modinfo.sh"
@@ -11,8 +11,8 @@ fi
# Compare RTC with interval timer.
# Not 100% proper but should check that timer is running ok
dt=`echo 'date; sleep 10; date' | @builddir@/grub-shell`
dt1="$(date -u -d "$(echo "$dt" | head -n 1)" +%s)"
dt2="$(date -u -d "$(echo "$dt" | tail -n 1)" +%s)"
dt1="$(date -u -d "$(echo "$dt" | head -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)"
dt2="$(date -u -d "$(echo "$dt" | tail -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)"
# Ignore QEMU bug
if [ "${grub_modinfo_target_cpu}" = arm ] && [ $((dt2 - dt1)) -ge 15 ] && [ $((dt2 - dt1)) -le 17 ]; then

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
# create a randome file
empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1

View File

@@ -1,4 +1,4 @@
#! /bin/bash -e
#! @BUILD_SHEBANG@ -e
# Run GRUB script in a Qemu instance
# Copyright (C) 2010 Free Software Foundation, Inc.

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
. "@builddir@/grub-core/modinfo.sh"

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
@builddir@/grub-script-check <<EOF

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
# Run GRUB script in a Qemu instance
# Copyright (C) 2010 Free Software Foundation, Inc.

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
@builddir@/grub-script-check << EOF

View File

@@ -1,4 +1,4 @@
#! /bin/bash
#! @BUILD_SHEBANG@
set -e
# Run GRUB script in a Qemu instance

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
@builddir@/grub-script-check <<EOF

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
set -e
# grub-script-check refuses to pass a file with no commands; this usually

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

View File

@@ -1,4 +1,4 @@
#! /bin/sh
#! @BUILD_SHEBANG@
# Copyright (C) 2013 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify

Some files were not shown because too many files have changed in this diff Show More