Blame SOURCES/0363-Implement-grub_machine_get_bootlocation-for-ARC.patch

f96e0b
From 081e3821a7800ef03e67788efd60fc86f18e645d Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sat, 27 Apr 2013 19:12:11 +0200
f96e0b
Subject: [PATCH 363/482] 	Implement grub_machine_get_bootlocation for
f96e0b
 ARC.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                            |   4 +
f96e0b
 grub-core/Makefile.core.def          |   1 +
f96e0b
 grub-core/boot/mips/startup_raw.S    |  22 ++++-
f96e0b
 grub-core/kern/mips/arc/init.c       | 167 +++++++++++++++++++++++++++++++++++
f96e0b
 grub-core/kern/mips/init.c           |   6 --
f96e0b
 grub-core/kern/mips/loongson/init.c  |   6 ++
f96e0b
 grub-core/kern/mips/qemu_mips/init.c |   6 ++
f96e0b
 util/grub-mkrescue.in                |   4 +-
f96e0b
 8 files changed, 207 insertions(+), 9 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 0d4329c..09a6c70 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,9 @@
f96e0b
 2013-04-27  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	Implement grub_machine_get_bootlocation for ARC.
f96e0b
+
f96e0b
+2013-04-27  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	Improve AHCI detection and command issuing.
f96e0b
 
