├── README.md ├── checkout.py ├── config.json └── patches ├── .gitkeep ├── fix_htmlresc.patch ├── tl_mbox_fmt.patch └── wpan_dbg_trace.patch /README.md: -------------------------------------------------------------------------------- 1 | # STM32WB Coprocessor Project extraction scripts 2 | 3 | Scripts for extracting a subset of the STM32CubeWB package used to build Flipper Zero firmware. 4 | 5 | 6 | ## How to update 7 | 8 | This repo's scritps must be called from a directory where the output files should be. 9 | 10 | Run `python3 path/to/update.py -v v1.15.0` to update to specific version of STM32CubeWB package. See `python3 update.py -h` for more options. 11 | 12 | 13 | ## Configuration 14 | 15 | Update script is configured using a JSON file. It is located in "config.json". It has 2 sections: 16 | 17 | - `patches`: list of file patches to apply to STM32CubeWB package; 18 | - `paths`: object with keys that are paths to folders in this repository and values that are corresponding paths to folders in STM32CubeWB package. -------------------------------------------------------------------------------- /checkout.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import json 3 | import logging 4 | import os 5 | import shutil 6 | import subprocess 7 | import sys 8 | import tempfile 9 | from pathlib import Path 10 | 11 | log = logging.getLogger(__name__) 12 | 13 | VERSION_FILENAME = "VERSION" 14 | 15 | 16 | def main(): 17 | logging.basicConfig( 18 | format="%(asctime)s.%(msecs)03d [%(levelname).1s] %(message)s", 19 | level=logging.INFO, 20 | datefmt="%H:%M:%S", 21 | ) 22 | 23 | arg_parser = argparse.ArgumentParser() 24 | arg_parser.add_argument( 25 | "--cube-version", 26 | "-v", 27 | help="STM32CubeWB version to use. Must be a tag or branch name", 28 | default="v1.15.0", 29 | required=False, 30 | ) 31 | arg_parser.add_argument( 32 | "--cube-git-url", 33 | help="STM32CubeWB git repo path", 34 | default="https://github.com/STMicroelectronics/STM32CubeWB.git", 35 | required=False, 36 | ) 37 | arg_parser.add_argument( 38 | "--config", 39 | "-p", 40 | help="Print paths to used files", 41 | default=Path(__file__).parent / "config.json", 42 | required=False, 43 | ) 44 | arg_parser.add_argument( 45 | "target_dir", 46 | help="Output directory", 47 | default=os.getcwd(), 48 | nargs="?", 49 | ) 50 | arg_parser.add_argument( 51 | "--force", 52 | "-f", 53 | help="Skip target directory checks", 54 | action="store_true", 55 | default=False, 56 | required=False, 57 | ) 58 | 59 | args = arg_parser.parse_args() 60 | 61 | target_dir = Path(args.target_dir) 62 | log.info(f"Target directory: {target_dir}") 63 | if not (target_dir / VERSION_FILENAME).exists(): 64 | if args.force: 65 | log.warning("Target directory does not contain a valid checkout") 66 | else: 67 | log.error( 68 | "Target directory does not contain a valid checkout. Use --force to continue" 69 | ) 70 | return 1 71 | 72 | log.info(f"Loading config file {args.config}") 73 | with open(args.config, "r") as f: 74 | path_config = json.load(f) 75 | 76 | log.info(f"Cloning STM32CubeWB, {args.cube_version} from {args.cube_git_url}") 77 | with tempfile.TemporaryDirectory() as tmpdir: 78 | subprocess.check_call( 79 | [ 80 | "git", 81 | "clone", 82 | "--depth=1", 83 | "--branch", 84 | args.cube_version, 85 | args.cube_git_url, 86 | tmpdir, 87 | ], 88 | ) 89 | 90 | for patch_file in path_config.get("patches", []): 91 | patch_file_path = Path(args.config).parent / patch_file 92 | if not patch_file_path.exists(): 93 | log.error(f"Patch {patch_file} not found") 94 | return 1 95 | 96 | log.info(f"Applying patch {patch_file_path}") 97 | subprocess.check_call(["git", "apply", patch_file_path], cwd=tmpdir) 98 | 99 | for dest, src in path_config.get("paths", {}).items(): 100 | dest = target_dir / dest 101 | src = Path(tmpdir) / src 102 | if not src.exists(): 103 | log.error(f"Source '{src}' not found") 104 | return 1 105 | 106 | log.info(f"Moving '{src}' to '{dest}'") 107 | shutil.rmtree(dest, ignore_errors=True) 108 | os.makedirs(dest.parent, exist_ok=True) 109 | # shutil.copytree(src, dest) 110 | shutil.move(src, dest) 111 | 112 | with open(target_dir / VERSION_FILENAME, "wt") as f: 113 | f.write(args.cube_version) 114 | 115 | log.info("Done") 116 | 117 | 118 | if __name__ == "__main__": 119 | sys.exit(main() or 0) 120 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "patches": [ 3 | "patches/tl_mbox_fmt.patch", 4 | "patches/wpan_dbg_trace.patch", 5 | "patches/fix_htmlresc.patch" 6 | ], 7 | "paths": { 8 | "wpan": "Middlewares/ST/STM32_WPAN", 9 | "firmware": "Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x", 10 | "firmware/htmresc": "_htmresc" 11 | } 12 | } -------------------------------------------------------------------------------- /patches/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flipperdevices/stm32wb_copro_scripts/781464e628eb694b4c98a79ab524c293f527fc8d/patches/.gitkeep -------------------------------------------------------------------------------- /patches/fix_htmlresc.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html b/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html 2 | index 08a5aadfb..4ced7c322 100644 3 | --- a/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html 4 | +++ b/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/Release_Notes.html 5 | @@ -11,11 +11,11 @@ 6 | span.underline{text-decoration: underline;} 7 | div.column{display: inline-block; vertical-align: top; width: 50%;} 8 | 9 | - 10 | + 11 | 14 | - 15 | + 16 | 17 | 18 |
19 | @@ -25,7 +25,7 @@ 20 |

