From patchwork Tue Dec 18 04:19:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 1014975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43JlFY5dWxz9sBZ for ; Tue, 18 Dec 2018 15:21:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="l8DSRsYP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="jHow1ItA"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 43JlFY1N8vzDqQR for ; Tue, 18 Dec 2018 15:21:05 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="l8DSRsYP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="jHow1ItA"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mendozajonas.com (client-ip=66.111.4.25; helo=out1-smtp.messagingengine.com; envelope-from=sam@mendozajonas.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="l8DSRsYP"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="jHow1ItA"; dkim-atps=neutral Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 43JlDR2dtMzDqWn for ; Tue, 18 Dec 2018 15:20:06 +1100 (AEDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id D786822BCB; Mon, 17 Dec 2018 23:20:03 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 17 Dec 2018 23:20:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=fm1; bh=vo0D4r8cZGDDE JD0Lxz3YF8aRFP5h5atvDX3LKWcIZs=; b=l8DSRsYPTkKyMZf6t+A4hBaNrYEFi YFDG6U7HQWaDXbvPUc50N1IDN+k/r0lfUcn1xI3WAwnABY1Q0Utjs2UztIESg846 rvPivwDP5cx8nHovPteggPW8mlcWdlhWpRrfmazdLaljKZ2mKYrw90JLtUggTaVz R4qiAXizDw9oxJs+uyuBc4kHe7AyLP8PQpmLr3fcu9rr4c35ctAsDj46aVZFk31/ cGjyEkjZydJ74KBaWb0cbu3N8tu+JNVymf3wAO/NhjzipJ6x02sW6m3USjRIU+vo r8pX7kxxUNACXHl+GD1TCSV2m/wX8E9ilxriyyToKWUGSRhdISoKTeSgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=vo0D4r8cZGDDEJD0L xz3YF8aRFP5h5atvDX3LKWcIZs=; b=jHow1ItAVq+t9SUwM/6YXiwrtqLUZlLpy Hz4Rz0bCbg8Z30NjQwSUZ9RLNRo41L5dwqE6TG6kEx1M1vpfqhw55xkNbNwaYE8v ekQnkMBw2squfNtXRQW6lV/0LIetcLITkeE6CVL0uenQs7HAacMfAQP+jlQtIWNn aGRFFCkd4i6jD+AnW/WVZYygbp8XYDc1x6hwDIYjLdDo9bacj9fEoFs+iUoSX8UQ +VFJV1XwvJGZCfAmkAADJAozY8/umzviPDI7mc5W4KzxkoDolMGUn2uoMbk7paD5 Oc0uUm6q1db3QaP2m7OkZGpY3aLtd5sCFUjFDg/QiY/YmNz8ElJBQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudeigedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefurg hmuhgvlhcuofgvnhguohiirgdqlfhonhgrshcuoehsrghmsehmvghnughoiigrjhhonhgr shdrtghomheqnecukfhppeduvddvrdelledrkedvrddutdenucfrrghrrghmpehmrghilh hfrhhomhepshgrmhesmhgvnhguohiirghjohhnrghsrdgtohhmnecuvehluhhsthgvrhfu ihiivgeptd X-ME-Proxy: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 86EF910084; Mon, 17 Dec 2018 23:20:01 -0500 (EST) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [RFC PATCH 0/8] Introduce pb-plugin 'commands' & Rust PoC Date: Tue, 18 Dec 2018 15:19:45 +1100 Message-Id: <20181218041953.8960-1-sam@mendozajonas.com> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This series extends the pb-plugin API with support for defining specific command & argument combinations to present to the user to run. These can either be executables contained in the plugin or commands already present in the Petitboot environment. Arguments can be of several types, the values of which are substituted into an argument format string appended to the command. While making the pb-plugin interface more user-friendly, the original idea behind this approach is to provide a way to include extra "platform options" in the Petitboot UI without having to add in dedicated configuration options or additional screens per-platform (or per sub-platform as in some cases). Instead this dynamically displays options in nc-plugin as read from a plugin 'command' file. These could range from including a platform-specific utility to configure a certain feature, to something as simple as setting some specific NVRAM parameters from the UI with a description of the parameter to aid the user. The current changes still depend on pb-discover finding a plugin; most likely I'll introduce an option to find 'baked in' plugins at that can be included at build time in a directory like /etc/petitboot. Comments on areas such as the command format (see patch 3) are very welcome. Patch 1 of the series also acts a proof-of-concept of including a more modern language (in this case, Rust) in Petitboot features. The new directory lib/rust includes a small amount of Rust to parse the plugin command JSON file and some helper functions to handle the interaction between C and Rust. Aside from being a bit of fun to experiment with this avoids introducing ever more string parsing in C and opens an avenue to using safer languages where appropriate. Built statically so the runtime isn't required and stripping at compile time the resulting size is manageable and it fits well enough into the existing Autoconf. Comments, suggestions, and intense bikeshedding welcome, but if this shakes out well enough it could be an interesting addition to Petitboot. Samuel Mendoza-Jonas (8): rust: Add rust interface for parsing JSON lib/pb-protocol: Reflect additions to plugin_option utils: Add plugin_commands parameter utils/pb-exec: Prepend sudo if normal user discover/device-handler: Read command files if present ui/ncurses: Don't post screen after command ui/ncurses: Add current_field accessor ui/ncurses: Present plugin commands in nc-plugin Makefile.am | 1 - configure.ac | 9 ++ discover/device-handler.c | 8 ++ discover/user-event.c | 2 + lib/Makefile.am | 9 +- lib/pb-protocol/pb-protocol.c | 168 ++++++++++++++++++++++ lib/pb-protocol/pb-protocol.h | 6 + lib/rust/Cargo.lock | 117 ++++++++++++++++ lib/rust/Cargo.toml | 20 +++ lib/rust/Makefile.am | 30 ++++ lib/rust/build.rs | 70 ++++++++++ lib/rust/rustlibs.c | 109 +++++++++++++++ lib/rust/rustlibs.h | 11 ++ lib/rust/src/lib.rs | 230 ++++++++++++++++++++++++++++++ lib/types/types.h | 30 ++++ test/lib/Makefile.am | 3 +- test/lib/test-protocol.c | 158 +++++++++++++++++++++ ui/ncurses/nc-cui.c | 1 - ui/ncurses/nc-plugin.c | 256 +++++++++++++++++++++++++++++++--- ui/ncurses/nc-widgets.c | 13 ++ ui/ncurses/nc-widgets.h | 1 + utils/pb-exec | 8 +- utils/pb-plugin | 8 +- 23 files changed, 1243 insertions(+), 25 deletions(-) create mode 100644 lib/rust/Cargo.lock create mode 100644 lib/rust/Cargo.toml create mode 100644 lib/rust/Makefile.am create mode 100644 lib/rust/build.rs create mode 100644 lib/rust/rustlibs.c create mode 100644 lib/rust/rustlibs.h create mode 100644 lib/rust/src/lib.rs create mode 100644 test/lib/test-protocol.c