├── wrapper ├── requirements.txt ├── requirements_dev.txt ├── triplets │ └── x64-windows-sd.cmake ├── MANIFEST.in ├── tests │ └── __init__.py ├── vcpkg.json ├── vcpkg-configuration.json ├── libuuu │ └── __init__.py ├── CMakePresets.json ├── LICENSE ├── .gitignore ├── README.md ├── build_backend.py ├── CMakeLists.txt └── pyproject.toml ├── snap ├── hooks │ ├── post-refresh │ └── configure ├── gui │ └── universal-update-utility.png ├── local │ ├── screenshots │ │ └── carbon-help.png │ ├── bash-completion │ │ └── universal-update-utility │ ├── LICENSE │ └── launchers │ │ └── universal-update-utility-launch └── snapcraft.yaml ├── webusb ├── public │ ├── robots.txt │ ├── manifest.json │ └── index.html ├── src │ ├── images │ │ └── imx8qxp_mek_bootmode.png │ ├── setupTests.js │ ├── App.test.js │ ├── index.css │ ├── reportWebVitals.js │ ├── components │ │ ├── Combined.css │ │ ├── ProgressBar.js │ │ └── Combined.js │ ├── index.js │ ├── App.css │ ├── logic │ │ ├── usePopup.js │ │ ├── usePopupContent.js │ │ └── useHIDBoot.js │ ├── helper │ │ ├── functions.js │ │ └── sparse.js │ └── App.js ├── package.json └── README.md ├── uuu ├── gen_txt_include.sh ├── fat_write.lst ├── spl_boot.lst ├── sd_burn_loader.lst ├── emmc_burn_loader.lst ├── nvme_burn_all.lst ├── fspinand_burn_loader.lst ├── sd_burn_all.lst ├── nand_burn_loader.lst ├── emmc_burn_all.lst ├── qspi_burn_loader.lst ├── CMakeLists.txt ├── buildincmd.h └── uuu.lst ├── .gitignore ├── libusb.prop ├── msvc ├── createversion.bat ├── tinyxml2.vcxproj.filters ├── libuuu.filters ├── uuu.vcxproj.filters ├── bzip2.vcxproj.filters ├── zlib.vcxproj.filters └── libuuu.vcxproj.filters ├── .gitmodules ├── Doxyfile.in ├── libuuu ├── gen_ver.sh ├── bmap.h ├── liberror.h ├── backfile.h ├── CMakeLists.txt ├── sparse.h ├── sdps.h ├── http.h ├── config.h ├── sparse_format.h ├── tar.h ├── version.cpp ├── error.cpp ├── notify.cpp ├── hidreport.h ├── rominfo.h ├── fat.h ├── hidreport.cpp ├── trans.h ├── tar.cpp ├── bmap.cpp ├── ffu_format.h ├── libcomm.h └── zip.h ├── .travis.yml ├── .github ├── scripts │ ├── common_functions.sh │ ├── build_macos.sh │ ├── build_linux.sh │ └── build_windows.bat └── workflows │ ├── doc.yaml │ ├── build.yaml │ ├── build_old_ubuntu.yaml │ ├── win.yaml │ ├── tar.yaml │ ├── macOS.yaml │ └── build_arm.yaml ├── CMakeLists.txt ├── LICENSE ├── SCR-mfgtools.txt ├── SBOM.spdx.json └── README.md /wrapper/requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /snap/hooks/post-refresh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | -------------------------------------------------------------------------------- /webusb/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /uuu/gen_txt_include.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "R\"####(" > $2 4 | cat $1 >> $2 5 | echo ")####\"" >> $2 6 | -------------------------------------------------------------------------------- /snap/gui/universal-update-utility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nxp-imx/mfgtools/HEAD/snap/gui/universal-update-utility.png -------------------------------------------------------------------------------- /snap/local/screenshots/carbon-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nxp-imx/mfgtools/HEAD/snap/local/screenshots/carbon-help.png -------------------------------------------------------------------------------- /wrapper/requirements_dev.txt: -------------------------------------------------------------------------------- 1 | # package management 2 | build 3 | bump-my-version 4 | twine 5 | # code quality 6 | nxp-codecheck -------------------------------------------------------------------------------- /webusb/src/images/imx8qxp_mek_bootmode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nxp-imx/mfgtools/HEAD/webusb/src/images/imx8qxp_mek_bootmode.png -------------------------------------------------------------------------------- /wrapper/triplets/x64-windows-sd.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE static) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | 5 | -------------------------------------------------------------------------------- /snap/local/bash-completion/universal-update-utility: -------------------------------------------------------------------------------- 1 | _uuu_autocomplete() 2 | { 3 | COMPREPLY=($(uuu $1 $2 $3)) 4 | } 5 | complete -o nospace -F _uuu_autocomplete uuu 6 | -------------------------------------------------------------------------------- /wrapper/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements* 2 | 3 | recursive-include libuuu * 4 | include build_backend.py 5 | 6 | recursive-exclude * __pycache__ 7 | recursive-exclude * *.py[co] 8 | 9 | -------------------------------------------------------------------------------- /wrapper/tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | ## Copyright 2025 NXP 4 | # 5 | # SPDX-License-Identifier: BSD-3-Clause 6 | 7 | """Unit test package for libuuu wrapper.""" 8 | -------------------------------------------------------------------------------- /wrapper/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | "libusb", 4 | "tinyxml2", 5 | "bzip2", 6 | "zstd", 7 | "zlib", 8 | "openssl" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | gitversion.h 4 | *.user 5 | .vs 6 | CMakeFiles 7 | *.cmake 8 | *.swp 9 | *.a 10 | *.so 11 | uuu/uuu 12 | Makefile 13 | CMakeCache.txt 14 | *.clst 15 | *.snap 16 | node_modules 17 | build -------------------------------------------------------------------------------- /webusb/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | ], 6 | "start_url": ".", 7 | "display": "standalone", 8 | "theme_color": "#000000", 9 | "background_color": "#ffffff" 10 | } 11 | -------------------------------------------------------------------------------- /webusb/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /libusb.prop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Level3 5 | false 6 | 7 | 8 | -------------------------------------------------------------------------------- /webusb/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /webusb/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /wrapper/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "47bf3d1ac192b3fa0feb6e6ac9c845de179eebe9", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /webusb/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /msvc/createversion.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | call git --version 4 | IF ERRORLEVEL 1 ( 5 | echo build from tarball 6 | ) ELSE ( 7 | IF "%APPVEYOR_BUILD_VERSION%" == "" ( 8 | echo build not from appveryor 9 | ) ELSE ( 10 | git tag -m "uuu %APPVEYOR_BUILD_VERSION%" uuu_%APPVEYOR_BUILD_VERSION% 11 | ) 12 | 13 | FOR /F "tokens=*" %%a in ('call git describe --long') do ( 14 | echo #define GIT_VERSION "lib%%a" > %1/gitversion.h 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /wrapper/libuuu/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | # 4 | # Copyright 2024-2025 NXP 5 | # 6 | # SPDX-License-Identifier: BSD-3-Clause 7 | 8 | """Wrapper for libuuu.""" 9 | 10 | from .__version__ import __version__ as version 11 | from .libuuu import LibUUU, UUUNotifyCallback, UUUShowConfig, UUUState 12 | 13 | __author__ = """NXP""" 14 | __version__ = version 15 | __all__ = ["LibUUU", "UUUNotifyCallback", "UUUShowConfig", "UUUState"] 16 | -------------------------------------------------------------------------------- /webusb/src/components/Combined.css: -------------------------------------------------------------------------------- 1 | .checkbox-container { 2 | width: 1rem; 3 | } 4 | 5 | .checkbox { 6 | margin:0; 7 | padding-right: 1rem; 8 | } 9 | 10 | .boot-image { 11 | width:100%; 12 | height:auto; 13 | border-radius: 50%; 14 | } 15 | 16 | .Popup-list { 17 | margin:0; 18 | padding-left: 1rem; 19 | list-style-position: outside; 20 | list-style-type: none; 21 | } 22 | 23 | .image-container { 24 | width: 8rem; 25 | height: 8rem; 26 | } -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libusb"] 2 | path = libusb 3 | url = https://github.com/libusb/libusb.git 4 | [submodule "zlib"] 5 | path = zlib 6 | url = https://github.com/madler/zlib.git 7 | [submodule "bzip2"] 8 | path = bzip2 9 | url = git://sourceware.org/git/bzip2.git 10 | [submodule "zstd"] 11 | path = zstd 12 | url = https://github.com/facebook/zstd.git 13 | [submodule "tinyxml2"] 14 | path = tinyxml2 15 | url = https://github.com/leethomason/tinyxml2.git 16 | branch = master 17 | -------------------------------------------------------------------------------- /uuu/fat_write.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.1.4 2 | 3 | # @_image | image, which cp to fat partition 4 | # @_device | storage device, mmc\sata 5 | # @_partition | fat partition number, like 1:1 6 | # @_filename [_image] | file name in target fat partition, only support rootdir now 7 | 8 | FB: ucmd setenv fastboot_buffer ${loadaddr} 9 | FB: download -f _image 10 | FB: ucmd if test ! -n "$fastboot_bytes"; then setenv fastboot_bytes $filesize; else true; fi 11 | FB[-t 20000]: ucmd fatwrite _device _partition ${fastboot_buffer} _filename ${fastboot_bytes} 12 | FB: done 13 | -------------------------------------------------------------------------------- /Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "uuu" 2 | PROJECT_BRIEF = "uuu (Universal Update Utility), mfgtools 3.0" 3 | DOXYFILE_ENCODING = UTF-8 4 | 5 | OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/docs/ 6 | INPUT = @CMAKE_CURRENT_SOURCE_DIR@/uuu/ @CMAKE_CURRENT_SOURCE_DIR@/libuuu/ 7 | RECURSIVE = YES 8 | 9 | EXTRACT_ALL = YES 10 | EXTRACT_PRIVATE = YES 11 | EXTRACT_PACKAGE = YES 12 | EXTRACT_STATIC = YES 13 | EXTRACT_LOCAL_CLASSES = YES 14 | EXTRACT_LOCAL_METHODS = YES 15 | 16 | CALL_GRAPH = YES 17 | CALLER_GRAPH = YES 18 | -------------------------------------------------------------------------------- /webusb/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /uuu/spl_boot.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 4 | SDP: boot -f _flash.bin 5 | 6 | # This command will be run when ROM support stream mode 7 | # i.MX8QXP, i.MX8QM 8 | SDPS[-t 10000]: boot -f _flash.bin 9 | 10 | # These commands will be run when use SPL and will be skipped if no spl 11 | # SDPU will be deprecated. please use SDPV instead of SDPU 12 | # { 13 | SDPU: delay 1000 14 | SDPU: write -f _flash.bin -offset 0x57c00 15 | SDPU: jump 16 | SDPU: done 17 | # } 18 | 19 | # These commands will be run when use SPL and will be skipped if no spl 20 | # if (SPL support SDPV) 21 | # { 22 | SDPV: delay 1000 23 | SDPV: write -f _flash.bin -skipspl 24 | SDPV: jump 25 | SDPV: done 26 | # } 27 | -------------------------------------------------------------------------------- /libuuu/gen_ver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Input parameters 4 | file_to_write="$1" 5 | 6 | set -e 7 | 8 | if [ -f ../.tarball-version ] 9 | then 10 | echo "#define GIT_VERSION \"lib$(cat ../.tarball-version)\"" > "$file_to_write" 11 | exit 0 12 | fi 13 | 14 | if [ "${APPVEYOR_BUILD_VERSION}" = "" ]; 15 | then 16 | echo build not in appveyor 17 | else 18 | git tag -m"uuu ${APPVEYOR_BUILD_VERSION}" uuu_${APPVEYOR_BUILD_VERSION} 19 | fi 20 | 21 | # Test if we are in a repo 22 | if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; 23 | then 24 | #echo "In a repo" 25 | # Get the version of the last commit of the repo 26 | version=`git describe --long` 27 | echo "#define GIT_VERSION \"lib$version\"" > $file_to_write 28 | fi 29 | -------------------------------------------------------------------------------- /wrapper/CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "configurePresets": [ 4 | { 5 | "name": "default", 6 | "hidden": true, 7 | "binaryDir": "${sourceDir}/build", 8 | "cacheVariables": { 9 | "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 10 | "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/triplets" 11 | } 12 | }, 13 | { 14 | "name": "windows", 15 | "generator": "Visual Studio 17 2022", 16 | "inherits": [ "default" ], 17 | "cacheVariables": { 18 | "VCPKG_TARGET_TRIPLET": "x64-windows-sd", 19 | "CMAKE_CXX_VERSION": "19.42" 20 | } 21 | }, 22 | { 23 | "name": "unix", 24 | "generator": "Ninja", 25 | "inherits": [ "default" ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /snap/hooks/configure: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configure hook to set up configuration when `snap set` is called 3 | # 4 | # Copyright (c) 2021 Snapcrafters 5 | 6 | # lint: The use of backticks in the printf messages is intended 7 | # shellcheck disable=SC2016 8 | 9 | set \ 10 | -o errexit \ 11 | -o errtrace \ 12 | -o nounset \ 13 | -o pipefail 14 | 15 | disable_snap_confinement_warnings="$(snapctl get disable-snap-confinement-warnings)" 16 | 17 | if test -n "${disable_snap_confinement_warnings}"; then 18 | if [[ ! "${disable_snap_confinement_warnings}" =~ (false|true) ]]; then 19 | printf -- \ 20 | 'Error: disable-snap-confinement-warnings must be either `true` or `false`.\n' \ 21 | 1>&2 22 | exit 1 23 | fi 24 | else 25 | snapctl set disable-snap-confinement-warnings=false 26 | fi 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c++ 2 | 3 | matrix: 4 | include: 5 | 6 | - os: osx 7 | osx_image: xcode9.4 8 | compiler: clang 9 | 10 | - os: osx 11 | osx_image: xcode9.4 12 | compiler: gcc 13 | 14 | - os: osx 15 | osx_image: xcode10.1 16 | compiler: clang 17 | 18 | - os: osx 19 | osx_image: xcode10.1 20 | compiler: gcc 21 | 22 | - os: osx 23 | osx_image: xcode11.6 24 | compiler: clang 25 | 26 | - os: osx 27 | osx_image: xcode11.6 28 | compiler: gcc 29 | 30 | addons: 31 | homebrew: 32 | update: true 33 | packages: 34 | - cmake 35 | - libusb 36 | - openssl 37 | - pkg-config 38 | 39 | script: 40 | - cmake -DOPENSSL_ROOT_DIR=$(brew --prefix)/opt/openssl . && make 41 | -------------------------------------------------------------------------------- /.github/scripts/common_functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | log_and_run() { 4 | echo "[INFO] $1" 5 | shift 6 | "$@" 7 | } 8 | 9 | dump_logs() { 10 | echo "=== DUMPING ALL AVAILABLE LOGS ===" 11 | 12 | # vcpkg logs 13 | if [ -d "/tmp/vcpkg/buildtrees" ]; then 14 | find /tmp/vcpkg/buildtrees -name "*.log" -print0 | while IFS= read -r -d '' logfile; do 15 | echo "=== LOG: $logfile ===" 16 | cat "$logfile" 2>/dev/null || echo "Could not read $logfile" 17 | echo "=== END LOG ===" 18 | done 19 | fi 20 | 21 | # Project build logs 22 | if [ -d "build" ]; then 23 | find build -name "*.log" -print0 | while IFS= read -r -d '' logfile; do 24 | echo "=== LOG: $logfile ===" 25 | cat "$logfile" 2>/dev/null || echo "Could not read $logfile" 26 | echo "=== END LOG ===" 27 | done 28 | fi 29 | } 30 | -------------------------------------------------------------------------------- /msvc/tinyxml2.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 7 | 8 | 9 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 10 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 11 | 12 | 13 | 14 | 15 | Header Files 16 | 17 | 18 | 19 | 20 | Source Files 21 | 22 | 23 | -------------------------------------------------------------------------------- /uuu/sd_burn_loader.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # @_flash.bin | bootloader 4 | # @_image [_flash.bin] | image burn to emmc, default is the same as bootloader 5 | 6 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 7 | SDP: boot -f _flash.bin 8 | 9 | # This command will be run when ROM support stream mode 10 | # i.MX8QXP, i.MX8QM 11 | SDPS: boot -f _flash.bin 12 | 13 | # These commands will be run when use SPL and will be skipped if no spl 14 | # SDPU will be deprecated. please use SDPV instead of SDPU 15 | # { 16 | SDPU: delay 1000 17 | SDPU: write -f _flash.bin -offset 0x57c00 18 | SDPU: jump 19 | # } 20 | 21 | # These commands will be run when use SPL and will be skipped if no spl 22 | # if (SPL support SDPV) 23 | # { 24 | SDPV: delay 1000 25 | SDPV: write -f _flash.bin -skipspl 26 | SDPV: jump 27 | # } 28 | 29 | FB: ucmd setenv fastboot_dev mmc 30 | FB: ucmd setenv mmcdev ${sd_dev} 31 | FB: ucmd mmc dev ${sd_dev} 32 | FB: flash bootloader _image 33 | FB: Done 34 | -------------------------------------------------------------------------------- /uuu/emmc_burn_loader.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # @_flash.bin | bootloader 4 | # @_image [_flash.bin] | image burn to emmc, default is the same as bootloader 5 | 6 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 7 | SDP: boot -f _flash.bin 8 | 9 | # This command will be run when ROM support stream mode 10 | # i.MX8QXP, i.MX8QM 11 | SDPS: boot -f _flash.bin 12 | 13 | # These commands will be run when use SPL and will be skipped if no spl 14 | # SDPU will be deprecated. please use SDPV instead of SDPU 15 | # { 16 | SDPU: delay 1000 17 | SDPU: write -f _flash.bin -offset 0x57c00 18 | SDPU: jump 19 | # } 20 | 21 | # These commands will be run when use SPL and will be skipped if no spl 22 | # if (SPL support SDPV) 23 | # { 24 | SDPV: delay 1000 25 | SDPV: write -f _flash.bin -skipspl 26 | SDPV: jump 27 | # } 28 | 29 | FB: ucmd setenv fastboot_dev mmc 30 | FB: ucmd setenv mmcdev ${emmc_dev} 31 | FB: ucmd mmc dev ${emmc_dev} 32 | FB: flash bootloader _image 33 | FB: ucmd if env exists emmc_ack; then ; else setenv emmc_ack 0; fi; 34 | FB: ucmd mmc partconf ${emmc_dev} ${emmc_ack} 1 0 35 | FB: Done 36 | -------------------------------------------------------------------------------- /webusb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "eslint": "^8.48.0", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-scripts": "^5.0.1", 13 | "web-vitals": "^2.1.4", 14 | "@types/w3c-web-serial": "^1.0.3", 15 | "web-serial-polyfill": "^1.0.14", 16 | "xterm": "^5.2.1", 17 | "xterm-addon-fit": "^0.7.0", 18 | "xterm-addon-web-links": "^0.8.0" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | }, 38 | "homepage": "/webuuu/" 39 | } 40 | -------------------------------------------------------------------------------- /snap/local/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Snapcrafters 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /uuu/nvme_burn_all.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.4.149 2 | 3 | # @_flash.bin | bootloader, which can extract from wic image 4 | # @_image [_flash.bin] | wic image burn to emmc. 5 | 6 | 7 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 8 | SDP: boot -f _flash.bin -scanlimited 0x800000 9 | 10 | # This command will be run when ROM support stream mode 11 | # i.MX8QXP, i.MX8QM 12 | SDPS: boot -scanterm -f _flash.bin -scanlimited 0x800000 13 | 14 | # These commands will be run when use SPL and will be skipped if no spl 15 | # SDPU will be deprecated. please use SDPV instead of SDPU 16 | # { 17 | SDPU: delay 1000 18 | SDPU: write -f _flash.bin -offset 0x57c00 19 | SDPU: jump -scanlimited 0x800000 20 | # } 21 | 22 | # These commands will be run when use SPL and will be skipped if no spl 23 | # if (SPL support SDPV) 24 | # { 25 | SDPV: delay 1000 26 | SDPV: write -f _flash.bin -skipspl -scanterm -scanlimited 0x800000 27 | SDPV: jump -scanlimited 0x800000 28 | # } 29 | 30 | FB: ucmd pci 31 | FB: ucmd nvme scan 32 | FB: ucmd setenv fastboot_buffer ${loadaddr} 33 | FB: write -format "nvme write ${fastboot_buffer} @off @size" -blksz 512 -f _image 34 | FB: done 35 | -------------------------------------------------------------------------------- /webusb/src/components/ProgressBar.js: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react'; 2 | 3 | const ProgressBar = (props) => { 4 | const [soFar, setSoFar] = useState(); 5 | const [total, setTotal] = useState(); 6 | 7 | const Parentdiv = { 8 | height: 20, 9 | width: '100%', 10 | backgroundColor: 'whitesmoke', 11 | } 12 | 13 | const Childdiv = { 14 | height: '100%', 15 | width: `${total? soFar/total*100: 0}%`, 16 | backgroundColor: 'green', 17 | textAlign: 'right' 18 | } 19 | 20 | useEffect(()=> { 21 | setTotal(props.total); 22 | setSoFar(props.soFar); 23 | }, [props]) 24 | 25 | return( 26 |
27 |
31 |
32 |
33 | { 34 | soFar&&total? 35 | (soFar===total? "Done": 36 | {soFar} out of {total} bytes downloaded):"" 37 | } 38 |
39 | ) 40 | } 41 | 42 | export default ProgressBar -------------------------------------------------------------------------------- /uuu/fspinand_burn_loader.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # @_flexspi.bin | bootloader 4 | # @_image [_flexspi.bin] | image burn to fspinand, default is the same as bootloader 5 | 6 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 7 | SDP: boot -f _flexspi.bin 8 | 9 | # This command will be run when ROM support stream mode 10 | # i.MX8QXP, i.MX8QM, skip QSPI header 11 | SDPS: boot -f _flexspi.bin -skipfhdr 12 | 13 | # These commands will be run when use SPL and will be skipped if no spl 14 | # SDPU will be deprecated. please use SDPV instead of SDPU 15 | # { 16 | SDPU: delay 1000 17 | SDPU: write -f _flexspi.bin -offset 0x10000 -skipfhdr 18 | SDPU: jump 19 | # } 20 | 21 | # These commands will be run when use SPL and will be skipped if no spl 22 | # if (SPL support SDPV) 23 | # { 24 | SDPV: delay 1000 25 | SDPV: write -f _flexspi.bin -skipspl -skipfhdr 26 | SDPV: jump 27 | # } 28 | 29 | FB: ucmd setenv fastboot_buffer ${loadaddr} 30 | FB: download -f _image 31 | 32 | FB: ucmd if test ! -n "$fastboot_bytes"; then setenv fastboot_bytes $filesize; else true; fi 33 | 34 | FB[-t 60000]: ucmd fspinand init spi-nand0 ${fastboot_buffer} ${fastboot_bytes} 35 | 36 | FB: done 37 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(uuu) 4 | 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_SKIP_RPATH ON) 8 | 9 | option(BUILD_DOC "Build documentation" OFF) 10 | 11 | add_subdirectory(libuuu) 12 | add_subdirectory(uuu) 13 | 14 | if (BUILD_DOC) 15 | # check if Doxygen is installed 16 | find_package(Doxygen) 17 | if (DOXYGEN_FOUND) 18 | # set input and output files 19 | set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) 20 | set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) 21 | 22 | # request to configure the file 23 | configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) 24 | message("Doxygen build started") 25 | 26 | # note the option ALL which allows to build the docs together with the application 27 | add_custom_target( doc_doxygen ALL 28 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} 29 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 30 | COMMENT "Generating documentation with Doxygen" 31 | VERBATIM ) 32 | else (DOXYGEN_FOUND) 33 | message("Doxygen need to be installed to generate the doxygen documentation") 34 | endif (DOXYGEN_FOUND) 35 | endif (BUILD_DOC) 36 | -------------------------------------------------------------------------------- /uuu/sd_burn_all.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.4.149 2 | 3 | # @_flash.bin | bootloader, which can extract from wic image 4 | # @_image [_flash.bin] | wic image burn to emmc. 5 | 6 | 7 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 8 | SDP: boot -f _flash.bin -scanlimited 0x800000 9 | 10 | # This command will be run when ROM support stream mode 11 | # i.MX8QXP, i.MX8QM 12 | SDPS: boot -scanterm -f _flash.bin -scanlimited 0x800000 13 | 14 | # These commands will be run when use SPL and will be skipped if no spl 15 | # SDPU will be deprecated. please use SDPV instead of SDPU 16 | # { 17 | SDPU: delay 1000 18 | SDPU: write -f _flash.bin -offset 0x57c00 -scanlimited 0x800000 19 | SDPU: jump -scanlimited 0x800000 20 | # } 21 | 22 | # These commands will be run when use SPL and will be skipped if no spl 23 | # if (SPL support SDPV) 24 | # { 25 | SDPV: delay 1000 26 | SDPV: write -f _flash.bin -skipspl -scanterm -scanlimited 0x800000 27 | SDPV: jump -scanlimited 0x800000 28 | # } 29 | 30 | FB: ucmd setenv fastboot_dev mmc 31 | FB: ucmd setenv mmcdev ${sd_dev} 32 | FB: ucmd mmc dev ${sd_dev} 33 | FB: flash -raw2sparse all _image 34 | FB: flash -scanterm -scanlimited 0x800000 bootloader _flash.bin 35 | FB: done 36 | -------------------------------------------------------------------------------- /msvc/libuuu.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /uuu/nand_burn_loader.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # @_flash.bin | bootloader 4 | # @_image [_flash.bin] | image burn to nand, default is the same as bootloader 5 | 6 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 7 | SDP: boot -f _flash.bin 8 | 9 | # This command will be run when ROM support stream mode 10 | # i.MX8QXP, i.MX8QM 11 | SDPS: boot -f _flash.bin 12 | 13 | # These commands will be run when use SPL and will be skipped if no spl 14 | # SDPU will be deprecated. please use SDPV instead of SDPU 15 | # { 16 | SDPU: delay 1000 17 | SDPU: write -f _flash.bin -offset 0x57c00 18 | SDPU: jump 19 | # } 20 | 21 | # These commands will be run when use SPL and will be skipped if no spl 22 | # if (SPL support SDPV) 23 | # { 24 | SDPV: delay 1000 25 | SDPV: write -f _flash.bin -skipspl 26 | SDPV: jump 27 | # } 28 | 29 | FB: ucmd setenv fastboot_buffer ${loadaddr} 30 | FB: download -f _image 31 | FB: ucmd if test ! -n "$fastboot_bytes"; then setenv fastboot_bytes $filesize; else true; fi 32 | # Burn image to nandfit partition if needed 33 | FB: ucmd if env exists nandfit_part; then nand erase.part nandfit; nand write ${fastboot_buffer} nandfit ${fastboot_bytes}; else true; fi; 34 | FB: ucmd nandbcb init ${fastboot_buffer} nandboot ${fastboot_bytes} 35 | FB: Done 36 | -------------------------------------------------------------------------------- /uuu/emmc_burn_all.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.4.149 2 | 3 | # @_flash.bin | bootloader, which can extract from wic image 4 | # @_image [_flash.bin] | wic image burn to emmc. 5 | 6 | 7 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 8 | SDP: boot -f _flash.bin -scanlimited 0x800000 9 | 10 | # This command will be run when ROM support stream mode 11 | # i.MX8QXP, i.MX8QM 12 | SDPS: boot -scanterm -f _flash.bin -scanlimited 0x800000 13 | 14 | # These commands will be run when use SPL and will be skipped if no spl 15 | # SDPU will be deprecated. please use SDPV instead of SDPU 16 | # { 17 | SDPU: delay 1000 18 | SDPU: write -f _flash.bin -offset 0x57c00 19 | SDPU: jump -scanlimited 0x800000 20 | # } 21 | 22 | # These commands will be run when use SPL and will be skipped if no spl 23 | # if (SPL support SDPV) 24 | # { 25 | SDPV: delay 1000 26 | SDPV: write -f _flash.bin -skipspl -scanterm -scanlimited 0x800000 27 | SDPV: jump -scanlimited 0x800000 28 | # } 29 | 30 | 31 | FB: ucmd setenv fastboot_dev mmc 32 | FB: ucmd setenv mmcdev ${emmc_dev} 33 | FB: ucmd mmc dev ${emmc_dev} 34 | FB: flash -raw2sparse all _image 35 | FB: flash -scanterm -scanlimited 0x800000 bootloader _flash.bin 36 | FB: ucmd if env exists emmc_ack; then ; else setenv emmc_ack 0; fi; 37 | FB: ucmd mmc partconf ${emmc_dev} ${emmc_ack} 1 0 38 | FB: done 39 | -------------------------------------------------------------------------------- /msvc/uuu.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /.github/scripts/build_macos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | ARCH="${1:-x86_64}" 5 | 6 | # Source common functions (same dump_logs function) 7 | source "$(dirname "$0")/common_functions.sh" 8 | 9 | main() { 10 | log_and_run "Installing pytest" \ 11 | python -m pip install pytest 12 | 13 | # Install build dependencies 14 | log_and_run "Installing build dependencies" \ 15 | brew install ninja cmake autoconf automake libtool 16 | 17 | export PROJECT_DIR=$(pwd) 18 | 19 | # Setup vcpkg 20 | log_and_run "Setting up vcpkg" setup_vcpkg 21 | 22 | # Build libuuu 23 | log_and_run "Building libuuu for $ARCH" build_libuuu "$ARCH" 24 | 25 | # Copy artifacts 26 | log_and_run "Copying artifacts" copy_artifacts "$ARCH" 27 | } 28 | 29 | setup_vcpkg() { 30 | cd /tmp 31 | git clone https://github.com/microsoft/vcpkg.git 32 | cd vcpkg 33 | ./bootstrap-vcpkg.sh || { 34 | echo "VCPKG BOOTSTRAP FAILED" 35 | dump_logs 36 | exit 1 37 | } 38 | export VCPKG_ROOT=/tmp/vcpkg 39 | export PATH=$VCPKG_ROOT:$PATH 40 | cd "$PROJECT_DIR/wrapper" 41 | } 42 | 43 | build_libuuu() { 44 | local arch="$1" 45 | cmake --preset=unix -DCMAKE_OSX_ARCHITECTURES="$arch" 46 | cmake --build build 47 | } 48 | 49 | copy_artifacts() { 50 | local arch="$1" 51 | mkdir -p "libuuu/lib/darwin/$arch/" 52 | cp build/libuuu.dylib "libuuu/lib/darwin/$arch/" 53 | } 54 | 55 | main "$@" 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 NXP. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the Freescale Semiconductor nor the names of its 15 | contributors may be used to endorse or promote products derived from this 16 | software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | -------------------------------------------------------------------------------- /wrapper/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | 3 | BSD License 4 | 5 | Copyright (c) 2024, NXP 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above copyright notice, this 15 | list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | * Neither the name of the copyright holder nor the names of its 19 | contributors may be used to endorse or promote products derived from this 20 | software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 29 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 | OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | -------------------------------------------------------------------------------- /webusb/src/App.css: -------------------------------------------------------------------------------- 1 | /* SplitLayout.css */ 2 | .split-layout { 3 | display: flex; /* Use Flexbox */ 4 | justify-content: space-between; /* Space between the columns */ 5 | align-items: stretch; /* Stretch columns to match height */ 6 | 7 | } 8 | 9 | .left-column, .right-column { 10 | flex: 1; /* Equal width for both columns */ 11 | padding: 20px; /* Add padding to the columns */ 12 | } 13 | 14 | .u-flex { 15 | display: flex; 16 | } 17 | 18 | .u-row { 19 | flex-direction: row; 20 | padding-bottom: 1rem; 21 | } 22 | .u-column { 23 | flex-direction: column; 24 | } 25 | 26 | .u-row-reverse { 27 | flex-direction: row-reverse; 28 | } 29 | 30 | .u-space-between { 31 | justify-content: space-between; 32 | } 33 | 34 | .u-center { 35 | justify-content: center; 36 | } 37 | 38 | .u-inline-block { 39 | display: inline-block; 40 | } 41 | 42 | .link-container{ 43 | display: inline-block; 44 | width : 8rem; 45 | } 46 | 47 | .popup-loc { 48 | position: relative; 49 | } 50 | 51 | .popup-container { 52 | background-color: white; 53 | position: absolute; 54 | display: inline-block; 55 | 56 | border: thin black solid; 57 | border-radius: 4px; 58 | 59 | padding: 1rem; 60 | width: 24rem; 61 | } 62 | 63 | .popup-container li { 64 | padding-bottom: 1rem; 65 | } 66 | 67 | .popup-button { 68 | width:2rem 69 | } 70 | 71 | .input { 72 | display: none; 73 | } 74 | 75 | .custom-file-upload { 76 | border: thin black solid; 77 | border-radius: 4px; 78 | cursor: pointer; 79 | } 80 | 81 | .file-name { 82 | display: inline-block; 83 | width: 32rem; 84 | } 85 | -------------------------------------------------------------------------------- /.github/scripts/build_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | ARCH="${1:-x86_64}" 5 | 6 | # Source common functions (same dump_logs function) 7 | source "$(dirname "$0")/common_functions.sh" 8 | 9 | main() { 10 | log_and_run "Installing pytest" \ 11 | python -m pip install pytest 12 | 13 | # Install build dependencies 14 | log_and_run "Installing build dependencies" \ 15 | yum install -y git cmake3 ninja-build gcc-c++ libudev-devel \ 16 | autoconf automake libtool curl zip unzip tar \ 17 | perl-core kernel-headers make 18 | 19 | # Setup vcpkg 20 | log_and_run "Setting up vcpkg" setup_vcpkg 21 | 22 | # Build libuuu 23 | log_and_run "Building libuuu" build_libuuu 24 | 25 | # Copy artifacts 26 | log_and_run "Copying artifacts" copy_artifacts "$ARCH" 27 | } 28 | 29 | setup_vcpkg() { 30 | cd /tmp 31 | git clone https://github.com/microsoft/vcpkg.git 32 | cd vcpkg 33 | ./bootstrap-vcpkg.sh || { 34 | echo "VCPKG BOOTSTRAP FAILED" 35 | dump_logs 36 | exit 1 37 | } 38 | export VCPKG_ROOT=/tmp/vcpkg 39 | export PATH=$VCPKG_ROOT:$PATH 40 | cd /project/wrapper 41 | } 42 | 43 | build_libuuu() { 44 | cmake --preset=unix 45 | cmake --build build 46 | } 47 | 48 | copy_artifacts() { 49 | local arch="$1" 50 | mkdir -p "libuuu/lib/linux/$arch/" 51 | cp build/libuuu.so "libuuu/lib/linux/$arch/" 52 | mkdir -p "/output/libuuu/lib/linux/$arch/" 53 | cp build/libuuu.so "/output/libuuu/lib/linux/$arch/" 54 | echo "[INFO] Copied libuuu.so to /output/libuuu/lib/linux/$arch/" 55 | } 56 | 57 | main "$@" 58 | -------------------------------------------------------------------------------- /SCR-mfgtools.txt: -------------------------------------------------------------------------------- 1 | 2 | Package: mfgtools.git 3 | Version: 3 4 | Outgoing License: BSD-3-Clause 5 | License File: LICENSE 6 | Type of Content: source 7 | Description and comments: NXP I.MX Chip image deploy tools. Use uuu. 8 | Release Location: https://github.com/NXPmicro/mfgtools -b master 9 | Origin: NXP (BSD-3-clause) 10 | zlib (zlib) - https://github.com/madler/zlib 11 | libusb (LGPL-2.1) - https://github.com/libusb/libusb.git 12 | Android Open Source Project (Apache-2.0) [sparse_format.h] - https://developer.android.com/ 13 | 14 | Generated Binary: uuu, uuu.exe, uuu_mac 15 | Outgoing License: BSD-3-Clause 16 | Description and comments: NXP I.MX Chip image deploy tools 17 | Release Location: https://github.com/NXPmicro/mfgtools/releases 18 | Origin: NXP (BSD-3-clause) 19 | bzip2 (BSD-4-Clause) - https://github.com/enthought/bzip2-1.0.6 20 | zlib (zlib) - https://github.com/madler/zlib 21 | zstd (BSD-3-clause) - https://github.com/facebook/zstd 22 | libusb (LGPL-2.1) - https://github.com/libusb/libusb.git 23 | Android Open Source Project (Apache-2.0) [sparse_format.h] - https://developer.android.com/ 24 | snapcraft.yaml allows uuu to be built by snap (MIT) - https://snapcraft.io/ 25 | create-react-app (MIT) - https://github.com/facebook/create-react-app/ 26 | -------------------------------------------------------------------------------- /.github/workflows/doc.yaml: -------------------------------------------------------------------------------- 1 | name: Build pdf document 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | name: Build for pdf 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | repository: nxp-imx/mfgtools.wiki.git 25 | path: wiki 26 | ref: master 27 | 28 | - name: Set up environment 29 | run: | 30 | sudo apt-get update 31 | sudo DEBIAN_FRONTEND=noninteractive apt-get --yes --force-yes install asciidoc rename 32 | 33 | - name: Build 34 | run: | 35 | cd wiki 36 | rename -f 's/\.asciidoc$//' * 37 | echo "" > UUU-docinfo.xml 38 | git log -n25 --reverse --format="format:%h%cd%an%s" >> UUU-docinfo.xml 39 | echo "" >> UUU-docinfo.xml 40 | a2x -L -a docinfo UUU 41 | 42 | - name: Upload Build Artifacts 43 | uses: actions/upload-artifact@v4 44 | with: 45 | name: UUU.pdf 46 | path: wiki/UUU.pdf 47 | 48 | - name: Create or Update Release 49 | if: github.ref_type == 'tag' 50 | uses: ncipollo/release-action@v1 51 | with: 52 | name: Release ${{ github.ref_name }} 53 | tag: ${{ github.ref_name }} 54 | commit: ${{ github.sha }} 55 | allowUpdates: true 56 | prerelease: true 57 | artifacts: "wiki/UUU.pdf" 58 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build for x64 ubuntu 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | name: Build for x64 ubuntu 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | matrix: 20 | os: 21 | - ubuntu-22.04 22 | - ubuntu-24.04 23 | 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@v3 27 | with: 28 | fetch-depth: 0 29 | 30 | - name: Set up environment 31 | run: sudo DEBIAN_FRONTEND=noninteractive apt-get --yes --force-yes install libusb-1.0-0-dev libbz2-dev libzstd-dev libtinyxml2-dev 32 | 33 | - name: Build 34 | run: | 35 | git fetch --tags --force # Retrieve annotated tags. #issue 290 36 | if [ "${{ matrix.os }}" == "ubuntu-22.04" ]; then git submodule update --init tinyxml2; cd tinyxml2; cmake .; make; cd ..; fi; 37 | if [ "${{ matrix.os }}" == "ubuntu-22.04" ]; then cmake -D 'STATIC=1' -D 'FORCE_OLD=on' . ; else cmake .; fi; 38 | make 39 | 40 | - name: Upload Build Artifacts 41 | if: matrix.os == 'ubuntu-22.04' 42 | uses: actions/upload-artifact@v4 43 | with: 44 | name: uuu 45 | path: ./uuu/uuu 46 | 47 | - name: Create or Update Release 48 | if: matrix.os == 'ubuntu-22.04' && github.ref_type == 'tag' 49 | uses: ncipollo/release-action@v1 50 | with: 51 | name: Release ${{ github.ref_name }} 52 | tag: ${{ github.ref_name }} 53 | commit: ${{ github.sha }} 54 | allowUpdates: true 55 | prerelease: true 56 | artifacts: "./uuu/uuu" 57 | -------------------------------------------------------------------------------- /libuuu/bmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct bmap_t { 7 | using bmap_type = std::vector>; 8 | 9 | bmap_t() = default; 10 | // fully mapped image 11 | bmap_t(size_t img_size, size_t blk_size = 4096) 12 | : m_img_size(img_size), 13 | m_blk_size(blk_size), 14 | m_blk_count(default_blocks_count(img_size, blk_size)) 15 | { 16 | set_mapped_range(0, m_blk_count - 1); 17 | } 18 | 19 | bmap_t& set_image_size(size_t size) { 20 | m_img_size = size; 21 | return *this; 22 | } 23 | 24 | bmap_t& set_block_size(size_t size = 4096) { 25 | m_blk_size = size; 26 | return *this; 27 | } 28 | 29 | bmap_t& set_blocks_count(size_t size = 0) { 30 | if (size) 31 | m_blk_count = size; 32 | else 33 | m_blk_count = default_blocks_count(m_img_size, m_blk_size); 34 | return *this; 35 | } 36 | 37 | bmap_t& set_mapped_range(size_t begin, size_t end) { 38 | m_blk_map.emplace_back(begin, end); 39 | return *this; 40 | } 41 | 42 | static size_t default_blocks_count(size_t img_size, size_t blk_size) { 43 | return img_size / blk_size + (img_size % blk_size ? 1 : 0); 44 | } 45 | 46 | size_t image_size() const { return m_img_size; } 47 | size_t block_size() const { return m_blk_size; } 48 | size_t blocks_count() const { return m_blk_count; } 49 | 50 | const bmap_type& mapped_ranges() const { return m_blk_map; } 51 | 52 | bool is_mapped_block(size_t index) const; 53 | 54 | private: 55 | size_t m_img_size = 0; 56 | size_t m_blk_size = 4096; 57 | size_t m_blk_count = 0; 58 | bmap_type m_blk_map; 59 | mutable bool m_gap_set = false; 60 | mutable size_t m_gap_begin = 0; 61 | mutable size_t m_gap_end = 0; 62 | mutable size_t m_next_gap_begin = 0; 63 | }; 64 | 65 | int load_bmap(const std::string& filename, bmap_t& bmap); 66 | -------------------------------------------------------------------------------- /libuuu/liberror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | 36 | void set_last_err_string(const std::string &str); 37 | void set_last_err_id(int id); 38 | 39 | #define ERR_OUT_MEMORY -2 40 | #define ERR_ACCESS_DENIED -3 41 | -------------------------------------------------------------------------------- /.github/workflows/build_old_ubuntu.yaml: -------------------------------------------------------------------------------- 1 | name: Build for old ubuntu 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | name: Build with Ubuntu 20.04 Docker 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | 25 | - name: Build 26 | run: | 27 | git fetch --tags --force # Retrieve annotated tags. #issue 290 28 | git submodule update --init tinyxml2; 29 | 30 | docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace -e DEBIAN_FRONTEND=noninteractive -e TZ=UTC ubuntu:20.04 bash -c " 31 | apt-get update && 32 | apt-get --yes --force-yes install libusb-1.0-0-dev libbz2-dev libzstd-dev pkg-config cmake libssl-dev g++ zlib1g-dev git libtinyxml2-dev 33 | git config --global --add safe.directory /workspace && 34 | cd tinyxml2 && cmake . && make && cd .. && 35 | cmake -D 'STATIC=1' -D 'FORCE_OLD=on' . && make" 36 | 37 | - name: Copy 38 | run: | 39 | cp ./uuu/uuu ./uuu/uuu-ubuntu20.04 40 | 41 | - name: Upload Build Artifacts 42 | uses: actions/upload-artifact@v4 43 | with: 44 | name: uuu-ubuntu-20.04 45 | path: ./uuu/uuu-ubuntu20.04 46 | 47 | - name: Create or Update Release 48 | uses: ncipollo/release-action@v1 49 | with: 50 | name: Release ${{ github.ref_name }} 51 | tag: ${{ github.ref_name }} 52 | commit: ${{ github.sha }} 53 | allowUpdates: true 54 | prerelease: true 55 | artifacts: "./uuu/uuu-ubuntu20.04" 56 | -------------------------------------------------------------------------------- /libuuu/backfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | 36 | class Backfile 37 | { 38 | public: 39 | const std::string& get_filename() const noexcept { return m_filename; } 40 | 41 | protected: 42 | std::string m_filename; 43 | }; 44 | -------------------------------------------------------------------------------- /wrapper/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | *.dll 9 | 10 | # Generated files 11 | libuuu/__version__.py 12 | 13 | # Distribution / packaging 14 | outputs/ 15 | .Python 16 | env/ 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | reports 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # pyenv 81 | .python-version 82 | 83 | # celery beat schedule file 84 | celerybeat-schedule 85 | 86 | # SageMath parsed files 87 | *.sage.py 88 | 89 | # dotenv 90 | .env 91 | 92 | # virtualenv 93 | .venv 94 | venv/ 95 | ENV/ 96 | 97 | # Spyder project settings 98 | .spyderproject 99 | .spyproject 100 | 101 | # Rope project settings 102 | .ropeproject 103 | 104 | # mkdocs documentation 105 | /site 106 | 107 | # mypy 108 | .mypy_cache/ 109 | 110 | # IDE settings 111 | .vscode/ 112 | -------------------------------------------------------------------------------- /webusb/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.github/workflows/win.yaml: -------------------------------------------------------------------------------- 1 | name: Build with VS Studio 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | runs-on: windows-2022 17 | 18 | strategy: 19 | matrix: 20 | configuration: ['Debug', 'Release'] 21 | platform: ['x86', 'x64'] 22 | 23 | steps: 24 | - name: Checkout code 25 | uses: actions/checkout@v3 26 | with: 27 | fetch-depth: 0 28 | submodules: true 29 | 30 | - name: Set up Visual Studio 31 | uses: microsoft/setup-msbuild@v1.1 32 | 33 | - name: Build static solution 34 | run: | 35 | git fetch --tags --force # Retrieve annotated tags. #issue 290 36 | msbuild /p:Configuration=${{ matrix.configuration }} /p:PlatformToolset=v143 /p:Platform=${{ matrix.platform }} /p:ForceImportBeforeCppTargets=${{ github.workspace }}/libusb.prop msvc/uuu-static-link.sln 37 | 38 | - name: Upload Build Artifacts 39 | if: matrix.configuration == 'Release' && matrix.platform == 'x64' 40 | uses: actions/upload-artifact@v4 41 | with: 42 | name: uuu.exe 43 | path: msvc/x64/Release/uuu.exe 44 | 45 | - name: Create or Update Release 46 | if: matrix.configuration == 'Release' && matrix.platform == 'x64' && github.ref_type == 'tag' 47 | uses: ncipollo/release-action@v1 48 | with: 49 | name: Release ${{ github.ref_name }} 50 | tag: ${{ github.ref_name }} 51 | commit: ${{ github.sha }} 52 | allowUpdates: true 53 | prerelease: true 54 | artifacts: msvc/x64/Release/uuu.exe 55 | 56 | - name: Build dynamic solution 57 | run: msbuild /p:Configuration=${{ matrix.configuration }} /p:PlatformToolset=v143 /p:Platform=${{ matrix.platform }} /p:ForceImportBeforeCppTargets=${{ github.workspace }}/libusb.prop msvc/uuu.sln 58 | -------------------------------------------------------------------------------- /libuuu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | set(CMAKE_CXX_STANDARD 14) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | set(CMAKE_SKIP_RPATH ON) 6 | 7 | find_package(BZip2 REQUIRED) 8 | find_package(PkgConfig REQUIRED) 9 | pkg_check_modules(LIBUSB REQUIRED libusb-1.0>=1.0.16) 10 | pkg_check_modules(LIBZSTD REQUIRED libzstd) 11 | find_package(Threads) 12 | pkg_check_modules(TINYXML2 REQUIRED tinyxml2) 13 | 14 | if (STATIC) 15 | set(OPENSSL_USE_STATIC_LIBS TRUE) 16 | endif() 17 | 18 | find_package(OpenSSL) 19 | 20 | if(OPENSSL_FOUND) 21 | set(UUUSSL "-DUUUSSL") 22 | set(UUUOPENSLL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) 23 | endif() 24 | 25 | include_directories(${LIBUSB_INCLUDE_DIRS} ${LIBZSTD_INCLUDE_DIRS} ${UUUOPENSLL_INCLUDE_DIR} ${TINYXML2_INCLUDE_DIRS} include) 26 | 27 | 28 | if (FORCE_OLD) 29 | set(FORCE_OLDLIBUSB "-DFORCE_OLDLIBUSB") 30 | endif() 31 | 32 | set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wstrict-aliasing -Wextra ${UUUSSL} ${FORCE_OLDLIBUSB}") 33 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UUUSSL} ${FORCE_OLDLIBUSB}") 34 | 35 | set(SOURCES 36 | error.cpp 37 | buffer.cpp 38 | cmd.cpp 39 | config.cpp 40 | notify.cpp 41 | sdps.cpp 42 | trans.cpp 43 | usbhotplug.cpp 44 | version.cpp 45 | sdp.cpp 46 | gitversion.h 47 | fastboot.cpp 48 | zip.cpp 49 | fat.cpp 50 | tar.cpp 51 | rominfo.cpp 52 | http.cpp 53 | hidreport.cpp 54 | sparse.cpp 55 | bmap.cpp 56 | ) 57 | 58 | set(generated_files_dir "${CMAKE_BINARY_DIR}/libuuu/gen") 59 | set(gitversion_h "${generated_files_dir}/gitversion.h") 60 | 61 | add_custom_command( 62 | OUTPUT gitversion.h 63 | PRE_BUILD 64 | COMMAND mkdir -p ${generated_files_dir} 65 | COMMAND sh -c 'cd ${CMAKE_CURRENT_SOURCE_DIR} && rm -f ${gitversion_h} && ./gen_ver.sh "${gitversion_h}.tmp" && mv -f "${gitversion_h}.tmp" "${gitversion_h}"' 66 | 67 | ) 68 | include_directories(${generated_files_dir}) 69 | 70 | #add_library( uuc SHARED ${SOURCES} )) 71 | add_library( uuc_s STATIC ${SOURCES} ) 72 | -------------------------------------------------------------------------------- /.github/workflows/tar.yaml: -------------------------------------------------------------------------------- 1 | name: Create source package 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | name: Create source package 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | submodules: true 25 | 26 | - name: Build 27 | run: | 28 | git archive --prefix "uuu-${{ github.ref_name }}/" -o "uuu_source-${{ github.ref_name }}.tar" HEAD ; 29 | git submodule foreach --recursive "git archive --prefix=uuu-${{ github.ref_name }}/\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/uuu_source-${{ github.ref_name }}.tar \$sha1.tar && rm \$sha1.tar" 30 | mkdir uuu-${{ github.ref_name }}; git describe --tags --long >uuu-${{ github.ref_name }}/.tarball-version 31 | tar -r uuu-${{ github.ref_name }}/.tarball-version -f uuu_source-${{ github.ref_name }}.tar 32 | gzip uuu_source-${{ github.ref_name }}.tar 33 | tar xzf uuu_source-${{ github.ref_name }}.tar.gz && zip uuu_source-${{ github.ref_name }}.zip $(tar tf uuu_source-${{ github.ref_name }}.tar.gz) 34 | 35 | - name: Upload Build Artifacts 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: uuu_source-${{ github.ref_name }}.tar.gz 39 | path: uuu_source-${{ github.ref_name }}.tar.gz 40 | 41 | - name: Create or Update Release 42 | if: github.ref_type == 'tag' 43 | uses: ncipollo/release-action@v1 44 | with: 45 | name: Release ${{ github.ref_name }} 46 | tag: ${{ github.ref_name }} 47 | commit: ${{ github.sha }} 48 | allowUpdates: true 49 | prerelease: true 50 | artifacts: "uuu_source-${{ github.ref_name }}.tar.gz, uuu_source-${{ github.ref_name }}.zip" 51 | -------------------------------------------------------------------------------- /.github/workflows/macOS.yaml: -------------------------------------------------------------------------------- 1 | name: macOS Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | name: macOS Build 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | matrix: 20 | os: 21 | - macos-15 22 | - macos-14-intel 23 | 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@v3 27 | with: 28 | fetch-depth: 0 29 | 30 | - name: Set up environment 31 | run: brew install libusb pkg-config zstd tinyxml2 32 | 33 | - name: Build 34 | run: | 35 | git fetch --tags --force # Retrieve annotated tags. #issue 290 36 | export PATH="/usr/local/Cellar/pkg-config/0.29.2_3/bin:${PATH}"; pkg-config --list-all; cmake -DOPENSSL_ROOT_DIR=$(brew --prefix)/opt/openssl . ; make 37 | 38 | - name: Rename_x86 39 | if: matrix.os == 'macos-14-intel' 40 | run: cp uuu/uuu uuu_mac_x86 41 | 42 | - name: Rename_arm 43 | if: matrix.os == 'macos-15' 44 | run: cp uuu/uuu uuu_mac_arm 45 | 46 | - name: Upload Build Artifacts 47 | if: matrix.os == 'macos-14-intel' 48 | uses: actions/upload-artifact@v4 49 | with: 50 | name: uuu_mac_x86 51 | path: uuu_mac_x86 52 | 53 | - name: Upload Build Artifacts 54 | if: matrix.os == 'macos-15' 55 | uses: actions/upload-artifact@v4 56 | with: 57 | name: uuu_mac_arm 58 | path: uuu_mac_arm 59 | 60 | - name: Create or Update Release 61 | if: github.ref_type == 'tag' 62 | uses: ncipollo/release-action@v1 63 | with: 64 | name: Release ${{ github.ref_name }} 65 | tag: ${{ github.ref_name }} 66 | commit: ${{ github.sha }} 67 | allowUpdates: true 68 | prerelease: true 69 | artifacts: "uuu_mac_*" 70 | -------------------------------------------------------------------------------- /wrapper/README.md: -------------------------------------------------------------------------------- 1 | # libuuu 2 | 3 | A python wrapper for `libuuu`. 4 | 5 | Supported Python versions: 3.9 or newer. 6 | 7 | ## Manual Build and Installation 8 | 9 | To build the project you first need to build libuuu dynamic libraries for your 10 | operating system, or download them. In this section, manual build is described. 11 | 12 | ### Building libraries 13 | 14 | We first install `vcpkg` which is a C++ library manager for Windows, Linux, and MacOS. Then we set some necessary environment variables, how you set them depends on your operating system, but it is basically the same. 15 | 16 | #### Linux & MacOS 17 | > Downloading vcpkg and setting up environment variables 18 | ```bash 19 | git clone https://github.com/microsoft/vcpkg.git 20 | cd vcpkg 21 | export VCPKG_ROOT=$(pwd) 22 | export PATH=$VCPKG_ROOT:$PATH 23 | ./bootstrap-vcpkg.sh 24 | ``` 25 | 26 | > Dependencies on Linux (Ubuntu) 27 | ```bash 28 | sudo apt-get install gcc cmake ninja-build autotools-dev automake autoconf libudev-dev 29 | ``` 30 | > Dependencies on MacOS 31 | ```bash 32 | brew install ninja cmake autoconf automake libtool 33 | ``` 34 | > Build 35 | ```bash 36 | cd ../wrapper 37 | cmake --preset=unix #Needs to have vcpkg in PATH & VCPKG_ROOT set. 38 | cmake --build build 39 | ``` 40 | 41 | #### Windows 42 | > Downloading vcpkg and setting up environment variables 43 | ```powershell 44 | git clone https://github.com/microsoft/vcpkg.git 45 | cd vcpkg 46 | $env:VCPKG_ROOT = $PWD.Path 47 | $env:Path = $env:VCPKG_ROOT + ';' + $env:Path 48 | ./bootstrap-vcpkg.bat 49 | ``` 50 | > Dependencies on Windows 51 | ```powershell 52 | choco install ninja llvm cmake 53 | ``` 54 | > Build 55 | ```powershell 56 | cmake --preset=windows -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 57 | cmake --build build 58 | ``` 59 | 60 | ### Building python package 61 | We just need to create folder `./wrapper/libuuu/lib` and move the dynamic libraries there. 62 | 63 | ```bash 64 | mkdir ./libuuu/lib 65 | cp build/*.dll ./libuuu/lib # *.so for Linux, *.dylib for MacOS 66 | pip install -e . 67 | ``` -------------------------------------------------------------------------------- /msvc/bzip2.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | -------------------------------------------------------------------------------- /webusb/src/logic/usePopup.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | import {useState} from 'react'; 33 | 34 | const usePopup = ({bootFile, flashFile}) => { 35 | const [error, setError] = useState(); 36 | const [show, setShow] = useState(false); 37 | 38 | const showPopup = () => { 39 | if (flashFile == null || bootFile == null) { 40 | setError("Please choose flash files") 41 | } 42 | else { 43 | setError(""); 44 | setShow(true); 45 | } 46 | } 47 | const closePopup = () => { 48 | setShow(false); 49 | } 50 | 51 | return [{ 52 | showPopup, 53 | closePopup, 54 | show, 55 | error, 56 | }] 57 | } 58 | 59 | export default usePopup -------------------------------------------------------------------------------- /uuu/qspi_burn_loader.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.2.39 2 | 3 | # @_flexspi.bin | bootloader 4 | # @_image [_flexspi.bin] | image burn to flexspi, default is the same as bootloader 5 | 6 | # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ 7 | SDP: boot -f _flexspi.bin 8 | 9 | # This command will be run when ROM support stream mode 10 | # i.MX8QXP, i.MX8QM, skip QSPI header 11 | SDPS: boot -f _flexspi.bin -skipfhdr 12 | 13 | # These commands will be run when use SPL and will be skipped if no spl 14 | # SDPU will be deprecated. please use SDPV instead of SDPU 15 | # { 16 | SDPU: delay 1000 17 | SDPU: write -f _flexspi.bin -offset 0x10000 -skipfhdr 18 | SDPU: jump 19 | # } 20 | 21 | # These commands will be run when use SPL and will be skipped if no spl 22 | # if (SPL support SDPV) 23 | # { 24 | SDPV: delay 1000 25 | SDPV: write -f _flexspi.bin -skipspl -skipfhdr 26 | SDPV: jump 27 | # } 28 | 29 | FB: ucmd setenv fastboot_buffer ${loadaddr} 30 | FB: download -f _image 31 | 32 | FB: ucmd if test ! -n "$fastboot_bytes"; then setenv fastboot_bytes $filesize; else true; fi 33 | 34 | # Check Image if include flexspi header 35 | FB: ucmd if qspihdr dump ${fastboot_buffer}; then setenv qspihdr_exist yes; else setenv qspihdr_exist no; fi; 36 | # Check Image size if larger than 16M, then use uboot command to write image 37 | FB: ucmd if itest ${fastboot_bytes} -gt 1000000; then setenv qspihdr_large yes; else setenv qspihdr_large no; fi; 38 | 39 | FB[-t 60000]: ucmd if test ${qspihdr_exist} = yes -a ${qspihdr_large} = no; then qspihdr init ${fastboot_buffer} ${fastboot_bytes} safe; else true; fi; 40 | 41 | #if uboot can't support qspihdr command, use uboot image to write qspi image, which require image include qspi flash header 42 | FB: ucmd if test ${qspihdr_exist} = no; then sf probe; else true; fi; 43 | FB[-t 40000]: ucmd if test ${qspihdr_exist} = no; then sf erase 0 +${fastboot_bytes}; else true; fi; 44 | FB[-t 20000]: ucmd if test ${qspihdr_exist} = no; then sf write ${fastboot_buffer} 0 ${fastboot_bytes}; else true; fi; 45 | # if Image is larger than 16M, use uboot command to write image 46 | FB: ucmd if test ${qspihdr_large} = yes; then sf probe; else true; fi; 47 | FB: write -f _image -format "if test ${qspihdr_large} = yes; then sf erase @off +@size; sf write ${fastboot_buffer} @off @size; else true; fi;" -blksz 1 -each 0x100000 48 | FB: done 49 | -------------------------------------------------------------------------------- /webusb/src/logic/usePopupContent.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | import {useState} from 'react'; 33 | 34 | const usePopupContent = ({bootFile, flashFile}) => { 35 | const [error, setError] = useState(); 36 | const [show, setShow] = useState(false); 37 | 38 | const showPopup = () => { 39 | if (flashFile == null || bootFile == null) { 40 | setError("Please choose flash files") 41 | } 42 | else { 43 | setError(""); 44 | setShow(true); 45 | } 46 | } 47 | const closePopup = () => { 48 | setShow(false); 49 | } 50 | 51 | return [{ 52 | showPopup, 53 | closePopup, 54 | show, 55 | error, 56 | }] 57 | } 58 | 59 | export default usePopupContent -------------------------------------------------------------------------------- /libuuu/sparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | #pragma once 32 | 33 | #include "sparse_format.h" 34 | 35 | #include 36 | #include 37 | 38 | class SparseFile 39 | { 40 | public: 41 | std::vector m_data; 42 | 43 | static chunk_header_t * get_next_chunk(uint8_t *p, size_t &pos); 44 | 45 | int init_header(size_t blsz, int blcount); 46 | 47 | bool is_append_old_chuck(int type, void *p); 48 | bool is_same_value(void *data, size_t sz); 49 | static bool is_validate_sparse_file(void *p, size_t sz); 50 | 51 | int push(void *p, size_t sz); 52 | int push_one_block(void *data, bool skip=false); 53 | size_t push_one_chuck(chunk_header_t *p, void *data); 54 | size_t push_raw_data(void *data, size_t sz); 55 | 56 | private: 57 | size_t m_cur_chunk_header_pos; 58 | size_t m_max_size; 59 | uint32_t *m_pcrc; 60 | }; 61 | -------------------------------------------------------------------------------- /libuuu/sdps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "cmd.h" 33 | #include 34 | 35 | class SDPSCmd : public CmdBase 36 | { 37 | public: 38 | SDPSCmd(const char *cmd) :CmdBase(cmd) 39 | { 40 | insert_param_info("boot", nullptr, Param::Type::e_null); 41 | insert_param_info("-f", &m_filename, Param::Type::e_string_filename); 42 | insert_param_info("-offset", &m_offset, Param::Type::e_uint32); 43 | insert_param_info("-skipfhdr", &m_bskipflashheader, Param::Type::e_bool); 44 | insert_param_info("-scanterm", &m_bscanterm, Param::Type::e_bool); 45 | insert_param_info("-scanlimited", &m_scan_limited, Param::Type::e_uint64); 46 | } 47 | int run(CmdCtx *p) override; 48 | 49 | private: 50 | bool m_bskipflashheader=0; 51 | bool m_bscanterm=0; 52 | std::string m_filename; 53 | uint32_t m_offset = 0; 54 | uint64_t m_scan_limited = UINT64_MAX; 55 | }; 56 | -------------------------------------------------------------------------------- /libuuu/http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | class HttpStream 39 | { 40 | std::vector m_buff; 41 | int m_socket = -1; 42 | std::map m_response; 43 | size_t m_data_start; 44 | 45 | #ifdef _WIN32 46 | void far * m_hSession; 47 | void far * m_hConnect; 48 | void far * m_hRequest; 49 | #endif 50 | 51 | void * m_ssl = nullptr; 52 | int parser_response(std::string rep); 53 | public: 54 | HttpStream(); 55 | int HttpGetHeader(std::string host, std::string path, int port = 80, bool ishttps=false); 56 | size_t HttpGetFileSize(); 57 | int HttpDownload(char *buff, size_t sz); 58 | ~HttpStream(); 59 | 60 | private: 61 | int RecvPacket(char *buff, size_t sz); 62 | int SendPacket(char *buff, size_t sz); 63 | }; 64 | -------------------------------------------------------------------------------- /uuu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | set(CMAKE_CXX_STANDARD 14) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | set(CMAKE_SKIP_RPATH ON) 6 | 7 | find_package(PkgConfig REQUIRED) 8 | pkg_check_modules(LIBUSB REQUIRED libusb-1.0>=1.0.16) 9 | pkg_check_modules(LIBZ REQUIRED zlib) 10 | pkg_check_modules(LIBZSTD REQUIRED libzstd) 11 | find_package(Threads) 12 | pkg_check_modules(TINYXML2 REQUIRED tinyxml2) 13 | 14 | if (STATIC) 15 | set(OPENSSL_USE_STATIC_LIBS TRUE) 16 | endif() 17 | 18 | find_package(OpenSSL) 19 | 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O2") 21 | 22 | if (STATIC) 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc") 24 | set(TINYXML2_LIBRARY_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../tinyxml2") 25 | set(TINYXML2_LIBRARIES "tinyxml2.a") 26 | endif() 27 | 28 | set(LSTS 29 | uuu.lst 30 | emmc_burn_loader.lst 31 | emmc_burn_all.lst 32 | fat_write.lst 33 | qspi_burn_loader.lst 34 | fspinand_burn_loader.lst 35 | sd_burn_loader.lst 36 | spl_boot.lst 37 | sd_burn_all.lst 38 | nand_burn_loader.lst 39 | nvme_burn_all.lst 40 | ) 41 | 42 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libuuu ${LIBUSB_LIBRARY_DIRS} ${LIBZSTD_LIBRARY_DIRS} ${LIBZ_LIBRARY_DIRS} ${TINYXML2_LIBRARY_DIRS}) 43 | 44 | set(CLIST_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/gen_txt_include.sh) 45 | set(generated_files_dir "${CMAKE_BINARY_DIR}/uuu/gen") 46 | 47 | function(preprocess_clst out_var) 48 | set(result) 49 | foreach(in_f ${ARGN}) 50 | set(out_f "${generated_files_dir}/${in_f}") 51 | string(REPLACE ".lst" ".clst" out_f ${out_f}) 52 | add_custom_command(OUTPUT ${out_f} 53 | PRE_BUILD 54 | COMMAND mkdir -p ${generated_files_dir} 55 | COMMAND ${CLIST_EXECUTABLE} ${in_f} ${out_f} 56 | DEPENDS ${in_f} 57 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 58 | COMMENT "Creating preprocessed clst file ${out_f}" 59 | VERBATIM 60 | ) 61 | list(APPEND result ${out_f}) 62 | endforeach() 63 | set(${out_var} "${result}" PARENT_SCOPE) 64 | endfunction() 65 | 66 | preprocess_clst(CLSTS ${LSTS}) 67 | 68 | include_directories(${generated_files_dir}) 69 | 70 | set(SOURCES 71 | uuu.cpp 72 | buildincmd.cpp 73 | autocomplete.cpp 74 | ${CLSTS} 75 | ) 76 | 77 | add_executable(uuu ${SOURCES}) 78 | target_link_libraries(uuu uuc_s ${OPENSSL_LIBRARIES} ${LIBUSB_LIBRARIES} ${LIBZ_LIBRARIES} ${LIBZSTD_LIBRARIES} ${TINYXML2_LIBRARIES} dl bz2) 79 | 80 | install(TARGETS uuu DESTINATION bin) 81 | target_compile_definitions(uuu 82 | PRIVATE "TARGET_PATH=\"${CMAKE_INSTALL_PREFIX}/bin/uuu\"" 83 | ) 84 | -------------------------------------------------------------------------------- /libuuu/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | class ConfigItem 39 | { 40 | public: 41 | ConfigItem() = default; 42 | ConfigItem(const char *pro, const char *chip, const char *comp, uint16_t vid, uint16_t pid, uint16_t verLow = 0, uint16_t verUp = UINT16_MAX) : 43 | m_pid{pid}, m_vid{vid}, m_bcdVerMin{verLow}, m_bcdVerMax{verUp} 44 | { 45 | if (pro) 46 | m_protocol = pro; 47 | if (chip) 48 | m_chip = chip; 49 | if (comp) 50 | m_compatible = comp; 51 | } 52 | std::string m_protocol; 53 | std::string m_chip; 54 | std::string m_compatible; 55 | uint16_t m_pid = 0; 56 | uint16_t m_vid = 0; 57 | uint16_t m_bcdVerMin = 0; 58 | uint16_t m_bcdVerMax = UINT16_MAX; 59 | }; 60 | 61 | class Config :public std::vector 62 | { 63 | public: 64 | Config(); 65 | ConfigItem *find(uint16_t vid, uint16_t pid, uint16_t ver); 66 | }; 67 | 68 | Config * get_config() noexcept; 69 | -------------------------------------------------------------------------------- /libuuu/sparse_format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBSPARSE_SPARSE_FORMAT_H_ 18 | #define _LIBSPARSE_SPARSE_FORMAT_H_ 19 | 20 | #include 21 | 22 | typedef uint32_t __le32; 23 | typedef uint16_t __le16; 24 | 25 | #pragma pack(1) 26 | 27 | typedef struct sparse_header { 28 | __le32 magic; /* 0xed26ff3a */ 29 | __le16 major_version; /* (0x1) - reject images with higher major versions */ 30 | __le16 minor_version; /* (0x0) - allow images with higher minor versions */ 31 | __le16 file_hdr_sz; /* 28 bytes for first revision of the file format */ 32 | __le16 chunk_hdr_sz; /* 12 bytes for first revision of the file format */ 33 | __le32 blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */ 34 | __le32 total_blks; /* total blocks in the non-sparse output image */ 35 | __le32 total_chunks; /* total chunks in the sparse input image */ 36 | __le32 image_checksum; /* CRC32 checksum of the original data, counting "don't care" */ 37 | /* as 0. Standard 802.3 polynomial, use a Public Domain */ 38 | /* table implementation */ 39 | } sparse_header_t; 40 | 41 | #define SPARSE_HEADER_MAGIC 0xed26ff3a 42 | 43 | #define CHUNK_TYPE_RAW 0xCAC1 44 | #define CHUNK_TYPE_FILL 0xCAC2 45 | #define CHUNK_TYPE_DONT_CARE 0xCAC3 46 | #define CHUNK_TYPE_CRC32 0xCAC4 47 | 48 | typedef struct chunk_header { 49 | __le16 chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 50 | __le16 reserved1; 51 | __le32 chunk_sz; /* in blocks in output image */ 52 | __le32 total_sz; /* in bytes of chunk input file including chunk header and data */ 53 | } chunk_header_t; 54 | 55 | /* Following a Raw or Fill or CRC32 chunk is data. 56 | * For a Raw chunk, it's the data in chunk_sz * blk_sz. 57 | * For a Fill chunk, it's 4 bytes of the fill data. 58 | * For a CRC32 chunk, it's 4 bytes of CRC32 59 | */ 60 | #pragma pack() 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /snap/local/launchers/universal-update-utility-launch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is the maintainence launcher for the snap, make necessary runtime 3 | # environment changes to make the snap work here. You may also insert 4 | # security confinement/deprecation/obsoletion notice of the snap here. 5 | 6 | # lint: The use of backticks in the printf messages is intended 7 | # shellcheck disable=SC2016 8 | 9 | set \ 10 | -o errexit \ 11 | -o errtrace \ 12 | -o nounset \ 13 | -o pipefail 14 | 15 | #export IMPORTANT_ENVIRONMENT_VARIABLE=value 16 | 17 | # Run the command, if fails, check and present security confinement 18 | # warnings to the user 19 | if ! "${@}" \ 20 | && test "$(snapctl get disable-snap-confinement-warnings)" != true; then 21 | snap_confinement_warning_triggered=false 22 | if ! snapctl is-connected home; then 23 | snap_confinement_warning_triggered=true 24 | printf \ 25 | "Warning: It appears that the %s snap isn't connected to the \`home\` interface, accessing files under your home directory will not be possible.\n\n" \ 26 | "${SNAP_NAME}" \ 27 | 1>&2 28 | printf \ 29 | "To fix this problem run the following command as root:\n\n snap connect %s:home\n\n" \ 30 | "${SNAP_NAME}" \ 31 | 1>&2 32 | fi 33 | 34 | if ! snapctl is-connected raw-usb; then 35 | snap_confinement_warning_triggered=true 36 | printf \ 37 | "Warning: It appears that the %s snap isn't connected to the \`raw-usb\` interface, direct-access of USB devices will not be possible.\n\n" \ 38 | "${SNAP_NAME}" \ 39 | 1>&2 40 | printf \ 41 | "To fix this problem run the following command as root:\n\n snap connect %s:raw-usb\n\n" \ 42 | "${SNAP_NAME}" \ 43 | 1>&2 44 | fi 45 | 46 | if ! snapctl is-connected removable-media; then 47 | snap_confinement_warning_triggered=true 48 | printf \ 49 | "Warning: It appears that the %s snap isn't connected to the \`removable-media\` interface, accessing files under /media and /mnt directory will not be possible.\n\n" \ 50 | "${SNAP_NAME}" \ 51 | 1>&2 52 | printf \ 53 | "To fix this problem run the following command as root:\n\n snap connect %s:removable-media\n\n" \ 54 | "${SNAP_NAME}" \ 55 | 1>&2 56 | fi 57 | 58 | if test "${snap_confinement_warning_triggered}" == true; then 59 | printf \ 60 | "To disable these warnings, run the following command as root:\n\n snap set %s disable-snap-confinement-warnings=true\n\n" \ 61 | "${SNAP_NAME}" \ 62 | 1>&2 63 | fi 64 | fi 65 | -------------------------------------------------------------------------------- /libuuu/tar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | class FileBuffer; 40 | 41 | #define TAR_BLOCK_SIZE 512 42 | 43 | #pragma pack(1) 44 | struct Tar_header 45 | { 46 | uint8_t name[100]; 47 | uint8_t mode[8]; 48 | uint8_t owner_id[8]; 49 | uint8_t group_id[8]; 50 | uint8_t size[12]; 51 | uint8_t modi_time[12]; 52 | uint8_t checksum[8]; 53 | uint8_t type[1]; 54 | uint8_t linkname[100]; 55 | uint8_t ustar[6]; 56 | uint8_t version[2]; 57 | uint8_t uname[32]; 58 | uint8_t gname[32]; 59 | uint8_t major_num[8]; 60 | uint8_t minor_num[8]; 61 | uint8_t prefix[155]; 62 | }; 63 | #pragma pack() 64 | 65 | class Tar_file_Info 66 | { 67 | public: 68 | std::string filename; 69 | uint64_t offset; 70 | uint64_t size; 71 | }; 72 | 73 | 74 | class Tar 75 | { 76 | std::string m_tarfilename; 77 | 78 | public: 79 | std::map m_filemap; 80 | int Open(const std::string &filename); 81 | bool check_file_exist(const std::string &filename); 82 | int get_file_buff(const std::string &filename, std::shared_ptr p); 83 | }; 84 | -------------------------------------------------------------------------------- /msvc/zlib.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | -------------------------------------------------------------------------------- /libuuu/version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "gitversion.h" 33 | #include "libuuu.h" 34 | 35 | #include 36 | 37 | using namespace std; 38 | 39 | static constexpr auto g_version = GIT_VERSION; 40 | 41 | const char *uuu_get_version_string() 42 | { 43 | return g_version; 44 | } 45 | 46 | int uuu_get_version() 47 | { 48 | string version_str{g_version}; 49 | 50 | // Find first dot because major version number must be before it 51 | auto pos = version_str.find("."); 52 | // Find the position of the character right before the start of the number 53 | auto vs = version_str.find_last_not_of("0123456789", pos - 1); 54 | // Let "vs" point exactly to the first character of the major version number 55 | ++vs; 56 | 57 | string temp_num_str = version_str.substr(vs, pos - vs); 58 | const auto maj = static_cast(stoll(temp_num_str, nullptr, 10)); 59 | 60 | version_str = version_str.substr(pos + 1); 61 | pos = version_str.find("."); 62 | temp_num_str = version_str.substr(0, pos); 63 | const auto min = static_cast(stoll(temp_num_str, nullptr, 10)); 64 | 65 | version_str = version_str.substr(pos + 1); 66 | temp_num_str = version_str.substr(0, pos = version_str.find("-")); 67 | const auto build = static_cast(stoll(temp_num_str, nullptr, 10)); 68 | 69 | return (maj << 24) | (min << 12) | build; 70 | } 71 | -------------------------------------------------------------------------------- /libuuu/error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "liberror.h" 33 | #include "libuuu.h" 34 | #include "libusb.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace std; 40 | 41 | static mutex g_last_error_str_mutex; 42 | static string g_last_error_str; 43 | static atomic g_last_err_id; 44 | 45 | static uint32_t g_debug_level; 46 | 47 | int get_libusb_debug_level() noexcept 48 | { 49 | return g_debug_level & 0xFFFF; 50 | } 51 | 52 | int get_libuuu_debug_level() noexcept 53 | { 54 | return g_debug_level & 0xFFFF0000; 55 | } 56 | 57 | void uuu_set_debug_level(uint32_t mask) 58 | { 59 | g_debug_level = mask; 60 | 61 | #if LIBUSB_API_VERSION > 0x01000106 && !defined(FORCE_OLDLIBUSB) 62 | libusb_set_option(nullptr, LIBUSB_OPTION_LOG_LEVEL, get_libusb_debug_level()); 63 | #else 64 | libusb_set_debug(nullptr, get_libusb_debug_level()); 65 | #endif 66 | } 67 | 68 | const char * uuu_get_last_err_string() 69 | { 70 | lock_guard l(g_last_error_str_mutex); 71 | return g_last_error_str.c_str(); 72 | } 73 | 74 | void set_last_err_string(const string &str) 75 | { 76 | lock_guard l(g_last_error_str_mutex); 77 | g_last_error_str = str; 78 | } 79 | 80 | int uuu_get_last_err() 81 | { 82 | return g_last_err_id.load(); 83 | } 84 | 85 | void set_last_err_id(int id) 86 | { 87 | g_last_err_id = id; 88 | } 89 | -------------------------------------------------------------------------------- /libuuu/notify.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "libuuu.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | using namespace std; 41 | 42 | static map g_notification_map; 43 | static mutex g_mutex_notify; 44 | 45 | using namespace std::chrono; 46 | static const time_point g_now = steady_clock::now(); 47 | 48 | int uuu_register_notify_callback(uuu_notify_fun f, void *data) 49 | { 50 | std::lock_guard lock(g_mutex_notify); 51 | 52 | return g_notification_map.emplace(f, data).second ? 0 : 1; 53 | } 54 | 55 | int uuu_unregister_notify_callback(uuu_notify_fun f) 56 | { 57 | std::lock_guard lock(g_mutex_notify); 58 | 59 | return g_notification_map.erase(f) > 0 ? 0 : 1; 60 | } 61 | 62 | void call_notify(struct uuu_notify nf) 63 | { 64 | //Change RW lock later; 65 | std::lock_guard lock(g_mutex_notify); 66 | 67 | nf.id = std::hash{}(std::this_thread::get_id()); 68 | nf.timestamp = static_cast( 69 | duration_cast(steady_clock::now() - g_now).count()); 70 | 71 | for (const auto &item : g_notification_map) 72 | { 73 | try { 74 | item.first(nf, item.second); 75 | } catch (const std::exception& e) { 76 | std::cerr << "notify exception: " << e.what() << std::endl; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /libuuu/hidreport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | #pragma once 32 | 33 | #include "libuuu.h" 34 | 35 | #include 36 | 37 | class TransBase; 38 | 39 | class HIDReport 40 | { 41 | public: 42 | HIDReport(TransBase *trans) : m_pdev{trans} 43 | { 44 | m_out_buff.resize(m_size_out + m_size_payload); 45 | } 46 | virtual ~HIDReport(); 47 | 48 | size_t get_out_package_size() noexcept { return m_size_out; } 49 | virtual void notify(size_t index, uuu_notify::NOTIFY_TYPE type); 50 | int read(std::vector &buff); 51 | void set_notify_total(size_t notify_total) noexcept { m_notify_total = notify_total; } 52 | void set_out_package_size(size_t sz) 53 | { 54 | m_size_out = sz; 55 | m_out_buff.resize(m_size_out + m_size_payload); 56 | } 57 | void set_position_base(size_t position_base) noexcept { m_postion_base = position_base; } 58 | void set_skip_notify(bool skip_notify) noexcept { m_skip_notify = skip_notify; } 59 | int write(const void *p, size_t sz, uint8_t report_id); 60 | int write(const std::vector &buff, uint8_t report_id) 61 | { 62 | return write(buff.data(), buff.size(), report_id); 63 | } 64 | 65 | private: 66 | size_t m_notify_total = 0; 67 | std::vector m_out_buff; 68 | TransBase * const m_pdev = nullptr; 69 | size_t m_postion_base = 0; 70 | size_t m_size_in = 64; 71 | size_t m_size_out = 1024; 72 | size_t m_size_payload = 1; 73 | bool m_skip_notify = true; 74 | }; 75 | -------------------------------------------------------------------------------- /webusb/src/helper/functions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* UTILITY */ 33 | 34 | /* 35 | * hex: Hex number to convert 36 | * size: Int number of bytes 37 | * Returns: an UInt8Array; 2 digits in hex = 1 byte 38 | */ 39 | function hex_to_ab(hex, sz) { 40 | let buffer = new Array(sz).fill(0) 41 | 42 | for (let i=0; i> 8; 45 | } 46 | return buffer; 47 | } 48 | 49 | /* 50 | * str: String 51 | * Returns: a Uint8Array 52 | */ 53 | function str_to_arr(str) { 54 | const encoder = new TextEncoder(); 55 | return encoder.encode(str); 56 | } 57 | 58 | /* 59 | * ab: ArrayBuffer 60 | * Returns a string decoding message in array buffer 61 | */ 62 | function ab_to_str(ab) { 63 | const decoder = new TextDecoder(); 64 | return decoder.decode(ab); 65 | } 66 | 67 | /* 68 | * obj: Object with key (property) value (hex value) pairs 69 | * obj_sz: Object with key (property) value (size of prop, in bytes) pairs 70 | * sz: size of complete array buffer, in bytes 71 | * Returns Uint8Array with padded values 72 | */ 73 | function obj_to_arr(obj, obj_sz, sz) { 74 | let ab = new Uint8Array(sz); 75 | let offset = 0; 76 | for (const prop in obj) { 77 | let prop_arr = hex_to_ab(obj[prop], obj_sz[prop]); 78 | ab.set(prop_arr, offset); 79 | offset += obj_sz[prop]; 80 | } 81 | return ab; 82 | } 83 | 84 | export {hex_to_ab, str_to_arr, ab_to_str, obj_to_arr}; -------------------------------------------------------------------------------- /wrapper/build_backend.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright 2025 NXP 5 | # 6 | # SPDX-License-Identifier: BSD-3-Clause 7 | """Custom build backend that wraps setuptools and forces platform wheels.""" 8 | 9 | import os 10 | from typing import Any, Tuple 11 | 12 | from setuptools.build_meta import build_editable as _build_editable 13 | from setuptools.build_meta import build_sdist as _build_sdist 14 | from setuptools.build_meta import build_wheel as _build_wheel 15 | from setuptools.dist import Distribution 16 | from wheel.bdist_wheel import bdist_wheel 17 | 18 | 19 | def patch() -> None: 20 | """Patch the bdist wheel build.""" 21 | # Apply the monkey patch when the module is imported 22 | original_has_ext_modules = getattr(Distribution, "has_ext_modules", None) 23 | if original_has_ext_modules is not None: 24 | Distribution.has_ext_modules = lambda self: True 25 | 26 | # Also patch the is_pure method to return False 27 | original_is_pure = getattr(Distribution, "is_pure", None) 28 | if original_is_pure is not None: 29 | Distribution.is_pure = lambda self: False 30 | 31 | # Override the wheel tag generation 32 | 33 | original_get_tag = getattr(bdist_wheel, "get_tag", None) 34 | if original_get_tag is not None: 35 | 36 | def tag(self: Any) -> Tuple[str, str, str]: 37 | _, _, platform_tag = original_get_tag(self) 38 | return ("py3", "none", platform_tag) 39 | 40 | bdist_wheel.get_tag = tag 41 | 42 | print("Custom build backend loaded: Platform-specific wheels enabled") 43 | 44 | 45 | def validate_native_libraries() -> None: 46 | """Validate that native libraries exist in the expected locations.""" 47 | lib_dir = os.path.join(os.path.dirname(__file__), "libuuu", "lib") 48 | 49 | if os.path.exists(lib_dir): 50 | print(f"Native libraries found in: {lib_dir}") 51 | # List found libraries 52 | for root, _, files in os.walk(lib_dir): 53 | for file in files: 54 | if file.endswith((".dll", ".so", ".dylib")): 55 | print(f" - {os.path.relpath(os.path.join(root, file), lib_dir)}") 56 | else: 57 | print(f"Warning: No native libraries found in {lib_dir}") 58 | 59 | 60 | def build_wheel(wheel_directory, config_settings=None, metadata_directory=None) -> str: # type: ignore 61 | """Build wheel.""" 62 | patch() 63 | validate_native_libraries() 64 | return _build_wheel(wheel_directory, config_settings, metadata_directory) 65 | 66 | 67 | def build_sdist(sdist_directory, config_settings=None) -> str: # type: ignore 68 | """Build source.""" 69 | patch() 70 | validate_native_libraries() 71 | return _build_sdist(sdist_directory, config_settings) 72 | 73 | 74 | def build_editable(wheel_directory, config_settings=None, metadata_directory=None) -> str: # type: ignore 75 | """Build editable.""" 76 | patch() 77 | validate_native_libraries() 78 | return _build_editable(wheel_directory, config_settings, metadata_directory) 79 | -------------------------------------------------------------------------------- /SBOM.spdx.json: -------------------------------------------------------------------------------- 1 | { 2 | "SPDXID": "SPDXRef-DOCUMENT", 3 | "spdxVersion": "SPDX-2.3", 4 | "creationInfo": { 5 | "created": "2025-08-24T08:15:58Z", 6 | "creators": [ 7 | "Organization: NXP" 8 | ], 9 | "licenseListVersion": "3.20" 10 | }, 11 | "name": "mfgtools-1.5.222", 12 | "dataLicense": "CC0-1.0", 13 | "documentNamespace": "https://nxp.com/spdx/5db452dd-a4ca-4c0d-91de-a85ed94fa7e1", 14 | "packages": [ 15 | { 16 | "SPDXID": "SPDXRef-package-5db452dd-a4ca-4c0d-91de-a85ed94fa7e1", 17 | "name": "mfgtools", 18 | "versionInfo": "1.5.222", 19 | "licenseConcluded": "(BSD-3-Clause)", 20 | "licenseDeclared": "(BSD-3-Clause)", 21 | "downloadLocation": "https://github.com/nxp-imx/mfgtools -b master", 22 | "originator": "Organization: NXP", 23 | "supplier": "NOASSERTION", 24 | "externalRefs": [], 25 | "filesAnalyzed": false 26 | }, 27 | { 28 | "SPDXID": "SPDXRef-package-4823f66e-28e1-4c3d-a580-b5d87c083ca6", 29 | "name": "create-react-app", 30 | "versionInfo": "5.27.2", 31 | "licenseConcluded": "MIT", 32 | "licenseDeclared": "MIT", 33 | "homepage": "https://github.com/facebook/create-react-app", 34 | "downloadLocation": "NOASSERTION", 35 | "originator": "Organization: create-react-app", 36 | "supplier": "NOASSERTION", 37 | "externalRefs": [], 38 | "filesAnalyzed": false 39 | }, 40 | { 41 | "SPDXID": "SPDXRef-package-6009a07b-b1a5-4a14-b3eb-47715883fa40", 42 | "name": "mfgtools", 43 | "versionInfo": "uuu_1.5.219", 44 | "licenseConcluded": "BSD-3-Clause", 45 | "licenseDeclared": "BSD-3-Clause", 46 | "homepage": "https://github.com/nxp-imx/mfgtools", 47 | "downloadLocation": "NOASSERTION", 48 | "originator": "Organization: nxp-imx", 49 | "supplier": "NOASSERTION", 50 | "externalRefs": [ 51 | { 52 | "referenceCategory": "PACKAGE-MANAGER", 53 | "referenceLocator": "pkg:github/nxp-imx/mfgtools@uuu_1.5.219", 54 | "referenceType": "purl" 55 | }, 56 | { 57 | "referenceCategory": "OTHER", 58 | "referenceLocator": "575bed60-fad1-49b2-b7e1-188bbd9dedfc", 59 | "referenceType": "BlackDuck-ComponentOrigin" 60 | } 61 | ], 62 | "filesAnalyzed": false 63 | } 64 | ], 65 | "relationships": [ 66 | { 67 | "spdxElementId": "SPDXRef-DOCUMENT", 68 | "relationshipType": "DESCRIBES", 69 | "relatedSpdxElement": "SPDXRef-package-5db452dd-a4ca-4c0d-91de-a85ed94fa7e1" 70 | }, 71 | { 72 | "spdxElementId": "SPDXRef-package-5db452dd-a4ca-4c0d-91de-a85ed94fa7e1", 73 | "relationshipType": "DYNAMIC_LINK", 74 | "relatedSpdxElement": "SPDXRef-package-6009a07b-b1a5-4a14-b3eb-47715883fa40" 75 | }, 76 | { 77 | "spdxElementId": "SPDXRef-package-5db452dd-a4ca-4c0d-91de-a85ed94fa7e1", 78 | "relationshipType": "DYNAMIC_LINK", 79 | "relatedSpdxElement": "SPDXRef-package-4823f66e-28e1-4c3d-a580-b5d87c083ca6" 80 | } 81 | ] 82 | } -------------------------------------------------------------------------------- /.github/scripts/build_windows.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | echo [INFO] Starting Windows build process 5 | 6 | call :install_dependencies || goto :error 7 | call :setup_environment || goto :error 8 | call :build_project || goto :error 9 | call :copy_artifacts || goto :error 10 | 11 | echo [SUCCESS] Windows build completed successfully 12 | exit /b 0 13 | 14 | :install_dependencies 15 | echo [INFO] Installing build dependencies via Chocolatey 16 | choco install cmake pkgconfiglite ninja --yes --no-progress 17 | if errorlevel 1 ( 18 | echo [ERROR] Failed to install build dependencies 19 | exit /b 1 20 | ) 21 | echo [SUCCESS] Build dependencies installed 22 | pip install pytest 23 | if errorlevel 1 ( 24 | echo [ERROR] Failed to install pytest 25 | exit /b 1 26 | ) 27 | echo [SUCCESS] pytest installed 28 | exit /b 0 29 | 30 | :setup_environment 31 | echo [INFO] Setting up build environment 32 | cd wrapper 33 | set PROJECT_DIR=%CD% 34 | 35 | if exist "vcpkg" ( 36 | echo [INFO] Removing existing vcpkg directory 37 | rmdir /s /q vcpkg 38 | ) 39 | 40 | echo [INFO] Cloning vcpkg repository 41 | git clone https://github.com/microsoft/vcpkg.git 42 | if errorlevel 1 ( 43 | echo [ERROR] Failed to clone vcpkg repository 44 | exit /b 1 45 | ) 46 | 47 | cd vcpkg 48 | echo [INFO] Bootstrapping vcpkg 49 | call bootstrap-vcpkg.bat 50 | if errorlevel 1 ( 51 | echo [ERROR] Failed to bootstrap vcpkg 52 | exit /b 1 53 | ) 54 | 55 | set VCPKG_ROOT=%CD% 56 | set PATH=%VCPKG_ROOT%;%PATH% 57 | cd %PROJECT_DIR% 58 | echo [SUCCESS] Build environment setup completed 59 | exit /b 0 60 | 61 | :build_project 62 | echo [INFO] Configuring and building project 63 | cmake --preset=windows 64 | if errorlevel 1 ( 65 | echo [ERROR] CMake configuration failed 66 | call :debug_info 67 | exit /b 1 68 | ) 69 | 70 | cmake --build build 71 | if errorlevel 1 ( 72 | echo [ERROR] Build failed 73 | call :debug_info 74 | exit /b 1 75 | ) 76 | echo [SUCCESS] Project built successfully 77 | exit /b 0 78 | 79 | :copy_artifacts 80 | echo [INFO] Copying built libraries 81 | set TARGET_DIR=libuuu\lib\windows\x86_64 82 | mkdir "%TARGET_DIR%" 2>nul 83 | 84 | REM Try different build output locations 85 | for %%D in (Debug Release .) do ( 86 | if exist "build\%%D\*.dll" ( 87 | echo [INFO] Copying DLLs from build\%%D\ 88 | copy "build\%%D\*.dll" "%TARGET_DIR%\" >nul 89 | if not errorlevel 1 ( 90 | echo [SUCCESS] DLL files copied successfully 91 | exit /b 0 92 | ) 93 | ) 94 | ) 95 | 96 | echo [ERROR] No DLL files found in any expected location 97 | call :debug_info 98 | exit /b 1 99 | 100 | :debug_info 101 | echo [DEBUG] Current directory: %CD% 102 | if exist "build" ( 103 | echo [DEBUG] Build directory contents: 104 | dir build /s 105 | ) else ( 106 | echo [DEBUG] Build directory does not exist 107 | ) 108 | exit /b 0 109 | 110 | :error 111 | echo [ERROR] Build script failed 112 | exit /b 1 -------------------------------------------------------------------------------- /libuuu/rominfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | class ConfigItem; 39 | class FileBuffer; 40 | class DataBuffer; 41 | 42 | constexpr uint32_t ROM_INFO_HID = 0x1; 43 | constexpr uint32_t ROM_INFO_HID_MX23 = 0x2; 44 | constexpr uint32_t ROM_INFO_HID_MX50 = 0x4; 45 | constexpr uint32_t ROM_INFO_HID_MX6 = 0x8; 46 | constexpr uint32_t ROM_INFO_HID_SKIP_DCD = 0x10; 47 | constexpr uint32_t ROM_INFO_HID_MX8_MULTI_IMAGE = 0x20; 48 | constexpr uint32_t ROM_INFO_HID_MX8_STREAM = 0x40; 49 | constexpr uint32_t ROM_INFO_HID_UID_STRING = 0x80; 50 | // Omitted value: 0x100 51 | // Omitted value: 0x200 52 | constexpr uint32_t ROM_INFO_HID_NO_CMD = 0x400; 53 | constexpr uint32_t ROM_INFO_SPL_JUMP = 0x800; 54 | constexpr uint32_t ROM_INFO_HID_EP1 = 0x1000; 55 | constexpr uint32_t ROM_INFO_HID_PACK_SIZE_1020 = 0x2000; 56 | constexpr uint32_t ROM_INFO_HID_SDP_NO_MAX_PER_TRANS = 0x4000; 57 | constexpr uint32_t ROM_INFO_AUTO_SCAN_UBOOT_POS = 0x8000; 58 | constexpr uint32_t ROM_INFO_HID_ROMAPI = 0x10000; 59 | constexpr uint32_t ROM_INFO_NEED_BAREBOX_FULL_IMAGE = 0x20000; 60 | 61 | struct ROM_INFO 62 | { 63 | const char * m_name; 64 | uint32_t free_addr; 65 | uint32_t flags; 66 | int serial_idx; 67 | }; 68 | 69 | const ROM_INFO * search_rom_info(const std::string &s); 70 | const ROM_INFO * search_rom_info(const ConfigItem *item); 71 | 72 | size_t GetContainerActualSize(std::shared_ptr p, size_t offset, bool bROMAPI=false, bool skipspl=false); 73 | size_t GetFlashHeaderSize(std::shared_ptr p, size_t offset = 0); 74 | 75 | -------------------------------------------------------------------------------- /webusb/src/components/Combined.js: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react'; 2 | import ProgressBar from './ProgressBar'; 3 | import useHIDBoot from '../logic/useHIDBoot'; 4 | import useUSBFlash from '../logic/useUSBFlash' 5 | import imgSrc from '../images/imx8qxp_mek_bootmode.png' 6 | 7 | import "./Combined.css" 8 | 9 | const Combined = ({bootFile, flashFile}) => { 10 | // const [imgUrl, setImgUrl] = useState(); 11 | 12 | const [{ requestHIDDevice, HIDdevice, bootProgress, bootTotal }] = useHIDBoot(bootFile); 13 | const [{ requestUSBDevice, USBDevice, flashProgress, flashTotal}] = useUSBFlash(flashFile); 14 | 15 | // useEffect(() => { 16 | // const dothis = async()=>{ 17 | // const response = await fetch("mode"); 18 | // const blob = await response.blob(); 19 | // setImgUrl(URL.createObjectURL(blob)); 20 | // } 21 | // dothis(); 22 | // }, []) 23 | 24 | return( 25 |
26 |
    27 |
  • 28 | 1. Switch Boot Mode to "SERIAL" 29 |
    30 |
    31 | {imgSrc? : ""} 32 |
    33 |
    34 |
  • 35 |
  • 36 |
    37 |
    38 | {bootProgress&&(bootProgress===bootTotal)?

    :""} 39 |
    40 |
    41 | 2. 42 | 43 | {bootProgress? `${bootProgress} bytes out of ${bootTotal} downloaded`: ""} 44 |
    45 | {bootProgress&&(bootProgress===bootTotal)?`connected: ${HIDdevice.productName}`: (bootProgress?`Pairing`:"")} 46 |
    47 |
    48 |
    49 |
  • 50 |
  • 51 |
    52 |
    53 | {USBDevice?

    :""} 54 |
    55 |
    56 | 3. 57 | 58 |
    {USBDevice? `connected: ${USBDevice.productName}`: ""}
    59 |
    60 |
    61 |
  • 62 |
