Skip to content

Commit

Permalink
- Test cases and creation of correct R43 SMC.BIN for testing
Browse files Browse the repository at this point in the history
- Fixing SMC.BIN header for compatible ROM.BINs
  • Loading branch information
FlightControl-User committed Oct 8, 2023
1 parent 634481b commit a0b0223
Show file tree
Hide file tree
Showing 18 changed files with 8,997 additions and 8,043 deletions.
Binary file added SMC.BIN
Binary file not shown.
Binary file added python/SMC-HEADER.BIN
Binary file not shown.
File renamed without changes.
Binary file added python/SMC.BIN
Binary file not shown.
499 changes: 0 additions & 499 deletions python/firmware_and_bootloader_r45.1.preview.hex

This file was deleted.

21 changes: 18 additions & 3 deletions python/smc_convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
from intelhex import IntelHex

src1 = IntelHex()
src1.
src1.fromfile("C:/Users/svenv/OneDrive/Documents/GitHub/x16-flash/python/x16-smc-r45.1.hex", format="hex")
src1.tofile("r45.1.preview.bin", format="bin")

src1.fromfile("C:/Users/svenv/OneDrive/Documents/GitHub/x16-flash/python/x16-smc-header.hex", format="hex")
src1.tofile("python/SMC-HEADER.BIN", format="bin")

src2 = IntelHex()

src2.fromfile("C:/Users/svenv/OneDrive/Documents/GitHub/x16-flash/python/x16-smc-r45.1.0.hex", format="hex")
src2.tofile("python/SMC-R45.1.0.BIN", format="bin")

# Try reading the file in binary mode and writing it back in binary
# mode. By default it reads files in text mode
input1 = open('python/SMC-HEADER.BIN', 'rb').read()
input2 = open('python/SMC-R45.1.0.bin', 'rb').read()

input1 += input2

with open('python/SMC.BIN', 'wb') as fp:
fp.write(input1)
3 changes: 3 additions & 0 deletions python/x16-smc-header.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:100000002B2C000000000000000000000000000099
:1000100000000000000000000000000000000000E0
:00000001FF
931 changes: 464 additions & 467 deletions python/x16-smc-r45.1.hex → python/x16-smc-r45.1.0.hex

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions src/cx16-display-text.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,28 @@ const char* display_no_valid_smc_bootloader_text[9] = {
"a CX16 community friend containing a valid bootloader!"
};

const char display_smc_rom_issue_count = 7;
const char* display_smc_rom_issue__text[7] = {
const char display_smc_rom_issue_count = 8;
const char* display_smc_rom_issue_text[8] = {
"There is an issue with the CX16 SMC or ROM flash readiness.",
"",
"Both the SMC and the main ROM must be updated together,",
"to avoid possible conflicts of firmware, bricking your CX16.",
"",
"Therefore, ensure you have the correct SMC.BIN and ROM.BIN",
"files placed on your SDcard."
"files placed on your SDcard. Also ensure that the",
"J1 jumper pins on the CX16 board are closed."
};

const char display_smc_unsupported_rom_count = 7;
const char* display_smc_unsupported_rom_text[7] = {
"There is an issue with the CX16 SMC or ROM flash versions.",
"",
"Both the SMC and the main ROM must be updated together,",
"to avoid possible conflicts of firmware, bricking your CX16.",
"",
"The SMC.BIN does not support the current ROM.BIN file",
"placed on your SDcard. Upgrade the CX16 upon your own risk!"
};


const char display_debriefing_count_smc = 12;
Expand Down
2 changes: 1 addition & 1 deletion src/cx16-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void display_info_smc(unsigned char info_status, unsigned char* info_text) {
status_smc = info_status;
display_smc_led(status_color[info_status]);
gotoxy(INFO_X, INFO_Y);
printf("SMC %-9s ATTiny v%s ", status_text[info_status], smc_version_string);
printf("SMC %-9s ATTiny v%s ", status_text[info_status], smc_version_text);
if(info_text) {
printf("%-25s", info_text);
}
Expand Down
62 changes: 43 additions & 19 deletions src/cx16-smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
// Globals (to save zeropage and code overhead with parameter passing.)
__mem unsigned int smc_bootloader = 0;
__mem unsigned int smc_file_size = 0;
__mem unsigned char smc_version_string[16];

__mem unsigned char smc_rom_releases[32];

__mem unsigned char smc_release;
__mem unsigned char smc_major;
__mem unsigned char smc_minor;

__mem unsigned char smc_file_release;
__mem unsigned char smc_file_major;
__mem unsigned char smc_file_minor;

__mem unsigned char smc_version_text[16];



Expand Down Expand Up @@ -67,7 +78,13 @@ unsigned long smc_get_version_text(unsigned char* version_string, unsigned char
return MAKELONG(MAKEWORD(minor, major), MAKEWORD(0, release));
}


unsigned char smc_supported_rom(unsigned char rom_release) {
for(unsigned char i=0; i<32; i++) {
if(smc_rom_releases[i] == rom_release)
return 1;
}
return 0;
}

/**
* @brief Shut down the CX16 through an SMC reboot.
Expand Down Expand Up @@ -138,27 +155,34 @@ unsigned int smc_read(unsigned char display_progress) {
FILE *fp = fopen("SMC.BIN", "r");
if (fp) {

// We read block_size bytes at a time, and each block_size bytes we plot a dot.
// Every r bytes we move to the next line.
while (smc_file_read = fgets(ram_ptr, SMC_PROGRESS_CELL, fp)) {
// Read the ROM releases in the SMC.BIN header first.
smc_file_read = fgets(smc_rom_releases, 32, fp);

sprintf(info_text, "Reading SMC.BIN:%05x/%05x -> RAM:%02x:%04p ...", smc_file_read, smc_file_size, 0, ram_ptr);
display_action_text(info_text);
// Has the header been read, all ok, otherwise the file size is wrong!
if(smc_file_read) {

if (progress_row_bytes == SMC_PROGRESS_ROW) {
gotoxy(x, ++y);
progress_row_bytes = 0;
}
// We read block_size bytes at a time, and each block_size bytes we plot a dot.
// Every r bytes we move to the next line.
while (smc_file_read = fgets(ram_ptr, SMC_PROGRESS_CELL, fp)) {

if(display_progress)
cputc('.');
sprintf(info_text, "Reading SMC.BIN:%05x/%05x -> RAM:%02x:%04p ...", smc_file_read, smc_file_size, 0, ram_ptr);
display_action_text(info_text);

ram_ptr += smc_file_read;
smc_file_size += smc_file_read;
progress_row_bytes += smc_file_read;
}
if (progress_row_bytes == SMC_PROGRESS_ROW) {
gotoxy(x, ++y);
progress_row_bytes = 0;
}

fclose(fp);
if(display_progress)
cputc('.');

ram_ptr += smc_file_read;
smc_file_size += smc_file_read;
progress_row_bytes += smc_file_read;
}

fclose(fp);
}
}

// We return the amount of bytes read.
Expand Down Expand Up @@ -277,7 +301,7 @@ unsigned int smc_flash(unsigned int smc_bytes_total) {
if(smc_attempts_flashed >= 10) {
sprintf(info_text, "There were too many attempts trying to flash the SMC at location %04x", smc_bytes_flashed);
display_action_text(info_text);
return 0;
return 0xFFFFFFFF;
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/cx16-smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@
#define FLASH_I2C_SMC_DEVICE 0x42

extern unsigned int smc_bootloader;
extern unsigned char smc_version_string[16];
extern unsigned char smc_version_text[16];
extern unsigned int smc_file_size;

extern unsigned char smc_rom_releases[32];

extern unsigned char smc_release;
extern unsigned char smc_major;
extern unsigned char smc_minor;

extern unsigned char smc_file_release;
extern unsigned char smc_file_major;
extern unsigned char smc_file_minor;


unsigned int smc_detect();
unsigned long smc_get_version_text(unsigned char* version_string, unsigned char release, unsigned char major, unsigned char minor);
void smc_reset();
Expand Down
20 changes: 10 additions & 10 deletions src/cx16-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __mem unsigned char status_rom[8] = {0};
* @param status The status to be checked.
* @return unsigned char true if the status is equal.
*/
inline unsigned char check_status_smc(unsigned char status) {
unsigned char check_status_smc(unsigned char status) {
return (unsigned char)(status_smc == status);
}

Expand All @@ -34,7 +34,7 @@ inline unsigned char check_status_smc(unsigned char status) {
* @param status The status to be checked.
* @return unsigned char true if the status is equal.
*/
inline unsigned char check_status_vera(unsigned char status) {
unsigned char check_status_vera(unsigned char status) {
return (unsigned char)(status_vera == status);
}

Expand All @@ -45,7 +45,7 @@ inline unsigned char check_status_vera(unsigned char status) {
* @param status The status to be checked.
* @return unsigned char true if the status is equal.
*/
inline unsigned char check_status_rom(unsigned char rom_chip, unsigned char status) {
unsigned char check_status_rom(unsigned char rom_chip, unsigned char status) {
return (unsigned char)(status_rom[rom_chip] == status);
}

Expand All @@ -65,13 +65,13 @@ inline unsigned char check_status_cx16_rom(unsigned char status) {
* @param status The status to be checked.
* @return unsigned char true if one chip is equal to the status.
*/
inline unsigned char check_status_card_roms(unsigned char status) {
unsigned char check_status_card_roms(unsigned char status) {
for(unsigned char rom_chip = 1; rom_chip < 8; rom_chip++) {
if(check_status_rom(rom_chip, status)) {
return status;
return 1;
}
}
return STATUS_NONE;
return 0;
}

/**
Expand All @@ -80,13 +80,13 @@ inline unsigned char check_status_card_roms(unsigned char status) {
* @param status The status to be checked.
* @return unsigned char true if one chip is equal to the status.
*/
inline unsigned char check_status_roms(unsigned char status) {
unsigned char check_status_roms(unsigned char status) {
for(unsigned char rom_chip = 0; rom_chip < 8; rom_chip++) {
if(check_status_rom(rom_chip, status)) {
return status;
return 1;
}
}
return STATUS_NONE;
return 0;
}

/**
Expand All @@ -95,7 +95,7 @@ inline unsigned char check_status_roms(unsigned char status) {
* @param status The status to be checked.
* @return unsigned char true if all chips are equal to the status.
*/
inline unsigned char check_status_roms_all(unsigned char status) {
unsigned char check_status_roms_all(unsigned char status) {
for(unsigned char rom_chip = 0; rom_chip < 8; rom_chip++) {
if(check_status_rom(rom_chip, status) != status) {
return 0;
Expand Down
Loading

0 comments on commit a0b0223

Please sign in to comment.