Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash encryption #145

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/typescript/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h3> Program </h3>
<thead class="thead-light">
<tr>
<th>Flash Address</th>
<th>Encrypt file ?</th>
<th>File</th>
<th></th>
</tr>
Expand Down
67 changes: 39 additions & 28 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
// Temporarily broken
// await esploader.flashId();
} catch (e) {
console.error(e);

Check warning on line 103 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
}

console.log("Settings done for :" + chip);

Check warning on line 107 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
lblBaudrate.style.display = "none";
lblConnTo.innerHTML = "Connected to device: " + chip;
lblConnTo.style.display = "block";
Expand Down Expand Up @@ -136,7 +136,7 @@
try {
await esploader.eraseFlash();
} catch (e) {
console.error(e);

Check warning on line 139 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
} finally {
eraseButton.disabled = false;
Expand All @@ -155,35 +155,43 @@
element1.value = "0x1000";
cell1.appendChild(element1);

// Column 2 - File selector
// Column 2 - Encrypt file ?
const cell2 = row.insertCell(1);
const element2 = document.createElement("input");
element2.type = "file";
element2.id = "selectFile" + rowCount;
element2.name = "selected_File" + rowCount;
element2.addEventListener("change", handleFileSelect, false);
element2.type = "checkbox";
element2.id = "file_encrypted" + rowCount;
element2.checked = false;
cell2.appendChild(element2);

// Column 3 - Progress
// Column 3 - File selector
const cell3 = row.insertCell(2);
cell3.classList.add("progress-cell");
cell3.style.display = "none";
cell3.innerHTML = `<progress value="0" max="100"></progress>`;

// Column 4 - Remove File
const element3 = document.createElement("input");
element3.type = "file";
element3.id = "selectFile" + rowCount;
element3.name = "selected_File" + rowCount;
element3.addEventListener("change", handleFileSelect, false);
cell3.appendChild(element3);

// Column 4 - Progress
const cell4 = row.insertCell(3);
cell4.classList.add("action-cell");
cell4.classList.add("progress-cell");
cell4.style.display = "none";
cell4.innerHTML = `<progress value="0" max="100"></progress>`;

// Column 5 - Remove File
const cell5 = row.insertCell(4);
cell5.classList.add("action-cell");
if (rowCount > 1) {
const element4 = document.createElement("input");
element4.type = "button";
const element5 = document.createElement("input");
element5.type = "button";
const btnName = "button" + rowCount;
element4.name = btnName;
element4.setAttribute("class", "btn");
element4.setAttribute("value", "Remove"); // or element1.value = "button";
element4.onclick = function () {
element5.name = btnName;
element5.setAttribute("class", "btn");
element5.setAttribute("value", "Remove"); // or element1.value = "button";
element5.onclick = function () {
removeRow(row);
};
cell4.appendChild(element4);
cell5.appendChild(element5);
}
};

Expand Down Expand Up @@ -254,7 +262,7 @@
break;
}
}
console.log("quitting console");

Check warning on line 265 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
};

consoleStopButton.onclick = async () => {
Expand Down Expand Up @@ -299,7 +307,7 @@
else if (offsetArr.includes(offset)) return "Offset field in row " + index + " is already in use!";
else offsetArr.push(offset);

const fileObj = row.cells[1].childNodes[0];
const fileObj = row.cells[2].childNodes[0];
fileData = fileObj.data;
if (fileData == null) return "No file selected for row " + index + "!";
}
Expand All @@ -319,7 +327,7 @@
// Hide error message
alertDiv.style.display = "none";

const fileArray = [];
const fileArray: { data: string; address: number; encrypted: boolean }[] = [];
const progressBars = [];

for (let index = 1; index < table.rows.length; index++) {
Expand All @@ -328,16 +336,19 @@
const offSetObj = row.cells[0].childNodes[0] as HTMLInputElement;
const offset = parseInt(offSetObj.value);

const fileObj = row.cells[1].childNodes[0] as ChildNode & { data: string };
const progressBar = row.cells[2].childNodes[0];
const encryptedObj = row.cells[1].childNodes[0] as HTMLInputElement;
const encryptFlag = encryptedObj.checked;

const fileObj = row.cells[2].childNodes[0] as ChildNode & { data: string };

const progressBar = row.cells[3].childNodes[0];
progressBar.textContent = "0";
progressBars.push(progressBar);

row.cells[2].style.display = "initial";
row.cells[3].style.display = "none";
row.cells[3].style.display = "initial";
row.cells[4].style.display = "none";

fileArray.push({ data: fileObj.data, address: offset });
fileArray.push({ data: fileObj.data, address: offset, encrypted: encryptFlag });
}

try {
Expand All @@ -353,13 +364,13 @@
} as FlashOptions;
await esploader.writeFlash(flashOptions);
} catch (e) {
console.error(e);

Check warning on line 367 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
} finally {
// Hide progress bars and show erase buttons
for (let index = 1; index < table.rows.length; index++) {
table.rows[index].cells[2].style.display = "none";
table.rows[index].cells[3].style.display = "initial";
table.rows[index].cells[3].style.display = "none";
table.rows[index].cells[4].style.display = "initial";
}
}
};
Expand Down
Loading
Loading