- oc_loader: major refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const CUST_REV = 2;
|
||||
var buffer;
|
||||
var buffer: string | ArrayBuffer;
|
||||
|
||||
function FindMagicOffset(buffer) {
|
||||
let view = new DataView(buffer);
|
||||
@@ -11,7 +11,7 @@ function FindMagicOffset(buffer) {
|
||||
throw new Error("Invalid loader.kip file");
|
||||
}
|
||||
|
||||
function CustEntry(name, size, desc, defval, minmax = [0, 1_000_000], step = 1, extra_validator = null) {
|
||||
function CustEntry(name: string, size: number, desc: string, defval: number, minmax = [0, 1_000_000], step = 1, extra_validator?) {
|
||||
this.name = name;
|
||||
this.size = size;
|
||||
this.desc = desc;
|
||||
@@ -31,9 +31,7 @@ function InitCustTable() {
|
||||
2,
|
||||
"<b>DRAM Timing</b>\
|
||||
<li><b>0</b>: AUTO_ADJ_MARIKO_SAFE: Auto adjust timings for LPDDR4 ≤3733 Mbps specs, 8Gb density.</li>\
|
||||
<li><b>1</b>: AUTO_ADJ_MARIKO_4266: Auto adjust timings for LPDDR4X 4266 Mbps specs, 8Gb density.</li>\
|
||||
<li><b>2</b>: ENTIRE_TABLE_ERISTA: Not implemented.</li>\
|
||||
<li><b>3</b>: ENTIRE_TABLE_MARIKO: Not implemented.</li>",
|
||||
<li><b>1</b>: AUTO_ADJ_MARIKO_4266: Auto adjust timings for LPDDR4X 4266 Mbps specs, 8Gb density.</li>",
|
||||
0,
|
||||
[0, 3],
|
||||
),
|
||||
@@ -42,11 +40,11 @@ function InitCustTable() {
|
||||
4,
|
||||
"<b>Mariko CPU Max Clock in kHz</b>\
|
||||
<li>System default: 1785000</li>\
|
||||
<li>≥ 2193000 will enable overvolting (> 1120 mV)</li>",
|
||||
<li>≥ 2397000 will enable overvolting (> 1120 mV)</li>",
|
||||
2397_000,
|
||||
[1785_000, 3000_000],
|
||||
100,
|
||||
(x) => { return (x % 100) == 0; }
|
||||
(x: number) => (x % 100) == 0
|
||||
),
|
||||
new CustEntry(
|
||||
"marikoCpuBoostClock",
|
||||
@@ -57,7 +55,7 @@ function InitCustTable() {
|
||||
1785_000,
|
||||
[1785_000, 3000_000],
|
||||
100,
|
||||
(x) => { return (x % 100) == 0; }
|
||||
(x: number) => (x % 100) == 0
|
||||
),
|
||||
new CustEntry(
|
||||
"marikoCpuMaxVolt",
|
||||
@@ -65,7 +63,7 @@ function InitCustTable() {
|
||||
"<b>Mariko CPU Max Voltage in mV</b>\
|
||||
<li>System default: 1120</li>\
|
||||
<li>Acceptable range: 1100 ≤ x ≤ 1300</li>",
|
||||
1220,
|
||||
1235,
|
||||
[1100, 1300],
|
||||
),
|
||||
new CustEntry(
|
||||
@@ -77,7 +75,7 @@ function InitCustTable() {
|
||||
1305_600,
|
||||
[768_000, 1536_000],
|
||||
100,
|
||||
(x) => { return (x % 100) == 0; }
|
||||
(x: number) => (x % 100) == 0
|
||||
),
|
||||
new CustEntry(
|
||||
"marikoEmcMaxClock",
|
||||
@@ -88,26 +86,25 @@ function InitCustTable() {
|
||||
1996_800,
|
||||
[1612_800, 2400_000],
|
||||
3200,
|
||||
(x) => { return (x % 3200) == 0; }
|
||||
(x: number) => (x % 3200) == 0
|
||||
),
|
||||
new CustEntry(
|
||||
"eristaCpuOCEnable",
|
||||
4,
|
||||
"<b>Erista CPU Enable Overclock</b>\
|
||||
<li>Not usable unless CPU cvb table is filled in</li>",
|
||||
0,
|
||||
<li>Not tested</li>",
|
||||
1,
|
||||
[0, 1]
|
||||
),
|
||||
new CustEntry(
|
||||
"eristaCpuMaxVolt",
|
||||
4,
|
||||
"<b>Erista CPU Max Voltage in mV</b>\
|
||||
<li>Acceptable range: 1100 ≤ x ≤ 1400</li>\
|
||||
<li>Not enabled by default</li>",
|
||||
0,
|
||||
<li>Acceptable range: 1100 ≤ x ≤ 1400</li>",
|
||||
1257,
|
||||
[0, 1400],
|
||||
100,
|
||||
(x) => { return x >= 1100; }
|
||||
(x: number) => x >= 1100
|
||||
),
|
||||
new CustEntry(
|
||||
"eristaEmcMaxClock",
|
||||
@@ -118,7 +115,7 @@ function InitCustTable() {
|
||||
1862_400,
|
||||
[1600_000, 2400_000],
|
||||
3200,
|
||||
(x) => { return (x % 3200) == 0; }
|
||||
(x: number) => (x % 3200) == 0
|
||||
),
|
||||
new CustEntry(
|
||||
"eristaEmcVolt",
|
||||
@@ -129,7 +126,7 @@ function InitCustTable() {
|
||||
0,
|
||||
[0, 1250_000],
|
||||
12500,
|
||||
(x) => { return (x % 12500) == 0 && x >= 1100_000; }
|
||||
(x: number) => (x % 12500) == 0 && x >= 1100000
|
||||
),
|
||||
];
|
||||
return cust;
|
||||
@@ -140,18 +137,18 @@ function ValidateCust(cust) {
|
||||
if (i.value == 0)
|
||||
continue;
|
||||
if (i.value < i.min || i.value > i.max) {
|
||||
document.getElementById(i.name).focus();
|
||||
document.getElementById(i.name)!.focus();
|
||||
throw new Error(`Expected range: ${i.min} ≤ ${i.name} ≤ ${i.max}, got ${i.value}`);
|
||||
}
|
||||
if (i.validator && !i.validator(i.value)) {
|
||||
document.getElementById(i.name).focus();
|
||||
document.getElementById(i.name)!.focus();
|
||||
throw new Error(`Invalid value: ${i.value}(${i.name})\nValidator: ${i.validator}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SaveCust(cust, buffer) {
|
||||
let dict = Object.assign({}, ...cust.map((x) => ({[x.name]: x})));
|
||||
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
|
||||
let view = new DataView(buffer);
|
||||
let storage = {};
|
||||
for (let i of cust) {
|
||||
@@ -166,7 +163,7 @@ function SaveCust(cust, buffer) {
|
||||
view.setUint32(i.offset, i.value, true);
|
||||
break;
|
||||
default:
|
||||
document.getElementById(i.name).focus();
|
||||
document.getElementById(i.name)!.focus();
|
||||
throw new Error("Unknown size at " + i);
|
||||
}
|
||||
}
|
||||
@@ -195,7 +192,7 @@ function LastSaved() {
|
||||
function LoadLastSaved() {
|
||||
if (LastSaved()) {
|
||||
let storage = localStorage.getItem("last_saved");
|
||||
let sObj = JSON.parse(storage);
|
||||
let sObj = JSON.parse(storage!);
|
||||
for (let key in sObj) {
|
||||
if (key == "custRev") {
|
||||
continue;
|
||||
@@ -205,16 +202,16 @@ function LoadLastSaved() {
|
||||
}
|
||||
}
|
||||
|
||||
function LoadDefault(cust) {
|
||||
let dict = Object.assign({}, ...cust.map((x) => ({[x.name]: x})));
|
||||
function LoadDefault(cust: any[]) {
|
||||
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
|
||||
for (let i of cust) {
|
||||
let id = i.name;
|
||||
(document.getElementById(id) as HTMLInputElement).value = i.defval;
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateHTMLForm(cust) {
|
||||
let dict = Object.assign({}, ...cust.map((x) => ({[x.name]: x})));
|
||||
function UpdateHTMLForm(cust: any[]) {
|
||||
let dict = Object.assign({}, ...cust.map((x: { name: any; }) => ({[x.name]: x})));
|
||||
let form = document.getElementById("form");
|
||||
for (let i of cust) {
|
||||
let id = i.name;
|
||||
@@ -245,12 +242,12 @@ function UpdateHTMLForm(cust) {
|
||||
div.appendChild(tip);
|
||||
}
|
||||
|
||||
form.appendChild(div);
|
||||
form?.appendChild(div);
|
||||
}
|
||||
input.value = dict[i.name].value;
|
||||
}
|
||||
|
||||
let btn = document.getElementById("load");
|
||||
let btn = document.getElementById("load")!;
|
||||
btn.classList.remove("hide");
|
||||
if (LastSaved()) {
|
||||
btn.innerHTML = "Load Last Saved";
|
||||
@@ -263,7 +260,7 @@ function UpdateHTMLForm(cust) {
|
||||
});
|
||||
}
|
||||
|
||||
btn = document.getElementById("save");
|
||||
btn = document.getElementById("save")!;
|
||||
btn.classList.remove("hide");
|
||||
btn.addEventListener('click', () => {
|
||||
try {
|
||||
@@ -294,7 +291,7 @@ function ParseCust(magicOffset, buffer) {
|
||||
i.value = view.getUint32(offset, true);
|
||||
break;
|
||||
default:
|
||||
document.getElementById(i.name).focus();
|
||||
document.getElementById(i.name)!.focus();
|
||||
throw new Error("Unknown size at " + i);
|
||||
}
|
||||
offset += i.size;
|
||||
@@ -306,10 +303,10 @@ function ParseCust(magicOffset, buffer) {
|
||||
const fileInput = document.getElementById("file") as HTMLInputElement;
|
||||
fileInput.addEventListener('change', (event) => {
|
||||
let reader = new FileReader();
|
||||
reader.readAsArrayBuffer((event.target as HTMLInputElement).files[0]);
|
||||
reader.readAsArrayBuffer((event.target as HTMLInputElement).files![0]);
|
||||
reader.onloadend = (progEvent) => {
|
||||
if (progEvent.target.readyState === FileReader.DONE) {
|
||||
buffer = progEvent.target.result;
|
||||
if (progEvent.target!.readyState === FileReader.DONE) {
|
||||
buffer = progEvent.target!.result!;
|
||||
try {
|
||||
let offset = FindMagicOffset(buffer);
|
||||
ParseCust(offset, buffer);
|
||||
|
||||
Reference in New Issue
Block a user