1 /*
2 * Copyright (C) 2011 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
17 #include <stdio.h>
18 #include <errno.h>
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "edify/expr.h"
24 #include "bootloader.h"
25
WriteBootloaderFn(const char * name,State * state,int argc,Expr * argv[])26 Value* WriteBootloaderFn(const char* name, State* state, int argc, Expr* argv[])
27 {
28 int result = -1;
29 Value* img;
30 Value* xloader_loc;
31 Value* sbl_loc;
32
33 if (argc != 3) {
34 return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc);
35 }
36
37 if (ReadValueArgs(state, argv, 3, &img, &xloader_loc, &sbl_loc) < 0) {
38 return NULL;
39 }
40
41 if(img->type != VAL_BLOB ||
42 xloader_loc->type != VAL_STRING ||
43 sbl_loc->type != VAL_STRING) {
44 FreeValue(img);
45 FreeValue(xloader_loc);
46 FreeValue(sbl_loc);
47 return ErrorAbort(state, "%s(): argument types are incorrect", name);
48 }
49
50 result = update_bootloader(img->data, img->size,
51 xloader_loc->data, sbl_loc->data);
52 FreeValue(img);
53 FreeValue(xloader_loc);
54 FreeValue(sbl_loc);
55 return StringValue(strdup(result == 0 ? "t" : ""));
56 }
57
Register_librecovery_updater_tuna()58 void Register_librecovery_updater_tuna() {
59 fprintf(stderr, "installing samsung updater extensions\n");
60
61 RegisterFunction("samsung.write_bootloader", WriteBootloaderFn);
62 }
63