Multiple bugs correction for Reed-Solomon
This commit is contained in:
parent
419cbeb06d
commit
3ac9e79207
5 changed files with 28 additions and 18 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue