mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 20:38:07 -08:00
A photograph of the board shows two 4 Mbit flash parts side by side, an Intel 28F400 and an AMD Am29F400AT, which is why the boot code probes Intel first and falls back to AMD. The harness was answering as Intel at the window the updater identifies, and the difference is not cosmetic: under Intel the updater erased and programmed nothing, under AMD it erases its sector and writes 4,096 words. So the model defaults to the Am29F400AT and carries AMD's command set -- a0 program, 80/30 sector erase, 10 chip erase, f0 reset -- alongside Intel's, with the part's real top-boot geometry instead of a uniform block. That geometry confirms the 8 KiB block size this repository had inferred from the erase address alone: 78100 falls in SA8, its first boot sector. Reading back the 386EX chip-select unit gives the board's map outright: 256 KiB of SRAM at 00000-3ffff, which is ATI7's Ram 256k, and 768 KiB from 40000 to fffff, which is its Eprom 768k -- across two parts, since the identify at 34983 is hardwired to 80000 with no bank loop. The 40000 window this repository called "the updater in RAM" is its own chip select. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
103 lines
3.2 KiB
Python
103 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from courier_emu.flash import ERASED_BYTE, FLASH_SIZE, ParameterFlash
|
|
from courier_emu.parameters import SECTOR_COUNT, SECTOR_SIZE, ParameterSector
|
|
|
|
|
|
class ParameterFlashTests(unittest.TestCase):
|
|
|
|
def test_programming_only_clears_bits(self) -> None:
|
|
flash = ParameterFlash()
|
|
self.assertEqual(flash.program_word(0, 0xF0F0), 0xF0F0)
|
|
# A second program can clear further bits but never set them again.
|
|
self.assertEqual(flash.program_word(0, 0xFF00), 0xF000)
|
|
self.assertEqual(flash.programmed_words, 2)
|
|
|
|
|
|
def test_erase_restores_one_sector_only(self) -> None:
|
|
flash = ParameterFlash()
|
|
flash.program_word(0, 0x0000)
|
|
flash.program_word(SECTOR_SIZE, 0x0000)
|
|
start, size = flash.erase_sector(0)
|
|
self.assertEqual((start, size), (0, SECTOR_SIZE))
|
|
self.assertEqual(flash.erases, 1)
|
|
self.assertEqual(int.from_bytes(flash.data[:2], "little"), 0xFFFF)
|
|
# The neighbouring sector keeps what was programmed into it.
|
|
self.assertEqual(
|
|
int.from_bytes(flash.data[SECTOR_SIZE : SECTOR_SIZE + 2], "little"), 0
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|
|
|
|
# -- the part the board actually carries -----------------------------------
|
|
|
|
from courier_emu.flash_device import ( # noqa: E402
|
|
AMD, AM29F400AT, FLASH_BASE, FlashDevice,
|
|
)
|
|
|
|
|
|
def amd_part() -> FlashDevice:
|
|
part = FlashDevice()
|
|
part.load(b"\x00" * part.size)
|
|
return part
|
|
|
|
|
|
def unlock(part: FlashDevice, command: int, offset: int = 0xAAAA) -> None:
|
|
"""AMD's three-write sequence: aa at 0xaaaa, 55 at 0x5554, the command."""
|
|
part.on_write(FLASH_BASE + 0xAAAA, 1, 0xAA)
|
|
part.on_write(FLASH_BASE + 0x5554, 1, 0x55)
|
|
part.on_write(FLASH_BASE + offset, 1, command)
|
|
|
|
|
|
def test_the_part_identifies_as_the_am29f400at_on_the_board():
|
|
part = amd_part()
|
|
assert part.manufacturer == AMD
|
|
assert part.device == AM29F400AT
|
|
unlock(part, 0x90)
|
|
assert part.take_patches()[-1] == (FLASH_BASE, b"\x01\x00\x23\x22")
|
|
|
|
|
|
def test_amd_sector_erase_erases_only_that_sector():
|
|
part = amd_part()
|
|
unlock(part, 0x80)
|
|
unlock(part, 0x30, offset=0x78100)
|
|
assert part.erases == 1
|
|
# SA8 is the first 8 KiB boot sector, 0x78000..0x79fff - which is where
|
|
# the updater's one erase lands.
|
|
assert part.contents[0x78000:0x7A000] == b"\xff" * 0x2000
|
|
assert part.contents[0x77FFF] == 0x00
|
|
assert part.contents[0x7A000] == 0x00
|
|
|
|
|
|
def test_amd_program_clears_bits_and_leaves_the_rest():
|
|
part = amd_part()
|
|
part.contents[0x1000] = 0xFF
|
|
unlock(part, 0xA0)
|
|
part.on_write(FLASH_BASE + 0x1000, 1, 0x5A)
|
|
assert part.programs == 1
|
|
assert part.contents[0x1000] == 0x5A
|
|
assert part.contents[0x1001] == 0x00
|
|
|
|
|
|
def test_the_sector_map_is_the_top_boot_geometry():
|
|
part = FlashDevice()
|
|
assert part._sector(0x00000) == (0x00000, 0x10000)
|
|
assert part._sector(0x6FFFF) == (0x60000, 0x10000)
|
|
assert part._sector(0x70000) == (0x70000, 0x08000)
|
|
assert part._sector(0x78100) == (0x78000, 0x02000)
|
|
assert part._sector(0x7A000) == (0x7A000, 0x02000)
|
|
assert part._sector(0x7FFFF) == (0x7C000, 0x04000)
|