@@ -265,13 +265,37 @@ def cmd_flash(self, args: str):
265265 logger .info ("No bmap file found, flashing in non-sparse mode" )
266266 flash_func (file_size = file_size , file_offset = 0 , offset = offset )
267267
268+ def flash_mtd_section (
269+ self ,
270+ fb_addr : int ,
271+ path : str ,
272+ file_offset : int ,
273+ file_size : int ,
274+ padding : int ,
275+ part : str ,
276+ dest_offset : int ,
277+ dest_size : int ,
278+ ):
279+ fast = self .fast
280+
281+ logger .debug (
282+ f"erasing flash area part { part } offset 0x{ dest_offset :x} size 0x{ dest_size :x} ..."
283+ )
284+ fast .oem_run (f"mtd erase { part } 0x{ dest_offset :x} 0x{ dest_size :x} " )
285+
286+ logger .info (
287+ f"flashing file { path } range start 0x{ file_offset :x} size 0x{ file_size } "
288+ )
289+ fast .download_section (path , file_offset , file_size , padding = padding )
290+ fast .oem_run (
291+ f"mtd write { part } 0x{ fb_addr :x} 0x{ dest_offset :x} 0x{ dest_size :x} "
292+ )
293+
268294 def flash_mtd (
269295 self , path : str , offset : int , part : str , file_size : int , file_offset : int = 0
270296 ):
271297 logger .info ("Flashing to MTD device..." )
272298
273- fast = self .fast
274-
275299 fb_addr = int (self .request_env ("fb-addr" ), 0 )
276300 fb_size = self .fb_size
277301 eraseblk_size = int (self .request_env ("eraseblk-size" ), 0 )
@@ -290,17 +314,8 @@ def flash_mtd(
290314 flash_size = file_size
291315
292316 if flash_size <= fb_size :
293- logger .debug (
294- f"erasing flash area part { part } offset 0x{ offset :x} size 0x{ flash_size :x} ..."
295- )
296- fast .oem_run (f"mtd erase { part } 0x{ offset :x} 0x{ flash_size :x} " )
297-
298- logger .info (
299- f"flashing file { path } range start 0x{ file_offset :x} size 0x{ file_size } "
300- )
301- fast .download_section (path , file_offset , file_size , padding = padding )
302- fast .oem_run (
303- f"mtd write { part } 0x{ fb_addr :x} 0x{ offset :x} 0x{ flash_size :x} "
317+ self .flash_mtd_section (
318+ fb_addr , path , file_offset , file_size , padding , part , offset , flash_size
304319 )
305320 return
306321
@@ -314,33 +329,45 @@ def flash_mtd(
314329 remainder = flash_size % fb_size
315330
316331 for i in range (nchunks ):
317- logger .info (f"downloading section { i + 1 } /{ nchunks } " )
318- fast .download_section (path , file_offset + i * fb_size , fb_size )
319-
320- target_offset = offset + i * fb_size
321- logger .info (
322- f"erasing flash area offset 0x{ target_offset :x} size 0x{ fb_size :x} ..."
332+ logger .info (f"flashing section { i + 1 } /{ nchunks } " )
333+ self .flash_mtd_section (
334+ fb_addr ,
335+ path ,
336+ file_offset + i * fb_size ,
337+ fb_size ,
338+ 0 ,
339+ part ,
340+ offset * i * fb_size ,
341+ fb_size ,
323342 )
324- fast .oem_run (f"mtd erase { part } { target_offset :x} { fb_size :x} " )
325343
326- logger .info (f"writing section { i + 1 } /{ nchunks } " )
327- fast .oem_run (
328- f"mtd write { part } 0x{ fb_addr :x} 0x{ target_offset :x} 0x{ fb_size :x} "
344+ if remainder > 0 :
345+ logger .info ("flashing remainder" )
346+ self .flash_mtd_section (
347+ fb_addr ,
348+ path ,
349+ file_offset + nchunks * fb_size ,
350+ remainder ,
351+ 0 ,
352+ part ,
353+ offset + nchunks * fb_size ,
354+ remainder ,
329355 )
330356
331- if remainder > 0 :
332- logger .info ("downloading remainder" )
333- fast .download_section (path , file_offset + nchunks * fb_size , remainder )
357+ def flash_mmc_section (
358+ self ,
359+ fb_addr : int ,
360+ path : str ,
361+ file_offset : int ,
362+ file_size : int ,
363+ dest_offset : int ,
364+ dest_size : int ,
365+ ):
366+ fast = self .fast
334367
335- target_offset = offset + nchunks * fb_size
336- logger .info (
337- f"erasing flash area offset 0x{ target_offset } size 0x{ remainder :x} ..."
338- )
339- fast .oem_run (f"mtd erase { part } { target_offset :x} { remainder :x} " )
368+ fast .download_section (path , file_offset , file_size )
340369
341- fast .oem_run (
342- f"mtd write { part } 0x{ fb_addr :x} 0x{ target_offset :x} 0x{ remainder :x} "
343- )
370+ fast .oem_run (f"mmc write 0x{ fb_addr :x} 0x{ dest_offset :x} 0x{ dest_size :x} " )
344371
345372 def flash_mmc (
346373 self ,
@@ -393,10 +420,13 @@ def flash_mmc(
393420 logger .info (
394421 f"flashing file { path } range start 0x{ file_offset :x} size 0x{ file_size :x} "
395422 )
396- fast .download_section (path , file_offset , file_size )
397-
398- fast .oem_run (
399- f"mmc write 0x{ fb_addr :x} 0x{ part_start + offset_lba :x} 0x{ file_size_lba :x} "
423+ self .flash_mmc_section (
424+ fb_addr ,
425+ path ,
426+ file_offset ,
427+ file_size ,
428+ part_start + offset_lba ,
429+ file_size_lba ,
400430 )
401431 return
402432
@@ -408,23 +438,25 @@ def flash_mmc(
408438 for i in range (nchunks ):
409439 logger .info (f"flashing section { i + 1 } /{ nchunks } " )
410440 target_offset = part_start + offset_lba + i * fb_size_lba
411- fast .download_section (
412- path , file_offset + i * fb_size_aligned , fb_size_aligned
413- )
414-
415- fast .oem_run (
416- f"mmc write 0x{ fb_addr :x} 0x{ target_offset :x} 0x{ fb_size_lba :x} "
441+ self .flash_mmc_section (
442+ fb_addr ,
443+ path ,
444+ file_offset + i * fb_size_aligned ,
445+ fb_size_aligned ,
446+ target_offset ,
447+ fb_size_lba ,
417448 )
418449
419450 if remainder > 0 :
420451 logger .info ("flashing remainder" )
421452 target_offset = part_start + offset_lba + nchunks * fb_size_lba
422- fast .download_section (
423- path , file_offset + nchunks * fb_size_aligned , remainder
424- )
425-
426- fast .oem_run (
427- f"mmc write 0x{ fb_addr :x} 0x{ target_offset :x} 0x{ remainder_lba :x} "
453+ self .flash_mmc_section (
454+ fb_addr ,
455+ path ,
456+ file_offset + nchunks * fb_size_aligned ,
457+ remainder ,
458+ target_offset ,
459+ remainder_lba ,
428460 )
429461
430462 def run (self , cmds : list ):
0 commit comments