From patchwork Thu Oct 18 15:52:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 192368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 509D82C0092 for ; Fri, 19 Oct 2012 02:52:18 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TOsOO-0006B0-Gd; Thu, 18 Oct 2012 15:52:16 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TOsOM-0006Av-OP for fwts-devel@lists.ubuntu.com; Thu, 18 Oct 2012 15:52:14 +0000 Received: from [175.182.142.86] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TOsOL-00024L-Dv; Thu, 18 Oct 2012 15:52:14 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] fwts_efi_module: add fwts library helper fuctions for efi_runtime module Date: Thu, 18 Oct 2012 23:52:09 +0800 Message-Id: <1350575529-28509-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com These helper fuctions are used for loading, unloading and checking the existence of efi_euntime module. Signed-off-by: Ivan Hu --- src/lib/include/fwts_efi_module.h | 26 ++++++++++ src/lib/src/Makefile.am | 3 +- src/lib/src/fwts_efi_module.c | 99 +++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/lib/include/fwts_efi_module.h create mode 100644 src/lib/src/fwts_efi_module.c diff --git a/src/lib/include/fwts_efi_module.h b/src/lib/include/fwts_efi_module.h new file mode 100644 index 0000000..31a3714 --- /dev/null +++ b/src/lib/include/fwts_efi_module.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 Canonical + * + * 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; either version 2 + * of the License, or (at your option) any later version. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __FWTS_EFI_MODULE_H__ +#define __FWTS_EFI_MODULE_H__ + +int fwts_lib_efi_runtime_load_module(fwts_framework *fw); +int fwts_lib_efi_runtime_unload_module(fwts_framework *fw); + +#endif diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am index ea97cdb..3f8764e 100644 --- a/src/lib/src/Makefile.am +++ b/src/lib/src/Makefile.am @@ -60,4 +60,5 @@ libfwts_la_SOURCES = \ fwts_wakealarm.c \ fwts_ac_adapter.c \ fwts_battery.c \ - fwts_button.c + fwts_button.c \ + fwts_efi_module.c diff --git a/src/lib/src/fwts_efi_module.c b/src/lib/src/fwts_efi_module.c new file mode 100644 index 0000000..710bf4d --- /dev/null +++ b/src/lib/src/fwts_efi_module.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2012 Canonical + * + * 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; either version 2 + * of the License, or (at your option) any later version. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include +#include +#include + +#include "fwts_pipeio.h" + +static bool module_already_loaded = false; + +static int check_module_loaded(void) +{ + FILE *fp; + char buffer[1024]; + module_already_loaded = false; + if ((fp = fopen("/proc/modules", "r")) != NULL) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + if (strstr(buffer, "efi_runtime") != NULL) + module_already_loaded = true; + } + fclose(fp); + return FWTS_OK; + } + return FWTS_ERROR; +} + +int fwts_lib_efi_runtime_load_module(fwts_framework *fw) +{ + struct stat statbuf; + fwts_list *output; + + if (check_module_loaded() != FWTS_OK) { + fwts_log_error(fw, "Could not open /proc/modules for checking module loaded."); + return FWTS_ERROR; + } + + if (!module_already_loaded) { + if (fwts_pipe_exec("modprobe efi_runtime", &output) != FWTS_OK) { + fwts_log_error(fw, "Load efi_runtime module error."); + return FWTS_ERROR; + } else { + check_module_loaded(); + if (!module_already_loaded) { + fwts_log_error(fw, "Could not load efi_runtime module."); + return FWTS_ERROR; + } + } + } + + if (stat("/dev/efi_runtime", &statbuf)) { + fwts_log_error(fw, "Loaded efi_runtime module but /dev/efi_runtime is not present."); + return FWTS_ERROR; + } + + return FWTS_OK; +} + + +int fwts_lib_efi_runtime_unload_module(fwts_framework *fw) +{ + fwts_list *output; + if (check_module_loaded() != FWTS_OK) { + fwts_log_error(fw, "Could not open /proc/modules for checking module loaded."); + return FWTS_ERROR; + } + if (module_already_loaded) { + if (fwts_pipe_exec("modprobe -r efi_runtime", &output) != FWTS_OK) { + fwts_log_error(fw, "Unload efi_runtime module error."); + return FWTS_ERROR; + } else { + check_module_loaded(); + if (module_already_loaded) { + fwts_log_error(fw, "Could not unload efi_runtime module."); + return FWTS_ERROR; + } + } + } + + return FWTS_OK; +}