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
|
grub_script.yy.c: grub_script.yy.h
|
||||||
|
|
||||||
rs_decoder.S: $(srcdir)/lib/reed_solomon.c
|
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
|
CLEANFILES += grub_script.yy.c grub_script.yy.h
|
||||||
|
|
||||||
|
|
|
@ -206,16 +206,16 @@ LOCAL (codestart):
|
||||||
incl %eax
|
incl %eax
|
||||||
call grub_gate_a20
|
call grub_gate_a20
|
||||||
|
|
||||||
movl EXT_C(grub_kernel_image_size), %eax
|
movl EXT_C(grub_compressed_size), %edx
|
||||||
addl EXT_C(grub_total_module_size), %eax
|
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx
|
||||||
movl reed_solomon_redundancy, %ecx
|
movl reed_solomon_redundancy, %ecx
|
||||||
leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %edx
|
leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax
|
||||||
testl %eax, %eax
|
testl %edx, %edx
|
||||||
jz post_reed_solomon
|
jz post_reed_solomon
|
||||||
call EXT_C (grub_reed_solomon_recover)
|
call EXT_C (grub_reed_solomon_recover)
|
||||||
jmp post_reed_solomon
|
jmp post_reed_solomon
|
||||||
|
|
||||||
#include "/home/phcoder/compile/grub-core/rs_decoder.S"
|
#include <rs_decoder.S>
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,12 @@ typedef grub_uint8_t gf_single_t;
|
||||||
typedef grub_uint16_t gf_double_t;
|
typedef grub_uint16_t gf_double_t;
|
||||||
#define GF_POLYNOMIAL 0x1d
|
#define GF_POLYNOMIAL 0x1d
|
||||||
#define GF_INVERT2 0x8e
|
#define GF_INVERT2 0x8e
|
||||||
#ifdef STANDALONE
|
#if defined (STANDALONE) && !defined (TEST)
|
||||||
static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100000;
|
static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000;
|
||||||
|
static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100;
|
||||||
#else
|
#else
|
||||||
static char *scratch;
|
static char *scratch;
|
||||||
|
static grub_uint8_t gf_invert[256];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SECTOR_SIZE 512
|
#define SECTOR_SIZE 512
|
||||||
|
@ -85,8 +87,6 @@ gf_mul (gf_single_t a, gf_single_t b)
|
||||||
return gf_reduce (res);
|
return gf_reduce (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_uint8_t gf_invert[256];
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_inverts (void)
|
init_inverts (void)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,7 @@ pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined (STANDALONE) || defined (TEST)
|
#if !defined (STANDALONE)
|
||||||
static void
|
static void
|
||||||
rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
|
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
|
static void
|
||||||
encode_block (gf_single_t *ptr, grub_size_t s,
|
encode_block (gf_single_t *ptr, grub_size_t s,
|
||||||
gf_single_t *rptr, grub_size_t rs)
|
gf_single_t *rptr, grub_size_t rs)
|
||||||
|
@ -402,7 +402,7 @@ encode_block (gf_single_t *ptr, grub_size_t s,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined (STANDALONE) || defined (TEST)
|
#if !defined (STANDALONE)
|
||||||
void
|
void
|
||||||
grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
|
grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
|
||||||
grub_size_t redundancy)
|
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 *ptr = buffer;
|
||||||
gf_single_t *rptr = ptr + s;
|
gf_single_t *rptr = ptr + s;
|
||||||
|
|
||||||
|
grub_printf ("solomon: %p, %x, %x\n", buffer, data_size, redundancy);
|
||||||
|
|
||||||
while (s > 0)
|
while (s > 0)
|
||||||
{
|
{
|
||||||
grub_size_t tt;
|
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 *ptr = ptr_;
|
||||||
gf_single_t *rptr = ptr + s;
|
gf_single_t *rptr = ptr + s;
|
||||||
|
|
||||||
#if defined (STANDALONE) && !defined (TEST)
|
#if defined (STANDALONE)
|
||||||
init_inverts ();
|
init_inverts ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -475,7 +477,9 @@ main (int argc, char **argv)
|
||||||
scratch = xmalloc (1048576);
|
scratch = xmalloc (1048576);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef STANDALONE
|
||||||
init_inverts ();
|
init_inverts ();
|
||||||
|
#endif
|
||||||
|
|
||||||
in = fopen ("tst.bin", "rb");
|
in = fopen ("tst.bin", "rb");
|
||||||
if (!in)
|
if (!in)
|
||||||
|
@ -487,6 +491,10 @@ main (int argc, char **argv)
|
||||||
buf = xmalloc (s + rs + SECTOR_SIZE);
|
buf = xmalloc (s + rs + SECTOR_SIZE);
|
||||||
fread (buf, 1, s, in);
|
fread (buf, 1, s, in);
|
||||||
|
|
||||||
|
s = 0x5fbb;
|
||||||
|
rs = 0x6af9;
|
||||||
|
|
||||||
|
#if 0
|
||||||
grub_reed_solomon_add_redundancy (buf, s, rs);
|
grub_reed_solomon_add_redundancy (buf, s, rs);
|
||||||
|
|
||||||
out = fopen ("tst_rs.bin", "wb");
|
out = fopen ("tst_rs.bin", "wb");
|
||||||
|
@ -498,7 +506,9 @@ main (int argc, char **argv)
|
||||||
out = fopen ("tst_dam.bin", "wb");
|
out = fopen ("tst_dam.bin", "wb");
|
||||||
fwrite (buf, 1, s + rs, out);
|
fwrite (buf, 1, s + rs, out);
|
||||||
fclose (out);
|
fclose (out);
|
||||||
|
#endif
|
||||||
|
s = 0x5fbb;
|
||||||
|
rs = 0x6af9;
|
||||||
grub_reed_solomon_recover (buf, s, rs);
|
grub_reed_solomon_recover (buf, s, rs);
|
||||||
|
|
||||||
out = fopen ("tst_rec.bin", "wb");
|
out = fopen ("tst_rec.bin", "wb");
|
||||||
|
|
|
@ -41,9 +41,9 @@
|
||||||
#define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20
|
#define GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE 0x20
|
||||||
|
|
||||||
/* The size of the first region which won't be compressed. */
|
/* 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. */
|
/* The offset of GRUB_PREFIX. */
|
||||||
#define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE
|
#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);
|
0, GRUB_DISK_SECTOR_SIZE);
|
||||||
|
|
||||||
block = first_block;
|
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),
|
save_blocklists (sectors[i] + grub_partition_get_start (container),
|
||||||
0, GRUB_DISK_SECTOR_SIZE);
|
0, GRUB_DISK_SECTOR_SIZE);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue