Skip to content

Commit

Permalink
bk7238
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Feb 14, 2025
1 parent 757c510 commit 277c454
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 35 deletions.
70 changes: 37 additions & 33 deletions BK7231Flasher/BK7231Flasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum BKType
BK7231T,
BK7231N,
BK7231M,
BK7238,
Detect,
Invalid
}
Expand Down Expand Up @@ -965,50 +966,53 @@ bool doGenericSetup()
}
// make sure it's clear
lastEncryptionKey = "";
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M)
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M || chipType == BKType.BK7238)
{
if (doUnprotect())
{
return false;
}
addLog("Going to read encryption key..." +Environment.NewLine);
string key = readEncryptionKey();
addLog("Encryption key read done!" + Environment.NewLine);
addLog("Encryption key: " + key+Environment.NewLine);
string otherMode;
string expectedKey;
if (chipType == BKType.BK7231N)
if (chipType != BKType.BK7238)
{
otherMode = "BK7231M";
expectedKey = TUYA_ENCRYPTION_KEY;
}
else
{
otherMode = "BK7231N";
expectedKey = EMPTY_ENCRYPTION_KEY;
}
if (key != expectedKey)
{
addError("^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^" + Environment.NewLine);
addError("WARNING! Non-standard encryption key!" + Environment.NewLine);
addError("If it's all zero, it may also mean that read is disabled." + Environment.NewLine);
addError("Please report to forum https://www.elektroda.com/rtvforum/forum51.html " + Environment.NewLine);

addLog("Going to read encryption key..." + Environment.NewLine);
string key = readEncryptionKey();
addLog("Encryption key read done!" + Environment.NewLine);
addLog("Encryption key: " + key + Environment.NewLine);
string otherMode;
string expectedKey;
if (chipType == BKType.BK7231N)
{
addError("Or just try using BK7231M mode " + Environment.NewLine);
otherMode = "BK7231M";
expectedKey = TUYA_ENCRYPTION_KEY;
}
else
{

otherMode = "BK7231N";
expectedKey = EMPTY_ENCRYPTION_KEY;
}
addError("^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^" + Environment.NewLine);
if (bSkipKeyCheck == false)
if (key != expectedKey)
{
return false;
addError("^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^" + Environment.NewLine);
addError("WARNING! Non-standard encryption key!" + Environment.NewLine);
addError("If it's all zero, it may also mean that read is disabled." + Environment.NewLine);
addError("Please report to forum https://www.elektroda.com/rtvforum/forum51.html " + Environment.NewLine);

if (chipType == BKType.BK7231N)
{
addError("Or just try using BK7231M mode " + Environment.NewLine);
}
else
{

}
addError("^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^" + Environment.NewLine);
if (bSkipKeyCheck == false)
{
return false;
}
}
lastEncryptionKey = key;
}
lastEncryptionKey = key;
}
return true;
}
Expand Down Expand Up @@ -1250,7 +1254,7 @@ bool doTestReadWriteInternal(int startSector = 0x11000, int sectors = 10)
{
return false;
}
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M)
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M || chipType == BKType.BK7238)
{
if (doUnprotect())
{
Expand Down Expand Up @@ -1532,7 +1536,7 @@ bool doReadAndWriteInternal(int startSector, int sectors, string sourceFileName,
{
return false;
}
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M)
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M || chipType == BKType.BK7238)
{
if (doUnprotect())
{
Expand Down Expand Up @@ -1776,7 +1780,7 @@ byte[] readSector(int addr)
}
uint calcCRC(int start, int end)
{
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M)
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M || chipType == BKType.BK7238)
{
end = end - 1;
}
Expand Down Expand Up @@ -1810,7 +1814,7 @@ bool isSectorModificationAllowed(int addr)
return false;
}
addr %= FLASH_SIZE;
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M)
if (chipType == BKType.BK7231N || chipType == BKType.BK7231M || chipType == BKType.BK7238)
return true;
if (addr >= 0 && addr < BOOTLOADER_SIZE)
{
Expand Down
14 changes: 13 additions & 1 deletion BK7231Flasher/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private void Form1_Load(object sender, EventArgs e)
comboBoxChipType.Items.Add(BKType.BK7231T);
comboBoxChipType.Items.Add(BKType.BK7231N);
comboBoxChipType.Items.Add(BKType.BK7231M);
comboBoxChipType.Items.Add(BKType.BK7238);

comboBoxChipType.SelectedIndex = 0;

Expand Down Expand Up @@ -522,7 +523,7 @@ void doOnlyFlashOBKConfig()
int getBackupStartSectorForCurrentPlatform()
{
int startSector;
if (curType == BKType.BK7231N || curType == BKType.BK7231M)
if (curType == BKType.BK7231N || curType == BKType.BK7231M || curType == BKType.BK7238)
{
startSector = 0;
}
Expand Down Expand Up @@ -629,6 +630,10 @@ public static string getFirmwarePrefix(BKType t)
{
return ("OpenBK7231N_QIO_");
}
if (t == BKType.BK7238)
{
return ("OpenBK7238_QIO_");
}
if (t == BKType.BK7231T)
{
return ("OpenBK7231T_UA_");
Expand All @@ -653,6 +658,13 @@ public bool checkFirmwareForCurType(string s)
return true;
}
}
if (curType == BKType.BK7238)
{
if (s.StartsWith("OpenBK7238_QIO_"))
{
return true;
}
}
if (curType == BKType.BK7231T)
{
if (s.StartsWith("OpenBK7231T_UA_"))
Expand Down
10 changes: 9 additions & 1 deletion BK7231Flasher/FormOBKConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ bool tryToImportOBKSettings(string fname, BKType type)
{
type = BKType.BK7231N;
}
if (fname.Contains("BK7238"))
{
type = BKType.BK7238;
}
}
bool bError = cfg.loadFrom(fname, type);
if (bError == true)
Expand Down Expand Up @@ -366,7 +370,11 @@ string getTypeLetter(BKType t)
{
if (t == BKType.BK7231N)
return "N";
return "T";
if (t == BKType.BK7231M)
return "M";
if (t == BKType.BK7231T)
return "T";
return "";
}
void generateNamesForMAC(byte [] mac, BKType curType)
{
Expand Down
2 changes: 2 additions & 0 deletions BK7231Flasher/OBKDeviceAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ internal BKType getBKType()
string cs = getChipSet();
if (cs == "BK7231N")
return BKType.BK7231N;
if (cs == "BK7238")
return BKType.BK7238;
if (cs == "BK7231T")
return BKType.BK7231T;
return BKType.Invalid;
Expand Down

0 comments on commit 277c454

Please sign in to comment.