Initial import of Leif's work

This commit is contained in:
Leif Lindholm 2013-04-07 02:41:07 +02:00 committed by Vladimir 'phcoder' Serbinenko
parent 21026747df
commit 389b31cd71
65 changed files with 7311 additions and 13 deletions

View file

@ -316,6 +316,8 @@ if [ x$source_dir = x ]; then
target=i386-pc
fi
;;
x"arm"*)
target="arm-uboot";;
*)
gettext "Unable to determine your platform. Use --target." ;
echo ;;
@ -335,7 +337,7 @@ if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] ; then
if [ x$disk_module = xunspecified ]; then
disk_module=biosdisk
fi
elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] ; then
elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] || [ "${grub_modinfo_platform}" = "uboot" ] ; then
disk_module=
else
disk_module=native
@ -464,6 +466,8 @@ if [ x"$grub_modinfo_platform" = xefi ]; then
# expansion.
ia64)
efi_file=BOOTIA64.EFI ;;
arm)
efi_file=BOOTARM.EFI ;;
esac
else
# It is convenient for each architecture to have a different
@ -478,6 +482,8 @@ if [ x"$grub_modinfo_platform" = xefi ]; then
# expansion.
ia64)
efi_file=grubia64.efi ;;
arm)
efi_file=grubarm.efi ;;
*)
efi_file=grub.efi ;;
esac
@ -827,6 +833,14 @@ elif [ x"$grub_modinfo_platform" = xefi ]; then
-L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
fi
fi
elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xarm-uboot ]; then
grub_imgname="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}"
raw_imgname="${uboot_imgname}.raw"
mv "$grub_imgname" "$raw_imgname"
mkimage -T kernel -A ARM -O Linux -a 0x08000000 -e 0x08000000 -C none -d "$raw_imgname" "$grub_imgname"
if [ $? -eq 0 ]; then
rm -f "$raw_imgname"
fi
else
gettext "WARNING: no platform-specific install was performed" 1>&2
echo 1>&2

View file

@ -69,7 +69,7 @@ struct image_target_desc
IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275,
IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH,
IMAGE_FULOONG2F_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC,
IMAGE_QEMU_MIPS_FLASH
IMAGE_QEMU_MIPS_FLASH, IMAGE_UBOOT
} id;
enum
{
@ -455,6 +455,46 @@ struct image_target_desc image_targets[] =
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = COMPRESSION_NONE
},
{
.dirname = "arm-uboot",
.names = { "arm-uboot", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_UBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_ARM_UBOOT_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_ARM_UBOOT_LINK_ADDR,
.elf_target = EM_ARM,
.mod_gap = GRUB_KERNEL_ARM_UBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN,
.link_align = 4
},
{
.dirname = "arm-efi",
.names = { "arm-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE
+ GRUB_PE32_SIGNATURE_SIZE
+ sizeof (struct grub_pe32_coff_header)
+ sizeof (struct grub_pe32_optional_header)
+ 4 * sizeof (struct grub_pe32_section_table),
GRUB_PE32_SECTION_ALIGNMENT),
.pe_target = GRUB_PE32_MACHINE_ARMTHUMB_MIXED,
.elf_target = EM_ARM,
},
};
#define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x)))
@ -1022,6 +1062,7 @@ generate_image (const char *dir, const char *prefix,
case IMAGE_SPARC64_RAW:
case IMAGE_I386_IEEE1275:
case IMAGE_PPC:
case IMAGE_UBOOT:
break;
}
@ -1684,6 +1725,9 @@ generate_image (const char *dir, const char *prefix,
core_size = program_size + header_size + footer_size;
}
break;
case IMAGE_UBOOT:
/* Raw image, header added by grub-install */
break;
}
grub_util_write_image (core_img, core_size, out, outname);

View file

@ -58,6 +58,11 @@
#error "I'm confused"
#endif
static Elf_Addr SUFFIX (entry_point);
grub_err_t reloc_thm_call (grub_uint16_t *addr, Elf32_Addr sym_addr);
grub_err_t reloc_thm_jump19 (grub_uint16_t *addr, Elf32_Addr sym_addr);
/* Relocate symbols; note that this function overwrites the symbol table.
Return the address of a start symbol. */
static Elf_Addr
@ -528,6 +533,48 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
}
break;
#endif
#if defined(MKIMAGE_ELF32)
case EM_ARM:
{
sym_addr += addend;
sym_addr -= SUFFIX (entry_point);
switch (ELF_R_TYPE (info))
{
case R_ARM_ABS32:
{
grub_util_info (" ABS32:\toffset=%d\t(0x%08x)",
(int) sym_addr, (int) sym_addr);
/* Data will be naturally aligned */
// sym_addr -= offset;
sym_addr += 0x400;
*target = grub_host_to_target32 (grub_target_to_host32 (*target) + sym_addr);
}
break;
case R_ARM_THM_CALL:
case R_ARM_THM_JUMP24:
{
grub_util_info (" THM_JUMP24:\ttarget=0x%08x\toffset=(0x%08x)", (unsigned int) target, sym_addr);
sym_addr -= offset;
/* Thumb instructions can be 16-bit aligned */
reloc_thm_call ((grub_uint16_t *) target, sym_addr);
}
break;
case R_ARM_THM_JUMP19:
{
grub_util_info (" THM_JUMP19:\toffset=%d\t(0x%08x)",
sym_addr, sym_addr);
sym_addr -= offset;
/* Thumb instructions can be 16-bit aligned */
reloc_thm_jump19 ((grub_uint16_t *) target, sym_addr);
}
break;
default:
grub_util_error (_("relocation 0x%x is not implemented yet!"), ELF_R_TYPE (info));
break;
}
break;
}
#endif /* MKIMAGE_ELF32 */
default:
grub_util_error ("unknown architecture type %d",
image_target->elf_target);
@ -755,6 +802,46 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
break;
}
break;
#if defined(MKIMAGE_ELF32)
case EM_ARM:
switch (ELF_R_TYPE (info))
{
/* Relative relocations do not require fixup entries. */
case R_ARM_JUMP24:
case R_ARM_THM_CALL:
case R_ARM_THM_JUMP19:
case R_ARM_THM_JUMP24:
{
Elf_Addr addr;
addr = section_address + offset;
grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) current_address);
}
break;
/* Create fixup entry for PE/COFF loader */
case R_ARM_ABS32:
{
Elf_Addr addr;
addr = section_address + offset;
#if 0
grub_util_info (" %s: add_fixup: 0x%08x : 0x%08x",
__FUNCTION__, (unsigned int) addr,
(unsigned int) current_address);
#endif
current_address
= SUFFIX (add_fixup_entry) (&lst,
GRUB_PE32_REL_BASED_HIGHLOW,
addr, 0, current_address,
image_target);
}
break;
default:
grub_util_error (_("relocation 0x%x is not implemented yet2"), ELF_R_TYPE (info));
break;
}
break;
#endif /* defined(MKIMAGE_ELF32) */
default:
grub_util_error ("unknown machine type 0x%x", image_target->elf_target);
}
@ -1065,6 +1152,8 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
if (*start == 0)
grub_util_error ("start symbol is not defined");
SUFFIX (entry_point) = (Elf_Addr) *start;
/* Resolve addresses in the virtual address space. */
SUFFIX (relocate_addresses) (e, sections, section_addresses,
section_entsize,

103
util/import_libfdt.py Normal file
View file

@ -0,0 +1,103 @@
#*
#* 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/>.
#*
import re
import sys
import os
import codecs
import datetime
if len (sys.argv) < 3:
print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])
exit (0)
dtcdir = sys.argv[1]
indir = os.path.join (dtcdir, "libfdt/")
outdir = os.path.join (sys.argv[2], "lib/dtc-grub/libfdt/")
try:
os.makedirs (outdir)
except:
print ("WARNING: %s already exists" % outdir)
conf = codecs.open (os.path.join ("grub-core/", "Makefile.libfdt.def"), "w", "utf-8")
conf.write ("AutoGen definitions Makefile.tpl;\n\n")
conf.write ("module = {\n")
conf.write (" name = fdt;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt.c;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt_ro.c;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt_rw.c;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt_strerror.c;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt_sw.c;\n")
conf.write (" common = lib/dtc-grub/libfdt/fdt_wip.c;\n")
conf.write (" cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_LIBFDT)';\n")
conf.write ("\n")
conf.write (" enable = fdt;\n")
conf.write ("};\n")
conf.close ();
libfdt_files = sorted (os.listdir (indir))
chlog = ""
for libfdt_file in libfdt_files:
infile = os.path.join (indir, (libfdt_file))
outfile = os.path.join (outdir, (libfdt_file))
if not re.match (".*\.[ch]$", libfdt_file):
chlog = "%s * %s: Removed\n" % (chlog, libfdt_file)
continue
# print ("file: %s, infile: %s, outfile: %s" % (libfdt_file, infile, outfile))
f = codecs.open (infile, "r", "utf-8")
fw = codecs.open (outfile, "w", "utf-8")
lineno = 1
fw.write ("/* This file was automatically imported with \n")
fw.write (" import_libfdt.py. Please don't modify it */\n")
fw.write ("#include <grub/dl.h>\n")
# libfdt is dual-licensed: BSD or GPLv2+
if re.match (".*\.c$", libfdt_file):
fw.write ("GRUB_MOD_LICENSE (\"GPLv2+\");\n")
lines = f.readlines()
for line in lines:
fw.write (line)
f.close ()
fw.close ()
patchfile = os.path.join (dtcdir, "libfdt-grub.diff")
#print "Patchfile: %s\n" % patchfile
ret = os.system("patch -d %s -p1 < %s" % (outdir, patchfile))
if ret:
chlog = "%s * Applied Grub build patch\n" % chlog
dt = datetime.date.today ()
fw = codecs.open (os.path.join (outdir, "ImportLog"), "w", "utf-8")
fw.write ("%04d-%02d-%02d Automatic import tool\n" % \
(dt.year,dt.month, dt.day))
fw.write ("\n")
fw.write (" Imported libfdt to GRUB\n")
fw.write ("\n")
fw.write (chlog)
fw.close ()