yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2016, ZIXC Corporation. |
| 3 | * |
| 4 | * File Name:cmd_compat_read.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 <boot_mode.h> |
| 31 | |
| 32 | #include "errno.h" |
| 33 | /**************************************************************************** |
| 34 | * Global Function Prototypes |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | |
| 38 | /******************************************************************************* |
| 39 | * Function:do_compat_read |
| 40 | * Description: |
| 41 | * Parameters: |
| 42 | * Input: |
| 43 | * |
| 44 | * Output: |
| 45 | * |
| 46 | * Returns: |
| 47 | * |
| 48 | * |
| 49 | * Others: |
| 50 | ********************************************************************************/ |
| 51 | int do_compat_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 52 | { |
| 53 | partition_entry_t *part = NULL; |
| 54 | char *par = NULL; |
| 55 | char ack[64]={0}; |
| 56 | unsigned int offset = 0; |
| 57 | unsigned int size = 0; |
| 58 | unsigned int ret = 0; |
| 59 | |
| 60 | if(argc<4) |
| 61 | { |
| 62 | return cmd_usage(cmdtp); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | par = argv[1]; |
| 67 | offset = (unsigned int)simple_strtoul (argv[2], NULL, 16); |
| 68 | size = (unsigned int)simple_strtoul (argv[3], NULL, 16); |
| 69 | part = downloader_get_part(par); |
| 70 | if(part == NULL) |
| 71 | { |
| 72 | sprintf(ack,"FAIL INVALID PARTITION TYPE"); |
| 73 | downloader_serial_write(ack, strlen(ack)+1); |
| 74 | return -1; |
| 75 | } |
| 76 | |
| 77 | if((read_boot_flashtype() == IF_TYPE_NOR) |
| 78 | && (strcmp((const char *)part->part_type,"nand") == 0)) |
| 79 | |
| 80 | { |
| 81 | ret = do_nor_read(part, par, offset,size); |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | if(strcmp((const char *)part->part_type,"nand") == 0) |
| 87 | { |
| 88 | ret = do_nand_read(part, par, offset, size); |
| 89 | return ret; |
| 90 | } |
| 91 | else if (strcmp((const char *)part->part_type,"fs") == 0) |
| 92 | { |
| 93 | ret = do_yaffs_read(part, par, offset, size); |
| 94 | return ret; |
| 95 | } |
| 96 | else if (strcmp((const char *)part->part_type,"ddr") == 0) |
| 97 | { |
| 98 | ret = do_ram_read(offset, size); |
| 99 | return ret; |
| 100 | } |
| 101 | else if (strcmp((const char *)part->part_type,"raw") == 0) |
| 102 | { |
| 103 | ret = do_raw_read(offset, size); |
| 104 | return ret; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | sprintf(ack,"FAIL INVALID PARTITION TYPE"); |
| 109 | downloader_serial_write(ack, strlen(ack)+1); |
| 110 | return -1; |
| 111 | } |
| 112 | } |
| 113 | U_BOOT_CMD( |
| 114 | compat_read, CONFIG_SYS_MAXARGS, 0, do_compat_read, |
| 115 | "upload: compat_read [partition][offset][size]", |
| 116 | "" |
| 117 | ); |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |