From patchwork Thu Aug 2 17:29:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952913 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKW1MMdz9s2g for ; Fri, 3 Aug 2018 03:31:43 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I1zldRdv"; 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 41hHKV6MQ4zF277 for ; Fri, 3 Aug 2018 03:31:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I1zldRdv"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I1zldRdv"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH72fQMzF22V for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=e0/cGeFWL0VJgkbnlL20G8/LM0j6moHXWubhjgQjuns=; b=I1zldRdvLLT9v42GnIw1irqTv FNbPm58W1FCDcJFCfVTsiOqEgyj019xYXd8SV5L+wcIiGIrytdQsbUTFKJ/simzx0RVKKsMlA613o ctTvKXDUwodAZt/maDk5YJFm8wT16dtbj+34ILFZ3/5P4/l7xSEzx3VAg5QO4/DYNGiTsPDR4AfiO fG3uOdSSgRVq2cDIf7rxaLMePufZjeS2Ed+QhSw4C04PKEgqdL3TOsk92p3YtdMLlgBATmsGhC/1t 5iSBWf6vpiLOSMR4K8PT7KZf+o27M87omBvScb9SuI1HJHAcwx3SH3l5k91GDptJR+kFwt5ldTHKh Oxd+aF/dQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPp-0007WJ-EA; Thu, 02 Aug 2018 17:29:33 +0000 Message-Id: <575933f14e61faefe264fe89ac62f7fdb29054df.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 01/30] docker: Add libfdt-dev To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:33 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add package libfdt-dev to the pb-builder docker image. Signed-off-by: Geoff Levand --- docker/Dockerfile.builder | 1 + docker/builder-include | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.builder b/docker/Dockerfile.builder index b4e3827..280887c 100644 --- a/docker/Dockerfile.builder +++ b/docker/Dockerfile.builder @@ -19,6 +19,7 @@ RUN apt-get update && apt-get install -y \ libtool \ libuv-dev \ libdevmapper-dev \ + libfdt-dev \ libncurses-dev \ pkg-config \ && rm -rf /var/lib/apt/lists/* diff --git a/docker/builder-include b/docker/builder-include index 87405b8..d2d94a4 100644 --- a/docker/builder-include +++ b/docker/builder-include @@ -50,7 +50,7 @@ show_tag () { echo "${DOCKER_TAG}" } -: ${VERSION:="1"} +: ${VERSION:="2"} : ${ARCH_TAG:="$(arch_tag)"} : ${DOCKER_NAME:="pb-builder"} : ${DOCKER_TAG:="${DOCKER_NAME}:${VERSION}${ARCH_TAG}"} From patchwork Thu Aug 2 17:29:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLB2x6Tz9s2g for ; Fri, 3 Aug 2018 03:32:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I8ttuGe0"; 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 41hHLB1PF6zF2DP for ; Fri, 3 Aug 2018 03:32:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I8ttuGe0"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="I8ttuGe0"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74s7tzF2D3 for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6W7YFmYZqZVmxRBtVV9npS9MJkBUfePmdqUOKEUn4n0=; b=I8ttuGe0Qht0VDaOIDnmNjO3i 8MAsj6Go31dUBM7qAM+yyE3qem2K+tDVLmU7WH8j3mv/NXZ1g96g0fvKS5e2AaANlxtwKnkn9SNyt fi/peud65wLwPpz3b5mUTI+1wpNymTBtUJaSYHW6AzF+3twaDAnluATF+CAU4aMHhO8+G+Zw4jj+u Uqx/la58NBMPiXZa8+fzf9UbHRQcnQWEf3C/7g94SPsjRvAHzniAIfOzbUCAG+D1jeBEYur5wntU9 qaPD+xcZ3mSu4QTF/BNNDUIaMV1vCgiSN1v23XxfvBbEo1Vt6mvxzLlOdQq6LPDQOzR0/P53RDpdX CaTiFogfg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPp-0007WN-Je; Thu, 02 Aug 2018 17:29:33 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 02/30] configure: Add check for UI build To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:33 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Emit configure warning if no UI program is to be built. Signed-off-by: Geoff Levand --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index f12e48d..d02c85f 100644 --- a/configure.ac +++ b/configure.ac @@ -135,6 +135,13 @@ AM_CONDITIONAL( [WITH_TWIN], [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"]) +AS_IF( + [test "x$with_twin_x11" != "xyes" && \ + test "x$with_twin_fbdev" != "xyes" && \ + test "x$ax_cv_curses" != "xyes"], + [AC_MSG_WARN([ No user interface programs configured. Consider using --with-ncurses, --with-twin-x11 or --with-twin-fbdev'])] +) + AS_IF( [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"], [PKG_CHECK_MODULES( From patchwork Thu Aug 2 17:29:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHL30R5kz9s2g for ; Fri, 3 Aug 2018 03:32:11 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="oehvCszX"; 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 41hHL254YJzF21T for ; Fri, 3 Aug 2018 03:32:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="oehvCszX"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="oehvCszX"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74YsBzF2D0 for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NynvFxppzXOjV8Tsn/PRf0nvyqTAzrqw8DDtBAumpT4=; b=oehvCszXrEeBrC264AX8fOn9C 7q1/mEHFviKSsHa+D8f1EZJc3/dWZI0egOhAMOUiy1JL0kkYeC6GqiYGPhU96pb0CPyPPsYJtc85F UUGMWJ6Th6/xJO9nDn88pgCkU+cW39x9L3PzTinF29lnOiMFTPl4nkk6GaJFlMJXr8WqrwLG8k5cx QsQ6qu1IJWUL8YVG9SytW4ilGsVOJ5Wpi1hqKX7IhP5vVDlxvkAuP8W+QvMT7YkrNPW9Fs+L0XVp3 6+pxvA9m9X3/mpr75usf8ftdAwZ8S6UOx2L9Lz0bFmosnUdvL/F5ChpquUnEt4vGYRcPUtTvPl+S+ 0XyPgyOqQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPp-0007WR-P4; Thu, 02 Aug 2018 17:29:33 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 03/30] configure: Remove unused ENABLE_DEBUG To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:33 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" We setup debug builds in the configure script with DEFAULT_CFLAGS and DEFAULT_CPPFLAGS. Remove the unused ENABLE_DEBUG AM conditional. Signed-off-by: Geoff Levand --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index d02c85f..2cf94ef 100644 --- a/configure.ac +++ b/configure.ac @@ -322,7 +322,6 @@ AC_ARG_ENABLE( [], [enable_debug=check] ) -#AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"]) AC_ARG_ENABLE( [test-valgrind], From patchwork Thu Aug 2 17:29:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952912 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKL4pfhz9s2g for ; Fri, 3 Aug 2018 03:31:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="njiqu7cl"; 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 41hHKL3CbvzF2D0 for ; Fri, 3 Aug 2018 03:31:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="njiqu7cl"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="njiqu7cl"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH751gBzF2D8 for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=wElgGKHg27LxslOehNSMy0/cD6ooH8seS5YOJqhFJvU=; b=njiqu7cl/cp/2Mgl/ahchBvJS u9u+91McYOp74yTokuw4puomJtq4U35GKXrESnXvgnjTynAN0MJsK5prJdc6TWQr25QQ3lNTeJ9ax 4CTVtIbEC8HVM2CboZYaM+C3W/nb7ugn/BBUOaS07B5TJ5CuRtuh6grUl4+vONbt64ApwULdSiKZ/ bInDxwGMpStID/kW9L8DaeW89uDo4HEPpY6JHq5NFkQRDfXZjrdDLVR5nXUoLvxyG6MF2h/YVNrGn C0pY4y1XHQcWpTVzdiFTn4z+AvWIwj8aWrcwJqcyYsVV8NtLHnh7ov29BRdLLDJFIm7inSVxVmoTw K6NG1RduQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPp-0007WV-UM; Thu, 02 Aug 2018 17:29:33 +0000 Message-Id: <1f34794c770bf970381f6b72a3f85177cc1d4853.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 04/30] lib/log: Add verbose logging routines To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:33 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add three new logging routines pb_log_fn and pb_debug_fn, which print the calling function's name to the log, and pb_debug_fl which prints the calling function's name and the file line number to the log. Signed-off-by: Geoff Levand --- lib/log/log.c | 31 +++++++++++++++++++++++++++++++ lib/log/log.h | 10 ++++++++++ s | 0 3 files changed, 41 insertions(+) create mode 100644 s diff --git a/s b/s new file mode 100644 index 0000000..e69de29 diff --git a/lib/log/log.c b/lib/log/log.c index adb2078..0b145e0 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -34,6 +34,15 @@ void pb_log(const char *fmt, ...) va_end(ap); } +void _pb_log_fn(const char *func, const char *fmt, ...) +{ + va_list ap; + pb_log("%s: ", func); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + void pb_debug(const char *fmt, ...) { va_list ap; @@ -44,6 +53,28 @@ void pb_debug(const char *fmt, ...) va_end(ap); } +void _pb_debug_fn(const char *func, const char *fmt, ...) +{ + va_list ap; + if (!debug) + return; + pb_log("%s: ", func); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + +void _pb_debug_fl(const char *func, int line, const char *fmt, ...) +{ + va_list ap; + if (!debug) + return; + pb_log("%s:%d: ", func, line); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + void __pb_log_init(FILE *fp, bool _debug) { if (logf) diff --git a/lib/log/log.h b/lib/log/log.h index 9454596..2d4fd91 100644 --- a/lib/log/log.h +++ b/lib/log/log.h @@ -5,7 +5,17 @@ #include void __attribute__ ((format (printf, 1, 2))) pb_log(const char *fmt, ...); +void __attribute__ ((format (printf, 2, 3))) _pb_log_fn(const char *func, + const char *fmt, ...); +#define pb_log_fn(args...) _pb_log_fn(__func__, args) + void __attribute__ ((format (printf, 1, 2))) pb_debug(const char *fmt, ...); +void __attribute__ ((format (printf, 2, 3))) _pb_debug_fn(const char *func, + const char *fmt, ...); +#define pb_debug_fn(args...) _pb_debug_fn(__func__, args) +void __attribute__ ((format (printf, 3, 4))) _pb_debug_fl(const char *func, + int line, const char *fmt, ...); +#define pb_debug_fl(args...) _pb_debug_fl(__func__, __LINE__, args) void __pb_log_init(FILE *stream, bool debug); From patchwork Thu Aug 2 17:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952901 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHHV6FHSz9s2g for ; Fri, 3 Aug 2018 03:29:58 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="MfaFuehR"; 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 41hHHV2fK1zF2DG for ; Fri, 3 Aug 2018 03:29:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="MfaFuehR"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="MfaFuehR"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74knBzF2D1 for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=i0uxIUTQ95aqiDQ/wOIU9F1mIk0cwzLKQ+03Ate9DfU=; b=MfaFuehRdQrcV4foMlPWoussp U2qc0AGPi9q9nJQlhk2il1TE/mHUiNvJDIYj7O+QAsT99WuDrsnF744/9UEr33aDsQV5C8UbfDR08 /T22xSmyYOLLKLc09LCn0nSFE95vwhLAgND9YfqNU0qHirOeTU/7HmC7VyaaOHs42k71TiiLD5x7d AuD9zR5Lti94wKi8eP78yus4X3UoSsFLjEsmwznD98vQRcjLK6WYD2NZGM5xQ17mm2gt2kUDOagx6 9tUAEwDT3w03hwPez+334YyblBsySVp6UXqUGS4BEzLWtOPkW5XKsrg2W9t3tl0Z8f3yPTMLMpKtR NAlQ9y+vg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPq-0007WZ-3X; Thu, 02 Aug 2018 17:29:34 +0000 Message-Id: <52a6a377a24074f725957107df2f74ed51b9e8f7.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 05/30] lib/log: Switch to pb_log_fn To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:34 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" The only functional change should be an additional '/n' to a few log messagees that seemed to be missing it. Signed-off-by: Geoff Levand --- discover/boot.c | 14 +++++++------- discover/device-handler.c | 8 ++++---- discover/devmapper.c | 14 +++++++------- discover/discover-server.c | 6 +++--- discover/event.c | 8 ++++---- discover/ipmi.c | 2 +- discover/platform-powerpc.c | 4 ++-- discover/pxe-parser.c | 2 +- discover/resource.c | 2 +- discover/udev.c | 4 ++-- discover/user-event.c | 16 ++++++++-------- lib/file/file.c | 6 +++--- lib/flash/flash.c | 8 ++++---- lib/pb-protocol/pb-protocol.c | 8 ++++---- lib/process/process.c | 12 ++++++------ lib/security/common.c | 2 +- lib/security/gpg.c | 26 +++++++++++++------------- lib/security/openssl.c | 18 +++++++++--------- lib/url/url.c | 2 +- ui/common/discover-client.c | 20 ++++++++++---------- ui/common/joystick.c | 4 ++-- ui/common/ps3.c | 18 +++++++++--------- ui/common/timer.c | 2 +- ui/common/ui-system.c | 2 +- ui/ncurses/generic-main.c | 2 +- ui/ncurses/nc-cui.c | 36 ++++++++++++++++++------------------ ui/ncurses/nc-menu.c | 8 ++++---- ui/ncurses/ps3-main.c | 8 ++++---- ui/twin/main-generic.c | 4 ++-- ui/twin/main-ps3.c | 2 +- ui/twin/pbt-client.c | 12 ++++++------ ui/twin/pbt-scr.c | 16 ++++++++-------- 32 files changed, 148 insertions(+), 148 deletions(-) diff --git a/discover/boot.c b/discover/boot.c index 04c32a1..7faec9f 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -94,7 +94,7 @@ static int kexec_load(struct boot_task *boot_task) process = process_create(boot_task); if (!process) { - pb_log("%s: failed to create process\n", __func__); + pb_log_fn("failed to create process\n"); return -1; } @@ -131,14 +131,14 @@ static int kexec_load(struct boot_task *boot_task) result = process_run_sync(process); if (result) { - pb_log("%s: failed to run process\n", __func__); + pb_log_fn("failed to run process\n"); goto abort_kexec; } result = process->exit_status; if (result) { - pb_log("%s: failed: (%d)\n", __func__, result); + pb_log_fn("failed: (%d)\n", result); update_status(boot_task->status_fn, boot_task->status_arg, STATUS_ERROR, "%s", process->stdout_buf); } @@ -170,7 +170,7 @@ static int kexec_reboot(struct boot_task *task) } if (result) - pb_log("%s: failed: (%d)\n", __func__, result); + pb_log_fn("failed: (%d)\n", result); /* okay, kexec -e -f */ if (result) { @@ -179,7 +179,7 @@ static int kexec_reboot(struct boot_task *task) } if (result) - pb_log("%s: failed: (%d)\n", __func__, result); + pb_log_fn("failed: (%d)\n", result); return result; @@ -423,7 +423,7 @@ static void boot_process(struct load_url_result *result, void *data) _("Performing kexec load")); rc = kexec_load(task); - pb_log("%s: kexec_load returned %d\n", __func__, rc); + pb_log_fn("kexec_load returned %d\n", rc); if (rc == KEXEC_LOAD_DECRYPTION_FALURE) { update_status(task->status_fn, task->status_arg, STATUS_ERROR, _("Decryption failed")); @@ -526,7 +526,7 @@ struct boot_task *boot(void *ctx, struct discover_boot_option *opt, } else if (opt && opt->boot_image) { image = opt->boot_image->url; } else { - pb_log("%s: no image specified\n", __func__); + pb_log_fn("no image specified\n"); update_status(status_fn, status_arg, STATUS_INFO, _("Boot failed: no image specified")); return NULL; diff --git a/discover/device-handler.c b/discover/device-handler.c index 69bc050..1299c33 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -675,7 +675,7 @@ void device_handler_status_download(struct device_handler *handler, } if (!update) { - pb_log("%s: failed to allocate new status\n", __func__); + pb_log_fn("failed to allocate new status\n"); } else { device_handler_status_info(handler, "%s\n", update); talloc_free(update); @@ -1568,7 +1568,7 @@ static void process_url_cb(struct load_url_result *result, void *data) const char *mac; if (result->status != LOAD_OK) { - pb_log("%s: Load failed for %s\n", __func__, result->url->full); + pb_log_fn("Load failed for %s\n", result->url->full); return; } @@ -1673,7 +1673,7 @@ static void plugin_install_cb(struct process *process) struct device_handler *handler = process->data; if (!handler) { - pb_log("%s: Missing data!\n", __func__); + pb_log_fn("Missing data!\n"); return; } @@ -2206,7 +2206,7 @@ void device_handler_discover_context_commit( struct device_handler *handler __attribute__((unused)), struct discover_context *ctx __attribute__((unused))) { - pb_log("%s stubbed out for test cases\n", __func__); + pb_log_fn("stubbed out for test cases\n"); } static void device_handler_update_lang(const char *lang __attribute__((unused))) diff --git a/discover/devmapper.c b/discover/devmapper.c index d8445e6..f7407b7 100644 --- a/discover/devmapper.c +++ b/discover/devmapper.c @@ -138,7 +138,7 @@ static bool snapshot_merge_complete(const char *dm_name) task = dm_task_create(DM_DEVICE_STATUS); if (!task) { - pb_log("%s: Error creating task\n", __func__); + pb_log_fn("Error creating task\n"); return result; } @@ -198,7 +198,7 @@ static int set_device_active(const char *dm_name, bool active) task = dm_task_create(DM_DEVICE_SUSPEND); if (!task) { - pb_log("%s: Could not create dm_task\n", __func__); + pb_log_fn("Could not create dm_task\n"); return rc; } @@ -461,7 +461,7 @@ static int destroy_device(const char *dm_name) task = dm_task_create(DM_DEVICE_REMOVE); if (!task) { - pb_log("%s: could not create dm_task\n", __func__); + pb_log_fn("could not create dm_task\n"); return -1; } @@ -543,13 +543,13 @@ static int reload_snapshot(struct discover_device *device, bool merge) device->ramdisk->base); } if (!target.ttype || !target.params) { - pb_log("%s: failed to allocate parameters\n", __func__); + pb_log_fn("failed to allocate parameters\n"); goto err1; } task = dm_task_create(DM_DEVICE_RELOAD); if (!task) { - pb_log("%s: Error creating task\n", __func__); + pb_log_fn("Error creating task\n"); goto err1; } @@ -560,7 +560,7 @@ static int reload_snapshot(struct discover_device *device, bool merge) if (!dm_task_add_target(task, target.start_sector, target.end_sector, target.ttype, target.params)) { - pb_log("%s: Failed to set target\n", __func__); + pb_log_fn("Failed to set target\n"); goto err2; } @@ -581,7 +581,7 @@ err1: int devmapper_merge_snapshot(struct discover_device *device) { if (device->mounted) { - pb_log("%s: %s still mounted\n", __func__, device->device->id); + pb_log_fn("%s still mounted\n", device->device->id); return -1; } diff --git a/discover/discover-server.c b/discover/discover-server.c index 3377fa6..34d82be 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -270,7 +270,7 @@ static int discover_server_process_message(void *arg) rc = pb_protocol_deserialise_boot_command(boot_command, message); if (rc) { - pb_log("%s: no boot command?", __func__); + pb_log_fn("no boot command?\n"); return 0; } @@ -291,7 +291,7 @@ static int discover_server_process_message(void *arg) rc = pb_protocol_deserialise_config(config, message); if (rc) { - pb_log("%s: no config?", __func__); + pb_log_fn("no config?\n"); return 0; } @@ -328,7 +328,7 @@ static int discover_server_process_message(void *arg) break; default: - pb_log("%s: invalid action %d\n", __func__, message->action); + pb_log_fn("invalid action %d\n", message->action); return 0; } diff --git a/discover/event.c b/discover/event.c index 047e928..ead2fda 100644 --- a/discover/event.c +++ b/discover/event.c @@ -29,14 +29,14 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, headerlen = strnlen(buf, len); if (!headerlen) { - pb_log("%s: bad header, no data\n", __func__); + pb_log_fn("bad header, no data\n"); return -1; } /* we should see an @\0 at the head of the buffer */ sep = strchr(buf, '@'); if (!sep) { - pb_log("%s: bad header: %s\n", __func__, buf); + pb_log_fn("bad header: %s\n", buf); return -1; } @@ -58,12 +58,12 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, else if (streq(buf, "plugin")) *action = EVENT_ACTION_PLUGIN; else { - pb_log("%s: unknown action: %s\n", __func__, buf); + pb_log_fn("unknown action: %s\n", buf); return -1; } if (!*(sep + 1)) { - pb_log("%s: bad device: %s\n", __func__, buf); + pb_log_fn("bad device: %s\n", buf); return -1; } diff --git a/discover/ipmi.c b/discover/ipmi.c index d652e9f..f94dab7 100644 --- a/discover/ipmi.c +++ b/discover/ipmi.c @@ -239,7 +239,7 @@ int parse_ipmi_interface_override(struct config *config, uint8_t *buf, i += sizeof(ipsize); if (!hwsize || !ipsize) { - pb_log("%s: Empty response\n", __func__); + pb_log_fn("Empty response\n"); return -1; } diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index df8c7d6..22d213d 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -1193,7 +1193,7 @@ static void get_ipmi_network_override(struct platform_powerpc *platform, memcpy(&cookie, &resp[i], sizeof(cookie)); cookie = __be32_to_cpu(cookie); if (cookie != magic_value) { - pb_log("%s: Incorrect cookie %x\n", __func__, cookie); + pb_log_fn("Incorrect cookie %x\n", cookie); return; } i += sizeof(cookie); @@ -1259,7 +1259,7 @@ static int load_config(struct platform *p, struct config *config) rc = parse_nvram(platform); if (rc) - pb_log("%s: Failed to parse nvram\n", __func__); + pb_log_fn("Failed to parse nvram\n"); populate_config(platform, config); diff --git a/discover/pxe-parser.c b/discover/pxe-parser.c index 9221f95..ba0f81c 100644 --- a/discover/pxe-parser.c +++ b/discover/pxe-parser.c @@ -500,7 +500,7 @@ static int pxe_parse(struct discover_context *dc) file_url = dc->conf_url; if (!file_url) { - pb_log("%s: Failed to parse conf url!\n", __func__); + pb_log_fn("Failed to parse conf url!\n"); goto out_conf; } diff --git a/discover/resource.c b/discover/resource.c index 04e14cb..c09c1c5 100644 --- a/discover/resource.c +++ b/discover/resource.c @@ -86,7 +86,7 @@ struct resource *create_devpath_resource(struct discover_boot_option *opt, devstr = talloc_strndup(res, devpath, pos - devpath); path = talloc_strdup(res, pos + 1); - pb_log("%s: resource depends on device %s\n", __func__, devstr); + pb_log_fn("resource depends on device %s\n", devstr); /* defer resolution until we can find a suitable matching device */ info = talloc(res, struct devpath_resource_info); diff --git a/discover/udev.c b/discover/udev.c index 883313b..fa5d4b4 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -81,11 +81,11 @@ static void udev_setup_device_params(struct udev_device *udev, static void lvm_vg_search(struct device_handler *handler) { if (process_run_simple(handler, pb_system_apps.vgscan, "-qq", NULL)) - pb_log("%s: Failed to execute vgscan\n", __func__); + pb_log_fn("Failed to execute vgscan\n"); if (process_run_simple(handler, pb_system_apps.vgchange, "-ay", "-qq", NULL)) - pb_log("%s: Failed to execute vgchange\n", __func__); + pb_log_fn("Failed to execute vgchange\n"); } static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, diff --git a/discover/user-event.c b/discover/user-event.c index 128186b..1257796 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -94,13 +94,13 @@ static struct resource *user_event_resource(struct discover_boot_option *opt, siaddr = event_get_param(event, "siaddr"); if (!siaddr) { - pb_log("%s: next server option not found\n", __func__); + pb_log_fn("next server option not found\n"); return NULL; } boot_file = event_get_param(event, "bootfile"); if (!boot_file) { - pb_log("%s: bootfile not found\n", __func__); + pb_log_fn("bootfile not found\n"); return NULL; } @@ -148,7 +148,7 @@ static int parse_user_event(struct discover_context *ctx, struct event *event) val = event_get_param(event, "name"); if (!val) { - pb_log("%s: no name found\n", __func__); + pb_log_fn("no name found\n"); goto fail_opt; } @@ -157,7 +157,7 @@ static int parse_user_event(struct discover_context *ctx, struct event *event) d_opt->boot_image = user_event_resource(d_opt, event, false); if (!d_opt->boot_image) { - pb_log("%s: no boot image found for %s!\n", __func__, + pb_log_fn("no boot image found for %s!\n", opt->name); goto fail_opt; } @@ -288,7 +288,7 @@ struct pb_url *user_event_parse_conf_url(struct discover_context *ctx, host = parse_host_addr(event); if (!host) { - pb_log("%s: host address not found\n", __func__); + pb_log_fn("host address not found\n"); /* No full URLs and no host address? Check for DHCPv6 options */ if (bootfile_url && is_url(bootfile_url)) { @@ -362,7 +362,7 @@ char **user_event_parse_conf_filenames( } if (!mac_addr && !ip_hex) { - pb_log("%s: neither mac nor ip parameter found\n", __func__); + pb_log_fn("neither mac nor ip parameter found\n"); return NULL; } @@ -672,12 +672,12 @@ static int user_event_process(void *arg) len = recvfrom(uev->socket, buf, PBOOT_USER_EVENT_SIZE, 0, NULL, NULL); if (len < 0) { - pb_log("%s: socket read failed: %s", __func__, strerror(errno)); + pb_log_fn("socket read failed: %s\n", strerror(errno)); return 0; } if (len == 0) { - pb_log("%s: empty", __func__); + pb_log_fn("empty\n"); return 0; } diff --git a/lib/file/file.c b/lib/file/file.c index b575d34..6028005 100644 --- a/lib/file/file.c +++ b/lib/file/file.c @@ -54,13 +54,13 @@ int copy_file_secure_dest(void *ctx, const char *source_file, destination_fd = mkstemp(template); if (destination_fd < 0) { - pb_log("%s: unable to create temp file, %m\n", __func__); + pb_log_fn("unable to create temp file, %m\n"); fclose(source_handle); return -1; } destination_handle = fdopen(destination_fd, "w"); if (!destination_handle) { - pb_log("%s: unable to open destination file, %m\n", __func__); + pb_log_fn("unable to open destination file, %m\n"); fclose(source_handle); close(destination_fd); return -1; @@ -81,7 +81,7 @@ int copy_file_secure_dest(void *ctx, const char *source_file, if (ferror(destination_handle)) { /* General error */ result = -1; - pb_log("%s: failed: unknown fault\n", __func__); + pb_log_fn("failed: unknown fault\n"); } else { /* No space on destination device */ diff --git a/lib/flash/flash.c b/lib/flash/flash.c index 464b876..b7e5b88 100644 --- a/lib/flash/flash.c +++ b/lib/flash/flash.c @@ -94,7 +94,7 @@ static struct flash_info *flash_setup_buffer(void *ctx, const char *partition) rc = ffs_init(0, info->size, info->bl, &info->ffs, 1); if (rc) { - pb_log("%s: Failed to init ffs\n", __func__); + pb_log_fn("Failed to init ffs\n"); goto out_flash; } @@ -171,7 +171,7 @@ int flash_parse_version(void *ctx, char ***versions, bool current) len = cur_info->attr_data_len - ecc_size(cur_info->attr_data_len); buffer = talloc_array(cur_info, char, len); if (!buffer) { - pb_log("%s: Failed to init buffer!\n", __func__); + pb_log_fn("Failed to init buffer!\n"); goto out; } @@ -187,7 +187,7 @@ int flash_parse_version(void *ctx, char ***versions, bool current) if (tok) { tmp = talloc_realloc(ctx, tmp, char *, n + 1); if (!tmp) { - pb_log("%s: Failed to allocate memory\n", __func__); + pb_log_fn("Failed to allocate memory\n"); goto out; } tmp[n++] = talloc_strdup(ctx, tok); @@ -198,7 +198,7 @@ int flash_parse_version(void *ctx, char ***versions, bool current) /* Ignore leading tab from subsequent lines */ tmp = talloc_realloc(ctx, tmp, char *, n + 1); if (!tmp) { - pb_log("%s: Failed to reallocate memory\n", __func__); + pb_log_fn("Failed to reallocate memory\n"); n = 0; goto out; } diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 41707da..315efc4 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -725,7 +725,7 @@ int pb_protocol_write_message(int fd, struct pb_protocol_message *message) if (!total_len) return 0; - pb_log("%s: failed: %s\n", __func__, strerror(errno)); + pb_log_fn("failed: %s\n", strerror(errno)); return -1; } @@ -735,7 +735,7 @@ struct pb_protocol_message *pb_protocol_create_message(void *ctx, struct pb_protocol_message *message; if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) { - pb_log("%s: payload too big %u/%u\n", __func__, payload_len, + pb_log_fn("payload too big %u/%u\n", payload_len, PB_PROTOCOL_MAX_PAYLOAD_SIZE); return NULL; } @@ -766,7 +766,7 @@ struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd) m.action = __be32_to_cpu(m.action); if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) { - pb_log("%s: payload too big %u/%u\n", __func__, m.payload_len, + pb_log_fn("payload too big %u/%u\n", m.payload_len, PB_PROTOCOL_MAX_PAYLOAD_SIZE); return NULL; } @@ -779,7 +779,7 @@ struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd) if (rc <= 0) { talloc_free(message); - pb_log("%s: failed (%u): %s\n", __func__, len, + pb_log_fn("failed (%u): %s\n", len, strerror(errno)); return NULL; } diff --git a/lib/process/process.c b/lib/process/process.c index c1606a5..1fa0bb0 100644 --- a/lib/process/process.c +++ b/lib/process/process.c @@ -92,7 +92,7 @@ static int process_read_stdout_once(struct process_info *procinfo, char **line) if (rc < 0) { if (errno == EINTR) return 1; - pb_log("%s: read failed: %s\n", __func__, strerror(errno)); + pb_log_fn("read failed: %s\n", strerror(errno)); return rc; } @@ -232,7 +232,7 @@ static void sigchld_sigaction(int signo, siginfo_t *info, rc = write(procset->sigchld_pipe[1], &pid, sizeof(pid)); if (rc != sizeof(pid)) - pb_log("%s: write failed: %s\n", __func__, strerror(errno)); + pb_log_fn("write failed: %s\n", strerror(errno)); } static int sigchld_pipe_event(void *arg) @@ -306,7 +306,7 @@ struct procset *process_init(void *ctx, struct waitset *set, bool dry_run) rc = pipe(procset->sigchld_pipe); if (rc) { - pb_log("%s: pipe() failed: %s\n", __func__, strerror(errno)); + pb_log_fn("pipe() failed: %s\n", strerror(errno)); goto err_free; } @@ -322,7 +322,7 @@ struct procset *process_init(void *ctx, struct waitset *set, bool dry_run) rc = sigaction(SIGCHLD, &sa, NULL); if (rc) { - pb_log("%s: sigaction() failed: %s\n", __func__, + pb_log_fn("sigaction() failed: %s\n", strerror(errno)); goto err_remove; } @@ -374,7 +374,7 @@ static int process_run_common(struct process_info *procinfo) pid = fork(); if (pid < 0) { - pb_log("%s: fork failed: %s\n", __func__, strerror(errno)); + pb_log_fn("fork failed: %s\n", strerror(errno)); return pid; } @@ -410,7 +410,7 @@ int process_run_sync(struct process *process) if (errno == EINTR) continue; - pb_log("%s: waitpid failed: %s\n", __func__, strerror(errno)); + pb_log_fn("waitpid failed: %s\n", strerror(errno)); return rc; } diff --git a/lib/security/common.c b/lib/security/common.c index df04054..a93ee98 100644 --- a/lib/security/common.c +++ b/lib/security/common.c @@ -81,7 +81,7 @@ int validate_boot_files(struct boot_task *boot_task) { /* Load authorized signatures file */ authorized_signatures_handle = fopen(LOCKDOWN_FILE, "r"); if (!authorized_signatures_handle) { - pb_log("%s: unable to read lockdown file\n", __func__); + pb_log_fn("unable to read lockdown file\n"); return KEXEC_LOAD_SIG_SETUP_INVALID; } diff --git a/lib/security/gpg.c b/lib/security/gpg.c index aae85aa..e319a06 100644 --- a/lib/security/gpg.c +++ b/lib/security/gpg.c @@ -73,22 +73,22 @@ int decrypt_file(const char *filename, gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: OpenPGP support not available\n", __func__); + pb_log_fn("OpenPGP support not available\n"); return -1; } err = gpgme_get_engine_info(&enginfo); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG engine failed to initialize\n", __func__); + pb_log_fn("GPG engine failed to initialize\n"); return -1; } err = gpgme_new(&gpg_context); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG context could not be created\n", __func__); + pb_log_fn("GPG context could not be created\n"); return -1; } err = gpgme_set_protocol(gpg_context, GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG protocol could not be set\n", __func__); + pb_log_fn("GPG protocol could not be set\n"); return -1; } if (keyring_path) @@ -100,7 +100,7 @@ int decrypt_file(const char *filename, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, enginfo->home_dir); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: Could not set GPG engine information\n", __func__); + pb_log_fn("Could not set GPG engine information\n"); return -1; } err = gpgme_data_new(&plaintext_data); @@ -120,7 +120,7 @@ int decrypt_file(const char *filename, err = gpgme_op_decrypt_verify(gpg_context, ciphertext_data, plaintext_data); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: Could not decrypt file\n", __func__); + pb_log_fn("Could not decrypt file\n"); return -1; } verification_result = gpgme_op_verify_result(gpg_context); @@ -210,7 +210,7 @@ int decrypt_file(const char *filename, gpgme_release(gpg_context); if (!valid) { - pb_log("%s: Incorrect GPG signature\n", __func__); + pb_log_fn("Incorrect GPG signature\n"); return -1; } @@ -242,22 +242,22 @@ int verify_file_signature(const char *plaintext_filename, gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: OpenPGP support not available\n", __func__); + pb_log_fn("OpenPGP support not available\n"); return -1; } err = gpgme_get_engine_info(&enginfo); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG engine failed to initialize\n", __func__); + pb_log_fn("GPG engine failed to initialize\n"); return -1; } err = gpgme_new(&gpg_context); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG context could not be created\n", __func__); + pb_log_fn("GPG context could not be created\n"); return -1; } err = gpgme_set_protocol(gpg_context, GPGME_PROTOCOL_OpenPGP); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: GPG protocol could not be set\n", __func__); + pb_log_fn("GPG protocol could not be set\n"); return -1; } if (keyring_path) @@ -269,7 +269,7 @@ int verify_file_signature(const char *plaintext_filename, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, enginfo->home_dir); if (err != GPG_ERR_NO_ERROR) { - pb_log("%s: Could not set GPG engine information\n", __func__); + pb_log_fn("Could not set GPG engine information\n"); return -1; } err = gpgme_data_new_from_file(&plaintext_data, plaintext_filename, 1); @@ -340,7 +340,7 @@ int verify_file_signature(const char *plaintext_filename, gpgme_release(gpg_context); if (!valid) { - pb_log("%s: Incorrect GPG signature\n", __func__); + pb_log_fn("Incorrect GPG signature\n"); return -1; } diff --git a/lib/security/openssl.c b/lib/security/openssl.c index 6454f8a..d9dfb95 100644 --- a/lib/security/openssl.c +++ b/lib/security/openssl.c @@ -94,7 +94,7 @@ static int get_pkcs12(FILE *keyfile, X509 **cert, EVP_PKEY **priv) */ if (!PKCS12_parse(p12, NULL, priv, cert, NULL) && !PKCS12_parse(p12, "", priv, cert, NULL)) { - pb_log("%s: Error parsing OpenSSL PKCS12:\n", __func__); + pb_log_fn("Error parsing OpenSSL PKCS12:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); } else ok = 1; @@ -131,7 +131,7 @@ static STACK_OF(X509) *get_cert_stack(FILE *keyfile) if (cert) sk_X509_push(certs, get_cert(keyfile)); } else { - pb_log("%s: Error allocating OpenSSL X509 stack:\n", __func__); + pb_log_fn("Error allocating OpenSSL X509 stack:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); } @@ -168,7 +168,7 @@ static EVP_PKEY *get_public_key(FILE *keyfile) /* handles both cases */ if (!pkey) { - pb_log("%s: Error loading OpenSSL public key:\n", __func__); + pb_log_fn("Error loading OpenSSL public key:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); } @@ -240,7 +240,7 @@ int decrypt_file(const char *filename, certs = sk_X509_new_null(); if (!certs) { - pb_log("%s: Error allocating OpenSSL X509 stack:\n", __func__); + pb_log_fn("Error allocating OpenSSL X509 stack:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); goto out; } @@ -268,7 +268,7 @@ int decrypt_file(const char *filename, /* in this mode its attached content */ if (!CMS_verify(cms, certs, NULL, content_bio, out_bio, CMS_NO_SIGNER_CERT_VERIFY | CMS_BINARY)) { - pb_log("%s: Failed OpenSSL CMS decrypt verify:\n", __func__); + pb_log_fn("Failed OpenSSL CMS decrypt verify:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); goto out; } @@ -359,7 +359,7 @@ int verify_file_signature(const char *plaintext_filename, if (!CMS_verify(cms, certs, NULL, plaintext_bio, NULL, CMS_DETACHED | CMS_NO_SIGNER_CERT_VERIFY | CMS_BINARY)) { - pb_log("%s: Failed OpenSSL CMS verify:\n", __func__); + pb_log_fn("Failed OpenSSL CMS verify:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); goto out; } @@ -375,7 +375,7 @@ int verify_file_signature(const char *plaintext_filename, ctx = EVP_MD_CTX_create(); if (!ctx) { - pb_log("%s: Error allocating OpenSSL MD ctx:\n", __func__); + pb_log_fn("Error allocating OpenSSL MD ctx:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); goto out; } @@ -385,7 +385,7 @@ int verify_file_signature(const char *plaintext_filename, goto out; if (EVP_DigestVerifyInit(ctx, NULL, s_verify_md, NULL, pkey) < 1) { - pb_log("%s: Error initializing OpenSSL verify:\n", __func__); + pb_log_fn("Error initializing OpenSSL verify:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); goto out; } @@ -425,7 +425,7 @@ int verify_file_signature(const char *plaintext_filename, if (EVP_DigestVerifyFinal(ctx, (unsigned char*)sigbuf, siglen)) nok = 0; else { - pb_log("%s: Error finalizing OpenSSL verify:\n", __func__); + pb_log_fn("Error finalizing OpenSSL verify:\n"); ERR_print_errors_cb(&pb_log_print_errors_cb, NULL); } } diff --git a/lib/url/url.c b/lib/url/url.c index f0e8b0e..44e9ac4 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -193,7 +193,7 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str) path = strchr(p, '/'); if (!path) { - pb_log("%s: parse path failed '%s'\n", __func__ , p); + pb_log_fn("parse path failed '%s'\n" , p); goto fail; } diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c index 88d0b4e..d941497 100644 --- a/ui/common/discover-client.c +++ b/ui/common/discover-client.c @@ -197,7 +197,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_device(dev, message); if (rc) { - pb_log("%s: no device?\n", __func__); + pb_log_fn("no device?\n"); goto out; } @@ -208,7 +208,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_boot_option(opt, message); if (rc) { - pb_log("%s: no boot_option?\n", __func__); + pb_log_fn("no boot_option?\n"); goto out; } @@ -217,7 +217,7 @@ static int discover_client_process(void *arg) case PB_PROTOCOL_ACTION_DEVICE_REMOVE: dev_id = pb_protocol_deserialise_string(ctx, message); if (!dev_id) { - pb_log("%s: no device id?\n", __func__); + pb_log_fn("no device id?\n"); goto out; } device_remove(client, dev_id); @@ -227,7 +227,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_boot_status(status, message); if (rc) { - pb_log("%s: invalid status message?\n", __func__); + pb_log_fn("invalid status message?\n"); goto out; } update_status(client, status); @@ -237,7 +237,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_system_info(sysinfo, message); if (rc) { - pb_log("%s: invalid sysinfo message?\n", __func__); + pb_log_fn("invalid sysinfo message?\n"); goto out; } update_sysinfo(client, sysinfo); @@ -247,7 +247,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_config(config, message); if (rc) { - pb_log("%s: invalid config message?\n", __func__); + pb_log_fn("invalid config message?\n"); goto out; } update_config(client, config); @@ -257,7 +257,7 @@ static int discover_client_process(void *arg) rc = pb_protocol_deserialise_plugin_option(p_opt, message); if (rc) { - pb_log("%s: no plugin_option?\n", __func__); + pb_log_fn("no plugin_option?\n"); goto out; } @@ -267,7 +267,7 @@ static int discover_client_process(void *arg) plugins_remove(client); break; default: - pb_log("%s: unknown action %d\n", __func__, message->action); + pb_log_fn("unknown action %d\n", message->action); } out: @@ -291,7 +291,7 @@ struct discover_client* discover_client_init(struct waitset *waitset, client->fd = socket(AF_UNIX, SOCK_STREAM, 0); if (client->fd < 0) { - pb_log("%s: socket: %s\n", __func__, strerror(errno)); + pb_log_fn("socket: %s\n", strerror(errno)); goto out_err; } @@ -304,7 +304,7 @@ struct discover_client* discover_client_init(struct waitset *waitset, strcpy(addr.sun_path, PB_SOCKET_PATH); if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr))) { - pb_log("%s: connect: %s\n", __func__, strerror(errno)); + pb_log_fn("connect: %s\n", strerror(errno)); goto out_err; } diff --git a/ui/common/joystick.c b/ui/common/joystick.c index a3d6abd..f75ae3d 100644 --- a/ui/common/joystick.c +++ b/ui/common/joystick.c @@ -47,7 +47,7 @@ int pjs_process_event(const struct pjs *pjs) result = read(pjs->fd, &e, sizeof(e)); if (result != sizeof(e)) { - pb_log("%s: read failed: %s\n", __func__, strerror(errno)); + pb_log_fn("read failed: %s\n", strerror(errno)); return 0; } @@ -86,7 +86,7 @@ struct pjs *pjs_init(void *ctx, int (*map)(const struct js_event *)) pjs->fd = open(dev_name, O_RDONLY | O_NONBLOCK); if (pjs->fd < 0) { - pb_log("%s: open %s failed: %s\n", __func__, dev_name, + pb_log_fn("open %s failed: %s\n", dev_name, strerror(errno)); goto out_err; } diff --git a/ui/common/ps3.c b/ui/common/ps3.c index c9b97b5..d2a57a5 100644 --- a/ui/common/ps3.c +++ b/ui/common/ps3.c @@ -79,7 +79,7 @@ static int ps3_flash_open(struct ps3_flash_ctx *fc, const char *mode) fc->dev = fopen(flash_dev, mode); if (!fc->dev) { - pb_log("%s: fopen failed: %s: %s\n", __func__, strerror(errno), + pb_log_fn("fopen failed: %s: %s\n", strerror(errno), flash_dev); return -1; } @@ -89,7 +89,7 @@ static int ps3_flash_open(struct ps3_flash_ctx *fc, const char *mode) result = os_area_fixed_read(&fc->header, &fc->params, fc->dev); if (result) { - pb_log("%s: os_area_fixed_read failed\n", __func__); + pb_log_fn("os_area_fixed_read failed\n"); goto fail; } @@ -123,7 +123,7 @@ int ps3_flash_get_values(struct ps3_flash_values *values) ps3_flash_close(&fc); if (result) { - pb_log("%s: os_area_db_read failed: %s\n", __func__, + pb_log_fn("os_area_db_read failed: %s\n", strerror(errno)); goto fail; } @@ -176,14 +176,14 @@ int ps3_flash_set_values(const struct ps3_flash_values *values) result = os_area_db_read(&fc.db, &fc.header, fc.dev); if (result) { - pb_log("%s: os_area_db_read failed: %s\n", __func__, + pb_log_fn("os_area_db_read failed: %s\n", strerror(errno)); - pb_log("%s: formating db\n", __func__); + pb_log_fn("formating db\n"); result = os_area_db_format(&fc.db, &fc.header, fc.dev); if (result) { - pb_log("%s: db_format failed: %s\n", __func__, + pb_log_fn("db_format failed: %s\n", strerror(errno)); goto fail; } @@ -220,7 +220,7 @@ static int ps3_video_ioctl(int request, unsigned int *mode_id) fd = open(fb_dev, O_RDWR); if (fd < 0) { - pb_log("%s: open failed: %s: %s\n", __func__, strerror(errno), + pb_log_fn("open failed: %s: %s\n", strerror(errno), fb_dev); return -1; } @@ -230,7 +230,7 @@ static int ps3_video_ioctl(int request, unsigned int *mode_id) close(fd); if (result < 0) { - pb_log("%s: ioctl failed: %s: %s\n", __func__, strerror(errno), + pb_log_fn("ioctl failed: %s: %s\n", strerror(errno), fb_dev); return -1; } @@ -266,6 +266,6 @@ int ps3_get_video_mode(unsigned int *mode_id) result = ps3_video_ioctl(PS3FB_IOCTL_GETMODE, mode_id); - pb_log("%s: %u\n", __func__, *mode_id); + pb_log_fn("%u\n", *mode_id); return result; } diff --git a/ui/common/timer.c b/ui/common/timer.c index b0cae0d..23c3e62 100644 --- a/ui/common/timer.c +++ b/ui/common/timer.c @@ -35,7 +35,7 @@ void ui_timer_init(struct waitset *waitset, struct ui_timer *timer, unsigned int seconds) { - pb_log("%s: %u\n", __func__, seconds); + pb_log_fn("%u\n", seconds); timer->timeout = seconds; timer->waitset = waitset; } diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c index 7e04801..02142db 100644 --- a/ui/common/ui-system.c +++ b/ui/common/ui-system.c @@ -78,7 +78,7 @@ unsigned int pb_elf_hash(const char *str) h ^= g >> 24; h &= ~g; } - pb_log("%s: %x\n", __func__, h); + pb_log_fn("%x\n", h); return h; } diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 7062796..096eb56 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -245,7 +245,7 @@ int main(int argc, char *argv[]) result += sigaction(SIGWINCH, &sa, NULL); if (result) { - pb_log("%s sigaction failed.\n", __func__); + pb_log_fn("sigaction failed.\n"); return EXIT_FAILURE; } diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 87d2503..3abeac3 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -169,7 +169,7 @@ static void cui_atexit(void) void cui_abort(struct cui *cui) { - pb_log("%s: exiting\n", __func__); + pb_log_fn("exiting\n"); cui->abort = 1; } @@ -254,7 +254,7 @@ int cui_run_cmd(struct cui *cui, const char **cmd_argv) nc_scr_post(cui->current); if (result) { - pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]); + pb_log_fn("failed: '%s'\n", cmd_argv[0]); nc_scr_status_printf(cui->current, _("Failed: %s"), cmd_argv[0]); } @@ -688,7 +688,7 @@ static void cui_handle_resize(struct cui *cui) struct winsize ws; if (ioctl(1, TIOCGWINSZ, &ws) == -1) { - pb_log("%s: ioctl failed: %s\n", __func__, strerror(errno)); + pb_log_fn("ioctl failed: %s\n", strerror(errno)); return; } @@ -783,7 +783,7 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, result = set_menu_items(menu->ncm, NULL); if (result) - pb_log("%s: set_menu_items failed: %d\n", __func__, result); + pb_log_fn("set_menu_items failed: %d\n", result); /* Insert new items at insert_pt. */ if (dev_hdr) { @@ -798,10 +798,10 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, } if (plugin_option) { - pb_log("%s: adding plugin '%s'\n", __func__, cod->name); + pb_log_fn("adding plugin '%s'\n", cod->name); pb_log(" file '%s'\n", cod->pd->plugin_file); } else { - pb_log("%s: adding opt '%s'\n", __func__, cod->name); + pb_log_fn("adding opt '%s'\n", cod->name); pb_log(" image '%s'\n", cod->bd->image); pb_log(" initrd '%s'\n", cod->bd->initrd); pb_log(" args '%s'\n", cod->bd->args); @@ -826,14 +826,14 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, } result = set_menu_items(cui->main->ncm, cui->main->items); if (result) - pb_log("%s: set_menu_items failed: %d\n", __func__, result); + pb_log_fn("set_menu_items failed: %d\n", result); } /* Re-attach the items array. */ result = set_menu_items(menu->ncm, menu->items); if (result) - pb_log("%s: set_menu_items failed: %d\n", __func__, result); + pb_log_fn("set_menu_items failed: %d\n", result); if (0) { pb_log("%s\n", __func__); @@ -878,7 +878,7 @@ static void cui_device_remove(struct device *dev, void *arg) int rows, cols, top, last; int result; - pb_log("%s: %p %s\n", __func__, dev, dev->id); + pb_log_fn("%p %s\n", dev, dev->id); if (cui->current == &cui->main->scr) nc_scr_unpost(cui->current); @@ -891,7 +891,7 @@ static void cui_device_remove(struct device *dev, void *arg) result |= set_menu_items(cui->plugin_menu->ncm, NULL); if (result) - pb_log("%s: set_menu_items failed: %d\n", __func__, result); + pb_log_fn("set_menu_items failed: %d\n", result); list_for_each_entry(&dev->boot_options, opt, list) { struct pmenu_item *item = pmenu_item_from_arg(opt->ui_info); @@ -948,7 +948,7 @@ static void cui_device_remove(struct device *dev, void *arg) } if (result) - pb_log("%s: set_menu_items failed: %d\n", __func__, result); + pb_log_fn("set_menu_items failed: %d\n", result); if (0) { pb_log("%s\n", __func__); @@ -1300,14 +1300,14 @@ static struct pmenu *main_menu_init(struct cui *cui) m = pmenu_init(cui, 9, cui_on_exit); if (!m) { - pb_log("%s: failed\n", __func__); + pb_log_fn("failed\n"); return NULL; } m->n_hot_keys = 1; m->hot_keys = talloc_array(m, hot_key_fn, m->n_hot_keys); if (!m->hot_keys) { - pb_log("%s: failed to allocate hot_keys\n", __func__); + pb_log_fn("failed to allocate hot_keys\n"); talloc_free(m); return NULL; } @@ -1506,7 +1506,7 @@ struct cui *cui_init(void* platform_info, cui = talloc_zero(NULL, struct cui); if (!cui) { - pb_log("%s: alloc cui failed.\n", __func__); + pb_log_fn("alloc cui failed.\n"); fprintf(stderr, _("%s: alloc cui failed.\n"), __func__); goto fail_alloc; } @@ -1526,7 +1526,7 @@ retry_start: &cui_client_ops, cui); if (cui->client || !i) break; - pb_log("%s: waiting for server %d\n", __func__, i); + pb_log_fn("waiting for server %d\n", i); sleep(1); } @@ -1540,7 +1540,7 @@ retry_start: if (!result) goto retry_start; - pb_log("%s: discover_client_init failed.\n", __func__); + pb_log_fn("discover_client_init failed.\n"); fprintf(stderr, _("%s: error: discover_client_init failed.\n"), __func__); fprintf(stderr, _("could not start pb-discover, the petitboot " @@ -1554,7 +1554,7 @@ retry_start: waiter_register_timeout(cui->waitset, 0, cui_server_wait, cui); } else if (!cui->client) { - pb_log("%s: discover_client_init failed.\n", __func__); + pb_log_fn("discover_client_init failed.\n"); fprintf(stderr, _("%s: error: discover_client_init failed.\n"), __func__); fprintf(stderr, _("check that pb-discover, " @@ -1653,7 +1653,7 @@ int cui_run(struct cui *cui) int result = waiter_poll(cui->waitset); if (result < 0) { - pb_log("%s: poll: %s\n", __func__, strerror(errno)); + pb_log_fn("poll: %s\n", strerror(errno)); break; } diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c index a6c2b15..a90a02e 100644 --- a/ui/ncurses/nc-menu.c +++ b/ui/ncurses/nc-menu.c @@ -117,7 +117,7 @@ static const char *pmenu_item_label(struct pmenu_item *item, const char *name) label = talloc_array(item, char, len + 1); wcstombs(label, tmp, len + 1); - pb_log("%s: %s\n", __func__, label); + pb_log_fn("%s\n", label); talloc_free(tmp); return label; @@ -357,7 +357,7 @@ static int pmenu_item_get_index(const struct pmenu_item *item) if (item->pmenu->items[i] == item->nci) return i; - pb_log("%s: not found: %p %s\n", __func__, item, + pb_log_fn("not found: %p %s\n", item, (item ? item->nci->name.str : "(null)")); return -1; } @@ -491,7 +491,7 @@ unsigned int pmenu_grow(struct pmenu *menu, unsigned int count) assert(item_count(menu->ncm) == 0 && "not disconnected"); - pb_log("%s: %u current + %u new = %u\n", __func__, menu->item_count, + pb_log_fn("%u current + %u new = %u\n", menu->item_count, count, menu->item_count + count); /* Note that items array has a null terminator. */ @@ -526,7 +526,7 @@ int pmenu_remove(struct pmenu *menu, struct pmenu_item *item) assert(menu->item_count); - pb_log("%s: %u\n", __func__, menu->item_count); + pb_log_fn("%u\n", menu->item_count); index = pmenu_item_get_index(item); diff --git a/ui/ncurses/ps3-main.c b/ui/ncurses/ps3-main.c index f60a05e..eda15d0 100644 --- a/ui/ncurses/ps3-main.c +++ b/ui/ncurses/ps3-main.c @@ -407,14 +407,14 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) m = pmenu_init(ps3_cui->cui, 3, cui_on_exit); if (!m) { - pb_log("%s: failed\n", __func__); + pb_log_fn("failed\n"); return NULL; } m->n_hot_keys = 2; m->hot_keys = talloc_array(m, hot_key_fn *, m->n_hot_keys); if (!m->hot_keys) { - pb_log("%s: failed to allocate hot_keys\n", __func__); + pb_log_fn("failed to allocate hot_keys\n"); talloc_free(m); return NULL; } @@ -474,7 +474,7 @@ static struct pmenu *ps3_svm_init(struct ps3_cui *ps3_cui) m = pmenu_init(ps3_cui->cui, 12, ps3_svm_to_mm_helper); if (!m) { - pb_log("%s: failed\n", __func__); + pb_log_fn("failed\n"); return NULL; } @@ -621,7 +621,7 @@ int main(int argc, char *argv[]) result += sigaction(SIGWINCH, &sa, NULL); if (result) { - pb_log("%s sigaction failed.\n", __func__); + pb_log_fn("sigaction failed.\n"); return EXIT_FAILURE; } diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index 8ddec9e..a85cace 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -204,7 +204,7 @@ static int run(struct pbt_client *client) int result = waiter_poll(client->waitset); if (result < 0) { - pb_log("%s: poll: %s\n", __func__, strerror(errno)); + pb_log_fn("poll: %s\n", strerror(errno)); break; } @@ -304,7 +304,7 @@ int main(int argc, char *argv[]) result += sigaction(SIGWINCH, &sa, NULL); if (result) { - pb_log("%s sigaction failed.\n", __func__); + pb_log_fn("sigaction failed.\n"); return EXIT_FAILURE; } diff --git a/ui/twin/main-ps3.c b/ui/twin/main-ps3.c index ba4b1d7..f98aca8 100644 --- a/ui/twin/main-ps3.c +++ b/ui/twin/main-ps3.c @@ -411,7 +411,7 @@ int main(int argc, char *argv[]) result += sigaction(SIGWINCH, &sa, NULL); if (result) { - pb_log("%s sigaction failed.\n", __func__); + pb_log_fn("sigaction failed.\n"); return EXIT_FAILURE; } diff --git a/ui/twin/pbt-client.c b/ui/twin/pbt-client.c index 48de816..cffb5de 100644 --- a/ui/twin/pbt-client.c +++ b/ui/twin/pbt-client.c @@ -66,7 +66,7 @@ static int pbt_client_boot(struct pbt_item *item) NULL, opt_data->opt, opt_data->bd); if (result) { - pb_log("%s: failed: %s\n", __func__, opt_data->bd->image); + pb_log_fn("failed: %s\n", opt_data->bd->image); pbt_frame_status_printf(&item->pbt_client->frame, "Failed: kexec %s", opt_data->bd->image); } @@ -194,7 +194,7 @@ static void pbt_device_remove(struct device *dev, struct pbt_client *client) } if (!removed_item) { - pb_log("%s: %p %s: unknown device\n", __func__, dev, dev->id); + pb_log_fn("%p %s: unknown device\n", dev, dev->id); assert(0 && "unknown device"); return; } @@ -260,7 +260,7 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, pbt_client = talloc_zero(NULL, struct pbt_client); if (!pbt_client) { - pb_log("%s: alloc pbt_client failed.\n", __func__); + pb_log_fn("alloc pbt_client failed.\n"); fprintf(stderr, "%s: alloc pbt_client failed.\n", __func__); goto fail_alloc; } @@ -288,7 +288,7 @@ retry_start: &pbt_client_ops, pbt_client); if (pbt_client->discover_client || !i) break; - pb_log("%s: waiting for server %d\n", __func__, i); + pb_log_fn("waiting for server %d\n", i); sleep(1); } @@ -302,7 +302,7 @@ retry_start: if (!result) goto retry_start; - pb_log("%s: discover_client_init failed.\n", __func__); + pb_log_fn("discover_client_init failed.\n"); fprintf(stderr, "%s: error: discover_client_init failed.\n", __func__); fprintf(stderr, "could not start pb-discover, the petitboot " @@ -311,7 +311,7 @@ retry_start: } if (!pbt_client->discover_client) { - pb_log("%s: discover_client_init failed.\n", __func__); + pb_log_fn("discover_client_init failed.\n"); fprintf(stderr, "%s: error: discover_client_init failed.\n", __func__); fprintf(stderr, "check that pb-discover, " diff --git a/ui/twin/pbt-scr.c b/ui/twin/pbt-scr.c index e10cab1..c360047 100644 --- a/ui/twin/pbt-scr.c +++ b/ui/twin/pbt-scr.c @@ -138,7 +138,7 @@ twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen, raw_background = twin_jpeg_to_pixmap(filename, TWIN_ARGB32); if (!raw_background) { - pb_log("%s: loading image '%s' failed\n", __func__, filename); + pb_log_fn("loading image '%s' failed\n", filename); /* Fallback to a default pattern */ @@ -158,7 +158,7 @@ twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen, tscreen->width, tscreen->height); if (!scaled_background) { - pb_log("%s: scale '%s' failed\n", __func__, filename); + pb_log_fn("scale '%s' failed\n", filename); twin_pixmap_destroy(raw_background); return twin_make_pattern(); } @@ -224,7 +224,7 @@ retry: new.icon = twin_png_to_pixmap(filename, TWIN_ARGB32); if (!new.icon) { - pb_log("%s: loading image '%s' failed\n", __func__, filename); + pb_log_fn("loading image '%s' failed\n", filename); if (filename == default_icon_file) return NULL; @@ -384,7 +384,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, assert(backend && backend < 3); if (!scr) { - pb_log("%s: alloc pbt_scr failed.\n", __func__); + pb_log_fn("alloc pbt_scr failed.\n"); goto fail_alloc; } @@ -395,7 +395,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, scr->twin_ctx.backend = backend; if (backend == pbt_twin_x11) { - pb_log("%s: using twin x11 backend.\n", __func__); + pb_log_fn("using twin x11 backend.\n"); assert(width > 100); assert(height > 100); @@ -406,7 +406,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, width, height, 0); if (!scr->twin_ctx.x11) { - pb_log("%s: twin_x11_create_ext failed.\n", __func__); + pb_log_fn("twin_x11_create_ext failed.\n"); perror("failed to create twin x11 context\n"); goto fail_ctx_create; } @@ -418,14 +418,14 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, waiter_fd = ConnectionNumber(scr->twin_ctx.x11->dpy); #endif } else if (backend == pbt_twin_fbdev) { - pb_log("%s: using twin fbdev backend.\n", __func__); + pb_log_fn("using twin fbdev backend.\n"); #if !defined(HAVE_LIBTWIN_TWIN_FBDEV_H) assert(0); #else scr->twin_ctx.fbdev = twin_fbdev_create_ext(-1, SIGUSR1, 0); if (!scr->twin_ctx.fbdev) { - pb_log("%s: twin_fbdev_create_ext failed.\n", __func__); + pb_log_fn("twin_fbdev_create_ext failed.\n"); perror("failed to create twin fbdev context\n"); goto fail_ctx_create; } From patchwork Thu Aug 2 17:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHHJ4KgWz9s3q for ; Fri, 3 Aug 2018 03:29:48 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="KJ0vGq73"; 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 41hHHJ2qpTzF21T for ; Fri, 3 Aug 2018 03:29:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="KJ0vGq73"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="KJ0vGq73"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74S0xzF2Ct for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7eH6g2bwNZtOcNPz0RL965XLOJM9fVu1B4n4CMGuKe8=; b=KJ0vGq73EVEnGTS0mDY5LxR/6 JZMje1L9smhOKyHrBnrtjHAtgC2hz+JB/szvba7PRgLcoDqq3k4R6SYBHJZoQC+sqX8kM0GIhnTtQ zqnVQZLYPY8YYaxCm64sWQWgDvr8SxGcTdRULWpVBBRQOvIzJUYubyvLGJ0F7/Pwt8KfD7qXnn2Gv LQuKC1H3+PCOrsmaaXncqUreJVNviHdG5Yn34MZfBKcLw4FlGIC5qdKWfJ4kqgJwXGAJRin+tR3xp RGqI5ZCYd6PFMXbw07gzn75uzZecOILjxYZH0OuKOGIDiCmL6Vpa6FWzlbCydBKDR5F5nJTOiBc13 gfMYKtqMg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPq-0007Wd-97; Thu, 02 Aug 2018 17:29:34 +0000 Message-Id: <7ca198d87bd13d441627ca6789fd198da33c168f.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 06/30] discover: Add --debug to kexec To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:34 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" If verbose logging is enabled then add '--debug' to the kexec command line. Adds a new routine pb_log_get_debug() that can be used to query the log debug state. Signed-off-by: Geoff Levand --- discover/boot.c | 16 ++++++++++------ lib/log/log.c | 5 +++++ lib/log/log.h | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/discover/boot.c b/discover/boot.c index 7faec9f..3de7d28 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -62,7 +62,7 @@ static int kexec_load(struct boot_task *boot_task) struct process *process; char *s_initrd = NULL; char *s_args = NULL; - const char *argv[7]; + const char *argv[8]; char *s_dtb = NULL; const char **p; int result; @@ -107,27 +107,31 @@ static int kexec_load(struct boot_task *boot_task) *p++ = pb_system_apps.kexec; /* 1 */ *p++ = "-l"; /* 2 */ + if (pb_log_get_debug()) { + *p++ = "--debug"; /* 3 */ + } + if (local_initrd) { s_initrd = talloc_asprintf(boot_task, "--initrd=%s", local_initrd); assert(s_initrd); - *p++ = s_initrd; /* 3 */ + *p++ = s_initrd; /* 4 */ } if (local_dtb) { s_dtb = talloc_asprintf(boot_task, "--dtb=%s", local_dtb); assert(s_dtb); - *p++ = s_dtb; /* 4 */ + *p++ = s_dtb; /* 5 */ } s_args = talloc_asprintf(boot_task, "--append=%s", boot_task->args ?: "\"\""); assert(s_args); - *p++ = s_args; /* 5 */ + *p++ = s_args; /* 6 */ - *p++ = local_image; /* 6 */ - *p++ = NULL; /* 7 */ + *p++ = local_image; /* 7 */ + *p++ = NULL; /* 8 */ result = process_run_sync(process); if (result) { diff --git a/lib/log/log.c b/lib/log/log.c index 0b145e0..5466d81 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -88,6 +88,11 @@ void pb_log_set_debug(bool _debug) debug = _debug; } +bool pb_log_get_debug(void) +{ + return debug; +} + FILE *pb_log_get_stream(void) { static FILE *null_stream; diff --git a/lib/log/log.h b/lib/log/log.h index 2d4fd91..c2ad58e 100644 --- a/lib/log/log.h +++ b/lib/log/log.h @@ -26,6 +26,7 @@ void __pb_log_init(FILE *stream, bool debug); #endif void pb_log_set_debug(bool debug); +bool pb_log_get_debug(void); FILE *pb_log_get_stream(void); #endif /* _LOG_H */ From patchwork Thu Aug 2 17:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952908 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJk0S2tz9s2g for ; Fri, 3 Aug 2018 03:31:02 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="NRAAsT+D"; 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 41hHJj6442zF27J for ; Fri, 3 Aug 2018 03:31:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="NRAAsT+D"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="NRAAsT+D"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH73PhczF27G for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mfWaTp0gd1w43MwYk+HFmjfPh0AVJ/0FyjhNwg3ykrw=; b=NRAAsT+DNLZ9jcISOcfYowpIk drt5NAMi4SrUm9vlXY+UaExA7y77+/XSP8qc4N3it+r6dRNYN+IWwCPy8gMaChyvkV7GevTo/OKXx dCcnws77t5UfucP1LHn9zc6XsXAZ4VjpoJ7k6PknyFchJyJmDnevQJZf4hGUAhxwejytANs1k0Exm kfZdD2Ch7PNmczdehg69J70mYcHJopfAoWZuG3A8geEbxBdgucGbzT3TJpho4JBBrekQDBx7tTlIc bkPbN6nI0bDabnIOelRbgwerwg6G9qkOk3iss8se3t2N//Qwm2qfV97N9lQvVBtqvtX5QpMfCcCrK PKefuMeGQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPq-0007Wh-EM; Thu, 02 Aug 2018 17:29:34 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 07/30] discover/kboot-parser: Look in /boot To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:34 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Other parsers look in /boot for config files, so add it to the kboot parser. Signed-off-by: Geoff Levand --- discover/kboot-parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index bf9c5eb..62512cf 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -145,10 +145,14 @@ static const char *const kboot_conf_files[] = { "/kboot.cnf", "/etc/kboot.conf", "/etc/kboot.cnf", + "/boot/kboot.conf", + "/boot/kboot.cnf", "/KBOOT.CONF", "/KBOOT.CNF", "/ETC/KBOOT.CONF", "/ETC/KBOOT.CNF", + "/BOOT/KBOOT.CONF", + "/BOOT/KBOOT.CNF", NULL }; From patchwork Thu Aug 2 17:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHHw0JXzz9s2g for ; Fri, 3 Aug 2018 03:30:20 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cUCeCJ6W"; 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 41hHHv3SBlzF2DP for ; Fri, 3 Aug 2018 03:30:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cUCeCJ6W"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cUCeCJ6W"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH70VkjzF21T for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=R6ZMUPnvGTtKF7l4KwTK5uAzzWz9EW2fA3VyL5VGiTM=; b=cUCeCJ6WqUG/CjqdCW+hgsx23 Tel+X9wgjwKNZZFr3+6gUHce3BZdVall+316tH5P+tkgr8EsPFBMgy/AaI3OI3HjWqn5F3YzyL+CZ 0evihtIE6vrx+Cj4aHHuZzSSOJ7HB3gK1PDNaGYDy+aeAE0RI+XRDrTd+9QrF7OOGFsH8tbLMt5qs wQwqFS7OuC15NtJukWwxi904ymBwt95Tz+r5BxgLhrzGRqfneAEFpDds8AUFNiXa8X8TENgh12eIo EvwHjN81H013admQnIVSYNHAZIsyirgVJdn17XfE/Q3TOi4saQWA1jp0RUkBGwalI4lpADQYU88xS SyCYGMhyw==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPq-0007Wz-L6; Thu, 02 Aug 2018 17:29:34 +0000 Message-Id: <070c0dda4ceb08f26f97445b17332726ef2ceeaf.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 08/30] discover: Add some debug print messages To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:34 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" To aid in debugging print some additinal discover messages to the log. Signed-off-by: Geoff Levand --- discover/device-handler.c | 1 + discover/platform.c | 1 + 2 files changed, 2 insertions(+) diff --git a/discover/device-handler.c b/discover/device-handler.c index 1299c33..9c05029 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -522,6 +522,7 @@ void device_handler_remove(struct device_handler *handler, void device_handler_status(struct device_handler *handler, struct status *status) { + pb_debug("%s: %s\n", __func__, status->message); discover_server_notify_boot_status(handler->server, status); } diff --git a/discover/platform.c b/discover/platform.c index cc6306f..e69c6f6 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -166,6 +166,7 @@ int platform_init(void *ctx) platform_ctx = talloc_new(ctx); for (p = &__start_platforms; p < &__stop_platforms; p++) { + pb_debug("%s: Try platform %s\n", __func__, (*p)->name); if (!(*p)->probe(*p, platform_ctx)) continue; platform = *p; From patchwork Thu Aug 2 17:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJP5c5Qz9s2g for ; Fri, 3 Aug 2018 03:30:45 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="owotSWcD"; 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 41hHJP3nkTzF27J for ; Fri, 3 Aug 2018 03:30:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="owotSWcD"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="owotSWcD"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74PwNzF27J for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VGIEnp5XDzPHJgMUAa4dbpujvhsctu83QYSacgpp5Jg=; b=owotSWcDHyodw0vQkjpZXwPf7 Z8NUzFcS1XCve56/OqHndzAgTo0snf2nyHC4+rO3JY3xlDLapAx/qluGSd8b8LFbJH62wrHlvNT4D r9QZ9PJq8Xif/FMIlbbHlnTixvsjaRbh532r6YZ4dVqrXzGiTZbLjPQjTXWJWwDlnlQoRWX55B909 Q5cQcqJk3Wsqiqf+DLxcA5JTeNqlX0eLWvqzsXx+anGOIR2r7qBccQYyYZch9p6w1XtuBMdFBpYdr Ps4KyRpwcNt4Tx5QWOIj5YK5wkFbszmjrEwJuqCAQj/pozQ2ZLYyXtifm5lWkRo/NvOFbs6dftzri fMTEjGIcg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPq-0007XL-SV; Thu, 02 Aug 2018 17:29:34 +0000 Message-Id: <570e68fb79e324e3db3fb00bc6b47e1a5b2b3ce3.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 09/30] discover/parser: Add new parser_is_unique To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:34 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a new routine parser_is_unique that tests a file's inode against a list of known file inodes. Useful when searching case-insensitive filesystems. Signed-off-by: Geoff Levand --- discover/parser.c | 30 ++++++++++++++++++++++++++++++ discover/parser.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/discover/parser.c b/discover/parser.c index 9fe1925..5478720 100644 --- a/discover/parser.c +++ b/discover/parser.c @@ -73,6 +73,36 @@ out: return rc; } +bool parser_is_unique(struct discover_context *ctx, struct discover_device *dev, + const char *filename, struct list *found_list) +{ + struct stat stat; + struct parser_found_file *found_file; + const struct parser_found_file *entry; + + if (parser_stat_path(ctx, dev, filename, &stat)) { + pb_debug("%s: Not found: '%s'\n", __func__, filename); + return false; + } + + list_for_each_entry(found_list, entry, list) { + if (entry->ino == stat.st_ino) { + pb_log("%s: Duplicate: '%s' = '%s'\n", + __func__, filename, entry->filename); + return false; + } + } + + pb_debug("%s: Found: '%s'\n", __func__, filename); + + found_file = talloc_zero(found_list, struct parser_found_file); + found_file->filename = talloc_strdup(found_file, filename); + found_file->ino = stat.st_ino; + list_add(found_list, &found_file->list); + + return true; +} + int parser_replace_file(struct discover_context *ctx, struct discover_device *dev, const char *filename, char *buf, int len) diff --git a/discover/parser.h b/discover/parser.h index bff52e3..e7d52fe 100644 --- a/discover/parser.h +++ b/discover/parser.h @@ -45,6 +45,12 @@ enum generic_icon_type { ICON_TYPE_UNKNOWN }; +struct parser_found_file { + const char *filename; + unsigned ino; + struct list_item list; +}; + #define streq(a,b) (!strcasecmp((a),(b))) void parser_init(void); @@ -85,4 +91,12 @@ int parser_scandir(struct discover_context *ctx, const char *dirname, struct dirent ***files, int (*filter)(const struct dirent *), int (*comp)(const struct dirent **, const struct dirent **)); +/* parser_is_unique - Test a file against a list of known files. + * If the file @filename exists and the file is not in @found_list add the + * file to @found_list and return true. Use when searching case-insensitive + * filesystems. + */ +bool parser_is_unique(struct discover_context *ctx, struct discover_device *dev, const char *filename, + struct list *found_list); + #endif /* _PARSER_H */ From patchwork Thu Aug 2 17:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952915 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKv0cw7z9s2g for ; Fri, 3 Aug 2018 03:32:03 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LRE55tK9"; 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 41hHKt6HKrzF2DN for ; Fri, 3 Aug 2018 03:32:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LRE55tK9"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LRE55tK9"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH73mzbzF27H for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5wZ60ZCl/YTR/WGzs4cRraVtCH59FCa5gVMDzSco26w=; b=LRE55tK99o9XOWn+OWDNWkPUi CHmFHXI41GNR4uZH2IFBfYbhCvz1f4BaA/p4WBdUdI0c8k8oKEFlp8WNOh7ChcQ9cSXSnwOsz10C3 9pWff36SLytSYGMntKywTh4g3Z77+Lmk5p7BvRNjhkMLklz6dLgaOGa86XUCwEis39emwgDNcnPdy qPOF3a54zX2Xvl6EO1A+6F+ZqLPBE1zSQQ8CHi84/b2z0dqXfie3n7FvGwLrGCpqjE8LCD5vnUi9I ElMu2MUHJ9eO68icnHucgHVeigB+OFt2pydykv4ycz/OcIOFPJ62PGl1XzyYZDeoKTUOMnZoT0hq1 RZxiutdgQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPr-0007XT-49; Thu, 02 Aug 2018 17:29:35 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 10/30] test/parser: Add parser_is_unique To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:35 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- test/parser/utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/parser/utils.c b/test/parser/utils.c index c6d1a17..d8499a4 100644 --- a/test/parser/utils.c +++ b/test/parser/utils.c @@ -371,6 +371,18 @@ err_cleanup: return -1; } +bool parser_is_unique(struct discover_context *ctx, struct discover_device *dev, + const char *filename, struct list *found_list) +{ + (void)ctx; + (void)dev; + (void)filename; + (void)found_list; + + /* Just let the parser process everything. */ + return true; +} + struct load_url_result *load_url_async(void *ctx, struct pb_url *url, load_url_complete async_cb, void *async_data, waiter_cb stdout_cb, void *stdout_data) From patchwork Thu Aug 2 17:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952910 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHK43YB4z9s4c for ; Fri, 3 Aug 2018 03:31:20 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LH0WGlsr"; 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 41hHK422sKzF2D9 for ; Fri, 3 Aug 2018 03:31:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LH0WGlsr"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LH0WGlsr"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH72z9NzF277 for ; Fri, 3 Aug 2018 03:29:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S8X5T6Si/IAKrr54mPC4o0AzHX7Jm3HSEkwtFSL00WQ=; b=LH0WGlsrOanut9OKBJzSqpduT neKjHP1cqHlVLxHo1JzZfDwE0bOg6yj28vC6sLyvHqG/9Xr7JjMqtSSJTb4p2rm3Zt8SkAW6mw4Cw rDaUvMW8T+m5H9zGJjnkdIhDf/SPvmI52DiALOk1m8dmTBKnfc1yH3GyD4kM1lBDvNmmqbOS7wcSn FHod+wf3flwsQmigz5p+tn9z18I6GMadX9He9bMuNU9ve67IxCVoCHu47AwN8L6gaU9xmfHiVQQcb Mfy7Hc9CwwO5BLdu74AOwh9hCbM3PDK54okZCH0Rm6gkqpy00+BeoP1x80z5Ypjzz1wuj/hJ8foBU ZxdRMbPaA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPr-0007Xb-D9; Thu, 02 Aug 2018 17:29:35 +0000 Message-Id: <854b24277967df533cf753b02975e464fae51406.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 11/30] discover/parser: Hookup parser_is_unique To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:35 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- discover/kboot-parser.c | 15 ++++++++++++--- discover/syslinux-parser.c | 47 +++++++++++----------------------------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index 62512cf..e4b36b6 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -167,19 +167,22 @@ static const char *const kboot_ignored_names[] = { static int kboot_parse(struct discover_context *dc) { struct conf_context *conf; + struct list *found_list; const char * const *filename; - char *buf; - int len, rc; /* Support block device boot only at present */ if (dc->event) return -1; conf = talloc_zero(dc, struct conf_context); - if (!conf) return -1; + found_list = talloc(conf, struct list); + if (!found_list) + return -1; + list_init(found_list); + conf->dc = dc; conf->global_options = kboot_global_options, conf_init_global_options(conf); @@ -188,6 +191,12 @@ static int kboot_parse(struct discover_context *dc) conf->parser_info = (void *)kboot_ignored_names; for (filename = kboot_conf_files; *filename; filename++) { + int len, rc; + char *buf; + + if (!parser_is_unique(dc, dc->device, *filename, found_list)) + continue; + rc = parser_request_file(dc, dc->device, *filename, &buf, &len); if (rc) continue; diff --git a/discover/syslinux-parser.c b/discover/syslinux-parser.c index defafd2..38cfd1d 100644 --- a/discover/syslinux-parser.c +++ b/discover/syslinux-parser.c @@ -36,12 +36,6 @@ struct syslinux_options { char *cfg_dir; }; -struct conf_file_stat { - char *name; - struct stat stat; - struct list_item list; -}; - static const char *const syslinux_conf_files[] = { "/boot/syslinux/syslinux.cfg", "/syslinux/syslinux.cfg", @@ -424,25 +418,24 @@ fail: static int syslinux_parse(struct discover_context *dc) { - struct conf_file_stat *confcmp, *confdat; - struct list processed_conf_files; struct syslinux_options *state; const char * const *filename; struct conf_context *conf; - struct stat statbuf; - char *cfg_dir; - int len, rc; - char *buf; + struct list *found_list; /* Support block device boot only at present */ if (dc->event) return -1; conf = talloc_zero(dc, struct conf_context); - if (!conf) return -1; + found_list = talloc(conf, struct list); + if (!found_list) + return -1; + list_init(found_list); + conf->dc = dc; conf->global_options = syslinux_global_options, conf_init_global_options(conf); @@ -452,8 +445,6 @@ static int syslinux_parse(struct discover_context *dc) conf->parser_info = state = talloc_zero(conf, struct syslinux_options); list_init(&state->processed_options); - list_init(&processed_conf_files); - /* * set the global defaults * by spec 'default' defaults to 'linux' and @@ -463,37 +454,21 @@ static int syslinux_parse(struct discover_context *dc) conf_set_global_option(conf, "implicit", "1"); for (filename = syslinux_conf_files; *filename; filename++) { + char *cfg_dir; + int len, rc; + char *buf; + /* * guard against duplicate entries in case-insensitive * filesystems, mainly vfat boot partitions */ - rc = parser_stat_path(dc, dc->device, *filename, &statbuf); - if (rc) - continue; - - rc = 0; - - list_for_each_entry(&processed_conf_files, confcmp, list) { - if (confcmp->stat.st_ino == statbuf.st_ino) { - pb_log("conf file %s is a path duplicate of %s..skipping\n", - *filename, confcmp->name); - rc = 1; - break; - } - } - - if (rc) + if (!parser_is_unique(dc, dc->device, *filename, found_list)) continue; rc = parser_request_file(dc, dc->device, *filename, &buf, &len); if (rc) continue; - confdat = talloc_zero(conf, struct conf_file_stat); - confdat->stat = statbuf; - confdat->name = talloc_strdup(confdat, *filename); - list_add(&processed_conf_files, &confdat->list); - /* * save location of root config file for possible * INCLUDE directives later From patchwork Thu Aug 2 17:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952911 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKC4xwQz9s2g for ; Fri, 3 Aug 2018 03:31:27 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; 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 41hHKC3THJzF2DN for ; Fri, 3 Aug 2018 03:31:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74zhczF2D4 for ; Fri, 3 Aug 2018 03:29:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aqBzsM/xa9xn9TGIuw10hac4EqrhkGbteLU3RuzLpHk=; b=PlvLOkXgyybmH0AQunhsha9An LAsXU0Xs/20v3+M+l3Haj1g5Uo/hZXd9qtkyYZ3ZCo5mAd2Q+Za2+Ob5NoRiKpgGDFvv0Lk1S5lM7 gE1vxgu3Z+aVSx3JB2GHT7EiFcvyv3jKTBcphzccrffn2BZMnLAfwLVRlKge34cYWtbjh+9rQxXNG BuGudLnzVlGZCLO+/ekAHqF7u27OD9mCYphkho3ye1BiG03e73VrWmSnaMdX49n5A4NVi4EH+EUUO mQE86FYYosCy8HzwY6JHN1F/O2cLA1XkTikQooZudbS7AdpKtpeM2Bzicn6IrtW1TqmROrFdvmeT1 wN7X3obOA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPr-0007Xj-LI; Thu, 02 Aug 2018 17:29:35 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 12/30] lib/process: Cleanup stdout callback To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:35 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" General cleanup of async stdout processing. The process_stdout_cb and process_stdout_custom routines were doing the same thing, so rename process_stdout_custom to process_process_stdout and make process_stdout_cb a wrapper that calls process_process_stdout. Signed-off-by: Geoff Levand --- discover/paths.c | 2 +- lib/process/process.c | 32 ++++++++------------------------ lib/process/process.h | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/discover/paths.c b/discover/paths.c index 174bdae..dc654bd 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -158,7 +158,7 @@ static int busybox_progress_cb(void *arg) p = procinfo_get_process(procinfo); handler = p->stdout_data; - rc = process_stdout_custom(procinfo, &line); + rc = process_process_stdout(procinfo, &line); if (rc) { /* Unregister ourselves from progress tracking */ diff --git a/lib/process/process.c b/lib/process/process.c index 1fa0bb0..bc392dc 100644 --- a/lib/process/process.c +++ b/lib/process/process.c @@ -178,28 +178,7 @@ static int process_read_stdout(struct process_info *procinfo) return rc < 0 ? rc : 0; } -static int process_stdout_cb(void *arg) -{ - struct process_info *procinfo = arg; - int rc; - - rc = process_read_stdout_once(procinfo, NULL); - - /* if we're going to signal to the waitset that we're done (ie, non-zero - * return value), then the waiters will remove us, so we drop the - * reference */ - if (rc < 0) { - talloc_unlink(procset, procinfo); - procinfo->stdout_waiter = NULL; - rc = -1; - } else { - rc = 0; - } - - return rc; -} - -int process_stdout_custom(struct process_info *procinfo, char **line) +int process_process_stdout(struct process_info *procinfo, char **line) { int rc; @@ -417,10 +396,14 @@ int process_run_sync(struct process *process) return 0; } +static int process_stdout_cb(struct process_info *procinfo) +{ + return process_process_stdout(procinfo, NULL); +} + int process_run_async(struct process *process) { struct process_info *procinfo = get_info(process); - waiter_cb stdout_cb; int rc; rc = process_run_common(procinfo); @@ -428,7 +411,8 @@ int process_run_async(struct process *process) return rc; if (process->keep_stdout) { - stdout_cb = process->stdout_cb ?: process_stdout_cb; + waiter_cb stdout_cb = process->stdout_cb ?: + (waiter_cb)process_stdout_cb; procinfo->stdout_waiter = waiter_register_io(procset->waitset, procinfo->stdout_pipe[0], WAIT_IN, stdout_cb, procinfo); diff --git a/lib/process/process.h b/lib/process/process.h index 4904ffc..003ff8e 100644 --- a/lib/process/process.h +++ b/lib/process/process.h @@ -87,6 +87,6 @@ bool process_exit_ok(struct process *process); /* Functions to assist callers using a custom stdout callback */ struct process *procinfo_get_process(struct process_info *procinfo); -int process_stdout_custom(struct process_info *procinfo, char **line); +int process_process_stdout(struct process_info *procinfo, char **line); #endif /* PROCESS_H */ From patchwork Thu Aug 2 17:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJG2yZtz9s2g for ; Fri, 3 Aug 2018 03:30:38 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="v2oAcN/B"; 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 41hHJG1RYjzF277 for ; Fri, 3 Aug 2018 03:30:38 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="v2oAcN/B"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="v2oAcN/B"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH75c0lzF2DB for ; Fri, 3 Aug 2018 03:29:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g3cbieJr9ppaMh850AWS9WGcLTyN2v3uibOBcLxmPBs=; b=v2oAcN/BkB/dHEgrdeeiar24O Vqiqq7iFHEi2ZvxqDwOyMlJ9l9pVBXk70G+fayLnyDv8yezQzdgIKq1qDVCHbiVONi8kunKKvV4SL jabm5TeJrEnzzD7rg+QEC6iCFIvhrB6r3a4kAdqqvBGetaM26x8ZTpTwvbe9R4fRtFM8OwKYobI13 6iP88H6xROaeQp7xsXYLlobRb+8O80hWPxs4WwuR17vtfV3yv+hH3aWv503bd09HMO1LuiW1chnbK MY/Fr6KqET5rUnQt3S8f9VhsuA5gDthgPwyAIpCbpNA+79mV8Ktofpu/WkJHDq7/+AmALGv+l15wk 6ZcPy6YlQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPr-0007Xr-VI; Thu, 02 Aug 2018 17:29:36 +0000 Message-Id: <70923aafdbe947471df91b4e920c9f2b94033e1e.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 13/30] lib/process: Add process_get_stdout To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:35 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a new structure 'struct process_stdout' and optional parameter 'stdout' to the process_run_simple functions to allow the caller to get a buffer filled with the stdout from the child process. Rename the process_run_simple functions to process_get_stdout and add wrappers for the old process_run_simple function names. Signed-off-by: Geoff Levand --- lib/process/process.c | 54 ++++++++++++++++++++++++++++++++++++++------------- lib/process/process.h | 26 ++++++++++++++++++++----- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/lib/process/process.c b/lib/process/process.c index bc392dc..02b6f49 100644 --- a/lib/process/process.c +++ b/lib/process/process.c @@ -452,48 +452,76 @@ void process_stop_async_all(void) } } -int process_run_simple_argv(void *ctx, const char *argv[]) +int process_get_stdout_argv(void *ctx, struct process_stdout **stdout, + const char *argv[]) { - struct process *process; + struct process *p; int rc; - process = process_create(ctx); + p = process_create(NULL); + p->path = argv[0]; + p->argv = argv; - process->path = argv[0]; - process->argv = argv; + if (stdout) { + p->keep_stdout = true; + *stdout = NULL; + } - rc = process_run_sync(process); + rc = process_run_sync(p); if (!rc) - rc = process->exit_status; + rc = p->exit_status; + else { + pb_debug("%s: process_run_sync failed: %s.\n", __func__, + p->path); + if (stdout) + pb_debug("%s: stdout: %s\n\n", __func__, p->stdout_buf); + goto exit; + } + + if (!stdout) + goto exit; + + *stdout = talloc(ctx, struct process_stdout); + + if (!*stdout) { + rc = -1; + goto exit; + } - process_release(process); + (*stdout)->len = p->stdout_len; + (*stdout)->buf = talloc_memdup(*stdout, p->stdout_buf, + p->stdout_len + 1); + (*stdout)->buf[p->stdout_len] = 0; +exit: + process_release(p); return rc; } -int process_run_simple(void *ctx, const char *name, ...) +int process_get_stdout(void *ctx, struct process_stdout **stdout, + const char *path, ...) { int rc, i, n_argv = 1; const char **argv; va_list ap; - va_start(ap, name); + va_start(ap, path); while (va_arg(ap, char *)) n_argv++; va_end(ap); argv = talloc_array(ctx, const char *, n_argv + 1); - argv[0] = name; + argv[0] = path; - va_start(ap, name); + va_start(ap, path); for (i = 1; i < n_argv; i++) argv[i] = va_arg(ap, const char *); va_end(ap); argv[i] = NULL; - rc = process_run_simple_argv(ctx, argv); + rc = process_get_stdout_argv(ctx, stdout, argv); talloc_free(argv); diff --git a/lib/process/process.h b/lib/process/process.h index 003ff8e..9473a0d 100644 --- a/lib/process/process.h +++ b/lib/process/process.h @@ -27,6 +27,11 @@ struct process_info; typedef void (*process_exit_cb)(struct process *); +struct process_stdout { + size_t len; + char *buf; +}; + struct process { /* caller-provided configuration */ const char *path; @@ -63,13 +68,24 @@ struct process *process_create(void *ctx); */ void process_release(struct process *process); -/* Synchronous interface. These functions will all block while waiting for - * the process to exit. +/* Synchronous interface. The process_run_sync, process_run_simple and + * process_get_stdout functions will all block while waiting for the child + * process to exit. Calls to the variadic versions must have a NULL terminating + * argument. For the process_get_stdout calls stderr will go to the log. */ int process_run_sync(struct process *process); -int process_run_simple_argv(void *ctx, const char *argv[]); -int process_run_simple(void *ctx, const char *name, ...) - __attribute__((sentinel(0))); +int process_get_stdout_argv(void *ctx, struct process_stdout **stdout, + const char *argv[]); +int process_get_stdout(void *ctx, struct process_stdout **stdout, + const char *path, ...) __attribute__((sentinel(0))); + +static inline int process_run_simple_argv(void *ctx, const char *argv[]) +{ + return process_get_stdout_argv(ctx, NULL, argv); +} +#define process_run_simple(_ctx, _path, args...) \ + process_get_stdout(_ctx, NULL, _path, args) + /* Asynchronous interface. When a process is run with process_run_async, the * function returns without wait()ing for the child process to exit. If the From patchwork Thu Aug 2 17:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKk1MMPz9s2g for ; Fri, 3 Aug 2018 03:31:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cVHtQ3S8"; 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 41hHKj6p9bzF27G for ; Fri, 3 Aug 2018 03:31:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cVHtQ3S8"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="cVHtQ3S8"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH76HXKzF2DC for ; Fri, 3 Aug 2018 03:29:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=J7p6rnL9eiBMYVO4+Nm+wVD1Jzwiuhv9c7EsI3uMKSo=; b=cVHtQ3S88s7UQJmgLd4uEbcJy ORVj6RmCYN41kxYMK1Bo96C4bcih+ARFkBDz50aZ/BpziZxDIGwwxJmuelpP9HMKlcQORSjNqHrlE YBo+ZCdFzRzVYZTB+D/+7qRuLqD4k5JqTWqWs08HfYUJLQBxyUeXIvElu27hAaUUOM/PBh256Yr3n V1wjjWJNRDUesIbg5MCIcYi0ha+Vn5cgChddM3WGN6/HED33/yLzKnbprTUmFQwhdQ1nd29Wajzmx izjVAPqFvn4xDe7JWU/4Gnpa2h2FUJwsWCmJu5/oVGisXhS7EYBBdyYtbAY3D9pP4cVy0RKHHndl1 ftyLgsuwg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPs-0007Xz-8E; Thu, 02 Aug 2018 17:29:36 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 14/30] discover/powerpc: Use process_get_stdout To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:36 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 22d213d..2ee376d 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -148,7 +148,7 @@ static int parse_nvram_params(struct platform_powerpc *platform, static int parse_nvram(struct platform_powerpc *platform) { - struct process *process; + struct process_stdout *stdout; const char *argv[5]; int rc; @@ -158,23 +158,17 @@ static int parse_nvram(struct platform_powerpc *platform) argv[3] = partition; argv[4] = NULL; - process = process_create(platform); - process->path = "nvram"; - process->argv = argv; - process->keep_stdout = true; + rc = process_get_stdout_argv(NULL, &stdout, argv); - rc = process_run_sync(process); - - if (rc || !process_exit_ok(process)) { + if (rc) { fprintf(stderr, "nvram process returned " "non-zero exit status\n"); rc = -1; } else { - rc = parse_nvram_params(platform, process->stdout_buf, - process->stdout_len); + rc = parse_nvram_params(platform, stdout->buf, stdout->len); } - process_release(process); + talloc_free(stdout); return rc; } From patchwork Thu Aug 2 17:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952904 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJ51yYKz9s3q for ; Fri, 3 Aug 2018 03:30:29 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ggEmVzAT"; 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 41hHJ42gHZzF2DG for ; Fri, 3 Aug 2018 03:30:28 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ggEmVzAT"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ggEmVzAT"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH81djtzF2DD for ; Fri, 3 Aug 2018 03:29:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Evay5XhiSYHFkC4KwWT2mCLpPg/WV7ttQiEEFLpyVpk=; b=ggEmVzATDHMoWUFcKLNV1vkli 05W9fG+Z6IO6MF1XGKhVxtxX7w0Mn9Id+74cokPp/jkkYjXuibWde6SqgBsDQ+6CC2v0xV5W4wo6L NxTulWn73CjDZg8popVF8E+tm34ZUJ7XOgHVlBouF6A+rDBsHHw9BSvQRL2OOIOeMce//mY3AkBf+ +3WcYGOR1QjChDvW+LLpDBJ3bakJggBI5tlHSdSUD7g1R2tFgvcPDRDcD0kG2jAWx7KtVJDvMf1uJ k6o89uKlXx5NLIBxpwF0ByyMerB7PZyAHod6Vcr5q0kgJKkEh3GgjUAvHtT5spqETKYgA6h2r1Qea e2bdXOfIA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPs-0007Y7-Hc; Thu, 02 Aug 2018 17:29:36 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 15/30] lib/efi: Add new routines to access efi variables To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:36 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Provide methods to load/store petitboot's configuration on efi-based platforms. A test case is also provided. Signed-off-by: Ge Song [Cleanup file comments, make efivarfs_path static.] Signed-off-by: Geoff Levand --- lib/Makefile.am | 4 +- lib/efi/efivar.c | 191 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/efi/efivar.h | 46 ++++++++++++ test/lib/test-efivar.c | 127 ++++++++++++++++++++++++++++++++ 4 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 lib/efi/efivar.c create mode 100644 lib/efi/efivar.h create mode 100644 test/lib/test-efivar.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 0088e0b..59d37ab 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -65,7 +65,9 @@ lib_libpbcore_la_SOURCES = \ lib/util/util.h \ lib/flash/config.h \ lib/flash/flash.h \ - lib/security/security.h + lib/security/security.h \ + lib/efi/efivar.h \ + lib/efi/efivar.c if ENABLE_MTD lib_libpbcore_la_SOURCES += \ diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c new file mode 100644 index 0000000..1ac6990 --- /dev/null +++ b/lib/efi/efivar.c @@ -0,0 +1,191 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights + * reserved. + * Author: Ge Song + */ + +#include +#include +#include +#include + +#include +#include + +#include "efivar.h" +#include "log/log.h" +#include "talloc/talloc.h" + +static const char *efivarfs_path; + +inline void set_efivarfs_path(const char *path) +{ + efivarfs_path = path; +} + +inline const char *get_efivarfs_path(void) +{ + + return efivarfs_path; +} + +int efi_del_variable(void *ctx, const char *guidstr, + const char *name) +{ + int fd, flag, errno_value; + int rc = -1; + const char *dir; + char *path; + + dir = get_efivarfs_path(); + if (!dir) + return -1; + + path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); + if (!path) + return -1; + + fd = open(path, O_RDONLY|O_NONBLOCK); + if (fd == -1) + goto err; + + rc = ioctl(fd, FS_IOC_GETFLAGS, &flag); + if (rc == -1) + goto err; + + flag &= ~FS_IMMUTABLE_FL; + rc = ioctl(fd, FS_IOC_SETFLAGS, &flag); + if (rc == -1) + goto err; + + close(fd); + rc = unlink(path); + +err: + errno_value = errno; + if (fd > 0) + close(fd); + + errno = errno_value; + return rc; +} + +int efi_get_variable(void *ctx, const char *guidstr, const char *name, + uint8_t **data, size_t *data_size, uint32_t *attributes) +{ + int fd, errno_value; + int rc = -1; + void *p, *buf; + size_t bufsize = 4096; + size_t filesize = 0; + ssize_t sz; + const char *dir; + char *path; + + dir = get_efivarfs_path(); + if (!dir) + return EFAULT; + + path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); + if (!path) + return ENOMEM; + + fd = open(path, O_RDONLY|O_NONBLOCK); + if (fd < 0) + goto err; + + buf = talloc_size(ctx, bufsize); + if (!buf) + goto err; + + do { + p = buf + filesize; + sz = read(fd, p, bufsize); + if (sz < 0 && errno == EAGAIN) { + continue; + } else if (sz == 0) { + break; + } + filesize += sz; + } while (1); + + *attributes = *(uint32_t *)buf; + *data = (uint8_t *)(buf + sizeof(uint32_t)); + *data_size = strlen(buf + sizeof(uint32_t)); + rc = 0; + +err: + errno_value = errno; + if (fd > 0) + close(fd); + + errno = errno_value; + return rc; +} + +int efi_set_variable(void *ctx, const char *guidstr, const char *name, + uint8_t *data, size_t data_size, uint32_t attributes) +{ + int rc = -1, errno_value; + int fd = -1; + ssize_t len; + const char *dir; + char *path; + void *buf; + size_t bufsize; + mode_t mask = 0644; + + dir = get_efivarfs_path(); + if (!dir) + return EFAULT; + + path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); + if (!path) + return ENOMEM; + + if (!access(path, F_OK)) { + rc = efi_del_variable(ctx, guidstr, name); + if (rc < 0) { + goto err; + } + } + + fd = open(path, O_CREAT|O_WRONLY, mask); + if (fd < 0) + goto err; + + bufsize = sizeof(uint32_t) + data_size; + buf = talloc_size(ctx, bufsize); + if (!buf) + goto err; + + *(uint32_t *)buf = attributes; + memcpy(buf + sizeof(uint32_t), data, data_size); + + len = write(fd, buf, bufsize); + if ((size_t)len != bufsize) + goto err; + else + rc = 0; + +err: + errno_value = errno; + if (fd > 0) + close(fd); + + errno = errno_value; + return rc; +} diff --git a/lib/efi/efivar.h b/lib/efi/efivar.h new file mode 100644 index 0000000..ebf73fa --- /dev/null +++ b/lib/efi/efivar.h @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights + * reserved. + * Author: Ge Song + */ +#ifndef EFIVAR_H +#define EFIVAR_H + +#include +#include + +#define EFI_VARIABLE_NON_VOLATILE 0x00000001 +#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 +#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 +#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008 +#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010 +#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020 +#define EFI_VARIABLE_APPEND_WRITE 0x00000040 + +#ifndef EFIVARFS_MAGIC +#define EFIVARFS_MAGIC 0xde5e81e4 +#endif + +void set_efivarfs_path(const char *path); +const char *get_efivarfs_path(void); + +int efi_get_variable(void *ctx, const char *guidstr, const char *name, + uint8_t **data, size_t *data_size, uint32_t *attributes); +int efi_set_variable(void *ctx, const char *guidstr, const char *name, + uint8_t *data, size_t data_size, uint32_t attributes); +int efi_del_variable(void *ctx, const char *guidstr, const char *name); + +#endif /* EFIVAR_H */ diff --git a/test/lib/test-efivar.c b/test/lib/test-efivar.c new file mode 100644 index 0000000..8ceb8f5 --- /dev/null +++ b/test/lib/test-efivar.c @@ -0,0 +1,127 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights + * reserved. + * Author: Ge Song + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "efi/efivar.h" +#include "talloc/talloc.h" + +#define DEF_ATTR (EFI_VARIABLE_NON_VOLATILE | \ + EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS) + +static const char *test_efivar_guid = "c9c07add-256e-4452-b911-f8d0d35a1ac7"; +static const char *test_varname = "efivartest"; +static const char *test_data = "petitboot"; + +static char* find_efitest_path(void) +{ + static char dir[PATH_MAX] = {0}; + static bool run = false; + char *rest_path = "/efivarfs_data/"; + char *pos = NULL; + + if (run) + return dir; + + readlink("/proc/self/exe", dir, PATH_MAX); + + pos = strrchr(dir, '/'); + *pos = '\0'; + + strcat(dir, rest_path); + run = true; + + return dir; +} + +static bool probe(void) +{ + char *path; + int rc; + + path = find_efitest_path(); + + rc = access(path, F_OK); + if (rc) { + if (errno == ENOENT) { + rc = mkdir(path, 0755); + if(rc) + return false; + } else { + return false; + } + } + + set_efivarfs_path(path); + + return true; +} + +int main(void) +{ + void *ctx = NULL; + int rc, errno_value; + size_t size; + uint8_t *data = NULL; + uint32_t attr = DEF_ATTR; + char *path = NULL; + + if(!probe()) + return ENOENT; + + talloc_new(ctx); + size = strlen(test_data) + 1; + rc = efi_set_variable(ctx, test_efivar_guid, test_varname, + (uint8_t *)test_data, size, attr); + + rc = efi_get_variable(ctx, test_efivar_guid, test_varname, + &data, &size, &attr); + + assert(data != NULL); + rc = strcmp((char *)data, test_data); + if (rc) { + talloc_free(ctx); + assert(0); + } + + rc = efi_del_variable(ctx, test_efivar_guid, test_varname); + + rc = efi_get_variable(ctx, test_efivar_guid, test_varname, + &data, &size, &attr); + + errno_value = errno; + talloc_free(ctx); + + assert(errno_value == ENOENT); + + path = find_efitest_path(); + rmdir(path); + + return EXIT_SUCCESS; +} From patchwork Thu Aug 2 17:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952907 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJZ0kwRz9s4c for ; Fri, 3 Aug 2018 03:30:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="gEQHJglq"; 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 41hHJY5zhlzF2D4 for ; Fri, 3 Aug 2018 03:30:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="gEQHJglq"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="gEQHJglq"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH82GqTzF2DG for ; Fri, 3 Aug 2018 03:29:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZI5KVHdkWM+NfABceRV7zZHh8Gj3Mj94VV7nHIwBy9k=; b=gEQHJglqtCQfD4mlfT/dEyg0+ /XzUn6Y2hM2RlChUH51P9vYPa3Sd5qGo1anXy5NjK2jrMKVO1Z8ITvw2v1nMdpQqDp/Or/76sDYEX xuR8Uje4DrSEyaobt00K/6d3JOAMf/4GPN6qFf63pPg1vODnMVxBUoUZgPSm6zSvEg8h0++AMDgJR 2WnEXPqff3CI3czAEBvmbOkaxUKRAqPJODXrLLOGfFWg8WoPeZCiZf0y8nzQOMoFmuVzUduYSFSiA G35dZM/sy975P/w2McLyQcjU2ECMuIfrt+5xdUCx4wkFxpKdVrcQaAK08oAJFoUqZn5dAqy6r591O d+Fz1Qg4w==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPs-0007YF-QI; Thu, 02 Aug 2018 17:29:36 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 16/30] lib/efi: Cleanup read/write routines To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:36 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Make a new stucture struct efi_data to hold the info that describes an efi variable. Make a common routine efi_open that opens the efi variable file. Switch the efi get/set/del routines over to use efi_open. Signed-off-by: Geoff Levand --- lib/efi/efivar.c | 201 ++++++++++++++++++++++++++++--------------------------- lib/efi/efivar.h | 15 +++-- 2 files changed, 112 insertions(+), 104 deletions(-) diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c index 1ac6990..21c5d34 100644 --- a/lib/efi/efivar.c +++ b/lib/efi/efivar.c @@ -24,6 +24,7 @@ #include #include +#include #include "efivar.h" #include "log/log.h" @@ -42,150 +43,150 @@ inline const char *get_efivarfs_path(void) return efivarfs_path; } -int efi_del_variable(void *ctx, const char *guidstr, - const char *name) +static int efi_open(const char *name, const char *guidstr, int flags, + mode_t mode, char **path) { - int fd, flag, errno_value; - int rc = -1; - const char *dir; - char *path; + int fd; + + *path = NULL; - dir = get_efivarfs_path(); - if (!dir) + if (!get_efivarfs_path()) return -1; - path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); - if (!path) + *path = talloc_asprintf(NULL, "%s%s-%s", get_efivarfs_path(), name, guidstr); + if (!*path) return -1; - fd = open(path, O_RDONLY|O_NONBLOCK); - if (fd == -1) - goto err; + flags = flags ? flags : O_RDONLY | O_NONBLOCK; + + fd = open(*path, flags, mode); + + if (fd < 0) { + pb_log("%s: open failed %s: %s\n", __func__, *path, + strerror(errno)); + talloc_free(*path); + *path = NULL; + return -1; + } + + return fd; +} + +int efi_del_variable(const char *guidstr, const char *name) +{ + int fd, flag; + int rc = -1; + char *path; + + fd = efi_open(name, guidstr, 0, 0, &path); + if (fd < 0) + return -1; rc = ioctl(fd, FS_IOC_GETFLAGS, &flag); if (rc == -1) - goto err; + goto exit; flag &= ~FS_IMMUTABLE_FL; rc = ioctl(fd, FS_IOC_SETFLAGS, &flag); if (rc == -1) - goto err; + goto exit; close(fd); + fd = 0; rc = unlink(path); - -err: - errno_value = errno; - if (fd > 0) - close(fd); - - errno = errno_value; +exit: + talloc_free(path); + close(fd); return rc; } int efi_get_variable(void *ctx, const char *guidstr, const char *name, - uint8_t **data, size_t *data_size, uint32_t *attributes) + struct efi_data **efi_data) { - int fd, errno_value; + int fd; int rc = -1; - void *p, *buf; - size_t bufsize = 4096; - size_t filesize = 0; - ssize_t sz; - const char *dir; + char *p; + char buf[4096]; + ssize_t total; + ssize_t count; char *path; - dir = get_efivarfs_path(); - if (!dir) - return EFAULT; + *efi_data = NULL; - path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); - if (!path) - return ENOMEM; - - fd = open(path, O_RDONLY|O_NONBLOCK); + fd = efi_open(name, guidstr, 0, 0, &path); if (fd < 0) - goto err; + return -1; - buf = talloc_size(ctx, bufsize); - if (!buf) - goto err; - - do { - p = buf + filesize; - sz = read(fd, p, bufsize); - if (sz < 0 && errno == EAGAIN) { - continue; - } else if (sz == 0) { - break; + for (p = buf, total = 0; ; p = buf + count) { + count = read(fd, p, sizeof(buf) - total); + if (count < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) + continue; + + pb_log("%s: read failed %s: (%ld) %s\n", __func__, path, + count, strerror(errno)); + goto exit; } - filesize += sz; - } while (1); + if (p >= (buf + sizeof(buf))) { + pb_log("%s: buffer full %s: (%ld)\n", __func__, path, + sizeof(buf)); + goto exit; + } + if (count == 0) + break; + total += count; + }; - *attributes = *(uint32_t *)buf; - *data = (uint8_t *)(buf + sizeof(uint32_t)); - *data_size = strlen(buf + sizeof(uint32_t)); - rc = 0; + *efi_data = (void*)talloc_zero_array(ctx, char, + sizeof (struct efi_data) + total); -err: - errno_value = errno; - if (fd > 0) - close(fd); + (*efi_data)->attributes = *(uint32_t *)buf; + (*efi_data)->data_size = total; + (*efi_data)->data = (*efi_data)->fill; + memcpy((*efi_data)->data, buf + sizeof (uint32_t), total); - errno = errno_value; + rc = 0; +exit: + talloc_free(path); + close(fd); return rc; } -int efi_set_variable(void *ctx, const char *guidstr, const char *name, - uint8_t *data, size_t data_size, uint32_t attributes) +int efi_set_variable(const char *guidstr, const char *name, + const struct efi_data *efi_data) { - int rc = -1, errno_value; - int fd = -1; - ssize_t len; - const char *dir; - char *path; + int rc = -1; + int fd; + ssize_t count; void *buf; size_t bufsize; - mode_t mask = 0644; - - dir = get_efivarfs_path(); - if (!dir) - return EFAULT; - - path = talloc_asprintf(ctx, "%s%s-%s", dir, name, guidstr); - if (!path) - return ENOMEM; + char *path; - if (!access(path, F_OK)) { - rc = efi_del_variable(ctx, guidstr, name); - if (rc < 0) { - goto err; - } - } + efi_del_variable(guidstr, name); - fd = open(path, O_CREAT|O_WRONLY, mask); + fd = efi_open(name, guidstr, O_CREAT | O_WRONLY, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &path); if (fd < 0) - goto err; + return -1; - bufsize = sizeof(uint32_t) + data_size; - buf = talloc_size(ctx, bufsize); + bufsize = sizeof(uint32_t) + efi_data->data_size; + buf = talloc_size(path, bufsize); if (!buf) - goto err; - - *(uint32_t *)buf = attributes; - memcpy(buf + sizeof(uint32_t), data, data_size); + goto exit; - len = write(fd, buf, bufsize); - if ((size_t)len != bufsize) - goto err; - else - rc = 0; + *(uint32_t *)buf = efi_data->attributes; + memcpy(buf + sizeof(uint32_t), efi_data->data, efi_data->data_size); -err: - errno_value = errno; - if (fd > 0) - close(fd); + count = write(fd, buf, bufsize); + if ((size_t)count != bufsize) { + pb_log("%s: write failed %s: (%ld) %s\n", __func__, name, + count, strerror(errno)); + goto exit; + } + rc = 0; - errno = errno_value; +exit: + talloc_free(path); + close(fd); return rc; } diff --git a/lib/efi/efivar.h b/lib/efi/efivar.h index ebf73fa..0d44100 100644 --- a/lib/efi/efivar.h +++ b/lib/efi/efivar.h @@ -34,13 +34,20 @@ #define EFIVARFS_MAGIC 0xde5e81e4 #endif +struct efi_data { + uint32_t attributes; + size_t data_size; + void *data; + uint8_t fill[0]; +}; + void set_efivarfs_path(const char *path); const char *get_efivarfs_path(void); int efi_get_variable(void *ctx, const char *guidstr, const char *name, - uint8_t **data, size_t *data_size, uint32_t *attributes); -int efi_set_variable(void *ctx, const char *guidstr, const char *name, - uint8_t *data, size_t data_size, uint32_t attributes); -int efi_del_variable(void *ctx, const char *guidstr, const char *name); + struct efi_data **efi_data); +int efi_set_variable(const char *guidstr, const char *name, + const struct efi_data *efi_data); +int efi_del_variable(const char *guidstr, const char *name); #endif /* EFIVAR_H */ From patchwork Thu Aug 2 17:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHJv0TY1z9s4c for ; Fri, 3 Aug 2018 03:31:11 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="jR7O6Txx"; 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 41hHJt67m4zF2DC for ; Fri, 3 Aug 2018 03:31:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="jR7O6Txx"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="jR7O6Txx"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH85tqtzF2DN for ; Fri, 3 Aug 2018 03:29:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RG7a9gS4X3156fv1qxMZQ0d9Mp6qtrT4JIZ4BuOAYPQ=; b=jR7O6Txx+5f5h+BEl2ppH6mAw mCDF/S3r/fK4WVvZSjP2lBvZl2vBLTmqQBEcCg/e/vmOcCxqpOKKbdHNYHW0p2E71BjltSdu1fpWH TptUHGTwLlOurPDGSzAcsncBQ+Nnc4fnVnJX+PHOROKS96J7achN3VuRwa8Sq0MOyoCOe+NbPcEkN Poyb+qQINkq6LV3ExnLbXoOp3WcytNn+ezYJXQweUWAtscMCiiuDzJ+socq67KX8i5WEP99Y51E3U hSiSI4noPg7DyTwkdwTSpAbbBHkQe/ki471VUk+L40AnTpuzZ6YBczYg753sdlKtMpXCHPWfEj/6H TGgcuRbvA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPt-0007YN-1h; Thu, 02 Aug 2018 17:29:37 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 17/30] test-efivar: Update to latest lib/efi routines To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:37 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Samuel Mendoza-Jonas From: Samuel Mendoza-Jonas Signed-off-by: Geoff Levand --- test/lib/Makefile.am | 3 ++- test/lib/test-efivar.c | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am index 047fcb2..65991a5 100644 --- a/test/lib/Makefile.am +++ b/test/lib/Makefile.am @@ -23,7 +23,8 @@ lib_TESTS = \ test/lib/test-process-parent-stdout \ test/lib/test-process-both \ test/lib/test-process-stdout-eintr \ - test/lib/test-fold + test/lib/test-fold \ + test/lib/test-efivar if WITH_OPENSSL lib_TESTS += \ diff --git a/test/lib/test-efivar.c b/test/lib/test-efivar.c index 8ceb8f5..a85b73c 100644 --- a/test/lib/test-efivar.c +++ b/test/lib/test-efivar.c @@ -87,33 +87,38 @@ int main(void) { void *ctx = NULL; int rc, errno_value; - size_t size; - uint8_t *data = NULL; uint32_t attr = DEF_ATTR; char *path = NULL; + struct efi_data *efi_data; if(!probe()) return ENOENT; talloc_new(ctx); - size = strlen(test_data) + 1; - rc = efi_set_variable(ctx, test_efivar_guid, test_varname, - (uint8_t *)test_data, size, attr); + efi_data = talloc_zero(ctx, struct efi_data); + efi_data->attributes = attr; + efi_data->data = talloc_strdup(efi_data, test_data); + efi_data->data_size = strlen(test_data) + 1; + + rc = efi_set_variable(test_efivar_guid, test_varname, + efi_data); + + talloc_free(efi_data); rc = efi_get_variable(ctx, test_efivar_guid, test_varname, - &data, &size, &attr); + &efi_data); - assert(data != NULL); - rc = strcmp((char *)data, test_data); + assert(efi_data->data != NULL); + rc = strcmp((char *)efi_data->data, test_data); if (rc) { talloc_free(ctx); assert(0); } - rc = efi_del_variable(ctx, test_efivar_guid, test_varname); + rc = efi_del_variable(test_efivar_guid, test_varname); rc = efi_get_variable(ctx, test_efivar_guid, test_varname, - &data, &size, &attr); + &efi_data); errno_value = errno; talloc_free(ctx); From patchwork Thu Aug 2 17:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLL05JGz9s2g for ; Fri, 3 Aug 2018 03:32:26 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="0km4FzZA"; 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 41hHLK5W75zF2DG for ; Fri, 3 Aug 2018 03:32:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="0km4FzZA"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="0km4FzZA"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH91KD8zF2DP for ; Fri, 3 Aug 2018 03:29:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OuORnqZf9tBz1c1gO8tAH2pPtoJ+xFvbdift+aO99xk=; b=0km4FzZAP0a9K0baAM4odyhmr qEIbBXtAFeN7moo2bpWiySR0JEQNjA+wZsSo8oKiSv8Y2ClXVHVhDBXl2JEHC8lKd+vH5DMfHdwYw MZiDwb0JFtvkkar3xagZTY6Z6WXqJMn6rnFmXEpjM/IrsXpseyJRGIibgfSJp/1+iEjqyPnPeHdWk 63f4DIUiQZZEjRr1W9GHhy2Nvp3/h5D+Kaj51W+G9ah6/lUztWk9YQNfeIdc9ngPglP0BAzAxZ8xy J3TWMi3bg5ZyzbPjzIzWiaN6hB58Ktl+40HJRkxS36ZsDqMAp+DjqGgX/CkLjs4HNg0o8ea2H55r8 Lj/aaK2YA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPt-0007YV-9m; Thu, 02 Aug 2018 17:29:37 +0000 Message-Id: <18271eb875350ff328f951feb8ed8bfc16fbbbfb.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 18/30] discover: Move generic ipmi routines to ipmi To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:37 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Signed-off-by: Ge Song [Split from a larger patch] Signed-off-by: Geoff Levand --- discover/ipmi.c | 123 ++++++++++++++++++++++++++++++++++++++++ discover/ipmi.h | 4 ++ discover/platform-powerpc.c | 133 ++------------------------------------------ 3 files changed, 131 insertions(+), 129 deletions(-) diff --git a/discover/ipmi.c b/discover/ipmi.c index f94dab7..840fdee 100644 --- a/discover/ipmi.c +++ b/discover/ipmi.c @@ -320,3 +320,126 @@ int parse_ipmi_interface_override(struct config *config, uint8_t *buf, return 0; } + +void ipmi_get_bmc_mac(struct ipmi *ipmi, uint8_t *buf) +{ + uint16_t resp_len = 8; + uint8_t resp[8]; + uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 }; + int i, rc; + + rc = ipmi_transaction(ipmi, IPMI_NETFN_TRANSPORT, + IPMI_CMD_TRANSPORT_GET_LAN_PARAMS, + req, sizeof(req), + resp, &resp_len, + ipmi_timeout); + + pb_debug_fn("BMC MAC resp [%d][%d]:\n", rc, resp_len); + + if (rc == 0 && resp_len > 0) { + for (i = 2; i < resp_len; i++) { + pb_debug(" %x", resp[i]); + buf[i - 2] = resp[i]; + } + pb_debug("\n"); + } + +} + +/* + * Retrieve info from the "Get Device ID" IPMI commands. + * See Chapter 20.1 in the IPMIv2 specification. + */ +void ipmi_get_bmc_versions(struct ipmi *ipmi, struct system_info *info) +{ + uint16_t resp_len = 16; + uint8_t resp[16], bcd; + int i, rc; + + /* Retrieve info from current side */ + rc = ipmi_transaction(ipmi, IPMI_NETFN_APP, + IPMI_CMD_APP_GET_DEVICE_ID, + NULL, 0, + resp, &resp_len, + ipmi_timeout); + + pb_debug_fn("BMC version resp [%d][%d]:\n", rc, resp_len); + if (resp_len > 0) { + for (i = 0; i < resp_len; i++) { + pb_debug(" %x", resp[i]); + } + pb_debug("\n"); + } + + if (rc == 0 && (resp_len == 12 || resp_len == 16)) { + info->bmc_current = talloc_array(info, char *, 4); + info->n_bmc_current = 4; + + info->bmc_current[0] = talloc_asprintf(info, "Device ID: 0x%x", + resp[1]); + info->bmc_current[1] = talloc_asprintf(info, "Device Rev: 0x%x", + resp[2]); + bcd = resp[4] & 0x0f; + bcd += 10 * (resp[4] >> 4); + /* rev1.rev2.aux_revision */ + info->bmc_current[2] = talloc_asprintf(info, + "Firmware version: %u.%02u", + resp[3], bcd); + if (resp_len == 16) { + info->bmc_current[2] = talloc_asprintf_append( + info->bmc_current[2], + ".%02x%02x%02x%02x", + resp[12], resp[13], resp[14], resp[15]); + } + bcd = resp[5] & 0x0f; + bcd += 10 * (resp[5] >> 4); + info->bmc_current[3] = talloc_asprintf(info, "IPMI version: %u", + bcd); + } else + pb_debug_fn("Failed to retrieve Device ID from IPMI\n"); + + /* Retrieve info from golden side */ + memset(resp, 0, sizeof(resp)); + resp_len = 16; + rc = ipmi_transaction(ipmi, IPMI_NETFN_AMI, + IPMI_CMD_APP_GET_DEVICE_ID_GOLDEN, + NULL, 0, + resp, &resp_len, + ipmi_timeout); + + pb_debug_fn("BMC golden resp [%d][%d]:\n", rc, resp_len); + if (resp_len > 0) { + for (i = 0; i < resp_len; i++) { + pb_debug(" %x", resp[i]); + } + pb_debug("\n"); + } + + if (rc == 0 && (resp_len == 12 || resp_len == 16)) { + info->bmc_golden = talloc_array(info, char *, 4); + info->n_bmc_golden = 4; + + info->bmc_golden[0] = talloc_asprintf(info, "Device ID: 0x%x", + resp[1]); + info->bmc_golden[1] = talloc_asprintf(info, "Device Rev: 0x%x", + resp[2]); + bcd = resp[4] & 0x0f; + bcd += 10 * (resp[4] >> 4); + /* rev1.rev2.aux_revision */ + info->bmc_golden[2] = talloc_asprintf(info, + "Firmware version: %u.%02u", + resp[3], bcd); + if (resp_len == 16) { + info->bmc_golden[2] = talloc_asprintf_append( + info->bmc_golden[2], + ".%02x%02x%02x%02x", + resp[12], resp[13], resp[14], resp[15]); + } + bcd = resp[5] & 0x0f; + bcd += 10 * (resp[5] >> 4); + info->bmc_golden[3] = talloc_asprintf(info, "IPMI version: %u", + bcd); + } else + pb_debug_fn("Failed to retrieve Golden Device ID from IPMI\n"); +} + diff --git a/discover/ipmi.h b/discover/ipmi.h index af8df35..c8ccb46 100644 --- a/discover/ipmi.h +++ b/discover/ipmi.h @@ -29,6 +29,8 @@ enum ipmi_sensor_ids { struct ipmi; +static const int ipmi_timeout = 10000; /* milliseconds. */ + bool ipmi_present(void); bool ipmi_bootdev_is_valid(int x); struct ipmi *ipmi_open(void *ctx); @@ -40,6 +42,8 @@ int ipmi_transaction(struct ipmi *ipmi, uint8_t netfn, uint8_t cmd, int parse_ipmi_interface_override(struct config *config, uint8_t *buf, uint16_t len); +void ipmi_get_bmc_mac(struct ipmi *ipmi, uint8_t *buf); +void ipmi_get_bmc_versions(struct ipmi *ipmi, struct system_info *info); #endif /* _IPMI_H */ diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 2ee376d..d7bd949 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -26,7 +26,6 @@ static const char *partition = "common"; static const char *sysparams_dir = "/sys/firmware/opal/sysparams/"; static const char *devtree_dir = "/proc/device-tree/"; -static const int ipmi_timeout = 10000; /* milliseconds. */ struct param { char *name; @@ -986,130 +985,6 @@ static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform) return 0; } -static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf) -{ - struct platform_powerpc *platform = p->platform_data; - uint16_t resp_len = 8; - uint8_t resp[8]; - uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 }; - int i, rc; - - rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_TRANSPORT, - IPMI_CMD_TRANSPORT_GET_LAN_PARAMS, - req, sizeof(req), - resp, &resp_len, - ipmi_timeout); - - pb_debug("BMC MAC resp [%d][%d]:\n", rc, resp_len); - - if (rc == 0 && resp_len > 0) { - for (i = 2; i < resp_len; i++) { - pb_debug(" %x", resp[i]); - buf[i - 2] = resp[i]; - } - pb_debug("\n"); - } - -} - -/* - * Retrieve info from the "Get Device ID" IPMI commands. - * See Chapter 20.1 in the IPMIv2 specification. - */ -static void get_ipmi_bmc_versions(struct platform *p, struct system_info *info) -{ - struct platform_powerpc *platform = p->platform_data; - uint16_t resp_len = 16; - uint8_t resp[16], bcd; - int i, rc; - - /* Retrieve info from current side */ - rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_APP, - IPMI_CMD_APP_GET_DEVICE_ID, - NULL, 0, - resp, &resp_len, - ipmi_timeout); - - pb_debug("BMC version resp [%d][%d]:\n", rc, resp_len); - if (resp_len > 0) { - for (i = 0; i < resp_len; i++) { - pb_debug(" %x", resp[i]); - } - pb_debug("\n"); - } - - if (rc == 0 && (resp_len == 12 || resp_len == 16)) { - info->bmc_current = talloc_array(info, char *, 4); - info->n_bmc_current = 4; - - info->bmc_current[0] = talloc_asprintf(info, "Device ID: 0x%x", - resp[1]); - info->bmc_current[1] = talloc_asprintf(info, "Device Rev: 0x%x", - resp[2]); - bcd = resp[4] & 0x0f; - bcd += 10 * (resp[4] >> 4); - /* rev1.rev2.aux_revision */ - info->bmc_current[2] = talloc_asprintf(info, - "Firmware version: %u.%02u", - resp[3], bcd); - if (resp_len == 16) { - info->bmc_current[2] = talloc_asprintf_append( - info->bmc_current[2], - ".%02x%02x%02x%02x", - resp[12], resp[13], resp[14], resp[15]); - } - bcd = resp[5] & 0x0f; - bcd += 10 * (resp[5] >> 4); - info->bmc_current[3] = talloc_asprintf(info, "IPMI version: %u", - bcd); - } else - pb_log("Failed to retrieve Device ID from IPMI\n"); - - /* Retrieve info from golden side */ - memset(resp, 0, sizeof(resp)); - resp_len = 16; - rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_AMI, - IPMI_CMD_APP_GET_DEVICE_ID_GOLDEN, - NULL, 0, - resp, &resp_len, - ipmi_timeout); - - pb_debug("BMC golden resp [%d][%d]:\n", rc, resp_len); - if (resp_len > 0) { - for (i = 0; i < resp_len; i++) { - pb_debug(" %x", resp[i]); - } - pb_debug("\n"); - } - - if (rc == 0 && (resp_len == 12 || resp_len == 16)) { - info->bmc_golden = talloc_array(info, char *, 4); - info->n_bmc_golden = 4; - - info->bmc_golden[0] = talloc_asprintf(info, "Device ID: 0x%x", - resp[1]); - info->bmc_golden[1] = talloc_asprintf(info, "Device Rev: 0x%x", - resp[2]); - bcd = resp[4] & 0x0f; - bcd += 10 * (resp[4] >> 4); - /* rev1.rev2.aux_revision */ - info->bmc_golden[2] = talloc_asprintf(info, - "Firmware version: %u.%02u", - resp[3], bcd); - if (resp_len == 16) { - info->bmc_golden[2] = talloc_asprintf_append( - info->bmc_golden[2], - ".%02x%02x%02x%02x", - resp[12], resp[13], resp[14], resp[15]); - } - bcd = resp[5] & 0x0f; - bcd += 10 * (resp[5] >> 4); - info->bmc_golden[3] = talloc_asprintf(info, "IPMI version: %u", - bcd); - } else - pb_log("Failed to retrieve Golden Device ID from IPMI\n"); -} - static void get_ipmi_network_override(struct platform_powerpc *platform, struct config *config) { @@ -1320,11 +1195,11 @@ static int get_sysinfo(struct platform *p, struct system_info *sysinfo) talloc_free(filename); sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE); - if (platform->ipmi) - get_ipmi_bmc_mac(p, sysinfo->bmc_mac); - if (platform->ipmi) - get_ipmi_bmc_versions(p, sysinfo); + if (platform->ipmi) { + ipmi_get_bmc_mac(platform->ipmi, sysinfo->bmc_mac); + ipmi_get_bmc_versions(platform->ipmi, sysinfo); + } if (platform->get_platform_versions) platform->get_platform_versions(sysinfo); From patchwork Thu Aug 2 17:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLT1Yjfz9s2g for ; Fri, 3 Aug 2018 03:32:33 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="n1EheInp"; 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 41hHLT02rZzF2D3 for ; Fri, 3 Aug 2018 03:32:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="n1EheInp"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="n1EheInp"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH92K8tzF2DQ for ; Fri, 3 Aug 2018 03:29:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=j6i2dtmluYYtoCfpSk+eksMm7HHXSw6RuRAzfRjzaow=; b=n1EheInppWdga3WUrYo/YRT8X AyvlA9pph4eijiQM7NyW5RFEZhGkslSx9gWoLhYn8BQ1iCrdMrL13EkNz5D1Y6DxkuHxCXbYOPtyF TtqpI+lBdPUJFU1Oykw/ur2KzyulIMhghYdvmQV79vor30skBePXY5kOoZOsJx9rATF+G6OSje1Vh zi8uxbULbenDdXP3FlZk1SznUh4/3y9MpJYgUtUrgqZEQ1GYDw9rffTWbU3Q8AeLfcS1L9U2g9LD3 16jt3Cmtq+tK58F4mSl470MJGt+6Xh8+Wtn3bLA/j1wkdRPm+ri61QDXiCyrj39y1YNiLQi8rnCob BvOiaATgw==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPt-0007Yj-LC; Thu, 02 Aug 2018 17:29:37 +0000 Message-Id: <0e7ce185c6a7f690cd660811034a2c62f7b4fc19.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 19/30] discover/event: Rename param -> event_param To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:37 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" To avoid name clash with other 'struct param'. Signed-off-by: Geoff Levand --- discover/event.c | 8 ++++---- discover/event.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/discover/event.c b/discover/event.c index ead2fda..ec5537a 100644 --- a/discover/event.c +++ b/discover/event.c @@ -80,7 +80,7 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, static void event_parse_params(struct event *event, const char *buf, int len) { int param_len, name_len, value_len; - struct param *param; + struct event_param *param; char *sep; for (; len > 0; len -= param_len + 1, buf += param_len + 1) { @@ -95,7 +95,7 @@ static void event_parse_params(struct event *event, const char *buf, int len) /* update the params array */ event->params = talloc_realloc(event, event->params, - struct param, ++event->n_params); + struct event_param, ++event->n_params); param = &event->params[event->n_params - 1]; sep = memchr(buf, '=', param_len); @@ -150,7 +150,7 @@ const char *event_get_param(const struct event *event, const char *name) void event_set_param(struct event *event, const char *name, const char *value) { - struct param *param; + struct event_param *param; int i; /* if it's already present, replace the value of the old param */ @@ -165,7 +165,7 @@ void event_set_param(struct event *event, const char *name, const char *value) /* not found - create a new param */ event->params = talloc_realloc(event, event->params, - struct param, ++event->n_params); + struct event_param, ++event->n_params); param = &event->params[event->n_params - 1]; param->name = talloc_strdup(event, name); diff --git a/discover/event.h b/discover/event.h index 1f6966c..2d83ad9 100644 --- a/discover/event.h +++ b/discover/event.h @@ -23,7 +23,7 @@ struct event { enum event_action action; const char *device; - struct param { + struct event_param { char *name; char *value; } *params; From patchwork Thu Aug 2 17:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLc3gbyz9s3q for ; Fri, 3 Aug 2018 03:32:40 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="RfXnM+N0"; 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 41hHLc29C5zF2DQ for ; Fri, 3 Aug 2018 03:32:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="RfXnM+N0"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="RfXnM+N0"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH9663CzF21T for ; Fri, 3 Aug 2018 03:29:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=K4DcYaRzMfdkfyWBqtKjnUFK7/4ZsMlM9t+WjYSU0Oo=; b=RfXnM+N0lhzyFpVMVutwpLfww YQd0/EjDkHgE1YiekBmAh/n1BirYEM5iYdwFKizdBQViE6SxiXfChCGLspEl7dE45o7aYSBmn98tc ljlPlsV8xEZ9QdjFtZbghyRgVzstMGS6t855g+l1va9LQVEWpOoWkDCXUoElIcrbT5hr+OhRxndKQ uBm+rzh3L46UYdhzODDdEgti85hB+BxjYpWbXCOPisr+CohsO93irgi8Ngp+HyFjksB8NV9Z0DEYW 7pjjjzW0LQYc4CI8jRpt+uDSXvmRC+E2WE09A+1uaXUpqtYoNNUdEbqj/NsVzTkvc7iMsNdRcKlMN ji4wCbsSw==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPu-0007Yy-1C; Thu, 02 Aug 2018 17:29:38 +0000 Message-Id: <22b172c971f9e5989aca8346f539cf14e8a212d5.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 20/30] lib/param_list: Add new parameter list routines To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:38 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Based on the powerpc param routines adds new generic routines to manage a name + value parameter list. Signed-off-by: Geoff Levand --- lib/Makefile.am | 4 +- lib/param_list/param_list.c | 118 ++++++++++++++++++++++++++++++++++++++++++++ lib/param_list/param_list.h | 48 ++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 lib/param_list/param_list.c create mode 100644 lib/param_list/param_list.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 59d37ab..016a14d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -67,7 +67,9 @@ lib_libpbcore_la_SOURCES = \ lib/flash/flash.h \ lib/security/security.h \ lib/efi/efivar.h \ - lib/efi/efivar.c + lib/efi/efivar.c \ + lib/param_list/param_list.c \ + lib/param_list/param_list.h if ENABLE_MTD lib_libpbcore_la_SOURCES += \ diff --git a/lib/param_list/param_list.c b/lib/param_list/param_list.c new file mode 100644 index 0000000..b3a45f8 --- /dev/null +++ b/lib/param_list/param_list.c @@ -0,0 +1,118 @@ + +#define _GNU_SOURCE + +#include +#include + +#include +#include +#include + +const char **common_known_params(void) +{ + static const char *common[] = { + "auto-boot?", + "petitboot,network", + "petitboot,timeout", + "petitboot,bootdevs", + "petitboot,language", + "petitboot,debug?", + "petitboot,write?", + "petitboot,snapshots?", + "petitboot,console", + "petitboot,http_proxy", + "petitboot,https_proxy", + NULL, + }; + + return common; +} + +void param_list_init(struct param_list *pl, const char *known_params[]) +{ + assert(known_params); + list_init(&pl->params); + pl->known_params = known_params; +} + +bool param_list_is_known_n(const struct param_list *pl, const char *name, + unsigned int name_len) +{ + const char **known; + + assert(pl->known_params); + + param_list_for_each_known_param(pl, known) { + if (name_len == strlen(*known) && !strncmp(name, *known, name_len)) { + return true; + } + } + + return false; +} + +bool param_list_is_known(const struct param_list *pl, const char *name) +{ + const char **known; + + assert(pl->known_params); + + param_list_for_each_known_param(pl, known) { + if (!strcmp(name, *known)) { + return true; + } + } + + return false; +} + +struct param *param_list_get_param(struct param_list *pl, const char *name) +{ + struct param *param; + + param_list_for_each(pl, param) { + if (!strcmp(param->name, name)) + return param; + } + return NULL; +} + +void param_list_set(struct param_list *pl, const char *name, const char *value, + bool modified_on_create) +{ + struct param *param; + + param_list_for_each(pl, param) { + if (strcmp(param->name, name)) + continue; + + if (!strcmp(param->value, value)) + return; + + /* Update existing list entry. */ + talloc_free(param->value); + param->value = talloc_strdup(param, value); + param->modified = true; + pb_debug_fn("Updated: %s:%s\n", name, value); + return; + } + + /* Add new entry to list. */ + param = talloc(pl, struct param); + param->modified = modified_on_create; + param->name = talloc_strdup(pl, name); + param->value = talloc_strdup(pl, value); + list_add(&pl->params, ¶m->list); + pb_debug_fn("Created: %s:%s\n", name, value); +} + +void param_list_set_non_empty(struct param_list *pl, const char *name, const char *value, + bool modified_on_create) +{ + if (!param_list_get_value(pl, name) && !strlen(value)) { + return; + } + + param_list_set(pl, name, value, modified_on_create); +} + diff --git a/lib/param_list/param_list.h b/lib/param_list/param_list.h new file mode 100644 index 0000000..89ef400 --- /dev/null +++ b/lib/param_list/param_list.h @@ -0,0 +1,48 @@ +#ifndef PARAM_LIST_H +#define PARAM_LIST_H + +#include + +#include + +struct param { + char *name; + char *value; + bool modified; + struct list_item list; +}; + +struct param_list { + struct list params; + const char **known_params; +}; + +#define param_list_for_each(_pl_ptr, _pos) \ + list_for_each_entry(&(_pl_ptr)->params, _pos, list) + +#define param_list_for_each_known_param(_pl_ptr, _pos) \ + for (_pos = (_pl_ptr)->known_params; *_pos; _pos++) + +const char **common_known_params(void); + +void param_list_init(struct param_list *pl, const char *known_params[]); +bool param_list_is_known(const struct param_list *pl, const char *name); +bool param_list_is_known_n(const struct param_list *pl, const char *name, + unsigned int name_len); +struct param *param_list_get_param(struct param_list *pl, const char *name); +static inline const char *param_list_get_value(const struct param_list *pl, + const char *name) +{ + const struct param *param = + param_list_get_param((struct param_list *)pl, name); + return param ? param->value : NULL; +} +void param_list_set(struct param_list *pl, const char *name, const char *value, + bool modified_on_create); + +/* param_list_set_non_empty - Won't create a new parameter that would be empty. */ +void param_list_set_non_empty(struct param_list *pl, const char *name, + const char *value, bool modified_on_create); + +#endif /* PARAM_LIST_H */ + From patchwork Thu Aug 2 17:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLm4kFWz9s2g for ; Fri, 3 Aug 2018 03:32:48 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Pvuoww5u"; 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 41hHLm1krVzF2D1 for ; Fri, 3 Aug 2018 03:32:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Pvuoww5u"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Pvuoww5u"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHB0jqbzF277 for ; Fri, 3 Aug 2018 03:29:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=J1psddjeysDMcdi87FfMXGYCU1Jiz3mKa/maFF8kP78=; b=Pvuoww5u77eXP4IKoE2ZVdzeA O+T0SXubfm6wJR7yBm8KvcRoqj6UOuZZPPZ9KlguAdDKcJI7J8XpBveWTwOqZ7AT07K+EIRVj5fbj OPXlwxCYiQHgMgqu3PX8rSaUwBIFp0E93OA4qdgdwg9LtKcJnR3miKnAIRdEpN7PAIWow/s6KHKcd +t6nYXeRijqIQXReQF3SbGWkbiqHlNplP8dpz4cAM18DqYfqzOQ5VNFp7FZTJonurg19MWXKCH28X a+aUD2sLjQdeugqCS7gHAgqz6++oSE1yo7+xItpPGhdHyUAXciLZAdnR0ZZbWt5+8kv3drQsB7zqa XfXVIdqZg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPu-0007Z6-9z; Thu, 02 Aug 2018 17:29:38 +0000 Message-Id: <11848bbc30746cb1a817f261cda3355999f41659.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 21/30] discover/powerpc: Rearange save_config To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:38 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Rearange update_config and save_config so that update_config only operates on the platform params list. Signed-off-by: Ge Song [Split from a larger patch and cleaned up] Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index d7bd949..c7432fb 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -680,7 +680,7 @@ static void update_bootdev_config(struct platform_powerpc *platform, talloc_free(boot_str); } -static int update_config(struct platform_powerpc *platform, +static void update_config(struct platform_powerpc *platform, struct config *config, struct config *defaults) { char *tmp = NULL; @@ -698,14 +698,6 @@ static int update_config(struct platform_powerpc *platform, val = tmp = talloc_asprintf(platform, "%d", config->autoboot_timeout_sec); - if (config->ipmi_bootdev == IPMI_BOOTDEV_INVALID && - platform->clear_ipmi_bootdev) { - platform->clear_ipmi_bootdev(platform, - config->ipmi_bootdev_persistent); - config->ipmi_bootdev = IPMI_BOOTDEV_NONE; - config->ipmi_bootdev_persistent = false; - } - update_string_config(platform, "petitboot,timeout", val); if (tmp) talloc_free(tmp); @@ -732,8 +724,6 @@ static int update_config(struct platform_powerpc *platform, update_network_config(platform, config); update_bootdev_config(platform, config); - - return write_nvram(platform); } static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, @@ -1154,15 +1144,22 @@ static int save_config(struct platform *p, struct config *config) { struct platform_powerpc *platform = to_platform_powerpc(p); struct config *defaults; - int rc; + + if (config->ipmi_bootdev == IPMI_BOOTDEV_INVALID && + platform->clear_ipmi_bootdev) { + platform->clear_ipmi_bootdev(platform, + config->ipmi_bootdev_persistent); + config->ipmi_bootdev = IPMI_BOOTDEV_NONE; + config->ipmi_bootdev_persistent = false; + } defaults = talloc_zero(platform, struct config); config_set_defaults(defaults); - rc = update_config(platform, config, defaults); + update_config(platform, config, defaults); talloc_free(defaults); - return rc; + return write_nvram(platform); } static void pre_boot(struct platform *p, const struct config *config) From patchwork Thu Aug 2 17:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952922 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHLv6K2Kz9s2g for ; Fri, 3 Aug 2018 03:32:55 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="3auY0gJZ"; 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 41hHLv4hxnzF277 for ; Fri, 3 Aug 2018 03:32:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="3auY0gJZ"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="3auY0gJZ"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHB2WM6zF22V for ; Fri, 3 Aug 2018 03:29:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=72yIn2a3b1rfxyQ8JWHII1cK+3K0ZgNLGpTLE0aHQMM=; b=3auY0gJZTMsoO9XrasA5j3+zb naZDJqJqmn1lmwR1GJTxvYqRZi3jGFngB69+JbzbEIQSWeGZ+UaACKHnG6WHLvtSEQ+AoppyRr9mM lp6oRhzlcUyakSnlmOjf/DsJOiE/sxqEaxLtHjsLtx1GZLooiRFlDeKudm8GTd8vRyGqZ3rw7CA5B O+jb/CJYydJ1FbrX7G3xRp7IIemhhxrXlbmAxpYSIXjeJvvc3nUq9wqkeynJuxoSKDeM/tFZom+DF DQAjQ9JhhJJNSUqjOvU7nYSOGmu9rMrHVeYaCT0ZeCUuVJpUXwLb4BMp0OrIsDvc1aHJMxEa01Mfj iy2rcldpg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPu-0007ZG-LA; Thu, 02 Aug 2018 17:29:38 +0000 Message-Id: <048ee2258797a9d9c102814f06f368ab7bbca4d2.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 22/30] discover/powerpc: Add param_name arg To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:38 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Update update_network_config and update_bootdev_config to operate on a generic parameter name passed as an argument. Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index c7432fb..87ff72e 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -609,7 +609,7 @@ static void update_string_config(struct platform_powerpc *platform, } static void update_network_config(struct platform_powerpc *platform, - struct config *config) + const char *param_name, const struct config *config) { unsigned int i; char *val; @@ -642,13 +642,13 @@ static void update_network_config(struct platform_powerpc *platform, talloc_free(dns_str); } - update_string_config(platform, "petitboot,network", val); + update_string_config(platform, param_name, val); talloc_free(val); } static void update_bootdev_config(struct platform_powerpc *platform, - struct config *config) + const char *param_name, const struct config *config) { char *val = NULL, *boot_str = NULL, *tmp = NULL; struct autoboot_option *opt; @@ -674,7 +674,7 @@ static void update_bootdev_config(struct platform_powerpc *platform, tmp = val = talloc_asprintf_append(val, "%s", boot_str); } - update_string_config(platform, "petitboot,bootdevs", val); + update_string_config(platform, param_name, val); talloc_free(tmp); if (boot_str) talloc_free(boot_str); @@ -721,9 +721,9 @@ static void update_config(struct platform_powerpc *platform, val = config->https_proxy ?: ""; update_string_config(platform, "petitboot,https_proxy", val); - update_network_config(platform, config); + update_network_config(platform, "petitboot,network", config); - update_bootdev_config(platform, config); + update_bootdev_config(platform, "petitboot,bootdevs", config); } static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, @@ -1071,7 +1071,7 @@ static void get_ipmi_network_override(struct platform_powerpc *platform, if (!rc && persistent) { /* Write this new config to NVRAM */ - update_network_config(platform, config); + update_network_config(platform, "petitboot,network", config); rc = write_nvram(platform); if (rc) pb_log("platform: Failed to save persistent interface override\n"); From patchwork Thu Aug 2 17:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952923 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHM34Gmwz9s2g for ; Fri, 3 Aug 2018 03:33:03 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="1c3G4Ooi"; 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 41hHM32gzSzF2DG for ; Fri, 3 Aug 2018 03:33:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="1c3G4Ooi"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="1c3G4Ooi"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHB4qbDzF21T for ; Fri, 3 Aug 2018 03:29:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fIqN0Fwan8A2aac1R38qyR0sNRBoXuKKTSO3tfR6VFM=; b=1c3G4OoiWVZYb7AcDiqxz0W4+ EjR80/hWBKfZlnLqtnBUtpf1Gd01a6nDBzeuzsdoVz383NhkInDx+MsuWHDJzP5ZV0c8uifLNnJ0e ASd3PagKXkKTKPLwHR+IoNjoFIS+pfUICAL3/IT7TEhln1RCNI4YkhwO1seREj9aQN8Mppvibb49Z jOVrRa3oPwFUIcsE3uk4a4UFACsexxWvySEvFaTH896xOh3PZJ1Pcz65RFbI4MNoOFgdcef7cxeYH CyTyqP5TNSqgDJGLY1PgtgitIY/h51WPvraJXXTAAUxX5+sTn+wR9Rx8NgdfdrXhG8Y7P5LoSaF6E y73adTUMw==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPu-0007ZP-Tg; Thu, 02 Aug 2018 17:29:39 +0000 Message-Id: <977a5c8f438ce013f26a2074d2b327413b032252.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 23/30] discover/powerpc: Switch to new param_list To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:38 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 201 ++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 149 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 87ff72e..b5e4a8e 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -27,15 +28,8 @@ static const char *partition = "common"; static const char *sysparams_dir = "/sys/firmware/opal/sysparams/"; static const char *devtree_dir = "/proc/device-tree/"; -struct param { - char *name; - char *value; - bool modified; - struct list_item list; -}; - struct platform_powerpc { - struct list params; + struct param_list params; struct ipmi *ipmi; bool ipmi_bootdev_persistent; int (*get_ipmi_bootdev)( @@ -49,39 +43,9 @@ struct platform_powerpc { void (*get_platform_versions)(struct system_info *info); }; -static const char *known_params[] = { - "auto-boot?", - "petitboot,network", - "petitboot,timeout", - "petitboot,bootdevs", - "petitboot,language", - "petitboot,debug?", - "petitboot,write?", - "petitboot,snapshots?", - "petitboot,console", - "petitboot,http_proxy", - "petitboot,https_proxy", - NULL, -}; - #define to_platform_powerpc(p) \ (struct platform_powerpc *)(p->platform_data) -static bool param_is_known(const char *param, unsigned int len) -{ - const char *known_param; - unsigned int i; - - for (i = 0; known_params[i]; i++) { - known_param = known_params[i]; - if (len == strlen(known_param) && - !strncmp(param, known_param, len)) - return true; - } - - return false; -} - static int parse_nvram_params(struct platform_powerpc *platform, char *buf, int len) { @@ -110,7 +74,6 @@ static int parse_nvram_params(struct platform_powerpc *platform, for (pos = buf + i; pos < buf + len; pos += paramlen + 1) { unsigned int namelen; - struct param *param; char *newline; newline = strchr(pos, '\n'); @@ -130,16 +93,12 @@ static int parse_nvram_params(struct platform_powerpc *platform, if (namelen == 0) continue; - if (!param_is_known(name, namelen)) + if (!param_list_is_known_n(&platform->params, name, namelen)) continue; value++; - param = talloc(platform, struct param); - param->modified = false; - param->name = talloc_strndup(platform, name, namelen); - param->value = talloc_strdup(platform, value); - list_add(&platform->params, ¶m->list); + param_list_set(&platform->params, name, value, false); } return 0; @@ -189,7 +148,7 @@ static int write_nvram(struct platform_powerpc *platform) process->path = "nvram"; process->argv = argv; - list_for_each_entry(&platform->params, param, list) { + param_list_for_each(&platform->params, param) { char *paramstr; if (!param->modified) @@ -215,43 +174,6 @@ static int write_nvram(struct platform_powerpc *platform) return rc; } -static const char *get_param(struct platform_powerpc *platform, - const char *name) -{ - struct param *param; - - list_for_each_entry(&platform->params, param, list) - if (!strcmp(param->name, name)) - return param->value; - return NULL; -} - -static void set_param(struct platform_powerpc *platform, const char *name, - const char *value) -{ - struct param *param; - - list_for_each_entry(&platform->params, param, list) { - if (strcmp(param->name, name)) - continue; - - if (!strcmp(param->value, value)) - return; - - talloc_free(param->value); - param->value = talloc_strdup(param, value); - param->modified = true; - return; - } - - - param = talloc(platform, struct param); - param->modified = true; - param->name = talloc_strdup(platform, name); - param->value = talloc_strdup(platform, value); - list_add(&platform->params, ¶m->list); -} - static int parse_hwaddr(struct interface_config *ifconf, char *str) { int i; @@ -277,8 +199,7 @@ static int parse_hwaddr(struct interface_config *ifconf, char *str) return 0; } -static int parse_one_interface_config(struct config *config, - char *confstr) +static int parse_one_interface_config(struct config *config, char *confstr) { struct interface_config *ifconf; char *tok, *tok_gw, *tok_url, *saveptr; @@ -352,8 +273,7 @@ out_err: return -1; } -static int parse_one_dns_config(struct config *config, - char *confstr) +static int parse_one_dns_config(struct config *config, char *confstr) { char *tok, *saveptr = NULL; @@ -373,14 +293,11 @@ static int parse_one_dns_config(struct config *config, return 0; } -static void populate_network_config(struct platform_powerpc *platform, - struct config *config) +static void populate_network_config(struct config *config, const char *cval) { char *val, *saveptr = NULL; - const char *cval; int i; - cval = get_param(platform, "petitboot,network"); if (!cval || !strlen(cval)) return; @@ -445,8 +362,8 @@ static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt) return rc; } -static void populate_bootdev_config(struct platform_powerpc *platform, - struct config *config) +static void populate_bootdev_config(struct config *config, + const struct param_list *pl) { struct autoboot_option *opt, *new = NULL; char *pos, *end; @@ -454,7 +371,7 @@ static void populate_bootdev_config(struct platform_powerpc *platform, const char *val; /* Check for ordered bootdevs */ - val = get_param(platform, "petitboot,bootdevs"); + val = param_list_get_value(pl, "petitboot,bootdevs"); if (!val || !strlen(val)) { pos = end = NULL; } else { @@ -494,8 +411,7 @@ static void populate_bootdev_config(struct platform_powerpc *platform, config->n_autoboot_opts = n_new; } -static void populate_config(struct platform_powerpc *platform, - struct config *config) +static void populate_config(struct config *config, const struct param_list *pl) { const char *val; char *end; @@ -503,10 +419,10 @@ static void populate_config(struct platform_powerpc *platform, /* if the "auto-boot?' property is present and "false", disable auto * boot */ - val = get_param(platform, "auto-boot?"); + val = param_list_get_value(pl, "auto-boot?"); config->autoboot_enabled = !val || strcmp(val, "false"); - val = get_param(platform, "petitboot,timeout"); + val = param_list_get_value(pl, "petitboot,timeout"); if (val) { timeout = strtoul(val, &end, 10); if (end != val) { @@ -516,37 +432,38 @@ static void populate_config(struct platform_powerpc *platform, } } - val = get_param(platform, "petitboot,language"); + val = param_list_get_value(pl, "petitboot,language"); config->lang = val ? talloc_strdup(config, val) : NULL; - populate_network_config(platform, config); + val = param_list_get_value(pl, "petitboot,network"); + populate_network_config(config, val); - populate_bootdev_config(platform, config); + populate_bootdev_config(config, pl); if (!config->debug) { - val = get_param(platform, "petitboot,debug?"); + val = param_list_get_value(pl, "petitboot,debug?"); config->debug = val && !strcmp(val, "true"); } - val = get_param(platform, "petitboot,write?"); + val = param_list_get_value(pl, "petitboot,write?"); if (val) config->allow_writes = !strcmp(val, "true"); - val = get_param(platform, "petitboot,snapshots?"); + val = param_list_get_value(pl, "petitboot,snapshots?"); if (val) config->disable_snapshots = !strcmp(val, "false"); - val = get_param(platform, "petitboot,console"); + val = param_list_get_value(pl, "petitboot,console"); if (val) config->boot_console = talloc_strdup(config, val); /* If a full path is already set we don't want to override it */ config->manual_console = config->boot_console && !strchr(config->boot_console, '['); - val = get_param(platform, "petitboot,http_proxy"); + val = param_list_get_value(pl, "petitboot,http_proxy"); if (val) config->http_proxy = talloc_strdup(config, val); - val = get_param(platform, "petitboot,https_proxy"); + val = param_list_get_value(pl, "petitboot,https_proxy"); if (val) config->https_proxy = talloc_strdup(config, val); } @@ -594,22 +511,8 @@ static char *dns_config_str(void *ctx, const char **dns_servers, int n) return str; } -static void update_string_config(struct platform_powerpc *platform, - const char *name, const char *value) -{ - const char *cur; - - cur = get_param(platform, name); - - /* don't set an empty parameter if it doesn't already exist */ - if (!cur && !strlen(value)) - return; - - set_param(platform, name, value); -} - -static void update_network_config(struct platform_powerpc *platform, - const char *param_name, const struct config *config) +static void update_network_config(struct param_list *pl, const char *param_name, + const struct config *config) { unsigned int i; char *val; @@ -623,10 +526,10 @@ static void update_network_config(struct platform_powerpc *platform, config->network.interfaces[0]->override) return; - val = talloc_strdup(platform, ""); + val = talloc_strdup(pl, ""); for (i = 0; i < config->network.n_interfaces; i++) { - char *iface_str = iface_config_str(platform, + char *iface_str = iface_config_str(pl, config->network.interfaces[i]); val = talloc_asprintf_append(val, "%s%s", *val == '\0' ? "" : " ", iface_str); @@ -634,7 +537,7 @@ static void update_network_config(struct platform_powerpc *platform, } if (config->network.n_dns_servers) { - char *dns_str = dns_config_str(platform, + char *dns_str = dns_config_str(pl, config->network.dns_servers, config->network.n_dns_servers); val = talloc_asprintf_append(val, "%s%s", @@ -642,13 +545,12 @@ static void update_network_config(struct platform_powerpc *platform, talloc_free(dns_str); } - update_string_config(platform, param_name, val); - + param_list_set_non_empty(pl, param_name, val, true); talloc_free(val); } -static void update_bootdev_config(struct platform_powerpc *platform, - const char *param_name, const struct config *config) +static void update_bootdev_config(struct param_list *pl, const char *param_name, + const struct config *config) { char *val = NULL, *boot_str = NULL, *tmp = NULL; struct autoboot_option *opt; @@ -674,14 +576,14 @@ static void update_bootdev_config(struct platform_powerpc *platform, tmp = val = talloc_asprintf_append(val, "%s", boot_str); } - update_string_config(platform, param_name, val); + param_list_set_non_empty(pl, param_name, val, true); talloc_free(tmp); if (boot_str) talloc_free(boot_str); } -static void update_config(struct platform_powerpc *platform, - struct config *config, struct config *defaults) +static void update_config(struct param_list *pl, struct config *config, + const struct config *defaults) { char *tmp = NULL; const char *val; @@ -690,40 +592,40 @@ static void update_config(struct platform_powerpc *platform, val = ""; else val = config->autoboot_enabled ? "true" : "false"; - update_string_config(platform, "auto-boot?", val); + + param_list_set_non_empty(pl, "auto-boot?", val, true); if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec) val = ""; else - val = tmp = talloc_asprintf(platform, "%d", - config->autoboot_timeout_sec); + val = tmp = talloc_asprintf(pl, "%d", + config->autoboot_timeout_sec); - update_string_config(platform, "petitboot,timeout", val); + param_list_set_non_empty(pl, "petitboot,timeout", val, true); if (tmp) talloc_free(tmp); val = config->lang ?: ""; - update_string_config(platform, "petitboot,language", val); + param_list_set_non_empty(pl, "petitboot,language", val, true); if (config->allow_writes == defaults->allow_writes) val = ""; else val = config->allow_writes ? "true" : "false"; - update_string_config(platform, "petitboot,write?", val); + param_list_set_non_empty(pl, "petitboot,write?", val, true); if (!config->manual_console) { val = config->boot_console ?: ""; - update_string_config(platform, "petitboot,console", val); + param_list_set_non_empty(pl, "petitboot,console", val, true); } val = config->http_proxy ?: ""; - update_string_config(platform, "petitboot,http_proxy", val); + param_list_set_non_empty(pl, "petitboot,http_proxy", val, true); val = config->https_proxy ?: ""; - update_string_config(platform, "petitboot,https_proxy", val); - - update_network_config(platform, "petitboot,network", config); + param_list_set_non_empty(pl, "petitboot,https_proxy", val, true); - update_bootdev_config(platform, "petitboot,bootdevs", config); + update_network_config(pl, "petitboot,network", config); + update_bootdev_config(pl, "petitboot,bootdevs", config); } static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, @@ -1071,7 +973,8 @@ static void get_ipmi_network_override(struct platform_powerpc *platform, if (!rc && persistent) { /* Write this new config to NVRAM */ - update_network_config(platform, "petitboot,network", config); + update_network_config(&platform->params, "petitboot,network", + config); rc = write_nvram(platform); if (rc) pb_log("platform: Failed to save persistent interface override\n"); @@ -1120,7 +1023,7 @@ static int load_config(struct platform *p, struct config *config) if (rc) pb_log_fn("Failed to parse nvram\n"); - populate_config(platform, config); + populate_config(config, &platform->params); if (platform->get_ipmi_bootdev) { bool bootdev_persistent; @@ -1156,7 +1059,7 @@ static int save_config(struct platform *p, struct config *config) defaults = talloc_zero(platform, struct config); config_set_defaults(defaults); - update_config(platform, config, defaults); + update_config(&platform->params, config, defaults); talloc_free(defaults); return write_nvram(platform); @@ -1220,7 +1123,7 @@ static bool probe(struct platform *p, void *ctx) return false; platform = talloc_zero(ctx, struct platform_powerpc); - list_init(&platform->params); + param_list_init(&platform->params, common_known_params()); p->platform_data = platform; From patchwork Thu Aug 2 17:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952924 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMC0DgXz9s2g for ; Fri, 3 Aug 2018 03:33:11 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="A8HsD4ph"; 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 41hHMB5j1mzF2D8 for ; Fri, 3 Aug 2018 03:33:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="A8HsD4ph"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="A8HsD4ph"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHC0GttzF22V for ; Fri, 3 Aug 2018 03:29:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=V8WTnAm5xTs8KSZf5dxdjmP7hwrX0ECzYhA1ujUirdk=; b=A8HsD4phsFKp1SR827o3CJBx7 CwZPx4/+Z7Xo8zzsEhOwaE2j6IrnNaQEToeHWzbgDW01ZZle/32HBhROJZQb6DJZExYRAHMpxj8GC YhniGkIeuYJzknddrDgMKFM2eLFj4GwpwOUk1bwJINtMWoE1mLaeS7LZzt1doMh0TcLEAN5WlI8b3 kiOm0EFu6pdULglRqtKKXgovWNZrukFLgNPJyTct+s7/UMafusxW3evkR8pEQo8MiGd/EoM+cLLVg /IkgKTvyNg1DQ7hzHc4Mvjp95ntyolDLi/lghompbFNuvFLI4WfbEtKzsKIDxOT0NoAj3mMAy//i3 +KpPUsMgQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPv-0007ZY-A5; Thu, 02 Aug 2018 17:29:39 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 24/30] discover: Move generic config routines to platform To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:39 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Move the generic config routines from platform-powerpc to platform. Also, for clarity, add a config_ prefix to the names. Signed-off-by: Ge Song [Split from a larger patch and cleaned up] Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 315 ++------------------------------------------ discover/platform.c | 299 ++++++++++++++++++++++++++++++++++++++++- discover/platform.h | 6 +- 3 files changed, 311 insertions(+), 309 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index b5e4a8e..a96f5d5 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -14,10 +13,7 @@ #include #include #include -#include #include -#include -#include #include "hostboot.h" #include "platform.h" @@ -174,301 +170,7 @@ static int write_nvram(struct platform_powerpc *platform) return rc; } -static int parse_hwaddr(struct interface_config *ifconf, char *str) -{ - int i; - - if (strlen(str) != strlen("00:00:00:00:00:00")) - return -1; - - for (i = 0; i < HWADDR_SIZE; i++) { - char byte[3], *endp; - unsigned long x; - - byte[0] = str[i * 3 + 0]; - byte[1] = str[i * 3 + 1]; - byte[2] = '\0'; - - x = strtoul(byte, &endp, 16); - if (endp != byte + 2) - return -1; - - ifconf->hwaddr[i] = x & 0xff; - } - - return 0; -} - -static int parse_one_interface_config(struct config *config, char *confstr) -{ - struct interface_config *ifconf; - char *tok, *tok_gw, *tok_url, *saveptr; - - ifconf = talloc_zero(config, struct interface_config); - - if (!confstr || !strlen(confstr)) - goto out_err; - - /* first token should be the mac address */ - tok = strtok_r(confstr, ",", &saveptr); - if (!tok) - goto out_err; - - if (parse_hwaddr(ifconf, tok)) - goto out_err; - - /* second token is the method */ - tok = strtok_r(NULL, ",", &saveptr); - if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) { - ifconf->ignore = true; - - } else if (!strcmp(tok, "dhcp")) { - ifconf->method = CONFIG_METHOD_DHCP; - - } else if (!strcmp(tok, "static")) { - ifconf->method = CONFIG_METHOD_STATIC; - - /* ip/mask, [optional] gateway, [optional] url */ - tok = strtok_r(NULL, ",", &saveptr); - if (!tok) - goto out_err; - ifconf->static_config.address = - talloc_strdup(ifconf, tok); - - /* - * If a url is set but not a gateway, we can accidentally - * interpret the url as the gateway. To avoid changing the - * parameter format check if the "gateway" is actually a - * pb-url if it's the last token. - */ - tok_gw = strtok_r(NULL, ",", &saveptr); - tok_url = strtok_r(NULL, ",", &saveptr); - - if (tok_gw) { - if (tok_url || !is_url(tok_gw)) - ifconf->static_config.gateway = - talloc_strdup(ifconf, tok_gw); - else - tok_url = tok_gw; - } - - if (tok_url) - ifconf->static_config.url = - talloc_strdup(ifconf, tok_url); - } else { - pb_log("Unknown network configuration method %s\n", tok); - goto out_err; - } - - config->network.interfaces = talloc_realloc(config, - config->network.interfaces, - struct interface_config *, - ++config->network.n_interfaces); - - config->network.interfaces[config->network.n_interfaces - 1] = ifconf; - - return 0; -out_err: - talloc_free(ifconf); - return -1; -} - -static int parse_one_dns_config(struct config *config, char *confstr) -{ - char *tok, *saveptr = NULL; - - for (tok = strtok_r(confstr, ",", &saveptr); tok; - tok = strtok_r(NULL, ",", &saveptr)) { - - char *server = talloc_strdup(config, tok); - - config->network.dns_servers = talloc_realloc(config, - config->network.dns_servers, const char *, - ++config->network.n_dns_servers); - - config->network.dns_servers[config->network.n_dns_servers - 1] - = server; - } - - return 0; -} - -static void populate_network_config(struct config *config, const char *cval) -{ - char *val, *saveptr = NULL; - int i; - - if (!cval || !strlen(cval)) - return; - - val = talloc_strdup(config, cval); - - for (i = 0; ; i++) { - char *tok; - - tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr); - if (!tok) - break; - - if (!strncasecmp(tok, "dns,", strlen("dns,"))) - parse_one_dns_config(config, tok + strlen("dns,")); - else - parse_one_interface_config(config, tok); - - } - - talloc_free(val); -} - -static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt) -{ - char *delim = strchr(*pos, ' '); - int len, prefix = 0, rc = -1; - enum device_type type; - - if (!strncmp(*pos, "uuid:", strlen("uuid:"))) { - prefix = strlen("uuid:"); - opt->boot_type = BOOT_DEVICE_UUID; - } else if (!strncmp(*pos, "mac:", strlen("mac:"))) { - prefix = strlen("mac:"); - opt->boot_type = BOOT_DEVICE_UUID; - } else { - type = find_device_type(*pos); - if (type != DEVICE_TYPE_UNKNOWN) { - opt->type = type; - opt->boot_type = BOOT_DEVICE_TYPE; - rc = 0; - } - } - - if (opt->boot_type == BOOT_DEVICE_UUID) { - if (delim) - len = (int)(delim - *pos) - prefix; - else - len = strlen(*pos) - prefix; - - if (len) { - opt->uuid = talloc_strndup(ctx, *pos + prefix, len); - rc = 0; - } - } - - /* Always advance pointer to next option or end */ - if (delim) - *pos = delim + 1; - else - *pos += strlen(*pos); - - return rc; -} - -static void populate_bootdev_config(struct config *config, - const struct param_list *pl) -{ - struct autoboot_option *opt, *new = NULL; - char *pos, *end; - unsigned int n_new = 0; - const char *val; - - /* Check for ordered bootdevs */ - val = param_list_get_value(pl, "petitboot,bootdevs"); - if (!val || !strlen(val)) { - pos = end = NULL; - } else { - pos = talloc_strdup(config, val); - end = strchr(pos, '\0'); - } - - while (pos && pos < end) { - opt = talloc(config, struct autoboot_option); - - if (read_bootdev(config, &pos, opt)) { - pb_log("bootdev config is in an unknown format " - "(expected uuid:... or mac:...)\n"); - talloc_free(opt); - continue; - } - - new = talloc_realloc(config, new, struct autoboot_option, - n_new + 1); - new[n_new] = *opt; - n_new++; - talloc_free(opt); - - } - - if (!n_new) { - /* If autoboot has been disabled, clear the default options */ - if (!config->autoboot_enabled) { - talloc_free(config->autoboot_opts); - config->n_autoboot_opts = 0; - } - return; - } - - talloc_free(config->autoboot_opts); - config->autoboot_opts = new; - config->n_autoboot_opts = n_new; -} - -static void populate_config(struct config *config, const struct param_list *pl) -{ - const char *val; - char *end; - unsigned long timeout; - - /* if the "auto-boot?' property is present and "false", disable auto - * boot */ - val = param_list_get_value(pl, "auto-boot?"); - config->autoboot_enabled = !val || strcmp(val, "false"); - - val = param_list_get_value(pl, "petitboot,timeout"); - if (val) { - timeout = strtoul(val, &end, 10); - if (end != val) { - if (timeout >= INT_MAX) - timeout = INT_MAX; - config->autoboot_timeout_sec = (int)timeout; - } - } - - val = param_list_get_value(pl, "petitboot,language"); - config->lang = val ? talloc_strdup(config, val) : NULL; - - val = param_list_get_value(pl, "petitboot,network"); - populate_network_config(config, val); - - populate_bootdev_config(config, pl); - - if (!config->debug) { - val = param_list_get_value(pl, "petitboot,debug?"); - config->debug = val && !strcmp(val, "true"); - } - - val = param_list_get_value(pl, "petitboot,write?"); - if (val) - config->allow_writes = !strcmp(val, "true"); - - val = param_list_get_value(pl, "petitboot,snapshots?"); - if (val) - config->disable_snapshots = !strcmp(val, "false"); - - val = param_list_get_value(pl, "petitboot,console"); - if (val) - config->boot_console = talloc_strdup(config, val); - /* If a full path is already set we don't want to override it */ - config->manual_console = config->boot_console && - !strchr(config->boot_console, '['); - - val = param_list_get_value(pl, "petitboot,http_proxy"); - if (val) - config->http_proxy = talloc_strdup(config, val); - val = param_list_get_value(pl, "petitboot,https_proxy"); - if (val) - config->https_proxy = talloc_strdup(config, val); -} - -static char *iface_config_str(void *ctx, struct interface_config *config) +static char *interface_config_str(void *ctx, struct interface_config *config) { char *str; @@ -529,7 +231,7 @@ static void update_network_config(struct param_list *pl, const char *param_name, val = talloc_strdup(pl, ""); for (i = 0; i < config->network.n_interfaces; i++) { - char *iface_str = iface_config_str(pl, + char *iface_str = interface_config_str(pl, config->network.interfaces[i]); val = talloc_asprintf_append(val, "%s%s", *val == '\0' ? "" : " ", iface_str); @@ -546,6 +248,7 @@ static void update_network_config(struct param_list *pl, const char *param_name, } param_list_set_non_empty(pl, param_name, val, true); + talloc_free(val); } @@ -577,6 +280,7 @@ static void update_bootdev_config(struct param_list *pl, const char *param_name, } param_list_set_non_empty(pl, param_name, val, true); + talloc_free(tmp); if (boot_str) talloc_free(boot_str); @@ -628,7 +332,7 @@ static void update_config(struct param_list *pl, struct config *config, update_bootdev_config(pl, "petitboot,bootdevs", config); } -static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, +static void config_set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, bool persistent) { config->ipmi_bootdev = bootdev; @@ -981,7 +685,7 @@ static void get_ipmi_network_override(struct platform_powerpc *platform, } } -static void get_active_consoles(struct config *config) +static void config_get_active_consoles(struct config *config) { struct stat sbuf; char *fsp_prop = NULL; @@ -1023,7 +727,7 @@ static int load_config(struct platform *p, struct config *config) if (rc) pb_log_fn("Failed to parse nvram\n"); - populate_config(config, &platform->params); + config_populate_all(config, &platform->params); if (platform->get_ipmi_bootdev) { bool bootdev_persistent; @@ -1031,14 +735,15 @@ static int load_config(struct platform *p, struct config *config) rc = platform->get_ipmi_bootdev(platform, &bootdev, &bootdev_persistent); if (!rc && ipmi_bootdev_is_valid(bootdev)) { - set_ipmi_bootdev(config, bootdev, bootdev_persistent); + config_set_ipmi_bootdev(config, bootdev, + bootdev_persistent); } } if (platform->ipmi) get_ipmi_network_override(platform, config); - get_active_consoles(config); + config_get_active_consoles(config); return 0; } diff --git a/discover/platform.c b/discover/platform.c index e69c6f6..2ac2de2 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -2,13 +2,16 @@ #define _GNU_SOURCE #include -#include +#include #include +#include +#include #include #include #include #include +#include #include "platform.h" @@ -263,3 +266,297 @@ int platform_fini(void) talloc_free(platform_ctx); return 0; } + +static int parse_hwaddr(struct interface_config *ifconf, const char *str) +{ + int i; + + if (strlen(str) != strlen("00:00:00:00:00:00")) + return -1; + + for (i = 0; i < HWADDR_SIZE; i++) { + char byte[3], *endp; + unsigned long x; + + byte[0] = str[i * 3 + 0]; + byte[1] = str[i * 3 + 1]; + byte[2] = '\0'; + + x = strtoul(byte, &endp, 16); + if (endp != byte + 2) + return -1; + + ifconf->hwaddr[i] = x & 0xff; + } + + return 0; +} + +static int config_parse_one_interface(struct config *config, char *confstr) +{ + struct interface_config *ifconf; + char *tok, *tok_gw, *tok_url, *saveptr; + + ifconf = talloc_zero(config, struct interface_config); + + if (!confstr || !strlen(confstr)) + goto out_err; + + /* first token should be the mac address */ + tok = strtok_r(confstr, ",", &saveptr); + if (!tok) + goto out_err; + + if (parse_hwaddr(ifconf, tok)) + goto out_err; + + /* second token is the method */ + tok = strtok_r(NULL, ",", &saveptr); + if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) { + ifconf->ignore = true; + + } else if (!strcmp(tok, "dhcp")) { + ifconf->method = CONFIG_METHOD_DHCP; + + } else if (!strcmp(tok, "static")) { + ifconf->method = CONFIG_METHOD_STATIC; + + /* ip/mask, [optional] gateway, [optional] url */ + tok = strtok_r(NULL, ",", &saveptr); + if (!tok) + goto out_err; + ifconf->static_config.address = + talloc_strdup(ifconf, tok); + + /* + * If a url is set but not a gateway, we can accidentally + * interpret the url as the gateway. To avoid changing the + * parameter format check if the "gateway" is actually a + * pb-url if it's the last token. + */ + tok_gw = strtok_r(NULL, ",", &saveptr); + tok_url = strtok_r(NULL, ",", &saveptr); + + if (tok_gw) { + if (tok_url || !is_url(tok_gw)) + ifconf->static_config.gateway = + talloc_strdup(ifconf, tok_gw); + else + tok_url = tok_gw; + } + + if (tok_url) + ifconf->static_config.url = + talloc_strdup(ifconf, tok_url); + } else { + pb_log("Unknown network configuration method %s\n", tok); + goto out_err; + } + + config->network.interfaces = talloc_realloc(config, + config->network.interfaces, + struct interface_config *, + ++config->network.n_interfaces); + + config->network.interfaces[config->network.n_interfaces - 1] = ifconf; + + return 0; +out_err: + talloc_free(ifconf); + return -1; +} + +static int config_parse_one_dns(struct config *config, char *confstr) +{ + char *tok, *saveptr = NULL; + + for (tok = strtok_r(confstr, ",", &saveptr); tok; + tok = strtok_r(NULL, ",", &saveptr)) { + + char *server = talloc_strdup(config, tok); + + config->network.dns_servers = talloc_realloc(config, + config->network.dns_servers, const char *, + ++config->network.n_dns_servers); + + config->network.dns_servers[config->network.n_dns_servers - 1] + = server; + } + + return 0; +} + +static void config_populate_network(struct config *config, const char *cval) +{ + char *val, *saveptr = NULL; + int i; + + if (!cval || !strlen(cval)) + return; + + val = talloc_strdup(config, cval); + + for (i = 0; ; i++) { + char *tok; + + tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr); + if (!tok) + break; + + if (!strncasecmp(tok, "dns,", strlen("dns,"))) + config_parse_one_dns(config, tok + strlen("dns,")); + else + config_parse_one_interface(config, tok); + + } + + talloc_free(val); +} + +static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt) +{ + char *delim = strchr(*pos, ' '); + int len, prefix = 0, rc = -1; + enum device_type type; + + if (!strncmp(*pos, "uuid:", strlen("uuid:"))) { + prefix = strlen("uuid:"); + opt->boot_type = BOOT_DEVICE_UUID; + } else if (!strncmp(*pos, "mac:", strlen("mac:"))) { + prefix = strlen("mac:"); + opt->boot_type = BOOT_DEVICE_UUID; + } else { + type = find_device_type(*pos); + if (type != DEVICE_TYPE_UNKNOWN) { + opt->type = type; + opt->boot_type = BOOT_DEVICE_TYPE; + rc = 0; + } + } + + if (opt->boot_type == BOOT_DEVICE_UUID) { + if (delim) + len = (int)(delim - *pos) - prefix; + else + len = strlen(*pos) - prefix; + + if (len) { + opt->uuid = talloc_strndup(ctx, *pos + prefix, len); + rc = 0; + } + } + + /* Always advance pointer to next option or end */ + if (delim) + *pos = delim + 1; + else + *pos += strlen(*pos); + + return rc; +} + +static void config_populate_bootdev(struct config *config, + const struct param_list *pl) +{ + struct autoboot_option *opt, *new = NULL; + char *pos, *end; + unsigned int n_new = 0; + const char *val; + + /* Check for ordered bootdevs */ + val = param_list_get_value(pl, "petitboot,bootdevs"); + if (!val || !strlen(val)) { + pos = end = NULL; + } else { + pos = talloc_strdup(config, val); + end = strchr(pos, '\0'); + } + + while (pos && pos < end) { + opt = talloc(config, struct autoboot_option); + + if (read_bootdev(config, &pos, opt)) { + pb_log("bootdev config is in an unknown format " + "(expected uuid:... or mac:...)\n"); + talloc_free(opt); + continue; + } + + new = talloc_realloc(config, new, struct autoboot_option, + n_new + 1); + new[n_new] = *opt; + n_new++; + talloc_free(opt); + + } + + if (!n_new) { + /* If autoboot has been disabled, clear the default options */ + if (!config->autoboot_enabled) { + talloc_free(config->autoboot_opts); + config->n_autoboot_opts = 0; + } + return; + } + + talloc_free(config->autoboot_opts); + config->autoboot_opts = new; + config->n_autoboot_opts = n_new; +} + +void config_populate_all(struct config *config, const struct param_list *pl) +{ + const char *val; + char *end; + unsigned long timeout; + + /* if the "auto-boot?' property is present and "false", disable auto + * boot */ + val = param_list_get_value(pl, "auto-boot?"); + config->autoboot_enabled = !val || strcmp(val, "false"); + + val = param_list_get_value(pl, "petitboot,timeout"); + if (val) { + timeout = strtoul(val, &end, 10); + if (end != val) { + if (timeout >= INT_MAX) + timeout = INT_MAX; + config->autoboot_timeout_sec = (int)timeout; + } + } + + val = param_list_get_value(pl, "petitboot,language"); + config->lang = val ? talloc_strdup(config, val) : NULL; + + val = param_list_get_value(pl, "petitboot,network"); + config_populate_network(config, val); + + config_populate_bootdev(config, pl); + + if (!config->debug) { + val = param_list_get_value(pl, "petitboot,debug?"); + config->debug = val && !strcmp(val, "true"); + } + + val = param_list_get_value(pl, "petitboot,write?"); + if (val) + config->allow_writes = !strcmp(val, "true"); + + val = param_list_get_value(pl, "petitboot,snapshots?"); + if (val) + config->disable_snapshots = !strcmp(val, "false"); + + val = param_list_get_value(pl, "petitboot,console"); + if (val) + config->boot_console = talloc_strdup(config, val); + /* If a full path is already set we don't want to override it */ + config->manual_console = config->boot_console && + !strchr(config->boot_console, '['); + + val = param_list_get_value(pl, "petitboot,http_proxy"); + if (val) + config->http_proxy = talloc_strdup(config, val); + val = param_list_get_value(pl, "petitboot,https_proxy"); + if (val) + config->https_proxy = talloc_strdup(config, val); +} diff --git a/discover/platform.h b/discover/platform.h index 5aa8e3f..a9ea79b 100644 --- a/discover/platform.h +++ b/discover/platform.h @@ -2,6 +2,7 @@ #define PLATFORM_H #include +#include struct platform { const char *name; @@ -24,10 +25,9 @@ void platform_pre_boot(void); /* configuration interface */ const struct config *config_get(void); int config_set(struct config *config); -void config_set_autoboot(bool autoboot_enabled); - -/* for use by the platform-specific storage code */ void config_set_defaults(struct config *config); +void config_set_autoboot(bool autoboot_enabled); +void config_populate_all(struct config *config, const struct param_list *pl); #define __platform_ptrname(_n) __platform_ ## _n #define _platform_ptrname(_n) __platform_ptrname(_n) From patchwork Thu Aug 2 17:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952925 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMM0N4vz9s2g for ; Fri, 3 Aug 2018 03:33:19 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="e130YGGX"; 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 41hHML5vnJzF2DY for ; Fri, 3 Aug 2018 03:33:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="e130YGGX"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="e130YGGX"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHC2pg3zF27G for ; Fri, 3 Aug 2018 03:29:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1bjjJnfCxuen2ADbRmY0SCf0ElSeh1wlZT2iXz+HS64=; b=e130YGGXBKq9shc+q2OIFdpD6 N/1JPET3NSW/8wc00ttHTere+FSCA0WPL6c0JmxIPKJ0NbJeGPgT3Utf/138Ow0/Ymm1z+9keQmdF L4hVQjjD9HbbpedVj05Qug0C2UOrzlzDfUNhfiOO60/ufaZ0316JLHG2yKGaoR5q/exol/JE9HoPk KdQozqdbFOhDwcjqdtG/zo0EaegN6UpNDPAa/yaFQc6ybkaCm9hVlF2QEhkNAElLTahr4l+CGR2GI J7NHjfdV9EvXbgGyNkR6J3UHB1QbnIinU97BwF0YXF2xPvzcCd/ZDct9BBngLIsFSk2lJmQEsdSAI L8+wqnGMg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPv-0007Zh-KH; Thu, 02 Aug 2018 17:29:39 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 25/30] discover: Move generic params routines to platform To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:39 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Move the generic params routines from platform-powerpc to platform. Also, for clarity, add a params prefix to the names. Signed-off-by: Ge Song [Split from a larger patch and cleaned up] Signed-off-by: Geoff Levand --- discover/platform-powerpc.c | 130 +++----------------------------------------- discover/platform.c | 117 +++++++++++++++++++++++++++++++++++++++ discover/platform.h | 5 ++ 3 files changed, 129 insertions(+), 123 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index a96f5d5..b2f60e4 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -170,124 +170,8 @@ static int write_nvram(struct platform_powerpc *platform) return rc; } -static char *interface_config_str(void *ctx, struct interface_config *config) -{ - char *str; - - /* todo: HWADDR size is hardcoded as 6, but we may need to handle - * different hardware address formats */ - str = talloc_asprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x,", - config->hwaddr[0], config->hwaddr[1], - config->hwaddr[2], config->hwaddr[3], - config->hwaddr[4], config->hwaddr[5]); - - if (config->ignore) { - str = talloc_asprintf_append(str, "ignore"); - - } else if (config->method == CONFIG_METHOD_DHCP) { - str = talloc_asprintf_append(str, "dhcp"); - - } else if (config->method == CONFIG_METHOD_STATIC) { - str = talloc_asprintf_append(str, "static,%s%s%s%s%s", - config->static_config.address, - config->static_config.gateway ? "," : "", - config->static_config.gateway ?: "", - config->static_config.url ? "," : "", - config->static_config.url ?: ""); - } - return str; -} - -static char *dns_config_str(void *ctx, const char **dns_servers, int n) -{ - char *str; - int i; - - str = talloc_strdup(ctx, "dns,"); - for (i = 0; i < n; i++) { - str = talloc_asprintf_append(str, "%s%s", - i == 0 ? "" : ",", - dns_servers[i]); - } - - return str; -} - -static void update_network_config(struct param_list *pl, const char *param_name, - const struct config *config) -{ - unsigned int i; - char *val; - - /* - * Don't store IPMI overrides to NVRAM. If this was a persistent - * override it was already stored in NVRAM by - * get_ipmi_network_override() - */ - if (config->network.n_interfaces && - config->network.interfaces[0]->override) - return; - - val = talloc_strdup(pl, ""); - - for (i = 0; i < config->network.n_interfaces; i++) { - char *iface_str = interface_config_str(pl, - config->network.interfaces[i]); - val = talloc_asprintf_append(val, "%s%s", - *val == '\0' ? "" : " ", iface_str); - talloc_free(iface_str); - } - - if (config->network.n_dns_servers) { - char *dns_str = dns_config_str(pl, - config->network.dns_servers, - config->network.n_dns_servers); - val = talloc_asprintf_append(val, "%s%s", - *val == '\0' ? "" : " ", dns_str); - talloc_free(dns_str); - } - - param_list_set_non_empty(pl, param_name, val, true); - - talloc_free(val); -} - -static void update_bootdev_config(struct param_list *pl, const char *param_name, - const struct config *config) -{ - char *val = NULL, *boot_str = NULL, *tmp = NULL; - struct autoboot_option *opt; - const char delim = ' '; - unsigned int i; - - if (!config->n_autoboot_opts) - val = ""; - - for (i = 0; i < config->n_autoboot_opts; i++) { - opt = &config->autoboot_opts[i]; - switch (opt->boot_type) { - case BOOT_DEVICE_TYPE: - boot_str = talloc_asprintf(config, "%s%c", - device_type_name(opt->type), - delim); - break; - case BOOT_DEVICE_UUID: - boot_str = talloc_asprintf(config, "uuid:%s%c", - opt->uuid, delim); - break; - } - tmp = val = talloc_asprintf_append(val, "%s", boot_str); - } - - param_list_set_non_empty(pl, param_name, val, true); - - talloc_free(tmp); - if (boot_str) - talloc_free(boot_str); -} - -static void update_config(struct param_list *pl, struct config *config, - const struct config *defaults) +static void params_update_all(struct param_list *pl, + const struct config *config, const struct config *defaults) { char *tmp = NULL; const char *val; @@ -328,8 +212,8 @@ static void update_config(struct param_list *pl, struct config *config, val = config->https_proxy ?: ""; param_list_set_non_empty(pl, "petitboot,https_proxy", val, true); - update_network_config(pl, "petitboot,network", config); - update_bootdev_config(pl, "petitboot,bootdevs", config); + params_update_network_values(pl, "petitboot,network", config); + params_update_bootdev_values(pl, "petitboot,bootdevs", config); } static void config_set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev, @@ -677,8 +561,8 @@ static void get_ipmi_network_override(struct platform_powerpc *platform, if (!rc && persistent) { /* Write this new config to NVRAM */ - update_network_config(&platform->params, "petitboot,network", - config); + params_update_network_values(&platform->params, + "petitboot,network", config); rc = write_nvram(platform); if (rc) pb_log("platform: Failed to save persistent interface override\n"); @@ -764,7 +648,7 @@ static int save_config(struct platform *p, struct config *config) defaults = talloc_zero(platform, struct config); config_set_defaults(defaults); - update_config(&platform->params, config, defaults); + params_update_all(&platform->params, config, defaults); talloc_free(defaults); return write_nvram(platform); diff --git a/discover/platform.c b/discover/platform.c index 2ac2de2..767f66e 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -560,3 +560,120 @@ void config_populate_all(struct config *config, const struct param_list *pl) if (val) config->https_proxy = talloc_strdup(config, val); } + +static char *interface_config_str(void *ctx, struct interface_config *config) +{ + char *str; + + /* todo: HWADDR size is hardcoded as 6, but we may need to handle + * different hardware address formats */ + str = talloc_asprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x,", + config->hwaddr[0], config->hwaddr[1], + config->hwaddr[2], config->hwaddr[3], + config->hwaddr[4], config->hwaddr[5]); + + if (config->ignore) { + str = talloc_asprintf_append(str, "ignore"); + + } else if (config->method == CONFIG_METHOD_DHCP) { + str = talloc_asprintf_append(str, "dhcp"); + + } else if (config->method == CONFIG_METHOD_STATIC) { + str = talloc_asprintf_append(str, "static,%s%s%s%s%s", + config->static_config.address, + config->static_config.gateway ? "," : "", + config->static_config.gateway ?: "", + config->static_config.url ? "," : "", + config->static_config.url ?: ""); + } + return str; +} + +static char *dns_config_str(void *ctx, const char **dns_servers, int n) +{ + char *str; + int i; + + str = talloc_strdup(ctx, "dns,"); + for (i = 0; i < n; i++) { + str = talloc_asprintf_append(str, "%s%s", + i == 0 ? "" : ",", + dns_servers[i]); + } + + return str; +} + +void params_update_network_values(struct param_list *pl, + const char *param_name, const struct config *config) +{ + unsigned int i; + char *val; + + /* + * Don't store IPMI overrides to NVRAM. If this was a persistent + * override it was already stored in NVRAM by + * get_ipmi_network_override() + */ + if (config->network.n_interfaces && + config->network.interfaces[0]->override) + return; + + val = talloc_strdup(pl, ""); + + for (i = 0; i < config->network.n_interfaces; i++) { + char *iface_str = interface_config_str(pl, + config->network.interfaces[i]); + val = talloc_asprintf_append(val, "%s%s", + *val == '\0' ? "" : " ", iface_str); + talloc_free(iface_str); + } + + if (config->network.n_dns_servers) { + char *dns_str = dns_config_str(pl, + config->network.dns_servers, + config->network.n_dns_servers); + val = talloc_asprintf_append(val, "%s%s", + *val == '\0' ? "" : " ", dns_str); + talloc_free(dns_str); + } + + param_list_set_non_empty(pl, param_name, val, true); + + talloc_free(val); +} + +void params_update_bootdev_values(struct param_list *pl, + const char *param_name, const struct config *config) +{ + char *val = NULL, *boot_str = NULL, *tmp = NULL; + struct autoboot_option *opt; + const char delim = ' '; + unsigned int i; + + if (!config->n_autoboot_opts) + val = ""; + + for (i = 0; i < config->n_autoboot_opts; i++) { + opt = &config->autoboot_opts[i]; + switch (opt->boot_type) { + case BOOT_DEVICE_TYPE: + boot_str = talloc_asprintf(config, "%s%c", + device_type_name(opt->type), + delim); + break; + case BOOT_DEVICE_UUID: + boot_str = talloc_asprintf(config, "uuid:%s%c", + opt->uuid, delim); + break; + } + tmp = val = talloc_asprintf_append(val, "%s", boot_str); + } + + param_list_set_non_empty(pl, param_name, val, true); + + talloc_free(tmp); + if (boot_str) + talloc_free(boot_str); +} + diff --git a/discover/platform.h b/discover/platform.h index a9ea79b..2940562 100644 --- a/discover/platform.h +++ b/discover/platform.h @@ -29,6 +29,11 @@ void config_set_defaults(struct config *config); void config_set_autoboot(bool autoboot_enabled); void config_populate_all(struct config *config, const struct param_list *pl); +void params_update_network_values(struct param_list *pl, + const char *param_name, const struct config *config); +void params_update_bootdev_values(struct param_list *pl, + const char *param_name, const struct config *config); + #define __platform_ptrname(_n) __platform_ ## _n #define _platform_ptrname(_n) __platform_ptrname(_n) From patchwork Thu Aug 2 17:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMV1cftz9s3q for ; Fri, 3 Aug 2018 03:33:26 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LEHBQ42c"; 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 41hHMT5cf1zF2DC for ; Fri, 3 Aug 2018 03:33:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LEHBQ42c"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LEHBQ42c"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHC4v5xzF27H for ; Fri, 3 Aug 2018 03:29:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PTiTEk8ck1hFMxUHC+v1f5JF9GRn+9t3qNklD6W7Cu4=; b=LEHBQ42cMjh95uIRReBdwuUq/ ycEvLA1qOJ4uvGJMwDp09gYxwSBYRmkx2kxvYhM9LgA+75QNjHmSfPl3oFsus228Nhd/sZ/9P+epk HHJr4XZ6cxz7nq5SodHUPJFfjAUIKNkZPGg07/BgnfWRPG84ey6RzyLNTz0embvZ1AKh07bbZlp3n X9XC2YDaeM20fiF5c5OGjKdSq4IjDseBAm7TRKfcfbVTC7ZzfZ+0WWW7sB8ObFaXCojAYnj9e/JZx W7FOMeKBfnmbFDpMmkHxY6wBpb6xfEntHaGpZlDQpiWzbCasJQ6ELgbRGyQPEvO+iHuX91vI+IAQc 3An3C3rHA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPv-0007Zr-Uy; Thu, 02 Aug 2018 17:29:40 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 26/30] configure: Rename ENABLE_PS3 to PLATFORM_PS3 To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:39 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" To prepare for other configure platform names. Signed-off-by: Geoff Levand --- configure.ac | 13 +++++-------- ui/common/Makefile.am | 2 +- ui/ncurses/Makefile.am | 2 +- ui/twin/Makefile.am | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 2cf94ef..290617b 100644 --- a/configure.ac +++ b/configure.ac @@ -304,15 +304,12 @@ AS_IF( ) AC_ARG_ENABLE( - [ps3], + [platform-ps3], [AS_HELP_STRING( - [--enable-ps3], - [build additional programs for the PS3 game console [default=no]] - )], - [], - [enable_ps3=no] -) -AM_CONDITIONAL([ENABLE_PS3], [test "x$enable_ps3" = "xyes"]) + [--enable-platform-ps3], + [build support for the PS3 game console [default=no]] + )]) +AM_CONDITIONAL([PLATFORM_PS3], [test "x$enable_platform_ps3" = "xyes"]) AC_ARG_ENABLE( [debug], diff --git a/ui/common/Makefile.am b/ui/common/Makefile.am index df6ea02..88692bb 100644 --- a/ui/common/Makefile.am +++ b/ui/common/Makefile.am @@ -24,7 +24,7 @@ ui_common_libpbui_la_SOURCES = \ ui/common/ui-system.c \ ui/common/ui-system.h -if ENABLE_PS3 +if PLATFORM_PS3 ui_common_libpbui_la_SOURCES += \ ui/common/ps3.c \ ui/common/ps3.h diff --git a/ui/ncurses/Makefile.am b/ui/ncurses/Makefile.am index 3bc5254..b791b9d 100644 --- a/ui/ncurses/Makefile.am +++ b/ui/ncurses/Makefile.am @@ -61,7 +61,7 @@ ui_ncurses_libpbnc_la_SOURCES = \ sbin_PROGRAMS += ui/ncurses/petitboot-nc -if ENABLE_PS3 +if PLATFORM_PS3 sbin_PROGRAMS += ui/ncurses/petitboot-ps3-nc endif diff --git a/ui/twin/Makefile.am b/ui/twin/Makefile.am index 2c5032a..6317377 100644 --- a/ui/twin/Makefile.am +++ b/ui/twin/Makefile.am @@ -38,7 +38,7 @@ ui_twin_libpbt_la_CPPFLAGS = $(ui_twin_common_cppflags) sbin_PROGRAMS += ui/twin/petitboot-twin -if ENABLE_PS3 +if PLATFORM_PS3 sbin_PROGRAMS += ui/twin/petitboot-ps3-twin endif From patchwork Thu Aug 2 17:29:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMg4T0zz9s2g for ; Fri, 3 Aug 2018 03:33:35 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qXBu1S1E"; 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 41hHMg2WcGzF2D9 for ; Fri, 3 Aug 2018 03:33:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qXBu1S1E"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qXBu1S1E"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHD05GxzF21T for ; Fri, 3 Aug 2018 03:29:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9QZRSQy+QE4RAnA35J3r+ESNwlG2vDrDIsBSItfh6GI=; b=qXBu1S1El8srhL4wDjPUyOC7k aZ7yE9//bdsU5lzUPv7MSKs0eX/eria1rFhQ/05iwrmz3BxxzB7mlFfKivNMNOHWAa6ovqJ7dpiWZ MsjJCPocAJrSYl8JU2HnULzbLzWcuOaDII5Jml7gb11ytMbws3n+1rpZrG5HWSUkcDflmDI3gStxj DrIEzg9Pq17Fm5IIABXNonybHg56lROcDI+kDOgqXa4V+Up7vWI+IyTPMGr3tNkb4zFHnxU2ts06v F65xEzEy1ictA2IQKT3LjBy0Lct0VVNKiA8ekWvU4bTvLwGiSZa0vw+pflT6JwMrolpFJRREq+eaJ 22u0Fud8A==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPw-0007Zz-8o; Thu, 02 Aug 2018 17:29:40 +0000 Message-Id: <79b9b18150add1e833f3fcffea3fc5c788647d09.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 27/30] discover: Add platform-dummy To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:40 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" With the new configure enable-platform parameters it is possible configure no platform support. Add a new minimal 'dummy' platform so that the __start_platforms and __stop_platforms variables needed by platform_init are created. Signed-off-by: Geoff Levand --- discover/Makefile.am | 3 +++ discover/platform-dummy.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 discover/platform-dummy.c diff --git a/discover/Makefile.am b/discover/Makefile.am index 3992a66..f9625ec 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -86,6 +86,9 @@ discover_platform_ro_SOURCES = \ discover_platform_ro_CPPFLAGS = \ $(AM_CPPFLAGS) +# Build dummy last to put it at the end of the platforms section. +discover_platform_ro_SOURCES += discover/platform-dummy.c + if ENABLE_MTD discover_platform_ro_SOURCES += \ discover/hostboot.c diff --git a/discover/platform-dummy.c b/discover/platform-dummy.c new file mode 100644 index 0000000..7c2e1dc --- /dev/null +++ b/discover/platform-dummy.c @@ -0,0 +1,16 @@ +#include "platform.h" + +static bool probe(struct platform *p, void *ctx) +{ + (void)p; + (void)ctx; + + return false; +} + +static struct platform dummy = { + .name = "dummy", + .probe = probe, +}; + +register_platform(dummy); From patchwork Thu Aug 2 17:29:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMq06CNz9s2g for ; Fri, 3 Aug 2018 03:33:43 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="w3d7o9Ao"; 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 41hHMp5V17zF2DQ for ; Fri, 3 Aug 2018 03:33:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="w3d7o9Ao"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="w3d7o9Ao"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHD2WGQzF27J for ; Fri, 3 Aug 2018 03:29:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=eGtOunhAcbAccv6q64Gupkxhan/1oBkdsAU4c6p2dUU=; b=w3d7o9AoGBWTuRwxYcYQMdywm h2svfkvH3tHonFZ66EVHfYfkwnYxIa9KUJ2h2hGpAigdrqpAgz2tHIVJvnp1XThyUIxK72+CjQDPM SG4pO+fYt931unJ08L/M1zSuB4qVXxIESr71gVsj7YMDKVdjwMc66q9rmeyVCGv7opBRwMfefz2U9 UFtRieRuTVlUDRS+1Te35Ez35ekAlGQu+y0YX982vk0IWoFSSmUxGQFMWdWFStT5H+XUIb9Nfb0Ph johuqKl95kHbifWkjlKlrFKyBBjelORweznKqhi/7EWlZ853K+BwTi/NRtW9QIvzqsw16NWJX9JH3 xPnywVKJg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPw-0007a9-Hh; Thu, 02 Aug 2018 17:29:40 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 28/30] configure: Add conditional platform builds To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:40 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add configure --enable-platform-XXX options to allow specifying which platform support to build. --enable-platform-auto, the default, will use the host triplet to guess which platforms to build. --enable-platform-all will build all platforms. Signed-off-by: Geoff Levand --- configure.ac | 38 ++++++++++++++++++++++++++++++++++++++ discover/Makefile.am | 11 +++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 290617b..38fe341 100644 --- a/configure.ac +++ b/configure.ac @@ -303,6 +303,44 @@ AS_IF( ] ) +# platform choice +AC_ARG_ENABLE( + [platform-all], + [AS_HELP_STRING( + [--enable-platform-all], + [build support for all platforms [default=no]] + )] +) +AS_IF( + [test "x$enable_platform_all" = "xyes"], + [enable_platform_powerpc="yes"; enable_platform_ps3="yes"] +) + +AC_ARG_ENABLE( + [platform-auto], + [AS_HELP_STRING( + [--enable-platform-auto], + [auto detect platform support to build [default=yes]] + )], + [], + [enable_platform_auto="yes"] +) +AS_IF( + [test "x$enable_platform_auto" = "xyes"], + [AS_CASE([$host], + [powerpc*-*-*], [enable_platform_powerpc="yes"], + )] +) + +AC_ARG_ENABLE( + [platform-powerpc], + [AS_HELP_STRING( + [--enable-platform-powerpc], + [build support for powerpc platforms [default=no]] + )] +) +AM_CONDITIONAL([PLATFORM_POWERPC], [test "x$enable_platform_powerpc" = "xyes"]) + AC_ARG_ENABLE( [platform-ps3], [AS_HELP_STRING( diff --git a/discover/Makefile.am b/discover/Makefile.am index f9625ec..2b7c794 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -80,11 +80,11 @@ discover_platform_ro_SOURCES = \ discover/ipmi.h \ discover/dt.c \ discover/dt.h \ - discover/hostboot.h \ - discover/platform-powerpc.c + discover/hostboot.h -discover_platform_ro_CPPFLAGS = \ - $(AM_CPPFLAGS) +if PLATFORM_POWERPC +discover_platform_ro_SOURCES += discover/platform-powerpc.c +endif # Build dummy last to put it at the end of the platforms section. discover_platform_ro_SOURCES += discover/platform-dummy.c @@ -99,5 +99,8 @@ discover_platform_ro_LDFLAGS = \ endif +discover_platform_ro_CPPFLAGS = \ + $(AM_CPPFLAGS) + discover_platform_ro_LINK = \ $(LD) -r -o $@ From patchwork Thu Aug 2 17:29:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHMy4Wywz9s2g for ; Fri, 3 Aug 2018 03:33:50 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ZIl1p8YP"; 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 41hHMy2h9GzF2D3 for ; Fri, 3 Aug 2018 03:33:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ZIl1p8YP"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ZIl1p8YP"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHD3HM4zF22V for ; Fri, 3 Aug 2018 03:29:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=O2IGqd3u2qqS48+LU7fscKP4MqPZoUYGCROJG6Fp6m8=; b=ZIl1p8YPgpx4k08QRZWWSOsy9 VlaNfLKMwoZvNjrnMxwXYTGDHxEmtG/a2O2mKUaqSRaLdTaedR1RL8f5dllMc3bQuzUDoBkBTOueh tpe3RhlCLBfZYKM4FIevqQ8eS0TUa3g9Wvq4aLT0gD6i9y3sKoBiymq1uLI7PkOosKYLhsHn9/y6G 5HCxr014ouBtVHPKlb45q5swON2EOhImFG2Z8/I6QcwXSueN8IMlMhsQTWyMesNGJ00loSG2r9bu7 KjfuFUGlDQ7YjQfsHP5KhfvR+/GTrUL6vrc/dsFh52b/uHZC/NPMKxSJ3acLe9zYim1PoOx2Nchff z5q4/bXfQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPw-0007aI-UY; Thu, 02 Aug 2018 17:29:41 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 29/30] lib/system: Add dmidecode as system app To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:40 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" For use by the arm64 get_sysinfo. Signed-off-by: Geoff Levand --- configure.ac | 1 + lib/system/system.c | 1 + lib/system/system.h | 1 + 3 files changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 38fe341..eca574a 100644 --- a/configure.ac +++ b/configure.ac @@ -394,6 +394,7 @@ DEFINE_HOST_PROG(PB_PLUGIN, pb-plugin, [/usr/sbin/pb-plugin]) DEFINE_HOST_PROG(PB_EXEC, pb-exec, [/usr/sbin/pb-exec]) DEFINE_HOST_PROG(SH, sh, [/bin/sh]) DEFINE_HOST_PROG(SCSI_RESCAN, scsi-rescan, [/usr/sbin/scsi-rescan]) +DEFINE_HOST_PROG(DMIDECODE, dmidecode, [/sbin/dmidecode]) AC_ARG_WITH( [tftp], diff --git a/lib/system/system.c b/lib/system/system.c index df27c87..89790ba 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -35,6 +35,7 @@ const struct pb_system_apps pb_system_apps = { .pb_exec = HOST_PROG_PB_EXEC, .sh = HOST_PROG_SH, .scsi_rescan = HOST_PROG_SCSI_RESCAN, + .dmidecode = HOST_PROG_DMIDECODE, }; #ifndef TFTP_TYPE diff --git a/lib/system/system.h b/lib/system/system.h index e3e8a30..2389951 100644 --- a/lib/system/system.h +++ b/lib/system/system.h @@ -20,6 +20,7 @@ struct pb_system_apps { const char *pb_exec; const char *sh; const char *scsi_rescan; + const char *dmidecode; }; extern const struct pb_system_apps pb_system_apps; From patchwork Thu Aug 2 17:29:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952930 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHN572Gpz9s2g for ; Fri, 3 Aug 2018 03:33:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="iHYqBSj+"; 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 41hHN55VJGzF2DT for ; Fri, 3 Aug 2018 03:33:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="iHYqBSj+"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="iHYqBSj+"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHHD3Z9vzF277 for ; Fri, 3 Aug 2018 03:29:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cGRIvkEHojtd1nGZ/X9lANdJVYsnHhxOA1RpcVkWRYE=; b=iHYqBSj+cZCQAG3CVQL9uDMIm cgpMP3iGbqpIg7MY0a6V/9q78vYs6B+pE0h9OnwmL5zht/xHDXNS3cUP6pIUGKeuiIWtPldZmH6ys 9/gjJZgUEXV3UsgNighLDPdd77pBmWlJ4z8KMyWQjkH2DbEqxPdxuHWuEzD+Z24PaMEDEflPVdw1K b9Hiz1ksB6LhPiN0qiibaYrm/xJQp/j8Itc8+3pkjyfgXoXdrBjqsLKc1rUkSbsUYfT6l3BtYynmz RoEeyyQM9/vSh8xCxZB0HEw8h7WoFj9VrzvWz71bZprXEhelw7v+OTGwPFN7tMrCJhpu1dyPrtbx+ GSmPKbz0w==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPx-0007aR-77; Thu, 02 Aug 2018 17:29:41 +0000 Message-Id: <1afb2a0dacace72f0b29b54e609430e208163867.1533230644.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:54 -0700 Subject: [PATCH v2 30/30] discover: Add platform-arm64 To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:41 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Signed-off-by: Ge Song [Split from a larger patch and cleaned up] Signed-off-by: Geoff Levand --- configure.ac | 12 +- discover/Makefile.am | 4 + discover/platform-arm64.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 discover/platform-arm64.c diff --git a/configure.ac b/configure.ac index eca574a..2bf6e6f 100644 --- a/configure.ac +++ b/configure.ac @@ -313,7 +313,7 @@ AC_ARG_ENABLE( ) AS_IF( [test "x$enable_platform_all" = "xyes"], - [enable_platform_powerpc="yes"; enable_platform_ps3="yes"] + [enable_platform_arm64="yes"; enable_platform_powerpc="yes"; enable_platform_ps3="yes"] ) AC_ARG_ENABLE( @@ -328,10 +328,20 @@ AC_ARG_ENABLE( AS_IF( [test "x$enable_platform_auto" = "xyes"], [AS_CASE([$host], + [aarch64-*-*], [enable_platform_arm64="yes"], [powerpc*-*-*], [enable_platform_powerpc="yes"], )] ) +AC_ARG_ENABLE( + [platform-arm64], + [AS_HELP_STRING( + [--enable-platform-arm64], + [build support for arm64 platforms [default=no]] + )] +) +AM_CONDITIONAL([PLATFORM_ARM64], [test "x$enable_platform_arm64" = "xyes"]) + AC_ARG_ENABLE( [platform-powerpc], [AS_HELP_STRING( diff --git a/discover/Makefile.am b/discover/Makefile.am index 2b7c794..f5b799d 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -82,6 +82,10 @@ discover_platform_ro_SOURCES = \ discover/dt.h \ discover/hostboot.h +if PLATFORM_ARM64 +discover_platform_ro_SOURCES += discover/platform-arm64.c +endif + if PLATFORM_POWERPC discover_platform_ro_SOURCES += discover/platform-powerpc.c endif diff --git a/discover/platform-arm64.c b/discover/platform-arm64.c new file mode 100644 index 0000000..9cd6641 --- /dev/null +++ b/discover/platform-arm64.c @@ -0,0 +1,278 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights + * reserved. + * Author: Ge Song + */ + +#include +#include +#include +#include +#include +#include + +#include "efi/efivar.h" +#include "file/file.h" +#include "log/log.h" +#include +#include +#include "talloc/talloc.h" +#include "types/types.h" + + +#include "ipmi.h" +#include "platform.h" + +static const char *efi_vars_guid = "fb78ab4b-bd43-41a0-99a2-4e74bef9169b"; + +struct platform_arm64 { + struct param_list params; + struct ipmi *ipmi; +}; + +static inline struct platform_arm64 *to_platform_arm64(struct platform *p) +{ + return (struct platform_arm64 *)(p->platform_data); +} + +static void parse_nvram(struct param_list *pl) +{ + const char** known; + + param_list_for_each_known_param(pl, known) { + struct efi_data *efi_data; + + if (efi_get_variable(NULL, efi_vars_guid, *known, &efi_data)) + continue; + + param_list_set(pl, *known, efi_data->data, + true); + + talloc_free(efi_data); + } +} + +static void write_nvram(const struct param_list *pl) +{ + struct efi_data efi_data; + struct param *param; + + efi_data.attributes = + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_BOOTSERVICE_ACCESS; + + param_list_for_each(pl, param) { + if (!param->modified) + continue; + + efi_data.data = param->value; + efi_data.data_size = strlen(param->value) + 1; + efi_set_variable(efi_vars_guid, param->name, &efi_data); + } +} + +static void get_active_consoles(struct config *config) +{ + config->n_consoles = 0; + config->consoles = talloc_array(config, char *, 3); + if (!config->consoles) + return; + + config->consoles[0] = talloc_asprintf(config, + "/dev/hvc0 [IPMI / Serial]"); + config->consoles[1] = talloc_asprintf(config, + "/dev/ttyAMA0 [Serial]"); + config->consoles[2] = talloc_asprintf(config, + "/dev/tty1 [VGA]"); + config->n_consoles = 3; +} + +static int load_config(struct platform *p, struct config *config) +{ + struct param_list *pl = &to_platform_arm64(p)->params; + + parse_nvram(pl); + config_populate_all(config, pl); + get_active_consoles(config); + + return 0; +} + +static char *stdout_cleaner(struct process_stdout *out) +{ + char *p; + const char *const end = out->buf + out->len; + + for (p = out->buf; *p && p < end; p++) { + if (*p == '\n' || *p == '\r') { + *p = 0; + } else if (!isprint(*p)) { + *p = '.'; + } else if (*p == '\t') { + *p = ' '; + } + } + return out->buf; +} + +static int get_sysinfo(struct platform *p, struct system_info *sysinfo) +{ + struct platform_arm64 *platform = to_platform_arm64(p); + struct process_stdout *out1, *out2; + + /* Use dmidecode to get sysinfo type and identifier. */ + + process_get_stdout(NULL, &out1, pb_system_apps.dmidecode, + "--string=system-manufacturer", + NULL); + process_get_stdout(NULL, &out2, pb_system_apps.dmidecode, + "--string=system-product-name", + NULL); + + if (out1 || out2) + sysinfo->type = talloc_asprintf(sysinfo, "%s %s", + out1 ? stdout_cleaner(out1) : "Unknown", + out2 ? stdout_cleaner(out2) : "Unknown"); + talloc_free(out1); + talloc_free(out2); + + process_get_stdout(NULL, &out1, pb_system_apps.dmidecode, + "--string=system-uuid", + NULL); + + if (out1) + sysinfo->identifier = talloc_asprintf(sysinfo, "%s", + stdout_cleaner(out1)); + talloc_free(out1); + + sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE); + + if (platform->ipmi) { + ipmi_get_bmc_mac(platform->ipmi, sysinfo->bmc_mac); + ipmi_get_bmc_versions(platform->ipmi, sysinfo); + } + + pb_debug_fn("type: '%s'\n", sysinfo->type); + pb_debug_fn("identifier: '%s'\n", sysinfo->identifier); + pb_debug_fn("bmc_mac: '%s'\n", sysinfo->bmc_mac); + + return 0; +} + +static void params_update_all(struct param_list *pl, + const struct config *config, const struct config *defaults) +{ + char *tmp = NULL; + const char *val; + + if (config->autoboot_enabled == defaults->autoboot_enabled) + val = ""; + else + val = config->autoboot_enabled ? "true" : "false"; + + param_list_set_non_empty(pl, "auto-boot?", val, true); + + if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec) + val = ""; + else + val = tmp = talloc_asprintf(pl, "%d", + config->autoboot_timeout_sec); + + param_list_set_non_empty(pl, "petitboot,timeout", val, true); + if (tmp) + talloc_free(tmp); + + val = config->lang ?: ""; + param_list_set_non_empty(pl, "petitboot,language", val, true); + + if (config->allow_writes == defaults->allow_writes) + val = ""; + else + val = config->allow_writes ? "true" : "false"; + param_list_set_non_empty(pl, "petitboot,write?", val, true); + + if (!config->manual_console) { + val = config->boot_console ?: ""; + param_list_set_non_empty(pl, "petitboot,console", val, true); + } + + val = config->http_proxy ?: ""; + param_list_set_non_empty(pl, "petitboot,http_proxy", val, true); + val = config->https_proxy ?: ""; + param_list_set_non_empty(pl, "petitboot,https_proxy", val, true); + + params_update_network_values(pl, "petitboot,network", config); + params_update_bootdev_values(pl, "petitboot,bootdevs", config); +} + +static int save_config(struct platform *p, struct config *config) +{ + struct param_list *pl = &to_platform_arm64(p)->params; + struct config *defaults; + + defaults = talloc_zero(NULL, struct config); + config_set_defaults(defaults); + + params_update_all(pl, config, defaults); + talloc_free(defaults); + + write_nvram(pl); + + return 0; +} + +static bool probe(struct platform *p, void *ctx) +{ + static const char *efivars = "/sys/firmware/efi/efivars"; + struct platform_arm64 *platform; + struct statfs buf; + + if (access(efivars, R_OK | W_OK)) { + pb_debug_fn("Can't access %s\n", efivars); + return false; + } + + memset(&buf, '\0', sizeof(buf)); + if (statfs(efivars, &buf)) { + pb_debug_fn("statfs failed: %s: %s\n", efivars, + strerror(errno)); + return false; + } + + if (buf.f_type != EFIVARFS_MAGIC) { + pb_debug_fn("Bad magic = 0x%lx\n", (unsigned long)buf.f_type); + return false; + } + + platform = talloc_zero(ctx, struct platform_arm64); + param_list_init(&platform->params, common_known_params()); + + p->platform_data = platform; + + return true; +} + +static struct platform platform_arm64 = { + .name = "arm64", + .dhcp_arch_id = 0x000d, + .probe = probe, + .load_config = load_config, + .save_config = save_config, + .get_sysinfo = get_sysinfo, +}; + +register_platform(platform_arm64);