// // Copyright (C) 2015-2018 Markus Hiienkari // // This file is part of Open Source Scan Converter project. // // 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 3 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, see . // #include #include #include "firmware.h" #include "sdcard.h" #include "flash.h" #include "controls.h" #include "tvp7002.h" #include "av_controller.h" #include "lcd.h" #include "utils.h" #include "menu.h" #include "altera_avalon_pio_regs.h" extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; extern alt_u16 rc_keymap[REMOTE_MAX_KEYS]; extern SD_DEV sdcard_dev; extern alt_u16 sys_ctrl; static int check_fw_header(alt_u8 *databuf, fw_hdr *hdr) { alt_u32 crcval, tmp; strncpy(hdr->fw_key, (char*)databuf, 4); if (strncmp(hdr->fw_key, "OSSC", 4)) return FW_IMAGE_ERROR; hdr->version_major = databuf[4]; hdr->version_minor = databuf[5]; strncpy(hdr->version_suffix, (char*)(databuf+6), 8); hdr->version_suffix[7] = 0; memcpy(&tmp, databuf+14, 4); hdr->hdr_len = bswap32(tmp); memcpy(&tmp, databuf+18, 4); hdr->data_len = bswap32(tmp); memcpy(&tmp, databuf+22, 4); hdr->data_crc = bswap32(tmp); // Always at bytes [508-511] memcpy(&tmp, databuf+508, 4); hdr->hdr_crc = bswap32(tmp); if (hdr->hdr_len < 26 || hdr->hdr_len > 508) return FW_HDR_ERROR; crcval = crc32(databuf, hdr->hdr_len, 1); if (crcval != hdr->hdr_crc) return FW_HDR_CRC_ERROR; return 0; } static int check_fw_image(alt_u32 offset, alt_u32 size, alt_u32 golden_crc, alt_u8 *tmpbuf) { alt_u32 crcval=0, i, bytes_to_read; SDRESULTS res; for (i=0; i 0)) { sniprintf(menu_row1, LCD_ROW_LEN+1, "Retrying update"); retries--; goto update_init; } render_osd_page(); return -1; }