xref: /openbsd-src/sys/dev/microcode/fxp/build.c (revision 867e01266ee717d282de13c2e4f16d72d8402dd8)
1*867e0126Skrw /*	$OpenBSD: build.c,v 1.4 2016/12/18 18:28:39 krw Exp $	*/
2365a4273Sgrange 
3365a4273Sgrange /*
4365a4273Sgrange  * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org>
5a1d11a4eSbrad  * Copyright (c) 2004 Dmitry Bogdan <dsb@imcs.dvgu.ru>
6365a4273Sgrange  *
7365a4273Sgrange  * Permission to use, copy, modify, and distribute this software for any
8365a4273Sgrange  * purpose with or without fee is hereby granted, provided that the above
9365a4273Sgrange  * copyright notice and this permission notice appear in all copies.
10365a4273Sgrange  *
11365a4273Sgrange  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12365a4273Sgrange  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13365a4273Sgrange  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14365a4273Sgrange  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15365a4273Sgrange  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16365a4273Sgrange  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17365a4273Sgrange  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18365a4273Sgrange  */
19365a4273Sgrange 
20365a4273Sgrange #include <sys/types.h>
21365a4273Sgrange 
22365a4273Sgrange #include <fcntl.h>
23365a4273Sgrange #include <stdlib.h>
24948e15b6Sjason #include <stdio.h>
25948e15b6Sjason #include <err.h>
26948e15b6Sjason #include <unistd.h>
27365a4273Sgrange 
28365a4273Sgrange #include "rcvbundl.h"
29365a4273Sgrange 
30365a4273Sgrange const u_int32_t fxp_ucode_d101a[] = D101_A_RCVBUNDLE_UCODE;
31365a4273Sgrange const u_int32_t fxp_ucode_d101b0[] = D101_B0_RCVBUNDLE_UCODE;
32365a4273Sgrange const u_int32_t fxp_ucode_d101ma[] = D101M_B_RCVBUNDLE_UCODE;
33365a4273Sgrange const u_int32_t fxp_ucode_d101s[] = D101S_RCVBUNDLE_UCODE;
34365a4273Sgrange const u_int32_t fxp_ucode_d102[] = D102_B_RCVBUNDLE_UCODE;
35365a4273Sgrange const u_int32_t fxp_ucode_d102c[] = D102_C_RCVBUNDLE_UCODE;
36a1d11a4eSbrad const u_int32_t fxp_ucode_d102e[] = D102_E_RCVBUNDLE_UCODE;
37365a4273Sgrange 
38365a4273Sgrange #define UCODE(x)	x, sizeof(x)
39365a4273Sgrange 
40365a4273Sgrange static void
output(const char * name,const u_int32_t * ucode,const int ucode_len)41365a4273Sgrange output(const char *name, const u_int32_t *ucode, const int ucode_len)
42365a4273Sgrange {
43948e15b6Sjason 	ssize_t rlen;
44365a4273Sgrange 	int fd, i;
45365a4273Sgrange 	u_int32_t dword;
46365a4273Sgrange 
47*867e0126Skrw 	printf("creating %s length %d (microcode: %zu DWORDS)\n",
48365a4273Sgrange 	    name, ucode_len, ucode_len / sizeof(u_int32_t));
49365a4273Sgrange 	fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
50365a4273Sgrange 	if (fd == -1)
51365a4273Sgrange 		err(1, "%s", name);
52365a4273Sgrange 	for (i = 0; i < ucode_len / sizeof(u_int32_t); i++) {
53365a4273Sgrange 		dword = htole32(ucode[i]);
54948e15b6Sjason 		rlen = write(fd, &dword, sizeof(dword));
55948e15b6Sjason 		if (rlen == -1)
56948e15b6Sjason 			err(1, "%s", name);
57948e15b6Sjason 		if (rlen != sizeof(dword))
58948e15b6Sjason 			errx(1, "%s: short write", name);
59365a4273Sgrange 	}
60365a4273Sgrange 	close(fd);
61365a4273Sgrange }
62365a4273Sgrange 
63365a4273Sgrange int
main(int argc,char * argv[])64365a4273Sgrange main(int argc, char *argv[])
65365a4273Sgrange {
66365a4273Sgrange 	output("fxp-d101a", UCODE(fxp_ucode_d101a));
67365a4273Sgrange 	output("fxp-d101b0", UCODE(fxp_ucode_d101b0));
68365a4273Sgrange 	output("fxp-d101ma", UCODE(fxp_ucode_d101ma));
69365a4273Sgrange 	output("fxp-d101s", UCODE(fxp_ucode_d101s));
70365a4273Sgrange 	output("fxp-d102", UCODE(fxp_ucode_d102));
71365a4273Sgrange 	output("fxp-d102c", UCODE(fxp_ucode_d102c));
72a1d11a4eSbrad 	output("fxp-d102e", UCODE(fxp_ucode_d102e));
73365a4273Sgrange 
74365a4273Sgrange 	return (0);
75365a4273Sgrange }
76