@@ -142,7 +142,7 @@ def get_espidf():
142142board = None
143143skip_partition_resize = False
144144partition_size = None
145- flash_size = 8
145+ flash_size = 0
146146oct_flash = False
147147
148148
@@ -174,27 +174,59 @@ def parse_args(extra_args, lv_cflags, brd):
174174if arg .startswith ('BOARD_VARIANT' ):
175175raise RuntimeError (f'BOARD_VARIANT not supported by "{ board } "' )
176176
177- if board == 'ESP32_GENERIC_S3' :
178- esp_argParser = ArgumentParser (prefix_chars = '-' )
177+ if board_variant in ('SPIRAM' ,'SPIRAM_OCT' ):
178+ if board == 'ESP32_GENERIC_S2' :
179+ esp_argParser = ArgumentParser (prefix_chars = '-' )
180+
181+ esp_argParser .add_argument (
182+ '--flash-size' ,
183+ dest = 'flash_size' ,
184+ help = 'flash size' ,
185+ choices = (2 ,4 ),
186+ default = 4 ,
187+ type = int ,
188+ action = 'store'
189+ )
190+ esp_args ,extra_args = esp_argParser .parse_known_args (extra_args )
191+ flash_size = esp_args .flash_size
192+
193+ if board == 'ESP32_GENERIC' :
194+ esp_argParser = ArgumentParser (prefix_chars = '-' )
195+
196+ esp_argParser .add_argument (
197+ '--flash-size' ,
198+ dest = 'flash_size' ,
199+ help = 'flash size' ,
200+ choices = (4 ,8 ,16 ),
201+ default = 4 ,
202+ type = int ,
203+ action = 'store'
204+ )
205+ esp_args ,extra_args = esp_argParser .parse_known_args (extra_args )
206+ flash_size = esp_args .flash_size
179207
180- esp_argParser .add_argument (
181- '--octal-flash' ,
182- help = 'octal spi flash' ,
183- dest = 'oct_flash' ,
184- action = 'store_true'
185- )
208+ elif board == 'ESP32_GENERIC_S3' :
209+ esp_argParser = ArgumentParser (prefix_chars = '-' )
186210
187- esp_argParser .add_argument (
188- '--flash-size' ,
189- dest = 'flash_size' ,
190- help = 'flash size' ,
191- default = 8 ,
192- type = int ,
193- action = 'store'
194- )
195- esp_args ,extra_args = esp_argParser .parse_known_args (extra_args )
196- flash_size = esp_args .flash_size
197- oct_flash = esp_args .oct_flash
211+ esp_argParser .add_argument (
212+ '--octal-flash' ,
213+ help = 'octal spi flash' ,
214+ dest = 'oct_flash' ,
215+ action = 'store_true'
216+ )
217+
218+ esp_argParser .add_argument (
219+ '--flash-size' ,
220+ dest = 'flash_size' ,
221+ help = 'flash size' ,
222+ choices = (4 ,8 ,16 ,32 ),
223+ default = 8 ,
224+ type = int ,
225+ action = 'store'
226+ )
227+ esp_args ,extra_args = esp_argParser .parse_known_args (extra_args )
228+ flash_size = esp_args .flash_size
229+ oct_flash = esp_args .oct_flash
198230
199231esp_argParser = ArgumentParser (prefix_chars = '-' )
200232
@@ -466,7 +498,10 @@ def submodules():
466498def compile ():# NOQA
467499env = setup_idf_environ ()
468500
469- if board == 'ESP32_GENERIC_S3' :
501+ if (
502+ board in ('ESP32_GENERIC' ,'ESP32_GENERIC_S2' ,'ESP32_GENERIC_S3' )and
503+ board_variant in ('SPIRAM' ,'SPIRAM_OCT' )
504+ ):
470505base_config = [
471506'CONFIG_ESPTOOLPY_FLASHMODE_QIO=y' ,
472507'CONFIG_ESPTOOLPY_FLASHFREQ_80M=y' ,
@@ -480,15 +515,17 @@ def compile(): # NOQA
480515'CONFIG_ESPTOOLPY_FLASHSIZE_8MB=n' ,
481516'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=n' ,
482517'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n' ,
483- 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB.csv"'
518+ 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME='
519+ '"partitions-4MiB.csv"'
484520 ])
485521elif flash_size == 8 :
486522base_config .extend ([
487523'CONFIG_ESPTOOLPY_FLASHSIZE_4MB=n' ,
488524'CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y' ,
489525'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=n' ,
490526'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n' ,
491- 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv"'
527+ 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME='
528+ '"partitions-8MiB.csv"'
492529 ])
493530
494531elif flash_size == 16 :
@@ -497,37 +534,70 @@ def compile(): # NOQA
497534'CONFIG_ESPTOOLPY_FLASHSIZE_8MB=n' ,
498535'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y' ,
499536'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n' ,
500- 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16MiB.csv"'
537+ 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME='
538+ '"partitions-16MiB.csv"'
501539 ])
502540if flash_size == 32 :
503541base_config .extend ([
504542'CONFIG_ESPTOOLPY_FLASHSIZE_4MB=n' ,
505543'CONFIG_ESPTOOLPY_FLASHSIZE_8MB=n' ,
506544'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=n' ,
507545'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=y' ,
508- 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-32MiB.csv"'
546+ 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME='
547+ '"partitions-32MiB.csv"'
509548 ])
510549else :
511- base_config = [
512- 'CONFIG_ESPTOOLPY_FLASHSIZE_4MB=n' ,
513- 'CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y' ,
514- 'CONFIG_ESPTOOLPY_FLASHSIZE_16MB=n' ,
515- 'CONFIG_ESPTOOLPY_FLASHSIZE_32MB=n' ,
516- 'CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv"'
517- ]
550+ raise RuntimeError ('unsupported flash size' )
518551
519- if oct_flash :
520- base_config [0 ]= 'CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y'
521- base_config .append ('CONFIG_ESPTOOLPY_OCT_FLASH=y' )
552+ if board == 'ESP32_GENERIC_S3' :
553+ if oct_flash and flash_size in (16 ,32 ):
554+ if flash_size == 32 :
555+ base_config [0 ]= 'CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y'
522556
523- base_config = ' \n ' . join ( base_config )
557+ base_config . append ( 'CONFIG_ESPTOOLPY_OCT_FLASH=y' )
524558
525- sdkconfig_board_path = (
526- 'lib/micropython/ports/esp32/'
527- 'boards/ESP32_GENERIC_S3/sdkconfig.board'
528- )
529- with open (sdkconfig_board_path ,'w' )as f :
530- f .write (base_config + '\n ' )
559+ base_config = '\n ' .join (base_config )
560+
561+ if board in ('ESP32_GENERIC' ,'ESP32_GENERIC_S3' ):
562+ mpconfigboard_cmake_path = (
563+ 'lib/micropython/ports/esp32/boards/'
564+ f'{ board } /mpconfigboard.cmake'
565+ )
566+
567+ with open (mpconfigboard_cmake_path ,'rb' )as f :
568+ data = f .read ().decode ('utf-8' )
569+
570+ if f'boards/{ board } /sdkconfig.board' not in data :
571+ if board == 'ESP32_GENERIC' :
572+ data = data .replace (
573+ 'boards/sdkconfig.spiram' ,
574+ 'boards/sdkconfig.spiram\n '
575+ 'boards/ESP32_GENERIC/sdkconfig.board'
576+ )
577+ else :
578+ data = data .replace (
579+ 'boards/sdkconfig.spiram_ex' ,
580+ 'boards/sdkconfig.spiram_ex\n '
581+ 'boards/ESP32_GENERIC_S2/sdkconfig.board'
582+ )
583+
584+ with open (mpconfigboard_cmake_path ,'wb' )as f :
585+ f .write (data .encode ('utf-8' ))
586+
587+ sdkconfig_spiram_path = (
588+ 'lib/micropython/ports/esp32/boards/'
589+ f'{ board } /sdkconfig.board'
590+ )
591+ with open (sdkconfig_spiram_path ,'w' )as f :
592+ f .write (base_config )
593+
594+ else :
595+ sdkconfig_board_path = (
596+ 'lib/micropython/ports/esp32/'
597+ f'boards/{ board } /sdkconfig.board'
598+ )
599+ with open (sdkconfig_board_path ,'w' )as f :
600+ f .write (base_config + '\n ' )
531601
532602if board in ('ESP32_GENERIC_S2' ,'ESP32_GENERIC_S3' ):
533603