Skip to content

Commit 7fd7352

Browse files
authored
Merge pull request #28 from a3s7p/arm64
arm64
2 parents 998de3b + 006a918 commit 7fd7352

File tree

2 files changed

+91
-33
lines changed

2 files changed

+91
-33
lines changed

fablib/installer.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
logger = logging.getLogger('fab.installer')
1919

2020
import hashlib
21-
import debian
21+
from debian import debfile
2222

2323
from chroot import Chroot
2424
from fablib import common
@@ -86,7 +86,7 @@ def __init__(self, path: str, lines: Iterable[str]):
8686
class Installer:
8787
def __init__(
8888
self, chroot_path: str,
89-
environ: Optional[Dict[str, str]]=None
89+
environ: dict[str, str] = None
9090
):
9191
if environ is None:
9292
environ = {}
@@ -96,7 +96,7 @@ def __init__(
9696
self.chroot = Chroot(chroot_path, environ=env)
9797

9898
@staticmethod
99-
def _get_packages_priority(packages: List[str]) -> Tuple[List[str], List[str]]:
99+
def _get_packages_priority(packages: list[str]) -> tuple[list[str], list[str]]:
100100
"""high priority packages must be installed before regular packages
101101
APT should handle this, but in some circumstances it chokes...
102102
"""
@@ -114,9 +114,9 @@ def _get_packages_priority(packages: List[str]) -> Tuple[List[str], List[str]]:
114114
return high, regular
115115

116116
def _install(
117-
self, packages: List[str],
118-
ignore_errors: Optional[List[str]]=None,
119-
extra_apt_args: Optional[List[str]]=None) -> None:
117+
self, packages: list[str],
118+
ignore_errors: list[str] = None,
119+
extra_apt_args: list[str] = None) -> None:
120120

121121
if ignore_errors is None:
122122
ignore_errors = []
@@ -139,7 +139,7 @@ def _install(
139139
"#!/bin/sh",
140140
"echo",
141141
'echo "Warning: Deferring update-initramfs $@"',
142-
'echo "update-initramfs $@" >> /%s' % defer_log,
142+
f'echo "update-initramfs $@" >> /{defer_log}'
143143
]
144144

145145
for packages in (high, regular):
@@ -150,7 +150,7 @@ def _install(
150150
f"apt-get {' '.join((args + packages))}")
151151
if apt_return_code != 0:
152152

153-
def get_last_log(path: str) -> List[str]:
153+
def get_last_log(path: str) -> list[str]:
154154
log = []
155155
with open(path) as fob:
156156
for line in fob:
@@ -163,7 +163,7 @@ def get_last_log(path: str) -> List[str]:
163163
log.reverse()
164164
return log
165165

166-
def get_errors(log: List[str], error_str: str) -> List[str]:
166+
def get_errors(log: list[str], error_str: str) -> list[str]:
167167
errors = []
168168
for line in reversed(log):
169169
if line == error_str:
@@ -195,13 +195,11 @@ def get_errors(log: List[str], error_str: str) -> List[str]:
195195
errors = set(errors) - set(ignore_errors)
196196

197197
if ignored_errors:
198-
print(
199-
"Warning: ignoring package installation errors (%s)"
200-
% " ".join(ignored_errors)
201-
)
198+
print(f"Warning: ignoring package installation errors"
199+
f" ({' '.join(ignored_errors)})")
202200

203201
if errors:
204-
for error in error:
202+
for error in errors:
205203
common.error(error)
206204
raise Error('package installation errors')
207205

@@ -225,15 +223,15 @@ def get_errors(log: List[str], error_str: str) -> List[str]:
225223
os.remove(defer_log)
226224

227225
def install(
228-
self, packages: List[str],
229-
ignore_errors: Optional[List[str]]=None) -> None:
226+
self, packages: list[str],
227+
ignore_errors: list[str] = None) -> None:
230228
raise NotImplementedError()
231229

