summaryrefslogtreecommitdiff
path: root/bsp/rockchip/tools/buildutil.py
blob: ea51cfca6b56f38aa9716f30306bab54ada0a7b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os

def GetStringFromConfig(bsp_dir, string):
    try:
        config = open(bsp_dir + '/rtconfig.h', 'r')
    except IOError:
        print('no found rtconfig.h, use scons --menuconfig before compile')
    else:
        cfg_list = config.readlines()
        for cfg in cfg_list:
            if cfg.find(string) != -1:
                target = cfg[cfg.find('"'):-1]
                target = eval(target)
                config.close()
                return target
        print('no found ' + string + ' in rtconfig.h, you must define this in kconfig of board')

    return ''

def GetRTConfigOption(bsp_dir, option):
    value = False
    try:
        config = open(bsp_dir + '/rtconfig.h', 'r')
    except IOError:
        print('no found rtconfig.h, use scons --menuconfig before compile')
    else:
        cfg_list = config.readlines()
        for cfg in cfg_list:
            if cfg.find('#define ' + option) != -1:
                cfg = cfg.rstrip('\n')
                values = cfg.split(' ')

                if len(values) == 3:
                    value = values[2]
                else:
                    value = True

                config.close()
                return value

    return value

def GetImageSetting(bsp_dir):
    board = GetStringFromConfig(bsp_dir, 'RT_BOARD_NAME')
    path = 'board/{dir}/setting.ini'.format(dir = board)
    if (bsp_dir.endswith('/') == False):
        bsp_dir += '/'
    if os.path.exists(bsp_dir + path) == True:
        return path
    else:
        return 'board/common/setting.ini'

def ParsePartitionStart(bsp_dir, name):
    start = -1
    path = GetImageSetting(bsp_dir)
    configer = configparser.ConfigParser()
    configer.read(path)
    for section in configer.sections():
        if (configer.has_option(section, 'Name')):
            if configer.get(section, 'Name') == name:
                sector = int(configer.get(section, 'PartOffset'), 16)
                start = (sector + 1) * 512
    return start