Skip to contentSkip to conversation

Fix build problems in ntldr-img

RFT Vladimir 'φ-coder/phcoder' Serbinenko 1 participant 1 message Nov 29, 2013

lore
Share & tools
lore
#0 lore raw

Currently ntldr-img build fails on anything else than the most plain compile on i386 system. Attached patch improves the situation a tiny bit but build system for ntldr-img stays horrible, the worst being including of target binary in the host tool. Could someon test that this patch didn't break anything?

ntldr-img/Makefile.core.common +9 -8
index f46acd5..f5c0c60 100644
@@ -6,32 +6,33 @@ g2hdr.bin: g2hdr.img
 platform_DATA += g2hdr.bin
 CLEANFILES += g2hdr.bin
 
+g2ldr.mbr: g2ldr.img
+	head -c 8192 $< > $@
+platform_DATA += g2ldr.mbr
+CLEANFILES += g2ldr.mbr
+
 grldr.mbr: grldr.img
 	head -c 8192 $< > $@
 CLEANFILES += grldr.mbr
 
 bin2h: contrib/ntldr-img/bin2h.c
-	$(CC) $^ -o $@
+	$(BUILD_CC) $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $^ -o $@
 CLEANFILES += bin2h
 
 grub_mbr.h: grldr.mbr bin2h
 	./bin2h grub_mbr 8192 < $< > $@
 CLEANFILES += grub_mbr.h
 
-grub-ntldr-img: contrib/ntldr-img/grubinst.c contrib/ntldr-img/utils.c grub_mbr.h
-	$(CC) -I. -I$(srcdir)/contrib/ntldr-img -DLINUX -o $@ $(srcdir)/contrib/ntldr-img/grubinst.c $(srcdir)/contrib/ntldr-img/utils.c
+grub-ntldr-img$(EXEEXT): contrib/ntldr-img/grubinst.c contrib/ntldr-img/utils.c grub_mbr.h
+	$(HOST_CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(HOST_LDFLAGS) -DGRUB_UTIL=1 -I. -I$(srcdir)/contrib/ntldr-img -DLINUX -o $@ $(srcdir)/contrib/ntldr-img/grubinst.c $(srcdir)/contrib/ntldr-img/utils.c
 bin_PROGRAMS += grub-ntldr-img
 CLEANFILES += grub-ntldr-img
 
 # Compatibility symlink.
-grubinst: grub-ntldr-img
+grubinst$(EXEEXT): grub-ntldr-img$(EXEEXT)
 	rm -f $@
 	$(LN_S) $< $@
 noinst_PROGRAMS += grubinst
 CLEANFILES += grubinst
 
-g2ldr.mbr: grub-ntldr-img
-	./grub-ntldr-img --grub2 -o $@
-platform_DATA += g2ldr.mbr
-CLEANFILES += g2ldr.mbr
 endif
ntldr-img/Makefile.core.def +11 -0
index a41f4cc..59dd44b 100644
@@ -19,3 +19,14 @@ image = {
   objcopyflags = '-O binary';
   enable = i386_pc;
 };
+
+image = {
+  name = g2ldr;
+  i386_pc = contrib/ntldr-img/grldrstart.S;
+  i386_pc = contrib/ntldr-img/ntfsbs.S;
+  i386_pc_ccasflags = '-DGRLDR_MBR -DBOOTGRUB2';
+  i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7c00';
+  objcopyflags = '-O binary';
+  enable = i386_pc;
+};
ntldr-img/grldrstart.S +12 -8
index 6553926..2f523f9 100644
@@ -1302,7 +1302,7 @@ Entry_32:
 
 	. = Entry_32 + 0x03
 
-#ifdef	BOOTGRUB
+#if defined (BOOTGRUB)
 	.ascii	"GRLDR   "	/* OEM name string (of OS which formatted the disk). */
 #endif
 
@@ -1830,7 +1830,9 @@ msg_BootError_32:
 
 filename_32:
 
-#ifdef	BOOTGRUB
+#ifdef	BOOTGRUB2
+	.ascii	"G2LDR      \0"
+#elif defined (BOOTGRUB)
 	.ascii	"GRLDR      \0"
 #else
 	.ascii	"KERNEL  SYS\0"
@@ -2002,7 +2004,7 @@ Entry_12_16:
 
 	. = Entry_12_16 + 0x03
 
-#ifdef	BOOTGRUB
+#ifdef BOOTGRUB
 	.ascii	"GRLDR   "
 #endif
 
@@ -2555,7 +2557,9 @@ msg_BootError_12_16:
 
 filename_12_16:
 
-#ifdef	BOOTGRUB
+#ifdef	BOOTGRUB2
+	.ascii	"G2LDR      \0"
+#elif defined (BOOTGRUB)
 	.ascii	"GRLDR      \0"
 #else
 	.ascii	"KERNEL  SYS\0"
@@ -3378,8 +3382,11 @@ msg_No_grldr_ext2:
 	.ascii	"No "
 
 filename_ext2:
+#ifdef	BOOTGRUB2
+	.ascii	"g2ldr\0"
+#else
 	.ascii	"grldr\0"
-
+#endif
 	. = Entry_ext2 + 0x1ee
 
 filename_end_ext2:
@@ -3426,9 +3433,7 @@ boot_error_ext2:
 	. = Entry_ext2 + 0x1fe
 
 	.word	0xAA55
-
 	. = _start1 + 0xA00
-
 #define INSIDE_GRLDR
 
 #include "ntfsbs.S"
@@ -5783,4 +5788,3 @@ grldr_signature:
 
 pre_stage2_start:
 
-
ntldr-img/grubinst.c +61 -54

279 lines not on this page · raw message

ntldr-img/ntfsbs.S +4 -0
index 88b9180..039caf3 100644
@@ -432,7 +432,11 @@ msg_NTFS_Not_Found_Error:
 	.ascii "No "
 
 nt_boot_image:
+#ifdef	BOOTGRUB2
+	.ascii "g2ldr\0"
+#else
 	.ascii "grldr\0"
+#endif
 
 	. = nt_boot_image + 8
 
ntldr-img/utils.c +37 -36

175 lines not on this page · raw message

ntldr-img/utils.h +33 -4
index 05ab114..e48aac8 100644
@@ -42,16 +42,45 @@ typedef struct {
   unsigned long	bse;		// Partition start address
   unsigned long len;		// Partition length
   unsigned long ebs;		// Base address for the extended partition
-} xde_t;
+} __attribute__ ((packed)) xde_t;
 
