]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Multiple bugs correction for Reed-Solomon
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 25 Sep 2010 18:40:26 +0000 (20:40 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 25 Sep 2010 18:40:26 +0000 (20:40 +0200)
grub-core/Makefile.am
grub-core/kern/i386/pc/startup.S
grub-core/lib/reed_solomon.c
include/grub/offsets.h
util/grub-setup.c

index 307467f44e602ab0ee9fbae30e260c4ff186813e..a740cb5cbb945d2bd6ed39e5b7fd478caf9a99da 100644 (file)
@@ -50,7 +50,7 @@ grub_script.yy.h: script/yylex.l
 grub_script.yy.c: grub_script.yy.h
 
 rs_decoder.S: $(srcdir)/lib/reed_solomon.c
-       $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $<
+       $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0
 
 CLEANFILES += grub_script.yy.c grub_script.yy.h
 
index 283fc4f4953c4c3253e4a2aca91b048dc969d33e..9319df98ee1f99c470cd9fabf54fc3406d59c0e9 100644 (file)
@@ -206,16 +206,16 @@ LOCAL (codestart):
        incl    %eax
        call    grub_gate_a20
 
-       movl    EXT_C(grub_kernel_image_size), %eax
-       addl    EXT_C(grub_total_module_size), %eax
+       movl    EXT_C(grub_compressed_size), %edx
+       addl    $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx
        movl    reed_solomon_redundancy, %ecx
-       leal    _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %edx
-       testl   %eax, %eax
+       leal    _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax
+       testl   %edx, %edx
        jz post_reed_solomon
        call    EXT_C (grub_reed_solomon_recover)
        jmp post_reed_solomon
 
-#include "/home/phcoder/compile/grub-core/rs_decoder.S"
+#include <rs_decoder.S>
 
        .text
 
index 290eb94829ea86d194b27219c1fc3a497c372012..f87ff155200fc8a1a352cb9611e92b0c2dc3e404 100644 (file)
@@ -55,10 +55,12 @@ typedef grub_uint8_t gf_single_t;
 typedef grub_uint16_t gf_double_t;
 #define GF_POLYNOMIAL 0x1d
 #define GF_INVERT2 0x8e
-#ifdef STANDALONE
-static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100000;
+#if defined (STANDALONE) && !defined (TEST)
+static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000;
+static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100;
 #else
 static char *scratch;
+static grub_uint8_t gf_invert[256];
 #endif
 
 #define SECTOR_SIZE 512
@@ -85,8 +87,6 @@ gf_mul (gf_single_t a, gf_single_t b)
   return gf_reduce (res);
 }
 
-static grub_uint8_t gf_invert[256];
-
 static void
 init_inverts (void)
 {
@@ -113,7 +113,7 @@ pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x)
   return s;
 }
 
-#if !defined (STANDALONE) || defined (TEST)
+#if !defined (STANDALONE)
 static void
 rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
 {
@@ -382,7 +382,7 @@ decode_block (gf_single_t *ptr, grub_size_t s,
     }
 }
 
-#if !defined (STANDALONE) || defined (TEST)
+#if !defined (STANDALONE)
 static void
 encode_block (gf_single_t *ptr, grub_size_t s,
              gf_single_t *rptr, grub_size_t rs)
@@ -402,7 +402,7 @@ encode_block (gf_single_t *ptr, grub_size_t s,
 }
 #endif
 
-#if !defined (STANDALONE) || defined (TEST)
+#if !defined (STANDALONE)
 void
 grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
                                  grub_size_t redundancy)
@@ -412,6 +412,8 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
   gf_single_t *ptr = buffer;
   gf_single_t *rptr = ptr + s;
 
+  grub_printf ("solomon: %p, %x, %x\n", buffer, data_size, redundancy);
+
   while (s > 0)
     {
       grub_size_t tt;
@@ -439,7 +441,7 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs)
   gf_single_t *ptr = ptr_;
   gf_single_t *rptr = ptr + s;
 
-#if defined (STANDALONE) && !defined (TEST)
+#if defined (STANDALONE)
   init_inverts ();
 #endif
 
@@ -475,7 +477,9 @@ main (int argc, char **argv)
   scratch = xmalloc (1048576);
 #endif
 
+#ifndef STANDALONE
   init_inverts ();
+#endif
 
   in = fopen ("tst.bin", "rb");
   if (!in)
@@ -487,6 +491,10 @@ main (int argc, char **argv)
   buf = xmalloc (s + rs + SECTOR_SIZE);
   fread (buf, 1, s, in);
 
+  s = 0x5fbb;
+  rs = 0x6af9;
+
+#if 0
   grub_reed_solomon_add_redundancy (buf, s, rs);
 
   out = fopen ("tst_rs.bin", "wb");
@@ -498,7 +506,9 @@ main (int argc, char **argv)
   out = fopen ("tst_dam.bin", "wb");
   fwrite (buf, 1, s + rs, out);
   fclose (out);
-
+#endif
+  s = 0x5fbb;
+  rs = 0x6af9;
   grub_reed_solomon_recover (buf, s, rs);
 
   out = fopen ("tst_rec.bin", "wb");
index b8fbe40d4adb4ff7fdda243a0c63bb3530ab5e1e..28db0115cf96a6b986ee85afc3d8c9ad3a73fe93 100644 (file)
@@ -41,9 +41,9 @@
 #define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20
 
 /* The size of the first region which won't be compressed.  */
-#define GRUB_KERNEL_I386_PC_RAW_SIZE           0xc6c
+#define GRUB_KERNEL_I386_PC_RAW_SIZE           0xc80
 
-#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x748
+#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x75c
 
 /* The offset of GRUB_PREFIX.  */
 #define GRUB_KERNEL_I386_PC_PREFIX             GRUB_KERNEL_I386_PC_RAW_SIZE
index 1518bb0a8bf487f0dcba2cd9e4f991ba02dbdc61..953f0038bc8c0a0bef83e470b9f86836a09411ed 100644 (file)
@@ -438,7 +438,7 @@ setup (const char *dir,
                       0, GRUB_DISK_SECTOR_SIZE);
 
     block = first_block;
-    for (i = 1; i < core_sectors; i++)
+    for (i = 1; i < nsec; i++)
       save_blocklists (sectors[i] + grub_partition_get_start (container),
                       0, GRUB_DISK_SECTOR_SIZE);