184 lines
18 KiB
HTML
Executable File
184 lines
18 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="TempleOS V5.03">
|
|
<meta name="viewport" content="width=device-width">
|
|
<link rel="stylesheet" href="/style/templeos.css">
|
|
<script src="/script/templeos.js"></script>
|
|
<style type="text/css">
|
|
.cF0{color:#000000;background-color:#ffffff;}
|
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
|
.cF8{color:#555555;background-color:#ffffff;}
|
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre id="content">
|
|
<a name="l1"></a><span class=cF2>//See </span><a href="/Wb/Doc/Install.DD.HTML#l1"><span class=cF4>Install Documentation</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l2"></a></span><span class=cF2>//Study my account examples: </span><a href="/Wb/Demo/AcctExample/TOS/TOSCfg.HC.HTML#l1"><span class=cF4>Cfg Strs</span></a><span class=cF2>, </span><a href="/Wb/Demo/AcctExample/TOS/TOSDistro.HC.HTML#l1"><span class=cF4>Update Funs</span></a><span class=cF0>
|
|
<a name="l3"></a>
|
|
<a name="l4"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>"BootMHD"</span><span class=cF0>
|
|
<a name="l5"></a>#</span><span class=cF1>include</span><span class=cF0> </span><span class=cF6>"BootMHD2"</span><span class=cF0>
|
|
<a name="l6"></a>
|
|
<a name="l7"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>"Install"</span><span class=cF0>
|
|
<a name="l8"></a>
|
|
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>BOOT_DIR</span><span class=cF0> </span><span class=cF6>"/0000Boot"</span><span class=cF0>
|
|
<a name="l10"></a></span><span class=cF2>//Stage 2 of master boot loader</span><span class=cF0>
|
|
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>BOOT_DIR_BOOTMHD2_BIN_C</span><span class=cF0> </span><span class=cF3>BOOT_DIR</span><span class=cF0> </span><span class=cF6>"/BootMHD2.BIN.C"</span><span class=cF0>
|
|
<a name="l12"></a></span><span class=cF2>//Old master boot record</span><span class=cF0>
|
|
<a name="l13"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>BOOT_DIR_OLDMBR_BIN_C</span><span class=cF0> </span><span class=cF3>BOOT_DIR</span><span class=cF0> </span><span class=cF6>"/OldMBR.BIN.C"</span><span class=cF0>
|
|
<a name="l14"></a>
|
|
<a name="l15"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BootMHDOldRead</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> src_drv,</span><span class=cF1>U8</span><span class=cF0> dst_drv)
|
|
<a name="l16"></a>{</span><span class=cF2>//Reads MBR from disk drive containing src partition.</span><span class=cF0>
|
|
<a name="l17"></a></span><span class=cF2>//Writes a single blk file to dst BOOT_DIR.</span><span class=cF0>
|
|
<a name="l18"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=</span><span class=cF5>Let2BlkDev</span><span class=cF0>(src_drv);
|
|
<a name="l19"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv;
|
|
<a name="l20"></a> </span><span class=cF9>CMasterBoot</span><span class=cF0> mbr;
|
|
<a name="l21"></a> </span><span class=cF5>Drv</span><span class=cF0>(dst_drv);
|
|
<a name="l22"></a> dv=</span><span class=cF5>Fs</span><span class=cF0>->cur_dv;
|
|
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0> && dv->fs_type!=</span><span class=cF3>FSt_FAT32</span><span class=cF0>)
|
|
<a name="l24"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File System Not Supported\n"</span><span class=cF0>);
|
|
<a name="l25"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l26"></a></span><span class=cF2>//Bypass partition bounds-checking</span><span class=cF0>
|
|
<a name="l27"></a> </span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
|
|
<a name="l28"></a> </span><span class=cF5>ATAReadBlks</span><span class=cF0>(bd,&mbr,0,1);
|
|
<a name="l29"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
|
|
<a name="l30"></a>
|
|
<a name="l31"></a> </span><span class=cF5>Drv</span><span class=cF0>(dst_drv);
|
|
<a name="l32"></a> </span><span class=cF5>DirMk</span><span class=cF0>(</span><span class=cF3>BOOT_DIR</span><span class=cF0>);
|
|
<a name="l33"></a> </span><span class=cF5>FileWrite</span><span class=cF0>(</span><span class=cF3>BOOT_DIR_OLDMBR_BIN_C</span><span class=cF0>,&mbr,</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
|
<a name="l34"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l35"></a>}
|
|
<a name="l36"></a>
|
|
<a name="l37"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BootMHDOldWrite</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> src_drv,</span><span class=cF1>U8</span><span class=cF0> dst_drv)
|
|
<a name="l38"></a>{</span><span class=cF2>//Reads OldMBR from src drive BOOT_DIR.</span><span class=cF0>
|
|
<a name="l39"></a></span><span class=cF2>//writes it to the MBR of the drive with dst partition.</span><span class=cF0>
|
|
<a name="l40"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=</span><span class=cF5>Let2BlkDev</span><span class=cF0>(dst_drv);
|
|
<a name="l41"></a> </span><span class=cF9>CMasterBoot</span><span class=cF0> *mbr;
|
|
<a name="l42"></a> </span><span class=cF5>Drv</span><span class=cF0>(src_drv);
|
|
<a name="l43"></a> </span><span class=cF1>if</span><span class=cF0> (mbr=</span><span class=cF5>FileRead</span><span class=cF7>(</span><span class=cF3>BOOT_DIR_OLDMBR_BIN_C</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l44"></a></span><span class=cF2>//Bypass partition bounds-checking</span><span class=cF0>
|
|
<a name="l45"></a> </span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
|
|
<a name="l46"></a> </span><span class=cF5>ATAWriteBlks</span><span class=cF0>(bd,mbr,0,1);
|
|
<a name="l47"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
|
|
<a name="l48"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l49"></a> </span><span class=cF5>Free</span><span class=cF0>(mbr);
|
|
<a name="l50"></a>}
|
|
<a name="l51"></a>
|
|
<a name="l52"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BootMHDZero</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> dst_drv)
|
|
<a name="l53"></a>{</span><span class=cF2>//Set MBR of disk with dst partition to zero.</span><span class=cF0>
|
|
<a name="l54"></a>
|
|
<a name="l55"></a> </span><span class=cF2>//This is dangerous!!</span><span class=cF0>
|
|
<a name="l56"></a> </span><span class=cF2>//The TempleOS partitioner doesn't play well</span><span class=cF0>
|
|
<a name="l57"></a> </span><span class=cF2>//with other operating systems at this time and you need</span><span class=cF0>
|
|
<a name="l58"></a> </span><span class=cF2>//to do this on a drive partitioned by TempleOS</span><span class=cF0>
|
|
<a name="l59"></a> </span><span class=cF2>//if you wish to partition with another operating system.</span><span class=cF0>
|
|
<a name="l60"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=</span><span class=cF5>Let2BlkDev</span><span class=cF0>(dst_drv);
|
|
<a name="l61"></a> </span><span class=cF9>CMasterBoot</span><span class=cF0> mbr;
|
|
<a name="l62"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&mbr,0,</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
|
<a name="l63"></a></span><span class=cF2>//Bypass partition bounds-checking</span><span class=cF0>
|
|
<a name="l64"></a> </span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
|
|
<a name="l65"></a> </span><span class=cF5>ATAWriteBlks</span><span class=cF0>(bd,&mbr,0,1);
|
|
<a name="l66"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
|
|
<a name="l67"></a>}
|
|
<a name="l68"></a>
|
|
<a name="l69"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BootMHDIns</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let,</span><span class=cF1>U8</span><span class=cF0> *drv_lst=</span><span class=cF3>NULL</span><span class=cF0>)
|
|
<a name="l70"></a>{</span><span class=cF2>//Create new MBR on the disk that has drv_let as a partition.</span><span class=cF0>
|
|
<a name="l71"></a></span><span class=cF2>//Puts stage 2 in BOOT_DIR of drv_let.</span><span class=cF0>
|
|
<a name="l72"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd,*bd1;
|
|
<a name="l73"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv,*p1;
|
|
<a name="l74"></a> </span><span class=cF9>CMasterBoot</span><span class=cF0> mbr;
|
|
<a name="l75"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
|
|
<a name="l76"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,size,*_q;
|
|
<a name="l77"></a> </span><span class=cF1>U8</span><span class=cF0> *menu_ptr,*ptr,ch,buf[</span><span class=cF3>STR_LEN</span><span class=cF0>];
|
|
<a name="l78"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l79"></a>
|
|
<a name="l80"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (drv_lst) {
|
|
<a name="l82"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(buf,drv_lst);
|
|
<a name="l83"></a> </span><span class=cF5>StrUtil</span><span class=cF0>(buf,</span><span class=cF3>SUF_TO_UPPER</span><span class=cF0>);
|
|
<a name="l84"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l85"></a> j=0;
|
|
<a name="l86"></a> </span><span class=cF1>for</span><span class=cF0> (i=</span><span class=cF6>'A'</span><span class=cF0>;i<=</span><span class=cF6>'Z'</span><span class=cF0>;i++)
|
|
<a name="l87"></a> buf[j++]=i;
|
|
<a name="l88"></a> buf[j++]=0;
|
|
<a name="l89"></a> }
|
|
<a name="l90"></a> </span><span class=cF5>Drv</span><span class=cF0>(drv_let);
|
|
<a name="l91"></a> dv=</span><span class=cF5>Fs</span><span class=cF0>->cur_dv;
|
|
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0> && dv->fs_type!=</span><span class=cF3>FSt_FAT32</span><span class=cF0>)
|
|
<a name="l93"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File System Not Supported\n"</span><span class=cF0>);
|
|
<a name="l94"></a> </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l95"></a> bd=dv->bd;
|
|
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF3>BOOT_DIR_OLDMBR_BIN_C</span><span class=cF0>,,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l97"></a> </span><span class=cF5>BootMHDOldRead</span><span class=cF0>(drv_let,drv_let);
|
|
<a name="l98"></a>
|
|
<a name="l99"></a> _q=</span><span class=cFD>BMHD2_BLK_ARRAY</span><span class=cF0>;
|
|
<a name="l100"></a> </span><span class=cF5>MemSet</span><span class=cF0>(_q,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0>*8);
|
|
<a name="l101"></a> menu_ptr=</span><span class=cFD>BMHD2_BOOT_MSG</span><span class=cF0>;
|
|
<a name="l102"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(menu_ptr,</span><span class=cF6>"\n\r\n\rTempleOS Boot Loader\n\r\n\r"</span><span class=cF0>);
|
|
<a name="l103"></a> j=0;
|
|
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF3>BOOT_DIR_OLDMBR_BIN_C</span><span class=cF0>,&de,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l105"></a> </span><span class=cF5>Free</span><span class=cF0>(de.full_name);
|
|
<a name="l106"></a> *_q++=</span><span class=cF5>Clus2Blk</span><span class=cF0>(dv,de.clus);
|
|
<a name="l107"></a> </span><span class=cF5>CatPrint</span><span class=cF0>(menu_ptr,</span><span class=cF6>"0. Old Boot Record\n\r"</span><span class=cF0>);
|
|
<a name="l108"></a> j++;
|
|
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l110"></a>
|
|
<a name="l111"></a> ptr=buf;
|
|
<a name="l112"></a> </span><span class=cF1>while</span><span class=cF0> (ch=*ptr++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>p1=</span><span class=cF5>Let2Drv</span><span class=cF0>(ch,</span><span class=cF3>FALSE</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0> && </span><span class=cF7>(</span><span class=cF0>bd1=p1->bd</span><span class=cF7>)</span><span class=cF0> && bd1==bd) {
|
|
<a name="l114"></a> *_q=p1->drv_offset;
|
|
<a name="l115"></a> </span><span class=cF6>"Drive %C:%16X\n"</span><span class=cF0>,</span><span class=cF5>Drv2Let</span><span class=cF0>(p1),*_q;
|
|
<a name="l116"></a> </span><span class=cF5>CatPrint</span><span class=cF0>(menu_ptr,</span><span class=cF6>"%d. Drive %C\n\r"</span><span class=cF0>,j++,</span><span class=cF5>Drv2Let</span><span class=cF7>(</span><span class=cF0>p1</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l117"></a> _q++;
|
|
<a name="l118"></a> }
|
|
<a name="l119"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l120"></a> </span><span class=cF5>CatPrint</span><span class=cF0>(menu_ptr,</span><span class=cF6>"\n\rSelection:"</span><span class=cF0>);
|
|
<a name="l121"></a>
|
|
<a name="l122"></a> size=</span><span class=cFD>BMHD2_END</span><span class=cF0>-</span><span class=cFD>BMHD2_START</span><span class=cF0>;
|
|
<a name="l123"></a> </span><span class=cF5>FileWrite</span><span class=cF0>(</span><span class=cF3>BOOT_DIR_BOOTMHD2_BIN_C</span><span class=cF0>,</span><span class=cFD>BMHD2_START</span><span class=cF0>,size);
|
|
<a name="l124"></a>
|
|
<a name="l125"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF3>BOOT_DIR_BOOTMHD2_BIN_C</span><span class=cF0>,&de,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l126"></a> </span><span class=cF6>"No Boot Loader Image\n"</span><span class=cF0>;
|
|
<a name="l127"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l128"></a> </span><span class=cF5>Free</span><span class=cF0>(de.full_name);
|
|
<a name="l129"></a> *</span><span class=cFD>BMHD_BLK_CNT</span><span class=cF0>(</span><span class=cF9>U16</span><span class=cF0> *)=(size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1)>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
|
<a name="l130"></a> *</span><span class=cFD>BMHD_DAP_BLK</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> *)=</span><span class=cF5>Clus2Blk</span><span class=cF0>(dv,de.clus);
|
|
<a name="l131"></a></span><span class=cF2>//Bypass partition bounds-checking</span><span class=cF0>
|
|
<a name="l132"></a> </span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
|
|
<a name="l133"></a> </span><span class=cF5>ATAReadBlks</span><span class=cF0>(bd,&mbr,0,1);
|
|
<a name="l134"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<</span><span class=cFD>BMHD_END</span><span class=cF0>-</span><span class=cFD>BMHD_CODE</span><span class=cF0>;i++)
|
|
<a name="l135"></a> mbr.code[i]=</span><span class=cFD>BMHD_CODE</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *)[i];
|
|
<a name="l136"></a>#</span><span class=cF1>assert</span><span class=cF0> </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMasterBoot</span><span class=cF0>.code)>=</span><span class=cFD>BMHD_END</span><span class=cF0>-</span><span class=cFD>BMHD_CODE</span><span class=cF0>
|
|
<a name="l137"></a> </span><span class=cF1>for</span><span class=cF0> (;i<</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMasterBoot</span><span class=cF0>.code</span><span class=cF7>)</span><span class=cF0>;i++)
|
|
<a name="l138"></a> mbr.code[i]=0;
|
|
<a name="l139"></a> </span><span class=cF1>if</span><span class=cF0> (!mbr.media_id)
|
|
<a name="l140"></a> mbr.media_id=</span><span class=cF5>RandU32</span><span class=cF0>;
|
|
<a name="l141"></a> mbr.zero=0;
|
|
<a name="l142"></a> mbr.signature=0xAA55;
|
|
<a name="l143"></a>
|
|
<a name="l144"></a> </span><span class=cF5>ATAWriteBlks</span><span class=cF0>(bd,&mbr,0,1);
|
|
<a name="l145"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
|
|
<a name="l146"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l147"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l148"></a> }
|
|
<a name="l149"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
|
<a name="l150"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
|
|
<a name="l151"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l152"></a>}
|
|
</span></pre></body>
|
|
</html>
|