STM32WB Copro Wireless Binaries

21 |

Copyright © 2020 STMicroelectronics
22 |

23 | - 24 | + 25 | 26 |

Known Limitations

27 |

If Anti-Rollback needs to be activated, please make sure to activate it only after installing the latest FUS version (>= V1.2.0) and after successfully installing a wireless stack (without deleting it). Otherwise, further wireless stack installation will be blocked.

28 | -------------------------------------------------------------------------------- /patches/tl_mbox_fmt.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl_mbox.c b/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl_mbox.c 2 | index 4112429dc..65bd3e188 100644 3 | --- a/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl_mbox.c 4 | +++ b/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl_mbox.c 5 | @@ -681,24 +681,24 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) 6 | case TL_BLEEVT_CS_OPCODE: 7 | TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); 8 | TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); 9 | - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); 10 | + TL_MM_DBG_MSG(" buffer addr: %p", p_evt_packet); 11 | break; 12 | 13 | case TL_BLEEVT_CC_OPCODE: 14 | TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); 15 | TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); 16 | - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); 17 | + TL_MM_DBG_MSG(" buffer addr: %p", p_evt_packet); 18 | break; 19 | 20 | case TL_BLEEVT_VS_OPCODE: 21 | TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); 22 | TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); 23 | - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); 24 | + TL_MM_DBG_MSG(" buffer addr: %p", p_evt_packet); 25 | break; 26 | 27 | default: 28 | TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); 29 | - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); 30 | + TL_MM_DBG_MSG(" buffer addr: %p", p_evt_packet); 31 | break; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /patches/wpan_dbg_trace.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Middlewares/ST/STM32_WPAN/utilities/dbg_trace.c b/Middlewares/ST/STM32_WPAN/utilities/dbg_trace.c 2 | index ea9a3b08c..397709d8c 100644 3 | --- a/Middlewares/ST/STM32_WPAN/utilities/dbg_trace.c 4 | +++ b/Middlewares/ST/STM32_WPAN/utilities/dbg_trace.c 5 | @@ -255,6 +255,7 @@ size_t DbgTraceWrite(int handle, const unsigned char * buf, size_t bufSize) 6 | { 7 | size_t chars_written = 0; 8 | uint8_t* buffer; 9 | + (void)buffer; 10 | 11 | BACKUP_PRIMASK(); 12 | 13 | --------------------------------------------------------------------------------