[Etherboot-developers] 3Com MBA+nbi image support patch
Brought to you by:
marty_connor,
stefanhajnoczi
|
From: Michael G. <mge...@so...> - 2003-01-22 01:02:54
|
So, this patch adds support for booting linux kernel images with a 3Com
MBA + NBI header. Non NBI 3Com MBA headers are aborted.
diff -Nur etherboot-5.1.5/src/Config etherboot-5.1.5-mba/src/Config
--- etherboot-5.1.5/src/Config Fri Jan 10 10:20:05 2003
+++ etherboot-5.1.5-mba/src/Config Tue Jan 21 19:39:50 2003
@@ -122,6 +122,8 @@
#
# Boot image options:
#
+# -DMBA_IMAGE
+# Add 3Com MBA+nbi image kernel boot support.
# -DTAGGED_IMAGE
# Add tagged image kernel boot support (recommended).
# -DAOUT_IMAGE
diff -Nur etherboot-5.1.5/src/arch/i386/core/mba_loader.c etherboot-5.1.5-mba/src/arch/i386/core/mba_loader.c
--- etherboot-5.1.5/src/arch/i386/core/mba_loader.c Wed Dec 31 19:00:00 1969
+++ etherboot-5.1.5-mba/src/arch/i386/core/mba_loader.c Tue Jan 21 19:36:01 2003
@@ -0,0 +1,143 @@
+static int mba_curpos;
+static int mba_oldpos;
+static int mba_headersize;
+static char mba_nbi_header[512];
+
+static sector_t mba_tagged_download(unsigned char *data, unsigned int len, int eof);
+static inline os_download_t mba_tagged_probe(unsigned char *data, unsigned int len)
+{
+ struct segheader *sh;
+ unsigned long loc;
+ char mbasig[] = "TCPIP";
+ int i;
+ if (memcmp(data + 2, mbasig, strlen("TCPIP")) != 0) {
+ return 0;
+ }
+ mba_headersize = *(data + 10) + (*(data + 11) << 8);
+ printf("(MBA %d)",mba_headersize);
+
+ mba_curpos = 0;
+ mba_oldpos = 0;
+
+ return mba_tagged_download;
+
+}
+static sector_t mba_tagged_download(unsigned char *data, unsigned int len, int eof)
+{
+ int i;
+
+ mba_oldpos = mba_curpos;
+ mba_curpos += len;
+
+#ifdef DEBUG
+ printf ("curpos:%d oldpos:%d\n",
+ mba_curpos,
+ mba_oldpos);
+#endif
+
+ /* If we're already past the headers, then we're in the middle of
+ * loading the kernel and we should proceed as normal */
+ if (mba_oldpos > mba_headersize+512)
+ {
+ return tagged_download(data,len,eof);
+ }
+ /* If not then we're still in the middle of mangling the MBA and nbi
+ * headers. */
+ else if (mba_curpos > mba_headersize)
+ {
+ int nbi_start;
+ int nbi_len;
+ /* Case where packet holds first portion of nbi header:
+ * put first portion into the nbi buffer and continue */
+ if ((mba_oldpos <= mba_headersize) &&
+ (mba_curpos < (mba_headersize+512)))
+ {
+ nbi_start = mba_headersize - mba_oldpos;
+ nbi_len = len - nbi_start;
+#ifdef DEBUG
+ printf ("First fraction bytes %d to %d (%d bytes)\n",
+ 0,
+ nbi_len-1,
+ nbi_len);
+#endif
+ memcpy (mba_nbi_header,
+ data+nbi_start,
+ nbi_len);
+ }
+
+ /* Case where packet holds entire nbi header:
+ * don't even bother with the nbi buffer, just adjust the
+ * len dohickey to point to the start of the nbi header,
+ * pass it to the probe function, then proceed as normal */
+ if ((mba_oldpos <= mba_headersize) &&
+ (mba_curpos >= (mba_headersize+512)))
+ {
+ nbi_start = mba_headersize + len - mba_curpos;
+ len -= nbi_start;
+ data += nbi_start;
+ if (!tagged_probe(data,len))
+ {
+ printf ("(!NBI)");
+ longjmp(restart_etherboot, -2);
+ }
+ }
+
+ /* Case where packet holds last portion of nbi header:
+ * save the last portion to the nbi buffer, pass the addr
+ * of the nbi buffer to probe, run the tagged_loader with
+ * twiddled len and tctx.first values. */
+ if ((mba_oldpos > mba_headersize) &&
+ (mba_curpos >= (mba_headersize+512)))
+ {
+ nbi_start = mba_oldpos - mba_headersize;
+ nbi_len = 512 - nbi_start;
+#ifdef DEBUG
+ printf ("Last fraction bytes %d to %d (%d bytes)\n",
+ nbi_start,
+ nbi_start+nbi_len,
+ nbi_len);
+#endif
+ memcpy (mba_nbi_header+nbi_start,
+ data,
+ nbi_len);
+ if (!tagged_probe(mba_nbi_header,512))
+ {
+ printf ("(!NBI)");
+ longjmp(restart_etherboot, -2);
+ }
+ tctx.first = 0;
+ len -= nbi_len;
+ data += nbi_len;
+ }
+
+ /* Case where packet holds sub portion of nbi header:
+ * probably never happen, but better save than sorry, place sub
+ * portion into the nbi buffer, proceed as normal */
+ if ((mba_oldpos > mba_headersize) &&
+ (mba_curpos < (mba_headersize+512)))
+ {
+ nbi_start = mba_oldpos - mba_headersize;
+ nbi_len = len;
+#ifdef DEBUG
+ printf ("Last fraction bytes %d to %d (%d bytes)\n",
+ nbi_start,
+ nbi_start+nbi_len,
+ nbi_len);
+#endif
+ memcpy (mba_nbi_header+nbi_start,
+ data,
+ nbi_len);
+ }
+
+ /* Since we're past the end of the headers, we know it's time
+ * to do the first tagged_download call. We assume that
+ * anything that needs to be jiggered to make this work has
+ * been above. */
+ if (mba_curpos >= (mba_headersize + 512))
+ {
+ return tagged_download(data,len,eof);
+ }
+ }
+
+ return 0;
+}
diff -Nur etherboot-5.1.5/src/core/osloader.c etherboot-5.1.5-mba/src/core/osloader.c
--- etherboot-5.1.5/src/core/osloader.c Fri Dec 13 04:53:59 2002
+++ etherboot-5.1.5-mba/src/core/osloader.c Tue Jan 21 18:38:55 2003
@@ -80,10 +80,14 @@
#include "../arch/i386/core/aout_loader.c"
#endif
-#ifdef TAGGED_IMAGE
+#if defined(TAGGED_IMAGE) || defined(MBA_IMAGE)
#include "../arch/i386/core/tagged_loader.c"
#endif
+#ifdef MBA_IMAGE
+#include "../arch/i386/core/mba_loader.c"
+#endif
+
#if defined(ELF_IMAGE) || defined(ELF64_IMAGE)
#include "elf_loader.c"
#endif
@@ -233,6 +237,9 @@
#endif
#ifdef WINCE_IMAGE
if (!os_download) os_download = wince_probe(data, len);
+#endif
+#ifdef MBA_IMAGE
+ if (!os_download) os_download = mba_tagged_probe(data, len);
#endif
#ifdef TAGGED_IMAGE
if (!os_download) os_download = tagged_probe(data, len);
|