/* * sdma-gen-image - generate Freescale i.MX SDMA firmware images suitable * for Linux * * Copyright (c) 2010 Sascha Hauer , Pengutronix * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "sdma-firmware.h" static struct sdma_firmware *firmwares[] = { &sdma_imx25_to1, &sdma_imx31_to1, &sdma_imx31_to2, &sdma_imx35_to1, &sdma_imx35_to2, &sdma_imx51, &sdma_imx53, }; static int gen_one(struct sdma_firmware *fw) { struct sdma_firmware_header header; int ret; char *name; FILE *f; ret = asprintf(&name, "%s.bin", fw->name); if (ret < 0) return ret; printf("generating %s\n", name); header.magic = htole32(SDMA_FIRMWARE_MAGIC); header.version_major = htole32(1); header.version_minor = htole32(fw->version); header.script_addrs_start = htole32(sizeof(header)); header.num_script_addrs = htole32(sizeof(struct sdma_script_start_addrs) / sizeof(uint32_t)); header.ram_code_start = htole32(header.script_addrs_start + sizeof(struct sdma_script_start_addrs)); header.ram_code_size = htole32(fw->blob_size * sizeof(uint16_t)); f = fopen(name, "w"); if (!f) { perror("fopen"); ret = -1; goto out_free; } ret = fwrite(&header, sizeof(header), 1, f); if (ret != 1) goto out_free; ret = fwrite(fw->addr, sizeof(struct sdma_script_start_addrs), 1, f); if (ret != 1) goto out_free; ret = fwrite(fw->blob, header.ram_code_size, 1, f); if (ret != 1) goto out_free; fclose(f); return 0; out_free: free(name); return ret; } int main(void) { int i, ret; for (i = 0; i < ARRAY_SIZE(firmwares); i++) { ret = gen_one(firmwares[i]); if (ret) exit(1); } return 0; }