1 /* 2 * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0 5 */ 6 7 #include <blk.h> 8 9 #include "rkflash_debug.h" 10 #include "rkflash_blk.h" 11 12 void rkflash_print_hex(char *s, void *buf, u32 width, u32 len) 13 { 14 u32 i, j; 15 char *p8 = (char *)buf; 16 short *p16 = (short *)buf; 17 u32 *p32 = (u32 *)buf; 18 19 j = 0; 20 for (i = 0; i < len; i++) { 21 if (j == 0) 22 printf("%s 0x%x:", s, i * width); 23 24 if (width == 4) 25 printf("%x ", p32[i]); 26 else if (width == 2) 27 printf("%x ", p16[i]); 28 else 29 printf("%02x ", p8[i]); 30 if (++j >= 16) { 31 j = 0; 32 printf("\n"); 33 } 34 } 35 printf("\n"); 36 } 37 38 #if (BLK_STRESS_TEST_EN) 39 #define max_test_sector 64 40 static u8 pwrite[max_test_sector * 512]; 41 static u8 pread[max_test_sector * 512]; 42 static u32 *pwrite32; 43 void blk_stress_test(struct udevice *udev) 44 { 45 struct blk_desc *block_dev = dev_get_uclass_platdata(udev); 46 struct rkflash_info *priv = dev_get_priv(udev->parent); 47 u16 i, j, loop = 0; 48 u32 test_end_lba; 49 u32 test_lba = 0; 50 u16 test_sec_count = 1; 51 u16 print_flag; 52 53 if (!priv || !block_dev) { 54 printf("device unknown\n"); 55 return; 56 } 57 58 test_end_lba = priv->density; 59 pwrite32 = (u32 *)pwrite; 60 for (i = 0; i < (max_test_sector * 512); i++) 61 pwrite[i] = i; 62 for (loop = 0; loop < 10; loop++) { 63 printf("---------Test loop = %d---------\n", loop); 64 printf("---------Test ftl write---------\n"); 65 test_sec_count = 1; 66 printf("test_end_lba = %x\n", test_end_lba); 67 printf("test_lba = %x\n", test_lba); 68 for (test_lba = 0; 69 (test_lba + test_sec_count) < test_end_lba;) { 70 pwrite32[0] = test_lba; 71 blk_dwrite(block_dev, test_lba, test_sec_count, pwrite); 72 blk_dread(block_dev, test_lba, test_sec_count, pread); 73 for (j = 0; j < test_sec_count * 512; j++) { 74 if (pwrite[j] != pread[j]) { 75 rkflash_print_hex("w:", 76 pwrite, 77 4, 78 test_sec_count * 128); 79 rkflash_print_hex("r:", 80 pread, 81 4, 82 test_sec_count * 128); 83 printf("r=%x, n=%x, w=%x, r=%x\n", 84 test_lba, 85 j, 86 pwrite[j], 87 pread[j]); 88 while (1) 89 ; 90 break; 91 } 92 } 93 print_flag = test_lba & 0x1FF; 94 if (print_flag < test_sec_count) 95 printf("test_lba = %x\n", test_lba); 96 test_lba += test_sec_count; 97 test_sec_count++; 98 if (test_sec_count > max_test_sector) 99 test_sec_count = 1; 100 } 101 printf("---------Test ftl check---------\n"); 102 103 test_sec_count = 1; 104 for (test_lba = 0; 105 (test_lba + test_sec_count) < test_end_lba;) { 106 pwrite32[0] = test_lba; 107 blk_dread(block_dev, test_lba, test_sec_count, pread); 108 print_flag = test_lba & 0x7FF; 109 if (print_flag < test_sec_count) 110 printf("test_lba = %x\n", test_lba); 111 112 for (j = 0; j < test_sec_count * 512; j++) { 113 if (pwrite[j] != pread[j]) { 114 printf("r=%x, n=%x, w=%x, r=%x\n", 115 test_lba, 116 j, 117 pwrite[j], 118 pread[j]); 119 /* while(1); */ 120 break; 121 } 122 } 123 test_lba += test_sec_count; 124 test_sec_count++; 125 if (test_sec_count > max_test_sector) 126 test_sec_count = 1; 127 } 128 } 129 printf("---------Test end---------\n"); 130 /* while(1); */ 131 } 132 #endif 133 134 void rkflash_test(struct udevice *udev) 135 { 136 #if (BLK_STRESS_TEST_EN) 137 blk_stress_test(udev); 138 #endif 139 } 140 141