View | Details | Raw Unified | Return to bug 273814 | Differences between
and this patch

Collapse All | Expand All

(-)b/sysutils/grub2-bhyve/Makefile (-1 / +1 lines)
Lines 1-7 Link Here
1
PORTNAME=	grub2-bhyve
1
PORTNAME=	grub2-bhyve
2
DISTVERSIONPREFIX=	v
2
DISTVERSIONPREFIX=	v
3
DISTVERSION=	0.40
3
DISTVERSION=	0.40
4
PORTREVISION=	10
4
PORTREVISION=	11
5
CATEGORIES=	sysutils
5
CATEGORIES=	sysutils
6
6
7
PATCH_SITES+=	https://github.com/grehan-freebsd/grub2-bhyve/commit/
7
PATCH_SITES+=	https://github.com/grehan-freebsd/grub2-bhyve/commit/
(-)b/sysutils/grub2-bhyve/files/patch-grub-core_loader_i386_bsd.c (+71 lines)
Added Link Here
1
--- grub-core/loader/i386/bsd.c.orig	2015-08-31 22:42:56 UTC
2
+++ grub-core/loader/i386/bsd.c
3
@@ -74,6 +74,7 @@ static struct grub_openbsd_ramdisk_descriptor openbsd_
4
 static grub_uint32_t openbsd_root;
5
 static struct grub_relocator *relocator = NULL;
6
 static struct grub_openbsd_ramdisk_descriptor openbsd_ramdisk;
7
+static grub_int32_t openbsd_force_legacy_console = 0;
8
 
9
 struct bsd_tag
