Online loader_configurator for web browser

This commit is contained in:
KazushiM
2022-11-08 17:06:46 +08:00
parent 523d2dc45a
commit d884077db8
9 changed files with 4412 additions and 4 deletions

View File

@@ -0,0 +1,292 @@
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./output.css" rel="stylesheet">
</head>
<body>
<div class="flex justify-center">
<div id="form" class="form-group p-6 rounded-lg shadow-lg bg-white max-w-sm">
<label for="file" class="inline-block mb-2 text-gray-700">Upload loader.kip</label>
<input id="file" type="file" class="form-control form-entry">
</div>
</div>
</body>
<script type="text/javascript">
var buffer;
function FindMagicOffset(buffer) {
let view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
if (view.getUint32(i, true) == 0x54535543) { // "CUST"
return i;
}
}
throw new Error("Invalid loader.kip file");
}
function CustEntry(name, size, desc, minmax = [0, 1_000_000], step = 1, extra_validator = undefined) {
this.name = name;
this.size = size;
this.value = null;
this.offset = null;
this.desc = desc;
this.min = minmax[0];
this.max = minmax[1];
this.step = step;
this.validator = extra_validator;
}
function InitCustTable() {
let cust = [
new CustEntry(
"custRev",
2,
"Cust Version, must be 2",
[2, 2],
),
new CustEntry(
"mtcConf",
2,
"<b>DRAM Timing</b>\
<li><b>0</b>: AUTO_ADJ_MARIKO_SAFE (Default): 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>",
[0, 3],
),
new CustEntry(
"marikoCpuMaxClock",
4,
"<b>Mariko CPU Max Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>≥ 2193000 will enable overvolting (> 1120 mV)</li>",
[1785_000, 3000_000],
100,
(x) => { return (x % 100) == 0; }
),
new CustEntry(
"marikoCpuBoostClock",
4,
"<b>Mariko CPU Boost Clock in kHz</b>\
<li>System default: 1785000</li>\
<li>Must not be higher than marikoCpuMaxClock</li>",
[1785_000, 3000_000],
100,
(x) => { return (x % 100) == 0; }
),
new CustEntry(
"marikoCpuMaxVolt",
4,
"<b>Mariko CPU Max Voltage in mV</b>\
<li>System default: 1120</li>\
<li>Acceptable range: 1100 ≤ x ≤ 1300</li>",
[1100, 1300],
),
new CustEntry(
"marikoGpuMaxClock",
4,
"<b>Mariko GPU Max Clock in kHz</b>\
<li>System default: 921600</li>\
<li>Tegra X1+ official maximum: 1267200</li>",
[768_000, 1536_000],
100,
(x) => { return (x % 100) == 0; }
),
new CustEntry(
"marikoEmcMaxClock",
4,
"<b>Mariko RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>",
[1612_800, 2400_000],
3200,
(x) => { return (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, 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, 1400],
100,
(x) => { return x >= 1100; }
),
new CustEntry(
"eristaEmcMaxClock",
4,
"<b>Erista RAM Max Clock in kHz</b>\
<li>Values should be > 1600000, and divided evenly by 3200.</li>\
<li><b>WARNING:</b> RAM overclock could be UNSTABLE if timing parameters are not suitable for your DRAM</li>",
[1600_000, 2400_000],
3200,
(x) => { return (x % 3200) == 0; }
),
new CustEntry(
"eristaEmcVolt",
4,
"<b>Erista RAM Voltage in uV</b>\
<li>Acceptable range: 1100000 ≤ x ≤ 1250000, and it should be divided evenly by 12500.</li>\
<li>Not enabled by default</li>",
[0, 1250_000],
12500,
(x) => { return (x % 12500) == 0 && x >= 1100_000; }
),
];
return cust;
}
function ValidateCust(cust) {
for (let i of cust) {
if (i.value == 0)
continue;
if (i.value < i.min || i.value > i.max) {
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();
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 view = new DataView(buffer);
for (let i of cust) {
if (i.name == "custRev") {
continue;
}
let id = i.name;
i.value = document.getElementById(id).value;
switch (i.size) {
case 2:
view.setUint16(i.offset, i.value, true);
break;
case 4:
view.setUint32(i.offset, i.value, true);
break;
default:
document.getElementById(i.name).focus();
throw new Error("Unknown size at", i);
}
}
ValidateCust(cust);
let a = document.createElement("a");
a.href = window.URL.createObjectURL(new Blob([buffer], {type: "application/octet-stream"}));
a.download = "loader.kip";
a.click();
}
function UpdateHTMLForm(cust) {
let dict = Object.assign({}, ...cust.map((x) => ({[x.name]: x})));
let form = document.getElementById("form");
for (let i of cust) {
if (i.name == "custRev") {
continue;
}
let id = i.name;
let input = document.getElementById(id);
if (!input) {
let div = document.createElement("div");
div.classList.add("form-floating", "my-3");
let label = document.createElement("label");
label.setAttribute("for", id);
label.innerHTML = id;
label.classList.add("form-entry");
input = document.createElement("input");
input.classList.add("form-control", "form-entry");
input.min = dict[i.name].min;
input.max = dict[i.name].max;
input.id = id;
input.type = "number";
input.step = dict[i.name].step;
div.appendChild(input);
div.appendChild(label);
let desc = dict[i.name].desc;
if (desc) {
let tip = document.createElement("small");
tip.innerHTML = desc;
tip.classList.add("form-entry");
tip.setAttribute("for", id);
div.appendChild(tip);
}
form.appendChild(div);
}
input.value = dict[i.name].value;
}
let btn = document.getElementById("save");
if (!btn) {
let div = document.createElement("div");
div.classList.add("flex", "space-x-2", "justify-center");
btn = document.createElement("button");
btn.innerHTML = "Save Changes"
btn.id = "save";
btn.classList.add("save-btn");
btn.addEventListener('click', () => {
try {
SaveCust(cust, buffer);
} catch (e) {
console.log(e);
alert(e);
}
});
div.appendChild(btn);
form.appendChild(div);
}
}
function ParseCust(magicOffset, buffer) {
let view = new DataView(buffer);
let cust = InitCustTable();
let offset = magicOffset + 4;
for (let i of cust) {
i.offset = offset;
switch (i.size) {
case 2:
i.value = view.getUint16(offset, true);
break;
case 4:
i.value = view.getUint32(offset, true);
break;
default:
document.getElementById(i.name).focus();
throw new Error("Unknown size at", i);
}
offset += i.size;
}
ValidateCust(cust);
UpdateHTMLForm(cust);
}
const fileInput = document.getElementById("file");
fileInput.addEventListener('change', (event) => {
let reader = new FileReader();
reader.readAsArrayBuffer(event.target.files[0]);
reader.onloadend = (progEvent) => {
if (progEvent.target.readyState === FileReader.DONE) {
buffer = progEvent.target.result;
try {
let offset = FindMagicOffset(buffer);
ParseCust(offset, buffer);
} catch (e) {
console.log(e);
alert(e);
fileInput.value = "";
}
}
}
})
</script>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
label.form-entry {
@apply inline-block mb-2 text-gray-700;
}
input.form-entry {
@apply block w-full px-3 py-1.5 text-base font-normal text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 rounded transition ease-in-out m-0 focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none;
}
small.form-entry {
@apply block mt-1 text-xs text-gray-600 px-3 py-1.5;
}
button.save-btn {
@apply inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-blue-700 hover:shadow-lg focus:bg-blue-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-blue-800 active:shadow-lg transition duration-150 ease-in-out;
}