Convert extlinux to bash script to eliminate need for Python

This is a function for function equivalent implementation of the
previously shipped Python script, simplifying the package dependency
chain.

Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
Signed-off-by: Petr Šabata <contyk@redhat.com>
This commit is contained in:
Petr Šabata 2017-05-15 15:13:36 +02:00
parent 4ff00e1e10
commit 2e6df0d240
3 changed files with 76 additions and 93 deletions

View File

@ -1,88 +0,0 @@
#!/usr/bin/python3
# Copyright (C) 2015 Red Hat Inc.
# Author(s): Dennis Gilmore <dennis@ausil.us>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.
import os
def is_calxeda():
#is the system a calxeda one
fd = open('/proc/cpuinfo','r')
cpuinfo = fd.readlines()
fd.close()
for line in cpuinfo:
if line.startswith('Hardware'):
if line.split(' ')[1].startswith('Highbank'):
return True
if line.split(' ')[1].startswith('Midway'):
return True
return False
def update_sysconfig():
'''
update /etc/sysconfig/uboot to reflect if the platform provides its own dtb and
we do not need to pass anything.
'''
configfile = '/etc/sysconfig/uboot'
fd = open(configfile, 'r')
uboot = fd.read()
fd.close()
newuboot = uboot.replace('#SHIPSDTB=no','SHIPSDTB=yes')
fd = open(configfile, 'w')
fd.write(newuboot)
fd.close()
def insert_fdtdir():
'''
insert into /boot/extlinux/extlinux.conf a fdtdir line
'''
configfile = '/boot/extlinux/extlinux.conf'
fd = open(configfile, 'r')
extlinux = fd.readlines()
fd.close()
newextlinux = []
fdtdirline = ''
for line in extlinux:
newextlinux.append(line)
if line.startswith('\tkernel'):
fdtdirline = line.replace('kernel','fdtdir').replace('vmlinuz', 'dtb')
if line.startswith('\tappend'):
newextlinux.append(fdtdirline)
fd = open(configfile, 'w')
fd.writelines(newextlinux)
fd.close()
def copy_rescue_dtbs():
'''
check if there is a rescue image and copy the dtb files if there is
'''
boot = os.listdir('/boot')
dtbsource = ''
dtbdest = ''
has_rescue = False
for target in boot:
if target.startswith('vmlinuz-0-rescue'):
has_rescue = True
dtbdest = '/boot/%s' % target.replace('vmlinuz', 'dtb')
if target.startswith('dtb'):
dtbsource = '/boot/%s' % target
if has_rescue:
if not os.path.isdir(dtbdest):
os.mkdir(dtbdest)
for dtb in os.listdir(dtbsource):
os.link(os.path.join(dtbsource, dtb), os.path.join(dtbdest, dtb))
if __name__ == "__main__":
# platform ships its own dtb
if is_calxeda():
update_sysconfig()
else:
# need to add fdtdir to extlinux.conf
insert_fdtdir()
copy_rescue_dtbs()

View File

@ -1,12 +1,12 @@
Name: extlinux-bootloader
Version: 1.1
Release: 7%{?dist}
Version: 1.2
Release: 1%{?dist}
Summary: The EXTLINUX bootloader framework, for booting the local system
License: GPLv2+
URL: http://fedoraproject.org/wiki/extlinux-bootloader
Source1: extlinux
Source1: extlinux.sh
BuildRequires: coreutils
Provides: syslinux-extlinux
ExclusiveArch: %{arm} aarch64
@ -27,7 +27,7 @@ mkdir -p %{buildroot}/boot/extlinux/
mkdir -p %{buildroot}/etc
( cd %{buildroot}/etc && ln -s ../boot/extlinux/extlinux.conf . )
install -p %{SOURCE1} %{buildroot}%{_sbindir}
install -p %{SOURCE1} %{buildroot}%{_sbindir}/extlinux
%files
%doc
@ -38,6 +38,9 @@ install -p %{SOURCE1} %{buildroot}%{_sbindir}
%changelog
* Wed May 10 2017 Merlin Mathesius <mmathesi@redhat.com> - 1.2-1
- Convert extlinux to bash script to eliminate need for Python.
* Fri Feb 10 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.1-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

68
extlinux.sh Executable file
View File

@ -0,0 +1,68 @@
#!/bin/sh
# Copyright (C) 2015, 2017 Red Hat Inc.
# Author(s): Dennis Gilmore <dennis@ausil.us>
# Merlin Mathesius <mmathesi@redhat.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.
# is the system a calxeda one
is_calxeda() {
grep -Eq '^Hardware[^ ]* (Highbank|Midway)' /proc/cpuinfo
}
# update /etc/sysconfig/uboot to reflect if the platform provides its own dtb and
# we do not need to pass anything.
update_sysconfig() {
sed -i -e 's/#SHIPSDTB=no/SHIPSDTB=yes/g' /etc/sysconfig/uboot
}
# insert into /boot/extlinux/extlinux.conf a fdtdir line
insert_fdtdir() {
# for every 'kernel' directive found, map it to an 'fdtdir' directive
# referencing the dtb directory and add it after the 'append' directive
sed -i \
-e '/ kernel/{h;s/kernel/fdtdir/g;s/vmlinuz/dtb/g;x}' \
-e '/ append/{p;x}' \
/boot/extlinux/extlinux.conf
}
# check if there is a rescue image and copy the dtb files if there is
copy_rescue_dtbs() {
has_rescue=0
for target in /boot/vmlinuz-0-rescue* ; do
# if target exists, the glob matched a file
if [ -e "$target" ] ; then
has_rescue=1
dtbdest=$(echo "$target" | sed -e 's/vmlinuz/dtb/g')
fi
break
done
for target in /boot/dtb* ; do
# if target exists, the glob matched a file
if [ -e "$target" ] ; then
dtbsource="$target"
fi
break
done
if [ $has_rescue = 1 ] && [ ! -d "$dtbdest" ] ; then
mkdir "$dtbdest"
for dtb in $(ls "$dtbsource") ; do
ln "$dtbsource/$dtb" "$dtbdest/$dtb"
done
fi
}
# platform ships its own dtb
if is_calxeda
then
update_sysconfig
else
# need to add fdtdir to extlinux.conf
insert_fdtdir
copy_rescue_dtbs
fi