Set access to HBB and HBI partitions to Read Only

This change removes a revert of the "Mark Read Only Partitions as
Such" change and updates the pnor makefiles to ensure HBB and HBI
partitions are marked read only at the pnor level.

Signed-off-by: Jaymes Wilks <mjwilks@us.ibm.com>
diff --git a/openpower/package/hostboot/hostboot-0002-Revert-Mark-Read-Only-Partitions-as-Such.patch b/openpower/package/hostboot/hostboot-0002-Revert-Mark-Read-Only-Partitions-as-Such.patch
deleted file mode 100644
index c572fee..0000000
--- a/openpower/package/hostboot/hostboot-0002-Revert-Mark-Read-Only-Partitions-as-Such.patch
+++ /dev/null
@@ -1,371 +0,0 @@
-From 3dba59d5b60a9ad307b91d4063279cb1535cda8f Mon Sep 17 00:00:00 2001
-From: Stewart Smith <stewart@linux.ibm.com>
-Date: Wed, 18 Apr 2018 17:06:09 +1000
-Subject: [PATCH] Revert "Mark Read-Only Partitions as Such"
-
-This reverts commit f5cd23d6c3be17356e0851ec5d5bb65cee48f15f.
-
-Only changing the presence of this commit, we go from failing to boot
-(error below) to being able to boot.
-
- 24.41069|ISTEP 10. 2 - host_slave_sbe_update
- 24.44213|System shutting down with error status 0x90000012
- 24.45270|================================================
- 24.45420|Error reported by initservice (0x0500) PLID 0x90000012
- 24.45422|  Initialization Service launched a function and
-the task returned an error.
- 24.45423|  ModuleId   0x01 BASE_INITSVC_MOD_ID
- 24.45573|  ReasonCode 0x0506 WAIT_FN_FAILED
- 24.45574|  UserData1  task id or task return code : 0x00000000000000ec
- 24.45574|  UserData2  returned status from task : 0x0000000000000001
- 24.45575|------------------------------------------------
- 24.45875|  Callout type             : Procedure Callout
- 24.45876|  Procedure                : EPUB_PRC_HB_CODE
- 24.45876|  Priority                 : SRCI_PRIORITY_HIGH
- 24.45877|------------------------------------------------
- 24.45878|  host_slave_sbe_update
- 24.45878|------------------------------------------------
- 24.45879|  Hostboot Build ID:
- 24.45879|================================================
-
-Change-Id: I7ac38afc8bed608d6272f1ef6f099e3fc03bb270
-Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
----
- src/include/usr/pnor/pnor_reasoncodes.H         |   1 -
- src/usr/pnor/pnorrp.C                           |  15 +-
- src/usr/pnor/test/pnorrptest.H                  | 188 ++++++++----------------
- src/usr/secureboot/base/test/securerommgrtest.H |  20 ---
- 4 files changed, 71 insertions(+), 153 deletions(-)
-
-diff --git a/src/include/usr/pnor/pnor_reasoncodes.H b/src/include/usr/pnor/pnor_reasoncodes.H
-index 2835f8a153d0..4dd2ef1c43de 100644
---- a/src/include/usr/pnor/pnor_reasoncodes.H
-+++ b/src/include/usr/pnor/pnor_reasoncodes.H
-@@ -187,7 +187,6 @@ namespace PNOR
-         RC_SECURE_SIZE_MISMATCH      = PNOR_COMP_ID | 0x3A,
-         RC_NOT_PAGE_ALIGNED          = PNOR_COMP_ID | 0x3B,
-         RC_SECURE_PRO_SIZE_MISMATCH  = PNOR_COMP_ID | 0x3C,
--        RC_READ_ONLY_PERM_FAIL       = PNOR_COMP_ID | 0x3D,
- 
-         //@fixme-RTC:131607-Temporary value to allow HWSV compile
-         //termination_rc
-diff --git a/src/usr/pnor/pnorrp.C b/src/usr/pnor/pnorrp.C
-index df88ba821b70..e33a1b0c377c 100644
---- a/src/usr/pnor/pnorrp.C
-+++ b/src/usr/pnor/pnorrp.C
-@@ -1776,31 +1776,32 @@ errlHndl_t PnorRP::setVirtAddrs(void)
-           // Handle section permissions
-         if (iv_TOC[i].misc & FFS_MISC_READ_ONLY)
-         {
--            // Partitions marked with readOnly flag should be
--            // READ_ONLY and not WRITABLE.
-+            // Need to set permissions to allow writing to virtual
-+            // addresses, but prevents the kernel from ejecting
-+            // dirty pages (no WRITE_TRACKED).
-             int rc = mm_set_permission(
-                                     (void*)iv_TOC[i].virtAddr,
-                                     iv_TOC[i].size,
--                                    READ_ONLY);
-+                                    WRITABLE);
-             if (rc)
-             {
--                TRACFCOMP(g_trac_pnor, "E>PnorRP::readTOC: Failed to set block permissions to READ_ONLY for section %s.",
-+                TRACFCOMP(g_trac_pnor, "E>PnorRP::readTOC: Failed to set block permissions to WRITABLE for section %s.",
-                           SectionIdToString(i));
-                 /*@
-                 * @errortype
-                 * @moduleid PNOR::MOD_PNORRP_READTOC
--                * @reasoncode PNOR::RC_READ_ONLY_PERM_FAIL
-+                * @reasoncode PNOR::RC_WRITABLE_PERM_FAIL
-                 * @userdata1 PNOR section id
-                 * @userdata2 PNOR section vaddr
-                 * @devdesc Could not set permissions of the
--                *          given PNOR section to READ_ONLY
-+                *          given PNOR section to WRITABLE
-                 * @custdesc A problem occurred while reading
-                 *           Processor NOR flash partition table
-                 */
-                 l_errhdl = new ERRORLOG::ErrlEntry(
-                                 ERRORLOG::ERRL_SEV_UNRECOVERABLE,
-                                 PNOR::MOD_PNORRP_READTOC,
--                                PNOR::RC_READ_ONLY_PERM_FAIL,
-+                                PNOR::RC_WRITABLE_PERM_FAIL,
-                                 i,
-                                 iv_TOC[i].virtAddr,
-                                 true /*Add HB SW Callout*/);
-diff --git a/src/usr/pnor/test/pnorrptest.H b/src/usr/pnor/test/pnorrptest.H
-index 5108840f5040..942eff9abdff 100644
---- a/src/usr/pnor/test/pnorrptest.H
-+++ b/src/usr/pnor/test/pnorrptest.H
-@@ -5,7 +5,7 @@
- /*                                                                        */
- /* OpenPOWER HostBoot Project                                             */
- /*                                                                        */
--/* Contributors Listed Below - COPYRIGHT 2011,2018                        */
-+/* Contributors Listed Below - COPYRIGHT 2011,2017                        */
- /* [+] Google Inc.                                                        */
- /* [+] International Business Machines Corp.                              */
- /*                                                                        */
-@@ -39,7 +39,6 @@
- #include <sys/msg.h>
- #include <limits.h>
- #include <sys/mm.h>
--#include <sys/task.h>
- #include <targeting/common/targetservice.H>
- #include <devicefw/userif.H>
- #include <config.h>
-@@ -626,53 +625,82 @@ class PnorRpTest : public CxxTest::TestSuite
-     }
- 
-     /**
--     * @brief PNOR RP test - read_ReadOnly_partition
--     *        Tests if we can read a readOnly partition
-+     * @brief PNOR RP test - ReadOnlyTag
-+     *        Tests if readOnly tag on a section is being processed correctly
-      *
-      */
--    void test_read_ReadOnly_partition(void)
-+    void test_ReadOnlyTag(void)
-     {
--        TRACFCOMP(g_trac_pnor,"PnorRpTest::test_read_ReadOnly_partition Start");
--
--        int l_status = TASK_STATUS_EXITED_CLEAN;
--        PNOR::SectionId l_testroSecId = PNOR::TESTRO;
--        tid_t l_childTask =
--                         task_create(readFromReadOnlyPartition, &l_testroSecId);
-+        TRACFCOMP(g_trac_pnor, "PnorRpTest::test_ReadOnlyTag Start" );
-+        PNOR::SectionInfo_t l_info;
-+        errlHndl_t l_errhdl = NULL;
-+        uint64_t chip_select = 0xF;
-+        bool needs_ecc = false;
- 
--        if((l_childTask != task_wait_tid(l_childTask, &l_status, nullptr)) ||
--           (l_status != TASK_STATUS_EXITED_CLEAN))
-+        l_errhdl = PNOR::getSectionInfo(PNOR::TESTRO, l_info);
-+        if( l_errhdl )
-         {
--            TS_FAIL("Could not read from readOnly partition.");
-+            TRACFCOMP(g_trac_pnor, "PnorRpTest::test_ReadOnlyTag> ERROR : getSectionInfo returned error for %d : RC=%X",
-+                      PNOR::TESTRO, l_errhdl->reasonCode());
-+            ERRORLOG::errlCommit(l_errhdl, PNOR_COMP_ID);
-+            TS_FAIL( "PnorRpTest::test_ReadOnlyTag> ERROR : could not read pnor section %d", PNOR::TESTRO);
-         }
--        TRACFCOMP(g_trac_pnor,"PnorRpTest::test_read_ReadOnly_partition End");
--    }
- 
--    /**
--     * @brief PNOR RP test - write_ReadOnly_partition
--     *        Tests if we can write to a readOnly partition (fail expected)
--     *
--     */
--    void test_write_ReadOnly_partition(void)
--    {
--        TRACFCOMP(g_trac_pnor,
--                             "PnorRpTest::test_write_ReadOnly_partition Start");
-+        // Write some data
-+        const uint64_t l_writeData = 0x1122334455667788;
-+        uint64_t* l_dataptr = reinterpret_cast<uint64_t*> (l_info.vaddr);
-+        l_dataptr[0] = l_writeData;
- 
--        int l_status = TASK_STATUS_EXITED_CLEAN;
--        PNOR::SectionId l_testroSecId = PNOR::TESTRO;
-+        // Flush the page to make sure it gets out to the device
-+        // Due to ReadOnly permissions set on TESTRO should be a no-op
-+        int rc = mm_remove_pages( RELEASE, l_dataptr, PAGESIZE );
-+        if( rc )
-+        {
-+            TRACFCOMP( g_trac_pnor, "PnorRpTest::test_ReadOnlyTag> ERROR : error on RELEASE : rc=%X", rc );
-+            TS_FAIL( "PnorRpTest::test_ReadOnlyTag> ERROR : error on RELEASE" );
-+        }
- 
--        printk("Test case: Expect to see uncaught exception! ");
--        tid_t l_childTask =
--                          task_create(writeToReadOnlyPartition, &l_testroSecId);
-+        // Get physical address of pnor section
-+        uint64_t l_address = 0;
-+        l_errhdl = PnorRP::getInstance().computeDeviceAddr((void*)l_info.vaddr,
-+                                                        l_address,
-+                                                        chip_select,
-+                                                        needs_ecc);
-+        if(l_errhdl)
-+        {
-+            TRACFCOMP(g_trac_pnor, "PnorRpTest::test_ReadOnlyTag> ERROR : computeDeviceAddr vaddr = 0x%X",l_info.vaddr);
-+            errlCommit(l_errhdl,PNOR_COMP_ID);
-+            TS_FAIL( "PnorRpTest::test_ReadOnlyTag> ERROR : computeDeviceAddr vaddr = 0x%X",l_info.vaddr);
-+        }
- 
--        if((l_childTask != task_wait_tid(l_childTask, &l_status, nullptr)) ||
--           (l_status != TASK_STATUS_CRASHED))
-+        // Read pnor section and check if write did not occur
-+        uint64_t l_readData = 0;
-+        size_t l_size = sizeof(uint64_t);
-+        l_errhdl = deviceRead(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
-+                              &l_readData,
-+                              l_size,
-+                              DEVICE_PNOR_ADDRESS(0, l_address));
-+        TRACFCOMP(g_trac_pnor, "PnorRpTest::test_ReadOnlyTag> Read Data = 0x%X",l_readData);
-+        if(l_errhdl)
-         {
--            TS_FAIL("Write to readOnly partition exception not caught.");
-+            TS_FAIL("PnorRpTest::test_ReadOnlyTag: deviceRead() failed! Error committed.");
-+            ERRORLOG::errlCommit(l_errhdl, PNOR_COMP_ID);
-+        }
-+        if(l_readData == l_writeData)
-+        {
-+            TS_FAIL("PnorRpTest::test_ReadOnlyTag: Data was written to readOnly section = %s",
-+                     l_info.name);
-+        }
-+        if(l_size != sizeof(uint64_t))
-+        {
-+            TS_FAIL("PnorRpTest::test_ReadOnlyTag: deviceRead() Read length not expected value. Addr: 0x%llx, Exp: %d, Act: %d",
-+                    l_address, sizeof(uint64_t), l_size);
-         }
- 
--        TRACFCOMP(g_trac_pnor, "PnorRpTest::test_write_ReadOnly_partition End");
-+        TRACFCOMP(g_trac_pnor, "PnorRpTest::test_ReadOnlyTag End");
-     }
- 
-+
-     //@todo - import config data from build and compare to section info
- 
-     /**
-@@ -885,97 +913,7 @@ class PnorRpTest : public CxxTest::TestSuite
- 
-         } while (0);
- #endif
--    }
--
--    private:
--    static void* readFromReadOnlyPartition(void* i_section)
--    {
--        TRACFCOMP(g_trac_pnor, "readFromReadOnlyPartition Start");
--        PNOR::SectionId* l_section =
--                                reinterpret_cast<PNOR::SectionId*>(i_section);
--        PNOR::SectionInfo_t l_info;
--        errlHndl_t l_errhdl = nullptr;
--
--        do {
--
--        if(isEnforcedSecureSection(*l_section))
--        {
--            TS_FAIL("readFromReadOnlyPartition: section %d is secure."
--                    " readFromReadOnlyPartition does not support testing"
--                    " secure sections.", *l_section);
--            break;
--        }
--
--        l_errhdl = PNOR::getSectionInfo(*l_section, l_info);
--        if(l_errhdl)
--        {
--            TRACFCOMP(g_trac_pnor, "readFromReadOnlyPartition: getSectionInfo "
--                      " returned an error for section %d : RC = 0x%.04x",
--                      *l_section, l_errhdl->reasonCode());
--            ERRORLOG::errlCommit(l_errhdl, PNOR_COMP_ID);
--            TS_FAIL("readFromReadOnlyPartition: failed to getSectionInfo"
--                    " for section %d", *l_section);
--            break;
--        }
--
--        uint64_t l_data = 0;
--        memcpy(&l_data, (void*)l_info.vaddr, sizeof(l_data));
--        // For this testing purpose, it doesn't actually matter what the data is
--        } while(0);
--        TRACFCOMP(g_trac_pnor, "readFromReadOnlyPartition End");
--        return nullptr;
--    }
--
--    static void* writeToReadOnlyPartition(void* i_section)
--    {
--        TRACFCOMP(g_trac_pnor, "writeToReadOnlyPartition Start");
--        PNOR::SectionId* l_section =
--                                reinterpret_cast<PNOR::SectionId*>(i_section);
--        PNOR::SectionInfo_t l_info;
--        errlHndl_t l_errhdl = nullptr;
--
--        do {
--
--        if(isEnforcedSecureSection(*l_section))
--        {
--            TS_FAIL("writeToReadOnlyPartition: section %d is secure."
--                    " writeToReadOnlyPartition does not support testing secure"
--                    " sections.", *l_section);
--            break;
--        }
--
--        l_errhdl = PNOR::getSectionInfo(*l_section, l_info);
--        if(l_errhdl)
--        {
--            TRACFCOMP(g_trac_pnor, "writeToReadOnlyPartition:"
--                      " getSectionInfo returned"
--                      " an error for section %d : RC=0x%.04x",
--                      *l_section, l_errhdl->reasonCode());
--            ERRORLOG::errlCommit(l_errhdl, PNOR_COMP_ID);
--            TS_FAIL("writeToReadOnlyPartition: could not read pnor section %d",
--                                                                    *l_section);
--            break;
--        }
--
--        // Write some data; should cause a task crash
--        const uint64_t l_writeData = 0x1122334455667788;
--        uint64_t* l_dataptr = reinterpret_cast<uint64_t*> (l_info.vaddr);
--        l_dataptr[0] = l_writeData;
--
--        int rc = mm_remove_pages(RELEASE, l_dataptr, PAGESIZE);
--        if(!rc)
--        {
--            TRACFCOMP(g_trac_pnor, "writeToReadOnlyPartition : uncaught "
--                      "exception - write to a readOnly partition succeeded");
--            TS_FAIL("writeToReadOnlyPartition : no error returned on writing to"
--                    " a readOnly partition");
--            break;
--        }
--
--        } while(0);
--        TRACFCOMP(g_trac_pnor, "writeToReadOnlyPartition End");
--        return nullptr;
--    }
-+     }
- };
- 
- 
-diff --git a/src/usr/secureboot/base/test/securerommgrtest.H b/src/usr/secureboot/base/test/securerommgrtest.H
-index 35e70f707598..8ffa8375daff 100644
---- a/src/usr/secureboot/base/test/securerommgrtest.H
-+++ b/src/usr/secureboot/base/test/securerommgrtest.H
-@@ -380,16 +380,6 @@ class SecureRomManagerTest : public CxxTest::TestSuite
-                                - VFS::VfsRp::getInstance().iv_unprotectedOffset
-                                + l_vaddr;
-         memcpy(l_originPage, reinterpret_cast<uint8_t*>(l_pnorVaddr), PAGESIZE);
--        // Open the write permissions to allow the test to temporarily corrupt
--        // the partition.
--        int l_rc = mm_set_permission(reinterpret_cast<void*>(l_pnorVaddr),
--                                     2*PAGESIZE,
--                                     WRITABLE);
--        if(l_rc)
--        {
--            TS_FAIL("mm_set_permission: Cannot set permissions to write");
--            break;
--        }
- 
-         // Corrupt page
-         uint8_t l_corruptByte = 0xFF;
-@@ -410,16 +400,6 @@ class SecureRomManagerTest : public CxxTest::TestSuite
-         delete l_errl;
-         l_errl = nullptr;
- 
--        // Reset to read-only permissions.
--        l_rc = mm_set_permission(reinterpret_cast<void*>(l_pnorVaddr),
--                                     2*PAGESIZE,
--                                     READ_ONLY);
--        if(l_rc)
--        {
--            TS_FAIL("mm_set_permission: Cannot reset permissions to read only");
--            break;
--        }
--
-         } while(0);
- 
-         if ( signedFile_pageAddr != nullptr   )
--- 
-2.14.3
-
diff --git a/openpower/package/openpower-pnor/openpower-pnor.mk b/openpower/package/openpower-pnor/openpower-pnor.mk
index 04511fb..8fe7e07 100644
--- a/openpower/package/openpower-pnor/openpower-pnor.mk
+++ b/openpower/package/openpower-pnor/openpower-pnor.mk
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-OPENPOWER_PNOR_VERSION ?= f6d970c6a600a7e248fa5d604eb471db4482760b
+OPENPOWER_PNOR_VERSION ?= 491ac2632f951ba77e2220ed87b8002b01ed6fae
 OPENPOWER_PNOR_SITE ?= $(call github,open-power,pnor,$(OPENPOWER_PNOR_VERSION))
 
 OPENPOWER_PNOR_LICENSE = Apache-2.0