1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /* Add firmware update command to recovery script */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22
23 #include "edify/expr.h"
24 #include "update_fw.h"
25
firmware_update(const char * name,State * state,int argc,Expr * argv[])26 Value* firmware_update(const char *name, State * state, int argc, Expr * argv[]) {
27 Value *firmware;
28 Value *ec;
29 int res;
30 Value *retval = NULL;
31
32 printf("%s: running %s.\n", __func__, name);
33 if (argc < 2) {
34 ErrorAbort(state, "syntax: %s bios.bin ec.bin", name);
35 return NULL;
36 }
37 if (ReadValueArgs(state, argv, 2, &firmware, &ec) < 0) {
38 ErrorAbort(state, "%s: invalid arguments", name);
39 return NULL;
40 }
41
42 res = update_fw(firmware, ec, 0);
43 if (res < 0)
44 ErrorAbort(state, "%s: firmware update error", name);
45 else
46 retval = StringValue(strdup(res ? "UPDATED" : ""));
47
48 FreeValue(firmware);
49 FreeValue(ec);
50
51 printf("%s: [%s] done.\n", __func__,
52 retval ? retval->data : state->errmsg);
53 return retval;
54 }
55
Register_librecovery_updater_dragon()56 void Register_librecovery_updater_dragon() {
57 RegisterFunction("dragon.firmware_update", firmware_update);
58 }
59