- self.path = u_boot_console.config.persistent_data_dir + '/' + filename
-
- if os.path.exists(self.path):
- u_boot_console.log.action('Disk image file ' + self.path +
- ' already exists')
- else:
- u_boot_console.log.action('Generating ' + self.path)
- fd = os.open(self.path, os.O_RDWR | os.O_CREAT)
- os.ftruncate(fd, 4194304)
- os.close(fd)
- cmd = ('sgdisk', '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe',
- self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
- cmd = ('sgdisk', '--new=1:2048:2560', self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
- cmd = ('sgdisk', '--new=2:4096:4608', self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
- cmd = ('sgdisk', '-l', self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+
+ persistent = u_boot_console.config.persistent_data_dir + '/' + filename
+ self.path = u_boot_console.config.result_dir + '/' + filename
+
+ with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
+ if os.path.exists(persistent):
+ u_boot_console.log.action('Disk image file ' + persistent +
+ ' already exists')
+ else:
+ u_boot_console.log.action('Generating ' + persistent)
+ fd = os.open(persistent, os.O_RDWR | os.O_CREAT)
+ os.ftruncate(fd, 4194304)
+ os.close(fd)
+ cmd = ('sgdisk',
+ '--disk-guid=375a56f7-d6c9-4e81-b5f0-09d41ca89efe',
+ persistent)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ # part1 offset 1MB size 1MB
+ cmd = ('sgdisk', '--new=1:2048:4095', '--change-name=1:part1',
+ persistent)
+ # part2 offset 2MB size 1.5MB
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ cmd = ('sgdisk', '--new=2:4096:7167', '--change-name=2:part2',
+ persistent)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+ cmd = ('sgdisk', '--load-backup=' + persistent)
+ u_boot_utils.run_and_log(u_boot_console, cmd)
+
+ cmd = ('cp', persistent, self.path)
+ u_boot_utils.run_and_log(u_boot_console, cmd)