summaryrefslogtreecommitdiffstats
path: root/sys/dev/microcode/myx/build.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2011-07-08 03:58:27 +0000
committerdlg <dlg@openbsd.org>2011-07-08 03:58:27 +0000
commitde35ac4b6814b6a59e5af30441d8c09aac8661b4 (patch)
tree47680164809e9e5c76da85740f32af4306618fd2 /sys/dev/microcode/myx/build.c
parentRemove spurious prototype. (diff)
downloadwireguard-openbsd-de35ac4b6814b6a59e5af30441d8c09aac8661b4.tar.xz
wireguard-openbsd-de35ac4b6814b6a59e5af30441d8c09aac8661b4.zip
update the firmware to 1.4.50 via freebsd.
the freebsd firmwares are compressed and get the kernel to uncompress them to use them. we uncompress in build.c so the kernel can just read off disk onto the card without any extra work. this lets us copy future fbsd fw updates directly without any extra work. myri have also rescinded one of the clauses on their license. ok claudio@ deraadt@
Diffstat (limited to 'sys/dev/microcode/myx/build.c')
-rw-r--r--sys/dev/microcode/myx/build.c76
1 files changed, 51 insertions, 25 deletions
diff --git a/sys/dev/microcode/myx/build.c b/sys/dev/microcode/myx/build.c
index fc0368fd8b6..7a12c39593a 100644
--- a/sys/dev/microcode/myx/build.c
+++ b/sys/dev/microcode/myx/build.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: build.c,v 1.1 2007/05/31 18:27:59 reyk Exp $ */
+/* $OpenBSD: build.c,v 1.2 2011/07/08 03:58:27 dlg Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org>
@@ -27,45 +27,71 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <zlib.h>
-#include "myxfw.h"
+#include "eth_z8e.h"
+#include "ethp_z8e.h"
+
+#define CHUNK 8192
void
-myx_build_firmware(u_int32_t *fw, size_t len, const char *file)
+myx_build_firmware(u_int8_t *fw, size_t len, size_t ulen, const char *file)
{
- int fd, rlen;
- size_t i, total = 0;
- u_int32_t data;
+ z_stream zs;
+
+ FILE *f;
+ size_t rlen, total = 0;
+ u_int8_t *ufw;
+ int rv;
- printf("creating %s", file);
- fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (fd == -1)
+ f = fopen(file, "w");
+ if (f == NULL)
err(1, file);
- for (i = 0; i < len; i++) {
- data = letoh32(fw[i]);
- rlen = write(fd, &data, sizeof(u_int32_t));
- if (rlen == -1) {
- printf("\n");
+ ufw = malloc(ulen);
+ if (ufw == NULL)
+ err(1, "ufw malloc");
+
+ bzero(&zs, sizeof (zs));
+ rv = inflateInit(&zs);
+ if (rv != Z_OK)
+ errx(1, "uncompress init failure");
+
+ zs.avail_in = len;
+ zs.next_in = fw;
+ zs.avail_out = ulen;
+ zs.next_out = ufw;
+ rv = inflate(&zs, Z_FINISH);
+ if (rv != Z_STREAM_END)
+ errx(1, "zlib %d", rv);
+
+ inflateEnd(&zs);
+
+ do {
+ rlen = ulen - total;
+ if (rlen > CHUNK)
+ rlen = CHUNK;
+
+ if (fwrite(&ufw[total], rlen, 1, f) < 1) {
+ if (!ferror(f))
+ errx(1, "unexpected short write");
err(1, "%s", file);
}
- if (rlen != sizeof(u_int32_t)) {
- printf("\n");
- errx(1, "%s: short write", file);
- }
+
total += rlen;
- }
+ } while (total < ulen);
- printf(" total %d\n", total);
- close(fd);
+ printf("%s: len %zu -> %zu\n", file, len, ulen);
+ free(ufw);
+ fclose(f);
}
int
main(int argc, char *argv[])
{
- myx_build_firmware(myxfw_eth_z8e,
- MYXFW_ETH_Z8E_SIZE, MYXFW_ALIGNED);
- myx_build_firmware(myxfw_ethp_z8e,
- MYXFW_ETHP_Z8E_SIZE, MYXFW_UNALIGNED);
+ myx_build_firmware(eth_z8e, eth_z8e_length,
+ eth_z8e_uncompressed_length, MYXFW_ALIGNED);
+ myx_build_firmware(ethp_z8e, ethp_z8e_length,
+ ethp_z8e_uncompressed_length, MYXFW_UNALIGNED);
return (0);
}