63 | 67 |
68 | ) 69 | } 70 | 71 | export default Combined -------------------------------------------------------------------------------- /libuuu/fat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include "backfile.h" 35 | #include "buffer.h" 36 | 37 | #include 38 | 39 | #pragma pack(1) 40 | struct Partition 41 | { 42 | uint8_t status; 43 | uint8_t start_head; 44 | uint8_t start_sector; 45 | uint8_t start_cylinder; 46 | uint8_t type; 47 | uint8_t end_head; 48 | uint8_t end_sector; 49 | uint8_t end_cylinder; 50 | uint32_t lba_start; 51 | uint32_t lba_num; 52 | }; 53 | 54 | struct FatDirEntry 55 | { 56 | uint8_t filename[8]; 57 | uint8_t ext[3]; 58 | uint8_t attr; 59 | uint8_t user_attr; 60 | uint8_t delete_char; 61 | uint16_t create_time; 62 | uint16_t create_date; 63 | uint16_t userid; 64 | uint16_t access; 65 | uint16_t modify_time; 66 | uint16_t modify_date; 67 | uint16_t start_cluster; 68 | uint32_t file_size; 69 | }; 70 | 71 | struct FatLFN 72 | { 73 | uint8_t seq; 74 | uint8_t name1[10]; 75 | uint8_t attr; 76 | uint8_t type; 77 | uint8_t sum; 78 | uint8_t name2[12]; 79 | uint16_t start_cluster; 80 | uint8_t name3[4]; 81 | }; 82 | 83 | #pragma pack() 84 | 85 | class Fat : public Backfile 86 | { 87 | public: 88 | void *get_data_buff(shared_ptr p, int cluster); 89 | int get_file_buff(string filename, shared_ptrp); 90 | int get_next_cluster(shared_ptr p, int cluster); 91 | string lfn2string(FatLFN *p); 92 | int Open(const string &filename); 93 | 94 | map m_filemap; 95 | 96 | private: 97 | uint64_t m_cluster; 98 | uint64_t m_fat_part_start; 99 | uint64_t m_fat_table_offset; 100 | uint64_t m_logical_sector_perfat; 101 | int m_num_of_rootdir; 102 | uint64_t m_root_dir_offset; 103 | }; 104 | -------------------------------------------------------------------------------- /.github/workflows/build_arm.yaml: -------------------------------------------------------------------------------- 1 | name: Build for arm ubuntu 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - uuu* 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build_job: 16 | # The host should always be linux 17 | runs-on: ubuntu-latest 18 | name: Build on ${{ matrix.distro }} ${{ matrix.arch }} 19 | 20 | # Run steps on a matrix of 4 arch/distro combinations 21 | strategy: 22 | matrix: 23 | include: 24 | - arch: aarch64 25 | distro: ubuntu22.04 26 | - arch: armv7 27 | distro: ubuntu22.04 28 | steps: 29 | - uses: actions/checkout@v3 30 | with: 31 | fetch-depth: 0 32 | submodules: true 33 | 34 | - name: git fetch tags 35 | run: | 36 | git fetch --tags --force # Retrieve annotated tags. #issue 290 37 | 38 | - uses: uraimo/run-on-arch-action@v2 39 | name: Build artifact 40 | id: build 41 | with: 42 | arch: ${{ matrix.arch }} 43 | distro: ${{ matrix.distro }} 44 | 45 | # Not required, but speeds up builds 46 | githubToken: ${{ github.token }} 47 | 48 | # Mount the artifacts directory as /artifacts in the container 49 | dockerRunArgs: | 50 | --volume "${PWD}:/mfgtools" 51 | 52 | # Pass some environment variables to the container 53 | env: | # YAML, but pipe character is necessary 54 | artifact_name: git-${{ matrix.distro }}_${{ matrix.arch }} 55 | 56 | # The shell to run commands with in the container 57 | shell: /bin/sh 58 | 59 | # Install some dependencies in the container. This speeds up builds if 60 | # you are also using githubToken. Any dependencies installed here will 61 | # be part of the container image that gets cached, so subsequent 62 | # builds don't have to re-install them. The image layer is cached 63 | # publicly in your project's package repository, so it is vital that 64 | # no secrets are present in the container state or logs. 65 | install: apt-get update -q -y; apt-get install -q -y libusb-1.0-0-dev libbz2-dev libzstd-dev pkg-config cmake libssl-dev g++ zlib1g-dev git libtinyxml2-dev 66 | 67 | # Produce a binary artifact and place it in the mounted volume 68 | run: | 69 | git config --global --add safe.directory /mfgtools 70 | cd /mfgtools/tinyxml2; cmake .; make; 71 | cd /mfgtools 72 | cmake -D 'STATIC=1' . 73 | make 74 | 75 | - name: Rename 76 | run: cp uuu/uuu uuu_${{ matrix.arch }} 77 | 78 | - name: Upload Build Artifacts 79 | uses: actions/upload-artifact@v4 80 | with: 81 | name: uuu_${{ matrix.arch }} 82 | path: uuu_${{ matrix.arch }} 83 | 84 | - name: Create or Update Release 85 | if: github.ref_type == 'tag' 86 | uses: ncipollo/release-action@v1 87 | with: 88 | name: Release ${{ github.ref_name }} 89 | tag: ${{ github.ref_name }} 90 | commit: ${{ github.sha }} 91 | allowUpdates: true 92 | prerelease: true 93 | artifacts: "uuu_${{ matrix.arch }}" 94 | 95 | -------------------------------------------------------------------------------- /webusb/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /libuuu/hidreport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "hidreport.h" 33 | #include "libcomm.h" 34 | #include "liberror.h" 35 | #include "trans.h" 36 | #include "zip.h" 37 | 38 | #include 39 | 40 | HIDReport::~HIDReport() 41 | { 42 | } 43 | 44 | void HIDReport::notify(size_t index, uuu_notify::NOTIFY_TYPE type) 45 | { 46 | uuu_notify nf; 47 | nf.type = type; 48 | if(type == uuu_notify::NOTIFY_TRANS_POS) 49 | nf.index = index + m_postion_base; 50 | if (type == uuu_notify::NOTIFY_TRANS_SIZE) 51 | { 52 | nf.index = m_notify_total > index ? m_notify_total : index; 53 | } 54 | call_notify(nf); 55 | } 56 | 57 | int HIDReport::read(std::vector &buff) 58 | { 59 | if (buff.size() < m_size_in + m_size_payload) 60 | { 61 | set_last_err_string("buffer to small to get a package"); 62 | return -1; 63 | } 64 | size_t rs; 65 | int ret = m_pdev->read(buff.data(), m_size_in + m_size_payload, &rs); 66 | 67 | return ret; 68 | } 69 | 70 | int HIDReport::write(const void *p, size_t sz, uint8_t report_id) 71 | { 72 | notify(sz, uuu_notify::NOTIFY_TRANS_SIZE); 73 | 74 | const uint8_t * const buff = reinterpret_cast(p); 75 | size_t off = 0; 76 | for (; off < sz; off += m_size_out) 77 | { 78 | m_out_buff[0] = report_id; 79 | 80 | size_t s = sz - off; 81 | 82 | if (s > m_size_out) 83 | s = m_size_out; 84 | 85 | memcpy(m_out_buff.data() + m_size_payload, buff + off, s); 86 | 87 | /* 88 | * The Windows HIDAPI is ver strict. It always require to send 89 | * buffers of the size reported by the HID Report Descriptor. 90 | * Therefore we must to send m_size_out buffers for HID ID 2 91 | * albeit it may not required for the last buffer. 92 | */ 93 | if (report_id == 2) 94 | s = m_size_out; 95 | 96 | int ret = m_pdev->write(m_out_buff.data(), s + m_size_payload); 97 | 98 | if (ret < 0) 99 | return -1; 100 | 101 | if (off % 0x1F == 0) 102 | { 103 | notify(off, uuu_notify::NOTIFY_TRANS_POS); 104 | } 105 | } 106 | 107 | notify(sz, uuu_notify::NOTIFY_TRANS_POS); 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /webusb/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import Combined from "./components/Combined"; 3 | import usePopup from "./logic/usePopup"; 4 | import UartTerminal from './terminal'; 5 | import 'xterm/css/xterm.css'; 6 | import './App.css' 7 | 8 | const App = () => { 9 | const [bootFile, setBootFile] = useState(); 10 | const [flashFile, setFlashFile] = useState(); 11 | const [term, setTerm] = useState(); 12 | const [port, setPort] = useState(); 13 | const [{ showPopup, closePopup, show, error }] = usePopup({ bootFile, flashFile }); 14 | const pipetoterm = async (port) => { 15 | await port.open({ baudRate: 115200 }); 16 | const reader = port.readable.getReader(); 17 | const readfun = (port, reader) => { 18 | reader.read().then(({ value, done }) => { 19 | if (!done) { 20 | console.log(value); 21 | term.write(value); 22 | return readfun(port, reader); 23 | } else { 24 | console.log("End of stream"); 25 | } 26 | }) 27 | }; 28 | readfun(port, reader); 29 | } 30 | 31 | return ( 32 |
33 |
34 |
35 |
36 |
Demo for webuuu, Only Support 8QXP/8QM board, NO SPL version
37 |
This is early development version. Any issue or idea: report to https://github.com/nxp-imx/mfgtools/issues
38 |

