root/dev/microcode/kue/build.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

    1 /*      $OpenBSD: build.c,v 1.4 2007/01/09 16:30:06 deraadt 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/usb/if_kuevar.h>
   20 #include <fcntl.h>
   21 #include <stdlib.h>
   22 #include <err.h>
   23 #include <unistd.h>
   24 #include <string.h>
   25 #include <stdio.h>
   26 #include "kue_fw.h"
   27 
   28 #define FILENAME "kue"
   29 
   30 int
   31 main(int argc, char *argv[])
   32 {
   33         struct  kue_firmware kfproto, *kf;
   34         int len, fd;
   35         ssize_t rlen;
   36 
   37         len = sizeof(*kf) - sizeof(kfproto.data) +
   38             sizeof(kue_code_seg) + sizeof(kue_fix_seg) +
   39             sizeof(kue_trig_seg);
   40 
   41         kf = (struct kue_firmware *)malloc(len);
   42         bzero(kf, len);
   43 
   44         kf->codeseglen = htonl(sizeof(kue_code_seg));
   45         kf->fixseglen = htonl(sizeof(kue_fix_seg));
   46         kf->trigseglen = htonl(sizeof(kue_trig_seg));
   47 
   48         bcopy(kue_code_seg, &kf->data[0],
   49             sizeof(kue_code_seg));
   50         bcopy(kue_fix_seg, &kf->data[sizeof(kue_code_seg)],
   51             sizeof(kue_fix_seg));
   52         bcopy(kue_trig_seg,
   53             &kf->data[sizeof(kue_code_seg) + sizeof(kue_fix_seg)],
   54             sizeof(kue_trig_seg));
   55 
   56         printf("creating %s length %d [%d+%d+%d]\n",
   57             FILENAME, len, sizeof(kue_code_seg), sizeof(kue_fix_seg),
   58             sizeof(kue_trig_seg));
   59         fd = open(FILENAME, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   60         if (fd == -1)
   61                 err(1, FILENAME);
   62 
   63         rlen = write(fd, kf, len);
   64         if (rlen == -1)
   65                 err(1, "%s", FILENAME);
   66         if (rlen != len)
   67                 errx(1, "%s: short write", FILENAME);
   68         free(kf);
   69         close(fd);
   70         return 0;
   71 }

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