target: Some improvements to partition selection
target: Some improvements to partition selection

Mainly, when selecting an "INACTIVE" partition, take into account
the valid flag. Also use sorting instead of branching if
statements.

SilverLiningSystems/cxmanage-test,Cynerva/cxmanage,SLS-Dev/cxmanage,SilverLiningSystems/cxmanage-test2,Cynerva/cxmanage,SilverLiningSystems/cxmanage-test2,SLS-Dev/cxmanage,SilverLiningSystems/cxmanage-test