link-intel-driver.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/python
  2. import sys, os, re
  3. isgx_path = os.getenv("ISGX_DRIVER_PATH")
  4. isgx_version = os.getenv("ISGX_DRIVER_VERSION")
  5. try:
  6. # get the locations of directories
  7. print "\n" + \
  8. "*****************************************************************\n" + \
  9. "Make sure you have downloaded and installed the Intel sgx driver \n" + \
  10. "from https://github.com/01org/linux-sgx-driver.\n" + \
  11. "*****************************************************************\n" + \
  12. "\n"
  13. while True:
  14. if not isgx_path:
  15. isgx_path = raw_input('Enter the Intel SGX driver derctory: ')
  16. if os.path.exists(isgx_path + '/sgx.h'):
  17. break
  18. if os.path.exists(isgx_path + '/isgx.h'):
  19. break
  20. print '{0} is not a directory for the Intel SGX driver'.format(isgx_path)
  21. isgx_path = None
  22. # get the driver version
  23. while True:
  24. if not isgx_version:
  25. isgx_version = raw_input('Enter the driver version (default: 1.9, 1.9 means "1.9 and above"): ')
  26. if not isgx_version:
  27. isgx_version_major = 1
  28. isgx_version_minor = 9
  29. break
  30. m = re.match('([1-9])\.([0-9]+)', isgx_version)
  31. if m:
  32. isgx_version_major = m.group(1)
  33. isgx_version_minor = m.group(2)
  34. break
  35. print '{0} is not a valid version (x.xx)'.format(isgx_version)
  36. isgx_version = None
  37. # create a symbolic link called 'linux-sgx-driver'
  38. isgx_link = 'linux-sgx-driver'
  39. isgx_path = os.path.abspath(isgx_path)
  40. print isgx_link + ' -> ' + isgx_path
  41. if os.path.exists(isgx_link):
  42. os.unlink(isgx_link)
  43. os.symlink(isgx_path, isgx_link)
  44. # create isgx_version.h
  45. with open('isgx_version.h', 'w') as versionfile:
  46. print 'create isgx_version.h'
  47. print >> versionfile, '#include <linux/version.h>'
  48. print >> versionfile
  49. print >> versionfile, '#define SDK_DRIVER_VERSION KERNEL_VERSION(' + \
  50. str(isgx_version_major) + ',' + \
  51. str(isgx_version_minor) + ',0)'
  52. print >> versionfile, '#define SDK_DRIVER_VERSION_STRING "' + \
  53. str(isgx_version_major) + '.' + \
  54. str(isgx_version_minor) + '"'
  55. except:
  56. print 'uh-oh: {0}'.format(sys.exc_info()[0])
  57. exit(-1)