Skip to content

Instantly share code, notes, and snippets.

@r0mdau
Last active March 21, 2023 08:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r0mdau/8d9ebfde39ae2ae109738a41c740b0e3 to your computer and use it in GitHub Desktop.
Save r0mdau/8d9ebfde39ae2ae109738a41c740b0e3 to your computer and use it in GitHub Desktop.
Python script to check raspberry pi SD card health
#!/usr/bin/python3
import os
def writeSomeBytesSucceed(datas):
filepath = "/sdCardTest.raw"
testpattern = bytes(datas)
writer = open(filepath, "wb", buffering=0)
writer.write(testpattern)
writer.close()
reader = open(filepath, "rb", buffering=0)
reader.seek(0)
testpattern_read = reader.read(8)
result = testpattern_read == testpattern
reader.close()
os.remove(filepath)
return result
if writeSomeBytesSucceed([0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55]) is False or writeSomeBytesSucceed(
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa]) is False:
print("ERROR writing test pattern !")
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment