lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | ****************************************************************************** |
| 3 | * Copyright (C) 2016, ZIXC Corporation. |
| 4 | * |
| 5 | * File Name: |
| 6 | * File Mark: |
| 7 | * Description: |
| 8 | * Others: |
| 9 | * Version: 1.0 |
| 10 | * Author: geanfeng |
| 11 | * Date: 2013-3-4 |
| 12 | * History 1: |
| 13 | * Date: |
| 14 | * Version: |
| 15 | * Author: |
| 16 | * Modification: |
| 17 | * History 2: |
| 18 | ******************************************************************************* |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | *************************************************************************** |
| 23 | * Include files |
| 24 | *************************************************************************** |
| 25 | */ |
| 26 | #include <common.h> |
| 27 | #include <command.h> |
| 28 | #include <net.h> |
| 29 | #include "downloader_serial.h" |
| 30 | #include "partition_table.h" |
| 31 | |
| 32 | |
| 33 | /**************************************************************************** |
| 34 | * Local Macros |
| 35 | ****************************************************************************/ |
| 36 | #define TSP_DOWNLOADER_CBSIZE 256 |
| 37 | |
| 38 | /**************************************************************************** |
| 39 | * Local Types |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | /**************************************************************************** |
| 43 | * Global Variables |
| 44 | ****************************************************************************/ |
| 45 | //char tsp_console_buffer[TSP_DOWNLOADER_CBSIZE + 1]; /* downloader I/O buffer */ |
| 46 | char *tsp_console_buffer = (char*)(CONFIG_NAND_DMA_BUF_ADDR+0x4000); |
| 47 | |
| 48 | unsigned int null_slice_flag = 0; |
| 49 | |
| 50 | |
| 51 | /**************************************************************************** |
| 52 | * Global Function Prototypes |
| 53 | ****************************************************************************/ |
| 54 | extern void downloader_serial_init(void); |
| 55 | extern int UART_CmdRead(char *pchBuf, int dwLen); |
| 56 | |
| 57 | /**************************************************************************** |
| 58 | * Function Definitions |
| 59 | ****************************************************************************/ |
| 60 | /******************************************************************************* |
| 61 | * Function:downloader_readline_into_buffer |
| 62 | * Description: |
| 63 | * Parameters: |
| 64 | * Input: |
| 65 | * |
| 66 | * Output: |
| 67 | * |
| 68 | * Returns: |
| 69 | * |
| 70 | * |
| 71 | * Others: |
| 72 | ********************************************************************************/ |
| 73 | int downloader_readline_into_buffer (char * buffer) |
| 74 | { |
| 75 | char * p_buf = buffer; |
| 76 | unsigned int retSize = 0; |
| 77 | unsigned int recvSize = 0; |
| 78 | |
| 79 | while(1) |
| 80 | { |
| 81 | #if CONFIG_USB_DL |
| 82 | retSize = downloader_serial_read(p_buf,512); |
| 83 | #else |
| 84 | retSize = UART_CmdRead(p_buf,512); |
| 85 | #endif |
| 86 | if(retSize<=0) |
| 87 | { |
| 88 | continue; |
| 89 | } |
| 90 | recvSize += retSize; |
| 91 | if(recvSize >= TSP_DOWNLOADER_CBSIZE) |
| 92 | { |
| 93 | recvSize = 0; |
| 94 | p_buf = buffer; |
| 95 | } |
| 96 | if(buffer[0] == 0x5a) /*filter syc 0x5a*/ |
| 97 | { |
| 98 | printf("readline filter syc 0x5a\n"); |
| 99 | recvSize = 0; |
| 100 | continue; |
| 101 | } |
| 102 | |
| 103 | switch(p_buf[retSize-1]) |
| 104 | { |
| 105 | case '\r': /*Enter */ |
| 106 | case '\n': |
| 107 | case '\0': |
| 108 | while(retSize>0) |
| 109 | { |
| 110 | if( (p_buf[retSize-1] >='a' && p_buf[retSize-1]<='z') ||\ |
| 111 | (p_buf[retSize-1] >='A' && p_buf[retSize-1]<='Z') || \ |
| 112 | (p_buf[retSize-1] >='0' && p_buf[retSize-1]<='9') ) /*filter invalid character*/ |
| 113 | { |
| 114 | break; |
| 115 | } |
| 116 | retSize--; |
| 117 | } |
| 118 | p_buf[retSize]='\0'; |
| 119 | return 0; |
| 120 | default: |
| 121 | p_buf += retSize; |
| 122 | continue; |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | /******************************************************************************* |
| 130 | * Function:downloader_readline |
| 131 | * Description: |
| 132 | * Parameters: |
| 133 | * Input: |
| 134 | * |
| 135 | * Output: |
| 136 | * |
| 137 | * Returns: |
| 138 | * |
| 139 | * |
| 140 | * Others: |
| 141 | ********************************************************************************/ |
| 142 | int downloader_readline (char * buffer) |
| 143 | { |
| 144 | /* |
| 145 | * If console_buffer isn't 0-length the user will be prompted to modify |
| 146 | * it instead of entering it from scratch as desired. |
| 147 | */ |
| 148 | buffer[0] = '\0'; |
| 149 | |
| 150 | return downloader_readline_into_buffer(buffer); |
| 151 | } |
| 152 | |
| 153 | /******************************************************************************* |
| 154 | * Function:do_downloader |
| 155 | * Description: |
| 156 | * Parameters: |
| 157 | * Input: |
| 158 | * |
| 159 | * Output: |
| 160 | * |
| 161 | * Returns: |
| 162 | * |
| 163 | * |
| 164 | * Others: |
| 165 | ********************************************************************************/ |
| 166 | int do_downloader(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 167 | { |
| 168 | int ret = 0; |
| 169 | int type = 0; |
| 170 | char ack[20] = {0}; |
| 171 | printf( "[sys_entry]: do downloader\n"); |
| 172 | |
| 173 | ret = read_partition_and_check(); |
| 174 | if( ret != 0 ) |
| 175 | { |
| 176 | printf( "[sys_entry]: read_partition error...\n"); |
| 177 | } |
| 178 | |
| 179 | type = read_boot_flashtype(); |
| 180 | if(type == IF_TYPE_NOR) |
| 181 | { |
| 182 | ret = get_nor_null_slice_flag(&null_slice_flag); |
| 183 | if(ret) |
| 184 | { |
| 185 | printf ("nor flash read null_slice_flag error.\n"); |
| 186 | return 1; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | downloader_serial_init(); |
| 191 | printf ("### downloader : serial init success \n"); |
| 192 | |
| 193 | /*sync*/ |
| 194 | while(1) |
| 195 | { |
| 196 | #if CONFIG_USB_DL |
| 197 | downloader_serial_read(tsp_console_buffer,512); |
| 198 | #else |
| 199 | downloader_serial_read(tsp_console_buffer,1); |
| 200 | #endif |
| 201 | if(tsp_console_buffer[0]==0x5a) |
| 202 | { |
| 203 | tsp_console_buffer[0]=0xa7; /*ack*/ |
| 204 | downloader_serial_write(tsp_console_buffer,1); |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /*run commands*/ |
| 210 | while(1) |
| 211 | { |
| 212 | downloader_readline(tsp_console_buffer); |
| 213 | ret = run_command (tsp_console_buffer, 0); |
| 214 | if(ret == -2) |
| 215 | { |
| 216 | sprintf(ack,"UNKNOWN COMMAND"); |
| 217 | downloader_serial_write(ack, strlen(ack)+1); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | U_BOOT_CMD( |
| 225 | downloader, 1, 0, do_downloader, |
| 226 | "Perform ZIXC TSP downloader", |
| 227 | "" |
| 228 | ); |
| 229 | |