- }
- }
-
- len = (ascii_to_nibble(buf[0]) & 0xf)<< 4;
- len |= ascii_to_nibble(buf[1]) & 0xf;
- len <<= 8;
- len |= (ascii_to_nibble(buf[2]) & 0xf)<< 4;
- len |= ascii_to_nibble(buf[3]) & 0xf;
-
- /* This might be wrong, but it works for current fw */
- if (len > MAX_BLOCK_LENGTH) {
- fprintf(stderr, "Invalid block-length %u > %u for block %d!\n", len, MAX_BLOCK_LENGTH, fw_blocks+1);
- exit(EXIT_FAILURE);
- }
-
- fw = realloc(fw, sizeof(uint8_t*) * (fw_blocks + 1));
- if (fw == NULL) {
- perror("Can't reallocate fw-blocklist");
- exit(EXIT_FAILURE);
- }
-
- fw[fw_blocks] = malloc(len + 4);
- if (fw[fw_blocks] == NULL) {
- perror("Can't allocate memory for fw-block");
- exit(EXIT_FAILURE);
- }
-
- fw[fw_blocks][0] = (fw_blocks >> 8) & 0xff;
- fw[fw_blocks][1] = fw_blocks & 0xff;
- fw[fw_blocks][2] = (len >> 8) & 0xff;
- fw[fw_blocks][3] = len & 0xff;
-
- r = read(fd, buf, len * 2);
- if (r < 0) {
- perror("read");
- exit(EXIT_FAILURE);
- } else if (r < len * 2) {
- fprintf(stderr, "short read, aborting (%d < %d)\n", r, len * 2);
- exit(EXIT_FAILURE);