jcs's openbsd hax
openbsd
at rk3128 75 lines 2.5 kB view raw
1/* $OpenBSD: build.c,v 1.4 2016/12/18 18:28:39 krw Exp $ */ 2 3/* 4 * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org> 5 * Copyright (c) 2004 Dmitry Bogdan <dsb@imcs.dvgu.ru> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/types.h> 21 22#include <fcntl.h> 23#include <stdlib.h> 24#include <stdio.h> 25#include <err.h> 26#include <unistd.h> 27 28#include "rcvbundl.h" 29 30const u_int32_t fxp_ucode_d101a[] = D101_A_RCVBUNDLE_UCODE; 31const u_int32_t fxp_ucode_d101b0[] = D101_B0_RCVBUNDLE_UCODE; 32const u_int32_t fxp_ucode_d101ma[] = D101M_B_RCVBUNDLE_UCODE; 33const u_int32_t fxp_ucode_d101s[] = D101S_RCVBUNDLE_UCODE; 34const u_int32_t fxp_ucode_d102[] = D102_B_RCVBUNDLE_UCODE; 35const u_int32_t fxp_ucode_d102c[] = D102_C_RCVBUNDLE_UCODE; 36const u_int32_t fxp_ucode_d102e[] = D102_E_RCVBUNDLE_UCODE; 37 38#define UCODE(x) x, sizeof(x) 39 40static void 41output(const char *name, const u_int32_t *ucode, const int ucode_len) 42{ 43 ssize_t rlen; 44 int fd, i; 45 u_int32_t dword; 46 47 printf("creating %s length %d (microcode: %zu DWORDS)\n", 48 name, ucode_len, ucode_len / sizeof(u_int32_t)); 49 fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); 50 if (fd == -1) 51 err(1, "%s", name); 52 for (i = 0; i < ucode_len / sizeof(u_int32_t); i++) { 53 dword = htole32(ucode[i]); 54 rlen = write(fd, &dword, sizeof(dword)); 55 if (rlen == -1) 56 err(1, "%s", name); 57 if (rlen != sizeof(dword)) 58 errx(1, "%s: short write", name); 59 } 60 close(fd); 61} 62 63int 64main(int argc, char *argv[]) 65{ 66 output("fxp-d101a", UCODE(fxp_ucode_d101a)); 67 output("fxp-d101b0", UCODE(fxp_ucode_d101b0)); 68 output("fxp-d101ma", UCODE(fxp_ucode_d101ma)); 69 output("fxp-d101s", UCODE(fxp_ucode_d101s)); 70 output("fxp-d102", UCODE(fxp_ucode_d102)); 71 output("fxp-d102c", UCODE(fxp_ucode_d102c)); 72 output("fxp-d102e", UCODE(fxp_ucode_d102e)); 73 74 return (0); 75}