blob: e751a3bd36a8e212d19a6587c33c34043a3dd4a2 [file] [log] [blame]
Love Kumar40598bd2024-01-19 19:55:50 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5import random
6import re
Simon Glassfb916372025-02-09 09:07:15 -07007import utils
Love Kumar40598bd2024-01-19 19:55:50 +05308
9"""
10Note: This test doesn't rely on boardenv_* configuration values but it can
11change the test behavior. To test MMC file system cases (fat32, ext2, ext4),
12MMC device should be formatted and valid partitions should be created for
13different file system, otherwise it may leads to failure. This test will be
14skipped if the MMC device is not detected.
15
16For example:
17
18# Setup env__mmc_device_test_skip to not skipping the test. By default, its
19# value is set to True. Set it to False to run all tests for MMC device.
20env__mmc_device_test_skip = False
Love Kumar57624672024-11-12 14:27:56 +053021
22# Setup env__mmc_device to set the supported mmc modes to be tested
23env__mmc_device {
24 'mmc_modes': ['MMC_LEGACY', 'SD_HS'],
25}
26
Love Kumar40598bd2024-01-19 19:55:50 +053027"""
28
29mmc_set_up = False
30controllers = 0
31devices = {}
Love Kumar57624672024-11-12 14:27:56 +053032mmc_modes_name = []
33mmc_modes = []
34
Simon Glass32701112025-02-09 09:07:17 -070035def setup_mmc_modes(ubman):
Love Kumar57624672024-11-12 14:27:56 +053036 global mmc_modes, mmc_modes_name
Simon Glass32701112025-02-09 09:07:17 -070037 f = ubman.config.env.get('env__mmc_device', None)
Love Kumar57624672024-11-12 14:27:56 +053038 if f:
39 mmc_modes_name = f.get('mmc_modes', None)
40
41 # Set mmc mode to default mode (legacy), if speed mode config isn't enabled
Simon Glass32701112025-02-09 09:07:17 -070042 if ubman.config.buildconfig.get('config_mmc_speed_mode_set', 'n') != 'y':
Love Kumar57624672024-11-12 14:27:56 +053043 mmc_modes = [0]
44 return
45
46 if mmc_modes_name:
Simon Glass32701112025-02-09 09:07:17 -070047 mmc_help = ubman.run_command('mmc -help')
Love Kumar57624672024-11-12 14:27:56 +053048 m = re.search(r"\[MMC_LEGACY(.*\n.+])", mmc_help)
49 modes = [
50 x.strip()
51 for x in m.group()
52 .replace('\n', '')
53 .replace('[', '')
54 .replace(']', '')
55 .split(',')
56 ]
57
58 for mode in mmc_modes_name:
59 mmc_modes += [modes.index(mode)]
60 else:
61 # Set mmc mode to default mode (legacy), if it is not defined in env
62 mmc_modes = [0]
Love Kumar40598bd2024-01-19 19:55:50 +053063
Simon Glassddba5202025-02-09 09:07:14 -070064def setup_mmc(ubman):
65 if ubman.config.env.get('env__mmc_device_test_skip', True):
Love Kumar40598bd2024-01-19 19:55:50 +053066 pytest.skip('MMC device test is not enabled')
67
Simon Glassddba5202025-02-09 09:07:14 -070068 setup_mmc_modes(ubman)
Love Kumar57624672024-11-12 14:27:56 +053069
Love Kumar40598bd2024-01-19 19:55:50 +053070@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -070071def test_mmc_list(ubman):
72 setup_mmc(ubman)
73 output = ubman.run_command('mmc list')
Love Kumar40598bd2024-01-19 19:55:50 +053074 if 'No MMC device available' in output:
75 pytest.skip('No SD/MMC/eMMC controller available')
76
77 if 'Card did not respond to voltage select' in output:
78 pytest.skip('No SD/MMC card present')
79
80 array = output.split()
81 global devices
82 global controllers
83 controllers = int(len(array) / 2)
84 for x in range(0, controllers):
85 y = x * 2
86 devices[x] = {}
87 devices[x]['name'] = array[y]
88
89 global mmc_set_up
90 mmc_set_up = True
91
92@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -070093def test_mmc_dev(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +053094 if not mmc_set_up:
95 pytest.skip('No SD/MMC/eMMC controller available')
96
97 fail = 0
98 for x in range(0, controllers):
99 devices[x]['detected'] = 'yes'
Love Kumar40598bd2024-01-19 19:55:50 +0530100
Love Kumar57624672024-11-12 14:27:56 +0530101 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700102 output = ubman.run_command('mmc dev %d 0 %d' % x, y)
Love Kumar40598bd2024-01-19 19:55:50 +0530103
Love Kumar57624672024-11-12 14:27:56 +0530104 if 'Card did not respond to voltage select' in output:
105 fail = 1
106 devices[x]['detected'] = 'no'
Love Kumar40598bd2024-01-19 19:55:50 +0530107
Love Kumar57624672024-11-12 14:27:56 +0530108 if 'no mmc device at slot' in output:
109 devices[x]['detected'] = 'no'
Love Kumar40598bd2024-01-19 19:55:50 +0530110
Love Kumar57624672024-11-12 14:27:56 +0530111 if 'MMC: no card present' in output:
112 devices[x]['detected'] = 'no'
113
114 if fail:
115 pytest.fail('Card not present')
Love Kumar40598bd2024-01-19 19:55:50 +0530116
117@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -0700118def test_mmcinfo(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530119 if not mmc_set_up:
120 pytest.skip('No SD/MMC/eMMC controller available')
121
122 for x in range(0, controllers):
123 if devices[x]['detected'] == 'yes':
Love Kumar57624672024-11-12 14:27:56 +0530124 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700125 ubman.run_command('mmc dev %d 0 %d' % x, y)
126 output = ubman.run_command('mmcinfo')
Love Kumar57624672024-11-12 14:27:56 +0530127 if 'busy timeout' in output:
128 pytest.skip('No SD/MMC/eMMC device present')
Love Kumar40598bd2024-01-19 19:55:50 +0530129
Love Kumar57624672024-11-12 14:27:56 +0530130 assert mmc_modes_name[mmc_modes.index(y)] in output
131
132 obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
133 try:
134 capacity = float(obj.groups()[0])
135 print(capacity)
136 devices[x]['capacity'] = capacity
137 print('Capacity of dev %d is: %g GiB' % (x, capacity))
138 except ValueError:
139 pytest.fail('MMC capacity not recognized')
Love Kumar40598bd2024-01-19 19:55:50 +0530140
141@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -0700142def test_mmc_info(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530143 if not mmc_set_up:
144 pytest.skip('No SD/MMC/eMMC controller available')
145
146 for x in range(0, controllers):
147 if devices[x]['detected'] == 'yes':
Love Kumar57624672024-11-12 14:27:56 +0530148 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700149 ubman.run_command('mmc dev %d 0 %d' % x, y)
Love Kumar40598bd2024-01-19 19:55:50 +0530150
Simon Glassddba5202025-02-09 09:07:14 -0700151 output = ubman.run_command('mmc info')
Love Kumar57624672024-11-12 14:27:56 +0530152 assert mmc_modes_name[mmc_modes.index(y)] in output
Love Kumar40598bd2024-01-19 19:55:50 +0530153
Love Kumar57624672024-11-12 14:27:56 +0530154 obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
155 try:
156 capacity = float(obj.groups()[0])
157 print(capacity)
158 if devices[x]['capacity'] != capacity:
159 pytest.fail("MMC capacity doesn't match mmcinfo")
Love Kumar40598bd2024-01-19 19:55:50 +0530160
Love Kumar57624672024-11-12 14:27:56 +0530161 except ValueError:
162 pytest.fail('MMC capacity not recognized')
Love Kumar40598bd2024-01-19 19:55:50 +0530163
164@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -0700165def test_mmc_rescan(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530166 if not mmc_set_up:
167 pytest.skip('No SD/MMC/eMMC controller available')
168
169 if not devices:
170 pytest.skip('No devices detected')
171
172 for x in range(0, controllers):
173 if devices[x]['detected'] == 'yes':
Love Kumar57624672024-11-12 14:27:56 +0530174 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700175 ubman.run_command('mmc dev %d 0 %d' % x, y)
176 output = ubman.run_command('mmc rescan')
Love Kumar57624672024-11-12 14:27:56 +0530177 if output:
178 pytest.fail('mmc rescan has something to check')
Simon Glassddba5202025-02-09 09:07:14 -0700179 output = ubman.run_command('echo $?')
Love Kumar57624672024-11-12 14:27:56 +0530180 assert output.endswith('0')
Love Kumar40598bd2024-01-19 19:55:50 +0530181
182@pytest.mark.buildconfigspec('cmd_mmc')
Simon Glassddba5202025-02-09 09:07:14 -0700183def test_mmc_part(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530184 if not mmc_set_up:
185 pytest.skip('No SD/MMC/eMMC controller available')
186
187 if not devices:
188 pytest.skip('No devices detected')
189
190 for x in range(0, controllers):
191 if devices[x]['detected'] == 'yes':
Simon Glassddba5202025-02-09 09:07:14 -0700192 ubman.run_command('mmc dev %d' % x)
193 output = ubman.run_command('mmc part')
Love Kumar40598bd2024-01-19 19:55:50 +0530194
195 lines = output.split('\n')
196 part_fat = []
Love Kumar1ff2ed82024-11-12 14:27:27 +0530197 part_ext2 = []
198 part_ext4 = []
Love Kumar40598bd2024-01-19 19:55:50 +0530199 for line in lines:
200 obj = re.search(
201 r'(\d)\s+\d+\s+\d+\s+\w+\d+\w+-\d+\s+(\d+\w+)', line)
202 if obj:
203 part_id = int(obj.groups()[0])
204 part_type = obj.groups()[1]
205 print('part_id:%d, part_type:%s' % (part_id, part_type))
206
207 if part_type in ['0c', '0b', '0e']:
208 print('Fat detected')
209 part_fat.append(part_id)
210 elif part_type == '83':
Love Kumar1ff2ed82024-11-12 14:27:27 +0530211 print('ext(2/4) detected')
Simon Glassddba5202025-02-09 09:07:14 -0700212 output = ubman.run_command(
Love Kumar1ff2ed82024-11-12 14:27:27 +0530213 'fstype mmc %d:%d' % x, part_id
214 )
215 if 'ext2' in output:
216 part_ext2.append(part_id)
217 elif 'ext4' in output:
218 part_ext4.append(part_id)
Love Kumar40598bd2024-01-19 19:55:50 +0530219 else:
220 pytest.fail('Unsupported Filesystem on device %d' % x)
Love Kumar1ff2ed82024-11-12 14:27:27 +0530221 devices[x]['ext4'] = part_ext4
222 devices[x]['ext2'] = part_ext2
Love Kumar40598bd2024-01-19 19:55:50 +0530223 devices[x]['fat'] = part_fat
224
Love Kumar1ff2ed82024-11-12 14:27:27 +0530225 if not part_ext2 and not part_ext4 and not part_fat:
Love Kumar40598bd2024-01-19 19:55:50 +0530226 pytest.fail('No partition detected on device %d' % x)
227
228@pytest.mark.buildconfigspec('cmd_mmc')
229@pytest.mark.buildconfigspec('cmd_fat')
Simon Glassddba5202025-02-09 09:07:14 -0700230def test_mmc_fatls_fatinfo(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530231 if not mmc_set_up:
232 pytest.skip('No SD/MMC/eMMC controller available')
233
234 if not devices:
235 pytest.skip('No devices detected')
236
237 part_detect = 0
238 fs = 'fat'
239 for x in range(0, controllers):
240 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530241 try:
242 partitions = devices[x][fs]
243 except:
244 print('No %s table on this device' % fs.upper())
245 continue
246
247 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530248 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700249 ubman.run_command('mmc dev %d %d %d' % x, part, y)
250 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530251 'fatls mmc %d:%s' % (x, part))
252 if 'Unrecognized filesystem type' in output:
253 partitions.remove(part)
254 pytest.fail('Unrecognized filesystem')
Love Kumar40598bd2024-01-19 19:55:50 +0530255
Love Kumar57624672024-11-12 14:27:56 +0530256 if not re.search(r'\d file\(s\), \d dir\(s\)', output):
257 pytest.fail('%s read failed on device %d' % (fs.upper, x))
Simon Glassddba5202025-02-09 09:07:14 -0700258 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530259 'fatinfo mmc %d:%s' % (x, part))
260 string = 'Filesystem: %s' % fs.upper
261 if re.search(string, output):
262 pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
263 part_detect = 1
Love Kumar40598bd2024-01-19 19:55:50 +0530264
265 if not part_detect:
266 pytest.skip('No %s partition detected' % fs.upper())
267
268
269@pytest.mark.buildconfigspec('cmd_mmc')
270@pytest.mark.buildconfigspec('cmd_fat')
271@pytest.mark.buildconfigspec('cmd_memory')
Simon Glassddba5202025-02-09 09:07:14 -0700272def test_mmc_fatload_fatwrite(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530273 if not mmc_set_up:
274 pytest.skip('No SD/MMC/eMMC controller available')
275
276 if not devices:
277 pytest.skip('No devices detected')
278
279 part_detect = 0
280 fs = 'fat'
281 for x in range(0, controllers):
282 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530283 try:
284 partitions = devices[x][fs]
285 except:
286 print('No %s table on this device' % fs.upper())
287 continue
288
289 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530290 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700291 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530292 part_detect = 1
Simon Glassfb916372025-02-09 09:07:15 -0700293 addr = utils.find_ram_base(ubman)
Love Kumar57624672024-11-12 14:27:56 +0530294 devices[x]['addr_%d' % part] = addr
295 size = random.randint(4, 1 * 1024 * 1024)
296 devices[x]['size_%d' % part] = size
297 # count CRC32
Simon Glassddba5202025-02-09 09:07:14 -0700298 output = ubman.run_command('crc32 %x %x' % (addr, size))
Love Kumar57624672024-11-12 14:27:56 +0530299 m = re.search('==> (.+?)', output)
300 if not m:
301 pytest.fail('CRC32 failed')
302 expected_crc32 = m.group(1)
303 devices[x]['expected_crc32_%d' % part] = expected_crc32
304 # do write
305 file = '%s_%d' % ('uboot_test', size)
306 devices[x]['file_%d' % part] = file
Simon Glassddba5202025-02-09 09:07:14 -0700307 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530308 '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
309 )
310 assert 'Unable to write' not in output
311 assert 'Error' not in output
312 assert 'overflow' not in output
313 expected_text = '%d bytes written' % size
314 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530315
Love Kumar57624672024-11-12 14:27:56 +0530316 alignment = int(
Simon Glassddba5202025-02-09 09:07:14 -0700317 ubman.config.buildconfig.get(
Love Kumar57624672024-11-12 14:27:56 +0530318 'config_sys_cacheline_size', 128
319 )
320 )
321 offset = random.randrange(alignment, 1024, alignment)
Simon Glassddba5202025-02-09 09:07:14 -0700322 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530323 '%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
Love Kumar40598bd2024-01-19 19:55:50 +0530324 )
Love Kumar57624672024-11-12 14:27:56 +0530325 assert 'Invalid FAT entry' not in output
326 assert 'Unable to read file' not in output
327 assert 'Misaligned buffer address' not in output
328 expected_text = '%d bytes read' % size
329 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530330
Simon Glassddba5202025-02-09 09:07:14 -0700331 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530332 'crc32 %x $filesize' % (addr + offset)
333 )
334 assert expected_crc32 in output
Love Kumar40598bd2024-01-19 19:55:50 +0530335
336 if not part_detect:
337 pytest.skip('No %s partition detected' % fs.upper())
338
339@pytest.mark.buildconfigspec('cmd_mmc')
340@pytest.mark.buildconfigspec('cmd_ext4')
Simon Glassddba5202025-02-09 09:07:14 -0700341def test_mmc_ext4ls(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530342 if not mmc_set_up:
343 pytest.skip('No SD/MMC/eMMC controller available')
344
345 if not devices:
346 pytest.skip('No devices detected')
347
348 part_detect = 0
349 fs = 'ext4'
350 for x in range(0, controllers):
351 if devices[x]['detected'] == 'yes':
352 try:
353 partitions = devices[x][fs]
354 except:
355 print('No %s table on this device' % fs.upper())
356 continue
357
Love Kumar40598bd2024-01-19 19:55:50 +0530358 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530359 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700360 ubman.run_command('mmc dev %d %d %d' % x, part, y)
361 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530362 '%sls mmc %d:%s' % (fs, x, part)
363 )
364 if 'Unrecognized filesystem type' in output:
365 partitions.remove(part)
366 pytest.fail('Unrecognized filesystem')
367 part_detect = 1
Love Kumar40598bd2024-01-19 19:55:50 +0530368
369 if not part_detect:
370 pytest.skip('No %s partition detected' % fs.upper())
371
372@pytest.mark.buildconfigspec('cmd_mmc')
373@pytest.mark.buildconfigspec('cmd_ext4')
374@pytest.mark.buildconfigspec('ext4_write')
375@pytest.mark.buildconfigspec('cmd_memory')
Simon Glassddba5202025-02-09 09:07:14 -0700376def test_mmc_ext4load_ext4write(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530377 if not mmc_set_up:
378 pytest.skip('No SD/MMC/eMMC controller available')
379
380 if not devices:
381 pytest.skip('No devices detected')
382
383 part_detect = 0
384 fs = 'ext4'
385 for x in range(0, controllers):
386 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530387 try:
388 partitions = devices[x][fs]
389 except:
390 print('No %s table on this device' % fs.upper())
391 continue
392
393 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530394 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700395 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530396 part_detect = 1
Simon Glassfb916372025-02-09 09:07:15 -0700397 addr = utils.find_ram_base(ubman)
Love Kumar57624672024-11-12 14:27:56 +0530398 devices[x]['addr_%d' % part] = addr
399 size = random.randint(4, 1 * 1024 * 1024)
400 devices[x]['size_%d' % part] = size
401 # count CRC32
Simon Glassddba5202025-02-09 09:07:14 -0700402 output = ubman.run_command('crc32 %x %x' % (addr, size))
Love Kumar57624672024-11-12 14:27:56 +0530403 m = re.search('==> (.+?)', output)
404 if not m:
405 pytest.fail('CRC32 failed')
406 expected_crc32 = m.group(1)
407 devices[x]['expected_crc32_%d' % part] = expected_crc32
Love Kumar40598bd2024-01-19 19:55:50 +0530408
Love Kumar57624672024-11-12 14:27:56 +0530409 # do write
410 file = '%s_%d' % ('uboot_test', size)
411 devices[x]['file_%d' % part] = file
Simon Glassddba5202025-02-09 09:07:14 -0700412 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530413 '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
414 )
415 assert 'Unable to write' not in output
416 assert 'Error' not in output
417 assert 'overflow' not in output
418 expected_text = '%d bytes written' % size
419 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530420
Love Kumar57624672024-11-12 14:27:56 +0530421 offset = random.randrange(128, 1024, 128)
Simon Glassddba5202025-02-09 09:07:14 -0700422 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530423 '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
424 )
425 expected_text = '%d bytes read' % size
426 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530427
Simon Glassddba5202025-02-09 09:07:14 -0700428 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530429 'crc32 %x $filesize' % (addr + offset)
430 )
431 assert expected_crc32 in output
Love Kumar40598bd2024-01-19 19:55:50 +0530432
433 if not part_detect:
434 pytest.skip('No %s partition detected' % fs.upper())
435
436@pytest.mark.buildconfigspec('cmd_mmc')
437@pytest.mark.buildconfigspec('cmd_ext2')
Simon Glassddba5202025-02-09 09:07:14 -0700438def test_mmc_ext2ls(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530439 if not mmc_set_up:
440 pytest.skip('No SD/MMC/eMMC controller available')
441
442 if not devices:
443 pytest.skip('No devices detected')
444
445 part_detect = 0
446 fs = 'ext2'
447 for x in range(0, controllers):
448 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530449 try:
450 partitions = devices[x][fs]
451 except:
452 print('No %s table on this device' % fs.upper())
453 continue
454
455 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530456 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700457 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530458 part_detect = 1
Simon Glassddba5202025-02-09 09:07:14 -0700459 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530460 '%sls mmc %d:%s' % (fs, x, part)
461 )
462 if 'Unrecognized filesystem type' in output:
463 partitions.remove(part)
464 pytest.fail('Unrecognized filesystem')
465 part_detect = 1
Love Kumar40598bd2024-01-19 19:55:50 +0530466
467 if not part_detect:
468 pytest.skip('No %s partition detected' % fs.upper())
469
470@pytest.mark.buildconfigspec('cmd_mmc')
471@pytest.mark.buildconfigspec('cmd_ext2')
472@pytest.mark.buildconfigspec('cmd_ext4')
473@pytest.mark.buildconfigspec('ext4_write')
474@pytest.mark.buildconfigspec('cmd_memory')
Simon Glassddba5202025-02-09 09:07:14 -0700475def test_mmc_ext2load(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530476 if not mmc_set_up:
477 pytest.skip('No SD/MMC/eMMC controller available')
478
479 if not devices:
480 pytest.skip('No devices detected')
481
482 part_detect = 0
483 fs = 'ext2'
484 for x in range(0, controllers):
485 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530486 try:
487 partitions = devices[x][fs]
488 except:
489 print('No %s table on this device' % fs.upper())
490 continue
491
492 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530493 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700494 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530495 part_detect = 1
496 addr = devices[x]['addr_%d' % part]
497 size = devices[x]['size_%d' % part]
498 expected_crc32 = devices[x]['expected_crc32_%d' % part]
499 file = devices[x]['file_%d' % part]
Love Kumar40598bd2024-01-19 19:55:50 +0530500
Love Kumar57624672024-11-12 14:27:56 +0530501 offset = random.randrange(128, 1024, 128)
Simon Glassddba5202025-02-09 09:07:14 -0700502 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530503 '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
504 )
505 expected_text = '%d bytes read' % size
506 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530507
Simon Glassddba5202025-02-09 09:07:14 -0700508 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530509 'crc32 %x $filesize' % (addr + offset)
510 )
511 assert expected_crc32 in output
Love Kumar40598bd2024-01-19 19:55:50 +0530512
513 if not part_detect:
514 pytest.skip('No %s partition detected' % fs.upper())
515
516@pytest.mark.buildconfigspec('cmd_mmc')
517@pytest.mark.buildconfigspec('cmd_fs_generic')
Simon Glassddba5202025-02-09 09:07:14 -0700518def test_mmc_ls(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530519 if not mmc_set_up:
520 pytest.skip('No SD/MMC/eMMC controller available')
521
522 if not devices:
523 pytest.skip('No devices detected')
524
525 part_detect = 0
526 for x in range(0, controllers):
527 if devices[x]['detected'] == 'yes':
Love Kumar1ff2ed82024-11-12 14:27:27 +0530528 for fs in ['fat', 'ext4', 'ext2']:
Love Kumar40598bd2024-01-19 19:55:50 +0530529 try:
530 partitions = devices[x][fs]
531 except:
532 print('No %s table on this device' % fs.upper())
533 continue
534
535 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530536 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700537 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530538 part_detect = 1
Simon Glassddba5202025-02-09 09:07:14 -0700539 output = ubman.run_command('ls mmc %d:%s' % (x, part))
Love Kumar57624672024-11-12 14:27:56 +0530540 if re.search(r'No \w+ table on this device', output):
541 pytest.fail(
542 '%s: Partition table not found %d' % (fs.upper(), x)
543 )
Love Kumar40598bd2024-01-19 19:55:50 +0530544
545 if not part_detect:
546 pytest.skip('No partition detected')
547
548@pytest.mark.buildconfigspec('cmd_mmc')
549@pytest.mark.buildconfigspec('cmd_fs_generic')
Simon Glassddba5202025-02-09 09:07:14 -0700550def test_mmc_load(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530551 if not mmc_set_up:
552 pytest.skip('No SD/MMC/eMMC controller available')
553
554 if not devices:
555 pytest.skip('No devices detected')
556
557 part_detect = 0
558 for x in range(0, controllers):
559 if devices[x]['detected'] == 'yes':
Love Kumar1ff2ed82024-11-12 14:27:27 +0530560 for fs in ['fat', 'ext4', 'ext2']:
Love Kumar40598bd2024-01-19 19:55:50 +0530561 try:
562 partitions = devices[x][fs]
563 except:
564 print('No %s table on this device' % fs.upper())
565 continue
566
567 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530568 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700569 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530570 part_detect = 1
571 addr = devices[x]['addr_%d' % part]
572 size = devices[x]['size_%d' % part]
573 expected_crc32 = devices[x]['expected_crc32_%d' % part]
574 file = devices[x]['file_%d' % part]
Love Kumar40598bd2024-01-19 19:55:50 +0530575
Love Kumar57624672024-11-12 14:27:56 +0530576 offset = random.randrange(128, 1024, 128)
Simon Glassddba5202025-02-09 09:07:14 -0700577 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530578 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
579 )
580 expected_text = '%d bytes read' % size
581 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530582
Simon Glassddba5202025-02-09 09:07:14 -0700583 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530584 'crc32 %x $filesize' % (addr + offset)
585 )
586 assert expected_crc32 in output
Love Kumar40598bd2024-01-19 19:55:50 +0530587
588 if not part_detect:
589 pytest.skip('No partition detected')
590
591@pytest.mark.buildconfigspec('cmd_mmc')
592@pytest.mark.buildconfigspec('cmd_fs_generic')
Simon Glassddba5202025-02-09 09:07:14 -0700593def test_mmc_save(ubman):
Love Kumar40598bd2024-01-19 19:55:50 +0530594 if not mmc_set_up:
595 pytest.skip('No SD/MMC/eMMC controller available')
596
597 if not devices:
598 pytest.skip('No devices detected')
599
600 part_detect = 0
601 for x in range(0, controllers):
602 if devices[x]['detected'] == 'yes':
Love Kumar1ff2ed82024-11-12 14:27:27 +0530603 for fs in ['fat', 'ext4', 'ext2']:
Love Kumar40598bd2024-01-19 19:55:50 +0530604 try:
605 partitions = devices[x][fs]
606 except:
607 print('No %s table on this device' % fs.upper())
608 continue
609
610 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530611 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700612 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530613 part_detect = 1
614 addr = devices[x]['addr_%d' % part]
615 size = 0
616 file = devices[x]['file_%d' % part]
Love Kumar40598bd2024-01-19 19:55:50 +0530617
Love Kumar57624672024-11-12 14:27:56 +0530618 offset = random.randrange(128, 1024, 128)
Simon Glassddba5202025-02-09 09:07:14 -0700619 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530620 'save mmc %d:%s %x /%s %d'
621 % (x, part, addr + offset, file, size)
622 )
623 expected_text = '%d bytes written' % size
624 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530625
626 if not part_detect:
627 pytest.skip('No partition detected')
628
629@pytest.mark.buildconfigspec('cmd_mmc')
630@pytest.mark.buildconfigspec('cmd_fat')
631@pytest.mark.buildconfigspec('cmd_memory')
Simon Glassddba5202025-02-09 09:07:14 -0700632def test_mmc_fat_read_write_files(ubman):
633 test_mmc_list(ubman)
634 test_mmc_dev(ubman)
635 test_mmcinfo(ubman)
636 test_mmc_part(ubman)
Love Kumar40598bd2024-01-19 19:55:50 +0530637 if not mmc_set_up:
638 pytest.skip('No SD/MMC/eMMC controller available')
639
640 if not devices:
641 pytest.skip('No devices detected')
642
643 part_detect = 0
644 fs = 'fat'
645
646 # Number of files to be written/read in MMC card
647 num_files = 100
648
649 for x in range(0, controllers):
650 if devices[x]['detected'] == 'yes':
Love Kumar40598bd2024-01-19 19:55:50 +0530651 try:
652 partitions = devices[x][fs]
653 except:
654 print('No %s table on this device' % fs.upper())
655 continue
656
657 for part in partitions:
Love Kumar57624672024-11-12 14:27:56 +0530658 for y in mmc_modes:
Simon Glassddba5202025-02-09 09:07:14 -0700659 ubman.run_command('mmc dev %d %d %d' % x, part, y)
Love Kumar57624672024-11-12 14:27:56 +0530660 part_detect = 1
Simon Glassfb916372025-02-09 09:07:15 -0700661 addr = utils.find_ram_base(ubman)
Love Kumar57624672024-11-12 14:27:56 +0530662 count_f = 0
663 addr_l = []
664 size_l = []
665 file_l = []
666 crc32_l = []
667 offset_l = []
668 addr_l.append(addr)
Love Kumar40598bd2024-01-19 19:55:50 +0530669
Love Kumar57624672024-11-12 14:27:56 +0530670 while count_f < num_files:
671 size_l.append(random.randint(4, 1 * 1024 * 1024))
Love Kumar40598bd2024-01-19 19:55:50 +0530672
Love Kumar57624672024-11-12 14:27:56 +0530673 # CRC32 count
Simon Glassddba5202025-02-09 09:07:14 -0700674 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530675 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
676 )
677 m = re.search('==> (.+?)', output)
678 if not m:
679 pytest.fail('CRC32 failed')
680 crc32_l.append(m.group(1))
Love Kumar40598bd2024-01-19 19:55:50 +0530681
Love Kumar57624672024-11-12 14:27:56 +0530682 # Write operation
683 file_l.append(
684 '%s_%d_%d' % ('uboot_test', count_f, size_l[count_f])
Love Kumar40598bd2024-01-19 19:55:50 +0530685 )
Simon Glassddba5202025-02-09 09:07:14 -0700686 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530687 '%swrite mmc %d:%s %x %s %x'
688 % (
689 fs,
690 x,
691 part,
692 addr_l[count_f],
693 file_l[count_f],
694 size_l[count_f],
695 )
696 )
697 assert 'Unable to write' not in output
698 assert 'Error' not in output
699 assert 'overflow' not in output
700 expected_text = '%d bytes written' % size_l[count_f]
701 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530702
Love Kumar57624672024-11-12 14:27:56 +0530703 addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
704 count_f += 1
Love Kumar40598bd2024-01-19 19:55:50 +0530705
Love Kumar57624672024-11-12 14:27:56 +0530706 count_f = 0
707 while count_f < num_files:
708 alignment = int(
Simon Glassddba5202025-02-09 09:07:14 -0700709 ubman.config.buildconfig.get(
Love Kumar57624672024-11-12 14:27:56 +0530710 'config_sys_cacheline_size', 128
711 )
Love Kumar40598bd2024-01-19 19:55:50 +0530712 )
Love Kumar57624672024-11-12 14:27:56 +0530713 offset_l.append(random.randrange(alignment, 1024, alignment))
Love Kumar40598bd2024-01-19 19:55:50 +0530714
Love Kumar57624672024-11-12 14:27:56 +0530715 # Read operation
Simon Glassddba5202025-02-09 09:07:14 -0700716 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530717 '%sload mmc %d:%s %x %s'
718 % (
719 fs,
720 x,
721 part,
722 addr_l[count_f] + offset_l[count_f],
723 file_l[count_f],
724 )
Love Kumar40598bd2024-01-19 19:55:50 +0530725 )
Love Kumar57624672024-11-12 14:27:56 +0530726 assert 'Invalid FAT entry' not in output
727 assert 'Unable to read file' not in output
728 assert 'Misaligned buffer address' not in output
729 expected_text = '%d bytes read' % size_l[count_f]
730 assert expected_text in output
Love Kumar40598bd2024-01-19 19:55:50 +0530731
Simon Glassddba5202025-02-09 09:07:14 -0700732 output = ubman.run_command(
Love Kumar57624672024-11-12 14:27:56 +0530733 'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
734 )
735 assert crc32_l[count_f] in output
Love Kumar40598bd2024-01-19 19:55:50 +0530736
Love Kumar57624672024-11-12 14:27:56 +0530737 count_f += 1
Love Kumar40598bd2024-01-19 19:55:50 +0530738
739 if not part_detect:
740 pytest.skip('No %s partition detected' % fs.upper())