aboutsummaryrefslogtreecommitdiffstats
path: root/diag
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-04-25 12:39:08 -0700
committerH. Peter Anvin <hpa@zytor.com>2011-04-25 12:39:08 -0700
commit5d138981b4666d39963dfeca0f1f33fcb16e26f0 (patch)
treedd461f3ddc25c1ec6fd415bcec51ff4cf14ddf84 /diag
parent5450db41bb3f3a5c291caf4042d226b349821d2b (diff)
downloadsyslinux-5d138981b4666d39963dfeca0f1f33fcb16e26f0.tar.gz
syslinux-5d138981b4666d39963dfeca0f1f33fcb16e26f0.tar.xz
syslinux-5d138981b4666d39963dfeca0f1f33fcb16e26f0.zip
diag/geodsp: Avoid large intermediate files
Allow the generation program mk-lba-img to merge the prefix file and output to stdout, so it can be fed directly to the compressor; that way we avoid generating huge intermediate files on disk. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'diag')
-rw-r--r--diag/geodsp/Makefile18
-rw-r--r--diag/geodsp/mk-lba-img.c53
2 files changed, 41 insertions, 30 deletions
diff --git a/diag/geodsp/Makefile b/diag/geodsp/Makefile
index 6af0d2db..44002bb4 100644
--- a/diag/geodsp/Makefile
+++ b/diag/geodsp/Makefile
@@ -22,7 +22,7 @@ topdir = ../..
# include $(topdir)/MCONFIG.embedded
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
@@ -36,29 +36,23 @@ all: $(BTARGET)
# .PRECIOUS: lba-%.img
# Higher compression levels result in larger files
-%.img.xz: %.img
- xz -k0f $<
+%.img.xz: %.bin mk-lba-img
+ ./mk-lba-img < $< | xz -0f > $@ || ( rm -f $@ ; false )
%.img.gz: %.img
- gzip -9c $< > $@
-
-%.img: %.bin lba.img
- (cp -a lba.img $@ && dd conv=notrunc if=$< of=$@) || rm -f $@
+ ./mk-lba-img < $< | gzip -9 > $@ || ( rm -f $@ ; false )
%.bin: %.asm $(coredir)/writehex.inc $(coredir)/macros.inc $(coredir)/diskboot.inc
nasm $(NASMOPT) -o $@ -l $(@:.bin=.lst) $<
mk-lba-img: mk-lba-img.c
- gcc -o $@ $<
-
-lba.img: mk-lba-img
- ./$< $@
+ gcc -g -O -o $@ $<
tidy dist:
rm -Rf *.img
clean: tidy
- rm -f *.lst *.bin *_bin.c
+ rm -f *.lst *.bin *_bin.c mk-lba-img
spotless: clean
rm -f $(BTARGET)
diff --git a/diag/geodsp/mk-lba-img.c b/diag/geodsp/mk-lba-img.c
index 795de1a7..9de6624e 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,38 @@ 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, BPS, 1, stdin))) {
+ if (len < BPS)
+ memset((char *)b + len, 0, BPS - len);
+ fwrite(b, BPS, 1, f);
+ lba++;
+ }
+
+ 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, BPS, 1, f);
+ lba++;
}
+
+ if (f != stdout)
+ fclose(f);
+
return rv;
}