Ejemplo n.º 1
0
def test_unsupported_gpio_platform():
    try:
        bitbang()
    except luma.core.error.UnsupportedPlatform as ex:
        assert str(ex) == 'GPIO access not available'
    except ImportError:
        pytest.skip(rpi_gpio_missing)
Ejemplo n.º 2
0
 def bitbang(self):
     from luma.core.interface.serial import bitbang
     GPIO = self.__init_alternative_GPIO()
     return bitbang(transfer_size=self.opts.spi_transfer_size,
                    reset_hold_time=self.opts.gpio_reset_hold_time,
                    reset_release_time=self.opts.gpio_reset_release_time,
                    gpio=self.gpio or GPIO)
Ejemplo n.º 3
0
 def run_blocking(self, oled, cmdline, reason, showerror=True, timeout=60):
     result = subprocess.run(cmdline, capture_output=True, timeout=timeout, env=self.environment)
     if (result.returncode != 0) or (len(result.stderr) != 0):
         if showerror:
             if oled == None: # special case when we're running an EC process that scrambles the OLED pins
                 oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
             self.display_error(oled, result.stdout, result.stderr)
         self.reasons.append(reason)
         self.passing = False
         return self.passing
Ejemplo n.º 4
0
def main():
    global SCRIPT
    oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
    oled.clear()
    with canvas(oled) as draw:
        draw.text((0, 0), "scriptminder.py started...", fill="White")
    time.sleep(3)

    while True:
        if checkIfProcessRunning(SCRIPT):
            print(SCRIPT + " is running, sleeping!")
            time.sleep(3)
        else:
            print(SCRIPT + " is not running, restarting it!")
            killScript(
                SCRIPT)  # just in case, so we don't have multiple copies
            subprocess.run(
                ['/home/pi/code/bootstrap-mainboard/factory-firmware.py'])
            time.sleep(3)
Ejemplo n.º 5
0
def test_data():
    data = (0xFF, 0x0F, 0x00)
    serial = bitbang(gpio=gpio, SCLK=13, SDA=14, CE=15, DC=16, RST=17)
    serial.data(data)

    reset = [call(17, gpio.LOW), call(17, gpio.HIGH)]
    clock = [call(13, gpio.HIGH), call(13, gpio.LOW)]
    data = lambda x: call(14, 0x80 if x == gpio.HIGH else 0x00)
    ce = lambda x: [call(15, x)]
    dc = lambda x: [call(16, x)]

    calls = reset + \
        dc(gpio.HIGH) + \
        ce(gpio.LOW) + \
        (([data(gpio.HIGH)] + clock) * 8) + \
        (([data(gpio.LOW)] + clock) * 4) + \
        (([data(gpio.HIGH)] + clock) * 4) + \
        (([data(gpio.LOW)] + clock) * 8) + \
        ce(gpio.HIGH)

    gpio.output.assert_has_calls(calls)
Ejemplo n.º 6
0
 def __bitbang__(self):
     from luma.core.interface.serial import bitbang
     return bitbang(SCLK=24, SDA=23)
Ejemplo n.º 7
0
def test_cleanup_custom_pins():
    serial = bitbang(gpio=gpio, SCLK=13, SDA=14, CE=15, DC=16, RST=17)
    serial._managed = True
    serial.cleanup()
    assert_only_cleans_whats_setup(gpio)
Ejemplo n.º 8
0
def test_cleanup():
    serial = bitbang(gpio=gpio)
    serial._managed = True
    serial.cleanup()
    assert_only_cleans_whats_setup(gpio)
Ejemplo n.º 9
0
def test_cleanup():
    serial = bitbang(gpio=gpio)
    serial._managed = True
    serial.cleanup()
    gpio.cleanup.assert_called_once_with()
Ejemplo n.º 10
0
               time.sleep(0.2)
           else:
                do_menu()

       # wait for the operator to let go of the switch
       while GPIO.input(GPIO_START) == GPIO.HIGH:
           time.sleep(0.1)
                  
       loops += 1
       if logfile:
           logfile.write("------------------------------------------------------------------\n".format(loops, str(datetime.now())))
           logfile.write("Starting run {} at {}\n".format(loops, str(datetime.now())))
           logfile.flush()
       
       run_tests(tests, logfile=logfile)

def cleanup():
    reset_tester_outputs()
    GPIO.cleanup()
    
if __name__ == "__main__":
    global environment
    environment = os.environ.copy() 
    atexit.register(cleanup)
    try:
        print("Tester main loop starting...")
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        main()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 11
0
    def run(self, oled):
        self.passing = True
        self.has_run = True

        with canvas(oled) as draw:
            draw.text((0, 0), "Stop SoC boot...", fill="white")
        time.sleep(0.2)

        if False == self.run_nonblocking(oled, [
                'betrusted-scripts/jtag-tools/jtag_gpio.py', '-f',
                'precursors/blank_short.bin', '--erase', '-a', '0',
                '--erase-len=0x1000', '-r'
        ],
                                         reason="Stop SoC boot failed",
                                         timeout=20,
                                         title='Ensure SoC blank...'):
            return self.passing

        with canvas(oled) as draw:
            draw.text((0, 0), "Burning WFX firmware...", fill="white")
        time.sleep(0.5)

        # oled is None for EC because the firmware burner program is contra-indicated with the oled interface
        # (as in they share the same pins so the interface has to be rebuilt after every call)
        if False == self.run_blocking(None, [
                'sudo', 'fomu-flash/fomu-flash', '-w', self.wfx_firmware, '-a',
                '0x9C000', '-q'
        ],
                                      reason="EC|WFX firmware burn failure",
                                      timeout=60):
            return self.passing

        # must regenerate the OLED interface because it's co-opted by the EC firmware commands
        oled.cleanup()
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        with canvas(oled) as draw:
            draw.text((0, 0), "Verifying WFX firmware...", fill="white")
        time.sleep(0.5)

        if False == self.run_blocking(None, [
                'sudo', 'fomu-flash/fomu-flash', '-v', self.wfx_firmware, '-a',
                '0x9C000', '-q'
        ],
                                      reason="EC|WFX firmware verify failure",
                                      timeout=10):
            return self.passing

        oled.cleanup()
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        with canvas(oled) as draw:
            draw.text((0, 0), "Burning EC firmware...", fill="white")
        time.sleep(0.5)

        if False == self.run_blocking(None,
                                      ['sudo', 'fomu-flash/fomu-flash', '-4'],
                                      reason="Set QSPI mode",
                                      timeout=2):
            return self.passing

        if False == self.run_blocking(
                None,
            ['sudo', 'fomu-flash/fomu-flash', '-w', self.ec_firmware, '-q'],
                reason="EC main firmware burn failure",
                timeout=60):
            return self.passing

        oled.cleanup()
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        with canvas(oled) as draw:
            draw.text((0, 0), "Verifying EC firmware...", fill="white")
        time.sleep(0.5)

        if False == self.run_blocking(
                None,
            ['sudo', 'fomu-flash/fomu-flash', '-v', self.ec_firmware, '-q'],
                reason="EC main firmware verify failure",
                timeout=10):
            return self.passing

        # disable the UP5K drive explicitly to make sure we aren't intefering with normal operation
        GPIO.output(GPIO_DRV_UP5K_N, 1)

        oled.cleanup()
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        with canvas(oled) as draw:
            draw.text((0, 0), "Restarting EC...", fill="white")
        time.sleep(0.5)

        if False == self.run_blocking(None,
                                      ['sudo', 'fomu-flash/fomu-flash', '-r'],
                                      reason="EC reboot failure",
                                      timeout=10):
            return self.passing

        oled.cleanup()
        oled = ssd1322(bitbang(SCLK=11, SDA=10, CE=7, DC=1, RST=12))
        with canvas(oled) as draw:
            draw.text((0, 0), "EC burning complete!", fill="white")
        time.sleep(1)
        oled.clear()
        time.sleep(0.2)

        if self.logfile:
            self.logfile.write(self.sha256sum(self.wfx_firmware))
            self.logfile.write(self.sha256sum(self.ec_firmware))

        return self.passing