f96e0b
 2013-04-26  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index 2a8ac6f..7f93723 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -76,6 +76,7 @@ kernel = {
f96e0b
   mips_arc_ldflags    = '-Wl,-Ttext,$(TARGET_LINK_ADDR)';
f96e0b
   mips_qemu_mips_ldflags    = '-Wl,-Ttext,0x80200000';
f96e0b
 
f96e0b
+  mips_arc_cppflags = '-DGRUB_DECOMPRESSOR_LINK_ADDR=$(TARGET_DECOMPRESSOR_LINK_ADDR)';
f96e0b
   mips_loongson_cppflags = '-DUSE_ASCII_FAILBACK';
f96e0b
   i386_qemu_cppflags     = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
f96e0b
   emu_cflags = '$(CFLAGS_GNULIB)';
f96e0b
diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S
f96e0b
index bbbc1db..6061976 100644
f96e0b
--- a/grub-core/boot/mips/startup_raw.S
f96e0b
+++ b/grub-core/boot/mips/startup_raw.S
f96e0b
@@ -197,6 +197,21 @@ argfw:
f96e0b
 	not $s7, $a2
f96e0b
 cmdlinedone:	
f96e0b
 #endif
f96e0b
+#ifdef GRUB_MACHINE_ARC
f96e0b
+	lui $t0, %hi(_start - 256)
f96e0b
+	addiu $t0, $t0, %lo(_start - 256)
f96e0b
+	addiu $t3, $t0, 255
f96e0b
+	lw $t1, 0($a1)
f96e0b
+1:	
f96e0b
+	bne $t0, $t3, 2f
f96e0b
+	 lb $t2, 0($t1)
f96e0b
+	move $t2, $zero
f96e0b
+2:
f96e0b
+	sb $t2, 0($t0)
f96e0b
+	addiu $t0, $t0, 1
f96e0b
+	bnez $t2, 1b
f96e0b
+	 addiu $t1, $t1, 1
f96e0b
+#endif
f96e0b
 	/* Copy the decompressor. */
f96e0b
 	lui $t1, %hi(base)
f96e0b
 	addiu $t1, $t1, %lo(base)
f96e0b
@@ -253,10 +268,15 @@ cmdlinedone:
f96e0b
 	lui $t0, %hi(EXT_C(grub_decompress_core))
f96e0b
 	addiu $t0, $t0, %lo(EXT_C(grub_decompress_core))
f96e0b
 
f96e0b
+#ifdef GRUB_MACHINE_ARC
f96e0b
+	lui $sp, %hi(_start - 512)
f96e0b
+	jalr $t0
f96e0b
+	 addiu $sp, $sp, %lo(_start - 512)
f96e0b
+#else
f96e0b
 	lui $sp, %hi(_start - 256)
f96e0b
 	jalr $t0
f96e0b
 	 addiu $sp, $sp, %lo(_start - 256)
f96e0b
-	
f96e0b
+#endif	
f96e0b
 	move $a0, $s1
f96e0b
 	move $a1, $s6
f96e0b
 
f96e0b
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
f96e0b
index 92a2877..d279ada 100644
f96e0b
--- a/grub-core/kern/mips/arc/init.c
f96e0b
+++ b/grub-core/kern/mips/arc/init.c
f96e0b
@@ -34,6 +34,8 @@
f96e0b
 #include <grub/arc/arc.h>
f96e0b
 #include <grub/offsets.h>
f96e0b
 #include <grub/i18n.h>
f96e0b
+#include <grub/disk.h>
f96e0b
+#include <grub/partition.h>
f96e0b
 
f96e0b
 const char *type_names[] = {
f96e0b
 #ifdef GRUB_CPU_WORDS_BIGENDIAN
f96e0b
@@ -164,10 +166,42 @@ grub_arc_alt_name_to_norm (const char *name, const char *suffix)
f96e0b
   return ret;
f96e0b
 }
f96e0b
 
f96e0b
+static char *
f96e0b
+norm_name_to_alt (const char *name)
f96e0b
+{
f96e0b
+  char *optr;
f96e0b
+  const char *iptr;
f96e0b
+  int state = 0;
f96e0b
+  char * ret = grub_malloc (grub_strlen (name) + sizeof ("arc/"));
f96e0b
+
f96e0b
+  if (!ret)
f96e0b
+    return NULL;
f96e0b
+  optr = grub_stpcpy (ret, "arc/");
f96e0b
+  for (iptr = name; *iptr; iptr++)
f96e0b
+    {
f96e0b
+      if (state == 1)
f96e0b
+	{
f96e0b
+	  *optr++ = '/';
f96e0b
+	  state = 0;
f96e0b
+	}
f96e0b
+      if (*iptr == '(')
f96e0b
+	continue;
f96e0b
+      if (*iptr == ')')
f96e0b
+	{
f96e0b
+	  state = 1;
f96e0b
+	  continue;
f96e0b
+	}
f96e0b
+      *optr++ = *iptr;
f96e0b
+    }
f96e0b
+  *optr = '\0';
f96e0b
+  return ret;
f96e0b
+}
f96e0b
+
f96e0b
 extern grub_uint32_t grub_total_modules_size __attribute__ ((section(".text")));
f96e0b
 grub_addr_t grub_modbase;
f96e0b
 
f96e0b
 extern char _end[];
f96e0b
+static char boot_location[256];
f96e0b
 
f96e0b
 void
f96e0b
 grub_machine_init (void)
f96e0b
@@ -175,6 +209,9 @@ grub_machine_init (void)
f96e0b
   struct grub_arc_memory_descriptor *cur = NULL;
f96e0b
   grub_addr_t modend;
f96e0b
 
f96e0b
+  grub_memcpy (boot_location,
f96e0b
+	       (char *) (GRUB_DECOMPRESSOR_LINK_ADDR - 256), 256);
f96e0b
+
f96e0b
   grub_modbase = ALIGN_UP ((grub_addr_t) _end, GRUB_KERNEL_MACHINE_MOD_ALIGN);
f96e0b
   modend = grub_modbase + grub_total_modules_size;
f96e0b
   grub_console_init_early ();
f96e0b
@@ -239,3 +276,133 @@ grub_exit (void)
f96e0b
   while (1);
f96e0b
 }
f96e0b
 
