mirror of
https://github.com/linux-msm/qdl.git
synced 2026-02-25 13:12:25 -08:00
Compare commits
186 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a601db1868 | ||
|
|
29f623bd8c | ||
|
|
a83406f21b | ||
|
|
739b1ad4db | ||
|
|
cd32723503 | ||
|
|
9e5195cbe1 | ||
|
|
ce6faee104 | ||
|
|
a9deec3349 | ||
|
|
02c008adfd | ||
|
|
3250ce0026 | ||
|
|
228ab33af8 | ||
|
|
4288cebfdb | ||
|
|
7447251b25 | ||
|
|
80b45a99fe | ||
|
|
25562d208d | ||
|
|
d48d852ca2 | ||
|
|
ec418a144f | ||
|
|
3e5426d5cb | ||
|
|
03560e9e04 | ||
|
|
adf906c646 | ||
|
|
67472bf750 | ||
|
|
cc4dced2f8 | ||
|
|
e46302830c | ||
|
|
a79ccefb2e | ||
|
|
fbb965174d | ||
|
|
eab45794d2 | ||
|
|
669c2005d3 | ||
|
|
2204f90bee | ||
|
|
7bdf416118 | ||
|
|
4c942eea55 | ||
|
|
fb47383c92 | ||
|
|
a691179284 | ||
|
|
c70255e3e8 | ||
|
|
7a8b6f3115 | ||
|
|
8818b98e85 | ||
|
|
6454ab46f2 | ||
|
|
62464e4ab6 | ||
|
|
54da7531ea | ||
|
|
4d612bc25b | ||
|
|
cdcdc51a3d | ||
|
|
6c0fbcce08 | ||
|
|
ad123a9531 | ||
|
|
81da98bc8a | ||
|
|
4bb672f00f | ||
|
|
52cb41f0d7 | ||
|
|
cc55fda4b2 | ||
|
|
4ed250c184 | ||
|
|
5db7794e9f | ||
|
|
824d4c067e | ||
|
|
ec0e19f068 | ||
|
|
4e944d29da | ||
|
|
77df84fa12 | ||
|
|
672abb1e81 | ||
|
|
f066304676 | ||
|
|
fde56c8993 | ||
|
|
1ec12f6a1f | ||
|
|
c856721827 | ||
|
|
0b6b9e3b78 | ||
|
|
328e06962b | ||
|
|
172c3c257c | ||
|
|
8a996e5fed | ||
|
|
3ed79bef47 | ||
|
|
ccfa1fe073 | ||
|
|
f87efad54b | ||
|
|
c07419cb81 | ||
|
|
6867a75063 | ||
|
|
c69d9adc76 | ||
|
|
b3dccab6a6 | ||
|
|
3a7c00b931 | ||
|
|
f73656237d | ||
|
|
33a2f151a6 | ||
|
|
136f8e2158 | ||
|
|
30ac3a8abc | ||
|
|
ab17b2e78d | ||
|
|
c9abbe7aba | ||
|
|
cfdb938111 | ||
|
|
21966c61d0 | ||
|
|
2872a8ea62 | ||
|
|
ad320a1a66 | ||
|
|
8718752d81 | ||
|
|
20fab24ee0 | ||
|
|
4800d4afc2 | ||
|
|
e6469d9748 | ||
|
|
cc584d4560 | ||
|
|
a8e3f661d2 | ||
|
|
7b5d5da48d | ||
|
|
8c32a74086 | ||
|
|
a0f977935f | ||
|
|
0e08e852bf | ||
|
|
321e776cb7 | ||
|
|
23c84163aa | ||
|
|
aa44721fe8 | ||
|
|
8adc9f3192 | ||
|
|
ceddd78c9d | ||
|
|
0214cbd3b6 | ||
|
|
b121a92752 | ||
|
|
6fc456da62 | ||
|
|
ad13228e6a | ||
|
|
fa070e81b4 | ||
|
|
f63c4df679 | ||
|
|
b068cc58d9 | ||
|
|
f8fae69796 | ||
|
|
cbd46184d3 | ||
|
|
a1cd535439 | ||
|
|
a60d45c3b7 | ||
|
|
c647d6d9eb | ||
|
|
b761963272 | ||
|
|
adfdcc6b01 | ||
|
|
1d8a3fff7d | ||
|
|
8b01b6254e | ||
|
|
95be64392f | ||
|
|
aeb70e0645 | ||
|
|
b1ec56fc9e | ||
|
|
fac09b2980 | ||
|
|
b18bca7d28 | ||
|
|
ba6b6e5b3a | ||
|
|
0132a8eb5a | ||
|
|
7cc2748c61 | ||
|
|
25ce7fad22 | ||
|
|
37b0d0cf69 | ||
|
|
983ec51d02 | ||
|
|
5f2f82a526 | ||
|
|
2fd923ec97 | ||
|
|
5b69b112f5 | ||
|
|
74779c7a77 | ||
|
|
a10d2bf57b | ||
|
|
7cc077d066 | ||
|
|
7d4020fedd | ||
|
|
a629f43428 | ||
|
|
3b22df2bc7 | ||
|
|
dbcb6fed63 | ||
|
|
1acf511839 | ||
|
|
392394086d | ||
|
|
bdcf93b4a3 | ||
|
|
e25c981207 | ||
|
|
a8d10da050 | ||
|
|
0fcf944ab5 | ||
|
|
2021b303a8 | ||
|
|
f02ed6abca | ||
|
|
2e258d9d56 | ||
|
|
13681fcb35 | ||
|
|
3c0405c03d | ||
|
|
ec6c8a034e | ||
|
|
650b477ca5 | ||
|
|
00d93b29f5 | ||
|
|
7f75f17c53 | ||
|
|
40df480740 | ||
|
|
91e609b611 | ||
|
|
da8dd7139a | ||
|
|
b6e0ea31d7 | ||
|
|
56076936a6 | ||
|
|
bead963d33 | ||
|
|
760b3dffb0 | ||
|
|
7623ff5e1e | ||
|
|
fd48f7ce18 | ||
|
|
90d3a6fee6 | ||
|
|
1c958b2bc2 | ||
|
|
5ec4f210a0 | ||
|
|
1ac148c4e6 | ||
|
|
8456cb2cf5 | ||
|
|
8589513f65 | ||
|
|
ba86b03391 | ||
|
|
59717efcd4 | ||
|
|
5ea1e20c01 | ||
|
|
826a5cd4fd | ||
|
|
8f7987f756 | ||
|
|
b338928519 | ||
|
|
dc61f8f79e | ||
|
|
cfce0beeab | ||
|
|
a50ec8047c | ||
|
|
5fc4cdbba4 | ||
|
|
37edf318b2 | ||
|
|
d9935e1f54 | ||
|
|
d77b106a57 | ||
|
|
45cc3521d8 | ||
|
|
5d51472f1c | ||
|
|
df842101b1 | ||
|
|
44a80b1266 | ||
|
|
d2e791a950 | ||
|
|
b4c2e8f267 | ||
|
|
7be48f4fc9 | ||
|
|
19e8a2d4ba | ||
|
|
1fc3c04d17 | ||
|
|
0251833b4d | ||
|
|
febbbcc32e | ||
|
|
922699c4db |
35
.checkpatch.conf
Normal file
35
.checkpatch.conf
Normal file
@@ -0,0 +1,35 @@
|
||||
--no-tree
|
||||
--strict
|
||||
--max-line-length=120
|
||||
--ignore FILE_PATH_CHANGES
|
||||
--ignore EMAIL_SUBJECT
|
||||
--ignore SPLIT_STRING
|
||||
|
||||
# NEW_TYPEDEFS reports "do not add new typedefs"
|
||||
# typedef struct __attribute__((__packed__)) sparse_header {
|
||||
--ignore NEW_TYPEDEFS
|
||||
|
||||
# PREFER_DEFINED_ATTRIBUTE_MACRO reports this kind of messages:
|
||||
# WARNING: Prefer __packed over __attribute__((__packed__))
|
||||
--ignore PREFER_DEFINED_ATTRIBUTE_MACRO
|
||||
|
||||
# PREFER_KERNEL_TYPES reports this kind of messages (when using --strict):
|
||||
# "Prefer kernel type 'u32' over 'uint32_t'"
|
||||
--ignore PREFER_KERNEL_TYPES
|
||||
|
||||
# BRACES reports this kind of messages:
|
||||
# braces {} are not necessary for any arm of this statement
|
||||
--ignore BRACES
|
||||
|
||||
# CAMELCASE reports this kind of messages:
|
||||
# Avoid CamelCase: <xmlFreeDoc>
|
||||
--ignore CAMELCASE
|
||||
|
||||
# AVOID_EXTERNS reports this kind of messages:
|
||||
# externs should be avoided in .c files
|
||||
# extern const char *__progname;
|
||||
--ignore AVOID_EXTERNS
|
||||
|
||||
# COMMIT_LOG_LONG_LINE reports line lengths > 75 in commit log
|
||||
# Lets ignore this
|
||||
--ignore COMMIT_LOG_LONG_LINE
|
||||
155
.github/workflows/build.yml
vendored
Normal file
155
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
name: Buildtest
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { arch: x64, os: 24, runner: ubuntu-24.04 }
|
||||
- { arch: arm64, os: 24, runner: ubuntu-24.04-arm }
|
||||
- { arch: x64, os: 22, runner: ubuntu-22.04 }
|
||||
- { arch: arm64, os: 22, runner: ubuntu-22.04-arm }
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libxml2-dev libusb-1.0-0-dev
|
||||
|
||||
- name: Build
|
||||
run: make
|
||||
|
||||
- name: Run tests
|
||||
run: make tests
|
||||
|
||||
- name: Package
|
||||
run: |
|
||||
mkdir dist
|
||||
cp `pkg-config --variable=libdir libusb-1.0`/libusb-1.0.so.0 dist
|
||||
chmod 0644 dist/*
|
||||
cp qdl dist
|
||||
patchelf --set-rpath '$ORIGIN' dist/qdl
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: qdl-binary-ubuntu-${{matrix.os}}-${{ matrix.arch }}
|
||||
path: dist/*
|
||||
|
||||
|
||||
build-mac:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { sys: macos-14, arch: arm64 }
|
||||
- { sys: macos-13, arch: intel }
|
||||
runs-on: ${{ matrix.sys }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Dependencies
|
||||
run: |
|
||||
brew install libxml2
|
||||
|
||||
- name: Build
|
||||
run: make
|
||||
|
||||
- name: Run tests
|
||||
run: make tests
|
||||
|
||||
- name: Package
|
||||
run: |
|
||||
set -x
|
||||
mkdir dist
|
||||
cp `pkg-config --variable=libdir libusb-1.0`/libusb-1.0.0.dylib dist
|
||||
cp `pkg-config --variable=libdir liblzma`/liblzma.5.dylib dist
|
||||
chmod 0644 dist/*
|
||||
cp qdl dist
|
||||
|
||||
if uname -a | grep -q arm64; then
|
||||
LIBUSB_DIR=/opt/homebrew/opt/libusb/lib
|
||||
LIBLZMA_DIR=/usr/lib
|
||||
else
|
||||
LIBUSB_DIR=/usr/local/opt/libusb/lib
|
||||
LIBLZMA_DIR=/usr/local/opt/xz/lib
|
||||
fi
|
||||
|
||||
install_name_tool -add_rpath @executable_path dist/qdl
|
||||
install_name_tool -change $LIBUSB_DIR/libusb-1.0.0.dylib @rpath/libusb-1.0.0.dylib dist/qdl
|
||||
install_name_tool -change $LIBLZMA_DIR/liblzma.5.dylib @rpath/liblzma.5.dylib dist/qdl
|
||||
otool -L dist/qdl
|
||||
dist/qdl || true
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: qdl-binary-macos-${{ matrix.arch }}
|
||||
path: dist/*
|
||||
|
||||
build-windows:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { sys: windows-latest, arch: x64 }
|
||||
- { sys: windows-11-arm, arch: arm64 }
|
||||
runs-on: ${{ matrix.sys }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup MSYS2
|
||||
id: msys2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: MINGW64
|
||||
install: >
|
||||
base-devel
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-make
|
||||
mingw-w64-x86_64-pkg-config
|
||||
mingw-w64-x86_64-libxml2
|
||||
mingw-w64-x86_64-libusb
|
||||
|
||||
- name: Build
|
||||
run: make
|
||||
shell: msys2 {0}
|
||||
|
||||
- name: Run tests
|
||||
run: make tests
|
||||
shell: msys2 {0}
|
||||
|
||||
- name: Package
|
||||
shell: pwsh
|
||||
run: |
|
||||
$MSYS2_LOCATION = "${{ steps.msys2.outputs.msys2-location }}"
|
||||
$BIN_DIR = Join-Path $MSYS2_LOCATION "mingw64\bin"
|
||||
$DistDir = "dist"
|
||||
New-Item -ItemType Directory -Path $DistDir | Out-Null
|
||||
|
||||
Copy-Item (Join-Path $BIN_DIR "zlib1.dll") $DistDir
|
||||
Copy-Item (Join-Path $BIN_DIR "libxml2-16.dll") $DistDir
|
||||
Copy-Item (Join-Path $BIN_DIR "libusb-1.0.dll") $DistDir
|
||||
Copy-Item (Join-Path $BIN_DIR "liblzma-5.dll") $DistDir
|
||||
Copy-Item (Join-Path $BIN_DIR "libiconv-2.dll") $DistDir
|
||||
|
||||
Copy-Item "qdl.exe" $DistDir
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: qdl-binary-windows-${{ matrix.arch }}
|
||||
path: dist/*
|
||||
|
||||
15
.github/workflows/checkpatch.yml
vendored
Normal file
15
.github/workflows/checkpatch.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: Checkpatch Review
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
check-patch:
|
||||
name: checkpatch review
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 'Calculate PR commits + 1'
|
||||
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
- name: Run checkpatch review
|
||||
uses: webispy/checkpatch-action@v9
|
||||
36
.github/workflows/codeql.yml
vendored
Normal file
36
.github/workflows/codeql.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: CodeQL
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
codeql:
|
||||
permissions:
|
||||
# required for all workflows
|
||||
security-events: write
|
||||
|
||||
# required to fetch internal or private CodeQL packs
|
||||
packages: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libxml2-dev libusb-1.0-0-dev
|
||||
|
||||
- name: CodeQL init
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: c-cpp
|
||||
build-mode: autobuild
|
||||
|
||||
- name: CodeQL build
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
- name: CodeQL analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
||||
11
.github/workflows/markdown-lint.yml
vendored
Normal file
11
.github/workflows/markdown-lint.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
name: Markdown Lint
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: DavidAnson/markdownlint-cli2-action@v20
|
||||
with:
|
||||
globs: |
|
||||
README.md
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,2 +1,11 @@
|
||||
*.o
|
||||
qdl
|
||||
qdl-ramdump
|
||||
ks
|
||||
*.exe
|
||||
compile_commands.json
|
||||
.cache
|
||||
.version.h
|
||||
version.h
|
||||
scripts
|
||||
.checkpatch-camelcase.git.
|
||||
|
||||
4
.gitreview
Normal file
4
.gitreview
Normal file
@@ -0,0 +1,4 @@
|
||||
[gerrit]
|
||||
host=review.linaro.org
|
||||
port=29418
|
||||
project=landing-teams/working/qualcomm/qdl
|
||||
86
Makefile
86
Makefile
@@ -1,17 +1,83 @@
|
||||
OUT := qdl
|
||||
QDL := qdl
|
||||
RAMDUMP := qdl-ramdump
|
||||
VERSION := $(or $(VERSION), $(shell git describe --dirty --always --tags 2>/dev/null), "unknown-version")
|
||||
|
||||
CFLAGS := -O2 -Wall -g `xml2-config --cflags`
|
||||
LDFLAGS := `xml2-config --libs`
|
||||
CFLAGS += -O2 -Wall -g `pkg-config --cflags libxml-2.0 libusb-1.0`
|
||||
LDFLAGS += `pkg-config --libs libxml-2.0 libusb-1.0`
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LDFLAGS += -lws2_32
|
||||
endif
|
||||
prefix := /usr/local
|
||||
|
||||
SRCS := firehose.c qdl.c sahara.c util.c patch.c program.c
|
||||
OBJS := $(SRCS:.c=.o)
|
||||
QDL_SRCS := firehose.c io.c qdl.c sahara.c util.c patch.c program.c read.c sha2.c sim.c ufs.c usb.c ux.c oscompat.c vip.c sparse.c
|
||||
QDL_OBJS := $(QDL_SRCS:.c=.o)
|
||||
|
||||
$(OUT): $(OBJS)
|
||||
RAMDUMP_SRCS := ramdump.c sahara.c io.c sim.c usb.c util.c ux.c oscompat.c
|
||||
RAMDUMP_OBJS := $(RAMDUMP_SRCS:.c=.o)
|
||||
|
||||
KS_OUT := ks
|
||||
KS_SRCS := ks.c sahara.c util.c ux.c oscompat.c
|
||||
KS_OBJS := $(KS_SRCS:.c=.o)
|
||||
|
||||
CHECKPATCH_SOURCES := $(shell find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.sh" \) ! -name "sha2.c" ! -name "sha2.h" ! -name "*version.h")
|
||||
CHECKPATCH_ROOT := https://raw.githubusercontent.com/torvalds/linux/v6.15/scripts
|
||||
CHECKPATCH_URL := $(CHECKPATCH_ROOT)/checkpatch.pl
|
||||
CHECKPATCH_SP_URL := $(CHECKPATCH_ROOT)/spelling.txt
|
||||
CHECKPATCH := ./.scripts/checkpatch.pl
|
||||
CHECKPATCH_SP := ./.scripts/spelling.txt
|
||||
|
||||
default: $(QDL) $(RAMDUMP) $(KS_OUT)
|
||||
|
||||
$(QDL): $(QDL_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(OUT) $(OBJS)
|
||||
$(RAMDUMP): $(RAMDUMP_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
install: $(OUT)
|
||||
install -D -m 755 $< $(DESTDIR)$(prefix)/bin/$<
|
||||
$(KS_OUT): $(KS_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
compile_commands.json: $(QDL_SRCS) $(KS_SRCS)
|
||||
@echo -n $^ | jq -snR "[inputs|split(\" \")[]|{directory:\"$(PWD)\", command: \"$(CC) $(CFLAGS) -c \(.)\", file:.}]" > $@
|
||||
|
||||
version.h::
|
||||
@echo "#define VERSION \"$(VERSION)\"" > .version.h
|
||||
@cmp -s .version.h version.h || cp .version.h version.h
|
||||
|
||||
util.o: version.h
|
||||
|
||||
clean:
|
||||
rm -f $(QDL) $(QDL_OBJS)
|
||||
rm -f $(RAMDUMP) $(RAMDUMP_OBJS)
|
||||
rm -f $(KS_OUT) $(KS_OBJS)
|
||||
rm -f compile_commands.json
|
||||
rm -f version.h .version.h
|
||||
rm -f $(CHECKPATCH)
|
||||
rm -f $(CHECKPATCH_SP)
|
||||
if [ -d .scripts ]; then rmdir .scripts; fi
|
||||
|
||||
install: $(QDL) $(RAMDUMP) $(KS_OUT)
|
||||
install -d $(DESTDIR)$(prefix)/bin
|
||||
install -m 755 $^ $(DESTDIR)$(prefix)/bin
|
||||
|
||||
tests: default
|
||||
tests:
|
||||
@./tests/run_tests.sh
|
||||
|
||||
# Target to download checkpatch.pl if not present
|
||||
$(CHECKPATCH):
|
||||
@echo "Downloading checkpatch.pl..."
|
||||
@mkdir -p $(dir $(CHECKPATCH))
|
||||
@curl -sSfL $(CHECKPATCH_URL) -o $(CHECKPATCH)
|
||||
@curl -sSfL $(CHECKPATCH_SP_URL) -o $(CHECKPATCH_SP)
|
||||
@chmod +x $(CHECKPATCH)
|
||||
|
||||
check: $(CHECKPATCH)
|
||||
@echo "Running checkpatch on source files (excluding sha2.c and sha2.h)..."
|
||||
@for file in $(CHECKPATCH_SOURCES); do \
|
||||
perl $(CHECKPATCH) --no-tree -f $$file || exit 1; \
|
||||
done
|
||||
|
||||
check-cached: $(CHECKPATCH)
|
||||
@echo "Running checkpatch on staged changes..."
|
||||
@git diff --cached -- . | perl $(CHECKPATCH) --no-tree -
|
||||
|
||||
16
README
16
README
@@ -1,16 +0,0 @@
|
||||
Qualcomm Download
|
||||
=================
|
||||
|
||||
This tool communicates with USB devices of id 05c6:9008 to upload a flash
|
||||
loader and use this to flash images.
|
||||
|
||||
Usage:
|
||||
qdl <prog.mbn> [<program> <patch> ...]
|
||||
|
||||
Building
|
||||
========
|
||||
In order to build the project you need libxml2 headers and libraries, found in
|
||||
e.g. the libxml2-dev package.
|
||||
|
||||
With this installed run:
|
||||
make
|
||||
170
README.md
Normal file
170
README.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# Qualcomm Download
|
||||
|
||||
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||
[](https://github.com/linux-msm/qdl/actions/workflows/build.yml/badge.svg)
|
||||
|
||||
This tool communicates with USB devices of id `05c6:9008` to upload a flash
|
||||
loader and use this to flash images.
|
||||
|
||||
## Build
|
||||
|
||||
### Linux
|
||||
|
||||
```bash
|
||||
sudo apt install libxml2 libusb-1.0-0-dev
|
||||
make
|
||||
```
|
||||
|
||||
### MacOS
|
||||
|
||||
```bash
|
||||
brew install libxml2 pkg-config libusb
|
||||
make
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
First, install the [MSYS2 environment](https://www.msys2.org/). Then, run the
|
||||
MSYS2 MinGW64 terminal (located at `<msys2-installation-path>\mingw64.exe`) and
|
||||
install additional packages needed for QDL compilation using the `pacman` tool:
|
||||
|
||||
```bash
|
||||
pacman -S base-devel --needed
|
||||
pacman -S mingw-w64-x86_64-gcc
|
||||
pacman -S mingw-w64-x86_64-make
|
||||
pacman -S mingw-w64-x86_64-pkg-config
|
||||
pacman -S mingw-w64-x86_64-libusb
|
||||
pacman -S mingw-w64-x86_64-libxml2
|
||||
```
|
||||
|
||||
Then use the `make` tool to build QDL:
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
## Use QDL
|
||||
|
||||
### EDL mode
|
||||
|
||||
The device intended for flashing must be booted into **Emergency Download (EDL)**
|
||||
mode. EDL is a special boot mode available on Qualcomm-based devices that provides
|
||||
low-level access for firmware flashing and recovery. It bypasses the standard boot
|
||||
process, allowing operations such as flashing firmware even on unresponsive devices
|
||||
or those with locked bootloaders.
|
||||
|
||||
Please consult your device’s documentation for instructions on how to enter EDL mode.
|
||||
|
||||
### Flash device
|
||||
|
||||
Run QDL with the `--help` option to view detailed usage information.
|
||||
|
||||
Below is an example of how to invoke QDL to flash a FLAT build:
|
||||
|
||||
```bash
|
||||
qdl --dry-run prog_firehose_ddr.elf rawprogram*.xml patch*.xml
|
||||
```
|
||||
|
||||
If you have multiple boards connected the host, provide the serial number of
|
||||
the board to flash through `--serial` param:
|
||||
|
||||
```bash
|
||||
qdl --serial=0AA94EFD prog_firehose_ddr.elf rawprogram*.xml patch*.xml
|
||||
```
|
||||
|
||||
### Validated Image Programming (VIP)
|
||||
|
||||
QDL now supports **Validated Image Programming (VIP)** mode , which is activated
|
||||
when Secure Boot is enabled on the target. VIP controls which packets are allowed
|
||||
to be issued to the target. Controlling the packets that can be sent to the target
|
||||
is done through hashing. The target applies a hashing function to all received data,
|
||||
comparing the resulting hash digest against an existing digest table in memory.
|
||||
If the calculated hash digest matches the next entry in the table, the packet
|
||||
(data or command) is accepted; otherwise, the packet is rejected,and the target halts.
|
||||
|
||||
To use VIP programming, a digest table must be generated prior to flashing the device.
|
||||
To generate table of digests run QDL with `--create-digests` param,
|
||||
providing a path to store VIP tables. For example:
|
||||
|
||||
```bash
|
||||
mkdir vip
|
||||
qdl --create-digests=./vip prog_firehose_ddr.elf rawprogram*.xml patch*.xml
|
||||
```
|
||||
|
||||
As a result 3 types of files are generated:
|
||||
|
||||
- `DIGEST_TABLE.bin` - contains the SHA256 table of digests for all firehose
|
||||
packets to be sent to the target. It is an intermediary table and is
|
||||
used only for the subsequent generation of `DigestsToSign.bin` and
|
||||
`ChainedTableOfDigests\<n\>.bin` files. It is not used by QDL for VIP
|
||||
programming.
|
||||
|
||||
- `DigestsToSign.bin` - first 53 digests + digest of `ChainedTableOfDigests.bin`.
|
||||
This file has to be converted to MBN format and then signed with sectools:
|
||||
|
||||
```bash
|
||||
sectools mbn-tool generate --data DigestsToSign.bin --mbn-version 6 --outfile DigestsToSign.bin.mbn
|
||||
sectools secure-image --sign DigestsToSign.bin.mbn --image-id=VIP
|
||||
```
|
||||
|
||||
Please check the security profile for your SoC to determine which version of
|
||||
the MBN format should be used.
|
||||
|
||||
- `ChainedTableOfDigests\<n\>.bin` - contains left digests, split on
|
||||
multiple files with 255 digests + appended hash of next table.
|
||||
|
||||
To flash board using VIP mode provide a path where previously generated and signed
|
||||
table of digests are stored using `--vip-table-path` param:
|
||||
|
||||
```bash
|
||||
qdl --vip-table-path=./vip prog_firehose_ddr.elf rawprogram*.xml patch*.xml
|
||||
```
|
||||
|
||||
## Run tests
|
||||
|
||||
To run the integration test suite for QDL, use the `make tests` target:
|
||||
|
||||
```bash
|
||||
make tests
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Please submit any patches to the qdl (`master` branch) by using the GitHub pull
|
||||
request feature. Fork the repo, create a branch, do the work, rebase with upstream,
|
||||
and submit the pull request.
|
||||
|
||||
The preferred coding style for this tool is [Linux kernel coding style](https://www.kernel.org/doc/html/v6.15/process/coding-style.html).
|
||||
|
||||
Before creating a commit, please ensure that your changes adhere to the coding style
|
||||
by using the `make check-cached` target, for example:
|
||||
|
||||
```bash
|
||||
$ git status
|
||||
On branch improvements
|
||||
Changes to be committed:
|
||||
(use "git restore --staged <file>..." to unstage)
|
||||
modified: qdl.c
|
||||
modified: qdl.h
|
||||
|
||||
$ make check-cached
|
||||
Running checkpatch on staged changes...
|
||||
ERROR: trailing whitespace
|
||||
#28: FILE: qdl.h:32:
|
||||
+^IQDL_DEVICE_USB, $
|
||||
|
||||
total: 1 errors, 0 warnings, 0 checks, 27 lines checked
|
||||
|
||||
NOTE: For some of the reported defects, checkpatch may be able to
|
||||
mechanically convert to the typical style using --fix or --fix-inplace.
|
||||
|
||||
NOTE: Whitespace errors detected.
|
||||
You may wish to use scripts/cleanpatch or scripts/cleanfile
|
||||
|
||||
Your patch has style problems, please review.
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This tool is licensed under the BSD 3-Clause licensed. Check out [LICENSE](LICENSE)
|
||||
for more detais.
|
||||
843
firehose.c
843
firehose.c
File diff suppressed because it is too large
Load Diff
49
io.c
Normal file
49
io.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
/*
|
||||
* Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "qdl.h"
|
||||
|
||||
struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type)
|
||||
{
|
||||
if (type == QDL_DEVICE_USB)
|
||||
return usb_init();
|
||||
|
||||
if (type == QDL_DEVICE_SIM)
|
||||
return sim_init();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void qdl_deinit(struct qdl_device *qdl)
|
||||
{
|
||||
if (qdl)
|
||||
free(qdl);
|
||||
}
|
||||
|
||||
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size)
|
||||
{
|
||||
qdl->set_out_chunk_size(qdl, size);
|
||||
}
|
||||
|
||||
int qdl_open(struct qdl_device *qdl, const char *serial)
|
||||
{
|
||||
return qdl->open(qdl, serial);
|
||||
}
|
||||
|
||||
void qdl_close(struct qdl_device *qdl)
|
||||
{
|
||||
qdl->close(qdl);
|
||||
}
|
||||
|
||||
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
|
||||
{
|
||||
return qdl->read(qdl, buf, len, timeout);
|
||||
}
|
||||
|
||||
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len)
|
||||
{
|
||||
return qdl->write(qdl, buf, len);
|
||||
}
|
||||
131
ks.c
Normal file
131
ks.c
Normal file
@@ -0,0 +1,131 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "qdl.h"
|
||||
#include "oscompat.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
const char *__progname = "ks";
|
||||
#endif
|
||||
|
||||
static struct qdl_device qdl;
|
||||
|
||||
bool qdl_debug;
|
||||
|
||||
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
|
||||
{
|
||||
return read(qdl->fd, buf, len);
|
||||
}
|
||||
|
||||
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len)
|
||||
{
|
||||
return write(qdl->fd, buf, len);
|
||||
}
|
||||
|
||||
static void print_usage(void)
|
||||
{
|
||||
extern const char *__progname;
|
||||
|
||||
fprintf(stderr,
|
||||
"%s -p <sahara dev_node> -s <id:file path> ...\n",
|
||||
__progname);
|
||||
fprintf(stderr,
|
||||
" -p --port Sahara device node to use\n"
|
||||
" -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n"
|
||||
"\n"
|
||||
"One -p instance is required. One or more -s instances are required.\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
"ks -p /dev/mhi0_QAIC_SAHARA -s 1:/opt/qti-aic/firmware/fw1.bin -s 2:/opt/qti-aic/firmware/fw2.bin\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool found_mapping = false;
|
||||
char *dev_node = NULL;
|
||||
long file_id;
|
||||
char *colon;
|
||||
int opt;
|
||||
int ret;
|
||||
|
||||
static struct option options[] = {
|
||||
{"debug", no_argument, 0, 'd'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"port", required_argument, 0, 'p'},
|
||||
{"sahara", required_argument, 0, 's'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "dvp:s:", options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
qdl_debug = true;
|
||||
break;
|
||||
case 'v':
|
||||
print_version();
|
||||
return 0;
|
||||
case 'p':
|
||||
dev_node = optarg;
|
||||
printf("Using port - %s\n", dev_node);
|
||||
break;
|
||||
case 's':
|
||||
found_mapping = true;
|
||||
file_id = strtol(optarg, NULL, 10);
|
||||
if (file_id < 0) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
if (file_id >= MAPPING_SZ) {
|
||||
fprintf(stderr,
|
||||
"ID:%ld exceeds the max value of %d\n",
|
||||
file_id,
|
||||
MAPPING_SZ - 1);
|
||||
return 1;
|
||||
}
|
||||
colon = strchr(optarg, ':');
|
||||
if (!colon) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
qdl.mappings[file_id] = &optarg[colon - optarg + 1];
|
||||
printf("Created mapping ID:%ld File:%s\n", file_id, qdl.mappings[file_id]);
|
||||
break;
|
||||
default:
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// -p and -s is required
|
||||
if (!dev_node || !found_mapping) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (qdl_debug)
|
||||
print_version();
|
||||
|
||||
qdl.fd = open(dev_node, O_RDWR);
|
||||
if (qdl.fd < 0) {
|
||||
fprintf(stderr, "Unable to open %s\n", dev_node);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = sahara_run(&qdl, qdl.mappings, false, NULL, NULL);
|
||||
if (ret < 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
76
oscompat.c
Normal file
76
oscompat.c
Normal file
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "oscompat.h"
|
||||
|
||||
extern const char *__progname;
|
||||
|
||||
void timeradd(const struct timeval *a, const struct timeval *b, struct timeval *result)
|
||||
{
|
||||
result->tv_sec = a->tv_sec + b->tv_sec;
|
||||
result->tv_usec = a->tv_usec + b->tv_usec;
|
||||
if (result->tv_usec >= 1000000) {
|
||||
result->tv_sec += 1;
|
||||
result->tv_usec -= 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
void err(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s: ", __progname);
|
||||
if (fmt) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
va_end(ap);
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void errx(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s: ", __progname);
|
||||
if (fmt)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s: ", __progname);
|
||||
if (fmt) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s: ", __progname);
|
||||
if (fmt)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
25
oscompat.h
Normal file
25
oscompat.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
#ifndef __OSCOMPAT_H__
|
||||
#define __OSCOMPAT_H__
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <err.h>
|
||||
|
||||
#define O_BINARY 0
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void timeradd(const struct timeval *a, const struct timeval *b, struct timeval *result);
|
||||
|
||||
void err(int eval, const char *fmt, ...);
|
||||
void errx(int eval, const char *fmt, ...);
|
||||
void warn(const char *fmt, ...);
|
||||
void warnx(const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
96
patch.c
96
patch.c
@@ -1,65 +1,21 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Linaro Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "patch.h"
|
||||
|
||||
#include "qdl.h"
|
||||
|
||||
static struct patch *patches;
|
||||
static struct patch *patches_last;
|
||||
|
||||
static unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
|
||||
{
|
||||
xmlChar *value;
|
||||
|
||||
value = xmlGetProp(node, (xmlChar*)attr);
|
||||
if (!value)
|
||||
(*errors)++;
|
||||
|
||||
return strtoul((char*)value, NULL, 10);
|
||||
}
|
||||
|
||||
static const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
|
||||
{
|
||||
xmlChar *value;
|
||||
|
||||
value = xmlGetProp(node, (xmlChar*)attr);
|
||||
if (!value)
|
||||
(*errors)++;
|
||||
|
||||
return strdup((char*)value);
|
||||
}
|
||||
|
||||
int patch_load(const char *patch_file)
|
||||
{
|
||||
struct patch *patch;
|
||||
@@ -70,7 +26,7 @@ int patch_load(const char *patch_file)
|
||||
|
||||
doc = xmlReadFile(patch_file, NULL, 0);
|
||||
if (!doc) {
|
||||
fprintf(stderr, "[PATCH] failed to parse %s\n", patch_file);
|
||||
ux_err("failed to parse patch-type file \"%s\"\n", patch_file);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -79,8 +35,8 @@ int patch_load(const char *patch_file)
|
||||
if (node->type != XML_ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
if (xmlStrcmp(node->name, (xmlChar*)"patch")) {
|
||||
fprintf(stderr, "[PATCH] unrecognized tag \"%s\", ignoring\n", node->name);
|
||||
if (xmlStrcmp(node->name, (xmlChar *)"patch")) {
|
||||
ux_err("unrecognized tag \"%s\" in patch-type file, ignoring\n", node->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -98,7 +54,7 @@ int patch_load(const char *patch_file)
|
||||
patch->what = attr_as_string(node, "what", &errors);
|
||||
|
||||
if (errors) {
|
||||
fprintf(stderr, "[PATCH] errors while parsing patch\n");
|
||||
ux_err("errors while parsing patch-type file \"%s\"\n", patch_file);
|
||||
free(patch);
|
||||
continue;
|
||||
}
|
||||
@@ -116,20 +72,48 @@ int patch_load(const char *patch_file)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int patch_execute(int fd, int (*apply)(int fd, struct patch *patch))
|
||||
|
||||
int patch_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct patch *patch))
|
||||
{
|
||||
struct patch *patch;
|
||||
unsigned int count = 0;
|
||||
unsigned int idx = 0;
|
||||
int ret;
|
||||
|
||||
for (patch = patches; patch; patch = patch->next) {
|
||||
if (!strcmp(patch->filename, "DISK"))
|
||||
count++;
|
||||
}
|
||||
|
||||
for (patch = patches; patch; patch = patch->next) {
|
||||
if (strcmp(patch->filename, "DISK"))
|
||||
continue;
|
||||
|
||||
ret = apply(fd, patch);
|
||||
ret = apply(qdl, patch);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ux_progress("Applying patches", idx++, count);
|
||||
}
|
||||
|
||||
ux_info("%d patches applied\n", idx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_patches(void)
|
||||
{
|
||||
struct patch *patch = patches;
|
||||
struct patch *next;
|
||||
|
||||
for (patch = patches; patch; patch = next) {
|
||||
next = patch->next;
|
||||
free((void *)patch->filename);
|
||||
free((void *)patch->start_sector);
|
||||
free((void *)patch->value);
|
||||
free((void *)patch->what);
|
||||
free(patch);
|
||||
}
|
||||
|
||||
patches = NULL;
|
||||
}
|
||||
|
||||
14
patch.h
14
patch.h
@@ -1,12 +1,15 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
#ifndef __PATCH_H__
|
||||
#define __PATCH_H__
|
||||
|
||||
struct qdl_device;
|
||||
|
||||
struct patch {
|
||||
unsigned sector_size;
|
||||
unsigned byte_offset;
|
||||
unsigned int sector_size;
|
||||
unsigned int byte_offset;
|
||||
const char *filename;
|
||||
unsigned partition;
|
||||
unsigned size_in_bytes;
|
||||
unsigned int partition;
|
||||
unsigned int size_in_bytes;
|
||||
const char *start_sector;
|
||||
const char *value;
|
||||
const char *what;
|
||||
@@ -15,6 +18,7 @@ struct patch {
|
||||
};
|
||||
|
||||
int patch_load(const char *patch_file);
|
||||
int patch_execute(int fd, int (*apply)(int fd, struct patch *patch));
|
||||
int patch_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct patch *patch));
|
||||
void free_patches(void);
|
||||
|
||||
#endif
|
||||
|
||||
34
program.h
34
program.h
@@ -1,25 +1,41 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
#ifndef __PROGRAM_H__
|
||||
#define __PROGRAM_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "qdl.h"
|
||||
|
||||
struct program {
|
||||
unsigned sector_size;
|
||||
unsigned file_offset;
|
||||
unsigned int pages_per_block;
|
||||
unsigned int sector_size;
|
||||
unsigned int file_offset;
|
||||
const char *filename;
|
||||
const char *label;
|
||||
unsigned num_sectors;
|
||||
unsigned partition;
|
||||
unsigned size;
|
||||
unsigned int num_sectors;
|
||||
unsigned int partition;
|
||||
bool sparse;
|
||||
const char *start_bytes;
|
||||
const char *start_sector;
|
||||
unsigned int last_sector;
|
||||
|
||||
bool is_nand;
|
||||
bool is_erase;
|
||||
|
||||
unsigned int sparse_chunk_type;
|
||||
uint32_t sparse_fill_value;
|
||||
off_t sparse_offset;
|
||||
|
||||
struct program *next;
|
||||
};
|
||||
|
||||
int program_load(const char *program_file);
|
||||
int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program, int fd));
|
||||
int program_find_bootable_partition(void);
|
||||
int program_load(const char *program_file, bool is_nand);
|
||||
int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program, int fd),
|
||||
const char *incdir, bool allow_missing);
|
||||
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
|
||||
int program_find_bootable_partition(bool *multiple_found);
|
||||
int program_is_sec_partition_flashed(void);
|
||||
|
||||
void free_programs(void);
|
||||
|
||||
#endif
|
||||
|
||||
421
qdl.c
421
qdl.c
@@ -1,58 +1,37 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Linaro Ltd.
|
||||
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include "qdl.h"
|
||||
#include "patch.h"
|
||||
#include "program.h"
|
||||
#include "ufs.h"
|
||||
#include "oscompat.h"
|
||||
#include "vip.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
const char *__progname = "qdl";
|
||||
#endif
|
||||
|
||||
#define MAX_USBFS_BULK_SIZE (16 * 1024)
|
||||
|
||||
enum {
|
||||
QDL_FILE_UNKNOWN,
|
||||
QDL_FILE_PATCH,
|
||||
QDL_FILE_PROGRAM,
|
||||
QDL_FILE_READ,
|
||||
QDL_FILE_UFS,
|
||||
QDL_FILE_CONTENTS,
|
||||
};
|
||||
|
||||
@@ -62,205 +41,245 @@ static int detect_type(const char *xml_file)
|
||||
{
|
||||
xmlNode *root;
|
||||
xmlDoc *doc;
|
||||
int type;
|
||||
xmlNode *node;
|
||||
int type = QDL_FILE_UNKNOWN;
|
||||
|
||||
doc = xmlReadFile(xml_file, NULL, 0);
|
||||
if (!doc) {
|
||||
fprintf(stderr, "[PATCH] failed to parse %s\n", xml_file);
|
||||
ux_err("failed to parse XML file \"%s\"\n", xml_file);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
root = xmlDocGetRootElement(doc);
|
||||
if (!xmlStrcmp(root->name, (xmlChar*)"patches"))
|
||||
if (!xmlStrcmp(root->name, (xmlChar *)"patches")) {
|
||||
type = QDL_FILE_PATCH;
|
||||
else if (!xmlStrcmp(root->name, (xmlChar*)"data"))
|
||||
type = QDL_FILE_PROGRAM;
|
||||
else if (!xmlStrcmp(root->name, (xmlChar*)"contents"))
|
||||
} else if (!xmlStrcmp(root->name, (xmlChar *)"data")) {
|
||||
for (node = root->children; node ; node = node->next) {
|
||||
if (node->type != XML_ELEMENT_NODE)
|
||||
continue;
|
||||
if (!xmlStrcmp(node->name, (xmlChar *)"program")) {
|
||||
type = QDL_FILE_PROGRAM;
|
||||
break;
|
||||
}
|
||||
if (!xmlStrcmp(node->name, (xmlChar *)"read")) {
|
||||
type = QDL_FILE_READ;
|
||||
break;
|
||||
}
|
||||
if (!xmlStrcmp(node->name, (xmlChar *)"ufs")) {
|
||||
type = QDL_FILE_UFS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!xmlStrcmp(root->name, (xmlChar *)"contents")) {
|
||||
type = QDL_FILE_CONTENTS;
|
||||
else
|
||||
type = QDL_FILE_UNKNOWN;
|
||||
}
|
||||
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static int readat(int dir, const char *name, char *buf, size_t len)
|
||||
static void print_usage(FILE *out)
|
||||
{
|
||||
ssize_t n;
|
||||
int fd;
|
||||
int ret = 0;
|
||||
extern const char *__progname;
|
||||
|
||||
fd = openat(dir, name, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
n = read(fd, buf, len - 1);
|
||||
if (n < 0) {
|
||||
warn("failed to read %s", name);
|
||||
ret = -EINVAL;
|
||||
goto close_fd;
|
||||
}
|
||||
buf[n] = '\0';
|
||||
|
||||
buf[strcspn(buf, "\n")] = '\0';
|
||||
|
||||
close_fd:
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int find_qdl_tty(char *dev_name, size_t dev_name_len)
|
||||
{
|
||||
struct dirent *de;
|
||||
int found = -ENOENT;
|
||||
char vid[5];
|
||||
char pid[5];
|
||||
DIR *dir;
|
||||
int tty;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
tty = open("/sys/class/tty", O_DIRECTORY);
|
||||
if (tty < 0)
|
||||
err(1, "failed to open /sys/class/tty");
|
||||
|
||||
dir = fdopendir(tty);
|
||||
if (!dir)
|
||||
err(1, "failed to opendir /sys/class/tty");
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (strncmp(de->d_name, "ttyUSB", 6) != 0)
|
||||
continue;
|
||||
|
||||
fd = openat(tty, de->d_name, O_DIRECTORY);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
|
||||
ret = readat(fd, "../../../../idVendor", vid, sizeof(vid));
|
||||
if (ret < 0)
|
||||
goto close_fd;
|
||||
|
||||
ret = readat(fd, "../../../../idProduct", pid, sizeof(pid));
|
||||
if (ret < 0)
|
||||
goto close_fd;
|
||||
|
||||
if (strcmp(vid, "05c6") || strcmp(pid, "9008"))
|
||||
goto close_fd;
|
||||
|
||||
snprintf(dev_name, dev_name_len, "/dev/%s", de->d_name);
|
||||
found = 0;
|
||||
|
||||
close_fd:
|
||||
close(fd);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
close(tty);
|
||||
|
||||
return found;
|
||||
|
||||
}
|
||||
|
||||
static int tty_open(struct termios *old)
|
||||
{
|
||||
struct termios tios;
|
||||
char path[PATH_MAX];
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
retry:
|
||||
ret = find_qdl_tty(path, sizeof(path));
|
||||
if (ret < 0) {
|
||||
printf("Waiting for QDL tty...\r");
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
fd = open(path, O_RDWR | O_NOCTTY | O_EXCL);
|
||||
if (fd < 0) {
|
||||
err(1, "unable to open \"%s\"", path);
|
||||
}
|
||||
|
||||
ret = tcgetattr(fd, old);
|
||||
if (ret < 0)
|
||||
err(1, "unable to retrieve \"%s\" tios", path);
|
||||
|
||||
memset(&tios, 0, sizeof(tios));
|
||||
tios.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
|
||||
tios.c_iflag = IGNPAR;
|
||||
tios.c_oflag = 0;
|
||||
|
||||
tcflush(fd, TCIFLUSH);
|
||||
|
||||
ret = tcsetattr(fd, TCSANOW, &tios);
|
||||
if (ret < 0)
|
||||
err(1, "unable to update \"%s\" tios", path);
|
||||
|
||||
return fd;
|
||||
fprintf(out, "Usage: %s [options] <prog.mbn> [<program> <patch> ...]\n", __progname);
|
||||
fprintf(out, " -d, --debug\t\t\tPrint detailed debug info\n");
|
||||
fprintf(out, " -v, --version\t\t\tPrint the current version and exit\n");
|
||||
fprintf(out, " -n, --dry-run\t\t\tDry run execution, no device reading or flashing\n");
|
||||
fprintf(out, " -f, --allow-missing\t\tAllow skipping of missing files during flashing\n");
|
||||
fprintf(out, " -s, --storage=T\t\tSet target storage type T: <emmc|nand|ufs>\n");
|
||||
fprintf(out, " -l, --finalize-provisioning\tProvision the target storage\n");
|
||||
fprintf(out, " -i, --include=T\t\tSet an optional folder T to search for files\n");
|
||||
fprintf(out, " -S, --serial=T\t\t\tSelect target by serial number T (e.g. <0AA94EFD>)\n");
|
||||
fprintf(out, " -u, --out-chunk-size=T\t\tOverride chunk size for transaction with T\n");
|
||||
fprintf(out, " -t, --create-digests=T\t\tGenerate table of digests in the T folder\n");
|
||||
fprintf(out, " -D, --vip-table-path=T\t\tUse digest tables in the T folder for VIP\n");
|
||||
fprintf(out, " -h, --help\t\t\tPrint this usage info\n");
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, "Example: %s prog_firehose_ddr.elf rawprogram*.xml patch*.xml\n", __progname);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
extern const char *__progname;
|
||||
struct termios tios;
|
||||
char *prog_mbn;
|
||||
char *prog_mbn, *storage = "ufs";
|
||||
char *incdir = NULL;
|
||||
char *serial = NULL;
|
||||
const char *vip_generate_dir = NULL;
|
||||
const char *vip_table_path = NULL;
|
||||
int type;
|
||||
int ret;
|
||||
int fd;
|
||||
int i;
|
||||
int opt;
|
||||
bool qdl_finalize_provisioning = false;
|
||||
bool allow_fusing = false;
|
||||
bool allow_missing = false;
|
||||
long out_chunk_size = 0;
|
||||
struct qdl_device *qdl = NULL;
|
||||
enum QDL_DEVICE_TYPE qdl_dev_type = QDL_DEVICE_USB;
|
||||
|
||||
if (argc >= 2 && strcmp(argv[1], "--debug") == 0) {
|
||||
qdl_debug = true;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
static struct option options[] = {
|
||||
{"debug", no_argument, 0, 'd'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"include", required_argument, 0, 'i'},
|
||||
{"finalize-provisioning", no_argument, 0, 'l'},
|
||||
{"out-chunk-size", required_argument, 0, 'u' },
|
||||
{"serial", required_argument, 0, 'S'},
|
||||
{"vip-table-path", required_argument, 0, 'D'},
|
||||
{"storage", required_argument, 0, 's'},
|
||||
{"allow-missing", no_argument, 0, 'f'},
|
||||
{"allow-fusing", no_argument, 0, 'c'},
|
||||
{"dry-run", no_argument, 0, 'n'},
|
||||
{"create-digests", required_argument, 0, 't'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "%s <prog.mbn> [<program> <patch> ...]\n", __progname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
prog_mbn = argv[1];
|
||||
|
||||
for (i = 2; i < argc; i++) {
|
||||
type = detect_type(argv[i]);
|
||||
if (type < 0 || type == QDL_FILE_UNKNOWN)
|
||||
errx(1, "failed to detect file type of %s\n", argv[i]);
|
||||
|
||||
switch (type) {
|
||||
case QDL_FILE_PATCH:
|
||||
ret = patch_load(argv[i]);
|
||||
if (ret < 0)
|
||||
errx(1, "patch_load %s failed", argv[i]);
|
||||
while ((opt = getopt_long(argc, argv, "dvi:lu:S:D:s:fcnt:h", options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
qdl_debug = true;
|
||||
break;
|
||||
case QDL_FILE_PROGRAM:
|
||||
ret = program_load(argv[i]);
|
||||
if (ret < 0)
|
||||
errx(1, "program_load %s failed", argv[i]);
|
||||
case 'n':
|
||||
qdl_dev_type = QDL_DEVICE_SIM;
|
||||
break;
|
||||
case 't':
|
||||
vip_generate_dir = optarg;
|
||||
/* we also enforce dry-run mode */
|
||||
qdl_dev_type = QDL_DEVICE_SIM;
|
||||
break;
|
||||
case 'v':
|
||||
print_version();
|
||||
return 0;
|
||||
case 'f':
|
||||
allow_missing = true;
|
||||
break;
|
||||
case 'i':
|
||||
incdir = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
qdl_finalize_provisioning = true;
|
||||
break;
|
||||
case 'c':
|
||||
allow_fusing = true;
|
||||
break;
|
||||
case 'u':
|
||||
out_chunk_size = strtol(optarg, NULL, 10);
|
||||
break;
|
||||
case 's':
|
||||
storage = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
serial = optarg;
|
||||
break;
|
||||
case 'D':
|
||||
vip_table_path = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(stdout);
|
||||
return 0;
|
||||
default:
|
||||
errx(1, "%s type not yet supported", argv[i]);
|
||||
break;
|
||||
print_usage(stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
fd = tty_open(&tios);
|
||||
if (fd < 0)
|
||||
err(1, "failed to open QDL tty");
|
||||
/* at least 2 non optional args required */
|
||||
if ((optind + 2) > argc) {
|
||||
print_usage(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = sahara_run(fd, prog_mbn);
|
||||
qdl = qdl_init(qdl_dev_type);
|
||||
if (!qdl) {
|
||||
ret = -1;
|
||||
goto out_cleanup;
|
||||
}
|
||||
|
||||
if (vip_table_path) {
|
||||
if (vip_generate_dir)
|
||||
errx(1, "VIP mode and VIP table generation can't be enabled together\n");
|
||||
ret = vip_transfer_init(qdl, vip_table_path);
|
||||
if (ret)
|
||||
errx(1, "VIP initialization failed\n");
|
||||
}
|
||||
|
||||
if (out_chunk_size)
|
||||
qdl_set_out_chunk_size(qdl, out_chunk_size);
|
||||
|
||||
if (vip_generate_dir) {
|
||||
ret = vip_gen_init(qdl, vip_generate_dir);
|
||||
if (ret)
|
||||
goto out_cleanup;
|
||||
}
|
||||
|
||||
ux_init();
|
||||
|
||||
if (qdl_debug)
|
||||
print_version();
|
||||
|
||||
prog_mbn = argv[optind++];
|
||||
|
||||
do {
|
||||
type = detect_type(argv[optind]);
|
||||
if (type < 0 || type == QDL_FILE_UNKNOWN)
|
||||
errx(1, "failed to detect file type of %s\n", argv[optind]);
|
||||
|
||||
switch (type) {
|
||||
case QDL_FILE_PATCH:
|
||||
ret = patch_load(argv[optind]);
|
||||
if (ret < 0)
|
||||
errx(1, "patch_load %s failed", argv[optind]);
|
||||
break;
|
||||
case QDL_FILE_PROGRAM:
|
||||
ret = program_load(argv[optind], !strcmp(storage, "nand"));
|
||||
if (ret < 0)
|
||||
errx(1, "program_load %s failed", argv[optind]);
|
||||
|
||||
if (!allow_fusing && program_is_sec_partition_flashed())
|
||||
errx(1, "secdata partition to be programmed, which can lead to irreversible"
|
||||
" changes. Allow explicitly with --allow-fusing parameter");
|
||||
break;
|
||||
case QDL_FILE_READ:
|
||||
ret = read_op_load(argv[optind]);
|
||||
if (ret < 0)
|
||||
errx(1, "read_op_load %s failed", argv[optind]);
|
||||
break;
|
||||
case QDL_FILE_UFS:
|
||||
ret = ufs_load(argv[optind], qdl_finalize_provisioning);
|
||||
if (ret < 0)
|
||||
errx(1, "ufs_load %s failed", argv[optind]);
|
||||
break;
|
||||
default:
|
||||
errx(1, "%s type not yet supported", argv[optind]);
|
||||
break;
|
||||
}
|
||||
} while (++optind < argc);
|
||||
|
||||
ret = qdl_open(qdl, serial);
|
||||
if (ret)
|
||||
goto out_cleanup;
|
||||
|
||||
qdl->mappings[0] = prog_mbn;
|
||||
ret = sahara_run(qdl, qdl->mappings, true, NULL, NULL);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
goto out_cleanup;
|
||||
|
||||
ret = firehose_run(fd);
|
||||
|
||||
out:
|
||||
ret = tcsetattr(fd, TCSANOW, &tios);
|
||||
ret = firehose_run(qdl, incdir, storage, allow_missing);
|
||||
if (ret < 0)
|
||||
warn("unable to restore tios of ttyUSB1");
|
||||
close(fd);
|
||||
goto out_cleanup;
|
||||
|
||||
return 0;
|
||||
out_cleanup:
|
||||
if (vip_generate_dir)
|
||||
vip_gen_finalize(qdl);
|
||||
|
||||
qdl_close(qdl);
|
||||
free_programs();
|
||||
free_patches();
|
||||
|
||||
if (qdl->vip_data.state != VIP_DISABLED)
|
||||
vip_transfer_deinit(qdl);
|
||||
|
||||
qdl_deinit(qdl);
|
||||
|
||||
return !!ret;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user