@ -15,8 +15,11 @@
# include "helper.hpp"
std : : vector < std : : string > splitString ( const std : : string & subject ) {
if ( subject . size ( ) = = 0 ) {
return std : : vector < std : : string > ( ) ;
}
static const std : : regex re { " \\ s+ " } ;
std : : vector < std : : string > container {
std : : vector < std : : string > container {
std : : sregex_token_iterator ( subject . begin ( ) , subject . end ( ) , re , - 1 ) ,
std : : sregex_token_iterator ( )
} ;
@ -24,27 +27,63 @@ std::vector<std::string> splitString(const std::string& subject) {
}
int main ( int , char * * ) {
auto cfigOps = CfigAvbOps ( ) ;
auto preloads = getenv ( " preload " ) ;
int flags = AVB_SLOT_VERIFY_FLAGS_NONE ;
//param 1: preload partitions
auto preloads = getenv ( " preloads " ) ;
if ( preloads = = NULL ) {
} else {
preloads = ( char * ) " " ;
}
std : : cout < < " [ " < < __FUNCTION__ < < " ]: partitions to preload: " < < preloads < < std : : endl ;
//param 2: requested partitions
auto requests = getenv ( " requests " ) ;
if ( requests = = NULL ) {
requests = ( char * ) " " ;
}
std : : cout < < " [ " < < __FUNCTION__ < < " ]: requested partitions: " < < requests < < std : : endl ;
auto requestVec = splitString ( requests ) ;
//example: const char* requestedPartitions[] = { (const char*) "boot", (const char*)NULL };
const char * requestedPartitions [ requestVec . size ( ) + 1 ] ;
for ( int i = 0 ; i < requestVec . size ( ) ; i + + ) {
requestedPartitions [ i ] = requestVec [ i ] . c_str ( ) ;
if ( requestVec [ i ] = = " recovery " ) {
flags | = AVB_SLOT_VERIFY_FLAGS_NO_VBMETA_PARTITION ;
std : : cout < < " [ " < < __FUNCTION__ < < " ]: using NO-VBMETA mode for recovery " < < std : : endl ;
}
}
requestedPartitions [ requestVec . size ( ) ] = ( const char * ) NULL ;
//param3: ab_suffix
auto abSuffix = getenv ( " suffix " ) ;
if ( abSuffix = = NULL ) {
abSuffix = ( char * ) " " ;
}
std : : cout < < " [ " < < __FUNCTION__ < < " ]: ab_suffix: " < < abSuffix < < std : : endl ;
//main
auto cfigOps = CfigAvbOps ( ) ;
{ //preload partitions
auto preloadVec = splitString ( preloads ) ;
for ( auto item : preloadVec ) {
cfigOps . preload_partition ( item ) ;
}
}
cfigOps . preload_partition ( " vbmeta " ) ;
bool isDeviceLocked = true ;
cfigOps . avb_ops_ . read_is_device_unlocked ( NULL , & isDeviceLocked ) ;
if ( isDeviceLocked ) {
flags | = AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR ;
}
std : : cout < < " [ " < < __FUNCTION__ < < " ]: flags: " < < flags < < std : : endl ;
AvbSlotVerifyData * slotData = NULL ;
const char * requestedPartitions [ ] = { ( const char * ) " boot " , ( const char * ) NULL } ;
AvbSlotVerifyResult result = avb_slot_verify (
& ( cfigOps . avb_ops_ ) ,
requestedPartitions ,
" " ,
AVB_SLOT_VERIFY_FLAGS_NONE ,
abSuffix , /* ab_suffix */
static_cast < AvbSlotVerifyFlags > ( flags ) , /* AvbSlotVerifyFlags */
AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE ,
& slotData ) ;
std : : cout < < " AvbSlotVerifyResult = " < < toString ( result ) < < std : : endl ;
if ( AVB_SLOT_VERIFY_RESULT_OK = = result ) {
auto outFile = " verify_result.json " ;
std : : cout < < " Writing result to " < < outFile < < " ... " ;
@ -52,6 +91,9 @@ int main(int, char**) {
outJson < < toString ( slotData ) ;
outJson . close ( ) ;
std : : cout < < " done " < < std : : endl ;
std : : cout < < " Run: \n python -m json.tool " < < outFile < < std : : endl ;
}
if ( slotData ) { avb_slot_verify_data_free ( slotData ) ; }
std : : cerr < < " \n \t Verify Result: " < < toString ( result ) < < std : : endl ;
return 0 ;
}