Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the command 'mtk_board_flash_write' have issue? #11

Open
yunhai20082008 opened this issue Feb 4, 2024 · 0 comments
Open

Does the command 'mtk_board_flash_write' have issue? #11

yunhai20082008 opened this issue Feb 4, 2024 · 0 comments

Comments

@yunhai20082008
Copy link

yunhai20082008 commented Feb 4, 2024

int hex2int(char ch)  
{  
    if(isdigit(ch))  
        return ch - 48;  
  
    if( ch < 'A' || (ch > 'F' && ch < 'a') || ch > 'f' )  
        return -1;  
  
    if(isalpha(ch))  
        return isupper(ch) ? ch - 55 : ch - 87;  
  
    return -1;  
}  


static int do_testflash(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]){
	if ( argc <= 3 )
		return cmd_usage(cmdtp);
	
	void *flash;
	flash = mtk_board_get_flash_dev();

	ulong offset=simple_strtoul(argv[2], NULL, 16);

	uint8_t *buf ={0x01};
	int ret;
	
	if ( strcmp(argv[1], "r") == 0 ){
		printf("testflash read  ...\n");
		ulong length=simple_strtoul(argv[3], NULL, 16);
		ret = mtk_board_flash_read(flash, offset, length, buf);
		print_buffer(offset, buf, 1, length, 16);

		int i;
		for(i=0; i<length; i++){
			printf("buf_r[%d]= %d \n", i,buf[i]);
		}
		// unmap_sysmem(buf);
		return 0;
	}
	else if ( strcmp(argv[1], "w") == 0 ) {
		printf("testflash write ...\n");
		size_t length = strlen(argv[3]);
		if  (length % 2 == 1 ) {
			return cmd_usage(cmdtp);
		}
		printf("length= %d \n", length);
		int i,m,n;
		int k=0;
		uint8_t j;
		for(i=0; i<length; i=i+2){
			m = hex2int(argv[3][i]);
			n = hex2int(argv[3][i+1]);
			if ( m == -1 || n == -1 ) {
				return cmd_usage(cmdtp);
				k=1;
				break;
			}
			j = ( ( m << 4 ) + n );
			printf("combine=%d \n", j);
			buf[i>>1]=j;
		}
		
		length = length>>1;
		for(i=0; i<length; i++){
			printf("buf[%d]= %d \n", i,buf[i]);
		}

		if ( k == 0 ){
			ret = mtk_board_flash_write(flash, offset, length, buf);
			printf("ret=%d \n", ret);
		}
		printf("ret=%d \n", ret);
		return 0;
	}
	else
	{
		return cmd_usage(cmdtp);
	}
}

U_BOOT_CMD(testflash, 4, 0, do_testflash,
	"MTK testflash utility",
	"testflash <r|w> <offset> <len>\n"
	"type    - upgrade file type\n"
	"          r|w      - Read or Write\n"
	"          offset   - First offset\n"
	"          len/hex  - Length/HEX\n"
);

testflash r works fine.

testflash w works not fine;
usually,it works fine when the content of flash has not been written
but if the content of the flash has been written ,Even if the power is replugged,it works maybe not fine

@yunhai20082008 yunhai20082008 changed the title Is the command 'mtk_board_flash_write' has issue? Does the command 'mtk_board_flash_write' has issue? Feb 4, 2024
@yunhai20082008 yunhai20082008 changed the title Does the command 'mtk_board_flash_write' has issue? Does the command 'mtk_board_flash_write' have issue? Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant