Re: [PATCH v5] ofdisk: add sas disks to the device list

2015-11-12 Thread Paulo Flabiano Smorigo
On Wed, Nov 11, 2015 at 11:39 PM, Vladimir 'phcoder' Serbinenko
 wrote:
> Other than small comment inline go ahead
>
> Le 12 nov. 2015 1:36 AM, "Paulo Flabiano Smorigo"
>  a écrit :
>
>>
>
>> Changes:
>
>> - using sizeof ("/disk@7766554433221100");
>
>> - grub_uint64_t *table;
>
>> +  grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"),
>
>> +"/disk@%" PRIxGRUB_UINT64_T, *(table + i));
>
> table[i] is cleaner

Changed and commited:
http://git.savannah.gnu.org/cgit/grub.git/commit/?id=c899d9f42c543939abc92d79c9729d429740492e

Thanks!

>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v5] ofdisk: add sas disks to the device list

2015-11-11 Thread Paulo Flabiano Smorigo
Changes:
- using sizeof ("/disk@7766554433221100");
- grub_uint64_t *table;

---
 grub-core/disk/ieee1275/ofdisk.c | 76 
 1 file changed, 76 insertions(+)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 297f058..b1f7c56 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   grub_free (buf);
   return;
 }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+{
+  /* The method returns the number of disks and a table where
+   * each ID is 64-bit long. Example of sas paths:
+   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
+
+  struct sas_children
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t max;
+  grub_ieee1275_cell_t table;
+  grub_ieee1275_cell_t catch_result;
+  grub_ieee1275_cell_t nentries;
+}
+  args;
+  char *buf, *bufptr;
+  unsigned i;
+  grub_uint64_t *table;
+  grub_uint16_t table_size;
+  grub_ieee1275_ihandle_t ihandle;
+
+  buf = grub_malloc (grub_strlen (alias->path) +
+ sizeof ("/disk@7766554433221100"));
+  if (!buf)
+return;
+  bufptr = grub_stpcpy (buf, alias->path);
+
+  /* Power machines documentation specify 672 as maximum SAS disks in
+ one system. Using a slightly larger value to be safe. */
+  table_size = 768;
+  table = grub_malloc (table_size * sizeof (grub_uint64_t));
+
+  if (!table)
+{
+  grub_free (buf);
+  return;
+}
+
+  if (grub_ieee1275_open (alias->path, &ihandle))
+{
+  grub_free (buf);
+  grub_free (table);
+  return;
+}
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+  args.method = (grub_ieee1275_cell_t) "get-sas-children";
+  args.ihandle = ihandle;
+  args.max = table_size;
+  args.table = (grub_ieee1275_cell_t) table;
+  args.catch_result = 0;
+  args.nentries = 0;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+{
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+  return;
+}
+
+  for (i = 0; i < args.nentries; i++)
+{
+  grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"),
+"/disk@%" PRIxGRUB_UINT64_T, *(table + i));
+  dev_iterate_real (buf, buf);
+}
+
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+}
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
   && grub_strcmp (alias->type, "block") == 0)
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v4] ofdisk: add sas disks to the device list

2015-11-11 Thread Paulo Flabiano Smorigo
Yes, that could be an option. phcoder, can I commit using andrei's approach?
--
P. F. Smorigo


On Wed, Nov 11, 2015 at 3:28 PM, Andrei Borzenkov  wrote:
> 11.11.2015 16:14, Paulo Flabiano Smorigo пишет:
>
>> Same patch with the fix.
>> ---
>>   grub-core/disk/ieee1275/ofdisk.c | 75
>> 
>>   1 file changed, 75 insertions(+)
>>
>> diff --git a/grub-core/disk/ieee1275/ofdisk.c
>> b/grub-core/disk/ieee1275/ofdisk.c
>> index 297f058..ef290bc 100644
>> --- a/grub-core/disk/ieee1275/ofdisk.c
>> +++ b/grub-core/disk/ieee1275/ofdisk.c
>> @@ -260,6 +260,81 @@ dev_iterate (const struct grub_ieee1275_devalias
>> *alias)
>> grub_free (buf);
>> return;
>>   }
>> +  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
>> +{
>> +  /* The method returns the number of disks and a table where
>> +   * each ID is 64-bit long. Example of sas paths:
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
>> +
>> +  struct sas_children
>> +{
>> +  struct grub_ieee1275_common_hdr common;
>> +  grub_ieee1275_cell_t method;
>> +  grub_ieee1275_cell_t ihandle;
>> +  grub_ieee1275_cell_t max;
>> +  grub_ieee1275_cell_t table;
>> +  grub_ieee1275_cell_t catch_result;
>> +  grub_ieee1275_cell_t nentries;
>> +}
>> +  args;
>> +  char *buf, *bufptr, *table;
>> +  unsigned i;
>> +  grub_uint16_t table_size;
>> +  grub_ieee1275_ihandle_t ihandle;
>> +
>> +  buf = grub_malloc (grub_strlen (alias->path) + 32);
>
>
> Actually I liked previous version more :) Magic hidden constants are always
> error prone.
>
>
>> +  if (!buf)
>> +return;
>> +  bufptr = grub_stpcpy (buf, alias->path);
>> +
>> +  /* Power machines documentation specify 672 as maximum SAS disks in
>> + one system. Using a slightly larger value to be safe. */
>> +  table_size = 768;
>> +  table = grub_malloc (table_size * sizeof (grub_uint64_t));
>> +
>> +  if (!table)
>> +{
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  if (grub_ieee1275_open (alias->path, &ihandle))
>> +{
>> +  grub_free (buf);
>> +  grub_free (table);
>> +  return;
>> +}
>> +
>> +  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
>> +  args.method = (grub_ieee1275_cell_t) "get-sas-children";
>> +  args.ihandle = ihandle;
>> +  args.max = table_size;
>> +  args.table = (grub_ieee1275_cell_t) table;
>> +  args.catch_result = 0;
>> +  args.nentries = 0;
>> +
>> +  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
>> +{
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  grub_uint64_t *ptr;
>> +  for (i = 0; i < args.nentries; i++)
>> +{
>> +  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
>> +  grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
>
>
> What about
>
> grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"), ... )
>
>> +  dev_iterate_real (buf, buf);
>> +}
>> +
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +}
>>
>> if (!grub_ieee1275_test_flag
>> (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
>> && grub_strcmp (alias->type, "block") == 0)
>>
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v4] ofdisk: add sas disks to the device list

2015-11-11 Thread Paulo Flabiano Smorigo
Same patch with the fix.
---
 grub-core/disk/ieee1275/ofdisk.c | 75 
 1 file changed, 75 insertions(+)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 297f058..ef290bc 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -260,6 +260,81 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   grub_free (buf);
   return;
 }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+{
+  /* The method returns the number of disks and a table where
+   * each ID is 64-bit long. Example of sas paths:
+   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
+
+  struct sas_children
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t max;
+  grub_ieee1275_cell_t table;
+  grub_ieee1275_cell_t catch_result;
+  grub_ieee1275_cell_t nentries;
+}
+  args;
+  char *buf, *bufptr, *table;
+  unsigned i;
+  grub_uint16_t table_size;
+  grub_ieee1275_ihandle_t ihandle;
+
+  buf = grub_malloc (grub_strlen (alias->path) + 32);
+  if (!buf)
+return;
+  bufptr = grub_stpcpy (buf, alias->path);
+
+  /* Power machines documentation specify 672 as maximum SAS disks in
+ one system. Using a slightly larger value to be safe. */
+  table_size = 768;
+  table = grub_malloc (table_size * sizeof (grub_uint64_t));
+
+  if (!table)
+{
+  grub_free (buf);
+  return;
+}
+
+  if (grub_ieee1275_open (alias->path, &ihandle))
+{
+  grub_free (buf);
+  grub_free (table);
+  return;
+}
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+  args.method = (grub_ieee1275_cell_t) "get-sas-children";
+  args.ihandle = ihandle;
+  args.max = table_size;
+  args.table = (grub_ieee1275_cell_t) table;
+  args.catch_result = 0;
+  args.nentries = 0;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+{
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+  return;
+}
+
+  grub_uint64_t *ptr;
+  for (i = 0; i < args.nentries; i++)
+{
+  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+  grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+  dev_iterate_real (buf, buf);
+}
+
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+}
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
   && grub_strcmp (alias->type, "block") == 0)
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] ofdisk: allocate space for vscsi table

2015-11-10 Thread Paulo Flabiano Smorigo
On Mon, Nov 9, 2015 at 2:49 PM, Vladimir 'phcoder' Serbinenko
 wrote:
>
> Le 9 nov. 2015 5:34 PM, "Paulo Flabiano Smorigo"  a
> écrit :
>>
>> On Mon, Nov 9, 2015 at 10:03 AM, Vladimir 'phcoder' Serbinenko
>>  wrote:
>> >
>> > Le 9 nov. 2015 1:00 PM, "Paulo Flabiano Smorigo"  a
>> > écrit :
>> >>
>> >> On Mon, Nov 9, 2015 at 8:46 AM, Vladimir 'φ-coder/phcoder' Serbinenko
>> >>  wrote:
>> >> > On 09.11.2015 02:33, Paulo Flabiano Smorigo wrote:
>> >> >> +  /* 64 entries should be enough */
>> >> >> +  table_size = sizeof (grub_uint64_t) * 64;
>> >> > Can we do something better than assuming a particular upper limit?
>> >> > You
>> >> > don't even pass this limit to the function in any way. You basically
>> >> > get
>> >> > a buffer overflow. Should we perhaps pass the limit in nentries? Or
>> >> > do
>> >> > something similar?
>> >>
>> >> For sas there is an input attribute called max that I use as an upper
>> >> limit. AFAIK, vscsi method doesn't have it. nentries is a output
>> >> attribute.
>> >>
>> >> I'll investigate it.
>> >>
>> > Can't we just properly free returned memory? Or perhaps even just
>> > tolerate
>> > the leak and only ensure that it happens only once per controller per
>> > GRUB
>> > run?
>>
>> Talked to the Open firmware team and we don't need to allocate the
>> space. The vscsi implementation takes care of all of the memory
>> management. The result of the call stays in a reserved memory and is
>> never freed.
>>
>> For vscsi-report-luns method there are no input values.
>>
>> So, this patch isn't necessary. Should I put this info as a comment in the
>> code?
>>
> Sure, add this as a comment

Done. Commit ID: a50dbb743e53e5e643f27daa84261e6e9d7747c1

>> >> >
>> >> >
>> >> > ___
>> >> > Grub-devel mailing list
>> >> > Grub-devel@gnu.org
>> >> > https://lists.gnu.org/mailman/listinfo/grub-devel
>> >> >
>> >>
>> >> ___
>> >> Grub-devel mailing list
>> >> Grub-devel@gnu.org
>> >> https://lists.gnu.org/mailman/listinfo/grub-devel
>> >
>> >
>> > ___
>> > Grub-devel mailing list
>> > Grub-devel@gnu.org
>> > https://lists.gnu.org/mailman/listinfo/grub-devel
>> >
>>
>> ___
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3] ofdisk: add sas disks to the device list

2015-11-10 Thread Paulo Flabiano Smorigo
Same patch with the fixes.

---
 grub-core/disk/ieee1275/ofdisk.c | 77 
 1 file changed, 77 insertions(+)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 297f058..8caca16 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -260,6 +260,83 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   grub_free (buf);
   return;
 }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+{
+  /* The method returns the number of disks and a table where
+   * each ID is 64-bit long. Example of sas paths:
+   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
+
+  struct sas_children
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t max;
+  grub_ieee1275_cell_t table;
+  grub_ieee1275_cell_t catch_result;
+  grub_ieee1275_cell_t nentries;
+}
+  args;
+  char *buf, *bufptr, *table;
+  unsigned i;
+  grub_uint16_t table_size;
+  grub_ieee1275_ihandle_t ihandle;
+
+  buf = grub_malloc (grub_strlen (alias->path)
+ + sizeof ("/disk@7766554433221100"));
+  if (!buf)
+return;
+
+  /* Power machines documentation specify 672 as maximum SAS disks in
+ one system. Using a slightly larger value to be safe. */
+  table_size = 768;
+  table = grub_malloc (table_size * sizeof (grub_uint64_t));
+
+  if (!table)
+{
+  grub_free (buf);
+  return;
+}
+
+  bufptr = grub_stpcpy (buf, alias->path);
+
+  if (grub_ieee1275_open (alias->path, &ihandle))
+{
+  grub_free (buf);
+  grub_free (table);
+  return;
+}
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+  args.method = (grub_ieee1275_cell_t) "get-sas-children";
+  args.ihandle = ihandle;
+  args.max = table_size;
+  args.table = (grub_ieee1275_cell_t) table;
+  args.catch_result = 0;
+  args.nentries = 0;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+{
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+  return;
+}
+
+  grub_uint64_t *ptr;
+  for (i = 0; i < args.nentries; i++)
+{
+  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+  grub_snprintf (bufptr, 64, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+  dev_iterate_real (buf, buf);
+}
+
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+}
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
   && grub_strcmp (alias->type, "block") == 0)
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] ofdisk: add sas disks to the device list

2015-11-09 Thread Paulo Flabiano Smorigo
On Mon, Nov 9, 2015 at 10:01 AM, Vladimir 'phcoder' Serbinenko
 wrote:
>
> Le 9 nov. 2015 8:39 AM, "Paulo Flabiano Smorigo"
>  a écrit :
>>
>> All SAS disks attached will be added to the device list. This is the
>> second
>> version of a patch that I send a while ago [1].
>>
>> [1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg0.html
>>
>> ---
>>  grub-core/disk/ieee1275/ofdisk.c | 76
>> 
>>  1 file changed, 76 insertions(+)
>>
>> diff --git a/grub-core/disk/ieee1275/ofdisk.c
>> b/grub-core/disk/ieee1275/ofdisk.c
>> index 297f058..afec9ba 100644
>> --- a/grub-core/disk/ieee1275/ofdisk.c
>> +++ b/grub-core/disk/ieee1275/ofdisk.c
>> @@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias
>> *alias)
>>grub_free (buf);
>>return;
>>  }
>> +  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
>> +{
>> +  /* The method returns the number of disks and a table where
>> +   * each ID is 64-bit long. Example of sas paths:
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
>> +
>> +  struct sas_children
>> +{
>> +  struct grub_ieee1275_common_hdr common;
>> +  grub_ieee1275_cell_t method;
>> +  grub_ieee1275_cell_t ihandle;
>> +  grub_ieee1275_cell_t max;
>> +  grub_ieee1275_cell_t table;
>> +  grub_ieee1275_cell_t catch_result;
>> +  grub_ieee1275_cell_t nentries;
>> +}
>> +  args;
>> +  char *buf, *bufptr, *table;
>> +  unsigned i;
>> +  grub_uint32_t table_size;
>> +  grub_ieee1275_ihandle_t ihandle;
>> +
>> +  buf = grub_malloc (grub_strlen (alias->path)
>> + + sizeof ("/disk@7766554433221100"));
>> +  if (!buf)
>> +return;
>> +
>> +  /* 64 entries should be enough */
> Why? Sounds like an arbitrary limit. What does OF call return when it's not
> true? Does it set nentries to total or to how much it has really provided?

Asked the Open firmware development team...

The maximum value for max is 0x but this is a very high number IMHO.

About the limit, if there are more entries than will fit in the buffer
provided, you will only get up to that number. The return value is the
number in the buffer.

I tested here using max = 4 and nentries was 4. The table only had 4
entries as well.

>> +  table_size = sizeof (grub_uint64_t) * 64;
>> +  table = grub_malloc (table_size);
>> +
>> +  if (!table)
>> +{
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  bufptr = grub_stpcpy (buf, alias->path);
>> +
>> +  if (grub_ieee1275_open (alias->path, &ihandle))
>> +{
>> +  grub_free (buf);
>> +  grub_free (table);
>> +  return;
>> +}
>> +
>> +  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
>> +  args.method = (grub_ieee1275_cell_t) "get-sas-children";
>> +  args.ihandle = ihandle;
>> +  args.max = table_size;
> Please double check that this field is in bytes.

My fault. it's entries, not bytes. Will fix it.

>> +  args.table = (grub_ieee1275_cell_t) table;
>> +  args.catch_result = 0;
>> +  args.nentries = 0;
>> +
>> +  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
>> +{
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  grub_uint64_t *ptr;
>> +  for (i = 0; i < args.nentries; i++)
>> +{
>> +  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
>> +  grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
> This 32 doesn't match the above allocation.

Ok.

>> +  dev_iterate_real (buf, buf);
>> +}
>> +
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +}
>>
>>if (!grub_ieee1275_test_flag
>> (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
>>&& grub_strcmp (alias->type, "block") == 0)
>> --
>> 2.1.0
>>
>>
>> ___
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] ofdisk: allocate space for vscsi table

2015-11-09 Thread Paulo Flabiano Smorigo
On Mon, Nov 9, 2015 at 10:03 AM, Vladimir 'phcoder' Serbinenko
 wrote:
>
> Le 9 nov. 2015 1:00 PM, "Paulo Flabiano Smorigo"  a
> écrit :
>>
>> On Mon, Nov 9, 2015 at 8:46 AM, Vladimir 'φ-coder/phcoder' Serbinenko
>>  wrote:
>> > On 09.11.2015 02:33, Paulo Flabiano Smorigo wrote:
>> >> +  /* 64 entries should be enough */
>> >> +  table_size = sizeof (grub_uint64_t) * 64;
>> > Can we do something better than assuming a particular upper limit? You
>> > don't even pass this limit to the function in any way. You basically get
>> > a buffer overflow. Should we perhaps pass the limit in nentries? Or do
>> > something similar?
>>
>> For sas there is an input attribute called max that I use as an upper
>> limit. AFAIK, vscsi method doesn't have it. nentries is a output
>> attribute.
>>
>> I'll investigate it.
>>
> Can't we just properly free returned memory? Or perhaps even just tolerate
> the leak and only ensure that it happens only once per controller per GRUB
> run?

Talked to the Open firmware team and we don't need to allocate the
space. The vscsi implementation takes care of all of the memory
management. The result of the call stays in a reserved memory and is
never freed.

For vscsi-report-luns method there are no input values.

So, this patch isn't necessary. Should I put this info as a comment in the code?

>> >
>> >
>> > ___
>> > Grub-devel mailing list
>> > Grub-devel@gnu.org
>> > https://lists.gnu.org/mailman/listinfo/grub-devel
>> >
>>
>> ___
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] ofdisk: allocate space for vscsi table

2015-11-09 Thread Paulo Flabiano Smorigo
On Mon, Nov 9, 2015 at 8:46 AM, Vladimir 'φ-coder/phcoder' Serbinenko
 wrote:
> On 09.11.2015 02:33, Paulo Flabiano Smorigo wrote:
>> +  /* 64 entries should be enough */
>> +  table_size = sizeof (grub_uint64_t) * 64;
> Can we do something better than assuming a particular upper limit? You
> don't even pass this limit to the function in any way. You basically get
> a buffer overflow. Should we perhaps pass the limit in nentries? Or do
> something similar?

For sas there is an input attribute called max that I use as an upper
limit. AFAIK, vscsi method doesn't have it. nentries is a output
attribute.

I'll investigate it.

>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] ofdisk: add sas disks to the device list

2015-11-09 Thread Paulo Flabiano Smorigo
On Mon, Nov 9, 2015 at 2:18 AM, Andrei Borzenkov  wrote:
> 09.11.2015 04:29, Paulo Flabiano Smorigo пишет:
>>
>> All SAS disks attached will be added to the device list. This is the
>> second
>> version of a patch that I send a while ago [1].
>>
>> [1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg0.html
>>
>> ---
>>   grub-core/disk/ieee1275/ofdisk.c | 76
>> 
>>   1 file changed, 76 insertions(+)
>>
>> diff --git a/grub-core/disk/ieee1275/ofdisk.c
>> b/grub-core/disk/ieee1275/ofdisk.c
>> index 297f058..afec9ba 100644
>> --- a/grub-core/disk/ieee1275/ofdisk.c
>> +++ b/grub-core/disk/ieee1275/ofdisk.c
>> @@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias
>> *alias)
>> grub_free (buf);
>> return;
>>   }
>> +  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
>> +{
>> +  /* The method returns the number of disks and a table where
>> +   * each ID is 64-bit long. Example of sas paths:
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
>> +   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
>
>
> Did you omit last 3 bytes on purpose?
>
> Out of curiosity - is it really true that SAS address is written backwards
> (at least, I assume this is SAS address)?

The 3 missing bytes are leading zeros that it's not used in the path.

This is the table that I got:

00 00 00 00 c0 5d b7 08 00 00 00 00 a0 5d b7 08 00
10 00 00 00 80 5d b7 08 00 00 00 00 60 5d b7 08 00
20 00 00 00 40 5d b7 08 00 00 00 00 20 5d b7 08 00
30 50 05 07 60 64 79 f9 01 00 00 00 00 00 00 00 00
40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...

It's not backwards, each address has a space between them. It's exactly 128GB:

>>> (0xc05db70800-0xa05db70800)/(1024.**3)
128.0

>
>
>> +
>> +  struct sas_children
>> +{
>> +  struct grub_ieee1275_common_hdr common;
>> +  grub_ieee1275_cell_t method;
>> +  grub_ieee1275_cell_t ihandle;
>> +  grub_ieee1275_cell_t max;
>> +  grub_ieee1275_cell_t table;
>> +  grub_ieee1275_cell_t catch_result;
>> +  grub_ieee1275_cell_t nentries;
>> +}
>> +  args;
>> +  char *buf, *bufptr, *table;
>> +  unsigned i;
>> +  grub_uint32_t table_size;
>> +  grub_ieee1275_ihandle_t ihandle;
>> +
>> +  buf = grub_malloc (grub_strlen (alias->path)
>> + + sizeof ("/disk@7766554433221100"));
>> +  if (!buf)
>> +return;
>> +
>> +  /* 64 entries should be enough */
>> +  table_size = sizeof (grub_uint64_t) * 64;
>> +  table = grub_malloc (table_size);
>> +
>> +  if (!table)
>> +{
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  bufptr = grub_stpcpy (buf, alias->path);
>> +
>> +  if (grub_ieee1275_open (alias->path, &ihandle))
>> +{
>> +  grub_free (buf);
>> +  grub_free (table);
>> +  return;
>> +}
>> +
>> +  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
>> +  args.method = (grub_ieee1275_cell_t) "get-sas-children";
>> +  args.ihandle = ihandle;
>> +  args.max = table_size;
>> +  args.table = (grub_ieee1275_cell_t) table;
>> +  args.catch_result = 0;
>> +  args.nentries = 0;
>> +
>> +  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
>> +{
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +  return;
>> +}
>> +
>> +  grub_uint64_t *ptr;
>> +  for (i = 0; i < args.nentries; i++)
>> +{
>> +  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
>> +  grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
>> +  dev_iterate_real (buf, buf);
>> +}
>> +
>> +  grub_ieee1275_close (ihandle);
>> +  grub_free (table);
>> +  grub_free (buf);
>> +}
>>
>> if (!grub_ieee1275_test_flag
>> (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
>> && grub_strcmp (alias->type, "block") == 0)
>>
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] ofdisk: allocate space for vscsi table

2015-11-08 Thread Paulo Flabiano Smorigo
The table must be allocated in order to avoid memory leak. Also added some
vscsi paths for illustration purpose.

---
 grub-core/disk/ieee1275/ofdisk.c | 30 +-
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index afec9ba..4ea6089 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -211,6 +211,11 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
 {
   if (grub_strcmp (alias->type, "vscsi") == 0)
 {
+  /* Example of vscsi paths:
+   *  /vdevice/v-scsi@3002/disk@8100
+   *  /vdevice/v-scsi@3002/disk@8200
+   *  /vdevice/v-scsi@3002/disk@8400  */
+
   static grub_ieee1275_ihandle_t ihandle;
   struct set_color_args
   {
@@ -222,27 +227,41 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
grub_ieee1275_cell_t table;
   }
   args;
-  char *buf, *bufptr;
+  char *buf, *bufptr, *table;
   unsigned i;
+  grub_uint32_t table_size;
 
   if (grub_ieee1275_open (alias->path, &ihandle))
return;
-
+
+  /* 64 entries should be enough */
+  table_size = sizeof (grub_uint64_t) * 64;
+  table = grub_malloc (table_size);
+
+  if (!table)
+   return;
+
   INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
   args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
   args.ihandle = ihandle;
-  args.table = 0;
+  args.table = (grub_ieee1275_cell_t) table;
   args.nentries = 0;
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result)
{
  grub_ieee1275_close (ihandle);
- return;
+  grub_free (table);
+  return;
}
 
   buf = grub_malloc (grub_strlen (alias->path) + 32);
   if (!buf)
-   return;
+{
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  return;
+}
+
   bufptr = grub_stpcpy (buf, alias->path);
 
   for (i = 0; i < args.nentries; i++)
@@ -257,6 +276,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
}
}
   grub_ieee1275_close (ihandle);
+  grub_free (table);
   grub_free (buf);
   return;
 }
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2] ofdisk: add sas disks to the device list

2015-11-08 Thread Paulo Flabiano Smorigo
All SAS disks attached will be added to the device list. This is the second
version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg0.html

---
 grub-core/disk/ieee1275/ofdisk.c | 76 
 1 file changed, 76 insertions(+)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 297f058..afec9ba 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   grub_free (buf);
   return;
 }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+{
+  /* The method returns the number of disks and a table where
+   * each ID is 64-bit long. Example of sas paths:
+   *  /pci@800201f/pci1014,034A@0/sas/disk@c05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@a05db70800
+   *  /pci@800201f/pci1014,034A@0/sas/disk@805db70800 */
+
+  struct sas_children
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t max;
+  grub_ieee1275_cell_t table;
+  grub_ieee1275_cell_t catch_result;
+  grub_ieee1275_cell_t nentries;
+}
+  args;
+  char *buf, *bufptr, *table;
+  unsigned i;
+  grub_uint32_t table_size;
+  grub_ieee1275_ihandle_t ihandle;
+
+  buf = grub_malloc (grub_strlen (alias->path)
+ + sizeof ("/disk@7766554433221100"));
+  if (!buf)
+return;
+
+  /* 64 entries should be enough */
+  table_size = sizeof (grub_uint64_t) * 64;
+  table = grub_malloc (table_size);
+
+  if (!table)
+{
+  grub_free (buf);
+  return;
+}
+
+  bufptr = grub_stpcpy (buf, alias->path);
+
+  if (grub_ieee1275_open (alias->path, &ihandle))
+{
+  grub_free (buf);
+  grub_free (table);
+  return;
+}
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+  args.method = (grub_ieee1275_cell_t) "get-sas-children";
+  args.ihandle = ihandle;
+  args.max = table_size;
+  args.table = (grub_ieee1275_cell_t) table;
+  args.catch_result = 0;
+  args.nentries = 0;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+{
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+  return;
+}
+
+  grub_uint64_t *ptr;
+  for (i = 0; i < args.nentries; i++)
+{
+  ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+  grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+  dev_iterate_real (buf, buf);
+}
+
+  grub_ieee1275_close (ihandle);
+  grub_free (table);
+  grub_free (buf);
+}
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
   && grub_strcmp (alias->type, "block") == 0)
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] ofdisk: Recognizes SAS disks automatically

2015-07-31 Thread Paulo Flabiano Smorigo
Read all children from sas path and add it to the device list.

---
 grub-core/disk/ieee1275/ofdisk.c | 51 
 include/grub/ieee1275/ofdisk.h   |  3 +++
 2 files changed, 54 insertions(+)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 331769b..b17f6d1 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -260,6 +260,57 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   grub_free (buf);
   return;
 }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+{
+  struct sas_children
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t max;
+  grub_ieee1275_cell_t table;
+  grub_ieee1275_cell_t catch_result;
+  grub_ieee1275_cell_t nentries;
+}
+  args;
+  char *buf, *bufptr;
+  unsigned i;
+  grub_ieee1275_ihandle_t ihandle;
+
+  buf = grub_malloc (grub_strlen (alias->path)
+ + sizeof("/disk@") + IEEE1275_SAS_CHILDREN_SIZE + 1);
+  if (!buf)
+return;
+
+  bufptr = grub_stpcpy (buf, alias->path);
+
+  if (grub_ieee1275_open (alias->path, &ihandle))
+return;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+  args.method = (grub_ieee1275_cell_t) "get-sas-children";
+  args.ihandle = ihandle;
+  args.max = IEEE1275_SAS_CHILDREN_BUFFER_SIZE;
+  args.table = 0;
+  args.catch_result = 0;
+  args.nentries = 0;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+{
+  grub_ieee1275_close (ihandle);
+  return;
+}
+  grub_uint64_t *ptr;
+  for (i = 0; i < args.nentries; i++)
+{
+  ptr = (grub_uint64_t *) (args.table + IEEE1275_SAS_CHILDREN_SIZE * 
i);
+  grub_snprintf (bufptr, 100, "/disk@%" PRIxGRUB_UINT64_T, 
(grub_uint64_t) *ptr);
+  dev_iterate_real (buf, buf);
+}
+
+  grub_ieee1275_close (ihandle);
+  grub_free (buf);
+}
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
   && grub_strcmp (alias->type, "block") == 0)
diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h
index 2f69e3f..59f84f7 100644
--- a/include/grub/ieee1275/ofdisk.h
+++ b/include/grub/ieee1275/ofdisk.h
@@ -19,6 +19,9 @@
 #ifndef GRUB_OFDISK_HEADER
 #define GRUB_OFDISK_HEADER 1
 
+#define IEEE1275_SAS_CHILDREN_SIZE 8
+#define IEEE1275_SAS_CHILDREN_BUFFER_SIZE 100*IEEE1275_SAS_CHILDREN_SIZE
+
 extern void grub_ofdisk_init (void);
 extern void grub_ofdisk_fini (void);
 
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] Suport for bi-endianess in elf file

2015-07-26 Thread Paulo Flabiano Smorigo

On 2015-07-24 16:00, Vladimir 'phcoder' Serbinenko wrote:


Le 23 juil. 2015 16:11, "Paulo Flabiano Smorigo"
mailto:pfsmor...@linux.vnet.ibm.com>> a
écrit :
 >
 > Updated version with the suggestions from Andrei Borzenkov.
 >
 > * grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
 > cpu functions.
 > * grub-core/kern/elfXX.c: Likewise.
 >
 > Also-by: Tomohiro B Berry mailto:tbbe...@us.ibm.com>>
 > ---
 >  grub-core/kern/elf.c   | 51 ++---
 >  grub-core/kern/elfXX.c | 76
++
 >  2 files changed, 123 insertions(+), 4 deletions(-)
 >
 > diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
 > index 5f99c43..1be9c1c 100644
 > --- a/grub-core/kern/elf.c
 > +++ b/grub-core/kern/elf.c
 > @@ -28,6 +28,11 @@
 >
 >  GRUB_MOD_LICENSE ("GPLv3+");
 >
 > +#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
 > +void grub_elf32_check_endianess (grub_elf_t elf);
 > +void grub_elf64_check_endianess (grub_elf_t elf);
 > +#endif /* defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) */
 > +
 >  /* Check if EHDR is a valid ELF header.  */
 >  static grub_err_t
 >  grub_elf_check_header (grub_elf_t elf)
 > @@ -38,8 +43,19 @@ grub_elf_check_header (grub_elf_t elf)
 >|| 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
 > -  || e->e_version != EV_CURRENT)
 > +  || e->e_ident[EI_VERSION] != EV_CURRENT)
 > +return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent
ELF magic"));
 > +
 > +#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
 > +  if (grub_elf_is_elf32 (elf))
 > +  grub_elf32_check_endianess (elf);
 > +  else if (grub_elf_is_elf64 (elf))
 > +  grub_elf64_check_endianess (elf);
 > +  else
 > +return grub_error (GRUB_ERR_BAD_OS, N_("Uknown ELF class"));
 > +#endif /* defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) */
 > +
 > +  if (e->e_version != EV_CURRENT)
 >  return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent
ELF magic"));
 >
 >return GRUB_ERR_NONE;
 > @@ -116,7 +132,11 @@ grub_elf_open (const char *name)
 >return elf;
 >  }
 >
 > -
 > +#define grub_be_to_halfXX grub_be_to_cpu16
 > +#define grub_le_to_halfXX grub_le_to_cpu16
 > +#define grub_be_to_wordXX grub_be_to_cpu32
 > +#define grub_le_to_wordXX grub_le_to_cpu32
 > +
 >  /* 32-bit */
 >  #define ehdrXX ehdr32
 >  #define ELFCLASSXX ELFCLASS32
 > @@ -127,7 +147,15 @@ grub_elf_open (const char *name)
 >  #define grub_elf_is_elfXX grub_elf_is_elf32
 >  #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 >  #define ElfXX_Phdr Elf32_Phdr
 > +#define ElfXX_Ehdr Elf32_Ehdr
 >  #define grub_uintXX_t grub_uint32_t
 > +#define grub_be_to_addrXX grub_be_to_cpu32
 > +#define grub_le_to_addrXX grub_le_to_cpu32
 > +#define grub_be_to_offXX grub_be_to_cpu32
 > +#define grub_le_to_offXX grub_le_to_cpu32
 > +#define grub_be_to_XwordXX grub_be_to_cpu32
 > +#define grub_le_to_XwordXX grub_le_to_cpu32
 > +#define grub_elfXX_check_endianess grub_elf32_check_endianess
 >
 >  #include "elfXX.c"
 >
 > @@ -140,9 +168,16 @@ grub_elf_open (const char *name)
 >  #undef grub_elf_is_elfXX
 >  #undef grub_elfXX_load_phdrs
 >  #undef ElfXX_Phdr
 > +#undef ElfXX_Ehdr
 >  #undef grub_uintXX_t
 > +#undef grub_be_to_addrXX
 > +#undef grub_le_to_addrXX
 > +#undef grub_be_to_offXX
 > +#undef grub_le_to_offXX
 > +#undef grub_be_to_XwordXX
 > +#undef grub_le_to_XwordXX
 > +#undef grub_elfXX_check_endianess
 >
 > -
 >  /* 64-bit */
 >  #define ehdrXX ehdr64
 >  #define ELFCLASSXX ELFCLASS64
 > @@ -153,6 +188,14 @@ grub_elf_open (const char *name)
 >  #define grub_elf_is_elfXX grub_elf_is_elf64
 >  #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 >  #define ElfXX_Phdr Elf64_Phdr
 > +#define ElfXX_Ehdr Elf64_Ehdr
 >  #define grub_uintXX_t grub_uint64_t
 > +#define grub_be_to_addrXX grub_be_to_cpu64
 > +#define grub_le_to_addrXX grub_le_to_cpu64
 > +#define grub_be_to_offXX grub_be_to_cpu64
 > +#define grub_le_to_offXX grub_le_to_cpu64
 > +#define grub_be_to_XwordXX grub_be_to_cpu64
 > +#define grub_le_to_XwordXX grub_le_to_cpu64
 > +#define grub_elfXX_check_endianess grub_elf64_check_endianess
 >
 >  #include "elfXX.c"
 > diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
 > index 1d09971..c14e071 100644
 > --- a/grub-core/kern/elfXX.c
 > +++ b/grub-core/kern/elfXX.c
 > @@ -31,6 +31,39 @@ gr

[PATCH v2] Suport for bi-endianess in elf file

2015-07-23 Thread Paulo Flabiano Smorigo
Updated version with the suggestions from Andrei Borzenkov.

* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry 
---
 grub-core/kern/elf.c   | 51 ++---
 grub-core/kern/elfXX.c | 76 ++
 2 files changed, 123 insertions(+), 4 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..1be9c1c 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+#endif /* defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) */
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_elf_check_header (grub_elf_t elf)
@@ -38,8 +43,19 @@ grub_elf_check_header (grub_elf_t elf)
   || 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
-  || e->e_version != EV_CURRENT)
+  || e->e_ident[EI_VERSION] != EV_CURRENT)
+return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF 
magic"));
+
+#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
+  if (grub_elf_is_elf32 (elf))
+  grub_elf32_check_endianess (elf);
+  else if (grub_elf_is_elf64 (elf))
+  grub_elf64_check_endianess (elf);
+  else
+return grub_error (GRUB_ERR_BAD_OS, N_("Uknown ELF class"));
+#endif /* defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) */
+
+  if (e->e_version != EV_CURRENT)
 return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF 
magic"));
 
   return GRUB_ERR_NONE;
@@ -116,7 +132,11 @@ grub_elf_open (const char *name)
   return elf;
 }
 
-
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_le_to_wordXX grub_le_to_cpu32
+
 /* 32-bit */
 #define ehdrXX ehdr32
 #define ELFCLASSXX ELFCLASS32
@@ -127,7 +147,15 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf32
 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 #define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
 #define grub_uintXX_t grub_uint32_t
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_cpu32
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
 
 #include "elfXX.c"
 
@@ -140,9 +168,16 @@ grub_elf_open (const char *name)
 #undef grub_elf_is_elfXX
 #undef grub_elfXX_load_phdrs
 #undef ElfXX_Phdr
+#undef ElfXX_Ehdr
 #undef grub_uintXX_t
+#undef grub_be_to_addrXX
+#undef grub_le_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_le_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
 
-
 /* 64-bit */
 #define ehdrXX ehdr64
 #define ELFCLASSXX ELFCLASS64
@@ -153,6 +188,14 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf64
 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 #define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
 #define grub_uintXX_t grub_uint64_t
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
 
 #include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..c14e071 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -31,6 +31,39 @@ grub_elfXX_load_phdrs (grub_elf_t elf)
   return grub_errno;
 }
 
+#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
+  ElfXX_Phdr *phdr;
+  for (phdr = elf->phdrs;
+   phdr && phdr < (ElfXX_Phdr *) elf->phdrs + elf->ehdr.ehdrXX.e_phnum;
+   phdr++)
+{
+  if (elf->ehdr.ehdrXX.e_ident[EI_DATA] == ELFDATA2LSB)
+{
+  phdr->p_type = grub_le_to_wordXX (phdr->p_type);
+  phdr->p_flags = grub_le_to_wordXX (phdr->p_flags);
+  phdr->p_offset = grub_le_to_offXX (phdr->p_offset);
+  phdr->p_vaddr = grub_le_to_addrXX (phdr->p_vaddr);
+  phdr->p_paddr = grub_le_to_addrXX (phdr->p_paddr);
+  phdr->p_filesz = grub_le_to_XwordXX (phdr->p_filesz);
+  phdr->p_memsz = grub_le_to_XwordXX (phdr->p_memsz);
+  phdr->p_align = grub_le_to_XwordXX (phdr->p_align);
+}
+#if !defined(GRUB_CPU_WORDS_BIGENDIAN) && 0
+  else if (elf->ehdr.ehdrXX.e_ident[EI_DATA] == ELFDATA2MSB)
+{
+  phdr->p_type = grub_be_to_w

Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags

2015-07-22 Thread Paulo Flabiano Smorigo

On 2015-07-22 00:23, Andrei Borzenkov wrote:

В Wed, 15 Jul 2015 19:42:39 +0200
Vladimir 'φ-coder/phcoder' Serbinenko  пишет:




It is possible to compile using "--target=powerpc -Wl,-EB" - this works
on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
dependency.


Thanks for this info.
See attached patch


I do not think it was right to commit this patch without bi-endian ELF
support; this makes GRUB compile of ppc64le but it still cannot load
kernel.


Yes, you are right. Let me finish the changes on the second patch so we 
can commit both.






___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel




--
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags

2015-07-20 Thread Paulo Flabiano Smorigo

On 2015-07-16 16:30, Andrei Borzenkov wrote:

В Thu, 16 Jul 2015 21:05:07 +0200
Vladimir 'φ-coder/phcoder' Serbinenko  пишет:


On 16.07.2015 20:55, Andrei Borzenkov wrote:

В Wed, 15 Jul 2015 19:42:39 +0200
Vladimir 'φ-coder/phcoder' Serbinenko  пишет:


It is possible to compile using "--target=powerpc -Wl,-EB" - this works
on all three ppc, ppc64 and ppc64le, but this means hardcoding GNU ld
dependency.


Thanks for this info.
See attached patch

Test has to come before asm tests (so that we are sure to compile
for the right target).

But real problem is that -Wl,-EB has to be added to TARGET_LDFLAGS only


Yes, discovered it already and updated the patch

Yes, this version builds OK both in native PPC environment as well as
cross-compiling.


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Here works too. Both native and cross-compiled.

--
Paulo Flabiano Smorigo
IBM Linux Technology Center

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 2/2] Suport for bi-endianess in elf file

2015-06-30 Thread Paulo Flabiano Smorigo

On 2015-06-30 12:03, Andrei Borzenkov wrote:

Did you intentionally ignore my comments to previous version?


OH no, sorry, I will take a look.



Отправлено с iPhone


30 июня 2015 г., в 15:56, Paulo Flabiano Smorigo  
написал(а):

* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry 
---
grub-core/kern/elf.c   | 60 +++--
grub-core/kern/elfXX.c | 73 ++
2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..de90811 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@

GRUB_MOD_LICENSE ("GPLv3+");

+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+grub_err_t grub_elf32_check_version (grub_elf_t elf);
+grub_err_t grub_elf64_check_version (grub_elf_t elf);
+
/* Check if EHDR is a valid ELF header.  */
static grub_err_t
grub_elf_check_header (grub_elf_t elf)
@@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
   || 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
-  || e->e_version != EV_CURRENT)
+  || e->e_ident[EI_VERSION] != EV_CURRENT)
 return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF 
magic"));

+  if (grub_elf_is_elf32 (elf))
+{
+  grub_elf32_check_endianess (elf);
+  grub_elf32_check_version (elf);
+}
+  else if (grub_elf_is_elf64 (elf))
+{
+  grub_elf64_check_endianess (elf);
+  grub_elf64_check_version (elf);
+}
+  else
+return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF 
magic"));
+
   return GRUB_ERR_NONE;
}

@@ -127,7 +144,20 @@ grub_elf_open (const char *name)
#define grub_elf_is_elfXX grub_elf_is_elf32
#define grub_elfXX_load_phdrs grub_elf32_load_phdrs
#define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
#define grub_uintXX_t grub_uint32_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_wordXX
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_wordXX
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
+#define grub_elfXX_check_version grub_elf32_check_version

#include "elfXX.c"

@@ -140,7 +170,20 @@ grub_elf_open (const char *name)
#undef grub_elf_is_elfXX
#undef grub_elfXX_load_phdrs
#undef ElfXX_Phdr
+#undef ElfXX_Ehdr
#undef grub_uintXX_t
+#undef grub_be_to_halfXX
+#undef grub_be_to_wordXX
+#undef grub_be_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_halfXX
+#undef grub_le_to_wordXX
+#undef grub_le_to_addrXX
+#undef grub_le_to_offXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
+#undef grub_elfXX_check_version


/* 64-bit */
@@ -153,6 +196,19 @@ grub_elf_open (const char *name)
#define grub_elf_is_elfXX grub_elf_is_elf64
#define grub_elfXX_load_phdrs grub_elf64_load_phdrs
#define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
#define grub_uintXX_t grub_uint64_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
+#define grub_elfXX_check_version grub_elf64_check_version

#include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..ecf9df6 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,

   return grub_errno;
}
+
+void
+grub_elfXX_check_endianess (grub_elf_t elf)
+{
+  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
+  ElfXX_Phdr *phdr;
+
+  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
+{
+  e->e_type = grub_be_to_halfXX (e->e_type);
+  e->e_machine = grub_be_to_halfXX (e->e_machine);
+  e->e_version = grub_be_to_wordXX (e->e_version);
+  e->e_entry = grub_be_to_addrXX (e->e_entry);
+  e->e_phoff = grub_be_to_offXX (e->e_phoff);
+  e->e_shoff = grub_be_to_offXX (e->e_shoff);
+  e->e_flags = grub_be_to_wordXX (e->e_flags);
+  e->e_ehsize = grub_be_to_halfXX (

Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags

2015-06-30 Thread Paulo Flabiano Smorigo

On 2015-06-30 11:33, Vladimir 'phcoder' Serbinenko wrote:

What about clang?


Not good news about clang support. This is what the toolchain team said 
about it:


The -mbig-endian option was added around April 10th, 2014. 
Unfortunately, those who implemented it only implemented it for ARM and 
one other architecture.


The option is currently accepted on Power systems, but does not have any 
affect on the code generation for Power.



So, what can we do here? Maybe add a constrain in the configure file 
saying that it's not possible to build GRUB in a LE environment using clang.


Le 30 juin 2015 16:30, "Andrei Borzenkov" mailto:arvidj...@gmail.com>> a écrit :

On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
mailto:phco...@gmail.com>> wrote:
 > Which compilers support these flags? I'm concerned of breaking
old compilers
 >

-static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.

 > Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
 > mailto:pfsmor...@linux.vnet.ibm.com>> a écrit :
 >>
 >> libgcc dependency was removed *just* for this target because
 >> the distros that use ppc64el doesn't have 32-bit support on it.
 >>
 >> * configure.ac <http://configure.ac>: Add targets for
powerpc64el and skip libgcc.
 >> * Makefile.am: Likewise.
 >> ---
 >> configure.ac <http://configure.ac> | 8 
 >>  1 file changed, 8 insertions(+)
 >>
 >> diff --git a/configure.ac <http://configure.ac> b/configure.ac
<http://configure.ac>
 >> index fd8a62e..0a79fad 100644
 >> --- a/configure.ac <http://configure.ac>
 >> +++ b/configure.ac <http://configure.ac>
 >> @@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
 >>  x86_64-*) platform=pc ;;
 >>  powerpc-*) platform=ieee1275 ;;
 >>  powerpc64-*) platform=ieee1275 ;;
 >> +powerpc64le-*) platform=ieee1275 ;;
 >>  sparc64-*) platform=ieee1275 ;;
 >>  mipsel-*) platform=loongson ;;
 >>  mips-*) platform=arc ;;
 >> @@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
 >>x86_64-none) ;;
 >>x86_64-*) target_cpu=i386 ;;
 >>powerpc64-ieee1275) target_cpu=powerpc ;;
 >> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
 >>  esac
 >>
 >>  # Check if the platform is supported, make final adjustments.
 >> @@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test
"x$platform"
 >> != xemu; then
 >>TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 >>  fi
 >>
 >> +if test x$target_cpu = xpowerpc; then
 >> +  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
 >> +  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
 >> +  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
 >> +fi
 >> +
 >>  if test "x$target_m32" = x1; then
 >># Force 32-bit mode.
 >>TARGET_CFLAGS="$TARGET_CFLAGS -m32"
 >> --
 >> 2.1.0
 >>
 >>
 >> ___
 >> Grub-devel mailing list
 >> Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
 >> https://lists.gnu.org/mailman/listinfo/grub-devel
     >
     >
 > ___
 > Grub-devel mailing list
 > Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
 > https://lists.gnu.org/mailman/listinfo/grub-devel
 >

___
Grub-devel mailing list
Grub-devel@gnu.org <mailto:Grub-devel@gnu.org>
https://lists.gnu.org/mailman/listinfo/grub-devel



___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel




--
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 1/2] Add powerpc little-endian (ppc64le) flags

2015-06-30 Thread Paulo Flabiano Smorigo

On 2015-06-30 11:29, Andrei Borzenkov wrote:

On Tue, Jun 30, 2015 at 5:03 PM, Vladimir 'phcoder' Serbinenko
 wrote:

Which compilers support these flags? I'm concerned of breaking old compilers



-static and -mbig-endian are listed in gcc 2.95.3 documentation for PPC.


I asked some toolchain folks and this flag is really old. IIUC even 
before GCC 2.95, which was released at March 16, 2001.





Le 30 juin 2015 14:57, "Paulo Flabiano Smorigo"
 a écrit :


libgcc dependency was removed *just* for this target because
the distros that use ppc64el doesn't have 32-bit support on it.

* configure.ac: Add targets for powerpc64el and skip libgcc.
* Makefile.am: Likewise.
---
  configure.ac | 8 
  1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index fd8a62e..0a79fad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
  x86_64-*) platform=pc ;;
  powerpc-*) platform=ieee1275 ;;
  powerpc64-*) platform=ieee1275 ;;
+powerpc64le-*) platform=ieee1275 ;;
  sparc64-*) platform=ieee1275 ;;
  mipsel-*) platform=loongson ;;
  mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
x86_64-none) ;;
x86_64-*) target_cpu=i386 ;;
powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
  esac

  # Check if the platform is supported, make final adjustments.
@@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform"
!= xemu; then
TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
  fi

+if test x$target_cpu = xpowerpc; then
+  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
  if test "x$target_m32" = x1; then
# Force 32-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m32"
--
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel



___________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel






--
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 0/2] Add remaining parts for ppc64le environment

2015-06-30 Thread Paulo Flabiano Smorigo
It's almost the same as the one that I sent in the beginning of the year.
The only difference is that the I remove a flag from the first patch.

Paulo Flabiano Smorigo (2):
  Add powerpc little-endian (ppc64le) flags
  Suport for bi-endianess in elf file

 configure.ac   |  8 ++
 grub-core/kern/elf.c   | 60 +++--
 grub-core/kern/elfXX.c | 73 ++
 3 files changed, 139 insertions(+), 2 deletions(-)

-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/2] Suport for bi-endianess in elf file

2015-06-30 Thread Paulo Flabiano Smorigo
* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry 
---
 grub-core/kern/elf.c   | 60 +++--
 grub-core/kern/elfXX.c | 73 ++
 2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..de90811 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+grub_err_t grub_elf32_check_version (grub_elf_t elf);
+grub_err_t grub_elf64_check_version (grub_elf_t elf);
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_elf_check_header (grub_elf_t elf)
@@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
   || 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
-  || e->e_version != EV_CURRENT)
+  || e->e_ident[EI_VERSION] != EV_CURRENT)
 return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF 
magic"));
 
+  if (grub_elf_is_elf32 (elf))
+{
+  grub_elf32_check_endianess (elf);
+  grub_elf32_check_version (elf);
+}
+  else if (grub_elf_is_elf64 (elf))
+{
+  grub_elf64_check_endianess (elf);
+  grub_elf64_check_version (elf);
+}
+  else
+return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF 
magic"));
+
   return GRUB_ERR_NONE;
 }
 
@@ -127,7 +144,20 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf32
 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 #define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
 #define grub_uintXX_t grub_uint32_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_wordXX
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_wordXX
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
+#define grub_elfXX_check_version grub_elf32_check_version
 
 #include "elfXX.c"
 
@@ -140,7 +170,20 @@ grub_elf_open (const char *name)
 #undef grub_elf_is_elfXX
 #undef grub_elfXX_load_phdrs
 #undef ElfXX_Phdr
+#undef ElfXX_Ehdr
 #undef grub_uintXX_t
+#undef grub_be_to_halfXX
+#undef grub_be_to_wordXX
+#undef grub_be_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_halfXX
+#undef grub_le_to_wordXX
+#undef grub_le_to_addrXX
+#undef grub_le_to_offXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
+#undef grub_elfXX_check_version
 
 
 /* 64-bit */
@@ -153,6 +196,19 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf64
 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 #define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
 #define grub_uintXX_t grub_uint64_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
+#define grub_elfXX_check_version grub_elf64_check_version
 
 #include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..ecf9df6 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
 
   return grub_errno;
 }
+
+void
+grub_elfXX_check_endianess (grub_elf_t elf)
+{
+  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
+  ElfXX_Phdr *phdr;
+
+  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
+{
+  e->e_type = grub_be_to_halfXX (e->e_type);
+  e->e_machine = grub_be_to_halfXX (e->e_machine);
+  e->e_version = grub_be_to_wordXX (e->e_version);
+  e->e_entry = grub_be_to_addrXX (e->e_entry);
+  e->e_phoff = grub_be_to_offXX (e->e_phoff);
+  e->e_shoff = grub_be_to_offXX (e->e_shoff);
+  e->e_flags = grub_be_to_wordXX (e->e_flags);
+  e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
+  e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
+  e->e_phnum = grub_be_to_halfXX (e->e_phnum);
+  e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
+  e->e_shnum = grub_be_to_halfXX (e->e_shnum);
+  e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
+
+  FOR_ELFXX_PHDRS (elf,

[PATCH 1/2] Add powerpc little-endian (ppc64le) flags

2015-06-30 Thread Paulo Flabiano Smorigo
libgcc dependency was removed *just* for this target because
the distros that use ppc64el doesn't have 32-bit support on it.

* configure.ac: Add targets for powerpc64el and skip libgcc.
* Makefile.am: Likewise.
---
 configure.ac | 8 
 1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index fd8a62e..0a79fad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,7 @@ if test "x$with_platform" = x; then
 x86_64-*) platform=pc ;;
 powerpc-*) platform=ieee1275 ;;
 powerpc64-*) platform=ieee1275 ;;
+powerpc64le-*) platform=ieee1275 ;;
 sparc64-*) platform=ieee1275 ;;
 mipsel-*) platform=loongson ;;
 mips-*) platform=arc ;;
@@ -138,6 +139,7 @@ case "$target_cpu"-"$platform" in
   x86_64-none) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -601,6 +603,12 @@ if test "x$target_cpu" = xi386 && test "x$platform" != 
xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc; then
+  TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-- 
2.1.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement

2015-06-16 Thread Paulo Flabiano Smorigo

On 2015-06-15 14:15, Andrei Borzenkov wrote:

В Thu, 28 Aug 2014 16:56:02 -0300
Paulo Flabiano Smorigo  пишет:


From: Paulo Flabiano Smorigo 

Hi,

At the beginning of the year we provide a patchset that enabled GRUB for
little-endian PowerPC. Our approach at the time was to build GRUB itself and
its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.

This patchset was not welcomed at the time because it would bring a
high-maintainance-cost, without real gain since it could just be cross-compiled.

After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
that would cross-compile but without 32-bit dependencies. This patchset is the
result of this new approach. It's based on the work of Brent Baude, Vladimir
(phcoder), and Tomohiro.

It can be devided in two parts:

   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);


This is now default for all platforms


   2) Check elf endianess and byteswap if necessary (patch 3);



That's still pending.


Yes, I'm aware of that. :)




The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
satisfies the needs of the distros. I tested it in three different distros, in
both endianess and it's fine.

If thoses patches were accepted we will have an official solution. Nowadays,
distros are taking diffrent approachs. Some of then are using the original
solutions and others are using cross-compiler.



Could you resend missing bits rebased to current head?


Sure thing. I'll review it once more and send it to the ML later this week.

--
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] Add flags for powerpc in order to avoid exceptions

2014-10-08 Thread Paulo Flabiano Smorigo
Mon, Sep 29, 2014 at 10:30:16PM +0400, Andrei Borzenkov wrote:
> В Sat, 27 Sep 2014 09:06:53 +0400
> Andrei Borzenkov  пишет:
> 
> > В Fri, 26 Sep 2014 16:29:40 -0300
> > Paulo Flabiano Smorigo  пишет:
> > 
> > > * conf/Makefile.common [COND_powerpc_ieee1275] (CFLAGS_PLATFORM): Add
> > > -msoft-float -mno-vsx -mno-altivec.
> > > 
> > > Also-By: Adhemerval Zanella 
> > > ---
> > >  ChangeLog| 7 +++
> > >  conf/Makefile.common | 3 +++
> > >  2 files changed, 10 insertions(+)
> > > 
> > > diff --git a/ChangeLog b/ChangeLog
> > > index 192e8bc..40eb90c 100644
> > > --- a/ChangeLog
> > > +++ b/ChangeLog
> > > @@ -1,3 +1,10 @@
> > > +2014-09-26  Paulo Flabiano Smorigo  
> > > +
> > > + Add flags for powerpc in order to avoid exceptions
> > > +
> > > + * conf/Makefile.common [COND_powerpc_ieee1275] (CFLAGS_PLATFORM): Add
> > > + -msoft-float -mno-vsx -mno-altivec.
> > > +
> > >  2014-09-25  Colin Watson  
> > >  
> > >   Fix in-tree --platform=none
> > > diff --git a/conf/Makefile.common b/conf/Makefile.common
> > > index 51fbaf9..57c491a 100644
> > > --- a/conf/Makefile.common
> > > +++ b/conf/Makefile.common
> > > @@ -22,6 +22,9 @@ endif
> > >  if COND_arm64
> > >CFLAGS_PLATFORM += -mcmodel=large
> > >  endif
> > > +if COND_powerpc_ieee1275
> > > +  CFLAGS_PLATFORM += -msoft-float -mno-vsx -mno-altivec
> > > +endif
> > >  
> > >  #FIXME: discover and check XEN headers
> > >  CPPFLAGS_XEN = -I/usr/include
> > 
> > Thank you! I confirm that this patch works and does not break grub on
> > earlier CPU :)
> > 
> > There are still differences in generated code, so we probably need to
> > tune some more flags.
> 
> I looked at compiler options for PowerPC and I think instead of trying
> to catch individual flags which may change with every release we should
> simply force the most common platform by
> 
> +if COND_powerpc_ieee1275
> +  CFLAGS_PLATFORM += -mcpu=powerpc -mtune=powerpc
> +endif
> 
> 
> This makes sure result is identical on every platform and provides most
> generic code that is expected to run on every(?) system.
> 
> WDYT?

Hi Andrei,

Sorry to take so long to answer your question.

After an internal discussion with some toolchain experts we found out
that your approach is good. It works and it's more generic but we think
that we should change it a little bit:

 * skip -mtune, not really necessary
 * add "-msoft-float" to be completly safe.

Something like:

+if COND_powerpc_ieee1275
+  CFLAGS_PLATFORM += -mcpu=powerpc -msoft-float
+endif

This approach is similar to what the linux kernel do.

In addition, they recomend to set FP MSR value to zero as well.

Andrei, Vladimir, agree?

> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] Disable VSX instruction

2014-09-29 Thread Paulo Flabiano Smorigo
Sat, Sep 27, 2014 at 08:41:40AM +0400, Andrei Borzenkov wrote:
> В Fri, 26 Sep 2014 10:52:02 -0300
> Paulo Flabiano Smorigo  пишет:
> 
> > Fri, Sep 26, 2014 at 11:14:00AM +0100, Colin Watson wrote:
> > > On Thu, Sep 25, 2014 at 07:33:39PM -0300, Paulo Flabiano Smorigo wrote:
> > > > @@ -28,6 +30,14 @@
> > > > .globl  start, _start
> > > >  start:
> > > >  _start:
> > > > + _start:
> > > > +
> > > > +/* Disable VSX instruction */
> > > 
> > > Isn't the second _start: label here redundant?
> > 
> > yes, sorry. I will remove it from the patch.
> > 
> 
> Is it still needs? I tested "Add flags for powerpc in order to avoid
> exceptions" and it works, so I assume this patch is obsolete?

Friday we discovered that this asm stills enables vsx so we think that the
flags are the right way to do it.

I talked with some toolchain experts and add two more flags that can
cause the problem as well.

> 
> > Tks!
> > 
> > > 
> > > -- 
> > > Colin Watson   [cjwat...@ubuntu.com]
> > > 
> > > ___
> > > Grub-devel mailing list
> > > Grub-devel@gnu.org
> > > https://lists.gnu.org/mailman/listinfo/grub-devel
> > > 
> > 
> 
> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add flags for powerpc in order to avoid exceptions

2014-09-26 Thread Paulo Flabiano Smorigo
* conf/Makefile.common [COND_powerpc_ieee1275] (CFLAGS_PLATFORM): Add
-msoft-float -mno-vsx -mno-altivec.

Also-By: Adhemerval Zanella 
---
 ChangeLog| 7 +++
 conf/Makefile.common | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 192e8bc..40eb90c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-09-26  Paulo Flabiano Smorigo  
+
+   Add flags for powerpc in order to avoid exceptions
+
+   * conf/Makefile.common [COND_powerpc_ieee1275] (CFLAGS_PLATFORM): Add
+   -msoft-float -mno-vsx -mno-altivec.
+
 2014-09-25  Colin Watson  
 
Fix in-tree --platform=none
diff --git a/conf/Makefile.common b/conf/Makefile.common
index 51fbaf9..57c491a 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -22,6 +22,9 @@ endif
 if COND_arm64
   CFLAGS_PLATFORM += -mcmodel=large
 endif
+if COND_powerpc_ieee1275
+  CFLAGS_PLATFORM += -msoft-float -mno-vsx -mno-altivec
+endif
 
 #FIXME: discover and check XEN headers
 CPPFLAGS_XEN = -I/usr/include
-- 
1.8.1.4


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement

2014-09-26 Thread Paulo Flabiano Smorigo
Fri, Sep 26, 2014 at 07:52:02PM +0400, Andrei Borzenkov wrote:
> В Thu, 25 Sep 2014 19:48:04 -0300
> Paulo Flabiano Smorigo  пишет:
> 
> > Sun, Sep 21, 2014 at 06:24:25PM +0400, Andrei Borzenkov wrote:
> > > В Sun, 21 Sep 2014 17:58:44 +0400
> > > Andrei Borzenkov  пишет:
> > > 
> > > > В Thu, 28 Aug 2014 16:56:02 -0300
> > > > Paulo Flabiano Smorigo  пишет:
> > > > 
> > > > > From: Paulo Flabiano Smorigo 
> > > > > 
> > > > > Hi,
> > > > > 
> > > > > At the beginning of the year we provide a patchset that enabled GRUB 
> > > > > for
> > > > > little-endian PowerPC. Our approach at the time was to build GRUB 
> > > > > itself and
> > > > > its tools in 64-bit little-endian. One of the reasons of build in 
> > > > > 64-bit is
> > > > > to avoid 32-bit dependencies in the distro and build a system 
> > > > > entirely 64-bit.
> > > > > 
> > > > > This patchset was not welcomed at the time because it would bring a
> > > > > high-maintainance-cost, without real gain since it could just be 
> > > > > cross-compiled.
> > > > > 
> > > > > After that, Brent Baude, Vladmir (phcoder) and I started to work in a 
> > > > > solution
> > > > > that would cross-compile but without 32-bit dependencies. This 
> > > > > patchset is the
> > > > > result of this new approach. It's based on the work of Brent Baude, 
> > > > > Vladimir
> > > > > (phcoder), and Tomohiro.
> > > > > 
> > > > > It can be devided in two parts:
> > > > > 
> > > > >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> > > > >   2) Check elf endianess and byteswap if necessary (patch 3);
> > > > > 
> > > > > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. 
> > > > > This solution
> > > > > satisfies the needs of the distros. I tested it in three different 
> > > > > distros, in
> > > > > both endianess and it's fine.
> > > > > 
> > > > 
> > > > Unfortunately I'm still not able to boot this version on QEMU. I build
> > > > on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> > > > boot successfully. Third one does not work - it ends up in exception. I
> > > > get initial GRUB greeting and that's all.
> > > > 
> > > > Same problem I got with Vladimir libgcc patch series.
> > > > 
> > > > It could be toolkit issue of course; but still it would need fixing
> > > > before we can merge it.
> > > > 
> > > > Could you help in debugging this issue? I have near to zero experience
> > > > with PPC; I can do what you tell me, but not much more.
> > > > 
> > > > I run it with
> > > > 
> > > > qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> > > > 
> > > > Attached is screenshot of error.
> > > > 
> > > > 
> > > 
> > > And here is the difference in generated code in case it helps (one
> > > random module as example) ...
> > > 
> > > --- /tmp/a1   2014-09-21 18:19:59.316494117 +0400
> > > +++ /tmp/a2   2014-09-21 18:20:06.169398736 +0400
> > > @@ -1,5 +1,5 @@
> > >  
> > > -usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod: file format 
> > > elf32-powerpc
> > > +usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod: file format 
> > > elf32-powerpc
> > >  
> > >  
> > >  Disassembly of section .text:
> > > @@ -18,15 +18,15 @@ Disassembly of section .text:
> > >28:38 21 00 10 addir1,r1,16
> > >2c:7c 08 03 a6 mtlrr0
> > >30:4e 80 00 20 blr
> > > -  34:94 21 ff a0 stwur1,-96(r1)
> > > +  34:94 21 ff 90 stwur1,-112(r1)
> > >38:38 e3 00 28 addir7,r3,40
> > >3c:7d 80 00 26 mfcrr12
> > >40:39 23 00 14 addir9,r3,20
> > >44:7c 08 02 a6 mflrr0
> > >48:39 43 00 18 addir10,r3,24
> > > -  4c:bf 61 00 4c stmwr27,76(r1)
> > > -  50:90 01 00 64 stw r0,100(r1)
> > > -  54:91 81 00 48 stw r12,72(r1)

Re: [PATCH] Disable VSX instruction

2014-09-26 Thread Paulo Flabiano Smorigo
Fri, Sep 26, 2014 at 11:14:00AM +0100, Colin Watson wrote:
> On Thu, Sep 25, 2014 at 07:33:39PM -0300, Paulo Flabiano Smorigo wrote:
> > @@ -28,6 +30,14 @@
> > .globl  start, _start
> >  start:
> >  _start:
> > + _start:
> > +
> > +/* Disable VSX instruction */
> 
> Isn't the second _start: label here redundant?

yes, sorry. I will remove it from the patch.

Tks!

> 
> -- 
> Colin Watson   [cjwat...@ubuntu.com]
> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [RFC PATCH 0/3] grub powerpc64 little-endian enablement

2014-09-25 Thread Paulo Flabiano Smorigo
Sun, Sep 21, 2014 at 06:24:25PM +0400, Andrei Borzenkov wrote:
> В Sun, 21 Sep 2014 17:58:44 +0400
> Andrei Borzenkov  пишет:
> 
> > В Thu, 28 Aug 2014 16:56:02 -0300
> > Paulo Flabiano Smorigo  пишет:
> > 
> > > From: Paulo Flabiano Smorigo 
> > > 
> > > Hi,
> > > 
> > > At the beginning of the year we provide a patchset that enabled GRUB for
> > > little-endian PowerPC. Our approach at the time was to build GRUB itself 
> > > and
> > > its tools in 64-bit little-endian. One of the reasons of build in 64-bit 
> > > is
> > > to avoid 32-bit dependencies in the distro and build a system entirely 
> > > 64-bit.
> > > 
> > > This patchset was not welcomed at the time because it would bring a
> > > high-maintainance-cost, without real gain since it could just be 
> > > cross-compiled.
> > > 
> > > After that, Brent Baude, Vladmir (phcoder) and I started to work in a 
> > > solution
> > > that would cross-compile but without 32-bit dependencies. This patchset 
> > > is the
> > > result of this new approach. It's based on the work of Brent Baude, 
> > > Vladimir
> > > (phcoder), and Tomohiro.
> > > 
> > > It can be devided in two parts:
> > > 
> > >   1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
> > >   2) Check elf endianess and byteswap if necessary (patch 3);
> > > 
> > > The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This 
> > > solution
> > > satisfies the needs of the distros. I tested it in three different 
> > > distros, in
> > > both endianess and it's fine.
> > > 
> > 
> > Unfortunately I'm still not able to boot this version on QEMU. I build
> > on openSUSE for three acrhs - ppc, ppc64, ppc64le. First two are OK and
> > boot successfully. Third one does not work - it ends up in exception. I
> > get initial GRUB greeting and that's all.
> > 
> > Same problem I got with Vladimir libgcc patch series.
> > 
> > It could be toolkit issue of course; but still it would need fixing
> > before we can merge it.
> > 
> > Could you help in debugging this issue? I have near to zero experience
> > with PPC; I can do what you tell me, but not much more.
> > 
> > I run it with
> > 
> > qemu-system-ppc64 -M pseries -cdrom /tmp/grub2-ppc64le.iso -boot d
> > 
> > Attached is screenshot of error.
> > 
> > 
> 
> And here is the difference in generated code in case it helps (one
> random module as example) ...
> 
> --- /tmp/a1   2014-09-21 18:19:59.316494117 +0400
> +++ /tmp/a2   2014-09-21 18:20:06.169398736 +0400
> @@ -1,5 +1,5 @@
>  
> -usr.ppc/lib/grub2/powerpc-ieee1275/ext2.mod: file format elf32-powerpc
> +usr.ppc64le/lib/grub2/powerpc-ieee1275/ext2.mod: file format 
> elf32-powerpc
>  
>  
>  Disassembly of section .text:
> @@ -18,15 +18,15 @@ Disassembly of section .text:
>28:38 21 00 10 addir1,r1,16
>2c:7c 08 03 a6 mtlrr0
>30:4e 80 00 20 blr
> -  34:94 21 ff a0 stwur1,-96(r1)
> +  34:94 21 ff 90 stwur1,-112(r1)
>38:38 e3 00 28 addir7,r3,40
>3c:7d 80 00 26 mfcrr12
>40:39 23 00 14 addir9,r3,20
>44:7c 08 02 a6 mflrr0
>48:39 43 00 18 addir10,r3,24
> -  4c:bf 61 00 4c stmwr27,76(r1)
> -  50:90 01 00 64 stw r0,100(r1)
> -  54:91 81 00 48 stw r12,72(r1)
> +  4c:bf 61 00 5c stmwr27,92(r1)
> +  50:90 01 00 74 stw r0,116(r1)
> +  54:91 81 00 58 stw r12,88(r1)
>58:3b c4 ff ff addir30,r4,-1
>5c:7c 7f 1b 78 mr  r31,r3
>60:7c bc 2b 78 mr  r28,r5
> @@ -103,10 +103,10 @@ Disassembly of section .text:
>   17c:2f 83 00 00 cmpwi   cr7,r3,0
>   180:41 9e 00 08 beq cr7,188 
>   184:81 3d 00 00 lwz r9,0(r29)
> - 188:81 81 00 48 lwz r12,72(r1)
> - 18c:39 61 00 60 addir11,r1,96
> + 188:81 81 00 58 lwz r12,88(r1)
> + 18c:39 61 00 70 addir11,r1,112
>   190:7d 23 4b 78 mr  r3,r9
> - 194:7d 80 81 20 mtcrf   8,r12
> + 194:7d 90 81 20 mtocrf  8,r12
>   198:48 00 00 00 b   198 
>   19c:94 21 ff e0 stwur1,-32(r1)
>   1a0:7c 08 02 a6 mflrr0
> @@

[PATCH] Include a text attribute reset in the clear command for ppc

2014-09-25 Thread Paulo Flabiano Smorigo
Always clear text attribute for clear command in order to avoid problems
after it boots.

* grub-core/term/terminfo.c: Add escape for text attribute reset
---
 grub-core/term/terminfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
index f0d3e3d..7cb7909 100644
--- a/grub-core/term/terminfo.c
+++ b/grub-core/term/terminfo.c
@@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term,
   /* Clear the screen.  Using serial console, screen(1) only recognizes the
* ANSI escape sequence.  Using video console, Apple Open Firmware
* (version 3.1.1) only recognizes the literal ^L.  So use both.  */
-  data->cls   = grub_strdup ("\e[2J");
+  data->cls   = grub_strdup ("\e[2J\e[m");
   data->reverse_video_on  = grub_strdup ("\e[7m");
   data->reverse_video_off = grub_strdup ("\e[m");
   if (grub_strcmp ("ieee1275", str) == 0)
-- 
1.8.1.4


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Disable VSX instruction

2014-09-25 Thread Paulo Flabiano Smorigo
VSX bit is enabled by default for Power7 and Power8 CPU models,
so we need to disable them in order to avoid instruction exceptions.
Kernel will activate it when necessary.

* grub-core/kern/powerpc/ieee1275/startup.S: Disable VSX.

Also-By: Adhemerval Zanella 
---
 ChangeLog | 10 ++
 grub-core/kern/powerpc/ieee1275/startup.S | 10 ++
 2 files changed, 20 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 192e8bc..c1b0637 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-09-25  Paulo Flabiano Smroigo  
+
+   Disable VSX instruction
+
+   VSX bit is enabled by default for Power7 and Power8 CPU models, so we
+   need to disable them in order to avoid instruction exceptions. Kernel
+   will activate it when necessary.
+
+   * grub-core/kern/powerpc/ieee1275/startup.S: Disable VSX.
+
 2014-09-25  Colin Watson  
 
Fix in-tree --platform=none
diff --git a/grub-core/kern/powerpc/ieee1275/startup.S 
b/grub-core/kern/powerpc/ieee1275/startup.S
index 21c884b..c4621a6 100644
--- a/grub-core/kern/powerpc/ieee1275/startup.S
+++ b/grub-core/kern/powerpc/ieee1275/startup.S
@@ -20,6 +20,8 @@
 #include 
 #include 
 
+#define MSR_VSX 0x80
+
 .extern __bss_start
 .extern _end
 
@@ -28,6 +30,14 @@
.globl  start, _start
 start:
 _start:
+ _start:
+
+/* Disable VSX instruction */
+   mfmsr  0
+   oris   0,0,MSR_VSX
+   mtmsrd 0
+   isync
+
li  2, 0
li  13, 0
 
-- 
1.8.1.4


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Disable VSX instruction

2014-09-25 Thread Paulo Flabiano Smorigo
VSX bit is enabled by default for Power7 and Power8 CPU models,
so we need to disable them in order to avoid instruction exceptions.
Kernel will activate it when necessary.

Also-By: Adhemerval Zanella 
---
 ChangeLog | 10 ++
 grub-core/kern/powerpc/ieee1275/startup.S | 10 ++
 2 files changed, 20 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 192e8bc..c1b0637 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-09-25  Paulo Flabiano Smroigo  
+
+   Disable VSX instruction
+
+   VSX bit is enabled by default for Power7 and Power8 CPU models, so we
+   need to disable them in order to avoid instruction exceptions. Kernel
+   will activate it when necessary.
+
+   * grub-core/kern/powerpc/ieee1275/startup.S: Disable VSX.
+
 2014-09-25  Colin Watson  
 
Fix in-tree --platform=none
diff --git a/grub-core/kern/powerpc/ieee1275/startup.S 
b/grub-core/kern/powerpc/ieee1275/startup.S
index 21c884b..c4621a6 100644
--- a/grub-core/kern/powerpc/ieee1275/startup.S
+++ b/grub-core/kern/powerpc/ieee1275/startup.S
@@ -20,6 +20,8 @@
 #include 
 #include 
 
+#define MSR_VSX 0x80
+
 .extern __bss_start
 .extern _end
 
@@ -28,6 +30,14 @@
.globl  start, _start
 start:
 _start:
+ _start:
+
+/* Disable VSX interrupt instruction */
+   mfmsr  0
+   oris   0,0,MSR_VSX
+   mtmsrd 0
+   isync
+
li  2, 0
li  13, 0
 
-- 
1.8.1.4


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Include a text attribute reset in the clear command for ppc

2014-09-25 Thread Paulo Flabiano Smorigo
Always clear text attribute for clear command in order to avoid problems
after it boots.

* grub-core/term/terminfo.c: Add escape for text attribute reset
---
 grub-core/term/terminfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
index f0d3e3d..7cb7909 100644
--- a/grub-core/term/terminfo.c
+++ b/grub-core/term/terminfo.c
@@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term,
   /* Clear the screen.  Using serial console, screen(1) only recognizes the
* ANSI escape sequence.  Using video console, Apple Open Firmware
* (version 3.1.1) only recognizes the literal ^L.  So use both.  */
-  data->cls   = grub_strdup ("\e[2J");
+  data->cls   = grub_strdup ("\e[2J\e[m");
   data->reverse_video_on  = grub_strdup ("\e[7m");
   data->reverse_video_off = grub_strdup ("\e[m");
   if (grub_strcmp ("ieee1275", str) == 0)
-- 
1.8.1.4


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags

2014-09-17 Thread Paulo Flabiano Smorigo
Thu, Aug 28, 2014 at 04:56:03PM -0300, Paulo Flabiano Smorigo wrote:
> libgcc dependency was removed *just* for this target because
> the distros that use ppc64el doesn't have 32-bit support on it.
> 
> * configure.ac: Add targets for powerpc64el and skip libgcc.
> * Makefile.am: Likewise.
> ---
>  configure.ac  | 17 +++--
>  grub-core/Makefile.am |  2 ++
>  2 files changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index c2f..1364c8b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -119,6 +119,7 @@ if test "x$with_platform" = x; then
>  x86_64-*) platform=pc ;;
>  powerpc-*) platform=ieee1275 ;;
>  powerpc64-*) platform=ieee1275 ;;
> +powerpc64le-*) platform=ieee1275 ;;
>  sparc64-*) platform=ieee1275 ;;
>  mipsel-*) platform=loongson ;;
>  mips-*) platform=arc ;;
> @@ -137,6 +138,7 @@ case "$target_cpu"-"$platform" in
>x86_64-xen) ;;
>x86_64-*) target_cpu=i386 ;;
>powerpc64-ieee1275) target_cpu=powerpc ;;
> +  powerpc64le-ieee1275) target_cpu=powerpc ;;
>  esac
> 
>  # Check if the platform is supported, make final adjustments.
> @@ -581,6 +583,13 @@ if test "x$target_cpu" = xi386 && test "x$platform" != 
> xemu; then
>TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
>  fi
> 
> +if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
> + LD_FORCE_LE=1
> + TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian -DNO_LIBGCC=1"
> + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
> + TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
> +fi
> +
>  if test "x$target_m32" = x1; then
># Force 32-bit mode.
>TARGET_CFLAGS="$TARGET_CFLAGS -m32"
> @@ -1024,7 +1033,8 @@ else
>  CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
>  fi
>  CPPFLAGS="$TARGET_CPPFLAGS"
> -if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test 
> "x$grub_cv_cc_target_clang" = xyes ; then
> +if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test 
> "x$grub_cv_cc_target_clang" = xyes \
> + || ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); 
> then
>  TARGET_LIBGCC=
>  else
>  TARGET_LIBGCC=-lgcc
> @@ -1608,7 +1618,9 @@ if test x"$enable_werror" != xno ; then
>HOST_CFLAGS="$HOST_CFLAGS -Werror"
>  fi
> 
> -if test "x$grub_cv_cc_target_clang" = xno; then
> +# if not clang or power LE, use static libgcc
> +if test "x$grub_cv_cc_target_clang" = xno \
> +   || ! ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); 
> then
> TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
>  else
> TARGET_LDFLAGS_STATIC_LIBGCC=
> @@ -1671,6 +1683,7 @@ AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu 
> = xmips -o x$target_cpu =
>  AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a 
> x$platform = xieee1275])
>  AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a 
> x$platform = xemu])
>  AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a 
> x$platform = xieee1275])
> +AM_CONDITIONAL([COND_powerpc_le], [test x$target_cpu = xpowerpc -a 
> x$ac_cv_c_bigendian = xno])
>  AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = 
> xmipsel])
>  AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
>  AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
> diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
> index 5c087c8..cb7fd9f 100644
> --- a/grub-core/Makefile.am
> +++ b/grub-core/Makefile.am
> @@ -84,8 +84,10 @@ 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
>  if !COND_clang
> +if !COND_powerpc_le
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
>  endif
> +endif
>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
> 
>  if COND_i386_pc
> -- 
> 1.8.1.4
> 
> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 

I just moved some part of this patch to the second one. Now this patch
only add the target and all libgcc stuff is in the second one.

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center
>From 7a2e287e6ed00476c6760797541c3aff49dbeb40 Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo 
Date: Wed, 17 Sep 2014 14:42:40 -0300
Subject: [PA

Re: [RFC PATCH 2/3] Files reorganization and include some libgcc fuctions

2014-09-17 Thread Paulo Flabiano Smorigo
Colin, I changed the patches following your suggestions and making it
more likely to the no-libgcc branch from Vladimir. In this branch,
phcoder added compiler-rt.{c,h,S} with the necessary code in it.

My approach is very minimalist and only for powerpc. I tried to avoid
change the behavior for other architecture since we are in code freeze.

In the future we can think in spread this approach for all archs and use
all implementation that phcoder is doing in the no-libgcc branch.

Mon, Sep 08, 2014 at 03:16:21AM +0100, Colin Watson wrote:
> On Thu, Aug 28, 2014 at 04:56:04PM -0300, Paulo Flabiano Smorigo wrote:
> > diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> > index c5c815d..353a207 100644
> > --- a/grub-core/kern/misc.c
> > +++ b/grub-core/kern/misc.c
> > @@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
> >grub_error_pop ();
> >  }
> >  #endif
> > +
> > +#if defined (NO_LIBGCC)
> 
> Should this perhaps be restricted to __powerpc__ as well?
> Alternatively, the prototypes in include/grub/compiler.h (or
> include/grub/misc.h; see below) should be used on other architectures
> too.  Either way, the declarations and definitions should match.

Yes, now I only use __powerpc__

> 
> > diff --git a/include/grub/compiler.h b/include/grub/compiler.h
> > index c9e1d7a..a9a684c 100644
> > --- a/include/grub/compiler.h
> > +++ b/include/grub/compiler.h
> > @@ -48,4 +48,65 @@
> >  #  define WARN_UNUSED_RESULT
> >  #endif
> >  
> > +#include "types.h"
> 
> Shouldn't this be #include , assuming that you need this
> for grub_uint*_t?  Also, includes should generally be grouped at the top
> of the file.

All in the compile-rt.c now

> 
> > +union component64
> > +{
> > +  grub_uint64_t full;
> > +  struct
> > +  {
> > +#ifdef GRUB_CPU_WORDS_BIGENDIAN
> > +grub_uint32_t high;
> > +grub_uint32_t low;
> > +#else
> > +grub_uint32_t low;
> > +grub_uint32_t high;
> > +#endif
> > +  };
> > +};
> 
> This is only used by grub-core/kern/misc.c.  Please move it there rather
> than putting it somewhere that's included by everything in GRUB.
> 
> > +#if defined (__powerpc__)
> 
> Should this be #if defined (__powerpc__) && defined (NO_LIBGCC) or
> something similar, to match the general way things are set up in
> configure.ac?  (Also see comment above about declarations matching
> definitions.)

Fixed.

> 
> Relatedly, have you tested this patch set with a native build on a
> 32-bit BE powerpc system, as opposed to 32-bit BE built on a 64-bit LE
> system?  This looks like a potential problem there.
> 

Yes. I tested it in both BE and LE systems. No problem found. I did
another round of test with this changes and will do some more this week.

> > +grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
> > +grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b);
> > +grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b);
> > +int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
> > +void EXPORT_FUNC (_restgpr_14_x) (void);
> [...]
>
> These aren't compiler features, so don't belong in
> include/grub/compiler.h.  Other architectures seem to have this kind of
> thing in include/grub/misc.h inside a big #ifndef GRUB_UTIL conditional,
> so please move all this to there.

Yes, I follow what phcoder did in no-libgcc branch. This lines are in
the compiler-rt.c file.

> 
> > diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h
> > index 8e93b67..5bdb8fb 100644
> > --- a/include/grub/libgcc.h
> > +++ b/include/grub/libgcc.h
> > @@ -16,73 +16,6 @@
> >   *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> >   */
> >  
> > -/* We need to include config-util.h.in for HAVE_*.  */
> > -#ifndef __STDC_VERSION__
> > -#define __STDC_VERSION__ 0
> > -#endif
> > -#include 
> > -
> > -/* On x86 these functions aren't really needed. Save some space.  */
> > -#if !defined (__i386__) && !defined (__x86_64__)
> > -# ifdef HAVE___ASHLDI3
> > -void EXPORT_FUNC (__ashldi3) (void);
> > -# endif
> > -# ifdef HAVE___ASHRDI3
> > -void EXPORT_FUNC (__ashrdi3) (void);
> > -# endif
> > -# ifdef HAVE___LSHRDI3
> > -void EXPORT_FUNC (__lshrdi3) (void);
> > -# endif
> > -# ifdef HAVE___UCMPDI2
> > -void EXPORT_FUNC (__ucmpdi2) (void);
> > -# endif
> > -# ifdef HAVE___BSWAPSI2
> > -void EXPORT_FUNC (__bswapsi2) (void);
> > -# endif
> > -# ifdef HAVE___BSWAPDI2
> > -void EXPORT_FUNC (__bswapdi

[RFC PATCH 2/3] Files reorganization and include some libgcc fuctions

2014-08-28 Thread Paulo Flabiano Smorigo
As we avoid libgcc dependency for powerpc64el, we moved some functions
to other files and add the necessary ones.

* Makefile.core.def: Include compiler-rt.S.
* misc.c: Add the necessary libgcc functions.
* compiler-rt.S: New file.
* libgcc.h: Move some content from here ...
* compiler.h: ... to here.

Also-By: Brent Baude 
Also-By: Vladimir 'phcoder' Serbinenko 
---
 grub-core/Makefile.core.def  |   1 +
 grub-core/kern/misc.c| 107 
 grub-core/kern/powerpc/compiler-rt.S | 130 +++
 include/grub/compiler.h  |  61 
 include/grub/libgcc.h|  67 --
 5 files changed, 299 insertions(+), 67 deletions(-)
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 42443bc..65858d9 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -252,6 +252,7 @@ kernel = {
 
   powerpc_ieee1275 = kern/powerpc/cache.S;
   powerpc_ieee1275 = kern/powerpc/dl.c;
+  powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
 
   sparc64_ieee1275 = kern/sparc64/cache.S;
   sparc64_ieee1275 = kern/sparc64/dl.c;
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index c5c815d..353a207 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -1342,3 +1342,110 @@ grub_real_boot_time (const char *file,
   grub_error_pop ();
 }
 #endif
+
+#if defined (NO_LIBGCC)
+
+/* Based on libgcc2.c from gcc suite.  */
+int
+__ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
+{
+  union component64 ac, bc;
+  ac.full = a;
+  bc.full = b;
+
+  if (ac.high < bc.high)
+return 0;
+  else if (ac.high > bc.high)
+return 2;
+
+  if (ac.low < bc.low)
+return 0;
+  else if (ac.low > bc.low)
+return 2;
+  return 1;
+}
+
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__lshrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+{
+  w.high = 0;
+  w.low = (grub_uint32_t) uu.high >> -bm;
+}
+  else
+{
+  const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+  w.high = (grub_uint32_t) uu.high >> b;
+  w.low = ((grub_uint32_t) uu.low >> b) | carries;
+}
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashrdi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+{
+  /* w.high = 1..1 or 0..0 */
+  w.high = uu.high >> (32 - 1);
+  w.low = uu.high >> -bm;
+}
+  else
+{
+  const grub_uint32_t carries = (grub_uint32_t) uu.high << bm;
+
+  w.high = uu.high >> b;
+  w.low = ((grub_uint32_t) uu.low >> b) | carries;
+}
+
+  return w.full;
+}
+
+/* Based on libgcc2.c from gcc suite.  */
+grub_uint64_t
+__ashldi3 (grub_uint64_t u, int b)
+{
+  if (b == 0)
+return u;
+
+  const union component64 uu = {.full = u};
+  const int bm = 32 - b;
+  union component64 w;
+
+  if (bm <= 0)
+{
+  w.low = 0;
+  w.high = (grub_uint32_t) uu.low << -bm;
+}
+  else
+{
+  const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm;
+
+  w.low = (grub_uint32_t) uu.low << b;
+  w.high = ((grub_uint32_t) uu.high << b) | carries;
+}
+
+  return w.full;
+}
+
+#endif
diff --git a/grub-core/kern/powerpc/compiler-rt.S 
b/grub-core/kern/powerpc/compiler-rt.S
new file mode 100644
index 000..63e3a0d
--- /dev/null
+++ b/grub-core/kern/powerpc/compiler-rt.S
@@ -0,0 +1,130 @@
+/*
+ * Special support for eabi and SVR4
+ *
+ *   Copyright (C) 1995-2014 Free Software Foundation, Inc.
+ *   Written By Michael Meissner
+ *   64-bit support written by David Edelsohn
+ *
+ * This file 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, or (at your option) any
+ * later version.
+ *
+ * This file 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.
+ *
+ * Under Section 7 of GPL version 3, you are granted additional
+ * permissions described in the GCC Runtime Library Exception, version
+ * 3.1, as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * a copy of the GCC Runtime Library Exception along with this program;
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ * .
+ */
+
+/* Do any initializations needed for the eabi environment */
+
+#include 
+#include 
+
+   .section ".text"
+
+#define CFI_RESTORE(reg) 

[RFC PATCH 3/3] Suport for bi-endianess in elf file

2014-08-28 Thread Paulo Flabiano Smorigo
* grub-core/kern/elf.c: check and switch endianess with grub_{be,le}_to
  cpu functions.
* grub-core/kern/elfXX.c: Likewise.

Also-by: Tomohiro B Berry 
---
 grub-core/kern/elf.c   | 60 +++--
 grub-core/kern/elfXX.c | 73 ++
 2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c
index 5f99c43..de90811 100644
--- a/grub-core/kern/elf.c
+++ b/grub-core/kern/elf.c
@@ -28,6 +28,11 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+void grub_elf32_check_endianess (grub_elf_t elf);
+void grub_elf64_check_endianess (grub_elf_t elf);
+grub_err_t grub_elf32_check_version (grub_elf_t elf);
+grub_err_t grub_elf64_check_version (grub_elf_t elf);
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_elf_check_header (grub_elf_t elf)
@@ -38,10 +43,22 @@ grub_elf_check_header (grub_elf_t elf)
   || 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
-  || e->e_version != EV_CURRENT)
+  || e->e_ident[EI_VERSION] != EV_CURRENT)
 return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF 
magic"));
 
+  if (grub_elf_is_elf32 (elf))
+{
+  grub_elf32_check_endianess (elf);
+  grub_elf32_check_version (elf);
+}
+  else if (grub_elf_is_elf64 (elf))
+{
+  grub_elf64_check_endianess (elf);
+  grub_elf64_check_version (elf);
+}
+  else
+return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF 
magic"));
+
   return GRUB_ERR_NONE;
 }
 
@@ -127,7 +144,20 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf32
 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs
 #define ElfXX_Phdr Elf32_Phdr
+#define ElfXX_Ehdr Elf32_Ehdr
 #define grub_uintXX_t grub_uint32_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu32
+#define grub_be_to_offXX grub_be_to_cpu32
+#define grub_be_to_XwordXX grub_be_to_wordXX
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu32
+#define grub_le_to_offXX grub_le_to_cpu32
+#define grub_le_to_XwordXX grub_le_to_wordXX
+#define grub_elfXX_check_endianess grub_elf32_check_endianess
+#define grub_elfXX_check_version grub_elf32_check_version
 
 #include "elfXX.c"
 
@@ -140,7 +170,20 @@ grub_elf_open (const char *name)
 #undef grub_elf_is_elfXX
 #undef grub_elfXX_load_phdrs
 #undef ElfXX_Phdr
+#undef ElfXX_Ehdr
 #undef grub_uintXX_t
+#undef grub_be_to_halfXX
+#undef grub_be_to_wordXX
+#undef grub_be_to_addrXX
+#undef grub_be_to_offXX
+#undef grub_be_to_XwordXX
+#undef grub_le_to_halfXX
+#undef grub_le_to_wordXX
+#undef grub_le_to_addrXX
+#undef grub_le_to_offXX
+#undef grub_le_to_XwordXX
+#undef grub_elfXX_check_endianess
+#undef grub_elfXX_check_version
 
 
 /* 64-bit */
@@ -153,6 +196,19 @@ grub_elf_open (const char *name)
 #define grub_elf_is_elfXX grub_elf_is_elf64
 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs
 #define ElfXX_Phdr Elf64_Phdr
+#define ElfXX_Ehdr Elf64_Ehdr
 #define grub_uintXX_t grub_uint64_t
+#define grub_be_to_halfXX grub_be_to_cpu16
+#define grub_be_to_wordXX grub_be_to_cpu32
+#define grub_be_to_addrXX grub_be_to_cpu64
+#define grub_be_to_offXX grub_be_to_cpu64
+#define grub_be_to_XwordXX grub_be_to_cpu64
+#define grub_le_to_halfXX grub_le_to_cpu16
+#define grub_le_to_wordXX grub_le_to_cpu32
+#define grub_le_to_addrXX grub_le_to_cpu64
+#define grub_le_to_offXX grub_le_to_cpu64
+#define grub_le_to_XwordXX grub_le_to_cpu64
+#define grub_elfXX_check_endianess grub_elf64_check_endianess
+#define grub_elfXX_check_version grub_elf64_check_version
 
 #include "elfXX.c"
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index 1d09971..ecf9df6 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -154,3 +154,76 @@ grub_elfXX_load (grub_elf_t elf, const char *filename,
 
   return grub_errno;
 }
+
+void
+grub_elfXX_check_endianess (grub_elf_t elf)
+{
+  ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX);
+  ElfXX_Phdr *phdr;
+
+  if (e->e_ident[EI_DATA] == ELFDATA2MSB)
+{
+  e->e_type = grub_be_to_halfXX (e->e_type);
+  e->e_machine = grub_be_to_halfXX (e->e_machine);
+  e->e_version = grub_be_to_wordXX (e->e_version);
+  e->e_entry = grub_be_to_addrXX (e->e_entry);
+  e->e_phoff = grub_be_to_offXX (e->e_phoff);
+  e->e_shoff = grub_be_to_offXX (e->e_shoff);
+  e->e_flags = grub_be_to_wordXX (e->e_flags);
+  e->e_ehsize = grub_be_to_halfXX (e->e_ehsize);
+  e->e_phentsize = grub_be_to_halfXX (e->e_phentsize);
+  e->e_phnum = grub_be_to_halfXX (e->e_phnum);
+  e->e_shentsize = grub_be_to_halfXX (e->e_shentsize);
+  e->e_shnum = grub_be_to_halfXX (e->e_shnum);
+  e->e_shstrndx = grub_be_to_halfXX (e->e_shstrndx);
+
+  FOR_ELFXX_PHDRS (el

[RFC PATCH 1/3] Add powerpc little-endian (ppc64le) flags

2014-08-28 Thread Paulo Flabiano Smorigo
libgcc dependency was removed *just* for this target because
the distros that use ppc64el doesn't have 32-bit support on it.

* configure.ac: Add targets for powerpc64el and skip libgcc.
* Makefile.am: Likewise.
---
 configure.ac  | 17 +++--
 grub-core/Makefile.am |  2 ++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index c2f..1364c8b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,7 @@ if test "x$with_platform" = x; then
 x86_64-*) platform=pc ;;
 powerpc-*) platform=ieee1275 ;;
 powerpc64-*) platform=ieee1275 ;;
+powerpc64le-*) platform=ieee1275 ;;
 sparc64-*) platform=ieee1275 ;;
 mipsel-*) platform=loongson ;;
 mips-*) platform=arc ;;
@@ -137,6 +138,7 @@ case "$target_cpu"-"$platform" in
   x86_64-xen) ;;
   x86_64-*) target_cpu=i386 ;;
   powerpc64-ieee1275) target_cpu=powerpc ;;
+  powerpc64le-ieee1275) target_cpu=powerpc ;;
 esac
 
 # Check if the platform is supported, make final adjustments.
@@ -581,6 +583,13 @@ if test "x$target_cpu" = xi386 && test "x$platform" != 
xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
+if test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno; then
+   LD_FORCE_LE=1
+   TARGET_CFLAGS="$TARGET_CFLAGS -mbig-endian -DNO_LIBGCC=1"
+   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mbig-endian"
+   TARGET_LDFLAGS="$TARGET_LDFLAGS -static -mbig-endian"
+fi
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
@@ -1024,7 +1033,8 @@ else
 CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
 fi
 CPPFLAGS="$TARGET_CPPFLAGS"
-if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test 
"x$grub_cv_cc_target_clang" = xyes ; then
+if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test 
"x$grub_cv_cc_target_clang" = xyes \
+   || ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); 
then
 TARGET_LIBGCC=
 else
 TARGET_LIBGCC=-lgcc
@@ -1608,7 +1618,9 @@ if test x"$enable_werror" != xno ; then
   HOST_CFLAGS="$HOST_CFLAGS -Werror"
 fi
 
-if test "x$grub_cv_cc_target_clang" = xno; then
+# if not clang or power LE, use static libgcc
+if test "x$grub_cv_cc_target_clang" = xno \
+   || ! ( test x$target_cpu = xpowerpc && test x$ac_cv_c_bigendian = xno ); 
then
TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
 else
TARGET_LDFLAGS_STATIC_LIBGCC=
@@ -1671,6 +1683,7 @@ AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = 
xmips -o x$target_cpu =
 AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a 
x$platform = xieee1275])
 AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform 
= xemu])
 AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a 
x$platform = xieee1275])
+AM_CONDITIONAL([COND_powerpc_le], [test x$target_cpu = xpowerpc -a 
x$ac_cv_c_bigendian = xno])
 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = 
xmipsel])
 AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index 5c087c8..cb7fd9f 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -84,8 +84,10 @@ 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
 if !COND_clang
+if !COND_powerpc_le
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
 endif
+endif
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
 
 if COND_i386_pc
-- 
1.8.1.4


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[RFC PATCH 0/3] grub powerpc64 little-endian enablement

2014-08-28 Thread Paulo Flabiano Smorigo
From: Paulo Flabiano Smorigo 

Hi,

At the beginning of the year we provide a patchset that enabled GRUB for
little-endian PowerPC. Our approach at the time was to build GRUB itself and
its tools in 64-bit little-endian. One of the reasons of build in 64-bit is
to avoid 32-bit dependencies in the distro and build a system entirely 64-bit.

This patchset was not welcomed at the time because it would bring a
high-maintainance-cost, without real gain since it could just be cross-compiled.

After that, Brent Baude, Vladmir (phcoder) and I started to work in a solution
that would cross-compile but without 32-bit dependencies. This patchset is the
result of this new approach. It's based on the work of Brent Baude, Vladimir
(phcoder), and Tomohiro.

It can be devided in two parts:

  1) Skip libgcc dependency just for ppc64el (patch 1 and 2);
  2) Check elf endianess and byteswap if necessary (patch 3);

The result is GRUB itself in 32-bit BE and its tools in 64-bit LE. This solution
satisfies the needs of the distros. I tested it in three different distros, in
both endianess and it's fine.

If thoses patches were accepted we will have an official solution. Nowadays,
distros are taking diffrent approachs. Some of then are using the original
solutions and others are using cross-compiler.

--
Paulo Flabiano Smorigo
IBM Linux Technology Center


Paulo Flabiano Smorigo (3):
  Add powerpc little-endian (ppc64le) flags
  Files reorganization and include some libgcc fuctions
  Suport for bi-endianess in elf file

 configure.ac |  17 -
 grub-core/Makefile.am|   2 +
 grub-core/Makefile.core.def  |   1 +
 grub-core/kern/elf.c |  60 +++-
 grub-core/kern/elfXX.c   |  73 
 grub-core/kern/misc.c| 107 
 grub-core/kern/powerpc/compiler-rt.S | 130 +++
 include/grub/compiler.h  |  61 
 include/grub/libgcc.h|  67 --
 9 files changed, 447 insertions(+), 71 deletions(-)
 create mode 100644 grub-core/kern/powerpc/compiler-rt.S

-- 
1.8.1.4


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] grub-core/net/arp.c: trim arp packets with abnormal size.

2014-01-31 Thread Paulo Flabiano Smorigo
Fri, Jan 31, 2014 at 08:02:07PM +0400, Andrey Borzenkov wrote:
> В Fri, 31 Jan 2014 13:35:11 -0200
> Paulo Flabiano Smorigo  пишет:
> 
> > * grub-core/net/arp.c (grub_net_arp_receive): Trim arp packets with 
> > abnormal size.
> > 
> > GRUB uses arp request to create the arp response. If the incoming packet is
> > foobared, GRUB needs to trim the arp response packet before sending it.
> > 
> > This is just a fix in time for 2.02. I'm planning to rewrite the arp 
> > response code
> > after the release.
> > 
> > diff --git a/ChangeLog b/ChangeLog
> > index cfa9c83..10e9c3d 100644
> > --- a/ChangeLog
> > +++ b/ChangeLog
> > @@ -1,3 +1,11 @@
> > +2014-01-31  Paulo Flabiano Smorigo  
> > +
> > +   * grub-core/net/arp.c (grub_net_arp_receive): Trim arp packets with
> > +   abnormal size.
> > +
> > +   GRUB uses arp request to create the arp response. If the incoming 
> > packet is
> > +   foobared, GRUB needs to trim the arp response packet before sending it.
> > +
> >  2014-01-29  Vladimir Serbinenko  
> >  
> > * grub-core/disk/ahci.c: Increase timeout. Some SSDs take up to
> > diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c
> > index d62d0cc..77581f4 100644
> > --- a/grub-core/net/arp.c
> > +++ b/grub-core/net/arp.c
> > @@ -162,6 +162,12 @@ grub_net_arp_receive (struct grub_net_buff *nb,
> >  if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
> > && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST)
> >{
> > +if ((nb->tail - nb->data) > 50)
> 
> Using large ping size is quite common during network troubleshooting.
> This looks like rather arbitrary restriction. I'd say - if we were able
> to receive packet we should be able to also send packet of the same
> size; what problem does it fix?

I hit a firmware bug where after a while every packet comes with MTU 
size (~1500 bytes). GRUB handles those foobared packets well and the
only problem is the case that I described above:

ARP responses are built using ARP request as its base. ARP responses
with trash are usually ignored by the network and my patch only trim the arp
responses to the corrent size, nothing more.

> 
> > +  {
> > +grub_dprintf ("net", "arp packet with abnormal size (%ld 
> > bytes).\n",
> > + nb->tail - nb->data);
> > +nb->tail = nb->data + 50;
> > +  }
> > grub_net_link_level_address_t target;
> > /* We've already checked that pln is either 4 or 16.  */
> > char tmp[16];
> > 
> 
> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] grub-core/net/arp.c: trim arp packets with abnormal size.

2014-01-31 Thread Paulo Flabiano Smorigo
* grub-core/net/arp.c (grub_net_arp_receive): Trim arp packets with abnormal 
size.

GRUB uses arp request to create the arp response. If the incoming packet is
foobared, GRUB needs to trim the arp response packet before sending it.

This is just a fix in time for 2.02. I'm planning to rewrite the arp response 
code
after the release.

diff --git a/ChangeLog b/ChangeLog
index cfa9c83..10e9c3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-01-31  Paulo Flabiano Smorigo  
+
+   * grub-core/net/arp.c (grub_net_arp_receive): Trim arp packets with
+   abnormal size.
+
+   GRUB uses arp request to create the arp response. If the incoming 
packet is
+   foobared, GRUB needs to trim the arp response packet before sending it.
+
 2014-01-29  Vladimir Serbinenko  
 
* grub-core/disk/ahci.c: Increase timeout. Some SSDs take up to
diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c
index d62d0cc..77581f4 100644
--- a/grub-core/net/arp.c
+++ b/grub-core/net/arp.c
@@ -162,6 +162,12 @@ grub_net_arp_receive (struct grub_net_buff *nb,
 if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
&& grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST)
   {
+if ((nb->tail - nb->data) > 50)
+  {
+grub_dprintf ("net", "arp packet with abnormal size (%ld 
bytes).\n",
+ nb->tail - nb->data);
+nb->tail = nb->data + 50;
+  }
grub_net_link_level_address_t target;
/* We've already checked that pln is either 4 or 16.  */
char tmp[16];

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] add a exit condition even for no stop case

2014-01-20 Thread Paulo Flabiano Smorigo
Hi all,

As I said in the my last email, I'm running tests in a network with
heavy traffic, like, over 150 arp requests comming every second. Under these
condition, I found an issue in the receive_packets function.

On line 1456 of net/net.c there is a while (1) that only exits if there
is a stop condition and more then 10 packages or if there is no package
received.

If GRUB is idle and enter in this loop, the only condition to leave is
if it doesn't have incoming packages. In a network with heavy traffic
(like mine) this never happens.

The result is that GRUB becomes muted and freeze.

I made a small fix that exits this loop if the incoming packages rearch
a maximum level. I used 100 packages and it seems fine.

---
 grub-core/net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 683ab28..f2e723b 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -1453,7 +1453,7 @@ receive_packets (struct grub_net_card *card, int 
*stop_condition)
}
   card->opened = 1;
 }
-  while (1)
+  while (received < 100)
 {
   /* Maybe should be better have a fixed number of packets for each card
 and just mark them as used and not used.  */ 
-- 
1.8.2.1


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] increase network try interval gradually

2014-01-20 Thread Paulo Flabiano Smorigo
Hi all,

This patch changes GRUB net interval gradually over time to avoid timeout
problems. I'm currently doing tests in a network with heavy traffic. In this
network GRUB fails with the original timeout value.

---
 grub-core/net/arp.c   | 3 ++-
 grub-core/net/icmp6.c | 3 ++-
 grub-core/net/net.c   | 5 +++--
 grub-core/net/tftp.c  | 3 ++-
 include/grub/net.h| 1 +
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c
index 3076b18..248bd4b 100644
--- a/grub-core/net/arp.c
+++ b/grub-core/net/arp.c
@@ -110,7 +110,8 @@ grub_net_arp_send_request (struct 
grub_net_network_level_interface *inf,
return GRUB_ERR_NONE;
   pending_req = proto_addr->ipv4;
   have_pending = 0;
-  grub_net_poll_cards (GRUB_NET_INTERVAL, &have_pending);
+  grub_net_poll_cards (GRUB_NET_INTERVAL + (i * 
GRUB_NET_INTERVAL_ADDITION),
+   &have_pending);
   if (grub_net_link_layer_resolve_check (inf, proto_addr))
return GRUB_ERR_NONE;
   nb.data = nbd;
diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c
index 2741e6f..bbc9020 100644
--- a/grub-core/net/icmp6.c
+++ b/grub-core/net/icmp6.c
@@ -518,7 +518,8 @@ grub_net_icmp6_send_request (struct 
grub_net_network_level_interface *inf,
 {
   if (grub_net_link_layer_resolve_check (inf, proto_addr))
break;
-  grub_net_poll_cards (GRUB_NET_INTERVAL, 0);
+  grub_net_poll_cards (GRUB_NET_INTERVAL + (i * 
GRUB_NET_INTERVAL_ADDITION),
+   0);
   if (grub_net_link_layer_resolve_check (inf, proto_addr))
break;
   nb->data = nbd;
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 8f9d183..683ab28 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -1596,8 +1596,9 @@ grub_net_fs_read_real (grub_file_t file, char *buf, 
grub_size_t len)
   if (!net->eof)
{
  try++;
- grub_net_poll_cards (GRUB_NET_INTERVAL, &net->stall);
-   }
+ grub_net_poll_cards (GRUB_NET_INTERVAL +
+   (try * GRUB_NET_INTERVAL_ADDITION), 
&net->stall);
+}
   else
return total;
 }
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index 9c489f1..5173614 100644
--- a/grub-core/net/tftp.c
+++ b/grub-core/net/tftp.c
@@ -398,7 +398,8 @@ tftp_open (struct grub_file *file, const char *filename)
  destroy_pq (data);
  return err;
}
-  grub_net_poll_cards (GRUB_NET_INTERVAL, &data->have_oack);
+  grub_net_poll_cards (GRUB_NET_INTERVAL + (i * 
GRUB_NET_INTERVAL_ADDITION),
+   &data->have_oack);
   if (data->have_oack)
break;
 }
diff --git a/include/grub/net.h b/include/grub/net.h
index 843f74f..538baa3 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -536,5 +536,6 @@ extern char *grub_net_default_server;
 
 #define GRUB_NET_TRIES 40
 #define GRUB_NET_INTERVAL 400
+#define GRUB_NET_INTERVAL_ADDITION 20
 
 #endif /* ! GRUB_NET_HEADER */
-- 
1.8.2.1


-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Request a freeze exception for vlantag feature

2014-01-09 Thread Paulo Flabiano Smorigo
Thu, Jan 09, 2014 at 07:05:16AM +0400, Andrey Borzenkov wrote:
> В Wed, 8 Jan 2014 16:57:28 -0200
> Paulo Flabiano Smorigo  пишет:
> 
> > +
> > +  inter->vlantag.pcp = vlantag >> 12;
> > +  inter->vlantag.dei = (vlantag >> 11) & 0x1;
> > +  inter->vlantag.vid = vlantag & 0x1fff;
> 
> That's 13 bits, not 12, right? And this really looks like
> overengeneering - do you really want to be able to set static VLAN
> priority bits? I do not think it belongs to grub.
> 
> > +
> > +  if (grub_strcmp (args[3], "vlan") == 0)
> > +vlan_pos = 3;
> > +
> > +  if (grub_strcmp (args[4], "vlan") == 0)
> > +vlan_pos = 4;
> 

You're right, thanks. I fixed:

diff --git a/grub-core/net/drivers/ieee1275/ofnet.c 
b/grub-core/net/drivers/ieee1275/ofnet.c
index ffcb943..72359c3 100644
--- a/grub-core/net/drivers/ieee1275/ofnet.c
+++ b/grub-core/net/drivers/ieee1275/ofnet.c
@@ -213,13 +213,12 @@ grub_ieee1275_parse_bootargs (const char *devpath, char 
*bootpath,
   inter = grub_net_add_addr ((*card)->name, *card, &client_addr, &hw_addr,
  flags);
 
-  inter->vlantag.pcp = vlantag >> 12;
-  inter->vlantag.dei = (vlantag >> 11) & 0x1;
-  inter->vlantag.vid = vlantag & 0x1fff;
+  inter->vlantag.pcp = vlantag >> 13;
+  inter->vlantag.dei = (vlantag >> 12) & 0x1;
+  inter->vlantag.vid = vlantag & 0xfff;
 
   grub_net_add_ipv4_local (inter,
   __builtin_ctz (~grub_le_to_cpu32 
(subnet_mask.ipv4)));
-
 }
 
   if (gateway_addr.ipv4 != 0)
diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c
index ae195bc..7ca14e9 100644
--- a/grub-core/net/ethernet.c
+++ b/grub-core/net/ethernet.c
@@ -88,8 +88,8 @@ send_ethernet_packet (struct grub_net_network_level_interface 
*inf,
   if (inf->vlantag.vid != 0)
 {
   grub_uint32_t vlantag;
-  vlantag = (VLANTAG_IDENTIFIER << 16) + (inf->vlantag.pcp << 12) +
-(inf->vlantag.dei << 11) + inf->vlantag.vid;
+  vlantag = (VLANTAG_IDENTIFIER << 16) | (inf->vlantag.pcp << 13) |
+(inf->vlantag.dei << 12) | inf->vlantag.vid;
 
   /* Move eth type to the right */
   grub_memcpy ((char *) nb->data + etherhdr_size - 2,


Virtual lan priority is an option in PowerPC SMS:

 PowerPC Firmware
 Version ZM770_024
 SMS 1.7 (c) Copyright IBM Corp. 2000,2008 All rights reserved.
---
 Advanced Setup: BOOTP
Interpartition Logical LAN: U9109.RMD.10F037P-V4-C3-T1

 1.   Bootp Retries5
 2.   Bootp Blocksize  512
 3.   TFTP  Retries5
 4.   VLAN  Priority   0
 5.   VLAN  ID 0 (default - not configured)


Maybe we can use the priority and DEI of incoming package as the values for the
following packages. What do you think?

> May be it should really start using proper options at this point
> keeping existing three argument form as legacy.
> 
> net_add_addr --if=... --addr=... --mask=... --vlan=... --hw=... card

I prefer the current format but we can switch to another if it's more suitable.

Andrey, ping me in IRC so we can talk about it.

> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

I ask this patch as a freeze exception. This feature will only add a option for
vlan tag and will not change the default grub workflow. Can I push the current
version in master so it can be included in 2.02? Anyone against?

Thanks!

--
Paulo Flabiano Smorigo
IBM Linux Technology Center


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Request a freeze exception for vlantag feature

2014-01-08 Thread Paulo Flabiano Smorigo
Thu, Dec 26, 2013 at 03:25:28PM -0200, pfsmor...@linux.vnet.ibm.com wrote:
> Mon, Dec 23, 2013 at 09:02:57PM +0400, Andrey Borzenkov wrote:
> > В Пн, 23/12/2013 в 11:34 -0500, Paulo Flabiano Smorigo/Brazil/IBM пишет:
> > > Hello everyone,
> > > 
> > > With the consent of Vladimir Serbinenko, I committed three patches in  
> > > the next branch. Those patches add support for virtual LAN (VLAN)  
> > > tagging. VLAN tagging allows multiple VLANs in a bridged network to  
> > > share the same physical network link but maintain isolation:
> > > 
> > > http://en.wikipedia.org/wiki/IEEE_802.1Q
> > > 
> > > http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=11454e94ea8e78317b9c9ab22855e26890880745
> > > http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=8ff3c31f6d59ca758b3bc0020e5140dcc937edd6
> > > http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=af768f8d4166aae41bbac8575fca7c65a319bfdb
> > > 
> > > 
> > 
> > VLAN tag is 12 bits, with 4 remaining bits being packet priority. You
> > need to mask them off before comparing. 
> > 
> 
> Tks for the feedback. I fixed it. Can you take a look?
> 
> http://git.io/ol5y-Q
> 
> > A couple of words in documentation would be nice (are those variables
> > for this platform documented at all?)
> 
> Ok, I'll will add a documentation.
> 
> 
> Btw, I need to add it to the commands. I'm not sure if I add a parameter
> to net_add_addr and net_bootp or create a new one to set it.
> 
> > 
> > > I come here to ask for an freeze exception so it can be also in master  
> > > and in 2.02 release.
> > >
> > > Thanks in advance,
> > > --
> > > Paulo Flabiano Smorigo
> > > Software Engineer
> > > Linux Technology Center - IBM Systems & Technology Group
> > > 
> > > 
> > > _______
> > > Grub-devel mailing list
> > > Grub-devel@gnu.org
> > > https://lists.gnu.org/mailman/listinfo/grub-devel
> > 
> > 
> > 
> > 
> > ___
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> 
> -- 
> --
> Paulo Flabiano Smorigo
> IBM Linux Technology Center
> 
> 
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

This is a reviewed version of the patch. I added vlantag option to the 
net_add_addr
and net_bootp commands.

---
 grub-core/net/arp.c|  8 +++---
 grub-core/net/bootp.c  | 24 ++---
 grub-core/net/drivers/ieee1275/ofnet.c |  6 -
 grub-core/net/ethernet.c   | 20 +++---
 grub-core/net/ip.c | 22 +++
 grub-core/net/net.c| 49 +++---
 include/grub/net.h | 11 +++-
 include/grub/net/arp.h |  2 +-
 include/grub/net/ip.h  |  2 +-
 9 files changed, 110 insertions(+), 34 deletions(-)

diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c
index 2e3cf44..8485ff2 100644
--- a/grub-core/net/arp.c
+++ b/grub-core/net/arp.c
@@ -122,7 +122,7 @@ grub_net_arp_send_request (struct 
grub_net_network_level_interface *inf,
 
 grub_err_t
 grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,
-  grub_uint16_t *vlantag)
+  grub_uint16_t vlantag_vid)
 {
   struct arphdr *arp_header = (struct arphdr *) nb->data;
   grub_uint8_t *sender_hardware_address;
@@ -158,11 +158,11 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct 
grub_net_card *card,
   FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
   {
 /* Verify vlantag id */
-if (inf->card == card && inf->vlantag != *vlantag)
+if (inf->card == card && inf->vlantag.vid != vlantag_vid)
   {
 grub_dprintf ("net", "invalid vlantag! %x != %x\n",
-  inf->vlantag, *vlantag);
-break;
+  inf->vlantag.vid, vlantag_vid);
+continue;
   }
 
 /* Am I the protocol address target? */
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index 6310ed4..4c4217a 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -425,10 +425,12 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ 
((unused)),
   unsigned j = 0;
   int interval;
   grub_err_t err;
+  grub_int8_t vlan_pos = -1;
 
   FOR_NET_CARDS (card)
   {
-if (argc > 0 && grub_strcmp (card->name, args[0]) != 0)
+if (argc 

Request a freeze exception for vlantag feature

2013-12-23 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hello everyone,

With the consent of Vladimir Serbinenko, I committed three patches in  
the next branch. Those patches add support for virtual LAN (VLAN)  
tagging. VLAN tagging allows multiple VLANs in a bridged network to  
share the same physical network link but maintain isolation:


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

http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=11454e94ea8e78317b9c9ab22855e26890880745
http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=8ff3c31f6d59ca758b3bc0020e5140dcc937edd6
http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=af768f8d4166aae41bbac8575fca7c65a319bfdb


I come here to ask for an freeze exception so it can be also in master  
and in 2.02 release.


Thanks in advance,
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: New module added: load progress

2013-10-22 Thread Paulo Flabiano Smorigo
The correct link is:
http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=84a0e9699f8d3cd2900892e8fafca42cde09dbfb

On Tue, Oct 22, 2013 at 9:11 PM, Paulo Flabiano Smorigo/Brazil/IBM
 wrote:
> Hi All,
>
> After a couple of weeks of development and with a great help from Vladimir
> Serbinenko I committed today [1] the load progress module. The idea is to
> display the current status of a loading file in grub. It works both for
> local and remote files (network).
>
> An example of the progress module in action:
> ---
> Loading Linux...
>  [ vmlinuz-3.6.10-4  16.47MiB  85%  4.49MiB/s ]
> ---
>
> Feel free to test and maybe send some feedbacks. icedphoenix will add the
> gfx support for the progress module soon.
>
> [1]
> http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=0d711431c713741a7e1d9c8c44a74d804855198e
>
> --
> Paulo Flabiano Smorigo
> Software Engineer
> Linux Technology Center - IBM Systems & Technology Group
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


New module added: load progress

2013-10-22 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi All,

After a couple of weeks of development and with a great help from  
Vladimir Serbinenko I committed today [1] the load progress module.  
The idea is to display the current status of a loading file in grub.  
It works both for local and remote files (network).


An example of the progress module in action:
---
Loading Linux...
 [ vmlinuz-3.6.10-4  16.47MiB  85%  4.49MiB/s ]
---

Feel free to test and maybe send some feedbacks. icedphoenix will add  
the gfx support for the progress module soon.


[1]  
http://git.savannah.gnu.org/gitweb/?p=grub.git;a=commit;h=0d711431c713741a7e1d9c8c44a74d804855198e


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Send tftp ack packet before closing the socket

2013-08-14 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This is another patch from Avik Sil. Bellow are the bug explanation:

I found another grub bug in tftp transfer. The issue comes for a  
subtle corner case.


While grub sends tftp acks, it maintains a 'count' variable that is  
incremented on each data packet received from tftp server. On every  
data packet received, if 'count' is less than 50, it
sends an ack, otherwise it wont. So for this '50'th packet the ack is  
sent by another function 'tftp_packets_pulled' that is called later  
from net read routine through a function pointer.


When the last block of a file is received as a data packet it is  
verified that it's the last block and the socket is closed.


Now there is a corner case. In case the last block happens to be that  
'50'th block the ack is not sent (as usual) and the socket is closed.  
Afterwards, when the net read routine calls 'tftp_packets_pulled' it
tries to send the ack using that closed socket, resulting in failure  
in sending the ack packet! This happened to be the case for the  
vmlinuz file I'm trying to load.


The attached patch fixes this issue by checking if the ack packet is  
already sent before closing the packet; if not sent call the ack  
routine.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-08-14 13:36:18 +
+++ ChangeLog	2013-08-14 13:38:05 +
@@ -1,5 +1,9 @@
 2013-08-14 Avik Sil 
 
+	* grub-core/net/tftp.c: Send tftp ack packet before closing the socket.
+
+2013-08-14 Avik Sil 
+
 	* grub-core/net/drivers/ieee1275/ofnet.c: Get proper mac address when
 	using qemu.
 

=== modified file 'grub-core/net/tftp.c'
--- grub-core/net/tftp.c	2012-07-02 09:22:50 +
+++ grub-core/net/tftp.c	2013-08-14 13:36:51 +
@@ -243,6 +243,8 @@
 	data->block++;
 	if (size < data->block_size)
 	  {
+		if (data->ack_sent < data->block)
+		  ack (data, data->block);
 		file->device->net->eof = 1;
 		file->device->net->stall = 1;
 		grub_net_udp_close (data->sock);

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Get proper mac address when using qemu

2013-08-14 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This patch fixes an issue when net booting GRUB with QEMU. It was made  
by Avik Sil, a colleague from IBM.


QEMU uses the local-mac-address property to store the mac address but  
it uses a 64bit property for it. This patch makes a proper treatment.


To illustrate, this is the property from our tests:

0 > dev /vdevice/l-lan@7102   ok
0 > .properties
...
local-mac-address5254  00123456
...

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-08-14 09:10:09 +
+++ ChangeLog	2013-08-14 13:35:34 +
@@ -1,3 +1,8 @@
+2013-08-14 Avik Sil 
+
+	* grub-core/net/drivers/ieee1275/ofnet.c: Get proper mac address when
+	using qemu.
+
 2013-08-14  Vladimir Serbinenko  
 
 	* include/grub/i386/pc/biosdisk.h (grub_biosdisk_drp): Fix device_path

=== modified file 'grub-core/net/drivers/ieee1275/ofnet.c'
--- grub-core/net/drivers/ieee1275/ofnet.c	2013-04-13 18:12:11 +
+++ grub-core/net/drivers/ieee1275/ofnet.c	2013-08-14 13:30:17 +
@@ -202,6 +202,8 @@
   struct grub_net_card *card;
   grub_ieee1275_phandle_t devhandle;
   grub_net_link_level_address_t lla;
+  grub_ssize_t prop_size;
+  grub_uint8_t prop_array[8], *pprop;
   char *shortname;
 
   if (grub_strcmp (alias->type, "network") != 0)
@@ -235,16 +237,20 @@
   card->mtu = t;
   }
 
+  pprop = &prop_array[0];
   if (grub_ieee1275_get_property (devhandle, "mac-address",
   &(lla.mac), 6, 0)
   && grub_ieee1275_get_property (devhandle, "local-mac-address",
- &(lla.mac), 6, 0))
+ pprop, 8, &prop_size))
 {
   grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
   grub_print_error ();
   return 0;
 }
 
+  if (prop_size == 8) {
+grub_memcpy(&lla.mac, &prop_array[2], 6);
+  }
   lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
   card->default_address = lla;
 

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


New files to .bzrignore

2013-08-02 Thread Paulo Flabiano Smorigo/Brazil/IBM
Add bootinfo.txt, grub.chrp, gnulib/float.h and, remove-potcdate.sed  
to the .bzrignore file.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file '.bzrignore'
--- .bzrignore	2013-07-25 16:01:48 +
+++ .bzrignore	2013-08-02 15:18:59 +
@@ -166,6 +166,7 @@
 **/.dirstamp
 Makefile.util.am
 contrib
+grub-core/bootinfo.txt
 grub-core/Makefile.core.am
 grub-core/Makefile.gcry.def
 grub-core/contrib
@@ -173,6 +174,7 @@
 grub-core/genmod.sh
 grub-core/gensyminfo.sh
 grub-core/gmodule.pl
+grub-core/grub.chrp
 grub-core/modinfo.sh
 grub-core/*.module
 grub-core/*.pp
@@ -182,6 +184,7 @@
 grub-core/gnulib/c++defs.h
 grub-core/gnulib/charset.alias
 grub-core/gnulib/configmake.h
+grub-core/gnulib/float.h
 grub-core/gnulib/getopt.h
 grub-core/gnulib/langinfo.h
 grub-core/gnulib/ref-add.sed
@@ -204,6 +207,7 @@
 po/*.po
 po/*.gmo
 po/LINGUAS
+po/remove-potcdate.sed
 include/grub/gcrypt/gcrypt.h
 include/grub/gcrypt/g10lib.h
 po/POTFILES.in

=== modified file 'ChangeLog'
--- ChangeLog	2013-07-25 16:01:48 +
+++ ChangeLog	2013-08-02 15:28:41 +
@@ -1,3 +1,8 @@
+2013-08-02  Paulo Flabiano Smorigo  
+
+	* .bzrignore: Add bootinfo.txt, grub.chrp, gnulib/float.h, and
+	remove-potcdate.sed.
+
 2013-07-25  Andrey Borzenkov 
 
 	* .bzrignore: Remove grub-core/lib/dtc-grub,

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] powerpc: fix startup bss cleaning

2013-07-15 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi,

The trunk version of GRUB is crashing on power machines. Openfirmware  
returns the following message:

Welcome to GRUB!

DEFAULT CATCH!, exception-handler=fff00700
at   %SRR0: 3940   %SRR1: 00083002
Open Firmware exception handler entered from non-OF code

Client's Fix Pt Regs:
 00 0020a074 01a3ff40  001e3de0
 04 001e3eb0 0004 001d1fd0 007c
 08 4000 3940 001d4810 01a3ff40
 0c 4084   
 10    
 14 00c0 0008  
 18    
 1c 00219620 001e3eb0 00219620 001e3de0
Special Regs:
%IV: 0700 %CR: 2084%XER:   %DSISR: 
  %SRR0: 3940   %SRR1: 00083002
%LR: 0020a0a4%CTR: 3940
   %DAR: 
Virtual PID = 0
 ok
0 >

After some investigation, my colleague Gustavo Duarte discover that  
the problem is caused by grub_file_filters_enabled. Its initial value  
isn't zero:

grub_file_filters_enabled[0]@0x219614 0x0
grub_file_filters_enabled[1]@0x219618 0x0
grub_file_filters_enabled[2]@0x21961c 0x0
grub_file_filters_enabled[3]@0x219620 0x3940


Using objdump I noticed that this variable is the last one from the  
bss section:

$objdump -t grub-core/kernel.exec | sort
...
00218d14 l O .bss   0004 count.2347
00218d18 l O .bss   0100 buf.1909
00218e18 l O .bss   0100 linebuf
00218f18 g O .bss   0100 grub_errmsg
00219018 g O .bss   0010 grub_file_filters_all
00219028 g O .bss   0010 grub_file_filters_enabled
00219038 g   .bss    _end

It seems that startup.S for powerpc skips the last bytes, so I made a  
patch to fix it. Tried again and the problem was gone:

grub_file_filters_enabled[0]@0x219614 0x0
grub_file_filters_enabled[1]@0x219618 0x0
grub_file_filters_enabled[2]@0x21961c 0x0
grub_file_filters_enabled[3]@0x219620 0x0



Best regards!
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-07-14 21:10:27 +
+++ ChangeLog	2013-07-15 19:04:03 +
@@ -1,3 +1,6 @@
+2013-07-15  Paulo Flabiano Smorigo  
+	* grub-core/kern/powerpc/ieee1275/startup.S: Fix bss clean up.
+
 2013-07-14  Vladimir Testov 
 
 	* grub-core/gfxmenu/gui_list.c: USe viewport when drawing strings.

=== modified file 'grub-core/kern/powerpc/ieee1275/startup.S'
--- grub-core/kern/powerpc/ieee1275/startup.S	2011-10-18 13:21:51 +
+++ grub-core/kern/powerpc/ieee1275/startup.S	2013-07-15 18:59:29 +
@@ -32,10 +32,10 @@
 	li  13, 0
 
 	/* Stage1 won't zero BSS for us. In other cases, why not do it again?  */
-	lis	6, (__bss_start - 4)@h
-	ori	6, 6, (__bss_start - 4)@l
-	lis	7, (_end - 4)@h
-	ori	7, 7, (_end - 4)@l
+	lis	6, __bss_start@h
+	ori	6, 6, __bss_start@l
+	lis	7, _end@h
+	ori	7, 7, _end@l
 	subf	7, 6, 7
 	srwi	7, 7, 2 /* We store 4 bytes at a time.  */
 	mtctr	7

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add a check for network cards in bootp command

2013-05-06 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This fix add a check for a network card before continue the bootp  
command execution.


Thanks,
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file 'ChangeLog'
--- ChangeLog	2013-05-05 16:16:48 +
+++ ChangeLog	2013-05-06 15:49:29 +
@@ -1,3 +1,9 @@
+2013-05-06 Paulo Flabiano Smorigo 
+
+	* grub-core/net/bootp.c (grub_cmd_bootp): Check if there is any card
+	present.
+	* include/grub/err.h (grub_err_t): New enum value GRUB_ERR_NET_NO_CARD.
+
 2013-05-05  Bean  
 
 	* grub-core/commands/testspeed.c: New command testspeed.

=== modified file 'grub-core/net/bootp.c'
--- grub-core/net/bootp.c	2013-01-20 13:24:47 +
+++ grub-core/net/bootp.c	2013-05-06 15:21:48 +
@@ -444,6 +444,12 @@
 ncards++;
   }
 
+  if (ncards == 0)
+{
+  err = grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found"));
+  return err;
+}
+
   ifaces = grub_zalloc (ncards * sizeof (ifaces[0]));
   if (!ifaces)
 return grub_errno;

=== modified file 'include/grub/err.h'
--- include/grub/err.h	2013-01-11 20:32:42 +
+++ include/grub/err.h	2013-05-06 15:21:48 +
@@ -62,6 +62,7 @@
 GRUB_ERR_NET_ROUTE_LOOP,
 GRUB_ERR_NET_NO_ROUTE,
 GRUB_ERR_NET_NO_ANSWER,
+GRUB_ERR_NET_NO_CARD,
 GRUB_ERR_WAIT,
 GRUB_ERR_BUG,
 GRUB_ERR_NET_PORT_CLOSED,

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] Fix ofpathname for sas disks

2013-04-19 Thread Paulo Flabiano Smorigo/Brazil/IBM


Quoting Paulo Flabiano Smorigo/Brazil/IBM :


Hello all,

I found wrong outputs for some sas devices then I made this patch in  
order to fix it. Bellow are the outputs using my patch:


grub-probe -t ieee1275_hints -d /dev/sda
ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/disk@200

grub-probe -t ieee1275_hints -d /dev/sdb
ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/disk@300

grub-probe -t ieee1275_hints -d /dev/sdf
ieee1275//pci@8002204/pci1000\,72@0/sas/disk@50080e5234006000\,1

grub-probe -t ieee1275_hints -d /dev/sdh
ieee1275//pci@8002204/pci1000\,72@0/sas/disk@50080e5234006000\,3


I checked it against openfirmware and all of them were right now.  
Please, let me know if you find a disk with a wrong ofw output.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


Hello again,

I forgot to add "sas" in the disk path. The first and second path from  
example should output:


ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/sas/disk@200
ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/sas/disk@300

Second version of patch fixed it.

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-04-17 17:08:31 +
+++ ChangeLog	2013-04-19 00:48:38 +
@@ -1,3 +1,9 @@
+2013-04-18  Paulo Flabiano Smorigo 
+
+	* util/ieee1275/ofpath.c (of_path_of_scsi): Fix path output for sas
+	disks.
+	* util/ieee1275/ofpath.c (check_sas): Get sas_adress info.
+
 2013-04-17  Vladimir Serbinenko  
 
 	* util/grub-mkrescue.in: Add GPT for EFI boot.

=== modified file 'util/ieee1275/ofpath.c'
--- util/ieee1275/ofpath.c	2013-01-13 21:45:16 +
+++ util/ieee1275/ofpath.c	2013-04-19 16:01:44 +
@@ -324,11 +324,11 @@
 }
 
 static void
-check_sas (char *sysfs_path, int *tgt)
+check_sas (char *sysfs_path, int *tgt, unsigned long int *sas_address)
 {
   char *ed = strstr (sysfs_path, "end_device");
   char *p, *q, *path;
-  char phy[16];
+  char phy[20];
   int fd;
   size_t path_size;
 
@@ -348,16 +348,25 @@
 	   + sizeof ("%s/sas_device/%s/phy_identifier"));
   path = xmalloc (path_size);
   snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed);
-
   fd = open (path, O_RDONLY);
   if (fd < 0)
 grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
 
   memset (phy, 0, sizeof (phy));
   read (fd, phy, sizeof (phy));
+  close (fd);
 
   sscanf (phy, "%d", tgt);
 
+  snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed);
+  fd = open (path, O_RDONLY);
+  if (fd < 0)
+  grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
+
+  memset (phy, 0, sizeof (phy));
+  read (fd, phy, sizeof (phy));
+  *sas_address = strtoul (phy, NULL, 16);
+
   free (path);
   free (p);
   close (fd);
@@ -370,13 +379,14 @@
 {
   const char *p, *digit_string, *disk_name;
   int host, bus, tgt, lun;
+  unsigned long int sas_address;
   char *sysfs_path, disk[MAX_DISK_CAT - sizeof ("/fp@0,0")];
   char *of_path;
 
   sysfs_path = block_device_get_sysfs_path_and_link(devicenode);
   p = get_basename (sysfs_path);
   sscanf(p, "%d:%d:%d:%d", &host, &bus, &tgt, &lun);
-  check_sas (sysfs_path, &tgt);
+  check_sas (sysfs_path, &tgt, &sas_address);
 
   if (vendor_is_ATA(sysfs_path))
 {
@@ -417,18 +427,52 @@
 }
   else
 {
-  if (*digit_string == '\0')
-	{
-	  snprintf(disk, sizeof (disk), "/%s@%x,%d", disk_name, tgt, lun);
-	}
+  if (lun == 0)
+{
+  int sas_id = 0;
+  sas_id = bus << 16 | tgt << 8 | lun;
+
+  if (*digit_string == '\0')
+{
+  snprintf(disk, sizeof (disk), "/sas/%s@%x", disk_name, sas_id);
+}
+  else
+{
+  int part;
+
+  sscanf(digit_string, "%d", &part);
+  snprintf(disk, sizeof (disk),
+   "/sas/%s@%x:%c", disk_name, sas_id, 'a' + (part - 1));
+}
+}
   else
-	{
-	  int part;
-
-	  sscanf(digit_string, "%d", &part);
-	  snprintf(disk, sizeof (disk),
-		   "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1));
-	}
+{
+  char *lunstr;
+  int lunpart[4];
+
+  lunstr = xmalloc (20);
+
+  lunpart[0] = (lun >> 8) & 0xff;
+  lunpart[1] = lun & 0xff;
+  lunpart[2] = (lun >> 24) & 0xff;
+  lunpart[3] = (lun >> 16) & 0xff;
+
+  sprintf(lunstr, "%02x%02x%02x%02x", lunpart[0], lunpart[1], lunpart[2], lunpart[3]);
+  long int longlun = atol(lunstr);
+
+  if (*digit_string == '

[PATCH] Fix ofpathname for sas disks

2013-04-18 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hello all,

I found wrong outputs for some sas devices then I made this patch in  
order to fix it. Bellow are the outputs using my patch:


grub-probe -t ieee1275_hints -d /dev/sda
ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/disk@200

grub-probe -t ieee1275_hints -d /dev/sdb
ieee1275//pci@8002200/pci@2/pci1014\,02BD@1/disk@300

grub-probe -t ieee1275_hints -d /dev/sdf
ieee1275//pci@8002204/pci1000\,72@0/sas/disk@50080e5234006000\,1

grub-probe -t ieee1275_hints -d /dev/sdh
ieee1275//pci@8002204/pci1000\,72@0/sas/disk@50080e5234006000\,3


I checked it against openfirmware and all of them were right now.  
Please, let me know if you find a disk with a wrong ofw output.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file 'ChangeLog'
--- ChangeLog	2013-04-17 17:08:31 +
+++ ChangeLog	2013-04-19 00:48:38 +
@@ -1,3 +1,9 @@
+2013-04-18  Paulo Flabiano Smorigo 
+
+	* util/ieee1275/ofpath.c (of_path_of_scsi): Fix path output for sas
+	disks.
+	* util/ieee1275/ofpath.c (check_sas): Get sas_adress info.
+
 2013-04-17  Vladimir Serbinenko  
 
 	* util/grub-mkrescue.in: Add GPT for EFI boot.

=== modified file 'util/ieee1275/ofpath.c'
--- util/ieee1275/ofpath.c	2013-01-13 21:45:16 +
+++ util/ieee1275/ofpath.c	2013-04-19 00:32:59 +
@@ -324,11 +324,11 @@
 }
 
 static void
-check_sas (char *sysfs_path, int *tgt)
+check_sas (char *sysfs_path, int *tgt, unsigned long int *sas_address)
 {
   char *ed = strstr (sysfs_path, "end_device");
   char *p, *q, *path;
-  char phy[16];
+  char phy[20];
   int fd;
   size_t path_size;
 
@@ -348,16 +348,25 @@
 	   + sizeof ("%s/sas_device/%s/phy_identifier"));
   path = xmalloc (path_size);
   snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed);
-
   fd = open (path, O_RDONLY);
   if (fd < 0)
 grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
 
   memset (phy, 0, sizeof (phy));
   read (fd, phy, sizeof (phy));
+  close (fd);
 
   sscanf (phy, "%d", tgt);
 
+  snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed);
+  fd = open (path, O_RDONLY);
+  if (fd < 0)
+  grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
+
+  memset (phy, 0, sizeof (phy));
+  read (fd, phy, sizeof (phy));
+  *sas_address = strtoul (phy, NULL, 16);
+
   free (path);
   free (p);
   close (fd);
@@ -370,13 +379,14 @@
 {
   const char *p, *digit_string, *disk_name;
   int host, bus, tgt, lun;
+  unsigned long int sas_address;
   char *sysfs_path, disk[MAX_DISK_CAT - sizeof ("/fp@0,0")];
   char *of_path;
 
   sysfs_path = block_device_get_sysfs_path_and_link(devicenode);
   p = get_basename (sysfs_path);
   sscanf(p, "%d:%d:%d:%d", &host, &bus, &tgt, &lun);
-  check_sas (sysfs_path, &tgt);
+  check_sas (sysfs_path, &tgt, &sas_address);
 
   if (vendor_is_ATA(sysfs_path))
 {
@@ -417,18 +427,52 @@
 }
   else
 {
-  if (*digit_string == '\0')
-	{
-	  snprintf(disk, sizeof (disk), "/%s@%x,%d", disk_name, tgt, lun);
-	}
+  if (lun == 0)
+{
+  int sas_id = 0;
+  sas_id = bus << 16 | tgt << 8 | lun;
+
+  if (*digit_string == '\0')
+{
+  snprintf(disk, sizeof (disk), "/%s@%x", disk_name, sas_id);
+}
+  else
+{
+  int part;
+
+  sscanf(digit_string, "%d", &part);
+  snprintf(disk, sizeof (disk),
+   "/sas/%s@%x:%c", disk_name, sas_id, 'a' + (part - 1));
+}
+}
   else
-	{
-	  int part;
-
-	  sscanf(digit_string, "%d", &part);
-	  snprintf(disk, sizeof (disk),
-		   "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1));
-	}
+{
+  char *lunstr;
+  int lunpart[4];
+
+  lunstr = xmalloc (20);
+
+  lunpart[0] = (lun >> 8) & 0xff;
+  lunpart[1] = lun & 0xff;
+  lunpart[2] = (lun >> 24) & 0xff;
+  lunpart[3] = (lun >> 16) & 0xff;
+
+  sprintf(lunstr, "%02x%02x%02x%02x", lunpart[0], lunpart[1], lunpart[2], lunpart[3]);
+  long int longlun = atol(lunstr);
+
+  if (*digit_string == '\0')
+{
+  snprintf(disk, sizeof (disk), "/sas/%s@%lx,%lu", disk_name, sas_address, longlun);
+}
+  else
+{
+  int part;
+
+  sscanf(digit_string, "%d", &part);
+  snprintf(disk, sizeof (disk),
+   "/sas/%s@%lx,%lu:%c", disk_name, sas_address, longlun, 'a' + (part - 1));
+}
+}
 }
   strcat(of_path, disk);
   return of_path;

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] fix build error caused by define

2013-04-18 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hello all,

This just fix the following build crash:

../util/grub-glue-efi.c: In function 'write_fat':
../util/grub-glue-efi.c:109:3: error: large integer implicitly  
truncated to unsigned type [-Werror=overflow]


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file 'ChangeLog'
--- ChangeLog	2013-04-17 17:08:31 +
+++ ChangeLog	2013-04-18 16:12:22 +
@@ -1,3 +1,7 @@
+2013-04-18  Paulo Flabiano Smorigo 
+
+	* include/grub/macho.h: Set GRUB_MACHO_FAT_EFI_MAGIC as unsigned.
+
 2013-04-17  Vladimir Serbinenko  
 
 	* util/grub-mkrescue.in: Add GPT for EFI boot.

=== modified file 'include/grub/macho.h'
--- include/grub/macho.h	2013-04-12 22:38:04 +
+++ include/grub/macho.h	2013-04-18 15:32:46 +
@@ -34,7 +34,7 @@
   };
 
 #define GRUB_MACHO_FAT_MAGIC 0xcafebabe
-#define GRUB_MACHO_FAT_EFI_MAGIC 0x0ef1fab9
+#define GRUB_MACHO_FAT_EFI_MAGIC 0x0ef1fab9U
 
 typedef grub_uint32_t grub_macho_cpu_type_t;
 typedef grub_uint32_t grub_macho_cpu_subtype_t;

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Add --memdisk parameter to grub-install

2013-02-06 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This patch adds an option to store all modules inside the core. This  
approach follows the suggestion from:

http://lists.gnu.org/archive/html/grub-devel/2012-10/msg00053.html

It works this way:

grub rescue> set
prefix=(mduuid/f897565f27383014091630e267aa4720)/grub
root=mduuid/f897565f27383014091630e267aa4720
grub rescue> set root=memdisk
grub rescue> set prefix=($root)/
grub rescue> ls /
powerpc-ieee1275/
grub rescue> insmod normal
grub rescue> normal

 GNU GRUB  version 2.00

   Minimal BASH-like line editing is supported. For the first word, TAB
   lists possible command completions. Anywhere else TAB lists possible
   device or file completions.


grub>


Tks!
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-02-06 16:37:29 +
+++ ChangeLog	2013-02-06 22:08:33 +
@@ -1,3 +1,7 @@
+2013-02-06  Paulo Flabiano Smorigo 
+
+	* util/grub-install.in: New option --memdisk.
+
 2013-02-06  Vladimir Serbinenko  
 
 	* grub-core/commands/lsacpi.c: Fix types on 64-bit platform.

=== modified file 'util/grub-install.in'
--- util/grub-install.in	2013-01-27 15:17:21 +
+++ util/grub-install.in	2013-02-06 22:08:48 +
@@ -50,6 +50,8 @@
 bootdir=
 grubdir="`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`"
 modules=
+memdisk=no
+memdisk_img=
 
 install_device=
 force_lba=
@@ -110,6 +112,7 @@
 print_option_help  "--removable" "$(gettext "the installation device is removable. This option is only available on EFI.")"
 print_option_help  "--bootloader-id=$(gettext "ID")" "$(gettext "the ID of bootloader. This option is only available on EFI.")"
 print_option_help "--efi-directory=$(gettext "DIR")" "$(gettext "use DIR as the EFI System Partition root.")"
+print_option_help "--memdisk" "$(gettext "include all modules in memdisk.")"
 echo
 gettext "INSTALL_DEVICE must be system device filename.";echo
 echo
@@ -240,6 +243,9 @@
 --no-nvram)
 	update_nvram=no ;;
 
+--memdisk)
+	memdisk=yes ;;
+
 # This is an undocumented feature...
 --debug)
 	debug=yes ;;
@@ -558,6 +564,22 @@
 exit 1
 fi
 
+if test $memdisk = yes; then
+  memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XX"`" || exit 1
+
+  mkdir -p "${memdisk_dir}"/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
+
+  for file in "${source_dir}"/*.mod "${source_dir}"/*.lst; do
+cp -f "$file" "${memdisk_dir}"/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" || exit 1
+  done
+
+  memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XX"` || exit 1
+  (cd "${memdisk_dir}"; tar -cf - *) > "${memdisk_img}"
+  rm -rf "${memdisk_dir}"
+
+  modules="$modules memdisk tar"
+fi
+
 # Write device to a variable so we don't have to traverse /dev every time.
 grub_device="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" || exit 1
 
@@ -710,11 +732,15 @@
 *) imgext=img ;;
 esac
 
-if [ x"$config_opt_file" = x ]; then
-"$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
-else
-"$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
-fi
+additional_options=
+if [ x"$config_opt_file" != x ]; then
+	additional_options="-c \"${config_opt_file}\""
+fi
+if [ x"$memdisk_img" != x ]; then
+	additional_options="${additional_options} -m ${memdisk_img}"
+fi
+
+"$grub_mkimage" ${additional_options} -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
 
 # Backward-compatibility kludges
 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mipsel-loongson" ]; then
@@ -723,13 +749,12 @@
 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${grubdir}/grub"
 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-efi" ] || [ "${grub_modinfo_target_cpu}-${grub_

Re: [PATCH] Support Openfirmware disks with non-512B sectors

2013-01-30 Thread Paulo Flabiano Smorigo/Brazil/IBM


Quoting Vladimir 'φ-coder/phcoder' Serbinenko :


On 28.01.2013 18:18, Paulo Flabiano Smorigo/Brazil/IBM wrote:



Quoting Vladimir 'φ-coder/phcoder' Serbinenko :


On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:


+  grub_ieee1275_open (device, &dev_ihandle);


Please don't open another handle. This can cause lockdown on some
platforms. Use the already available framework.

--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


Hi phcoder,

Here is a new version of my patch using last_ihandle. Is it ok now?


This patch lacks sanity checks. You need to check that sector size is
sane (never trust openfirmware or BIOS). Like this (taken from biosdisk.c):
  if (drp->bytes_per_sector
  && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1))
  && drp->bytes_per_sector >= 512
  && drp->bytes_per_sector <= 16384)



Thanks in advance


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel




--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


Hi,

Sanity check added.

Best regards,
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file 'ChangeLog'
--- ChangeLog	2013-01-27 15:17:21 +
+++ ChangeLog	2013-01-28 16:39:41 +
@@ -1,3 +1,15 @@
+2013-01-28  Paulo Flabiano Smorigo 
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-27  Andrey Borzenkov 
 
 	* util/grub-install.in: change misleading comment about

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-30 19:05:49 +
@@ -349,6 +349,14 @@
   return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
 }
 
+  grub_uint32_t block_size = 0;
+  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
+{
+  for (disk->log_sector_size = 0;
+   (1U << disk->log_sector_size) < block_size;
+   disk->log_sector_size++);
+}
+
   /* XXX: There is no property to read the number of blocks.  There
  should be a property `#blocks', but it is not there.  Perhaps it
  is possible to use seek for this.  */
@@ -415,7 +423,7 @@
   last_devpath = disk->data;  
 }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +442,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		  &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
 return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 	   "from `%s'"),
 		   (unsigned long long) sector,
@@ -454,9 +462,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		   &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
 return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 		"to `%s'"),
 		   (unsigned long long) sector,
@@ -493,3 +501,44 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+grub_err_t
+grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
+{
+  struct size_args_ieee1275
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t result;
+  grub_ieee1275_cell_t size1;
+  grub_ieee1275_cell_t size2;
+} args_ieee1275;
+
+  if (last_ihandle)
+grub_ieee1275_close (last_ihandle);
+
+  last_ihandle = 0;
+  last_devpath = NULL;
+
+  grub_ieee1275_open (device, &last_ihandle);
+  if (! last_ihandle)
+return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.com

Re: [PATCH] Support Openfirmware disks with non-512B sectors

2013-01-28 Thread Paulo Flabiano Smorigo/Brazil/IBM


Quoting Vladimir 'φ-coder/phcoder' Serbinenko :


On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:


+  grub_ieee1275_open (device, &dev_ihandle);


Please don't open another handle. This can cause lockdown on some
platforms. Use the already available framework.

--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


Hi phcoder,

Here is a new version of my patch using last_ihandle. Is it ok now?

Thanks in advance
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
Phone: +55 (19) 2132-1647 T/L: 839-1647
Mobile: +55 (12) 9122-2734
freenode/bluenet: pfsmorigo or smow

=== modified file 'ChangeLog'
--- ChangeLog	2013-01-27 15:17:21 +
+++ ChangeLog	2013-01-28 16:39:41 +
@@ -1,3 +1,15 @@
+2013-01-28  Paulo Flabiano Smorigo 
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-27  Andrey Borzenkov 
 
 	* util/grub-install.in: change misleading comment about

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-28 16:39:24 +
@@ -349,6 +349,14 @@
   return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
 }
 
+  grub_uint32_t block_size = 0;
+  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
+{
+  for (disk->log_sector_size = 0;
+   (1U << disk->log_sector_size) < block_size;
+   disk->log_sector_size++);
+}
+
   /* XXX: There is no property to read the number of blocks.  There
  should be a property `#blocks', but it is not there.  Perhaps it
  is possible to use seek for this.  */
@@ -415,7 +423,7 @@
   last_devpath = disk->data;  
 }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +442,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		  &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
 return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 	   "from `%s'"),
 		   (unsigned long long) sector,
@@ -454,9 +462,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		   &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
 return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 		"to `%s'"),
 		   (unsigned long long) sector,
@@ -493,3 +501,43 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+grub_err_t
+grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
+{
+  struct size_args_ieee1275
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t result;
+  grub_ieee1275_cell_t size1;
+  grub_ieee1275_cell_t size2;
+} args_ieee1275;
+
+  if (last_ihandle)
+grub_ieee1275_close (last_ihandle);
+
+  last_ihandle = 0;
+  last_devpath = NULL;
+
+  grub_ieee1275_open (device, &last_ihandle);
+  if (! last_ihandle)
+return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.ihandle = last_ihandle;
+  args_ieee1275.result = 1;
+
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+{
+  /* If the method isn't available use the common size */
+  grub_dprintf ("disk", "can't get block size\n");
+  *block_size = GRUB_DISK_SECTOR_SIZE;
+}
+  else
+*block_size = args_ieee1275.size1;
+
+  return 0;
+}

=== modified file 'include/grub/ieee1275/ofdisk.h'
--- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +
+++ in

Re: [PATCH] Support Openfirmware disks with non-512B sectors

2013-01-22 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi,

You need a different approach for each platform. Afaik, grub already  
have support

for some platforms:

http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3325?start_revid=4682

Regards,

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group



Quoting Seth Goldberg :


Hi,

  Why is this limited to OpenFirmware only?  Can you generate a  
patch that supports 4KN disks on ALL platforms?


 Thanks,
 --S

Quoting Paulo Flabiano Smorigo/Brazil/IBM, who wrote the following  
on Tue,...:



Hi all,

This patch adds non-512B sectors disks support for Openfirmware (ieee1275).

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel



___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Display the sector size

2013-01-22 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

What about show the disk sector size with the disk info?

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-01-22 17:54:34 +
+++ ChangeLog	2013-01-22 17:59:00 +
@@ -1,5 +1,10 @@
 2013-01-22  Paulo Flabiano Smorigo 
 
+	* grub-core/normal/misc.c (grub_normal_print_device_info): Display
+	the sector size.
+
+2013-01-22  Paulo Flabiano Smorigo 
+
 	Support Openfirmware disks with non-512B sectors.
 
 	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block

=== modified file 'grub-core/normal/misc.c'
--- grub-core/normal/misc.c	2012-05-23 07:10:56 +
+++ grub-core/normal/misc.c	2013-01-22 17:55:49 +
@@ -119,6 +119,10 @@
   if (dev->disk->partition)
 	grub_printf (_(" - Partition start at %llu"),
 		 (unsigned long long) grub_partition_get_start (dev->disk->partition));
+  
+  if (dev->disk->log_sector_size != 0)
+grub_printf (_(" - Sector size %u"), 1 << dev->disk->log_sector_size);
+
   if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN)
 	grub_puts_ (N_(" - Total size unknown"));
   else

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Support Openfirmware disks with non-512B sectors

2013-01-22 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This patch adds non-512B sectors disks support for Openfirmware (ieee1275).

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2013-01-22 14:28:32 +
+++ ChangeLog	2013-01-22 17:35:51 +
@@ -1,3 +1,15 @@
+2013-01-22  Paulo Flabiano Smorigo 
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-22  Colin Watson  
 
 	* util/grub-reboot.in (usage): Document the need for

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-22 16:45:28 +
@@ -354,6 +354,13 @@
  is possible to use seek for this.  */
   disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
 
+  grub_uint32_t block_size = 0;
+  block_size = grub_ofdisk_get_block_size (devpath);
+
+  for (disk->log_sector_size = 0;
+   (1U << disk->log_sector_size) < block_size;
+   disk->log_sector_size++);
+
   {
 struct ofdisk_hash_ent *op;
 op = ofdisk_hash_find (devpath);
@@ -415,7 +422,7 @@
   last_devpath = disk->data;  
 }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +441,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		  &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
 return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 	   "from `%s'"),
 		   (unsigned long long) sector,
@@ -454,9 +461,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
 return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		   &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
 return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 		"to `%s'"),
 		   (unsigned long long) sector,
@@ -493,3 +500,46 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+
+grub_uint32_t grub_ofdisk_get_block_size (const char *device)
+{
+  grub_uint32_t block_size = 0;
+  grub_ieee1275_ihandle_t dev_ihandle = 0;
+
+  struct size_args_ieee1275
+{
+  struct grub_ieee1275_common_hdr common;
+  grub_ieee1275_cell_t method;
+  grub_ieee1275_cell_t ihandle;
+  grub_ieee1275_cell_t result;
+  grub_ieee1275_cell_t size1;
+  grub_ieee1275_cell_t size2;
+} args_ieee1275;
+
+  grub_ieee1275_open (device, &dev_ihandle);
+  if (! dev_ihandle)
+{
+  grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+  return 0;
+}
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.ihandle = dev_ihandle;
+  args_ieee1275.result = 1;
+
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+{
+  /* If the method isn't available use the common size */
+  grub_dprintf ("disk", "can't get block size\n");
+  grub_ieee1275_close (dev_ihandle);
+  return GRUB_DISK_SECTOR_SIZE;
+}
+
+  grub_ieee1275_close (dev_ihandle);
+  block_size = args_ieee1275.size1;
+
+  return block_size;
+}
+

=== modified file 'include/grub/ieee1275/ofdisk.h'
--- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +
+++ include/grub/ieee1275/ofdisk.h	2013-01-22 16:45:28 +
@@ -21,5 +21,6 @@
 
 extern void grub_ofdisk_init (void);
 extern void grub_ofdisk_fini (void);
+extern grub_uint32_t grub_ofdisk_get_block_size (const char *device);
 
 #endif /* ! GRUB_INIT_HEADER */

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Fix dhcp parse

2012-11-26 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

A small fix in the parse_dhcp_vendor function. The pointer was already  
incremented inside the case. Use a continue to skip the additional one.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2012-10-28 10:55:22 +
+++ ChangeLog	2012-11-26 16:24:42 +
@@ -1,3 +1,7 @@
+2012-11-26  Paulo Flabiano 
+
+	* grub-core/net/bootp.c (parse_dhcp_vendor): Fix dhcp parse.
+
 2012-10-28  Grégoire Sutre  

 	* util/grub.d/10_netbsd.in: Fix tab indentation and make sure

=== modified file 'grub-core/net/bootp.c'
--- grub-core/net/bootp.c	2012-06-21 20:20:57 +
+++ grub-core/net/bootp.c	2012-11-26 16:20:59 +
@@ -121,6 +121,8 @@
 		grub_net_add_dns_server (&s);
 		ptr += 4;
 	  }
+/*  Skip additional increment */
+continue;
 	  }
 	  break;
 	case GRUB_NET_BOOTP_HOSTNAME:

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add Virtual LAN (VLAN) support

2012-10-30 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging  
allows multiple VLANs in a bridged network to share the same physical  
network link but maintain isolation:


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

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2012-10-28 10:55:22 +
+++ ChangeLog	2012-10-30 15:10:13 +
@@ -1,3 +1,17 @@
+2012-10-30  Paulo Flabiano Smorigo 
+
+	Virtual LAN (VLAN) support added.
+
+	* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_parse_net_options):
+	New function.
+	* grub-core/kern/ieee1275/init.c (grub_machine_get_bootlocation):
+	Increase buffer.  Add function.
+	* grub-core/net/ethernet.c (send_ethernet_packet): Add vlan-tag
+	validation.
+	(grub_net_recv_ethernet_packet): Likewise.
+	* include/grub/ieee1275/ieee1275.h: New proto.
+	* include/grub/net.h: New define.
+
 2012-10-28  Grégoire Sutre  

 	* util/grub.d/10_netbsd.in: Fix tab indentation and make sure

=== modified file 'grub-core/kern/ieee1275/init.c'
--- grub-core/kern/ieee1275/init.c	2012-06-11 18:44:38 +
+++ grub-core/kern/ieee1275/init.c	2012-10-29 19:08:55 +
@@ -82,7 +82,7 @@
 void
 grub_machine_get_bootlocation (char **device, char **path)
 {
-  char bootpath[64]; /* XXX check length */
+  char bootpath[256]; /* XXX check length */
   char *filename;
   char *type;

@@ -102,6 +102,7 @@
   char *dev, *canon;
   char *ptr;
   dev = grub_ieee1275_get_aliasdevname (bootpath);
+  grub_ieee1275_parse_net_options (bootpath);
   canon = grub_ieee1275_canonicalise_devname (dev);
   ptr = canon + grub_strlen (canon) - 1;
   while (ptr > canon && (*ptr == ',' || *ptr == ':'))

=== modified file 'grub-core/kern/ieee1275/openfw.c'
--- grub-core/kern/ieee1275/openfw.c	2012-06-20 21:31:59 +
+++ grub-core/kern/ieee1275/openfw.c	2012-10-29 17:26:41 +
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 

 enum grub_ieee1275_parse_type
 {
@@ -413,6 +414,35 @@
   return ret;
 }

+int
+grub_ieee1275_parse_net_options (const char *path)
+{
+  char *comma;
+  char *args;
+  char *option = 0;
+
+  args = grub_ieee1275_get_devargs (path);
+  if (!args)
+/* There is no option.  */
+return -1;
+
+  do
+{
+  comma = grub_strchr (args, ',');
+  if (! comma)
+option = grub_strdup (args);
+  else
+option = grub_strndup (args, (grub_size_t)(comma - args));
+  args = comma + 1;
+
+  if (! grub_strncmp(option, "vtag", 4))
+  grub_env_set ("vlan-tag", option + grub_strlen("vtag="));
+
+} while (comma);
+
+  return 0;
+}
+
 char *
 grub_ieee1275_get_device_type (const char *path)
 {

=== modified file 'grub-core/net/ethernet.c'
--- grub-core/net/ethernet.c	2011-10-13 18:53:22 +
+++ grub-core/net/ethernet.c	2012-10-30 13:15:08 +
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -56,10 +57,19 @@
 {
   struct etherhdr *eth;
   grub_err_t err;
-
-  COMPILE_TIME_ASSERT (sizeof (*eth) < GRUB_NET_MAX_LINK_HEADER_SIZE);
-
-  err = grub_netbuff_push (nb, sizeof (*eth));
+  grub_uint32_t vlantag = 0;
+  grub_uint8_t etherhdr_size;
+
+  etherhdr_size = sizeof (*eth);
+  COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
+
+  const char *vlantag_text = grub_env_get ("vlan-tag");
+  if (vlantag_text != 0) {
+  etherhdr_size += 4;
+  vlantag = grub_strtoul (vlantag_text, 0, 16);
+  }
+
+  err = grub_netbuff_push (nb, etherhdr_size);
   if (err)
 return err;
   eth = (struct etherhdr *) nb->data;
@@ -76,6 +86,19 @@
 	return err;
   inf->card->opened = 1;
 }
+
+  /* Check if a vlan-tag is needed. */
+  if (vlantag != 0)
+{
+  /* Move eth type to the right */
+  grub_memcpy((char *) nb->data + etherhdr_size - 2,
+  (char *) nb->data + etherhdr_size - 6, 2);
+
+  /* Add the tag in the middle */
+  grub_memcpy((char *) nb->data + etherhdr_size - 6,
+  &vlantag, 4);
+}
+
   return inf->card->driver->send (inf->card, nb);
 }

@@ -90,10 +113,23 @@
   grub_net_link_level_address_t hwaddress;
   grub_net_link_level_address_t src_hwaddress;
   grub_err_t err;
+  grub_uint8_t etherhdr_size = sizeof (*eth);
+
+  grub_uint16_t vlantag_identifier = 0;
+  grub_memcpy (&vlantag_identifier, nb->data + etherhdr_size - 2, 2);
+
+  /* Check if a vlan-tag is present. */
+  if (vlantag_identifier == VLANTAG_IDENTIFIER)
+{
+  etherhdr_size += 4;
+  /* Move eth type to the original position */
+  grub_memcpy((char *) nb->data + etherhdr_size - 6,
+  (char *) nb->data + etherhdr_size - 2, 2);
+}

   eth = (struct etherhdr *) nb->data;
   type = grub_be_to_cpu16 (eth->type);
-  err = gru

Re: for ppc, include all modules in the core image

2012-10-22 Thread Paulo Flabiano Smorigo/Brazil/IBM


Quoting Vladimir 'φ-coder/phcoder' Serbinenko :


On 16.10.2012 12:28, Paulo Flabiano Smorigo/Brazil/IBM wrote:


Hi all!

This patch implements the solution suggested by Gustavo Luiz Duarte
:

Adding more modules to be built-in to the grub core ELF is easy. It is a
parameter passed by grub2-install to grub2-mkimage. However, there is a
downside
on adding many modules to the core ELF: they are fully initialized in
the grub's
first stage. It means you could hit a bug on a module you don't need and
end up
with a non-bootable system.

Another downside is that you wouldn't get updates for these built-in
modules, as
updating the grub2 package only updates the modules residing in /boot
and not
the grub core ELF in the PReP partition.

A proper solution would be to add to grub the ability of having built-in
*inactive* modules which would be loaded and initialized only on demand
(i.e.
explicitly calling the insmod command).



This is what memdisk does (i.a.). Why do you need anything else?




___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel




--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


Hi phcoder,

Thanks for the reply. I studied memdisk and tried to use grub-mkstandalone
but the idea used in this patch is different. It's like a plan B just in
case /boot isn't found. It gives the "grub rescue" a new level of recovery,
increasing the chances to fix the system. This extra modules is stored in a
different area and will *only* be used in this case.

Otherwise, the normal modules, inside /boot, will be used normally and If
there is an update or if grub.cfg changes, the new files will be used.

Best regards,
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


for ppc, include all modules in the core image

2012-10-16 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all!

This patch implements the solution suggested by Gustavo Luiz Duarte
:

Adding more modules to be built-in to the grub core ELF is easy. It is a
parameter passed by grub2-install to grub2-mkimage. However, there is  
a downside
on adding many modules to the core ELF: they are fully initialized in  
the grub's
first stage. It means you could hit a bug on a module you don't need  
and end up

with a non-bootable system.

Another downside is that you wouldn't get updates for these built-in  
modules, as

updating the grub2 package only updates the modules residing in /boot and not
the grub core ELF in the PReP partition.

A proper solution would be to add to grub the ability of having built-in
*inactive* modules which would be loaded and initialized only on demand (i.e.
explicitly calling the insmod command).

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2012-10-12 14:37:49 +
+++ ChangeLog	2012-10-16 00:22:26 +
@@ -1,3 +1,24 @@
+2012-10-15  Paulo Flabiano Smorigo  
+
+	For ppc, include all modules inside core.elf just in case of grub
+	rescue. The additional modules aren't loaded automatically, only
+	when the insmod command is called.
+
+	* grub-core/kern/dl.c (grub_dl_load_core_by_name): New function that
+	search for modules inside the core by its name.
+	(grub_dl_load): If the file is not found try using the new funtion.
+	* include/grub/dl.h (grub_dl_load_core_by_name): New proto.
+	* grub-core/kern/corecmd.c (grub_core_cmd_insmod): Add a call to the
+	new funtion.
+	* include/grub/kernel.h (OBJ_TYPE_ELF_STALE): New enum value.
+	* util/resolve.c (grub_util_create_complementary_module_list): New
+	function.
+	* include/grub/util/resolve.h
+	(grub_util_create_complementary_module_list): New proto.
+	* util/grub-mkimage.c (generate_image): Include additional modules
+	using the new function.
+	Based on suggestions from Gustavo Luiz Duarte.
+
 2012-10-12  Christoph Junghans  
 
 	* grub-core/Makefile.am (moddep.lst): Use $(AWK) rather than awk.

=== modified file 'grub-core/kern/corecmd.c'
--- grub-core/kern/corecmd.c	2012-02-24 10:18:06 +
+++ grub-core/kern/corecmd.c	2012-10-15 23:33:08 +
@@ -89,6 +89,9 @@
   else
 mod = grub_dl_load (argv[0]);
 
+  if (!mod)
+grub_dl_load_core_by_name (argv[0]);
+
   if (mod)
 grub_dl_ref (mod);
 

=== modified file 'grub-core/kern/dl.c'
--- grub-core/kern/dl.c	2012-03-19 10:10:11 +
+++ grub-core/kern/dl.c	2012-10-15 23:33:08 +
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Platforms where modules are in a readonly area of memory.  */
 #if defined(GRUB_MACHINE_QEMU)
@@ -47,6 +48,7 @@
 #pragma GCC diagnostic ignored "-Wcast-align"
 
 grub_dl_t grub_dl_head = 0;
+char grub_use_stale_modules = 0;
 
 grub_err_t
 grub_dl_add (grub_dl_t mod);
@@ -659,6 +661,57 @@
   return mod;
 }
 
+/* Load a module from core using a symbolic name.  */
+grub_dl_t
+grub_dl_load_core_by_name (const char *name)
+{
+  struct grub_module_header *header;
+  grub_dl_t mod;
+  char *module_addr;
+
+  mod = (grub_dl_t) grub_zalloc (sizeof (*mod));
+  if (! mod)
+return 0;
+
+  grub_use_stale_modules = 1;
+
+  FOR_MODULES (header)
+{
+  /* Not an ELF module, skip.  */
+  if ((header->type != OBJ_TYPE_ELF) &&
+  (header->type != OBJ_TYPE_ELF_STALE))
+continue;
+
+  module_addr = (char *) header + sizeof (struct grub_module_header);
+  grub_dl_resolve_name (mod, (Elf_Ehdr *) module_addr);
+
+  if (grub_strcmp(name, mod->name) == 0)
+{
+  grub_printf ("WARNING: You are using the built-in '%s' module!\n", name);
+
+  mod = grub_dl_load_core ((char *) header + sizeof (struct grub_module_header),
+   (header->size - sizeof (struct grub_module_header)));
+
+  break;
+}
+  else
+mod = 0;
+}
+
+  if (! mod)
+return 0;
+  else
+{
+  if (grub_errno == GRUB_ERR_IO)
+grub_errno = GRUB_ERR_NONE;
+}
+
+  if (grub_strcmp (mod->name, name) != 0)
+grub_error (GRUB_ERR_BAD_MODULE, "mismatched names");
+
+  return mod;
+}
+
 /* Load a module from the file FILENAME.  */
 grub_dl_t
 grub_dl_load_file (const char *filename)
@@ -718,13 +771,19 @@
 return 0;
   }
 
+  /* First, try to load module from the grub directory */
   filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM "/%s.mod",
 			 grub_dl_dir, name);
-  if (! filename)
-return 0;
+  if (filename)
+{
+  mod = grub_dl_load_file (filename);
+  grub_free (filename);
+}
 
-  mod = grub_dl_load_file (filename);
-  grub_free (filename);
+  /* If the module isn't loaded, check if there is a stale module available and
+   * use it*/
+  if (! mod && gr

[PATCH] grub-install: Follow the symbolic link parameter added to the file command (powerpc-ieee1275)

2012-10-02 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

For powerpc-ieee1275, if the given install device is a symlink, file  
cmd will follow the link to know the device type.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
=== modified file 'ChangeLog'
--- ChangeLog	2012-09-26 12:51:13 +
+++ ChangeLog	2012-10-02 14:36:55 +
@@ -1,3 +1,8 @@
+2012-10-02  Paulo Flabiano Smorigo 
+
+	* util/grub-install.in: Follow the symbolic link parameter added
+	to the file command.
+
 2012-09-26  Colin Watson  
 
 	* Makefile.util.def (grub-mknetdir): Move to $prefix/bin.

=== modified file 'util/grub-install.in'
--- util/grub-install.in	2012-09-24 17:50:35 +
+++ util/grub-install.in	2012-10-02 14:33:18 +
@@ -750,7 +750,7 @@
 	   exit 1
 fi
 
-if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
+if [ "$(file -s -b -L "${install_device}" | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
 	dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
 	gettext "Failed to copy Grub to the PReP partition." 1>&2
 	echo 1>&2

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Use dynamic allocation for the bootpath buffer

2012-09-14 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

There are some cases when the device path is bigger then 64 chars.  
Using a dynamic allocation will avoid problems with the size.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


bootpath_size.path
Description: Binary data
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] IBM client architecture (CAS) reboot

2012-09-10 Thread Paulo Flabiano Smorigo/Brazil/IBM


Hi all,

This is an implementation of IBM client architecture (CAS) reboot for GRUB.

There are cases where the POWER firmware must reboot in order to  
support specific features requested by a kernel. The kernel calls  
ibm,client-architecture-support and it may either return or reboot  
with the new feature set. eg:


Calling ibm,client-architecture-support.../
Elapsed time since release of system processors: 70959 mins 50 secs
Welcome to GRUB!

Instead of return to the GRUB menu, it will check if the flag for CAS  
reboot is set. If so, grub will automatically boot the last booted  
kernel using the same parameters


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

=== modified file 'ChangeLog'
--- ChangeLog	2012-09-10 07:34:29 +
+++ ChangeLog	2012-09-10 20:35:05 +
@@ -1,3 +1,17 @@
+2012-09-10  Paulo Flabiano Smorigo 
+
+	IBM client architecture (CAS) reboot support added.
+
+	* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_cas_reboot): New
+	function.
+	(grub_ieee1275_set_boot_last_label): Likewise.
+	* include/grub/ieee1275/ieee1275.h (grub_ieee1275_cas_reboot): New
+	proto.
+	(grub_ieee1275_set_boot_last_label): Likewise.
+	* grub-core/normal/main.c (grub_normal_execute): CAS reboot check added.
+	* grub-core/script/execute.c (grub_script_execute_sourcecode): Store
+	the meny entry for CAS reboot.
+
 2012-09-10  Benoit Gschwind 
 
 	* grub-core/loader/efi/appleloader.c (devpath_8): New var.

=== modified file 'grub-core/kern/ieee1275/openfw.c'
--- grub-core/kern/ieee1275/openfw.c	2012-06-20 21:31:59 +
+++ grub-core/kern/ieee1275/openfw.c	2012-09-05 21:17:35 +
@@ -523,3 +523,66 @@
   return NULL;
 }
 
+/* Check if it's a CAS reboot. If so, set the script to be executed.  */
+int
+grub_ieee1275_cas_reboot (char *script)
+{
+  grub_uint32_t ibm_ca_support_reboot;
+  grub_uint32_t ibm_fw_nbr_reboots;
+  char property_value[10];
+  grub_ssize_t actual;
+  grub_ieee1275_ihandle_t options;
+
+  if (grub_ieee1275_finddevice ("/options", &options) < 0)
+return -1;
+
+  /* Check two properties, one is enough to get cas reboot value */
+  ibm_ca_support_reboot = 0;
+  if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen,
+  "ibm,client-architecture-support-reboot",
+  &ibm_ca_support_reboot,
+  sizeof (ibm_ca_support_reboot),
+  &actual) >= 0)
+grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n",
+ ibm_ca_support_reboot);
+
+  ibm_fw_nbr_reboots = 0;
+  if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots",
+  property_value, sizeof (property_value),
+  &actual) >= 0)
+{
+  property_value[sizeof (property_value) - 1] = 0;
+  ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10);
+  grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots);
+}
+
+  if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
+{
+  if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual))
+{
+  if (actual > 1024)
+script = grub_realloc (script, actual + 1);
+  grub_ieee1275_get_property (options, "boot-last-label", script, actual,
+  &actual);
+  return 0;
+}
+}
+
+  grub_ieee1275_set_boot_last_label ("");
+
+  return -1;
+}
+
+int grub_ieee1275_set_boot_last_label (const char *text)
+{
+  grub_ieee1275_ihandle_t options;
+  grub_ssize_t actual;
+
+  grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text));
+  if (! grub_ieee1275_finddevice ("/options", &options) &&
+  options != (grub_ieee1275_ihandle_t) -1)
+grub_ieee1275_set_property (options, "boot-last-label", text,
+grub_strlen (text), &actual);
+  return 0;
+}
+

=== modified file 'grub-core/normal/main.c'
--- grub-core/normal/main.c	2012-06-28 00:06:36 +
+++ grub-core/normal/main.c	2012-09-05 21:17:41 +
@@ -32,6 +32,9 @@
 #include 
 #include 
 #include 
+#ifdef GRUB_MACHINE_IEEE1275
+#include 
+#endif
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -296,6 +299,22 @@
 {
   menu = read_config_file (config);
 
+#ifdef GRUB_MACHINE_IEEE1275
+  int boot;
+  boot = 0;
+  char *script;
+  script = grub_malloc (1024);
+  if (! grub_ieee1275_cas_reboot (script))
+{
+  char *dummy[1] = { NULL };
+  if (! grub_script_execute_sourcecode (script, 0, dummy))
+boot = 1;
+}
+  grub_free (script);
+  if 

[PATCH 2/2] Search for specific config file when it boots from tftp

2012-08-14 Thread Paulo Flabiano Smorigo/Brazil/IBM


Hi all,

This patch implements a search for a specific configuration (based on  
MAC or IP) when the config file is on the tftp server. He uses the  
following order:


   1) By MAC address (in lower case hexadecimal with dash separators);
   2) By IP (in upper case hexadecimal). It removes one hex digit  
from the end and try again;

   3) The original grub.cfg file.

For example, MAC address e4:1f:13:f4:ad:c2 and IP 192.168.1.100 (C0A80164):

(tftp,192.168.1.1)//boot/grub/grub.cfg-01-e4-1f-13-f4-ad-c2
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A80164
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A8016
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A801
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A80
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A8
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0A
(tftp,192.168.1.1)//boot/grub/grub.cfg-C0
(tftp,192.168.1.1)//boot/grub/grub.cfg-C
(tftp,192.168.1.1)//boot/grub/grub.cfg

This procedure is similar to what is used by pxelinux and yaboot:

http://www.syslinux.org/wiki/index.php/PXELINUX#config

--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
freenode/bluenet: pfsmorigo or smow

=== modified file 'ChangeLog'
--- ChangeLog	2012-08-14 08:56:19 +
+++ ChangeLog	2012-08-14 09:10:27 +
@@ -1,5 +1,14 @@
 2012-08-13 Paulo Flabiano Smorigo 

+	Search for specific config file when it boots from tftp.
+
+	* grub-core/normal/main.c: Call search function.
+	* grub-core/net/net.c: New function.
+	* include/grub/net.h: New function.
+
+
+2012-08-13 Paulo Flabiano Smorigo 
+
 	* grub-core/kern/misc.c: Add %X option to printf functions.

 2012-08-05  Grégoire Sutre  

=== modified file 'grub-core/net/net.c'
--- grub-core/net/net.c	2012-06-22 20:02:47 +
+++ grub-core/net/net.c	2012-08-14 08:59:46 +
@@ -1548,6 +1548,96 @@
   return GRUB_ERR_NONE;
 }

+grub_err_t
+grub_net_search_configfile (char *config)
+{
+  grub_size_t config_len;
+  char *suffix;
+
+  auto int search_through (grub_size_t num_tries, grub_size_t slice_size);
+  int search_through (grub_size_t num_tries, grub_size_t slice_size)
+{
+  while (num_tries-- > 0)
+{
+	  grub_dprintf ("net", "probe %s\n", config);
+
+  grub_file_t file;
+  file = grub_file_open (config);
+
+  if (file)
+{
+  grub_file_close (file);
+  grub_dprintf ("net", "found!\n");
+  return 0;
+}
+  else
+{
+  if (grub_errno == GRUB_ERR_IO)
+grub_errno = GRUB_ERR_NONE;
+}
+
+  if (grub_strlen (suffix) < slice_size)
+break;
+
+  config[grub_strlen (config) - slice_size] = '\0';
+}
+
+  return 1;
+}
+
+  config_len = grub_strlen (config);
+  config[config_len] = '-';
+  suffix = config + config_len + 1;
+
+  struct grub_net_network_level_interface *inf;
+  FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
+{
+  /* Try by the MAC address. */
+
+  /* Add ethernet type */
+  grub_strcpy (suffix, "01-");
+
+  grub_net_hwaddr_to_str (&inf->hwaddress, suffix + 3);
+
+  char *ptr;
+  for (ptr = suffix; *ptr; ptr++)
+if (*ptr == ':')
+  *ptr = '-';
+
+  if (search_through (1, 3) == 0) return GRUB_ERR_NONE;
+
+  /* Then by IP address */
+
+  switch ((&inf->address)->type)
+{
+case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6:
+{
+  break;
+}
+case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4:
+{
+  grub_uint32_t n = grub_be_to_cpu32 ((&inf->address)->ipv4);
+  grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%02X%02X%02X%02X", \
+ ((n >> 24) & 0xff), ((n >> 16) & 0xff), \
+ ((n >> 8) & 0xff), ((n >> 0) & 0xff));
+
+  if (search_through (8, 1) == 0) return GRUB_ERR_NONE;
+  break;
+}
+case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
+  return grub_error (GRUB_ERR_BUG, "shouldn't reach here");
+default:
+  return grub_error (GRUB_ERR_BUG,
+ "unsupported address type %d", (&inf->address)->type);
+}
+}
+
+  /* Remove the remaining minus sign at the end. */
+  config[config_len] = '\0';
+
+  return GRUB_ERR_NONE;
+}
+
 static struct grub_preboot *fini_hnd;

 static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;

=== modified file 'grub-core/normal/main.c'
--- grub-core/normal/main.c	2012-06-28 00:06:36 +
+++ grub-core/normal/main.c	2012-08-14 08:56:59 +
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 

 GRUB_MOD_LICENSE ("GPLv3+");

@@

[PATCH 1/2] Add %X option to printf functions.

2012-08-14 Thread Paulo Flabiano Smorigo/Brazil/IBM

Hi all,

This adds the option to print hex in upper case. It is necessary for  
the search config file patch.


--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
freenode/bluenet: pfsmorigo or smow
=== modified file 'ChangeLog'
--- ChangeLog	2012-08-05 14:49:03 +
+++ ChangeLog	2012-08-14 03:29:49 +
@@ -1,3 +1,7 @@
+2012-08-13 Paulo Flabiano Smorigo 
+
+	* grub-core/kern/misc.c: Add %X option to printf functions.
+
 2012-08-05  Grégoire Sutre  

 	* configure.ac: Strengthen the test for working -nostdinc -isystem.

=== modified file 'grub-core/kern/misc.c'
--- grub-core/kern/misc.c	2012-05-28 15:49:18 +
+++ grub-core/kern/misc.c	2012-08-14 03:26:15 +
@@ -596,7 +596,7 @@
 static char *
 grub_lltoa (char *str, int c, unsigned long long n)
 {
-  unsigned base = (c == 'x') ? 16 : 10;
+  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
   char *p;

   if ((long long) n < 0 && c == 'd')
@@ -611,7 +611,7 @@
 do
   {
 	unsigned d = (unsigned) (n & 0xf);
-	*p++ = (d > 9) ? d + 'a' - 10 : d + '0';
+	*p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
   }
 while (n >>= 4);
   else
@@ -702,6 +702,7 @@
 	{
 	case 'p':
 	case 'x':
+	case 'X':
 	case 'u':
 	case 'd':
 	case 'c':
@@ -777,6 +778,7 @@
   switch (c)
 	{
 	case 'x':
+	case 'X':
 	case 'u':
 	case 'd':
 	  if (longlongfmt)
@@ -918,6 +920,7 @@
 	  longlongfmt |= (sizeof (void *) == sizeof (long long));
 	  /* Fall through. */
 	case 'x':
+	case 'X':
 	case 'u':
 	  unsig = 1;
 	  /* Fall through. */

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] PReP record when the --no-nvram param is used

2012-05-30 Thread Paulo Flabiano Smorigo

This is a fix to write grub in prep even if the --no-nvram is used.

--
Paulo Flabiano Smorigo
Linux Technology Center Brazil Software Engineer
IBM Systems & Technology Group
pfsmor...@br.ibm.com / pfsmor...@linux.vnet.ibm.com
=== modified file 'util/grub-install.in'
--- util/grub-install.in	2012-05-11 19:07:39 +
+++ util/grub-install.in	2012-05-30 18:46:05 +
@@ -734,8 +734,31 @@
 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
 # Now perform the installation.
 "$grub_setup" ${allow_floppy} ${setup_verbose} ${setup_force} --directory="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" \
-	--device-map="${device_map}" "${install_device}" || exit 1
+--device-map="${device_map}" "${install_device}" || exit 1
 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
+
+# If a install device is defined, copy the core.elf to PReP partition.
+if [ -n "${install_device}" ]; then
+if [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t msdos_parttype)" != "41" ]; then
+	   gettext "The chosen partition is not a PReP partition." 1>&2
+	   echo 1>&2
+	   exit 1
+fi
+
+if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
+	dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
+	gettext "Failed to copy Grub to the PReP partition." 1>&2
+	echo 1>&2
+	exit 1
+	}
+else
+	gettext "The PReP partition is not empty. If you are sure you want to use it, run dd to clear it:" 1>&2
+	echo 1>&2
+	echo "  dd if=/dev/zero of=${install_device}"
+	exit 1
+fi
+fi
+
 if [ x"$update_nvram" = xyes ]; then
 	ofpathname="`which ofpathname`"
 	nvsetenv="`which nvsetenv`"
@@ -768,28 +791,8 @@
 # Point boot-device at the new grub install
 	boot_device="$ofpath:$partno,"`"$grub_mkrelpath" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" | sed 's,/,,g'`
 
-# If a install device is defined, copy the core.elf to PReP partition.
 	else
-if [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t msdos_parttype)" != "41" ]; then
-		gettext "The chosen partition is not a PReP partition." 1>&2
-		echo 1>&2
-		exit 1
-fi
 
-if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
-# Change boot device to the harddisk root
-		boot_device="$ofpath"
-		dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
-		gettext "Failed to copy Grub to the PReP partition." 1>&2
-		echo 1>&2
-		exit 1
-		}
-else
-		gettext "The PReP partition is not empty. If you are sure you want to use it, run dd to clear it:" 1>&2
-		echo 1>&2
-		echo "  dd if=/dev/zero of=${install_device}"
-		exit 1
-fi
 	dev="`echo "${install_device}" | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
 	boot_device="`$ofpathname "$dev"`" || {
 	# TRANSLATORS: "device tree path" is the name of the device

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Skip boot-device set for powerpc-ieee1275

2012-05-29 Thread Paulo Flabiano Smorigo
This patch is to skip the boot-device set for powerpc-ieee1275.  
Changing it could be problematic in some cases.

The choice of the boot device can be done by the SMS menu of the firmware.

--
Paulo Flabiano Smorigo
Linux Technology Center Brazil Software Engineer
IBM Systems & Technology Group
pfsmor...@br.ibm.com / pfsmor...@linux.vnet.ibm.com
irc: pfsmorigo
=== modified file 'util/grub-install.in'
--- util/grub-install.in	2012-05-11 19:07:39 +
+++ util/grub-install.in	2012-05-29 18:22:55 +
@@ -799,14 +799,16 @@
 	}
 	fi
 
-	"$nvsetenv" boot-device "$boot_device" || {
-	# TRANSLATORS: The %s will be replaced by an external program name.
-	gettext_printf "\`%s' failed.\n" "$nvsetenv" 1>&2
-	gettext "You will have to set \`boot-device' variable manually.  At the IEEE1275 prompt, type:" 1>&2
-	echo 1>&2
-	echo "  setenv boot-device $boot_device" 1>&2
-	exit 1
-	}
+if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ]; then
+	"$nvsetenv" boot-device "$boot_device" || {
+	# TRANSLATORS: The %s will be replaced by an external program name.
+gettext_printf "\`%s' failed.\n" "$nvsetenv" 1>&2
+gettext "You will have to set \`boot-device' variable manually.  At the IEEE1275 prompt, type:" 1>&2
+echo 1>&2
+echo "  setenv boot-device $boot_device" 1>&2
+exit 1
+}
+fi
 fi
 elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xmips-arc ]; then
 dvhtool -d "${install_device}" --unix-to-vh "{grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" grub

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel