Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from fbs to Pyinstaller, and some other major changes #21

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/clean-libraries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
cd dist/sonix-flasher
rm libgobject-2.0.so.* \
libgio-2.0.so.* \
libgtk-3.so.* \
libgdk-3.so.* \
libharfbuzz.so.* \
libfontconfig.so.* \
libfreetype.so.* \
libgpg-error.so.* \
libstdc++.so.* \
libglib-2.0.so.*
28 changes: 15 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: CI

on:
push:
branches: [ master ]
branches: [ pyinstaller-switch ]

jobs:
build-linux:
runs-on: ubuntu-18.04

steps:
- name: Install dependencies
run: sudo apt-get install libusb-1.0-0-dev libudev-dev
run: sudo apt-get install qtbase5-dev libxcomposite-dev libxkbcommon-x11-dev libusb-1.0-0-dev libudev-dev

- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -28,14 +28,16 @@ jobs:
- name: Build
run: |
source venv/bin/activate
fbs freeze
cd target
tar cfJ flasher-linux.tar.xz "Sonix Keyboard Flasher"
pyinstaller sonix-flasher.spec
chmod +x .github/workflows/clean-libraries.sh
.github/workflows/clean-libraries.sh
cd dist
tar cfJ flasher-linux.tar.xz "sonix-flasher"

- uses: actions/upload-artifact@v1
with:
name: flasher-linux
path: target/flasher-linux.tar.xz
path: dist/flasher-linux.tar.xz

build-mac:
runs-on: macos-10.15
Expand All @@ -44,7 +46,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -56,8 +58,8 @@ jobs:
- name: Build
run: |
source venv/bin/activate
fbs freeze
hdiutil create -volname "Sonix Keyboard Flasher" -srcfolder "target/Sonix Keyboard Flasher.app" -ov -format UDZO flasher-mac.dmg
pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py
hdiutil create -volname "sonix-flasher" -srcfolder "dist/" -ov -format UDZO flasher-mac.dmg

- uses: actions/upload-artifact@v1
with:
Expand All @@ -71,7 +73,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -82,8 +84,8 @@ jobs:
- name: Build
run: |
. .\venv\Scripts\activate.ps1
fbs freeze
Compress-Archive -Path "target\Sonix Keyboard Flasher" -DestinationPath flasher-win.zip
pyinstaller sonix-flasher.spec
Compress-Archive -Path "dist\sonix-flasher" -DestinationPath flasher-win.zip

- uses: actions/upload-artifact@v1
with:
Expand Down
32 changes: 20 additions & 12 deletions .github/workflows/upload_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ jobs:
create-release-tag:
name: Create The Release
runs-on: ubuntu-latest

outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}

steps:
- name: Create Release
id: create_release
Expand All @@ -23,17 +25,19 @@ jobs:
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

build-linux:
runs-on: ubuntu-18.04
needs: create-release-tag

steps:
- name: Install dependencies
run: sudo apt-get install libusb-1.0-0-dev libudev-dev
run: sudo apt-get install qtbase5-dev libxcomposite-dev libxkbcommon-x11-dev libusb-1.0-0-dev libudev-dev

- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -46,9 +50,11 @@ jobs:
- name: Build
run: |
source venv/bin/activate
fbs freeze
cd target
tar cfJ flasher-linux.tar.xz "Sonix Keyboard Flasher"
pyinstaller sonix-flasher.spec
chmod +x .github/workflows/clean-libraries.sh
.github/workflows/clean-libraries.sh
cd dist
tar cfJ flasher-linux.tar.xz "sonix-flasher"

- name: Upload Release Asset
id: upload-release-asset
Expand All @@ -57,18 +63,19 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release-tag.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: target/flasher-linux.tar.xz
asset_path: dist/flasher-linux.tar.xz
asset_name: flasher-linux.tar.xz
asset_content_type: application/zip

build-mac:
runs-on: macos-10.15
needs: create-release-tag

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -80,8 +87,8 @@ jobs:
- name: Build
run: |
source venv/bin/activate
fbs freeze
hdiutil create -volname "Sonix Keyboard Flasher" -srcfolder "target/Sonix Keyboard Flasher.app" -ov -format UDZO flasher-mac.dmg
pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py
hdiutil create -volname "sonix-flasher" -srcfolder "dist/" -ov -format UDZO flasher-mac.dmg

- name: Upload Release Asset
id: upload-release-asset
Expand All @@ -97,11 +104,12 @@ jobs:
build-win:
runs-on: windows-2019
needs: create-release-tag

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.6.x'
python-version: '3.7.x'

- name: Setup venv
run: |
Expand All @@ -112,8 +120,8 @@ jobs:
- name: Build
run: |
. .\venv\Scripts\activate.ps1
fbs freeze
Compress-Archive -Path "target\Sonix Keyboard Flasher" -DestinationPath flasher-win.zip
pyinstaller sonix-flasher.spec
Compress-Archive -Path "dist\sonix-flasher" -DestinationPath flasher-win.zip

- name: Upload Release Asset
id: upload-release-asset
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
venv
target
build
dist
__pycache__
*.pyc
.idea
.vscode
106 changes: 90 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,112 @@
# Sonix Flasher
[![CI](https://github.com/SonixQMK/sonix-flasher/actions/workflows/main.yml/badge.svg)](https://github.com/SonixQMK/sonix-flasher/actions/workflows/main.yml)

## Usage
A simple multi-platform utility for flashing QMK firmware into SONiX microcontrolers.

<img src="https://i.imgur.com/8zckoo0.png" alt="Sonix Flasher">

## Usage
### Entering bootloader

You must boot into bootloader to flash the firmware,you have some choices to do it
To perform firmware flashing, you need to boot your keyboard into bootloader mode. In order to do this, you can use one of the ways described below:

- for stock firmware,click “Reboot to Bootloader” if your keyboard listed in the device list
- Pulled down the BOOT pin
- If you have a jumploader ,It’s strongly recommended to flash the jumploader on SN32F260 since the 260 series can become brick if the bootloader is overrided. [See](https://github.com/SonixQMK/sonix-keyboard-bootloader#entering-the-bootloader)
* If you are on stock firmware (and your keyboard is listed in the device list), click 'Reboot to Bootloader' button
* On flashed keyboard, you should be able to press `Fn + Esc` combination to immediately boot into bootloader
* As a last resort, you can open a keyboard and briefly short BOOT pin of the MCU with GND

### Flash Firmware
**[NOTE]** It’s strongly recommended to flash the jumploader on keyboards with SN32F260 chips since the 260 series can become bricked if the bootloader is overrided. [See](https://github.com/SonixQMK/sonix-keyboard-bootloader#entering-the-bootloader)

- Set qmk_offset to 0x200 only if you have a jumploader flashed in the keyboard
### Flashing firmware

## Compile
Put your keyboard in bootloader mode, set the correct qmk offset (which should be 0x200 only if you have jumploader flashed, so basically only on 260 series chips) and press `Flash QMK...` button

```
## Compiling
### Requirements
* Python >= 3.7
* libusb and libudev (only in Linux)

### Linux

Open terminal and type:

```sh
python3 -m venv venv
. venv/bin/activate
source venv/bin/activate
pip install wheel
pip install -r requirements.txt
fbs run
# or "fbs freeze" to create the package
pyinstaller sonix-flasher.spec
```

Alternatively, if you're running NixOS or have Nix installed, you can run
To run an application, type this in terminal:
`./dist/sonix-flasher/sonix-flasher`

```
**[NOTE]** To run it for immediate use, just run `run.sh` and it'll set itself up and run. (only for Linux)

### NixOS

Alternatively, if you're running NixOS or have Nix installed, you can run:

```sh
nix shell
fbs run
```

### Mac OS

Open terminal and type:

```sh
python -m venv venv
source venv/bin/activate
pip install cython
pip install wheel
pip install -r requirements.txt
pyinstaller --onefile -n "sonix-flasher" --windowed src/sonix-flasher/main.py
```

To run an application, type this in terminal:
`open -n ./dist/sonix-flasher/sonix-flasher.app`

To run it for immediate use, just run `run.sh` and it'll set itself up and run.
### Windows

Open Powershell and type:

```powershell
python -m venv venv
. venv\Scripts\Activate.ps1
pip install -r requirements.txt
pyinstaller sonix-flasher.spec
```

## Running with sudo

It is highly recommended that instead of running Sonix Flasher with root permissions, you'll make yourself needed udev rules.

Example of udev rule for Akko:
```sh
SUBSYSTEM=="usb", ATTR{idVendor}=="320f", ATTR{idProduct}=="5013", TAG+="uaccess", TAG+="udev-acl"
KERNEL=="hidraw*", ATTR{idVendor}=="320f", ATTR{idProduct}=="5013", TAG+="uaccess", TAG+="udev-acl"
```

Change `ATTR{idVendor}` and `ATTR{idProduct}` to values valid for your keyboard, save a file as `your-keyboard.rules` (name can be changed) in `/etc/udev/rules.d/`, and type in terminal as root: `udevadm control --reload`

## Troubleshooting
### Keyboard isn't showing in device list

Before doing anything, check if your keyboard is plugged in properly.

If you are on Windows, download [Zadig](https://zadig.akeo.ie/) to get VID and PID (first value in USB ID is VID and the second is PID).

On Linux and Mac OS open terminal and type `lsusb`, then find your keyboard by name to get an USB ID (like in Zadig, first value is VID and the second is PID).

[Create a new issue](https://github.com/SonixQMK/sonix-flasher/issues/new) with a name of your keyboard and its USB ID in description.

### Sonix Flasher is crashing with message like this:
```
Authorization required, but no authorization protocol specified

qt.qpa.xcb: could not connect to display :0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
```

Run with sudo to flash unless you have the correct udev rules set up.
This means that you are probably trying to run application with sudo on (X)Wayland session. (X)Wayland doesn't support running applications with sudo because of security reasons. You should refer to [Running with sudo](#running-with-sudo) section, or check [here](https://wiki.archlinux.org/title/Running_GUI_applications_as_root#Wayland) for a workaround.
13 changes: 4 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
altgraph==0.17
fbs==0.8.6
future==0.18.2
hidapi==0.9.0.post2
macholib==1.14
pefile==2019.4.18
PyInstaller==3.4
PyQt5==5.15.2
sip==5.0.0
hidapi==0.11.2
PyInstaller
PyQt5
sip
5 changes: 3 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
python3 -m venv venv
. venv/bin/activate
source venv/bin/activate
pip install wheel
pip install -r requirements.txt
fbs run
pyinstaller sonix-flasher.spec
./dist/sonix-flasher/sonix-flasher
Loading