Attachment 'write_images.c'
Download 1 /*
2 * Write out firmware images for Cirrus Logic's Sound Fusion CS46XX
3 * based soundcards
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Modified on 2008-04-06 by Kalle Olavi Niemitalo.
22 * Modified on 2009-12-17 by Geoff Simmons.
23 */
24
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29
30 /* The following two #defines were copied from
31 * linux-2.6.24/sound/pci/cs46xx/cs46xx_lib.h,
32 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> */
33 /* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */
34 #define BA1_DWORD_SIZE (13 * 1024 + 512)
35 #define BA1_MEMORY_COUNT 3
36
37 typedef uint32_t u32;
38 #include "cs46xx_image.h"
39
40 static int write_image(const char *filename, const void *data, size_t len)
41 {
42 FILE *file = fopen(filename, "wb");
43 if (file == NULL) {
44 perror(filename);
45 return 1;
46 }
47 if (fwrite(data, len, 1, file) != 1) {
48 perror(filename);
49 fclose(file);
50 remove(filename);
51 return 1;
52 }
53 if (fclose(file) != 0) {
54 perror(filename);
55 remove(filename);
56 return 1;
57 }
58 return 0;
59 }
60
61 int main(void)
62 {
63 mkdir("cs46xx", S_IRWXU | S_IRWXG | S_IRWXO);
64 if (write_image("cs46xx/cs46xx-old.fw", &BA1Struct, sizeof BA1Struct))
65 return 1;
66 return 0;
67 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.