2015-03-31 03:52:06 +00:00
|
|
|
#!/usr/bin/python2
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2015-04-01 17:39:16 +00:00
|
|
|
import os
|
2015-03-31 03:52:06 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2015-04-01 17:39:16 +00:00
|
|
|
def copy_rescue_dtbs():
|
|
|
|
'''
|
|
|
|
check if there is a rescue image and copy the dtb files if there is
|
|
|
|
'''
|
2015-04-01 18:48:45 +00:00
|
|
|
boot = os.listdir('/boot')
|
2015-04-01 17:39:16 +00:00
|
|
|
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))
|
|
|
|
|
2015-03-31 03:52:06 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# platform ships its own dtb
|
|
|
|
if is_calxeda():
|
|
|
|
update_sysconfig()
|
|
|
|
else:
|
|
|
|
# need to add fdtdir to extlinux.conf
|
|
|
|
insert_fdtdir()
|
2015-04-01 17:39:16 +00:00
|
|
|
copy_rescue_dtbs()
|