xref: /openbsd/sys/dev/microcode/rtwn/build.c (revision d415bd75)
1 /*	$OpenBSD: build.c,v 1.1 2021/10/04 01:33:42 kevlo Exp $	*/
2 
3 /*-
4  * Copyright (c) 2006
5  *	Damien Bergamini <damien.bergamini@free.fr>
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 <err.h>
23 #include <fcntl.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 
27 #include "microcode.h"
28 
29 static void
30 output(const char *name, const uint8_t *ucode, int size)
31 {
32 	ssize_t rlen;
33 	int fd;
34 
35 	printf("creating %s length %d\n", name, size);
36 
37 	fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
38 	if (fd == -1)
39 		err(1, "%s", name);
40 
41 	rlen = write(fd, ucode, size);
42 	if (rlen == -1)
43 		err(1, "%s", name);
44 	if (rlen != size)
45 		errx(1, "%s: short write", name);
46 
47 	close(fd);
48 }
49 
50 int
51 main(void)
52 {
53 	output("rtwn-rtl8188e", rtl8188e, sizeof rtl8188e);
54 	output("rtwn-rtl8192cU", rtl8192cU, sizeof rtl8192cU);
55 	output("rtwn-rtl8192cU_B", rtl8192cU_B, sizeof rtl8192cU_B);
56 	output("rtwn-rtl8723", rtl8723, sizeof rtl8723);
57 	output("rtwn-rtl8723_B", rtl8723_B, sizeof rtl8723_B);
58 
59 	return 0;
60 }
61