Changeset 46 for trunk/TOOLS/INTERNAL


Ignore:
Timestamp:
Apr 12, 2014, 8:23:32 AM (11 years ago)
Author:
Ben Rietbroek
Message:

Various Changes [2012-04-14]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Changes

o Added BLDLEVEL support
o Enhanced Master Make
o Sanitized sources
o Support for Wasm and Masm6 (experimental)
o Renamed MBR_PROT.ASM to MBR-PROT.ASM
o Merged bitfield code Into Installer
o First steps for cross platform Installer
o More...

Location:
trunk/TOOLS/INTERNAL
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/TOOLS/INTERNAL/FIXCODE

    r43 r46  
    44# $airboot@ecomstation.com$
    55#
    6 # This is a hack until the Linux version of FIXCODE.C is finished.
     6# This is a quick-hack until the Linux version of FIXCODE.C is finished.
    77# Note that it does not search for the AiR-BOOT Protection Signature,
    88# but embeds it at the 'well known' location.
    9 # It the protection image is moved, this script will corrupt AIR-BOOT.COM
    10 # of which the final AIRBOOT.BIN is derived.
     9# If the protection image is moved, this script will produce a corrupted
     10# AIRBOOT.BIN.
    1111# Also, a code-size of 35h (max size) is always inserted.
    12 # Furthermore, it does no sanity checks whatsoever.
     12# Furthermore, it does not do any sanity checks whatsoever.
    1313#
    1414
    15 PROT_IMG="MBR-PROT/MBR_PROT.COM"
     15#
     16# This script is now obsolete.
     17#
     18exit 1;
     19
     20
     21PROT_IMG="MBR-PROT/MBR-PROT.BIN"
    1622AB_INTERIM_IMG="AIR-BOOT.COM"
     23AB_IMG="AIRBOOT.BIN"
    1724CODE_SIZE_OFFSET=16
    1825PROT_IMG_OFFSET=26624
    1926
    2027
     28function    echox() {
     29    echo -e $@;
     30}
     31
     32
    2133function        Header() {
    22         echo "Header";
     34    echox "\t## FIXCODE script for Linux ##";
    2335}
    2436
    2537function        CheckIfFileExists() {
    26         echo "CheckIfFileExists";
     38        echox "\tCheckIfFileExists";
    2739        if [ ! -f "${1}" ]; then
    28                 echo "ERROR: File ${1} could not be found !";
    29                 echo "       Aborting...";
     40                echox "\tERROR: File ${1} could not be found !";
     41                echox "\t       Aborting...";
    3042                exit 1;
    3143        else
    32                 echo "File ${1} found, OK.";
     44                echox "\tFile ${1} found, OK.";
    3345        fi;
    3446}
    3547
     48function    CreateImage() {
     49    echox "\tCreateImage";
     50    cp -a "${1}" "${2}";
     51}
     52
    3653function        EmbedCodeSize() {
    37         echo "EmbedCodeSize";
    38         echo -n "5" | dd of="${1}" bs=1 seek=${CODE_SIZE_OFFSET} conv=notrunc;
     54        echox "\tEmbedCodeSize";
     55    echo "${1}"
     56        echo -n "5" | dd of="${1}" bs=1 seek=${CODE_SIZE_OFFSET} conv=notrunc 2> /dev/null;
    3957}
    4058
    4159function        EmbedProtectionImage() {
    42         echo "EmbedProtectionImage";
    43         dd if="${1}" of="${2}" bs=1 seek=${PROT_IMG_OFFSET} conv=notrunc;
     60        echox "\tEmbedProtectionImage";
     61        dd if="${1}" of="${2}" bs=1 seek=${PROT_IMG_OFFSET} conv=notrunc 2> /dev/null;
    4462}
    4563
    4664function        VerifyImage() {
    47         echo "VerfyImage";
     65        echox "\tVerfyImage";
    4866}
    4967
    5068function        Footer() {
    51         echo "Footer";
     69        echox "\t## AiR-BOOT code fixed ##";
     70    echo "";
    5271}
    5372
     
    5877#
    5978function        Main() {
    60         echo "## Main ##";
     79    echo "";
    6180        Header;
    62         CheckIfFileExists "${PROT_IMG}"
    63         CheckIfFileExists "${AB_INTERIM_IMG}"
    64         EmbedCodeSize "${AB_INTERIM_IMG}";
    65         EmbedProtectionImage "${PROT_IMG}" "${AB_INTERIM_IMG}";
     81        CheckIfFileExists "${PROT_IMG}";
     82        CheckIfFileExists "${AB_INTERIM_IMG}";
     83    CreateImage "${AB_INTERIM_IMG}" "${AB_IMG}";
     84        EmbedProtectionImage "${PROT_IMG}" "${AB_IMG}";
     85    EmbedCodeSize "${AB_IMG}";
    6686        Footer;
    6787}
  • trunk/TOOLS/INTERNAL/FIXCODE.ASM

    r43 r46  
    4141COM_CodeName    db 'AIR-BOOT.COM', 0
    4242COM_LoadMBR     db ' - Loading MBR-protection from file...$'
    43 COM_MBRName     db 'MBR-PROT\MBR_PROT.COM', 0
     43COM_MBRName     db 'MBR-PROT\MBR-PROT.BIN', 0
    4444COM_MergeMBR    db ' - Merging MBR-protection into bootcode...$'
    4545COM_CountCode   db ' - Count code in bootcode-image...$'
     
    5151COM_FailedReadCode    db 'Read air-boot.com failed', 13, 10, '$'
    5252COM_FailedInvalidCode db 'Invalid air-boot.com', 13, 10, '$'
    53 COM_FailedOpenMBR     db 'mbr-prot\mbr_prot.com not found', 13, 10, '$'
    54 COM_FailedReadMBR     db 'Read mbr-prot\mbr_prot.com failed', 13, 10, '$'
    55 COM_FailedInvalidMBR  db 'Invalid mbr-prot\mbr_prot.com', 13, 10, '$'
     53COM_FailedOpenMBR     db 'mbr-prot\mbr-prot.bin not found', 13, 10, '$'
     54COM_FailedReadMBR     db 'Read mbr-prot\mbr-prot.bin failed', 13, 10, '$'
     55COM_FailedInvalidMBR  db 'Invalid mbr-prot\mbr-prot.bin', 13, 10, '$'
    5656COM_FailedWriteCode   db 'Write air-boot.com failed', 13, 10, '$'
    5757
     
    6565ShowMessage     EndP
    6666
    67 ShowError       Proc Near
    68    mov     ah, 09h
    69    int     21h              ; DOS: WRITE STRING DS:DX TO CONSOLE
    70    jmp     EndProgram
    71    ret
    72 ShowError       EndP
     67ShowError   Proc Near
     68        mov     ah, 09h
     69        int     21h             ; DOS: WRITE STRING DS:DX TO CONSOLE
     70        mov     al,1            ; Error code
     71        jmp     EndProgram
     72        ret
     73ShowError   EndP
    7374
    7475COM_Init:
     
    128129                call    ShowMessage
    129130
    130                 ; Open MBR_PROT.COM
     131                ; Open MBR_PROT.BIN
    131132                mov     dx, offset COM_LoadMBR
    132133                call    ShowMessage
     
    141142DoneOpenMBR:    mov     bx, ax           ; BX = Filehandle
    142143
    143                 ; Load MBR_PROT.COM
     144                ; Load MBR-PROT.BIN
    144145                mov     ah, 3Fh
    145146                mov     cx, 1024         ; Image size
     
    204205                mov     dx, offset COM_Failed
    205206                call    ShowMessage
     207                mov     al,2            ; Error code
    206208                jmp     EndProgram
    207209
     
    220222
    221223                mov     si, offset BootCode
    222                 add     si, 512*53
    223                 mov     cx, 256
    224                 mov     dx, 53
     224                add     si, 512*53  ; 6A00
     225                mov     cx, 256     ; 512 bytes
     226                mov     dx, 53      ; initial count
    225227COM_CodeEndLoop:push    cx
    226228                push    si
     
    277279                mov     dx, offset COM_Okay
    278280                call    ShowMessage
     281                xor     al,al           ; No Error
    279282                jmp     EndProgram
    280283
     
    282285EndProgram:
    283286   ; DOS: TERMINATE PROGRAM
    284    mov     ax, 4C00h
     287   mov     ah, 04Ch
    285288   int     21h
    286289
  • trunk/TOOLS/INTERNAL/FIXCODE.C

    r37 r46  
     1// AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
     2//
     3// This file is part of AiR-BOOT
     4//
     5// AiR-BOOT is free software: you can redistribute it and/or modify it under
     6//  the terms of the GNU General Public License as published by the Free
     7//  Software Foundation, either version 3 of the License, or (at your option)
     8//  any later version.
     9//
     10// AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
     11//  WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
     12//  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     13//  details.
     14//
     15// You should have received a copy of the GNU General Public License along with
     16//  AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
     17//
     18
     19/*
     20// FIXCODE.C -- Fix the AiR-BOOT image; include the code-size and MBR prot-img.
     21//  This reads AIR-BOOT.COM, merges MBR-PROT.BIN and writes AIRBOOT.BIN.
     22//  It is a quick-and-dirty translation of the original DOS-only ASM file.
     23//  Of course it's not as small but it's much easier to maintain across
     24//  multiple platforms.
     25*/
     26
     27
    128#include    "FIXCODE.H"
    229
     
    1946
    2047
    21 #define     IN_FILE     "AIR-BOOT.COM"  // Target from assembly.
    22 #define     MERGE_FILE  "MBR_PROT.BIN"  // MBR protection TSR.
    23 #define     OUT_FILE    "AIRBOOT.BIN"   // Generated loader image.
    24 
    25 
    26 
     48/* File names */
     49#define     IN_FILE     "AIR-BOOT.COM"              // Target from assembly.
     50#ifdef      PLATFORM_LINUX
     51#define     MERGE_FILE  "MBR-PROT/MBR-PROT.BIN"     // MBR protection TSR.
     52#else
     53#define     MERGE_FILE  "MBR-PROT\\MBR-PROT.BIN"    // MBR protection TSR.
     54#endif
     55#define     OUT_FILE    "AIRBOOT.BIN"               // Generated loader image.
     56
     57
     58/* Copyright message */
     59char    Copyright[] = "AiR-BOOT Bootcode Image Fix\n"
     60                        " - (c) Copyright 2009-2012 by M. Kiewitz\n";
     61/* Progress messages */
     62char    LoadCode[]  = " - Loading bootcode from file...";
     63char    LoadMBR[]   = " - Loading MBR-protection from file...";
     64char    MergeMBR[]  = " - Merging MBR-protection into bootcode...";
     65char    CountCode[] = " - Count code in bootcode-image...";
     66char    WriteCode[] = " - Saving bootcode to file...";
     67char    Okay[]      = "ok\n";
     68char    Failed[]    = "failed\n";
     69
     70/* Error messages */
     71char    FailedOpenCode[]    = IN_FILE" not found\n";
     72char    FailedReadCode[]    = "Read "IN_FILE" failed\n";
     73char    FailedInvalidCode[] = "Invalid "IN_FILE"\n";
     74char    FailedOpenMBR[]     = MERGE_FILE" not found\n";
     75char    FailedReadMBR[]     = "Read "MERGE_FILE" failed\n";
     76char    FailedInvalidMBR[]  = "Invalid "MERGE_FILE"\n";
     77char    FailedWriteCode[]   = "Write "OUT_FILE" failed\n";
     78
     79/* The signature we search for in the AIR-BOOT.COM image */
     80char    MBRProtectionSignature[]    = "AiR-BOOT MBR-Protection Image";
     81
     82/* File buffers */
     83char    BootCode[IMAGE_SIZE];   // Buffer for boot-image
     84char    MBRProtection[1024];    // Buffer for protection-image
     85
     86
     87
     88
     89/*
     90// Main Entrypoint.
     91*/
    2792int     main(int argc, char* argv[]) {
    28     FILE*   ifile   = NULL;
    29     FILE*   mfile   = NULL;
    30     FILE*   ofile   = NULL;
    31 
     93    FILE*       ifile   = NULL;
     94    FILE*       mfile   = NULL;
     95    FILE*       ofile   = NULL;
     96    size_t      ibytes  = 0;
     97    size_t      mbytes  = 0;
     98    size_t      obytes  = 0;
     99    unsigned    i       = 0;
     100    unsigned    found   = 0;
     101
     102
     103#if DEBUG_LEVEL > 0
     104    printf("\n%s\n", welcome);
     105    printf("Debug level is: %d\n\n", DEBUG_LEVEL);
     106#endif
     107
     108    /*
     109    // Show copyright message.
     110    */
     111    printf("%s",Copyright);
     112
     113    /*
     114    // Load AIR-BOOT.COM
     115    */
     116    printf("%s",LoadCode);
    32117    ifile = fopen(IN_FILE, "rb");
     118    if (!ifile) {
     119        printf("%s",FailedOpenCode);
     120        exit(1);
     121    }
     122    ibytes = fread(BootCode, 1, IMAGE_SIZE, ifile);
     123    if (ferror(ifile)) {
     124        printf("%s",FailedReadCode);
     125        exit(1);
     126    }
     127    //printf("ibytes: %d\n", ibytes);
     128    fread(BootCode, 1, 1, ifile);
     129    if (ibytes != IMAGE_SIZE || !feof(ifile)) {
     130        printf("%s", FailedInvalidCode);
     131        exit(1);
     132    }
     133    printf("%s", Okay);
     134
     135
     136    /*
     137    // Load MBR-PROT.BIN
     138    */
     139    printf("%s",LoadMBR);
    33140    mfile = fopen(MERGE_FILE, "rb");
     141    if (!mfile) {
     142        printf("%s",FailedOpenMBR);
     143        exit(1);
     144    }
     145    mbytes = fread(MBRProtection, 1, MBRPROT_SIZE, mfile);
     146    if (ferror(mfile)) {
     147        printf("%s",FailedReadMBR);
     148        exit(1);
     149    }
     150    fread(MBRProtection, 1, 1, mfile);
     151    if (mbytes != MBRPROT_SIZE || !feof(mfile)) {
     152        printf("%s", FailedInvalidMBR);
     153        exit(1);
     154    }
     155    printf("%s", Okay);
     156
     157
     158    /*
     159    // Find Protection Image Signature.
     160    // Note that this signature must reside on a sector boundary.
     161    */
     162    for (i=0; i<55; i++) {
     163        if (!memcmp(MBRProtectionSignature, &BootCode[i*SECSIZE], strlen(MBRProtectionSignature))) {
     164            found = 1;
     165            break;
     166        }
     167    }
     168
     169    /*
     170    // Merge Protection Image.
     171    */
     172    printf("%s",MergeMBR);
     173    if (!found) {
     174        printf("%s",Failed);
     175        exit(2);
     176    }
     177    memcpy(&BootCode[i*SECSIZE], MBRProtection, MBRPROT_SIZE);
     178    printf("%s", Okay);
     179
     180
     181    /*
     182    // Count Code Sectors.
     183    // Obsolete now since the Protection Image has moved just below the
     184    // Configuration and the code is always max. size.
     185    // Overlap checking is done while assembling AIR-BOOT.ASM.
     186    */
     187    printf("%s", CountCode);
     188    BootCode[16] = 53;
     189    printf("%s", Okay);
     190
     191    /*
     192    // Write AIRBOOT.BIN
     193    */
     194    printf("%s", WriteCode);
    34195    ofile = fopen(OUT_FILE, "wb");
    35 
    36 
    37     printf("\n%s\n", welcome);
    38 
    39 #if DEBUG_LEVEL > 0
    40     printf("Debug level is: %d", DEBUG_LEVEL);
    41 #endif
    42 
    43 
     196    if (!ofile) {
     197        printf("%s", FailedWriteCode);
     198        exit(3);
     199    }
     200    obytes = fwrite(BootCode, 1, IMAGE_SIZE, ofile);
     201    if (obytes != IMAGE_SIZE || ferror(ofile)) {
     202        printf("%s", FailedWriteCode);
     203        exit(3);
     204    }
     205    printf("%s", Okay);
     206
     207
     208    /*
     209    // Close files.
     210    */
     211    if (ifile)
     212        fclose(ifile);
     213    if (mfile)
     214        fclose(mfile);
     215    if (ofile)
     216        fclose(ofile);
    44217
    45218
  • trunk/TOOLS/INTERNAL/FIXCODE.H

    r37 r46  
    66    #define PLATFORM_DOS
    77#elif defined(__OS2__) && !defined(OS2)
    8     #define INCL_NOPMAPI
    9     #define INCL_BASE
    10     #define INCL_DOS
    11     #define INCL_DOSDEVIOCTL
    12     #include <os2.h>
    138    #define PLATFORM_OS2
    149#elif defined(__NT__)
    15     #include <windows.h>
    1610    #define PLATFORM_WINNT
    1711#elif defined(__LINUX__)
     
    2115#endif
    2216
     17
    2318#include    <stdlib.h>
    2419#include    <stdio.h>
     
    2621
    2722
    28 
    29 
    30 
    31 
    32 
    33 
    34 
    35 
     23#define     IMAGE_SIZE      31744
     24#define     MBRPROT_SIZE    1024
     25#define     SECSIZE         512
    3626
    3727#endif
    38 
    39 
    40 
    41 
    42 
    43 
  • trunk/TOOLS/INTERNAL/Makefile

    r37 r46  
    102102#
    103103CC16=wcc
    104 CC16_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -w4 -e25 -zq -od -fo=$^.
    105 CC16_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -d2 -w4 -e25 -zq -od -fo=$^.
    106 CC16_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -d2 -w4 -e25 -zq -od -fo=$^.
     104MM16=-ml
     105CC16_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) -w4 -e25 -zq -otexan -fo=$^. -fr=$^&.ERR
     106CC16_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) -d2 -w4 -e25 -zq -od -fo=$^. -fr=$^&.ERR
     107CC16_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) -d2 -w4 -e25 -zq -od -fo=$^. -fr=$^&.ERR
    107108CC16_FLAGS=$(CC16_FLAGS_D$(DEBUG_LEVEL))
    108109
     
    110111# 32-bits C Compiler
    111112#
     113MM32=-mf
    112114CC32=wcc386
    113 CC32_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -w4 -e25 -zq -od -6r -mf -fo=$^.
    114 CC32_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -d2 -w4 -e25 -zq -od -6r -mf -fo=$^.
    115 CC32_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -d2 -w4 -e25 -zq -od -6r -mf -fo=$^.
     115CC32_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) -w4 -e25 -zq -otexan -6r -fo=$^. -fr=$^&.ERR
     116CC32_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) -d2 -w4 -e25 -zq -od -6r -fo=$^. -fr=$^&.ERR
     117CC32_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) -d2 -w4 -e25 -zq -od -6r -fo=$^. -fr=$^&.ERR
    116118CC32_FLAGS_R=-w4 -e25 -zq -od -6r -mf -fo=$^.
    117119CC32_FLAGS=$(CC32_FLAGS_D$(DEBUG_LEVEL))
     
    210212#
    211213
    212 #
    213 # While the DOS build-environment has been kept alive in this version,
    214 # it has several drawbacks:
    215 # - No support for long filenames
    216 # - Very limited memory
    217 # - JWasmR does not work because of memory limitations
    218 # - JWasmD does not work at all
    219 # - Batch scripting is very rudimentairy
    220 #
    221 # Therefore, the DOS build-environment will most probably disappear
    222 # in future versions.
    223 # This does not influence the building of DOS targets, which can be done
    224 # on OS/2, Windows or Linux.
    225 #
    226 
    227 
    228214
    229215
     
    244230        @echo TARGET: $^&.COM   [DOS 16-bits COM-file]
    245231        $(ASM) $(ASM_FLAGS) $(BASENAME).ASM
    246         @wdis $^. > $^&.WDA
     232        @wdis -fi $^. > $^&.WDA
    247233
    248234
     
    259245        @echo TARGET: $^&.EXE   [DOS 16-bits Executable]
    260246        $(CC16) $(CC16_FLAGS) -bt=dos $(BASENAME).C
    261         @wdis $^. > $^&.WDA
     247        @wdis -fi $^. > $^&.WDA
    262248
    263249
     
    274260        @echo TARGET: $^&.EXE   [NT 32-bits Executable]
    275261        $(CC32) $(CC32_FLAGS) -I$(%WATCOM)$(DS)h$(DS)nt -bt=nt $(BASENAME).C
    276         @wdis $^. > $^&.WDA
     262        @wdis -fi $^. > $^&.WDA
    277263
    278264
     
    289275        @echo TARGET: $^&.EXE   [OS/2 32-bits Executable]
    290276        $(CC32) $(CC32_FLAGS) -I$(%WATCOM)$(DS)h$(DS)os2 -bt=os2 $(BASENAME).C
    291         @wdis $^. > $^&.WDA
     277        @wdis -fi $^. > $^&.WDA
    292278
    293279
     
    305291        @echo TARGET: $^&.ELF   [Linux 32-bits Executable]
    306292        $(CC32) $(CC32_FLAGS) -bt=linux $(BASENAME).C
    307         @wdis $^. > $^&.WDA
     293        @wdis -fi $^. > $^&.WDA
    308294
    309295
     
    330316        @if exist *.OBJ $(RM) *.OBJ
    331317        @if exist *.WDA $(RM) *.WDA
     318        @if exist *.NDA $(RM) *.NDA
    332319        @if exist *.MAP $(RM) *.MAP
    333320        @if exist *.LST $(RM) *.LST
Note: See TracChangeset for help on using the changeset viewer.