From 787880f797891cd19669527cf23a49807953f6d5 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Fri, 21 Jul 2023 11:15:39 -0500 Subject: [PATCH 01/15] cleanup 2 at nxp/master --- webusb/src/components/Combined.js | 18 ++++-------------- webusb/src/components/Decompress.js | 26 ++++++++++++++++++++++++++ webusb/src/helper/sparse.js | 6 ++---- webusb/src/logic/useUSBFlash.js | 3 +-- 4 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 webusb/src/components/Decompress.js diff --git a/webusb/src/components/Combined.js b/webusb/src/components/Combined.js index e52427ef..75214035 100644 --- a/webusb/src/components/Combined.js +++ b/webusb/src/components/Combined.js @@ -1,4 +1,3 @@ -import {useEffect, useState} from 'react'; import ProgressBar from './ProgressBar'; import useHIDBoot from '../logic/useHIDBoot'; import useUSBFlash from '../logic/useUSBFlash' @@ -7,20 +6,9 @@ import imgSrc from '../images/imx8qxp_mek_bootmode.png' import "./Combined.css" const Combined = ({bootFile, flashFile}) => { - // const [imgUrl, setImgUrl] = useState(); - const [{ requestHIDDevice, HIDdevice, bootProgress, bootTotal }] = useHIDBoot(bootFile); const [{ requestUSBDevice, USBDevice, flashProgress, flashTotal}] = useUSBFlash(flashFile); - // useEffect(() => { - // const dothis = async()=>{ - // const response = await fetch("mode"); - // const blob = await response.blob(); - // setImgUrl(URL.createObjectURL(blob)); - // } - // dothis(); - // }, []) - return(
diff --git a/webusb/src/components/Decompress.js b/webusb/src/components/Decompress.js new file mode 100644 index 00000000..57d18621 --- /dev/null +++ b/webusb/src/components/Decompress.js @@ -0,0 +1,26 @@ +import { useEffect, useState } from "react" +import useDecompress from '../logic/useDecompress' +import { DATA_SZ, BLK_SZ, PACKET_SZ } from "../helper/sparse"; + +const Decompress = () => { + const [flashFile, setFlashFile] = useState(); + const [{ + requestUSBDevice + }] = useDecompress(flashFile); + + useEffect(()=> { + console.log(ZstdCodec) + console.log(window.binding); + }, []) + + return ( +
+ file to decompress: + setFlashFile(e.target.files[0])}/> + + +
+ ) +} + +export default Decompress diff --git a/webusb/src/helper/sparse.js b/webusb/src/helper/sparse.js index cf454acf..7e59eca9 100644 --- a/webusb/src/helper/sparse.js +++ b/webusb/src/helper/sparse.js @@ -79,14 +79,12 @@ export function build_chunk_header (chunk_type, raw_data_bytelength, i) { } if (chunk_type === CHUNK_TYPE_DONT_CARE) { - chunk_format.chunk_sz = CHUNK_SZ * i; // don't care + chunk_format.chunk_sz = CHUNK_SZ * i; chunk_format.total_sz = CHUNK_SZ*BLK_SZ * i + CHUNK_HEADER_SZ; // bytes raw_data + header } - else if (chunk_type === CHUNK_TYPE_RAW) { // raw_data + else if (chunk_type === CHUNK_TYPE_RAW) { chunk_format.chunk_sz = Math.ceil(raw_data_bytelength/BLK_SZ); chunk_format.total_sz = raw_data_bytelength + CHUNK_HEADER_SZ; - - console.log(chunk_format) } return obj_to_arr(chunk_format, chunk_header, CHUNK_HEADER_SZ); diff --git a/webusb/src/logic/useUSBFlash.js b/webusb/src/logic/useUSBFlash.js index 30e757e3..bc33cfe2 100644 --- a/webusb/src/logic/useUSBFlash.js +++ b/webusb/src/logic/useUSBFlash.js @@ -31,7 +31,7 @@ import {useEffect, useState} from 'react'; import {str_to_arr, ab_to_str} from '../helper/functions.js' -import {CHUNK_SZ, BLK_SZ, CHUNK_TYPE_RAW, CHUNK_TYPE_DONT_CARE, build_sparse_header, build_chunk_header} from '../helper/sparse.js' +import {CHUNK_SZ, BLK_SZ, PACKET_SZ, CHUNK_TYPE_RAW, CHUNK_TYPE_DONT_CARE, build_sparse_header, build_chunk_header} from '../helper/sparse.js' const USBrequestParams = { filters: [{ vendorId: 8137, productId: 0x0152 }] }; @@ -77,7 +77,6 @@ const useUSBFlash = (flashFile) => { const doFlash = async () => { // downloads and splits image into chunks to be processed - const PACKET_SZ = 0x10000; const DATA_SZ = CHUNK_SZ * BLK_SZ; // in bytes if (flashFile===null) {return;} From 08b5fd6dfc8b946b39db28db1dda8f6f65ed7373 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 20 Jul 2023 15:10:11 -0500 Subject: [PATCH 02/15] webusb: add zstd decompress support for wic image --- .gitignore | 3 +- webusb/index.js | 2 + webusb/package.json | 19 +- webusb/public/index.html | 6 + webusb/src/App.js | 4 + webusb/src/index.js | 1 + webusb/src/logic/useDecompress.js | 293 ++++++++++++++++++++++++++++++ 7 files changed, 318 insertions(+), 10 deletions(-) create mode 100644 webusb/index.js create mode 100644 webusb/src/logic/useDecompress.js diff --git a/.gitignore b/.gitignore index 9c22502f..c8b87a88 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ CMakeCache.txt *.clst *.snap node_modules -build \ No newline at end of file +build +*-lock.json \ No newline at end of file diff --git a/webusb/index.js b/webusb/index.js new file mode 100644 index 00000000..82d6e3bd --- /dev/null +++ b/webusb/index.js @@ -0,0 +1,2 @@ +window.ZstdCodec = require('zstd-codec').ZstdCodec; +require("zstd-codec/lib/module.js").run((binding) => {console.log("running", binding); window.binding = binding} ) diff --git a/webusb/package.json b/webusb/package.json index befb1d02..1b5db90e 100644 --- a/webusb/package.json +++ b/webusb/package.json @@ -3,26 +3,24 @@ "version": "0.1.0", "private": true, "dependencies": { + "-": "^0.0.1", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", + "fs": "^0.0.1-security", + "g": "^2.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "^5.0.1", - "web-vitals": "^2.1.4" + "web-vitals": "^2.1.4", + "zstd-codec": "^0.1.4" }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "react-scripts build; browserify index.js -o build/bundle.js -t babelify --presets es2015; ", "test": "react-scripts test", "eject": "react-scripts eject" }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, "browserslist": { "production": [ ">0.2%", @@ -35,5 +33,8 @@ "last 1 safari version" ] }, - "proxy": "http://localhost:5000" + "devDependencies": { + "@babel/core": "^7.22.9", + "babelify": "^10.0.0" + } } diff --git a/webusb/public/index.html b/webusb/public/index.html index 690b31d0..2ded04a7 100644 --- a/webusb/public/index.html +++ b/webusb/public/index.html @@ -25,8 +25,14 @@ Learn how to configure a non-root public URL by running `npm run build`. --> React App + + +

Sample Applications

+
+ +
React App + + +

Sample Applications

+
+ +