Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bongbui321 committed Mar 23, 2024
1 parent de5b04c commit 0bbb096
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion public/static/detach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

config="1.0"
device=$(lsusb | egrep 05c6:9008)
device=$(lsusb | grep 05c6:9008)
if [ -z "$device" ]; then
echo "Error: No device found"
exit 1
Expand Down
1 change: 0 additions & 1 deletion src/QDL/firehose.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class response {

class cfg {
constructor() {
this.TargetName = "";
this.ZLPAwareHost = 1;
this.SkipStorageInit = 0;
this.SkipWrite = 0;
Expand Down
1 change: 1 addition & 0 deletions src/QDL/qdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export function useQdl() {
async function unpackImages() {
for await (const [image, onProgress] of withProgress(manifest.current, setProgress)) {
setMessage(`Unpacking ${image.name}`)
if (image.name == "system") continue;
await imageWorker.current.unpackImage(image, Comlink.proxy(onProgress))
}
}
Expand Down
40 changes: 13 additions & 27 deletions src/QDL/sahara.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@ import config from "@/config"
export class Sahara {
constructor(cdc) {
this.cdc = cdc;
this.pktSize = null;
this.version = null;
this.ch = new CommandHandler();
this.programmer = "6000000000010000_f8ab20526358c4fa_fhprg.bin";
this.id = null;
this.serial = "";
this.mode = "";
this.rootDir = null;
this.rootDir = null;
}


async connect() {
let v = await this.cdc?.read(0xC * 0x4);
const v = await this.cdc?.read(0xC * 0x4);
if (v.length > 1) {
if (v[0] == 0x01) {
let pkt = this.ch.pkt_cmd_hdr(v);
if (pkt.cmd === cmd_t.SAHARA_HELLO_REQ) {
let rsp = this.ch.pkt_hello_req(v);
this.pktSize = rsp.cmd_packet_length;
this.version = rsp.version;
const rsp = this.ch.pkt_hello_req(v);
return { "mode" : "sahara", "cmd" : cmd_t.SAHARA_HELLO_REQ, "data" : rsp };
}
}
Expand All @@ -35,31 +31,20 @@ export class Sahara {


async cmdHello(mode, version=2, version_min=1, max_cmd_len=0) {
let cmd = cmd_t.SAHARA_HELLO_RSP;
let len = 0x30;
const cmd = cmd_t.SAHARA_HELLO_RSP;
const len = 0x30;
const elements = [cmd, len, version, version_min, max_cmd_len, mode, 1, 2, 3, 4, 5, 6];
const responseData = packGenerator(elements);

try {
await this.cdc?.write(responseData);
return true;
} catch (error) {
console.log(`${error}`);
return false;
}
await this.cdc?.write(responseData);
return true;
}


async cmdModeSwitch(mode) {
const elements = [cmd_t.SAHARA_SWITCH_MODE, 0xC, mode];
let data = packGenerator(elements);

try {
await this.cdc?.write(data);
return true;
} catch (error) {
throw new Error(`Sahara - ${error}`);
}
await this.cdc?.write(data);
return true;
}


Expand Down Expand Up @@ -119,15 +104,16 @@ export class Sahara {

async cmdGetSerialNum() {
let res = await this.cmdExec(exec_cmd_t.SAHARA_EXEC_CMD_SERIAL_NUM_READ);
if (res === null)
throw new Error("Sahara - Unable to get serial number of device");
let data = new DataView(res.buffer, 0).getUint32(0, true);
return data.toString(16).padStart(8, '0');
}


async enterCommandMode() {
if (!await this.cmdHello(sahara_mode_t.SAHARA_MODE_COMMAND)) {
if (!await this.cmdHello(sahara_mode_t.SAHARA_MODE_COMMAND))
return false;
}
let res = await this.getResponse();
if (res.hasOwnProperty("cmd")) {
if (res["cmd"] === cmd_t.SAHARA_END_TRANSFER) {
Expand Down Expand Up @@ -273,7 +259,7 @@ export class Sahara {
}
}
} else {
throw new Error("Sahara - Received invalid resposne");
throw new Error("Sahara - Received invalid response");
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/QDL/sparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const CHUNK_HEADER_SIZE = 12;
const MAX_DOWNLOAD_SIZE = 1024 * 1024 * 1024; // 1 GiB

const ChunkType = {
Raw : 0xCAC1,
Fill : 0xCAC2,
Skip : 0xCAC3,
Raw : 0xCAC1,
Fill : 0xCAC2,
Skip : 0xCAC3,
Crc32 : 0xCAC4,
}


class QCSparse {
constructor(blob, header) {
this.blob = blob;
this.blk_sz = header.blk_sz;
this.blob = blob;
this.blk_sz = header.blk_sz;
this.total_chunks = header.total_chunks;
this.blobOffset = 0;
this.blobOffset = 0;
}


Expand Down Expand Up @@ -178,7 +178,7 @@ function calcChunksRealDataBytes(chunk, blockSize) {
case ChunkType.Crc32:
return 0;
default:
return null;
throw new Error("Sparse - Unknown chunk type");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/QDL/usblib.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class usbClass {
await this.device?.reset();
await this.device?.forget();
await this.device?.close();
throw new Error(`USB - ${error}`);
console.error(error);
}
} catch (error) {
throw new Error(`USB - ${error}`);
Expand Down

0 comments on commit 0bbb096

Please sign in to comment.