-#define valueat(buf,ofs,type)	*((type*)(((char*)&buf)+ofs))
+static inline unsigned short
+get16 (const void *buf_, unsigned offset)
+{
+  unsigned char *buf = (unsigned char *) buf_ + offset;
+  return buf[0] | (buf[1] << 8);
+}
+static inline unsigned int
+get32 (const void *buf_, unsigned offset)
+{
+  unsigned char *buf = (unsigned char *) buf_ + offset;
+  return buf[0] | (buf[1] << 8) | (buf[1] << 16) | (buf[1] << 24);
+}
+
+static inline void
+set16 (void *buf_, unsigned offset, unsigned short val)
+{
+  unsigned char *buf = (unsigned char *) buf_ + offset;
+  buf[0] = val;
+  buf[1] = val >> 8;
+}
+
+static inline void
+set32 (void *buf_, unsigned offset, unsigned int val)
+{
+  unsigned char *buf = (unsigned char *) buf_ + offset;
+  buf[0] = val;
+  buf[1] = val >> 8;
+  buf[2] = val >> 16;
+  buf[3] = val >> 24;
+}
 
 extern int mbr_nhd, mbr_spt;
 int go_sect(int,unsigned long);
 int xd_enum(int,xde_t*);
 int get_fstype(unsigned char*);
-char* fst2str(int);
-char* dfs2str(int);
+const char* fst2str(int);
+const char* dfs2str(int);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }