Check the memory and return the target board memory layout.
This 68HC11 bootstrap program checks the target memory to find out the memory regions which contain some RAM. It prints out the starting and ending addresses of the RAM banks. The output format is:
- +{ADDR}
- Indicates that a RAM bank starts at {ADDR} inclusive.
- -{ADDR}
- Indicates that a non-RAM bank bank starts at {ADDR} inclusive. {ADDR}-1 is the end address of the previous RAM bank.
Addresses are printed in hexadecimal.
To find the RAM, we use a basic destructive algorithm:
- read the memory
- invert all the bits and write to the memory
- read again and verify that this matches with what we wrote.
Once all the memory space is scanned, the program reboots by jumping to the internal ROM. The loader is then able to upload another program.
This bootstrap program is uploaded by the GTAM to obtain the configuration of the target board and verify the consistency with the program that must be uploaded (if we are uploading some program outside of the 256 bytes RAM bank).
Implementation Notes:
- This program must not be linked with a startup file. It implements the startup entry point.
- The
_start function must be at beginning of this file. By doing so, it will be mapped at address 0 by the linker and we avoid to have some jump to call it (since the boot will jump there). - It must be compiled with -mshort -Os -fomit-frame-pointer to make sure it fits in less than 248 bytes (keep a few bytes at end for the stack).
- It must be compiled with -msoft-reg-count=0 or =1 to reduce the use of soft-registers (since they are mapped in RAM in .page0).
- The pointer used to scan the memory is marked volatile to prevent GCC from optimizing memory accesses.
- Before scanning the memory, we switch the bus in the expanded mode. We switch back to single chip before rebooting.
- The soft registers must be located at beginning of the .page0. This will clobber the beginning of the
_start function. We don't care because this clobbers some initialisation part. - Compile with -DNO_REBOOT to avoid the reboot. In that case, the program loops indefinately checking the memory regions.
Caveats:
- It does not detect RAM banks which are mapped at several addresses.
Source file: checker.c
|