From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lgWH9-00035u-6G for mharc-grub-devel@gnu.org; Tue, 11 May 2021 13:34:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgWH7-00035L-HL for grub-devel@gnu.org; Tue, 11 May 2021 13:34:29 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32074) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgWH5-0000Uw-80 for grub-devel@gnu.org; Tue, 11 May 2021 13:34:29 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14BHX6bQ093914 for ; Tue, 11 May 2021 13:34:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=WiL+2VPX5gAnVnVchNebxnBRrGtyqNBu8FlyEm1/tUM=; b=ZVjpvggE3e3ikoqe2erHOFcBO2yHFOFqWVaysWRdgOohJHOH9anFs+fNuQ2WzTUD0jaq qzEVEyTnale4N+SSPelFAeRQ01m4LO5cqhnL3HCwe8TYYIV1Z2yUo/vp09G6yybC2Ubo R1HjM6W8TbRQAYXPo0spKa4b/kBPWO4NGmwIFceMpK3htqK03zeDhXqYJTDBny1BbNY8 779VOl42kXBR5DmfmrHA8ArgYEOMsCmq5/kUDeNUQb6zthu6PrbnY3tdjnQe2Vtvt3Jl 9Fhbk6yOQKs4/usQ2piqBYfjlcS3TVS2Y5eZOguvYkVhupa1Gfy/XrWfzk9kmI6JiEkj cA== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 38fwuj12c5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 May 2021 13:34:24 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14BHYLsR000478 for ; Tue, 11 May 2021 17:34:23 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma03dal.us.ibm.com with ESMTP id 38dj99dc80-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 May 2021 17:34:23 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14BHY9Id41943306 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 May 2021 17:34:09 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00FCDAC05F for ; Tue, 11 May 2021 17:34:09 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E9C5AC05B for ; Tue, 11 May 2021 17:34:08 +0000 (GMT) Received: from localhost.localdomain (unknown [9.160.13.174]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP for ; Tue, 11 May 2021 17:34:08 +0000 (GMT) From: Diego Domingos To: grub-devel@gnu.org Subject: [PATCH] IBM client architecture (CAS) reboot support Date: Tue, 11 May 2021 14:33:52 -0300 Message-Id: <20210511173352.365143-1-diegodo@linux.vnet.ibm.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: YRAX1Mo08a-SGk-IDY-50WSQIOfGjRjl X-Proofpoint-GUID: YRAX1Mo08a-SGk-IDY-50WSQIOfGjRjl X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-11_04:2021-05-11, 2021-05-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 mlxscore=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105110120 Received-SPF: none client-ip=148.163.158.5; envelope-from=diegodo@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2021 17:34:29 -0000 From: Paulo Flabiano Smorigo This is an implementation of IBM client architecture (CAS) reboot for GRUB. There are cases where the POWER firmware must reboot in order to support specific features requested by a kernel. The kernel calls ibm,client-architecture-support and it may either return or reboot with the new feature set. eg: Calling ibm,client-architecture-support.../ Elapsed time since release of system processors: 70959 mins 50 secs Welcome to GRUB! Instead of return to the GRUB menu, it will check if the flag for CAS reboot is set. If so, grub will automatically boot the last booted kernel using the same parameters --- grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++++++++++ grub-core/normal/main.c | 19 ++++++++++++ grub-core/script/execute.c | 7 +++++ include/grub/ieee1275/ieee1275.h | 2 ++ 4 files changed, 91 insertions(+) diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 62929d983bf..2d53c0e8608 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -588,3 +588,66 @@ grub_ieee1275_get_boot_dev (void) return bootpath; } + +/* Check if it's a CAS reboot. If so, set the script to be executed. */ +int +grub_ieee1275_cas_reboot (char *script) +{ + grub_uint32_t ibm_ca_support_reboot; + grub_uint32_t ibm_fw_nbr_reboots; + char property_value[10]; + grub_ssize_t actual; + grub_ieee1275_ihandle_t options; + + if (grub_ieee1275_finddevice ("/options", &options) < 0) + return -1; + + /* Check two properties, one is enough to get cas reboot value */ + ibm_ca_support_reboot = 0; + if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, + "ibm,client-architecture-support-reboot", + &ibm_ca_support_reboot, + sizeof (ibm_ca_support_reboot), + &actual) >= 0) + grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n", + ibm_ca_support_reboot); + + ibm_fw_nbr_reboots = 0; + if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots", + property_value, sizeof (property_value), + &actual) >= 0) + { + property_value[sizeof (property_value) - 1] = 0; + ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10); + grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots); + } + + if (ibm_ca_support_reboot || ibm_fw_nbr_reboots) + { + if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual)) + { + if (actual > 1024) + script = grub_realloc (script, actual + 1); + grub_ieee1275_get_property (options, "boot-last-label", script, actual, + &actual); + return 0; + } + } + + grub_ieee1275_set_boot_last_label (""); + + return -1; +} + +int grub_ieee1275_set_boot_last_label (const char *text) +{ + grub_ieee1275_ihandle_t options; + grub_ssize_t actual; + + grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text)); + if (! grub_ieee1275_finddevice ("/options", &options) && + options != (grub_ieee1275_ihandle_t) -1) + grub_ieee1275_set_property (options, "boot-last-label", text, + grub_strlen (text), &actual); + return 0; +} diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 78a70a8bf47..249e19bc788 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef GRUB_MACHINE_IEEE1275 +#include +#endif GRUB_MOD_LICENSE ("GPLv3+"); @@ -275,6 +278,22 @@ grub_normal_execute (const char *config, int nested, int batch) { menu = read_config_file (config); +#ifdef GRUB_MACHINE_IEEE1275 + int boot; + boot = 0; + char *script; + script = grub_malloc (1024); + if (! grub_ieee1275_cas_reboot (script)) + { + char *dummy[1] = { NULL }; + if (! grub_script_execute_sourcecode (script)) + boot = 1; + } + grub_free (script); + if (boot) + grub_command_execute ("boot", 0, 0); +#endif + /* Ignore any error. */ grub_errno = GRUB_ERR_NONE; } diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index a8502d90711..ab78ca87f90 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -27,6 +27,9 @@ #include #include #include +#ifdef GRUB_MACHINE_IEEE1275 +#include +#endif /* Max digits for a char is 3 (0xFF is 255), similarly for an int it is sizeof (int) * 3, and one extra for a possible -ve sign. */ @@ -877,6 +880,10 @@ grub_script_execute_sourcecode (const char *source) grub_err_t ret = 0; struct grub_script *parsed_script; +#ifdef GRUB_MACHINE_IEEE1275 + grub_ieee1275_set_boot_last_label (source); +#endif + while (source) { char *line; diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 8868f3a756f..2310f33dbc2 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -252,6 +252,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias); void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath, struct grub_ieee1275_devalias *alias); +int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script); +int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text); char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);