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
1diff --git a/DistUpgrade/DistUpgradeQuirks.py b/DistUpgrade/DistUpgradeQuirks.py
2index ed4534d..17ae602 100644
3--- a/DistUpgrade/DistUpgradeQuirks.py
4+++ b/DistUpgrade/DistUpgradeQuirks.py
5@@ -142,6 +142,9 @@ class DistUpgradeQuirks(object):
6 if cache['snapd'].is_installed and \
7 self._snap_list:
8 self._replaceDebsAndSnaps()
9+ if 'ubuntu-desktop-raspi' in cache:
10+ if cache['ubuntu-desktop-rapsi'].is_installed:
11+ self._replace_fkms_overlay()
12
13 # individual quirks handler when the dpkg run is finished ---------
14 def PostCleanup(self):
15@@ -1110,3 +1113,54 @@ class DistUpgradeQuirks(object):
16
17 self._snap_list[snap] = snap_object
18 return self._snap_list
19+
20+ def _replace_fkms_overlay(self, boot_dir='/boot/firmware'):
21+ failure_action = (
22+ "you may need to replace the vc4-fkms-v3d overlay with "
23+ "vc4-kms-v3d in config.txt on your boot partition")
24+
25+ try:
26+ boot_config_filename = os.path.join(boot_dir, 'config.txt')
27+ with open(boot_config_filename, 'r', encoding='utf-8') as f:
28+ boot_config = f.read()
29+ except FileNotFoundError:
30+ logging.error("failed to open boot configuration in %s; %s",
31+ boot_config_filename, failure_action)
32+ return
33+
34+ new_config = ''.join(
35+ # startswith and replace used to cope with (and preserve) any
36+ # trailing d-t parameters, and any use of the -pi4 suffix
37+ '# changed by do-release-upgrade (LP: #1923673)\n#' + line +
38+ line.replace('dtoverlay=vc4-fkms-v3d', 'dtoverlay=vc4-kms-v3d')
39+ if line.startswith('dtoverlay=vc4-fkms-v3d') else
40+ # camera firmware disabled due to incompatibility with "full" kms
41+ # overlay; without the camera firmware active it's also better to
42+ # disable gpu_mem leaving the default (64MB) to allow as much as
43+ # possible for the KMS driver
44+ '# disabled by do-release-upgrade (LP: #1923673)\n#' + line
45+ if line.startswith('gpu_mem=') or line.rstrip() == 'start_x=1' else
46+ line
47+ for line in boot_config.splitlines(keepends=True)
48+ )
49+
50+ if new_config == boot_config:
51+ logging.warning("no fkms overlay or camera firmware line found "
52+ "in %s", boot_config_filename)
53+ return
54+
55+ try:
56+ boot_backup_filename = os.path.join(
57+ boot_dir, 'config.txt.distUpgrade')
58+ with open(boot_backup_filename, 'w', encoding='utf-8') as f:
59+ f.write(boot_config)
60+ except IOError as exc:
61+ logging.error("unable to write boot config backup to %s: %s; %s",
62+ boot_backup_filename, exc, failure_action)
63+ return
64+ try:
65+ with open(boot_config_filename, 'w', encoding='utf-8') as f:
66+ f.write(new_config)
67+ except IOError as exc:
68+ logging.error("unable to write new boot config to %s: %s; %s",
69+ boot_config_filename, exc, failure_action)
70diff --git a/debian/changelog b/debian/changelog
71index a006a24..d7af5c7 100644
72--- a/debian/changelog
73+++ b/debian/changelog
74@@ -1,3 +1,11 @@
75+ubuntu-release-upgrader (1:21.04.9) hirsute; urgency=medium
76+
77+ * DistUpgrade/DistUpgradeQuirks.py: Add quirk to rewrite references to fkms
78+ overlay in Raspberry Pi boot configuration to kms overlay (and disable the
79+ related camera firmware lines). (LP: #1923673)
80+
81+ -- Dave Jones <dave.jones@canonical.com> Tue, 13 Apr 2021 23:34:22 +0100
82+
83 ubuntu-release-upgrader (1:21.04.8) hirsute; urgency=medium
84
85 * DistUpgrade/DistUpgradeQuirks.py: Modify the deb-to-snap quirk to also
86diff --git a/tests/test_quirks.py b/tests/test_quirks.py
87index 30f83d5..cc4c8f1 100644
88--- a/tests/test_quirks.py
89+++ b/tests/test_quirks.py
90@@ -446,6 +446,79 @@ class TestQuirks(unittest.TestCase):
91 q._test_and_fail_on_aufs()
92 self.assertTrue(len(mock_controller.abort.mock_calls))
93
94+ def test_replace_fkms_overlay_no_config(self):
95+ with tempfile.TemporaryDirectory() as boot_dir:
96+ mock_controller = mock.Mock()
97+
98+ q = DistUpgradeQuirks(mock_controller, mock.Mock())
99+
100+ q._replace_fkms_overlay(boot_dir)
101+ self.assertFalse(os.path.exists(os.path.join(
102+ boot_dir, 'config.txt.distUpgrade')))
103+
104+ def test_replace_fkms_overlay_no_changes(self):
105+ with tempfile.TemporaryDirectory() as boot_dir:
106+ demo_config = ("# This is a demo boot config\n"
107+ "[pi4\n"
108+ "max_framebuffers=2\n"
109+ "[all]\n"
110+ "arm_64bit=1\n"
111+ "kernel=vmlinuz\n"
112+ "initramfs initrd.img followkernel\n")
113+ with open(os.path.join(boot_dir, 'config.txt'), 'w') as f:
114+ f.write(demo_config)
115+
116+ mock_controller = mock.Mock()
117+
118+ q = DistUpgradeQuirks(mock_controller, mock.Mock())
119+
120+ q._replace_fkms_overlay(boot_dir)
121+ self.assertFalse(os.path.exists(os.path.join(
122+ boot_dir, 'config.txt.distUpgrade')))
123+ with open(os.path.join(boot_dir, 'config.txt')) as f:
124+ self.assertTrue(f.read() == demo_config)
125+
126+ def test_replace_fkms_overlay_with_changes(self):
127+ with tempfile.TemporaryDirectory() as boot_dir:
128+ demo_config = (
129+ "# This is a demo boot config\n"
130+ "[pi4\n"
131+ "max_framebuffers=2\n"
132+ "[all]\n"
133+ "arm_64bit=1\n"
134+ "kernel=vmlinuz\n"
135+ "initramfs initrd.img followkernel\n"
136+ "dtoverlay=vc4-fkms-v3d,cma-256\n"
137+ "start_x=1\n"
138+ "gpu_mem=256\n")
139+ expected_config = (
140+ "# This is a demo boot config\n"
141+ "[pi4\n"
142+ "max_framebuffers=2\n"
143+ "[all]\n"
144+ "arm_64bit=1\n"
145+ "kernel=vmlinuz\n"
146+ "initramfs initrd.img followkernel\n"
147+ "# changed by do-release-upgrade (LP: #1923673)\n"
148+ "#dtoverlay=vc4-fkms-v3d,cma-256\n"
149+ "dtoverlay=vc4-kms-v3d,cma-256\n"
150+ "# disabled by do-release-upgrade (LP: #1923673)\n"
151+ "#start_x=1\n"
152+ "# disabled by do-release-upgrade (LP: #1923673)\n"
153+ "#gpu_mem=256\n")
154+ with open(os.path.join(boot_dir, 'config.txt'), 'w') as f:
155+ f.write(demo_config)
156+
157+ mock_controller = mock.Mock()
158+
159+ q = DistUpgradeQuirks(mock_controller, mock.Mock())
160+
161+ q._replace_fkms_overlay(boot_dir)
162+ self.assertTrue(os.path.exists(os.path.join(
163+ boot_dir, 'config.txt.distUpgrade')))
164+ with open(os.path.join(boot_dir, 'config.txt')) as f:
165+ self.assertTrue(f.read() == expected_config)
166+
167
168 class TestSnapQuirks(unittest.TestCase):
169

Subscribers

People subscribed via source and target branches