10
 {
11
@@ -132,6 +133,7 @@ static const struct grub_arg_option openbsd_opts[] =
12
     {"config", 'c', 0, N_("Change configured devices."), 0, 0},
13
     {"single", 's', 0, N_("Boot into single mode."), 0, 0},
14
     {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
15
+    {"legacy", 'l', 0, N_("Use legacy boot structure."), 0, 0},
16
     {"root", 'r', 0, N_("Set root device."), "[sd|wd]XY", ARG_TYPE_STRING},
17
     {"serial", 'h', GRUB_ARG_OPTION_OPTIONAL, 
18
      N_("Use serial console."),
19
@@ -145,7 +147,7 @@ static const grub_uint32_t openbsd_flags[] =
20
 static const grub_uint32_t openbsd_flags[] =
21
 {
22
   OPENBSD_RB_ASKNAME, OPENBSD_RB_HALT, OPENBSD_RB_CONFIG,
23
-  OPENBSD_RB_SINGLE, OPENBSD_RB_KDB, 0
24
+  OPENBSD_RB_SINGLE, OPENBSD_RB_KDB, OPENBSD_RB_LEGACY, 0
25
 };
26
 
27
 #define OPENBSD_ROOT_ARG (ARRAY_SIZE (openbsd_flags) - 1)
28
@@ -811,6 +813,25 @@ grub_openbsd_boot (void)
29
   grub_err_t err;
30
   grub_size_t tag_buf_len;
31
 
32
+  if (openbsd_force_legacy_console || ! is_64bit ||
33
+      (openbsd_ramdisk.osrelease < 7003 && openbsd_ramdisk.osrelease > 0))
34
+    {
35
+      struct bsd_tag *tag;
36
+      for (tag = tags; tag; tag = tag->next)
37
+	if (tag->type == OPENBSD_BOOTARG_CONSOLE)
38
+	  {
39
+	    struct grub_openbsd_bootarg_console *s =
40
+	      (struct grub_openbsd_bootarg_console *) tag -> data;
41
+	    struct grub_openbsd_bootarg_console_legacy l_serial;
42
+	    grub_memset (&l_serial, 0, sizeof (l_serial));
43
+	    l_serial.device = s -> device;
44
+	    l_serial.speed = s -> speed;
45
+	    l_serial.addr = -1;
46
+	    grub_memcpy(tag -> data, &l_serial, sizeof(l_serial));
47
+	    tag -> len = sizeof(l_serial);
48
+	  }
49
+    }
50
+
51
   err = grub_bsd_add_mmap ();
52
   if (err)
53
     return err;
54
@@ -1644,6 +1665,9 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc
55
   else
56
     bootdev = 0;
57
 
58
+  openbsd_force_legacy_console = bootflags & OPENBSD_RB_LEGACY;
59
+  bootflags &= ~OPENBSD_RB_LEGACY;
60
+
61
   if (ctxt->state[OPENBSD_SERIAL_ARG].set)
62
     {
63
       struct grub_openbsd_bootarg_console serial;
64
@@ -1686,6 +1710,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc
65
       struct grub_openbsd_bootarg_console serial;
66
 
67
       grub_memset (&serial, 0, sizeof (serial));
68
+
69
       serial.device = (GRUB_OPENBSD_VGA_MAJOR << 8);
70
       grub_bsd_add_meta (OPENBSD_BOOTARG_CONSOLE, &serial, sizeof (serial));
71
       bootflags &= ~OPENBSD_RB_SERCONS;
(-)b/sysutils/grub2-bhyve/files/patch-grub-core_loader_i386_bsdXX.c (+170 lines)
Added Link Here
1
--- grub-core/loader/i386/bsdXX.c.orig	2015-08-31 22:42:56 UTC
2
+++ grub-core/loader/i386/bsdXX.c
3
@@ -521,17 +521,68 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
4
 				   struct grub_openbsd_ramdisk_descriptor *desc)
5
 {
6
   unsigned symoff, stroff, symsize, strsize, symentsize;
7
+  Elf_Shdr *rodata;
8
+  char *shdr = NULL;
9
 
10
   {
11
     grub_err_t err;
12
     Elf_Ehdr e;
13
-    Elf_Shdr *s;
14
-    char *shdr = NULL;
15
+    Elf_Shdr *s, *strtab;
16
+    char *strarr;
17
     
18
     err = read_headers (file, filename, &e, &shdr);
19
     if (err)
20
       return err;
21
 
22
+    for (s = (Elf_Shdr *) shdr;
23
+	 s < (Elf_Shdr *) (shdr + e.e_shnum * e.e_shentsize);
24
+	 s = (Elf_Shdr *) ((char *) s + e.e_shentsize))
25
+      if (s->sh_type == SHT_STRTAB)
26
+	break;
27
+    if (s >= (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize))
28
+      {
29
+	grub_free (shdr);
30
+	return GRUB_ERR_NONE;
31
+      }
32
+    strtab = s;
33
+
34
+    strarr = grub_malloc (strtab->sh_size);
35
+    if (!strarr)
36
+      {
37
+	grub_free (shdr);
38
+        return grub_errno;
39
+      }
40
+
41
+    if (grub_file_seek (file, strtab->sh_offset) == (grub_off_t) -1)
42
+      {
43
+	grub_free (strarr);
44
+	grub_free (shdr);
45
+	return grub_errno;
46
+      }
47
+    if (grub_file_read (file, strarr, strtab->sh_size) != (grub_ssize_t) strtab->sh_size)
48
+      {
49
+        grub_free (strarr);
50
+        grub_free (shdr);
51
+        if (! grub_errno)
52
+          return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
53
+			     filename);
54
+        return grub_errno;
55
+      }
56
+
57
+    for (s = (Elf_Shdr *) shdr;
58
+	 s < (Elf_Shdr *) (shdr + e.e_shnum * e.e_shentsize);
59
+	 s = (Elf_Shdr *) ((char *) s + e.e_shentsize))
60
+      if (s->sh_type == SHT_PROGBITS &&
61
+	  grub_strcmp(&strarr[s->sh_name], ".rodata") == 0)
62
+	break;
63
+    grub_free (strarr);
64
+    if (s >= (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize))
65
+      {
66
+	grub_free (shdr);
67
+	return GRUB_ERR_NONE;
68
+      }
69
+    rodata = s;
70
+
71
     for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) (shdr
72
 						  + e.e_shnum * e.e_shentsize);
73
 	 s = (Elf_Shdr *) ((char *) s + e.e_shentsize))
74
@@ -550,24 +601,26 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
75
     s = (Elf_Shdr *) (shdr + e.e_shentsize * s->sh_link);
76
     stroff = s->sh_offset;
77
     strsize = s->sh_size;
78
-    grub_free (shdr);
79
   }
80
   {
81
-    Elf_Sym *syms, *sym, *imagesym = NULL, *sizesym = NULL;
82
+    Elf_Sym *syms, *sym, *imagesym = NULL, *sizesym = NULL, *osrelsym = NULL;
83
     unsigned i;
84
     char *strs;
85
 
86
     syms = grub_malloc (symsize);
87
-    if (!syms)
88
+    if (!syms) {
89
+      grub_free (shdr);
90
       return grub_errno;
91
-
92
+    }
93
     if (grub_file_seek (file, symoff) == (grub_off_t) -1)
94
       {
95
+        grub_free (shdr);
96
 	grub_free (syms);
97
 	return grub_errno;
98
       }
99
     if (grub_file_read (file, syms, symsize) != (grub_ssize_t) symsize)
100
       {
101
+        grub_free (shdr);
102
 	grub_free (syms);
103
 	if (! grub_errno)
104
 	  return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
105
@@ -578,6 +631,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
106
     strs = grub_malloc (strsize);
107
     if (!strs)
108
       {
109
+	grub_free (shdr);
110
 	grub_free (syms);
111
 	return grub_errno;
112
       }
113
@@ -586,6 +640,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
114
       return grub_errno;
115
     if (grub_file_read (file, strs, strsize) != (grub_ssize_t) strsize)
116
       {
117
+	grub_free (shdr);
118
 	grub_free (syms);
119
 	grub_free (strs);
120
 	if (! grub_errno)
121
@@ -605,9 +660,48 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
122
 	  imagesym = sym;
123
 	if (grub_strcmp (strs + sym->st_name, "rd_root_size") == 0)
124
 	  sizesym = sym;
125
-	if (imagesym && sizesym)
126
+	if (grub_strcmp (strs + sym->st_name, "osrelease") == 0)
127
+	  osrelsym = sym;
128
+	if (imagesym && sizesym && osrelsym)
129
 	  break;
130
       }
131
+    if (osrelsym) {
132
+      char *p;
133
+      int major, minor;
134
+      grub_size_t sz;
135
+      char osrel[16];
136
+      stroff = ((osrelsym->st_value - rodata->sh_addr) + rodata->sh_offset);
137
+      if (grub_file_seek (file, stroff) == (grub_off_t) -1) {
138
+        grub_free (shdr);
139
+	grub_free (syms);
140
+	grub_free (strs);
141
+        return grub_errno;
142
+      }
143
+      sz = sizeof(osrel) < osrelsym->st_size ? sizeof(osrel) : osrelsym->st_size;
144
+      if (grub_file_read (file, osrel, sz) != (grub_ssize_t) sz) {
145
+        grub_free (shdr);
146
+	grub_free (syms);
147
+	grub_free (strs);
148
+        return grub_errno;
149
+      }
150
+      osrel[sz - 1] = '\0';
151
+      major = minor = 0;
152
+      for (p = osrel; *p != '\0'; p++)
153
+        if (*p >= '0' && *p <= '9')
154
+          major = major * 10 + *p - '0';
155
+        else
156
+          break;
157
+      if (*p == '.')
158
+        p++;
159
+      for (; *p != '\0'; p++)
160
+        if (*p >= '0' && *p <= '9')
161
+           minor = minor * 10 + *p - '0';
162
+        else
163
+          break;
164
+      desc->osrelease = major * 1000 + minor;
165
+      grub_free (shdr);
166
+    }
167
+
168
     if (!imagesym || !sizesym)
169
       {
170
 	grub_free (syms);
(-)b/sysutils/grub2-bhyve/files/patch-include_grub_i386_bsd.h (+10 lines)
Added Link Here
1
--- include/grub/i386/bsd.h.orig	2015-08-31 22:42:56 UTC
2
+++ include/grub/i386/bsd.h
3
@@ -108,6 +108,7 @@ struct grub_openbsd_ramdisk_descriptor
4
   grub_size_t max_size;
5
   grub_uint8_t *target;
6
   grub_uint32_t *size;
7
+  grub_uint32_t osrelease;
8
 };
9
 
10
 grub_err_t grub_openbsd_find_ramdisk32 (grub_file_t file,
(-)b/sysutils/grub2-bhyve/files/patch-include_grub_i386_openbsd__bootarg.h (+35 lines)
Added Link Here
1
--- include/grub/i386/openbsd_bootarg.h.orig	2015-08-31 22:42:56 UTC
2
+++ include/grub/i386/openbsd_bootarg.h
3
@@ -63,6 +63,7 @@
4
 #define	OPENBSD_BOOTARG_MMAP	0
5
 #define	OPENBSD_BOOTARG_PCIBIOS 4
6
 #define	OPENBSD_BOOTARG_CONSOLE 5
7
+#define	OPENBSD_BOOTARG_CONSOLE_LEGACY 6
8
 
9
 struct grub_openbsd_bootargs
10
 {
11
@@ -71,12 +72,23 @@ struct grub_openbsd_bootargs
12
   grub_uint32_t ba_next;
13
 } __attribute__ ((packed));
14
 
15
-struct grub_openbsd_bootarg_console
16
+struct grub_openbsd_bootarg_console_legacy
17
 {
18
   grub_uint32_t device;
19
   grub_uint32_t speed;
20
   grub_int32_t  addr;
21
   grub_uint32_t freq;
22
+};
23
+
24
+struct grub_openbsd_bootarg_console
25
+{
26
+  grub_uint32_t device;
27
+  grub_uint32_t speed;
28
+  grub_uint64_t addr;
29
+  grub_int32_t  freq;
30
+  grub_uint32_t flags;
31
+  grub_int32_t  reg_width;
32
+  grub_int32_t  reg_shift;
33
 };
34
 
35
 struct grub_openbsd_bootarg_pcibios
(-)b/sysutils/grub2-bhyve/files/patch-include_grub_i386_openbsd__reboot.h (+10 lines)
Added Link Here
1
--- include/grub/i386/openbsd_reboot.h.orig	2015-08-31 22:42:56 UTC
2
+++ include/grub/i386/openbsd_reboot.h
3
@@ -68,6 +68,7 @@
4
 #define OPENBSD_RB_POWERDOWN	(1 << 12) /* attempt to power down machine */
5
 #define OPENBSD_RB_SERCONS	(1 << 13) /* use serial console if available */
6
 #define OPENBSD_RB_USERREQ	(1 << 14) /* boot() called at user request (e.g. ddb) */
7
+#define OPENBSD_RB_LEGACY	(1 << 31) /* Use legacy serial console structure */
8
 
9
 #define OPENBSD_B_DEVMAGIC	0xa0000000
10
 #define OPENBSD_B_ADAPTORSHIFT	24

Return to bug 273814