This source file includes following definitions.
- hswapn
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <sys/types.h>
19 #include <dev/pci/ydsvar.h>
20 #include <fcntl.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <err.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include "yds_hwmcode.h"
27
28 #define FILENAME "yds"
29
30 void
31 hswapn(u_int32_t *p, int wcount)
32 {
33 for (; wcount; wcount -=4) {
34 *p = htonl(*p);
35 p++;
36 }
37 }
38
39 int
40 main(int argc, char *argv[])
41 {
42 struct yds_firmware yfproto, *yf;
43 int len, fd;
44 ssize_t rlen;
45
46 len = sizeof(*yf) - sizeof(yfproto.data) +
47 sizeof(yds_dsp_mcode) + sizeof(yds_ds1_ctrl_mcode) +
48 sizeof(yds_ds1e_ctrl_mcode);
49
50 yf = (struct yds_firmware *)malloc(len);
51 bzero(yf, len);
52
53 yf->dsplen = htonl(sizeof(yds_dsp_mcode));
54 yf->ds1len = htonl(sizeof(yds_ds1_ctrl_mcode));
55 yf->ds1elen = htonl(sizeof(yds_ds1e_ctrl_mcode));
56
57 bcopy(yds_dsp_mcode, &yf->data[0], sizeof(yds_dsp_mcode));
58 hswapn((u_int32_t *)&yf->data[0], sizeof(yds_dsp_mcode));
59
60 bcopy(yds_ds1_ctrl_mcode, &yf->data[sizeof(yds_dsp_mcode)],
61 sizeof(yds_ds1_ctrl_mcode));
62 hswapn((u_int32_t *)&yf->data[sizeof(yds_dsp_mcode)],
63 sizeof(yds_ds1_ctrl_mcode));
64
65 bcopy(yds_ds1e_ctrl_mcode,
66 &yf->data[sizeof(yds_dsp_mcode) + sizeof(yds_ds1_ctrl_mcode)],
67 sizeof(yds_ds1e_ctrl_mcode));
68 hswapn((u_int32_t *)&yf->data[sizeof(yds_dsp_mcode) +
69 sizeof(yds_ds1_ctrl_mcode)],
70 sizeof(yds_ds1e_ctrl_mcode));
71
72 printf("creating %s length %d [%d+%d+%d]\n",
73 FILENAME, len, sizeof(yds_dsp_mcode),
74 sizeof(yds_ds1_ctrl_mcode), sizeof(yds_ds1e_ctrl_mcode));
75 fd = open(FILENAME, O_WRONLY|O_CREAT|O_TRUNC, 0644);
76 if (fd == -1)
77 err(1, FILENAME);
78
79 rlen = write(fd, yf, len);
80 if (rlen == -1)
81 err(1, "%s", FILENAME);
82 if (rlen != len)
83 errx(1, "%s: short write", FILENAME);
84 free(yf);
85 close(fd);
86 return 0;
87 }