|
| 1 | +# pk2cmd-plus for LURE |
| 2 | + |
| 3 | +A [LURE](https://lure.sh/) package for **pk2cmd-plus** — the PICkit 2 command-line interface with updated device file support. |
| 4 | + |
| 5 | +## What is pk2cmd-plus? |
| 6 | + |
| 7 | +`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. |
| 8 | + |
| 9 | +This package provides: |
| 10 | +- **pk2cmd v1.21 RC1** — The last release candidate from Microchip |
| 11 | +- **Device File v2.63.218** — Extended device support from the community |
| 12 | +- **udev rules** — Allows non-root USB access to PICkit 2 hardware |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +# Build the package |
| 18 | +lure build |
| 19 | + |
| 20 | +# Install |
| 21 | +sudo apt install ./pk2cmd-plus_1.21~rc1+1.63.148-2_amd64.deb |
| 22 | + |
| 23 | +# Reload udev rules |
| 24 | +sudo udevadm control --reload-rules |
| 25 | +sudo udevadm trigger |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +```bash |
| 31 | +# Check version and device file |
| 32 | +pk2cmd -?V |
| 33 | + |
| 34 | +# Auto-detect connected PIC |
| 35 | +pk2cmd -P |
| 36 | + |
| 37 | +# Program a hex file |
| 38 | +pk2cmd -PPIC16F887 -M -F firmware.hex |
| 39 | + |
| 40 | +# Erase device |
| 41 | +pk2cmd -PPIC16F887 -E |
| 42 | +``` |
| 43 | + |
| 44 | +## Credits |
| 45 | + |
| 46 | +### Original AUR Package |
| 47 | +- **Package**: [pk2cmd-plus](https://aur.archlinux.org/packages/pk2cmd-plus) on AUR |
| 48 | +- **Maintainer**: BxS (bxsbxs at gmail dot com) |
| 49 | + |
| 50 | + |
| 51 | +### Source Code Mirrors |
| 52 | +- [psmay/pk2cmd](https://github.com/psmay/pk2cmd) — GitHub mirror of Microchip's v1.21 RC1 source |
| 53 | +- [martonmiklos/pk2cmd](https://github.com/martonmiklos/pk2cmd) — Fork with updated device files and PICkit 3 support |
| 54 | + |
| 55 | +### Original Software |
| 56 | +- **Microchip Technology Inc.** — Original pk2cmd software (discontinued) |
| 57 | + |
| 58 | +## Lessons Learned |
| 59 | + |
| 60 | +This section documents issues encountered while porting the AUR PKGBUILD to LURE, to help future packagers avoid the same pitfalls. |
| 61 | + |
| 62 | +### 1. LURE ZIP Extraction Bug |
| 63 | + |
| 64 | +**Problem**: LURE's archive handler fails on ZIP files with nested directory structures (e.g., `pk2cmd/pk2cmd/`). |
| 65 | + |
| 66 | +``` |
| 67 | +Error building package error="handling file 61: pk2cmd/: mkdir .../pk2cmd: file exists" |
| 68 | +``` |
| 69 | + |
| 70 | +**Solution**: Use `git+` source prefix instead of ZIP URLs: |
| 71 | +```bash |
| 72 | +sources=("git+https://github.com/psmay/pk2cmd.git") |
| 73 | +``` |
| 74 | + |
| 75 | +### 2. Dead Microchip URLs |
| 76 | + |
| 77 | +**Problem**: Original Microchip download URLs return 403/400 errors (as of 2023+). |
| 78 | + |
| 79 | +**Solution**: Use GitHub mirrors or Web Archive. The `git+` approach also sidesteps this issue entirely. |
| 80 | + |
| 81 | +### 3. LURE Source Naming Syntax |
| 82 | + |
| 83 | +**Problem**: The `filename::URL` syntax fails with certain characters: |
| 84 | +``` |
| 85 | +Error: parse "pk2_devicefile_osfile_paths.patch::https://...": first path segment in URL cannot contain colon |
| 86 | +``` |
| 87 | + |
| 88 | +**Solution**: Omit the filename prefix; let LURE derive filenames from the URL's last path segment. |
| 89 | + |
| 90 | +### 4. Patch Line Ending Mismatch |
| 91 | + |
| 92 | +**Problem**: AUR patches expect Windows CRLF line endings, but GitHub sources have Unix LF: |
| 93 | +``` |
| 94 | +Hunk #1 FAILED at 84 (different line endings). |
| 95 | +``` |
| 96 | + |
| 97 | +**Solution**: Replace patch files with equivalent `sed` commands: |
| 98 | +```bash |
| 99 | +sed -i 's/\r$//' cmd_app.cpp # Convert CRLF to LF first |
| 100 | +sed -i 's|old_pattern|new_pattern|g' cmd_app.cpp |
| 101 | +``` |
| 102 | + |
| 103 | +### 5. Debian Version Number Restrictions |
| 104 | + |
| 105 | +**Problem**: dpkg rejects underscores in version strings: |
| 106 | +``` |
| 107 | +'Version' field value '1.21rc1_1.63.148-2': invalid character in version number |
| 108 | +``` |
| 109 | + |
| 110 | +**Solution**: Use Debian-compliant version format: |
| 111 | +- `~` for pre-release indicators (sorts before release) |
| 112 | +- `+` for additional metadata |
| 113 | +- Example: `1.21~rc1+1.63.148` |
| 114 | + |
| 115 | +### 6. Device File Path Substitution |
| 116 | + |
| 117 | +**Problem**: The source code doesn't use a `#define` for the device file path. The original patch targets a specific code pattern. |
| 118 | + |
| 119 | +**Solution**: Match the exact source pattern with `sed`: |
| 120 | +```bash |
| 121 | +sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp |
| 122 | +``` |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +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. |
| 127 | + |
| 128 | +This LURE packaging script is provided as-is for convenience. |
| 129 | + |
| 130 | +## See Also |
| 131 | + |
| 132 | +- [PICkit 2 User's Guide](https://www.microchip.com/en-us/development-tool/pg164120) |
| 133 | +- [pk2cmd-minus](https://github.com/cjacker/pk2cmd-minus) — Enhanced fork with PICkit 3 support |
| 134 | +- [LURE Documentation](https://github.com/lure-sh/lure/tree/master/docs) |
0 commit comments