Frederick Ros wrote:
matthieu castet wrote :
| Pour les cartes dvb, ils rajoutent en tete de l'image du firmware son
| crc, pour verifier que le fichier est bien valide. As ton avis est ce
| que ca vaut le coup de le faire aussi ?
Je pense oui.. C'est ce que je pense aussi ajouter pour le code DSP
histoire de ne pas avoir de cas similaire a ceux expose par Gesp dans un
autre post.
Ci joint une version supportant le crc.
Matthieu
Index: driver/eu_utils.c
===================================================================
RCS file: /cvs/eagleusb/eagleusb/driver/eu_utils.c,v
retrieving revision 1.6
diff -u -r1.6 eu_utils.c
--- driver/eu_utils.c 9 Oct 2004 11:59:56 -0000 1.6
+++ driver/eu_utils.c 10 Oct 2004 19:29:16 -0000
@@ -29,8 +29,15 @@
#include "eu_utils.h"
#include "macros.h"
#include "debug.h"
-#include "eu_firmware.h"
+//need CONFIG_FW_LOADER
+#define EXTERN_FW
+
+#ifdef EXTERN_FW
+#include "linux/firmware.h"
+#else
+#include "eu_firmware.h"
+#endif
/* ----------------------- Private Macros/Variables ------------------------ */
@@ -73,8 +80,16 @@
{
int ret= 0;
uint8_t value;
+#ifdef EXTERN_FW
+ const struct firmware *fw_entry;
+ int size;
+ uint8_t *pfw;
+ char *fw_name;
+ uint32_t crc = 0;
+#else
uint32_t i = 0;
eu_hex_record_t *pfirm;
+#endif
eu_enters (DBG_UTILS);
@@ -91,6 +106,57 @@
goto byebye;
}
+#ifdef EXTERN_FW
+if ( IS_EAGLE_I (pid) )
+ {
+ fw_name = "eagleI.fw";
+ }
+ else if ( !IS_EAGLE_III (pid) )
+ {
+ fw_name = "eagleII.fw";
+ }
+ else
+ {
+ fw_name = "eagleIII.fw";
+ }
+
+ ret = request_firmware(&fw_entry, fw_name, &ins->usbdev->dev);
+ if(ret)
+ {
+ eu_err ("%s : Firmware not available\n", fw_name);
+ goto byebye;
+ }
+ pfw = fw_entry->data;
+ size = fw_entry->size;
+
+ crc = le32_to_cpu(*(uint32_t*)pfw);
+ pfw += 4;
+ size -= 4;
+ if (eu_crc_calculate(pfw, size, 0) != crc) {
+ eu_err ("%s : Firmware is corrupted\n", fw_name);
+ release_firmware(fw_entry);
+ ret = -1;
+ goto byebye;
+ }
+
+ while (size>0)
+ {
+ uint8_t len = *pfw;
+ uint16_t add = le16_to_cpu(*(uint16_t*)(pfw+1));
+ ret = eu_send_modem_cmd (ins,
+ add,
+ len,
+ pfw+3);
+ if ( ret < 0 )
+ {
+ eu_err ("eu_send_modem_cmd of download data failed (%d)\n",ret);
+ goto byebye;
+ }
+ pfw += len + 3;
+ size -= len + 3;
+ }
+ release_firmware(fw_entry);
+#else
if ( IS_EAGLE_I (pid) )
{
pfirm = &eu_eagle_I_firmware[0];
@@ -119,6 +185,7 @@
}
pfirm ++;
}
+#endif
/*
* De-assert reset
/*
* generator of eagle firmware image
*
* Copyright (c) 2004 by Castet Matthieu <[EMAIL PROTECTED]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 <inttypes.h>
#include "../eu_firmware.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <asm/byteorder.h>
/* crc stuff shamelessly stolen from linux-2.6.0/lib/crc32.c */
/*
* There are multiple 16-bit CRC polynomials in common use, but this is
* *the* standard CRC-32 polynomial, first popularized by Ethernet.
* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
*/
#define CRCPOLY_BE 0x04c11db7
uint32_t crc32_be(uint32_t crc, unsigned char const *p, size_t len)
{
int i;
while (len--) {
crc ^= *p++ << 24;
for (i = 0; i < 8; i++)
crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
}
return crc;
}
static void mk_fir(char * name, eu_hex_record_t *pfirm)
{
int fd;
uint32_t crc = 0;
fd = creat(name, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd == -1) {
perror("");
return ;
}
write(fd, &crc, 4); /*for crc*/
while(pfirm->type == 0) {
uint16_t add = __cpu_to_le16(pfirm->address);
write(fd, &pfirm->length, sizeof(pfirm->length)/*1*/);
crc = crc32_be(crc, &pfirm->length, sizeof(pfirm->length)/*1*/);
write(fd, &add, sizeof(pfirm->address)/*2*/);
crc = crc32_be(crc, (uint8_t*)&add, sizeof(pfirm->address)/*2*/);
write(fd, pfirm->data, pfirm->length);
crc = crc32_be(crc, pfirm->data, pfirm->length);
pfirm++;
}
crc = __cpu_to_le32(crc);
lseek(fd, 0, SEEK_SET);
write(fd, &crc, 4); /*for crc*/
close(fd);
}
int main() {
mk_fir("eagleI.fw", eu_eagle_I_firmware);
mk_fir("eagleII.fw", eu_eagle_I_firmware);
mk_fir("eagleIII.fw", eu_eagle_I_firmware);
return 0;
}