yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 |
|
| 2 | /******************************************************************************* |
| 3 | * Copyright (C) 2016, ZIXC Corporation.
|
| 4 | * |
| 5 | * File Name:cmd_compat_write.c
|
| 6 | * File Mark: |
| 7 | * Description: |
| 8 | * Others: |
| 9 | * Version: 1.0 |
| 10 | * Author: zangxiaofeng |
| 11 | * Date: 2013-3-13 |
| 12 | * History 1: |
| 13 | * Date: |
| 14 | * Version: |
| 15 | * Author: |
| 16 | * Modification: |
| 17 | * History 2: |
| 18 | ********************************************************************************/ |
| 19 | |
| 20 | |
| 21 | /**************************************************************************** |
| 22 | * Include files |
| 23 | ****************************************************************************/ |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <net.h> |
| 27 | #include <jffs2/load_kernel.h> |
| 28 | #include "downloader_config.h" |
| 29 | #include "downloader_nand.h"
|
| 30 | #include "downloader_serial.h"
|
| 31 | #include "errno.h"
|
| 32 |
|
| 33 | extern int downloader_readline (char * buffer);
|
| 34 | extern char *tsp_console_buffer;
|
| 35 | /******************************************************************************* |
| 36 | * Function:do_ram_write
|
| 37 | * Description: |
| 38 | * Parameters: |
| 39 | * Input: |
| 40 | * |
| 41 | * Output: |
| 42 | * |
| 43 | * Returns: |
| 44 | * |
| 45 | * |
| 46 | * Others: |
| 47 | ********************************************************************************/ |
| 48 | int do_ram_write( unsigned int offset, unsigned int size)
|
| 49 | { |
| 50 | char *ack = tsp_console_buffer;
|
| 51 | unsigned int addr = 0; |
| 52 | unsigned int leftWriteLength = 0; |
| 53 | unsigned int curWriteLength = 0;
|
| 54 | #ifdef CONFIG_LOAD_CRC
|
| 55 | unsigned long crc = 0; |
| 56 | unsigned long crc1 = 0;
|
| 57 | #endif
|
| 58 |
|
| 59 | addr = offset ;
|
| 60 | |
| 61 | if(size == 0)
|
| 62 | { |
| 63 | sprintf(ack,"FAIL INVALID LENGTH"); |
| 64 | downloader_serial_write(ack, strlen(ack)+1); |
| 65 | return EINVAL;
|
| 66 | }
|
| 67 | leftWriteLength = size; |
| 68 | |
| 69 | while(leftWriteLength>0) |
| 70 | { |
| 71 | curWriteLength = MIN(leftWriteLength,DOWNLOADER_BUFFER_SIZE); |
| 72 | #ifdef CONFIG_LOAD_CRC |
| 73 | sprintf(ack,"DATACRC %08x",curWriteLength);
|
| 74 | #else |
| 75 | sprintf(ack,"DATA %08x",curWriteLength);
|
| 76 | #endif |
| 77 | downloader_serial_write(ack, strlen(ack)+1); |
| 78 | #ifdef CONFIG_LOAD_CRC
|
| 79 |
|
| 80 | downloader_serial_read_actuallen((char *)DOWNLOADER_BUFFER_BASE, curWriteLength+4);
|
| 81 | memcpy(( char *)addr,(char *)DOWNLOADER_BUFFER_BASE, curWriteLength+4 );
|
| 82 |
|
| 83 |
|
| 84 | crc = crc32(0,(unsigned char*)addr,curWriteLength); |
| 85 | memcpy((unsigned char *)(&crc1),(unsigned char*)(addr+curWriteLength),4); |
| 86 | if(crc != crc1) |
| 87 | { |
| 88 | sprintf(ack,"FAIL CRC ERROR"); |
| 89 | downloader_serial_write(ack, strlen(ack)+1); |
| 90 | return ENOSYS; /* Function not implemented */ |
| 91 | } |
| 92 | #else
|
| 93 |
|
| 94 |
|
| 95 | downloader_serial_read_actuallen((char *)DOWNLOADER_BUFFER_BASE, curWriteLength);
|
| 96 | memcpy(( char *)addr,(char *)DOWNLOADER_BUFFER_BASE, curWriteLength );
|
| 97 |
|
| 98 | #endif |
| 99 | leftWriteLength -= curWriteLength; |
| 100 | addr += curWriteLength;
|
| 101 | } |
| 102 | |
| 103 | sprintf(ack,"OKAY"); |
| 104 | downloader_serial_write(ack, strlen(ack)+1); |
| 105 | return 0; |
| 106 | |
| 107 | }
|
| 108 |
|
| 109 | /******************************************************************************* |
| 110 | * Function:do_ram_read |
| 111 | * Description: |
| 112 | * Parameters: |
| 113 | * Input: |
| 114 | * |
| 115 | * Output: |
| 116 | * |
| 117 | * Returns: |
| 118 | * |
| 119 | * |
| 120 | * Others: |
| 121 | ********************************************************************************/ |
| 122 | int do_ram_read(unsigned int offset, unsigned int size)
|
| 123 | { |
| 124 | char *rx_buffer = tsp_console_buffer;
|
| 125 | char *ack = tsp_console_buffer;
|
| 126 | unsigned int addr = 0; |
| 127 | unsigned int leftReadLength = 0; |
| 128 | unsigned int curReadLength = 0;
|
| 129 |
|
| 130 | addr = offset ;
|
| 131 |
|
| 132 | |
| 133 | if((size == 0)||(size > CONFIG_SYS_SDRAM_SIZE)) |
| 134 | { |
| 135 | sprintf(ack,"FAIL INVALID LENGTH"); |
| 136 | downloader_serial_write(ack, strlen(ack)+1); |
| 137 | return EINVAL; /* Invalid argument */ |
| 138 | } |
| 139 | leftReadLength = size; |
| 140 | |
| 141 | sprintf(ack,"DATA %08x",MIN(size,DOWNLOADER_BUFFER_SIZE));
|
| 142 | downloader_serial_write(ack, strlen(ack)+1); |
| 143 | while(leftReadLength>0) |
| 144 | { |
| 145 | curReadLength = MIN(leftReadLength,DOWNLOADER_BUFFER_SIZE); |
| 146 | downloader_readline(rx_buffer); |
| 147 | if(memcmp(rx_buffer,"OKAY",4) == 0) |
| 148 | {
|
| 149 | memcpy((char *)DOWNLOADER_BUFFER_BASE, (const char *)addr, curReadLength );
|
| 150 | downloader_serial_write_actuallen((const char *)DOWNLOADER_BUFFER_BASE, curReadLength);
|
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | sprintf(ack,"FAIL COMMAND ERROR"); |
| 155 | downloader_serial_write(ack, strlen(ack)+1); |
| 156 | return EBADRQC; /* Invalid request code */ |
| 157 | } |
| 158 | leftReadLength -= curReadLength; |
| 159 | addr += curReadLength; |
| 160 | } |
| 161 | |
| 162 | downloader_readline(rx_buffer); |
| 163 | if(memcmp(rx_buffer,"OKAY",4) == 0) |
| 164 | { |
| 165 | return 0; |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | sprintf(ack,"FAIL COMMAND ERROR"); |
| 170 | downloader_serial_write(ack, strlen(ack)+1); |
| 171 | return EBADRQC; /* Invalid request code */ |
| 172 | } |
| 173 | |
| 174 | } |