39 |
Before use this tools, please add below udev rule at linux machine
40 |
KERNEL=="hidraw*", ATTRS{'{idVendor}'}=="1fc9", MODE="0666"
41 |
SUBSYSTEM=="usb", ATTRS{'{idVendor}'}=="1fc9", ATTRS{'{idProduct}'}=="0152", MODE="0664", TAG+="uaccess"
42 |

43 |
44 | bootloader: 45 | {bootFile ? bootFile.name : ""} 46 | 50 |
51 | 52 |
53 | wic image: 54 | {flashFile ? flashFile.name : ""} 55 | 59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 |
67 | 68 | 69 |
70 |
71 | {error} 72 |
73 |
74 |
75 |
76 | 83 |
84 |
85 | { 86 | setTerm(term); 87 | term.onData((data) => { 88 | console.log(data); 89 | const encoder = new TextEncoder(); 90 | const writer = window.uartport.writable.getWriter(); 91 | writer.write(encoder.encode(data)); 92 | writer.releaseLock(); 93 | }); 94 | }} /> 95 |
96 |
97 |
98 |
99 | ); 100 | } 101 | 102 | export default App; 103 | -------------------------------------------------------------------------------- /libuuu/trans.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | #pragma once 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | class TransBase 38 | { 39 | public: 40 | TransBase(int retry = 1) : m_retry{retry} {} 41 | TransBase(const TransBase&) = delete; 42 | TransBase& operator=(const TransBase&) = delete; 43 | virtual ~TransBase(); 44 | 45 | virtual int open(void *) { return 0; } 46 | virtual int close() { return 0; } 47 | int write(void *buff, size_t size); 48 | int read(void *buff, size_t size, size_t *return_size); 49 | int write(std::vector & buff) { return write(buff.data(), buff.size()); } 50 | int read(std::vector &buff); 51 | 52 | protected: 53 | void * m_devhandle = nullptr; 54 | int m_retry = 1; 55 | 56 | virtual int write_simple(void *buff, size_t size) = 0; 57 | virtual int read_simple(void *buff, size_t size, size_t *return_size) = 0; 58 | }; 59 | 60 | class EPInfo 61 | { 62 | public: 63 | constexpr EPInfo() = default; 64 | constexpr EPInfo(int a, int size) : addr{a}, package_size{size} {} 65 | int addr = 0; 66 | int package_size = 64; 67 | }; 68 | 69 | class USBTrans : public TransBase 70 | { 71 | public: 72 | USBTrans(int retry = 1) : TransBase(retry) {} 73 | int open(void *p) override; 74 | int close() override; 75 | 76 | protected: 77 | std::vector m_EPs; 78 | }; 79 | class HIDTrans : public USBTrans 80 | { 81 | public: 82 | HIDTrans(int timeout = 1000) : USBTrans(2), m_timeout{timeout} {} 83 | ~HIDTrans() override { if (m_devhandle) close(); m_devhandle = nullptr; } 84 | 85 | int open(void *p) override; 86 | void set_hid_out_ep(int ep) noexcept { m_outEP = ep; } 87 | 88 | protected: 89 | int write_simple(void *buff, size_t size) override; 90 | int read_simple(void *buff, size_t size, size_t *return_size) override; 91 | 92 | private: 93 | int m_outEP = 0; 94 | const int m_timeout = 1000; 95 | int m_set_report = 9; 96 | }; 97 | 98 | class BulkTrans : public USBTrans 99 | { 100 | public: 101 | BulkTrans(int timeout = 2000) : USBTrans(2), m_timeout{timeout} {} 102 | ~BulkTrans() override { if (m_devhandle) close(); m_devhandle = nullptr; } 103 | 104 | int open(void *p) override; 105 | 106 | protected: 107 | int write_simple(void *buff, size_t size) override; 108 | int read_simple(void *buff, size_t size, size_t *return_size) override; 109 | 110 | private: 111 | size_t m_MaxTransPreRequest = 0x100000; 112 | int m_b_send_zero = 0; 113 | EPInfo m_ep_in; 114 | EPInfo m_ep_out; 115 | int m_timeout = 2000; 116 | }; 117 | 118 | int polling_usb(std::atomic& bexit); 119 | -------------------------------------------------------------------------------- /wrapper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(libuuu) 3 | 4 | set(CMAKE_CXX_STANDARD 14) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_SKIP_RPATH ON) 7 | 8 | # Prefix all shared libraries with 'lib'. 9 | set(CMAKE_SHARED_LIBRARY_PREFIX "") 10 | # Prefix all static libraries with 'lib'. 11 | set(CMAKE_STATIC_LIBRARY_PREFIX "") 12 | 13 | # Set the directory where generated files will be placed 14 | set(generated_files_dir "${CMAKE_BINARY_DIR}/libuuu/gen") 15 | 16 | # Add the generated files directory to the include path 17 | include_directories(${generated_files_dir}) 18 | 19 | # Set the path for gitversion.h in the generated files directory 20 | set(gitversion_h "${generated_files_dir}/gitversion.h") 21 | # Run git describe without --always flag 22 | execute_process( 23 | COMMAND git describe --tags --long 24 | OUTPUT_VARIABLE version 25 | OUTPUT_STRIP_TRAILING_WHITESPACE 26 | RESULT_VARIABLE git_result 27 | ERROR_VARIABLE git_error 28 | ) 29 | 30 | # Check if git describe failed 31 | if(NOT git_result EQUAL 0) 32 | message(FATAL_ERROR "Failed to get version from git: ${git_error}\n" 33 | "Make sure you have tags in your repository.\n" 34 | "Create a tag with: git tag uuu_1.0.0") 35 | endif() 36 | 37 | # Validate version format 38 | if(NOT version MATCHES "^uuu_[0-9]+\\.[0-9]+\\.[0-9]+(\\-[0-9]+\\-g[0-9a-f]+)?$") 39 | message(FATAL_ERROR "Git version '${version}' doesn't match expected format 'uuu_X.Y.Z' or 'uuu_X.Y.Z-N-gHASH'") 40 | endif() 41 | # Add a custom command to generate definitions.h 42 | if (WIN32) 43 | add_custom_command( 44 | OUTPUT ${gitversion_h} 45 | COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_files_dir} 46 | COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"${version}\"" >> ${gitversion_h}; 47 | COMMAND ${CMAKE_COMMAND} -E echo "#define PLATFORM_WINDOWS 1" >> ${gitversion_h} 48 | COMMAND ${CMAKE_COMMAND} -E echo "#define ENABLE_LOGGING 1" >> ${gitversion_h} 49 | COMMAND ${CMAKE_COMMAND} -E echo "#define DEFAULT_VISIBILITY /**/" >> ${gitversion_h} 50 | COMMENT "Generating gitversion.h" 51 | VERBATIM 52 | ) 53 | else () 54 | add_custom_command( 55 | OUTPUT ${gitversion_h} 56 | COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_files_dir} 57 | COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"${version}\"" >> ${gitversion_h}; 58 | COMMENT "Generating gitversion.h" 59 | VERBATIM 60 | ) 61 | endif (WIN32) 62 | 63 | add_library( 64 | libuuu 65 | SHARED 66 | ../libuuu/error.cpp 67 | ../libuuu/buffer.cpp 68 | ../libuuu/cmd.cpp 69 | ../libuuu/config.cpp 70 | ../libuuu/notify.cpp 71 | ../libuuu/sdps.cpp 72 | ../libuuu/trans.cpp 73 | ../libuuu/usbhotplug.cpp 74 | ../libuuu/version.cpp 75 | ../libuuu/sdp.cpp 76 | ../libuuu/fastboot.cpp 77 | ../libuuu/zip.cpp 78 | ../libuuu/fat.cpp 79 | ../libuuu/tar.cpp 80 | ../libuuu/rominfo.cpp 81 | ../libuuu/http.cpp 82 | ../libuuu/hidreport.cpp 83 | ../libuuu/sparse.cpp 84 | ../libuuu/bmap.cpp 85 | ${gitversion_h} 86 | ) 87 | 88 | find_package(PkgConfig REQUIRED) 89 | pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0) 90 | pkg_check_modules(tinyxml2 REQUIRED IMPORTED_TARGET tinyxml2) 91 | pkg_check_modules(bzip2 REQUIRED IMPORTED_TARGET bzip2) 92 | pkg_check_modules(zstd REQUIRED IMPORTED_TARGET libzstd) 93 | pkg_check_modules(openssl REQUIRED IMPORTED_TARGET openssl) 94 | pkg_check_modules(zlib REQUIRED IMPORTED_TARGET zlib) 95 | 96 | 97 | if (DARWIN) 98 | set(CMAKE_C_COMPILER clang) 99 | set(CMAKE_CXX_COMPILER clang++) 100 | endif(DARWIN) 101 | 102 | if (WIN32) 103 | add_definitions(-D_WIN32 -DWIN32 -DDLL_EXPORT_LIBUUU) 104 | set(CMAKE_CXX_FLAGS_RELEASE "/MT") 105 | set(CMAKE_CXX_FLAGS_DEBUG "/MTd") 106 | endif(WIN32) 107 | 108 | add_definitions(-DUUUSSL) 109 | 110 | if (UNIX) 111 | set(CMAKE_CXX_FLAGS "-g -Wall -Wstrict-aliasing -Wall -Wextra") 112 | endif(UNIX) 113 | 114 | 115 | 116 | target_link_libraries(libuuu PkgConfig::libusb PkgConfig::tinyxml2 PkgConfig::bzip2 PkgConfig::zstd PkgConfig::zlib PkgConfig::openssl) 117 | -------------------------------------------------------------------------------- /uuu/buildincmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | extern const char * g_vt_boldwhite; 40 | extern const char * g_vt_default; 41 | extern const char * g_vt_kcyn; 42 | extern const char * g_vt_green; 43 | extern const char * g_vt_red ; 44 | extern const char * g_vt_yellow; 45 | 46 | /** 47 | * @brief Structure to hold the raw data of a built-in script 48 | */ 49 | struct BuiltInScriptRawData 50 | { 51 | //! The name of the built-in script 52 | const char * const m_name = nullptr; 53 | //! The actual built-in script itself 54 | const char * const m_text = nullptr; 55 | //! A description of the built-in script's purpose 56 | const char * const m_desc = nullptr; 57 | }; 58 | 59 | class BuiltInScript 60 | { 61 | public: 62 | /** 63 | * @brief A class for representing arguments of built-in scripts represented 64 | * by BuiltInScript 65 | */ 66 | class Arg 67 | { 68 | public: 69 | enum 70 | { 71 | ARG_MUST = 0x1, 72 | ARG_OPTION = 0x2, 73 | ARG_OPTION_KEY = 0x4, 74 | }; 75 | 76 | void parser(const std::string &option); 77 | 78 | //! The name of the argument 79 | std::string m_name; 80 | //! A description of the argument 81 | std::string m_desc; 82 | //! Flags of the argument (basically if it's optional or not) 83 | uint32_t m_flags = ARG_MUST; 84 | //! The argument whose value this one will fall back to if it's optional 85 | //! and not given explicitly 86 | std::string m_fallback_option; 87 | }; 88 | 89 | BuiltInScript() {}; 90 | BuiltInScript(const BuiltInScriptRawData*p); 91 | 92 | std::string replace_script_args(const std::vector &args) const; 93 | void show() const; 94 | void show_cmd() const; 95 | 96 | //! The actual script which is being represented 97 | const std::string m_text; 98 | //! A description of the script's purpose 99 | const std::string m_desc; 100 | //! A short name of the built-in script 101 | const std::string m_name; 102 | //! The arguments of the built-in script 103 | std::vector m_args; 104 | 105 | private: 106 | bool find_args(const std::string &arg) const; 107 | }; 108 | 109 | /** 110 | * @brief A map of all built-in scripts indexed by their names 111 | * 112 | * Each built-in script is represented by a BuiltInScript instance. 113 | */ 114 | class BuiltInScriptMap : public std::map 115 | { 116 | public: 117 | BuiltInScriptMap(const BuiltInScriptRawData*p); 118 | 119 | void PrintAutoComplete(const std::string &match, const char *space = " ") const; 120 | void ShowAll() const; 121 | void ShowCmds(FILE * file=stdout) const; 122 | }; 123 | 124 | //! A map of the built-in scripts' names to their BuiltInScript representations 125 | extern BuiltInScriptMap g_BuildScripts; 126 | -------------------------------------------------------------------------------- /webusb/src/logic/useHIDBoot.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | import {useEffect, useState} from 'react'; 33 | 34 | const HIDrequestParams = { 35 | filters: [{ vendorId: 8137, productId: 303 }] 36 | }; 37 | const outputReportId = 0x02; 38 | 39 | const useHIDBoot = (bootFile) => { 40 | const [HIDdevice, setHIDdevice] = useState(); 41 | const [bootProgress, setBootProgress] = useState(0); 42 | const [bootTotal, setBootTotal] = useState(0); 43 | 44 | useEffect(()=> { 45 | navigator.hid.addEventListener("connect", handleConnectedDevice); 46 | navigator.hid.addEventListener("disconnect", handleDisconnectedDevice); 47 | }, []) 48 | 49 | useEffect(() => { 50 | const downloadBoot = async() => { 51 | if (!HIDdevice) return; 52 | await HIDdevice.open(); 53 | console.log("Opened device: " + HIDdevice.productName); 54 | 55 | HIDdevice.addEventListener("inputreport", handleInputReport); 56 | doUBoot(); 57 | } 58 | downloadBoot(); 59 | }, [HIDdevice]) 60 | 61 | const handleConnectedDevice = (e) => { 62 | console.log("Device connected: " + e.device.productName); 63 | } 64 | 65 | const handleDisconnectedDevice = (e) => { 66 | console.log("Device disconnected: " + e.device.productName); 67 | } 68 | 69 | const handleInputReport = (e) => { 70 | console.log(e.device.productName + ": got input report " + e.reportId); 71 | console.log(new Uint8Array(e.data.buffer)); 72 | } 73 | 74 | const requestHIDDevice = async() => { 75 | const devices = await navigator.hid.requestDevice(HIDrequestParams); 76 | 77 | if (devices.length === 0) return; 78 | setHIDdevice(devices[0]); 79 | } 80 | 81 | const doUBoot = async() => { 82 | console.log("trying to boot..."); 83 | 84 | if (!bootFile) {console.log("choose a file"); return 0;} 85 | const imageByteLength = bootFile.size; 86 | console.log(bootFile) // 1313792 87 | setBootTotal(imageByteLength); 88 | setBootProgress(0); 89 | 90 | console.log(await bootFile.arrayBuffer()) 91 | 92 | for (let i=0; 1024*i imageByteLength) 95 | len = imageByteLength-1024*i; 96 | else 97 | len = 1024; 98 | const packet = await bootFile.slice(1024*i, 1024*i+len).arrayBuffer(); 99 | await HIDdevice.sendReport(outputReportId, packet) 100 | setBootProgress((1024*i + len)); 101 | console.log(1024*i + len) 102 | } 103 | } 104 | 105 | return [{ 106 | requestHIDDevice: requestHIDDevice, 107 | HIDdevice: HIDdevice, 108 | bootProgress, 109 | bootTotal, 110 | }] 111 | } 112 | 113 | export default useHIDBoot; 114 | -------------------------------------------------------------------------------- /libuuu/tar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "zlib.h" 37 | #include 38 | #include "buffer.h" 39 | #include "liberror.h" 40 | #include "libuuu.h" 41 | #include 42 | #include 43 | #include "tar.h" 44 | #include 45 | #include 46 | using namespace std; 47 | 48 | int Tar::Open(const string &filename) 49 | { 50 | bool end_of_file=false; 51 | char end_of_file_blocks[2*TAR_BLOCK_SIZE]; 52 | memset(end_of_file_blocks, 0, sizeof(end_of_file_blocks) ); 53 | m_tarfilename=filename; 54 | 55 | shared_ptr file = get_file_buffer(filename); 56 | if(file == nullptr) 57 | return -1; 58 | 59 | uint8_t* data=file->data(); 60 | uint64_t block_counter=0; 61 | while(!end_of_file) 62 | { 63 | if(!memcmp(end_of_file_blocks,data+block_counter*TAR_BLOCK_SIZE,TAR_BLOCK_SIZE)) 64 | { 65 | end_of_file=true; 66 | break; 67 | } 68 | struct Tar_header* th=(Tar_header*)(data+block_counter*TAR_BLOCK_SIZE); 69 | uint64_t size; 70 | string octal_str((char*)th->size); 71 | //printf("block_counter: %d\n",block_counter ); 72 | //printf("name: %s\n",th->name ); 73 | //printf("signature: %s\n",th->ustar ); 74 | //printf("size: %s\n", th->size); 75 | size=stoll(octal_str, 0, 8); 76 | string name((char*)th->name); 77 | m_filemap[name].size=size; 78 | m_filemap[name].offset=(block_counter+1)*TAR_BLOCK_SIZE; //+1 because the data located right after the header block 79 | m_filemap[name].filename.assign((char*)th->name); 80 | block_counter++; 81 | 82 | //skip the data blocks 83 | uint64_t data_block_num=size/TAR_BLOCK_SIZE; 84 | data_block_num += (size%TAR_BLOCK_SIZE>0)? 1:0; 85 | block_counter+=data_block_num; 86 | } 87 | return 0; 88 | } 89 | 90 | bool Tar::check_file_exist(const string &filename) 91 | { 92 | 93 | if (m_filemap.find(filename) == m_filemap.end()) 94 | { 95 | string err; 96 | err += "Can't find file "; 97 | err += filename; 98 | set_last_err_string(err); 99 | return false; 100 | } 101 | 102 | return true; 103 | } 104 | 105 | 106 | int Tar::get_file_buff(const string &filename, shared_ptr p ) 107 | { 108 | 109 | if (m_filemap.find(filename) == m_filemap.end()) 110 | { 111 | string err; 112 | err += "Can't find file "; 113 | err += filename; 114 | set_last_err_string(err); 115 | return -1; 116 | } 117 | 118 | p->resize(m_filemap[filename].size); 119 | atomic_fetch_or(&p->m_dataflags, FILEBUFFER_FLAG_KNOWN_SIZE); 120 | p->m_request_cv.notify_all(); 121 | 122 | shared_ptr file; 123 | file = get_file_buffer(m_tarfilename); 124 | size_t offset= m_filemap[filename].offset; 125 | size_t size=m_filemap[filename].size; 126 | 127 | p->ref_other_buffer(file, offset, size); 128 | atomic_fetch_or(&p->m_dataflags, FILEBUFFER_FLAG_LOADED); 129 | p->m_request_cv.notify_all(); 130 | 131 | return 0; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /webusb/src/helper/sparse.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {obj_to_arr} from './functions'; 18 | 19 | export const SPARSE_HEADER_MAGIC = 0xed26ff3a 20 | export const CHUNK_TYPE_RAW = 0xCAC1 21 | export const CHUNK_TYPE_FILL = 0xCAC2 22 | export const CHUNK_TYPE_DONT_CARE = 0xCAC3 23 | export const CHUNK_TYPE_CRC32 = 0xCAC4 24 | 25 | export const BLK_SZ = 0x1000; // bytes per block 26 | export const CHUNK_SZ = 0x1000; // blocks per full chunk 27 | 28 | const CHUNK_HEADER_SZ = 12; 29 | const SPARSE_HEADER_SZ = 28; 30 | 31 | export const sparse_header = { // in bytes 32 | magic : 4, /* 0xed26ff3a */ 33 | major_version : 2, /* (0x1) - reject images with higher major versions */ 34 | minor_version : 2, /* (0x0) - allow images with higher minor versions */ 35 | file_hdr_sz : 2, /* 28 bytes for first revision of the file format */ 36 | chunk_hdr_sz : 2, /* 12 bytes for first revision of the file format */ 37 | blk_sz : 4, /* block size in bytes, must be a multiple of 4 (4096) */ 38 | total_blks : 4, /* total blocks in the non-sparse output image */ // CHANGE 39 | total_chunks : 4, /* total chunks in the sparse input image */ // CHANGE 40 | image_checksum : 4, /* CRC32 checksum of the original data, counting "don't care" */ // CHANGE 41 | } 42 | 43 | export const chunk_header = { // in bytes 44 | chunk_type : 2, /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 45 | reserved1 : 2, 46 | chunk_sz : 4, /* in blocks in output image */ 47 | total_sz : 4, /* in bytes of chunk input file including chunk header and data */ 48 | } 49 | 50 | export const PACKET_SZ = 0x10000; 51 | export const DATA_SZ = CHUNK_SZ * BLK_SZ; // in bytes 52 | 53 | export function build_sparse_header(raw_data_bytelength, i) { 54 | let sparse_format = { 55 | magic : SPARSE_HEADER_MAGIC, /* 0xed26ff3a */ 56 | major_version : 0x1, /* (0x1) - reject images with higher major versions */ 57 | minor_version : 0x0, /* (0x0) - allow images with higher minor versions */ 58 | file_hdr_sz : 0x1c, /* 28 bytes for first revision of the file format */ 59 | chunk_hdr_sz : 0xc, /* 12 bytes for first revision of the file format */ 60 | blk_sz : 0x1000, /* block size in bytes, must be a multiple of 4 (4096) */ 61 | total_blks : 0x0, /* total blocks in the non-sparse output image */ // CHANGE 62 | total_chunks : 0x2, /* total chunks in the sparse input image */ //don't care and raw_data 63 | image_checksum : 0x0, /* CRC32 checksum of the original data, counting "don't care" */ 64 | } 65 | 66 | //first chunk is don't care: we don't care about the first 4096*i blocks 67 | //second chunk is raw_data: there are 4096 blocks in a 16mb chunk 68 | sparse_format.total_blks = CHUNK_SZ * i + raw_data_bytelength/BLK_SZ; 69 | 70 | return obj_to_arr(sparse_format, sparse_header, SPARSE_HEADER_SZ) 71 | } 72 | 73 | export function build_chunk_header (chunk_type, raw_data_bytelength, i) { 74 | let chunk_format = { 75 | chunk_type : chunk_type, /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 76 | reserved1 : 1, 77 | chunk_sz : 0, /* in blocks in output image */ 78 | total_sz : 0, /* in bytes of chunk input file including chunk header and data */ 79 | } 80 | 81 | if (chunk_type === CHUNK_TYPE_DONT_CARE) { 82 | chunk_format.chunk_sz = CHUNK_SZ * i; // don't care 83 | chunk_format.total_sz = CHUNK_SZ*BLK_SZ * i + CHUNK_HEADER_SZ; // bytes raw_data + header 84 | } 85 | else if (chunk_type === CHUNK_TYPE_RAW) { // raw_data 86 | chunk_format.chunk_sz = Math.ceil(raw_data_bytelength/BLK_SZ); 87 | chunk_format.total_sz = raw_data_bytelength + CHUNK_HEADER_SZ; 88 | 89 | console.log(chunk_format) 90 | } 91 | 92 | return obj_to_arr(chunk_format, chunk_header, CHUNK_HEADER_SZ); 93 | } -------------------------------------------------------------------------------- /snap/snapcraft.yaml: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | --- 3 | # Snapcraft Recipe for uuu (Universal Update Utility) 4 | # ------------------------------ 5 | # This file is in the YAML data serialization format: 6 | # http://yaml.org 7 | # For the spec. of writing this file refer the following documentation: 8 | # * The snapcraft format 9 | # https://docs.snapcraft.io/the-snapcraft-format/8337 10 | # * Snap Documentation 11 | # https://docs.snapcraft.io 12 | # * Topics under the doc category in the Snapcraft Forum 13 | # https://forum.snapcraft.io/c/doc 14 | # For support refer to the snapcraft section in the Snapcraft Forum: 15 | # https://forum.snapcraft.io/c/snapcraft 16 | # 17 | # Copyright (c) 2017 Snapcrafters 18 | # 19 | 20 | name: universal-update-utility 21 | title: Universal Update Utility - UUU 22 | summary: Freescale/NXP I.MX Chip image deploy tools 23 | description: | 24 | **Key features** 25 | 26 | - The real cross platform. Linux, Windows, MacOS(not test yet) 27 | - Multi devices program support 28 | - Daemon mode support 29 | - Few depedencies (only libusb, zlibc, libbz2) 30 | - Firmware (uboot/kernel) uses WCID to auto load the winusb driver 31 | on the Windows side. Windows7 users need to install the winusb driver 32 | from [https://zadig.akeo.ie/](https://zadig.akeo.ie/) Windows10 will 33 | install the driver automatically. 34 | 35 | **Search keywords** 36 | 37 | mfgtools, uuu, nxp, nxpmicro 38 | icon: snap/gui/universal-update-utility.png 39 | license: BSD-3-Clause 40 | adopt-info: main 41 | assumes: 42 | - command-chain 43 | # required by the `snapctl is-connected` command 44 | - snapd2.43 45 | base: core18 46 | confinement: strict 47 | grade: stable 48 | 49 | parts: 50 | # Launcher programs to fix problems at runtime 51 | launchers: 52 | source: snap/local/launchers 53 | plugin: dump 54 | organize: 55 | '*': bin/ 56 | stage: 57 | - -bin/README.* 58 | 59 | # Bash completion snippets 60 | bash-completion: 61 | source: snap/local/bash-completion 62 | plugin: dump 63 | organize: 64 | '*': bash-completion/ 65 | 66 | # Check out the tagged release revision if it isn't promoted to the stable channel 67 | # https://forum.snapcraft.io/t/selective-checkout-check-out-the-tagged-release-revision-if-it-isnt-promoted-to-the-stable-channel/10617 68 | selective-checkout: 69 | source: https://github.com/Lin-Buo-Ren/selective-checkout.git 70 | source-tag: v2.0.2 71 | plugin: dump 72 | build-packages: 73 | - curl 74 | - jq 75 | - sed 76 | 77 | - git 78 | stage: 79 | - scriptlets/selective-checkout 80 | prime: 81 | - -* 82 | 83 | main: 84 | after: 85 | - selective-checkout 86 | 87 | source: . 88 | source-depth: 50 89 | override-pull: | 90 | set -o nounset 91 | 92 | snapcraftctl pull 93 | 94 | "${SNAPCRAFT_STAGE}"/scriptlets/selective-checkout \ 95 | --release-tag-pattern='uuu_[[:digit:]]+(\.[[:digit:]]+){2}' \ 96 | --release-tag-prefix=uuu_ 97 | build-snaps: 98 | - cmake 99 | build-packages: 100 | # CMake shipped in Ubuntu 18.04(3.10.2) is too old 101 | #- cmake 102 | - g++ 103 | - libbz2-dev 104 | - libzstd-dev 105 | - libusb-1.0-0-dev 106 | - libssl-dev 107 | - zlib1g-dev 108 | - pkg-config 109 | plugin: cmake 110 | stage-packages: 111 | - libbz2-1.0 112 | - libusb-1.0-0 113 | - libssl1.0.0 114 | filesets: 115 | docs-copyright: 116 | - usr/share/doc/*/copyright 117 | 118 | executables: 119 | - bin/* 120 | 121 | library-shared: 122 | - lib/**/*.so* 123 | prime: 124 | - $docs-copyright 125 | - $executables 126 | - $library-shared 127 | 128 | apps: 129 | universal-update-utility: 130 | adapter: full 131 | command: bin/uuu 132 | command-chain: 133 | - bin/universal-update-utility-launch 134 | completer: bash-completion/universal-update-utility 135 | environment: 136 | # Snap runtime only ship C.UTF-8 locale 137 | LANG: C.UTF-8 138 | LC_ALL: C.UTF-8 139 | 140 | plugs: 141 | # Regular files access 142 | home: 143 | # Allow reading the SUDO_USER's uuu script when run as root 144 | # (by default only scripts under root's home dir is readable) 145 | read: all 146 | removable-media: # Non-A/C 147 | 148 | # NOTE: This only lifts the snapd side of confinement, the user still 149 | # require classic read/write access to the target device node 150 | raw-usb: 151 | 152 | network-bind: 153 | -------------------------------------------------------------------------------- /libuuu/bmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bmap.h" 5 | #include "buffer.h" 6 | #include "libcomm.h" 7 | #include "libuuu.h" 8 | 9 | bmap_mode g_bmap_mode = bmap_mode::Default; 10 | 11 | bmap_mode uuu_get_bmap_mode() 12 | { 13 | return g_bmap_mode; 14 | } 15 | 16 | int uuu_set_bmap_mode(bmap_mode mode) 17 | { 18 | g_bmap_mode = mode; 19 | return 0; 20 | } 21 | 22 | bool bmap_t::is_mapped_block(size_t index) const 23 | { 24 | if (index >= m_gap_begin && index < m_gap_end) 25 | return false; 26 | 27 | if (index >= m_gap_end && index < m_next_gap_begin) 28 | return true; 29 | 30 | if (index >= m_blk_count) 31 | return false; 32 | 33 | m_gap_begin = 0; 34 | 35 | for(auto iter = m_blk_map.begin(); iter != m_blk_map.end(); ++iter) { 36 | m_gap_end = iter->first; 37 | m_next_gap_begin = iter->second + 1; 38 | 39 | if (index >= m_gap_begin && index < m_gap_end) 40 | return false; 41 | 42 | if (index >= m_gap_end && index < m_next_gap_begin) 43 | return true; 44 | 45 | m_gap_begin = m_next_gap_begin; 46 | } 47 | 48 | return true; 49 | } 50 | 51 | static bool parse_image_size(bmap_t &bmap, const tinyxml2::XMLElement* elem) 52 | { 53 | auto img_size = elem->Int64Text(); 54 | if (img_size <= 0) { 55 | set_last_err_string("Invalid image size."); 56 | return false; 57 | } 58 | bmap.set_image_size(img_size); 59 | return true; 60 | } 61 | 62 | static bool parse_block_size(bmap_t &bmap, const tinyxml2::XMLElement* elem) 63 | { 64 | auto blk_size = elem->Int64Text(); 65 | if (blk_size <= 0) { 66 | set_last_err_string("Invalid block size."); 67 | return false; 68 | } 69 | bmap.set_block_size(blk_size); 70 | return true; 71 | } 72 | 73 | static bool parse_blocks_count(bmap_t &bmap, const tinyxml2::XMLElement* elem) 74 | { 75 | auto blk_count = elem->Int64Text(); 76 | if (blk_count <= 0) { 77 | set_last_err_string("Invalid blocks count."); 78 | return false; 79 | } 80 | bmap.set_blocks_count(blk_count); 81 | return true; 82 | } 83 | 84 | static bool parse_block_map(bmap_t &bmap, const tinyxml2::XMLElement* elem) 85 | { 86 | for (auto ch = elem->FirstChildElement(); ch != nullptr; ch = ch->NextSiblingElement()) { 87 | if (strcmp(ch->Name(), "Range")) { 88 | continue; 89 | } 90 | 91 | std::string text = ch->GetText(); 92 | 93 | auto f = std::strtoul(text.data(), nullptr, 0); 94 | auto l = f; 95 | 96 | auto pos = text.find('-'); 97 | if (pos != std::string::npos) 98 | l = std::strtoul(text.data() + pos + 1, nullptr, 0); 99 | 100 | bmap.set_mapped_range(f, l); 101 | } 102 | 103 | return true; 104 | } 105 | 106 | static const std::map handlers{ 107 | { "ImageSize", parse_image_size }, 108 | { "BlockSize", parse_block_size }, 109 | { "BlocksCount", parse_blocks_count }, 110 | { "BlockMap", parse_block_map }, 111 | }; 112 | 113 | void send_info(const std::string &msg) 114 | { 115 | uuu_notify nt; 116 | nt.type = uuu_notify::NOTIFY_CMD_INFO; 117 | nt.str = (char*)msg.c_str(); 118 | call_notify(nt); 119 | } 120 | 121 | int load_bmap(const std::string& filename, bmap_t& bmap) 122 | { 123 | tinyxml2::XMLDocument doc; 124 | auto fbuf = get_file_buffer(filename, true); 125 | if (fbuf == nullptr) { 126 | return -1; 127 | } 128 | 129 | auto dbuf = fbuf->request_data(0, fbuf->size()); 130 | if (dbuf == nullptr) { 131 | return -1; 132 | } 133 | 134 | auto err = doc.Parse((char*)dbuf->data(), dbuf->size()); 135 | if (err != tinyxml2::XML_SUCCESS) { 136 | return -1; 137 | } 138 | 139 | auto elem = doc.FirstChildElement(); 140 | 141 | if (!elem) { 142 | set_last_err_string("No bmap element"); 143 | return -1; 144 | } 145 | 146 | if (elem) { 147 | if (!elem->Attribute("version", "2.0")) { 148 | set_last_err_string("Invalid bmap version. 2.0 is expected."); 149 | return -1; 150 | } 151 | } 152 | 153 | for (auto ch = elem->FirstChildElement(); ch != nullptr; ch = ch->NextSiblingElement()) { 154 | auto it = handlers.find(ch->Name()); 155 | if (it == handlers.end()) 156 | continue; 157 | if (!it->second(bmap, ch)) 158 | return -1; 159 | } 160 | 161 | if (get_libuuu_debug_level() > LIBUUU_NORMAL) { 162 | auto info = std::string("\nUsing block map:") + 163 | "\n ImageSize: " + std::to_string(bmap.image_size()) + 164 | "\n BlockSize: " + std::to_string(bmap.block_size()) + 165 | "\n BlocksCount: " + std::to_string(bmap.blocks_count()) + 166 | "\n BlockMap:"; 167 | for (auto& r: bmap.mapped_ranges()) { 168 | if (r.first == r.second) 169 | info += "\n Range: " + std::to_string(r.first); 170 | else 171 | info += "\n Range: " + std::to_string(r.first) + 172 | "-" + std::to_string(r.second); 173 | } 174 | send_info(info + "\n"); 175 | } 176 | 177 | return 0; 178 | } 179 | -------------------------------------------------------------------------------- /msvc/libuuu.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {56b8d729-e8e8-4b90-be62-ef7a1d4e77c2} 6 | 7 | 8 | {9880b066-0013-4325-97c5-de85ce13b31f} 9 | 10 | 11 | 12 | 13 | Header Files 14 | 15 | 16 | Header Files 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | Header Files 68 | 69 | 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | Source Files 103 | 104 | 105 | Source Files 106 | 107 | 108 | Source Files 109 | 110 | 111 | Source Files 112 | 113 | 114 | Source Files 115 | 116 | 117 | Source Files 118 | 119 | 120 | Source Files 121 | 122 | 123 | Source Files 124 | 125 | 126 | Source Files 127 | 128 | 129 | -------------------------------------------------------------------------------- /wrapper/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=68.0", "wheel", "setuptools-scm>=8"] 3 | build-backend = "build_backend" 4 | backend-path = ["."] 5 | 6 | 7 | [project] 8 | dynamic = ["version", "dependencies"] 9 | name = "libuuu" 10 | description = "A python wraper for libuuu." 11 | 12 | requires-python = ">= 3.9" 13 | authors = [{ name = "NXP" }] 14 | maintainers = [] 15 | readme = { file = "README.md", content-type = "text/markdown" } 16 | license = { text = "BSD-3-Clause" } 17 | 18 | keywords = ["NXP"] 19 | classifiers = [ 20 | "Development Status :: 2 - Pre-Alpha", 21 | "Intended Audience :: Developers", 22 | "License :: OSI Approved :: BSD License", 23 | "Natural Language :: English", 24 | "Programming Language :: Python :: 3", 25 | "Programming Language :: Python :: 3.9", 26 | "Programming Language :: Python :: 3.10", 27 | "Programming Language :: Python :: 3.11", 28 | ] 29 | 30 | [tool.setuptools] 31 | packages = ["libuuu"] 32 | 33 | [tool.setuptools.package-data] 34 | "libuuu.lib.windows.x86_64" = [ 35 | "*.dll" 36 | ] 37 | "libuuu.lib.linux.x86_64" = [ 38 | "*.so" 39 | ] 40 | "libuuu.lib.linux.aarch64" = [ 41 | "*.so" 42 | ] 43 | "libuuu.lib.darwin.arm64" = [ 44 | "*.dylib" 45 | ] 46 | "libuuu.lib.darwin.x86_64" = [ 47 | "*.dylib" 48 | ] 49 | 50 | 51 | [tool.setuptools_scm] 52 | root = ".." 53 | version_file = "libuuu/__version__.py" 54 | tag_regex = "^(?Puuu_)?(?P\\d+(\\.\\d+)*)$" 55 | local_scheme = "no-local-version" 56 | fallback_version = "0.0.0" 57 | 58 | [tool.setuptools.dynamic] 59 | dependencies = {file = ["requirements.txt"]} 60 | 61 | [project.urls] 62 | Homepage = "https://github.com/nxp-imx/mfgtools/tree/master/wrapper" 63 | #Issues = "" 64 | 65 | [tool.pytest.ini_options] 66 | testpaths = ["tests"] 67 | junit_family = "xunit1" 68 | 69 | [tool.black] 70 | line-length = 100 71 | target-version = ["py39", "py310", "py311"] 72 | include = '\.pyi?$' 73 | 74 | [tool.isort] 75 | skip = ["__version__.py"] 76 | multi_line_output = 3 77 | include_trailing_comma = true 78 | force_grid_wrap = 0 79 | use_parentheses = true 80 | ensure_newline_before_comments = true 81 | line_length = 100 82 | 83 | [tool.mypy] 84 | disallow_untyped_defs = true 85 | ignore_missing_imports = true 86 | warn_unused_ignores = true 87 | 88 | [tool.pydocstyle] 89 | convention = "google" 90 | add_ignore = "D105,D301" 91 | match = '(?!test_|__version__).*\.py' 92 | 93 | [tool.pylint] 94 | format = { max-line-length = 120 } 95 | "messages control" = { disable = ["logging-fstring-interpolation"] } 96 | 97 | [tool.nxp_codecheck] 98 | git_parent_branch = "origin/master" 99 | output_directory = "reports" 100 | default_check_paths = ["libuuu", "tests", "build_backend.py"] 101 | 102 | # *********************************** Checker list *********************************** 103 | [[tool.nxp_codecheck.checkers]] 104 | name = "PYTEST" 105 | method = "check_pytest" 106 | # check_paths = [] # The default check paths could be overrides by local settings 107 | info_only = false 108 | kwargs = { disable_xdist = true } 109 | # dependencies = ["PYTEST"] 110 | [[tool.nxp_codecheck.checkers]] 111 | name = "PYLINT" 112 | method = "check_pylint" 113 | # check_paths = [] # The default check paths could be overrides by local settings 114 | info_only = false 115 | [[tool.nxp_codecheck.checkers]] 116 | name = "MYPY" 117 | method = "check_mypy" 118 | # check_paths = [] # The default check paths could be overrides by local settings 119 | info_only = false 120 | [[tool.nxp_codecheck.checkers]] 121 | name = "PYDOCSTYLE" 122 | method = "check_pydocstyle" 123 | # check_paths = [] # The default check paths could be overrides by local settings 124 | info_only = false 125 | [[tool.nxp_codecheck.checkers]] 126 | name = "BLACK" 127 | method = "check_black" 128 | # check_paths = [] # The default check paths could be overrides by local settings 129 | info_only = false 130 | dependencies = [] 131 | fixer = "fix_black" 132 | [[tool.nxp_codecheck.checkers]] 133 | name = "ISORT" 134 | method = "check_isort" 135 | # check_paths = [] # The default check paths could be overrides by local settings 136 | info_only = false 137 | dependencies = [] 138 | fixer = "fix_isort" 139 | [[tool.nxp_codecheck.checkers]] 140 | name = "COPYRIGHT" 141 | method = "check_copyright_year" 142 | # check_paths = [] # The default check paths could be overrides by local settings 143 | info_only = false 144 | dependencies = [] 145 | fixer = "fix_copyright_year" 146 | [[tool.nxp_codecheck.checkers]] 147 | name = "PY_HEADERS" 148 | method = "check_py_file_headers" 149 | # check_paths = [] # The default check paths could be overrides by local settings 150 | info_only = false 151 | dependencies = [] 152 | fixer = "fix_py_file_headers" 153 | [[tool.nxp_codecheck.checkers]] 154 | name = "CYCLIC" 155 | method = "check_cyclic_imports" 156 | # check_paths = [] # The default check paths could be overrides by local settings 157 | info_only = false 158 | dependencies = [] 159 | -------------------------------------------------------------------------------- /uuu/uuu.lst: -------------------------------------------------------------------------------- 1 | uuu_version 1.0.0 2 | # 3 | # uuu(universal update utility) command list file 4 | # First line must contain the minimum required uuu host version 5 | # --------------------------------------------------------------------- 6 | # Command Format PROTOCOL COMMAND ARG 7 | # PROTOCOL 8 | # ALL protocol supported common commands 9 | # done #last command for whole flow 10 | # delay # delay ms 11 | # sh\shell #Run shell command, such as wget to file from network 12 | # < #use shell command's output as uuu command 13 | # this command generally used to burn some sequence number, such as production id and mac address 14 | # for example: 15 | # FB:< echo ucmd print 16 | # 17 | # CFG: Config protocol of specific usb device vid/pid 18 | # SDPS|SDP|FB\Fastboot|FBK -chip -pid -vid [-bcdversion ] 19 | # 20 | # SDPS: Stream download after MX8QXPB0 21 | # boot -f [-offset 0x0000] 22 | # 23 | # SDP: iMX6/iMX7 HID download protocol. 24 | # dcd -f 25 | # write -f [-addr 0x000000] [-ivt 0] 26 | # jump -f [-ivt 0] 27 | # boot -f [-nojump] 28 | # rdmem -addr -format <8|16|32> 29 | # wrmem -addr -format <8|16|32> -value 30 | # 31 | # FB[-t timeout]:\Fastboot: android fastboot protocol (timeout in ms). 32 | # getvar 33 | # ucmd 34 | # acmd 35 | # flash [-raw2sparse [{-no-bmap|-bmap 36 | # download -f 37 | # crc -f [-format "mmc read $loadaddr"] [-blksz 512] [-each 0x4000000] 38 | # [-seek 0] [-skip 0] [-nostop] 39 | # each CRC size each loop 40 | # seek skip bytes from storage 41 | # skip skip bytes from -f 42 | # nostop continue check even if found mismatch 43 | # write -f [-format "mmc write $loadaddr"] [-blksz 512] [-each 0x4000000] 44 | # [-seek 0] [-skip 0] [-nostop] 45 | # each write size each loop 46 | # seek skip bytes from storage 47 | # skip skip bytes from -f 48 | # nostop continue write even if error occurs 49 | # 50 | # 51 | # FBK: community kernel with fastboot protocol (NOT compatible with fastboot tools). 52 | # ucmd and wait for command finish 53 | # acmd don't wait for command finish 54 | # sync wait for acmd process to finish 55 | # ucp copy file from/to target 56 | # T: means target board file 57 | # T:- means copy data to target's stdio pipe 58 | # copy image T:/root/image ;download image to path /root/image 59 | # copy T:/root/image image ;upload /root/image to file image 60 | # Example on how to transfer big files: 61 | # acmd tar - ; run tar background and get data from stdio 62 | # ucp rootfs.tar.gz T:- ; send to target stdio pipe 63 | # sync ; wait for tar process to exit 64 | # 65 | # For example: 66 | # SDPS: boot -f 67 | # SDP: boot -f 68 | # CFG: SDP: -chip imx6ull -pid 0x1234 -vid 0x5678 69 | # 70 | # SDP: boot -f u-boot-imx7dsabresd_sd.imx -nojump 71 | # SDP: write -f zImage -addr 0x80800000 72 | # SDP: write -f zImage-imx7d-sdb.dtb -addr 0x83000000 73 | # SDP: write -f fsl-image-mfgtool-initramfs-imx_mfgtools.cpio.gz.u-boot -addr 0x83800000 74 | # SDP: jump -f u-boot-dtb.imx -ivt 75 | 76 | CFG: FB: -vid 0x18D1 -pid 0x0D02 77 | SDP: boot -f u-boot-dtb.imx 78 | FB: getvar version 79 | FB: ucmd setenv fastboot_buffer 0x80800000 80 | FB: download -f zImage 81 | FB: ucmd setenv fastboot_buffer 0x83000000 82 | FB: download -f zImage-imx7d-sdb.dtb 83 | FB: ucmd bootz 0x80800000 - 0x83000000 84 | -------------------------------------------------------------------------------- /libuuu/ffu_format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | //ref: https://docs.microsoft.com/en-us/windows-hardware/manufacture/mobile/ffu-image-format 33 | 34 | #ifndef LIBSPARSE_FFU_FORMAT_H 35 | #define LIBSPARSE_FFU_FORMAT_H 36 | 37 | #include 38 | 39 | #define FFU_SECURITY_SIGNATURE "SignedImage " 40 | 41 | #pragma pack(1) 42 | 43 | typedef struct _FFU_SECURITY_HEADER 44 | { 45 | uint32_t cbSize; // size of struct, overall 46 | uint8_t signature[12]; // "SignedImage " 47 | uint32_t dwChunkSizeInKb; // size of a hashed chunk within the image 48 | uint32_t dwAlgId; // algorithm used to hash 49 | uint32_t dwCatalogSize; // size of catalog to validate 50 | uint32_t dwHashTableSize; // size of hash table 51 | } FFU_SECURITY_HEADER; 52 | 53 | #define FFU_SIGNATURE "ImageFlash " 54 | 55 | typedef struct _IMAGE_HEADER 56 | { 57 | uint32_t cbSize; // sizeof(ImageHeader) 58 | uint8_t Signature[12]; // "ImageFlash " 59 | uint32_t ManifestLength; // in bytes 60 | uint32_t dwChunkSize; // Used only during image generation. 61 | } FFU_IMAGE_HEADER; 62 | 63 | typedef struct _STORE_HEADER 64 | { 65 | uint32_t dwUpdateType; // indicates partial or full flash 66 | uint16_t MajorVersion, MinorVersion; // used to validate struct 67 | uint16_t FullFlashMajorVersion, FullFlashMinorVersion; // FFU version, i.e. the image format 68 | uint8_t szPlatformId[192]; // string which indicates what device this FFU is intended to be written to 69 | uint32_t dwBlockSizeInBytes; // size of an image block in bytes - the device's actual sector size may differ 70 | uint32_t dwWriteDescriptorCount; // number of write descriptors to iterate through 71 | uint32_t dwWriteDescriptorLength; // total size of all the write descriptors, in bytes (included so they can be read out up front and interpreted later) 72 | uint32_t dwValidateDescriptorCount; // number of validation descriptors to check 73 | uint32_t dwValidateDescriptorLength; // total size of all the validation descriptors, in bytes 74 | uint32_t dwInitialTableIndex; // block index in the payload of the initial (invalid) GPT 75 | uint32_t dwInitialTableCount; // count of blocks for the initial GPT, i.e. the GPT spans blockArray[idx..(idx + count -1)] 76 | uint32_t dwFlashOnlyTableIndex; // first block index in the payload of the flash-only GPT (included so safe flashing can be accomplished) 77 | uint32_t dwFlashOnlyTableCount; // count of blocks in the flash-only GPT 78 | uint32_t dwFinalTableIndex; // index in the table of the real GPT 79 | uint32_t dwFinalTableCount; // number of blocks in the real GPT 80 | uint16_t NumOfStores; // Total number of stores (V2 only) 81 | uint16_t StoreIndex; // Current store index, 1-based (V2 only) 82 | uint64_t StorePayloadSize; // Payload data only, excludes padding (V2 only) 83 | uint16_t DevicePathLength; // Length of the device path (V2 only) 84 | uint16_t DevicePath[1]; // Device path has no NUL at then end (V2 only) 85 | } FFU_STORE_HEADER; 86 | 87 | typedef struct _VALIDATION_ENTRY 88 | { 89 | uint32_t dwSectorIndex; 90 | uint32_t dwSectorOffset; 91 | uint32_t dwByteCount; 92 | uint8_t rgCompareData[1]; // size is dwByteCount 93 | } FFU_VALIDATION_ENTRY; 94 | 95 | enum DISK_ACCESS_METHOD 96 | { 97 | DISK_BEGIN = 0, 98 | DISK_END = 2 99 | }; 100 | 101 | typedef struct _DISK_LOCATION 102 | { 103 | uint32_t dwDiskAccessMethod; 104 | uint32_t dwBlockIndex; 105 | } FFU_DISK_LOCATION; 106 | 107 | typedef struct _BLOCK_DATA_ENTRY 108 | { 109 | uint32_t dwLocationCount; 110 | uint32_t dwBlockCount; 111 | FFU_DISK_LOCATION rgDiskLocations[1]; 112 | } FFU_BLOCK_DATA_ENTRY; 113 | #pragma pack() 114 | 115 | #endif // LIBSPARSE_FFU_FORMAT_H 116 | -------------------------------------------------------------------------------- /libuuu/libcomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "libuuu.h" 38 | 39 | #pragma once 40 | 41 | using namespace std; 42 | 43 | void call_notify(struct uuu_notify nf); 44 | 45 | #define log printf 46 | #define dbg printf 47 | 48 | int get_libusb_debug_level() noexcept; 49 | int get_libuuu_debug_level() noexcept; 50 | 51 | class string_ex : public std::string 52 | { 53 | public: 54 | 55 | int format(const char *fmt, ...) 56 | { 57 | va_list args; 58 | va_start(args, fmt); 59 | size_t len = std::vsnprintf(nullptr, 0, fmt, args); 60 | va_end(args); 61 | 62 | this->resize(len); 63 | 64 | va_start(args, fmt); 65 | std::vsnprintf((char*)c_str(), len+1, fmt, args); 66 | va_end(args); 67 | 68 | return 0; 69 | } 70 | void replace(char a, char b) 71 | { 72 | for (size_t i = 0; i < size(); i++) 73 | if (at(i) == a) 74 | (*this)[i] = b; 75 | } 76 | }; 77 | 78 | class Path : public string_ex 79 | { 80 | public: 81 | string get_file_name() 82 | { 83 | replace('\\', '/'); 84 | size_t pos; 85 | pos = rfind('/'); 86 | if (pos == string::npos) 87 | return *this; 88 | return substr(pos + 1); 89 | } 90 | }; 91 | 92 | inline uint64_t EndianSwap(uint64_t x) { 93 | return (((x & 0x00000000000000ffLL) << 56) | 94 | ((x & 0x000000000000ff00LL) << 40) | 95 | ((x & 0x0000000000ff0000LL) << 24) | 96 | ((x & 0x00000000ff000000LL) << 8) | 97 | ((x & 0x000000ff00000000LL) >> 8) | 98 | ((x & 0x0000ff0000000000LL) >> 24) | 99 | ((x & 0x00ff000000000000LL) >> 40) | 100 | ((x & 0xff00000000000000LL) >> 56)); 101 | } 102 | 103 | inline uint32_t EndianSwap(uint32_t x) 104 | { 105 | return (x >> 24) | 106 | ((x << 8) & 0x00FF0000) | 107 | ((x >> 8) & 0x0000FF00) | 108 | (x << 24); 109 | } 110 | inline uint16_t EndianSwap(uint16_t x) 111 | { 112 | return (x >> 8) | 113 | ((x << 8) & 0xFF00); 114 | } 115 | 116 | inline string str_to_upper(const string &str) 117 | { 118 | std::locale loc; 119 | string s; 120 | 121 | for (size_t i = 0; i < str.size(); i++) 122 | s.push_back(std::toupper(str[i], loc)); 123 | 124 | return s; 125 | } 126 | 127 | inline string remove_quota(string str) 128 | { 129 | if (!str.empty()) 130 | { 131 | if (str[0] == '"') 132 | { 133 | str.erase(0, 1); 134 | if (!str.empty() && str[str.size() - 1] == '"') 135 | str.erase(str.size() - 1, 1); 136 | } 137 | } 138 | return str; 139 | } 140 | 141 | inline bool compare_str(const string &str1, const string &str2, bool ignore_case) 142 | { 143 | if (ignore_case) 144 | return str_to_upper(str1) == str_to_upper(str2); 145 | else 146 | return str1 == str2; 147 | } 148 | 149 | uint16_t str_to_uint16(const string &str, bool * conversion_succeeded = nullptr); 150 | uint32_t str_to_uint32(const string &str, bool * conversion_succeeded = nullptr); 151 | uint64_t str_to_uint64(const string &str, bool * conversion_succeeded = nullptr); 152 | 153 | template 154 | inline T round_up(T x, T align) 155 | { 156 | return (x + align - 1) / align * align; 157 | } 158 | 159 | template 160 | inline T div_round_up(T x, T align) 161 | { 162 | return (x + align - 1) / align; 163 | } 164 | 165 | inline std::string trim(const std::string &s) 166 | { 167 | auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) {return std::isspace(c); }); 168 | return std::string(wsfront, std::find_if_not(s.rbegin(), std::string::const_reverse_iterator(wsfront), [](int c) {return std::isspace(c); }).base()); 169 | } 170 | 171 | static inline bool uuu_force_bmap() { 172 | return uuu_get_bmap_mode() == bmap_mode::Force; 173 | } 174 | 175 | static inline bool uuu_ignore_bmap() { 176 | return uuu_get_bmap_mode() == bmap_mode::Ignore; 177 | } 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # uuu (Universal Update Utility), mfgtools 3.0 2 | 3 | [![macOS Build](https://github.com/nxp-imx/mfgtools/actions/workflows/macOS.yaml/badge.svg?branch=master)](https://github.com/nxp-imx/mfgtools/actions/workflows/macOS.yaml) 4 | [![Build with VS Studio](https://github.com/nxp-imx/mfgtools/actions/workflows/win.yaml/badge.svg)](https://github.com/nxp-imx/mfgtools/actions/workflows/win.yaml) 5 | [![Build for x64 ubuntu-lastest](https://github.com/nxp-imx/mfgtools/actions/workflows/build.yaml/badge.svg)](https://github.com/nxp-imx/mfgtools/actions/workflows/build.yaml) 6 | 7 | [![GitHub](https://img.shields.io/github/license/nxp-imx/mfgtools.svg)](https://github.com/nxp-imx/mfgtools/blob/master/LICENSE) 8 | 9 | [![universal-update-utility](https://snapcraft.io/universal-update-utility/badge.svg)](https://snapcraft.io/universal-update-utility) 10 | 11 | Freescale/NXP I.MX Chip image deploy tools. 12 | **original linux version uses "linux" branch, windows version uses "windows" branch** 13 | 14 | uuu (universal update utility) for nxp imx chips -- libuuu-1.0.1-gffd9837 15 | 16 | Succeded:0 Failed:3 Wait for Known USB Devices to Appear... 17 | 18 | 1:11 5/5 [ ] SDP: jump -f u-boot-dtb.imx -ivtinitramf.... 19 | 2:1 1/5 [===> ] SDP: boot -f u-boot-imx7dsabresd_sd.imx .... 20 | 21 | # Key features 22 | - The real cross platform. Linux, Windows, MacOS(not test yet) 23 | - Multi devices program support 24 | - Daemon mode support 25 | - Few dependencies (only libusb, zlibc, libbz2) 26 | - Firmware (uboot/kernel) uses WCID to auto load the winusb driver on the Windows side. Windows7 users need to install the winusb driver from https://zadig.akeo.ie/ Windows10 will install the driver automatically. 27 | 28 | # Examples: 29 | ``` 30 | uuu u-boot.imx Download u-boot.imx via HID device 31 | 32 | uuu list.uu Run all the commands in list.uu 33 | 34 | uuu -s Enter shell mode. Input command. 35 | 36 | uuu -v u-boot.imx verbose mode 37 | 38 | uuu -d u-boot.imx Once it detects the attachment of a known device, download boot.imx. 39 | 40 | u-boot.imx can be replaced, new file will be download once board reset. 41 | 42 | Do not unplug the SD card, write to the SD card, nor plug in a SD card when debugging uboot. 43 | 44 | uuu -b emmc u-boot.imx write u-boot.imx to emmc boot partition. u-boot.imx need enable fastboot 45 | 46 | uuu -b emmc_all wic.zst decompress wic.zst file and download the whole image into emmc 47 | ``` 48 | 49 | # Prebuilt Image and pdf document 50 | 51 | The prebuilt image and document are here: 52 | - https://github.com/nxp-imx/mfgtools/releases 53 | - **ubuntu 22.04, 'apt-get install uuu'** 54 | - UUU.pdf is snapshot of [wiki](https://github.com/nxp-imx/mfgtools/wiki) 55 | 56 | # How to Build: 57 | 58 | ## Windows 59 | - `git clone --recurse-submodules https://github.com/nxp-imx/mfgtools.git` 60 | - `cd mfgtools` 61 | - `open msvs/uuu.sln with Visual Studio 2017` 62 | 63 | Visual Studio 64 | 65 | Note that, since uuu is an OSI compliant Open Source project, you are entitled to download and use the freely available Visual Studio Community Edition to build, run or develop for uuu. As per the Visual Studio Community Edition license this applies regardless of whether you are an individual or a corporate user. 66 | 67 | ## Linux 68 | - `git clone https://github.com/nxp-imx/mfgtools.git` 69 | - `cd mfgtools` 70 | - `sudo apt-get install libusb-1.0-0-dev libbz2-dev libzstd-dev pkg-config cmake libssl-dev g++ zlib1g-dev libtinyxml2-dev` 71 | - `cmake . && make` 72 | 73 | The above commands build mfgtools in source. To build it out of source 74 | (requires cmake 3.13 or newer): 75 | - `cmake -S . -B build` 76 | - `cmake --build build --target all` 77 | 78 | For cmake prior 3.13: 79 | - `mkdir build && cd build` 80 | - `cmake .. && make` 81 | 82 | ## macOS 83 | - `git clone https://github.com/nxp-imx/mfgtools.git` 84 | - `cd mfgtools` 85 | - `brew install cmake libusb openssl pkg-config tinyxml2` 86 | - `cmake -DOPENSSL_ROOT_DIR=$(brew --prefix)/opt/openssl . && make` 87 | 88 | Note that we assume [homebrew](https://brew.sh) is installed and can be used to resolve dependencies as shown above. The remaining dependency `libbz2` can be resolved via the XCode supplied libraries. 89 | 90 | Note if you meet "can't detach kernel driver" try to check libusb version. 91 | ``` 92 | brew info libusb 93 | ==> libusb: stable 1.0.26 (bottled), HEAD 94 | ``` 95 | 96 | # Run environment 97 | - Windows 10 64 bit 98 | - Linux (Ubuntu) 64 bit 99 | - macOS (Catalina) 100 | - 32 bit systems will have problems with big files. 101 | 102 | # Python bindings 103 | We also provide Python bindings for `libuuu` to enable integration of functionality from `uuu` into your code. For more information see [wrapper](./wrapper/). 104 | 105 | # License 106 | uuu is licensed under the BSD license. See LICENSE. 107 | The BSD licensed prebuilt Windows binary version of uuu is statically linked with the LGPL libusb library, which remains LGPL. 108 | 109 | - bzip2 (BSD license) is from https://github.com/enthought/bzip2-1.0.6 110 | - zlib (zlib license) is from https://github.com/madler/zlib.git 111 | - libusb (LGPL-2.1) is from https://github.com/libusb/libusb.git 112 | - zstd (Dual BSD\GPLv2 Licenses) is from https://github.com/facebook/zstd 113 | - tinyxml2 (zlib license) is from https://github.com/leethomason/tinyxml2 114 | -------------------------------------------------------------------------------- /libuuu/zip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 NXP. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | * 14 | * Neither the name of the NXP Semiconductor nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | #pragma once 32 | 33 | #include "backfile.h" 34 | 35 | #include "zlib.h" 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | /* Allow opportunistic use of the C++17 fall-through attribute . */ 42 | #if defined(__cplusplus) && __cplusplus >= 201703L 43 | #define FALLTHROUGH [[fallthrough]] 44 | #else 45 | #define FALLTHROUGH 46 | #endif 47 | 48 | class FileBuffer; 49 | 50 | #pragma pack(1) 51 | struct Zip_data_desc 52 | { 53 | uint32_t sign; 54 | uint32_t crc; 55 | uint32_t compressed_size; 56 | uint32_t uncompressed_size; 57 | }; 58 | 59 | struct Zip_file_desc 60 | { 61 | uint32_t sign; 62 | uint16_t version_mini_extract; 63 | uint16_t flags; 64 | uint16_t compress_method; 65 | uint16_t last_modify_time; 66 | uint16_t last_modify_date; 67 | uint32_t crc; 68 | uint32_t compressed_size; 69 | uint32_t uncompressed_size; 70 | uint16_t file_name_length; 71 | uint16_t extrafield_length; 72 | uint8_t filename[0]; 73 | }; 74 | struct Zip_central_dir 75 | { 76 | uint32_t sign; 77 | uint16_t version; 78 | uint16_t version_mini_extract; 79 | uint16_t flags; 80 | uint16_t compress_method; 81 | uint16_t last_modify_time; 82 | uint16_t last_modify_date; 83 | uint32_t crc; 84 | uint32_t compressed_size; 85 | uint32_t uncompressed_size; 86 | uint16_t file_name_length; 87 | uint16_t extrafield_length; 88 | uint16_t file_comment_length; 89 | uint16_t disk_number; 90 | uint16_t internal_file_attr; 91 | uint32_t external_file_attr; 92 | uint32_t offset; 93 | uint8_t filename[0]; 94 | }; 95 | 96 | struct Zip64_central_dir 97 | { 98 | uint32_t sign; 99 | uint16_t version; 100 | uint16_t version_mini_extract; 101 | uint16_t flags; 102 | uint16_t compress_method; 103 | uint16_t last_modify_time; 104 | uint16_t last_modify_date; 105 | uint32_t crc; 106 | uint32_t compressed_size; 107 | uint32_t uncompressed_size; 108 | uint16_t file_name_length; 109 | uint16_t extrafield_length; 110 | uint16_t file_comment_length; 111 | uint16_t disk_number; 112 | uint16_t internal_file_attr; 113 | uint32_t external_file_attr; 114 | uint32_t offset; 115 | uint8_t filename[0]; 116 | }; 117 | struct Zip_eocd 118 | { 119 | uint32_t sign; 120 | uint16_t num_of_thisdisk; 121 | uint16_t start_disk_of_dir; 122 | uint16_t num_of_dir_ondisk; 123 | uint16_t num_of_dir; 124 | uint32_t size_of_central_dir; 125 | uint32_t offset_of_central_dir; 126 | uint16_t length_of_comment; 127 | uint8_t comment[0]; 128 | }; 129 | 130 | struct Zip64_eocd_locator 131 | { 132 | uint32_t sign; 133 | uint32_t num_of_thisdisk; 134 | uint64_t offset_of_eocd; 135 | uint32_t total_num_disks; 136 | }; 137 | 138 | struct Zip64_eocd 139 | { 140 | uint32_t sign; 141 | uint64_t size_of_eocd; 142 | uint16_t version; 143 | uint16_t version_mini_extract; 144 | uint32_t num_of_dir_ondisk; 145 | uint32_t num_of_disk; 146 | uint64_t total_ondisk; 147 | uint64_t total; 148 | uint64_t size; 149 | uint64_t offset; 150 | }; 151 | 152 | struct Zip_ext 153 | { 154 | uint16_t tag; 155 | uint16_t size; 156 | }; 157 | 158 | #define EOCD_SIGNATURE 0x06054b50 159 | #define DIR_SIGNATURE 0x02014b50 160 | #define DATA_SIGNATURE 0x08074b50 161 | #define FILE_SIGNATURE 0x04034b50 162 | #define EOCD64_LOCATOR_SIGNATURE 0x07064b50 163 | #define EOCD64_SIGNATURE 0x06064b50 164 | 165 | class Zip; 166 | 167 | class Zip_file_Info 168 | { 169 | public: 170 | Zip_file_Info(); 171 | ~Zip_file_Info(); 172 | 173 | int decompress(Zip *pZip, std::shared_ptr p); 174 | 175 | private: 176 | std::string m_filename; 177 | uint32_t m_timestamp; 178 | size_t m_filesize; 179 | size_t m_compressedsize; 180 | size_t m_offset; 181 | z_stream m_strm; 182 | 183 | friend Zip; 184 | }; 185 | 186 | class Zip : public Backfile 187 | { 188 | public: 189 | int BuildDirInfo(); 190 | bool check_file_exist(const std::string &filename); 191 | int get_file_buff(std::string filename, std::shared_ptrp); 192 | int Open(const std::string &filename); 193 | 194 | std::map m_filemap; 195 | }; 196 | 197 | 198 | #pragma pack() 199 | --------------------------------------------------------------------------------