Skip to content

Commit

Permalink
lib: Add helper for Raspberry Pi
Browse files Browse the repository at this point in the history
Moved code from swtpm_env_setup with these changes:
* improved grep pattern (previous would fit to also TPM-bypass)
* use record_info (script_output will fail the same way as
  assert_script_run)
* works for any RPI version (previously tied to RPI 4)

Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
pevik committed Aug 29, 2022
1 parent c854485 commit cfa8f14
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
37 changes: 37 additions & 0 deletions lib/rpi.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SUSE's openQA tests
#
# Copyright SUSE LLC
# SPDX-License-Identifier: FSFAP

package rpi;

use warnings;
use strict;

use Exporter 'import';
use testapi;
use power_action_utils 'power_action';

our @EXPORT = 'enable_tpm_slb9670';

# Enable TPM on Raspberry Pi
# https://en.opensuse.org/HCL:Raspberry_Pi3_TPM
sub enable_tpm_slb9670 {
my $module = "tpm_tis_spi";

assert_script_run('echo -e "dtparam=spi=on\ndtoverlay=tpm-slb9670" >> /boot/efi/extraconfig.txt');
assert_script_run('cat /boot/efi/extraconfig.txt');
assert_script_run("echo '$module' > /etc/modules-load.d/tpm.conf");
power_action('reboot', textmode => 1);

# Add some timeout to wait for reboot
sleep(60);

# Restore SSH connection
reset_consoles;
select_console('root-ssh');

record_info('RPi TPM', script_output("dmesg | grep '$module.*2.0 TPM.*device-id.*rev-id'"));
}

1;
24 changes: 8 additions & 16 deletions tests/security/swtpm/swtpm_env_setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,21 @@ use warnings;
use testapi;
use utils 'zypper_call';
use Utils::Architectures;
use power_action_utils qw(power_action);
use rpi 'enable_tpm_slb9670';

sub run {
my $self = shift;
$self->select_serial_terminal if !(get_var('MACHINE') =~ /RPi4/);

# Enable TPM on Raspberry Pi 4
# Refer: https://en.opensuse.org/HCL:Raspberry_Pi3_TPM
if (get_var('MACHINE') =~ /RPi4/) {
assert_script_run('echo -e "dtparam=spi=on\ndtoverlay=tpm-slb9670" >> /boot/efi/extraconfig.txt');
assert_script_run('cat /boot/efi/extraconfig.txt');
assert_script_run('echo "tpm_tis_spi" > /etc/modules-load.d/tpm.conf');
power_action('reboot', textmode => 1);
enable_tpm_slb9670;
} else {
$self->select_serial_terminal;
}

# Add some timeout to wait for reboot
sleep(60);
# Restore SSH connection
reset_consoles;
select_console('root-ssh');

assert_script_run('dmesg | grep tpm');
record_info('RPi4 TPM', 'Enabled TPM on Rasperry Pi 4');
}
# Enable TPM on Raspberry Pi 4
# Refer: https://en.opensuse.org/HCL:Raspberry_Pi3_TPM
enable_tpm_slb9670 if (get_var('MACHINE') =~ /RPi4/);

# Install the required packages for libvirt environment setup,
# "expect" is used for later remote login test, so install here as well
Expand Down

0 comments on commit cfa8f14

Please sign in to comment.