📄 tftpput.c
字号:
#include "tftpput.h"#include "hexput.h"#include "bioscall.h"extern int startup_mode;extern int startup_param;static unsigned char *buf;static int data_len;int tftp_put_begin(void){ switch (startup_mode) { case BOOT_LOAD_PROGRAM: hex_put_begin(); break; case BOOT_UPDATE_BIOS: case BOOT_UPDATE_SYSPARAMETERS: case BOOT_UPDATE_PARTITIONTABLE: case BOOT_UPDATE_PARTITION: case BOOT_UPDATE_FIRMWARE: printf("Starting the TFTP download...\r\n"); buf = (unsigned char *)0x00008000; data_len = 0; break; default: break; } return 0;}int tftp_put(unsigned char *data, int len){ static int count = 0; count += len; if (count > 32 * 1024) { printf("."); count = 0; } switch (startup_mode) { case BOOT_LOAD_PROGRAM: hex_put(data, len); break; case BOOT_UPDATE_BIOS: case BOOT_UPDATE_SYSPARAMETERS: case BOOT_UPDATE_PARTITIONTABLE: case BOOT_UPDATE_PARTITION: case BOOT_UPDATE_FIRMWARE: memcpy(buf + data_len, data, len); data_len += len; break; default: break; } return 0;}int update_bios(unsigned char *bios, int size){ unsigned long offset, bios_size, l; offset = bios_bios_offset();// bios_size = bios_bios_size();// if (size > bios_size)// size = bios_size; printf("Update BIOS ......................... "); bios_flash_erase(offset, size); bios_flash_write(offset, size, &l, bios); printf("Done\r\n\r\n"); return 0;}int update_system_table(unsigned char *system_table, int size){ unsigned long offset, l; offset = bios_system_table_offset(); if (size > bios_system_table_size()) { printf("Bad System Paramters!\r\n\r\n"); return -1; } printf("Update System Paramters ............. "); bios_flash_erase(offset, size); bios_flash_write(offset, size, &l, system_table); printf("Done\r\n\r\n"); return 0;}int update_partition_table(unsigned char *partition_table, int size){ unsigned long offset, l; offset = bios_partition_table_offset(); if (size > bios_partition_table_size()) { printf("Bad Partition Table!\r\n\r\n"); return -1; } printf("Update Partition Table .............. "); bios_flash_erase(offset, size); bios_flash_write(offset, size, &l, partition_table); printf("Done\r\n\r\n"); return 0;}int update_partition(int partition_num, unsigned char *partition_data, int size){ struct partition_table_struct partition_table; struct partition_struct *partition; unsigned long offset, l; bios_partition_table(&partition_table); partition = &partition_table.partition[partition_num]; if (partition->type == 0) { printf("Bad Partition Type!\r\n\r\n"); return -1; } offset = partition->offset; if (offset < bios_partition_table_offset()) { printf("Bad Partition Offset!\r\n\r\n"); return -1; } if (size > partition->size) { printf("Bad Partition Size!\r\n\r\n"); return -1; } printf("Update Partition %d .................. ", partition_num + 1); bios_flash_erase(offset, partition->size); bios_flash_write(offset, size, &l, partition_data); printf("Done\r\n\r\n"); return 0;}int update_firmware(unsigned char *firmware, int size){ struct firmware_hdr *f_hdr; struct firmware_section_hdr *fs_hdr; unsigned char *p; f_hdr = (struct firmware_hdr *)firmware; if (f_hdr->vendor_id != bios_vendor_id() || f_hdr->device_id != bios_device_id() || f_hdr->sub_vendor_id != bios_sub_vendor_id() || f_hdr->sub_device_id != bios_sub_device_id()) { printf("Bad Firmware Format!\r\n\r\n"); return -1; } fs_hdr = (struct firmware_section_hdr *)(buf + f_hdr->offset); while (fs_hdr->size > 0) { p = (unsigned char *)fs_hdr + fs_hdr->offset; switch (fs_hdr->type) { case FIRMWARE_BIOS: printf("update_bios(p, fs_hdr->size)"); update_bios(p, fs_hdr->size); break; case FIRMWARE_SYSPARAMETERS: update_system_table(p, fs_hdr->size); break; case FIRMWARE_PARTITIONTABLE: update_partition_table(p, fs_hdr->size); break; case FIRMWARE_PARTITION: update_partition(fs_hdr->param, p, fs_hdr->size); break; } fs_hdr = (struct firmware_section_hdr *)(p + fs_hdr->size); } return 0;}int tftp_put_end(void){ int ch; unsigned long l; printf("\r\n"); switch (startup_mode) { case BOOT_LOAD_PROGRAM: hex_put_end(); break; case BOOT_UPDATE_BIOS: update_bios(buf, data_len); break; case BOOT_UPDATE_SYSPARAMETERS: //update_system_table(buf, data_len); printf("Update linux,Please wait several minutes...\r\n "); bios_flash_erase(0x00010000, data_len); printf("Finish erasing,writing......"); bios_flash_write(0x00010000, data_len, &l, buf); printf("Done,please press<ESC>\r\n\r\n"); return 0; break; case BOOT_UPDATE_PARTITIONTABLE: //update_partition_table(buf, data_len); asm( " ldr r14, =0x00008000; mov PC, r14; " );//HHTECH break; case BOOT_UPDATE_PARTITION: update_partition(startup_param, buf, data_len); break; case BOOT_UPDATE_FIRMWARE: update_firmware(buf, data_len); break; default: break; } printf("Reboot? (y/n) "); while (1) { ch = getch(); if (ch == 'y' || ch == 'Y') { putch(ch); bios_reboot(); } if (ch == 'n' || ch == 'N') { putch(ch); break; } } printf("\r\n\r\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -