1 /* $OpenBSD: build.c,v 1.6 2009/08/29 22:53:23 kettenis 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/ic/tivar.h> 20 #include <err.h> 21 #include <fcntl.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 #include <string.h> 25 #include <unistd.h> 26 27 #include "ti_fw.h" 28 #include "ti_fw2.h" 29 30 static void 31 output(const char *name, 32 const int FwReleaseMajor, const int FwReleaseMinor, 33 const int FwReleaseFix, const u_int32_t FwStartAddr, 34 const u_int32_t FwTextAddr, const int FwTextLen, 35 const u_int32_t FwRodataAddr, const int FwRodataLen, 36 const u_int32_t FwDataAddr, const int FwDataLen, 37 const u_int32_t FwSbssAddr, const int FwSbssLen, 38 const u_int32_t FwBssAddr, const int FwBssLen, 39 const u_int32_t *FwText, int sizetext, 40 const u_int32_t *FwRodata, int sizerodata, 41 const u_int32_t *FwData, int sizedata) 42 { 43 struct tigon_firmware tfproto, *tf; 44 int len, fd, i, cnt; 45 u_int32_t *b; 46 ssize_t rlen; 47 48 len = sizeof(tfproto) - sizeof(tfproto.data) + sizetext + 49 sizerodata + sizedata; 50 tf = (struct tigon_firmware *)malloc(len); 51 bzero(tf, len); 52 53 tf->FwReleaseMajor = FwReleaseMajor; 54 tf->FwReleaseMinor = FwReleaseMinor; 55 tf->FwReleaseFix = FwReleaseFix; 56 tf->FwStartAddr = FwStartAddr; 57 58 tf->FwTextAddr = FwTextAddr; 59 tf->FwTextLen = FwTextLen; 60 61 tf->FwRodataAddr = FwRodataAddr; 62 tf->FwRodataLen = FwRodataLen; 63 64 tf->FwDataAddr = FwDataAddr; 65 tf->FwDataLen = FwDataLen; 66 67 tf->FwSbssAddr = FwSbssAddr; 68 tf->FwSbssLen = FwSbssLen; 69 70 tf->FwBssAddr = FwBssAddr; 71 tf->FwBssLen = FwBssLen; 72 73 tf->FwTextOffset = 0; 74 tf->FwRodataOffset = sizetext; 75 tf->FwDataOffset = sizetext + sizerodata; 76 77 bcopy(FwText, &tf->data[tf->FwTextOffset], FwTextLen); 78 bcopy(FwRodata, &tf->data[tf->FwRodataOffset], FwRodataLen); 79 bcopy(FwData, &tf->data[tf->FwDataOffset], FwDataLen); 80 81 b = (u_int32_t *)tf; 82 cnt = len / sizeof(u_int32_t); 83 for (i = 0; i < cnt; i++) 84 b[i] = htole32(b[i]); 85 86 printf("creating %s length %d [%d+%d+%d] [%d+%d+%d]\n", 87 name, len, FwTextLen, FwRodataLen, FwDataLen, 88 sizetext, sizerodata, sizedata); 89 fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); 90 if (fd == -1) 91 err(1, "%s", name); 92 93 rlen = write(fd, tf, len); 94 if (rlen == -1) 95 err(1, "%s", name); 96 if (rlen != len) 97 errx(1, "%s: short write", name); 98 free(tf); 99 close(fd); 100 } 101 102 103 int 104 main(int argc, char *argv[]) 105 { 106 107 output("tigon1", 108 tigonFwReleaseMajor, tigonFwReleaseMinor, 109 tigonFwReleaseFix, tigonFwStartAddr, 110 tigonFwTextAddr, tigonFwTextLen, 111 tigonFwRodataAddr, tigonFwRodataLen, 112 tigonFwDataAddr, tigonFwDataLen, 113 tigonFwSbssAddr, tigonFwSbssLen, 114 tigonFwBssAddr, tigonFwBssLen, 115 tigonFwText, sizeof tigonFwText, 116 tigonFwRodata, sizeof tigonFwRodata, 117 tigonFwData, sizeof tigonFwData); 118 119 output("tigon2", 120 tigon2FwReleaseMajor, tigon2FwReleaseMinor, 121 tigon2FwReleaseFix, tigon2FwStartAddr, 122 tigon2FwTextAddr, tigon2FwTextLen, 123 tigon2FwRodataAddr, tigon2FwRodataLen, 124 tigon2FwDataAddr, tigon2FwDataLen, 125 tigon2FwSbssAddr, tigon2FwSbssLen, 126 tigon2FwBssAddr, tigon2FwBssLen, 127 tigon2FwText, sizeof tigon2FwText, 128 tigon2FwRodata, sizeof tigon2FwRodata, 129 tigon2FwData, sizeof tigon2FwData); 130 131 return 0; 132 } 133