yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2016, ZIXC Corporation. |
| 3 | * |
| 4 | * File Name:cmd_compat_write.c |
| 5 | * File Mark: |
| 6 | * Description: |
| 7 | * Others: |
| 8 | * Version: 1.0 |
| 9 | * Author: zangxiaofeng |
| 10 | * Date: 2013-3-13 |
| 11 | * History 1: |
| 12 | * Date: |
| 13 | * Version: |
| 14 | * Author: |
| 15 | * Modification: |
| 16 | * History 2: |
| 17 | ********************************************************************************/ |
| 18 | |
| 19 | |
| 20 | /**************************************************************************** |
| 21 | * Include files |
| 22 | ****************************************************************************/ |
| 23 | #include <common.h> |
| 24 | #include <command.h> |
| 25 | #include <net.h> |
| 26 | #include <jffs2/load_kernel.h> |
| 27 | #include "downloader_config.h" |
| 28 | #include "downloader_nand.h" |
| 29 | #include "downloader_serial.h" |
| 30 | #include "errno.h" |
| 31 | #include <boot_mode.h> |
| 32 | /**************************************************************************** |
| 33 | * Global Function Prototypes |
| 34 | ****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Function:do_compat_write |
| 38 | * Description: |
| 39 | * Parameters: |
| 40 | * Input: |
| 41 | * |
| 42 | * Output: |
| 43 | * |
| 44 | * Returns: |
| 45 | * |
| 46 | * |
| 47 | * Others: |
| 48 | ********************************************************************************/ |
| 49 | int do_compat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 50 | { |
| 51 | partition_entry_t *part = NULL; |
| 52 | char *par = NULL; |
| 53 | char ack[64]={0}; |
| 54 | unsigned int offset = 0; |
| 55 | unsigned int size = 0; |
| 56 | unsigned int ret = 0; |
| 57 | |
| 58 | if(argc<4) |
| 59 | { |
| 60 | return cmd_usage(cmdtp); |
| 61 | } |
| 62 | |
| 63 | par = argv[1]; |
| 64 | offset = (unsigned int)simple_strtoul (argv[2], NULL, 16); |
| 65 | size = (unsigned int)simple_strtoul (argv[3], NULL, 16); |
| 66 | part = downloader_get_part_dl(par); |
| 67 | if(part == NULL) |
| 68 | { |
| 69 | sprintf(ack,"FAIL INVALID PARTITION TYPE"); |
| 70 | downloader_serial_write(ack, strlen(ack)+1); |
| 71 | return -1; |
| 72 | } |
| 73 | |
| 74 | if((read_boot_flashtype() == IF_TYPE_NOR) |
| 75 | && (strcmp((const char *)part->part_type,"nand") == 0)) |
| 76 | { |
| 77 | ret = do_nor_write(part, par, offset,size); |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | if(strcmp((const char *)part->part_type,"nand") == 0) |
| 82 | { |
| 83 | ret = do_nand_write(part, par, offset, size); |
| 84 | return ret; |
| 85 | } |
| 86 | else if (strcmp((const char *)part->part_type,"fs") == 0) |
| 87 | { |
| 88 | ret = do_yaffs_write(part, par, offset, size); |
| 89 | return ret; |
| 90 | } |
| 91 | else if (strcmp((const char *)part->part_type,"ddr") == 0) |
| 92 | { |
| 93 | ret = do_ram_write(offset, size); |
| 94 | return ret; |
| 95 | } |
| 96 | else if (strcmp((const char *)part->part_type,"raw") == 0) |
| 97 | { |
| 98 | ret = do_raw_write(offset, size); |
| 99 | return ret; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | sprintf(ack,"FAIL INVALID PARTITION TYPE"); |
| 104 | downloader_serial_write(ack, strlen(ack)+1); |
| 105 | return -1; |
| 106 | } |
| 107 | } |
| 108 | U_BOOT_CMD( |
| 109 | compat_write, CONFIG_SYS_MAXARGS, 0, do_compat_write, |
| 110 | "download: compat_write [partition][offset][size]", |
| 111 | "" |
| 112 | ); |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |