summaryrefslogtreecommitdiffstats
path: root/recipes-bsp/u-boot/u-boot-target-env.inc
blob: c418a16bb479af885b08e56fa3e6fc38329bdd76 (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
# Handle severals environments generation for u-boot

#Env binary size
ENV_SIZE = "0x1000"

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"

do_build_mkimage_tool () {
   HOSTCC="${CC}" HOSTLD="${LD}" HOSTLDFLAGS="${LDFLAGS}" HOSTSTRIP=true oe_runmake  sandbox_defconfig 
   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('WORKDIR',True)
    # env files only for UBOOT_CONFIG
    env_uboot_config = d.getVar('UBOOT_CONFIG',True)
    env_files = []
    for f in os.listdir(target_root_dir):
        if f.endswith(".env"):
            env_files.append(os.path.join(target_root_dir,f))
    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)
    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]
        if target_filename not in env_uboot_config:
            continue
        # build output file path with ext
        target_bin = os.path.join(env_bin_dir,
            target_filename + '.bin')
        # generated mkenvimage tool command line
        cmd_mkimg ='cat %s | grep -v -E "^$|^\#" |' \
                ' ./tools/mkenvimage -s %s -r -o %s -' \
                % ( 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
    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