Skip to content

Commit 6aa0cd1

Browse files
committed
feat: Add pk2cmd-plus LURE package for Debian/Ubuntu
Port of AUR pk2cmd-plus package to LURE build system. Package contents: - pk2cmd v1.21 RC1 (PICkit 2 CLI programmer) - Device file v2.63.218 (extended PIC device support) - udev rules for non-root USB access Key adaptations from AUR PKGBUILD: - Use git source (GitHub mirror) instead of ZIP to avoid LURE extraction bug - Replace patch file with sed commands (line ending compatibility) - Use Debian-compliant version format (~ and + instead of _) - Correct device file path substitution pattern Credits: - Original AUR package: BxS, Manouchehri - Source mirrors: psmay/pk2cmd, martonmiklos/pk2cmd - Original software: Microchip Technology Inc. Tested on Linux Mint / Ubuntu with LURE.
1 parent 6f2d805 commit 6aa0cd1

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-0
lines changed

pk2cmd-plus/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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)

pk2cmd-plus/lure.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name="pk2cmd-plus"
2+
version="1.21~rc1+1.63.148"
3+
release="2"
4+
desc="PICkit 2 CLI software with updated DeviceFile and udev rules"
5+
homepage="http://www.microchip.com/pickit2"
6+
maintainer="BxS <bxsbxs at gmail dot com>"
7+
architectures=("amd64" "386")
8+
license=("Custom")
9+
provides=("pk2cmd")
10+
conflicts=("pk2cmd")
11+
12+
# Debian/Ubuntu Dependencies
13+
deps=("libusb-0.1-4")
14+
build_deps=("build-essential" "libusb-dev")
15+
16+
sources=(
17+
# 1. Main Source Code - Use GitHub mirror (avoids LURE ZIP extraction bug)
18+
"git+https://github.com/psmay/pk2cmd.git"
19+
# 2. Device File - Use GitHub from martonmiklos fork (has updated device files)
20+
"https://raw.githubusercontent.com/martonmiklos/pk2cmd/master/pk2cmd/PK2DeviceFile.dat"
21+
# 3. Udev Rules (from AUR)
22+
"https://aur.archlinux.org/cgit/aur.git/plain/60-pickit2.rules?h=pk2cmd-plus"
23+
# 4. License (from AUR)
24+
"https://aur.archlinux.org/cgit/aur.git/plain/LICENSE?h=pk2cmd-plus"
25+
)
26+
27+
checksums=(
28+
"SKIP"
29+
"SKIP"
30+
"SKIP"
31+
"SKIP"
32+
)
33+
34+
prepare() {
35+
cd "$srcdir/pk2cmd/pk2cmd"
36+
37+
# Convert CRLF to LF (source may have Windows line endings)
38+
sed -i 's/\r$//' cmd_app.cpp
39+
40+
# The source code falls back to searching current directory for PK2DeviceFile.dat
41+
# Change the fallback from "PK2DeviceFile.dat" (17 chars) to "/usr/share/pk2/PK2DeviceFile.dat" (33 chars)
42+
# This is the line: _tcsncpy_s(tempString, "PK2DeviceFile.dat", 17);
43+
sed -i 's|_tcsncpy_s(tempString, "PK2DeviceFile.dat", 17)|_tcsncpy_s(tempString, "/usr/share/pk2/PK2DeviceFile.dat", 33)|g' cmd_app.cpp
44+
45+
# Verify the change was made
46+
if grep -q '/usr/share/pk2/PK2DeviceFile.dat' cmd_app.cpp; then
47+
echo "Path substitution successful"
48+
else
49+
echo "ERROR: Path substitution failed!"
50+
exit 1
51+
fi
52+
}
53+
54+
build() {
55+
cd "$srcdir/pk2cmd/pk2cmd"
56+
make linux
57+
}
58+
59+
package() {
60+
cd "$srcdir/pk2cmd/pk2cmd"
61+
62+
# Install the executable
63+
install -Dm755 pk2cmd "${pkgdir}/usr/bin/pk2cmd"
64+
65+
# Install the Device File
66+
install -Dm644 "$srcdir/PK2DeviceFile.dat" "${pkgdir}/usr/share/pk2/PK2DeviceFile.dat"
67+
68+
# Install firmware hex file if present (may not be in GitHub mirror)
69+
if [ -f "$srcdir/pk2cmd/release/PK2V023200.hex" ]; then
70+
install -Dm644 "$srcdir/pk2cmd/release/PK2V023200.hex" "${pkgdir}/usr/share/pk2/PK2V023200.hex"
71+
elif [ -f "../release/PK2V023200.hex" ]; then
72+
install -Dm644 "../release/PK2V023200.hex" "${pkgdir}/usr/share/pk2/PK2V023200.hex"
73+
fi
74+
75+
# Install Udev rules (Debian location)
76+
install -Dm644 "$srcdir/60-pickit2.rules" "${pkgdir}/usr/lib/udev/rules.d/60-pickit2.rules"
77+
78+
# Install License
79+
install -Dm644 "$srcdir/LICENSE" "${pkgdir}/usr/share/licenses/${name}/LICENSE"
80+
}

0 commit comments

Comments
 (0)