Strong validate firmware version (to ensure that it is correct)

This commit is contained in:
Kamil Trzciński 2022-11-12 14:25:57 +01:00
parent 52d68d4b7f
commit a5fc409bfc
4 changed files with 115 additions and 30 deletions

View file

@ -44,9 +44,10 @@
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.propertyGridUpdateTimer = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.label1 = new System.Windows.Forms.Label();
this.helpLabel = new System.Windows.Forms.Label();
this.sensorWarningLabel = new System.Windows.Forms.Label();
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.helpLabel = new System.Windows.Forms.Label();
this.contextMenu.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@ -76,25 +77,25 @@
this.toolStripSeparator1,
this.toolStripMenuItem1});
this.contextMenu.Name = "fanModeSelectMenu";
this.contextMenu.Size = new System.Drawing.Size(182, 96);
this.contextMenu.Size = new System.Drawing.Size(311, 96);
//
// fanModeSelectNotifyMenu
//
this.fanModeSelectNotifyMenu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fanModeSelectNotifyMenu.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.fanModeSelectNotifyMenu.Name = "fanModeSelectNotifyMenu";
this.fanModeSelectNotifyMenu.Size = new System.Drawing.Size(121, 40);
this.fanModeSelectNotifyMenu.Size = new System.Drawing.Size(250, 40);
this.fanModeSelectNotifyMenu.SelectedIndexChanged += new System.EventHandler(this.fanModeSelect_SelectedValueChanged);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(178, 6);
this.toolStripSeparator1.Size = new System.Drawing.Size(307, 6);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(181, 38);
this.toolStripMenuItem1.Size = new System.Drawing.Size(310, 38);
this.toolStripMenuItem1.Text = "Exit";
this.toolStripMenuItem1.Click += new System.EventHandler(this.formClose_Event);
//
@ -116,7 +117,7 @@
this.fanModeSelectMenu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fanModeSelectMenu.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.fanModeSelectMenu.Name = "fanModeSelectMenu";
this.fanModeSelectMenu.Size = new System.Drawing.Size(121, 40);
this.fanModeSelectMenu.Size = new System.Drawing.Size(250, 40);
this.fanModeSelectMenu.SelectedIndexChanged += new System.EventHandler(this.fanModeSelect_SelectedValueChanged);
//
// controlToolStripMenuItem
@ -158,19 +159,51 @@
//
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.helpLabel, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.sensorWarningLabel, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.propertyGrid1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.helpLabel, 0, 2);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 44);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowCount = 4;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(712, 885);
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(712, 989);
this.tableLayoutPanel1.TabIndex = 5;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.label1.ForeColor = System.Drawing.Color.Red;
this.label1.Location = new System.Drawing.Point(3, 893);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(706, 64);
this.label1.TabIndex = 9;
this.label1.Text = "This application is highly experimental.\r\nUse at your own risk!";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// helpLabel
//
this.helpLabel.AutoSize = true;
this.helpLabel.Cursor = System.Windows.Forms.Cursors.Hand;
this.helpLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.helpLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.helpLabel.Font = new System.Drawing.Font("Segoe UI", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
this.helpLabel.ForeColor = System.Drawing.SystemColors.HotTrack;
this.helpLabel.Location = new System.Drawing.Point(3, 957);
this.helpLabel.Name = "helpLabel";
this.helpLabel.Size = new System.Drawing.Size(706, 32);
this.helpLabel.TabIndex = 8;
this.helpLabel.Text = "https://github.com/ayufan-research/SteamDeckTools";
this.helpLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// sensorWarningLabel
//
this.sensorWarningLabel.AutoSize = true;
@ -178,12 +211,12 @@
this.sensorWarningLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.sensorWarningLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.sensorWarningLabel.ForeColor = System.Drawing.Color.Red;
this.sensorWarningLabel.Location = new System.Drawing.Point(3, 725);
this.sensorWarningLabel.Location = new System.Drawing.Point(3, 797);
this.sensorWarningLabel.Name = "sensorWarningLabel";
this.sensorWarningLabel.Size = new System.Drawing.Size(706, 128);
this.sensorWarningLabel.Size = new System.Drawing.Size(706, 96);
this.sensorWarningLabel.TabIndex = 6;
this.sensorWarningLabel.Text = "Some sensors are missing.\r\nThe fan behavior might be incorrect.\r\nWhich might resu" +
"lt in device failure.\r\nUse at your own risk!";
"lt in device overheating.\r\n";
this.sensorWarningLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.sensorWarningLabel.Visible = false;
//
@ -194,31 +227,15 @@
this.propertyGrid1.HelpVisible = false;
this.propertyGrid1.Location = new System.Drawing.Point(3, 3);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(706, 719);
this.propertyGrid1.Size = new System.Drawing.Size(706, 791);
this.propertyGrid1.TabIndex = 1;
this.propertyGrid1.ToolbarVisible = false;
//
// helpLabel
//
this.helpLabel.AutoSize = true;
this.helpLabel.Cursor = System.Windows.Forms.Cursors.Hand;
this.helpLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.helpLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.helpLabel.Font = new System.Drawing.Font("Segoe UI", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
this.helpLabel.ForeColor = System.Drawing.SystemColors.HotTrack;
this.helpLabel.Location = new System.Drawing.Point(3, 853);
this.helpLabel.Name = "helpLabel";
this.helpLabel.Size = new System.Drawing.Size(706, 32);
this.helpLabel.TabIndex = 7;
this.helpLabel.Text = "https://github.com/ayufan-research/SteamDeckTools";
this.helpLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.helpLabel.DoubleClick += new System.EventHandler(this.help_DoubleClick);
//
// FanControlForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(712, 929);
this.ClientSize = new System.Drawing.Size(712, 1033);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.menuStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
@ -259,6 +276,7 @@
private PropertyGrid propertyGrid1;
private ToolStripMenuItem toolStripMenuItemStartupOnBoot;
private ToolStripSeparator toolStripSeparator2;
private Label label1;
private Label helpLabel;
}
}

