111077SCurtis.Dunham@arm.com# The backing store supporting the memories in the system has changed
211077SCurtis.Dunham@arm.com# in that it is now stored globally per address range. As a result the
311077SCurtis.Dunham@arm.com# actual storage is separate from the memory controllers themselves.
411077SCurtis.Dunham@arm.comdef upgrader(cpt):
511077SCurtis.Dunham@arm.com    for sec in cpt.sections():
611077SCurtis.Dunham@arm.com        import re
711077SCurtis.Dunham@arm.com        # Search for a physical memory
811077SCurtis.Dunham@arm.com        if re.search('.*sys.*\.physmem$', sec):
911077SCurtis.Dunham@arm.com            # Add the number of stores attribute to the global physmem
1011077SCurtis.Dunham@arm.com            cpt.set(sec, 'nbr_of_stores', '1')
1111077SCurtis.Dunham@arm.com
1211077SCurtis.Dunham@arm.com            # Get the filename and size as this is moving to the
1311077SCurtis.Dunham@arm.com            # specific backing store
1411077SCurtis.Dunham@arm.com            mem_filename = cpt.get(sec, 'filename')
1511077SCurtis.Dunham@arm.com            mem_size = cpt.get(sec, '_size')
1611077SCurtis.Dunham@arm.com            cpt.remove_option(sec, 'filename')
1711077SCurtis.Dunham@arm.com            cpt.remove_option(sec, '_size')
1811077SCurtis.Dunham@arm.com
1911077SCurtis.Dunham@arm.com            # Get the name so that we can create the new section
2011077SCurtis.Dunham@arm.com            system_name = str(sec).split('.')[0]
2111077SCurtis.Dunham@arm.com            section_name = system_name + '.physmem.store0'
2211077SCurtis.Dunham@arm.com            cpt.add_section(section_name)
2311077SCurtis.Dunham@arm.com            cpt.set(section_name, 'store_id', '0')
2411077SCurtis.Dunham@arm.com            cpt.set(section_name, 'range_size', mem_size)
2511077SCurtis.Dunham@arm.com            cpt.set(section_name, 'filename', mem_filename)
2611077SCurtis.Dunham@arm.com        elif re.search('.*sys.*\.\w*mem$', sec):
2711077SCurtis.Dunham@arm.com            # Due to the lack of information about a start address,
2811077SCurtis.Dunham@arm.com            # this migration only works if there is a single memory in
2911077SCurtis.Dunham@arm.com            # the system, thus starting at 0
3011077SCurtis.Dunham@arm.com            raise ValueError("more than one memory detected (" + sec + ")")
3111077SCurtis.Dunham@arm.com
3211077SCurtis.Dunham@arm.comlegacy_version = 2
33