|
145 | 145 | return chip === 'nor8m' ? ['nor8m'] : ['nor8m', 'nor16m']; |
146 | 146 | } |
147 | 147 |
|
| 148 | + // The layout a chip wears unless it is told otherwise: the largest one it |
| 149 | + // can hold, which is the last entry allowedLayouts returns. |
| 150 | + function naturalLayout(chip) { |
| 151 | + const allowed = allowedLayouts(chip); |
| 152 | + return allowed.length ? allowed[allowed.length - 1] : ''; |
| 153 | + } |
| 154 | + |
| 155 | + // Whether the visitor has settled the layout for themselves. Until they |
| 156 | + // have, it follows the chip, so choosing NOR 16M gets the 16MB layout -- |
| 157 | + // which is what the single menu this replaced always produced. |
| 158 | + // |
| 159 | + // Without it the 8MB layout the form opens on survived every later chip |
| 160 | + // change, because it is a legal choice on a larger part and so never |
| 161 | + // tripped the not-allowed branch. Picking NOR 16M then quietly gave a 16MB |
| 162 | + // camera 8MB partitions, and the edition limiter below took Ultimate away |
| 163 | + // with it. |
| 164 | + let layoutChosen = false; |
| 165 | + |
148 | 166 | // Narrow the layout menu to the chip, and answer what is now selected. |
149 | | - // Landing on the last allowed entry rather than the first makes the |
150 | | - // chip's own layout the default, which is what this form produced when |
151 | | - // the two were a single field. |
152 | 167 | function checkPartitionLayout() { |
153 | 168 | const el = document.querySelector('#camera_partition_layout'); |
154 | 169 | const chip = document.querySelector('#camera_flash_type').value; |
|
159 | 174 | const o = el.options.item(i); |
160 | 175 | o.disabled = !allowed.includes(o.value); |
161 | 176 | } |
162 | | - if (allowed.length && !allowed.includes(el.value)) el.value = allowed[allowed.length - 1]; |
| 177 | + if (allowed.length && !(layoutChosen && allowed.includes(el.value))) { |
| 178 | + el.value = naturalLayout(chip); |
| 179 | + } |
163 | 180 |
|
164 | | - return el.value; |
| 181 | + // Nothing, rather than whatever the hidden menu happens to hold, when |
| 182 | + // the chip has no NOR layout to choose. The menu keeps its value while |
| 183 | + // it is hidden, so NAND was reading back `nor8m` and having Ultimate |
| 184 | + // taken off it by a rootfs partition it does not have -- eleven of the |
| 185 | + // sixteen boards with a NAND build are published as Ultimate and |
| 186 | + // nothing else. |
| 187 | + return allowed.length ? el.value : ''; |
165 | 188 | } |
166 | 189 |
|
167 | 190 | function allowedEditions(chip, layout) { |
|
232 | 255 |
|
233 | 256 | document.querySelector('#generate-mac-address').addEventListener('click', generateMacAddress); |
234 | 257 | document.querySelector('#camera_flash_type').addEventListener('change', checkFlashSize); |
235 | | - document.querySelector('#camera_partition_layout').addEventListener('change', checkFlashSize); |
| 258 | + document.querySelector('#camera_partition_layout').addEventListener('change', function () { |
| 259 | + layoutChosen = true; |
| 260 | + checkFlashSize(); |
| 261 | + }); |
| 262 | + |
| 263 | + // Settled before the first narrowing, and after the chip has: a page that |
| 264 | + // opens on a layout that is not its chip's own got there from a permanent |
| 265 | + // link carrying `part`, and that is as deliberate as using the menu. A link |
| 266 | + // written before this field existed carries none, so it opens on the chip's |
| 267 | + // own layout and means exactly what it always did. |
| 268 | + useAnOfferedFlashType(); |
| 269 | + layoutChosen = allowedLayouts(document.querySelector('#camera_flash_type').value).length > 0 && |
| 270 | + document.querySelector('#camera_partition_layout').value |
| 271 | + !== naturalLayout(document.querySelector('#camera_flash_type').value); |
236 | 272 | checkFlashSize(); |
237 | 273 | </script> |
0 commit comments