f96e0b
+static char *
f96e0b
+get_part (char *dev)
f96e0b
+{
f96e0b
+  char *ptr;
f96e0b
+  if (!*dev)
f96e0b
+    return 0;
f96e0b
+  ptr = dev + grub_strlen (dev) - 1;
f96e0b
+  if (ptr == dev || *ptr != ')')
f96e0b
+    return 0;
f96e0b
+  ptr--;
f96e0b
+  while (grub_isdigit (*ptr) && ptr > dev)
f96e0b
+    ptr--;
f96e0b
+  if (*ptr != '(' || ptr == dev)
f96e0b
+    return 0;
f96e0b
+  ptr--;
f96e0b
+  if (ptr - dev < (int) sizeof ("partition") - 2)
f96e0b
+    return 0;
f96e0b
+  ptr -= sizeof ("partition") - 2;
f96e0b
+  if (grub_memcmp (ptr, "partition", sizeof ("partition") - 1) != 0)
f96e0b
+    return 0;
f96e0b
+  return ptr;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_disk_addr_t
f96e0b
+get_partition_offset (char *part, grub_disk_addr_t *en)
f96e0b
+{
f96e0b
+  grub_arc_fileno_t handle;
f96e0b
+  grub_disk_addr_t ret = -1;
f96e0b
+  struct grub_arc_fileinfo info;
f96e0b
+  grub_arc_err_t r;
f96e0b
+
f96e0b
+  if (GRUB_ARC_FIRMWARE_VECTOR->open (part, GRUB_ARC_FILE_ACCESS_OPEN_RO,
f96e0b
+				      &handle))
f96e0b
+    return -1;
f96e0b
+
f96e0b
+  r = GRUB_ARC_FIRMWARE_VECTOR->getfileinformation (handle, &info;;
f96e0b
+  if (!r)
f96e0b
+    {
f96e0b
+      ret = (info.start >> 9);
f96e0b
+      *en = (info.end >> 9);
f96e0b
+    }
f96e0b
+  GRUB_ARC_FIRMWARE_VECTOR->close (handle);
f96e0b
+  return ret;
f96e0b
+}
f96e0b
+
f96e0b
+struct get_device_name_ctx
f96e0b
+{
f96e0b
+  char *partition_name;
f96e0b
+  grub_disk_addr_t poff, pend;
f96e0b
+};
f96e0b
+
f96e0b
+static int
f96e0b
+get_device_name_iter (grub_disk_t disk __attribute__ ((unused)),
f96e0b
+		      const grub_partition_t part, void *data)
f96e0b
+{
f96e0b
+  struct get_device_name_ctx *ctx = data;
f96e0b
+
f96e0b
+  if (grub_partition_get_start (part) == ctx->poff
f96e0b
+      && grub_partition_get_len (part) == ctx->pend)
f96e0b
+    {
f96e0b
+      ctx->partition_name = grub_partition_get_name (part);
f96e0b
+      return 1;
f96e0b
+    }
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+void
f96e0b
+grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
f96e0b
+			       char **path __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  char *loaddev = boot_location;
f96e0b
+  char *pptr, *partptr;
f96e0b
+  char *dname;
f96e0b
+  grub_disk_addr_t poff = -1, pend;
f96e0b
+  struct get_device_name_ctx ctx;
f96e0b
+  grub_disk_t parent = 0;
f96e0b
+
f96e0b
+  pptr = grub_strchr (loaddev, '/');
f96e0b
+  if (pptr)
f96e0b
+    {
f96e0b
+      *path = grub_strdup (pptr);
f96e0b
+      *pptr = '\0';
f96e0b
+    }
f96e0b
+  partptr = get_part (loaddev);
f96e0b
+  if (partptr)
f96e0b
+    {
f96e0b
+      poff = get_partition_offset (loaddev, &pend);
f96e0b
+      *partptr = '\0';
f96e0b
+    }
f96e0b
+  dname = norm_name_to_alt (loaddev);
f96e0b
+  if (poff == (grub_addr_t) -1)
f96e0b
+    {
f96e0b
+      *device = dname;
f96e0b
+      return;
f96e0b
+    }
f96e0b
+
f96e0b
+  parent = grub_disk_open (dname);
f96e0b
+  if (!parent)
f96e0b
+    {
f96e0b
+      *device = dname;
f96e0b
+      return;
f96e0b
+    }
f96e0b
+
f96e0b
+  if (poff == 0
f96e0b
+      && pend == grub_disk_get_size (parent))
f96e0b
+    {
f96e0b
+      grub_disk_close (parent);
f96e0b
+      *device = dname;
f96e0b
+      return;
f96e0b
+    }
f96e0b
+
f96e0b
+  ctx.partition_name = NULL;
f96e0b
+  ctx.poff = poff;
f96e0b
+  ctx.pend = pend;
f96e0b
+
f96e0b
+  grub_partition_iterate (parent, get_device_name_iter, &ctx;;
f96e0b
+  grub_disk_close (parent);
f96e0b
+
f96e0b
+  if (! ctx.partition_name)
f96e0b
+    {
f96e0b
+      *device = dname;
f96e0b
+      return;
f96e0b
+    }
f96e0b
+
f96e0b
+  *device = grub_xasprintf ("%s,%s", dname,
f96e0b
+			    ctx.partition_name);
f96e0b
+  grub_free (ctx.partition_name);
f96e0b
+  grub_free (dname);
f96e0b
+}
f96e0b
diff --git a/grub-core/kern/mips/init.c b/grub-core/kern/mips/init.c
f96e0b
index 353f679..14b8752 100644
f96e0b
--- a/grub-core/kern/mips/init.c
f96e0b
+++ b/grub-core/kern/mips/init.c
f96e0b
@@ -36,9 +36,3 @@ grub_get_rtc (void)
f96e0b
 
f96e0b
   return (((grub_uint64_t) high) << 32) | low;
f96e0b
 }
f96e0b
-
f96e0b
-void
f96e0b
-grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
f96e0b
-			       char **path __attribute__ ((unused)))
f96e0b
-{
f96e0b
-}
f96e0b
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
f96e0b
index 756439b..1abcf1a 100644
f96e0b
--- a/grub-core/kern/mips/loongson/init.c
f96e0b
+++ b/grub-core/kern/mips/loongson/init.c
f96e0b
@@ -259,6 +259,12 @@ grub_exit (void)
f96e0b
   grub_halt ();
f96e0b
 }
