experimental support for loongson mips64el uefi

pull/786/head
longpanda 3 years ago
parent bb7e10d93e
commit b63ce2a3df

@ -13,6 +13,25 @@ ARCH=arm64 CROSS_COMPILE=aarch64-linux- make
rename ./busybox to xzcat
======== How to build ash/hexdump/xzcat for mips64el ========
#download mips64el-musl cross toolchain from https://github.com/ventoy/musl-cross-make/releases/download/latest/
#How to get ash.config/hexdump.cofig/xzcat.config
#ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make allnoconfig "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
#ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make menuconfig "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
#----> enable static build
#----> enable xzcat
#get mips64el_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy mips64el_xzcat.config as .config
ARCH=mips CROSS_COMPILE=mips64el-linux-musl- make "CFLAGS+=-mips64r2 -mabi=64 -Os" "LDFLAGS+=-mips64r2 -mabi=64 -Os"
rename ./busybox to xzcat
======== How to build full busybox =========
#make defconfig
#make menuconfig select static build
======== How to build ash/hexdump/xzcat for x86_64 ==========
#How to get ash.config/hexdump.cofig/xzcat.config

@ -3,13 +3,17 @@
DSTDIR=../../IMG/cpio/ventoy/busybox
rm -f vtchmod32 vtchmod64 vtchmod64_musl vtchmodaa64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64 $DSTDIR/vtchmodm64e
/opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32
/opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64
aarch64-linux-gcc -Os -static vtchmod.c -o vtchmodaa64
aarch64-linux-strip --strip-all vtchmodaa64
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -Os -static vtchmod.c -o vtchmodm64e
mips64el-linux-musl-strip --strip-all vtchmodm64e
gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static vtchmod.c -o vtchmod64_musl
strip --strip-all vtchmod64_musl
@ -17,9 +21,11 @@ chmod 777 vtchmod32
chmod 777 vtchmod64
chmod 777 vtchmodaa64
chmod 777 vtchmod64_musl
chmod 777 vtchmodm64e
cp -a vtchmod32 $DSTDIR/
cp -a vtchmod64 $DSTDIR/
cp -a vtchmodaa64 $DSTDIR/
cp -a vtchmod64_musl $DSTDIR/
cp -a vtchmodm64e $DSTDIR/

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -55,6 +55,16 @@ build for 32bit, static linked with dietlibc
6. get dmsetup/dmsetup.static as the dmsetupaa64 binary file
======================== Build for mips64 dmsetup =========================
1. extract device mapper source code
2. ./configure CC="mips64el-linux-musl-gcc -mips64r2 -mabi=64" --target=mips --host=x86_64-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
4. make
5. mips64el-linux-musl-strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetupm64e binary file

Binary file not shown.

@ -34,17 +34,13 @@
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz ===> /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--uclibc--stable-2020.08-1.tar.bz2 ===> /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2
http://ftp.loongnix.org/toolchain/gcc/release/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz ===> /opt/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz
https://github.com/ventoy/musl-cross-make/releases/download/latest/output.tar.bz2 ===> /opt/output.tar.bz2
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/vmlinuz64 ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/vmlinuz64
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/corepure64.gz ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/corepure64.gz
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/modules64.gz ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/modules64.gz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/glib2.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/glib2.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/libffi.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/libffi.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/liblvm2.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/liblvm2.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/ncursesw.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/ncursesw.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/parted.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/parted.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/readline.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/readline.tcz
http://distro.ibiblio.org/tinycorelinux/11.x/x86_64/tcz/udev-lib.tcz /home/Ventoy-master/LiveCD/VTOY/ventoy/tcz/udev-lib.tcz
http://www.tinycorelinux.net/11.x/x86_64/release/distribution_files/modules64.gz ===> /home/Ventoy-master/LiveCD/ISO/EFI/boot/modules64.gz
2.3 Prepare third-part tools
cd /home/Ventoy-master/DOC/
@ -54,9 +50,12 @@
tar xf /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt
tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt
tar xf /opt/output.tar.bz2 -C /opt
mv /opt/output /opt/mips64el-linux-musl-gcc730
2.4 Set PATH envrioment
export PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:/opt/aarch64--uclibc--stable-2020.08-1/bin
export PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:/opt/aarch64--uclibc--stable-2020.08-1/bin:/opt/mips64el-linux-musl-gcc730/bin
better to add this line to /root/.bashrc and relogin as root

@ -6,3 +6,4 @@
[ -d /opt/aarch64--uclibc--stable-2020.08-1 ] || tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt
[ -d /opt/mips-loongson-gcc7.3-linux-gnu ] || tar xf /opt/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz -C /opt

File diff suppressed because it is too large Load Diff

