root/dev/microcode/tigon/build.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. output
  2. main

    1 /*      $OpenBSD: build.c,v 1.3 2005/05/17 18:48:52 jason Exp $ */
    2 
    3 /*
    4  * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org>
    5  *
    6  * Permission to use, copy, modify, and distribute this software for any
    7  * purpose with or without fee is hereby granted, provided that the above
    8  * copyright notice and this permission notice appear in all copies.
    9  *
   10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   17  */
   18 #include <sys/types.h>
   19 #include <dev/pci/if_tivar.h>
   20 #include <fcntl.h>
   21 #include <stdlib.h>
   22 
   23 #include "ti_fw.h"
   24 #include "ti_fw2.h"
   25 
   26 static void
   27 output(const char *name,
   28     const int FwReleaseMajor, const int FwReleaseMinor,
   29     const int FwReleaseFix, const u_int32_t FwStartAddr,
   30     const u_int32_t FwTextAddr, const int FwTextLen,
   31     const u_int32_t FwRodataAddr, const int FwRodataLen,
   32     const u_int32_t FwDataAddr, const int FwDataLen,
   33     const u_int32_t FwSbssAddr, const int FwSbssLen,
   34     const u_int32_t FwBssAddr, const int FwBssLen,
   35     const u_int32_t *FwText, int sizetext,
   36     const u_int32_t *FwRodata, int sizerodata,
   37     const u_int32_t *FwData, int sizedata)
   38 {
   39         struct  tigon_firmware tfproto, *tf;
   40         int len, fd, i;
   41         ssize_t rlen;
   42 
   43         len = sizeof tf - sizeof(tfproto.data) + sizetext + sizerodata +
   44             sizedata;
   45         tf = (struct tigon_firmware *)malloc(len);
   46         bzero(tf, len);
   47 
   48         tf->FwReleaseMajor = FwReleaseMajor;
   49         tf->FwReleaseMinor = FwReleaseMinor;
   50         tf->FwReleaseFix = FwReleaseFix;
   51         tf->FwStartAddr = FwStartAddr;
   52 
   53         tf->FwTextAddr = FwTextAddr;
   54         tf->FwTextLen = FwTextLen;
   55 
   56         tf->FwRodataAddr = FwRodataAddr;
   57         tf->FwRodataLen = FwRodataLen;
   58 
   59         tf->FwDataAddr = FwDataAddr;
   60         tf->FwDataLen = FwDataLen;
   61 
   62         tf->FwSbssAddr = FwSbssAddr;
   63         tf->FwSbssLen = FwSbssLen;
   64 
   65         tf->FwBssAddr = FwBssAddr;
   66         tf->FwBssLen = FwBssLen;
   67 
   68         tf->FwTextOffset = 0;
   69         tf->FwRodataOffset = sizetext;
   70         tf->FwDataOffset = sizetext + sizerodata;
   71 
   72         bcopy(FwText, &tf->data[tf->FwTextOffset], FwTextLen);
   73         bcopy(FwRodata, &tf->data[tf->FwRodataOffset], FwRodataLen);
   74         bcopy(FwData, &tf->data[tf->FwDataOffset], FwDataLen);
   75 
   76         printf("creating %s length %d [%d+%d+%d] [%d+%d+%d]\n",
   77             name, len, FwTextLen, FwRodataLen, FwDataLen,
   78             sizetext, sizerodata, sizedata);
   79         fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   80         if (fd == -1)
   81                 err(1, "%s", name);
   82 
   83         rlen = write(fd, tf, len);
   84         if (rlen == -1)
   85                 err(1, "%s", name);
   86         if (rlen != len)
   87                 errx(1, "%s: short write", name);
   88         free(tf);
   89         close(fd);
   90 }
   91 
   92 
   93 int
   94 main(int argc, char *argv[])
   95 {
   96 
   97         output("tigon1",
   98             tigonFwReleaseMajor, tigonFwReleaseMinor,
   99             tigonFwReleaseFix, tigonFwStartAddr,
  100             tigonFwTextAddr, tigonFwTextLen,
  101             tigonFwRodataAddr, tigonFwRodataLen,
  102             tigonFwDataAddr, tigonFwDataLen,
  103             tigonFwSbssAddr, tigonFwSbssLen,
  104             tigonFwBssAddr, tigonFwBssLen,
  105             tigonFwText, sizeof tigonFwText,
  106             tigonFwRodata, sizeof tigonFwRodata,
  107             tigonFwData, sizeof tigonFwData);
  108 
  109         output("tigon2",
  110             tigon2FwReleaseMajor, tigon2FwReleaseMinor,
  111             tigon2FwReleaseFix, tigon2FwStartAddr,
  112             tigon2FwTextAddr, tigon2FwTextLen,
  113             tigon2FwRodataAddr, tigon2FwRodataLen,
  114             tigon2FwDataAddr, tigon2FwDataLen,
  115             tigon2FwSbssAddr, tigon2FwSbssLen,
  116             tigon2FwBssAddr, tigon2FwBssLen,
  117             tigon2FwText, sizeof tigon2FwText,
  118             tigon2FwRodata, sizeof tigon2FwRodata,
  119             tigon2FwData, sizeof tigon2FwData);
  120 
  121         return 0;
  122 }

/* [<][>][^][v][top][bottom][index][help] */