This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use west to implement a more portable repo patching system
Inspired by: zephyrproject-rtos/zephyr#71137
- Loading branch information
1 parent
b22419f
commit c019249
Showing
24 changed files
with
224 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ build | |
CMakeCache.txt | ||
build.ninja | ||
.vscode/settings.json | ||
scripts/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,17 @@ If you want to use the latest firmware version for your UHK, then instead of goi | |
|
||
If you're one of the brave few who wants to hack the firmware then read on. | ||
|
||
1. Make sure to clone this repo with: | ||
### Fetching the codebase | ||
|
||
Note that these commands will create a [west workspace](https://docs.zephyrproject.org/latest/develop/west/workspaces.html#t2-star-topology-application-is-the-manifest-repository) in your current directory. | ||
|
||
```bash | ||
west init -m [email protected]:UltimateHackingKeyboard/firmware-uhk80.git firmware-uhk80 | ||
cd firmware-uhk80 | ||
git clone [email protected]:UltimateHackingKeyboard/firmware-uhk80.git | ||
west init -l firmware-uhk80 | ||
west update | ||
west config --local build.cmake-args -- "-Wno-dev" | ||
./uhk/device/patches/patch-all.sh | ||
cd uhk | ||
west patch | ||
cd firmware-uhk80 | ||
git submodule update --init --recursive | ||
cd scripts | ||
npm i | ||
|
@@ -44,7 +46,7 @@ Then, depending whether you want a full IDE experience or just minimal tools for | |
- Install commandline stuff from [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/installation/install_ncs.html) | ||
- Launch nrfutil shell: | ||
``` | ||
nrfutil toolchain-manager launch --shell --ncs-version v2.5.0 | ||
nrfutil toolchain-manager launch --shell --ncs-version v2.6.1 | ||
``` | ||
- In the shell, you can build (e.g.) uhk-80-left as follows: | ||
- full build including cmake steps, as extracted from VS Code: | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
device/patches/zephyr-invalid-conversion-udc-data-api/patch.sh
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
device/patches/zephyr-invalid-conversion-udc-data-api/readme.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
From 5245ce30a25475ca9239e702f67dee29ea154d39 Mon Sep 17 00:00:00 2001 | ||
From: Benedek Kupper <[email protected]> | ||
Date: Tue, 9 Jul 2024 22:24:40 +0200 | ||
Subject: [PATCH] Always enter serial recovery mode upon startup | ||
|
||
Adds the BOOT_SERIAL_WAIT_FOR_DFU_ALWAYS MCUboot Kconfig option to enter serial recovery | ||
for the duration of BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT upon physically resetting the board. | ||
Otherwise, MCUboot immediately executes the application. | ||
|
||
--- | ||
boot/zephyr/Kconfig.serial_recovery | 8 ++++++++ | ||
boot/zephyr/main.c | 8 ++++++-- | ||
2 files changed, 14 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/boot/zephyr/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery | ||
index c73baddf..22cdd081 100644 | ||
--- a/boot/zephyr/Kconfig.serial_recovery | ||
|
@@ -52,3 +66,6 @@ index d601eae0..f12c4493 100644 | |
timeout_in_ms -= (k_uptime_get_32() - start); | ||
if( timeout_in_ms <= 0 ) { | ||
/* at least one check if time was expired */ | ||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
From 9f6342a09c416553381e4d478c894903ead17566 Mon Sep 17 00:00:00 2001 | ||
From: Benedek Kupper <[email protected]> | ||
Date: Tue, 9 Jul 2024 22:38:48 +0200 | ||
Subject: [PATCH] Remove mcuboot build warnings | ||
|
||
--- | ||
cmake/partition_manager.cmake | 12 ------------ | ||
modules/mcuboot/CMakeLists.txt | 7 ------- | ||
2 files changed, 19 deletions(-) | ||
|
||
diff --git a/cmake/partition_manager.cmake b/cmake/partition_manager.cmake | ||
index a45650a2..292dd9c3 100644 | ||
index a45650a2d..292dd9c3f 100644 | ||
--- a/cmake/partition_manager.cmake | ||
+++ b/cmake/partition_manager.cmake | ||
@@ -76,18 +76,6 @@ endif() | ||
|
@@ -22,7 +32,7 @@ index a45650a2..292dd9c3 100644 | |
|
||
|
||
diff --git a/modules/mcuboot/CMakeLists.txt b/modules/mcuboot/CMakeLists.txt | ||
index 5ec2643d..70c706d5 100644 | ||
index 5ec2643d7..70c706d52 100644 | ||
--- a/modules/mcuboot/CMakeLists.txt | ||
+++ b/modules/mcuboot/CMakeLists.txt | ||
@@ -379,13 +379,6 @@ if(CONFIG_BOOTLOADER_MCUBOOT) | ||
|
@@ -39,3 +49,6 @@ index 5ec2643d..70c706d5 100644 | |
set(mcuboot_key_file ${ZEPHYR_MCUBOOT_MODULE_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}) | ||
endif() | ||
|
||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
From df36898ebd062b07764d8437ccf17d16a0d70411 Mon Sep 17 00:00:00 2001 | ||
From: Benedek Kupper <[email protected]> | ||
Date: Tue, 9 Jul 2024 22:34:13 +0200 | ||
Subject: [PATCH] drivers: udc: eliminate C++ compiler warnings | ||
|
||
Pending upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69490 | ||
|
||
--- | ||
include/zephyr/drivers/usb/udc.h | 12 ++++++------ | ||
1 file changed, 6 insertions(+), 6 deletions(-) | ||
|
||
diff --git a/include/zephyr/drivers/usb/udc.h b/include/zephyr/drivers/usb/udc.h | ||
index f5f74ec127..eba4e78b07 100644 | ||
index 0f01d877e..70012660d 100644 | ||
--- a/include/zephyr/drivers/usb/udc.h | ||
+++ b/include/zephyr/drivers/usb/udc.h | ||
@@ -299,7 +299,7 @@ struct udc_data { | ||
|
@@ -56,3 +67,6 @@ index f5f74ec127..eba4e78b07 100644 | |
int ret; | ||
|
||
if (!udc_is_enabled(dev)) { | ||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
From 5e92c6d9d3af3f864523ba1c3b16c3b9e7e91f39 Mon Sep 17 00:00:00 2001 | ||
From: Benedek Kupper <[email protected]> | ||
Date: Tue, 9 Jul 2024 22:32:55 +0200 | ||
Subject: [PATCH] Remove __ASSERT() build warning | ||
|
||
--- | ||
CMakeLists.txt | 1 - | ||
1 file changed, 1 deletion(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 10196c435..a934cf0ba 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -1954,7 +1954,6 @@ add_subdirectory(cmake/reports) | ||
|
||
if(NOT CONFIG_TEST) | ||
if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) | ||
- message(WARNING "__ASSERT() statements are globally ENABLED") | ||
endif() | ||
endif() | ||
|
||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
From 8af07cac410f748fe3653278adb6332b7f186598 Mon Sep 17 00:00:00 2001 | ||
From: Benedek Kupper <[email protected]> | ||
Date: Tue, 9 Jul 2024 22:28:47 +0200 | ||
Subject: [PATCH] Add the USB_DFU_BCD_DEVICE_ID Kconfig option | ||
|
||
Adds the USB_DFU_BCD_DEVICE_ID Kconfig option which is used by MCUboot | ||
as the major number of the USB DFU bcdDevice descriptor field. | ||
This value is used by Agent to identify the UHK device. | ||
|
||
--- | ||
Kconfig.zephyr | 6 ++++++ | ||
include/zephyr/usb/usb_ch9.h | 5 +++-- | ||
2 files changed, 9 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/Kconfig.zephyr b/Kconfig.zephyr | ||
index 848ce58da7e..045e6258857 100644 | ||
index 848ce58da..045e62588 100644 | ||
--- a/Kconfig.zephyr | ||
+++ b/Kconfig.zephyr | ||
@@ -928,3 +928,9 @@ config BOOTLOADER_BOSSA_ADAFRUIT_UF2 | ||
|
@@ -13,7 +27,7 @@ index 848ce58da7e..045e6258857 100644 | |
+ help | ||
+ The major number of the USB DFU bcdDevice descriptor field is (ab)used for exposing the UHK device ID to Agent. | ||
diff --git a/include/zephyr/usb/usb_ch9.h b/include/zephyr/usb/usb_ch9.h | ||
index fa18b1c2dc8..0353fcc8679 100644 | ||
index fa18b1c2d..0353fcc86 100644 | ||
--- a/include/zephyr/usb/usb_ch9.h | ||
+++ b/include/zephyr/usb/usb_ch9.h | ||
@@ -259,8 +259,9 @@ struct usb_association_descriptor { | ||
|
@@ -28,3 +42,6 @@ index fa18b1c2dc8..0353fcc8679 100644 | |
|
||
/** Macro to obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request */ | ||
#define USB_GET_DESCRIPTOR_TYPE(wValue) ((uint8_t)((wValue) >> 8)) | ||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
west-commands: | ||
- file: scripts/west_patch.py | ||
commands: | ||
- name: patch | ||
class: WestPatch | ||
help: Manage patching across zephyr ecosystem repositories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# SPDX-License-Identifier: MIT | ||
from west.commands import WestCommand | ||
from west import log | ||
import git | ||
from west.manifest import Manifest | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
# https://github.com/zephyrproject-rtos/zephyr/issues/71137#issuecomment-2042447526 | ||
class WestPatch(WestCommand): | ||
def __init__(self): | ||
super().__init__( | ||
'patch', | ||
'manage patches across multiple repositories', | ||
dedent(''' | ||
This command manages patches across multiple repositories. | ||
It can apply, list, show diffs, and commit patches. | ||
Reverting patches is done by "west update" command. | ||
''') | ||
) | ||
self.manifest = Manifest.from_file() | ||
|
||
def do_add_parser(self, parser_adder): | ||
parser = parser_adder.add_parser( | ||
self.name, help=self.help, description=self.description) | ||
parser.add_argument('--list', action='store_true', | ||
help='list all patches') | ||
parser.add_argument('--diff', action='store_true', | ||
help='show current uncommitted changes') | ||
parser.add_argument('--commit', action='store_true', | ||
help='commit changes and create a new patch file') | ||
parser.add_argument('--stash', action='store_true', | ||
help='stash uncommitted changes') | ||
return parser | ||
|
||
def do_run(self, args, unknown_args): | ||
if args.list: | ||
self.list_patches() | ||
elif args.diff: | ||
self.show_diff() | ||
elif args.commit: | ||
self.commit_patches() | ||
elif args.stash: | ||
self.stash_changes() | ||
else: | ||
self.apply_patches() | ||
|
||
def get_git_projects(self): | ||
projects = [] | ||
for project in self.manifest.projects: | ||
if project.name == 'manifest': | ||
continue # Skip the manifest project itself | ||
try: | ||
project_repo = git.Repo(project.abspath) | ||
except git.exc.NoSuchPathError as e: | ||
continue # Skip projects that aren't dependencies | ||
projects.append(project) | ||
return projects | ||
|
||
def get_patch_dir(self, project): | ||
return Path(self.manifest.repo_abspath) / 'patches' / project.name | ||
|
||
def apply_patches(self): | ||
for project in self.get_git_projects(): | ||
patch_dir = self.get_patch_dir(project) | ||
if patch_dir.exists(): | ||
for patch_file in sorted(patch_dir.glob('*.patch')): | ||
try: | ||
project_repo = git.Repo(project.abspath) | ||
project_repo.git.am(patch_file.as_posix()) | ||
log.inf(f'Applied {patch_file.name} to {project.name}') | ||
except git.exc.GitCommandError as e: | ||
log.err(f'Error applying {patch_file.name} to {project.name}: {e}') | ||
|
||
def list_patches(self): | ||
for project in self.get_git_projects(): | ||
patch_dir = self.get_patch_dir(project) | ||
if patch_dir.exists(): | ||
patches = sorted(patch_file.name for patch_file in patch_dir.glob('*.patch')) | ||
if patches: | ||
log.inf(f'{project.name} has patches:') | ||
for patch in patches: | ||
log.inf(f' - {patch}') | ||
else: | ||
log.inf(f'{project.name} has no patches.') | ||
|
||
def show_diff(self): | ||
for project in self.get_git_projects(): | ||
project_repo = git.Repo(project.abspath) | ||
diff = project_repo.git.diff() | ||
if diff: | ||
log.inf(f'Uncommitted changes in {project.name}:') | ||
log.inf(diff) | ||
else: | ||
log.inf(f'No uncommitted changes in {project.name}') | ||
|
||
def commit_patches(self): | ||
for project in self.get_git_projects(): | ||
project_repo = git.Repo(project.abspath) | ||
if project_repo.is_dirty(untracked_files=True): | ||
patch_dir = self.get_patch_dir(project) | ||
patch_dir.mkdir(exist_ok=True) | ||
commit_message = input(f'Enter commit message for {project.name}: ') | ||
project_repo.git.add(A=True) | ||
project_repo.git.commit('-m', commit_message) | ||
ret = project_repo.git.format_patch('-1', '-o', patch_dir.as_posix()) | ||
log.inf(f'Committed changes and created patch {ret} for {project.name}') | ||
else: | ||
log.inf(f'No changes to commit for {project.name}') | ||
|
||
def stash_changes(self): | ||
for project in self.get_git_projects(): | ||
project_repo = git.Repo(project.abspath) | ||
if project_repo.is_dirty(untracked_files=True): | ||
log.inf(f'Stashing changes for {project.name}') | ||
project_repo.git.stash() |
Oops, something went wrong.