Merge ~waveform/ubuntu-release-upgrader:rewrite-fkms-overlay into ubuntu-release-upgrader:ubuntu/master

Proposed by Dave Jones
Status: Merged
Merged at revision: 5b6b0088aba9cff1b31835f2d158e4d7568365e6
Proposed branch: ~waveform/ubuntu-release-upgrader:rewrite-fkms-overlay
Merge into: ubuntu-release-upgrader:ubuntu/master
Diff against target: 168 lines (+135/-0)
3 files modified
DistUpgrade/DistUpgradeQuirks.py (+54/-0)
debian/changelog (+8/-0)
tests/test_quirks.py (+73/-0)
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+401236@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/DistUpgrade/DistUpgradeQuirks.py b/DistUpgrade/DistUpgradeQuirks.py
index ed4534d..17ae602 100644
--- a/DistUpgrade/DistUpgradeQuirks.py
+++ b/DistUpgrade/DistUpgradeQuirks.py
@@ -142,6 +142,9 @@ class DistUpgradeQuirks(object):
142 if cache['snapd'].is_installed and \142 if cache['snapd'].is_installed and \
143 self._snap_list:143 self._snap_list:
144 self._replaceDebsAndSnaps()144 self._replaceDebsAndSnaps()
145 if 'ubuntu-desktop-raspi' in cache:
146 if cache['ubuntu-desktop-rapsi'].is_installed:
147 self._replace_fkms_overlay()
145148
146 # individual quirks handler when the dpkg run is finished ---------149 # individual quirks handler when the dpkg run is finished ---------
147 def PostCleanup(self):150 def PostCleanup(self):
@@ -1110,3 +1113,54 @@ class DistUpgradeQuirks(object):
11101113
1111 self._snap_list[snap] = snap_object1114 self._snap_list[snap] = snap_object
1112 return self._snap_list1115 return self._snap_list
1116
1117 def _replace_fkms_overlay(self, boot_dir='/boot/firmware'):
1118 failure_action = (
1119 "you may need to replace the vc4-fkms-v3d overlay with "
1120 "vc4-kms-v3d in config.txt on your boot partition")
1121
1122 try:
1123 boot_config_filename = os.path.join(boot_dir, 'config.txt')
1124 with open(boot_config_filename, 'r', encoding='utf-8') as f:
1125 boot_config = f.read()
1126 except FileNotFoundError:
1127 logging.error("failed to open boot configuration in %s; %s",
1128 boot_config_filename, failure_action)
1129 return
1130
1131 new_config = ''.join(
1132 # startswith and replace used to cope with (and preserve) any
1133 # trailing d-t parameters, and any use of the -pi4 suffix
1134 '# changed by do-release-upgrade (LP: #1923673)\n#' + line +
1135 line.replace('dtoverlay=vc4-fkms-v3d', 'dtoverlay=vc4-kms-v3d')
1136 if line.startswith('dtoverlay=vc4-fkms-v3d') else
1137 # camera firmware disabled due to incompatibility with "full" kms
1138 # overlay; without the camera firmware active it's also better to
1139 # disable gpu_mem leaving the default (64MB) to allow as much as
1140 # possible for the KMS driver
1141 '# disabled by do-release-upgrade (LP: #1923673)\n#' + line
1142 if line.startswith('gpu_mem=') or line.rstrip() == 'start_x=1' else
1143 line
1144 for line in boot_config.splitlines(keepends=True)
1145 )
1146
1147 if new_config == boot_config:
1148 logging.warning("no fkms overlay or camera firmware line found "
1149 "in %s", boot_config_filename)
1150 return
1151
1152 try:
1153 boot_backup_filename = os.path.join(
1154 boot_dir, 'config.txt.distUpgrade')
1155 with open(boot_backup_filename, 'w', encoding='utf-8') as f:
1156 f.write(boot_config)
1157 except IOError as exc:
1158 logging.error("unable to write boot config backup to %s: %s; %s",
1159 boot_backup_filename, exc, failure_action)
1160 return
1161 try:
1162 with open(boot_config_filename, 'w', encoding='utf-8') as f:
1163 f.write(new_config)
1164 except IOError as exc:
1165 logging.error("unable to write new boot config to %s: %s; %s",
1166 boot_config_filename, exc, failure_action)
diff --git a/debian/changelog b/debian/changelog
index a006a24..d7af5c7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
1ubuntu-release-upgrader (1:21.04.9) hirsute; urgency=medium
2
3 * DistUpgrade/DistUpgradeQuirks.py: Add quirk to rewrite references to fkms
4 overlay in Raspberry Pi boot configuration to kms overlay (and disable the
5 related camera firmware lines). (LP: #1923673)
6
7 -- Dave Jones <dave.jones@canonical.com> Tue, 13 Apr 2021 23:34:22 +0100
8
1ubuntu-release-upgrader (1:21.04.8) hirsute; urgency=medium9ubuntu-release-upgrader (1:21.04.8) hirsute; urgency=medium
210
3 * DistUpgrade/DistUpgradeQuirks.py: Modify the deb-to-snap quirk to also11 * DistUpgrade/DistUpgradeQuirks.py: Modify the deb-to-snap quirk to also
diff --git a/tests/test_quirks.py b/tests/test_quirks.py
index 30f83d5..cc4c8f1 100644
--- a/tests/test_quirks.py
+++ b/tests/test_quirks.py
@@ -446,6 +446,79 @@ class TestQuirks(unittest.TestCase):
446 q._test_and_fail_on_aufs()446 q._test_and_fail_on_aufs()
447 self.assertTrue(len(mock_controller.abort.mock_calls))447 self.assertTrue(len(mock_controller.abort.mock_calls))
448448
449 def test_replace_fkms_overlay_no_config(self):
450 with tempfile.TemporaryDirectory() as boot_dir:
451 mock_controller = mock.Mock()
452
453 q = DistUpgradeQuirks(mock_controller, mock.Mock())
454
455 q._replace_fkms_overlay(boot_dir)
456 self.assertFalse(os.path.exists(os.path.join(
457 boot_dir, 'config.txt.distUpgrade')))
458
459 def test_replace_fkms_overlay_no_changes(self):
460 with tempfile.TemporaryDirectory() as boot_dir:
461 demo_config = ("# This is a demo boot config\n"
462 "[pi4\n"
463 "max_framebuffers=2\n"
464 "[all]\n"
465 "arm_64bit=1\n"
466 "kernel=vmlinuz\n"
467 "initramfs initrd.img followkernel\n")
468 with open(os.path.join(boot_dir, 'config.txt'), 'w') as f:
469 f.write(demo_config)
470
471 mock_controller = mock.Mock()
472
473 q = DistUpgradeQuirks(mock_controller, mock.Mock())
474
475 q._replace_fkms_overlay(boot_dir)
476 self.assertFalse(os.path.exists(os.path.join(
477 boot_dir, 'config.txt.distUpgrade')))
478 with open(os.path.join(boot_dir, 'config.txt')) as f:
479 self.assertTrue(f.read() == demo_config)
480
481 def test_replace_fkms_overlay_with_changes(self):
482 with tempfile.TemporaryDirectory() as boot_dir:
483 demo_config = (
484 "# This is a demo boot config\n"
485 "[pi4\n"
486 "max_framebuffers=2\n"
487 "[all]\n"
488 "arm_64bit=1\n"
489 "kernel=vmlinuz\n"
490 "initramfs initrd.img followkernel\n"
491 "dtoverlay=vc4-fkms-v3d,cma-256\n"
492 "start_x=1\n"
493 "gpu_mem=256\n")
494 expected_config = (
495 "# This is a demo boot config\n"
496 "[pi4\n"
497 "max_framebuffers=2\n"
498 "[all]\n"
499 "arm_64bit=1\n"
500 "kernel=vmlinuz\n"
501 "initramfs initrd.img followkernel\n"
502 "# changed by do-release-upgrade (LP: #1923673)\n"
503 "#dtoverlay=vc4-fkms-v3d,cma-256\n"
504 "dtoverlay=vc4-kms-v3d,cma-256\n"
505 "# disabled by do-release-upgrade (LP: #1923673)\n"
506 "#start_x=1\n"
507 "# disabled by do-release-upgrade (LP: #1923673)\n"
508 "#gpu_mem=256\n")
509 with open(os.path.join(boot_dir, 'config.txt'), 'w') as f:
510 f.write(demo_config)
511
512 mock_controller = mock.Mock()
513
514 q = DistUpgradeQuirks(mock_controller, mock.Mock())
515
516 q._replace_fkms_overlay(boot_dir)
517 self.assertTrue(os.path.exists(os.path.join(
518 boot_dir, 'config.txt.distUpgrade')))
519 with open(os.path.join(boot_dir, 'config.txt')) as f:
520 self.assertTrue(f.read() == expected_config)
521
449522
450class TestSnapQuirks(unittest.TestCase):523class TestSnapQuirks(unittest.TestCase):
451524

Subscribers

People subscribed via source and target branches