aboutsummaryrefslogtreecommitdiffstats
path: root/meta-intel-edison-bsp/recipes-bsp/u-boot/u-boot-target-env.inc
blob: 6dee3d151c3f861c5a7b0727f85be22cbeae522a (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Handle severals environments generation for u-boot
# and link the default one for Ifwi to u-boot-osip recipe

#Env binary size
ENV_SIZE = "0x10000"

#Env base Name
ENV_BASE_NAME = "${MACHINE}"
# Env base file correspond to common part of all environment
ENV_BASE_FILE = "${WORKDIR}/${ENV_BASE_NAME}.env"

# Env directory is where target variant files are stored
ENV_DIR = "${WORKDIR}/target_env"
# Env composed is directory where target env are composed
# by concatening of base environment file and variant files
# pattern name is applied the resulting files: base-variant.env
ENV_COMPOSED_DIR = "${WORKDIR}/target_composed"
# Env bin is directory where target env are store in binary form
# filename follows pattern name above : base-variant.bin
ENV_BIN_DIR = "${WORKDIR}/target_env_bin"

# Env deploy dir is the name of directory where binary envs will be deployed
ENV_DEPLOY_DIR="u-boot-envs"

# Env deploy src dir is the name of directory where txt envs will be deployed
ENV_SRC_DEPLOY_DIR="u-boot-envs-src"

# Env target to use for IFWI stitching process
ENV_IFWI_TARGET_NAME="ifwi"
# Env image is U-Boot primary environment (where internal U-Boot variables are stored)
# The same vairiable is also defined in u-boot-osip recip in charge of doing stitching
# process for IFWI
ENV_IMAGE = "${S}/env.bin"

do_build_mkimage_tool () {
   HOSTCC="${CC}" HOSTLD="${LD}" HOSTLDFLAGS="${LDFLAGS}" HOSTSTRIP=true oe_runmake  tools
}

python do_environment_mkimage() {
    import subprocess
    import shutil
    # list env variant target files
    target_root_dir = d.getVar('ENV_DIR',True)
    env_files = os.listdir(target_root_dir )
    # builds absolute paths
    env_files = [ os.path.join(target_root_dir,f) for f in env_files]

    env_bin_dir = d.getVar("ENV_BIN_DIR",True)
    # cleans if it exists env_bin directory
    shutil.rmtree(env_bin_dir, ignore_errors=True)
    # create env bin directory
    os.mkdir(env_bin_dir)
    # if a previous env image used for osip process exists delete it
    env_image = d.getVar('ENV_IMAGE',True)
    try:
        os.unlink(env_image)
    except OSError: pass
    print 'Building binary environments in : %s' % env_bin_dir
    # iterate targets list to build binary environment files
    for target_env in env_files :
        # get only filename without path and extension
        target_filename = os.path.splitext(os.path.basename(target_env))[0]
        # build output file path with ext
        target_bin = os.path.join(env_bin_dir,
            d.getVar('ENV_BASE_NAME',True) + '-' + target_filename + '.bin')
        # generated mkenvimage tool command line
        cmd_mkimg ='cat %s %s | grep -v -E "^$|^\#" |' \
                ' ./tools/mkenvimage -s %s -r -o %s -' \
                % ( d.getVar('ENV_BASE_FILE',True),target_env,
                d.getVar("ENV_SIZE",True), target_bin)
        print 'Building binary for %s target:' % (target_filename)
        print '%s' % cmd_mkimg
        # execute shell command
        ret = subprocess.call(cmd_mkimg, shell=True)
        if ret: return ret
        if d.getVar('ENV_IFWI_TARGET_NAME',True) in target_bin :
            # create a symbolic link on default binary file env file to
            # avoid modifying to much osip part
            print 'Create for IFWI stitching symlink %s to %s' % (env_image, target_bin)
            os.symlink(target_bin, env_image)
    return 0
}

do_deploy_append() {
    install -d ${DEPLOYDIR}
    # deploy  binary U-boot environments
    echo "Deploying U-boot Environments binary files in ${DEPLOYDIR}/${ENV_DEPLOY_DIR}"
    install -d ${DEPLOYDIR}/${ENV_DEPLOY_DIR}
    cp ${ENV_BIN_DIR}/*.bin ${DEPLOYDIR}/${ENV_DEPLOY_DIR}
}

addtask build_mkimage_tool after do_compile before do_environment_mkimage
addtask environment_mkimage after do_build_mkimage_tool before do_deploy