summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-ast2500/recipes-bsp/u-boot/files/0029-FFUJ-FW-IPMI-commands-and-flash-support-in-u-boot.patch
blob: 238630af66453bee2193b16aa16ef01bf3349397 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
From 61587868bf9979dd8308f12157310949f0e5c430 Mon Sep 17 00:00:00 2001
From: AppaRao Puli <apparao.puli@linux.intel.com>
Date: Tue, 21 May 2019 00:53:04 +0530
Subject: [PATCH] FFUJ: FW IPMI commands and flash support in u-boot

Firmware update and OEM ipmi commands implementation
for supporting Force Firmware Update Jumper(FFUJ)
mode. Also added support to update the fit images
in FFUJ mode.

Firmware update commands:
1) Get BMC Execution Context(0x23)
2) Get Firmware Update Random Number(0x26)
3) Set Firmware Update Mode(0x27)
4) Exit Firmware Update Mode(0x28)
5) Set/Get Firmware Update Control(0x29)
6) Get Firmware Update status(0x2A)
7) Set Firmware Update Options(0x2B)
8) Firmware Image Write(0x2C)

OEM Commands:
1) Get Buffer Size(0x66)

Tested:
 - Tested the individual commands implementation and negative
   cases.
 - Used debug tool for validating Firmware image transfer via
   KCS and flashing.

Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>

---
 .../include/asm/arch-aspeed/ast-g5-intel.h    |   1 +
 board/aspeed/ast-g5/Makefile                  |   2 +
 board/aspeed/ast-g5/fw-update.c               | 486 ++++++++++++++++++
 board/aspeed/ast-g5/fw-update.h               |  50 ++
 board/aspeed/ast-g5/ipmi-fwupd.c              | 402 +++++++++++++++
 board/aspeed/ast-g5/ipmi-fwupd.h              |  81 +++
 board/aspeed/ast-g5/ipmi-handler.c            |  66 ++-
 board/aspeed/ast-g5/ipmi-handler.h            |   3 +-
 common/autoboot.c                             |  13 +
 configs/ast_g5_phy_defconfig                  |   1 +
 10 files changed, 1093 insertions(+), 12 deletions(-)
 create mode 100644 board/aspeed/ast-g5/fw-update.c
 create mode 100644 board/aspeed/ast-g5/fw-update.h
 create mode 100644 board/aspeed/ast-g5/ipmi-fwupd.c
 create mode 100644 board/aspeed/ast-g5/ipmi-fwupd.h

diff --git a/arch/arm/include/asm/arch-aspeed/ast-g5-intel.h b/arch/arm/include/asm/arch-aspeed/ast-g5-intel.h
index cd9a0994fa..a88521a1b3 100644
--- a/arch/arm/include/asm/arch-aspeed/ast-g5-intel.h
+++ b/arch/arm/include/asm/arch-aspeed/ast-g5-intel.h
@@ -14,6 +14,7 @@
 
 #ifndef __ASSEMBLY__
 int intel_force_firmware_jumper_enabled(void);
+void start_fw_update_loop(void);
 #endif
 
 #endif /* __AST_INTEL_G5_H__ */
diff --git a/board/aspeed/ast-g5/Makefile b/board/aspeed/ast-g5/Makefile
index f28fcfe61c..0b2d936c23 100644
--- a/board/aspeed/ast-g5/Makefile
+++ b/board/aspeed/ast-g5/Makefile
@@ -6,3 +6,5 @@ obj-y += ast-g5-gpio.o
 obj-y += ast-g5-timer.o
 obj-y += ast-g5-kcs.o
 obj-y += ipmi-handler.o
+obj-y += ipmi-fwupd.o
+obj-y += fw-update.o
diff --git a/board/aspeed/ast-g5/fw-update.c b/board/aspeed/ast-g5/fw-update.c
new file mode 100644
index 0000000000..99239938b5
--- /dev/null
+++ b/board/aspeed/ast-g5/fw-update.c
@@ -0,0 +1,486 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <common.h>
+#include <cli.h>
+#include <flash.h>
+
+#include "fw-update.h"
+
+#define BOOTCMD_BOOTM_STR	"bootm "
+#define RANDOM_NUM_TIMEOUT	30 /* in seconds */
+#define WAIT_STATE_TIMEOUT	10000 /* 10 seconds */
+
+#define PROTECT_OFF		0
+#define PROTECT_ON		1
+
+extern struct fwupd_global_setting g_fwupd_settings;
+extern u32 g_write_addr;
+
+bool g_fwupd_settings_lock = false;
+unsigned long long etime;
+
+bool fwupd_settings_trylock(void)
+{
+	if (g_fwupd_settings_lock)
+		return false;
+
+	g_fwupd_settings_lock = true;
+	return g_fwupd_settings_lock;
+}
+
+void fwupd_settings_unlock(void)
+{
+	g_fwupd_settings_lock = false;
+}
+
+u8 get_active_boot_image(void)
+{
+	char *bootcmd = getenv("bootcmd");
+	char *start = strstr(bootcmd, BOOTCMD_BOOTM_STR);
+	u8 boot_image = PRIMARY_IMAGE;
+
+	if (start) {
+		ulong boot_addr = simple_strtoul(
+			(start + strlen(BOOTCMD_BOOTM_STR)), NULL, 16);
+		if (boot_addr == SECONDARY_FITIMAGE_START_ADDR)
+			return SECONDARY_IMAGE;
+	}
+	return boot_image;
+}
+
+static ulong get_flash_image_address(void)
+{
+	char *bootcmd = getenv("bootcmd");
+	char *start = strstr(bootcmd, BOOTCMD_BOOTM_STR);
+	ulong boot_addr = PRIMARY_FITIMAGE_START_ADDR;
+
+	if (start) {
+		boot_addr = simple_strtoul((start + strlen(BOOTCMD_BOOTM_STR)),
+					   NULL, 16);
+		/* We update in backup region and set the bootcmd accordingly */
+		if (boot_addr == PRIMARY_FITIMAGE_START_ADDR)
+			boot_addr = SECONDARY_FITIMAGE_START_ADDR;
+		else
+			boot_addr = PRIMARY_FITIMAGE_START_ADDR;
+	}
+
+	return boot_addr;
+}
+
+static void update_processing_status(u8 status, u8 percent)
+{
+	if (!fwupd_settings_trylock())
+		return;
+
+	g_fwupd_settings.processing_status = status;
+	g_fwupd_settings.percentage_completion = percent;
+
+	fwupd_settings_unlock();
+	return;
+}
+
+static void reset_all_settings(void)
+{
+	if (!fwupd_settings_trylock())
+		return;
+
+	memset(&g_fwupd_settings, 0, sizeof(g_fwupd_settings));
+	g_fwupd_settings.fwupd_mode_active = false;
+	g_fwupd_settings.start_update = false;
+
+	fwupd_settings_unlock();
+}
+
+unsigned int get_seed(void)
+{
+	char seed_str[] = { "INTEL" };
+	unsigned int seed;
+
+	for (int i = 0; i < strlen(seed_str); i++)
+		seed += (seed_str[i] << (i * 8));
+
+	return seed;
+}
+
+int generate_random_number(void)
+{
+	srand(get_seed());
+
+	if (!fwupd_settings_trylock()) {
+		printf("%s(): Lock failed\n", __func__);
+		return -1;
+	}
+	for (int i = 0; i < RAND_NUMBER_SIZE; i++)
+		g_fwupd_settings.rand_num[i] = (u8)(rand() & 0xFF);
+
+	g_fwupd_settings.random_number_valid = true;
+
+	fwupd_settings_unlock();
+
+	/* Random number should be cleared after 30sec timeout */
+	etime = endtick(RANDOM_NUM_TIMEOUT);
+
+	return 0;
+}
+
+static int sect_roundb(ulong *addr)
+{
+	flash_info_t *info;
+	ulong bank, sector_end_addr;
+	char found;
+	int i;
+
+	/* find the end addr of the sector where the *addr is */
+	found = 0;
+	for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS && !found; ++bank) {
+		info = &flash_info[bank];
+		for (i = 0; i < info->sector_count && !found; ++i) {
+			/* get the end address of the sector */
+			if (i == info->sector_count - 1) {
+				sector_end_addr =
+					info->start[0] + info->size - 1;
+			} else {
+				sector_end_addr = info->start[i + 1] - 1;
+			}
+
+			if (*addr <= sector_end_addr &&
+			    *addr >= info->start[i]) {
+				found = 1;
+				/* adjust *addr if necessary */
+				if (*addr < sector_end_addr)
+					*addr = sector_end_addr;
+			} /* sector */
+		} /* bank */
+	}
+	if (!found) {
+		/* error, address not in flash */
+		printf("Error: end address (0x%08lx) not in flash!\n", *addr);
+		return 1;
+	}
+
+	return 0;
+}
+
+static int fill_flash_sect_ranges(ulong addr_first, ulong addr_last,
+				  int *s_first, int *s_last, int *s_count)
+{
+	flash_info_t *info;
+	ulong bank;
+	int rcode = 0;
+
+	*s_count = 0;
+
+	for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+		s_first[bank] = -1; /* first sector to erase	*/
+		s_last[bank] = -1; /* last  sector to erase	*/
+	}
+
+	for (bank = 0, info = &flash_info[0];
+	     (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (addr_first <= addr_last);
+	     ++bank, ++info) {
+		ulong b_end;
+		int sect;
+		short s_end;
+
+		if (info->flash_id == FLASH_UNKNOWN)
+			continue;
+
+		b_end = info->start[0] + info->size - 1; /* bank end addr */
+		s_end = info->sector_count - 1; /* last sector   */
+
+		for (sect = 0; sect < info->sector_count; ++sect) {
+			ulong end; /* last address in current sect	*/
+
+			end = (sect == s_end) ? b_end :
+						info->start[sect + 1] - 1;
+
+			if (addr_first > end)
+				continue;
+			if (addr_last < info->start[sect])
+				continue;
+
+			if (addr_first == info->start[sect])
+				s_first[bank] = sect;
+			if (addr_last == end)
+				s_last[bank] = sect;
+		}
+		if (s_first[bank] >= 0) {
+			if (s_last[bank] < 0) {
+				if (addr_last > b_end) {
+					s_last[bank] = s_end;
+				} else {
+					printf("Error: end address  not on sector boundary\n");
+					rcode = 1;
+					break;
+				}
+			}
+			if (s_last[bank] < s_first[bank]) {
+				printf("Error: end sector precedes start sector\n");
+				rcode = 1;
+				break;
+			}
+			sect = s_last[bank];
+			addr_first = (sect == s_end) ? b_end + 1 :
+						       info->start[sect + 1];
+			(*s_count) += s_last[bank] - s_first[bank] + 1;
+		} else if (addr_first >= info->start[0] && addr_first < b_end) {
+			printf("Error: start address not on sector boundary\n");
+			rcode = 1;
+			break;
+		} else if (s_last[bank] >= 0) {
+			printf("Error: cannot span across banks when they are mapped in reverse order\n");
+			rcode = 1;
+			break;
+		}
+	}
+
+	return rcode;
+}
+
+static int protect_flash_sector(int state, ulong addr_first, ulong addr_last)
+{
+	flash_info_t *info;
+	ulong bank;
+	int s_first[CONFIG_SYS_MAX_FLASH_BANKS],
+		s_last[CONFIG_SYS_MAX_FLASH_BANKS];
+	int protected = 0;
+	int planned;
+	int rcode, i;
+
+	rcode = fill_flash_sect_ranges(addr_first, addr_last, s_first, s_last,
+				       &planned);
+
+	if (planned && (rcode == 0)) {
+		for (bank = 0, info = &flash_info[0];
+		     bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) {
+			if (info->flash_id == FLASH_UNKNOWN)
+				continue;
+
+			if (s_first[bank] >= 0 &&
+			    s_first[bank] <= s_last[bank]) {
+				debug("%sProtecting sectors %d..%d in bank %ld\n",
+				      state ? "" : "Un-", s_first[bank],
+				      s_last[bank], bank + 1);
+			    protected
+				+= s_last[bank] - s_first[bank] + 1;
+				for (i = s_first[bank]; i <= s_last[bank]; ++i)
+					info->protect[i] = state;
+			}
+		}
+		printf("%sProtected %d sectors\n", state ? "" : "Un-",
+		       protected);
+	} else if (rcode == 0) {
+		printf("Error: start and/or end address not on sector boundary\n");
+		rcode = 1;
+	}
+
+	return rcode;
+}
+
+static int erase_flash_sector(ulong addr_first, ulong addr_last)
+{
+	flash_info_t *info;
+	ulong bank;
+	int s_first[CONFIG_SYS_MAX_FLASH_BANKS];
+	int s_last[CONFIG_SYS_MAX_FLASH_BANKS];
+	int erased = 0;
+	int planned;
+	int rcode = 0;
+
+	rcode = fill_flash_sect_ranges(addr_first, addr_last, s_first, s_last,
+				       &planned);
+
+	if (planned && (rcode == 0)) {
+		for (bank = 0, info = &flash_info[0];
+		     (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (rcode == 0);
+		     ++bank, ++info) {
+			if (s_first[bank] >= 0) {
+				erased += s_last[bank] - s_first[bank] + 1;
+				debug("Erase Flash from 0x%08lx to 0x%08lx "
+				      "in Bank # %ld ",
+				      info->start[s_first[bank]],
+				      (s_last[bank] == info->sector_count) ?
+					      info->start[0] + info->size - 1 :
+					      info->start[s_last[bank] + 1] - 1,
+				      bank + 1);
+				rcode = flash_erase(info, s_first[bank],
+						    s_last[bank]);
+			}
+		}
+		if (rcode == 0)
+			printf("Erased %d sectors\n", erased);
+	} else if (rcode == 0) {
+		printf("Error: start and/or end address not on sector boundary\n");
+		rcode = 1;
+	}
+
+	return rcode;
+}
+
+static int verify_image(void)
+{
+	ulong src_addr = IMAGE_LOAD_RAM_ADDR;
+	void *hdr = (void *)src_addr;
+
+	printf("\n## Checking Image at 0x%08lx ...\n", src_addr);
+	/* AT the moment, we only support FIT image flash */
+	switch (genimg_get_format(hdr)) {
+	case IMAGE_FORMAT_FIT:
+		printf("   FIT image found\n");
+		if (!fit_check_format(hdr)) {
+			printf("Bad FIT image format!\n");
+			return -1;
+		}
+
+		if (!fit_all_image_verify(hdr)) {
+			printf("Bad hash in FIT image!\n");
+			return -1;
+		}
+		break;
+	default:
+		printf("Unknown image format!\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int flash_image(void)
+{
+	int rcode;
+	ulong max_size = MAX_FITIMAGE_SIZE;
+	ulong src_addr = IMAGE_LOAD_RAM_ADDR;
+	ulong addr_first = get_flash_image_address();
+	ulong addr_last = addr_first + max_size - 1;
+
+	if ((g_write_addr > max_size) || (g_write_addr == 0)) {
+		printf("ERROR: %s(): Invalid file uploaded. filesize(0x%08x)\n",
+		       __func__, g_write_addr);
+		return -1;
+	}
+
+	if (sect_roundb(&addr_last) > 0) {
+		printf("ERROR: %s(): sect_roundb failed\n", __func__);
+		return -1;
+	}
+
+	if (addr_first >= addr_last) {
+		printf("ERROR: %s(): addr_first(0x%08lx) >= addr_last(0x%08lx)\n",
+		       __func__, addr_first, addr_last);
+		return -1;
+	}
+
+	/* Hack: To update the percentage update,
+	 * treat logical division as below.
+	 * Image verify - 10%
+	 * Unprotecting flash sectors - 10%
+	 * Erase flash sectors - 40%
+	 * Copy to flash - 40% */
+
+	/* Unprotect the flash sectors */
+	rcode = protect_flash_sector(PROTECT_OFF, addr_first, addr_last);
+	if (rcode != 0) {
+		printf("%s(): Protecting flash sector failed(%d).\n", __func__,
+		       rcode);
+		return -1;
+	}
+	update_processing_status(IMG_PROGRAMMING, 20);
+
+	/* erase flash sectors */
+	rcode = erase_flash_sector(addr_first, addr_last);
+	if (rcode != 0) {
+		printf("%s(): Erasing flash sector failed(%d).\n", __func__,
+		       rcode);
+		return -1;
+	}
+	update_processing_status(IMG_PROGRAMMING, 60);
+
+	/* write to flash area */
+	printf("Copy to Flash... ");
+	rcode = flash_write((char *)src_addr, addr_first, g_write_addr * 1);
+	if (rcode != 0) {
+		printf("%s(): Flash copy failed(%d).\n", __func__, rcode);
+		flash_perror(rcode);
+		return -1;
+	}
+	printf("done\n");
+	return 0;
+}
+
+void start_fw_update_loop(void)
+{
+	int rc;
+	ulong boot_addr;
+	char boot_cmd[20];
+
+	while (1) {
+		if (g_fwupd_settings.random_number_valid) {
+			/* Random number should be cleared after 30seconds */
+			if (get_ticks() >= etime) {
+				printf("Clearing random number\n");
+
+				if (!fwupd_settings_trylock())
+					continue;
+				memcpy(g_fwupd_settings.rand_num, 0,
+				       RAND_NUMBER_SIZE);
+				g_fwupd_settings.random_number_valid = false;
+				fwupd_settings_unlock();
+			}
+		}
+
+		if (g_fwupd_settings.start_update) {
+			update_processing_status(IMG_VALIDATING, 0);
+
+			rc = verify_image();
+			if (rc != 0) {
+				update_processing_status(UPDATE_ERROR, 100);
+				/* Adding delay to make consumer gets status */
+				mdelay(WAIT_STATE_TIMEOUT);
+
+				reset_all_settings();
+				continue;
+			}
+
+			update_processing_status(IMG_PROGRAMMING, 10);
+
+			rc = flash_image();
+			if (rc == 0) {
+				/* Update successful, change the boot command */
+				boot_addr = get_flash_image_address();
+				snprintf(boot_cmd, sizeof(boot_cmd),
+					 "bootm %08x", boot_addr);
+				setenv("bootcmd", boot_cmd);
+				saveenv();
+
+				update_processing_status(UPDATE_SUCCESSFUL,
+							 100);
+			} else {
+				update_processing_status(UPDATE_ERROR, 100);
+			}
+
+			/* Adding delay to make sure consumer gets status */
+			mdelay(WAIT_STATE_TIMEOUT);
+
+			reset_all_settings();
+
+			/* Reset BMC */
+			do_reset(NULL, 0, 0, NULL);
+		}
+		mdelay(WAIT_STATE_TIMEOUT);
+	}
+
+	return;
+}
+
+#if 1 /* Debug purpose */
+int do_fwupd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	if (argc != 1)
+		return 1;
+
+	start_fw_update_loop();
+	return 0;
+}
+U_BOOT_CMD(fwupd, 1, 0, do_fwupd, "Start Firmware update process", "");
+#endif
diff --git a/board/aspeed/ast-g5/fw-update.h b/board/aspeed/ast-g5/fw-update.h
new file mode 100644
index 0000000000..ed033adfed
--- /dev/null
+++ b/board/aspeed/ast-g5/fw-update.h
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <common.h>
+
+/* SPI flash map */
+#define MAX_FITIMAGE_SIZE		0x1B80000
+#define PRIMARY_FITIMAGE_START_ADDR	0x20080000
+#define SECONDARY_FITIMAGE_START_ADDR	0x22480000
+#define IMAGE_LOAD_RAM_ADDR		0x83000000
+
+#define MAX_FILENAME_LENGTH		256
+#define RAND_NUMBER_SIZE		8
+
+enum boot_image {
+	PRIMARY_IMAGE = 0x01,
+	SECONDARY_IMAGE = 0x02
+};
+
+enum update_status {
+	INITIALIZING = 0,
+	IDLE,
+	IMG_DOWNLOADING,
+	IMG_VALIDATING,
+	IMG_PROGRAMMING,
+	UPDATE_SUCCESSFUL,
+	UPDATE_ERROR = 0x0F,
+	UPDATE_FORBIDDEN = 0x80,
+	AC_CYCLE_REQUIRED = 0x83
+};
+
+struct fwupd_global_setting {
+	bool fwupd_mode_active;
+	bool start_update;
+	bool random_number_valid;
+	u8 ctrl_state;
+	u8 options_mask;
+	u8 options_value;
+	u8 processing_status;
+	u8 percentage_completion;
+	u8 integrity_check_status;
+	u8 filename_len;
+	u8 filename[MAX_FILENAME_LENGTH];
+	u8 rand_num[RAND_NUMBER_SIZE];
+};
+
+bool fwupd_settings_trylock(void);
+void fwupd_settings_unlock(void);
+u8 get_active_boot_image(void);
+int generate_random_number(void);
diff --git a/board/aspeed/ast-g5/ipmi-fwupd.c b/board/aspeed/ast-g5/ipmi-fwupd.c
new file mode 100644
index 0000000000..3eba056e7f
--- /dev/null
+++ b/board/aspeed/ast-g5/ipmi-fwupd.c
@@ -0,0 +1,402 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include "ipmi-fwupd.h"
+
+struct fwupd_global_setting g_fwupd_settings;
+u32 g_write_addr = 0;
+
+u16 fwupd_get_execution_ctx(u8 *req, u16 req_len, u8 *res)
+{
+	int booting_image = 0x01;
+	struct fwupd_get_exe_ctx_res *result =
+		(struct fwupd_get_exe_ctx_res *)res;
+
+	/* Get active image location(primary/secondary) */
+	booting_image = get_active_boot_image();
+	result->patition_ptr = booting_image;
+	result->exection_ctx = 0x11; /* Forced Firmware Update mode */
+
+	result->completion_code = IPMI_CC_OK;
+	return sizeof(struct fwupd_get_exe_ctx_res);
+}
+u16 fwupd_get_rand_number(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_rand_num_res *result = (struct fwupd_rand_num_res *)res;
+
+	if (req_len != 0) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is critical operation is going on */
+	if (g_fwupd_settings.start_update) {
+		printf("%s(): Update in progress.\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is it already in fwupdate mode */
+	if (g_fwupd_settings.fwupd_mode_active) {
+		printf("%s(): Already in firmware update mode\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	if (generate_random_number() != 0) {
+		printf("%s(): Random number generation failed\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	result->completion_code = IPMI_CC_OK;
+	memcpy(result->rand_num, g_fwupd_settings.rand_num, RAND_NUMBER_SIZE);
+
+	return sizeof(struct fwupd_rand_num_res);
+}
+
+u16 fwupd_enter_update_mode(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_set_update_mode_res *result =
+		(struct fwupd_set_update_mode_res *)res;
+
+	if (req_len != RAND_NUMBER_SIZE) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is critical operation is going on */
+	if (g_fwupd_settings.start_update) {
+		printf("%s(): Update in progress.\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is it already in fwupdate mode */
+	if (g_fwupd_settings.fwupd_mode_active) {
+		printf("%s(): Already in firmware update mode\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	/* This command should excute within 30 seconds
+	 * after random number generation. */
+	if (!g_fwupd_settings.random_number_valid) {
+		printf("%s(): No valid random number exist.\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_CODE;
+		return sizeof(result->completion_code);
+	}
+
+	/* Validate the key to enter this mode */
+	for (int i = 0; i < RAND_NUMBER_SIZE; i++) {
+		if (req[i] != g_fwupd_settings.rand_num[i]) {
+			printf("%s(): Invalid key entered\n", __func__);
+			result->completion_code = IPMI_CC_INVALID_CODE;
+			return sizeof(result->completion_code);
+		}
+	}
+
+	if (!fwupd_settings_trylock()) {
+		printf("%s(): Lock failed\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+	/* Reset all the settings */
+	memset(&g_fwupd_settings, 0, sizeof(g_fwupd_settings));
+	g_fwupd_settings.fwupd_mode_active = true;
+	fwupd_settings_unlock();
+
+	result->completion_code = IPMI_CC_OK;
+
+	return sizeof(struct fwupd_set_update_mode_res);
+}
+
+u16 fwupd_exit_update_mode(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_exit_update_mode_res *result =
+		(struct fwupd_exit_update_mode_res *)res;
+
+	if (req_len != 0) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	if (!g_fwupd_settings.fwupd_mode_active) {
+		printf("%s(): Invalid command entered\n", __func__);
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+	}
+
+	if (!fwupd_settings_trylock()) {
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+	g_fwupd_settings.fwupd_mode_active = false;
+	fwupd_settings_unlock();
+
+	result->completion_code = IPMI_CC_OK;
+
+	return sizeof(struct fwupd_exit_update_mode_res);
+}
+u16 fwupd_set_options(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_options_req *options_req = (struct fwupd_options_req *)req;
+	struct fwupd_options_res *result = (struct fwupd_options_res *)res;
+
+	if (req_len < 2) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is critical operation is going on */
+	if (g_fwupd_settings.start_update) {
+		printf("%s(): Update in progress.\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	/* Setting any reserved bits will result the command being rejected */
+	if (((options_req->options_mask & 0xF0) != 0) ||
+	    ((options_req->options_value & 0xF0) != 0)) {
+		printf("%s(): Invalid request\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_FIELD;
+		return sizeof(result->completion_code);
+	}
+
+	if (!fwupd_settings_trylock()) {
+		printf("%s(): Lock failed\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+	g_fwupd_settings.options_mask = options_req->options_mask;
+	g_fwupd_settings.options_value = options_req->options_value;
+	fwupd_settings_unlock();
+
+	result->completion_code = IPMI_CC_OK;
+	result->options_value = (g_fwupd_settings.options_mask &
+				 g_fwupd_settings.options_value);
+
+	return sizeof(struct fwupd_options_res);
+}
+
+u16 fwupd_set_get_control(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_control_req *ctrl_req = (struct fwupd_control_req *)req;
+	struct fwupd_control_res *result = (struct fwupd_control_res *)res;
+
+	if (req_len < 1) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is critical operation is going on */
+	if (g_fwupd_settings.start_update) {
+		printf("%s(): Update in progress.\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	if ((ctrl_req->ctrl_state == SET_FW_FILENAME) && (req_len < 3)) {
+		printf("%s(): Invalid request data\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	} else if ((ctrl_req->ctrl_state != SET_FW_FILENAME) &&
+		   (req_len != 1)) {
+		printf("%s(): Invalid request data\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	if ((!g_fwupd_settings.fwupd_mode_active) &&
+	    (ctrl_req->ctrl_state != GET_CTRL_STATE)) {
+		printf("%s(): Invalid request. Control State: %d.\n", __func__,
+		       ctrl_req->ctrl_state);
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+	}
+
+	switch (ctrl_req->ctrl_state) {
+	case GET_CTRL_STATE:
+		break;
+	case IMG_TRANSFER_START:
+		if ((g_fwupd_settings.ctrl_state &
+		     IMG_TRANSFER_CTRL_BIT_START)) {
+			printf("%s(): Invalid request\n", __func__);
+			result->completion_code =
+				IPMI_CC_NOT_SUPPORTED_IN_STATE;
+			return sizeof(result->completion_code);
+		}
+
+		if (!fwupd_settings_trylock()) {
+			printf("%s(): Lock failed\n", __func__);
+			result->completion_code = IPMI_CC_NODE_BUSY;
+			return sizeof(result->completion_code);
+		}
+		g_fwupd_settings.processing_status = IMG_DOWNLOADING;
+		/* Reset control state during start */
+		g_fwupd_settings.ctrl_state = 0x00;
+		g_fwupd_settings.ctrl_state |= IMG_TRANSFER_CTRL_BIT_START;
+		/* Set current write address to ZERO */
+		g_write_addr = 0x00;
+		fwupd_settings_unlock();
+		break;
+	case IMG_TRANSFER_END:
+		if (!(g_fwupd_settings.ctrl_state &
+		      IMG_TRANSFER_CTRL_BIT_START)) {
+			printf("%s(): Invalid request\n", __func__);
+			result->completion_code =
+				IPMI_CC_NOT_SUPPORTED_IN_STATE;
+			return sizeof(result->completion_code);
+		}
+
+		if (!fwupd_settings_trylock()) {
+			result->completion_code = IPMI_CC_NODE_BUSY;
+			return sizeof(result->completion_code);
+		}
+		g_fwupd_settings.start_update = true;
+		g_fwupd_settings.ctrl_state |= IMG_TRANSFER_CTRL_BIT_END;
+
+		g_fwupd_settings.ctrl_state &= ~(IMG_TRANSFER_CTRL_BIT_START |
+						 IMG_TRANSFER_CTRL_BIT_ABORT);
+		fwupd_settings_unlock();
+		break;
+	case IMG_TRANSFER_ABORT:
+		if (!(g_fwupd_settings.ctrl_state &
+		      IMG_TRANSFER_CTRL_BIT_START)) {
+			printf("%s(): Invalid request\n", __func__);
+			result->completion_code =
+				IPMI_CC_NOT_SUPPORTED_IN_STATE;
+			return sizeof(result->completion_code);
+		}
+
+		if (!fwupd_settings_trylock()) {
+			printf("%s(): Lock failed\n", __func__);
+			result->completion_code = IPMI_CC_NODE_BUSY;
+			return sizeof(result->completion_code);
+		}
+		g_fwupd_settings.processing_status = UPDATE_ERROR;
+		g_fwupd_settings.ctrl_state |= IMG_TRANSFER_CTRL_BIT_ABORT;
+		g_fwupd_settings.ctrl_state &= ~(IMG_TRANSFER_CTRL_BIT_START |
+						 IMG_TRANSFER_CTRL_BIT_END);
+		fwupd_settings_unlock();
+		break;
+	case SET_FW_FILENAME:
+		/* Not supporting now */
+		if (ctrl_req->filename_len > sizeof(ctrl_req->filename)) {
+			printf("%s(): Invalid request\n", __func__);
+			result->completion_code = IPMI_CC_INVALID_DATA_FIELD;
+			return sizeof(result->completion_code);
+		}
+
+		if (!(g_fwupd_settings.ctrl_state &
+		      IMG_TRANSFER_CTRL_BIT_START)) {
+			printf("%s(): Invalid request\n", __func__);
+			result->completion_code =
+				IPMI_CC_NOT_SUPPORTED_IN_STATE;
+			return sizeof(result->completion_code);
+		}
+
+		if (!fwupd_settings_trylock()) {
+			printf("%s(): Lock failed\n", __func__);
+			result->completion_code = IPMI_CC_NODE_BUSY;
+			return sizeof(result->completion_code);
+		}
+		g_fwupd_settings.filename_len = ctrl_req->filename_len;
+		strncpy(g_fwupd_settings.filename, ctrl_req->filename,
+			ctrl_req->filename_len);
+		fwupd_settings_unlock();
+		/* TODO: Used for TFTP update but not implemented yet. */
+		/* TODO: Verify image and write to flash */
+		break;
+	case USB_DEV_ATTACH:
+		/* Not supporting now */
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+	case USB_DEV_DETACH:
+		/* Not supporting now */
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+		break;
+	default:
+		printf("%s(): Invalid request\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_FIELD;
+		return sizeof(result->completion_code);
+	}
+
+	result->completion_code = IPMI_CC_OK;
+	result->curr_state = g_fwupd_settings.ctrl_state;
+	return sizeof(struct fwupd_control_res);
+}
+u16 fwupd_get_update_status(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_get_update_status_res *result =
+		(struct fwupd_get_update_status_res *)res;
+
+	if (req_len != 0) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	result->processing_status = g_fwupd_settings.processing_status;
+	result->percent_completion = g_fwupd_settings.percentage_completion;
+	result->check_status = 0;
+	/* We don't support error code messages cmd(0x0EH) in uboot.*/
+	result->error_code = 0;
+
+	result->completion_code = IPMI_CC_OK;
+
+	return sizeof(struct fwupd_get_update_status_res);
+}
+
+u16 fwupd_image_write(u8 *req, u16 req_len, u8 *res)
+{
+	struct fwupd_image_write_res *result =
+		(struct fwupd_image_write_res *)res;
+
+	if (req_len < 1) {
+		printf("%s(): Invalid request length\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Check is critical operation is going on */
+	if (g_fwupd_settings.start_update) {
+		printf("%s(): Update in progress.\n", __func__);
+		result->completion_code = IPMI_CC_NODE_BUSY;
+		return sizeof(result->completion_code);
+	}
+
+	if (!g_fwupd_settings.fwupd_mode_active) {
+		printf("%s(): Invalid request\n", __func__);
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+	}
+
+	if (!(g_fwupd_settings.ctrl_state & IMG_TRANSFER_CTRL_BIT_START)) {
+		printf("%s(): Invalid request\n", __func__);
+		result->completion_code = IPMI_CC_NOT_SUPPORTED_IN_STATE;
+		return sizeof(result->completion_code);
+	}
+
+	if ((g_write_addr + req_len) > MAX_FITIMAGE_SIZE) {
+		printf("%s(): Request length exceeded max size\n", __func__);
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	u8 *mem_addr = (u8 *)((u32)IMAGE_LOAD_RAM_ADDR + g_write_addr);
+
+	memcpy(mem_addr, req, req_len);
+	g_write_addr += req_len;
+
+	result->completion_code = IPMI_CC_OK;
+	result->no_of_bytes_written = (u8)req_len;
+
+	return sizeof(struct fwupd_image_write_res);
+}
diff --git a/board/aspeed/ast-g5/ipmi-fwupd.h b/board/aspeed/ast-g5/ipmi-fwupd.h
new file mode 100644
index 0000000000..e490f6b527
--- /dev/null
+++ b/board/aspeed/ast-g5/ipmi-fwupd.h
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include "ipmi-handler.h"
+#include "fw-update.h"
+
+enum control_state {
+	GET_CTRL_STATE = 0,
+	IMG_TRANSFER_START,
+	IMG_TRANSFER_END,
+	IMG_TRANSFER_ABORT,
+	SET_FW_FILENAME,
+	USB_DEV_ATTACH,
+	USB_DEV_DETACH
+};
+enum control_state_bit {
+	IMG_TRANSFER_CTRL_BIT_START = (0x01 << 0),
+	IMG_TRANSFER_CTRL_BIT_END = (0x01 << 1),
+	IMG_TRANSFER_CTRL_BIT_ABORT = (0x01 << 2),
+	USB_CTRL_BIT_ATTACH = (0x01 << 3)
+};
+enum update_options_bit {
+	NO_DOWN_REVISION = 0,
+	DEFER_BMC_RESET = 1,
+	SHA32_INTEGRITY_CHECK = 2,
+	CRC32_INTEGRITY_CHECK = 3
+};
+
+struct fwupd_get_exe_ctx_res {
+	u8 completion_code;
+	u8 exection_ctx;
+	u8 patition_ptr;
+};
+struct fwupd_rand_num_res {
+	u8 completion_code;
+	u8 rand_num[RAND_NUMBER_SIZE];
+};
+struct fwupd_set_update_mode_res {
+	u8 completion_code;
+};
+struct fwupd_exit_update_mode_res {
+	u8 completion_code;
+};
+struct fwupd_options_req {
+	u8 options_mask;
+	u8 options_value;
+	u8 integrity_check_value[32];
+};
+struct fwupd_options_res {
+	u8 completion_code;
+	u8 options_value;
+};
+struct fwupd_control_req {
+	u8 ctrl_state;
+	u8 filename_len;
+	u8 filename[MAX_FILENAME_LENGTH];
+};
+struct fwupd_control_res {
+	u8 completion_code;
+	u8 curr_state;
+};
+struct fwupd_get_update_status_res {
+	u8 completion_code;
+	u8 processing_status;
+	u8 percent_completion;
+	u8 check_status;
+	u8 error_code;
+};
+struct fwupd_image_write_res {
+	u8 completion_code;
+	u8 no_of_bytes_written;
+};
+
+u16 fwupd_get_execution_ctx(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_get_rand_number(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_enter_update_mode(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_exit_update_mode(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_set_options(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_set_get_control(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_get_update_status(u8 *req, u16 req_len, u8 *res);
+u16 fwupd_image_write(u8 *req, u16 req_len, u8 *res);
diff --git a/board/aspeed/ast-g5/ipmi-handler.c b/board/aspeed/ast-g5/ipmi-handler.c
index 9cccee9f2f..5e78546e70 100644
--- a/board/aspeed/ast-g5/ipmi-handler.c
+++ b/board/aspeed/ast-g5/ipmi-handler.c
@@ -1,18 +1,37 @@
-
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2018-2019 Intel Corporation
 
-#include "ipmi-handler.h"
+#include "ipmi-fwupd.h"
 
 /* IPMI network function codes */
 #define NETFN_APP			0x06
+#define NETFN_FIRMWARE			0x08
+#define NETFN_INTEL_OEM			0x30
 
 /* IPMI command codes */
-#define CMD_GET_DEV_ID			0x01
-#define CMD_GET_SELF_TEST_RESULTS	0x04
+#define CMD_APP_GET_DEV_ID		0x01
+#define CMD_APP_GET_SELF_TEST_RESULTS	0x04
+#define CMD_FWUPD_GET_EXECUTION_CTX	0x23
+#define CMD_FWUPD_GET_RANDOM_NUMBER	0x26
+#define CMD_FWUPD_SET_UPDATE_MODE	0x27
+#define CMD_FWUPD_EXIT_UPDATE_MODE	0x28
+#define CMD_FWUPD_CONTROL_GET_SET	0x29
+#define CMD_FWUPD_GET_UPDATE_STATUS	0x2A
+#define CMD_FWUPD_SET_OPTIONS		0x2B
+#define CMD_FWUPD_IMAGE_WRITE		0x2C
+#define CMD_INTL_OEM_GET_BUFFER_SIZE	0x66
+
+#define MAX_KCS_BUF_SIZE		1020 /* (0xFF * 4) */
+#define MAX_IPMB_BUF_SIZE		1020 /* (0xFF * 4) */
 
 typedef u16 (*fun_handler)(u8 *req, u16 req_len, u8 *res);
 
+struct ipmi_cmd_table {
+	u8 net_fun;
+	u8 cmd;
+	fun_handler process_cmd;
+};
+
 struct get_dev_id {
 	u8 completion_code;
 	u8 dev_id;
@@ -29,11 +48,10 @@ struct self_test_res {
 	u8 completion_code;
 	u8 res_byte[2];
 };
-
-struct ipmi_cmd_table {
-	u8 net_fun;
-	u8 cmd;
-	fun_handler process_cmd;
+struct intc_get_buf_size_res {
+	u8 completion_code;
+	u8 kcs_size;
+	u8 ipmb_size;
 };
 
 static u16 get_device_id(u8 *req, u16 req_len, u8 *res)
@@ -84,10 +102,36 @@ static u16 get_self_test_result(u8 *req, u16 req_len, u8 *res)
 
 	return sizeof(struct self_test_res);
 }
+static u16 intel_get_buffer_size(u8 *req, u16 req_len, u8 *res)
+{
+	struct intc_get_buf_size_res *result =
+		(struct intc_get_buf_size_res *)res;
+
+	if (req_len != 0) {
+		result->completion_code = IPMI_CC_INVALID_DATA_LENGTH;
+		return sizeof(result->completion_code);
+	}
+
+	/* Size is multiples of four bytes */
+	result->completion_code = IPMI_CC_OK;
+	result->kcs_size = MAX_KCS_BUF_SIZE / 4;
+	result->ipmb_size = MAX_IPMB_BUF_SIZE / 4;
+
+	return sizeof(struct intc_get_buf_size_res);
+}
 
 const struct ipmi_cmd_table cmd_info[] = {
-	{ NETFN_APP,	CMD_GET_DEV_ID,			get_device_id },
-	{ NETFN_APP,	CMD_GET_SELF_TEST_RESULTS,	get_self_test_result }
+	{ NETFN_APP,		CMD_APP_GET_DEV_ID,		get_device_id },
+	{ NETFN_APP,		CMD_APP_GET_SELF_TEST_RESULTS,	get_self_test_result },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_GET_EXECUTION_CTX,	fwupd_get_execution_ctx },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_GET_RANDOM_NUMBER,	fwupd_get_rand_number },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_SET_UPDATE_MODE,	fwupd_enter_update_mode },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_EXIT_UPDATE_MODE,	fwupd_exit_update_mode },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_CONTROL_GET_SET,	fwupd_set_get_control },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_GET_UPDATE_STATUS,	fwupd_get_update_status },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_SET_OPTIONS,		fwupd_set_options },
+	{ NETFN_FIRMWARE,	CMD_FWUPD_IMAGE_WRITE,		fwupd_image_write },
+	{ NETFN_INTEL_OEM,	CMD_INTL_OEM_GET_BUFFER_SIZE,	intel_get_buffer_size }
 };
 
 #define CMD_TABLE_SIZE ARRAY_SIZE(cmd_info)
diff --git a/board/aspeed/ast-g5/ipmi-handler.h b/board/aspeed/ast-g5/ipmi-handler.h
index 9d46d9bd9a..8eea93063a 100644
--- a/board/aspeed/ast-g5/ipmi-handler.h
+++ b/board/aspeed/ast-g5/ipmi-handler.h
@@ -1,4 +1,3 @@
-
 /* SPDX-License-Identifier: GPL-2.0 */
 /* Copyright (c) 2018-2019 Intel Corporation */
 
@@ -6,12 +5,14 @@
 
 /* IPMI completion codes */
 #define IPMI_CC_OK			0x00
+#define IPMI_CC_INVALID_CODE		0x80
 #define IPMI_CC_NODE_BUSY		0xC0
 #define IPMI_CC_INVALID_CMD		0xC1
 #define IPMI_CC_INVALID_CMD_LUN		0xC2
 #define IPMI_CC_OUT_OF_SPACE		0xC4
 #define IPMI_CC_INVALID_DATA_LENGTH	0xC7
 #define IPMI_CC_INVALID_DATA_FIELD	0xCC
+#define IPMI_CC_NOT_SUPPORTED_IN_STATE	0xD5
 #define IPMI_CC_UNSPECIFIED		0xFF
 
 /* BMC IPMB LUNs */
diff --git a/common/autoboot.c b/common/autoboot.c
index d66c0fa63a..3647d5fb21 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -349,6 +349,19 @@ void autoboot_command(const char *s)
 {
 	debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
 
+#ifdef AST_G5_INTEL
+	/* TODO: Make run_command_list as non-blocking(blocked by getc())
+	 * and make main u-boot loop to check both keyboard inputs as well
+	 * as start_update firmware flags during FFUJ.
+	 * This will make sure debug mode intact during FFUJ.
+	 */
+	if (intel_force_firmware_jumper_enabled()) {
+		printf("#### Force firmware update mode is enabled, "
+					"Serial console is disabled. ####\n");
+		start_fw_update_loop();
+	}
+#endif
+
 	if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {
 #if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC)
 		int prev = disable_ctrlc(1);	/* disable Control C checking */
diff --git a/configs/ast_g5_phy_defconfig b/configs/ast_g5_phy_defconfig
index 1b96ab7f3b..5965a9b04f 100644
--- a/configs/ast_g5_phy_defconfig
+++ b/configs/ast_g5_phy_defconfig
@@ -15,3 +15,4 @@ CONFIG_SYS_NS16550=y
 CONFIG_USE_IRQ=y
 CONFIG_CMD_I2C=y
 CONFIG_SYS_I2C_AST=y
+CONFIG_LIB_RAND=y