@ -0,0 +1,909 @@
#! /usr/bin/python
# GRUB -- GRand Unified Bootloader
# Copyright (C) 2010,2011,2012,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/>.
from __future__ import print_function
__metaclass__ = type
from optparse import OptionParser
import re
#
# This is the python script used to generate Makefile.*.am
#
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
"i386_xen", "x86_64_xen", "i386_xen_pvh",
"mips_loongson", "mips64_efi", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
"arm_coreboot", "riscv32_efi", "riscv64_efi" ]
GROUPS = {}
GROUPS["common"] = GRUB_PLATFORMS[:]
# Groups based on CPU
GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
GROUPS["x86_64"] = [ "x86_64_efi" ]
GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
GROUPS["mips64"] = [ "mips64_efi" ]
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
GROUPS["arm64"] = [ "arm64_efi" ]
GROUPS["riscv32"] = [ "riscv32_efi" ]
GROUPS["riscv64"] = [ "riscv64_efi" ]
# Groups based on firmware
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", "mips64_efi",
"riscv32_efi", "riscv64_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")
# Groups based on hardware features
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"] + ["arm_coreboot"]
# If gfxterm is main output console integrate it into kernel
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
# Similar for terminfo
GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips", "i386_xen_pvh" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"];
GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
# Flattened Device Trees (FDT)
GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ]
# Needs software helpers for division
# Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"]
GROUPS["no_softdiv"] = GRUB_PLATFORMS[:]
for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i)
# Miscellaneous groups scheduled to disappear in future
GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc")
#
# Create platform => groups reverse map, where groups covering that
# platform are ordered by their sizes
#
RMAP = {}
for platform in GRUB_PLATFORMS:
# initialize with platform itself as a group
RMAP[platform] = [ platform ]
for k in GROUPS.keys():
v = GROUPS[k]
# skip groups that don't cover this platform
if platform not in v: continue
bigger = []
smaller = []
# partition currently known groups based on their size
for group in RMAP[platform]:
if group in GRUB_PLATFORMS: smaller.append(group)
elif len(GROUPS[group]) < len(v): smaller.append(group)
else: bigger.append(group)
# insert in the middle
RMAP[platform] = smaller + [ k ] + bigger
#
# Input
#
# We support a subset of the AutoGen definitions file syntax. Specifically,
# compound names are disallowed; some preprocessing directives are
# disallowed (though #if/#endif are allowed; note that, like AutoGen, #if
# skips everything to the next #endif regardless of the value of the
# conditional); and shell-generated strings, Scheme-generated strings, and
# here strings are disallowed.
class AutogenToken:
(autogen, definitions, eof, var_name, other_name, string, number,
semicolon, equals, comma, lbrace, rbrace, lbracket, rbracket) = range(14)
class AutogenState:
(init, need_def, need_tpl, need_semi, need_name, have_name, need_value,
need_idx, need_rbracket, indx_name, have_value, done) = range(12)
class AutogenParseError(Exception):
def __init__(self, message, path, line):
super(AutogenParseError, self).__init__(message)
self.path = path
self.line = line
def __str__(self):
return (
super(AutogenParseError, self).__str__() +
" at file %s line %d" % (self.path, self.line))
class AutogenDefinition(list):
def __getitem__(self, key):
try:
return super(AutogenDefinition, self).__getitem__(key)
except TypeError:
for name, value in self:
if name == key:
return value
def __contains__(self, key):
for name, value in self:
if name == key:
return True
return False
def get(self, key, default):
for name, value in self:
if name == key:
return value
else:
return default
def find_all(self, key):
for name, value in self:
if name == key:
yield value
class AutogenParser:
def __init__(self):
self.definitions = AutogenDefinition()
self.def_stack = [("", self.definitions)]
self.curdef = None
self.new_name = None
self.cur_path = None
self.cur_line = 0
@staticmethod
def is_unquotable_char(c):
return (ord(c) in range(ord("!"), ord("~") + 1) and
c not in "#,;<=>[\\]`{}?*'\"()")
@staticmethod
def is_value_name_char(c):
return c in ":^-_" or c.isalnum()
def error(self, message):
raise AutogenParseError(message, self.cur_file, self.cur_line)
def read_tokens(self, f):
data = f.read()
end = len(data)
offset = 0
while offset < end:
while offset < end and data[offset].isspace():
if data[offset] == "\n":
self.cur_line += 1
offset += 1
if offset >= end:
break
c = data[offset]
if c == "#":
offset += 1
try:
end_directive = data.index("\n", offset)
directive = data[offset:end_directive]
offset = end_directive
except ValueError:
directive = data[offset:]
offset = end
name, value = directive.split(None, 1)
if name == "if":
try:
end_if = data.index("\n#endif", offset)
new_offset = end_if + len("\n#endif")
self.cur_line += data[offset:new_offset].count("\n")
offset = new_offset
except ValueError:
self.error("#if without matching #endif")
else:
self.error("Unhandled directive '#%s'" % name)
elif c == "{":
yield AutogenToken.lbrace, c
offset += 1
elif c == "=":
yield AutogenToken.equals, c
offset += 1
elif c == "}":
yield AutogenToken.rbrace, c
offset += 1
elif c == "[":
yield AutogenToken.lbracket, c
offset += 1
elif c == "]":
yield AutogenToken.rbracket, c
offset += 1
elif c == ";":
yield AutogenToken.semicolon, c
offset += 1
elif c == ",":
yield AutogenToken.comma, c
offset += 1
elif c in ("'", '"'):
s = []
while True:
offset += 1
if offset >= end:
self.error("EOF in quoted string")
if data[offset] == "\n":
self.cur_line += 1
if data[offset] == "\\":
offset += 1
if offset >= end:
self.error("EOF in quoted string")
if data[offset] == "\n":
self.cur_line += 1
# Proper escaping unimplemented; this can be filled
# out if needed.
s.append("\\")
s.append(data[offset])
elif data[offset] == c:
offset += 1
break
else:
s.append(data[offset])
yield AutogenToken.string, "".join(s)
elif c == "/":
offset += 1
if data[offset] == "*":
offset += 1
try:
end_comment = data.index("*/", offset)
new_offset = end_comment + len("*/")
self.cur_line += data[offset:new_offset].count("\n")
offset = new_offset
except ValueError:
self.error("/* without matching */")
elif data[offset] == "/":
try:
offset = data.index("\n", offset)
except ValueError:
pass
elif (c.isdigit() or
(c == "-" and offset < end - 1 and
data[offset + 1].isdigit())):
end_number = offset + 1
while end_number < end and data[end_number].isdigit():
end_number += 1
yield AutogenToken.number, data[offset:end_number]
offset = end_number
elif self.is_unquotable_char(c):
end_name = offset
while (end_name < end and
self.is_value_name_char(data[end_name])):
end_name += 1
if end_name < end and self.is_unquotable_char(data[end_name]):
while (end_name < end and
self.is_unquotable_char(data[end_name])):
end_name += 1
yield AutogenToken.other_name, data[offset:end_name]
offset = end_name
else:
s = data[offset:end_name]
if s.lower() == "autogen":
yield AutogenToken.autogen, s
elif s.lower() == "definitions":
yield AutogenToken.definitions, s
else:
yield AutogenToken.var_name, s
offset = end_name
else:
self.error("Invalid input character '%s'" % c)
yield AutogenToken.eof, None
def do_need_name_end(self, token):
if len(self.def_stack) > 1:
self.error("Definition blocks were left open")
def do_need_name_var_name(self, token):
self.new_name = token
def do_end_block(self, token):
if len(self.def_stack) <= 1:
self.error("Too many close braces")
new_name, parent_def = self.def_stack.pop()
parent_def.append((new_name, self.curdef))
self.curdef = parent_def
def do_empty_val(self, token):
self.curdef.append((self.new_name, ""))
def do_str_value(self, token):
self.curdef.append((self.new_name, token))
def do_start_block(self, token):
self.def_stack.append((self.new_name, self.curdef))
self.curdef = AutogenDefinition()
def do_indexed_name(self, token):
self.new_name = token
def read_definitions_file(self, f):
self.curdef = self.definitions
self.cur_line = 0
state = AutogenState.init
# The following transition table was reduced from the Autogen
# documentation:
# info -f autogen -n 'Full Syntax'
transitions = {
AutogenState.init: {
AutogenToken.autogen: (AutogenState.need_def, None),
},
AutogenState.need_def: {
AutogenToken.definitions: (AutogenState.need_tpl, None),
},
AutogenState.need_tpl: {
AutogenToken.var_name: (AutogenState.need_semi, None),
AutogenToken.other_name: (AutogenState.need_semi, None),
AutogenToken.string: (AutogenState.need_semi, None),
},
AutogenState.need_semi: {
AutogenToken.semicolon: (AutogenState.need_name, None),
},
AutogenState.need_name: {
AutogenToken.autogen: (AutogenState.need_def, None),
AutogenToken.eof: (AutogenState.done, self.do_need_name_end),
AutogenToken.var_name: (
AutogenState.have_name, self.do_need_name_var_name),
AutogenToken.rbrace: (
AutogenState.have_value, self.do_end_block),
},
AutogenState.have_name: {
AutogenToken.semicolon: (
AutogenState.need_name, self.do_empty_val),
AutogenToken.equals: (AutogenState.need_value, None),
AutogenToken.lbracket: (AutogenState.need_idx, None),
},
AutogenState.need_value: {
AutogenToken.var_name: (
AutogenState.have_value, self.do_str_value),
AutogenToken.other_name: (
AutogenState.have_value, self.do_str_value),
AutogenToken.string: (
AutogenState.have_value, self.do_str_value),
AutogenToken.number: (
AutogenState.have_value, self.do_str_value),
AutogenToken.lbrace: (
AutogenState.need_name, self.do_start_block),
},
AutogenState.need_idx: {
AutogenToken.var_name: (
AutogenState.need_rbracket, self.do_indexed_name),
AutogenToken.number: (
AutogenState.need_rbracket, self.do_indexed_name),
},
AutogenState.need_rbracket: {
AutogenToken.rbracket: (AutogenState.indx_name, None),
},
AutogenState.indx_name: {
AutogenToken.semicolon: (
AutogenState.need_name, self.do_empty_val),
AutogenToken.equals: (AutogenState.need_value, None),
},
AutogenState.have_value: {
AutogenToken.semicolon: (AutogenState.need_name, None),
AutogenToken.comma: (AutogenState.need_value, None),
},
}
for code, token in self.read_tokens(f):
if code in transitions[state]:
state, handler = transitions[state][code]
if handler is not None:
handler(token)
else:
self.error(
"Parse error in state %s: unexpected token '%s'" % (
state, token))
if state == AutogenState.done:
break
def read_definitions(self, path):
self.cur_file = path
with open(path) as f:
self.read_definitions_file(f)
defparser = AutogenParser()
#
# Output
#
outputs = {}
def output(s, section=''):
if s == "":
return
outputs.setdefault(section, [])
outputs[section].append(s)
def write_output(section=''):
for s in outputs.get(section, []):
print(s, end='')
#
# Global variables
#
def gvar_add(var, value):
output(var + " += " + value + "\n")
#
# Per PROGRAM/SCRIPT variables
#
seen_vars = set()
def vars_init(defn, *var_list):
name = defn['name']
if name not in seen_target and name not in seen_vars:
for var in var_list:
output(var + " = \n", section='decl')
seen_vars.add(name)
def var_set(var, value):
output(var + " = " + value + "\n")
def var_add(var, value):
output(var + " += " + value + "\n")
#
# Variable names and rules
#
canonical_name_re = re.compile(r'[^0-9A-Za-z@_]')
canonical_name_suffix = ""
def set_canonical_name_suffix(suffix):
global canonical_name_suffix
canonical_name_suffix = suffix
def cname(defn):
return canonical_name_re.sub('_', defn['name'] + canonical_name_suffix)
def rule(target, source, cmd):
if cmd[0] == "\n":
output("\n" + target + ": " + source + cmd.replace("\n", "\n\t") + "\n")
else:
output("\n" + target + ": " + source + "\n\t" + cmd.replace("\n", "\n\t") + "\n")
#
# Handle keys with platform names as values, for example:
#
# kernel = {
# nostrip = emu;
# ...
# }
#
def platform_tagged(defn, platform, tag):
for value in defn.find_all(tag):
for group in RMAP[platform]:
if value == group:
return True
return False
def if_platform_tagged(defn, platform, tag, snippet_if, snippet_else=None):
if platform_tagged(defn, platform, tag):
return snippet_if
elif snippet_else is not None:
return snippet_else
#
# Handle tagged values
#
# module = {
# extra_dist = ...
# extra_dist = ...
# ...
# };
#
def foreach_value(defn, tag, closure):
r = []
for value in defn.find_all(tag):
r.append(closure(value))
return ''.join(r)
#
# Handle best matched values for a platform, for example:
#
# module = {
# cflags = '-Wall';
# emu_cflags = '-Wall -DGRUB_EMU=1';
# ...
# }
#
def foreach_platform_specific_value(defn, platform, suffix, nonetag, closure):
r = []
for group in RMAP[platform]:
values = list(defn.find_all(group + suffix))
if values:
for value in values:
r.append(closure(value))
break
else:
for value in defn.find_all(nonetag):
r.append(closure(value))
return ''.join(r)
#
# Handle values from sum of all groups for a platform, for example:
#
# module = {
# common = kern/misc.c;
# emu = kern/emu/misc.c;
# ...
# }
#
def foreach_platform_value(defn, platform, suffix, closure):
r = []
for group in RMAP[platform]:
for value in defn.find_all(group + suffix):
r.append(closure(value))
return ''.join(r)
def platform_conditional(platform, closure):
output("\nif COND_" + platform + "\n")
closure(platform)
output("endif\n")
#
# Handle guarding with platform-specific "enable" keys, for example:
#
# module = {
# name = pci;
# noemu = bus/pci.c;
# emu = bus/emu/pci.c;
# emu = commands/lspci.c;
#
# enable = emu;
# enable = i386_pc;
# enable = x86_efi;
# enable = i386_ieee1275;
# enable = i386_coreboot;
# };
#
def foreach_enabled_platform(defn, closure):
if 'enable' in defn:
for platform in GRUB_PLATFORMS:
if platform_tagged(defn, platform, "enable"):
platform_conditional(platform, closure)
else:
for platform in GRUB_PLATFORMS:
platform_conditional(platform, closure)
#
# Handle guarding with platform-specific automake conditionals, for example:
#
# module = {
# name = usb;
# common = bus/usb/usb.c;
# noemu = bus/usb/usbtrans.c;
# noemu = bus/usb/usbhub.c;
# enable = emu;
# enable = i386;
# enable = mips_loongson;
# emu_condition = COND_GRUB_EMU_SDL;
# };
#
def under_platform_specific_conditionals(defn, platform, closure):
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "if " + cond + "\n"))
closure(defn, platform)
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "endif " + cond + "\n"))
def platform_specific_values(defn, platform, suffix, nonetag):
return foreach_platform_specific_value(defn, platform, suffix, nonetag,
lambda value: value + " ")
def platform_values(defn, platform, suffix):
return foreach_platform_value(defn, platform, suffix, lambda value: value + " ")
def extra_dist(defn):
return foreach_value(defn, "extra_dist", lambda value: value + " ")
def platform_sources(defn, p): return platform_values(defn, p, "")
def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist")
def platform_startup(defn, p): return platform_specific_values(defn, p, "_startup", "startup")
def platform_ldadd(defn, p): return platform_specific_values(defn, p, "_ldadd", "ldadd")
def platform_dependencies(defn, p): return platform_specific_values(defn, p, "_dependencies", "dependencies")
def platform_cflags(defn, p): return platform_specific_values(defn, p, "_cflags", "cflags")
def platform_ldflags(defn, p): return platform_specific_values(defn, p, "_ldflags", "ldflags")
def platform_cppflags(defn, p): return platform_specific_values(defn, p, "_cppflags", "cppflags")
def platform_ccasflags(defn, p): return platform_specific_values(defn, p, "_ccasflags", "ccasflags")
def platform_stripflags(defn, p): return platform_specific_values(defn, p, "_stripflags", "stripflags")
def platform_objcopyflags(defn, p): return platform_specific_values(defn, p, "_objcopyflags", "objcopyflags")
#
# Emit snippet only the first time through for the current name.
#
seen_target = set()
def first_time(defn, snippet):
if defn['name'] not in seen_target:
return snippet
return ''
def is_platform_independent(defn):
if 'enable' in defn:
return False
for suffix in [ "", "_nodist" ]:
template = platform_values(defn, GRUB_PLATFORMS[0], suffix)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_values(defn, platform, suffix):
return False
for suffix in [ "startup", "ldadd", "dependencies", "cflags", "ldflags", "cppflags", "ccasflags", "stripflags", "objcopyflags", "condition" ]:
template = platform_specific_values(defn, GRUB_PLATFORMS[0], "_" + suffix, suffix)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_specific_values(defn, platform, "_" + suffix, suffix):
return False
for tag in [ "nostrip" ]:
template = platform_tagged(defn, GRUB_PLATFORMS[0], tag)
for platform in GRUB_PLATFORMS[1:]:
if template != platform_tagged(defn, platform, tag):
return False
return True
def module(defn, platform):
name = defn['name']
set_canonical_name_suffix(".module")
gvar_add("platform_PROGRAMS", name + ".module")
gvar_add("MODULE_FILES", name + ".module$(EXEEXT)")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources")
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("MOD_FILES", name + ".mod")
gvar_add("MARKER_FILES", name + ".marker")
gvar_add("CLEANFILES", name + ".marker")
output("""
""" + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES)
$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
grep 'MARKER' $@.new > $@; rm -f $@.new
""")
def kernel(defn, platform):
name = defn['name']
set_canonical_name_suffix(".exec")
gvar_add("platform_PROGRAMS", name + ".exec")
var_set(cname(defn) + "_SOURCES", platform_startup(defn, platform))
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_KERNEL) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_KERNEL) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(defn, platform))
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF)")
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("platform_DATA", name + ".img")
gvar_add("CLEANFILES", name + ".img")
rule(name + ".img", name + ".exec$(EXEEXT)",
if_platform_tagged(defn, platform, "nostrip",
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
$(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -wd1106 -nu -nd $< $@; \
elif test ! -z '$(TARGET_OBJ2ELF)'; then \
$(TARGET_OBJ2ELF) $< $@ || (rm -f $@; exit 1); \
else cp $< $@; fi""",
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
$(TARGET_STRIP) -S -x $(""" + cname(defn) + """) -o $@.bin $<; \
$(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -ed2016 -wd1106 -nu -nd $@.bin $@; \
rm -f $@.bin; \
elif test ! -z '$(TARGET_OBJ2ELF)'; then \
""" + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@.bin $< && \
$(TARGET_OBJ2ELF) $@.bin $@ || (rm -f $@; rm -f $@.bin; exit 1); \
rm -f $@.bin; \
else """ + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@ $<; \
fi"""))
def image(defn, platform):
name = defn['name']
set_canonical_name_suffix(".image")
gvar_add("platform_PROGRAMS", name + ".image")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + "## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_IMAGE) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_IMAGE) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_OBJCOPYFLAGS", "$(OBJCOPYFLAGS_IMAGE) " + platform_objcopyflags(defn, platform))
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("platform_DATA", name + ".img")
gvar_add("CLEANFILES", name + ".img")
rule(name + ".img", name + ".image$(EXEEXT)", """
if test x$(TARGET_APPLE_LINKER) = x1; then \
$(MACHO2IMG) $< $@; \
else \
$(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx $< $@; \
fi
""")
def library(defn, platform):
name = defn['name']
set_canonical_name_suffix("")
vars_init(defn,
cname(defn) + "_SOURCES",
"nodist_" + cname(defn) + "_SOURCES",
cname(defn) + "_CFLAGS",
cname(defn) + "_CPPFLAGS",
cname(defn) + "_CCASFLAGS")
# cname(defn) + "_DEPENDENCIES")
if name not in seen_target:
gvar_add("noinst_LIBRARIES", name)
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_add("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
var_add(cname(defn) + "_CFLAGS", first_time(defn, "$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(defn, platform))
var_add(cname(defn) + "_CPPFLAGS", first_time(defn, "$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(defn, platform))
var_add(cname(defn) + "_CCASFLAGS", first_time(defn, "$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(defn, platform))
# var_add(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
if name not in seen_target:
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
def installdir(defn, default="bin"):
return defn.get('installdir', default)
def manpage(defn, adddeps):
name = defn['name']
mansection = defn['mansection']
output("if COND_MAN_PAGES\n")
gvar_add("man_MANS", name + "." + mansection)
rule(name + "." + mansection, name + " " + adddeps, """
chmod a+x """ + name + """
PATH=$(builddir):$$PATH pkgdatadir=$(builddir) $(HELP2MAN) --section=""" + mansection + """ -i $(top_srcdir)/docs/man/""" + name + """.h2m -o $@ """ + name + """
""")
gvar_add("CLEANFILES", name + "." + mansection)
output("endif\n")
def program(defn, platform, test=False):
name = defn['name']
set_canonical_name_suffix("")
if 'testcase' in defn:
gvar_add("check_PROGRAMS", name)
gvar_add("TESTS", name)
else:
var_add(installdir(defn) + "_PROGRAMS", name)
if 'mansection' in defn:
manpage(defn, "")
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_PROGRAM) " + platform_cflags(defn, platform))
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(defn, platform))
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(defn, platform))
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(defn, platform))
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
def data(defn, platform):
var_add("dist_" + installdir(defn) + "_DATA", platform_sources(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
def transform_data(defn, platform):
name = defn['name']
var_add(installdir(defn) + "_DATA", name)
rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:-
chmod a+x """ + name + """
""")
gvar_add("CLEANFILES", name)
gvar_add("EXTRA_DIST", extra_dist(defn))
gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
def script(defn, platform):
name = defn['name']
if 'testcase' in defn:
gvar_add("check_SCRIPTS", name)
gvar_add ("TESTS", name)
else:
var_add(installdir(defn) + "_SCRIPTS", name)
if 'mansection' in defn:
manpage(defn, "grub-mkconfig_lib")
rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:-
chmod a+x """ + name + """
""")
gvar_add("CLEANFILES", name)
gvar_add("EXTRA_DIST", extra_dist(defn))
gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
def rules(target, closure):
seen_target.clear()
seen_vars.clear()
for defn in defparser.definitions.find_all(target):
if is_platform_independent(defn):
under_platform_specific_conditionals(defn, GRUB_PLATFORMS[0], closure)
else:
foreach_enabled_platform(
defn,
lambda p: under_platform_specific_conditionals(defn, p, closure))
# Remember that we've seen this target.
seen_target.add(defn['name'])
parser = OptionParser(usage="%prog DEFINITION-FILES")
_, args = parser.parse_args()
for arg in args:
defparser.read_definitions(arg)
rules("module", module)
rules("kernel", kernel)
rules("image", image)
rules("library", library)
rules("program", program)
rules("script", script)
rules("data", data)
rules("transform_data", transform_data)
write_output(section='decl')
write_output()

@ -0,0 +1,507 @@
AUTOMAKE_OPTIONS = subdir-objects -Wno-portability
DEPDIR=.deps-core
include $(top_srcdir)/conf/Makefile.common
CC=$(TARGET_CC)
CPP=$(TARGET_CC)
CCAS=$(TARGET_CC)
RANLIB=$(TARGET_RANLIB)
STRIP=$(TARGET_STRIP)
MACHO2IMG=$(top_builddir)/grub-macho2img
AM_CFLAGS = $(TARGET_CFLAGS)
AM_LDFLAGS = $(TARGET_LDFLAGS)
AM_CPPFLAGS = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT)
AM_CCASFLAGS = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT)
CFLAGS_PROGRAM += $(CFLAGS_PLATFORM)
LDFLAGS_PROGRAM += $(LDFLAGS_PLATFORM)
CPPFLAGS_PROGRAM += $(CPPFLAGS_PLATFORM)
CCASFLAGS_PROGRAM += $(CCASFLAGS_PLATFORM)
CFLAGS_LIBRARY += $(CFLAGS_PLATFORM) -fno-builtin
CPPFLAGS_LIBRARY += $(CPPFLAGS_PLATFORM)
CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
build-grub-pep2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=64 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pep2elf\" $^
CLEANFILES += build-grub-pep2elf$(BUILD_EXEEXT)
build-grub-pe2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=32 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pe2elf\" $^
CLEANFILES += build-grub-pe2elf$(BUILD_EXEEXT)
# gentrigtables
gentrigtables$(BUILD_EXEEXT): gentrigtables.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $< $(BUILD_LIBM)
CLEANFILES += gentrigtables$(BUILD_EXEEXT)
build-grub-module-verifier$(BUILD_EXEEXT): $(top_srcdir)/util/grub-module-verifier.c $(top_srcdir)/util/grub-module-verifier32.c $(top_srcdir)/util/grub-module-verifier64.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-module-verifier\" $^
CLEANFILES += build-grub-module-verifier$(BUILD_EXEEXT)
# trigtables.c
trigtables.c: gentrigtables$(BUILD_EXEEXT) gentrigtables.c $(top_srcdir)/configure.ac
./gentrigtables$(BUILD_EXEEXT) > $@
CLEANFILES += trigtables.c
# XXX Use Automake's LEX & YACC support
grub_script.tab.h: script/parser.y
$(YACC) -d -p grub_script_yy -b grub_script $<
grub_script.tab.c: grub_script.tab.h
CLEANFILES += grub_script.tab.c grub_script.tab.h
# For the lexer.
grub_script.yy.h: script/yylex.l
$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $<
grub_script.yy.c: grub_script.yy.h
rs_decoder.h: $(srcdir)/lib/reed_solomon.c
$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 -ffreestanding
CLEANFILES += grub_script.yy.c grub_script.yy.h
include $(srcdir)/Makefile.core.am
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h
if COND_emu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h
else
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h
endif
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
if COND_i386_pc
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_xen_pvh
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
endif
if COND_i386_efi
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
endif
if COND_i386_coreboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.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
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/acpi.h
endif
if COND_i386_multiboot
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_i386_qemu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_ieee1275
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
endif
if COND_i386_xen
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
endif
if COND_x86_64_xen
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/x86_64/xen/hypercall.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
endif
if COND_x86_64_efi
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
endif
if COND_ia64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h
endif
if COND_mips_arc
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
endif
if COND_mips_qemu_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_mips_loongson
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/time.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/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_mips_qemu_mips
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
endif
if COND_mips64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loongson.h
endif
if COND_powerpc_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_sparc64_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_arm_uboot
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/uboot.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/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/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_arm64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_riscv32_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_riscv64_efi
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
endif
if COND_emu
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
if COND_GRUB_EMU_SDL
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
endif
if COND_GRUB_EMU_PCI
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libpciaccess.h
endif
endif
symlist.h: $(top_builddir)/config.h $(KERNEL_HEADER_FILES)
@list='$^'; \
for p in $$list; do \
echo "#include <$$p>" >> $@ || (rm -f $@; exit 1); \
done
CLEANFILES += symlist.h
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 | $(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
if COND_HAVE_ASM_USCORE
ASM_PREFIX=_
else
ASM_PREFIX=
endif
noinst_DATA += kernel_syms.lst
kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input
cat kernel_syms.input | grep -v '^#' | sed -n \
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
| sort -u >$@
rm -f kernel_syms.input
CLEANFILES += kernel_syms.lst
if COND_emu
kern/emu/grub_emu-main.$(OBJEXT):grub_emu_init.h
grub_emu-grub_emu_init.$(OBJEXT):grub_emu_init.h
kern/emu/grub_emu_dyn-main.$(OBJEXT):grub_emu_init.h
grub_emu_dyn-grub_emu_init.$(OBJEXT):grub_emu_init.h
grub_emu_init.h: genemuinitheader.sh $(MODULE_FILES)
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinitheader.sh $(TARGET_NM) > $@
CLEANFILES += grub_emu_init.h
grub_emu_init.c: grub_emu_init.h genemuinit.sh $(MODULE_FILES)
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinit.sh $(TARGET_NM) > $@
CLEANFILES += grub_emu_init.c
endif
# List files
fs.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'FS_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += fs.lst
CLEANFILES += fs.lst
command.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += command.lst
CLEANFILES += command.lst
partmap.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'PARTMAP_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += partmap.lst
CLEANFILES += partmap.lst
terminal.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/INPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
-e "/OUTPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
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`; \
sed -n \
-e "/PARTTOOL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += parttool.lst
CLEANFILES += parttool.lst
video.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
if grep 'VIDEO_LIST_MARKER' $$pp >/dev/null 2>&1; then \
echo $$b; \
fi; \
done) | sort -u > $@
platform_DATA += video.lst
CLEANFILES += video.lst
# but, crypto.lst is simply copied
crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst
cp $^ $@
platform_DATA += crypto.lst
CLEANFILES += crypto.lst
syminfo.lst: gensyminfo.sh kernel_syms.lst $(MODULE_FILES)
cat kernel_syms.lst > $@.new
for m in $(MODULE_FILES); do \
sh $< $$m >> $@.new || exit 1; \
done
mv $@.new $@
# generate global module dependencies list
moddep.lst: syminfo.lst genmoddep.awk video.lst
cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1)
platform_DATA += moddep.lst
CLEANFILES += config.log syminfo.lst moddep.lst
$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT)
TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
platform_DATA += $(MOD_FILES)
platform_DATA += modinfo.sh
CLEANFILES += $(MOD_FILES)
if COND_ENABLE_EFIEMU
efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF)
-rm -f $@
-rm -f $@.bin
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m32 -Wall -Werror -nostdlib -static -O2 -c -o $@.bin $<
if test "x$(TARGET_APPLE_LINKER)" = x1; then \
$(TARGET_OBJCONV) -felf32 -nu -nd $@.bin $@ || exit 1; \
rm -f $@.bin ; \
elif test ! -z "$(TARGET_OBJ2ELF)"; then \
$(TARGET_OBJ2ELF) $@.bin || (rm -f $@.bin; exit 1); \
mv $@.bin $@ ; \
else \
mv $@.bin $@ ; \
fi
# Link format -arch,x86_64 means Apple linker
efiemu64_c.o: efiemu/runtime/efiemu.c
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -nostdlib -Wall -Werror -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
efiemu64_s.o: efiemu/runtime/efiemu.S
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -Wall -Werror -nostdlib -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELEF)
-rm -f $@
-rm -f $@.bin
$(TARGET_CC) -m64 $(EFIEMU64_LINK_FORMAT) -nostdlib -static -Wl,-r -o $@.bin $^
if test "x$(EFIEMU64_LINK_FORMAT)" = x-arch,x86_64; then \
$(TARGET_OBJCONV) -felf64 -nu -nd $@.bin $@ || exit 1; \
rm -f $@.bin; \
else \
mv $@.bin $@ ; \
fi
platform_DATA += efiemu32.o efiemu64.o
CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
endif
windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows
windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA)
test -d $(windowsdir)/$(target_cpu)-$(platform) || mkdir $(windowsdir)/$(target_cpu)-$(platform)
for x in $(platform_DATA); do \
cp -fp $$x $(windowsdir)/$(target_cpu)-$(platform)/$$x; \
done

@ -100,6 +100,10 @@ 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';
mips64_efi_ldflags = '-Wl,-r,-d';
mips64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame -R .MIPS.abiflags';
arm_coreboot_ldflags = '-Wl,-r,-d';
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
@ -114,6 +118,7 @@ kernel = {
i386_coreboot_startup = kern/i386/coreboot/startup.S;
i386_multiboot_startup = kern/i386/coreboot/startup.S;
mips_startup = kern/mips/startup.S;
mips64_efi_startup = kern/mips64/efi/startup.S;
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
arm_uboot_startup = kern/arm/startup.S;
@ -310,6 +315,15 @@ kernel = {
extra_dist = video/sis315_init.c;
mips_loongson = commands/keylayouts.c;
mips64 = kern/mips64/init.c;
mips64 = kern/mips64/dl.c;
mips64 = kern/mips64/cache.S;
mips64 = kern/generic/rtc_get_time_ms.c;
mips64_efi = kern/mips64/efi/init.c;
mips64_efi = kern/mips64/efi/loongson.c;
mips64_efi = lib/mips64/efi/loongson.c;
mips64_efi = lib/mips64/efi/loongson_asm.S;
powerpc_ieee1275 = kern/powerpc/cache.S;
powerpc_ieee1275 = kern/powerpc/dl.c;
powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
@ -828,6 +842,7 @@ module = {
enable = sparc64_ieee1275;
enable = powerpc_ieee1275;
enable = mips_arc;
enable = mips64_efi;
enable = ia64_efi;
enable = arm_efi;
enable = arm64_efi;
@ -1667,6 +1682,8 @@ module = {
efi = lib/efi/relocator.c;
mips = lib/mips/relocator_asm.S;
mips = lib/mips/relocator.c;
mips64 = lib/mips64/relocator_asm.S;
mips64 = lib/mips64/relocator.c;
powerpc = lib/powerpc/relocator_asm.S;
powerpc = lib/powerpc/relocator.c;
xen = lib/xen/relocator.c;
@ -1679,6 +1696,7 @@ module = {
extra_dist = kern/powerpc/cache_flush.S;
enable = mips;
enable = mips64;
enable = powerpc;
enable = x86;
enable = i386_xen_pvh;
@ -1809,6 +1827,7 @@ module = {
i386_pc = lib/i386/pc/vesa_modes_table.c;
i386_xen_pvh = lib/i386/pc/vesa_modes_table.c;
mips = loader/mips/linux.c;
mips64 = loader/mips64/linux.c;
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
ia64_efi = loader/ia64/efi/linux.c;
@ -1915,6 +1934,7 @@ module = {
enable = riscv32_efi;
enable = riscv64_efi;
enable = mips;
enable = mips64_efi;
};
module = {

@ -0,0 +1,672 @@
/* mm.c - generic EFI memory management */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/cpu/efi/memory.h>
#if defined (__i386__) || defined (__x86_64__)
#include <grub/pci.h>
#endif
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
#define BYTES_TO_PAGES_DOWN(bytes) ((bytes) >> 12)
#define PAGES_TO_BYTES(pages) ((pages) << 12)
/* The size of a memory map obtained from the firmware. This must be
a multiplier of 4KB. */
#define MEMORY_MAP_SIZE 0x3000
/* The minimum and maximum heap size for GRUB itself. */
#define MIN_HEAP_SIZE 0x100000
#define MAX_HEAP_SIZE (1600 * 0x100000)
static void *finish_mmap_buf = 0;
static grub_efi_uintn_t finish_mmap_size = 0;
static grub_efi_uintn_t finish_key = 0;
static grub_efi_uintn_t finish_desc_size;
static grub_efi_uint32_t finish_desc_version;
int grub_efi_is_finished = 0;
/*
* We need to roll back EFI allocations on exit. Remember allocations that
* we'll free on exit.
*/
struct efi_allocation;
struct efi_allocation {
grub_efi_physical_address_t address;
grub_efi_uint64_t pages;
struct efi_allocation *next;
};
static struct efi_allocation *efi_allocated_memory;
static void
grub_efi_store_alloc (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
struct efi_allocation *alloc;
grub_efi_status_t status;
b = grub_efi_system_table->boot_services;
status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
sizeof(*alloc), (void**)&alloc);
if (status == GRUB_EFI_SUCCESS)
{
alloc->next = efi_allocated_memory;
alloc->address = address;
alloc->pages = pages;
efi_allocated_memory = alloc;
}
else
grub_printf ("Could not malloc memory to remember EFI allocation. "
"Exiting GRUB won't free all memory.\n");
}
static void
grub_efi_drop_alloc (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
struct efi_allocation *ea, *eap;
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
for (eap = NULL, ea = efi_allocated_memory; ea; eap = ea, ea = ea->next)
{
if (ea->address != address || ea->pages != pages)
continue;
/* Remove the current entry from the list. */
if (eap)
eap->next = ea->next;
else
efi_allocated_memory = ea->next;
/* Then free the memory backing it. */
efi_call_1 (b->free_pool, ea);
/* And leave, we're done. */
break;
}
}
/* Allocate pages. Return the pointer to the first of allocated pages. */
void *
grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
grub_efi_uintn_t pages,
grub_efi_allocate_type_t alloctype,
grub_efi_memory_type_t memtype)
{
grub_efi_status_t status;
grub_efi_boot_services_t *b;
/* Limit the memory access to less than 4GB for 32-bit platforms. */
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
return 0;
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
if (status != GRUB_EFI_SUCCESS)
return 0;
if (address == 0)
{
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
address = GRUB_EFI_MAX_USABLE_ADDRESS;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
return 0;
}
grub_efi_store_alloc (address, pages);
return (void *) ((grub_addr_t) address);
}
void *
grub_efi_allocate_any_pages (grub_efi_uintn_t pages)
{
return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS,
pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS,
GRUB_EFI_LOADER_DATA);
}
void *
grub_efi_allocate_fixed (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
return grub_efi_allocate_pages_real (address, pages,
GRUB_EFI_ALLOCATE_ADDRESS,
GRUB_EFI_LOADER_DATA);
}
/* Free pages starting from ADDRESS. */
void
grub_efi_free_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
efi_call_2 (b->free_pages, address, pages);
grub_efi_drop_alloc (address, pages);
}
#if defined (__i386__) || defined (__x86_64__)
/* Helper for stop_broadcom. */
static int
find_card (grub_pci_device_t dev, grub_pci_id_t pciid,
void *data __attribute__ ((unused)))
{
grub_pci_address_t addr;
grub_uint8_t cap;
grub_uint16_t pm_state;
if ((pciid & 0xffff) != GRUB_PCI_VENDOR_BROADCOM)
return 0;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
if (grub_pci_read (addr) >> 24 != GRUB_PCI_CLASS_NETWORK)
return 0;
cap = grub_pci_find_capability (dev, GRUB_PCI_CAP_POWER_MANAGEMENT);
if (!cap)
return 0;
addr = grub_pci_make_address (dev, cap + 4);
pm_state = grub_pci_read_word (addr);
pm_state = pm_state | 0x03;
grub_pci_write_word (addr, pm_state);
grub_pci_read_word (addr);
return 0;
}
static void
stop_broadcom (void)
{
grub_pci_iterate (find_card, NULL);
}
#endif
grub_err_t
grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
grub_efi_uintn_t *map_key,
grub_efi_uintn_t *efi_desc_size,
grub_efi_uint32_t *efi_desc_version)
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;
#if defined (__i386__) || defined (__x86_64__)
const grub_uint16_t apple[] = { 'A', 'p', 'p', 'l', 'e' };
int is_apple;
is_apple = (grub_memcmp (grub_efi_system_table->firmware_vendor,
apple, sizeof (apple)) == 0);
#endif
while (1)
{
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
&finish_desc_size, &finish_desc_version) < 0)
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
if (outbuf && *outbuf_size < finish_mmap_size)
return grub_error (GRUB_ERR_IO, "memory map buffer is too small");
finish_mmap_buf = grub_malloc (finish_mmap_size);
if (!finish_mmap_buf)
return grub_errno;
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
&finish_desc_size, &finish_desc_version) <= 0)
{
grub_free (finish_mmap_buf);
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
}
b = grub_efi_system_table->boot_services;
status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
finish_key);
if (status == GRUB_EFI_SUCCESS)
break;
if (status != GRUB_EFI_INVALID_PARAMETER)
{
grub_free (finish_mmap_buf);
return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
}
grub_free (finish_mmap_buf);
grub_printf ("Trying to terminate EFI services again\n");
}
grub_efi_is_finished = 1;
if (outbuf_size)
*outbuf_size = finish_mmap_size;
if (outbuf)
grub_memcpy (outbuf, finish_mmap_buf, finish_mmap_size);
if (map_key)
*map_key = finish_key;
if (efi_desc_size)
*efi_desc_size = finish_desc_size;
if (efi_desc_version)
*efi_desc_version = finish_desc_version;
#if defined (__i386__) || defined (__x86_64__)
if (is_apple)
stop_broadcom ();
#endif
return GRUB_ERR_NONE;
}
/*
* To obtain the UEFI memory map, we must pass a buffer of sufficient size
* to hold the entire map. This function returns a sane start value for
* buffer size.
*/
grub_efi_uintn_t
grub_efi_find_mmap_size (void)
{
grub_efi_uintn_t mmap_size = 0;
grub_efi_uintn_t desc_size;
if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0)
{
grub_error (GRUB_ERR_IO, "cannot get EFI memory map size");
return 0;
}
/*
* Add an extra page, since UEFI can alter the memory map itself on
* callbacks or explicit calls, including console output.
*/
return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_SIZE);
}
/* Get the memory map as defined in the EFI spec. Return 1 if successful,
return 0 if partial, or return -1 if an error occurs. */
int
grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size,
grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t *map_key,
grub_efi_uintn_t *descriptor_size,
grub_efi_uint32_t *descriptor_version)
{
grub_efi_status_t status;
grub_efi_boot_services_t *b;
grub_efi_uintn_t key;
grub_efi_uint32_t version;
grub_efi_uintn_t size;
if (grub_efi_is_finished)
{
int ret = 1;
if (*memory_map_size < finish_mmap_size)
{
grub_memcpy (memory_map, finish_mmap_buf, *memory_map_size);
ret = 0;
}
else
{
grub_memcpy (memory_map, finish_mmap_buf, finish_mmap_size);
ret = 1;
}
*memory_map_size = finish_mmap_size;
if (map_key)
*map_key = finish_key;
if (descriptor_size)
*descriptor_size = finish_desc_size;
if (descriptor_version)
*descriptor_version = finish_desc_version;
return ret;
}
/* Allow some parameters to be missing. */
if (! map_key)
map_key = &key;
if (! descriptor_version)
descriptor_version = &version;
if (! descriptor_size)
descriptor_size = &size;
b = grub_efi_system_table->boot_services;
status = efi_call_5 (b->get_memory_map, memory_map_size, memory_map, map_key,
descriptor_size, descriptor_version);
if (*descriptor_size == 0)
*descriptor_size = sizeof (grub_efi_memory_descriptor_t);
if (status == GRUB_EFI_SUCCESS)
return 1;
else if (status == GRUB_EFI_BUFFER_TOO_SMALL)
return 0;
else
return -1;
}
/* Sort the memory map in place. */
static void
sort_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *d1;
grub_efi_memory_descriptor_t *d2;
for (d1 = memory_map;
d1 < memory_map_end;
d1 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size))
{
grub_efi_memory_descriptor_t *max_desc = d1;
for (d2 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size);
d2 < memory_map_end;
d2 = NEXT_MEMORY_DESCRIPTOR (d2, desc_size))
{
if (max_desc->num_pages < d2->num_pages)
max_desc = d2;
}
if (max_desc != d1)
{
grub_efi_memory_descriptor_t tmp;
tmp = *d1;
*d1 = *max_desc;
*max_desc = tmp;
}
}
}
/* Filter the descriptors. GRUB needs only available memory. */
static grub_efi_memory_descriptor_t *
filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_memory_descriptor_t *filtered_memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
grub_efi_memory_descriptor_t *filtered_desc;
for (desc = memory_map, filtered_desc = filtered_memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
{
if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY
#if 1
&& desc->physical_start <= GRUB_EFI_MAX_USABLE_ADDRESS
#endif
&& desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
&& desc->num_pages != 0)
{
grub_memcpy (filtered_desc, desc, desc_size);
/* Avoid less than 1MB, because some loaders seem to be confused. */
if (desc->physical_start < 0x100000)
{
desc->num_pages -= BYTES_TO_PAGES (0x100000
- desc->physical_start);
desc->physical_start = 0x100000;
}
#if 1
if (BYTES_TO_PAGES (filtered_desc->physical_start)
+ filtered_desc->num_pages
> BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS))
filtered_desc->num_pages
= (BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS)
- BYTES_TO_PAGES (filtered_desc->physical_start));
#endif
if (filtered_desc->num_pages == 0)
continue;
filtered_desc = NEXT_MEMORY_DESCRIPTOR (filtered_desc, desc_size);
}
}
return filtered_desc;
}
/* Return the total number of pages. */
static grub_efi_uint64_t
get_total_pages (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
grub_efi_uint64_t total = 0;
for (desc = memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
total += desc->num_pages;
return total;
}
/* Add memory regions. */
static void
add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end,
grub_efi_uint64_t required_pages)
{
grub_efi_memory_descriptor_t *desc;
for (desc = memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_uint64_t pages;
grub_efi_physical_address_t start;
void *addr;
start = desc->physical_start;
pages = desc->num_pages;
if (pages > required_pages)
{
start += PAGES_TO_BYTES (pages - required_pages);
pages = required_pages;
}
addr = grub_efi_allocate_pages_real (start, pages,
GRUB_EFI_ALLOCATE_ADDRESS,
GRUB_EFI_LOADER_CODE);
if (! addr)
grub_fatal ("cannot allocate conventional memory %p with %u pages",
(void *) ((grub_addr_t) start),
(unsigned) pages);
grub_mm_init_region (addr, PAGES_TO_BYTES (pages));
required_pages -= pages;
if (required_pages == 0)
break;
}
if (required_pages > 0)
grub_fatal ("too little memory");
}
void
grub_efi_memory_fini (void)
{
/*
* Free all stale allocations. grub_efi_free_pages() will remove
* the found entry from the list and it will always find the first
* list entry (efi_allocated_memory is the list start). Hence we
* remove all entries from the list until none is left altogether.
*/
while (efi_allocated_memory)
grub_efi_free_pages (efi_allocated_memory->address,
efi_allocated_memory->pages);
}
#if 0
/* Print the memory map. */
static void
print_memory_map (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t desc_size,
grub_efi_memory_descriptor_t *memory_map_end)
{
grub_efi_memory_descriptor_t *desc;
int i;
for (desc = memory_map, i = 0;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size), i++)
{
grub_printf ("MD: t=%x, p=%llx, v=%llx, n=%llx, a=%llx\n",
desc->type, desc->physical_start, desc->virtual_start,
desc->num_pages, desc->attribute);
}
}
#endif
void
grub_efi_mm_init (void)
{
grub_efi_memory_descriptor_t *memory_map;
grub_efi_memory_descriptor_t *memory_map_end;
grub_efi_memory_descriptor_t *filtered_memory_map;
grub_efi_memory_descriptor_t *filtered_memory_map_end;
grub_efi_uintn_t map_size;
grub_efi_uintn_t desc_size;
grub_efi_uint64_t total_pages;
grub_efi_uint64_t required_pages;
int mm_status;
/* Prepare a memory region to store two memory maps. */
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
if (! memory_map)
grub_fatal ("cannot allocate memory");
/* Obtain descriptors for available memory. */
map_size = MEMORY_MAP_SIZE;
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0);
if (mm_status == 0)
{
grub_efi_free_pages
((grub_efi_physical_address_t) ((grub_addr_t) memory_map),
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
/* Freeing/allocating operations may increase memory map size. */
map_size += desc_size * 32;
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size));
if (! memory_map)
grub_fatal ("cannot allocate memory");
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0,
&desc_size, 0);
}
if (mm_status < 0)
grub_fatal ("cannot get memory map");
memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size);
filtered_memory_map = memory_map_end;
filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
desc_size, memory_map_end);
/* By default, request a quarter of the available memory. */
total_pages = get_total_pages (filtered_memory_map, desc_size,
filtered_memory_map_end);
#if defined (__mips__) && (_MIPS_SIM == _ABI64)
required_pages = (total_pages > 4096) ? (total_pages - 4096) : (total_pages >> 1);
#else
required_pages = (total_pages >> 2);
#endif
if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
/* Sort the filtered descriptors, so that GRUB can allocate pages
from smaller regions. */
sort_memory_map (filtered_memory_map, desc_size, filtered_memory_map_end);
/* Allocate memory regions for GRUB's memory management. */
add_memory_regions (filtered_memory_map, desc_size,
filtered_memory_map_end, required_pages);
#if 0
/* For debug. */
map_size = MEMORY_MAP_SIZE;
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0)
grub_fatal ("cannot get memory map");
grub_printf ("printing memory map\n");
print_memory_map (memory_map, desc_size,
NEXT_MEMORY_DESCRIPTOR (memory_map, map_size));
grub_fatal ("Debug. ");
#endif
/* Release the memory maps. */
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
}
#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
grub_err_t
grub_efi_get_ram_base(grub_addr_t *base_addr)
{
grub_efi_memory_descriptor_t *memory_map, *desc;
grub_efi_uintn_t memory_map_size, desc_size;
int ret;
memory_map_size = grub_efi_find_mmap_size();
memory_map = grub_malloc (memory_map_size);
if (! memory_map)
return GRUB_ERR_OUT_OF_MEMORY;
ret = grub_efi_get_memory_map (&memory_map_size, memory_map, NULL,
&desc_size, NULL);
if (ret < 1)
return GRUB_ERR_BUG;
for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS;
(grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size);
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
if (desc->attribute & GRUB_EFI_MEMORY_WB)
*base_addr = grub_min (*base_addr, desc->physical_start);
grub_free(memory_map);
return GRUB_ERR_NONE;
}
#endif

@ -0,0 +1,23 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009,2017 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>
FUNCTION (grub_arch_sync_caches)
jr.hb $ra

@ -0,0 +1,150 @@
/* dl-mips64.c - arch-dependent part of loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2007,2009,2017 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/elf.h>
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/cpu/types.h>
#include <grub/mm.h>
#include <grub/i18n.h>
/* Check if EHDR is a valid ELF header. */
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
#ifdef GRUB_CPU_WORDS_BIGENDIAN
if (e->e_ident[EI_CLASS] != ELFCLASS64
|| e->e_ident[EI_DATA] != ELFDATA2MSB
|| e->e_machine != EM_MIPS)
#else
if (e->e_ident[EI_CLASS] != ELFCLASS64
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|| e->e_machine != EM_MIPS)
#endif
return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
return GRUB_ERR_NONE;
}
#pragma GCC diagnostic ignored "-Wcast-align"
grub_err_t
grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
grub_size_t *tramp, grub_size_t *got)
{
*tramp = 0;
*got = 0;
return GRUB_ERR_NONE;
}
/* Relocate symbols. */
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
Elf_Shdr *s, grub_dl_segment_t seg)
{
Elf_Ehdr *e = ehdr;
Elf_Rel *rel, *max;
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = (Elf_Rel *) ((char *) rel + s->sh_size);
rel < max;
rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
{
grub_uint8_t *addr;
Elf_Sym *sym;
Elf_Addr r_info;
grub_uint64_t sym_value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
r_info = ((grub_uint64_t) rel->r_info << 32) |
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
addr = (grub_uint8_t *) ((char *) seg->addr + rel->r_offset);
sym = (Elf_Sym *) ((char *) mod->symtab
+ mod->symsize * ELF_R_SYM (r_info));
sym_value = sym->st_value;
if (s->sh_type == SHT_RELA)
{
sym_value += ((Elf_Rela *) rel)->r_addend;
}
switch (ELF_R_TYPE (r_info))
{
case R_MIPS_64:
*(grub_uint64_t *) addr += sym_value;
break;
case R_MIPS_32:
*(grub_uint32_t *) addr += sym_value;
break;
case R_MIPS_26:
{
grub_uint32_t value;
grub_uint32_t raw;
raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
value = raw << 2;
value += sym_value;
raw = (value >> 2) & 0x3ffffff;
*(grub_uint32_t *) addr =
raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
}
break;
case R_MIPS_LO16:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) sym_value;
break;
case R_MIPS_HI16:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x8000UL) >> 16);
break;
case R_MIPS_HIGHER:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x80008000UL) >> 32);
break;
case R_MIPS_HIGHEST:
#ifdef GRUB_CPU_WORDS_BIGENDIAN
addr += 2;
#endif
*(grub_uint16_t *) addr = (grub_uint16_t) ((sym_value + 0x800080008000UL) >> 48);
break;
default:
{
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%x is not implemented yet"),
ELF_R_TYPE (r_info));
}
break;
}
}
return GRUB_ERR_NONE;
}

@ -0,0 +1,85 @@
/* init.c - initialize an arm-based EFI system */
/*
* 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/env.h>
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/cpu/time.h>
#include <grub/efi/efi.h>
#include <grub/loader.h>
#include <grub/time.h>
#include <grub/machine/loongson.h>
static grub_uint64_t tmr;
static grub_efi_event_t tmr_evt;
static grub_uint64_t
grub_efi_get_time_ms (void)
{
return tmr;
}
static void
grub_loongson_increment_timer (grub_efi_event_t event __attribute__ ((unused)),
void *context __attribute__ ((unused)))
{
tmr += 10;
}
void
grub_machine_init (void)
{
grub_efi_boot_services_t *b;
grub_efi_init ();
b = grub_efi_system_table->boot_services;
efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
grub_install_get_time_ms (grub_efi_get_time_ms);
if (grub_efi_is_loongson ())
grub_efi_loongson_init ();
else
/* FIXME: Get cpuclock from EFI. */
grub_timer_init (1000000000U);
}
void
grub_machine_fini (int flags)
{
grub_efi_boot_services_t *b;
if (!(flags & GRUB_LOADER_FLAG_NORETURN))
return;
b = grub_efi_system_table->boot_services;
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
efi_call_1 (b->close_event, tmr_evt);
if (grub_efi_is_loongson ())
grub_efi_loongson_fini ();
grub_efi_fini ();
}

@ -0,0 +1,33 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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/efi/efi.h>
#include <grub/cpu/time.h>
#include <grub/loader.h>
#include <grub/machine/loongson.h>
void
grub_efi_loongson_init (void)
{
}
void
grub_efi_loongson_fini (void)
{
}

@ -0,0 +1,47 @@
/*
* 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/symbol.h>
.file "startup.S"
.text
.set push
.align 4
FUNCTION(_start)
/*
* EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0.
*/
daddiu $sp, -16
sd $ra, ($sp)
dla $a2, grub_efi_image_handle
sd $a0, ($a2)
dla $a2, grub_efi_system_table
sd $a1, ($a2)
jal grub_main
1:
ld $ra, ($sp)
daddiu $sp, 16
jr $ra
.set pop

@ -0,0 +1,47 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009,2017 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/env.h>
#include <grub/time.h>
#include <grub/cpu/mips.h>
grub_uint32_t grub_arch_cpuclock;
/* FIXME: use interrupt to count high. */
grub_uint64_t
grub_get_rtc (void)
{
static grub_uint32_t high = 0;
static grub_uint32_t last = 0;
grub_uint32_t low;
asm volatile ("mfc0 %0, " GRUB_CPU_MIPS_COP0_TIMER_COUNT : "=r" (low));
if (low < last)
high++;
last = low;
return (((grub_uint64_t) high) << 32) | low;
}
void
grub_timer_init (grub_uint32_t cpuclock)
{
grub_arch_cpuclock = cpuclock;
grub_install_get_time_ms (grub_rtc_get_time_ms);
}

@ -0,0 +1,40 @@
/* efi.c - generic EFI support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/kernel.h>
#include <grub/acpi.h>
#include <grub/loader.h>
void
grub_halt (void)
{
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__mips__) &&\
!defined(__riscv)
grub_acpi_halt ();
#endif
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
while (1);
}

@ -0,0 +1,495 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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/cache.h>
#include <grub/efi/efi.h>
#include <grub/cpu/efi/memory.h>
#include <grub/cpu/memory.h>
#include <grub/machine/loongson.h>
#pragma GCC diagnostic ignored "-Wunused-function"
#define loongson_params (&loongson_boot_params->boot_params.efi.smbios.lp)
#define loongson_boot_params_size ALIGN_UP (sizeof (*loongson_boot_params), 8)
#define loongson_reset_code_size (&grub_efi_loongson_reset_end - &grub_efi_loongson_reset_start)
extern grub_uint8_t grub_efi_loongson_reset_start;
extern grub_uint8_t grub_efi_loongson_reset_end;
static struct
{
grub_efi_loongson_boot_params boot_params;
grub_efi_loongson_memory_map memory_map;
grub_efi_loongson_cpu_info cpu_info;
grub_efi_loongson_system_info system_info;
grub_efi_loongson_irq_src_routing_table irq_src_routing_table;
grub_efi_loongson_interface_info interface_info;
grub_efi_loongson_special_attribute special_attribute;
grub_efi_loongson_board_devices board_devices;
} GRUB_PACKED
* loongson_boot_params;
static void
grub_efi_loongson_init_reset_system (void)
{
grub_efi_loongson_boot_params *boot_params;
grub_uint8_t *reset_code_addr = (grub_uint8_t *) loongson_boot_params +
loongson_boot_params_size;
boot_params = &loongson_boot_params->boot_params;
grub_efi_loongson_reset_system_addr =
(grub_uint64_t) grub_efi_system_table->runtime_services->reset_system;
grub_memcpy (reset_code_addr, &grub_efi_loongson_reset_start, loongson_reset_code_size);
grub_arch_sync_caches (reset_code_addr, loongson_reset_code_size);
boot_params->reset_system.reset_cold = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_cold -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.reset_warm = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_warm -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.shutdown = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_shutdown -
(grub_uint64_t) &grub_efi_loongson_reset_start);
boot_params->reset_system.do_suspend = (grub_uint64_t) reset_code_addr +
((grub_uint64_t) &grub_efi_loongson_reset_suspend -
(grub_uint64_t) &grub_efi_loongson_reset_start);
}
static void
grub_efi_loongson_init_smbios (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_smbios_table *dst = &loongson_boot_params->boot_params.efi.smbios;
dst->vers = smbios_table->vers;
dst->vga_bios = smbios_table->vga_bios;
}
static void
grub_efi_loongson_init_cpu_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_cpu_info *src = (void *) smbios_table->lp.cpu_offset;
grub_efi_loongson_cpu_info *dst = &loongson_boot_params->cpu_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_cpu_info));
loongson_params->cpu_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_system_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_system_info *src = (void *) smbios_table->lp.system_offset;
grub_efi_loongson_system_info *dst = &loongson_boot_params->system_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_system_info));
loongson_params->system_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_irq_src_routing_table (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_irq_src_routing_table *src = (void *) smbios_table->lp.irq_offset;
grub_efi_loongson_irq_src_routing_table *dst = &loongson_boot_params->irq_src_routing_table;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_irq_src_routing_table));
loongson_params->irq_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_interface_info (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_interface_info *src = (void *) smbios_table->lp.interface_offset;
grub_efi_loongson_interface_info *dst = &loongson_boot_params->interface_info;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_interface_info));
loongson_params->interface_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_special_attribute (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_special_attribute *src = (void *) smbios_table->lp.special_offset;
grub_efi_loongson_special_attribute *dst = &loongson_boot_params->special_attribute;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_special_attribute));
loongson_params->special_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
static void
grub_efi_loongson_init_board_devices (grub_efi_loongson_smbios_table *smbios_table)
{
grub_efi_loongson_board_devices *src = (void *) smbios_table->lp.boarddev_table_offset;
grub_efi_loongson_board_devices *dst = &loongson_boot_params->board_devices;
if (!src)
return;
grub_memcpy (dst, src, sizeof (grub_efi_loongson_board_devices));
loongson_params->boarddev_table_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
}
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
static void
grub_efi_loongson_init_memory_map (grub_efi_loongson_smbios_table *smbios_table,
grub_efi_memory_descriptor_t *mmap_buf,
grub_efi_uintn_t mmap_size,
grub_efi_uintn_t desc_size)
{
grub_efi_loongson_memory_map *src = (void *) smbios_table->lp.memory_offset;
grub_efi_loongson_memory_map *dst = &loongson_boot_params->memory_map;
grub_efi_memory_descriptor_t *mmap_end;
grub_efi_memory_descriptor_t *desc;
grub_efi_memory_descriptor_t *desc_next;
grub_efi_uint32_t mem_types_reserved[] =
{
1, // GRUB_EFI_RESERVED_MEMORY_TYPE
0, // GRUB_EFI_LOADER_CODE
0, // GRUB_EFI_LOADER_DATA
0, // GRUB_EFI_BOOT_SERVICES_CODE
0, // GRUB_EFI_BOOT_SERVICES_DATA
1, // GRUB_EFI_RUNTIME_SERVICES_CODE
1, // GRUB_EFI_RUNTIME_SERVICES_DATA
0, // GRUB_EFI_CONVENTIONAL_MEMORY
1, // GRUB_EFI_UNUSABLE_MEMORY
0, // GRUB_EFI_ACPI_RECLAIM_MEMORY
0, // GRUB_EFI_ACPI_MEMORY_NVS
1, // GRUB_EFI_MEMORY_MAPPED_IO
1, // GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE
1, // GRUB_EFI_PAL_CODE
1, // GRUB_EFI_PERSISTENT_MEMORY
};
grub_uint32_t need_sort = 1;
if (!src)
return;
dst->vers = src->vers;
dst->nr_map = 0;
dst->mem_freq = src->mem_freq;
loongson_params->memory_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
if (!mmap_buf || !mmap_size || !desc_size)
return;
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
/* drop reserved */
for (desc = mmap_buf,
desc_next = desc;
desc < mmap_end;
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
desc->type = mem_types_reserved[desc->type];
if (desc->type)
continue;
if (desc != desc_next)
*desc_next = *desc;
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size);
}
mmap_end = desc_next;
/* sort: low->high */
while (need_sort)
{
need_sort = 0;
for (desc = mmap_buf,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
(desc < mmap_end) && (desc_next < mmap_end);
desc = desc_next,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_memory_descriptor_t tmp;
if (desc->physical_start <= desc_next->physical_start)
continue;
tmp = *desc;
*desc = *desc_next;
*desc_next = tmp;
need_sort = 1;
}
}
/* combine continuous memory map */
for (desc = mmap_buf,
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
desc_next < mmap_end;
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size))
{
grub_efi_physical_address_t prev_end = desc->physical_start + (desc->num_pages << 12);
if (prev_end == desc_next->physical_start)
{
desc->num_pages += desc_next->num_pages;
continue;
}
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
grub_memcpy (desc, desc_next, desc_size);
}
mmap_end = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
/* write to loongson memory map */
for (desc = mmap_buf;
desc < mmap_end;
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_physical_address_t physical_start = grub_vtop ((void *) desc->physical_start);
grub_efi_physical_address_t physical_end = physical_start + (desc->num_pages << 12);
physical_start = ALIGN_UP (physical_start, 0x100000);
physical_end = ALIGN_DOWN (physical_end, 0x100000);
if (physical_start >= physical_end || (physical_end - physical_start) < 0x100000)
continue;
dst->map[dst->nr_map].node_id = (desc->physical_start >> 44) & 0xf;
dst->map[dst->nr_map].mem_type = (physical_end <= 0x10000000) ?
GRUB_EFI_LOONGSON_SYSTEM_RAM_LOW :
GRUB_EFI_LOONGSON_SYSTEM_RAM_HIGH;
dst->map[dst->nr_map].mem_start = physical_start;
dst->map[dst->nr_map].mem_size = (physical_end - physical_start) >> 20;
grub_dprintf ("loongson", "memory map %03u: 0x%016lx 0x%016lx @ %u\n",
dst->nr_map, physical_start, physical_end - physical_start,
dst->map[dst->nr_map].node_id);
dst->nr_map ++;
}
}
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
#define SUB_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) - (size)))
void
grub_efi_loongson_alloc_boot_params (void)
{
grub_efi_memory_descriptor_t *mmap_buf;
grub_efi_memory_descriptor_t *mmap_end;
grub_efi_memory_descriptor_t *desc;
grub_efi_uintn_t mmap_size;
grub_efi_uintn_t desc_size;
grub_efi_physical_address_t address;
grub_efi_allocate_type_t type;
grub_efi_uintn_t pages;
grub_efi_status_t status;
grub_efi_boot_services_t *b;
int mm_status;
type = GRUB_EFI_ALLOCATE_ADDRESS;
pages = BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size);
mmap_size = (1 << 12);
mmap_buf = grub_malloc (mmap_size);
if (!mmap_buf)
grub_fatal ("out of memory!");
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
if (mm_status == 0)
{
grub_free (mmap_buf);
mmap_size += desc_size * 32;
mmap_buf = grub_malloc (mmap_size);
if (!mmap_buf)
grub_fatal ("out of memory!");
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
}
if (mm_status < 0)
grub_fatal ("cannot get memory map!");
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
for (desc = SUB_MEMORY_DESCRIPTOR (mmap_end, desc_size);
desc >= mmap_buf;
desc = SUB_MEMORY_DESCRIPTOR (desc, desc_size))
{
if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY)
continue;
if (desc->physical_start >= GRUB_EFI_MAX_USABLE_ADDRESS)
continue;
if (desc->num_pages < pages)
continue;
address = desc->physical_start;
break;
}
grub_free (mmap_buf);
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_RUNTIME_SERVICES_DATA, pages, &address);
if (status != GRUB_EFI_SUCCESS)
grub_fatal ("cannot allocate Loongson boot parameters!");
loongson_boot_params = (void *) ((grub_addr_t) address);
}
void
grub_efi_loongson_free_boot_params (void)
{
grub_efi_free_pages ((grub_addr_t) loongson_boot_params,
BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size));
}
void *
grub_efi_loongson_get_smbios_table (void)
{
static grub_efi_loongson_smbios_table *smbios_table;
grub_efi_loongson_boot_params *old_boot_params;
struct bootparamsinterface* boot_params;
void * tmp_boot_params = NULL;
char * p = NULL;
if(smbios_table)
return smbios_table;
tmp_boot_params = grub_efi_loongson_get_boot_params();
if(tmp_boot_params == NULL)
{
grub_dprintf("loongson", "tmp_boot_params is NULL\n");
return tmp_boot_params;
}
boot_params = (struct bootparamsinterface *)tmp_boot_params;
p = (char *)&(boot_params->signature);
if(grub_strncmp(p, "BPI", 3) == 0)
{
grub_dprintf("loongson", "find new bpi\n");
return boot_params ? boot_params : 0;
}
else
{
old_boot_params = (grub_efi_loongson_boot_params *)tmp_boot_params;
return old_boot_params ? &old_boot_params->efi.smbios : 0;
}
}
int
grub_efi_is_loongson (void)
{
return grub_efi_loongson_get_smbios_table () ? 1 : 0;
}
void *
grub_efi_loongson_get_boot_params (void)
{
static void * boot_params = NULL;
grub_efi_configuration_table_t *tables;
grub_efi_guid_t smbios_guid = GRUB_EFI_LOONGSON_SMBIOS_TABLE_GUID;
unsigned int i;
if (boot_params)
return boot_params;
/* Look for Loongson SMBIOS in UEFI config tables. */
tables = grub_efi_system_table->configuration_table;
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
if (grub_memcmp (&tables[i].vendor_guid, &smbios_guid, sizeof (smbios_guid)) == 0)
{
boot_params= tables[i].vendor_table;
grub_dprintf ("loongson", "found registered SMBIOS @ %p\n", boot_params);
break;
}
return boot_params;
}
grub_uint8_t
grub_efi_loongson_calculatesum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
{
grub_uint8_t sum;
grub_efi_uintn_t count;
for (sum = 0, count = 0; count < length; count++)
{
sum = (grub_uint8_t) (sum + *(buffer + count));
}
return sum;
}
grub_uint8_t
grub_efi_loongson_grub_calculatechecksum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
{
grub_uint8_t checksum;
checksum = grub_efi_loongson_calculatesum8(buffer, length);
return (grub_uint8_t) (0x100 - checksum);
}
grub_uint32_t
grub_efi_loongson_memmap_sort(struct memmap array[], grub_uint32_t length, mem_map * bpmem, grub_uint32_t index, grub_uint32_t memtype)
{
grub_uint64_t tempmemsize = 0;
grub_uint32_t j = 0;
grub_uint32_t t = 0;
for(j = 0; j < length;)
{
tempmemsize = array[j].memsize;
for(t = j + 1; t < length; t++)
{
if(array[j].memstart + tempmemsize == array[t].memstart)
{
tempmemsize += array[t].memsize;
}
else
{
break;
}
}
bpmem->map[index].memtype = memtype;
bpmem->map[index].memstart = array[j].memstart;
bpmem->map[index].memsize = tempmemsize;
grub_dprintf("loongson", "map[%d]:type %x, start 0x%llx, end 0x%llx\n",
index,
bpmem->map[index].memtype,
(unsigned long long)bpmem->map[index].memstart,
(unsigned long long)bpmem->map[index].memstart+ bpmem->map[index].memsize
);
j = t;
index++;
}
return index;
}

@ -0,0 +1,61 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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 "loongson.S"
.text
.set push
.set noreorder
.align 4
VARIABLE (grub_efi_loongson_reset_start)
VARIABLE (grub_efi_loongson_reset_system_addr)
.dword 0
reset_system:
bal 1f
move $a1, $zero
1:
ld $t9, -16($ra)
move $a2, $zero
jalr $t9
move $a3, $zero
FUNCTION(grub_efi_loongson_reset_cold)
b reset_system
li $a0, 0
FUNCTION(grub_efi_loongson_reset_warm)
b reset_system
li $a0, 1
FUNCTION(grub_efi_loongson_reset_shutdown)
b reset_system
li $a0, 2
FUNCTION(grub_efi_loongson_reset_suspend)
b reset_system
li $a0, 3
VARIABLE (grub_efi_loongson_reset_end)
.set pop

@ -0,0 +1,169 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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/misc.h>
#include <grub/types.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/cache.h>
#include <grub/mips64/relocator.h>
#include <grub/relocator_private.h>
extern grub_uint8_t grub_relocator_forward_start;
extern grub_uint8_t grub_relocator_forward_end;
extern grub_uint8_t grub_relocator_backward_start;
extern grub_uint8_t grub_relocator_backward_end;
#define REGW_SIZEOF (6 * sizeof (grub_uint32_t))
#define JUMP_SIZEOF (2 * sizeof (grub_uint32_t))
#define RELOCATOR_SRC_SIZEOF(x) (&grub_relocator_##x##_end \
- &grub_relocator_##x##_start)
#define RELOCATOR_SIZEOF(x) (RELOCATOR_SRC_SIZEOF(x) \
+ REGW_SIZEOF * 3)
grub_size_t grub_relocator_align = sizeof (grub_uint64_t);
grub_size_t grub_relocator_forward_size;
grub_size_t grub_relocator_backward_size;
grub_size_t grub_relocator_jumper_size = JUMP_SIZEOF + REGW_SIZEOF;
void
grub_cpu_relocator_init (void)
{
grub_relocator_forward_size = RELOCATOR_SIZEOF(forward);
grub_relocator_backward_size = RELOCATOR_SIZEOF(backward);
}
static void
write_reg (int regn, grub_uint64_t val, void **target)
{
grub_uint32_t lui;
grub_uint32_t ori;
grub_uint32_t dsll;
/* lui $r, 0 */
lui = (0x3c00 | regn) << 16;
/* ori $r, $r, 0 */
ori = (0x3400 | (regn << 5) | regn) << 16;
/* dsll $r, $r, 16 */
dsll = (regn << 16) | (regn << 11) | (16 << 6) | 56;
/* lui $r, val[63:48]. */
*(grub_uint32_t *) *target = lui | (grub_uint16_t) (val >> 48);
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[47:32]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 32);
*target = ((grub_uint32_t *) *target) + 1;
/* dsll $r, $r, 16 */
*(grub_uint32_t *) *target = dsll;
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[31:16]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 16);
*target = ((grub_uint32_t *) *target) + 1;
/* dsll $r, $r, 16 */
*(grub_uint32_t *) *target = dsll;
*target = ((grub_uint32_t *) *target) + 1;
/* ori $r, val[15:0]. */
*(grub_uint32_t *) *target = ori | (grub_uint16_t) val;
*target = ((grub_uint32_t *) *target) + 1;
}
static void
write_jump (int regn, void **target)
{
/* j $r. */
*(grub_uint32_t *) *target = (regn << 21) | 0x8;
*target = ((grub_uint32_t *) *target) + 1;
/* nop. */
*(grub_uint32_t *) *target = 0;
*target = ((grub_uint32_t *) *target) + 1;
}
void
grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
{
write_reg (1, addr, &rels);
write_jump (1, &rels);
}
void
grub_cpu_relocator_backward (void *ptr0, void *src, void *dest,
grub_size_t size)
{
void *ptr = ptr0;
write_reg (8, (grub_uint64_t) src, &ptr);
write_reg (9, (grub_uint64_t) dest, &ptr);
write_reg (10, (grub_uint64_t) size, &ptr);
grub_memcpy (ptr, &grub_relocator_backward_start,
RELOCATOR_SRC_SIZEOF (backward));
}
void
grub_cpu_relocator_forward (void *ptr0, void *src, void *dest,
grub_size_t size)
{
void *ptr = ptr0;
write_reg (8, (grub_uint64_t) src, &ptr);
write_reg (9, (grub_uint64_t) dest, &ptr);
write_reg (10, (grub_uint64_t) size, &ptr);
grub_memcpy (ptr, &grub_relocator_forward_start,
RELOCATOR_SRC_SIZEOF (forward));
}
grub_err_t
grub_relocator64_boot (struct grub_relocator *rel,
struct grub_relocator64_state state)
{
grub_relocator_chunk_t ch;
void *ptr;
grub_err_t err;
void *relst;
grub_size_t relsize;
grub_size_t stateset_size = 31 * REGW_SIZEOF + JUMP_SIZEOF;
unsigned i;
grub_addr_t vtarget;
err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
(0xffffffff - stateset_size)
+ 1, stateset_size,
grub_relocator_align,
GRUB_RELOCATOR_PREFERENCE_NONE, 0);
if (err)
return err;
ptr = get_virtual_current_address (ch);
for (i = 1; i < 32; i++)
write_reg (i, state.gpr[i], &ptr);
write_jump (state.jumpreg, &ptr);
vtarget = (grub_addr_t) grub_map_memory (get_physical_target_address (ch),
stateset_size);
err = grub_relocator_prepare_relocs (rel, vtarget, &relst, &relsize);
if (err)
return err;
grub_arch_sync_caches ((void *) relst, relsize);
((void (*) (void)) relst) ();
/* Not reached. */
return GRUB_ERR_NONE;
}

@ -0,0 +1,56 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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>
.p2align 4 /* force 16-byte alignment */
.set push
.set noreorder
.set nomacro
VARIABLE (grub_relocator_forward_start)
copycont1:
ld $11,0($8)
sd $11,0($9)
daddiu $8, $8, 8
daddiu $10, $10, -8
bne $10, $0, copycont1
daddiu $9, $9, 8
VARIABLE (grub_relocator_forward_end)
VARIABLE (grub_relocator_backward_start)
daddu $9, $9, $10
daddu $8, $8, $10
/* Backward movsl is implicitly off-by-one. compensate that. */
daddiu $9, $9, -8
daddiu $8, $8, -8
copycont2:
ld $11,0($8)
sd $11,0($9)
daddiu $8, $8, -8
daddiu $10, $10, -8
bne $10, $0, copycont2
daddiu $9, $9, -8
VARIABLE (grub_relocator_backward_end)
.set pop

@ -0,0 +1,69 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,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/symbol.h>
#include <grub/dl.h>
#include <grub/mips64/asm.h>
.file "setjmp.S"
GRUB_MOD_LICENSE "GPLv3+"
.text
/*
* int grub_setjmp (grub_jmp_buf env)
*/
FUNCTION(grub_setjmp)
GRUB_ASM_REG_S $s0, 0($a0)
GRUB_ASM_REG_S $s1, 8($a0)
GRUB_ASM_REG_S $s2, 16($a0)
GRUB_ASM_REG_S $s3, 24($a0)
GRUB_ASM_REG_S $s4, 32($a0)
GRUB_ASM_REG_S $s5, 40($a0)
GRUB_ASM_REG_S $s6, 48($a0)
GRUB_ASM_REG_S $s7, 56($a0)
GRUB_ASM_REG_S $s8, 64($a0)
GRUB_ASM_REG_S $gp, 72($a0)
GRUB_ASM_REG_S $sp, 80($a0)
GRUB_ASM_REG_S $ra, 88($a0)
move $v0, $zero
move $v1, $zero
jr $ra
nop
/*
* int grub_longjmp (grub_jmp_buf env, int val)
*/
FUNCTION(grub_longjmp)
GRUB_ASM_REG_L $s0, 0($a0)
GRUB_ASM_REG_L $s1, 8($a0)
GRUB_ASM_REG_L $s2, 16($a0)
GRUB_ASM_REG_L $s3, 24($a0)
GRUB_ASM_REG_L $s4, 32($a0)
GRUB_ASM_REG_L $s5, 40($a0)
GRUB_ASM_REG_L $s6, 48($a0)
GRUB_ASM_REG_L $s7, 56($a0)
GRUB_ASM_REG_L $s8, 64($a0)
GRUB_ASM_REG_L $gp, 72($a0)
GRUB_ASM_REG_L $sp, 80($a0)
GRUB_ASM_REG_L $ra, 88($a0)
addiu $v0, $zero, 1
movn $v0, $a1, $a1
move $v1, $zero
jr $ra
nop

File diff suppressed because it is too large Load Diff

@ -0,0 +1,26 @@
#if defined(__i386__)
#include "./i386/setjmp.S"
#elif defined(__x86_64__)
#include "./x86_64/setjmp.S"
#elif defined(__sparc__)
#include "./sparc64/setjmp.S"
#elif defined(__mips__)
#if _MIPS_SIM == _ABI64
#include "./mips64/setjmp.S"
#else
#include "./mips/setjmp.S"
#endif
#elif defined(__powerpc__) || defined(__PPC__)
#include "./powerpc/setjmp.S"
#elif defined(__ia64__)
#include "./ia64/setjmp.S"
#include "./ia64/longjmp.S"
#elif defined(__arm__)
#include "./arm/setjmp.S"
#elif defined(__aarch64__)
#include "./arm64/setjmp.S"
#elif defined(__riscv)
#include "./riscv/setjmp.S"
#else
#error "Unknown target cpu type"
#endif

File diff suppressed because it is too large Load Diff

@ -0,0 +1,463 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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/serial.h>
#include <grub/term.h>
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/terminfo.h>
#if !defined (GRUB_MACHINE_EMU) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
#include <grub/cpu/io.h>
#endif
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/list.h>
#ifdef GRUB_MACHINE_MIPS_LOONGSON
#include <grub/machine/kernel.h>
#endif
#ifdef GRUB_MACHINE_IEEE1275
#include <grub/ieee1275/console.h>
#endif
GRUB_MOD_LICENSE ("GPLv3+");
#define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports))
enum
{
OPTION_UNIT,
OPTION_PORT,
OPTION_SPEED,
OPTION_WORD,
OPTION_PARITY,
OPTION_STOP,
OPTION_BASE_CLOCK,
OPTION_RTSCTS
};
/* Argument options. */
static const struct grub_arg_option options[] =
{
{"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT},
{"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING},
{"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT},
{"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT},
{"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING},
{"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT},
{"base-clock", 'b', 0, N_("Set the base frequency."), 0, ARG_TYPE_STRING},
{"rtscts", 'f', 0, N_("Enable/disable RTS/CTS."), "on|off", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static struct grub_serial_port *grub_serial_ports;
struct grub_serial_output_state
{
struct grub_terminfo_output_state tinfo;
struct grub_serial_port *port;
};
struct grub_serial_input_state
{
struct grub_terminfo_input_state tinfo;
struct grub_serial_port *port;
};
static void
serial_put (grub_term_output_t term, const int c)
{
struct grub_serial_output_state *data = term->data;
data->port->driver->put (data->port, c);
}
static int
serial_fetch (grub_term_input_t term)
{
struct grub_serial_input_state *data = term->data;
return data->port->driver->fetch (data->port);
}
static const struct grub_serial_input_state grub_serial_terminfo_input_template =
{
.tinfo =
{
.readkey = serial_fetch
}
};
static const struct grub_serial_output_state grub_serial_terminfo_output_template =
{
.tinfo =
{
.put = serial_put,
.size = { 80, 24 }
}
};
static struct grub_serial_input_state grub_serial_terminfo_input;
static struct grub_serial_output_state grub_serial_terminfo_output;
static int registered = 0;
static struct grub_term_input grub_serial_term_input =
{
.name = "serial",
.init = grub_terminfo_input_init,
.getkey = grub_terminfo_getkey,
.data = &grub_serial_terminfo_input
};
static struct grub_term_output grub_serial_term_output =
{
.name = "serial",
.init = grub_terminfo_output_init,
.putchar = grub_terminfo_putchar,
.getwh = grub_terminfo_getwh,
.getxy = grub_terminfo_getxy,
.gotoxy = grub_terminfo_gotoxy,
.cls = grub_terminfo_cls,
.setcolorstate = grub_terminfo_setcolorstate,
.setcursor = grub_terminfo_setcursor,
.flags = GRUB_TERM_CODE_TYPE_ASCII,
.data = &grub_serial_terminfo_output,
.progress_update_divisor = GRUB_PROGRESS_SLOW
};
struct grub_serial_port *
grub_serial_find (const char *name)
{
struct grub_serial_port *port;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
#if ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)) && !defined(GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC)
if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) == 0
&& grub_isxdigit (name [sizeof ("port") - 1]))
{
name = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1],
0, 16));
if (!name)
return NULL;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
}
#endif
#ifdef GRUB_MACHINE_IEEE1275
if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
{
name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
if (!name)
return NULL;
FOR_SERIAL_PORTS (port)
if (grub_strcmp (port->name, name) == 0)
break;
}
#endif
return port;
}
static grub_err_t
grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
char pname[40];
const char *name = NULL;
struct grub_serial_port *port;
struct grub_serial_config config;
grub_err_t err;
if (state[OPTION_UNIT].set)
{
grub_snprintf (pname, sizeof (pname), "com%ld",
grub_strtoul (state[0].arg, 0, 0));
name = pname;
}
if (state[OPTION_PORT].set)
{
grub_snprintf (pname, sizeof (pname), "port%lx",
grub_strtoul (state[1].arg, 0, 0));
name = pname;
}
if (argc >= 1)
name = args[0];
if (!name)
name = "com0";
port = grub_serial_find (name);
if (!port)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("serial port `%s' isn't found"),
name);
config = port->config;
if (state[OPTION_SPEED].set) {
config.speed = grub_strtoul (state[OPTION_SPEED].arg, 0, 0);
if (config.speed == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port parity"));
}
if (state[OPTION_WORD].set)
config.word_len = grub_strtoul (state[OPTION_WORD].arg, 0, 0);
if (state[OPTION_PARITY].set)
{
if (! grub_strcmp (state[OPTION_PARITY].arg, "no"))
config.parity = GRUB_SERIAL_PARITY_NONE;
else if (! grub_strcmp (state[OPTION_PARITY].arg, "odd"))
config.parity = GRUB_SERIAL_PARITY_ODD;
else if (! grub_strcmp (state[OPTION_PARITY].arg, "even"))
config.parity = GRUB_SERIAL_PARITY_EVEN;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port parity"));
}
if (state[OPTION_RTSCTS].set)
{
if (grub_strcmp (state[OPTION_RTSCTS].arg, "on") == 0)
config.rtscts = 1;
else if (grub_strcmp (state[OPTION_RTSCTS].arg, "off") == 0)
config.rtscts = 0;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port flow control"));
}
if (state[OPTION_STOP].set)
{
if (! grub_strcmp (state[OPTION_STOP].arg, "1"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_1;
else if (! grub_strcmp (state[OPTION_STOP].arg, "2"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_2;
else if (! grub_strcmp (state[OPTION_STOP].arg, "1.5"))
config.stop_bits = GRUB_SERIAL_STOP_BITS_1_5;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port stop bits number"));
}
if (state[OPTION_BASE_CLOCK].set)
{
char *ptr;
config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0);
if (grub_errno)
return grub_errno;
if (ptr && *ptr == 'M')
config.base_clock *= 1000000;
if (ptr && (*ptr == 'k' || *ptr == 'K'))
config.base_clock *= 1000;
}
if (config.speed == 0)
config.speed = 9600;
/* Initialize with new settings. */
err = port->driver->configure (port, &config);
if (err)
return err;
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
/* Compatibility kludge. */
if (port->driver == &grub_ns8250_driver)
{
if (!registered)
{
grub_terminfo_output_register (&grub_serial_term_output, "vt100");
grub_term_register_input ("serial", &grub_serial_term_input);
grub_term_register_output ("serial", &grub_serial_term_output);
}
grub_serial_terminfo_output.port = port;
grub_serial_terminfo_input.port = port;
registered = 1;
}
#endif
return GRUB_ERR_NONE;
}
#ifdef GRUB_MACHINE_MIPS_LOONGSON
const char loongson_defserial[][6] =
{
[GRUB_ARCH_MACHINE_YEELOONG] = "com0",
[GRUB_ARCH_MACHINE_FULOONG2F] = "com2",
[GRUB_ARCH_MACHINE_FULOONG2E] = "com1"
};
#endif
grub_err_t
grub_serial_register (struct grub_serial_port *port)
{
struct grub_term_input *in;
struct grub_term_output *out;
struct grub_serial_input_state *indata;
struct grub_serial_output_state *outdata;
in = grub_malloc (sizeof (*in));
if (!in)
return grub_errno;
indata = grub_malloc (sizeof (*indata));
if (!indata)
{
grub_free (in);
return grub_errno;
}
grub_memcpy (in, &grub_serial_term_input, sizeof (*in));
in->data = indata;
in->name = grub_xasprintf ("serial_%s", port->name);
grub_memcpy (indata, &grub_serial_terminfo_input, sizeof (*indata));
if (!in->name)
{
grub_free (in);
grub_free (indata);
return grub_errno;
}
out = grub_zalloc (sizeof (*out));
if (!out)
{
grub_free (indata);
grub_free ((char *) in->name);
grub_free (in);
return grub_errno;
}
outdata = grub_malloc (sizeof (*outdata));
if (!outdata)
{
grub_free (indata);
grub_free ((char *) in->name);
grub_free (out);
grub_free (in);
return grub_errno;
}
grub_memcpy (out, &grub_serial_term_output, sizeof (*out));
out->data = outdata;
out->name = in->name;
grub_memcpy (outdata, &grub_serial_terminfo_output, sizeof (*outdata));
grub_list_push (GRUB_AS_LIST_P (&grub_serial_ports), GRUB_AS_LIST (port));
((struct grub_serial_input_state *) in->data)->port = port;
((struct grub_serial_output_state *) out->data)->port = port;
port->term_in = in;
port->term_out = out;
grub_terminfo_output_register (out, "vt100");
#ifdef GRUB_MACHINE_MIPS_LOONGSON
if (grub_strcmp (port->name, loongson_defserial[grub_arch_machine]) == 0)
{
grub_term_register_input_active ("serial_*", in);
grub_term_register_output_active ("serial_*", out);
}
else
{
grub_term_register_input_inactive ("serial_*", in);
grub_term_register_output_inactive ("serial_*", out);
}
#else
grub_term_register_input ("serial_*", in);
grub_term_register_output ("serial_*", out);
#endif
return GRUB_ERR_NONE;
}
void
grub_serial_unregister (struct grub_serial_port *port)
{
if (port->driver->fini)
port->driver->fini (port);
if (port->term_in)
grub_term_unregister_input (port->term_in);
if (port->term_out)
grub_term_unregister_output (port->term_out);
grub_list_remove (GRUB_AS_LIST (port));
}
void
grub_serial_unregister_driver (struct grub_serial_driver *driver)
{
struct grub_serial_port *port, *next;
for (port = grub_serial_ports; port; port = next)
{
next = port->next;
if (port->driver == driver)
grub_serial_unregister (port);
}
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(serial)
{
cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0,
N_("[OPTIONS...]"),
N_("Configure serial port."), options);
grub_memcpy (&grub_serial_terminfo_output,
&grub_serial_terminfo_output_template,
sizeof (grub_serial_terminfo_output));
grub_memcpy (&grub_serial_terminfo_input,
&grub_serial_terminfo_input_template,
sizeof (grub_serial_terminfo_input));
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
grub_ns8250_init ();
#endif
#ifdef GRUB_MACHINE_IEEE1275
grub_ofserial_init ();
#endif
#ifdef GRUB_MACHINE_EFI
grub_efiserial_init ();
#endif
#ifdef GRUB_MACHINE_ARC
grub_arcserial_init ();
#endif
}
GRUB_MOD_FINI(serial)
{
while (grub_serial_ports)
grub_serial_unregister (grub_serial_ports);
if (registered)
{
grub_term_unregister_input (&grub_serial_term_input);
grub_term_unregister_output (&grub_serial_term_output);
}
grub_unregister_extcmd (cmd);
}

@ -1427,6 +1427,11 @@ static int ventoy_arch_mode_init(void)
g_ventoy_plat_data = VTOY_PLAT_ARM64_UEFI;
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "aa64");
}
else if (grub_strcmp(GRUB_TARGET_CPU, "mips64el") == 0)
{
g_ventoy_plat_data = VTOY_PLAT_MIPS_UEFI;
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "mips");
}
else
{
g_ventoy_plat_data = VTOY_PLAT_X86_64_UEFI;

@ -56,6 +56,16 @@
#define VTOY_PLAT_ARM64_UEFI 0x41413634
#define VTOY_PLAT_X86_64_UEFI 0x55454649
#define VTOY_PLAT_X86_LEGACY 0x42494f53
#define VTOY_PLAT_MIPS_UEFI 0x4D495053
#define VTOY_COMM_CPIO "ventoy.cpio"
#if defined(__arm__) || defined(__aarch64__)
#define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
#elif defined(__mips__)
#define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
#else
#define VTOY_ARCH_CPIO "ventoy_x86.cpio"
#endif
#define VTOY_PWD_CORRUPTED(err) \
{\

@ -1124,6 +1124,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
grub_uint32_t injection_size = 0;
grub_uint32_t dud_size = 0;
grub_file_t file;
grub_file_t archfile;
grub_file_t tmpfile;
ventoy_img_chunk_list chunk_list;
@ -1142,12 +1143,21 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_COMM_CPIO);
if (!file)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_COMM_CPIO);
}
archfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_ARCH_CPIO);
if (!archfile)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_ARCH_CPIO);
grub_file_close(file);
}
debug("load %s %s success\n", VTOY_COMM_CPIO, VTOY_ARCH_CPIO);
if (g_ventoy_cpio_buf)
{
grub_free(g_ventoy_cpio_buf);
@ -1234,22 +1244,29 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
debug("dud not configed %s\n", args[1]);
}
g_ventoy_cpio_buf = grub_malloc(file->size + 40960 + template_size +
g_ventoy_cpio_buf = grub_malloc(file->size + archfile->size + 40960 + template_size +
persistent_size + injection_size + dud_size + img_chunk_size);
if (NULL == g_ventoy_cpio_buf)
{
grub_file_close(file);
grub_file_close(archfile);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size);
}
grub_file_read(file, g_ventoy_cpio_buf, file->size);
buf = (grub_uint8_t *)(g_ventoy_cpio_buf + file->size - 4);
while (*((grub_uint32_t *)buf) != 0x37303730)
{
buf -= 4;
}
grub_file_read(archfile, buf, archfile->size);
buf += (archfile->size - 4);
while (*((grub_uint32_t *)buf) != 0x37303730)
{
buf -= 4;
}
/* get initrd head len */
initrd_head_len = ventoy_cpio_newc_fill_head(buf, 0, NULL, "initrd000.xx");
@ -1313,6 +1330,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
ventoy_cpio_newc_fill_head(g_ventoy_initrd_head, 0, NULL, "initrd000.xx");
grub_file_close(file);
grub_file_close(archfile);
if (grub_strcmp(args[3], "busybox=64") == 0)
{
@ -1324,6 +1342,11 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "a64");
}
else if (grub_strcmp(args[3], "busybox=m64") == 0)
{
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "m64");
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

@ -0,0 +1,56 @@
/* cache.h - Flush the processor's cache. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2004,2007 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_CACHE_H
#define GRUB_CACHE_H 1
#include <grub/symbol.h>
#include <grub/types.h>
#if defined (__i386__) || defined (__x86_64__)
static inline void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#else
void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
#endif
#ifndef GRUB_MACHINE_EMU
#if defined (__aarch64__) || defined (__ia64__) || defined (__powerpc__) || \
defined (__sparc__)
#elif defined (__i386__) || defined (__x86_64__)
static inline void
grub_arch_sync_dma_caches (volatile void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#elif defined(__mips__) && (_MIPS_SIM != _ABI64)
void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address, grub_size_t len);
#endif
#endif
#ifdef __arm__
void
grub_arm_cache_enable (void);
#endif
#endif /* ! GRUB_CACHE_HEADER */

@ -0,0 +1,309 @@
/* dl.h - types and prototypes for loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_DL_H
#define GRUB_DL_H 1
#include <grub/symbol.h>
#ifndef ASM_FILE
#include <grub/err.h>
#include <grub/types.h>
#include <grub/elf.h>
#include <grub/list.h>
#include <grub/misc.h>
#endif
/*
* Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules
* to collect module names, so we define them only when they are not
* defined already.
*/
#ifndef ASM_FILE
#ifndef GRUB_MOD_INIT
#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
static void \
grub_mod_fini (void)
#elif defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void \
grub_##name##_init (void) { grub_mod_init (0); } \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
void \
grub_##name##_fini (void) { grub_mod_fini (); } \
static void \
grub_mod_fini (void)
#else
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void grub_##name##_init (void); \
void \
grub_##name##_init (void) { grub_mod_init (0); } \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
void grub_##name##_fini (void); \
void \
grub_##name##_fini (void) { grub_mod_fini (); } \
static void \
grub_mod_fini (void)
#endif
#endif
#endif
#ifndef ASM_FILE
#ifdef __APPLE__
#define GRUB_MOD_SECTION(x) "_" #x ", _" #x ""
#else
#define GRUB_MOD_SECTION(x) "." #x
#endif
#else
#ifdef __APPLE__
#define GRUB_MOD_SECTION(x) _ ## x , _ ##x
#else
#define GRUB_MOD_SECTION(x) . ## x
#endif
#endif
/* Me, Vladimir Serbinenko, hereby I add this module check as per new
GNU module policy. Note that this license check is informative only.
Modules have to be licensed under GPLv3 or GPLv3+ (optionally
multi-licensed under other licences as well) independently of the
presence of this check and solely by linking (module loading in GRUB
constitutes linking) and GRUB core being licensed under GPLv3+.
Be sure to understand your license obligations.
*/
#ifndef ASM_FILE
#if GNUC_PREREQ (3,2)
#define ATTRIBUTE_USED __used__
#else
#define ATTRIBUTE_USED __unused__
#endif
#define GRUB_MOD_LICENSE(license) \
static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license;
#define GRUB_MOD_DEP(name) \
static const char grub_module_depend_##name[] \
__attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name
#define GRUB_MOD_NAME(name) \
static const char grub_module_name_##name[] \
__attribute__((section(GRUB_MOD_SECTION(modname)), __used__)) = #name
#else
#ifdef __APPLE__
.macro GRUB_MOD_LICENSE
.section GRUB_MOD_SECTION(module_license)
.ascii "LICENSE="
.ascii $0
.byte 0
.endm
#else
.macro GRUB_MOD_LICENSE license
.section GRUB_MOD_SECTION(module_license), "a"
.ascii "LICENSE="
.ascii "\license"
.byte 0
.endm
#endif
#endif
/* Under GPL license obligations you have to distribute your module
under GPLv3(+). However, you can also distribute the same code under
another license as long as GPLv3(+) version is provided.
*/
#define GRUB_MOD_DUAL_LICENSE(x)
#ifndef ASM_FILE
struct grub_dl_segment
{
struct grub_dl_segment *next;
void *addr;
grub_size_t size;
unsigned section;
};
typedef struct grub_dl_segment *grub_dl_segment_t;
struct grub_dl;
struct grub_dl_dep
{
struct grub_dl_dep *next;
struct grub_dl *mod;
};
typedef struct grub_dl_dep *grub_dl_dep_t;
#ifndef GRUB_UTIL
struct grub_dl
{
char *name;
int ref_count;
int persistent;
grub_dl_dep_t dep;
grub_dl_segment_t segment;
Elf_Sym *symtab;
grub_size_t symsize;
void (*init) (struct grub_dl *mod);
void (*fini) (void);
#if !defined (__i386__) && !defined (__x86_64__)
void *got;
void *gotptr;
void *tramp;
void *trampptr;
#endif
#if defined(__mips__) && (_MIPS_SIM != _ABI64)
grub_uint32_t *reginfo;
#endif
void *base;
grub_size_t sz;
struct grub_dl *next;
};
#endif
typedef struct grub_dl *grub_dl_t;
grub_dl_t grub_dl_load_file (const char *filename);
grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size);
int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
void grub_dl_unload_unneeded (void);
int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
extern grub_dl_t EXPORT_VAR(grub_dl_head);
#ifndef GRUB_UTIL
#define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
#ifdef GRUB_MACHINE_EMU
void *
grub_osdep_dl_memalign (grub_size_t align, grub_size_t size);
void
grub_dl_osdep_dl_free (void *ptr);
#endif
static inline void
grub_dl_init (grub_dl_t mod)
{
if (mod->init)
(mod->init) (mod);
mod->next = grub_dl_head;
grub_dl_head = mod;
}
static inline grub_dl_t
grub_dl_get (const char *name)
{
grub_dl_t l;
FOR_DL_MODULES(l)
if (grub_strcmp (name, l->name) == 0)
return l;
return 0;
}
static inline void
grub_dl_set_persistent (grub_dl_t mod)
{
mod->persistent = 1;
}
static inline int
grub_dl_is_persistent (grub_dl_t mod)
{
return mod->persistent;
}
#endif
grub_err_t grub_dl_register_symbol (const char *name, void *addr,
int isfunc, grub_dl_t mod);
grub_err_t grub_arch_dl_check_header (void *ehdr);
#ifndef GRUB_UTIL
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
Elf_Shdr *s, grub_dl_segment_t seg);
#endif
#if defined (__mips__) && (_MIPS_SIM != _ABI64)
#define GRUB_LINKER_HAVE_INIT 1
void grub_arch_dl_init_linker (void);
#endif
#define GRUB_IA64_DL_TRAMP_ALIGN 16
#define GRUB_IA64_DL_GOT_ALIGN 16
grub_err_t
grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
grub_err_t
grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
#if defined (__ia64__)
#define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN
#define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN
#define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size
#elif defined (__aarch64__)
#define grub_arch_dl_get_tramp_got_size grub_arm64_dl_get_tramp_got_size
#else
grub_err_t
grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got);
#endif
#if defined (__powerpc__) || (defined (__mips__) && (_MIPS_SIM != _ABI64)) || defined (__arm__) || \
(defined(__riscv) && (__riscv_xlen == 32))
#define GRUB_ARCH_DL_TRAMP_ALIGN 4
#define GRUB_ARCH_DL_GOT_ALIGN 4
#endif
#if defined (__aarch64__) || defined (__sparc__) || (defined (__mips__) && (_MIPS_SIM == _ABI64)) || \
(defined(__riscv) && (__riscv_xlen == 64))
#define GRUB_ARCH_DL_TRAMP_ALIGN 8
#define GRUB_ARCH_DL_GOT_ALIGN 8
#endif
#endif
#endif /* ! GRUB_DL_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,339 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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_EFI_PE32_HEADER
#define GRUB_EFI_PE32_HEADER 1
#include <grub/types.h>
#include <grub/efi/memory.h>
/* The MSDOS compatibility stub. This was copied from the output of
objcopy, and it is not necessary to care about what this means. */
#define GRUB_PE32_MSDOS_STUB \
{ \
0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, \
0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, \
0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, \
0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd, \
0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68, \
0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, \
0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, \
0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e, \
0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, \
0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a, \
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \
}
#define GRUB_PE32_MSDOS_STUB_SIZE 0x80
#define GRUB_PE32_MAGIC 0x5a4d
/* According to the spec, the minimal alignment is 512 bytes...
But some examples (such as EFI drivers in the Intel
Sample Implementation) use 32 bytes (0x20) instead, and it seems
to be working.
However, there is firmware showing up in the field now with
page alignment constraints to guarantee that page protection
bits take effect. Because currently existing GRUB code can not
properly distinguish between in-memory and in-file layout, let's
bump all alignment to GRUB_EFI_PAGE_SIZE. */
#define GRUB_PE32_SECTION_ALIGNMENT GRUB_EFI_PAGE_SIZE
#define GRUB_PE32_FILE_ALIGNMENT GRUB_PE32_SECTION_ALIGNMENT
struct grub_pe32_coff_header
{
grub_uint16_t machine;
grub_uint16_t num_sections;
grub_uint32_t time;
grub_uint32_t symtab_offset;
grub_uint32_t num_symbols;
grub_uint16_t optional_header_size;
grub_uint16_t characteristics;
};
#define GRUB_PE32_MACHINE_I386 0x14c
#define GRUB_PE32_MACHINE_MIPS 0x166
#define GRUB_PE32_MACHINE_IA64 0x200
#define GRUB_PE32_MACHINE_X86_64 0x8664
#define GRUB_PE32_MACHINE_ARMTHUMB_MIXED 0x01c2
#define GRUB_PE32_MACHINE_ARM64 0xAA64
#define GRUB_PE32_MACHINE_RISCV32 0x5032
#define GRUB_PE32_MACHINE_RISCV64 0x5064
#define GRUB_PE32_RELOCS_STRIPPED 0x0001
#define GRUB_PE32_EXECUTABLE_IMAGE 0x0002
#define GRUB_PE32_LINE_NUMS_STRIPPED 0x0004
#define GRUB_PE32_LOCAL_SYMS_STRIPPED 0x0008
#define GRUB_PE32_AGGRESSIVE_WS_TRIM 0x0010
#define GRUB_PE32_LARGE_ADDRESS_AWARE 0x0020
#define GRUB_PE32_16BIT_MACHINE 0x0040
#define GRUB_PE32_BYTES_REVERSED_LO 0x0080
#define GRUB_PE32_32BIT_MACHINE 0x0100
#define GRUB_PE32_DEBUG_STRIPPED 0x0200
#define GRUB_PE32_REMOVABLE_RUN_FROM_SWAP 0x0400
#define GRUB_PE32_SYSTEM 0x1000
#define GRUB_PE32_DLL 0x2000
#define GRUB_PE32_UP_SYSTEM_ONLY 0x4000
#define GRUB_PE32_BYTES_REVERSED_HI 0x8000
struct grub_pe32_data_directory
{
grub_uint32_t rva;
grub_uint32_t size;
};
struct grub_pe32_optional_header
{
grub_uint16_t magic;
grub_uint8_t major_linker_version;
grub_uint8_t minor_linker_version;
grub_uint32_t code_size;
grub_uint32_t data_size;
grub_uint32_t bss_size;
grub_uint32_t entry_addr;
grub_uint32_t code_base;
grub_uint32_t data_base;
grub_uint32_t image_base;
grub_uint32_t section_alignment;
grub_uint32_t file_alignment;
grub_uint16_t major_os_version;
grub_uint16_t minor_os_version;
grub_uint16_t major_image_version;
grub_uint16_t minor_image_version;
grub_uint16_t major_subsystem_version;
grub_uint16_t minor_subsystem_version;
grub_uint32_t reserved;
grub_uint32_t image_size;
grub_uint32_t header_size;
grub_uint32_t checksum;
grub_uint16_t subsystem;
grub_uint16_t dll_characteristics;
grub_uint32_t stack_reserve_size;
grub_uint32_t stack_commit_size;
grub_uint32_t heap_reserve_size;
grub_uint32_t heap_commit_size;
grub_uint32_t loader_flags;
grub_uint32_t num_data_directories;
/* Data directories. */
struct grub_pe32_data_directory export_table;
struct grub_pe32_data_directory import_table;
struct grub_pe32_data_directory resource_table;
struct grub_pe32_data_directory exception_table;
struct grub_pe32_data_directory certificate_table;
struct grub_pe32_data_directory base_relocation_table;
struct grub_pe32_data_directory debug;
struct grub_pe32_data_directory architecture;
struct grub_pe32_data_directory global_ptr;
struct grub_pe32_data_directory tls_table;
struct grub_pe32_data_directory load_config_table;
struct grub_pe32_data_directory bound_import;
struct grub_pe32_data_directory iat;
struct grub_pe32_data_directory delay_import_descriptor;
struct grub_pe32_data_directory com_runtime_header;
struct grub_pe32_data_directory reserved_entry;
};
struct grub_pe64_optional_header
{
grub_uint16_t magic;
grub_uint8_t major_linker_version;
grub_uint8_t minor_linker_version;
grub_uint32_t code_size;
grub_uint32_t data_size;
grub_uint32_t bss_size;
grub_uint32_t entry_addr;
grub_uint32_t code_base;
grub_uint64_t image_base;
grub_uint32_t section_alignment;
grub_uint32_t file_alignment;
grub_uint16_t major_os_version;
grub_uint16_t minor_os_version;
grub_uint16_t major_image_version;
grub_uint16_t minor_image_version;
grub_uint16_t major_subsystem_version;
grub_uint16_t minor_subsystem_version;
grub_uint32_t reserved;
grub_uint32_t image_size;
grub_uint32_t header_size;
grub_uint32_t checksum;
grub_uint16_t subsystem;
grub_uint16_t dll_characteristics;
grub_uint64_t stack_reserve_size;
grub_uint64_t stack_commit_size;
grub_uint64_t heap_reserve_size;
grub_uint64_t heap_commit_size;
grub_uint32_t loader_flags;
grub_uint32_t num_data_directories;
/* Data directories. */
struct grub_pe32_data_directory export_table;
struct grub_pe32_data_directory import_table;
struct grub_pe32_data_directory resource_table;
struct grub_pe32_data_directory exception_table;
struct grub_pe32_data_directory certificate_table;
struct grub_pe32_data_directory base_relocation_table;
struct grub_pe32_data_directory debug;
struct grub_pe32_data_directory architecture;
struct grub_pe32_data_directory global_ptr;
struct grub_pe32_data_directory tls_table;
struct grub_pe32_data_directory load_config_table;
struct grub_pe32_data_directory bound_import;
struct grub_pe32_data_directory iat;
struct grub_pe32_data_directory delay_import_descriptor;
struct grub_pe32_data_directory com_runtime_header;
struct grub_pe32_data_directory reserved_entry;
};
#define GRUB_PE32_PE32_MAGIC 0x10b
#define GRUB_PE32_PE64_MAGIC 0x20b
#define GRUB_PE32_SUBSYSTEM_EFI_APPLICATION 10
#define GRUB_PE32_NUM_DATA_DIRECTORIES 16
struct grub_pe32_section_table
{
char name[8];
grub_uint32_t virtual_size;
grub_uint32_t virtual_address;
grub_uint32_t raw_data_size;
grub_uint32_t raw_data_offset;
grub_uint32_t relocations_offset;
grub_uint32_t line_numbers_offset;
grub_uint16_t num_relocations;
grub_uint16_t num_line_numbers;
grub_uint32_t characteristics;
};
#define GRUB_PE32_SCN_CNT_CODE 0x00000020
#define GRUB_PE32_SCN_CNT_INITIALIZED_DATA 0x00000040
#define GRUB_PE32_SCN_MEM_DISCARDABLE 0x02000000
#define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000
#define GRUB_PE32_SCN_MEM_READ 0x40000000
#define GRUB_PE32_SCN_MEM_WRITE 0x80000000
#define GRUB_PE32_SCN_ALIGN_1BYTES 0x00100000
#define GRUB_PE32_SCN_ALIGN_2BYTES 0x00200000
#define GRUB_PE32_SCN_ALIGN_4BYTES 0x00300000
#define GRUB_PE32_SCN_ALIGN_8BYTES 0x00400000
#define GRUB_PE32_SCN_ALIGN_16BYTES 0x00500000
#define GRUB_PE32_SCN_ALIGN_32BYTES 0x00600000
#define GRUB_PE32_SCN_ALIGN_64BYTES 0x00700000
#define GRUB_PE32_SCN_ALIGN_SHIFT 20
#define GRUB_PE32_SCN_ALIGN_MASK 7
#define GRUB_PE32_SIGNATURE_SIZE 4
struct grub_pe32_header
{
/* This should be filled in with GRUB_PE32_MSDOS_STUB. */
grub_uint8_t msdos_stub[GRUB_PE32_MSDOS_STUB_SIZE];
/* This is always PE\0\0. */
char signature[GRUB_PE32_SIGNATURE_SIZE];
/* The COFF file header. */
struct grub_pe32_coff_header coff_header;
#if GRUB_TARGET_SIZEOF_VOID_P == 8
/* The Optional header. */
struct grub_pe64_optional_header optional_header;
#else
/* The Optional header. */
struct grub_pe32_optional_header optional_header;
#endif
};
struct grub_pe32_fixup_block
{
grub_uint32_t page_rva;
grub_uint32_t block_size;
grub_uint16_t entries[0];
};
#define GRUB_PE32_FIXUP_ENTRY(type, offset) (((type) << 12) | (offset))
#define GRUB_PE32_REL_BASED_ABSOLUTE 0
#define GRUB_PE32_REL_BASED_HIGH 1
#define GRUB_PE32_REL_BASED_LOW 2
#define GRUB_PE32_REL_BASED_HIGHLOW 3
#define GRUB_PE32_REL_BASED_HIGHADJ 4
#define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5
#define GRUB_PE32_REL_BASED_MIPS_LOW 6
#define GRUB_PE32_REL_BASED_MIPS_HIGH 4
#define GRUB_PE32_REL_BASED_MIPS_HIGHER 7
#define GRUB_PE32_REL_BASED_MIPS_HIGHEST 8
#define GRUB_PE32_REL_BASED_ARM_MOV32A 5
#define GRUB_PE32_REL_BASED_RISCV_HI20 5
#define GRUB_PE32_REL_BASED_SECTION 6
#define GRUB_PE32_REL_BASED_REL 7
#define GRUB_PE32_REL_BASED_ARM_MOV32T 7
#define GRUB_PE32_REL_BASED_RISCV_LOW12I 7
#define GRUB_PE32_REL_BASED_RISCV_LOW12S 8
#define GRUB_PE32_REL_BASED_IA64_IMM64 9
#define GRUB_PE32_REL_BASED_DIR64 10
#define GRUB_PE32_REL_BASED_HIGH3ADJ 11
struct grub_pe32_symbol
{
union
{
char short_name[8];
grub_uint32_t long_name[2];
};
grub_uint32_t value;
grub_uint16_t section;
grub_uint16_t type;
grub_uint8_t storage_class;
grub_uint8_t num_aux;
} GRUB_PACKED;
#define GRUB_PE32_SYM_CLASS_EXTERNAL 2
#define GRUB_PE32_SYM_CLASS_STATIC 3
#define GRUB_PE32_SYM_CLASS_FILE 0x67
#define GRUB_PE32_DT_FUNCTION 0x20
struct grub_pe32_reloc
{
grub_uint32_t offset;
grub_uint32_t symtab_index;
grub_uint16_t type;
} GRUB_PACKED;
#define GRUB_PE32_REL_I386_DIR32 0x6
#define GRUB_PE32_REL_I386_REL32 0x14
#endif /* ! GRUB_EFI_PE32_HEADER */

@ -0,0 +1,10 @@
#ifndef GRUB_MIPS64_ASM_HEADER
#define GRUB_MIPS64_ASM_HEADER 1
#define GRUB_ASM_T4 $a4
#define GRUB_ASM_T5 $a5
#define GRUB_ASM_SZREG 8
#define GRUB_ASM_REG_S sd
#define GRUB_ASM_REG_L ld
#endif

@ -0,0 +1,25 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2006,2007,2017 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_LOADER_MACHINE_HEADER
#define GRUB_LOADER_MACHINE_HEADER 1
#include <grub/types.h>
#include <grub/symbol.h>
#endif /* ! GRUB_LOADER_MACHINE_HEADER */

@ -0,0 +1,303 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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_EFI_LOONGSON_HEADER
#define GRUB_EFI_LOONGSON_HEADER 1
#include <grub/types.h>
#include <grub/efi/api.h>
#define GRUB_EFI_LOONGSON_SMBIOS_TABLE_GUID \
{ 0x4660f721, 0x2ec5, 0x416a, \
{ 0x89, 0x9a, 0x43, 0x18, 0x02, 0x50, 0xa0, 0xc9 } \
}
#define GRUB_EFI_LOONGSON_MMAP_MAX 128
typedef enum
{
GRUB_EFI_LOONGSON_SYSTEM_RAM_LOW = 1,
GRUB_EFI_LOONGSON_SYSTEM_RAM_HIGH,
GRUB_EFI_LOONGSON_MEMORY_RESERVED,
GRUB_EFI_LOONGSON_PCI_IO,
GRUB_EFI_LOONGSON_PCI_MEM,
GRUB_EFI_LOONGSON_CFG_REG,
GRUB_EFI_LOONGSON_VIDEO_ROM,
GRUB_EFI_LOONGSON_ADAPTER_ROM,
GRUB_EFI_LOONGSON_ACPI_TABLE,
GRUB_EFI_LOONGSON_SMBIOS_TABLE,
GRUB_EFI_LOONGSON_UMA_VIDEO_RAM,
GRUB_EFI_LOONGSON_VUMA_VIDEO_RAM,
GRUB_EFI_LOONGSON_SYSTEM_RAM_LOW_DMA,
GRUB_EFI_LOONGSON_SYSTEM_RAM_HIGH_DMA,
GRUB_EFI_LOONGSON_ACPI_NVS,
GRUB_EFI_LOONGSON_MAX_MEMORY_TYPE
}
grub_efi_loongson_memory_type;
typedef struct
{
grub_uint16_t vers; /* version */
grub_uint32_t nr_map; /* number of memory_maps */
grub_uint32_t mem_freq; /* memory frequence */
struct mem_map {
grub_uint32_t node_id; /* node_id which memory attached to */
grub_uint32_t mem_type; /* system memory, pci memory, pci io, etc. */
grub_uint64_t mem_start; /* memory map start address */
grub_uint32_t mem_size; /* each memory_map size, not the total size */
} map[GRUB_EFI_LOONGSON_MMAP_MAX];
} GRUB_PACKED
grub_efi_loongson_memory_map;
/*
* Capability and feature descriptor structure for MIPS CPU
*/
typedef struct
{
grub_uint16_t vers; /* version */
grub_uint32_t processor_id; /* PRID, e.g. 6305, 6306 */
grub_uint32_t cputype; /* Loongson_3A/3B, etc. */
grub_uint32_t total_node; /* num of total numa nodes */
grub_uint16_t cpu_startup_core_id; /* Boot core id */
grub_uint16_t reserved_cores_mask;
grub_uint32_t cpu_clock_freq; /* cpu_clock */
grub_uint32_t nr_cpus;
} GRUB_PACKED
grub_efi_loongson_cpu_info;
#define GRUB_EFI_LOONGSON_MAX_UARTS 64
typedef struct
{
grub_uint32_t iotype; /* see include/linux/serial_core.h */
grub_uint32_t uartclk;
grub_uint32_t int_offset;
grub_uint64_t uart_base;
} GRUB_PACKED
grub_efi_loongson_uart_device;
#define GRUB_EFI_LOONGSON_MAX_SENSORS 64
typedef struct
{
char name[32]; /* a formal name */
char label[64]; /* a flexible description */
grub_uint32_t type; /* SENSOR_* */
grub_uint32_t id; /* instance id of a sensor-class */
grub_uint32_t fan_policy;
grub_uint32_t fan_percent; /* only for constant speed policy */
grub_uint64_t base_addr; /* base address of device registers */
} GRUB_PACKED
grub_efi_loongson_sensor_device;
typedef struct
{
grub_uint16_t vers; /* version */
grub_uint32_t ccnuma_smp; /* 0: no numa; 1: has numa */
grub_uint32_t sing_double_channel; /* 1:single; 2:double */
grub_uint32_t nr_uarts;
grub_efi_loongson_uart_device uarts[GRUB_EFI_LOONGSON_MAX_UARTS];
grub_uint32_t nr_sensors;
grub_efi_loongson_sensor_device sensors[GRUB_EFI_LOONGSON_MAX_SENSORS];
char has_ec;
char ec_name[32];
grub_uint64_t ec_base_addr;
char has_tcm;
char tcm_name[32];
grub_uint64_t tcm_base_addr;
grub_uint64_t workarounds; /* see workarounds.h */
} GRUB_PACKED
grub_efi_loongson_system_info;
typedef struct
{
grub_uint16_t vers;
grub_uint16_t size;
grub_uint16_t rtr_bus;
grub_uint16_t rtr_devfn;
grub_uint32_t vendor;
grub_uint32_t device;
grub_uint32_t PIC_type; /* conform use HT or PCI to route to CPU-PIC */
grub_uint64_t ht_int_bit; /* 3A: 1<<24; 3B: 1<<16 */
grub_uint64_t ht_enable; /* irqs used in this PIC */
grub_uint32_t node_id; /* node id: 0x0-0; 0x1-1; 0x10-2; 0x11-3 */
grub_uint64_t pci_mem_start_addr;
grub_uint64_t pci_mem_end_addr;
grub_uint64_t pci_io_start_addr;
grub_uint64_t pci_io_end_addr;
grub_uint64_t pci_config_addr;
grub_uint32_t dma_mask_bits;
} GRUB_PACKED
grub_efi_loongson_irq_src_routing_table;
typedef struct
{
grub_uint16_t vers; /* version */
grub_uint16_t size;
grub_uint8_t flag;
char description[64];
} GRUB_PACKED
grub_efi_loongson_interface_info;
#define GRUB_EFI_LOONGSON_MAX_RESOURCE_NUMBER 128
typedef struct
{
grub_uint64_t start; /* resource start address */
grub_uint64_t end; /* resource end address */
char name[64];
grub_uint32_t flags;
}
grub_efi_loongson_resource;
/* arch specific additions */
typedef struct
{
}
grub_efi_loongson_archdev_data;
typedef struct
{
char name[64]; /* hold the device name */
grub_uint32_t num_resources; /* number of device_resource */
/* for each device's resource */
grub_efi_loongson_resource resource[GRUB_EFI_LOONGSON_MAX_RESOURCE_NUMBER];
/* arch specific additions */
grub_efi_loongson_archdev_data archdata;
}
grub_efi_loongson_board_devices;
typedef struct
{
grub_uint16_t vers; /* version */
char special_name[64]; /* special_atribute_name */
grub_uint32_t loongson_special_type; /* type of special device */
/* for each device's resource */
grub_efi_loongson_resource resource[GRUB_EFI_LOONGSON_MAX_RESOURCE_NUMBER];
}
grub_efi_loongson_special_attribute;
typedef struct
{
grub_uint64_t memory_offset; /* efi_loongson_memory_map struct offset */
grub_uint64_t cpu_offset; /* efi_loongson_cpuinfo struct offset */
grub_uint64_t system_offset; /* efi_loongson_system_info struct offset */
grub_uint64_t irq_offset; /* efi_loongson_irq_src_routing_table struct offset */
grub_uint64_t interface_offset; /* interface_info struct offset */
grub_uint64_t special_offset; /* efi_loongson_special_attribute struct offset */
grub_uint64_t boarddev_table_offset; /* efi_loongson_board_devices offset */
}
grub_efi_loongson_params;
typedef struct
{
grub_uint16_t vers; /* version */
grub_uint64_t vga_bios; /* vga_bios address */
grub_efi_loongson_params lp;
}
grub_efi_loongson_smbios_table;
typedef struct
{
grub_uint64_t reset_cold;
grub_uint64_t reset_warm;
grub_uint64_t reset_type;
grub_uint64_t shutdown;
grub_uint64_t do_suspend; /* NULL if not support */
}
grub_efi_loongson_reset_system;
typedef struct
{
grub_uint64_t mps; /* MPS table */
grub_uint64_t acpi; /* ACPI table (IA64 ext 0.71) */
grub_uint64_t acpi20; /* ACPI table (ACPI 2.0) */
grub_efi_loongson_smbios_table smbios; /* SM BIOS table */
grub_uint64_t sal_systab; /* SAL system table */
grub_uint64_t boot_info; /* boot info table */
}
grub_efi_loongson;
typedef struct
{
grub_efi_loongson efi;
grub_efi_loongson_reset_system reset_system;
}
grub_efi_loongson_boot_params;
extern grub_uint64_t grub_efi_loongson_reset_system_addr;
extern void grub_efi_loongson_reset_cold (void);
extern void grub_efi_loongson_reset_warm (void);
extern void grub_efi_loongson_reset_shutdown (void);
extern void grub_efi_loongson_reset_suspend (void);
void grub_efi_loongson_init (void);
void grub_efi_loongson_fini (void);
void grub_efi_loongson_alloc_boot_params (void);
void grub_efi_loongson_free_boot_params (void);
void * grub_efi_loongson_get_smbios_table (void);
int EXPORT_FUNC(grub_efi_is_loongson) (void);
grub_uint8_t
EXPORT_FUNC(grub_efi_loongson_calculatesum8) (const grub_uint8_t *Buffer, grub_efi_uintn_t Length);
grub_uint8_t
EXPORT_FUNC(grub_efi_loongson_grub_calculatechecksum8) (const grub_uint8_t *Buffer, grub_efi_uintn_t Length);
void *
EXPORT_FUNC(grub_efi_loongson_get_boot_params) (void);
typedef struct _extention_list_hdr{
grub_uint64_t signature;
grub_uint32_t length;
grub_uint8_t revision;
grub_uint8_t checksum;
struct _extention_list_hdr *next;
}GRUB_PACKED
ext_list;
typedef struct bootparamsinterface {
grub_uint64_t signature; //{'B', 'P', 'I', '_', '0', '_', '1'}
grub_efi_system_table_t *systemtable;
ext_list *extlist;
}GRUB_PACKED
bootparamsinterface;
typedef struct {
ext_list header; // {'M', 'E', 'M'}
grub_uint8_t mapcount;
struct GRUB_PACKED memmap {
grub_uint32_t memtype;
grub_uint64_t memstart;
grub_uint64_t memsize;
} map[GRUB_EFI_LOONGSON_MMAP_MAX];
}GRUB_PACKED
mem_map;
typedef struct {
ext_list header; // {VBIOS}
grub_uint64_t vbiosaddr;
}GRUB_PACKED
vbios;
grub_uint32_t
EXPORT_FUNC (grub_efi_loongson_memmap_sort) (struct memmap array[], grub_uint32_t length, mem_map * bpmem, grub_uint32_t index, grub_uint32_t memtype);
#endif /* ! GRUB_EFI_LOONGSON_HEADER */

@ -0,0 +1,7 @@
#ifndef GRUB_MEMORY_CPU_HEADER
#include <grub/efi/memory.h>
//#define GRUB_EFI_MAX_USABLE_ADDRESS 0x980000000fffffffUL
#define GRUB_EFI_MAX_USABLE_ADDRESS 0x98000000ffffffffUL
#endif /* ! GRUB_MEMORY_CPU_HEADER */

@ -0,0 +1,62 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009,2017 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_IO_H
#define GRUB_IO_H 1
#include <grub/types.h>
typedef grub_addr_t grub_port_t;
static __inline unsigned char
grub_inb (grub_port_t port)
{
return *(volatile grub_uint8_t *) port;
}
static __inline unsigned short int
grub_inw (grub_port_t port)
{
return *(volatile grub_uint16_t *) port;
}
static __inline unsigned int
grub_inl (grub_port_t port)
{
return *(volatile grub_uint32_t *) port;
}
static __inline void
grub_outb (unsigned char value, grub_port_t port)
{
*(volatile grub_uint8_t *) port = value;
}
static __inline void
grub_outw (unsigned short int value, grub_port_t port)
{
*(volatile grub_uint16_t *) port = value;
}
static __inline void
grub_outl (unsigned int value, grub_port_t port)
{
*(volatile grub_uint32_t *) port = value;
}
#endif /* _SYS_IO_H */

@ -0,0 +1,24 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,2007,2008,2009,2017 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_CPU_HEADER
#define GRUB_KERNEL_CPU_HEADER 1
#include <grub/symbol.h>
#endif /* ! GRUB_KERNEL_MACHINE_HEADER */

@ -0,0 +1,57 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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_MEMORY_CPU_HEADER
#define GRUB_MEMORY_CPU_HEADER 1
#ifndef ASM_FILE
#include <grub/symbol.h>
#include <grub/err.h>
#include <grub/types.h>
#endif
#ifndef ASM_FILE
typedef grub_addr_t grub_phys_addr_t;
static inline grub_phys_addr_t
grub_vtop (void *a)
{
if (-1 == ((grub_int64_t) a >> 32))
return ((grub_phys_addr_t) a) & 0x1fffffffUL;
return ((grub_phys_addr_t) a) & 0xffffffffffffUL;
}
static inline void *
grub_map_memory (grub_phys_addr_t a, grub_size_t size)
{
if ((a + size) < 0x20000000UL)
return (void *) (a | 0xffffffff80000000UL);
// return (void *) (a | 0x9800000000000000UL);
return (void *) ((a&0x8fffffff) | 0xffffffff00000000UL);
}
static inline void
grub_unmap_memory (void *a __attribute__ ((unused)),
grub_size_t size __attribute__ ((unused)))
{
}
#endif
#endif

@ -0,0 +1,30 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010,2017 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_REGISTERS_CPU_HEADER
#define GRUB_REGISTERS_CPU_HEADER 1
#ifdef ASM_FILE
#define GRUB_CPU_REGISTER_WRAP(x) x
#else
#define GRUB_CPU_REGISTER_WRAP(x) #x
#endif
#define GRUB_CPU_MIPS_COP0_TIMER_COUNT GRUB_CPU_REGISTER_WRAP($9)
#endif

@ -0,0 +1,38 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2017 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_RELOCATOR_CPU_HEADER
#define GRUB_RELOCATOR_CPU_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
#include <grub/relocator.h>
struct grub_relocator64_state
{
/* gpr[0] is ignored since it's hardwired to 0. */
grub_uint64_t gpr[32];
/* Register holding target $pc. */
int jumpreg;
};
grub_err_t
grub_relocator64_boot (struct grub_relocator *rel,
struct grub_relocator64_state state);
#endif /* ! GRUB_RELOCATOR_CPU_HEADER */

@ -0,0 +1,27 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2006,2007,2009,2017 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_SETJMP_CPU_HEADER
#define GRUB_SETJMP_CPU_HEADER 1
typedef grub_uint64_t grub_jmp_buf[12];
int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
#endif /* ! GRUB_SETJMP_CPU_HEADER */

@ -0,0 +1,39 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2007,2017 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 KERNEL_CPU_TIME_HEADER
#define KERNEL_CPU_TIME_HEADER 1
#ifndef GRUB_UTIL
#define GRUB_TICKS_PER_SECOND (grub_arch_cpuclock / 2)
void grub_timer_init (grub_uint32_t cpuclock);
/* Return the real time in ticks. */
grub_uint64_t grub_get_rtc (void);
extern grub_uint32_t grub_arch_cpuclock;
#endif
static inline void
grub_cpu_idle(void)
{
}
#endif

@ -0,0 +1,38 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2006,2007,2009,2017 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_TYPES_CPU_HEADER
#define GRUB_TYPES_CPU_HEADER 1
/* The size of void *. */
#define GRUB_TARGET_SIZEOF_VOID_P 8
/* The size of long. */
#define GRUB_TARGET_SIZEOF_LONG 8
#ifdef GRUB_CPU_MIPS64EL
/* mips64EL is little-endian. */
#undef GRUB_TARGET_WORDS_BIGENDIAN
#elif defined (GRUB_CPU_MIPS64)
/* mips64 is big-endian. */
#define GRUB_TARGET_WORDS_BIGENDIAN
#elif !defined (GRUB_SYMBOL_GENERATOR)
#error Neither GRUB_CPU_MIPS64 nor GRUB_CPU_MIPS64EL is defined
#endif
#endif /* ! GRUB_TYPES_CPU_HEADER */

@ -0,0 +1,466 @@
/* misc.h - prototypes for misc functions */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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_MISC_HEADER
#define GRUB_MISC_HEADER 1
#include <stdarg.h>
#include <grub/types.h>
#include <grub/symbol.h>
#include <grub/err.h>
#include <grub/i18n.h>
#include <grub/compiler.h>
#define ALIGN_UP(addr, align) \
((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1))
#define ALIGN_DOWN(addr, align) \
((addr) & ~((typeof (addr)) align - 1))
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
#define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; }
#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__)
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
static inline char *
grub_strncpy (char *dest, const char *src, int c)
{
char *p = dest;
while ((*p++ = *src++) != '\0' && --c)
;
return dest;
}
static inline char *
grub_stpcpy (char *dest, const char *src)
{
char *d = dest;
const char *s = src;
do
*d++ = *s;
while (*s++ != '\0');
return d - 1;
}
/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
static inline void *
grub_memcpy (void *dest, const void *src, grub_size_t n)
{
return grub_memmove (dest, src, n);
}
#if defined(__x86_64__) && !defined (GRUB_UTIL)
#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (__MINGW64__)
#define GRUB_ASM_ATTR __attribute__ ((sysv_abi))
#else
#define GRUB_ASM_ATTR
#endif
#endif
int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n);
char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
/* Copied from gnulib.
Written by Bruno Haible <bruno@clisp.org>, 2005. */
static inline char *
grub_strstr (const char *haystack, const char *needle)
{
/* Be careful not to look at the entire extent of haystack or needle
until needed. This is useful because of these two cases:
- haystack may be very long, and a match of needle found early,
- needle may be very long, and not even a short initial segment of
needle may be found in haystack. */
if (*needle != '\0')
{
/* Speed up the following searches of needle by caching its first
character. */
char b = *needle++;
for (;; haystack++)
{
if (*haystack == '\0')
/* No match. */
return 0;
if (*haystack == b)
/* The first character matches. */
{
const char *rhaystack = haystack + 1;
const char *rneedle = needle;
for (;; rhaystack++, rneedle++)
{
if (*rneedle == '\0')
/* Found a match. */
return (char *) haystack;
if (*rhaystack == '\0')
/* No match. */
return 0;
if (*rhaystack != *rneedle)
/* Nothing in this round. */
break;
}
}
}
}
else
return (char *) haystack;
}
int EXPORT_FUNC(grub_isspace) (int c);
static inline int
grub_isprint (int c)
{
return (c >= ' ' && c <= '~');
}
static inline int
grub_iscntrl (int c)
{
return (c >= 0x00 && c <= 0x1F) || c == 0x7F;
}
static inline int
grub_isalpha (int c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
static inline int
grub_islower (int c)
{
return (c >= 'a' && c <= 'z');
}
static inline int
grub_isupper (int c)
{
return (c >= 'A' && c <= 'Z');
}
static inline int
grub_isgraph (int c)
{
return (c >= '!' && c <= '~');
}
static inline int
grub_isdigit (int c)
{
return (c >= '0' && c <= '9');
}
static inline int
grub_isxdigit (int c)
{
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
static inline int
grub_isalnum (int c)
{
return grub_isalpha (c) || grub_isdigit (c);
}
static inline int
grub_tolower (int c)
{
if (c >= 'A' && c <= 'Z')
return c - 'A' + 'a';
return c;
}
static inline int
grub_toupper (int c)
{
if (c >= 'a' && c <= 'z')
return c - 'a' + 'A';
return c;
}
static inline int
grub_strcasecmp (const char *s1, const char *s2)
{
while (*s1 && *s2)
{
if (grub_tolower ((grub_uint8_t) *s1)
!= grub_tolower ((grub_uint8_t) *s2))
break;
s1++;
s2++;
}
return (int) grub_tolower ((grub_uint8_t) *s1)
- (int) grub_tolower ((grub_uint8_t) *s2);
}
static inline int
grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
{
if (n == 0)
return 0;
while (*s1 && *s2 && --n)
{
if (grub_tolower (*s1) != grub_tolower (*s2))
break;
s1++;
s2++;
}
return (int) grub_tolower ((grub_uint8_t) *s1)
- (int) grub_tolower ((grub_uint8_t) *s2);
}
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
static inline long
grub_strtol (const char *str, char **end, int base)
{
int negative = 0;
unsigned long long magnitude;
while (*str && grub_isspace (*str))
str++;
if (*str == '-')
{
negative = 1;
str++;
}
magnitude = grub_strtoull (str, end, base);
if (negative)
{
if (magnitude > (unsigned long) GRUB_LONG_MAX + 1)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
return GRUB_LONG_MIN;
}
return -((long) magnitude);
}
else
{
if (magnitude > GRUB_LONG_MAX)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
return GRUB_LONG_MAX;
}
return (long) magnitude;
}
}
char *EXPORT_FUNC(grub_strdup) (const char *s) WARN_UNUSED_RESULT;
char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n) WARN_UNUSED_RESULT;
void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s) WARN_UNUSED_RESULT;
int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
/* Replace all `ch' characters of `input' with `with' and copy the
result into `output'; return EOS address of `output'. */
static inline char *
grub_strchrsub (char *output, const char *input, char ch, const char *with)
{
while (*input)
{
if (*input == ch)
{
grub_strcpy (output, with);
output += grub_strlen (with);
input++;
continue;
}
*output++ = *input++;
}
*output = '\0';
return output;
}
extern void (*EXPORT_VAR (grub_xputs)) (const char *str);
static inline int
grub_puts (const char *s)
{
const char nl[2] = "\n";
grub_xputs (s);
grub_xputs (nl);
return 1; /* Cannot fail. */
}
int EXPORT_FUNC(grub_puts_) (const char *s);
void EXPORT_FUNC(grub_real_dprintf) (const char *file,
const int line,
const char *condition,
const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5)));
int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...)
__attribute__ ((format (GNU_PRINTF, 3, 4)));
int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
va_list args);
char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
__attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
grub_uint64_t d,
grub_uint64_t *r);
/* Must match softdiv group in gentpl.py. */
#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \
(defined(__riscv) && (__riscv_xlen == 32)))
#define GRUB_DIVISION_IN_SOFTWARE 1
#else
#define GRUB_DIVISION_IN_SOFTWARE 0
#endif
/* Some division functions need to be in kernel if compiler generates calls
to them. Otherwise we still need them for consistent tests but they go
into a separate module. */
#if GRUB_DIVISION_IN_SOFTWARE
#define EXPORT_FUNC_IF_SOFTDIV EXPORT_FUNC
#else
#define EXPORT_FUNC_IF_SOFTDIV(x) x
#endif
grub_int64_t
EXPORT_FUNC_IF_SOFTDIV(grub_divmod64s) (grub_int64_t n,
grub_int64_t d,
grub_int64_t *r);
grub_uint32_t
EXPORT_FUNC_IF_SOFTDIV (grub_divmod32) (grub_uint32_t n,
grub_uint32_t d,
grub_uint32_t *r);
grub_int32_t
EXPORT_FUNC_IF_SOFTDIV (grub_divmod32s) (grub_int32_t n,
grub_int32_t d,
grub_int32_t *r);
/* Inline functions. */
static inline char *
grub_memchr (const void *p, int c, grub_size_t len)
{
const char *s = (const char *) p;
const char *e = s + len;
for (; s < e; s++)
if (*s == c)
return (char *) s;
return 0;
}
static inline unsigned int
grub_abs (int x)
{
if (x < 0)
return (unsigned int) (-x);
else
return (unsigned int) x;
}
/* Reboot the machine. */
#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) || \
defined (GRUB_MACHINE_EFI)
void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn));
#else
void grub_reboot (void) __attribute__ ((noreturn));
#endif
#if defined (__clang__) && !defined (GRUB_UTIL)
void __attribute__ ((noreturn)) EXPORT_FUNC (abort) (void);
#endif
#ifdef GRUB_MACHINE_PCBIOS
/* Halt the system, using APM if possible. If NO_APM is true, don't
* use APM even if it is available. */
void grub_halt (int no_apm) __attribute__ ((noreturn));
#elif (defined (__mips__) && (_MIPS_SIM != _ABI64)) && !defined (GRUB_MACHINE_EMU)
void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn));
#else
void grub_halt (void) __attribute__ ((noreturn));
#endif
#ifdef GRUB_MACHINE_EMU
/* Flag to check if module loading is available. */
extern const int EXPORT_VAR(grub_no_modules);
#else
#define grub_no_modules 0
#endif
static inline void
grub_error_save (struct grub_error_saved *save)
{
grub_memcpy (save->errmsg, grub_errmsg, sizeof (save->errmsg));
save->grub_errno = grub_errno;
grub_errno = GRUB_ERR_NONE;
}
static inline void
grub_error_load (const struct grub_error_saved *save)
{
grub_memcpy (grub_errmsg, save->errmsg, sizeof (grub_errmsg));
grub_errno = save->grub_errno;
}
#if BOOT_TIME_STATS
struct grub_boot_time
{
struct grub_boot_time *next;
grub_uint64_t tp;
const char *file;
int line;
char *msg;
};
extern struct grub_boot_time *EXPORT_VAR(grub_boot_time_head);
void EXPORT_FUNC(grub_real_boot_time) (const char *file,
const int line,
const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 3, 4)));
#define grub_boot_time(...) grub_real_boot_time(GRUB_FILE, __LINE__, __VA_ARGS__)
#else
#define grub_boot_time(...)
#endif
#define grub_max(a, b) (((a) > (b)) ? (a) : (b))
#define grub_min(a, b) (((a) < (b)) ? (a) : (b))
#endif /* ! GRUB_MISC_HEADER */

@ -0,0 +1,205 @@
/* serial.h - serial device interface */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_SERIAL_HEADER
#define GRUB_SERIAL_HEADER 1
#include <grub/types.h>
#if (defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)
#include <grub/cpu/io.h>
#endif
#include <grub/usb.h>
#include <grub/list.h>
#include <grub/term.h>
#ifdef GRUB_MACHINE_IEEE1275
#include <grub/ieee1275/ieee1275.h>
#endif
#ifdef GRUB_MACHINE_ARC
#include <grub/arc/arc.h>
#endif
struct grub_serial_port;
struct grub_serial_config;
struct grub_serial_driver
{
grub_err_t (*configure) (struct grub_serial_port *port,
struct grub_serial_config *config);
int (*fetch) (struct grub_serial_port *port);
void (*put) (struct grub_serial_port *port, const int c);
void (*fini) (struct grub_serial_port *port);
};
/* The type of parity. */
typedef enum
{
GRUB_SERIAL_PARITY_NONE,
GRUB_SERIAL_PARITY_ODD,
GRUB_SERIAL_PARITY_EVEN,
} grub_serial_parity_t;
typedef enum
{
GRUB_SERIAL_STOP_BITS_1,
GRUB_SERIAL_STOP_BITS_1_5,
GRUB_SERIAL_STOP_BITS_2,
} grub_serial_stop_bits_t;
struct grub_serial_config
{
unsigned speed;
int word_len;
grub_serial_parity_t parity;
grub_serial_stop_bits_t stop_bits;
grub_uint64_t base_clock;
int rtscts;
};
struct grub_serial_port
{
struct grub_serial_port *next;
struct grub_serial_port **prev;
char *name;
struct grub_serial_driver *driver;
struct grub_serial_config config;
int configured;
int broken;
/* This should be void *data but since serial is useful as an early console
when malloc isn't available it's a union.
*/
union
{
#if (defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)
grub_port_t port;
#endif
struct
{
grub_usb_device_t usbdev;
int configno;
int interfno;
char buf[64];
int bufstart, bufend;
struct grub_usb_desc_endp *in_endp;
struct grub_usb_desc_endp *out_endp;
};
struct grub_escc_descriptor *escc_desc;
#ifdef GRUB_MACHINE_IEEE1275
struct
{
grub_ieee1275_ihandle_t handle;
struct ofserial_hash_ent *elem;
};
#endif
#ifdef GRUB_MACHINE_EFI
struct grub_efi_serial_io_interface *interface;
#endif
#ifdef GRUB_MACHINE_ARC
struct
{
grub_arc_fileno_t handle;
int handle_valid;
};
#endif
};
grub_term_output_t term_out;
grub_term_input_t term_in;
};
grub_err_t EXPORT_FUNC(grub_serial_register) (struct grub_serial_port *port);
void EXPORT_FUNC(grub_serial_unregister) (struct grub_serial_port *port);
/* Convenience functions to perform primitive operations on a port. */
static inline grub_err_t
grub_serial_port_configure (struct grub_serial_port *port,
struct grub_serial_config *config)
{
return port->driver->configure (port, config);
}
static inline int
grub_serial_port_fetch (struct grub_serial_port *port)
{
return port->driver->fetch (port);
}
static inline void
grub_serial_port_put (struct grub_serial_port *port, const int c)
{
port->driver->put (port, c);
}
static inline void
grub_serial_port_fini (struct grub_serial_port *port)
{
port->driver->fini (port);
}
/* Set default settings. */
static inline grub_err_t
grub_serial_config_defaults (struct grub_serial_port *port)
{
struct grub_serial_config config =
{
#ifdef GRUB_MACHINE_MIPS_LOONGSON
.speed = 115200,
/* On Loongson machines serial port has only 3 wires. */
.rtscts = 0,
#else
.speed = 9600,
.rtscts = 1,
#endif
.word_len = 8,
.parity = GRUB_SERIAL_PARITY_NONE,
.stop_bits = GRUB_SERIAL_STOP_BITS_1,
.base_clock = 0
};
return port->driver->configure (port, &config);
}
#if (defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)
void grub_ns8250_init (void);
char *grub_serial_ns8250_add_port (grub_port_t port);
#endif
#ifdef GRUB_MACHINE_IEEE1275
void grub_ofserial_init (void);
#endif
#ifdef GRUB_MACHINE_EFI
void
grub_efiserial_init (void);
#endif
#ifdef GRUB_MACHINE_ARC
void
grub_arcserial_init (void);
const char *
grub_arcserial_add_port (const char *path);
#endif
struct grub_serial_port *grub_serial_find (const char *name);
extern struct grub_serial_driver grub_ns8250_driver;
void EXPORT_FUNC(grub_serial_unregister_driver) (struct grub_serial_driver *driver);
#ifndef GRUB_MACHINE_EMU
extern void grub_serial_init (void);
extern void grub_serial_fini (void);
#endif
#endif

@ -0,0 +1,269 @@
/*
* 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_UTIL_INSTALL_HEADER
#define GRUB_UTIL_INSTALL_HEADER 1
#include <sys/types.h>
#include <stdio.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/emu/hostfile.h>
#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 }, \
{ "themes", GRUB_INSTALL_OPTIONS_INSTALL_THEMES, N_("THEMES"), \
0, N_("install THEMES [default=%s]"), 1 }, \
{ "fonts", GRUB_INSTALL_OPTIONS_INSTALL_FONTS, N_("FONTS"), \
0, N_("install FONTS [default=%s]"), 1 }, \
{ "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\
0, N_("install only LOCALES [default=all]"), 1 }, \
{ "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \
"no|xz|gz|lzo", 0, \
N_("compress GRUB files [optional]"), 1 }, \
{"core-compress", GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, \
"xz|none|auto", \
0, N_("choose the compression to use for core image"), 2}, \
/* TRANSLATORS: platform here isn't identifier. It can be translated. */ \
{ "directory", 'd', N_("DIR"), 0, \
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
{ "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
N_("DIR"), OPTION_HIDDEN, \
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
{ "locale-directory", GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY, \
N_("DIR"), 0, \
N_("use translations under DIR [default=%s]"), 1 }, \
{ "themes-directory", GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY, \
N_("DIR"), OPTION_HIDDEN, \
N_("use themes under DIR [default=%s]"), 1 }, \
{ "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
"FILE", OPTION_HIDDEN, 0, 1 }, \
/* TRANSLATORS: "embed" is a verb (command description). "*/ \
{ "pubkey", 'k', N_("FILE"), 0, \
N_("embed FILE as public key for signature checking"), 0}, \
{ "verbose", 'v', 0, 0, \
N_("print verbose messages."), 1 }
int
grub_install_parse (int key, char *arg);
void
grub_install_push_module (const char *val);
void
grub_install_pop_module (void);
char *
grub_install_help_filter (int key, const char *text,
void *input __attribute__ ((unused)));
enum grub_install_plat
{
GRUB_INSTALL_PLATFORM_I386_PC,
GRUB_INSTALL_PLATFORM_I386_EFI,
GRUB_INSTALL_PLATFORM_I386_QEMU,
GRUB_INSTALL_PLATFORM_I386_COREBOOT,
GRUB_INSTALL_PLATFORM_I386_MULTIBOOT,
GRUB_INSTALL_PLATFORM_I386_IEEE1275,
GRUB_INSTALL_PLATFORM_X86_64_EFI,
GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
GRUB_INSTALL_PLATFORM_MIPS_ARC,
GRUB_INSTALL_PLATFORM_IA64_EFI,
GRUB_INSTALL_PLATFORM_ARM_UBOOT,
GRUB_INSTALL_PLATFORM_ARM_EFI,
GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS,
GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS,
GRUB_INSTALL_PLATFORM_I386_XEN,
GRUB_INSTALL_PLATFORM_X86_64_XEN,
GRUB_INSTALL_PLATFORM_I386_XEN_PVH,
GRUB_INSTALL_PLATFORM_ARM64_EFI,
GRUB_INSTALL_PLATFORM_MIPS64EL_EFI,
GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
GRUB_INSTALL_PLATFORM_RISCV32_EFI,
GRUB_INSTALL_PLATFORM_RISCV64_EFI,
GRUB_INSTALL_PLATFORM_MAX
};
enum grub_install_options {
GRUB_INSTALL_OPTIONS_DIRECTORY = 'd',
GRUB_INSTALL_OPTIONS_VERBOSITY = 'v',
GRUB_INSTALL_OPTIONS_MODULES = 0x201,
GRUB_INSTALL_OPTIONS_INSTALL_MODULES,
GRUB_INSTALL_OPTIONS_INSTALL_THEMES,
GRUB_INSTALL_OPTIONS_INSTALL_FONTS,
GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
GRUB_INSTALL_OPTIONS_DIRECTORY2,
GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY,
GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY,
GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE,
GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
GRUB_INSTALL_OPTIONS_DTB
};
extern char *grub_install_source_directory;
enum grub_install_plat
grub_install_get_target (const char *src);
void
grub_install_mkdir_p (const char *dst);
void
grub_install_copy_files (const char *src,
const char *dst,
enum grub_install_plat platid);
char *
grub_install_get_platform_name (enum grub_install_plat platid);
const char *
grub_install_get_platform_cpu (enum grub_install_plat platid);
const char *
grub_install_get_platform_platform (enum grub_install_plat platid);
char *
grub_install_get_platforms_string (void);
typedef enum {
GRUB_COMPRESSION_AUTO,
GRUB_COMPRESSION_NONE,
GRUB_COMPRESSION_XZ,
GRUB_COMPRESSION_LZMA
} grub_compression_t;
void
grub_install_make_image_wrap (const char *dir, const char *prefix,
const char *outname, char *memdisk_path,
char *config_path,
const char *format, int note);
void
grub_install_make_image_wrap_file (const char *dir, const char *prefix,
FILE *fp, const char *outname,
char *memdisk_path,
char *config_path,
const char *mkimage_target, int note);
int
grub_install_copy_file (const char *src,
const char *dst,
int is_critical);
struct grub_install_image_target_desc;
void
grub_install_generate_image (const char *dir, const char *prefix,
FILE *out,
const char *outname, char *mods[],
char *memdisk_path, char **pubkey_paths,
size_t npubkeys,
char *config_path,
const struct grub_install_image_target_desc *image_target,
int note,
grub_compression_t comp, const char *dtb_file);
const struct grub_install_image_target_desc *
grub_install_get_image_target (const char *arg);
void
grub_util_bios_setup (const char *dir,
const char *boot_file, const char *core_file,
const char *dest, int force,
int fs_probe, int allow_floppy,
int add_rs_codes);
void
grub_util_sparc_setup (const char *dir,
const char *boot_file, const char *core_file,
const char *dest, int force,
int fs_probe, int allow_floppy,
int add_rs_codes);
char *
grub_install_get_image_targets_string (void);
const char *
grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
void
grub_install_create_envblk_file (const char *name);
const char *
grub_install_get_default_arm_platform (void);
const char *
grub_install_get_default_x86_platform (void);
int
grub_install_register_efi (grub_device_t efidir_grub_dev,
const char *efifile_path,
const char *efi_distributor);
void
grub_install_register_ieee1275 (int is_prep, const char *install_device,
int partno, const char *relpath);
void
grub_install_sgi_setup (const char *install_device,
const char *imgfile, const char *destname);
int
grub_install_compress_gzip (const char *src, const char *dest);
int
grub_install_compress_lzop (const char *src, const char *dest);
int
grub_install_compress_xz (const char *src, const char *dest);
void
grub_install_get_blocklist (grub_device_t root_dev,
const char *core_path, const char *core_img,
size_t core_size,
void (*callback) (grub_disk_addr_t sector,
unsigned offset,
unsigned length,
void *data),
void *hook_data);
void
grub_util_create_envblk_file (const char *name);
void
grub_util_glue_efi (const char *file32, const char *file64, const char *out);
void
grub_util_render_label (const char *label_font,
const char *label_bgcolor,
const char *label_color,
const char *label_string,
const char *label);
const char *
grub_util_get_target_name (const struct grub_install_image_target_desc *t);
extern char *grub_install_copy_buffer;
#define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
#endif

@ -19,6 +19,8 @@ all_modules_uefi="setkey blocklist ventoy test true regexp newc search at_keyboa
all_modules_arm64_uefi="setkey blocklist ventoy test true regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
all_modules_mips64el_uefi="setkey blocklist ventoy test true regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
if [ "$1" = "uefi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi "
@ -34,6 +36,10 @@ elif [ "$1" = "arm64" ]; then
all_modules="$net_modules_uefi $all_modules_arm64_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/BOOTAA64.EFI" --format 'arm64-efi' --compression 'auto' $all_modules_arm64_uefi
elif [ "$1" = "mips64el" ]; then
all_modules="$net_modules_uefi $all_modules_mips64el_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/mips64el-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/BOOTMIPS.EFI" --format 'mips64el-efi' --compression 'auto' $all_modules_mips64el_uefi
else
all_modules="$net_modules_legacy $all_modules_legacy "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
@ -93,6 +99,24 @@ elif [ "$1" = "arm64" ]; then
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi/$line $VT_DIR/INSTALL/grub/arm64-efi/
fi
done
elif [ "$1" = "mips64el" ]; then
rm -f $VT_DIR/GRUB2/NBP/core.efi
cp -a $VT_DIR/GRUB2/PXE/grub2/mips64el-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
rm -rf $VT_DIR/INSTALL/grub/mips64el-efi
mkdir -p $VT_DIR/INSTALL/grub/mips64el-efi
cp -a $VT_DIR/GRUB2/PXE/grub2/mips64el-efi/normal.mod $VT_DIR/INSTALL/grub/mips64el-efi/normal.mod || exit 1
#copy other modules
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/mips64el-efi/ | egrep '\.(lst|mod)$' | while read line; do
if ! echo $all_modules | grep -q " ${line%.mod} "; then
echo "Copy $line ..."
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/mips64el-efi/$line $VT_DIR/INSTALL/grub/mips64el-efi/
xz $VT_DIR/INSTALL/grub/mips64el-efi/$line
mv $VT_DIR/INSTALL/grub/mips64el-efi/${line}.xz $VT_DIR/INSTALL/grub/mips64el-efi/${line}
fi
done
else
rm -f $VT_DIR/GRUB2/NBP/core.0
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,373 @@
# Helper library for grub-mkconfig
# Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
datadir="@datadir@"
bindir="@bindir@"
sbindir="@sbindir@"
if [ "x$pkgdatadir" = x ]; then
pkgdatadir="${datadir}/@PACKAGE@"
fi
if test "x$grub_probe" = x; then
grub_probe="${sbindir}/@grub_probe@"
fi
if test "x$grub_file" = x; then
grub_file="${bindir}/@grub_file@"
fi
if test "x$grub_mkrelpath" = x; then
grub_mkrelpath="${bindir}/@grub_mkrelpath@"
fi
if which gettext >/dev/null 2>/dev/null; then
:
else
gettext () {
printf "%s" "$@"
}
fi
grub_warn ()
{
echo "$(gettext "Warning:")" "$@" >&2
}
make_system_path_relative_to_its_root ()
{
"${grub_mkrelpath}" "$1"
}
is_path_readable_by_grub ()
{
path="$1"
# abort if path doesn't exist
if test -e "$path" ; then : ;else
return 1
fi
# abort if file is in a filesystem we can't read
if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else
return 1
fi
# ... or if we can't figure out the abstraction module, for example if
# memberlist fails on an LVM volume group.
if abstractions="`"${grub_probe}" -t abstraction "$path"`" 2> /dev/null ; then
:
else
return 1
fi
if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
return 0
fi
for abstraction in $abstractions; do
if [ "x$abstraction" = xcryptodisk ]; then
return 1
fi
done
return 0
}
convert_system_path_to_grub_path ()
{
path="$1"
grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
# abort if GRUB can't access the path
if is_path_readable_by_grub "${path}" ; then : ; else
return 1
fi
if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
return 1
fi
if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
return 1
fi
echo "${drive}${relative_path}"
}
save_default_entry ()
{
if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
cat << EOF
savedefault
EOF
fi
}
prepare_grub_to_access_device ()
{
old_ifs="$IFS"
IFS='
'
:<<\EOF
partmap="`"${grub_probe}" --device $@ --target=partmap`"
for module in ${partmap} ; do
case "${module}" in
netbsd | openbsd)
echo "insmod part_bsd";;
*)
echo "insmod part_${module}";;
esac
done
EOF
# Abstraction modules aren't auto-loaded.
abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
for module in ${abstraction} ; do
echo "insmod ${module}"
done
# fs="`"${grub_probe}" --device $@ --target=fs`"
# for module in ${fs} ; do
# echo "insmod ${module}"
# done
if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do
echo "cryptomount -u $uuid"
done
fi
# If there's a filesystem UUID that GRUB is capable of identifying, use it;
# otherwise set root as per value in device.map.
fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`"
if [ "x$fs_hint" != x ]; then
echo "set root='$fs_hint'"
fi
if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints=
echo "if [ x\$feature_platform_search_hint = xy ]; then"
echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
echo "else"
echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
echo "fi"
fi
IFS="$old_ifs"
}
grub_get_device_id ()
{
old_ifs="$IFS"
IFS='
'
device="$1"
if fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then
echo "$fs_uuid";
else
echo $device |sed 's, ,_,g'
fi
IFS="$old_ifs"
}
grub_file_is_not_garbage ()
{
if test -f "$1" ; then
case "$1" in
*.dpkg-*) return 1 ;; # debian dpkg
*.rpmsave|*.rpmnew) return 1 ;;
README*|*/README*) return 1 ;; # documentation
*.sig) return 1 ;; # signatures
esac
else
return 1
fi
return 0
}
version_sort ()
{
case $version_sort_sort_has_v in
yes)
LC_ALL=C sort -V;;
no)
LC_ALL=C sort -n;;
*)
if sort -V </dev/null > /dev/null 2>&1; then
version_sort_sort_has_v=yes
LC_ALL=C sort -V
else
version_sort_sort_has_v=no
LC_ALL=C sort -n
fi;;
esac
}
version_test_numeric ()
{
version_test_numeric_a="$1"
version_test_numeric_cmp="$2"
version_test_numeric_b="$3"
if [ "$version_test_numeric_a" = "$version_test_numeric_b" ] ; then
case "$version_test_numeric_cmp" in
ge|eq|le) return 0 ;;
gt|lt) return 1 ;;
esac
fi
if [ "$version_test_numeric_cmp" = "lt" ] ; then
version_test_numeric_c="$version_test_numeric_a"
version_test_numeric_a="$version_test_numeric_b"
version_test_numeric_b="$version_test_numeric_c"
fi
if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
return 0
else
return 1
fi
}
version_test_gt ()
{
version_test_gt_a="`echo "$1" | sed -e "s/[^-]*-//"`"
version_test_gt_b="`echo "$2" | sed -e "s/[^-]*-//"`"
version_test_gt_cmp=gt
if [ "x$version_test_gt_b" = "x" ] ; then
return 0
fi
case "$version_test_gt_a:$version_test_gt_b" in
*.old:*.old) ;;
*.old:*) version_test_gt_a="`echo "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;;
*:*.old) version_test_gt_b="`echo "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;;
esac
version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
return "$?"
}
version_find_latest ()
{
version_find_latest_a=""
for i in "$@" ; do
if version_test_gt "$i" "$version_find_latest_a" ; then
version_find_latest_a="$i"
fi
done
echo "$version_find_latest_a"
}
# One layer of quotation is eaten by "" and the second by sed; so this turns
# ' into \'.
grub_quote () {
sed "s/'/'\\\\''/g"
}
gettext_quoted () {
gettext "$@" | grub_quote
}
# Run the first argument through gettext, and then pass that and all
# remaining arguments to printf. This is a useful abbreviation and tends to
# be easier to type.
gettext_printf () {
gettext_printf_format="$1"
shift
printf "$(gettext "$gettext_printf_format")" "$@"
}
uses_abstraction () {
device="$1"
old_ifs="$IFS"
IFS='
'
abstraction="`"${grub_probe}" --device ${device} --target=abstraction`"
for module in ${abstraction}; do
if test "x${module}" = "x$2"; then
IFS="$old_ifs"
return 0
fi
done
IFS="$old_ifs"
return 1
}
print_option_help () {
if test x$print_option_help_wc = x; then
if wc -L </dev/null > /dev/null 2>&1; then
print_option_help_wc=-L
elif wc -m </dev/null > /dev/null 2>&1; then
print_option_help_wc=-m
else
print_option_help_wc=-b
fi
fi
if test x$grub_have_fmt = x; then
if fmt -w 40 </dev/null > /dev/null 2>&1; then
grub_have_fmt=y;
else
grub_have_fmt=n;
fi
fi
print_option_help_lead=" $1"
print_option_help_lspace="$(echo "$print_option_help_lead" | wc $print_option_help_wc)"
print_option_help_fill="$((26 - print_option_help_lspace))"
printf "%s" "$print_option_help_lead"
if test $print_option_help_fill -le 0; then
print_option_help_nl=y
echo
else
print_option_help_i=0;
while test $print_option_help_i -lt $print_option_help_fill; do
printf " "
print_option_help_i=$((print_option_help_i+1))
done
print_option_help_nl=n
fi
if test x$grub_have_fmt = xy; then
print_option_help_split="$(echo "$2" | fmt -w 50)"
else
print_option_help_split="$2"
fi
if test x$print_option_help_nl = xy; then
echo "$print_option_help_split" | awk \
'{ print " " $0; }'
else
echo "$print_option_help_split" | awk 'BEGIN { n = 0 }
{ if (n == 1) print " " $0; else print $0; n = 1 ; }'
fi
}
grub_fmt () {
if test x$grub_have_fmt = x; then
if fmt -w 40 < /dev/null > /dev/null; then
grub_have_fmt=y;
else
grub_have_fmt=n;
fi
fi
if test x$grub_have_fmt = xy; then
fmt
else
cat
fi
}
grub_tab=" "
grub_add_tab () {
sed -e "s/^/$grub_tab/"
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,225 @@
/*
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,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 <config.h>
#include <grub/util/install.h>
#include <grub/emu/config.h>
#include <grub/util/misc.h>
#include <string.h>
#include <errno.h>
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#include <argp.h>
#pragma GCC diagnostic error "-Wmissing-prototypes"
#pragma GCC diagnostic error "-Wmissing-declarations"
static char *rootdir = NULL, *subdir = NULL;
static char *debug_image = NULL;
enum
{
OPTION_NET_DIRECTORY = 0x301,
OPTION_SUBDIR,
OPTION_DEBUG,
OPTION_DEBUG_IMAGE
};
static struct argp_option options[] = {
GRUB_INSTALL_OPTIONS,
{"net-directory", OPTION_NET_DIRECTORY, N_("DIR"),
0, N_("root directory of TFTP server"), 2},
{"subdir", OPTION_SUBDIR, N_("DIR"),
0, N_("relative subdirectory on network server"), 2},
{"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2},
{"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2},
{0, 0, 0, 0, 0, 0}
};
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
if (grub_install_parse (key, arg))
return 0;
switch (key)
{
case OPTION_NET_DIRECTORY:
free (rootdir);
rootdir = xstrdup (arg);
return 0;
case OPTION_SUBDIR:
free (subdir);
subdir = xstrdup (arg);
return 0;
/* This is an undocumented feature... */
case OPTION_DEBUG:
verbosity++;
return 0;
case OPTION_DEBUG_IMAGE:
free (debug_image);
debug_image = xstrdup (arg);
return 0;
case ARGP_KEY_ARG:
default:
return ARGP_ERR_UNKNOWN;
}
}
struct argp argp = {
options, argp_parser, NULL,
"\v"N_("Prepares GRUB network boot images at net_directory/subdir "
"assuming net_directory being TFTP root."),
NULL, grub_install_help_filter, NULL
};
static char *base;
static const struct
{
const char *mkimage_target;
const char *netmodule;
const char *ext;
} targets[GRUB_INSTALL_PLATFORM_MAX] =
{
[GRUB_INSTALL_PLATFORM_I386_PC] = { "i386-pc-pxe", "pxe", ".0" },
[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64-ieee1275-aout", "ofnet", ".img" },
[GRUB_INSTALL_PLATFORM_I386_IEEE1275] = { "i386-ieee1275", "ofnet", ".elf" },
[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc-ieee1275", "ofnet", ".elf" },
[GRUB_INSTALL_PLATFORM_I386_EFI] = { "i386-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_MIPS64EL_EFI] = { "mips64el-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" },
};
static void
process_input_dir (const char *input_dir, enum grub_install_plat platform)
{
char *platsub = grub_install_get_platform_name (platform);
char *grubdir = grub_util_path_concat (3, rootdir, subdir, platsub);
char *load_cfg = grub_util_path_concat (2, grubdir, "load.cfg");
char *prefix;
char *output;
char *grub_cfg;
FILE *cfg;
grub_install_copy_files (input_dir, base, platform);
grub_util_unlink (load_cfg);
if (debug_image)
{
FILE *f = grub_util_fopen (load_cfg, "wb");
if (!f)
grub_util_error (_("cannot open `%s': %s"), load_cfg,
strerror (errno));
fprintf (f, "set debug='%s'\n", debug_image);
fclose (f);
}
else
{
free (load_cfg);
load_cfg = 0;
}
prefix = xasprintf ("/%s", subdir);
if (!targets[platform].mkimage_target)
grub_util_error (_("unsupported platform %s"), platsub);
grub_cfg = grub_util_path_concat (2, grubdir, "grub.cfg");
cfg = grub_util_fopen (grub_cfg, "wb");
if (!cfg)
grub_util_error (_("cannot open `%s': %s"), grub_cfg,
strerror (errno));
fprintf (cfg, "source %s/grub.cfg", subdir);
fclose (cfg);
grub_install_push_module (targets[platform].netmodule);
output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext);
grub_install_make_image_wrap (input_dir, prefix, output,
0, load_cfg,
targets[platform].mkimage_target, 0);
grub_install_pop_module ();
/* TRANSLATORS: First %s is replaced by platform name. Second one by filename. */
printf (_("Netboot directory for %s created. Configure your DHCP server to point to %s\n"),
platsub, output);
free (platsub);
free (output);
free (prefix);
free (grub_cfg);
free (grubdir);
}
int
main (int argc, char *argv[])
{
const char *pkglibdir;
grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
rootdir = xstrdup ("/srv/tftp");
pkglibdir = grub_util_get_pkglibdir ();
subdir = grub_util_path_concat (2, GRUB_BOOT_DIR_NAME, GRUB_DIR_NAME);
argp_parse (&argp, argc, argv, 0, 0, 0);
base = grub_util_path_concat (2, rootdir, subdir);
/* Create the GRUB directory if it is not present. */
grub_install_mkdir_p (base);
grub_install_push_module ("tftp");
if (!grub_install_source_directory)
{
enum grub_install_plat plat;
for (plat = 0; plat < GRUB_INSTALL_PLATFORM_MAX; plat++)
if (targets[plat].mkimage_target)
{
char *platdir = grub_util_path_concat (2, pkglibdir,
grub_install_get_platform_name (plat));
grub_util_info ("Looking for `%s'", platdir);
if (!grub_util_is_directory (platdir))
{
free (platdir);
continue;
}
process_input_dir (platdir, plat);
}
}
else
{
enum grub_install_plat plat;
plat = grub_install_get_target (grub_install_source_directory);
process_input_dir (grub_install_source_directory, plat);
}
return 0;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,247 @@
#include <stdio.h>
#include <string.h>
#include <grub/elf.h>
#include <grub/module_verifier.h>
#include <grub/misc.h>
#include <grub/util/misc.h>
struct grub_module_verifier_arch archs[] = {
{ "i386", 4, 0, EM_386, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
R_386_32,
R_386_PC32,
-1
} },
{ "x86_64", 8, 0, EM_X86_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_X86_64_64,
R_X86_64_PC64,
/* R_X86_64_32, R_X86_64_32S are supported but shouldn't be used because of their limited range. */
-1
}, (int[]){
R_X86_64_PC32,
R_X86_64_PLT32,
-1
}
},
{ "powerpc", 4, 1, EM_PPC, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
GRUB_ELF_R_PPC_ADDR16_LO,
GRUB_ELF_R_PPC_REL24, /* It has limited range but GRUB adds trampolines when necessarry. */
GRUB_ELF_R_PPC_ADDR16_HA,
GRUB_ELF_R_PPC_ADDR32,
GRUB_ELF_R_PPC_REL32,
GRUB_ELF_R_PPC_PLTREL24,
-1
} },
{ "sparc64", 8, 1, EM_SPARCV9, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_SPARC_WDISP30, /* It has limited range but GRUB adds trampolines when necessarry. */
R_SPARC_HH22,
R_SPARC_HM10,
R_SPARC_LM22,
R_SPARC_LO10,
R_SPARC_64,
R_SPARC_OLO10,
/* Following 2 relocations have limited range but unfortunately
clang generates them, as it doesn't implement mcmodel=large properly.
At least our heap and core are under 4G, so it's not a problem
usually. */
R_SPARC_HI22,
R_SPARC_32,
-1
} },
{ "ia64", 8, 0, EM_IA_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_IA64_PCREL21B, /* We should verify that it's pointing either
to a function or to a section in the same module.
Checking that external symbol is a function is
non-trivial and I have never seen this relocation used
for anything else, so assume that it always points to a
function.
*/
R_IA64_SEGREL64LSB,
R_IA64_FPTR64LSB,
R_IA64_DIR64LSB,
R_IA64_PCREL64LSB,
R_IA64_LTOFF22X,
R_IA64_LTOFF22,
R_IA64_GPREL64I,
R_IA64_LTOFF_FPTR22,
R_IA64_LDXMOV,
-1
}, (int[]){
R_IA64_GPREL22,
-1
} },
{ "mipsel", 4, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "mips", 4, 1, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "arm", 4, 0, EM_ARM, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
/* Some relocations are range-limited but trampolines are added when necessarry. */
R_ARM_ABS32,
R_ARM_CALL,
R_ARM_JUMP24,
R_ARM_THM_CALL,
R_ARM_THM_JUMP24,
R_ARM_V4BX,
R_ARM_THM_MOVW_ABS_NC,
R_ARM_THM_MOVT_ABS,
R_ARM_THM_JUMP19,
-1
} },
{ "arm64", 8, 0, EM_AARCH64, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_AARCH64_ABS64,
R_AARCH64_CALL26,
R_AARCH64_JUMP26,
R_AARCH64_ADR_GOT_PAGE,
R_AARCH64_LD64_GOT_LO12_NC,
-1
}, (int[]){
R_AARCH64_ADR_PREL_PG_HI21,
R_AARCH64_ADD_ABS_LO12_NC,
R_AARCH64_LDST64_ABS_LO12_NC,
R_AARCH64_PREL32,
-1
} },
{ "mips64el", 8, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_64,
R_MIPS_32,
R_MIPS_26,
R_MIPS_LO16,
R_MIPS_HI16,
R_MIPS_HIGHER,
R_MIPS_HIGHEST,
-1
}, (int[]){
-1
}
},
{ "riscv32", 4, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_RISCV_32,
R_RISCV_64,
R_RISCV_ADD8,
R_RISCV_ADD16,
R_RISCV_ADD32,
R_RISCV_ADD64,
R_RISCV_SUB8,
R_RISCV_SUB16,
R_RISCV_SUB32,
R_RISCV_SUB64,
R_RISCV_ALIGN,
R_RISCV_BRANCH,
R_RISCV_CALL,
R_RISCV_CALL_PLT,
R_RISCV_GOT_HI20,
R_RISCV_HI20,
R_RISCV_JAL,
R_RISCV_LO12_I,
R_RISCV_LO12_S,
R_RISCV_PCREL_HI20,
R_RISCV_PCREL_LO12_I,
R_RISCV_PCREL_LO12_S,
R_RISCV_RELAX,
R_RISCV_RVC_BRANCH,
R_RISCV_RVC_JUMP,
-1
} },
{ "riscv64", 8, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_RISCV_32,
R_RISCV_64,
R_RISCV_ADD8,
R_RISCV_ADD16,
R_RISCV_ADD32,
R_RISCV_ADD64,
R_RISCV_SUB8,
R_RISCV_SUB16,
R_RISCV_SUB32,
R_RISCV_SUB64,
R_RISCV_ALIGN,
R_RISCV_BRANCH,
R_RISCV_CALL,
R_RISCV_CALL_PLT,
R_RISCV_GOT_HI20,
R_RISCV_HI20,
R_RISCV_JAL,
R_RISCV_LO12_I,
R_RISCV_LO12_S,
R_RISCV_PCREL_HI20,
R_RISCV_PCREL_LO12_I,
R_RISCV_PCREL_LO12_S,
R_RISCV_RELAX,
R_RISCV_RVC_BRANCH,
R_RISCV_RVC_JUMP,
-1
}
},
};
struct platform_whitelist {
const char *arch;
const char *platform;
const char **whitelist_empty;
};
static struct platform_whitelist whitelists[] = {
{"i386", "xen", (const char *[]) {"all_video", 0}},
{"i386", "xen_pvh", (const char *[]) {"all_video", 0}},
{"x86_64", "xen", (const char *[]) {"all_video", 0}},
{"sparc64", "ieee1275", (const char *[]) {"all_video", 0}},
/* video is compiled-in on MIPS. */
{"mipsel", "loongson", (const char *[]) {"all_video", 0}},
{"mipsel", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mipsel", "arc", (const char *[]) {"all_video", 0}},
{"mips", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mips", "arc", (const char *[]) {"all_video", 0}},
};
int
main (int argc, char **argv)
{
size_t module_size;
unsigned arch, whitelist;
const char **whitelist_empty = 0;
char *module_img;
if (argc != 4) {
fprintf (stderr, "usage: %s FILE ARCH PLATFORM\n", argv[0]);
return 1;
}
for (arch = 0; arch < ARRAY_SIZE(archs); arch++)
if (strcmp(archs[arch].name, argv[2]) == 0)
break;
if (arch == ARRAY_SIZE(archs))
grub_util_error("%s: unknown arch: %s", argv[1], argv[2]);
for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++)
if (strcmp(whitelists[whitelist].arch, argv[2]) == 0
&& strcmp(whitelists[whitelist].platform, argv[3]) == 0)
break;
if (whitelist != ARRAY_SIZE(whitelists))
whitelist_empty = whitelists[whitelist].whitelist_empty;
module_size = grub_util_get_image_size (argv[1]);
module_img = grub_util_read_image (argv[1]);
if (archs[arch].voidp_sizeof == 8)
grub_module_verify64(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
else
grub_module_verify32(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
return 0;
}

@ -0,0 +1,446 @@
#include <string.h>
#include <grub/elf.h>
#include <grub/module_verifier.h>
#include <grub/util/misc.h>
#if defined(MODULEVERIFIER_ELF32)
# define SUFFIX(x) x ## 32
# define ELFCLASSXX ELFCLASS32
# define Elf_Ehdr Elf32_Ehdr
# define Elf_Phdr Elf32_Phdr
# define Elf_Nhdr Elf32_Nhdr
# define Elf_Addr Elf32_Addr
# define Elf_Sym Elf32_Sym
# define Elf_Off Elf32_Off
# define Elf_Shdr Elf32_Shdr
# define Elf_Rela Elf32_Rela
# define Elf_Rel Elf32_Rel
# define Elf_Word Elf32_Word
# define Elf_Half Elf32_Half
# define Elf_Section Elf32_Section
# define ELF_R_SYM(val) ELF32_R_SYM(val)
# define ELF_R_TYPE(val) ELF32_R_TYPE(val)
# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
#elif defined(MODULEVERIFIER_ELF64)
# define SUFFIX(x) x ## 64
# define ELFCLASSXX ELFCLASS64
# define Elf_Ehdr Elf64_Ehdr
# define Elf_Phdr Elf64_Phdr
# define Elf_Nhdr Elf64_Nhdr
# define Elf_Addr Elf64_Addr
# define Elf_Sym Elf64_Sym
# define Elf_Off Elf64_Off
# define Elf_Shdr Elf64_Shdr
# define Elf_Rela Elf64_Rela
# define Elf_Rel Elf64_Rel
# define Elf_Word Elf64_Word
# define Elf_Half Elf64_Half
# define Elf_Section Elf64_Section
# define ELF_R_SYM(val) ELF64_R_SYM(val)
# define ELF_R_TYPE(val) ELF64_R_TYPE(val)
# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val)
#else
#error "I'm confused"
#endif
#define grub_target_to_host32(x) (grub_target_to_host32_real (arch, (x)))
#define grub_host_to_target32(x) (grub_host_to_target32_real (arch, (x)))
#define grub_target_to_host64(x) (grub_target_to_host64_real (arch, (x)))
#define grub_host_to_target64(x) (grub_host_to_target64_real (arch, (x)))
#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (arch, (x)))
#define grub_target_to_host16(x) (grub_target_to_host16_real (arch, (x)))
#define grub_host_to_target16(x) (grub_host_to_target16_real (arch, (x)))
#define grub_target_to_host(val) grub_target_to_host_real(arch, (val))
static inline grub_uint32_t
grub_target_to_host32_real (const struct grub_module_verifier_arch *arch,
grub_uint32_t in)
{
if (arch->bigendian)
return grub_be_to_cpu32 (in);
else
return grub_le_to_cpu32 (in);
}
static inline grub_uint64_t
grub_target_to_host64_real (const struct grub_module_verifier_arch *arch,
grub_uint64_t in)
{
if (arch->bigendian)
return grub_be_to_cpu64 (in);
else
return grub_le_to_cpu64 (in);
}
static inline grub_uint64_t
grub_host_to_target64_real (const struct grub_module_verifier_arch *arch,
grub_uint64_t in)
{
if (arch->bigendian)
return grub_cpu_to_be64 (in);
else
return grub_cpu_to_le64 (in);
}
static inline grub_uint32_t
grub_host_to_target32_real (const struct grub_module_verifier_arch *arch,
grub_uint32_t in)
{
if (arch->bigendian)
return grub_cpu_to_be32 (in);
else
return grub_cpu_to_le32 (in);
}
static inline grub_uint16_t
grub_target_to_host16_real (const struct grub_module_verifier_arch *arch,
grub_uint16_t in)
{
if (arch->bigendian)
return grub_be_to_cpu16 (in);
else
return grub_le_to_cpu16 (in);
}
static inline grub_uint16_t
grub_host_to_target16_real (const struct grub_module_verifier_arch *arch,
grub_uint16_t in)
{
if (arch->bigendian)
return grub_cpu_to_be16 (in);
else
return grub_cpu_to_le16 (in);
}
static inline grub_uint64_t
grub_host_to_target_addr_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in)
{
if (arch->voidp_sizeof == 8)
return grub_host_to_target64_real (arch, in);
else
return grub_host_to_target32_real (arch, in);
}
static inline grub_uint64_t
grub_target_to_host_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in)
{
if (arch->voidp_sizeof == 8)
return grub_target_to_host64_real (arch, in);
else
return grub_target_to_host32_real (arch, in);
}
static Elf_Shdr *
find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name)
{
Elf_Shdr *s;
const char *str;
unsigned i;
s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host16 (e->e_shstrndx) * grub_target_to_host16 (e->e_shentsize));
str = (char *) e + grub_target_to_host (s->sh_offset);
for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (strcmp (str + grub_target_to_host32 (s->sh_name), name) == 0)
return s;
return NULL;
}
static void
check_license (const char * const filename,
const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s = find_section (arch, e, ".module_license");
if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0))
return;
grub_util_error ("%s: incompatible license", filename);
}
static Elf_Sym *
get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize)
{
unsigned i;
Elf_Shdr *s, *sections;
Elf_Sym *sym;
sections = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
for (i = 0, s = sections;
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (grub_target_to_host32 (s->sh_type) == SHT_SYMTAB)
break;
if (i == grub_target_to_host16 (e->e_shnum))
return NULL;
sym = (Elf_Sym *) ((char *) e + grub_target_to_host (s->sh_offset));
*size = grub_target_to_host (s->sh_size);
*entsize = grub_target_to_host (s->sh_entsize);
return sym;
}
static int
is_whitelisted (const char *modname, const char **whitelist)
{
const char **ptr;
if (!whitelist)
return 0;
if (!modname)
return 0;
for (ptr = whitelist; *ptr; ptr++)
if (strcmp (modname, *ptr) == 0)
return 1;
return 0;
}
static void
check_symbols (const struct grub_module_verifier_arch *arch,
Elf_Ehdr *e, const char *modname,
const char **whitelist_empty)
{
Elf_Sym *sym;
Elf_Word size, entsize;
unsigned i;
/* Module without symbol table and without .moddeps section is useless
at boot time, so catch it early to prevent build errors */
sym = get_symtab (arch, e, &size, &entsize);
if (!sym)
{
Elf_Shdr *s;
/* However some modules are dependencies-only,
e.g. insmod all_video pulls in all video drivers.
Some platforms e.g. xen have no video drivers, so
the module does nothing. */
if (is_whitelisted (modname, whitelist_empty))
return;
s = find_section (arch, e, ".moddeps");
if (!s)
grub_util_error ("%s: no symbol table and no .moddeps section", modname);
if (!s->sh_size)
grub_util_error ("%s: no symbol table and empty .moddeps section", modname);
return;
}
for (i = 0;
i < size / entsize;
i++, sym = (Elf_Sym *) ((char *) sym + entsize))
{
unsigned char type = ELF_ST_TYPE (sym->st_info);
switch (type)
{
case STT_NOTYPE:
case STT_OBJECT:
case STT_FUNC:
case STT_SECTION:
case STT_FILE:
break;
default:
return grub_util_error ("%s: unknown symbol type `%d'", modname, (int) type);
}
}
}
static int
is_symbol_local(Elf_Sym *sym)
{
switch (ELF_ST_TYPE (sym->st_info))
{
case STT_NOTYPE:
case STT_OBJECT:
if (sym->st_name != 0 && sym->st_shndx == 0)
return 0;
return 1;
case STT_FUNC:
case STT_SECTION:
return 1;
default:
return 0;
}
}
static void
section_check_relocations (const char * const modname,
const struct grub_module_verifier_arch *arch, void *ehdr,
Elf_Shdr *s, size_t target_seg_size)
{
Elf_Rel *rel, *max;
Elf_Sym *symtab;
Elf_Word symtabsize, symtabentsize;
symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize);
if (!symtab)
grub_util_error ("%s: relocation without symbol table", modname);
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
rel < max;
rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)))
{
Elf_Sym *sym;
unsigned i;
if (target_seg_size < grub_target_to_host (rel->r_offset))
grub_util_error ("%s: reloc offset is out of the segment", modname);
grub_size_t r_info;
if (arch->machine == EM_MIPS && arch->voidp_sizeof == 8)
r_info = ((grub_uint64_t) rel->r_info << 32) |
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
else
r_info = grub_target_to_host (rel->r_info);
grub_uint32_t type = ELF_R_TYPE (r_info);
if (arch->machine == EM_SPARCV9)
type &= 0xff;
for (i = 0; arch->supported_relocations[i] != -1; i++)
if (type == arch->supported_relocations[i])
break;
if (arch->supported_relocations[i] != -1)
continue;
if (!arch->short_relocations)
grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
for (i = 0; arch->short_relocations[i] != -1; i++)
if (type == arch->short_relocations[i])
break;
if (arch->short_relocations[i] == -1)
grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (r_info));
if (is_symbol_local (sym))
continue;
grub_util_error ("%s: relocation 0x%x is not module-local", modname, type);
}
#if defined(MODULEVERIFIER_ELF64)
if (arch->machine == EM_AARCH64)
{
unsigned unmatched_adr_got_page = 0;
Elf_Rela *rel2;
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
rel < max;
rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)))
{
switch (ELF_R_TYPE (grub_target_to_host (rel->r_info)))
{
case R_AARCH64_ADR_GOT_PAGE:
unmatched_adr_got_page++;
for (rel2 = (Elf_Rela *) ((char *) rel + grub_target_to_host (s->sh_entsize));
rel2 < (Elf_Rela *) max;
rel2 = (Elf_Rela *) ((char *) rel2 + grub_target_to_host (s->sh_entsize)))
if (ELF_R_SYM (rel2->r_info)
== ELF_R_SYM (rel->r_info)
&& ((Elf_Rela *) rel)->r_addend == rel2->r_addend
&& ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC)
break;
if (rel2 >= (Elf_Rela *) max)
grub_util_error ("%s: ADR_GOT_PAGE without matching LD64_GOT_LO12_NC", modname);
break;
case R_AARCH64_LD64_GOT_LO12_NC:
if (unmatched_adr_got_page == 0)
grub_util_error ("%s: LD64_GOT_LO12_NC without matching ADR_GOT_PAGE", modname);
unmatched_adr_got_page--;
break;
}
}
}
#endif
}
static void
check_relocations (const char * const modname,
const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s;
unsigned i;
for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (grub_target_to_host32 (s->sh_type) == SHT_REL || grub_target_to_host32 (s->sh_type) == SHT_RELA)
{
Elf_Shdr *ts;
if (grub_target_to_host32 (s->sh_type) == SHT_REL && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_REL))
grub_util_error ("%s: unsupported SHT_REL", modname);
if (grub_target_to_host32 (s->sh_type) == SHT_RELA && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_RELA))
grub_util_error ("%s: unsupported SHT_RELA", modname);
/* Find the target segment. */
if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum))
grub_util_error ("%s: orphaned reloc section", modname);
ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize));
section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size));
}
}
void
SUFFIX(grub_module_verify) (const char * const filename,
void *module_img, size_t size,
const struct grub_module_verifier_arch *arch,
const char **whitelist_empty)
{
Elf_Ehdr *e = module_img;
/* Check the header size. */
if (size < sizeof (Elf_Ehdr))
grub_util_error ("%s: ELF header smaller than expected", filename);
/* Check the magic numbers. */
if (e->e_ident[EI_MAG0] != ELFMAG0
|| e->e_ident[EI_MAG1] != ELFMAG1
|| e->e_ident[EI_MAG2] != ELFMAG2
|| e->e_ident[EI_MAG3] != ELFMAG3
|| e->e_ident[EI_VERSION] != EV_CURRENT
|| grub_target_to_host32 (e->e_version) != EV_CURRENT)
grub_util_error ("%s: invalid arch-independent ELF magic", filename);
if (e->e_ident[EI_CLASS] != ELFCLASSXX
|| e->e_ident[EI_DATA] != (arch->bigendian ? ELFDATA2MSB : ELFDATA2LSB)
|| grub_target_to_host16 (e->e_machine) != arch->machine)
grub_util_error ("%s: invalid arch-dependent ELF magic", filename);
if (grub_target_to_host16 (e->e_type) != ET_REL)
{
grub_util_error ("%s: this ELF file is not of the right type", filename);
}
/* Make sure that every section is within the core. */
if (size < grub_target_to_host (e->e_shoff)
+ (grub_uint32_t) grub_target_to_host16 (e->e_shentsize) * grub_target_to_host16(e->e_shnum))
{
grub_util_error ("%s: ELF sections outside core", filename);
}
check_license (filename, arch, e);
Elf_Shdr *s;
const char *modname;
s = find_section (arch, e, ".modname");
if (!s)
grub_util_error ("%s: no module name found", filename);
modname = (const char *) e + grub_target_to_host (s->sh_offset);
check_symbols(arch, e, modname, whitelist_empty);
check_relocations(modname, arch, e);
}

File diff suppressed because it is too large Load Diff

@ -55,6 +55,23 @@ make -j 16 || exit 1
sh install.sh arm64
#build for mips64el EFI
#http://ftp.loongnix.org/os/loongnix-server/1.7/os/Source/SPackages/grub2-2.02-0.40.lns7.14.loongnix.src.rpm
make distclean
./autogen.sh
./configure --prefix=/home/share/Ventoy/GRUB2/INSTALL/ \
--target=mips64el --with-platform=efi \
--host=x86_64-linux-gnu \
HOST_CC=x86_64-linux-gnu-gcc \
BUILD_CC=gcc \
TARGET_CC="mips-linux-gnu-gcc -mabi=64 -Wno-error=cast-align -Wno-error=misleading-indentation" \
TARGET_OBJCOPY=mips-linux-gnu-objcopy \
TARGET_STRIP=mips-linux-gnu-strip TARGET_NM=mips-linux-gnu-nm \
TARGET_RANLIB=mips-linux-gnu-ranlib
make -j 16 || exit 1
sh install.sh mips64el
# build for i386-pc
echo '======== build grub2 for i386-pc ==============='

@ -36,20 +36,34 @@ export SED=$BUSYBOX_PATH/sed
export SLEEP=$BUSYBOX_PATH/sleep
export HEAD=$BUSYBOX_PATH/head
if [ -e $BUSYBOX_PATH/32h ]; then
if [ -e $BUSYBOX_PATH/64h ]; then
#this is arm64
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
if [ -e $BUSYBOX_PATH/busyboxaa64.xz ]; then
export VTOY_ARCH=aarch64
elif [ -e $BUSYBOX_PATH/busyboxm64e.xz ]; then
export VTOY_ARCH=mips64el
else
if [ -e $BUSYBOX_PATH/32h ]; then
export VTOY_ARCH=x86_64
else
export VTOY_ARCH=i386
fi
fi
echo $VTOY_ARCH > $VTOY_PATH/ventoy_arch
if [ "$VTOY_ARCH" = "aarch64" ]; then
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
elif [ "$VTOY_ARCH" = "mips64el" ]; then
$BUSYBOX_PATH/xzminidecm64e < $BUSYBOX_PATH/busyboxm64e.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodm64e $BUSYBOX_PATH/busybox
elif [ "$VTOY_ARCH" = "x86_64" ]; then
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
#this is x86_64
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
else
$BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox
@ -91,35 +105,47 @@ else
xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG
fi
if [ -e $BUSYBOX_PATH/32h ]; then
if [ -e $BUSYBOX_PATH/64h ]; then
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
echo aarch64 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cataa64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
else
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
echo x86_64 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cat64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
fi
else
if [ "$VTOY_ARCH" = "x86_64" ]; then
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cat64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
elif [ "$VTOY_ARCH" = "i386" ]; then
echo "Use i386 busybox toolkit ..." >>$VTLOG
echo i386 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
elif [ "$VTOY_ARCH" = "mips64el" ]; then
echo "Use MIPS64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidecm64e $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupm64e $VTOY_PATH/tool/dmsetup
# TBD
#ln -s $VTOY_PATH/tool/lunzipm64e $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4catm64e $VTOY_PATH/tool/lz4cat
# TBD
#ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
elif [ "$VTOY_ARCH" = "aarch64" ]; then
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cataa64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
else
echo "Unknown busybox toolkit ..." >>$VTLOG
fi
rm -f *.xz

@ -39,7 +39,19 @@ if $GREP -q aarch64 $VTOY_PATH/ventoy_arch; then
done
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/vtoy_fuse_iso_aa64 $VTOY_PATH/tool/vtoy_fuse_iso
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_aa64 $VTOY_PATH/tool/vtoy_unsquashfs
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_aa64 $VTOY_PATH/tool/vtoy_unsquashfs
elif $GREP -q mips64el $VTOY_PATH/ventoy_arch; then
for vtdir in $(ls $VTOY_PATH/tool/vtoytool/); do
echo "try $VTOY_PATH/tool/vtoytool/$vtdir/ ..." >> $VTLOG
if $VTOY_PATH/tool/vtoytool/$vtdir/vtoytool_m64e --install 2>>$VTLOG; then
echo "vtoytool_m64e OK" >> $VTLOG
break
fi
done
# TBD
#$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/vtoy_fuse_iso_aa64 $VTOY_PATH/tool/vtoy_fuse_iso
#$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_aa64 $VTOY_PATH/tool/vtoy_unsquashfs
else
for vtdir in $(ls $VTOY_PATH/tool/vtoytool/); do
echo "try $VTOY_PATH/tool/vtoytool/$vtdir/ ..." >> $VTLOG

@ -2,9 +2,15 @@
VENTOY_PATH=$PWD/../
rm -f ventoy.cpio
if [ -d cpio_tmp ]; then
rm -rf cpio_tmp
fi
############### cpio ############
chmod -R 777 cpio
rm -f ventoy.cpio ventoy_x86.cpio ventoy_arm64.cpio ventoy_mips64.cpio
cp -a cpio cpio_tmp
@ -15,17 +21,46 @@ ln -s sbin/init linuxrc
cd ventoy
find ./loop | cpio -o -H newc>loop.cpio
xz loop.cpio
rm -rf loop
xz ventoy_chain.sh
xz ventoy_loop.sh
find ./hook | cpio -o -H newc>hook.cpio
xz hook.cpio
rm -rf hook
cd ..
find .| cpio -o -H newc>../ventoy.cpio
cd ..
rm -rf cpio_tmp
cp -a $VENTOY_PATH/DMSETUP/dmsetup* tool/
cp -a $VENTOY_PATH/SQUASHFS/unsquashfs_* tool/
cp -a $VENTOY_PATH/FUSEISO/vtoy_fuse_iso_* tool/
########## cpio_x86 ##############
chmod -R 777 cpio_x86
cp -a cpio_x86 cpio_tmp
cd cpio_tmp/ventoy
cp -a $VENTOY_PATH/DMSETUP/dmsetup32 tool/
cp -a $VENTOY_PATH/DMSETUP/dmsetup64 tool/
cp -a $VENTOY_PATH/SQUASHFS/unsquashfs_32 tool/
cp -a $VENTOY_PATH/SQUASHFS/unsquashfs_64 tool/
cp -a $VENTOY_PATH/FUSEISO/vtoy_fuse_iso_32 tool/
cp -a $VENTOY_PATH/FUSEISO/vtoy_fuse_iso_64 tool/
cp -a $VENTOY_PATH/VtoyTool/vtoytool tool/
cp -a $VENTOY_PATH/VBLADE/vblade-master/vblade_* tool/
rm -f tool/vtoytool/00/vtoytool_aa64
rm -f tool/vtoytool/00/vtoytool_m64e
cp -a $VENTOY_PATH/VBLADE/vblade-master/vblade_32 tool/
cp -a $VENTOY_PATH/VBLADE/vblade-master/vblade_64 tool/
cp -a $VENTOY_PATH/LZIP/lunzip32 tool/
cp -a $VENTOY_PATH/LZIP/lunzip64 tool/
cp -a $VENTOY_PATH/LZIP/lunzipaa64 tool/
chmod -R 777 ./tool
@ -33,25 +68,80 @@ find ./tool | cpio -o -H newc>tool.cpio
xz tool.cpio
rm -rf tool
find ./loop | cpio -o -H newc>loop.cpio
xz loop.cpio
rm -rf loop
cd ..
find .| cpio -o -H newc>../ventoy_x86.cpio
xz ventoy_chain.sh
xz ventoy_loop.sh
cd ..
rm -rf cpio_tmp
########## cpio_arm64 ##############
chmod -R 777 cpio_arm64
cp -a cpio_arm64 cpio_tmp
cp -a cpio_x86/ventoy/tool/*.sh cpio_tmp/ventoy/tool/
cd cpio_tmp/ventoy
cp -a $VENTOY_PATH/DMSETUP/dmsetupaa64 tool/
cp -a $VENTOY_PATH/SQUASHFS/unsquashfs_aa64 tool/
cp -a $VENTOY_PATH/FUSEISO/vtoy_fuse_iso_aa64 tool/
cp -a $VENTOY_PATH/VtoyTool/vtoytool tool/
rm -f tool/vtoytool/00/vtoytool_32
rm -f tool/vtoytool/00/vtoytool_64
rm -f tool/vtoytool/00/vtoytool_m64e
cp -a $VENTOY_PATH/VBLADE/vblade-master/vblade_aa64 tool/
cp -a $VENTOY_PATH/LZIP/lunzipaa64 tool/
chmod -R 777 ./tool
find ./tool | cpio -o -H newc>tool.cpio
xz tool.cpio
rm -rf tool
find ./hook | cpio -o -H newc>hook.cpio
xz hook.cpio
rm -rf hook
cd ..
find .| cpio -o -H newc>../ventoy_arm64.cpio
cd ..
rm -rf cpio_tmp
find .| cpio -o -H newc>../ventoy.cpio
########## cpio_mips64 ##############
chmod -R 777 cpio_mips64
cp -a cpio_mips64 cpio_tmp
cp -a cpio_x86/ventoy/tool/*.sh cpio_tmp/ventoy/tool/
cd cpio_tmp/ventoy
cp -a $VENTOY_PATH/DMSETUP/dmsetupm64e tool/
# cp -a $VENTOY_PATH/SQUASHFS/unsquashfs_m64e tool/
# cp -a $VENTOY_PATH/FUSEISO/vtoy_fuse_iso_m64e tool/
cp -a $VENTOY_PATH/VtoyTool/vtoytool tool/
rm -f tool/vtoytool/00/vtoytool_32
rm -f tool/vtoytool/00/vtoytool_64
rm -f tool/vtoytool/00/vtoytool_aa64
# cp -a $VENTOY_PATH/VBLADE/vblade-master/vblade_m64e tool/
# cp -a $VENTOY_PATH/LZIP/lunzipaa64 tool/
chmod -R 777 ./tool
find ./tool | cpio -o -H newc>tool.cpio
xz tool.cpio
rm -rf tool
cd ..
find .| cpio -o -H newc>../ventoy_mips64.cpio
cd ..
rm -rf cpio_tmp
echo '======== SUCCESS ============='
rm -f $VENTOY_PATH/INSTALL/ventoy/ventoy.cpio
cp -a ventoy.cpio $VENTOY_PATH/INSTALL/ventoy/
rm -f $VENTOY_PATH/INSTALL/ventoy/ventoy*.cpio
cp -a ventoy*.cpio $VENTOY_PATH/INSTALL/ventoy/

Binary file not shown.

Binary file not shown.

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

Loading…
Cancel
Save