f96e0b
 
f96e0b
+void
f96e0b
+grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
f96e0b
+			       char **path __attribute__ ((unused)))
f96e0b
+{
f96e0b
+}
f96e0b
+
f96e0b
 extern char _end[];
f96e0b
 grub_addr_t grub_modbase = (grub_addr_t) _end;
f96e0b
 
f96e0b
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
f96e0b
index aa414eb..050f19f 100644
f96e0b
--- a/grub-core/kern/mips/qemu_mips/init.c
f96e0b
+++ b/grub-core/kern/mips/qemu_mips/init.c
f96e0b
@@ -98,6 +98,12 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
f96e0b
   return GRUB_ERR_NONE;
f96e0b
 }
f96e0b
 
f96e0b
+void
f96e0b
+grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
f96e0b
+			       char **path __attribute__ ((unused)))
f96e0b
+{
f96e0b
+}
f96e0b
+
f96e0b
 extern char _end[];
f96e0b
 grub_addr_t grub_modbase = (grub_addr_t) _end;
f96e0b
 
f96e0b
diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in
f96e0b
index cc072c2..f2b24b4 100644
f96e0b
--- a/util/grub-mkrescue.in
f96e0b
+++ b/util/grub-mkrescue.in
f96e0b
@@ -489,7 +489,7 @@ if [ -e "${iso9660_dir}"/boot/grub/sparc64-ieee1275/core.img ] && [ "$system_are
f96e0b
    grub_mkisofs_arguments="${grub_mkisofs_arguments} -G $sysarea_img -B , --grub2-sparc-core /boot/grub/sparc64-ieee1275/core.img"
f96e0b
 fi
f96e0b
 
f96e0b
-make_image "${arcs_dir}" mips-arc "${iso9660_dir}/boot/grub/mips-arc/core.img" ""
f96e0b
+make_image_fwdisk "${arcs_dir}" mips-arc "${iso9660_dir}/boot/grub/mips-arc/core.img" ""
f96e0b
 if [ -e "${iso9660_dir}/boot/grub/mips-arc/core.img" ]; then
f96e0b
    grub_mkisofs_arguments="${grub_mkisofs_arguments} /boot/grub/mips-arc/grub=${iso9660_dir}/boot/grub/mips-arc/core.img /boot/grub/mips-arc/sashARCS=${iso9660_dir}/boot/grub/mips-arc/core.img  /boot/grub/mips-arc/sash=${iso9660_dir}/boot/grub/mips-arc/core.img"
f96e0b
 fi
f96e0b
@@ -497,7 +497,7 @@ if [ -e "${iso9660_dir}/boot/grub/mips-arc/core.img" ] && [ "$system_area" = arc
f96e0b
    grub_mkisofs_arguments="${grub_mkisofs_arguments} -mips-boot /boot/grub/mips-arc/sashARCS -mips-boot /boot/grub/mips-arc/sash -mips-boot /boot/grub/mips-arc/grub"
f96e0b
 fi
f96e0b
 
f96e0b
-make_image "${arc_dir}" mipsel-arc "${iso9660_dir}/boot/grub/arc.exe" ""
f96e0b
+make_image_fwdisk "${arc_dir}" mipsel-arc "${iso9660_dir}/boot/grub/arc.exe" ""
f96e0b
 
f96e0b
 make_image "${mipsel_qemu_dir}" mipsel-qemu_mips-elf "${iso9660_dir}/boot/grub/roms/mipsel-qemu_mips.elf" "pata"
f96e0b
 if [ -e "${iso9660_dir}/boot/grub/roms/mipsel-qemu_mips.elf" ] && [ -d "${rom_directory}" ]; then
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b