• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package dayu200
17
18import (
19	"context"
20	"fotff/pkg"
21	"fotff/pkg/gitee_common"
22	"fotff/res"
23	"fotff/utils"
24	"github.com/sirupsen/logrus"
25	"strconv"
26	"strings"
27)
28
29type Manager struct {
30	ArchiveDir     string `key:"archive_dir" default:"archive"`
31	WatchCI        string `key:"watch_ci" default:"false"`
32	Workspace      string `key:"workspace" default:"workspace"`
33	Branch         string `key:"branch" default:"master"`
34	ManifestBranch string `key:"manifest_branch" default:"master"`
35	FlashTool      string `key:"flash_tool" default:"python"`
36	LocationIDList string `key:"location_id_list"`
37
38	*gitee_common.Manager
39	locations map[string]string
40}
41
42// These commands are copied from ci project.
43const (
44	preCompileCMD = `rm -rf prebuilts/clang/ohos/darwin-x86_64/clang-480513;rm -rf prebuilts/clang/ohos/windows-x86_64/clang-480513;rm -rf prebuilts/clang/ohos/linux-x86_64/clang-480513;bash build/prebuilts_download.sh`
45	// compileCMD is copied from ci project and trim useless build-target 'make_test' to enhance build efficiency.
46	compileCMD = `echo 'start' && export NO_DEVTOOL=1 && export CCACHE_LOG_SUFFIX="dayu200-arm32" && export CCACHE_NOHASHDIR="true" && export CCACHE_SLOPPINESS="include_file_ctime" && ./build.sh --product-name rk3568 --ccache --build-target make_all --gn-args enable_notice_collection=false`
47)
48
49// This list is copied from ci project. Some of them are not available, has been annotated.
50var imgList = []string{
51	"out/rk3568/packages/phone/images/MiniLoaderAll.bin",
52	"out/rk3568/packages/phone/images/boot_linux.img",
53	"out/rk3568/packages/phone/images/parameter.txt",
54	"out/rk3568/packages/phone/images/system.img",
55	"out/rk3568/packages/phone/images/uboot.img",
56	"out/rk3568/packages/phone/images/userdata.img",
57	"out/rk3568/packages/phone/images/vendor.img",
58	"out/rk3568/packages/phone/images/resource.img",
59	"out/rk3568/packages/phone/images/config.cfg",
60	"out/rk3568/packages/phone/images/ramdisk.img",
61	// "out/rk3568/packages/phone/images/chipset.img",
62	"out/rk3568/packages/phone/images/sys_prod.img",
63	"out/rk3568/packages/phone/images/chip_prod.img",
64	"out/rk3568/packages/phone/images/updater.img",
65	// "out/rk3568/packages/phone/updater/bin/updater_binary",
66}
67
68func NewManager() pkg.Manager {
69	var ret Manager
70	utils.ParseFromConfigFile("dayu200", &ret)
71	watchCI, err := strconv.ParseBool(ret.WatchCI)
72	if err != nil {
73		logrus.Panicf("can not parse 'watch_ci', please check")
74	}
75	ret.Manager = gitee_common.NewManager("dayu200", ret.Branch, ret.ManifestBranch, ret.ArchiveDir, ret.Workspace, watchCI)
76	devs := res.DeviceList()
77	locs := strings.Split(ret.LocationIDList, ",")
78	if len(devs) != len(locs) {
79		logrus.Panicf("location_id_list and devices mismatch")
80	}
81	ret.locations = map[string]string{}
82	for i, loc := range locs {
83		ret.locations[devs[i]] = loc
84	}
85	return &ret
86}
87
88// Flash function implements pkg.Manager. Flash images in the 'pkg' directory to the given device.
89// If not all necessary images are available in the 'pkg' directory, will build them.
90func (m *Manager) Flash(device string, pkg string, ctx context.Context) error {
91	logrus.Infof("now flash %s", pkg)
92	buildConfig := gitee_common.BuildConfig{
93		Pkg:           pkg,
94		PreCompileCMD: preCompileCMD,
95		CompileCMD:    compileCMD,
96		ImgList:       imgList,
97	}
98	if err := m.Build(buildConfig, ctx); err != nil {
99		logrus.Errorf("build %s fail, err: %v", pkg, err)
100		return err
101	}
102	logrus.Infof("%s is available now, start to flash it", pkg)
103	return m.flashDevice(device, pkg, ctx)
104}
105