Home | History | Annotate | Download | only in Common
      1 # # @file

      2 # 

      3 # This file is used to handle the variable attributes and property information

      4 #

      5 #

      6 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>

      7 # This program and the accompanying materials

      8 # are licensed and made available under the terms and conditions of the BSD License

      9 # which accompanies this distribution.  The full text of the license may be found at

     10 # http://opensource.org/licenses/bsd-license.php

     11 #

     12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

     13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

     14 #

     15    
     16 class VariableAttributes(object):
     17     EFI_VARIABLE_NON_VOLATILE = 0x00000001
     18     EFI_VARIABLE_BOOTSERVICE_ACCESS = 0x00000002
     19     EFI_VARIABLE_RUNTIME_ACCESS = 0x00000004
     20     VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY = 0x00000001
     21     VarAttributesMap = {
     22                      "NV":EFI_VARIABLE_NON_VOLATILE,
     23                      "BS":EFI_VARIABLE_BOOTSERVICE_ACCESS,
     24                      "RT":EFI_VARIABLE_RUNTIME_ACCESS,
     25                      "RO":VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY
     26                      }
     27     
     28     def __init__(self):
     29         pass
     30     
     31     @staticmethod
     32     def GetVarAttributes(var_attr_str):
     33         VarAttr = 0x00000000
     34         VarProp = 0x00000000
     35         
     36         attr_list = var_attr_str.split(",")
     37         for attr in attr_list:
     38             attr = attr.strip()
     39             if attr == 'RO':
     40                 VarProp = VariableAttributes.VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY
     41             else:
     42                 VarAttr = VarAttr | VariableAttributes.VarAttributesMap.get(attr, 0x00000000)   
     43         return VarAttr, VarProp
     44     @staticmethod
     45     def ValidateVarAttributes(var_attr_str):
     46         if not var_attr_str:
     47             return True, ""
     48         attr_list = var_attr_str.split(",")
     49         attr_temp = []
     50         for attr in attr_list:
     51             attr = attr.strip()
     52             attr_temp.append(attr)
     53             if attr not in VariableAttributes.VarAttributesMap:
     54                 return False, "The variable attribute %s is not support to be specified in dsc file. Supported variable attribute are ['BS','NV','RT','RO'] "
     55         if 'RT' in attr_temp and 'BS' not in attr_temp:
     56             return False, "the RT attribute need the BS attribute to be present"
     57         return True, ""
     58