John Edward Broadbent | aa7e21d | 2021-09-02 17:31:45 -0700 | [diff] [blame] | 1 | # The offsets of the partitions that change when Hoth is enabled |
| 2 | # From the device tree, in kB |
| 3 | FLASH_IMAGE_DESC_OFFSET:npcm7xx:hoth = "${@960 if FLASH_SIZE == '65536' else 7232}" |
| 4 | FLASH_HOTH_UPDATE_OFFSET:npcm7xx:hoth = "${@1024 if FLASH_SIZE == '65536' else 31744}" |
| 5 | FLASH_HOTH_MAILBOX_OFFSET:npcm7xx:hoth = "${@65472 if FLASH_SIZE == '65536' else 7168}" |
| 6 | unset FLASH_UBOOT_ENV_OFFSET |
| 7 | |
| 8 | python do_generate_static:append() { |
| 9 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 10 | 'image-hoth-update'), |
| 11 | int(d.getVar('FLASH_HOTH_UPDATE_OFFSET', True)), |
| 12 | int(d.getVar('FLASH_SIZE', True))) |
| 13 | } |
| 14 | do_generate_static[depends] += "virtual/hoth-firmware:do_deploy" |
| 15 | |
| 16 | python do_generate_layout () { |
| 17 | import time |
| 18 | import json |
| 19 | |
| 20 | def convertPart(name, startKb, endKb, static=False, wp=False, persist=False): |
| 21 | regionTypes = [] |
| 22 | extraAttrs = {} |
| 23 | if static: |
| 24 | regionTypes.append('STATIC') |
| 25 | if wp: |
| 26 | regionTypes.append('WRITE_PROTECTED') |
| 27 | if persist: |
| 28 | regionTypes.append('PERSISTENT') |
| 29 | if name == 'hoth_mailbox': |
| 30 | regionTypes.append('MAILBOX') |
| 31 | extraAttrs['mailbox_length'] = 1024 |
| 32 | |
| 33 | start = int(startKb) * 1024 |
| 34 | end = int(endKb) * 1024 |
| 35 | |
| 36 | return { |
| 37 | 'name': name, |
| 38 | 'offset': start, |
| 39 | 'length': end - start, |
| 40 | 'region_type': regionTypes, |
| 41 | **extraAttrs, |
| 42 | } |
| 43 | |
| 44 | # TODO: make this work for Aspeed too |
| 45 | region = [ |
| 46 | convertPart( |
| 47 | 'u_boot', |
| 48 | d.getVar('FLASH_UBOOT_OFFSET'), |
| 49 | d.getVar('FLASH_IMAGE_DESC_OFFSET'), |
| 50 | static=True, |
| 51 | wp=True), |
| 52 | convertPart( |
| 53 | 'image_descriptor', |
| 54 | d.getVar('FLASH_IMAGE_DESC_OFFSET'), |
| 55 | d.getVar('FLASH_HOTH_UPDATE_OFFSET'), |
| 56 | static=True, |
| 57 | wp=True), |
| 58 | convertPart( |
| 59 | 'hoth_update', |
| 60 | d.getVar('FLASH_HOTH_UPDATE_OFFSET'), |
| 61 | d.getVar('FLASH_KERNEL_OFFSET')), |
| 62 | convertPart( |
| 63 | 'kernel', |
| 64 | d.getVar('FLASH_KERNEL_OFFSET'), |
| 65 | d.getVar('FLASH_ROFS_OFFSET'), |
| 66 | static=True, |
| 67 | wp=True), |
| 68 | convertPart( |
| 69 | 'rofs', |
| 70 | d.getVar('FLASH_ROFS_OFFSET'), |
| 71 | d.getVar('FLASH_RWFS_OFFSET'), |
| 72 | static=True, |
| 73 | wp=True), |
| 74 | convertPart( |
| 75 | 'rwfs', |
| 76 | d.getVar('FLASH_RWFS_OFFSET'), |
| 77 | d.getVar('FLASH_HOTH_MAILBOX_OFFSET'), |
| 78 | persist=True), |
| 79 | convertPart( |
| 80 | 'hoth_mailbox', |
| 81 | d.getVar('FLASH_HOTH_MAILBOX_OFFSET'), |
| 82 | d.getVar('FLASH_SIZE')), |
| 83 | ] if d.getVar('FLASH_SIZE') == '65536' else [ |
| 84 | convertPart( |
| 85 | 'u_boot', |
| 86 | d.getVar('FLASH_UBOOT_OFFSET'), |
| 87 | d.getVar('FLASH_KERNEL_OFFSET'), |
| 88 | static=True, |
| 89 | wp=True), |
| 90 | convertPart( |
| 91 | 'kernel', |
| 92 | d.getVar('FLASH_KERNEL_OFFSET'), |
| 93 | d.getVar('FLASH_HOTH_MAILBOX_OFFSET'), |
| 94 | static=True, |
| 95 | wp=True), |
| 96 | convertPart( |
| 97 | 'hoth_mailbox', |
| 98 | d.getVar('FLASH_HOTH_MAILBOX_OFFSET'), |
| 99 | d.getVar('FLASH_IMAGE_DESC_OFFSET')), |
| 100 | convertPart( |
| 101 | 'image_descriptor', |
| 102 | d.getVar('FLASH_IMAGE_DESC_OFFSET'), |
| 103 | d.getVar('FLASH_ROFS_OFFSET'), |
| 104 | static=True, |
| 105 | wp=True), |
| 106 | convertPart( |
| 107 | 'rofs', |
| 108 | d.getVar('FLASH_ROFS_OFFSET'), |
| 109 | d.getVar('FLASH_RWFS_OFFSET'), |
| 110 | static=True, |
| 111 | wp=True), |
| 112 | convertPart( |
| 113 | 'rwfs', |
| 114 | d.getVar('FLASH_RWFS_OFFSET'), |
| 115 | d.getVar('FLASH_HOTH_UPDATE_OFFSET'), |
| 116 | persist=True), |
| 117 | convertPart( |
| 118 | 'hoth_update', |
| 119 | d.getVar('FLASH_HOTH_UPDATE_OFFSET'), |
| 120 | d.getVar('FLASH_SIZE')), |
| 121 | ] |
| 122 | |
| 123 | machine = d.getVar('MACHINE') |
| 124 | platform = d.getVar('PLATFORM') |
| 125 | name = '{} {} image'.format(machine, d.getVar('DISTRO')) |
| 126 | version = d.getVar('GBMC_VERSION').split('.') |
| 127 | |
| 128 | if not platform: |
| 129 | raise NameError('PLATFORM not found, unable to generate layout, stopping build') |
| 130 | |
| 131 | layout = { |
| 132 | 'name': name, |
| 133 | 'major': int(version[0]), |
| 134 | 'minor': int(version[1]), |
| 135 | 'point': int(version[2]), |
| 136 | 'subpoint': int(version[3]), |
| 137 | 'platform': platform, |
| 138 | 'flash_capacity': int(d.getVar('FLASH_SIZE')) * 1024, |
| 139 | 'build_timestamp': int(time.time()), |
| 140 | 'region': region, |
| 141 | } |
| 142 | |
| 143 | dir = d.getVar('DEPLOY_DIR_IMAGE') |
| 144 | os.makedirs(dir, exist_ok=True) |
| 145 | path = os.path.join(dir, 'cr51-image-layout.json') |
| 146 | with open(path, 'w') as f: |
| 147 | json.dump(layout, f, sort_keys=True, indent=4) |
| 148 | } |
| 149 | |
| 150 | addtask generate_layout before do_image_complete |