xref: /openbsd/sys/dev/microcode/urtwn/build.c (revision 067851b1)
1*067851b1Skevlo /*	$OpenBSD: build.c,v 1.2 2023/04/28 01:24:14 kevlo Exp $	*/
21e1b982aSkevlo 
31e1b982aSkevlo /*-
41e1b982aSkevlo  * Copyright (c) 2006
51e1b982aSkevlo  *	Damien Bergamini <damien.bergamini@free.fr>
61e1b982aSkevlo  *
71e1b982aSkevlo  * Permission to use, copy, modify, and distribute this software for any
81e1b982aSkevlo  * purpose with or without fee is hereby granted, provided that the above
91e1b982aSkevlo  * copyright notice and this permission notice appear in all copies.
101e1b982aSkevlo  *
111e1b982aSkevlo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
121e1b982aSkevlo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
131e1b982aSkevlo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
141e1b982aSkevlo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
151e1b982aSkevlo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
161e1b982aSkevlo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
171e1b982aSkevlo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
181e1b982aSkevlo  */
191e1b982aSkevlo 
201e1b982aSkevlo #include <sys/types.h>
211e1b982aSkevlo 
221e1b982aSkevlo #include <err.h>
231e1b982aSkevlo #include <fcntl.h>
241e1b982aSkevlo #include <stdio.h>
251e1b982aSkevlo #include <unistd.h>
261e1b982aSkevlo 
271e1b982aSkevlo #include "microcode.h"
281e1b982aSkevlo 
291e1b982aSkevlo static void
output(const char * name,const uint8_t * ucode,int size)301e1b982aSkevlo output(const char *name, const uint8_t *ucode, int size)
311e1b982aSkevlo {
321e1b982aSkevlo 	ssize_t rlen;
331e1b982aSkevlo 	int fd;
341e1b982aSkevlo 
351e1b982aSkevlo 	printf("creating %s length %d\n", name, size);
361e1b982aSkevlo 
371e1b982aSkevlo 	fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
381e1b982aSkevlo 	if (fd == -1)
391e1b982aSkevlo 		err(1, "%s", name);
401e1b982aSkevlo 
411e1b982aSkevlo 	rlen = write(fd, ucode, size);
421e1b982aSkevlo 	if (rlen == -1)
431e1b982aSkevlo 		err(1, "%s", name);
441e1b982aSkevlo 	if (rlen != size)
451e1b982aSkevlo 		errx(1, "%s: short write", name);
461e1b982aSkevlo 
471e1b982aSkevlo 	close(fd);
481e1b982aSkevlo }
491e1b982aSkevlo 
501e1b982aSkevlo int
main(void)511e1b982aSkevlo main(void)
521e1b982aSkevlo {
531e1b982aSkevlo 	output("urtwn-rtl8188eu", rtl8188eu, sizeof rtl8188eu);
54*067851b1Skevlo 	output("urtwn-rtl8188ftv", rtl8188ftv, sizeof rtl8188ftv);
551e1b982aSkevlo 	output("urtwn-rtl8192cT", rtl8192cT, sizeof rtl8192cT);
561e1b982aSkevlo 	output("urtwn-rtl8192cU", rtl8192cU, sizeof rtl8192cU);
571e1b982aSkevlo 	output("urtwn-rtl8192eu", rtl8192eu, sizeof rtl8192eu);
581e1b982aSkevlo 
591e1b982aSkevlo 	return 0;
601e1b982aSkevlo }
61