summaryrefslogtreecommitdiff
path: root/diag
diff options
context:
space:
mode:
Diffstat (limited to 'diag')
-rw-r--r--diag/geodsp/Makefile35
-rw-r--r--diag/geodsp/mk-lba-img.c55
-rwxr-xr-xdiag/geodsp/mk-lba-img.pl94
-rw-r--r--diag/mbr/Makefile3
-rw-r--r--diag/mbr/README4
-rw-r--r--diag/mbr/handoff.S4
6 files changed, 153 insertions, 42 deletions
diff --git a/diag/geodsp/Makefile b/diag/geodsp/Makefile
index 6af0d2db..55160859 100644
--- a/diag/geodsp/Makefile
+++ b/diag/geodsp/Makefile
@@ -19,46 +19,41 @@
#
topdir = ../..
-# include $(topdir)/MCONFIG.embedded
+MAKEDIR = $(topdir)/mk
+include $(MAKEDIR)/embedded.mk
coredir = $(topdir)/core
-BTARGET = geodsp1s.bin geodspms.bin mk-lba-img \
+BTARGET = geodsp1s.bin geodspms.bin \
geodsp1s.img.xz geodspms.img.xz
-# lba-1s.img.xz lba-ms.img.xz
- # lba-1s.img lba-ms.img
NASMOPT = -i $(coredir)/ -Ox -f bin
NASMOPT += -w+orphan-labels
+CFLAGS = -g -O
all: $(BTARGET)
-.PRECIOUS: %.img
-# .PRECIOUS: lba-%.img
-
# Higher compression levels result in larger files
-%.img.xz: %.img
- xz -k0f $<
+%.img.xz: %.bin mk-lba-img.pl
+ $(PERL) mk-lba-img $< | $(XZ) -0 > $@ || ( rm -f $@ ; false )
-%.img.gz: %.img
- gzip -9c $< > $@
+%.img.gz: %.bin mk-lba-img.pl
+ $(PERL) mk-lba-img $< | $(GZIPPROG) -9 > $@ || ( rm -f $@ ; false )
-%.img: %.bin lba.img
- (cp -a lba.img $@ && dd conv=notrunc if=$< of=$@) || rm -f $@
+# in case someone really wants these without needing a decompressor
+%.img: %.bin mk-lba-img.pl
+ $(PERL) mk-lba-img $< > $@ || ( rm -f $@ ; false )
%.bin: %.asm $(coredir)/writehex.inc $(coredir)/macros.inc $(coredir)/diskboot.inc
- nasm $(NASMOPT) -o $@ -l $(@:.bin=.lst) $<
+ $(NASM) $(NASMOPT) -o $@ -l $(@:.bin=.lst) $<
mk-lba-img: mk-lba-img.c
- gcc -o $@ $<
-
-lba.img: mk-lba-img
- ./$< $@
+ $(CC) $(CFLAGS) -o $@ $<
tidy dist:
- rm -Rf *.img
+ rm -Rf *.lst *.img
+ rm -f mk-lba-img
clean: tidy
- rm -f *.lst *.bin *_bin.c
spotless: clean
rm -f $(BTARGET)
diff --git a/diag/geodsp/mk-lba-img.c b/diag/geodsp/mk-lba-img.c
index 795de1a7..eb1c3393 100644
--- a/diag/geodsp/mk-lba-img.c
+++ b/diag/geodsp/mk-lba-img.c
@@ -24,16 +24,18 @@
#define NUM_SECT (256*63+1)
#define BPS (512)
-#define SECT_INT (512 / sizeof(int))
+#define SECT_INT (BPS / sizeof(unsigned int))
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
-const char DEF_FN[] = "lba.img";
+const char DEF_FN[] = "-";
int main(int argc, char *argv[])
{
- int i, j, b[SECT_INT], rv = 0, one = 0;
+ int i, rv = 0, one = 0;
+ unsigned int lba, b[SECT_INT];
+ int len;
FILE *f;
uint8_t tt = 0;
const char *fn;
@@ -53,23 +55,40 @@ int main(int argc, char *argv[])
fn = DEF_FN;
}
- f = fopen(fn, "w");
+ if (!strcmp(fn, "-"))
+ f = stdout;
+ else
+ f = fopen(fn, "w");
- if (f) {
- for (i = 0; i < NUM_SECT; i++) {
- if (one) {
- b[0] = i;
- } else {
- for (j = 0; j < (512 / sizeof(int)); j++) {
- b[j] = i;
- }
- }
- fwrite(b, 512, 1, f);
+ if (!f) {
+ fprintf(stderr, "%s: %s: unable to open for writing: %s\n",
+ argv[0], fn, strerror(errno));
+ return 1;
+ }
+
+ lba = 0;
+ while ((len = fread(b, 1, BPS, stdin))) {
+ if (len < BPS)
+ memset((char *)b + len, 0, BPS - len);
+ fwrite(b, 1, BPS, f);
+ lba++;
+ }
+
+ memset(b, 0, sizeof b);
+
+ while (lba < NUM_SECT) {
+ if (one) {
+ b[0] = lba;
+ } else {
+ for (i = 0; i < SECT_INT; i++)
+ b[i] = lba;
}
- fclose(f);
- } else {
- puts("Unable to open for writing");
- rv = 1;
+ fwrite(b, 1, BPS, f);
+ lba++;
}
+
+ if (f != stdout)
+ fclose(f);
+
return rv;
}
diff --git a/diag/geodsp/mk-lba-img.pl b/diag/geodsp/mk-lba-img.pl
new file mode 100755
index 00000000..59ef4f0f
--- /dev/null
+++ b/diag/geodsp/mk-lba-img.pl
@@ -0,0 +1,94 @@
+## -----------------------------------------------------------------------
+##
+## Copyright 2011 Gene Cumm
+##
+## This program 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, Inc., 53 Temple Place Ste 330,
+## Boston MA 02111-1307, USA; either version 2 of the License, or
+## (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+##
+## mk-lba-img.pl
+##
+## Make an image where each sector contains the LBA of the sector with
+## a head of an input file.
+##
+
+# use bytes;
+
+use constant SECTOR_SIZE => 512;
+use constant LBA_SIZE => 8;
+use constant LONG_SIZE => 4;
+use constant NUM_SECTORS => (256*63+1);
+# use constant NUM_SECTORS => 5;
+use constant DEBUG => 1;
+
+# sub dprint
+# {
+# if (DEBUG) {
+# print($_);
+# }
+# }
+
+($ifilen, $ofilen) = @ARGV;
+
+if ((!defined($ifilen)) || ($ifilen eq "-")) { #
+ print(STDERR "Using stdin\n");
+ $IFILE = STDIN;
+} else {
+ open($IFILE, '<', $ifilen) or die "open:$!";
+ print(STDERR "Using $ifilen\n");
+}
+
+binmode($ifile);
+
+if (!defined($ofilen)) {
+ $OFILE = STDOUT;
+} else {
+ open($OFILE, '>', $ofilen) or die "open:$!";
+ print(STDERR "Using $ofilen\n");
+}
+
+binmode($OFILE);
+
+# $pk0 = pack('L', 0);
+$n_long = (SECTOR_SIZE/LONG_SIZE);
+$n_lba = (SECTOR_SIZE/LBA_SIZE);
+
+$len=0;
+while ( read($IFILE, $ch, 1) ) {
+ print($OFILE $ch);
+ $len++;
+}
+$tail = (SECTOR_SIZE - ($len % SECTOR_SIZE)) % SECTOR_SIZE;
+$ch = pack("C", 0);
+print("Len: $len\ttail: $tail\n");
+for ($i=0; $i<$tail; $i++) {
+ print($OFILE $ch);
+}
+
+$st = ($len + $tail) / SECTOR_SIZE;
+
+for ($i=$st; $i<(NUM_SECTORS); $i++) {
+ @ia = ();
+ for ($j=0; $j< $n_lba; $j++) {
+ push(@ia, $i, 0);
+ }
+ @ipk = pack("L[$n_long]", @ia);
+ # There is a 64-bit INT conversion but it normally isn't usable
+ # on a 32-bit platform
+ print($OFILE @ipk); # Gently simulate a 64-bit LBA
+}
+
+if (defined($ifilen) && (!($ifilen eq "-"))) {
+ close($IFILE);
+}
+
+if (defined($ofilen)) {
+ close($OFILE);
+}
+
+exit 0;
diff --git a/diag/mbr/Makefile b/diag/mbr/Makefile
index a94253af..79ff9f01 100644
--- a/diag/mbr/Makefile
+++ b/diag/mbr/Makefile
@@ -17,7 +17,8 @@
topdir = ../..
mbrdir = $(topdir)/mbr
-include $(topdir)/MCONFIG.embedded
+MAKEDIR = $(topdir)/mk
+include $(MAKEDIR)/embedded.mk
all: handoff.bin
diff --git a/diag/mbr/README b/diag/mbr/README
index fb7a7dd8..96b67c6c 100644
--- a/diag/mbr/README
+++ b/diag/mbr/README
@@ -5,11 +5,13 @@ handoff.bin Show the data that the BIOS/MBR hands off to an MBR/VBR.
+++ USAGE +++
+NOTE: in the examples, mbr.bin, /dev/hda and /dev/hda1 are used as generic representations.
+
Writing out an MBR is straight forward (it is assumed below that /dev/hda is the target raw device and /dev/hda1 is the target partition):
dd conv=notrunc bs=440 count=1 if=mbr.bin of=/dev/hda
-Writing a VBR to match Syslinux requires more work as it must have a jump and be offset into the partition:
+Writing a VBR to match Syslinux requires more work as it must have a jump and be offset into the partition (and as a result the code must be compaible with this offset):
echo -en "\0353\0130\0220" |dd conv=notrunc bs=1 count=3 of=/dev/hda1
dd conv=notrunc bs=2 count=210 seek=45 if=mbr.bin of=/dev/hda1
diff --git a/diag/mbr/handoff.S b/diag/mbr/handoff.S
index 7af3fdeb..ab8582b7 100644
--- a/diag/mbr/handoff.S
+++ b/diag/mbr/handoff.S
@@ -43,11 +43,11 @@
* Install instructions (assuming your target is /dev/dev; file or block device):
*
* MBR:
- * dd conv=notrunc bs=440 count=1 if=mbr_ho.bin of=/dev/dev
+ * dd conv=notrunc bs=440 count=1 if=handoff.bin of=/dev/dev
*
* VBR/PBR (should work for FAT12/16/32, ext[234]fs, btrfs):
* echo -en "\0353\0130\0220" |dd conv=notrunc bs=1 count=3 of=/dev/dev
- * dd conv=notrunc bs=2 count=210 seek=45 if=mbr_ho.bin of=/dev/dev
+ * dd conv=notrunc bs=2 count=210 seek=45 if=handoff.bin of=/dev/dev
*/
// #define DEBUG_MARKER1 /* Insert markers in binary */