View file

@ -25,6 +25,19 @@ namespace FanControl
Text += " v" + Application.ProductVersion.ToString();
notifyIcon.Text = Text;
if (!Vlv0100.IsSupported())
{
String message = "";
message += "Current device is not supported.\n";
message += "FirmwareVersion: " + Vlv0100.GetFirmwareVersion().ToString("X") + "\n";
message += "BoardID: " + Vlv0100.GetBoardID().ToString("X") + "\n";
message += "PDCS: " + Vlv0100.GetPDCS().ToString("X") + "\n";
MessageBox.Show(message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return;
}
toolStripMenuItemStartupOnBoot.Visible = startupManager.IsAvailable;
toolStripMenuItemStartupOnBoot.Checked = startupManager.Startup;
@ -80,6 +93,7 @@ namespace FanControl
{
WindowState = FormWindowState.Normal;
Show();
Activate();
propertyGrid1.Refresh();
}

View file

@ -30,6 +30,13 @@ namespace FanControl
[CategoryAttribute("Fan")]
public ushort DesiredRPM { get; private set; }
[CategoryAttribute("Board")]
public String FirmwareVersion { get; private set; } = Vlv0100.GetFirmwareVersion().ToString("X");
[CategoryAttribute("Board")]
public String BoardID { get; private set; } = Vlv0100.GetBoardID().ToString("X");
[CategoryAttribute("Board")]
public String PDCS { get; private set; } = Vlv0100.GetPDCS().ToString("X");
private LibreHardwareMonitor.Hardware.Computer libreHardwareComputer = new LibreHardwareMonitor.Hardware.Computer
{
IsCpuEnabled = true,

View file

@ -12,15 +12,61 @@ namespace FanControl
{
// Those addresses are taken from DSDT for VLV0100
// and might change at any time with a BIOS update
// Purpose: https://lore.kernel.org/lkml/20220206022023.376142-1-andrew.smirnov@gmail.com/
// Addresses: DSDT.txt
static IntPtr FSLO_FSHI = new IntPtr(0xFE700B00 + 0x92);
static IntPtr GNLO_GNHI = new IntPtr(0xFE700B00 + 0x95);
static IntPtr FRPR = new IntPtr(0xFE700B00 + 0x97);
static IntPtr FNRL_FNRH = new IntPtr(0xFE700300 + 0xB0);
static IntPtr FNCK = new IntPtr(0xFE700300 + 0x9F);
static IntPtr BATH_BATL = new IntPtr(0xFE700400 + 0x6E);
static IntPtr PDFV = new IntPtr(0xFE700C00 + 0x4C);
static IntPtr XBID = new IntPtr(0xFE700300 + 0xBD);
static IntPtr PDCT = new IntPtr(0xFE700C00 + 0x01);
static ushort IO6C = 0x6C;
public const ushort MAX_FAN_RPM = 0x1C84;
public static readonly ushort[] SupportedFirmwares = {
0xB030 // 45104
};
public static readonly byte[] SupportedBoardID = {
6
};
public static readonly byte[] SupportedPDCS = {
0x2B // 43
};
public static bool IsSupported()
{
var firmwareVersion = GetFirmwareVersion();
var boardID = GetBoardID();
var pdcs = GetPDCS();
return SupportedFirmwares.Contains(firmwareVersion) &&
SupportedBoardID.Contains(boardID) &&
SupportedPDCS.Contains(pdcs);
}
public static ushort GetFirmwareVersion()
{
byte[] data = InpOut.ReadMemory(PDFV, 2);
return BitConverter.ToUInt16(data);
}
public static byte GetBoardID()
{
byte[] data = InpOut.ReadMemory(XBID, 1);
return data[0];
}
public static byte GetPDCS()
{
byte[] data = InpOut.ReadMemory(PDCT, 1);
return data[0];
}
public static ushort GetFanDesiredRPM()
{