diff --git a/pk2cmd-jaka-fi/README.md b/pk2cmd-jaka-fi/README.md new file mode 100644 index 0000000..cfecac5 --- /dev/null +++ b/pk2cmd-jaka-fi/README.md @@ -0,0 +1,122 @@ +# pk2cmd-jaka-fi for LURE + +A [LURE](https://lure.sh/) package for **pk2cmd** from [jaka-fi](https://github.com/jaka-fi/pk2cmd) — an enhanced PICkit 2/3/PKOB command-line programmer with extended device support. + +## What is pk2cmd-jaka-fi? + +This is a significantly enhanced fork of Microchip's original pk2cmd tool, maintained by jaka-fi. Key improvements over the original: + +- **1588+ supported devices** (vs ~639 in the last official Microchip release) +- **PICkit 3 and PKOB support** (not just PICkit 2) +- **Modern libusb-1.0** (faster than legacy libusb-0.1) +- **MSB1st family support** (PIC16/PIC18 newer devices) +- **Optimized programming scripts** for faster write/verify +- **Active maintenance** with bug fixes and new device additions + +## Installation + +```bash +# Build the package +lure build + +# Install +sudo apt install ./pk2cmd-jaka-fi_1.26.06-1_amd64.deb + +# Reload udev rules +sudo udevadm control --reload-rules +sudo udevadm trigger +``` + +## Usage + +The command is `pk3cmd` (to avoid conflicts with pk2cmd-plus): + +```bash +# Check version and device file +pk3cmd -?V + +# Auto-detect connected PIC +pk3cmd -P + +# List all supported devices +pk3cmd -?P + +# Program a hex file +pk3cmd -PPIC16F887 -M -F firmware.hex + +# Erase device +pk3cmd -PPIC16F887 -E + +# Power target from PICkit and release from reset +pk3cmd -PPIC16F887 -T -A5 -R +``` + +## Supported Hardware + +- **PICkit 2** — Original and clones +- **PICkit 3** — Requires scripting firmware (see notes below) +- **PKOB** — PICkit On Board (found on some dev boards) + +### PICkit 3 Notes + +PICkit 3 requires special "scripting" firmware. If your PICkit 3 shows as not found: +1. Connect it to a Windows PC with MPLAB IPE +2. Let MPLAB update the firmware +3. Use this tool's scripting firmware mode + +To revert PICkit 3 for use with MPLAB again, the firmware must be reset. + +## Credits + +### Upstream Project +- **Repository**: [jaka-fi/pk2cmd](https://github.com/jaka-fi/pk2cmd) +- **Maintainer**: jaka-fi + +### Contributors (from upstream) +- **Microchip Technology Inc.** — Original pk2cmd software +- **Miklós Márton** — PICkit 3 support ([martonmiklos/pk2cmd](https://github.com/martonmiklos/pk2cmd)) +- **Anobium / PICkitPlus team** — Extended device file (969→1588 devices) +- **dougy83** — Device file editor +- **bequest333** — MSB1st chip support +- **boborjan2** — libusb-1.0 support + +### LURE Package +- **Packager**: Foad S. Farimani + +## Comparison with pk2cmd-plus + +| Feature | pk2cmd-plus | pk2cmd-jaka-fi | +|---------|-------------|----------------| +| Command | `pk2cmd` | `pk3cmd` | +| Devices | ~700 | 1588+ | +| PICkit 3 | ❌ | ✅ | +| PKOB | ❌ | ✅ | +| libusb | 0.1 (legacy) | 1.0 (modern) | +| Source | psmay/pk2cmd | jaka-fi/pk2cmd | + +**Recommendation**: Use pk2cmd-jaka-fi unless you specifically need the older pk2cmd-plus for compatibility reasons. + +## Lessons Learned + +### Device File Path Patch Required + +Same as pk2cmd-plus, the source code defaults to searching the current directory for `PK2DeviceFile.dat`. The `prepare()` function patches this to `/usr/share/pk2/`: + +```bash +sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp +``` + +### Version Mismatch + +The git repository may have a newer version than tagged releases. The actual executable version is determined at compile time from the source, not from `lure.sh`. + +## License + +pk2cmd is distributed under Microchip's proprietary license. See the LICENSE file for terms. + +## See Also + +- [jaka-fi/pk2cmd GitHub](https://github.com/jaka-fi/pk2cmd) +- [PICkitminus GUI](https://github.com/jaka-fi/PICkitminus) (Windows only) +- [pk2cmd-plus](../pk2cmd-plus/) — Alternative LURE package (PICkit 2 only) +- [LURE Documentation](https://github.com/lure-sh/lure/tree/master/docs) diff --git a/pk2cmd-jaka-fi/lure.sh b/pk2cmd-jaka-fi/lure.sh new file mode 100644 index 0000000..fd4835b --- /dev/null +++ b/pk2cmd-jaka-fi/lure.sh @@ -0,0 +1,70 @@ +name="pk2cmd-jaka-fi" +version="1.26.06" +release="1" +desc="PICkit 2/3/PKOB CLI programmer with extended device support (1588 devices)" +homepage="https://github.com/jaka-fi/pk2cmd" +maintainer="Foad Sojoodi Farimani " +architectures=("amd64" "386") +license=("Custom") +provides=("pk3cmd") +conflicts=("pk2cmd-plus") + +# Debian/Ubuntu Dependencies +# This fork uses libusb-1.0 (not the legacy 0.1 compatibility layer) +deps=("libusb-1.0-0") +build_deps=("build-essential" "libusb-1.0-0-dev") + +sources=( + "git+https://github.com/jaka-fi/pk2cmd.git" +) + +checksums=( + "SKIP" +) + +prepare() { + cd "$srcdir/pk2cmd/pk2cmd" + + # The source code falls back to searching current directory for PK2DeviceFile.dat + # Change the fallback from "PK2DeviceFile.dat" (17 chars) to "/usr/share/pk2/PK2DeviceFile.dat" (33 chars) + # Note: Line 116 has this commented out, we fix line 121 instead + sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp + + # Verify the change was made + if grep -q '/usr/share/pk2/PK2DeviceFile.dat' cmd_app.cpp; then + echo "Path substitution successful" + else + echo "ERROR: Path substitution failed!" + exit 1 + fi +} + +build() { + cd "$srcdir/pk2cmd/pk2cmd" + make linux +} + +package() { + cd "$srcdir/pk2cmd/pk2cmd" + + # Install the executable as pk3cmd to avoid conflict with pk2cmd-plus + install -Dm755 pk2cmd "${pkgdir}/usr/bin/pk3cmd" + + # Also create symlink for original name (user can choose which to use) + # Commented out to avoid conflicts - uncomment if pk2cmd-plus is not installed + # ln -s pk3cmd "${pkgdir}/usr/bin/pk2cmd" + + # Install the Device File (v2.63.218 with 1588 devices) + install -Dm644 PK2DeviceFile.dat "${pkgdir}/usr/share/pk2/PK2DeviceFile.dat" + + # Install firmware hex files + for hex in ../release/*.hex; do + [ -f "$hex" ] && install -Dm644 "$hex" "${pkgdir}/usr/share/pk2/$(basename "$hex")" + done + + # Install udev rules (supports PICkit2, PICkit3, and PKOB) + install -Dm644 "$srcdir/pk2cmd/60-pickit.rules" "${pkgdir}/usr/lib/udev/rules.d/60-pickit.rules" + + # Install license + install -Dm644 "$srcdir/pk2cmd/license.txt" "${pkgdir}/usr/share/licenses/${name}/LICENSE" +} diff --git a/pk2cmd-plus/README.md b/pk2cmd-plus/README.md new file mode 100644 index 0000000..79a7b6c --- /dev/null +++ b/pk2cmd-plus/README.md @@ -0,0 +1,134 @@ +# pk2cmd-plus for LURE + +A [LURE](https://lure.sh/) package for **pk2cmd-plus** — the PICkit 2 command-line interface with updated device file support. + +## What is pk2cmd-plus? + +`pk2cmd` is Microchip's command-line tool for programming PIC microcontrollers using the PICkit 2 programmer. The "plus" variant bundles an updated device file (`PK2DeviceFile.dat`) that supports newer PIC devices beyond what the original Microchip release included. + +This package provides: +- **pk2cmd v1.21 RC1** — The last release candidate from Microchip +- **Device File v2.63.218** — Extended device support from the community +- **udev rules** — Allows non-root USB access to PICkit 2 hardware + +## Installation + +```bash +# Build the package +lure build + +# Install +sudo apt install ./pk2cmd-plus_1.21~rc1+1.63.148-2_amd64.deb + +# Reload udev rules +sudo udevadm control --reload-rules +sudo udevadm trigger +``` + +## Usage + +```bash +# Check version and device file +pk2cmd -?V + +# Auto-detect connected PIC +pk2cmd -P + +# Program a hex file +pk2cmd -PPIC16F887 -M -F firmware.hex + +# Erase device +pk2cmd -PPIC16F887 -E +``` + +## Credits + +### Original AUR Package +- **Package**: [pk2cmd-plus](https://aur.archlinux.org/packages/pk2cmd-plus) on AUR +- **Maintainer**: BxS (bxsbxs at gmail dot com) + + +### Source Code Mirrors +- [psmay/pk2cmd](https://github.com/psmay/pk2cmd) — GitHub mirror of Microchip's v1.21 RC1 source +- [martonmiklos/pk2cmd](https://github.com/martonmiklos/pk2cmd) — Fork with updated device files and PICkit 3 support + +### Original Software +- **Microchip Technology Inc.** — Original pk2cmd software (discontinued) + +## Lessons Learned + +This section documents issues encountered while porting the AUR PKGBUILD to LURE, to help future packagers avoid the same pitfalls. + +### 1. LURE ZIP Extraction Bug + +**Problem**: LURE's archive handler fails on ZIP files with nested directory structures (e.g., `pk2cmd/pk2cmd/`). + +``` +Error building package error="handling file 61: pk2cmd/: mkdir .../pk2cmd: file exists" +``` + +**Solution**: Use `git+` source prefix instead of ZIP URLs: +```bash +sources=("git+https://github.com/psmay/pk2cmd.git") +``` + +### 2. Dead Microchip URLs + +**Problem**: Original Microchip download URLs return 403/400 errors (as of 2023+). + +**Solution**: Use GitHub mirrors or Web Archive. The `git+` approach also sidesteps this issue entirely. + +### 3. LURE Source Naming Syntax + +**Problem**: The `filename::URL` syntax fails with certain characters: +``` +Error: parse "pk2_devicefile_osfile_paths.patch::https://...": first path segment in URL cannot contain colon +``` + +**Solution**: Omit the filename prefix; let LURE derive filenames from the URL's last path segment. + +### 4. Patch Line Ending Mismatch + +**Problem**: AUR patches expect Windows CRLF line endings, but GitHub sources have Unix LF: +``` +Hunk #1 FAILED at 84 (different line endings). +``` + +**Solution**: Replace patch files with equivalent `sed` commands: +```bash +sed -i 's/\r$//' cmd_app.cpp # Convert CRLF to LF first +sed -i 's|old_pattern|new_pattern|g' cmd_app.cpp +``` + +### 5. Debian Version Number Restrictions + +**Problem**: dpkg rejects underscores in version strings: +``` +'Version' field value '1.21rc1_1.63.148-2': invalid character in version number +``` + +**Solution**: Use Debian-compliant version format: +- `~` for pre-release indicators (sorts before release) +- `+` for additional metadata +- Example: `1.21~rc1+1.63.148` + +### 6. Device File Path Substitution + +**Problem**: The source code doesn't use a `#define` for the device file path. The original patch targets a specific code pattern. + +**Solution**: Match the exact source pattern with `sed`: +```bash +sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp +``` + +## License + +pk2cmd is distributed under Microchip's proprietary license. See the [LICENSE](https://aur.archlinux.org/cgit/aur.git/plain/LICENSE?h=pk2cmd-plus) file for terms. + +This LURE packaging script is provided as-is for convenience. + +## See Also + +- [PICkit 2 User's Guide](https://www.microchip.com/en-us/development-tool/pg164120) +- [pk2cmd-minus](https://github.com/cjacker/pk2cmd-minus) — Enhanced fork with PICkit 3 support +- [LURE Documentation](https://github.com/lure-sh/lure/tree/master/docs) diff --git a/pk2cmd-plus/lure.sh b/pk2cmd-plus/lure.sh new file mode 100644 index 0000000..978c9e8 --- /dev/null +++ b/pk2cmd-plus/lure.sh @@ -0,0 +1,80 @@ +name="pk2cmd-plus" +version="1.21~rc1+1.63.148" +release="2" +desc="PICkit 2 CLI software with updated DeviceFile and udev rules" +homepage="http://www.microchip.com/pickit2" +maintainer="BxS " +architectures=("amd64" "386") +license=("Custom") +provides=("pk2cmd") +conflicts=("pk2cmd") + +# Debian/Ubuntu Dependencies +deps=("libusb-0.1-4") +build_deps=("build-essential" "libusb-dev") + +sources=( + # 1. Main Source Code - Use GitHub mirror (avoids LURE ZIP extraction bug) + "git+https://github.com/psmay/pk2cmd.git" + # 2. Device File - Use GitHub from martonmiklos fork (has updated device files) + "https://raw.githubusercontent.com/martonmiklos/pk2cmd/master/pk2cmd/PK2DeviceFile.dat" + # 3. Udev Rules (from AUR) + "https://aur.archlinux.org/cgit/aur.git/plain/60-pickit2.rules?h=pk2cmd-plus" + # 4. License (from AUR) + "https://aur.archlinux.org/cgit/aur.git/plain/LICENSE?h=pk2cmd-plus" +) + +checksums=( + "SKIP" + "SKIP" + "SKIP" + "SKIP" +) + +prepare() { + cd "$srcdir/pk2cmd/pk2cmd" + + # Convert CRLF to LF (source may have Windows line endings) + sed -i 's/\r$//' cmd_app.cpp + + # The source code falls back to searching current directory for PK2DeviceFile.dat + # Change the fallback from "PK2DeviceFile.dat" (17 chars) to "/usr/share/pk2/PK2DeviceFile.dat" (33 chars) + # This is the line: _tcsncpy_s(tempString, "PK2DeviceFile.dat", 17); + sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp + + # Verify the change was made + if grep -q '/usr/share/pk2/PK2DeviceFile.dat' cmd_app.cpp; then + echo "Path substitution successful" + else + echo "ERROR: Path substitution failed!" + exit 1 + fi +} + +build() { + cd "$srcdir/pk2cmd/pk2cmd" + make linux +} + +package() { + cd "$srcdir/pk2cmd/pk2cmd" + + # Install the executable + install -Dm755 pk2cmd "${pkgdir}/usr/bin/pk2cmd" + + # Install the Device File + install -Dm644 "$srcdir/PK2DeviceFile.dat" "${pkgdir}/usr/share/pk2/PK2DeviceFile.dat" + + # Install firmware hex file if present (may not be in GitHub mirror) + if [ -f "$srcdir/pk2cmd/release/PK2V023200.hex" ]; then + install -Dm644 "$srcdir/pk2cmd/release/PK2V023200.hex" "${pkgdir}/usr/share/pk2/PK2V023200.hex" + elif [ -f "../release/PK2V023200.hex" ]; then + install -Dm644 "../release/PK2V023200.hex" "${pkgdir}/usr/share/pk2/PK2V023200.hex" + fi + + # Install Udev rules (Debian location) + install -Dm644 "$srcdir/60-pickit2.rules" "${pkgdir}/usr/lib/udev/rules.d/60-pickit2.rules" + + # Install License + install -Dm644 "$srcdir/LICENSE" "${pkgdir}/usr/share/licenses/${name}/LICENSE" +}