232230

233231
class PoolInstaller(Installer):
234232
def __init__(
235233
self, chroot_path: str, pool_path: str,
236-
arch: str, environ: Optional[Dict[str, str]]=None):
234+
arch: str, environ: dict[str, str] = None):
237235
super(PoolInstaller, self).__init__(chroot_path, environ)
238236

239237
from pool_lib import Pool
@@ -244,7 +242,7 @@ def __init__(
244242
self.arch = arch
245243

246244
@staticmethod
247-
def _get_package_index(packagedir: str) -> List[str]:
245+
def _get_package_index(packagedir: str) -> list[str]:
248246
def filesize(path: str) -> str:
249247
return str(os.stat(path).st_size)
250248

@@ -262,7 +260,7 @@ def sha256sum(path: str) -> str:
262260
# dl_path would best be calculated; but we don't have access to chroot_path here...
263261
dl_path = os.path.join("var/cache/apt/archives", package)
264262
if path.endswith(".deb"):
265-
control = debian.debfile.DebFile(path).debcontrol()
263+
control = debfile.DebFile(path).debcontrol()
266264
for field in list(control.keys()):
267265
index.append(field + ": " + control[field])
268266

@@ -275,8 +273,8 @@ def sha256sum(path: str) -> str:
275273
return index
276274

277275
def install(
278-
self, packages: List[str],
279-
ignore_errors: Optional[List[str]]=None
276+
self, packages: list[str],
277+
ignore_errors: list[str] = None
280278
) -> None:
281279
"""install packages into chroot via pool"""
282280

@@ -297,7 +295,7 @@ def install(
297295
print("deb file:/// local debs", file=cast(TextIO, sources_list))
298296
sources_list.close()
299297

300-
index_file = "_dists_local_debs_binary-%s_Packages" % self.arch
298+
index_file = f"_dists_local_debs_binary-{self.arch}_Packages"
301299
index_path = join(self.chroot.path, "var/lib/apt/lists", index_file)
302300
index = self._get_package_index(packagedir)
303301
with open(index_path, "w") as fob:
@@ -311,15 +309,15 @@ def install(
311309
class LiveInstaller(Installer):
312310
def __init__(
313311
self, chroot_path: str,
314-
apt_proxy: Optional[str]=None,
315-
environ: Optional[Dict[str, str]]=None):
312+
apt_proxy: str = None,
313+
environ: dict[str, str] = None):
316314
super(LiveInstaller, self).__init__(chroot_path, environ)
317315

318316
self.apt_proxy = apt_proxy
319317

320318
def install(
321-
self, packages: List[str],
322-
ignore_errors: Optional[List[str]]=None) -> None:
319+
self, packages: list[str],
320+
ignore_errors: list[str] = None) -> None:
323321
"""install packages into chroot via live apt"""
324322
if ignore_errors is None:
325323
ignore_errors = []

share/product.mk

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,25 @@ CODENAME ?= $(shell basename $(RELEASE))
2222
UBUNTU = $(shell [ $(DISTRO) = 'ubuntu' ] && echo 'y')
2323
DEBIAN = $(shell [ $(DISTRO) = 'debian' ] && echo 'y')
2424

25-
FAB_ARCH = $(shell dpkg --print-architecture)
25+
FAB_ARCH ?= $(shell dpkg --print-architecture)
2626
I386 = $(shell [ $(FAB_ARCH) = 'i386' ] && echo 'y')
2727
AMD64 = $(shell [ $(FAB_ARCH) = 'amd64' ] && echo 'y')
28+
ARM64 = $(shell [ $(FAB_ARCH) = 'arm64' ] && echo 'y')
29+
30+
ifeq ($(I386),y)
31+
ARCH_FAMILY=x86
32+
endif
33+
ifeq ($(AMD64),y)
34+
ARCH_FAMILY=x86
35+
endif
36+
ifeq ($(ARM64),y)
37+
ARCH_FAMILY=arm
38+
# NONFREE is used to get raspi-firmware and firmware-brcm80211
39+
NONFREE=1
40+
endif
41+
ifndef ARCH_FAMILY
42+
$(error unsupported architecture)
43+
endif
2844

2945
ifdef FAB_POOL
3046
FAB_POOL_PATH=$(FAB_PATH)/pools/$(CODENAME)
@@ -45,7 +61,7 @@ endif
4561

4662
COMMON_PATCHES := turnkey.d $(COMMON_PATCHES)
4763

48-
CONF_VARS_BUILTIN ?= FAB_ARCH FAB_HTTP_PROXY I386 AMD64 RELEASE DISTRO CODENAME DEBIAN UBUNTU KERNEL DEBUG CHROOT_ONLY
64+
CONF_VARS_BUILTIN ?= FAB_ARCH FAB_HTTP_PROXY I386 AMD64 ARM64 RELEASE DISTRO CODENAME DEBIAN UBUNTU KERNEL DEBUG CHROOT_ONLY
4965

5066
define filter-undefined-vars
5167
$(foreach var,$1,$(if $($(var)), $(var)))
@@ -136,8 +152,12 @@ endef
136152
ifdef CHROOT_ONLY
137153
all: root.sandbox
138154
else
155+
ifeq ($(ARCH_FAMILY),arm)
156+
all: $O/product.img
157+
else
139158
all: $O/product.iso
140159
endif
160+
endif
141161

142162
define mount-deck
143163
@(deck $1 > /dev/null 2>&1) && echo deck $1 || true
@@ -173,6 +193,7 @@ define help/body
173193
@echo ' CONF_VARS $(value CONF_VARS)'
174194
@echo
175195
@echo ' FAB_ARCH $(value FAB_ARCH)'
196+
@echo ' ARCH_FAMILY $(value ARCH_FAMILY)'
176197
@echo ' FAB_POOL $(value FAB_POOL)'
177198
@echo ' FAB_POOL_PATH $(value FAB_POOL_PATH)'
178199
@echo ' FAB_PLAN_INCLUDE_PATH $(value FAB_PLAN_INCLUDE_PATH)/'
@@ -222,7 +243,12 @@ define help/body
222243
@echo '# remake target and the targets that depend on it'
223244
@echo '$$ rm $(value STAMPS_DIR)/<target>; make <target>'
224245
@echo
225-
@echo '# build a target (default: product.iso)'
246+
@if [ "$(ARCH_FAMILY)" = "arm" ]; \
247+
then \
248+
echo '# build a target (default: product.img)'; \
249+
else \
250+
echo '# build a target (default: product.iso)'; \
251+
fi
226252
@echo '$$ make [target] [O=path/to/build/dir]'
227253
@echo ' redeck # deck unmounted input/output decks (e.g., after reboot)'
228254
@echo
@@ -231,19 +257,24 @@ define help/body
231257
@echo ' root.spec # the spec from which root.build is built (I.e., resolved plan)'
232258
@echo ' root.build # created by applying the root.spec to the bootstrap'
233259
@echo ' root.patched # deck root.build and apply the root overlay and removelist'
234-
@echo
260+
@echo
235261
@echo ' root.sandbox # changes (e.g., manual prototyping) inside the copy-on-write sandbox'
236262
@echo ' # saved as a separate, temporary cdroot squashfs overlay'
237263
@echo
238264
endef
239265

240266
ifndef CHROOT_ONLY
267+
ifeq ($(ARCH_FAMILY),arm)
268+
help/body += ;\
269+
echo ' product.img \# product img for raspberry pi 4';
270+
else
241271
help/body += ;\
242272
echo ' cdroot \# created by squashing root.patched into cdroot template + overlay'; \
243273
echo ' product.iso \# product ISO created from the cdroot'; \
244274
echo; \
245275
echo ' updated-initramfs \# rebuild product with updated initramfs'
246276
endif
277+
endif
247278

248279
help:
249280
$(help/pre)
@@ -255,7 +286,7 @@ define clean/body
255286
$(call remove-deck, $O/root.patched)
256287
$(call remove-deck, $O/root.build)
257288
$(call remove-deck, $O/bootstrap)
258-
-rm -rf $O/root.spec $O/cdroot $O/product.iso $O/log $O/screens $(STAMPS_DIR)
289+
-rm -rf $O/root.spec $O/cdroot $O/product.iso $O/sdroot $O/product.img $O/product.img.xz $O/log $O/screens $(STAMPS_DIR)
259290
endef
260291

261292
clean:
@@ -303,7 +334,7 @@ define run-conf-scripts
303334
if [ -n "$(wildcard $1/*)" ]; then \
304335
echo "\$$(call $0,$1)"; \
305336
fi; \
306-
for script in $1/*; do \
337+
for script in $1/* $1/$(ARCH_FAMILY).d/*; do \
307338
[ -f "$$script" ] && [ -x "$$script" ] || continue; \
308339
args_path=$(strip $1)/args/$$(echo $$(basename $$script) | sed 's/^[^a-zA-Z]*//'); \
309340
args="$$([ -f $$args_path ] && (cat $$args_path | sed 's/#.*//'))"; \
@@ -337,7 +368,8 @@ define root.patched/body
337368
# apply the common overlays
338369
$(foreach overlay,$(_COMMON_OVERLAYS),
339370
@if echo $(overlay) | grep -q '\.d$$'; then \
340-
for d in $(overlay)/*; do \
371+
for d in $(overlay)/* $(overlay)/$(ARCH_FAMILY).d/*; do \
372+
if echo $$d | grep -q '\.d$$'; then continue; fi; \
341373
echo fab-apply-overlay $$d $O/root.patched; \
342374
fab-apply-overlay $$d $O/root.patched; \
343375
done; \
@@ -494,6 +526,26 @@ define product.iso/body
494526
$(run-isohybrid)
495527
endef
496528

529+
# target: product.img
530+
define product.img/body
531+
qemu-img create -f raw $O/product.img 2G
532+
parted -s $O/product.img mklabel msdos
533+
parted -s $O/product.img -- mkpart primary fat32 4MiB 400MiB
534+
parted -s $O/product.img -- mkpart primary ext2 400MiB 100%
535+
kpartx -asv $O/product.img
536+
mkfs -t vfat -n RASPIFIRM /dev/mapper/loop0p1
537+
mkfs -t ext4 -L RASPIROOT /dev/mapper/loop0p2
538+
mkdir -p $O/sdroot
539+
mount /dev/mapper/loop0p2 $O/sdroot
540+
mkdir -p $O/sdroot/boot/firmware
541+
mount /dev/mapper/loop0p1 $O/sdroot/boot/firmware
542+
cp -ax $O/root.sandbox/* $O/sdroot
543+
umount $O/sdroot/boot/firmware
544+
umount $O/sdroot
545+
kpartx -dsv $O/product.img
546+
xz -8 -f $O/product.img
547+
endef
548+
497549
cdroot-dynamic: $(STAMPS_DIR)/root.sandbox
498550
$(cdroot-dynamic/pre)
499551
$(cdroot-dynamic/body)
@@ -530,6 +582,14 @@ $O/product.iso: $(product.iso/deps) $(product.iso/deps/extra)
530582

531583
product.iso: $O/product.iso
532584

585+
product.img/deps ?= $(STAMPS_DIR)/root.sandbox
586+
$O/product.img: $(product.img/deps) $(product.img/deps/extra)
587+
$(product.img/pre)
588+
$(product.img/body)
589+
$(product.img/post)
590+
591+
product.img: $O/product.img
592+
533593
# target: updated-initramfs
534594
define updated-initramfs/body
535595
rm -rf $O/product.iso

0 commit comments

Comments
 (0)